繁体   English   中英

使用REST API的Google Cloud Status Check?

[英]Google Cloud Status Check using REST API?

我正在寻找一个REST API,通过它我们可以检查Job的状态。 我正在ServiceNow中使用REST API调用进行虚拟实例的提供。 我能够成功创建REST调用,并且从REST调用收到的响应指出STATUS:PENDING。

因此,我想检查状态是否已从STATUS:PENDING更改为STATUS:DONE / READY。 我想使用REST API调用进行检查,是否有任何REST API调用进行检查。

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

上面的链接在Google API控制台中用于在VM上执行各种操作。

您可以将GET请求发送到https://www.googleapis.com/compute/v1/projects/project/zones/zone/instances/instance

这将返回实例资源 ,其中包含status属性。

您可以在此处找到有关CE REST API的更多信息。

您还可以在Java中查看基于此页面发送GET请求的示例

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(); 
   }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM