diff --git a/cloud-api/src/main/java/com/sequenceiq/cloudbreak/cloud/model/VmType.java b/cloud-api/src/main/java/com/sequenceiq/cloudbreak/cloud/model/VmType.java index c464d6155101..7d0be29b2f9c 100644 --- a/cloud-api/src/main/java/com/sequenceiq/cloudbreak/cloud/model/VmType.java +++ b/cloud-api/src/main/java/com/sequenceiq/cloudbreak/cloud/model/VmType.java @@ -3,6 +3,7 @@ import com.sequenceiq.cloudbreak.cloud.model.generic.StringType; public class VmType extends StringType { + private String vmType; private VmTypeMeta metaData; @@ -16,6 +17,7 @@ private VmType(String vmType, VmTypeMeta meta, Boolean extended) { super(vmType); metaData = meta; this.extended = extended; + this.vmType = vmType; } public static VmType vmType(String vmType) { @@ -53,7 +55,8 @@ public boolean isMetaSet() { @Override public String toString() { return "VmType{" - + "metaData=" + metaData + + "vmType=" + vmType + + ", metaData=" + metaData + ", extended=" + extended + '}'; } diff --git a/cloud-aws/src/main/java/com/sequenceiq/cloudbreak/cloud/aws/AwsPlatformResources.java b/cloud-aws/src/main/java/com/sequenceiq/cloudbreak/cloud/aws/AwsPlatformResources.java index 0e6ed0033a03..98442df1c083 100644 --- a/cloud-aws/src/main/java/com/sequenceiq/cloudbreak/cloud/aws/AwsPlatformResources.java +++ b/cloud-aws/src/main/java/com/sequenceiq/cloudbreak/cloud/aws/AwsPlatformResources.java @@ -350,7 +350,9 @@ public CloudRegions regions(CloudCredential cloudCredential, Region region, Map< @Override @Cacheable(cacheNames = "cloudResourceVmTypeCache", key = "#cloudCredential?.id + #region.getRegionName()") public CloudVmTypes virtualMachines(CloudCredential cloudCredential, Region region, Map filters) { + LOGGER.info("CloudCredential(id=%s, name=%s)".format(cloudCredential.getId().toString(), cloudCredential.getName())); CloudRegions regions = regions(cloudCredential, region, filters); + LOGGER.info("CloudRegions regions: %s".format(regions.toString())); Map> cloudVmResponses = new HashMap<>(); Map defaultCloudVmResponses = new HashMap<>(); diff --git a/core/src/main/java/com/sequenceiq/cloudbreak/controller/validation/template/TemplateValidator.java b/core/src/main/java/com/sequenceiq/cloudbreak/controller/validation/template/TemplateValidator.java index 6fbbfe619efe..c7f51957b83f 100644 --- a/core/src/main/java/com/sequenceiq/cloudbreak/controller/validation/template/TemplateValidator.java +++ b/core/src/main/java/com/sequenceiq/cloudbreak/controller/validation/template/TemplateValidator.java @@ -1,7 +1,9 @@ package com.sequenceiq.cloudbreak.controller.validation.template; +import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; +import java.util.List; import java.util.Map; import java.util.Set; import java.util.function.Supplier; @@ -10,6 +12,8 @@ import org.apache.commons.lang3.BooleanUtils; import org.apache.commons.lang3.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.stereotype.Component; import com.google.common.base.Suppliers; @@ -30,6 +34,9 @@ @Component public class TemplateValidator { + private static final Logger LOGGER = LoggerFactory.getLogger(TemplateValidator.class); + + private List convenientLogs = new ArrayList<>(); @Inject private CloudParameterService cloudParameterService; @@ -43,42 +50,54 @@ public class TemplateValidator { private final Supplier> platformParameters = Suppliers.memoize(() -> cloudParameterService.getPlatformParameters()); - public void validateTemplateRequest(Credential credential, Template value, String region, String availabilityZone, String variant) { - + public void validateTemplateRequest(Credential credential, Template template, String region, String availabilityZone, String variant) { + String debugMsg = null; CloudVmTypes cloudVmTypes = cloudParameterService.getVmTypesV2(credential, region, variant, new HashMap<>()); - if (StringUtils.isEmpty(value.getInstanceType())) { - validateCustomInstanceType(value); + if (StringUtils.isEmpty(template.getInstanceType())) { + validateCustomInstanceType(template); } else { VmType vmType = null; VolumeParameterType volumeParameterType = null; - Platform platform = Platform.platform(value.cloudPlatform()); + Platform platform = Platform.platform(template.cloudPlatform()); Map> machines = cloudVmTypes.getCloudVmResponses(); + machines.forEach((k, v) -> { + String debugMsgLambda = "%s region/az has %d different vmtypes: %s".format(k, v.size(), v.toString()); + LOGGER.info(debugMsgLambda); + convenientLogs.add(debugMsgLambda); + }); String locationString = locationService.location(region, availabilityZone); + debugMsg = "Current region or az; locationService.location(region=%s, availabilityZone%s)=%s".format(region, availabilityZone, locationString); + LOGGER.info(debugMsg); + convenientLogs.add(debugMsg); if (machines.containsKey(locationString) && !machines.get(locationString).isEmpty()) { for (VmType type : machines.get(locationString)) { - if (type.value().equals(value.getInstanceType())) { + debugMsg = "template vmtype: %s available vmtype %s in this az/region".format(type.value(), template.getInstanceType()); + LOGGER.info(debugMsg); + convenientLogs.add(debugMsg); + if (type.value().equals(template.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())); + String.format("The '%s' instance type isn't supported by '%s' platform", template.getInstanceType(), platform.value())); } } Map> disks = diskMappings.get(); if (disks.containsKey(platform) && !disks.get(platform).isEmpty()) { Map map = disks.get(platform); - volumeParameterType = map.get(value.getVolumeType()); + volumeParameterType = map.get(template.getVolumeType()); if (volumeParameterType == null) { throw new BadRequestException( - String.format("The '%s' volume type isn't supported by '%s' platform", value.getVolumeType(), platform.value())); + String.format("The '%s' volume type isn't supported by '%s' platform\n%s", + template.getVolumeType(), platform.value(), String.join("\n", convenientLogs))); } } - validateVolume(value, vmType, platform, volumeParameterType); + validateVolume(template, vmType, platform, volumeParameterType); } }