use of com.google.container.v1beta1.Cluster in project java-container by googleapis.
the class ClusterManagerClientTest method listClustersTest2.
@Test
public void listClustersTest2() 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.v1beta1.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 parent = "parent-995424086";
ListClustersResponse actualResponse = client.listClusters(parent);
Assert.assertEquals(expectedResponse, actualResponse);
List<AbstractMessage> actualRequests = mockClusterManager.getRequests();
Assert.assertEquals(1, actualRequests.size());
ListClustersRequest actualRequest = ((ListClustersRequest) actualRequests.get(0));
Assert.assertEquals(parent, actualRequest.getParent());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
use of com.google.container.v1beta1.Cluster in project java-container by googleapis.
the class ClusterManagerClientTest method createClusterTest2.
@Test
public void createClusterTest2() throws Exception {
Operation expectedResponse = Operation.newBuilder().setName("name3373707").setZone("zone3744684").setDetail("detail-1335224239").setStatusMessage("statusMessage-958704715").setSelfLink("selfLink1191800166").setTargetLink("targetLink486368555").setLocation("location1901043637").setStartTime("startTime-2129294769").setEndTime("endTime-1607243192").setProgress(OperationProgress.newBuilder().build()).addAllClusterConditions(new ArrayList<StatusCondition>()).addAllNodepoolConditions(new ArrayList<StatusCondition>()).setError(Status.newBuilder().build()).build();
mockClusterManager.addResponse(expectedResponse);
String projectId = "projectId-894832108";
String zone = "zone3744684";
Cluster cluster = Cluster.newBuilder().build();
Operation actualResponse = client.createCluster(projectId, zone, cluster);
Assert.assertEquals(expectedResponse, actualResponse);
List<AbstractMessage> actualRequests = mockClusterManager.getRequests();
Assert.assertEquals(1, actualRequests.size());
CreateClusterRequest actualRequest = ((CreateClusterRequest) actualRequests.get(0));
Assert.assertEquals(projectId, actualRequest.getProjectId());
Assert.assertEquals(zone, actualRequest.getZone());
Assert.assertEquals(cluster, actualRequest.getCluster());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
use of com.google.container.v1beta1.Cluster in project java-container by googleapis.
the class ClusterManagerClientTest method createClusterTest.
@Test
public void createClusterTest() throws Exception {
Operation expectedResponse = Operation.newBuilder().setName("name3373707").setZone("zone3744684").setDetail("detail-1335224239").setStatusMessage("statusMessage-958704715").setSelfLink("selfLink1191800166").setTargetLink("targetLink486368555").setLocation("location1901043637").setStartTime("startTime-2129294769").setEndTime("endTime-1607243192").setProgress(OperationProgress.newBuilder().build()).addAllClusterConditions(new ArrayList<StatusCondition>()).addAllNodepoolConditions(new ArrayList<StatusCondition>()).setError(Status.newBuilder().build()).build();
mockClusterManager.addResponse(expectedResponse);
String projectId = "projectId-894832108";
String zone = "zone3744684";
Cluster cluster = Cluster.newBuilder().build();
Operation actualResponse = client.createCluster(projectId, zone, cluster);
Assert.assertEquals(expectedResponse, actualResponse);
List<AbstractMessage> actualRequests = mockClusterManager.getRequests();
Assert.assertEquals(1, actualRequests.size());
CreateClusterRequest actualRequest = ((CreateClusterRequest) actualRequests.get(0));
Assert.assertEquals(projectId, actualRequest.getProjectId());
Assert.assertEquals(zone, actualRequest.getZone());
Assert.assertEquals(cluster, actualRequest.getCluster());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
use of com.google.container.v1beta1.Cluster in project cdap by cdapio.
the class DataprocClient method getClusterStatus.
/**
* Get the status of the specified cluster.
*
* @param name the cluster name
* @return the cluster status
* @throws RetryableProvisionException if there was a non 4xx error code returned
*/
io.cdap.cdap.runtime.spi.provisioner.ClusterStatus getClusterStatus(String name) throws RetryableProvisionException {
io.cdap.cdap.runtime.spi.provisioner.ClusterStatus status = getDataprocCluster(name).map(cluster -> convertStatus(cluster.getStatus())).orElse(io.cdap.cdap.runtime.spi.provisioner.ClusterStatus.NOT_EXISTS);
// if it failed, try to get the create operation and log the error message
try {
if (status == io.cdap.cdap.runtime.spi.provisioner.ClusterStatus.FAILED) {
String resourceName = String.format("projects/%s/regions/%s/operations", conf.getProjectId(), conf.getRegion());
String filter = String.format("clusterName=%s AND operationType=CREATE", name);
OperationsClient.ListOperationsPagedResponse operationsResponse = client.getOperationsClient().listOperations(resourceName, filter);
OperationsClient.ListOperationsPage page = operationsResponse.getPage();
if (page == null) {
LOG.warn("Unable to get the cause of the cluster creation failure.");
return status;
}
if (page.getPageElementCount() > 1) {
// shouldn't be possible
LOG.warn("Multiple create operations found for cluster {}, may not be able to find the failure message.", name);
}
if (page.getPageElementCount() > 0) {
Operation operation = page.getValues().iterator().next();
Status operationError = operation.getError();
if (operationError != null) {
LOG.warn("Failed to create cluster {}: {}", name, operationError.getMessage());
}
}
}
} catch (Exception e) {
// if we failed to get the operations list, log an error and proceed with normal execution
LOG.warn("Unable to get the cause of the cluster creation failure.", e);
}
return status;
}
Aggregations