Exemplo n.º 1
0
    def stop_deployment(self):
        log.info('Job started for {}.'.format(self.deployment_id))

        self.job.set_progress(10)

        try:
            if Deployment.is_component(self.deployment):
                self.stop_component()
            elif Deployment.is_application(self.deployment):
                self.stop_application()
            elif Deployment.is_application_kubernetes(self.deployment):
                self.stop_application_kubernetes()
        except Exception as ex:
            log.error('Failed to {0} {1}: {2}'.format(self.job['action'],
                                                      self.deployment_id, ex))
            try:
                self.job.set_status_message(repr(ex))
                self.api_dpl.set_state_error(self.deployment_id)
            except Exception as ex_state:
                log.error('Failed to set error state for {0}: {1}'.format(
                    self.deployment_id, ex_state))

            raise ex

        self.try_delete_deployment_credentials(self.deployment_id)

        self.api_dpl.set_state_stopped(self.deployment_id)

        return 0
Exemplo n.º 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'
Exemplo n.º 3
0
    def handle_deployment(self, deployment: dict):

        if Deployment.is_component(deployment):
            self.start_component(deployment)
        elif Deployment.is_application(deployment):
            self.start_application(deployment)
        elif Deployment.is_application_kubernetes(deployment):
            self.start_application_kubernetes(deployment)

        self.create_user_output_params(deployment)
Exemplo n.º 4
0
def push_state(deployment):
    try:
        if Deployment.is_component(nuvla_deployment):
            ds.get_component_state(nuvla_deployment)
        elif Deployment.is_application(nuvla_deployment):
            ds.get_application_state(nuvla_deployment)
        elif Deployment.is_application_kubernetes(nuvla_deployment):
            ds.get_application_kubernetes_state(nuvla_deployment)
    except Exception as ex:
        logging.exception('Failed to get deployment state for {}: {}'.format(Deployment.id(deployment), ex))
        pass
Exemplo n.º 5
0
    def do_work(self):
        log.info('Job started for {}.'.format(self.deployment_id))
        self.job.set_progress(10)

        try:
            if Deployment.is_component(self.deployment):
                self.get_component_state()
            elif Deployment.is_application(self.deployment):
                self.get_application_state()
            elif Deployment.is_application_kubernetes(self.deployment):
                self.get_application_kubernetes_state()
        except Exception as ex:
            log.error('Failed to {0} {1}: {2}'.format(self.job['action'], self.deployment_id, ex))
            self.job.set_status_message(repr(ex))
            raise ex

        return 0
Exemplo n.º 6
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)