Beispiel #1
0
    def launch(self,
               command_line,
               dependencies_description=None,
               env=[],
               remote_staging=[],
               job_config=None,
               container_info=None,
               pulsar_app_config=None):
        """
        """
        launch_params = self._build_setup_message(
            command_line,
            dependencies_description=dependencies_description,
            env=env,
            remote_staging=remote_staging,
            job_config=job_config,
        )
        container = None
        guest_ports = None
        if container_info is not None:
            container = container_info.get("container_id")
            guest_ports = container_info.get("guest_ports")

        manager_type = "coexecution" if container is not None else "unqueued"
        if "manager" not in pulsar_app_config and "managers" not in pulsar_app_config:
            pulsar_app_config["manager"] = {"type": manager_type}

        using_dependencies = container is None and dependencies_description is not None
        if using_dependencies and "dependency_resolution" not in pulsar_app_config:
            # Setup default dependency resolution for container above...
            dependency_resolution = {
                "cache": False,
                "use": True,
                "default_base_path": "/pulsar_dependencies",
                "cache_dir": "/pulsar_dependencies/_cache",
                "resolvers": [{  # TODO: add CVMFS resolution...
                    "type": "conda",
                    "auto_init": True,
                    "auto_install": True,
                    "prefix": '/pulsar_dependencies/conda',
                }, {
                    "type": "conda",
                    "auto_init": True,
                    "auto_install": True,
                    "prefix": '/pulsar_dependencies/conda',
                    "versionless": True,
                }]
            }
            pulsar_app_config["dependency_resolution"] = dependency_resolution
        base64_message = to_base64_json(launch_params)
        base64_app_conf = to_base64_json(pulsar_app_config)

        job_name = self._k8s_job_name
        params = self.destination_params

        pulsar_container_image = self.pulsar_container_image

        job_directory = self.job_directory

        volumes = [
            {
                "name": "staging-directory",
                "emptyDir": {}
            },
        ]
        volume_mounts = [
            {
                "mountPath": "/pulsar_staging",
                "name": "staging-directory"
            },
        ]
        pulsar_container_dict = {
            "name":
            "pulsar-container",
            "image":
            pulsar_container_image,
            "command": ["pulsar-submit"],
            "args":
            ["--base64", base64_message, "--app_conf_base64", base64_app_conf],
            "workingDir":
            "/",
            "volumeMounts":
            volume_mounts,
        }
        tool_container_image = container
        container_dicts = [pulsar_container_dict]
        if container:
            command = TOOL_EXECUTION_CONTAINER_COMMAND_TEMPLATE % job_directory.job_directory
            tool_container_spec = {
                "name": "tool-container",
                "image": tool_container_image,
                "command": ["sh"],
                "args": ["-c", command],
                "workingDir": "/",
                "volumeMounts": volume_mounts,
            }
            if guest_ports:
                tool_container_spec["ports"] = [{
                    "containerPort": int(p)
                } for p in guest_ports]
            container_dicts.append(tool_container_spec)
        for container_dict in container_dicts:
            if self._default_pull_policy:
                container_dict["imagePullPolicy"] = self._default_pull_policy

        template = {
            "metadata": {
                "labels": {
                    "app": job_name
                },
            },
            "spec": {
                "volumes": volumes,
                "restartPolicy": "Never",
                "containers": container_dicts,
            }
        }
        spec = {"template": template}
        k8s_job_obj = job_object_dict(params, job_name, spec)
        pykube_client = self._pykube_client
        job = Job(pykube_client, k8s_job_obj)
        job.create()
