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;
}
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;
}
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);
}
}
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());
}
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);
}
}
Aggregations