一部の API 呼び出しでは、Vertex AI からオペレーション名が返されます。これらの API 呼び出しは、完了までに時間のかかる処理を開始するため、長時間実行オペレーションと呼ばれます。たとえば、データセットの作成、エンドポイントの削除、モデルのエクスポートはすべて、長時間実行オペレーションです。次のセクションで説明するように、オペレーション名と一緒にヘルパー メソッドを使用すると、長時間実行オペレーションのステータスの取得やキャンセルを行うことができます。
オペレーションのステータスの取得
オペレーションのステータスを取得するには、長時間実行オペレーションをリクエストしたときのレスポンスに含まれていたオペレーション名を使用します。たとえば、データセットを作成すると、Vertex AI から次のようなオペレーション名が返されます。
projects/PROJECT_NUMBER/locations/LOCATION/datasets/DATASET_ID/operations/OPERATION_ID
オペレーションを定期的にポーリングし、オペレーションの完了を確認できます。
REST
リクエストのデータを使用する前に、次のように置き換えます。
- OPERATION_NAME: 長時間実行オペレーションの開始時に返されるオペレーション名(
projects/PROJECT_NUMBER/locations/LOCATION/datasets/DATASET_ID/operations/OPERATION_IDなど)
HTTP メソッドと URL:
GET https://LOCATION-aiplatform.googleapis.com/v1/OPERATION_NAME
リクエストを送信するには、次のいずれかのオプションを選択します。
curl
次のコマンドを実行します。
curl -X GET \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
"https://LOCATION-aiplatform.googleapis.com/v1/OPERATION_NAME"
PowerShell
次のコマンドを実行します。
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method GET `
-Headers $headers `
-Uri "https://LOCATION-aiplatform.googleapis.com/v1/OPERATION_NAME" | Select-Object -Expand Content
出力で、metadata オブジェクトにはリクエスト タイプに固有の情報が含まれます。done フィールドは、オペレーションが完了したかどうかを示します。オペレーションが完了すると、response オブジェクトにオペレーションからの結果が含まれます。
{
"name": "projects/123456789012/locations/us-central1/datasets/1234567890123456789/operations/1223344556677889900",
"metadata": {
"@type": "type.googleapis.com/google.cloud.aiplatform.v1.CreateDatasetOperationMetadata",
"genericMetadata": {
"createTime": "2020-10-12T16:00:44.686500Z",
"updateTime": "2020-10-12T16:01:06.115081Z"
}
},
"done": true,
"response": {
"@type": "type.googleapis.com/google.cloud.aiplatform.v1.Dataset",
"name": "projects/123456789012/locations/us-central1/datasets/1234567890123456789",
"displayName": "image_dataset",
"metadataSchemaUri": "gs://google-cloud-aiplatform/schema/dataset/metadata/image_1.0.0.yaml",
"labels": {
"aiplatform.googleapis.com/dataset_metadata_schema": "IMAGE"
},
"metadata": {
"dataItemSchemaUri": "gs://google-cloud-aiplatform/schema/dataset/dataitem/image_1.0.0.yaml"
}
}
}
オペレーションのキャンセル
長時間実行オペレーションをキャンセルすると、オペレーションを完了前に停止できます。オペレーションを正常にキャンセルしても、オペレーションは削除されません。オペレーションが停止すると、エラーコード 1 と CANCELLED メッセージが返されます。ただし、キャンセルは必ず成功するとは限りません。
REST
リクエストのデータを使用する前に、次のように置き換えます。
- OPERATION_NAME: 長時間実行オペレーションの開始時に返されるオペレーション名(
projects/PROJECT_NUMBER/locations/LOCATION/datasets/DATASET_ID/operations/OPERATION_IDなど)
HTTP メソッドと URL:
POST https://LOCATION-aiplatform.googleapis.com/v1/OPERATION_NAME:cancel
リクエストを送信するには、次のいずれかのオプションを選択します。
curl
次のコマンドを実行します。
curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d "" \
"https://LOCATION-aiplatform.googleapis.com/v1/OPERATION_NAME:cancel"
PowerShell
次のコマンドを実行します。
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method POST `
-Headers $headers `
-Uri "https://LOCATION-aiplatform.googleapis.com/v1/OPERATION_NAME:cancel" | Select-Object -Expand Content
成功したことを示すステータス コード(2xx)と空のレスポンスが返されます。