当前位置: 首页>>代码示例>>Python>>正文


Python MarathonClient.create_app方法代码示例

本文整理汇总了Python中marathon.MarathonClient.create_app方法的典型用法代码示例。如果您正苦于以下问题:Python MarathonClient.create_app方法的具体用法?Python MarathonClient.create_app怎么用?Python MarathonClient.create_app使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在marathon.MarathonClient的用法示例。


在下文中一共展示了MarathonClient.create_app方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: MarathonDeployer

# 需要导入模块: from marathon import MarathonClient [as 别名]
# 或者: from marathon.MarathonClient import create_app [as 别名]
class MarathonDeployer(object):


    def __init__(self, marathon_url):
        self.url = marathon_url
        self.client = MarathonClient(self.url)

    def deploy(self, task_chain, environment_name):
        deployed_chain = DeployedTaskChain(task_chain, environment_name)
        for task in deployed_chain.list_all_tasks():
            task_id = task['id']
            safe_name = task_id.lower()
            # safe_name = task['name'].replace('.', '').lower()
            try:
                if self.client.get_app(safe_name):
                    self.client.delete_app(safe_name)
                    time.sleep(2)
            except Exception:
                pass

            app = MarathonApp(cmd='/var/riversnake/invoke.py {0} {1} {2}'.format(
                        task_chain.flow_name,
                        environment_name,
                        task_id),
                    mem=16, cpus=1)

            self.client.create_app(safe_name, app)
开发者ID:jal648,项目名称:riversnake,代码行数:29,代码来源:deploy.py

示例2: launch_qsf

# 需要导入模块: from marathon import MarathonClient [as 别名]
# 或者: from marathon.MarathonClient import create_app [as 别名]
def launch_qsf(marathon_url):
    logging.info('Launching QSF using %s' %(marathon_url))

    # launch via Marathon REST API
    c = MarathonClient(marathon_url)
    c.create_app('dromedar-qsf', MarathonApp(cmd='python dromedar-master/qsf.py %s' %(marathon_url), uris=['https://github.com/mhausenblas/dromedar/archive/master.zip'], mem=100, cpus=.5))
    
    logging.info('QSF up and running.')
开发者ID:else,项目名称:dromedar,代码行数:10,代码来源:dromedar.py

示例3: launch_drillbits

# 需要导入模块: from marathon import MarathonClient [as 别名]
# 或者: from marathon.MarathonClient import create_app [as 别名]
def launch_drillbits(marathon_url, scale_factor):
    logging.info('Launching Drillbits using %s and scale factor %d' %(marathon_url, int(scale_factor)))

    # launch Drillbits via Marathon REST API
    c = MarathonClient(marathon_url)
    # c.create_app('dromedar-drill', MarathonApp(cmd='dromedar-master/launch-drillbit.sh', uris=['https://github.com/mhausenblas/dromedar/archive/master.zip'], mem=400, cpus=1))
    
    c.create_app('dromedar-drill', MarathonApp(cmd='sudo /opt/drill/apache-drill-0.8.0/bin/drillbit.sh start', mem=400, cpus=1))

    print('Drillbits are deployed: DATASETSIZE, NUM_DRILLBITS')
    
    httpd = SocketServer.TCPServer(("", QSF_PORT), SimpleHTTPServer.SimpleHTTPRequestHandler)
    logging.info('Now listening to change requests on port %d' %(QSF_PORT))
    httpd.serve_forever()
开发者ID:else,项目名称:dromedar,代码行数:16,代码来源:qsf.py

示例4: launch

