2016-12-06 11 views
0

私はジョブのステータスを確認するために使用するREST APIを探しています。私は、ServiceNowで、REST API呼び出しを使用して仮想インスタンスの提供を行うために取り組んでいます。私は正常にREST呼び出しを作成することができ、REST呼び出しから受け取った応答はSTATUS:PENDINGという状態になりました。REST APIを使用したGoogle Cloud Status Check?

ステータスがSTATUS:PENDINGからSTATUS:DONE/READYに変更されているかどうか確認したいと思います。私はこれを確認するために、REST API呼び出しを使用して、REST API呼び出しを使用してチェックします。

https://developers.google.com/apis-explorer/?hl=en_US#p/compute/v1/

上記のリンクは、VM上でさまざまな操作を行うには、GoogleのAPIコンソールで使用されています。

+1

に基づいてGETリクエストを送信するJavaでこの例をチェックアウトすることができ、あなたがちょうど発売してきたインスタンスのステータスを照会する方法を求めていますか? compute.instances.getを使用できます(https://cloud.google.com/compute/docs/reference/latest/instances/getをご覧ください)。 – jarmod

答えて

0

https://www.googleapis.com/compute/v1/projects/project/zones/zone/instances/instanceにGETリクエストを送信できます。

これは、statusプロパティを含むInstance Resourceを返します。

CE REST API hereの詳細については、こちらをご覧ください。

またthis page

public class ComputeExample { 
    public static void main(String[] args) throws IOException, GeneralSecurityException { 
    // Authentication is provided by the 'gcloud' tool when running locally 
    // and by built-in service accounts when running on GAE, GCE, or GKE. 
    GoogleCredential credential = GoogleCredential.getApplicationDefault(); 

    // The createScopedRequired method returns true when running on GAE or a local developer 
    // machine. In that case, the desired scopes must be passed in manually. When the code is 
    // running in GCE, GKE or a Managed VM, the scopes are pulled from the GCE metadata server. 
    // For more information, see 
    // https://developers.google.com/identity/protocols/application-default-credentials 
    if (credential.createScopedRequired()) { 
     credential = 
      credential.createScoped(
       Collections.singletonList("https://www.googleapis.com/auth/cloud-platform")); 
    } 

    HttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport(); 
    JsonFactory jsonFactory = JacksonFactory.getDefaultInstance(); 
    Compute computeService = 
     new Compute.Builder(httpTransport, jsonFactory, credential) 
      .setApplicationName("Google Cloud Platform Sample") 
      .build(); 

    // TODO: Change placeholders below to appropriate parameter values for the 'get' method: 

    // * Project ID for this request. 
    String project = ""; 

    // * The name of the zone for this request. 
    String zone = ""; 

    // * Name of the instance resource to return. 
    String instance = ""; 

    Compute.Instances.Get request = computeService.instances().get(project, zone, instance); 
    Instance response = request.execute(); 

    //I'm assuming there's a getStatus method here 
    String status = response.getStatus(); 
    } 
} 
関連する問題