use of com.sequenceiq.cloudbreak.domain.VolumeTemplate in project cloudbreak by hortonworks.
the class EmbeddedDatabaseService method calculateVolumeCountOnGatewayGroup.
private int calculateVolumeCountOnGatewayGroup(Stack stack) {
Optional<InstanceGroup> gatewayGroup = stack.getInstanceGroups().stream().filter(ig -> ig.getInstanceGroupType() == InstanceGroupType.GATEWAY).findFirst();
Template template = gatewayGroup.map(InstanceGroup::getTemplate).orElse(null);
return template == null ? 0 : template.getVolumeTemplates().stream().filter(volumeTemplate -> volumeTemplate.getUsageType() == VolumeUsageType.DATABASE).mapToInt(VolumeTemplate::getVolumeCount).sum();
}
use of com.sequenceiq.cloudbreak.domain.VolumeTemplate in project cloudbreak by hortonworks.
the class StackDecorator method setupDatabaseAttachedVolume.
private void setupDatabaseAttachedVolume(Stack subject, InstanceGroup instanceGroup, Template template) {
InstanceGroupType instanceGroupType = instanceGroup.getInstanceGroupType();
if (instanceGroupType == InstanceGroupType.GATEWAY && embeddedDatabaseService.isEmbeddedDatabaseOnAttachedDiskEnabled(subject, subject.getCluster())) {
String databaseVolumeType = embeddedDatabaseConfig.getPlatformVolumeType(subject.cloudPlatform()).orElseThrow(() -> new BadRequestException(String.format("If embedded db is enabled on attached disk, database volumetype" + " have to be defined for cloudprovider in app config! Missing database volumetype on %s provider", subject.cloudPlatform())));
VolumeTemplate databaseVolumeTemplate = new VolumeTemplate();
databaseVolumeTemplate.setUsageType(VolumeUsageType.DATABASE);
databaseVolumeTemplate.setVolumeSize(embeddedDatabaseConfig.getSize());
databaseVolumeTemplate.setVolumeCount(1);
databaseVolumeTemplate.setVolumeType(databaseVolumeType);
databaseVolumeTemplate.setTemplate(template);
template.getVolumeTemplates().add(databaseVolumeTemplate);
LOGGER.debug("Extra disk is attached with {} type and {}GB size for the embedded database.", databaseVolumeTemplate.getVolumeType(), databaseVolumeTemplate.getVolumeSize());
} else {
if (instanceGroupType == InstanceGroupType.GATEWAY) {
LOGGER.debug("No extra disk will be attached to the gateway instance as db volume because it is disabled or external database is used.");
} else {
LOGGER.debug("No extra disk will be attached to the instance as db volume because it is CORE instance.");
}
}
}
use of com.sequenceiq.cloudbreak.domain.VolumeTemplate in project cloudbreak by hortonworks.
the class TemplateDecorator method decorate.
public Template decorate(Credential credential, Template template, String region, String availabilityZone, String variant, CdpResourceType cdpResourceType) {
setRootVolumeSize(template);
boolean needToFetchVolumeCountAndSize = template.getVolumeTemplates().stream().anyMatch(it -> it.getVolumeCount() == null || it.getVolumeSize() == null);
if (needToFetchVolumeCountAndSize) {
LOGGER.info("We need to fetch the VM types. Perhaps the client does not provide the volume count or size");
CloudVmTypes vmTypesV2 = cloudParameterService.getVmTypesV2(extendedCloudCredentialConverter.convert(credential), region, variant, cdpResourceType, new HashMap<>());
String locationString = locationService.location(region, availabilityZone);
PlatformDisks platformDisks = cloudParameterService.getDiskTypes();
for (VolumeTemplate volumeTemplate : template.getVolumeTemplates()) {
VolumeParameterConfig config;
try {
config = resolveVolumeParameterConfig(template, volumeTemplate, platformDisks, vmTypesV2, locationString);
} catch (NoSuchElementException ignored) {
LOGGER.debug("No VolumeParameterConfig found, which might be normal for platforms like YARN");
config = VolumeParameterConfig.EMPTY;
}
if (config.volumeParameterType() != null) {
if (volumeTemplate.getVolumeCount() == null) {
volumeTemplate.setVolumeCount(config.maximumNumber());
}
if (volumeTemplate.getVolumeSize() == null) {
volumeTemplate.setVolumeSize(config.maximumSize());
}
}
}
}
return template;
}
use of com.sequenceiq.cloudbreak.domain.VolumeTemplate in project cloudbreak by hortonworks.
the class InstanceTemplateValidatorTest method testValidateShouldAddValidationErrorWhenTheNumberOfVolumesIsMoreThanTheSupportedAndOnlyOneVolumeTemplateExists.
@Test
void testValidateShouldAddValidationErrorWhenTheNumberOfVolumesIsMoreThanTheSupportedAndOnlyOneVolumeTemplateExists() {
String instanceTemplateName = "anInstanceTemplate";
int volumeCount = 200;
VolumeTemplate volumeTemplate = new VolumeTemplate();
volumeTemplate.setVolumeCount(volumeCount);
Template instanceTemplate = new Template();
instanceTemplate.setName(instanceTemplateName);
instanceTemplate.setVolumeTemplates(Set.of(volumeTemplate));
ValidationResult result = underTest.validate(instanceTemplate);
Assertions.assertNotNull(result);
Assertions.assertTrue(result.hasError());
String expectedMessage = String.format(InstanceTemplateValidator.INVALID_NUMBER_OF_VOLUMES_MESSAGE_PATTERN, VolumeParameterConstants.MAXIMUM_NUMBER_OF_VOLUMES, instanceTemplateName, volumeCount);
Assertions.assertTrue(result.getErrors().contains(expectedMessage));
}
use of com.sequenceiq.cloudbreak.domain.VolumeTemplate in project cloudbreak by hortonworks.
the class InstanceTemplateValidatorTest method testValidateShouldNotAddValidationErrorWhenTheNumberOfVolumesIsLessThanTheMaximumSupportedOneVolumeTemplateExists.
@Test
void testValidateShouldNotAddValidationErrorWhenTheNumberOfVolumesIsLessThanTheMaximumSupportedOneVolumeTemplateExists() {
VolumeTemplate volumeTemplate = new VolumeTemplate();
volumeTemplate.setVolumeCount(20);
Template instanceTemplate = new Template();
instanceTemplate.setVolumeTemplates(Set.of(volumeTemplate));
ValidationResult result = underTest.validate(instanceTemplate);
Assertions.assertNotNull(result);
Assertions.assertFalse(result.hasError());
}
Aggregations