# 需要导入模块: from marathon import MarathonClient [as 别名]
# 或者: from marathon.MarathonClient import create_app [as 别名]
def launch(service):
	print 'launching ' + service
	service_dict = data['services'][service]
	image = service_dict['image']
	try:
		ports = service_dict['ports'].values()
	except:
		ports = []
	instances = 1 if not service_dict.get('instances') else service_dict.get('instances')
	cpus = 0.3 if not service_dict.get('cpus') else service_dict.get('cpus')
	mem = 512 if not service_dict.get('mem') else service_dict.get('mem')
	#
	# env variables
	#
	env = {}
	env['ETCD_HOST_ADDRESS'] = data['etcd']['host']
	env['SERVICE_NAME'] = service
	# set up custom environment variables
	custom_env = service_dict.get('environment')
	if custom_env:
		for key in custom_env.keys():
			env[key] = custom_env[key]
	options = []
	constraints = []

	#
	# TODO add support for this
	#
	if service == "cassandra":
		options = ["-p", "7000:7000", "-p", "9042:9042", "-p", "9160:9160", "-p", "22000:22", "-p", "5000:5000"]
		ports = []
		constraints = [["hostname", "UNIQUE"]]
	#
	# set up marathon client and launch container
	#
	marathon_client = MarathonClient('http://' + str(data['marathon']['host']) + ':' + str(data['marathon']['port']))
	marathon_client.create_app(
		container = {
			"image" : str("docker:///"+image), 
			"options" : options
		},
		id = service,
		instances = str(instances),
		constraints = constraints,
		cpus = str(cpus),
		mem = str(mem),
		env = env,
		ports = ports #should be listed in order they appear in dockerfile
		
	)
开发者ID:davidbliu,项目名称:Mesos-Docker,代码行数:52,代码来源:launcher.py

示例5: marathon_api_launch

# 需要导入模块: from marathon import MarathonClient [as 别名]
# 或者: from marathon.MarathonClient import create_app [as 别名]
def marathon_api_launch(image, options, marathon_app_id, instances, constraints, cpus, mem, env, ports):
	marathon_client = MarathonClient('http://' + str(marathon_host) + ':' + str(marathon_port))
	marathon_client.create_app(
		container = {
			"image" : str("docker:///"+image), 
			"options" : options
		},
		id = marathon_app_id,
		instances = str(instances),
		constraints = constraints,
		cpus = str(cpus),
		mem = str(mem),
		env = env,
		ports = ports #should be listed in order they appear in dockerfile
	)
	return marathon_app_id
开发者ID:davidbliu,项目名称:Marathon-Subscriber,代码行数:18,代码来源:launcher.py

示例6: launch_elsa

# 需要导入模块: from marathon import MarathonClient [as 别名]
# 或者: from marathon.MarathonClient import create_app [as 别名]
def launch_elsa(marathon, stats_file, scale_window):
    logging.info('Start monitoring the inbound traffic on topics using %s' %(stats_file))
    # make sure the stats file is properly initialized:
    if not os.path.exists(stats_file):
        f = open(stats_file, 'w')
        f.write('0')
        f.close()
    
    # launch the Elsa app via Marathon
    c = MarathonClient(marathon)
    c.create_app('elsa', MarathonApp(cmd='/home/vagrant/elsa/launch-elsa.sh', mem=200, cpus=1, user='vagrant'))
    # c.list_apps()
    
    print('ElSA is deployed and running, waiting now 5 sec before starting auto-scale ...')
    time.sleep(5) # allow time to deploy before autoscaling sets in
    
    # kick off traffic monitoring and trigger autoscaling:
    previous_topic_traffic = 0
    try:
        while True:
            with open(stats_file, 'r') as elsa_file:
                topic_traffic = int(elsa_file.read())
                topic_traffic_diff = topic_traffic - previous_topic_traffic
                print('Difference in traffic in the past %d seconds: %d' %(scale_window, topic_traffic_diff))
                previous_topic_traffic = topic_traffic
            
                current_instance_num = c.get_app('elsa').instances
            
                if topic_traffic_diff > TRAFFIC_INCREASE_THRESHOLD: # we see a surge of traffic above threshold ...
                    instance_multiplier = int(topic_traffic_diff / SCALE_FACTOR) # ... increase number of instances
                    c.scale_app('elsa', current_instance_num * instance_multiplier)
                    print('Increasing number of instances to %d' %(current_instance_num * instance_multiplier))
                elif topic_traffic_diff < 0: # negative, back off exponentially 
                    target_instance_num = int(current_instance_num/2)
                    if target_instance_num > 1:
                        c.scale_app('elsa', target_instance_num)
                        print('Decreasing number of instances to %d' %(target_instance_num))
                    else:
                        c.scale_app('elsa', 1)
                        print('Resetting number of instances to 1')
            time.sleep(scale_window)
    except KeyboardInterrupt:
        print('ElSA has been stopped by user, halting app and rolling back deployment. Thanks and bye!')
        c.delete_app('elsa', force=True)
