Class ComputeClientV2

java.lang.Object
com.google.jenkins.plugins.computeengine.client.ComputeClientV2

public class ComputeClientV2 extends Object
Extends ComputeClient with additional functionalities.

This class serves as a venue for implementing features not available in the archived Graphite Java library (gcp-plugin-core-java, last updated in December 2019). Consideration for the gradual evolution of this class is suggested, including the re-implementation of methods currently utilized from the Graphite library, to ensure dependency solely on the Google API Java Client Services library (google-api-java-client-services). This approach aims to eventually eliminate the reliance on the Graphite library.

  • Constructor Summary

    Constructors
    Constructor
    Description
    ComputeClientV2(String projectId, com.google.api.services.compute.Compute compute)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    com.google.api.services.compute.Compute
     
    List<com.google.api.services.compute.model.Image>
    listImages(String imageProject, long maxResults)
    Lists images in imageProject with an explicit maxResults, bypassing the archived gcp-plugin-core-java ComputeClient#listImages which silently truncates at the server default of 500.
    List<com.google.api.services.compute.model.Instance>
    Fetches instances by label key existence and status.
    void
    updateInstanceLabels(com.google.api.services.compute.model.Instance instance, Map<String,String> newLabels)
    Updates the labels of a specified instance by merging or replacing them with newLabels.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • ComputeClientV2

      public ComputeClientV2(String projectId, com.google.api.services.compute.Compute compute)
  • Method Details

    • updateInstanceLabels

      public void updateInstanceLabels(com.google.api.services.compute.model.Instance instance, Map<String,String> newLabels) throws IOException
      Updates the labels of a specified instance by merging or replacing them with newLabels.

      This method adds any new labels found in newLabels to the instance's existing labels and updates the values of any existing labels if they are also present in newLabels. Labels existing on the instance that are not in newLabels remain unchanged. This operation can only result in the addition of new labels or the modification of existing ones.

      Parameters:
      instance - the instance whose labels are to be updated; must not be null
      newLabels - the new labels to be merged with or replace the existing labels of the instance; must not be null
      Throws:
      IOException - if an I/O error occurs during the label update process.
    • retrieveInstanceByLabelKeyAndStatus

      public List<com.google.api.services.compute.model.Instance> retrieveInstanceByLabelKeyAndStatus(String key, String status) throws IOException
      Fetches instances by label key existence and status.

      Applies Google Compute Engine aggregated list syntax for filtering: aggregatedList API.

      Parameters:
      key - the non-empty label key to filter by.
      status - the instance status (RUNNING, STOPPING, etc.) as defined in: Instance States.
      Returns:
      List of Instance matching criteria, or empty list if none.
      Throws:
      IOException - for communication issues with Compute Engine API.
    • listImages

      public List<com.google.api.services.compute.model.Image> listImages(String imageProject, long maxResults) throws IOException
      Lists images in imageProject with an explicit maxResults, bypassing the archived gcp-plugin-core-java ComputeClient#listImages which silently truncates at the server default of 500.
      Throws:
      IOException
      See Also:
    • getCompute

      public com.google.api.services.compute.Compute getCompute()