Exemplo n.º 1
0
    def start_application_kubernetes(self, deployment: dict):
        deployment_id = Deployment.id(deployment)

        connector = initialize_connector(kubernetes_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)
Exemplo n.º 2
0
 def create_user_output_params(self, deployment):
     module_content = Deployment.module_content(deployment)
     for output_param in module_content.get('output-parameters', []):
         self.create_deployment_parameter(
             deployment_id=Deployment.id(deployment),
             user_id=Deployment.owner(deployment),
             param_name=output_param['name'],
             param_description=output_param.get('description'))
Exemplo n.º 3
0
def application_params_update(api_dpl, deployment, services):
    if services:
        for service in services:
            node_id = service['node-id']
            for key, value in service.items():
                api_dpl.set_parameter_create_if_needed(
                    Deployment.id(deployment),
                    Deployment.owner(deployment),
                    f'{node_id}.{key}',
                    param_value=value,
                    node_id=node_id)
Exemplo n.º 4
0
    def start_component(self, deployment: dict):
        connector = initialize_connector(docker_connector, self.job,
                                         deployment)

        deployment_id = Deployment.id(deployment)
        node_instance_name = Deployment.uuid(deployment)
        deployment_owner = Deployment.owner(deployment)
        module_content = Deployment.module_content(deployment)

        restart_policy = module_content.get('restart-policy', {})

        # create deployment parameters (with empty values) for all port mappings
        module_ports = module_content.get('ports')
        for port in (module_ports or []):
            target_port = port.get('target-port')
            protocol = port.get('protocol', 'tcp')
            if target_port is not None:
                self.create_deployment_parameter(
                    deployment_id=deployment_id,
                    user_id=deployment_owner,
                    param_name="{}.{}".format(protocol, str(target_port)),
                    param_description="mapping for {} port {}".format(
                        protocol, str(target_port)),
                    node_id=node_instance_name)

        registries_auth = self.private_registries_auth(deployment)

        _, service = connector.start(
            service_name=node_instance_name,
            image=module_content['image'],
            env=get_env(deployment),
            mounts_opt=module_content.get('mounts'),
            ports_opt=module_ports,
            cpu_ratio=module_content.get('cpus'),
            memory=module_content.get('memory'),
            restart_policy_condition=restart_policy.get('condition'),
            restart_policy_delay=restart_policy.get('delay'),
            restart_policy_max_attempts=restart_policy.get('max-attempts'),
            restart_policy_window=restart_policy.get('window'),
            registry_auth=registries_auth[0] if registries_auth else None)

        # FIXME: get number of desired replicas of Replicated service from deployment. 1 for now.
        desired = 1

        deployment_parameters = (
            (DeploymentParameter.SERVICE_ID, connector.extract_vm_id(service)),
            (DeploymentParameter.HOSTNAME, self.get_hostname()),
            (DeploymentParameter.REPLICAS_DESIRED, str(desired)),
            (DeploymentParameter.REPLICAS_RUNNING, '0'),
            (DeploymentParameter.CURRENT_DESIRED, ''),
            (DeploymentParameter.CURRENT_STATE, ''),
            (DeploymentParameter.CURRENT_ERROR, ''),
            (DeploymentParameter.RESTART_EXIT_CODE, ''),
            (DeploymentParameter.RESTART_ERR_MSG, ''),
            (DeploymentParameter.RESTART_TIMESTAMP, ''),
            (DeploymentParameter.RESTART_NUMBER, ''),
            (DeploymentParameter.CHECK_TIMESTAMP, ''),
        )

        for deployment_parameter, value in deployment_parameters:
            self.create_deployment_parameter(
                param_name=deployment_parameter['name'],
                param_value=value,
                param_description=deployment_parameter['description'],
                deployment_id=deployment_id,
                node_id=node_instance_name,
                user_id=deployment_owner)

        # immediately update any port mappings that are already available
        ports_mapping = connector.extract_vm_ports_mapping(service)
        self.api_dpl.update_port_parameters(deployment, ports_mapping)