开发者ID:SemanticBeeng,项目名称:elsa,代码行数:46,代码来源:autoscale.py

示例7: TestCreateApp

# 需要导入模块: from marathon import MarathonClient [as 别名]
# 或者: from marathon.MarathonClient import create_app [as 别名]
class TestCreateApp(unittest.TestCase):
    """
    Test the creation of a Marathon app against a live endpoint. Configure MARATHON_SERVER in tests.config.
    """

    def setUp(self):
        self._app = get_app()  # Generate a random server configuration.
        self.client = MarathonClient(MARATHON_SERVER)
        self.client.create_app(app_id=self._app.id, app=self._app)
        time.sleep(2)  # Wait two seconds for the POST to be processed by Marathon.
        self.app = self.client.get_app(self._app.id)
        while not self.app.tasks_healthy:  # Wait until the app becomes healthy.
            self.app = self.client.get_app(self._app.id)
            time.sleep(1)

    def test_create(self):
        self.assertIsInstance(self.app, MarathonApp)
        self.assertIsInstance(self.app.upgrade_strategy, MarathonUpgradeStrategy)
        self.assertIsInstance(self.app.tasks.pop(), MarathonTask)
        self.assertIsInstance(self.app.health_checks.pop(), MarathonHealthCheck)

    def tearDown(self):
        self.client.delete_app(self.app.id, force=True)
开发者ID:keshavdv,项目名称:marathon-python,代码行数:25,代码来源:test_create_app.py

示例8: new_deploy

# 需要导入模块: from marathon import MarathonClient [as 别名]
# 或者: from marathon.MarathonClient import create_app [as 别名]
def new_deploy(app_name, app_file):
    """Calls marathon API to make new deployment of application given file as request body

    :param app_name:
    :param app_file:
    :return:
    """
    marathon_addresses = _addresses()
    with open(app_file, 'r') as content_file:
        content = content_file.read()
    app_attr = json.loads(content)
    cli = MarathonClient(marathon_addresses)
    if not _is_deployed(cli, app_name):
        m_app = models.MarathonApp.from_json(app_attr)
        created_app = cli.create_app(app_name, m_app)
        return created_app.to_json()
    else:
        return None
开发者ID:MavenCode,项目名称:saltstack-formulas,代码行数:20,代码来源:marathon_client.py

示例9: MarathonHTTPClient

