Search in sources :

Example 1 with Platform

use of com.sequenceiq.cloudbreak.cloud.model.Platform in project cloudbreak by hortonworks.

the class TemplateDecoratorTest method testDecoratorWhenNoInstanceType.

@Test
public void testDecoratorWhenNoInstanceType() {
    String vmType = "vmType";
    String platform1 = "platform";
    String volumeType = "volumeType";
    String region = "region";
    String availibilityZone = "availabilityZone";
    String variant = "variant";
    Credential cloudCredential = mock(Credential.class);
    Template template = new Template();
    template.setInstanceType("missingVmType");
    template.setCloudPlatform(platform1);
    template.setVolumeType(volumeType);
    Platform platform = Platform.platform(platform1);
    int minimumSize = 10;
    int maximumSize = 100;
    int minimumNumber = 1;
    int maximumNumber = 5;
    VolumeParameterConfig config = new VolumeParameterConfig(VolumeParameterType.MAGNETIC, minimumSize, maximumSize, minimumNumber, maximumNumber);
    VmTypeMeta vmTypeMeta = new VmTypeMeta();
    vmTypeMeta.setMagneticConfig(config);
    Map<Platform, Map<String, VolumeParameterType>> diskMappings = newHashMap();
    diskMappings.put(platform, singletonMap(volumeType, VolumeParameterType.MAGNETIC));
    PlatformDisks platformDisk = new PlatformDisks(emptyMap(), emptyMap(), diskMappings, emptyMap());
    CloudVmTypes cloudVmTypes = new CloudVmTypes();
    Map<String, Set<VmType>> region1 = singletonMap(region, Collections.singleton(VmType.vmTypeWithMeta(vmType, vmTypeMeta, true)));
    cloudVmTypes.setCloudVmResponses(region1);
    when(cloudParameterService.getDiskTypes()).thenReturn(platformDisk);
    when(cloudParameterService.getVmTypesV2(eq(cloudCredential), eq(region), eq(variant), anyMap())).thenReturn(cloudVmTypes);
    when(locationService.location(region, availibilityZone)).thenReturn(region);
    Template actual = underTest.decorate(cloudCredential, template, region, availibilityZone, variant);
    Assert.assertNull(actual.getVolumeCount());
    Assert.assertNull(actual.getVolumeSize());
}
Also used : VmTypeMeta(com.sequenceiq.cloudbreak.cloud.model.VmTypeMeta) Credential(com.sequenceiq.cloudbreak.domain.Credential) Collections.emptySet(java.util.Collections.emptySet) Set(java.util.Set) Platform(com.sequenceiq.cloudbreak.cloud.model.Platform) PlatformDisks(com.sequenceiq.cloudbreak.cloud.model.PlatformDisks) VolumeParameterConfig(com.sequenceiq.cloudbreak.cloud.model.VolumeParameterConfig) Template(com.sequenceiq.cloudbreak.domain.Template) CloudVmTypes(com.sequenceiq.cloudbreak.cloud.model.CloudVmTypes) Map(java.util.Map) Collections.singletonMap(java.util.Collections.singletonMap) Collections.emptyMap(java.util.Collections.emptyMap) Maps.newHashMap(com.google.common.collect.Maps.newHashMap) Matchers.anyMap(org.mockito.Matchers.anyMap) Test(org.junit.Test)

Example 2 with Platform

use of com.sequenceiq.cloudbreak.cloud.model.Platform in project cloudbreak by hortonworks.

the class TemplateValidator method validateCustomInstanceType.

private void validateCustomInstanceType(Template template) {
    Map<String, Object> params = template.getAttributes().getMap();
    Platform platform = Platform.platform(template.cloudPlatform());
    PlatformParameters pps = platformParameters.get().get(platform);
    if (pps != null) {
        Boolean customInstanceType = pps.specialParameters().getSpecialParameters().get(PlatformParametersConsts.CUSTOM_INSTANCETYPE);
        if (BooleanUtils.isTrue(customInstanceType)) {
            if (params.get(PlatformParametersConsts.CUSTOM_INSTANCETYPE_CPUS) == null || params.get(PlatformParametersConsts.CUSTOM_INSTANCETYPE_MEMORY) == null) {
                throw new BadRequestException(String.format("Missing 'cpus' or 'memory' param for custom instancetype on %s platform", template.cloudPlatform()));
            }
        } else {
            throw new BadRequestException(String.format("Custom instancetype is not supported on %s platform", template.cloudPlatform()));
        }
    }
}
Also used : Platform(com.sequenceiq.cloudbreak.cloud.model.Platform) PlatformParameters(com.sequenceiq.cloudbreak.cloud.PlatformParameters) BadRequestException(com.sequenceiq.cloudbreak.controller.BadRequestException)

Example 3 with Platform

use of com.sequenceiq.cloudbreak.cloud.model.Platform in project cloudbreak by hortonworks.

the class TemplateValidator method validateTemplateRequest.

