use of com.google.container.v1.Cluster in project java-container by googleapis.
the class Util method cleanUpExistingInstanceCluster.
/**
* tear down any clusters that are older than 24 hours *
*/
public static void cleanUpExistingInstanceCluster(String projectId, String zone, ClusterManagerClient client) throws IOException, ExecutionException, InterruptedException {
ListClustersResponse clustersResponse = client.listClusters(projectId, zone);
List<Cluster> clusters = clustersResponse.getClustersList();
for (Cluster cluster : clusters) {
if (isCreatedBeforeThresholdTime(cluster.getCreateTime())) {
client.deleteCluster(projectId, zone, cluster.getName());
}
}
}
use of com.google.container.v1.Cluster in project java-container by googleapis.
the class ClusterManagerClientTest method listClustersTest.
@Test
public void listClustersTest() throws Exception {
ListClustersResponse expectedResponse = ListClustersResponse.newBuilder().addAllClusters(new ArrayList<Cluster>()).addAllMissingZones(new ArrayList<String>()).build();
mockClusterManager.addResponse(expectedResponse);
String projectId = "projectId-894832108";
String zone = "zone3744684";
ListClustersResponse actualResponse = client.listClusters(projectId, zone);
Assert.assertEquals(expectedResponse, actualResponse);
List<AbstractMessage> actualRequests = mockClusterManager.getRequests();
Assert.assertEquals(1, actualRequests.size());
ListClustersRequest actualRequest = ((ListClustersRequest) actualRequests.get(0));
Assert.assertEquals(projectId, actualRequest.getProjectId());
Assert.assertEquals(zone, actualRequest.getZone());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
use of com.google.container.v1.Cluster in project java-container by googleapis.
the class ClusterManagerClientTest method getClusterTest.
@Test
public void getClusterTest() throws Exception {
Cluster expectedResponse = Cluster.newBuilder().setName("name3373707").setDescription("description-1724546052").setInitialNodeCount(1682564205).setNodeConfig(NodeConfig.newBuilder().build()).setMasterAuth(MasterAuth.newBuilder().build()).setLoggingService("loggingService1098570326").setMonitoringService("monitoringService-1431578291").setNetwork("network1843485230").setClusterIpv4Cidr("clusterIpv4Cidr-277423341").setAddonsConfig(AddonsConfig.newBuilder().build()).setSubnetwork("subnetwork-1302785042").addAllNodePools(new ArrayList<NodePool>()).addAllLocations(new ArrayList<String>()).setEnableKubernetesAlpha(true).putAllResourceLabels(new HashMap<String, String>()).setLabelFingerprint("labelFingerprint379449680").setLegacyAbac(LegacyAbac.newBuilder().build()).setNetworkPolicy(NetworkPolicy.newBuilder().build()).setIpAllocationPolicy(IPAllocationPolicy.newBuilder().build()).setMasterAuthorizedNetworksConfig(MasterAuthorizedNetworksConfig.newBuilder().build()).setMaintenancePolicy(MaintenancePolicy.newBuilder().build()).setBinaryAuthorization(BinaryAuthorization.newBuilder().build()).setPodSecurityPolicyConfig(PodSecurityPolicyConfig.newBuilder().build()).setAutoscaling(ClusterAutoscaling.newBuilder().build()).setNetworkConfig(NetworkConfig.newBuilder().build()).setPrivateCluster(true).setMasterIpv4CidrBlock("masterIpv4CidrBlock42581458").setDefaultMaxPodsConstraint(MaxPodsConstraint.newBuilder().build()).setResourceUsageExportConfig(ResourceUsageExportConfig.newBuilder().build()).setAuthenticatorGroupsConfig(AuthenticatorGroupsConfig.newBuilder().build()).setPrivateClusterConfig(PrivateClusterConfig.newBuilder().build()).setVerticalPodAutoscaling(VerticalPodAutoscaling.newBuilder().build()).setShieldedNodes(ShieldedNodes.newBuilder().build()).setReleaseChannel(ReleaseChannel.newBuilder().build()).setWorkloadIdentityConfig(WorkloadIdentityConfig.newBuilder().build()).setWorkloadCertificates(WorkloadCertificates.newBuilder().build()).setMeshCertificates(MeshCertificates.newBuilder().build()).setClusterTelemetry(ClusterTelemetry.newBuilder().build()).setTpuConfig(TpuConfig.newBuilder().build()).setNotificationConfig(NotificationConfig.newBuilder().build()).setConfidentialNodes(ConfidentialNodes.newBuilder().build()).setIdentityServiceConfig(IdentityServiceConfig.newBuilder().build()).setSelfLink("selfLink1191800166").setZone("zone3744684").setEndpoint("endpoint1741102485").setInitialClusterVersion("initialClusterVersion-1547734558").setCurrentMasterVersion("currentMasterVersion1871927069").setCurrentNodeVersion("currentNodeVersion373921085").setCreateTime("createTime1369213417").setStatusMessage("statusMessage-958704715").setNodeIpv4CidrSize(1181176815).setServicesIpv4Cidr("servicesIpv4Cidr-1785842313").addAllInstanceGroupUrls(new ArrayList<String>()).setCurrentNodeCount(178977560).setExpireTime("expireTime-834724724").setLocation("location1901043637").setEnableTpu(true).setTpuIpv4CidrBlock("tpuIpv4CidrBlock997172251").setDatabaseEncryption(DatabaseEncryption.newBuilder().build()).addAllConditions(new ArrayList<StatusCondition>()).setMaster(Master.newBuilder().build()).setAutopilot(Autopilot.newBuilder().build()).setId("id3355").setNodePoolDefaults(NodePoolDefaults.newBuilder().build()).setLoggingConfig(LoggingConfig.newBuilder().build()).setMonitoringConfig(MonitoringConfig.newBuilder().build()).build();
mockClusterManager.addResponse(expectedResponse);
String projectId = "projectId-894832108";
String zone = "zone3744684";
String clusterId = "clusterId561939637";
Cluster actualResponse = client.getCluster(projectId, zone, clusterId);
Assert.assertEquals(expectedResponse, actualResponse);
List<AbstractMessage> actualRequests = mockClusterManager.getRequests();
Assert.assertEquals(1, actualRequests.size());
GetClusterRequest actualRequest = ((GetClusterRequest) actualRequests.get(0));
Assert.assertEquals(projectId, actualRequest.getProjectId());
Assert.assertEquals(zone, actualRequest.getZone());
Assert.assertEquals(clusterId, actualRequest.getClusterId());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
use of com.google.container.v1.Cluster in project java-container by googleapis.
the class ClusterManagerClientTest method createClusterExceptionTest.
@Test
public void createClusterExceptionTest() throws Exception {
StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
mockClusterManager.addException(exception);
try {
String projectId = "projectId-894832108";
String zone = "zone3744684";
Cluster cluster = Cluster.newBuilder().build();
client.createCluster(projectId, zone, cluster);
Assert.fail("No exception raised");
} catch (InvalidArgumentException e) {
// Expected exception.
}
}
use of com.google.container.v1.Cluster in project cdap by cdapio.
the class DataprocClient method updateClusterLabels.
/**
* Updates labelsToSet on the given Dataproc cluster.
*
* @param clusterName name of the cluster
* @param labelsToSet Key/Value pairs to set on the Dataproc cluster.
* @param labelsToRemove collection of labels to remove from the Dataproc cluster.
*/
void updateClusterLabels(String clusterName, Map<String, String> labelsToSet, Collection<String> labelsToRemove) throws RetryableProvisionException, InterruptedException {
if (labelsToSet.isEmpty() && labelsToRemove.isEmpty()) {
return;
}
try {
Cluster cluster = getDataprocCluster(clusterName).filter(c -> c.getStatus().getState() == ClusterStatus.State.RUNNING).orElseThrow(() -> new DataprocRuntimeException("Dataproc cluster " + clusterName + " does not exist or not in running state"));
Map<String, String> existingLabels = cluster.getLabelsMap();
// no need to update the cluster labelsToSet.
if (labelsToSet.entrySet().stream().allMatch(e -> Objects.equals(e.getValue(), existingLabels.get(e.getKey()))) && labelsToRemove.stream().noneMatch(existingLabels::containsKey)) {
return;
}
Map<String, String> newLabels = new HashMap<>(existingLabels);
newLabels.keySet().removeAll(labelsToRemove);
newLabels.putAll(labelsToSet);
FieldMask updateMask = FieldMask.newBuilder().addPaths("labels").build();
OperationFuture<Cluster, ClusterOperationMetadata> operationFuture = client.updateClusterAsync(UpdateClusterRequest.newBuilder().setProjectId(conf.getProjectId()).setRegion(conf.getRegion()).setClusterName(clusterName).setCluster(cluster.toBuilder().clearLabels().putAllLabels(newLabels)).setUpdateMask(updateMask).build());
ClusterOperationMetadata metadata = operationFuture.getMetadata().get();
int numWarnings = metadata.getWarningsCount();
if (numWarnings > 0) {
LOG.warn("Encountered {} warning {} while setting labels on cluster:\n{}", numWarnings, numWarnings > 1 ? "s" : "", String.join("\n", metadata.getWarningsList()));
}
} catch (ExecutionException e) {
Throwable cause = e.getCause();
if (cause instanceof ApiException) {
throw handleApiException((ApiException) cause);
}
throw new DataprocRuntimeException(cause);
}
}
Aggregations