Search in sources :

Example 1 with NetworkDeletionRequest

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();
}
Also used : CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) NetworkDeletionRequest(com.sequenceiq.cloudbreak.cloud.model.network.NetworkDeletionRequest)

Example 2 with NetworkDeletionRequest

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());
}
Also used : CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) NetworkDeletionRequest(com.sequenceiq.cloudbreak.cloud.model.network.NetworkDeletionRequest) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 3 with NetworkDeletionRequest

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());
}
Also used : CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) NetworkDeletionRequest(com.sequenceiq.cloudbreak.cloud.model.network.NetworkDeletionRequest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 4 with NetworkDeletionRequest

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());
}
Also used : NetworkDeletionRequest(com.sequenceiq.cloudbreak.cloud.model.network.NetworkDeletionRequest) Test(org.junit.Test)

Example 5 with NetworkDeletionRequest

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());
}
Also used : NetworkDeletionRequest(com.sequenceiq.cloudbreak.cloud.model.network.NetworkDeletionRequest) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Aggregations

NetworkDeletionRequest (com.sequenceiq.cloudbreak.cloud.model.network.NetworkDeletionRequest)15 Test (org.junit.Test)10 CloudCredential (com.sequenceiq.cloudbreak.cloud.model.CloudCredential)4 DeleteStackRequest (com.amazonaws.services.cloudformation.model.DeleteStackRequest)3 AmazonCloudFormationClient (com.sequenceiq.cloudbreak.cloud.aws.client.AmazonCloudFormationClient)3 AwsCredentialView (com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsCredentialView)3 EnvironmentDto (com.sequenceiq.environment.environment.dto.EnvironmentDto)3 Test (org.junit.jupiter.api.Test)3 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)3 ResourceGroup (com.microsoft.azure.management.resources.ResourceGroup)2 WaiterTimedOutException (com.amazonaws.waiters.WaiterTimedOutException)1 CloudException (com.microsoft.azure.CloudException)1 AuthenticatedContext (com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext)1 CloudContext (com.sequenceiq.cloudbreak.cloud.context.CloudContext)1 CloudConnectorException (com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException)1 GcpContext (com.sequenceiq.cloudbreak.cloud.gcp.context.GcpContext)1 CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)1 Network (com.sequenceiq.cloudbreak.cloud.model.Network)1 CreatedCloudNetwork (com.sequenceiq.cloudbreak.cloud.model.network.CreatedCloudNetwork)1 PollTask (com.sequenceiq.cloudbreak.cloud.task.PollTask)1