Beispiel #1
0
    def test_add_env_non_empty_dict(self):
        env_data = {"OTHER_ENV": "other-value"}
        app = MarathonApp(env=env_data)

        app.add_env("MY_ENV", "my-value")
        self.assertDictEqual({
            "MY_ENV": "my-value",
            "OTHER_ENV": "other-value"
        }, app.env)
    def test_creating_app_forcepull_not_checked(self, single_full_app_fixture):
        original_app = MarathonApp()
        request_app = MarathonApp.from_json(single_full_app_fixture)
        request_app.container.docker.force_pull_image = True

        modified_request_app = self.filter.write(user=None,
                                                 request_app=request_app,
                                                 app=original_app)
        self.assertTrue(modified_request_app.container.docker.force_pull_image,
                        True)
    def test_empty_request_app(self, single_full_app_fixture):
        """
        Isso acontece quando é um request de restart, por exemplo, onde o body do request é vazio.
        """
        original_app = MarathonApp.from_json(single_full_app_fixture)
        request_app = MarathonApp()

        modified_request_app = self.filter.write(user=None,
                                                 request_app=request_app,
                                                 app=original_app)
        self.assertTrue(request_app is modified_request_app)
Beispiel #4
0
    def start(self):
        # First make a quick call to determine if user info was updated
        self.update_users()
        # Go on to start the notebook
        docker_container = MarathonDockerContainer(
            image=self.app_image,
            network=self.network_mode,
            port_mappings=self.get_port_mappings())

        app_container = MarathonContainer(docker=docker_container,
                                          type='DOCKER',
                                          volumes=self.get_volumes())

        # the memory request in marathon is in MiB
        if hasattr(self, 'mem_limit') and self.mem_limit is not None:
            mem_request = self.mem_limit / 1024.0 / 1024.0
        else:
            mem_request = 1024.0

        if self.user_ssh_hagroup != "":
            myports = [self.user_ssh_port]
            labels = {
                "HAPROXY_GROUP": self.user_ssh_hagroup,
                "HA_EDGE_CONF": "1"
            }
        else:
            labels = {}
            myports = []

        app_request = MarathonApp(
            id=self.container_name,
            cmd=self.get_app_cmd(),
            env=self.get_env(),
            cpus=self.cpu_limit,
            mem=mem_request,
            container=app_container,
            constraints=self.get_constraints(),
            health_checks=self.get_health_checks(),
            instances=1,
            labels=labels,
            ports=myports,
            fetch=self.fetch,
        )

        app = self.marathon.create_app(self.container_name, app_request)
        if app is False or app.deployments is None:
            self.log.error("Failed to create application for %s",
                           self.container_name)
            return None

        while True:
            app_info = yield self.get_app_info(self.container_name)
            if app_info and app_info.tasks_healthy == 1:
                ip, port = self.get_ip_and_port(app_info)
                break
            yield gen.sleep(1)
        return (ip, port)
    def start(self):
        docker_container = MarathonDockerContainer(
            image=self.app_image,
            network=self.network_mode,
            port_mappings=self.get_port_mappings())

        app_container = MarathonContainer(docker=docker_container,
                                          type='DOCKER',
                                          volumes=self.get_volumes())

        # the memory request in marathon is in MiB
        if hasattr(self, 'mem_limit') and self.mem_limit is not None:
            mem_request = self.mem_limit / 1024.0 / 1024.0
        else:
            mem_request = 1024.0

        cmd = self.cmd + self.get_args()
        app_request = MarathonApp(id=self.container_name,
                                  cmd=' '.join(cmd),
                                  env=self.get_env(),
                                  cpus=self.cpu_limit,
                                  mem=mem_request,
                                  container=app_container,
                                  constraints=self.get_constraints(),
                                  health_checks=self.get_health_checks(),
                                  instances=1,
                                  accepted_resource_roles=['*'])

        self.log.info("Creating App: %s", app_request)
        self.log.info("self.marathon: %s", self.marathon)
        app = self.marathon.create_app(self.container_name, app_request)
        if app is False or app.deployments is None:
            self.log.error("Failed to create application for %s",
                           self.container_name)
            self.log.error("app: %s", app)
            return None

        while True:
            app_info = yield self.get_app_info(self.container_name)
            if app_info and app_info.tasks_healthy == 1:
                ip, port = self.get_ip_and_port(app_info)
                break
            yield gen.sleep(1)
        return (ip, port)
 def stop(self, now=False):
     try:
         self.marathon.update_app(self.app_id,
                                  MarathonApp(instances=0),
                                  force=True)
     except Exception as e:
         self.log.error("Failed to delete application %s", self.app_id)
         raise e
     else:
         if not now:
             while True:
                 app_info = yield self.get_app_info(self.app_id)
                 if app_info is None:
                     # Stopping application is lost, just ignore it!
                     break
                 elif len(app_info.deployments) == 0:
                     # This is the success case.
                     break
                 yield gen.sleep(1)