public void validateTemplateRequest(Credential credential, Template value, String region, String availabilityZone, String variant) {
    CloudVmTypes cloudVmTypes = cloudParameterService.getVmTypesV2(credential, region, variant, new HashMap<>());
    if (StringUtils.isEmpty(value.getInstanceType())) {
        validateCustomInstanceType(value);
    } else {
        VmType vmType = null;
        VolumeParameterType volumeParameterType = null;
        Platform platform = Platform.platform(value.cloudPlatform());
        Map<String, Set<VmType>> machines = cloudVmTypes.getCloudVmResponses();
        String locationString = locationService.location(region, availabilityZone);
        if (machines.containsKey(locationString) && !machines.get(locationString).isEmpty()) {
            for (VmType type : machines.get(locationString)) {
                if (type.value().equals(value.getInstanceType())) {
                    vmType = type;
                    break;
                }
            }
            if (vmType == null) {
                throw new BadRequestException(String.format("The '%s' instance type isn't supported by '%s' platform", value.getInstanceType(), platform.value()));
            }
        }
        Map<Platform, Map<String, VolumeParameterType>> disks = diskMappings.get();
        if (disks.containsKey(platform) && !disks.get(platform).isEmpty()) {
            Map<String, VolumeParameterType> map = disks.get(platform);
            volumeParameterType = map.get(value.getVolumeType());
            if (volumeParameterType == null) {
                throw new BadRequestException(String.format("The '%s' volume type isn't supported by '%s' platform", value.getVolumeType(), platform.value()));
            }
        }
        validateVolume(value, vmType, platform, volumeParameterType);
    }
}
Also used : CloudVmTypes(com.sequenceiq.cloudbreak.cloud.model.CloudVmTypes) Set(java.util.Set) Platform(com.sequenceiq.cloudbreak.cloud.model.Platform) VmType(com.sequenceiq.cloudbreak.cloud.model.VmType) VolumeParameterType(com.sequenceiq.cloudbreak.cloud.model.VolumeParameterType) BadRequestException(com.sequenceiq.cloudbreak.controller.BadRequestException) HashMap(java.util.HashMap) Map(java.util.Map)

Example 4 with Platform

use of com.sequenceiq.cloudbreak.cloud.model.Platform in project cloudbreak by hortonworks.

the class AbstractInstanceConnector method start.

@Override
public List<CloudVmInstanceStatus> start(AuthenticatedContext ac, List<CloudResource> resources, List<CloudInstance> vms) {
    CloudContext cloudContext = ac.getCloudContext();
    Platform platform = cloudContext.getPlatform();
    // context
    ResourceBuilderContext context = contextBuilders.get(platform).contextInit(cloudContext, ac, null, resources, true);
    // compute
    return computeResourceService.startInstances(context, ac, resources, vms);
}
Also used : Platform(com.sequenceiq.cloudbreak.cloud.model.Platform) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) ResourceBuilderContext(com.sequenceiq.cloudbreak.cloud.template.context.ResourceBuilderContext)

Example 5 with Platform

use of com.sequenceiq.cloudbreak.cloud.model.Platform in project cloudbreak by hortonworks.

the class AbstractResourceConnector method update.

@Override
public List<CloudResourceStatus> update(AuthenticatedContext auth, CloudStack stack, List<CloudResource> resources) throws Exception {
    CloudContext cloudContext = auth.getCloudContext();
    Platform platform = cloudContext.getPlatform();
    // context
    ResourceBuilderContext context = contextBuilders.get(platform).contextInit(cloudContext, auth, stack.getNetwork(), resources, true);
    // group
    List<CloudResource> groupResources = groupResourceService.getGroupResources(platform, resources);
    List<CloudResourceStatus> groupStatuses = groupResourceService.update(context, auth, stack.getNetwork(), stack.getCloudSecurity(), groupResources);
    // network
    List<CloudResource> networkResources = networkResourceService.getNetworkResources(platform, resources);
    List<CloudResourceStatus> networkStatuses = networkResourceService.update(context, auth, stack.getNetwork(), stack.getCloudSecurity(), networkResources);
    groupStatuses.addAll(networkStatuses);
    return groupStatuses;
}
Also used : Platform(com.sequenceiq.cloudbreak.cloud.model.Platform) CloudResourceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) ResourceBuilderContext(com.sequenceiq.cloudbreak.cloud.template.context.ResourceBuilderContext) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource)

Aggregations

Platform (com.sequenceiq.cloudbreak.cloud.model.Platform)26 CloudContext (com.sequenceiq.cloudbreak.cloud.context.CloudContext)7 ResourceBuilderContext (com.sequenceiq.cloudbreak.cloud.template.context.ResourceBuilderContext)7 Map (java.util.Map)7 PlatformDisks (com.sequenceiq.cloudbreak.cloud.model.PlatformDisks)6 HashMap (java.util.HashMap)6 CloudVmTypes (com.sequenceiq.cloudbreak.cloud.model.CloudVmTypes)5 Collection (java.util.Collection)5 PlatformParameters (com.sequenceiq.cloudbreak.cloud.PlatformParameters)4 CloudResourceStatus (com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus)4 BadRequestException (com.sequenceiq.cloudbreak.controller.BadRequestException)4 Set (java.util.Set)4 CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)3 Maps.newHashMap (com.google.common.collect.Maps.newHashMap)2 SpecialParameters (com.sequenceiq.cloudbreak.api.model.SpecialParameters)2 SpecialParametersJson (com.sequenceiq.cloudbreak.api.model.SpecialParametersJson)2 DiskType (com.sequenceiq.cloudbreak.cloud.model.DiskType)2 DiskTypes (com.sequenceiq.cloudbreak.cloud.model.DiskTypes)2 PlatformOrchestrators (com.sequenceiq.cloudbreak.cloud.model.PlatformOrchestrators)2 Region (com.sequenceiq.cloudbreak.cloud.model.Region)2