Search in sources :

Example 16 with DEFAULT

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

the class ResourceStatusConverterTest method testConvertToEntityAttributeWhenDefaultIsReturnAsDefault.

@Test
public void testConvertToEntityAttributeWhenDefaultIsReturnAsDefault() {
    ResourceStatus resourceStatus = resourceStatusConverter.convertToEntityAttribute("DEFAULT");
    Assert.assertEquals(ResourceStatus.DEFAULT, resourceStatus);
}
Also used : ResourceStatus(com.sequenceiq.cloudbreak.api.endpoint.v4.common.ResourceStatus) Test(org.junit.Test)

Example 17 with DEFAULT

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

the class SdxServiceTest method testCreateSdxClusterWithCustomRequestContainsImageInfo.

@Test
void testCreateSdxClusterWithCustomRequestContainsImageInfo() throws Exception {
    ImageV4Response imageResponse = getImageResponse();
    when(transactionService.required(isA(Supplier.class))).thenAnswer(invocation -> invocation.getArgument(0, Supplier.class).get());
    String lightDutyJson = FileReaderUtils.readFileFromClasspath("/duties/7.2.7/aws/light_duty.json");
    when(cdpConfigService.getConfigForKey(any())).thenReturn(JsonUtil.readValue(lightDutyJson, StackV4Request.class));
    SdxCustomClusterRequest sdxClusterRequest = createSdxCustomClusterRequest(LIGHT_DUTY, "cdp-default", "imageId_1");
    setSpot(sdxClusterRequest);
    withCloudStorage(sdxClusterRequest);
    when(imageCatalogService.getImageResponseFromImageRequest(eq(sdxClusterRequest.getImageSettingsV4Request()), any())).thenReturn(imageResponse);
    long id = 10L;
    when(sdxClusterRepository.save(any(SdxCluster.class))).thenAnswer(invocation -> {
        SdxCluster sdxWithId = invocation.getArgument(0, SdxCluster.class);
        sdxWithId.setId(id);
        return sdxWithId;
    });
    mockEnvironmentCall(sdxClusterRequest, CloudPlatform.AWS, null);
    Pair<SdxCluster, FlowIdentifier> result = ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.createSdx(USER_CRN, CLUSTER_NAME, sdxClusterRequest));
    SdxCluster createdSdxCluster = result.getLeft();
    StackV4Request stackV4Request = JsonUtil.readValue(createdSdxCluster.getStackRequest(), StackV4Request.class);
    assertNotNull(stackV4Request.getImage());
    assertEquals("cdp-default", stackV4Request.getImage().getCatalog());
    assertEquals("imageId_1", stackV4Request.getImage().getId());
}
Also used : SdxCustomClusterRequest(com.sequenceiq.sdx.api.model.SdxCustomClusterRequest) StackV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request) ImageV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.imagecatalog.responses.ImageV4Response) SdxCluster(com.sequenceiq.datalake.entity.SdxCluster) Supplier(java.util.function.Supplier) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) FlowIdentifier(com.sequenceiq.flow.api.model.FlowIdentifier) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Test(org.junit.jupiter.api.Test)

Example 18 with DEFAULT

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

the class SdxRecommendationServiceTest method validateVmTypeOverrideWhenInstanceGroupIsMissingFromDefaultTemplate.

@Test
public void validateVmTypeOverrideWhenInstanceGroupIsMissingFromDefaultTemplate() {
    when(cdpConfigService.getConfigForKey(any())).thenReturn(createStackRequest());
    when(environmentClientService.getVmTypesByCredential(anyString(), anyString(), anyString(), eq(CdpResourceType.DATALAKE), any())).thenReturn(createPlatformVmtypesResponse());
    StackV4Request stackRequest = createStackRequest();
    stackRequest.getInstanceGroups().get(0).setName("unknown");
    SdxCluster sdxCluster = createSdxCluster(stackRequest, LIGHT_DUTY);
    BadRequestException badRequestException = assertThrows(BadRequestException.class, () -> underTest.validateVmTypeOverride(createEnvironment("AWS"), sdxCluster));
    assertEquals("Instance group is missing from default template: unknown", badRequestException.getMessage());
}
Also used : StackV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request) SdxCluster(com.sequenceiq.datalake.entity.SdxCluster) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) Test(org.junit.jupiter.api.Test)

