Example #1
0
def describe(json_option, pipeline_path):
    """
    Display pipeline summary
    """

    click.echo()

    print_banner("Elyra Pipeline details")

    indent_length = 4
    blank_field = "Not Specified"
    blank_list = ["None Listed"]
    pipeline_keys = ["name", "description", "type", "version", "nodes", "file_dependencies", "component_dependencies"]
    iter_keys = {"file_dependencies", "component_dependencies"}

    pipeline_definition = _preprocess_pipeline(pipeline_path, runtime="local", runtime_config="local")

    primary_pipeline = PipelineDefinition(pipeline_definition=pipeline_definition).primary_pipeline

    describe_dict = OrderedDict()

    describe_dict["name"] = primary_pipeline.name
    describe_dict["description"] = primary_pipeline.get_property("description")
    describe_dict["type"] = primary_pipeline.type
    describe_dict["version"] = primary_pipeline.version
    describe_dict["nodes"] = len(primary_pipeline.nodes)
    describe_dict["file_dependencies"] = set()
    describe_dict["component_dependencies"] = set()
    for node in primary_pipeline.nodes:
        # collect information about file dependencies
        for dependency in node.get_component_parameter("dependencies", []):
            describe_dict["file_dependencies"].add(f"{dependency}")
        # collect information about component dependencies
        if node.component_source is not None:
            describe_dict["component_dependencies"].add(node.component_source)

    if not json_option:
        for key in pipeline_keys:
            readable_key = " ".join(key.title().split("_"))
            if key in iter_keys:
                click.echo(f"{readable_key}:")
                if describe_dict.get(key, set()) == set():
                    click.echo(f"{' ' * indent_length}{blank_list[0]}")
                else:
                    for item in describe_dict.get(key, blank_list):
                        click.echo(f"{' ' * indent_length}- {item}")
            else:
                click.echo(f"{readable_key}: {describe_dict.get(key, blank_field)}")
    else:
        for key in iter_keys:
            describe_dict[key] = list(describe_dict[key])
        for key in pipeline_keys:
            value = describe_dict.get(key)
            if value is None or (key in iter_keys and len(value) == 0):
                describe_dict.pop(key)
        click.echo(json.dumps(describe_dict, indent=indent_length))
Example #2
0
def describe(json_option, pipeline_path):
    """
    Display pipeline summary
    """

    indent_length = 4
    blank_field = "Not Specified"
    blank_list = ["None Listed"]

    pipeline_definition = _preprocess_pipeline(pipeline_path,
                                               runtime="local",
                                               runtime_config="local")

    primary_pipeline = PipelineDefinition(
        pipeline_definition=pipeline_definition).primary_pipeline

    describe_dict = OrderedDict()

    describe_dict["name"] = primary_pipeline.name
    describe_dict["description"] = primary_pipeline.get_property("description")
    describe_dict["type"] = primary_pipeline.type
    describe_dict["version"] = primary_pipeline.version
    describe_dict["runtime"] = primary_pipeline.get_property("runtime")
    describe_dict["nodes"] = len(primary_pipeline.nodes)
    describe_dict["scripts"] = set()
    describe_dict["notebooks"] = set()
    describe_dict["file_dependencies"] = set()
    describe_dict["component_dependencies"] = set()
    describe_dict[pipeline_constants.MOUNTED_VOLUMES] = set()
    describe_dict[pipeline_constants.RUNTIME_IMAGE] = set()
    for node in primary_pipeline.nodes:
        # collect information about file dependencies
        for dependency in node.get_component_parameter("dependencies", []):
            describe_dict["file_dependencies"].add(f"{dependency}")
        # collect information about component dependencies
        if node.component_source is not None:
            describe_dict["component_dependencies"].add(node.component_source)
        # collect information of mounted volumes
        for mounted_volume in node.get_component_parameter(
                pipeline_constants.MOUNTED_VOLUMES, []):
            describe_dict[pipeline_constants.MOUNTED_VOLUMES].add(
                f"{mounted_volume.pvc_name}")
        # collection runtime image details
        temp_runtime_image_value = node.get_component_parameter(
            pipeline_constants.RUNTIME_IMAGE)
        if temp_runtime_image_value:
            describe_dict[pipeline_constants.RUNTIME_IMAGE].add(
                f"{temp_runtime_image_value}")

        # collect notebook / script name when pipeline is generic
        if describe_dict["runtime"] == "Generic":
            temp_value = node.get_component_parameter("filename")
            if not temp_value:
                pass
            elif Path(Path(temp_value).name).suffix == ".ipynb":
                describe_dict["notebooks"].add(temp_value)
            else:
                describe_dict["scripts"].add(temp_value)

    if not json_option:
        click.echo()

        print_banner("Elyra Pipeline details")
        for key in list(describe_dict):
            readable_key = " ".join(key.title().split("_"))
            if isinstance(describe_dict[key], set):
                click.echo(f"{readable_key}:")
                if not describe_dict.get(key):
                    click.echo(f"{' ' * indent_length}{blank_list[0]}")
                else:
                    for item in describe_dict.get(key, blank_list):
                        click.echo(f"{' ' * indent_length}- {item}")
            else:
                click.echo(
                    f"{readable_key}: {describe_dict.get(key, blank_field)}")
    else:
        for key in list(describe_dict):
            if isinstance(describe_dict[key], set):
                describe_dict[key] = list(describe_dict[key])

            value = describe_dict.get(key)
            if not value:
                describe_dict.pop(key)
        click.echo(json.dumps(describe_dict, indent=indent_length))