def _store_pipeline(yaml_file_content: AnyStr, name=None, description=None):

    yaml_dict = yaml.load(yaml_file_content, Loader=yaml.FullLoader)

    template_metadata = yaml_dict.get("metadata") or dict()
    annotations = template_metadata.get("annotations", {})
    pipeline_spec = json.loads(annotations.get("pipelines.kubeflow.org/pipeline_spec", "{}"))

    name = name or template_metadata["name"]
    description = pipeline_spec.get("description", "").strip()
    namespace = pipeline_spec.get("namespace", "").strip()
    pipeline_id = "-".join([generate_id(length=l) for l in [8, 4, 4, 4, 12]])
    created_at = datetime.now()

    parameters = [ApiParameter(name=p.get("name"), description=p.get("description"),
                               default=p.get("default"), value=p.get("value"))
                  for p in yaml_dict["spec"].get("params", {})]

    api_pipeline = ApiPipeline(id=pipeline_id,
                               created_at=created_at,
                               name=name,
                               description=description,
                               parameters=parameters,
                               namespace=namespace)

    uuid = store_data(api_pipeline)

    api_pipeline.id = uuid

    store_file(bucket_name="mlpipeline", prefix=f"pipelines/",
               file_name=f"{pipeline_id}", file_content=yaml_file_content)

    enable_anonymous_read_access(bucket_name="mlpipeline", prefix="pipelines/*")

    return api_pipeline
Beispiel #2
0
def upload_pipeline_to_kfp(uploadfile: str, name: str = None) -> ApiPipeline:

    config = UploadClientConfig()
    config.host = _pipeline_service_url
    api_client = UploadApiClient(configuration=config)
    api_instance = PipelineUploadServiceApi(api_client=api_client)

    try:
        kfp_pipeline: KfpPipeline = api_instance.upload_pipeline(uploadfile=uploadfile, name=name)
        api_pipeline: ApiPipeline = ApiPipeline.from_dict(kfp_pipeline.to_dict())
        api_pipeline.status = kfp_pipeline.error
        return api_pipeline

    except PipelineUploadApiException as e:
        kfp_host = api_instance.api_client.configuration.host

        print(f"Error calling PipelineServiceApi ({kfp_host}) -> upload_pipeline(name='{name}'): {e}")

        error_body = json.loads(e.body) or {"error_message": str(e)}
        error_msg = error_body["error_message"]
        status_code = 409 if "already exist. Please specify a new name" in error_msg else e.status

        raise ApiError(error_msg, status_code)

    return None
Beispiel #3
0
def upload_pipeline_to_kfp(uploadfile: str,
                           name: str = None,
                           description: str = None) -> ApiPipeline:

    kfp_client = KfpClient()

    try:
        kfp_pipeline: KfpPipeline = kfp_client.upload_pipeline(
            pipeline_package_path=uploadfile,
            pipeline_name=name,
            description=description)
        api_pipeline: ApiPipeline = ApiPipeline.from_dict(
            kfp_pipeline.to_dict())
        api_pipeline.status = kfp_pipeline.error
        return api_pipeline

    except PipelineApiException as e:
        kfp_host = _pipeline_service_url

        print(
            f"Error calling PipelineServiceApi ({kfp_host}) -> upload_pipeline(name='{name}'): {e}"
        )

        error_body = json.loads(e.body) or {"error_message": str(e)}
        error_msg = error_body["error_message"]
        status_code = 409 if "already exist. Please specify a new name" in error_msg else e.status

        raise ApiError(error_msg, status_code)

    return None
    def test_create_pipeline(self):
        """Test case for create_pipeline

        
        """
        body = ApiPipeline()
        response = self.client.open('/apis/v1alpha1/pipelines',
                                    method='POST',
                                    data=json.dumps(body),
                                    content_type='application/json')
        self.assert200(response,
                       'Response body is : ' + response.data.decode('utf-8'))
def create_pipeline(body):  # noqa: E501
    """create_pipeline

    :param body: 
    :type body: dict | bytes

    :rtype: ApiPipeline
    """
    if connexion.request.is_json:
        body = ApiPipeline.from_dict(connexion.request.get_json())  # noqa: E501

    return "Not implemented, yet", 501
def create_pipeline(body):  # noqa: E501
    """create_pipeline

     # noqa: E501

    :param body: 
    :type body: dict | bytes

    :rtype: ApiPipeline
    """
    if connexion.request.is_json:
        body = ApiPipeline.from_dict(connexion.request.get_json())  # noqa: E501
    return util.invoke_controller_impl()