name: model_undeploy
description: |
    Undeploys a Google Cloud Vertex DeployedModel within the Endpoint.
    For more details, see https://cloud.google.com/vertex-ai/docs/reference/rest/v1/projects.locations.endpoints/deployModel.

    Args:
        model (google.VertexModel):
            Required. The model that was deployed to the Endpoint.
        endpoint (google.VertexEndpoint):
            Required. The endpoint for the DeployedModel to be undeployed from.
        traffic_split (Optional[Dict[str, int]]):
            If this field is provided, then the Endpoint's trafficSplit will be overwritten with it.
            If last DeployedModel is being undeployed from the Endpoint, the
            [Endpoint.traffic_split] will always end up empty when this call returns.
            A DeployedModel will be successfully undeployed only if it doesn't have any traffic
            assigned to it when this method executes, or if this field unassigns any traffic to it.

    Returns:
        gcp_resources (str):
            Serialized gcp_resources proto tracking the undeploy model's long running operation.

            For more details, see https://github.com/kubeflow/pipelines/blob/master/components/google-cloud/google_cloud_pipeline_components/proto/README.md.
inputs:
- {name: model, type: google.VertexModel}
- {name: endpoint, type: google.VertexEndpoint}
- {name: traffic_split, type: JsonObject, optional: true, default: '{}'}
outputs:
- {name: gcp_resources, type: String}
implementation:
  container:
    image: gcr.io/ml-pipeline/google-cloud-pipeline-components:1.10.13
    command: [python3, -u, -m, google_cloud_pipeline_components.container.v1.gcp_launcher.launcher]
    args: [
      --type, UndeployModel,
      --payload,
      concat: [
          '{',
          '"endpoint": "', "{{$.inputs.artifacts['endpoint'].metadata['resourceName']}}", '"',
          ', "model": "', "{{$.inputs.artifacts['model'].metadata['resourceName']}}", '"',
          ', "traffic_split": ', {inputValue: traffic_split},
          '}'
      ],
      --project, '', # not being used
      --location, '', # not being used
      --gcp_resources, {outputPath: gcp_resources},
    ]
