Search in sources :

Example 16 with FreeIpaCreationDto

use of com.sequenceiq.environment.environment.dto.FreeIpaCreationDto in project cloudbreak by hortonworks.

the class EnvironmentApiConverterTest method testAzureSingleRgEnabledAndAzureRequestWithSingleUsageAndName.

@Test
void testAzureSingleRgEnabledAndAzureRequestWithSingleUsageAndName() {
    EnvironmentRequest request = createEnvironmentRequest(AZURE);
    request.setAzure(AzureEnvironmentParameters.builder().withAzureResourceGroup(AzureResourceGroup.builder().withName("myResourceGroup").withResourceGroupUsage(ResourceGroupUsage.SINGLE).build()).build());
    FreeIpaCreationDto freeIpaCreationDto = mock(FreeIpaCreationDto.class);
    EnvironmentTelemetry environmentTelemetry = mock(EnvironmentTelemetry.class);
    AccountTelemetry accountTelemetry = mock(AccountTelemetry.class);
    Features features = mock(Features.class);
    NetworkDto networkDto = mock(NetworkDto.class);
    when(credentialService.getCloudPlatformByCredential(anyString(), anyString(), any())).thenReturn(AZURE.name());
    when(freeIpaConverter.convert(request.getFreeIpa(), "id", CloudConstants.AWS)).thenReturn(freeIpaCreationDto);
    when(accountTelemetry.getFeatures()).thenReturn(features);
    when(accountTelemetryService.getOrDefault(any())).thenReturn(accountTelemetry);
    when(telemetryApiConverter.convert(eq(request.getTelemetry()), any(), anyString())).thenReturn(environmentTelemetry);
    when(tunnelConverter.convert(request.getTunnel())).thenReturn(request.getTunnel());
    when(networkRequestToDtoConverter.convert(request.getNetwork())).thenReturn(networkDto);
    EnvironmentCreationDto actual = testInitCreationDto(request);
    assertEquals(ResourceGroupUsagePattern.USE_SINGLE, actual.getParameters().getAzureParametersDto().getAzureResourceGroupDto().getResourceGroupUsagePattern());
    assertEquals("myResourceGroup", actual.getParameters().getAzureParametersDto().getAzureResourceGroupDto().getName());
}
Also used : NetworkDto(com.sequenceiq.environment.network.dto.NetworkDto) EnvironmentTelemetry(com.sequenceiq.environment.environment.dto.telemetry.EnvironmentTelemetry) FreeIpaCreationDto(com.sequenceiq.environment.environment.dto.FreeIpaCreationDto) AccountTelemetry(com.sequenceiq.environment.telemetry.domain.AccountTelemetry) EnvironmentRequest(com.sequenceiq.environment.api.v1.environment.model.request.EnvironmentRequest) Features(com.sequenceiq.common.api.telemetry.model.Features) ExperimentalFeatures(com.sequenceiq.environment.environment.domain.ExperimentalFeatures) EnvironmentCreationDto(com.sequenceiq.environment.environment.dto.EnvironmentCreationDto) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 17 with FreeIpaCreationDto

use of com.sequenceiq.environment.environment.dto.FreeIpaCreationDto in project cloudbreak by hortonworks.

the class EnvironmentApiConverterTest method testAwsDiskEncryptionParametersAndAwsRequest.

