Exemple #1
0
 def setup_mesos_agent(self, index, local_port, is_exclusive=False,
                       exclusive_label_value=''):
     config = self.config
     prefix = config["mesos_agent_container"]
     attributes = config["attributes"]
     if is_exclusive:
         prefix += "-exclusive"
         attributes += ";peloton/exclusive:" + exclusive_label_value
     agent = prefix + repr(index)
     ctn_port = config["agent_port"]
     container = self.cli.create_container(
         name=agent,
         hostname=agent,
         volumes=["/files", "/var/run/docker.sock"],
         ports=[repr(ctn_port)],
         host_config=self.cli.create_host_config(
             port_bindings={ctn_port: local_port},
             binds=[
                 work_dir + "/files:/files",
                 work_dir
                 + "/mesos_config/etc_mesos-slave:/etc/mesos-slave",
                 "/var/run/docker.sock:/var/run/docker.sock",
             ],
             privileged=True,
         ),
         environment=[
             "MESOS_PORT=" + repr(ctn_port),
             "MESOS_MASTER=zk://{0}:{1}/mesos".format(
                 self.cli.get_container_ip(config["zk_container"]),
                 config["default_zk_port"],
             ),
             "MESOS_SWITCH_USER="******"switch_user"]),
             "MESOS_CONTAINERIZERS=" + config["containers"],
             "MESOS_LOG_DIR=" + config["log_dir"],
             "MESOS_ISOLATION=" + config["isolation"],
             "MESOS_SYSTEMD_ENABLE_SUPPORT=false",
             "MESOS_IMAGE_PROVIDERS=" + config["image_providers"],
             "MESOS_IMAGE_PROVISIONER_BACKEND={0}".format(
                 config["image_provisioner_backend"]
             ),
             "MESOS_APPC_STORE_DIR=" + config["appc_store_dir"],
             "MESOS_WORK_DIR=" + config["work_dir"],
             "MESOS_RESOURCES=" + config["resources"],
             "MESOS_ATTRIBUTES=" + attributes,
             "MESOS_MODULES=" + config["modules"],
             "MESOS_RESOURCE_ESTIMATOR=" + config["resource_estimator"],
             "MESOS_OVERSUBSCRIBED_RESOURCES_INTERVAL="
             + config["oversubscribed_resources_interval"],
             "MESOS_QOS_CONTROLLER=" + config["qos_controller"],
             "MESOS_QOS_CORRECTION_INTERVAL_MIN="
             + config["qos_correction_interval_min"],
         ],
         image=config["mesos_slave_image"],
         entrypoint="bash /files/run_mesos_slave.sh",
         detach=True,
     )
     self.cli.start(container=container.get("Id"))
     utils.wait_for_up(agent, local_port, "state.json")
Exemple #2
0
def start_and_wait(application_name,
                   container_name,
                   ports,
                   config,
                   extra_env=None):
    # TODO: It's very implicit that the first port is the HTTP port, perhaps we
    # should split it out even more.
    election_zk_servers = None
    mesos_zk_path = None
    if zk_url is not None:
        election_zk_servers = zk_url
        mesos_zk_path = "zk://{0}/mesos".format(zk_url)
    else:
        election_zk_servers = "{0}:{1}".format(
            utils.get_container_ip(config["zk_container"]),
            config["default_zk_port"],
        )
        mesos_zk_path = "zk://{0}:{1}/mesos".format(
            utils.get_container_ip(config["zk_container"]),
            config["default_zk_port"],
        )
    cass_hosts = utils.get_container_ip(config["cassandra_container"])
    env = {
        "CONFIG_DIR": "config",
        "APP": application_name,
        "HTTP_PORT": ports[0],
        "DB_HOST": utils.get_container_ip(config["cassandra_container"]),
        "ELECTION_ZK_SERVERS": election_zk_servers,
        "MESOS_ZK_PATH": mesos_zk_path,
        "MESOS_SECRET_FILE": "/files/hostmgr_mesos_secret",
        "CASSANDRA_HOSTS": cass_hosts,
        "ENABLE_DEBUG_LOGGING": config["debug"],
        "DATACENTER": "",
        # used to migrate the schema;used inside host manager
        "AUTO_MIGRATE": config["auto_migrate"],
        "CLUSTER": "minicluster",
    }
    if len(ports) > 1:
        env["GRPC_PORT"] = ports[1]
    if extra_env:
        env.update(extra_env)
    environment = []
    for key, value in env.iteritems():
        environment.append("%s=%s" % (key, value))
    # BIND_MOUNTS allows additional files to be mounted in the
    # the container. Expected format is a comma-separated list
    # of items of the form <host-path>:<container-path>
    mounts = os.environ.get("BIND_MOUNTS", "")
    mounts = mounts.split(",") if mounts else []
    container = cli.create_container(
        name=container_name,
        hostname=container_name,
        ports=[repr(port) for port in ports],
        environment=environment,
        host_config=cli.create_host_config(
            port_bindings={port: port
                           for port in ports},
            binds=[work_dir + "/files:/files"] + mounts,
        ),
        # pull or build peloton image if not exists
        image=config["peloton_image"],
        detach=True,
    )
    cli.start(container=container.get("Id"))
    utils.wait_for_up(container_name,
                      ports[0])  # use the first port as primary