Search in sources :

Example 1 with InstanceTemplateV1Request

use of com.sequenceiq.distrox.api.v1.distrox.model.instancegroup.template.InstanceTemplateV1Request in project cloudbreak by hortonworks.

the class RootVolumeSizeValidatorTest method tesIsValidWhenSizeIsNull.

@Test
public void tesIsValidWhenSizeIsNull() {
    InstanceTemplateV1Request templateV1Request = new InstanceTemplateV1Request();
    templateV1Request.setRootVolume(new RootVolumeV1Request());
    InstanceGroupV1Request value = new InstanceGroupV1Request();
    value.setTemplate(templateV1Request);
    boolean actual = underTest.isValid(value, null);
    Assertions.assertTrue(actual);
    verify(rootVolumeSizeProvider, never()).getForPlatform(any());
}
Also used : InstanceGroupV1Request(com.sequenceiq.distrox.api.v1.distrox.model.instancegroup.InstanceGroupV1Request) InstanceTemplateV1Request(com.sequenceiq.distrox.api.v1.distrox.model.instancegroup.template.InstanceTemplateV1Request) RootVolumeV1Request(com.sequenceiq.distrox.api.v1.distrox.model.instancegroup.template.volume.RootVolumeV1Request) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 2 with InstanceTemplateV1Request

use of com.sequenceiq.distrox.api.v1.distrox.model.instancegroup.template.InstanceTemplateV1Request in project cloudbreak by hortonworks.

the class RootVolumeSizeValidatorTest method testIsValid.

@ParameterizedTest
@MethodSource("isValidSource")
public void testIsValid(boolean valid, int size) {
    InstanceTemplateV1Request templateV1Request = new InstanceTemplateV1Request();
    templateV1Request.setAws(new AwsInstanceTemplateV1Parameters());
    RootVolumeV1Request rootVolume = new RootVolumeV1Request();
    rootVolume.setSize(size);
    templateV1Request.setRootVolume(rootVolume);
    ConstraintValidatorContext context = mock(ConstraintValidatorContext.class);
    ConstraintValidatorContext.ConstraintViolationBuilder builder = mock(ConstraintValidatorContext.ConstraintViolationBuilder.class);
    when(rootVolumeSizeProvider.getForPlatform("AWS")).thenReturn(10);
    if (!valid) {
        when(context.buildConstraintViolationWithTemplate("Group root volume (" + size + "GB) couldn't be less than 10GB")).thenReturn(builder);
    }
    InstanceGroupV1Request value = new InstanceGroupV1Request();
    value.setName("group");
    value.setTemplate(templateV1Request);
    boolean actual = underTest.isValid(value, context);
    Assertions.assertEquals(actual, valid);
    int times = valid ? 0 : 1;
    verify(context, times(times)).buildConstraintViolationWithTemplate("Group root volume (" + size + "GB) couldn't be less than 10GB");
}
Also used : InstanceGroupV1Request(com.sequenceiq.distrox.api.v1.distrox.model.instancegroup.InstanceGroupV1Request) InstanceTemplateV1Request(com.sequenceiq.distrox.api.v1.distrox.model.instancegroup.template.InstanceTemplateV1Request) ConstraintValidatorContext(javax.validation.ConstraintValidatorContext) AwsInstanceTemplateV1Parameters(com.sequenceiq.distrox.api.v1.distrox.model.instancegroup.template.AwsInstanceTemplateV1Parameters) RootVolumeV1Request(com.sequenceiq.distrox.api.v1.distrox.model.instancegroup.template.volume.RootVolumeV1Request) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 3 with InstanceTemplateV1Request

use of com.sequenceiq.distrox.api.v1.distrox.model.instancegroup.template.InstanceTemplateV1Request in project cloudbreak by hortonworks.

the class DistroXTestDto method withSpotPercentage.

public DistroXTestDto withSpotPercentage(int spotPercentage) {
    getRequest().getInstanceGroups().stream().map(InstanceGroupV1Request::getTemplate).forEach(instanceTemplateV1Request -> {
        AwsInstanceTemplateV1Parameters aws = instanceTemplateV1Request.getAws();
        if (Objects.isNull(aws)) {
            aws = new AwsInstanceTemplateV1Parameters();
            instanceTemplateV1Request.setAws(aws);
        }
        AwsInstanceTemplateV1SpotParameters spot = new AwsInstanceTemplateV1SpotParameters();
        spot.setPercentage(spotPercentage);
        aws.setSpot(spot);
    });
    return this;
}
Also used : AwsInstanceTemplateV1SpotParameters(com.sequenceiq.distrox.api.v1.distrox.model.instancegroup.template.AwsInstanceTemplateV1SpotParameters) AwsInstanceTemplateV1Parameters(com.sequenceiq.distrox.api.v1.distrox.model.instancegroup.template.AwsInstanceTemplateV1Parameters)

Example 4 with InstanceTemplateV1Request

use of com.sequenceiq.distrox.api.v1.distrox.model.instancegroup.template.InstanceTemplateV1Request in project cloudbreak by hortonworks.

the class InstanceTemplateV1ToInstanceTemplateV4Converter method convert.