# 需要导入模块: from marathon import MarathonClient [as 别名]
# 或者: from marathon.MarathonClient import create_app [as 别名]
class MarathonHTTPClient(object):

    def __init__(self, target, auth, options, pkey):
        self.target = settings.MARATHON_HOST
        self.auth = auth
        self.options = options
        self.pkey = pkey
        self.registry = settings.REGISTRY_HOST + ':' + settings.REGISTRY_PORT
        self.client = MarathonClient('http://'+self.target+':8180')
        self.fleet = FleetHTTPClient('/var/run/fleet.sock', auth, options, pkey)

    # helpers
    def _app_id(self, name):
        return name.replace('_', '.')

    # container api
    def create(self, name, image, command='', **kwargs):
        """Create a container"""
        app_id = self._app_id(name)
        l = locals().copy()
        l.update(re.match(MATCH, name).groupdict())
        image = self.registry + '/' + image
        mems = kwargs.get('memory', {}).get(l['c_type'])
        m = 0
        if mems:
            mems = mems.lower()
            if mems[-2:-1].isalpha() and mems[-1].isalpha():
                mems = mems[:-1]
            m = int(mems[:-1])
        c = 0.5
        cpu = kwargs.get('cpu', {}).get(l['c_type'])
        if cpu:
            c = cpu
        cmd = "docker run --name {name} -P {image} {command}".format(**locals())
        self.client.create_app(app_id, MarathonApp(cmd=cmd, mem=m, cpus=c))
        self.client.scale_app(app_id, 0, force=True)
        for _ in xrange(POLL_ATTEMPTS):
            if self.client.get_app(self._app_id(name)).tasks_running == 0:
                return
            time.sleep(1)

    def start(self, name):
        """Start a container"""
        self.client.scale_app(self._app_id(name), 1, force=True)
        for _ in xrange(POLL_ATTEMPTS):
            if self.client.get_app(self._app_id(name)).tasks_running == 1:
                break
            time.sleep(1)
        host = self.client.get_app(self._app_id(name)).tasks[0].host
        self._waitforcontainer(host, name)

    def stop(self, name):
        """Stop a container"""
        raise NotImplementedError

    def destroy(self, name):
        """Destroy a container"""
        try:
            host = self.client.get_app(self._app_id(name)).tasks[0].host
            self.client.delete_app(self._app_id(name), force=True)
            self._delete_container(host, name)
        except:
            self.client.delete_app(self._app_id(name), force=True)

    def _get_container_state(self, host, name):
        docker_cli = Client("tcp://{}:2375".format(host), timeout=1200, version='1.17')
        try:
            if docker_cli.inspect_container(name)['State']['Running']:
                return JobState.up
        except:
            return JobState.destroyed

    def _waitforcontainer(self, host, name):
        for _ in xrange(POLL_WAIT):
            if self._get_container_state(host, name) == JobState.up:
                return
            time.sleep(1)
        raise RuntimeError("App container Not Started")

    def _delete_container(self, host, name):
        docker_cli = Client("tcp://{}:2375".format(host), timeout=1200, version='1.17')
        if docker_cli.inspect_container(name)['State']:
            docker_cli.remove_container(name, force=True)

    def run(self, name, image, entrypoint, command):  # noqa
        """Run a one-off command"""
        return self.fleet.run(name, image, entrypoint, command)

    def state(self, name):
        try:
            for _ in xrange(POLL_ATTEMPTS):
                if self.client.get_app(self._app_id(name)).tasks_running == 1:
                    return JobState.up
                elif self.client.get_app(self._app_id(name)).tasks_running == 0:
                    return JobState.created
                time.sleep(1)
        except:
            return JobState.destroyed

    def attach(self, name):
#.........这里部分代码省略.........
开发者ID:Kazanz,项目名称:deis,代码行数:103,代码来源:mesos_marathon.py

示例10: MarathonIF

# 需要导入模块: from marathon import MarathonClient [as 别名]
# 或者: from marathon.MarathonClient import create_app [as 别名]
class MarathonIF(object):
    def __init__(self, marathon_addr, my_addr, mesos):
        self.mcli = MarathonClient(marathon_addr)
        self.myAddr = my_addr
        self.mesos = mesos

    def get_apps(self):
        listapps = self.mcli.list_apps()
        return listapps

    def get_app(self, app_id):
        try:
            a = self.mcli.get_app(app_id)
        except marathon.exceptions.NotFoundError as e:  # NOQA
            return None
        return a

    def delete_app(self, app_id, force=False):
        return self.mcli.delete_app(app_id, force)

    def delete_deployment(self, dep_id):
        return self.mcli.delete_deployment(dep_id)

    def get_deployments(self):
        return self.mcli.list_deployments()

    def delete_app_ifexisting(self, app_id, trys=4):
        for idx in range(0, trys):
            try:
                a = self.get_app(app_id)
                if a:
                    return self.delete_app(app_id)
                return None
            except:
                e = sys.exc_info()[0]
                pprint("<p>Error: %s</p>" % e)
                time.sleep(10)
        raise

    @staticmethod
    def is_valid_app_id(app_id):
        # allowed: lowercase letters, digits, hyphens, slash, dot
        if re.match("^[A-Za-z0-9-/.]*$", app_id):
            return True
        return False

    def create_app(self, app_id, attr):
        """
            Create and start an app.
            :param app_id: (str) - Application ID
            :param attr: marathon.models.app.MarathonApp application to create.
            :return: the created app
        """
        # Validate that app_id conforms to allowed naming scheme.
        if not self.is_valid_app_id(app_id):
            l.error("Error: Only lowercase letters, digits, hyphens are allowed in app_id. %s" % app_id)
            raise Exception("Invalid app_id")

        for idx in range(0, 10):
            try:
                a = self.mcli.create_app(app_id, attr)
                return a
            except marathon.exceptions.MarathonHttpError as e:
                if str(e).find('App is locked by one or more deployments. Override with the option') >= 0:
                    time.sleep(1)
                else:
                    raise
        raise

    def wait_app_removal(self, app):
        cnt = 0
        while True:
            if not self.get_app(app):
                break
            time.sleep(0.2)
            cnt += 1
            if cnt > 0:
                l.info("Stuck waiting for %s to be deleted CNT=%d" % (app, cnt))
        return True

    def wait_app_ready(self, app, running_count):
        cnt = 0
        while True:
            a1 = self.get_app(app)
            if a1.tasks_running == running_count:
                return a1
            cnt += 1
            time.sleep(1)
            if (cnt % 30) == 29:
                l.info("[%d]Waiting for task to move to running stage, " % cnt +
                       "current stat staged=%d running=%d expected Running=%d" %
                       (a1.tasks_staged, a1.tasks_running, running_count))

    def scale_app(self, app, scale):
        return self.mcli.scale_app(app, scale)

    def ping(self):
        return self.mcli.ping()
