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