Example 19 with DEFAULT

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

the class DefaultBlueprintCache method loadBlueprintsFromFile.

@PostConstruct
public void loadBlueprintsFromFile() {
    Map<String, Set<String>> blueprints = blueprints();
    for (Map.Entry<String, Set<String>> blueprintEntry : blueprints.entrySet()) {
        try {
            for (String blueprintText : blueprintEntry.getValue()) {
                String[] split = blueprintText.trim().split("=");
                if (blueprintUtils.isBlueprintNamePreConfigured(blueprintText, split)) {
                    LOGGER.debug("Load default validation '{}'.", AnonymizerUtil.anonymize(blueprintText));
                    BlueprintV4Request blueprintJson = new BlueprintV4Request();
                    blueprintJson.setName(split[0].trim());
                    JsonNode jsonNode = blueprintUtils.convertStringToJsonNode(blueprintUtils.readDefaultBlueprintFromFile(blueprintEntry.getKey(), split));
                    JsonNode blueprintNode = jsonNode.get("blueprint");
                    blueprintJson.setBlueprint(blueprintNode.toString());
                    Blueprint bp = converter.convert(blueprintJson);
                    JsonNode tags = jsonNode.get("tags");
                    Map<String, Object> tagParameters = blueprintUtils.prepareTags(tags);
                    bp.setTags(new Json(tagParameters));
                    JsonNode description = jsonNode.get("description");
                    bp.setDescription(description == null ? split[0] : description.asText(split[0]));
                    JsonNode blueprintUpgradeOption = blueprintNode.isMissingNode() ? null : blueprintNode.get("blueprintUpgradeOption");
                    bp.setBlueprintUpgradeOption(getBlueprintUpgradeOption(blueprintUpgradeOption));
                    BlueprintFile bpf = new BlueprintFile.Builder().name(bp.getName()).blueprintText(bp.getBlueprintText()).stackName(bp.getStackName()).stackVersion(bp.getStackVersion()).stackType(bp.getStackType()).blueprintUpgradeOption(bp.getBlueprintUpgradeOption()).hostGroupCount(bp.getHostGroupCount()).description(bp.getDescription()).build();
                    defaultBlueprints.put(bp.getName(), bpf);
                }
            }
        } catch (IOException e) {
            LOGGER.error("Can not read default validation from file: ", e);
        }
    }
}
Also used : Set(java.util.Set) Blueprint(com.sequenceiq.cloudbreak.domain.Blueprint) JsonNode(com.fasterxml.jackson.databind.JsonNode) Json(com.sequenceiq.cloudbreak.common.json.Json) IOException(java.io.IOException) BlueprintV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.blueprint.requests.BlueprintV4Request) BlueprintFile(com.sequenceiq.cloudbreak.domain.BlueprintFile) HashMap(java.util.HashMap) Map(java.util.Map) PostConstruct(javax.annotation.PostConstruct)

Example 20 with DEFAULT

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

the class DefaultClusterTemplateCache method convertToClusterTemplate.

private void convertToClusterTemplate(String templateAsString) throws IOException {
    DefaultClusterTemplateV4Request clusterTemplateRequest = new Json(templateAsString).get(DefaultClusterTemplateV4Request.class);
    if (defaultClusterTemplates.get(clusterTemplateRequest.getName()) != null) {
        LOGGER.warn("Default cluster template exists and it will be override: {}", clusterTemplateRequest.getName());
    }
    defaultClusterTemplates.put(clusterTemplateRequest.getName(), Base64.getEncoder().encodeToString(templateAsString.getBytes()));
}
Also used : DefaultClusterTemplateV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.clustertemplate.requests.DefaultClusterTemplateV4Request) Json(com.sequenceiq.cloudbreak.common.json.Json)

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