开发者ID:annym,项目名称:hydra,代码行数:100,代码来源:mmapi.py

示例11: MarathonIF

# 需要导入模块: from marathon import MarathonClient [as 别名]
# 或者: from marathon.MarathonClient import create_app [as 别名]
class MarathonIF(object):
    def __init__(self, marathon_addr, my_addr, mesos):
        self.mcli = MarathonClient(marathon_addr)
        self.myAddr = my_addr
        self.mesos = mesos

    def get_apps(self):
        listapps = self.mcli.list_apps()
        return listapps

    def get_app(self, app_id):
        try:
            a = self.mcli.get_app(app_id)
        except marathon.exceptions.NotFoundError as e:  # NOQA
            return None
        return a

    def delete_app(self, app_id, force=False):
        return self.mcli.delete_app(app_id, force)

    def delete_deployment(self, dep_id):
        return self.mcli.delete_deployment(dep_id)

    def get_deployments(self):
        return self.mcli.list_deployments()

    def delete_app_ifexisting(self, app_id, trys=4):
        for idx in range(0, trys):
            try:
                a = self.get_app(app_id)
                if a:
                    return self.delete_app(app_id)
                return None
            except:
                e = sys.exc_info()[0]
                pprint("<p>Error: %s</p>" % e)
                time.sleep(10)
        raise

    def create_app(self, app_id, attr):
        for idx in range(0, 10):
            try:
                a = self.mcli.create_app(app_id, attr)
                return a
            except marathon.exceptions.MarathonHttpError as e:
                if str(e).find('App is locked by one or more deployments. Override with the option') >= 0:
                    time.sleep(1)
                else:
                    raise
        raise

    def wait_app_removal(self, app):
        cnt = 0
        while True:
            if not self.get_app(app):
                break
            time.sleep(0.2)
            cnt += 1
            if cnt > 0:
                l.info("Stuck waiting for %s to be deleted CNT=%d" % (app, cnt))
        return True

    def wait_app_ready(self, app, running_count):
        cnt = 0
        while True:
            a1 = self.get_app(app)
            if a1.tasks_running == running_count:
                return a1
            cnt += 1
            time.sleep(1)
            if (cnt % 30) == 29:
                l.info("[%d]Waiting for task to move to running stage, " % cnt +
                       "current stat staged=%d running=%d expected Running=%d" %
                       (a1.tasks_staged, a1.tasks_running, running_count))

    def scale_app(self, app, scale):
        return self.mcli.scale_app(app, scale)

    def ping(self):
        return self.mcli.ping()
开发者ID:lorenzodavid,项目名称:hydra,代码行数:82,代码来源:mmapi.py

示例12: MarathonIF

