Class ComputeClientV2
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
ConstructorDescriptionComputeClientV2
(String projectId, com.google.api.services.compute.Compute compute) -
Method Summary
Modifier and TypeMethodDescriptioncom.google.api.services.compute.Compute
List<com.google.api.services.compute.model.Instance>
retrieveInstanceByLabelKeyAndStatus
(String key, String status) 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 specifiedinstance
by merging or replacing them withnewLabels
.
-
Constructor Details
-
ComputeClientV2
-
-
Method Details
-
updateInstanceLabels
public void updateInstanceLabels(com.google.api.services.compute.model.Instance instance, Map<String, String> newLabels) throws IOExceptionUpdates the labels of a specifiedinstance
by merging or replacing them withnewLabels
.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 innewLabels
. Labels existing on the instance that are not innewLabels
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 benull
newLabels
- the new labels to be merged with or replace the existing labels of the instance; must not benull
- 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.
-
getCompute
public com.google.api.services.compute.Compute getCompute()
-