use of com.google.api.services.container.v1beta1.Container.Projects.Locations.Operations in project platinum by hartwigmedical.
the class KubernetesEngineTest method shouldPollUntilCreateClusterOperationHasCompleted.
@Test
public void shouldPollUntilCreateClusterOperationHasCompleted() throws Exception {
Get foundOperation = mock(Get.class);
Create created = mock(Create.class);
Operation executedCreate = mock(Operation.class);
when(clusters.get(anyString())).thenReturn(foundOperation);
when(foundOperation.execute()).thenThrow(GoogleJsonResponseException.class);
when(clusters.create(eq(format("projects/%s/locations/%s", PROJECT, REGION)), any())).thenReturn(created);
when(created.execute()).thenReturn(executedCreate);
when(executedCreate.getName()).thenReturn("created");
Operations operations = mock(Operations.class);
Operations.Get operationsGet = mock(Operations.Get.class);
Operation executedOperationsGet = mock(Operation.class);
when(locations.operations()).thenReturn(operations);
when(operations.get(anyString())).thenReturn(operationsGet);
when(operationsGet.execute()).thenReturn(executedOperationsGet);
when(executedOperationsGet.getStatus()).thenReturn(null).thenReturn("RUNNING").thenReturn("DONE");
victim.findOrCreate(RUN_NAME, Collections.emptyList(), JSON_KEY, BUCKET, SERVICE_ACCOUNT);
// noinspection ResultOfMethodCallIgnored
verify(executedOperationsGet, times(3)).getStatus();
}
use of com.google.api.services.container.v1beta1.Container.Projects.Locations.Operations in project platinum by hartwigmedical.
the class KubernetesEngineTest method mockForClusterCreation.
public void mockForClusterCreation() throws IOException {
Operations operations = mock(Operations.class);
Operations.Get operationsGet = mock(Operations.Get.class);
Operation executedOperationsGet = mock(Operation.class);
when(locations.operations()).thenReturn(operations);
when(operations.get(anyString())).thenReturn(operationsGet);
when(operationsGet.execute()).thenReturn(executedOperationsGet);
when(executedOperationsGet.getStatus()).thenReturn("DONE");
}
use of com.google.api.services.container.v1beta1.Container.Projects.Locations.Operations in project platinum by hartwigmedical.
the class KubernetesEngine method create.
private static void create(final Container containerApi, final String parent, final String cluster, final GcpConfiguration gcpConfiguration) {
try {
Cluster newCluster = new Cluster();
newCluster.setName(cluster);
newCluster.setNetwork(gcpConfiguration.networkUrl());
newCluster.setSubnetwork(gcpConfiguration.subnetUrl());
newCluster.setLocations(gcpConfiguration.zones());
NodePool defaultNodePool = new NodePool().setName("default").setInitialNodeCount(2);
final NodeConfig nodeConfig = new NodeConfig().setPreemptible(gcpConfiguration.preemptibleCluster()).setOauthScopes(List.of("https://www.googleapis.com/auth/cloud-platform")).setDiskSizeGb(500);
if (!gcpConfiguration.networkTags().isEmpty()) {
nodeConfig.setTags(gcpConfiguration.networkTags());
}
defaultNodePool.setConfig(nodeConfig);
newCluster.setNodePools(List.of(defaultNodePool));
IPAllocationPolicy ipAllocationPolicy = new IPAllocationPolicy();
if (gcpConfiguration.privateCluster()) {
PrivateClusterConfig privateClusterConfig = new PrivateClusterConfig();
privateClusterConfig.setEnablePrivateEndpoint(true);
privateClusterConfig.setEnablePrivateNodes(true);
privateClusterConfig.setMasterIpv4CidrBlock(gcpConfiguration.masterIpv4CidrBlock());
newCluster.setPrivateCluster(true);
newCluster.setPrivateClusterConfig(privateClusterConfig);
ipAllocationPolicy.setUseIpAliases(true);
}
if (gcpConfiguration.secondaryRangeNamePods().isPresent() && gcpConfiguration.secondaryRangeNameServices().isPresent()) {
ipAllocationPolicy.setClusterSecondaryRangeName(gcpConfiguration.secondaryRangeNamePods().get());
ipAllocationPolicy.setServicesSecondaryRangeName(gcpConfiguration.secondaryRangeNameServices().get());
}
newCluster.setIpAllocationPolicy(ipAllocationPolicy);
CreateClusterRequest createRequest = new CreateClusterRequest();
createRequest.setCluster(newCluster);
Create created = containerApi.projects().locations().clusters().create(parent, createRequest);
Operation execute = created.execute();
LOGGER.info("Creating new kubernetes cluster {} in project {} and region {}, this can take upwards of 5 minutes...", Console.bold(newCluster.getName()), Console.bold(gcpConfiguration.projectOrThrow()), Console.bold(gcpConfiguration.regionOrThrow()));
Failsafe.with(new RetryPolicy<>().withMaxDuration(ofMinutes(15)).withDelay(ofSeconds(15)).withMaxAttempts(-1).handleResult(null).handleResult("RUNNING")).onFailure(objectExecutionCompletedEvent -> LOGGER.info("Waiting on operation, status is [{}]", objectExecutionCompletedEvent.getResult())).get(() -> containerApi.projects().locations().operations().get(String.format("projects/%s/locations/%s/operations/%s", gcpConfiguration.projectOrThrow(), gcpConfiguration.regionOrThrow(), execute.getName())).execute().getStatus());
} catch (Exception e) {
throw new RuntimeException("Failed to create cluster", e);
}
}
Aggregations