Search in sources :

Example 26 with CreateFreeIpaRequest

use of com.sequenceiq.freeipa.api.v1.freeipa.stack.model.create.CreateFreeIpaRequest in project cloudbreak by hortonworks.

the class FreeIpaV1ControllerTest method create.

@Test
void create() {
    CreateFreeIpaRequest freeIpaRequest = new CreateFreeIpaRequest();
    when(createFreeIpaRequestValidator.validate(freeIpaRequest)).thenReturn(ValidationResult.builder().build());
    assertNull(underTest.create(freeIpaRequest));
    verify(creationService, times(1)).launchFreeIpa(freeIpaRequest, ACCOUNT_ID);
}
Also used : CreateFreeIpaRequest(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.create.CreateFreeIpaRequest) Test(org.junit.jupiter.api.Test)

Example 27 with CreateFreeIpaRequest

use of com.sequenceiq.freeipa.api.v1.freeipa.stack.model.create.CreateFreeIpaRequest in project cloudbreak by hortonworks.

the class StackToCreateFreeIpaRequestConverter method convert.

@Override
public CreateFreeIpaRequest convert(Stack source) {
    LOGGER.debug("Creating a CreateFreeIpaRequest from {}", source);
    CreateFreeIpaRequest request = new CreateFreeIpaRequest();
    request.setEnvironmentCrn(source.getEnvironmentCrn());
    request.setName(getName(source));
    request.setPlacement(getPlacementRequest(source));
    request.setInstanceGroups(source.getInstanceGroups().stream().map(this::getInstanceGroupRequst).collect(Collectors.toList()));
    request.setAuthentication(getStackAuthenticationRequest(source.getStackAuthentication()));
    request.setNetwork(getNetworkRequest(source.getNetwork()));
    request.setImage(getImageSettingsRequest(source.getImage()));
    request.setFreeIpa(getFreeIpaServerRequest(source));
    request.setGatewayPort(source.getGatewayport());
    request.setTelemetry(getTelemetry(source));
    request.setBackup(getBackup(source));
    request.setTags(getTags(source.getTags()));
    request.setUseCcm(source.getUseCcm());
    request.setTunnel(source.getTunnel());
    request.setVariant(source.getPlatformvariant());
    LOGGER.info("Created CreateFreeIpaRequest {} from the original stack {}", request, source);
    return request;
}
Also used : CreateFreeIpaRequest(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.create.CreateFreeIpaRequest)

Example 28 with CreateFreeIpaRequest

use of com.sequenceiq.freeipa.api.v1.freeipa.stack.model.create.CreateFreeIpaRequest in project cloudbreak by hortonworks.

the class FreeIpaCreationService method launchFreeIpa.

public DescribeFreeIpaResponse launchFreeIpa(CreateFreeIpaRequest request, String accountId) {
    String userCrn = crnService.getUserCrn();
    Future<String> ownerFuture = initiateOwnerFetching(userCrn);
    Credential credential = credentialService.getCredentialByEnvCrn(request.getEnvironmentCrn());
    DetailedEnvironmentResponse environment = measure(() -> cachedEnvironmentClientService.getByCrn(request.getEnvironmentCrn()), LOGGER, "Environment properties were queried under {} ms for environment {}", request.getEnvironmentCrn());
    Stack stack = stackConverter.convert(request, environment, accountId, ownerFuture, userCrn, credential.getCloudPlatform());
    stack.setAppVersion(appVersion);
    GetPlatformTemplateRequest getPlatformTemplateRequest = templateService.triggerGetTemplate(stack, credential);
    Telemetry telemetry = stack.getTelemetry();
    if (telemetry != null) {
        telemetry.setRules(accountTelemetryService.getAnonymizationRules(accountId));
    }
    cloudStorageFolderResolverService.updateStorageLocation(telemetry, FluentClusterType.FREEIPA.value(), stack.getName(), stack.getResourceCrn());
    stack.setTelemetry(telemetry);
    Backup backup = stack.getBackup();
    backup = cloudBackupFolderResolverService.updateStorageLocation(backup, BackupClusterType.FREEIPA.value(), stack.getName(), stack.getResourceCrn());
    stack.setBackup(backup);
    fillInstanceMetadata(stack, environment);
    String template = templateService.waitGetTemplate(getPlatformTemplateRequest);
    stack.setTemplate(template);
    SecurityConfig securityConfig = tlsSecurityService.generateSecurityKeys(accountId);
    multiAzValidator.validateMultiAzForStack(stack.getPlatformvariant(), stack.getInstanceGroups());
    freeIpaRecommendationService.validateCustomInstanceType(stack, credential);
    try {
        Triple<Stack, ImageEntity, FreeIpa> stackImageFreeIpaTuple = transactionService.required(() -> {
            SecurityConfig savedSecurityConfig = securityConfigService.save(securityConfig);
            stack.setSecurityConfig(savedSecurityConfig);
            Stack savedStack = stackService.save(stack);
            ImageSettingsRequest imageSettingsRequest = request.getImage();
            ImageEntity image = imageService.create(savedStack, Objects.nonNull(imageSettingsRequest) ? imageSettingsRequest : new ImageSettingsRequest());
            FreeIpa freeIpa = freeIpaService.create(savedStack, request.getFreeIpa());
            return Triple.of(savedStack, image, freeIpa);
        });
        flowManager.notify(FlowChainTriggers.PROVISION_TRIGGER_EVENT, new StackEvent(FlowChainTriggers.PROVISION_TRIGGER_EVENT, stackImageFreeIpaTuple.getLeft().getId()));
        InMemoryStateStore.putStack(stack.getId(), PollGroup.POLLABLE);
        return stackToDescribeFreeIpaResponseConverter.convert(stackImageFreeIpaTuple.getLeft(), stackImageFreeIpaTuple.getMiddle(), stackImageFreeIpaTuple.getRight(), Optional.empty(), false);
    } catch (TransactionService.TransactionExecutionException e) {
        LOGGER.error("Creation of FreeIPA failed", e);
        throw new BadRequestException("Creation of FreeIPA failed: " + e.getCause().getMessage(), e);
    }
}
Also used : Credential(com.sequenceiq.freeipa.dto.Credential) ImageSettingsRequest(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.image.ImageSettingsRequest) TransactionService(com.sequenceiq.cloudbreak.common.service.TransactionService) ImageEntity(com.sequenceiq.freeipa.entity.ImageEntity) Backup(com.sequenceiq.freeipa.api.model.Backup) Telemetry(com.sequenceiq.common.api.telemetry.model.Telemetry) Stack(com.sequenceiq.freeipa.entity.Stack) FreeIpa(com.sequenceiq.freeipa.entity.FreeIpa) StackEvent(com.sequenceiq.freeipa.flow.stack.StackEvent) SecurityConfig(com.sequenceiq.freeipa.entity.SecurityConfig) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) GetPlatformTemplateRequest(com.sequenceiq.cloudbreak.cloud.event.platform.GetPlatformTemplateRequest)

