Search in sources :

Example 11 with DEFAULT

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

the class DistroXV1RequestToStackV4RequestConverterTest method createTagsV4Request.

private TagsV4Request createTagsV4Request() {
    TagsV4Request r = new TagsV4Request();
    r.setUserDefined(Map.of("apple", "tree"));
    r.setDefaults(Map.of("default", "fruit"));
    r.setApplication(Map.of("peach", "tree"));
    return r;
}
Also used : TagsV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.tags.TagsV4Request)

Example 12 with DEFAULT

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

the class SdxRecommendationServiceTest method validateVmTypeOverrideWhenDefaultVmTypeIsMissingFromAvailableVmTypes.

@Test
public void validateVmTypeOverrideWhenDefaultVmTypeIsMissingFromAvailableVmTypes() {
    StackV4Request defaultTemplate = createStackRequest();
    defaultTemplate.getInstanceGroups().get(0).getTemplate().setInstanceType("unknown");
    when(cdpConfigService.getConfigForKey(any())).thenReturn(defaultTemplate);
    when(environmentClientService.getVmTypesByCredential(anyString(), anyString(), anyString(), eq(CdpResourceType.DATALAKE), any())).thenReturn(createPlatformVmtypesResponse());
    BadRequestException badRequestException = assertThrows(BadRequestException.class, () -> underTest.validateVmTypeOverride(createEnvironment("AWS"), createSdxCluster(createStackRequest(), LIGHT_DUTY)));
    assertEquals("Missing vm type for default template instance group: master - unknown", badRequestException.getMessage());
}
Also used : StackV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) Test(org.junit.jupiter.api.Test)

Example 13 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, String accountId) {
    if (isCustomInstanceTypeSelected(customInstanceGroups) && !entitlementService.isDatalakeSelectInstanceTypeEnabled(accountId)) {
        throw new BadRequestException("Datalake instance type selection is not enabled! " + "Contact Cloudera support to enable CDP_DATALAKE_SELECT_INSTANCE_TYPE entitlement for the account.");
    }
    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)

Example 14 with DEFAULT

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

the class ImageCatalogService method getImageResponseFromImageRequest.

public ImageV4Response getImageResponseFromImageRequest(ImageSettingsV4Request imageSettingsV4Request, CloudPlatform cloudPlatform) {
    String accountId = ThreadBasedUserCrnProvider.getAccountId();
    if (imageSettingsV4Request == null) {
        return null;
    }
    ImageCatalogV4Endpoint imageCatalogV4Endpoint = cloudbreakInternalCrnClient.withInternalCrn().imageCatalogV4Endpoint();
    try {
        LOGGER.info("Calling cloudbreak to get image response for the given image catalog {} and image id {}", imageSettingsV4Request.getCatalog(), imageSettingsV4Request.getId());
        ImagesV4Response imagesV4Response = null;
        try {
            if (StringUtils.isBlank(imageSettingsV4Request.getCatalog())) {
                imagesV4Response = imageCatalogV4Endpoint.getImageByImageId(SdxService.WORKSPACE_ID_DEFAULT, imageSettingsV4Request.getId(), accountId);
            } else {
                imagesV4Response = imageCatalogV4Endpoint.getImageByCatalogNameAndImageId(SdxService.WORKSPACE_ID_DEFAULT, imageSettingsV4Request.getCatalog(), imageSettingsV4Request.getId(), accountId);
            }
        } catch (Exception e) {
            LOGGER.error("Sdx service fails to get image using image id", e);
        }
        if (imagesV4Response == null) {
            return null;
        }
        for (ImageV4Response imageV4Response : imagesV4Response.getCdhImages()) {
            // find the image can be used on the cloud platform of the environment
            if (imageV4Response.getImageSetsByProvider() != null) {
                if (imageV4Response.getImageSetsByProvider().containsKey(cloudPlatform.name().toLowerCase())) {
                    return imageV4Response;
                }
            }
        }
        String errorMessage = String.format("SDX cluster is on the cloud platform %s, but the image requested with uuid %s:%s does not support it", cloudPlatform.name(), imageSettingsV4Request.getCatalog() != null ? imageSettingsV4Request.getCatalog() : "default", imageSettingsV4Request.getId());
        LOGGER.error(errorMessage);
        return null;
    } catch (javax.ws.rs.NotFoundException e) {
        LOGGER.info("Sdx cluster not found on CB side", e);
        return null;
    }
}
Also used : ImageCatalogV4Endpoint(com.sequenceiq.cloudbreak.api.endpoint.v4.imagecatalog.ImageCatalogV4Endpoint) ImageV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.imagecatalog.responses.ImageV4Response) ImagesV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.imagecatalog.responses.ImagesV4Response) CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException)

Example 15 with DEFAULT

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

the class TestUtil method stack.

public static Stack stack(Status stackStatus, Credential credential) {
    User user = new User();
    user.setUserId("horton@hortonworks.com");
    user.setUserCrn("testCrn");
    user.setUserName("Alma ur");
    Workspace workspace = new Workspace();
    workspace.setId(1L);
    Tenant tenant = new Tenant();
    tenant.setName("testtenant");
    workspace.setTenant(tenant);
    Stack stack = new Stack();
    stack.setCreator(user);
    stack.setWorkspace(workspace);
    stack.setStackStatus(new StackStatus(stack, stackStatus, "statusReason", DetailedStackStatus.UNKNOWN));
    stack.setName("simplestack");
    stack.setId(1L);
    stack.setInstanceGroups(generateGcpInstanceGroups(3));
    stack.setRegion("region");
    stack.setCreated(123L);
    stack.setCloudPlatform(credential.cloudPlatform());
    stack.setOrchestrator(orchestrator());
    stack.setEnvironmentCrn("envCrn");
    stack.setResourceCrn("crn:cdp:cloudbreak:us-west-1:someone:stack:12345");
    switch(credential.cloudPlatform()) {
        case AWS:
            stack.setInstanceGroups(generateAwsInstanceGroups(3));
            break;
        case GCP:
            stack.setInstanceGroups(generateGcpInstanceGroups(3));
            break;
        default:
            break;
    }
    stack.setSecurityConfig(new SecurityConfig());
    return stack;
}
Also used : CloudbreakUser(com.sequenceiq.cloudbreak.common.user.CloudbreakUser) User(com.sequenceiq.cloudbreak.workspace.model.User) Tenant(com.sequenceiq.cloudbreak.workspace.model.Tenant) SecurityConfig(com.sequenceiq.cloudbreak.domain.SecurityConfig) StackStatus(com.sequenceiq.cloudbreak.domain.stack.StackStatus) DetailedStackStatus(com.sequenceiq.cloudbreak.api.endpoint.v4.common.DetailedStackStatus) Workspace(com.sequenceiq.cloudbreak.workspace.model.Workspace) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack)

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