# 需要导入模块: from marathon import MarathonClient [as 别名]
# 或者: from marathon.MarathonClient import create_app [as 别名]
class MarathonIF(object):
    def __init__(self, marathon_addr, my_addr, mesos):
        self.mcli = MarathonClient(marathon_addr)
        self.myAddr = my_addr
        self.mesos = mesos

    def get_apps(self):
        listapps = self.mcli.list_apps()
        return listapps

    def get_app(self, app_id, timeout=300):
        st_time = time.time()
        while(time.time() - st_time < timeout):
            try:
                try:
                    a = self.mcli.get_app(app_id)
                except marathon.exceptions.NotFoundError as e:  # NOQA
                    return None
                return a
            except:
                l.info("mcli: get_app returned error")
                l.info(traceback.format_exc())
                l.info("Retrying after 10 secs timeout=%d", timeout)
                time.sleep(10)
        raise Exception("mcli get_app timed out, possible zookeper/marathon/mesos malfunction")

    def delete_app(self, app_id, force=False, timeout=200):
        st_time = time.time()
        while(time.time() - st_time < timeout):
            try:
                self.mcli.delete_app(app_id, force)
                return
            except:
                l.info("mcli: delete_app returned error")
                l.info(traceback.format_exc())
                l.info("Retrying after 10 secs timeout=%d", timeout)
                time.sleep(10)
        raise Exception("mcli delete_app timed out, possible zookeper/marathon/mesos malfunction")

    def delete_deployment(self, dep_id):
        return self.mcli.delete_deployment(dep_id)

    def get_deployments(self):
        return self.mcli.list_deployments()

    def delete_app_ifexisting(self, app_id, trys=4):
        for idx in range(0, trys):
            try:
                a = self.get_app(app_id)
                if a:
                    return self.delete_app(app_id)
                return None
            except:
                e = sys.exc_info()[0]
                pprint("<p>Error: %s</p>" % e)
                time.sleep(10)
        raise

    @staticmethod
    def is_valid_app_id(app_id):
        # allowed: lowercase letters, digits, hyphens, slash, dot
        if re.match("^[A-Za-z0-9-/.]*$", app_id):
            return True
        return False

    def create_app(self, app_id, attr):
        """
            Create and start an app.
            :param app_id: (str) - Application ID
            :param attr: marathon.models.app.MarathonApp application to create.
            :return: the created app
        """
        # Validate that app_id conforms to allowed naming scheme.
        if not self.is_valid_app_id(app_id):
            l.error("Error: Only lowercase letters, digits, hyphens are allowed in app_id. %s" % app_id)
            raise Exception("Invalid app_id")

        for idx in range(0, 10):
            try:
                a = self.mcli.create_app(app_id, attr)
                return a
            except marathon.exceptions.MarathonHttpError as e:
                if str(e).find('App is locked by one or more deployments. Override with the option') >= 0:
                    time.sleep(1)
                else:
                    raise
        raise

    def wait_app_removal(self, app):
        cnt = 0
        while True:
            if not self.get_app(app):
                break
            time.sleep(0.2)
            cnt += 1
            if cnt > 0:
                l.info("Stuck waiting for %s to be deleted CNT=%d" % (app, cnt))
        return True

    def wait_app_ready(self, app, running_count, sleep_before_next_try=1):
#.........这里部分代码省略.........
开发者ID:kratos7,项目名称:hydra,代码行数:103,代码来源:mmapi.py

示例13: MarathonHTTPClient

