Search in sources :

Example 1 with AwsInstanceTemplateV4Parameters

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.parameter.template.AwsInstanceTemplateV4Parameters in project cloudbreak by hortonworks.

the class FreeIpaTestDto method mapInstanceTemplateRequest.

private InstanceTemplateRequest mapInstanceTemplateRequest(InstanceGroupV4Request request) {
    InstanceTemplateRequest template = new InstanceTemplateRequest();
    template.setInstanceType(request.getTemplate().getInstanceType());
    template.setAttachedVolumes(request.getTemplate().getAttachedVolumes().stream().map(volreq -> {
        VolumeRequest volumeRequest = new VolumeRequest();
        volumeRequest.setCount(volreq.getCount());
        volumeRequest.setSize(volreq.getSize());
        volumeRequest.setType(volreq.getType());
        return volumeRequest;
    }).collect(Collectors.toSet()));
    Optional.ofNullable(request.getTemplate().getAws()).map(AwsInstanceTemplateV4Parameters::getSpot).map(AwsInstanceTemplateV4SpotParameters::getPercentage).ifPresent(spotPercentage -> {
        AwsInstanceTemplateParameters awsInstanceTemplateParameters = new AwsInstanceTemplateParameters();
        AwsInstanceTemplateSpotParameters awsInstanceTemplateSpotParameters = new AwsInstanceTemplateSpotParameters();
        awsInstanceTemplateSpotParameters.setPercentage(spotPercentage);
        awsInstanceTemplateParameters.setSpot(awsInstanceTemplateSpotParameters);
        template.setAws(awsInstanceTemplateParameters);
    });
    return template;
}
Also used : AwsInstanceTemplateSpotParameters(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.instance.aws.AwsInstanceTemplateSpotParameters) InstanceTemplateRequest(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.instance.InstanceTemplateRequest) AwsInstanceTemplateV4Parameters(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.parameter.template.AwsInstanceTemplateV4Parameters) AwsInstanceTemplateParameters(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.instance.aws.AwsInstanceTemplateParameters) VolumeRequest(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.instance.VolumeRequest)

Example 2 with AwsInstanceTemplateV4Parameters

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.parameter.template.AwsInstanceTemplateV4Parameters in project cloudbreak by hortonworks.

the class InstanceTemplateParameterConverterTest method convertTestAwsInstanceTemplateV1ParametersToAwsInstanceTemplateV4ParametersWhenEncryption.

@ParameterizedTest(name = "{0}")
@MethodSource("convertTestAwsInstanceTemplateV1ParametersToAwsInstanceTemplateV4ParametersWhenEncryptionDataProvided")
void convertTestAwsInstanceTemplateV1ParametersToAwsInstanceTemplateV4ParametersWhenEncryption(String testCaseName, boolean withAws, boolean withResourceEncryption, String dataHubEncryptionKey, String environmentEncryptionKey, String expectedEncryptionKey) {
    AwsInstanceTemplateV1Parameters source = new AwsInstanceTemplateV1Parameters();
    String finalEncryptionKey = null;
    if (dataHubEncryptionKey != null) {
        source.setEncryption(encryption(EncryptionType.CUSTOM, DATAHUB_ENCRYPTION_KEY));
        finalEncryptionKey = DATAHUB_ENCRYPTION_KEY;
    } else {
        if (environmentEncryptionKey != null) {
            source.setEncryption(encryption(EncryptionType.CUSTOM, ENVIRONMENT_ENCRYPTION_KEY));
            finalEncryptionKey = ENVIRONMENT_ENCRYPTION_KEY;
        } else {
            source.setEncryption(encryption(null, null));
        }
    }
    DetailedEnvironmentResponse environment = createDetailedEnvironmentResponseForAwsEncryption(withAws, withResourceEncryption, finalEncryptionKey);
    AwsInstanceTemplateV4Parameters awsInstanceTemplateV4Parameters = underTest.convert(source, environment);
    assertThat(awsInstanceTemplateV4Parameters).isNotNull();
    AwsEncryptionV4Parameters encryption = awsInstanceTemplateV4Parameters.getEncryption();
    assertThat(encryption).isNotNull();
    if (dataHubEncryptionKey != null || environmentEncryptionKey != null) {
        assertThat(encryption.getType()).isEqualTo(EncryptionType.CUSTOM);
        assertThat(encryption.getKey()).isEqualTo(expectedEncryptionKey);
    } else {
        assertThat(encryption.getType()).isEqualTo(EncryptionType.DEFAULT);
    }
}
Also used : AwsInstanceTemplateV4Parameters(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.parameter.template.AwsInstanceTemplateV4Parameters) AwsEncryptionV4Parameters(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.parameter.template.AwsEncryptionV4Parameters) AwsInstanceTemplateV1Parameters(com.sequenceiq.distrox.api.v1.distrox.model.instancegroup.template.AwsInstanceTemplateV1Parameters) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 3 with AwsInstanceTemplateV4Parameters

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.parameter.template.AwsInstanceTemplateV4Parameters in project cloudbreak by hortonworks.

the class InstanceTemplateParameterConverterTest method testWhenDatahubEncryptionTypeSetToNull.

