Search in sources :

Example 1 with TagsV4Request

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.tags.TagsV4Request in project cloudbreak by hortonworks.

the class DistroXV1RequestToStackV4RequestConverter method getTags.

private TagsV4Request getTags(TagsV1Request source) {
    TagsV4Request response = new TagsV4Request();
    response.setApplication(source.getApplication());
    response.setUserDefined(source.getUserDefined());
    response.setDefaults(source.getDefaults());
    return response;
}
Also used : TagsV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.tags.TagsV4Request)

Example 2 with TagsV4Request

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.tags.TagsV4Request 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 3 with TagsV4Request

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.tags.TagsV4Request in project cloudbreak by hortonworks.

the class StackRequestManifester method setupStackRequestForCloudbreak.

private StackV4Request setupStackRequestForCloudbreak(SdxCluster sdxCluster, DetailedEnvironmentResponse environment) {
    try {
        LOGGER.info("Setting up stack request of SDX {} for cloudbreak", sdxCluster.getClusterName());
        StackV4Request stackRequest = JsonUtil.readValue(sdxCluster.getStackRequest(), StackV4Request.class);
        stackRequest.setName(sdxCluster.getClusterName());
        stackRequest.setType(StackType.DATALAKE);
        if (stackRequest.getTags() == null) {
            Map<String, String> userDefined = environment.getTags().getUserDefined();
            TagsV4Request tags = new TagsV4Request();
            try {
                Map<String, String> sdxUserDefined = new HashMap<>();
                // TODO currently the sdx app is putting 'null' if the user send us a null this is now fixed but we need to support old DL's
                if (sdxCluster.getTags() != null && !Strings.isNullOrEmpty(sdxCluster.getTags().getValue()) && !"null".equals(sdxCluster.getTags().getValue())) {
                    sdxUserDefined = sdxCluster.getTags().get(HashMap.class);
                }
                userDefined.putAll(sdxUserDefined);
                tags.setUserDefined(userDefined);
            } catch (IOException e) {
                LOGGER.error("Can not parse JSON to tags");
                throw new BadRequestException("Can not parse JSON to tags", e);
            }
            stackRequest.setTags(tags);
        }
        stackRequest.setEnvironmentCrn(sdxCluster.getEnvCrn());
        if (CloudPlatform.YARN.name().equals(environment.getCloudPlatform())) {
            setupYarnDetails(environment, stackRequest);
        }
        setupAuthentication(environment, stackRequest);
        setupSecurityAccess(environment, stackRequest);
        setupClusterRequest(stackRequest);
        prepareTelemetryForStack(stackRequest, environment, sdxCluster);
        setupCloudStorageAccountMapping(stackRequest, environment.getCrn(), environment.getIdBrokerMappingSource(), environment.getCloudPlatform());
        validateCloudStorage(sdxCluster, environment, stackRequest);
        setupInstanceVolumeEncryption(stackRequest, environment);
        setupGovCloud(sdxCluster, environment, stackRequest);
        setupMultiAz(sdxCluster, environment, stackRequest);
        return stackRequest;
    } catch (IOException e) {
        LOGGER.error("Can not parse JSON to stack request");
        throw new IllegalStateException("Can not parse JSON to stack request", e);
    }
}
Also used : StackV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request) HashMap(java.util.HashMap) TagsV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.tags.TagsV4Request) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) IOException(java.io.IOException)

Example 4 with TagsV4Request

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.tags.TagsV4Request in project cloudbreak by hortonworks.

the class DistroXV1RequestToStackV4RequestConverterTest method testWhenTagsProvidedTheyWillBePassedForStackConversion.

@Test
void testWhenTagsProvidedTheyWillBePassedForStackConversion() {
    when(databaseRequestConverter.convert(any(DatabaseRequest.class))).thenReturn(createDistroXDatabaseRequest());
    StackV4Request source = new StackV4Request();
    source.setName("stackname");
    DatabaseRequest databaseRequest = new DatabaseRequest();
    databaseRequest.setAvailabilityType(DatabaseAvailabilityType.HA);
    source.setExternalDatabase(databaseRequest);
    TagsV4Request tags = createTagsV4Request();
    source.setTags(tags);
    DistroXV1Request result = underTest.convert(source);
    assertThat(result.getExternalDatabase()).isNotNull();
    assertThat(result.getExternalDatabase().getAvailabilityType()).isEqualTo(DistroXDatabaseAvailabilityType.HA);
    checkTagsV4WithV1(tags, result.getTags());
}
Also used : StackV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request) DatabaseRequest(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.database.DatabaseRequest) DistroXDatabaseRequest(com.sequenceiq.distrox.api.v1.distrox.model.database.DistroXDatabaseRequest) TagsV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.tags.TagsV4Request) DistroXV1Request(com.sequenceiq.distrox.api.v1.distrox.model.DistroXV1Request) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 5 with TagsV4Request

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.tags.TagsV4Request in project cloudbreak by hortonworks.

the class StackV4RequestToStackConverter method getTags.

private Json getTags(StackV4Request source, DetailedEnvironmentResponse environment) {
    try {
        TagsV4Request tags = source.getTags();
        if (tags == null) {
            Map<String, String> userDefined = environment == null || environment.getTags() == null ? new HashMap<>() : environment.getTags().getUserDefined();
            return new Json(new StackTags(userDefined, new HashMap<>(), new HashMap<>()));
        }
        Map<String, String> userDefined = new HashMap<>();
        if (environment != null && environment.getTags() != null && environment.getTags().getUserDefined() != null && !environment.getTags().getUserDefined().isEmpty()) {
            userDefined = environment.getTags().getUserDefined();
        }
        CDPTagMergeRequest request = CDPTagMergeRequest.Builder.builder().withPlatform(source.getCloudPlatform().name()).withRequestTags(tags.getUserDefined() != null ? tags.getUserDefined() : Maps.newHashMap()).withEnvironmentTags(userDefined).build();
        return new Json(new StackTags(costTagging.mergeTags(request), tags.getApplication(), new HashMap<>()));
    } catch (Exception e) {
        throw new BadRequestException("Failed to convert dynamic tags. " + e.getMessage(), e);
    }
}
Also used : StackTags(com.sequenceiq.cloudbreak.cloud.model.StackTags) CDPTagMergeRequest(com.sequenceiq.cloudbreak.tag.request.CDPTagMergeRequest) HashMap(java.util.HashMap) TagsV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.tags.TagsV4Request) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) Json(com.sequenceiq.cloudbreak.common.json.Json) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) IOException(java.io.IOException)

Aggregations

TagsV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.tags.TagsV4Request)6 IOException (java.io.IOException)3 StackV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request)2 StackTags (com.sequenceiq.cloudbreak.cloud.model.StackTags)2 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)2 HashMap (java.util.HashMap)2 DatabaseRequest (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.database.DatabaseRequest)1 Json (com.sequenceiq.cloudbreak.common.json.Json)1 CDPTagMergeRequest (com.sequenceiq.cloudbreak.tag.request.CDPTagMergeRequest)1 DistroXV1Request (com.sequenceiq.distrox.api.v1.distrox.model.DistroXV1Request)1 DistroXDatabaseRequest (com.sequenceiq.distrox.api.v1.distrox.model.database.DistroXDatabaseRequest)1 Test (org.junit.jupiter.api.Test)1 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1