public InstanceTemplateV4Request convert(InstanceTemplateV1Request source, DetailedEnvironmentResponse environment) {
    InstanceTemplateV4Request response = new InstanceTemplateV4Request();
    response.setRootVolume(getIfNotNull(source.getRootVolume(), volumeConverter::convert));
    response.setAttachedVolumes(getIfNotNull(source.getAttachedVolumes(), volumeConverter::convertTo));
    response.setEphemeralVolume(getIfNotNull(source.getEphemeralVolume(), volumeConverter::convert));
    response.setAws(getIfNotNull(source.getAws(), environment, instanceTemplateParameterConverter::convert));
    AzureInstanceTemplateV1Parameters azureParametersEffective = Objects.requireNonNullElse(source.getAzure(), new AzureInstanceTemplateV1Parameters());
    response.setAzure(instanceTemplateParameterConverter.convert(azureParametersEffective, environment));
    GcpInstanceTemplateV1Parameters gcpParametersEffective = Objects.requireNonNullElse(source.getGcp(), new GcpInstanceTemplateV1Parameters());
    response.setGcp(instanceTemplateParameterConverter.convert(gcpParametersEffective, environment));
    response.setYarn(getIfNotNull(source.getYarn(), instanceTemplateParameterConverter::convert));
    response.setCloudPlatform(source.getCloudPlatform());
    response.setInstanceType(source.getInstanceType());
    response.setTemporaryStorage(source.getTemporaryStorage());
    return response;
}
Also used : InstanceTemplateV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.instancegroup.template.InstanceTemplateV4Request) GcpInstanceTemplateV1Parameters(com.sequenceiq.distrox.api.v1.distrox.model.instancegroup.template.GcpInstanceTemplateV1Parameters) AzureInstanceTemplateV1Parameters(com.sequenceiq.distrox.api.v1.distrox.model.instancegroup.template.AzureInstanceTemplateV1Parameters)

Example 5 with InstanceTemplateV1Request

use of com.sequenceiq.distrox.api.v1.distrox.model.instancegroup.template.InstanceTemplateV1Request in project cloudbreak by hortonworks.

the class InstanceTemplateV1ToInstanceTemplateV4ConverterTest method convertTestInstanceTemplateV1RequestToInstanceTemplateV4RequestWhenMinimal.

@Test
void convertTestInstanceTemplateV1RequestToInstanceTemplateV4RequestWhenMinimal() {
    InstanceTemplateV1Request source = new InstanceTemplateV1Request();
    source.setAzure(null);
    source.setInstanceType(INSTANCE_TYPE);
    AzureInstanceTemplateV4Parameters azureInstanceTemplateV4Parameters = new AzureInstanceTemplateV4Parameters();
    when(instanceTemplateParameterConverter.convert(any(AzureInstanceTemplateV1Parameters.class), eq(environment))).thenReturn(azureInstanceTemplateV4Parameters);
    InstanceTemplateV4Request instanceTemplateV4Request = underTest.convert(source, environment);
    assertThat(instanceTemplateV4Request).isNotNull();
    assertThat(instanceTemplateV4Request.getRootVolume()).isNull();
    assertThat(instanceTemplateV4Request.getAzure()).isSameAs(azureInstanceTemplateV4Parameters);
    assertThat(instanceTemplateV4Request.getCloudPlatform()).isNull();
    assertThat(instanceTemplateV4Request.getInstanceType()).isEqualTo(INSTANCE_TYPE);
}
Also used : AzureInstanceTemplateV4Parameters(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.parameter.template.AzureInstanceTemplateV4Parameters) InstanceTemplateV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.instancegroup.template.InstanceTemplateV4Request) InstanceTemplateV1Request(com.sequenceiq.distrox.api.v1.distrox.model.instancegroup.template.InstanceTemplateV1Request) AzureInstanceTemplateV1Parameters(com.sequenceiq.distrox.api.v1.distrox.model.instancegroup.template.AzureInstanceTemplateV1Parameters) Test(org.junit.jupiter.api.Test)

Aggregations

InstanceTemplateV1Request (com.sequenceiq.distrox.api.v1.distrox.model.instancegroup.template.InstanceTemplateV1Request)11 Test (org.junit.jupiter.api.Test)6 InstanceTemplateV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.instancegroup.template.InstanceTemplateV4Request)5 InstanceGroupV1Request (com.sequenceiq.distrox.api.v1.distrox.model.instancegroup.InstanceGroupV1Request)5 RootVolumeV1Request (com.sequenceiq.distrox.api.v1.distrox.model.instancegroup.template.volume.RootVolumeV1Request)5 AzureInstanceTemplateV1Parameters (com.sequenceiq.distrox.api.v1.distrox.model.instancegroup.template.AzureInstanceTemplateV1Parameters)4 AzureInstanceTemplateV4Parameters (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.parameter.template.AzureInstanceTemplateV4Parameters)3 AwsInstanceTemplateV1Parameters (com.sequenceiq.distrox.api.v1.distrox.model.instancegroup.template.AwsInstanceTemplateV1Parameters)3 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)3 RootVolumeV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.instancegroup.template.volume.RootVolumeV4Request)2 AwsEncryptionV1Parameters (com.sequenceiq.distrox.api.v1.distrox.model.instancegroup.template.AwsEncryptionV1Parameters)1 AwsInstanceTemplateV1SpotParameters (com.sequenceiq.distrox.api.v1.distrox.model.instancegroup.template.AwsInstanceTemplateV1SpotParameters)1 GcpInstanceTemplateV1Parameters (com.sequenceiq.distrox.api.v1.distrox.model.instancegroup.template.GcpInstanceTemplateV1Parameters)1 ConstraintValidatorContext (javax.validation.ConstraintValidatorContext)1 MethodSource (org.junit.jupiter.params.provider.MethodSource)1