use of com.google.api.services.compute.model.Operation in project cloudbreak by hortonworks.
the class GcpNetworkResourceBuilder method delete.
@Override
public CloudResource delete(GcpContext context, AuthenticatedContext auth, CloudResource resource, Network network) throws Exception {
if (!gcpStackUtil.isExistingNetwork(network)) {
Compute compute = context.getCompute();
String projectId = context.getProjectId();
try {
Operation operation = compute.networks().delete(projectId, resource.getName()).execute();
return createOperationAwareCloudResource(resource, operation);
} catch (GoogleJsonResponseException e) {
exceptionHandler(e, resource.getName(), resourceType());
return null;
}
}
return null;
}
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