use of com.sequenceiq.cloudbreak.api.endpoint.v4.clustertemplate.responses.ClusterTemplateV4Response in project cloudbreak by hortonworks.
the class ClusterTemplateToClusterTemplateV4ResponseConverter method convert.
public ClusterTemplateV4Response convert(ClusterTemplate source) {
ClusterTemplateV4Response clusterTemplateV4Response = new ClusterTemplateV4Response();
clusterTemplateV4Response.setName(source.getName());
clusterTemplateV4Response.setDescription(source.getDescription());
if (source.getStatus().isNonDefault()) {
Optional<Stack> stack = stackTemplateService.getByIdWithLists(source.getStackTemplate().getId());
if (stack.isPresent()) {
StackV4Request stackV4Request;
try {
stackV4Request = stackToStackV4RequestConverter.convert(stack.get());
} catch (Exception e) {
stackV4Request = null;
}
clusterTemplateV4Response.setDistroXTemplate(getIfNotNull(stackV4Request, stackV4RequestConverter::convert));
clusterTemplateV4Response.setNodeCount(stack.get().getFullNodeCount());
}
} else {
try {
DefaultClusterTemplateV4Request clusterTemplateV4Request = new Json(getTemplateString(source)).get(DefaultClusterTemplateV4Request.class);
clusterTemplateV4Response.setDistroXTemplate(clusterTemplateV4Request.getDistroXTemplate());
clusterTemplateV4Response.setNodeCount(getFullNodeCount(clusterTemplateV4Request.getDistroXTemplate()));
} catch (IOException e) {
LOGGER.info("There is no Data Hub template (stack entity missing) for cluster defintion {}", source.getName());
clusterTemplateV4Response.setDistroXTemplate(null);
}
}
clusterTemplateV4Response.setCloudPlatform(source.getCloudPlatform());
clusterTemplateV4Response.setStatus(source.getStatus());
clusterTemplateV4Response.setId(source.getId());
clusterTemplateV4Response.setDatalakeRequired(source.getDatalakeRequired());
clusterTemplateV4Response.setCrn(source.getResourceCrn());
clusterTemplateV4Response.setStatus(source.getStatus());
clusterTemplateV4Response.setType(source.getType());
clusterTemplateV4Response.setFeatureState(source.getFeatureState());
if (source.getStackTemplate() != null) {
Stack stackTemplate = source.getStackTemplate();
if (stackTemplate.getEnvironmentCrn() != null) {
clusterTemplateV4Response.setEnvironmentCrn(stackTemplate.getEnvironmentCrn());
}
if (source.getStackTemplate().getCluster() != null && source.getStackTemplate().getCluster().getBlueprint() != null) {
clusterTemplateV4Response.setStackType(source.getStackTemplate().getCluster().getBlueprint().getStackType());
clusterTemplateV4Response.setStackVersion(source.getStackTemplate().getCluster().getBlueprint().getStackVersion());
}
} else {
clusterTemplateV4Response.setStackType("CDH");
clusterTemplateV4Response.setStackVersion(source.getClouderaRuntimeVersion());
}
clusterTemplateV4Response.setCreated(source.getCreated());
return clusterTemplateV4Response;
}
use of com.sequenceiq.cloudbreak.api.endpoint.v4.clustertemplate.responses.ClusterTemplateV4Response in project cloudbreak by hortonworks.
the class ClusterTemplateV4Controller method getByName.
@Override
@CheckPermissionByResourceName(action = AuthorizationResourceAction.DESCRIBE_CLUSTER_DEFINITION)
public ClusterTemplateV4Response getByName(Long workspaceId, @ResourceName String name) {
try {
ClusterTemplate clusterTemplate = transactionService.required(() -> clusterTemplateService.getByNameForWorkspaceId(name, threadLocalService.getRequestedWorkspaceId()));
ClusterTemplateV4Response response = transactionService.required(() -> clusterTemplateToClusterTemplateV4ResponseConverter.convert(clusterTemplate));
Optional.ofNullable(response.getEnvironmentCrn()).ifPresent(crn -> environmentServiceDecorator.prepareEnvironment(response));
return response;
} catch (TransactionExecutionException cse) {
LOGGER.warn("Unable to find cluster definition due to " + cse.getMessage(), cse.getCause());
throw new CloudbreakServiceException("Unable to obtain cluster definition!", cse.getCause());
}
}
use of com.sequenceiq.cloudbreak.api.endpoint.v4.clustertemplate.responses.ClusterTemplateV4Response in project cloudbreak by hortonworks.
the class ClusterTemplateV4Controller method getByCrn.
@Override
@CheckPermissionByResourceCrn(action = AuthorizationResourceAction.DESCRIBE_CLUSTER_DEFINITION)
public ClusterTemplateV4Response getByCrn(Long workspaceId, @TenantAwareParam @ResourceCrn String crn) {
boolean internalTenant = isInternalTenant();
try {
ClusterTemplate clusterTemplate = transactionService.required(() -> clusterTemplateService.getByCrn(crn, threadLocalService.getRequestedWorkspaceId(), internalTenant));
ClusterTemplateV4Response response = transactionService.required(() -> clusterTemplateToClusterTemplateV4ResponseConverter.convert(clusterTemplate));
if (!StringUtils.isEmpty(response.getEnvironmentCrn())) {
environmentServiceDecorator.prepareEnvironment(response);
} else {
LOGGER.warn("Skipping response decoration with environment name. Environment CRN was empty.");
}
return response;
} catch (TransactionExecutionException cse) {
LOGGER.warn("Unable to find cluster definition due to {}", cse.getMessage());
throw new CloudbreakServiceException("Unable to obtain cluster definition!");
}
}
use of com.sequenceiq.cloudbreak.api.endpoint.v4.clustertemplate.responses.ClusterTemplateV4Response in project cloudbreak by hortonworks.
the class ClusterTemplateGetAction method action.
@Override
public ClusterTemplateTestDto action(TestContext testContext, ClusterTemplateTestDto testDto, CloudbreakClient client) throws Exception {
Log.when(LOGGER, " ClusterTemplateEntity get request: " + testDto.getName());
ClusterTemplateV4Response response = client.getDefaultClient().clusterTemplateV4EndPoint().getByName(client.getWorkspaceId(), testDto.getName());
testDto.setResponses(Sets.newHashSet(response));
Log.whenJson(LOGGER, " ClusterTemplateEntity get call was successful:\n", response);
return testDto;
}
Aggregations