@Test
void testAwsDiskEncryptionParametersAndAwsRequest() {
    EnvironmentRequest request = createEnvironmentRequest(AWS);
    FreeIpaCreationDto freeIpaCreationDto = mock(FreeIpaCreationDto.class);
    EnvironmentTelemetry environmentTelemetry = mock(EnvironmentTelemetry.class);
    EnvironmentBackup environmentBackup = mock(EnvironmentBackup.class);
    AccountTelemetry accountTelemetry = mock(AccountTelemetry.class);
    Features features = mock(Features.class);
    NetworkDto networkDto = mock(NetworkDto.class);
    when(credentialService.getCloudPlatformByCredential(anyString(), anyString(), any())).thenReturn(AWS.name());
    when(freeIpaConverter.convert(request.getFreeIpa(), "id", CloudConstants.AWS)).thenReturn(freeIpaCreationDto);
    when(accountTelemetry.getFeatures()).thenReturn(features);
    when(accountTelemetryService.getOrDefault(any())).thenReturn(accountTelemetry);
    when(telemetryApiConverter.convert(eq(request.getTelemetry()), any(), anyString())).thenReturn(environmentTelemetry);
    when(backupConverter.convert(eq(request.getBackup()))).thenReturn(environmentBackup);
    when(tunnelConverter.convert(request.getTunnel())).thenReturn(request.getTunnel());
    when(networkRequestToDtoConverter.convert(request.getNetwork())).thenReturn(networkDto);
    EnvironmentCreationDto actual = testInitCreationDto(request);
    assertEquals(ENCRYPTION_KEY_ARN, actual.getParameters().getAwsParametersDto().getAwsDiskEncryptionParametersDto().getEncryptionKeyArn());
}
Also used : NetworkDto(com.sequenceiq.environment.network.dto.NetworkDto) EnvironmentTelemetry(com.sequenceiq.environment.environment.dto.telemetry.EnvironmentTelemetry) FreeIpaCreationDto(com.sequenceiq.environment.environment.dto.FreeIpaCreationDto) EnvironmentBackup(com.sequenceiq.environment.environment.dto.EnvironmentBackup) AccountTelemetry(com.sequenceiq.environment.telemetry.domain.AccountTelemetry) EnvironmentRequest(com.sequenceiq.environment.api.v1.environment.model.request.EnvironmentRequest) Features(com.sequenceiq.common.api.telemetry.model.Features) ExperimentalFeatures(com.sequenceiq.environment.environment.domain.ExperimentalFeatures) EnvironmentCreationDto(com.sequenceiq.environment.environment.dto.EnvironmentCreationDto) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 18 with FreeIpaCreationDto

use of com.sequenceiq.environment.environment.dto.FreeIpaCreationDto in project cloudbreak by hortonworks.

the class EnvironmentApiConverterTest method testAzureSingleRgEnabledAndAzureRequestWithoutUsageAndWithName.

@Test
void testAzureSingleRgEnabledAndAzureRequestWithoutUsageAndWithName() {
    EnvironmentRequest request = createEnvironmentRequest(AZURE);
    request.setAzure(AzureEnvironmentParameters.builder().withAzureResourceGroup(AzureResourceGroup.builder().withName("myResourceGroup").build()).build());
    FreeIpaCreationDto freeIpaCreationDto = mock(FreeIpaCreationDto.class);
    EnvironmentTelemetry environmentTelemetry = mock(EnvironmentTelemetry.class);
    EnvironmentBackup environmentBackup = mock(EnvironmentBackup.class);
    AccountTelemetry accountTelemetry = mock(AccountTelemetry.class);
    Features features = mock(Features.class);
    NetworkDto networkDto = mock(NetworkDto.class);
    when(credentialService.getCloudPlatformByCredential(anyString(), anyString(), any())).thenReturn(AZURE.name());
    when(freeIpaConverter.convert(request.getFreeIpa(), "id", CloudConstants.AWS)).thenReturn(freeIpaCreationDto);
    when(accountTelemetry.getFeatures()).thenReturn(features);
    when(accountTelemetryService.getOrDefault(any())).thenReturn(accountTelemetry);
    when(telemetryApiConverter.convert(eq(request.getTelemetry()), any(), anyString())).thenReturn(environmentTelemetry);
    when(backupConverter.convert(eq(request.getBackup()))).thenReturn(environmentBackup);
    when(tunnelConverter.convert(request.getTunnel())).thenReturn(request.getTunnel());
    when(networkRequestToDtoConverter.convert(request.getNetwork())).thenReturn(networkDto);
    EnvironmentCreationDto actual = testInitCreationDto(request);
    assertNull(actual.getParameters().getAzureParametersDto().getAzureResourceGroupDto().getResourceGroupUsagePattern());
    assertEquals("myResourceGroup", actual.getParameters().getAzureParametersDto().getAzureResourceGroupDto().getName());
}
Also used : NetworkDto(com.sequenceiq.environment.network.dto.NetworkDto) EnvironmentTelemetry(com.sequenceiq.environment.environment.dto.telemetry.EnvironmentTelemetry) FreeIpaCreationDto(com.sequenceiq.environment.environment.dto.FreeIpaCreationDto) EnvironmentBackup(com.sequenceiq.environment.environment.dto.EnvironmentBackup) AccountTelemetry(com.sequenceiq.environment.telemetry.domain.AccountTelemetry) EnvironmentRequest(com.sequenceiq.environment.api.v1.environment.model.request.EnvironmentRequest) Features(com.sequenceiq.common.api.telemetry.model.Features) ExperimentalFeatures(com.sequenceiq.environment.environment.domain.ExperimentalFeatures) EnvironmentCreationDto(com.sequenceiq.environment.environment.dto.EnvironmentCreationDto) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 19 with FreeIpaCreationDto

