Search in sources :

Example 1 with StatusCheckResult

use of com.sequenceiq.cloudbreak.saas.sdx.status.StatusCheckResult in project cloudbreak by hortonworks.

the class DistroXService method validate.

private void validate(DistroXV1Request request) {
    DetailedEnvironmentResponse environment = Optional.ofNullable(environmentClientService.getByName(request.getEnvironmentName())).orElseThrow(() -> new BadRequestException("No environment name provided hence unable to obtain some important data"));
    if (environment == null) {
        throw new BadRequestException(format("'%s' Environment does not exist.", request.getEnvironmentName()));
    }
    DescribeFreeIpaResponse freeipa = freeipaClientService.getByEnvironmentCrn(environment.getCrn());
    if (freeipa == null || freeipa.getAvailabilityStatus() == null || !freeipa.getAvailabilityStatus().isAvailable()) {
        throw new BadRequestException(format("If you want to provision a Data Hub then the FreeIPA instance must be running in the '%s' Environment.", environment.getName()));
    }
    Set<String> sdxCrns = platformAwareSdxConnector.listSdxCrns(environment.getName(), environment.getCrn());
    if (sdxCrns.isEmpty()) {
        throw new BadRequestException(format("Data Lake stack cannot be found for environment CRN: %s (%s)", environment.getName(), environment.getCrn()));
    }
    Set<Pair<String, StatusCheckResult>> sdxCrnsWithAvailability = platformAwareSdxConnector.listSdxCrnsWithAvailability(environment.getName(), environment.getCrn(), sdxCrns);
    if (!sdxCrnsWithAvailability.stream().map(Pair::getValue).allMatch(statusCheckResult -> StatusCheckResult.AVAILABLE.equals(statusCheckResult))) {
        throw new BadRequestException("Data Lake stacks of environment should be available.");
    }
}
Also used : StackOperations(com.sequenceiq.distrox.v1.distrox.StackOperations) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) StatusCheckResult(com.sequenceiq.cloudbreak.saas.sdx.status.StatusCheckResult) Set(java.util.Set) WorkspaceService(com.sequenceiq.cloudbreak.service.workspace.WorkspaceService) EnvironmentClientService(com.sequenceiq.cloudbreak.service.environment.EnvironmentClientService) DistroXV1RequestToStackV4RequestConverter(com.sequenceiq.distrox.v1.distrox.converter.DistroXV1RequestToStackV4RequestConverter) String.format(java.lang.String.format) Inject(javax.inject.Inject) CloudbreakRestRequestThreadLocalService(com.sequenceiq.cloudbreak.structuredevent.CloudbreakRestRequestThreadLocalService) FreeipaClientService(com.sequenceiq.cloudbreak.service.freeipa.FreeipaClientService) DescribeFreeIpaResponse(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.describe.DescribeFreeIpaResponse) Pair(org.apache.commons.lang3.tuple.Pair) Service(org.springframework.stereotype.Service) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) Optional(java.util.Optional) PlatformAwareSdxConnector(com.sequenceiq.cloudbreak.saas.sdx.PlatformAwareSdxConnector) StackV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackV4Response) DistroXV1Request(com.sequenceiq.distrox.api.v1.distrox.model.DistroXV1Request) DescribeFreeIpaResponse(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.describe.DescribeFreeIpaResponse) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) Pair(org.apache.commons.lang3.tuple.Pair)

Aggregations

StackV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackV4Response)1 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)1 PlatformAwareSdxConnector (com.sequenceiq.cloudbreak.saas.sdx.PlatformAwareSdxConnector)1 StatusCheckResult (com.sequenceiq.cloudbreak.saas.sdx.status.StatusCheckResult)1 EnvironmentClientService (com.sequenceiq.cloudbreak.service.environment.EnvironmentClientService)1 FreeipaClientService (com.sequenceiq.cloudbreak.service.freeipa.FreeipaClientService)1 WorkspaceService (com.sequenceiq.cloudbreak.service.workspace.WorkspaceService)1 CloudbreakRestRequestThreadLocalService (com.sequenceiq.cloudbreak.structuredevent.CloudbreakRestRequestThreadLocalService)1 DistroXV1Request (com.sequenceiq.distrox.api.v1.distrox.model.DistroXV1Request)1 StackOperations (com.sequenceiq.distrox.v1.distrox.StackOperations)1 DistroXV1RequestToStackV4RequestConverter (com.sequenceiq.distrox.v1.distrox.converter.DistroXV1RequestToStackV4RequestConverter)1 DetailedEnvironmentResponse (com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse)1 DescribeFreeIpaResponse (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.describe.DescribeFreeIpaResponse)1 String.format (java.lang.String.format)1 Optional (java.util.Optional)1 Set (java.util.Set)1 Inject (javax.inject.Inject)1 Pair (org.apache.commons.lang3.tuple.Pair)1 Service (org.springframework.stereotype.Service)1