Search in sources :

Example 26 with DEFAULT

use of com.sequenceiq.cloudbreak.api.endpoint.v4.common.ResourceStatus.DEFAULT 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 27 with DEFAULT

use of com.sequenceiq.cloudbreak.api.endpoint.v4.common.ResourceStatus.DEFAULT 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)

Example 28 with DEFAULT

use of com.sequenceiq.cloudbreak.api.endpoint.v4.common.ResourceStatus.DEFAULT in project cloudbreak by hortonworks.

the class DistroXScaleTest method testCreateAndScaleDistroX.

@Test(dataProvider = TEST_CONTEXT, description = "Resilient Scaling: " + "UseCase1: " + "- Start upscale on running cluster " + "- Delete a non CM server host from provider other hostgroup during upscale " + "- Upscale should complete ")
@Description(given = "there is a running default Distrox cluster", when = "deleted a Compute instance while cluster was upscaling (by Worker nodes)", then = "cluster can be resiliently scaled up then down with higher node count")
public void testCreateAndScaleDistroX(TestContext testContext, ITestContext iTestContext) {
    DistroXScaleTestParameters params = new DistroXScaleTestParameters(iTestContext.getCurrentXmlTest().getAllParameters());
    if (params.getTimes() < 1) {
        throw new TestFailException("Test should execute at least 1 round of scaling");
    }
    StringBuilder instanceToStopId = new StringBuilder();
    testContext.given(DistroXTestDto.class).then((tc, testDto, client) -> {
        CloudFunctionality cloudFunctionality = tc.getCloudProvider().getCloudFunctionality();
        Optional<String> anInstanceToStop = distroxUtil.getInstanceIds(testDto, client, params.getHostGroup()).stream().findFirst();
        if (anInstanceToStop.isEmpty()) {
            throw new TestFailException(String.format("At least 1 instance needed from group %s to test stop it and test targeted upscale.", params.getIrrelevantHostGroup()));
        }
        cloudFunctionality.stopInstances(testDto.getName(), List.of(anInstanceToStop.get()));
        instanceToStopId.append(anInstanceToStop.get());
        return testDto;
    }).await(STACK_NODE_FAILURE).when(distroXTestClient.scale(params.getHostGroup(), params.getScaleUpTarget())).then((tc, testDto, client) -> {
        CloudFunctionality cloudFunctionality = tc.getCloudProvider().getCloudFunctionality();
        Optional<String> anInstanceToDelete = distroxUtil.getInstanceIds(testDto, client, params.getIrrelevantHostGroup()).stream().findFirst();
        if (anInstanceToDelete.isEmpty()) {
            throw new TestFailException(String.format("At least 1 instance needed from group %s to test delete it and test targeted upscale.", params.getIrrelevantHostGroup()));
        }
        cloudFunctionality.deleteInstances(testDto.getName(), List.of(anInstanceToDelete.get()));
        testDto.setInstanceIdsForActions(List.of(anInstanceToDelete.get()));
        return testDto;
    }).awaitForFlow().awaitForActionedInstances(DELETED_ON_PROVIDER_SIDE).then((tc, testDto, client) -> {
        testDto.setInstanceIdsForActions(mergeInstanceIdList(testDto.getInstanceIdsForAction(), instanceToStopId.toString()));
        return testDto;
    }).when(distroXTestClient.removeInstances()).awaitForFlow().when(distroXTestClient.scale(params.getHostGroup(), params.getScaleDownTarget())).awaitForFlow().validate();
    IntStream.range(1, params.getTimes()).forEach(i -> testContext.given(DistroXTestDto.class).when(distroXTestClient.scale(params.getHostGroup(), params.getScaleUpTarget())).awaitForFlow().when(distroXTestClient.scale(params.getHostGroup(), params.getScaleDownTarget())).awaitForFlow().validate());
}
Also used : IntStream(java.util.stream.IntStream) TestContext(com.sequenceiq.it.cloudbreak.context.TestContext) ITestContext(org.testng.ITestContext) Test(org.testng.annotations.Test) DELETED_ON_PROVIDER_SIDE(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus.DELETED_ON_PROVIDER_SIDE) DistroXTestDto(com.sequenceiq.it.cloudbreak.dto.distrox.DistroXTestDto) ArrayList(java.util.ArrayList) Description(com.sequenceiq.it.cloudbreak.context.Description) Inject(javax.inject.Inject) List(java.util.List) DistroXTestClient(com.sequenceiq.it.cloudbreak.client.DistroXTestClient) DistroxUtil(com.sequenceiq.it.cloudbreak.util.DistroxUtil) TestFailException(com.sequenceiq.it.cloudbreak.exception.TestFailException) CloudFunctionality(com.sequenceiq.it.cloudbreak.util.CloudFunctionality) Optional(java.util.Optional) AbstractE2ETest(com.sequenceiq.it.cloudbreak.testcase.e2e.AbstractE2ETest) Optional(java.util.Optional) CloudFunctionality(com.sequenceiq.it.cloudbreak.util.CloudFunctionality) TestFailException(com.sequenceiq.it.cloudbreak.exception.TestFailException) Description(com.sequenceiq.it.cloudbreak.context.Description) Test(org.testng.annotations.Test) AbstractE2ETest(com.sequenceiq.it.cloudbreak.testcase.e2e.AbstractE2ETest)

Example 29 with DEFAULT

use of com.sequenceiq.cloudbreak.api.endpoint.v4.common.ResourceStatus.DEFAULT in project cloudbreak by hortonworks.

the class SdxService method overrideDefaultTemplateValues.

private void overrideDefaultTemplateValues(StackV4Request defaultTemplate, List<SdxInstanceGroupRequest> customInstanceGroups) {
    if (CollectionUtils.isNotEmpty(customInstanceGroups)) {
        LOGGER.debug("Override default template with custom instance groups from request.");
        customInstanceGroups.forEach(customInstanceGroup -> {
            InstanceGroupV4Request templateInstanceGroup = defaultTemplate.getInstanceGroups().stream().filter(templateGroup -> templateGroup.getName() != null && templateGroup.getName().equals(customInstanceGroup.getName())).findAny().orElseThrow(() -> new BadRequestException("Custom instance group is missing from default template: " + customInstanceGroup.getName()));
            overrideInstanceType(templateInstanceGroup, customInstanceGroup.getInstanceType());
        });
    }
}
Also used : BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) InstanceGroupV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.instancegroup.InstanceGroupV4Request)

Aggregations

BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)13 List (java.util.List)10 StackV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request)8 Inject (javax.inject.Inject)7 Set (java.util.Set)6 Collectors (java.util.stream.Collectors)6 Logger (org.slf4j.Logger)6 LoggerFactory (org.slf4j.LoggerFactory)6 Service (org.springframework.stereotype.Service)6 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)5 Map (java.util.Map)5 Optional (java.util.Optional)5 Blueprint (com.sequenceiq.cloudbreak.domain.Blueprint)4 HashSet (java.util.HashSet)4 Sets (com.google.common.collect.Sets)3 ClusterV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.cluster.ClusterV4Request)3 Image (com.sequenceiq.cloudbreak.cloud.model.Image)3 Cluster (com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster)3 BlueprintService (com.sequenceiq.cloudbreak.service.blueprint.BlueprintService)3 Workspace (com.sequenceiq.cloudbreak.workspace.model.Workspace)3