Search in sources :

Example 1 with DescribeFreeIpaResponse

use of com.sequenceiq.freeipa.api.v1.freeipa.stack.model.describe.DescribeFreeIpaResponse 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)

Example 2 with DescribeFreeIpaResponse

use of com.sequenceiq.freeipa.api.v1.freeipa.stack.model.describe.DescribeFreeIpaResponse in project cloudbreak by hortonworks.

the class StackToDescribeFreeIpaResponseConverter method convert.

public DescribeFreeIpaResponse convert(Stack stack, ImageEntity image, FreeIpa freeIpa, Optional<UserSyncStatus> userSyncStatus, Boolean includeAllInstances) {
    DescribeFreeIpaResponse describeFreeIpaResponse = new DescribeFreeIpaResponse();
    describeFreeIpaResponse.setName(stack.getName());
    describeFreeIpaResponse.setEnvironmentCrn(stack.getEnvironmentCrn());
    describeFreeIpaResponse.setCrn(stack.getResourceCrn());
    describeFreeIpaResponse.setCloudPlatform(stack.getCloudPlatform());
    describeFreeIpaResponse.setVariant(stack.getPlatformvariant());
    describeFreeIpaResponse.setAuthentication(authenticationResponseConverter.convert(stack.getStackAuthentication()));
    Optional.ofNullable(image).ifPresent(i -> describeFreeIpaResponse.setImage(imageSettingsResponseConverter.convert(i)));
    Optional.ofNullable(freeIpa).ifPresent(f -> describeFreeIpaResponse.setFreeIpa(freeIpaServerResponseConverter.convert(f)));
    describeFreeIpaResponse.setNetwork(networkResponseConverter.convert(stack));
    describeFreeIpaResponse.setPlacement(convertToPlacementResponse(stack));
    describeFreeIpaResponse.setTunnel(stack.getTunnel());
    describeFreeIpaResponse.setInstanceGroups(instanceGroupConverter.convert(stack.getInstanceGroups(), includeAllInstances));
    describeFreeIpaResponse.setAvailabilityStatus(stackToAvailabilityStatusConverter.convert(stack));
    describeFreeIpaResponse.setStatus(stack.getStackStatus().getStatus());
    describeFreeIpaResponse.setStatusString(stack.getStackStatus().getStatusString());
    describeFreeIpaResponse.setStatusReason(stack.getStackStatus().getStatusReason());
    decorateFreeIpaServerResponseWithIps(describeFreeIpaResponse.getFreeIpa(), describeFreeIpaResponse.getInstanceGroups());
    decorateFreeIpaServerResponseWithLoadBalancedHost(stack, describeFreeIpaResponse.getFreeIpa(), freeIpa);
    describeFreeIpaResponse.setAppVersion(stack.getAppVersion());
    decorateWithCloudStorageAndTelemetry(stack, describeFreeIpaResponse);
    userSyncStatus.ifPresent(u -> describeFreeIpaResponse.setUserSyncStatus(userSyncStatusConverter.convert(u)));
    return describeFreeIpaResponse;
}
Also used : DescribeFreeIpaResponse(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.describe.DescribeFreeIpaResponse)

Example 3 with DescribeFreeIpaResponse

use of com.sequenceiq.freeipa.api.v1.freeipa.stack.model.describe.DescribeFreeIpaResponse in project cloudbreak by hortonworks.

the class EnvironmentStatusTest method setFreeIpaStatus.

private void setFreeIpaStatus(Status freeIpaStatus) {
    DescribeFreeIpaResponse freeIpaResponse = new DescribeFreeIpaResponse();
    freeIpaResponse.setStatus(freeIpaStatus);
    when(freeIpaService.internalDescribe(environment.getResourceCrn(), environment.getAccountId())).thenReturn(Optional.of(freeIpaResponse));
}
Also used : DescribeFreeIpaResponse(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.describe.DescribeFreeIpaResponse)

Example 4 with DescribeFreeIpaResponse

use of com.sequenceiq.freeipa.api.v1.freeipa.stack.model.describe.DescribeFreeIpaResponse in project cloudbreak by hortonworks.