Beispiel #2
0
    def launch(self,
               command_line,
               dependencies_description=None,
               env=[],
               remote_staging=[],
               job_config=None,
               container=None,
               pulsar_app_config=None):
        """
        """
        launch_params = self._build_setup_message(
            command_line,
            dependencies_description=dependencies_description,
            env=env,
            remote_staging=remote_staging,
            job_config=job_config,
        )
        base64_message = to_base64_json(launch_params)
        base64_app_conf = to_base64_json(pulsar_app_config)

        # TODO: instance_id for Pulsar...
        job_name = produce_unique_k8s_job_name(app_prefix="pulsar")
        params = self.destination_params

        pulsar_container_image = self.pulsar_container_image

        job_directory = self.job_directory

        volumes = [
            {
                "name": "staging-directory",
                "emptyDir": {}
            },
        ]
        volume_mounts = [
            {
                "mountPath": "/pulsar_staging",
                "name": "staging-directory"
            },
        ]
        tool_container_image = container  # TODO: this isn't right at all...
        if not container:
            raise Exception(
                "Must declare a container for kubernetes job execution.")
        pulsar_container_dict = {
            "name":
            "pulsar-container",
            "image":
            pulsar_container_image,
            "command": ["pulsar-submit"],
            "args":
            ["--base64", base64_message, "--app_conf_base64", base64_app_conf],
            "workingDir":
            "/",
            "volumeMounts":
            volume_mounts,
        }
        command = TOOL_EXECUTION_CONTAINER_COMMAND_TEMPLATE % job_directory.job_directory
        tool_container_spec = {
            "name": "tool-container",
            "image": tool_container_image,
            "command": ["sh"],
            "args": ["-c", command],
            "workingDir": "/",
            "volumeMounts": volume_mounts,
        }

        container_dicts = [pulsar_container_dict, tool_container_spec]
        for container_dict in container_dicts:
            if self._default_pull_policy:
                container_dict["imagePullPolicy"] = self._default_pull_policy

        template = {
            "metadata": {
                "labels": {
                    "app": job_name
                },
            },
            "spec": {
                "volumes": volumes,
                "restartPolicy": "Never",
                "containers": container_dicts,
            }
        }
        spec = {"template": template}
        k8s_job_obj = job_object_dict(params, job_name, spec)
        pykube_client = pykube_client_from_dict(self.destination_params)
        job = Job(pykube_client, k8s_job_obj)
        job.create()
Beispiel #3
0
    def launch(  # noqa: C901
            self,
            command_line,
            dependencies_description=None,
            env=[],
            remote_staging=[],
            job_config=None,
            container_info=None,
            pulsar_app_config=None):
        """
        """
        launch_params = self._build_setup_message(
            command_line,
            dependencies_description=dependencies_description,
            env=env,
            remote_staging=remote_staging,
            job_config=job_config,
        )
        container = None
        guest_ports = None
        if container_info is not None:
            container = container_info.get("container_id")
            guest_ports = container_info.get("guest_ports")

        manager_name = self.client_manager.manager_name
        manager_type = "coexecution" if container is not None else "unqueued"
        if "manager" not in pulsar_app_config and "managers" not in pulsar_app_config:
            pulsar_app_config["managers"] = {
                manager_name: {
                    "type": manager_type
                }
            }
        elif "manager" in pulsar_app_config and manager_name != '_default_':
            log.warning(
                "'manager' set in app config but client has non-default manager '%s', this will cause communication"
                " failures, remove `manager` from app or client config to fix",
                manager_name)

        manager_args = []
        if manager_name != "_default_":
            manager_args = ["--manager", manager_name]

        using_dependencies = container is None and dependencies_description is not None
        if using_dependencies and "dependency_resolution" not in pulsar_app_config:
            # Setup default dependency resolution for container above...
            dependency_resolution = {
                "cache": False,
                "use": True,
                "default_base_path": "/pulsar_dependencies",
                "cache_dir": "/pulsar_dependencies/_cache",
                "resolvers": [{  # TODO: add CVMFS resolution...
                    "type": "conda",
                    "auto_init": True,
                    "auto_install": True,
                    "prefix": '/pulsar_dependencies/conda',
                }, {
                    "type": "conda",
                    "auto_init": True,
                    "auto_install": True,
                    "prefix": '/pulsar_dependencies/conda',
                    "versionless": True,
                }]
            }
            pulsar_app_config["dependency_resolution"] = dependency_resolution
        base64_message = to_base64_json(launch_params)
        base64_app_conf = to_base64_json(pulsar_app_config)

        job_name = self._k8s_job_name
        params = self.destination_params

        pulsar_container_image = self.pulsar_container_image
        pulsar_container_resources = self._pulsar_container_resources(params)

        job_directory = self.job_directory

        volumes = [
            {
                "name": "staging-directory",
                "emptyDir": {}
            },
        ]
        volume_mounts = [
            {
                "mountPath": "/pulsar_staging",
                "name": "staging-directory"
            },
        ]
        pulsar_container_dict = {
            "name":
            "pulsar-container",
            "image":
            pulsar_container_image,
            "command": ["pulsar-submit"],
            "args":
            ["--base64", base64_message, "--app_conf_base64", base64_app_conf
             ] + manager_args,
            "workingDir":
            "/",
            "volumeMounts":
            volume_mounts,
        }
        if pulsar_container_resources:
            pulsar_container_dict["resources"] = pulsar_container_resources
        tool_container_image = container
        tool_container_resources = self._tool_container_resources(params)
        container_dicts = [pulsar_container_dict]
        if container:
            command = TOOL_EXECUTION_CONTAINER_COMMAND_TEMPLATE % job_directory.job_directory
            tool_container_spec = {
                "name": "tool-container",
                "image": tool_container_image,
                "command": ["sh"],
                "args": ["-c", command],
                "workingDir": "/",
                "volumeMounts": volume_mounts,
            }
            if tool_container_resources:
                tool_container_spec["resources"] = tool_container_resources
            if guest_ports:
                tool_container_spec["ports"] = [{
                    "containerPort": int(p)
                } for p in guest_ports]
            container_dicts.append(tool_container_spec)
        for container_dict in container_dicts:
            if self._default_pull_policy:
                container_dict["imagePullPolicy"] = self._default_pull_policy

        template = {
            "metadata": {
                "labels": {
                    "app": job_name
                },
            },
            "spec": {
                "volumes": volumes,
                "restartPolicy": "Never",
                "containers": container_dicts,
            }
        }
        spec = {"template": template}
        if "k8s_walltime_limit" in params:
            spec["activeDeadlineSeconds"] = int(params["k8s_walltime_limit"])
        k8s_job_obj = job_object_dict(params, job_name, spec)
        pykube_client = self._pykube_client
        job = Job(pykube_client, k8s_job_obj)
        job.create()
