Search in sources :

Example 1 with VmTypeResponse

use of com.sequenceiq.sdx.api.model.VmTypeResponse in project cloudbreak by hortonworks.

the class SdxRecommendationService method getAvailableVmTypes.

private List<VmTypeResponse> getAvailableVmTypes(String credentialCrn, String cloudPlatform, String region, String availabilityZone) {
    PlatformVmtypesResponse platformVmtypesResponse = environmentClientService.getVmTypesByCredential(credentialCrn, region, cloudPlatform, CdpResourceType.DATALAKE, availabilityZone);
    Set<com.sequenceiq.environment.api.v1.platformresource.model.VmTypeResponse> vmTypes = Collections.emptySet();
    if (platformVmtypesResponse.getVmTypes() != null && StringUtils.isNotBlank(availabilityZone)) {
        vmTypes = platformVmtypesResponse.getVmTypes().get(availabilityZone).getVirtualMachines();
    } else if (platformVmtypesResponse.getVmTypes() != null && !platformVmtypesResponse.getVmTypes().isEmpty()) {
        vmTypes = platformVmtypesResponse.getVmTypes().values().iterator().next().getVirtualMachines();
    }
    return vmTypeConverter.convert(vmTypes);
}
Also used : VmTypeResponse(com.sequenceiq.sdx.api.model.VmTypeResponse) PlatformVmtypesResponse(com.sequenceiq.environment.api.v1.platformresource.model.PlatformVmtypesResponse)

Example 2 with VmTypeResponse

use of com.sequenceiq.sdx.api.model.VmTypeResponse in project cloudbreak by hortonworks.

the class SdxRecommendationService method validateVmTypeOverride.

public void validateVmTypeOverride(DetailedEnvironmentResponse environment, SdxCluster sdxCluster) {
    try {
        LOGGER.debug("Validate vm type override for sdx cluster: {}", sdxCluster.getCrn());
        String cloudPlatform = environment.getCloudPlatform();
        if (shouldValidateVmTypes(sdxCluster, cloudPlatform)) {
            StackV4Request stackV4Request = JsonUtil.readValue(sdxCluster.getStackRequest(), StackV4Request.class);
            StackV4Request defaultTemplate = getDefaultTemplate(sdxCluster.getClusterShape(), sdxCluster.getRuntime(), cloudPlatform);
            String region = environment.getRegions().getNames().stream().findFirst().orElse(null);
            List<VmTypeResponse> availableVmTypes = getAvailableVmTypes(environment.getCredential().getCrn(), cloudPlatform, region, null);
            Map<String, VmTypeResponse> defaultVmTypesByInstanceGroup = getDefaultVmTypesByInstanceGroup(availableVmTypes, defaultTemplate);
            Map<String, List<String>> availableVmTypeNamesByInstanceGroup = filterAvailableVmTypeNamesBasedOnDefault(availableVmTypes, defaultVmTypesByInstanceGroup);
            stackV4Request.getInstanceGroups().forEach(instanceGroup -> {
                if (!defaultVmTypesByInstanceGroup.containsKey(instanceGroup.getName())) {
                    String message = "Instance group is missing from default template: " + instanceGroup.getName();
                    LOGGER.warn(message);
                    throw new BadRequestException(message);
                }
                VmTypeResponse defaultTemplateVmType = defaultVmTypesByInstanceGroup.get(instanceGroup.getName());
                if (isCustomInstanceTypeProvided(instanceGroup, defaultTemplateVmType.getValue()) && !isProvidedInstanceTypeIsAvailable(availableVmTypeNamesByInstanceGroup, instanceGroup)) {
                    String message = String.format("Invalid custom instance type for instance group: %s - %s", instanceGroup.getName(), instanceGroup.getTemplate().getInstanceType());
                    LOGGER.warn(message);
                    throw new BadRequestException(message);
                }
            });
        }
    } catch (NotFoundException | BadRequestException e) {
        throw e;
    } catch (Exception e) {
        LOGGER.warn("Validate VM type override failed!", e);
        throw new RuntimeException("Validate VM type override failed: " + e.getMessage());
    }
}
Also used : VmTypeResponse(com.sequenceiq.sdx.api.model.VmTypeResponse) StackV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException) List(java.util.List) NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException)

Example 3 with VmTypeResponse

use of com.sequenceiq.sdx.api.model.VmTypeResponse in project cloudbreak by hortonworks.

the class SdxRecommendationService method getRecommendation.

public SdxRecommendationResponse getRecommendation(String credentialCrn, SdxClusterShape clusterShape, String runtimeVersion, String cloudPlatform, String region, String availabilityZone) {
    try {
        StackV4Request defaultTemplate = getDefaultTemplate(clusterShape, runtimeVersion, cloudPlatform);
        List<VmTypeResponse> availableVmTypes = getAvailableVmTypes(credentialCrn, cloudPlatform, region, availabilityZone);
        Map<String, VmTypeResponse> defaultVmTypesByInstanceGroup = getDefaultVmTypesByInstanceGroup(availableVmTypes, defaultTemplate);
        Map<String, List<VmTypeResponse>> availableVmTypesByInstanceGroup = filterAvailableVmTypesBasedOnDefault(availableVmTypes, defaultVmTypesByInstanceGroup);
        LOGGER.debug("Return default template and available vm types for clusterShape: {}, " + "runtimeVersion: {}, cloudPlatform: {}, region: {}, availabilityZone: {}", clusterShape, runtimeVersion, cloudPlatform, region, availabilityZone);
        return new SdxRecommendationResponse(defaultTemplate, availableVmTypesByInstanceGroup);
    } catch (NotFoundException | BadRequestException e) {
        throw e;
    } catch (Exception e) {
        LOGGER.warn("Getting recommendation failed!", e);
        throw new RuntimeException("Getting recommendation failed: " + e.getMessage());
    }
}
Also used : NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException) NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) VmTypeResponse(com.sequenceiq.sdx.api.model.VmTypeResponse) StackV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request) SdxRecommendationResponse(com.sequenceiq.sdx.api.model.SdxRecommendationResponse) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) List(java.util.List)

Aggregations

VmTypeResponse (com.sequenceiq.sdx.api.model.VmTypeResponse)3 StackV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request)2 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)2 NotFoundException (com.sequenceiq.cloudbreak.common.exception.NotFoundException)2 List (java.util.List)2 PlatformVmtypesResponse (com.sequenceiq.environment.api.v1.platformresource.model.PlatformVmtypesResponse)1 SdxRecommendationResponse (com.sequenceiq.sdx.api.model.SdxRecommendationResponse)1