the class FreeIpaPollerServiceTest method testStartAttachedFreeipaInstancesWhenFreeipaStopped.

@Test
void testStartAttachedFreeipaInstancesWhenFreeipaStopped() {
    DescribeFreeIpaResponse freeipaResponse = new DescribeFreeIpaResponse();
    freeipaResponse.setAvailabilityStatus(AvailabilityStatus.UNAVAILABLE);
    freeipaResponse.setStatus(Status.STOPPED);
    when(freeIpaService.describe(ENV_CRN)).thenReturn(Optional.of(freeipaResponse));
    when(freeipaPollerProvider.startPoller(ENV_ID, ENV_CRN)).thenReturn(AttemptResults::justFinish);
    underTest.startAttachedFreeipaInstances(ENV_ID, ENV_CRN);
    verify(freeIpaService, times(1)).startFreeIpa(ENV_CRN);
}
Also used : DescribeFreeIpaResponse(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.describe.DescribeFreeIpaResponse) AttemptResults(com.dyngr.core.AttemptResults) Test(org.junit.jupiter.api.Test)

Example 5 with DescribeFreeIpaResponse

use of com.sequenceiq.freeipa.api.v1.freeipa.stack.model.describe.DescribeFreeIpaResponse in project cloudbreak by hortonworks.

the class FreeIpaPollerServiceTest method testSyncUsersWhenFreeIpaAvailable.

@Test
void testSyncUsersWhenFreeIpaAvailable() {
    DescribeFreeIpaResponse freeipaResponse = new DescribeFreeIpaResponse();
    freeipaResponse.setAvailabilityStatus(AvailabilityStatus.AVAILABLE);
    freeipaResponse.setStatus(Status.AVAILABLE);
    when(freeIpaService.describe(ENV_CRN)).thenReturn(Optional.of(freeipaResponse));
    when(freeIpaService.synchronizeAllUsersInEnvironment(ENV_CRN)).thenReturn(createStatus(SynchronizationStatus.REQUESTED, ""));
    when(freeipaPollerProvider.syncUsersPoller(ENV_ID, ENV_CRN, OPERATION)).thenReturn(AttemptResults::justFinish);
    underTest.waitForSynchronizeUsers(ENV_ID, ENV_CRN);
    verify(freeIpaService, times(1)).synchronizeAllUsersInEnvironment(ENV_CRN);
}
Also used : DescribeFreeIpaResponse(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.describe.DescribeFreeIpaResponse) AttemptResults(com.dyngr.core.AttemptResults) Test(org.junit.jupiter.api.Test)

Aggregations

DescribeFreeIpaResponse (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.describe.DescribeFreeIpaResponse)60 Test (org.junit.jupiter.api.Test)32 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)17 DetailedEnvironmentResponse (com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse)8 EnumSource (org.junit.jupiter.params.provider.EnumSource)8 DistroXV1Request (com.sequenceiq.distrox.api.v1.distrox.model.DistroXV1Request)7 InstanceGroupResponse (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.instance.InstanceGroupResponse)7 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)6 AttemptResults (com.dyngr.core.AttemptResults)5 Stack (com.sequenceiq.freeipa.entity.Stack)5 EnvironmentDto (com.sequenceiq.environment.environment.dto.EnvironmentDto)4 CloudbreakServiceException (com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException)3 EnvironmentDeletionDto (com.sequenceiq.environment.environment.dto.EnvironmentDeletionDto)3 FreeIpaOperationFailedException (com.sequenceiq.environment.exception.FreeIpaOperationFailedException)3 BaseNamedFlowEvent (com.sequenceiq.flow.reactor.api.event.BaseNamedFlowEvent)3 InstanceMetaDataResponse (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.instance.InstanceMetaDataResponse)3 CreateFreeIpaRequest (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.create.CreateFreeIpaRequest)3 FreeIpa (com.sequenceiq.freeipa.entity.FreeIpa)3 ImageEntity (com.sequenceiq.freeipa.entity.ImageEntity)3 Environment (com.sequenceiq.environment.environment.domain.Environment)2