Skip to content
This repository has been archived by the owner on Jan 8, 2024. It is now read-only.

Commit

Permalink
Added logs to debug vmtype availability and validation
Browse files Browse the repository at this point in the history
  • Loading branch information
ronso-rage committed Oct 16, 2020
1 parent 11b4bf0 commit 1e02c23
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.sequenceiq.cloudbreak.cloud.model.generic.StringType;

public class VmType extends StringType {
private String vmType;

private VmTypeMeta metaData;

Expand All @@ -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) {
Expand Down Expand Up @@ -53,7 +55,8 @@ public boolean isMetaSet() {
@Override
public String toString() {
return "VmType{"
+ "metaData=" + metaData
+ "vmType=" + vmType
+ ", metaData=" + metaData
+ ", extended=" + extended
+ '}';
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, String> 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<String, Set<VmType>> cloudVmResponses = new HashMap<>();
Map<String, VmType> defaultCloudVmResponses = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand All @@ -30,6 +34,9 @@

@Component
public class TemplateValidator {
private static final Logger LOGGER = LoggerFactory.getLogger(TemplateValidator.class);

private List<String> convenientLogs = new ArrayList<>();

@Inject
private CloudParameterService cloudParameterService;
Expand All @@ -43,42 +50,54 @@ public class TemplateValidator {
private final Supplier<Map<Platform, PlatformParameters>> 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<String, Set<VmType>> 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<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());
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);
}
}

Expand Down

0 comments on commit 1e02c23

Please sign in to comment.