Beispiel #7
0
    def start(self):
        docker_container = MarathonDockerContainer(
            image=self.app_image, network=self.network_mode
        )  #,port_mappings=self.get_port_mappings())

        app_container = MarathonContainer(docker=docker_container,
                                          type='DOCKER',
                                          volumes=self.get_volumes())

        # the memory request in marathon is in MiB
        if hasattr(self, 'mem_limit') and self.mem_limit is not None:
            mem_request = self.mem_limit / 1024.0 / 1024.0
        else:
            mem_request = 1024.0

        app_request = MarathonApp(id=self.container_name,
                                  env=self.get_env(),
                                  cpus=self.cpu_limit,
                                  mem=mem_request,
                                  container=app_container,
                                  constraints=self.get_constraints(),
                                  health_checks=self.get_health_checks(),
                                  instances=1,
                                  ports=[0])

        app = self.marathon.create_app(self.container_name, app_request)
        if app is False or app.deployments is None:
            self.log.error("Failed to create application for %s",
                           self.container_name)
            return None

        while True:
            app_info = yield self.get_app_info(self.container_name)
            self.state = app_info.tasks[0].state
            if app_info and app_info.tasks_healthy == 1:
                ip, port = self.get_ip_and_port(app_info)
                self.user.server.ip = ip
                self.user.server.port = port
                break
            yield gen.sleep(1)
        return (ip, port)
Beispiel #8
0
def _app_get(role=None, **kwargs):  # pylint: disable=W0142
    """
    Return Marathon app object
    """
    defaults = {
        'args': __salt__['appc.lxc_start_command'](role=role),
        'backoff_factor': None,
        'backoff_seconds': None,
        'cmd': None,
        'constraints': None,
        'container': _app_container_get(role=role, type='docker'),
        'cpus': None,
        'dependencies': None,
        'deployments': None,
        'disk': None,
        'env': __salt__['appc.lxc_config_environment'](role=role),
        'executor': None,
        'health_checks': None,
        'id': '/{0}'.format(role),
        'instances': None,
        'last_task_failure': None,
        'mem': None,
        'ports': None,
        'require_ports': None,
        'store_urls': None,
        'task_rate_limit': None,
        'tasks': None,
        'tasks_running': None,
        'tasks_staged': None,
        'upgrade_strategy': None,
        'uris': None,
        'user': None,
        'version': None,
    }
    kwargs = dict((k, kwargs.get(k) or defaults.get(k)) for k in defaults)

    return MarathonApp(**kwargs)  # pylint: disable=W0142
Beispiel #9
0
 def test_env_defaults_to_empty_dict(self):
     """
     é testé
     """
     app = MarathonApp()
     self.assertEquals(app.env, {})
Beispiel #10
0
 def test_add_env_empty_dict(self):
     app = MarathonApp()
     app.add_env("MY_ENV", "my-value")
     self.assertDictEqual({"MY_ENV": "my-value"}, app.env)
 def setUp(self, single_full_app_fixture):
     self.single_full_app_fixture = single_full_app_fixture
     self.original_app = MarathonApp.from_json(self.single_full_app_fixture)
     self.request_app = MarathonApp.from_json(single_full_app_fixture)
     self.filter = AddAppNameFilter()
     self.user = mock.MagicMock()
    def start(self):
        app_image = self.user_options.get('app_image', None) or self.app_image
        force_pull_image = self.user_options.get('force_pull_image', False)
        self.log.info("starting a Marathon app with image=%s" % app_image)

        container_params = {
            'image': app_image,
            'force_pull_image': force_pull_image
        }
        docker_container = MarathonDockerContainer(**container_params)

        app_container = MarathonContainer(docker=docker_container,
                                          type='MESOS',
                                          volumes=self.get_volumes())

        cpu = self.user_options.get('cpu', None)
        mem = self.user_options.get('mem', None)
        disk = self.user_options.get('disk', None)
        gpu = self.user_options.get('gpu', None)
        self.log.info("resource: (cpu=%s, mem=%s, disk=%s, gpu=%s)" %
                      (cpu, mem, disk, gpu))

        cmd = self.cmd + self.get_args()
        env = self.get_env()

        port_definitions = [PortDefinition(port=0, protocol='tcp')]

        app_request = MarathonApp(
            id=self.app_id,
            cmd=' '.join(
                cmd),  # cmd does not use Docker image's default entrypoint
            env=env,
            cpus=cpu,
            mem=mem,
            disk=disk,
            gpus=gpu,
            user=self.mesos_user,
            container=app_container,
            port_definitions=port_definitions,
            networks=[{
                'mode': 'host'
            }],
            constraints=self.get_constraints(),
            health_checks=self.get_health_checks(),
            unreachable_strategy=self.unreachable_strategy,
            instances=1)

        app_info = self.get_app_info(self.app_id)
        try:
            if app_info:
                self.marathon.update_app(self.app_id, app_request, force=True)
            else:
                self.marathon.create_app(self.app_id, app_request)
        except Exception as e:
            self.log.error("Failed to create application for %s: %s",
                           self.app_id, e)
            raise e

        while True:
            app_info = yield self.get_app_info(self.app_id)
            if app_info is None:
                raise MarathonSpawnerException("Application %s is lost",
                                               self.app_id)
            elif app_info.instances == 0:
                raise MarathonSpawnerException(
                    "No instance for application %s", self.app_id)
            elif app_info.tasks_healthy == 1:
                ip, port = self.get_ip_and_port(app_info)
                break
            yield gen.sleep(1)
        return (ip, port)