Search in sources :

Example 11 with Credential

use of com.sequenceiq.freeipa.dto.Credential in project cloudbreak by hortonworks.

the class FreeIpaRecommendationServiceTest method testValidateCustomInstanceTypeWhenCustomInstanceTypeIsSmaller.

@Test
public void testValidateCustomInstanceTypeWhenCustomInstanceTypeIsSmaller() {
    when(defaultInstanceTypeProvider.getForPlatform(eq("AWS"))).thenReturn("medium");
    when(entitlementService.isFreeIpaSelectInstanceTypeEnabled(anyString())).thenReturn(Boolean.TRUE);
    when(cloudParameterService.getVmTypesV2(any(), eq("eu-central-1"), eq("AWS"), eq(CdpResourceType.DEFAULT), any())).thenReturn(initCloudVmTypes());
    BadRequestException badRequestException = assertThrows(BadRequestException.class, () -> underTest.validateCustomInstanceType(createStack("small"), new Credential("AWS", "Cred", null, "crn", "account")));
    assertEquals("Invalid custom instance type for FreeIPA: master - small", badRequestException.getMessage());
}
Also used : Credential(com.sequenceiq.freeipa.dto.Credential) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) Test(org.junit.jupiter.api.Test)

Example 12 with Credential

use of com.sequenceiq.freeipa.dto.Credential in project cloudbreak by hortonworks.

the class CredentialService method convertToCredential.

private Credential convertToCredential(CredentialResponse credentialResponse) {
    SecretResponse secretResponse = credentialResponse.getAttributes();
    String attributes = secretService.getByResponse(secretResponse);
    return new Credential(credentialResponse.getCloudPlatform(), credentialResponse.getName(), attributes, credentialResponse.getCrn(), credentialResponse.getAccountId());
}
Also used : SecretResponse(com.sequenceiq.cloudbreak.service.secret.model.SecretResponse) Credential(com.sequenceiq.freeipa.dto.Credential)

Example 13 with Credential

use of com.sequenceiq.freeipa.dto.Credential 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 14 with Credential

use of com.sequenceiq.freeipa.dto.Credential in project cloudbreak by hortonworks.

the class FreeIpaRecommendationService method getRecommendation.

public FreeIpaRecommendationResponse getRecommendation(String credentialCrn, String region, String availabilityZone) {
    Credential credential = credentialService.getCredentialByCredCrn(credentialCrn);
    String defaultInstanceType = defaultInstanceTypeProvider.getForPlatform(credential.getCloudPlatform());
    Set<VmTypeResponse> availableVmTypes = getAvailableVmTypes(region, availabilityZone, credential, defaultInstanceType);
    return new FreeIpaRecommendationResponse(availableVmTypes, defaultInstanceType);
}
Also used : Credential(com.sequenceiq.freeipa.dto.Credential) VmTypeResponse(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.create.VmTypeResponse) FreeIpaRecommendationResponse(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.create.FreeIpaRecommendationResponse)

Example 15 with Credential

use of com.sequenceiq.freeipa.dto.Credential in project cloudbreak by hortonworks.

the class FreeIpaRecommendationService method getAvailableVmTypes.

