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

BDAP-2175 Added logs to debug vmtype availability and validation #7

Open
wants to merge 4 commits into
base: branch-2.7.2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Expand Up @@ -130,4 +130,13 @@ public Topology getTopology() {
public void setTopology(Topology topology) {
this.topology = topology;
}

@Override
public String toString() {
return "Credential{"
+ "id=" + id + ", name='" + name + '\'' + ", description='" + description + '\''
+ ", owner='" + owner + '\'' + ", account='" + account + '\'' + ", publicInAccount=" + publicInAccount
+ ", archived=" + archived + ", cloudPlatform='" + cloudPlatform + '\'' + ", attributes=" + attributes
+ ", topology=" + topology + '}';
}
}
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,7 @@

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

@Inject
private CloudParameterService cloudParameterService;
Expand All @@ -43,42 +48,59 @@ 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) {

private List<String> getVmTypes(Set<VmType> availableVmTypes) {
List vmTypes = new ArrayList();
for (VmType type : availableVmTypes) {
vmTypes.add(type.value());
}
return vmTypes;
}

public void validateTemplateRequest(Credential credential, Template template, String region, String availabilityZone, String variant) {
LOGGER.info("Josh and Toby's logging attempt 4. validateTemplateRequest is invoked");
LOGGER.error("SUDHAKAR -- HERE");
LOGGER.error("SUDHAKAR -- credential >" + credential + "< region >" + region + "< variant >" + variant);
CloudVmTypes cloudVmTypes = cloudParameterService.getVmTypesV2(credential, region, variant, new HashMap<>());

if (StringUtils.isEmpty(value.getInstanceType())) {
validateCustomInstanceType(value);
LOGGER.error("SUDHAKAR -- cloudVmTypes >" + cloudVmTypes);
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();
LOGGER.info("Checkpoint1 Validating %s for region %s and az %s".format(template.getInstanceType(), region, availabilityZone));
String locationString = locationService.location(region, availabilityZone);
LOGGER.info(locationString);
if (machines.containsKey(locationString) && !machines.get(locationString).isEmpty()) {
LOGGER.info("Checkpoint2 showing available types...");
LOGGER.info(String.join(" ", getVmTypes(machines.get(locationString))));
for (VmType type : machines.get(locationString)) {
if (type.value().equals(value.getInstanceType())) {
LOGGER.info("Checkpoint3");
if (type.value().equals(template.getInstanceType())) {
LOGGER.info("Checkpoint3 match");
vmType = type;
break;
}
}
LOGGER.info("Checkpoint4");
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", template.getVolumeType(), platform.value()));
}
}

validateVolume(value, vmType, platform, volumeParameterType);
validateVolume(template, vmType, platform, volumeParameterType);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ public StackResponse getStackForAmbari(AmbariAddressJson json) {

@Override
public Set<AutoscaleStackResponse> getAllForAutoscale() {
LOGGER.info("Josh and Toby's version is live and used on cloudbreak");
LOGGER.info("Get all stack, autoscale authorized only.");
return stackService.getAllForAutoscale();
}
Expand Down
5 changes: 5 additions & 0 deletions core/src/main/resources/logback.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,9 @@
<appender-ref ref="STDOUT"/>
</logger>

<logger name="com.sequenceiq.cloudbreak" level="INFO" additivity="false">
<appender-ref ref="CB_NODEID_BASED"/>
<appender-ref ref="STDOUT"/>
</logger>

</configuration>