use of com.sequenceiq.environment.environment.dto.FreeIpaCreationDto in project cloudbreak by hortonworks.

the class EnvironmentApiConverterTest method testAzureResourceEncryptionParametersAndAzureRequest.

@Test
void testAzureResourceEncryptionParametersAndAzureRequest() {
    EnvironmentRequest request = createEnvironmentRequest(AZURE);
    request.setAzure(AzureEnvironmentParameters.builder().withResourceEncryptionParameters(AzureResourceEncryptionParameters.builder().withEncryptionKeyUrl(KEY_URL).withEncryptionKeyResourceGroupName(KEY_URL_RESOURCE_GROUP).build()).build());
    FreeIpaCreationDto freeIpaCreationDto = mock(FreeIpaCreationDto.class);
    EnvironmentTelemetry environmentTelemetry = mock(EnvironmentTelemetry.class);
    EnvironmentBackup environmentBackup = mock(EnvironmentBackup.class);
    AccountTelemetry accountTelemetry = mock(AccountTelemetry.class);
    Features features = mock(Features.class);
    NetworkDto networkDto = mock(NetworkDto.class);
    when(credentialService.getCloudPlatformByCredential(anyString(), anyString(), any())).thenReturn(AZURE.name());
    when(freeIpaConverter.convert(request.getFreeIpa(), "id", CloudConstants.AWS)).thenReturn(freeIpaCreationDto);
    when(accountTelemetry.getFeatures()).thenReturn(features);
    when(accountTelemetryService.getOrDefault(any())).thenReturn(accountTelemetry);
    when(telemetryApiConverter.convert(eq(request.getTelemetry()), any(), anyString())).thenReturn(environmentTelemetry);
    when(backupConverter.convert(eq(request.getBackup()))).thenReturn(environmentBackup);
    when(tunnelConverter.convert(request.getTunnel())).thenReturn(request.getTunnel());
    when(networkRequestToDtoConverter.convert(request.getNetwork())).thenReturn(networkDto);
    EnvironmentCreationDto actual = testInitCreationDto(request);
    assertEquals(KEY_URL, actual.getParameters().getAzureParametersDto().getAzureResourceEncryptionParametersDto().getEncryptionKeyUrl());
    assertEquals(KEY_URL_RESOURCE_GROUP, actual.getParameters().getAzureParametersDto().getAzureResourceEncryptionParametersDto().getEncryptionKeyResourceGroupName());
}
Also used : NetworkDto(com.sequenceiq.environment.network.dto.NetworkDto) EnvironmentTelemetry(com.sequenceiq.environment.environment.dto.telemetry.EnvironmentTelemetry) FreeIpaCreationDto(com.sequenceiq.environment.environment.dto.FreeIpaCreationDto) EnvironmentBackup(com.sequenceiq.environment.environment.dto.EnvironmentBackup) AccountTelemetry(com.sequenceiq.environment.telemetry.domain.AccountTelemetry) EnvironmentRequest(com.sequenceiq.environment.api.v1.environment.model.request.EnvironmentRequest) Features(com.sequenceiq.common.api.telemetry.model.Features) ExperimentalFeatures(com.sequenceiq.environment.environment.domain.ExperimentalFeatures) EnvironmentCreationDto(com.sequenceiq.environment.environment.dto.EnvironmentCreationDto) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 20 with FreeIpaCreationDto

use of com.sequenceiq.environment.environment.dto.FreeIpaCreationDto in project cloudbreak by hortonworks.

