{
  "id": "/pulsar",
  "// Notice:" : "mem, cpus, volume size, zkServers, may need change according to your DC/OS deployment.",
  "groups": [
    {
      "id": "/pulsar/bookkeeper",
      "apps": [
        {
          "id": "/pulsar/bookkeeper/bookie",
          "cpus": 1,
          "mem": 1024,
          "instances": 3,
          "constraints": [["hostname", "UNIQUE"]],
          "container": {
            "type": "DOCKER",
            "volumes": [
              {
                "containerPath": "/bookkeeper/data/journal",
                "hostPath": "journal",
                "mode": "RW"
              },

              {
                "containerPath": "journal",
                "mode": "RW",
                "persistent": {
                  "size": 7000
                }
              },

              {
                "containerPath": "/bookkeeper/data/index",
                "hostPath": "index",
                "mode": "RW"
              },
              {
                "containerPath": "index",
                "mode": "RW",
                "persistent": {
                  "size": 7000
                }
              },

              {
                "containerPath": "/bookkeeper/data/ledgers",
                "hostPath": "ledgers",
                "mode": "RW"
              },
              {
                "containerPath": "ledgers",
                "mode": "RW",
                "persistent": {
                  "size": 30000
                }
              }
            ],

            "docker": {
              "image": "apachepulsar/pulsar:latest",
              "network": "HOST"
            }
          },

          "residency": {
            "taskLostBehavior": "WAIT_FOREVER"
          },


          "portDefinitions": [
            {
              "protocol": "tcp",
              "port": 3181
            },
            {
              "port": 8000,
              "protocol": "tcp",
              "labels": {
                "METRICS_PATH": "/metrics"
              }
            }
          ],

          "requirePorts": true,

          "env": {
            "// Notice": "add PULSAR_MEM, PULSAR_GC, according to your environment.",
            "zkServers":  "master.mesos:2181",
            "ledgerManagerType": "hierarchical",
            "statsProviderClass": "org.apache.bookkeeper.stats.prometheus.PrometheusMetricsProvider",
            "journalDirectory": "/bookkeeper/data/journal",
            "ledgerDirectories": "/bookkeeper/data/ledgers",
            "indexDirectories": "/bookkeeper/data/index"
          },

          "args": ["sh", "-c", "python bin/apply-config-from-env.py conf/bookkeeper.conf && python bin/apply-config-from-env.py conf/pulsar_env.sh && bin/bookkeeper shell metaformat -n || true; bin/pulsar bookie"],

          "healthChecks": [
            {
              "protocol": "TCP",
              "portIndex": 0,
              "gracePeriodSeconds": 300,
              "intervalSeconds": 60,
              "timeoutSeconds": 20,
              "maxConsecutiveFailures": 0,
              "ignoreHttp1xx": false
            }
          ],

          "upgradeStrategy": {
            "maximumOverCapacity": 0,
            "minimumHealthCapacity": 0
          }
        },
        {
          "id": "/pulsar/bookkeeper/bookie-autorecovery",
          "cpus": 1,
          "mem": 1024,
          "instances": 1,
          "constraints": [["hostname", "UNIQUE"]],
          "container": {
            "type": "DOCKER",

            "docker": {
              "image": "apachepulsar/pulsar:latest",
              "network": "HOST"
            }
          },

          "env": {
            "zkServers":  "master.mesos:2181",
            "PULSAR_MEM": "\" -Xmx128m \"",
            "PULSAR_GC": "\"  \""
          },

          "args": ["sh", "-c", "python bin/apply-config-from-env.py conf/bookkeeper.conf && bin/bookkeeper autorecovery"],

          "upgradeStrategy": {
            "maximumOverCapacity": 0,
            "minimumHealthCapacity": 0
          }
        }
      ]
    },

    {
      "id": "/pulsar/brokers",
      "dependencies": ["/pulsar/bookkeeper/bookie"],
      "apps": [
        {
          "// Notice:" : "change mem, cpu, volume size, zkServers, according to your DC/OS deployment.",
          "id": "/pulsar/brokers/broker",
          "cpus": 1,
          "mem": 1024,
          "instances": 3,
          "constraints": [["hostname", "UNIQUE"]],
          "container": {
            "type": "DOCKER",

            "docker": {
              "image": "apachepulsar/pulsar:latest",
              "network": "HOST"
            }
          },

          "portDefinitions": [
            {
              "protocol": "tcp",
              "port": 6650
            },
            {
              "protocol": "tcp",
              "port": 8082,
              "labels": {
                "METRICS_PATH": "/metrics"
              }
            }
          ],

          "requirePorts": true,

          "env": {
            "// Notice": "add PULSAR_MEM, PULSAR_GC, according to your environment.",
            "webServicePort": "8082",
            "zookeeperServers":  "master.mesos:2181",
            "configurationStoreServers":  "master.mesos:2181",
            "clusterName": "pulsar-dcos"
          },

          "args": ["sh", "-c", "python bin/apply-config-from-env.py conf/broker.conf && python bin/apply-config-from-env.py conf/pulsar_env.sh && bin/pulsar broker"],

          "healthChecks": [
            {
              "protocol": "TCP",
              "portIndex": 0,
              "gracePeriodSeconds": 300,
              "intervalSeconds": 60,
              "timeoutSeconds": 20,
              "maxConsecutiveFailures": 0,
              "ignoreHttp1xx": false
            }
          ],

          "upgradeStrategy": {
            "maximumOverCapacity": 0,
            "minimumHealthCapacity": 0
          }
        },
        {
          "id": "/pulsar/brokers/brokeradmin",
          "cpus": 1,
          "mem": 1024,
          "instances": 1,
          "constraints": [["hostname", "UNIQUE"]],
          "container": {
            "type": "DOCKER",

            "docker": {
              "image": "apachepulsar/pulsar:latest",
              "network": "HOST"
            }
          },

          "env": {
            "webServicePort": "8082",
            "zookeeperServers":  "master.mesos:2181",
            "configurationStoreServers":  "master.mesos:2181",
            "clusterName": "pulsar-dcos",
            "webServiceUrl": "http://broker.brokers.pulsar.marathon.mesos:8082",
            "brokerServiceUrl":  "pulsar://broker.brokers.pulsar.marathon.mesos:6650"
          },

          "args": ["sh", "-c", "bin/apply-config-from-env.py conf/client.conf && sleep 10000000000"]
        }
      ]
    },

    {
      "id": "/pulsar/monitor",
      "dependencies": ["/pulsar/brokers/broker"],
      "apps": [
        {
          "id": "/pulsar/monitor/prom",
          "cpus": 0.5,
          "mem": 512,
          "instances": 1,
          "constraints": [["hostname", "UNIQUE"]],
          "container": {
            "type": "DOCKER",

            "docker": {
              "image": "zhaijia/prometheus",
              "forcePullImage": false,
              "network": "BRIDGE"
            },

            "portMappings": [
              {
                "containerPort": 9090,
                "hostPort": 9090,
                "protocol": "tcp"
              }
            ],

            "volumes": [
              {
                "containerPath": "/prometheus",
                "hostPath": "data-volume",
                "mode": "RW"
              },

              {
                "containerPath": "data-volume",
                "mode": "RW",
                "persistent": {
                  "size": 7000
                }
              }
            ]
          },

          "upgradeStrategy": {
            "maximumOverCapacity": 0,
            "minimumHealthCapacity": 0
          },

          "healthChecks": [
            {
              "path": "/graph",
              "portIndex": 0,
              "protocol": "HTTP",
              "gracePeriodSeconds": 300,
              "intervalSeconds": 60,
              "timeoutSeconds": 20,
              "maxConsecutiveFailures": 0,
              "ignoreHttp1xx": false
            }
          ]
        },
        {
          "id": "/pulsar/monitor/grafana",
          "dependencies": ["/pulsar/monitor/prom"],
          "cpus": 0.5,
          "mem": 512,
          "instances": 1,
          "constraints": [["hostname", "UNIQUE"]],
          "container": {
            "type": "DOCKER",

            "docker": {
              "image": "apachepulsar/pulsar-grafana:latest",
              "network": "BRIDGE",
              "forcePullImage": false,
              "portMappings": [
                {
                  "containerPort": 3000,
                  "hostPort": 3000,
                  "protocol": "tcp",
                  "labels": {
                    "VIP_0": "/pulsar-grafana:3000"
                  }
                }
              ]
            }
          },

          "env": {
            "PROMETHEUS_URL": "http://prom.monitor.pulsar.marathon.mesos:9090"
          },

          "healthChecks": [
            {
              "path": "/login",
              "protocol": "HTTP",
              "portIndex": 0,
              "gracePeriodSeconds": 300,
              "intervalSeconds": 60,
              "timeoutSeconds": 20,
              "maxConsecutiveFailures": 0,
              "ignoreHttp1xx": false
            }
          ],
          "upgradeStrategy": {
            "maximumOverCapacity": 0,
            "minimumHealthCapacity": 0
          }
        }
      ]
    }
  ]
}
