Search in sources :

Example 1 with ClusterTemplateV4Response

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;
}
Also used : ClusterTemplateV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.clustertemplate.responses.ClusterTemplateV4Response) StackV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request) DefaultClusterTemplateV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.clustertemplate.requests.DefaultClusterTemplateV4Request) Json(com.sequenceiq.cloudbreak.common.json.Json) IOException(java.io.IOException) IOException(java.io.IOException) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack)

Example 2 with 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());
    }
}
Also used : ClusterTemplateV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.clustertemplate.responses.ClusterTemplateV4Response) ClusterTemplate(com.sequenceiq.cloudbreak.domain.stack.cluster.ClusterTemplate) TransactionExecutionException(com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionExecutionException) CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException) CheckPermissionByResourceName(com.sequenceiq.authorization.annotation.CheckPermissionByResourceName)

Example 3 with ClusterTemplateV4Response

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!");
    }
}
Also used : ClusterTemplateV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.clustertemplate.responses.ClusterTemplateV4Response) ClusterTemplate(com.sequenceiq.cloudbreak.domain.stack.cluster.ClusterTemplate) TransactionExecutionException(com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionExecutionException) CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException) CheckPermissionByResourceCrn(com.sequenceiq.authorization.annotation.CheckPermissionByResourceCrn)

Example 4 with ClusterTemplateV4Response

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;
}
Also used : ClusterTemplateV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.clustertemplate.responses.ClusterTemplateV4Response)

Aggregations

ClusterTemplateV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.clustertemplate.responses.ClusterTemplateV4Response)4 CloudbreakServiceException (com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException)2 TransactionExecutionException (com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionExecutionException)2 ClusterTemplate (com.sequenceiq.cloudbreak.domain.stack.cluster.ClusterTemplate)2 CheckPermissionByResourceCrn (com.sequenceiq.authorization.annotation.CheckPermissionByResourceCrn)1 CheckPermissionByResourceName (com.sequenceiq.authorization.annotation.CheckPermissionByResourceName)1 DefaultClusterTemplateV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.clustertemplate.requests.DefaultClusterTemplateV4Request)1 StackV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request)1 Json (com.sequenceiq.cloudbreak.common.json.Json)1 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)1 IOException (java.io.IOException)1