private Set<VmTypeResponse> getAvailableVmTypes(String region, String availabilityZone, Credential credential, String defaultInstanceType) {
    CloudVmTypes vmTypes = cloudParameterService.getVmTypesV2(extendedCloudCredentialConverter.convert(credential), region, credential.getCloudPlatform(), CdpResourceType.DEFAULT, Maps.newHashMap());
    Set<VmType> availableVmTypes = Collections.emptySet();
    if (vmTypes.getCloudVmResponses() != null && StringUtils.isNotBlank(availabilityZone) && vmTypes.getDefaultCloudVmResponses().containsKey(availabilityZone)) {
        availableVmTypes = vmTypes.getCloudVmResponses().get(availabilityZone);
    } else if (vmTypes.getCloudVmResponses() != null && !vmTypes.getCloudVmResponses().isEmpty()) {
        availableVmTypes = vmTypes.getCloudVmResponses().values().iterator().next();
    }
    Optional<VmType> defaultVmType = availableVmTypes.stream().filter(vmType -> defaultInstanceType.equals(vmType.value())).findAny();
    return availableVmTypes.stream().filter(vmType -> filterVmTypeLargerThanDefault(vmType, defaultVmType)).map(vmType -> vmTypeConverter.convert(vmType)).collect(Collectors.toSet());
}
Also used : CloudVmTypes(com.sequenceiq.cloudbreak.cloud.model.CloudVmTypes) EntitlementService(com.sequenceiq.cloudbreak.auth.altus.EntitlementService) LoggerFactory(org.slf4j.LoggerFactory) StringUtils(org.apache.commons.lang3.StringUtils) Inject(javax.inject.Inject) CdpResourceType(com.sequenceiq.common.api.type.CdpResourceType) Credential(com.sequenceiq.freeipa.dto.Credential) ObjectUtils(org.apache.commons.lang3.ObjectUtils) Service(org.springframework.stereotype.Service) Map(java.util.Map) FreeIpaRecommendationResponse(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.create.FreeIpaRecommendationResponse) Stack(com.sequenceiq.freeipa.entity.Stack) DefaultInstanceTypeProvider(com.sequenceiq.freeipa.service.stack.instance.DefaultInstanceTypeProvider) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) VmTypeResponse(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.create.VmTypeResponse) Logger(org.slf4j.Logger) VmTypeMeta(com.sequenceiq.cloudbreak.cloud.model.VmTypeMeta) CloudParameterService(com.sequenceiq.cloudbreak.cloud.service.CloudParameterService) Set(java.util.Set) Collectors(java.util.stream.Collectors) Maps(com.google.common.collect.Maps) VmType(com.sequenceiq.cloudbreak.cloud.model.VmType) Optional(java.util.Optional) CredentialToExtendedCloudCredentialConverter(com.sequenceiq.freeipa.converter.cloud.CredentialToExtendedCloudCredentialConverter) Collections(java.util.Collections) VmTypeToVmTypeResponseConverter(com.sequenceiq.freeipa.converter.instance.VmTypeToVmTypeResponseConverter) CredentialService(com.sequenceiq.freeipa.service.CredentialService) CloudVmTypes(com.sequenceiq.cloudbreak.cloud.model.CloudVmTypes) VmType(com.sequenceiq.cloudbreak.cloud.model.VmType)

Aggregations

Credential (com.sequenceiq.freeipa.dto.Credential)17 Stack (com.sequenceiq.freeipa.entity.Stack)9 CloudCredential (com.sequenceiq.cloudbreak.cloud.model.CloudCredential)7 CloudContext (com.sequenceiq.cloudbreak.cloud.context.CloudContext)5 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)4 InstanceMetaData (com.sequenceiq.freeipa.entity.InstanceMetaData)4 CredentialService (com.sequenceiq.freeipa.service.CredentialService)4 Optional (java.util.Optional)4 Collectors (java.util.stream.Collectors)4 Inject (javax.inject.Inject)4 CloudNetworks (com.sequenceiq.cloudbreak.cloud.model.CloudNetworks)3 CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)3 ExtendedCloudCredential (com.sequenceiq.cloudbreak.cloud.model.ExtendedCloudCredential)3 Location (com.sequenceiq.cloudbreak.cloud.model.Location)3 MDCBuilder (com.sequenceiq.cloudbreak.logger.MDCBuilder)3 FlowParameters (com.sequenceiq.flow.core.FlowParameters)3 FreeIpaRecommendationResponse (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.create.FreeIpaRecommendationResponse)3 VmTypeResponse (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.create.VmTypeResponse)3 CredentialToCloudCredentialConverter (com.sequenceiq.freeipa.converter.cloud.CredentialToCloudCredentialConverter)3 ResourceToCloudResourceConverter (com.sequenceiq.freeipa.converter.cloud.ResourceToCloudResourceConverter)3