the class FreeIpaCreationHandler method createInstanceGroupRequests.

private List<InstanceGroupRequest> createInstanceGroupRequests(CreateFreeIpaRequest createFreeIpaRequest, SecurityGroupRequest securityGroupRequest, EnvironmentDto environment, boolean multiAzRequired) {
    List<InstanceGroupRequest> instanceGroupRequests = new LinkedList<>();
    FreeIpaCreationDto freeIpaCreation = environment.getFreeIpaCreation();
    InstanceGroupRequest instanceGroupRequest = new InstanceGroupRequest();
    instanceGroupRequest.setName(MASTER_GROUP_NAME);
    instanceGroupRequest.setNodeCount(freeIpaCreation.getInstanceCountByGroup());
    instanceGroupRequest.setType(InstanceGroupType.MASTER);
    instanceGroupRequest.setSecurityGroup(securityGroupRequest);
    instanceGroupRequest.setInstanceTemplateRequest(createInstanceTemplate(freeIpaCreation));
    if (multiAzRequired && multiAzValidator.suportedMultiAzForEnvironment(environment.getCloudPlatform())) {
        FreeIpaNetworkProvider freeIpaNetworkProvider = freeIpaNetworkProviderMapByCloudPlatform.get(CloudPlatform.valueOf(environment.getCloudPlatform()));
        if (freeIpaNetworkProvider != null) {
            InstanceGroupNetworkRequest instanceGroupNetworkRequest = freeIpaNetworkProvider.networkByGroup(environment);
            instanceGroupRequest.setNetwork(instanceGroupNetworkRequest);
            createFreeIpaRequest.getPlacement().setAvailabilityZone(freeIpaNetworkProvider.availabilityZone(instanceGroupNetworkRequest, environment));
        }
    }
    instanceGroupRequests.add(instanceGroupRequest);
    return instanceGroupRequests;
}
Also used : InstanceGroupNetworkRequest(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.instance.InstanceGroupNetworkRequest) InstanceGroupRequest(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.instance.InstanceGroupRequest) FreeIpaCreationDto(com.sequenceiq.environment.environment.dto.FreeIpaCreationDto) LinkedList(java.util.LinkedList)

Aggregations

FreeIpaCreationDto (com.sequenceiq.environment.environment.dto.FreeIpaCreationDto)21 Test (org.junit.jupiter.api.Test)16 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)8 Features (com.sequenceiq.common.api.telemetry.model.Features)7 EnvironmentRequest (com.sequenceiq.environment.api.v1.environment.model.request.EnvironmentRequest)7 ExperimentalFeatures (com.sequenceiq.environment.environment.domain.ExperimentalFeatures)7 EnvironmentCreationDto (com.sequenceiq.environment.environment.dto.EnvironmentCreationDto)7 EnvironmentTelemetry (com.sequenceiq.environment.environment.dto.telemetry.EnvironmentTelemetry)7 NetworkDto (com.sequenceiq.environment.network.dto.NetworkDto)7 AccountTelemetry (com.sequenceiq.environment.telemetry.domain.AccountTelemetry)7 FreeIpaResponse (com.sequenceiq.environment.api.v1.environment.model.response.FreeIpaResponse)6 AttachedFreeIpaRequest (com.sequenceiq.environment.api.v1.environment.model.request.AttachedFreeIpaRequest)4 EnvironmentBackup (com.sequenceiq.environment.environment.dto.EnvironmentBackup)4 UsageProto (com.cloudera.thunderhead.service.common.usage.UsageProto)1 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)1 ValidationResult (com.sequenceiq.cloudbreak.validation.ValidationResult)1 FreeIpaImageRequest (com.sequenceiq.environment.api.v1.environment.model.request.FreeIpaImageRequest)1 FreeIpaCreationAwsParametersDto (com.sequenceiq.environment.environment.dto.FreeIpaCreationAwsParametersDto)1 FreeIpaCreationAwsSpotParametersDto (com.sequenceiq.environment.environment.dto.FreeIpaCreationAwsSpotParametersDto)1 InstanceGroupNetworkRequest (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.instance.InstanceGroupNetworkRequest)1