예제 #1
0
    def start_application(self, deployment: dict):
        deployment_id = Deployment.id(deployment)

        if Deployment.is_compatibility_docker_compose(deployment):
            connector = initialize_connector(docker_compose_cli_connector,
                                             self.job, deployment)
        else:
            connector = initialize_connector(docker_cli_connector, self.job,
                                             deployment)

        module_content = Deployment.module_content(deployment)
        deployment_owner = Deployment.owner(deployment)
        docker_compose = module_content['docker-compose']
        registries_auth = self.private_registries_auth(deployment)

        result, services = connector.start(
            docker_compose=docker_compose,
            stack_name=Deployment.uuid(deployment),
            env=get_env(deployment),
            files=module_content.get('files'),
            registries_auth=registries_auth)
        self.job.set_status_message(result)

        self.create_deployment_parameter(
            deployment_id=deployment_id,
            user_id=deployment_owner,
            param_name=DeploymentParameter.HOSTNAME['name'],
            param_value=self.get_hostname(),
            param_description=DeploymentParameter.HOSTNAME['description'])

        application_params_update(self.api_dpl, deployment, services)
예제 #2
0
 def get_connector_name(deployment):
     if Deployment.is_component(deployment):
         return 'docker_service'
     elif Deployment.is_application(deployment):
         is_compose = Deployment.is_compatibility_docker_compose(deployment)
         return 'docker_compose' if is_compose else 'docker_stack'
     elif Deployment.is_application_kubernetes(deployment):
         return 'kubernetes'
예제 #3
0
    def stop_application(self):
        if Deployment.is_compatibility_docker_compose(self.deployment):
            connector = initialize_connector(docker_compose_cli_connector,
                                             self.job, self.deployment)
        else:
            connector = initialize_connector(docker_cli_connector, self.job,
                                             self.deployment)

        result = connector.stop(stack_name=Deployment.uuid(self.deployment),
                                docker_compose=Deployment.module_content(
                                    self.deployment)['docker-compose'])

        self.job.set_status_message(result)
예제 #4
0
    def get_application_state(self):
        stack_name = Deployment.uuid(self.deployment)

        if Deployment.is_compatibility_docker_compose(self.deployment):
            module_content = Deployment.module_content(self.deployment)
            compose_file   = module_content['docker-compose']
            connector      = initialize_connector(docker_compose_cli_connector, self.job, self.deployment)
            services       = connector.stack_services(stack_name, compose_file)
        else:
            connector = initialize_connector(docker_cli_connector, self.job, self.deployment)
            services  = connector.stack_services(stack_name)

        application_params_update(self.api_dpl, self.deployment, services)
예제 #5
0
    def fetch_log(self, deployment_log):

        service_name = deployment_log['service']

        last_timestamp = deployment_log.get('last-timestamp')

        since = deployment_log.get('since')

        lines = deployment_log.get('lines', 200)

        deployment_id = deployment_log['parent']

        deployment = self.api_dpl.get(deployment_id)

        deployment_uuid = Deployment.uuid(deployment)

        tmp_since = last_timestamp or since

        if Deployment.is_application_kubernetes(deployment):
            connector = initialize_connector(kubernetes_cli_connector,
                                             self.job, deployment)
            since_opt = ['--since-time', tmp_since] if tmp_since else []
            list_opts = [
                service_name, '--timestamps=true', '--tail',
                str(lines), '--namespace', deployment_uuid
            ] + since_opt
        else:
            is_docker_compose = Deployment.is_compatibility_docker_compose(
                deployment)

            if is_docker_compose:
                connector = initialize_connector(docker_compose_cli_connector,
                                                 self.job, deployment)
                no_trunc = []
            else:
                connector = initialize_connector(docker_cli_connector,
                                                 self.job, deployment)
                no_trunc = ['--no-trunc']

            if Deployment.is_application(deployment):
                if is_docker_compose:
                    log.info(deployment_id)
                    log.info(service_name)

                    docker_service_name = self.api_dpl.get_parameter(
                        deployment_id, service_name,
                        service_name + '.service-id')
                else:
                    docker_service_name = deployment_uuid + '_' + service_name
            else:
                docker_service_name = deployment_uuid

            since_opt = ['--since', tmp_since] if tmp_since else []

            list_opts = ['-t'] + no_trunc + since_opt + [docker_service_name]

        result = connector.log(list_opts).strip().split('\n')[:lines]

        new_last_timestamp = DeploymentLogFetchJob.extract_last_timestamp(
            result)

        update_deployment_log = {'log': result}

        if new_last_timestamp:
            update_deployment_log['last-timestamp'] = new_last_timestamp

        self.api.edit(deployment_log['id'], update_deployment_log)