@Test
void testWhenDatahubEncryptionTypeSetToNull() {
    AwsInstanceTemplateV1Parameters source = new AwsInstanceTemplateV1Parameters();
    source.setEncryption(encryption(null, null));
    DetailedEnvironmentResponse environment = createDetailedEnvironmentResponseForAwsEncryption(true, false, null);
    AwsInstanceTemplateV4Parameters awsInstanceTemplateV4Parameters = underTest.convert(source, environment);
    assertThat(awsInstanceTemplateV4Parameters).isNotNull();
    AwsEncryptionV4Parameters encryption = awsInstanceTemplateV4Parameters.getEncryption();
    assertThat(encryption).isNotNull();
    assertThat(encryption.getType()).isEqualTo(EncryptionType.DEFAULT);
}
Also used : AwsInstanceTemplateV4Parameters(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.parameter.template.AwsInstanceTemplateV4Parameters) AwsEncryptionV4Parameters(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.parameter.template.AwsEncryptionV4Parameters) AwsInstanceTemplateV1Parameters(com.sequenceiq.distrox.api.v1.distrox.model.instancegroup.template.AwsInstanceTemplateV1Parameters) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 4 with AwsInstanceTemplateV4Parameters

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.parameter.template.AwsInstanceTemplateV4Parameters in project cloudbreak by hortonworks.

the class StackAwsEncryptionValidatorTest method testValidateEncryptionKeyWhenTemplateParametersHasTypeKeyAndItsTypeIsEncryptionTypeWithDefaultValueThenThereIsNoEncryptionKeyCheck.

@Test
public void testValidateEncryptionKeyWhenTemplateParametersHasTypeKeyAndItsTypeIsEncryptionTypeWithDefaultValueThenThereIsNoEncryptionKeyCheck() {
    AwsInstanceTemplateV4Parameters parameters = new AwsInstanceTemplateV4Parameters();
    parameters.setEncryption(encryption(EncryptionType.DEFAULT, null));
    when(subject.getInstanceGroups()).thenReturn(getInstanceGroupWithRequest(createRequestWithParameters(parameters)));
    ValidationResult.ValidationResultBuilder builder = new ValidationResult.ValidationResultBuilder();
    underTest.validate(subject, builder);
    assertValidationErrorIsEmpty(builder.build().getErrors());
    verify(platformResourceClientService, times(0)).getEncryptionKeys(anyString(), anyString());
}
Also used : AwsInstanceTemplateV4Parameters(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.parameter.template.AwsInstanceTemplateV4Parameters) ValidationResult(com.sequenceiq.cloudbreak.validation.ValidationResult) Test(org.junit.Test)

Example 5 with AwsInstanceTemplateV4Parameters

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.parameter.template.AwsInstanceTemplateV4Parameters in project cloudbreak by hortonworks.

the class StackAwsEncryptionValidatorTest method testValidateEncryptionKeyWhenEncryptionKeysCouldNotBeRetrievedThenThereIsNoEncryptionKeyCheck.

@Test
public void testValidateEncryptionKeyWhenEncryptionKeysCouldNotBeRetrievedThenThereIsNoEncryptionKeyCheck() {
    AwsInstanceTemplateV4Parameters parameters = new AwsInstanceTemplateV4Parameters();
    parameters.setEncryption(encryption(EncryptionType.CUSTOM, null));
    when(subject.getInstanceGroups()).thenReturn(getInstanceGroupWithRequest(createRequestWithParameters(parameters)));
    ValidationResult.ValidationResultBuilder builder = new ValidationResult.ValidationResultBuilder();
    underTest.validate(subject, builder);
    assertValidationErrorIsEmpty(builder.build().getErrors());
    verify(platformResourceClientService, times(1)).getEncryptionKeys(anyString(), anyString());
}
Also used : AwsInstanceTemplateV4Parameters(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.parameter.template.AwsInstanceTemplateV4Parameters) ValidationResult(com.sequenceiq.cloudbreak.validation.ValidationResult) Test(org.junit.Test)

Aggregations

AwsInstanceTemplateV4Parameters (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.parameter.template.AwsInstanceTemplateV4Parameters)15 AwsEncryptionV4Parameters (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.parameter.template.AwsEncryptionV4Parameters)5 ValidationResult (com.sequenceiq.cloudbreak.validation.ValidationResult)5 Test (org.junit.Test)5 AwsInstanceTemplateV1Parameters (com.sequenceiq.distrox.api.v1.distrox.model.instancegroup.template.AwsInstanceTemplateV1Parameters)3 DetailedEnvironmentResponse (com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse)3 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)3 AwsInstanceTemplateV4SpotParameters (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.parameter.template.AwsInstanceTemplateV4SpotParameters)2 Test (org.junit.jupiter.api.Test)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 InstanceTemplateV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.instancegroup.template.InstanceTemplateV4Request)1 ProviderParameterCalculator (com.sequenceiq.cloudbreak.common.mappable.ProviderParameterCalculator)1 AwsEnvironmentParameters (com.sequenceiq.environment.api.v1.environment.model.request.aws.AwsEnvironmentParameters)1 InstanceTemplateRequest (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.instance.InstanceTemplateRequest)1 VolumeRequest (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.instance.VolumeRequest)1 AwsInstanceTemplateParameters (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.instance.aws.AwsInstanceTemplateParameters)1 AwsInstanceTemplateSpotParameters (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.instance.aws.AwsInstanceTemplateSpotParameters)1 MethodSource (org.junit.jupiter.params.provider.MethodSource)1