# 需要导入模块: from marathon import MarathonClient [as 别名]
# 或者: from marathon.MarathonClient import create_app [as 别名]
class MarathonHTTPClient(AbstractSchedulerClient):
    def __init__(self, target, auth, options, pkey):
        super(MarathonHTTPClient, self).__init__(target, auth, options, pkey)
        self.target = settings.MARATHON_HOST
        self.registry = settings.REGISTRY_HOST + ":" + settings.REGISTRY_PORT
        self.client = MarathonClient("http://" + self.target + ":8180")
        self.fleet = FleetHTTPClient("/var/run/fleet.sock", auth, options, pkey)

    # helpers
    def _app_id(self, name):
        return name.replace("_", ".")

    # container api
    def create(self, name, image, command="", **kwargs):
        """Create a new container"""
        app_id = self._app_id(name)
        l = locals().copy()
        l.update(re.match(MATCH, name).groupdict())
        image = self.registry + "/" + image
        mems = kwargs.get("memory", {}).get(l["c_type"])
        m = 0
        if mems:
            mems = mems.lower()
            if mems[-2:-1].isalpha() and mems[-1].isalpha():
                mems = mems[:-1]
            m = int(mems[:-1])
        c = 0.5
        cpu = kwargs.get("cpu", {}).get(l["c_type"])
        if cpu:
            c = cpu
        cmd = "docker run --name {name} -P {image} {command}".format(**locals())
        self.client.create_app(app_id, MarathonApp(cmd=cmd, mem=m, cpus=c, instances=0))
        for _ in xrange(POLL_ATTEMPTS):
            if self.client.get_app(self._app_id(name)).tasks_running == 0:
                return
            time.sleep(1)

    def start(self, name):
        """Start a container."""
        self.client.scale_app(self._app_id(name), 1, force=True)
        for _ in xrange(POLL_ATTEMPTS):
            if self.client.get_app(self._app_id(name)).tasks_running == 1:
                break
            time.sleep(1)
        host = self.client.get_app(self._app_id(name)).tasks[0].host
        self._waitforcontainer(host, name)

    def destroy(self, name):
        """Destroy a container."""
        try:
            host = self.client.get_app(self._app_id(name)).tasks[0].host
            self.client.delete_app(self._app_id(name), force=True)
            self._delete_container(host, name)
        except:
            self.client.delete_app(self._app_id(name), force=True)

    def _get_container_state(self, host, name):
        docker_cli = Client("tcp://{}:2375".format(host), timeout=1200, version="1.17")
        try:
            if docker_cli.inspect_container(name)["State"]["Running"]:
                return JobState.up
        except:
            return JobState.destroyed

    def _waitforcontainer(self, host, name):
        for _ in xrange(POLL_WAIT):
            if self._get_container_state(host, name) == JobState.up:
                return
            time.sleep(1)
        raise RuntimeError("App container Not Started")

    def _delete_container(self, host, name):
        docker_cli = Client("tcp://{}:2375".format(host), timeout=1200, version="1.17")
        if docker_cli.inspect_container(name)["State"]:
            docker_cli.remove_container(name, force=True)

    def run(self, name, image, entrypoint, command):  # noqa
        """Run a one-off command."""
        return self.fleet.run(name, image, entrypoint, command)

    def state(self, name):
        """Display the given job's running state."""
        try:
            for _ in xrange(POLL_ATTEMPTS):
                if self.client.get_app(self._app_id(name)).tasks_running == 1:
                    return JobState.up
                elif self.client.get_app(self._app_id(name)).tasks_running == 0:
                    return JobState.created
                time.sleep(1)
        except:
            return JobState.destroyed
开发者ID:ngpestelos,项目名称:deis,代码行数:93,代码来源:mesos_marathon.py

示例14: HealthCheckBencher

