Exemplo n.º 1
0
def test_create_pipeline():
    pipeline_yaml = 'pipeline.yaml'

    requests = [
        pipelines_pb2.PipelinesCreateRequest(
            header=BaseClient.get_request_header(),
            definition=pipelines_pb2.PipelineDefinitionFile(
                path='pipeline.yaml', content=PIPELINE_TEXT))
    ]

    responses = [
        pipelines_pb2.PipelinesCreateResponse(
            header=common_pb2.ResponseHeader(code=0, messages=[]),
            pipeline_id=common_pb2.Identifier(
                value='92656d79fa414db6b294069c0e9e6df5'))
    ]

    stub_method_handlers = [('Create', 'stream_unary', (requests, responses))]

    # set handlers
    MockClaraPipelineServiceClient.stub_method_handlers = stub_method_handlers

    def_list = [
        pipeline_types.PipelineDefinition(name=pipeline_yaml,
                                          content=PIPELINE_TEXT)
    ]

    with MockClaraPipelineServiceClient('localhost:50051') as client:
        pipeline_id = client.create_pipeline(definition=def_list)
        print(pipeline_id)
        assert pipeline_id.value == '92656d79fa414db6b294069c0e9e6df5'
    def pipeline_details(self, pipeline_id: pipeline_types.PipelineId, timeout=None) -> pipeline_types.PipelineDetails:
        """
        Requests details of a pipeline, identified by pipeline_types.PipelineId, from Clara.

        Args:
            pipeline_id (pipeline_types.PipelineId): Unique identifier of the pipeline.

        Return:
            A pipeline_types.PipelineDetails instance with details on the pipeline specified by 'pipeline_id'
        """
        if (self._channel is None) or (self._stub is None):
            raise Exception("Connection is currently closed. Please run reconnect() to reopen connection")

        if pipeline_id.value is None or pipeline_id.value == "":
            raise Exception("Pipeline identifier argument must be initialized with non-null instance")

        request = pipelines_pb2.PipelinesDetailsRequest(
            header=self.get_request_header(),
            pipeline_id=pipeline_id.to_grpc_value(),
        )

        response = self._stub.Details(request, timeout=timeout)

        responses = [resp for resp in response]

        if len(responses) > 0:
            self.check_response_header(header=responses[0].header)

            result = pipeline_types.PipelineDetails(
                name=responses[0].name,
                pipeline_id=pipeline_types.PipelineId(responses[0].pipeline_id.value),
                metadata=responses[0].metadata
            )

            result_definition = []

            for resp in responses:
                result_definition.append(
                    pipeline_types.PipelineDefinition(
                        name=resp.name,
                        content=resp.definition
                    )
                )

            result.definition = result_definition

            return result

        return None
from pathlib import Path
from nvidia_clara.pipelines_client import PipelinesClient
import nvidia_clara.pipeline_types as pipeline_types

# Client Creation with IP and Port of running instance of Clara

clara_ip_address = "10.0.0.1"
clara_port = "30031"

pipeline_client = PipelinesClient(target=clara_ip_address, port=clara_port)

# Create list of pipeline_types.PipelineDefinition with local path to pipeline .yaml
file_path = "./liver-tumor-pipeline.yaml"
definitions = [
    pipeline_types.PipelineDefinition(name=file_path,
                                      content=Path(file_path).read_text())
]

# Create Pipeline with definition list created
pipeline_id = pipeline_client.create_pipeline(definition=definitions)
print(pipeline_id)

# Get List of Created Pipelines PipelinesClient.list_pipelines()
pipelines = [(pipe_info.pipeline_id.value, pipe_info.name)
             for pipe_info in pipeline_client.list_pipelines()]
print(pipelines)

# Get Details of Pipeline with PipelinesClient.pipeline_details()
pipeline_details = pipeline_client.pipeline_details(pipeline_id=pipeline_id)

# Remove Pipeline