Search in sources :

Example 1 with VolumeTemplate

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();
}
Also used : Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) StringUtils(org.apache.commons.lang3.StringUtils) Template(com.sequenceiq.cloudbreak.domain.Template) InstanceGroupType(com.sequenceiq.common.api.type.InstanceGroupType) Inject(javax.inject.Inject) VolumeTemplate(com.sequenceiq.cloudbreak.domain.VolumeTemplate) Component(org.springframework.stereotype.Component) DatabaseAvailabilityType(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.database.DatabaseAvailabilityType) ObjectUtils(org.apache.commons.lang3.ObjectUtils) Optional(java.util.Optional) CloudParameterCache(com.sequenceiq.cloudbreak.service.stack.CloudParameterCache) InstanceGroup(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup) VolumeUsageType(com.sequenceiq.cloudbreak.domain.VolumeUsageType) VolumeTemplate(com.sequenceiq.cloudbreak.domain.VolumeTemplate) InstanceGroup(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup) Template(com.sequenceiq.cloudbreak.domain.Template) VolumeTemplate(com.sequenceiq.cloudbreak.domain.VolumeTemplate)

Example 2 with VolumeTemplate

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.");
        }
    }
}
Also used : InstanceGroupType(com.sequenceiq.common.api.type.InstanceGroupType) VolumeTemplate(com.sequenceiq.cloudbreak.domain.VolumeTemplate) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException)

Example 3 with VolumeTemplate

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;
}
Also used : CloudVmTypes(com.sequenceiq.cloudbreak.cloud.model.CloudVmTypes) VolumeTemplate(com.sequenceiq.cloudbreak.domain.VolumeTemplate) PlatformDisks(com.sequenceiq.cloudbreak.cloud.model.PlatformDisks) VolumeParameterConfig(com.sequenceiq.cloudbreak.cloud.model.VolumeParameterConfig) NoSuchElementException(java.util.NoSuchElementException)

Example 4 with VolumeTemplate

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));
}
Also used : VolumeTemplate(com.sequenceiq.cloudbreak.domain.VolumeTemplate) ValidationResult(com.sequenceiq.cloudbreak.validation.ValidationResult) VolumeTemplate(com.sequenceiq.cloudbreak.domain.VolumeTemplate) Template(com.sequenceiq.cloudbreak.domain.Template) Test(org.junit.jupiter.api.Test)

Example 5 with VolumeTemplate

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());
}
Also used : VolumeTemplate(com.sequenceiq.cloudbreak.domain.VolumeTemplate) ValidationResult(com.sequenceiq.cloudbreak.validation.ValidationResult) VolumeTemplate(com.sequenceiq.cloudbreak.domain.VolumeTemplate) Template(com.sequenceiq.cloudbreak.domain.Template) Test(org.junit.jupiter.api.Test)

Aggregations

VolumeTemplate (com.sequenceiq.cloudbreak.domain.VolumeTemplate)37 Template (com.sequenceiq.cloudbreak.domain.Template)24 Test (org.junit.jupiter.api.Test)19 InstanceGroup (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup)6 HostgroupView (com.sequenceiq.cloudbreak.template.views.HostgroupView)6 StackContext (com.sequenceiq.cloudbreak.core.flow2.stack.StackContext)5 HashSet (java.util.HashSet)5 ApiClusterTemplateConfig (com.cloudera.api.swagger.model.ApiClusterTemplateConfig)4 CloudVmTypes (com.sequenceiq.cloudbreak.cloud.model.CloudVmTypes)4 Platform (com.sequenceiq.cloudbreak.cloud.model.Platform)4 PlatformDisks (com.sequenceiq.cloudbreak.cloud.model.PlatformDisks)4 ValidationResult (com.sequenceiq.cloudbreak.validation.ValidationResult)4 Map (java.util.Map)4 VolumeParameterConfig (com.sequenceiq.cloudbreak.cloud.model.VolumeParameterConfig)3 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)3 Collections.emptySet (java.util.Collections.emptySet)3 Set (java.util.Set)3 Maps.newHashMap (com.google.common.collect.Maps.newHashMap)2 VmTypeMeta (com.sequenceiq.cloudbreak.cloud.model.VmTypeMeta)2 VolumeParameterType (com.sequenceiq.cloudbreak.cloud.model.VolumeParameterType)2