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());
}
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");
}
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;
}
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;
}
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);
}
Aggregations