use of com.sequenceiq.cloudbreak.cloud.model.network.NetworkDeletionRequest in project cloudbreak by hortonworks.
the class EnvironmentNetworkService method createNetworkDeletionRequest.
private NetworkDeletionRequest createNetworkDeletionRequest(EnvironmentDto environment) {
CloudCredential cloudCredential = credentialToCloudCredentialConverter.convert(environment.getCredential());
NetworkDeletionRequest.Builder builder = new NetworkDeletionRequest.Builder().withStackName(networkCreationRequestFactory.getStackName(environment)).withCloudCredential(cloudCredential).withRegion(environment.getLocation().getName()).withSingleResourceGroup(isSingleResourceGroup(environment)).withSubnetIds(environment.getNetwork().getSubnetIds()).withEnvName(environment.getName()).withEnvId(environment.getId()).withAccountId(environment.getAccountId()).withUserId(environment.getCreator()).withRegion(environment.getLocation().getName()).withNetworkId(getNetworkId(environment.getNetwork(), environment.getName()));
getAzureResourceGroupName(environment).ifPresent(builder::withResourceGroup);
builder.withExisting(environment.getNetwork().getRegistrationType() == RegistrationType.EXISTING);
return builder.build();
}
use of com.sequenceiq.cloudbreak.cloud.model.network.NetworkDeletionRequest in project cloudbreak by hortonworks.
the class EnvironmentNetworkServiceTest method testDeleteNetworkShouldNotDeleteResourceGroupWhenUsagePatternSingle.
@ParameterizedTest
@EnumSource(value = ResourceGroupUsagePattern.class, names = { "USE_SINGLE", "USE_SINGLE_WITH_DEDICATED_STORAGE_ACCOUNT" })
void testDeleteNetworkShouldNotDeleteResourceGroupWhenUsagePatternSingle(ResourceGroupUsagePattern resourceGroupUsagePattern) {
CloudCredential cloudCredential = new CloudCredential("1", "credName", "account");
EnvironmentDto environmentDto = createEnvironmentDto("resourceGroup", "mySingleRg", resourceGroupUsagePattern);
when(cloudConnector.networkConnector()).thenReturn(networkConnector);
when(credentialToCloudCredentialConverter.convert(environmentDto.getCredential())).thenReturn(cloudCredential);
when(networkCreationRequestFactory.getStackName(any())).thenReturn(STACK_NAME);
underTest.deleteNetwork(environmentDto);
ArgumentCaptor<NetworkDeletionRequest> argumentCaptor = ArgumentCaptor.forClass(NetworkDeletionRequest.class);
verify(networkConnector).deleteNetworkWithSubnets(argumentCaptor.capture());
assertEquals(STACK_NAME, argumentCaptor.getValue().getStackName());
assertEquals(cloudCredential, argumentCaptor.getValue().getCloudCredential());
assertEquals(environmentDto.getLocation().getName(), argumentCaptor.getValue().getRegion());
assertEquals(environmentDto.getParameters().getAzureParametersDto().getAzureResourceGroupDto().getName(), argumentCaptor.getValue().getResourceGroup());
assertTrue(argumentCaptor.getValue().isSingleResourceGroup());
}
use of com.sequenceiq.cloudbreak.cloud.model.network.NetworkDeletionRequest in project cloudbreak by hortonworks.
the class EnvironmentNetworkServiceTest method testDeleteNetworkShouldDeleteTheNetwork.
@Test
void testDeleteNetworkShouldDeleteTheNetwork() {
CloudCredential cloudCredential = new CloudCredential("1", "asd", "account");
EnvironmentDto environmentDto = createEnvironmentDto(null);
when(cloudConnector.networkConnector()).thenReturn(networkConnector);
when(credentialToCloudCredentialConverter.convert(environmentDto.getCredential())).thenReturn(cloudCredential);
when(networkCreationRequestFactory.getStackName(any())).thenReturn(STACK_NAME);
underTest.deleteNetwork(environmentDto);
ArgumentCaptor<NetworkDeletionRequest> argumentCaptor = ArgumentCaptor.forClass(NetworkDeletionRequest.class);
verify(networkConnector).deleteNetworkWithSubnets(argumentCaptor.capture());
assertEquals(STACK_NAME, argumentCaptor.getValue().getStackName());
assertEquals(cloudCredential, argumentCaptor.getValue().getCloudCredential());
assertEquals(environmentDto.getLocation().getName(), argumentCaptor.getValue().getRegion());
assertNull(argumentCaptor.getValue().getResourceGroup());
}
use of com.sequenceiq.cloudbreak.cloud.model.network.NetworkDeletionRequest in project cloudbreak by hortonworks.
the class AzureNetworkConnectorTest method testDeleteNetworkWithSubnetsShouldDoNothingWhenResourceGroupNameIsNullInRequest.
@Test
public void testDeleteNetworkWithSubnetsShouldDoNothingWhenResourceGroupNameIsNullInRequest() {
NetworkDeletionRequest networkDeletionRequest = mock(NetworkDeletionRequest.class);
when(networkDeletionRequest.getResourceGroup()).thenReturn(null);
underTest.deleteNetworkWithSubnets(networkDeletionRequest);
verify(azureClient, times(0)).getResourceGroup(any());
verify(azureClient, times(0)).getResourceGroup(null);
verify(azureClient, times(0)).deleteTemplateDeployment(any(), any());
verify(azureClient, times(0)).deleteResourceGroup(any());
}
use of com.sequenceiq.cloudbreak.cloud.model.network.NetworkDeletionRequest in project cloudbreak by hortonworks.
the class AzureNetworkConnectorTest method testDeleteNetworkWithSubnetsShouldDoNothingWhenResourceGroupNameRefersToANonExistingResourceGroupInRequest.
@Test
public void testDeleteNetworkWithSubnetsShouldDoNothingWhenResourceGroupNameRefersToANonExistingResourceGroupInRequest() {
NetworkDeletionRequest networkDeletionRequest = mock(NetworkDeletionRequest.class);
String resourceGroupName = "someNotExistingResourceGroupName";
when(networkDeletionRequest.getResourceGroup()).thenReturn(resourceGroupName);
when(azureClientService.getClient(any())).thenReturn(azureClient);
when(azureClient.getResourceGroup(resourceGroupName)).thenReturn(null);
underTest.deleteNetworkWithSubnets(networkDeletionRequest);
verify(azureClient, times(1)).getResourceGroup(any());
verify(azureClient, times(1)).getResourceGroup(resourceGroupName);
verify(azureClient, times(0)).deleteTemplateDeployment(any(), any());
verify(azureClient, times(0)).deleteResourceGroup(any());
}
Aggregations