Beispiel #4
0
    def launch(self, command_line, dependencies_description=None, env=[], remote_staging=[], job_config=None, container=None, pulsar_app_config=None):
        """
        """
        launch_params = self._build_setup_message(
            command_line,
            dependencies_description=dependencies_description,
            env=env,
            remote_staging=remote_staging,
            job_config=job_config,
        )
        base64_message = to_base64_json(launch_params)
        base64_app_conf = to_base64_json(pulsar_app_config)

        # TODO: instance_id for Pulsar...
        job_name = produce_unique_k8s_job_name(app_prefix="pulsar")
        params = self.destination_params

        pulsar_container_image = self.pulsar_container_image

        job_directory = self.job_directory

        volumes = [
            {"name": "staging-directory", "emptyDir": {}},
        ]
        volume_mounts = [
            {"mountPath": "/pulsar_staging", "name": "staging-directory"},
        ]
        tool_container_image = container  # TODO: this isn't right at all...
        if not container:
            raise Exception("Must declare a container for kubernetes job execution.")
        pulsar_container_dict = {
            "name": "pulsar-container",
            "image": pulsar_container_image,
            "command": ["pulsar-submit"],
            "args": ["--base64", base64_message, "--app_conf_base64", base64_app_conf],
            "workingDir": "/",
            "volumeMounts": volume_mounts,
        }
        command = TOOL_EXECUTION_CONTAINER_COMMAND_TEMPLATE % job_directory.job_directory
        tool_container_spec = {
            "name": "tool-container",
            "image": tool_container_image,
            "command": ["sh"],
            "args": ["-c", command],
            "workingDir": "/",
            "volumeMounts": volume_mounts,
        }

        container_dicts = [pulsar_container_dict, tool_container_spec]
        for container_dict in container_dicts:
            if self._default_pull_policy:
                container_dict["imagePullPolicy"] = self._default_pull_policy

        template = {
            "metadata": {
                "labels": {"app": job_name},
            },
            "spec": {
                "volumes": volumes,
                "restartPolicy": "Never",
                "containers": container_dicts,
            }
        }
        spec = {"template": template}
        k8s_job_obj = job_object_dict(params, job_name, spec)
        pykube_client = pykube_client_from_dict(self.destination_params)
        job = Job(pykube_client, k8s_job_obj)
        job.create()