# 需要导入模块: from marathon import MarathonClient [as 别名]
# 或者: from marathon.MarathonClient import create_app [as 别名]
class HealthCheckBencher(object):
    def __init__(self, marathon_url, image, tasks):
        self.concurrency = 20
        self.docker_image = image
        self.app_base_name = 'health-check-test-'
        self.total_tasks_cout = int(tasks)
        self.instances_per_app = 50
        if tasks < self.instances_per_app:
            self.instances_per_app = self.total_tasks_cout
            self.app_count = 1
        else:
            self.app_count = self.total_tasks_cout/self.instances_per_app
        self.heath_check_interval = 30
        self.test_duration = 20
        self.marathon_cluster = MarathonClient(marathon_url, timeout=240)
        self.work_queue = Queue()
        self.result_queue = Queue()
        self.app_list_queue = Queue()
        self.action_list = [self.start_collect,
                            'sleep={}'.format(self.test_duration),
                            self.get_stats]

    def remove_apps(self):
        apps = self.marathon_cluster.list_apps()
        for app in apps:
            if app.id.startswith("/"+self.app_base_name):
                self.marathon_cluster.delete_app(app.id)
        active = 0
        while True:
            apps = self.marathon_cluster.list_apps()
            for app in apps:
                if app.id.startswith(self.app_base_name):
                    active += 1
            if active == 0:
                break

    def create_app(self, id):
        port_mapping = MarathonContainerPortMapping(container_port=80,
                                                    protocol="tcp")
        app_docker = MarathonDockerContainer(
            image=self.docker_image,
            network="BRIDGE",
            force_pull_image=True,
            port_mappings=[port_mapping])
        app_container = MarathonContainer(docker=app_docker)
        http_health_check = MarathonHealthCheck(
            protocol="HTTP",
            path="/status",
            grace_period_seconds=300,
            interval_seconds=self.heath_check_interval,
            timeout_seconds=20,
            max_consecutive_failures=0
        )

        app_suffix = str(md5(str(random())).hexdigest())
        app_name = self.app_base_name + app_suffix
        new_app = MarathonApp(cpus=CPUS, mem=MEM, disk=DISK,
                              container=app_container,
                              health_checks=[http_health_check],
                              instances=self.instances_per_app,
                              max_launch_delay_seconds=5)
        print("Creating {}".format(app_name))
        self.marathon_cluster.create_app(app_id=app_name, app=new_app)
        self.app_list_queue.put(app_name)
        return None

    def wait_instances(self, app_name):
        health_ok = 0
        while health_ok < self.instances_per_app:
            health_ok = 0
            tasks = self.marathon_cluster.list_tasks(app_name)
            for task in tasks:
                if task.health_check_results:
                    health_ok += 1

    def start_collect(self, task):
        url = 'http://'+task['host']+':'+str(task['port'])+'/start_collect'
        res = urlopen(url)
        if res.getcode() == 200:
            print(task['id']+': collecter was started')
        else:
            print(task['id']+': failed to start collecter')

    def stop_collect(self, task):
        url = 'http://'+task['host']+':'+str(task['port'])+'/stop_collect'
        res = urlopen(url)
        if res.getcode() == 200:
            print(task['id']+': collecter was stopped')
        else:
            print(task['id']+': failed to stop collecter')

    def clear_stats(self, task):
        url = 'http://'+task['host']+':'+str(task['port'])+'/clear_stats'
        res = urlopen(url)
        if res.getcode() == 200:
            print(task['id']+': stats was dropped')
        else:
            print(task['id']+': stats was dropped')

    def get_stats(self, task):
#.........这里部分代码省略.........
开发者ID:openstack,项目名称:performance-docs,代码行数:103,代码来源:HealthCheckBencher.py

示例15: OptionParser

# 需要导入模块: from marathon import MarathonClient [as 别名]
# 或者: from marathon.MarathonClient import create_app [as 别名]
import time
from optparse import OptionParser
from marathon import MarathonClient
from marathon.models import MarathonApp

if __name__ == '__main__':
    usage = ('python %prog')
    parser = OptionParser(description='Simple marathon-python based master to launch apps',
                          version="0.1 ", usage=usage)
    (options, args) = parser.parse_args()
    if (len(args) != 0):
        parser.print_help()
        sys.exit(2)


    print "Initiating marathonclient..."
    c = MarathonClient('http://localhost:8080')
    app_cmd = "python /home/abdullah/cosmic-space/test-mesos/py-zmq/sub_client.py --server_ip_ports 10.10.0.2:5556"

    # launch app
    print "Initiating zmq-client app"
    c.create_app('zmq-client', MarathonApp(cmd=app_cmd, mem=16, cpus=0.01))

    # scale
    raw_input("scale_apps upto 400")
    c.scale_app('zmq-client', instances=400)

    # delete
    raw_input("delete apps")
    c.delete_app('zmq-client')
开发者ID:kratos7,项目名称:cosmic-space,代码行数:32,代码来源:marathon_zmq_master.py


注:本文中的marathon.MarathonClient.create_app方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。