use of com.google.api.services.compute.model.Operation in project terra-cloud-resource-lib by DataBiosphere.
the class NetworkUtils method exceuteCreateNetwork.
/**
* Creates a new Network in a given GCP project for testing.
*/
public static Network exceuteCreateNetwork(String projectId, boolean autoCreateSubnetworks) throws Exception {
String netWorkName = randomNetworkName();
Network network = new Network().setName(netWorkName).setAutoCreateSubnetworks(autoCreateSubnetworks);
Operation networkOperation = getCloudComputeCow().networks().insert(projectId, network).execute();
OperationTestUtils.pollAndAssertSuccess(getCloudComputeCow().globalOperations().operationCow(projectId, networkOperation), Duration.ofSeconds(5), Duration.ofSeconds(100));
return getCloudComputeCow().networks().get(projectId, netWorkName).execute();
}
use of com.google.api.services.compute.model.Operation in project cloudbreak by hortonworks.
the class GcpInstanceStateCheckerTest method checkBasedOnOperationWhenGetOperationReturns.
@ParameterizedTest(name = "checkBasedOnOperationWhenGetOperationReturns with operation status: {0}, type: {1} then the expected instance status is: {3}")
@MethodSource("checkBasedOnOperationWhenGetOperationReturnsData")
void checkBasedOnOperationWhenGetOperationReturns(String operationStatus, String operationType, boolean operationFinished, InstanceStatus expectedInstanceStatus) throws Exception {
stubGcpContext();
CloudInstance cloudInstance = getCloudInstanceWithOperation(AVAILABILITY_ZONE, OPERATION_ID);
Compute.ZoneOperations.Get get = mock(Compute.ZoneOperations.Get.class);
Operation operation = getOperation(OPERATION_ID, operationStatus, operationType);
when(get.execute()).thenReturn(operation);
when(gcpStackUtil.zoneOperation(gcpCompute, PROJECT_ID, OPERATION_ID, AVAILABILITY_ZONE)).thenReturn(get);
when(gcpStackUtil.isOperationFinished(operation)).thenReturn(operationFinished);
List<CloudVmInstanceStatus> vmStatuses = underTest.checkBasedOnOperation(gcpContext, List.of(cloudInstance));
verify(gcpStackUtil).zoneOperation(gcpCompute, PROJECT_ID, OPERATION_ID, AVAILABILITY_ZONE);
assertFalse(vmStatuses.isEmpty());
assertTrue(vmStatuses.stream().allMatch(vmStatus -> expectedInstanceStatus.equals(vmStatus.getStatus())));
}
use of com.google.api.services.compute.model.Operation in project cloudbreak by hortonworks.
the class GcpInstanceStateCheckerTest method checkBasedOnOperationWhenGetOperationSucceedsAndFinishedButTheOperationTypeIsNotSupported.
@Test
void checkBasedOnOperationWhenGetOperationSucceedsAndFinishedButTheOperationTypeIsNotSupported() throws Exception {
stubGcpContext();
CloudInstance cloudInstance = getCloudInstanceWithOperation(AVAILABILITY_ZONE, OPERATION_ID);
Compute.ZoneOperations.Get get = mock(Compute.ZoneOperations.Get.class);
Operation operation = getOperation(OPERATION_ID, "DONE", "UNKNOWN");
when(get.execute()).thenReturn(operation);
when(gcpStackUtil.zoneOperation(gcpCompute, PROJECT_ID, OPERATION_ID, AVAILABILITY_ZONE)).thenReturn(get);
when(gcpStackUtil.isOperationFinished(operation)).thenReturn(Boolean.TRUE);
Assertions.assertThrows(GcpResourceException.class, () -> underTest.checkBasedOnOperation(gcpContext, List.of(cloudInstance)));
verify(gcpStackUtil).zoneOperation(gcpCompute, PROJECT_ID, OPERATION_ID, AVAILABILITY_ZONE);
}
use of com.google.api.services.compute.model.Operation in project cloudbreak by hortonworks.
the class GcpFirewallInResourceBuilderTest method testDeleteWhenEverythingGoesFine.
@Test
public void testDeleteWhenEverythingGoesFine() throws Exception {
CloudResource resource = new CloudResource.Builder().type(ResourceType.GCP_FIREWALL_IN).status(CommonStatus.CREATED).group("master").name("super").instanceId("id-123").params(new HashMap<>()).persistent(true).build();
GcpContext gcpContext = mock(GcpContext.class);
AuthenticatedContext authenticatedContext = mock(AuthenticatedContext.class);
Network network = mock(Network.class);
Compute compute = mock(Compute.class);
Compute.Firewalls firewalls = mock(Compute.Firewalls.class);
Compute.Firewalls.Delete firewallsDelete = mock(Compute.Firewalls.Delete.class);
Operation operation = mock(Operation.class);
when(gcpContext.getCompute()).thenReturn(compute);
when(gcpContext.getProjectId()).thenReturn("id");
when(compute.firewalls()).thenReturn(firewalls);
when(firewalls.delete(anyString(), anyString())).thenReturn(firewallsDelete);
when(firewallsDelete.execute()).thenReturn(operation);
when(operation.getName()).thenReturn("name");
CloudResource delete = underTest.delete(gcpContext, authenticatedContext, resource, network);
Assert.assertEquals(ResourceType.GCP_FIREWALL_IN, delete.getType());
Assert.assertEquals(CommonStatus.CREATED, delete.getStatus());
Assert.assertEquals("super", delete.getName());
Assert.assertEquals("master", delete.getGroup());
Assert.assertEquals("id-123", delete.getInstanceId());
}
use of com.google.api.services.compute.model.Operation in project cloudbreak by hortonworks.
the class GcpFirewallInternalResourceBuilderTest method testDeleteWhenEverythingGoesFine.
@Test
public void testDeleteWhenEverythingGoesFine() throws Exception {
CloudResource resource = new CloudResource.Builder().type(ResourceType.GCP_FIREWALL_INTERNAL).status(CommonStatus.CREATED).group("master").name("super").instanceId("id-123").params(new HashMap<>()).persistent(true).build();
GcpContext gcpContext = mock(GcpContext.class);
AuthenticatedContext authenticatedContext = mock(AuthenticatedContext.class);
Network network = mock(Network.class);
Compute compute = mock(Compute.class);
Compute.Firewalls firewalls = mock(Compute.Firewalls.class);
Compute.Firewalls.Delete firewallsDelete = mock(Compute.Firewalls.Delete.class);
Operation operation = mock(Operation.class);
when(gcpContext.getCompute()).thenReturn(compute);
when(gcpContext.getProjectId()).thenReturn("id");
when(compute.firewalls()).thenReturn(firewalls);
when(firewalls.delete(anyString(), anyString())).thenReturn(firewallsDelete);
when(firewallsDelete.execute()).thenReturn(operation);
when(operation.getName()).thenReturn("name");
CloudResource delete = underTest.delete(gcpContext, authenticatedContext, resource, network);
Assert.assertEquals(ResourceType.GCP_FIREWALL_INTERNAL, delete.getType());
Assert.assertEquals(CommonStatus.CREATED, delete.getStatus());
Assert.assertEquals("super", delete.getName());
Assert.assertEquals("master", delete.getGroup());
Assert.assertEquals("id-123", delete.getInstanceId());
}
Aggregations