Example 29 with CreateFreeIpaRequest

use of com.sequenceiq.freeipa.api.v1.freeipa.stack.model.create.CreateFreeIpaRequest in project cloudbreak by hortonworks.

the class RepairInstancesService method rebuild.

public DescribeFreeIpaResponse rebuild(String accountId, RebuildRequest rebuildRequest) {
    if (!entitlementService.isFreeIpaRebuildEnabled(accountId)) {
        throw new BadRequestException("The FreeIPA rebuild capability is disabled.");
    }
    Stack stack = stackService.getByCrnAndAccountIdEvenIfTerminated(rebuildRequest.getEnvironmentCrn(), accountId, rebuildRequest.getSourceCrn());
    Optional<Stack> nonTerminatedStack = stackService.findByEnvironmentCrnAndAccountId(rebuildRequest.getEnvironmentCrn(), accountId);
    if (nonTerminatedStack.isPresent()) {
        String error = "There is a stack which hasn't been terminated.";
        LOGGER.error(error);
        throw new BadRequestException(error);
    }
    renameStackIfNeeded(stack);
    CreateFreeIpaRequest createFreeIpaRequest = stackToCreateFreeIpaRequestConverter.convert(stack);
    return freeIpaCreationService.launchFreeIpa(createFreeIpaRequest, accountId);
}
Also used : CreateFreeIpaRequest(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.create.CreateFreeIpaRequest) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) Stack(com.sequenceiq.freeipa.entity.Stack)

Aggregations

CreateFreeIpaRequest (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.create.CreateFreeIpaRequest)23 Test (org.junit.jupiter.api.Test)18 InstanceGroupRequest (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.instance.InstanceGroupRequest)10 ValidationResult (com.sequenceiq.cloudbreak.validation.ValidationResult)6 Stack (com.sequenceiq.freeipa.entity.Stack)6 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)6 CloudConnector (com.sequenceiq.cloudbreak.cloud.CloudConnector)5 ExtendedPollingResult (com.sequenceiq.cloudbreak.polling.ExtendedPollingResult)5 Telemetry (com.sequenceiq.common.api.telemetry.model.Telemetry)5 Credential (com.sequenceiq.environment.credential.domain.Credential)5 Environment (com.sequenceiq.environment.environment.domain.Environment)5 EnvironmentDto (com.sequenceiq.environment.environment.dto.EnvironmentDto)5 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)5 DetailedEnvironmentResponse (com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse)4 Backup (com.sequenceiq.freeipa.api.model.Backup)4 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)3 TelemetryRequest (com.sequenceiq.common.api.telemetry.request.TelemetryRequest)3 FreeIpaServerRequest (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.FreeIpaServerRequest)3 ImageSettingsRequest (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.image.ImageSettingsRequest)3 InstanceTemplateRequest (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.instance.InstanceTemplateRequest)3