Search in sources :

Example 11 with Measure

use of com.sequenceiq.cloudbreak.aspect.Measure in project cloudbreak by hortonworks.

the class ImageService method determineImageFromCatalog.

// CHECKSTYLE:OFF
@Measure(ImageService.class)
public StatedImage determineImageFromCatalog(Long workspaceId, ImageSettingsV4Request imageSettings, String platformString, String variant, Blueprint blueprint, boolean useBaseImage, boolean baseImageEnabled, User user, Predicate<com.sequenceiq.cloudbreak.cloud.model.catalog.Image> imagePredicate) throws CloudbreakImageNotFoundException, CloudbreakImageCatalogException {
    ImageCatalogPlatform platform = platformStringTransformer.getPlatformStringForImageCatalog(platformString, variant);
    if (imageSettings != null && StringUtils.isNotEmpty(imageSettings.getId())) {
        LOGGER.debug("Image id {} is specified for the stack.", imageSettings.getId());
        if (imageSettings.getCatalog() == null) {
            imageSettings.setCatalog(CDP_DEFAULT_CATALOG_NAME);
        }
        StatedImage image = imageCatalogService.getImageByCatalogName(workspaceId, imageSettings.getId(), imageSettings.getCatalog());
        return checkIfBasePermitted(image, baseImageEnabled);
    } else if (useBaseImage && !baseImageEnabled) {
        throw new CloudbreakImageCatalogException("Inconsistent request, base images are disabled but custom repo information is submitted!");
    }
    String clusterVersion = getClusterVersion(blueprint);
    Set<String> operatingSystems;
    try {
        operatingSystems = getSupportedOperatingSystems(workspaceId, imageSettings, clusterVersion, platform);
    } catch (Exception ex) {
        throw new CloudbreakImageCatalogException(ex);
    }
    ImageCatalog imageCatalog = getImageCatalogFromRequestOrDefault(workspaceId, imageSettings, user);
    ImageFilter imageFilter = new ImageFilter(imageCatalog, Set.of(platform), null, baseImageEnabled, operatingSystems, clusterVersion);
    LOGGER.info("Image id is not specified for the stack.");
    if (baseImageEnabled && useBaseImage) {
        LOGGER.info("Trying to select a base image.");
        return imageCatalogService.getLatestBaseImageDefaultPreferred(imageFilter, imagePredicate);
    }
    LOGGER.info("Trying to select a prewarmed image.");
    return imageCatalogService.getImagePrewarmedDefaultPreferred(imageFilter, imagePredicate);
}
Also used : ImageCatalogPlatform(com.sequenceiq.cloudbreak.service.image.catalog.model.ImageCatalogPlatform) ImageCatalog(com.sequenceiq.cloudbreak.domain.ImageCatalog) CloudbreakImageCatalogException(com.sequenceiq.cloudbreak.core.CloudbreakImageCatalogException) NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException) IOException(java.io.IOException) CloudbreakImageNotFoundException(com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException) CloudbreakImageCatalogException(com.sequenceiq.cloudbreak.core.CloudbreakImageCatalogException) Measure(com.sequenceiq.cloudbreak.aspect.Measure)

Example 12 with Measure

use of com.sequenceiq.cloudbreak.aspect.Measure in project cloudbreak by hortonworks.

the class TlsSecurityService method generateSecurityKeys.

@Measure(TlsSecurityService.class)
public SecurityConfig generateSecurityKeys(Workspace workspace) {
    SecurityConfig securityConfig = new SecurityConfig();
    securityConfig.setWorkspace(workspace);
    SaltSecurityConfig saltSecurityConfig = new SaltSecurityConfig();
    saltSecurityConfig.setWorkspace(workspace);
    saltSecurityConfig.setSaltBootPassword(PasswordUtil.generatePassword());
    saltSecurityConfig.setSaltPassword(PasswordUtil.generatePassword());
    securityConfig.setSaltSecurityConfig(saltSecurityConfig);
    setClientKeys(securityConfig, keyPairCache.pop(), keyPairCache.pop());
    setSaltBootSignKeypair(saltSecurityConfig, convertKeyPair(keyPairCache.pop()));
    setSaltSignKeypair(securityConfig, convertKeyPair(keyPairCache.pop()));
    return securityConfig;
}
Also used : SecurityConfig(com.sequenceiq.cloudbreak.domain.SecurityConfig) SaltSecurityConfig(com.sequenceiq.cloudbreak.domain.SaltSecurityConfig) SaltSecurityConfig(com.sequenceiq.cloudbreak.domain.SaltSecurityConfig) Measure(com.sequenceiq.cloudbreak.aspect.Measure)

Example 13 with Measure

use of com.sequenceiq.cloudbreak.aspect.Measure in project cloudbreak by hortonworks.

the class StackDecorator method decorate.

@Measure(StackDecorator.class)
public Stack decorate(@Nonnull Stack subject, @Nonnull StackV4Request request, User user, Workspace workspace) {
    String stackName = request.getName();
    DetailedEnvironmentResponse environment = measure(() -> environmentClientService.getByCrn(subject.getEnvironmentCrn()), LOGGER, "Environment properties were queried under {} ms for environment {}", request.getEnvironmentCrn());
    Credential credential = measure(() -> prepareCredential(environment), LOGGER, "Credential was prepared under {} ms for stack {}", stackName);
    measure(() -> preparePlacement(subject, request, environment), LOGGER, "Placement was prepared under {} ms for stack {}, stackName");
    measure(() -> prepareParameters(subject, environment), LOGGER, "Parameters were prepared under {} ms for stack {}", stackName);
    measure(() -> prepareDomainIfDefined(subject, credential), LOGGER, "Domain was prepared under {} ms for stack {}", stackName);
    subject.setCloudPlatform(credential.cloudPlatform());
    if (subject.getInstanceGroups() == null) {
        throw new BadRequestException("Instance groups must be specified!");
    }
    measure(() -> {
        PlatformParameters pps = cloudParameterCache.getPlatformParameters().get(Platform.platform(subject.cloudPlatform()));
        Boolean mandatoryNetwork = pps.specialParameters().getSpecialParameters().get(PlatformParametersConsts.NETWORK_IS_MANDATORY);
        if (BooleanUtils.isTrue(mandatoryNetwork) && subject.getNetwork() == null) {
            throw new BadRequestException("Network must be specified!");
        }
    }, LOGGER, "Network was prepared and validated under {} ms for stack {}", stackName);
    measure(() -> prepareOrchestratorIfNotExist(subject, credential), LOGGER, "Orchestrator was prepared under {} ms for stack {}", stackName);
    if (subject.getFailurePolicy() != null) {
        measure(() -> validatFailurePolicy(subject, subject.getFailurePolicy()), LOGGER, "Failure policy was validated under {} ms for stack {}", stackName);
    }
    measure(() -> prepareInstanceGroups(subject, request, credential, user, environment), LOGGER, "Instance groups were prepared under {} ms for stack {}", stackName);
    measure(() -> validateInstanceGroups(subject), LOGGER, "Validation of gateway instance groups has been finished in {} ms for stack {}", stackName);
    measure(() -> {
        ValidationResult validationResult = sharedServiceValidator.checkSharedServiceStackRequirements(request, workspace);
        if (validationResult.hasError()) {
            throw new BadRequestException(validationResult.getFormattedErrors());
        }
    }, LOGGER, "Validation of shared services requirements has been finished in {} ms for stack {}", stackName);
    return subject;
}
Also used : Credential(com.sequenceiq.cloudbreak.dto.credential.Credential) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) PlatformParameters(com.sequenceiq.cloudbreak.cloud.PlatformParameters) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) ValidationResult(com.sequenceiq.cloudbreak.validation.ValidationResult) Measure(com.sequenceiq.cloudbreak.aspect.Measure)

Example 14 with Measure

use of com.sequenceiq.cloudbreak.aspect.Measure in project cloudbreak by hortonworks.

the class DnsRecordService method deleteDnsRecordByFqdn.

@Retryable(value = RetryableFreeIpaClientException.class, maxAttemptsExpression = RetryableFreeIpaClientException.MAX_RETRIES_EXPRESSION, backoff = @Backoff(delayExpression = RetryableFreeIpaClientException.DELAY_EXPRESSION, multiplierExpression = RetryableFreeIpaClientException.MULTIPLIER_EXPRESSION))
@Measure(DnsRecordService.class)
public void deleteDnsRecordByFqdn(String environmentCrn, String accountId, List<String> fqdns) throws FreeIpaClientException {
    FreeIpaAndClient freeIpaAndClient = createFreeIpaAndClient(environmentCrn, accountId);
    for (DnsZone dnsZone : freeIpaAndClient.getClient().findAllDnsZone()) {
        LOGGER.debug("Looking for records in zone [{}]", dnsZone.getIdnsname());
        Set<DnsRecord> allDnsRecordsInZone = freeIpaAndClient.getClient().findAllDnsRecordInZone(dnsZone.getIdnsname());
        deleteRegularRecords(freeIpaAndClient.getClient(), dnsZone, allDnsRecordsInZone, fqdns, freeIpaAndClient.getFreeIpa().getDomain());
        deleteSrvRecords(freeIpaAndClient.getClient(), dnsZone, allDnsRecordsInZone, fqdns);
    }
}
Also used : DnsRecord(com.sequenceiq.freeipa.client.model.DnsRecord) DnsZone(com.sequenceiq.freeipa.client.model.DnsZone) Retryable(org.springframework.retry.annotation.Retryable) Measure(com.sequenceiq.cloudbreak.aspect.Measure)

Example 15 with Measure

use of com.sequenceiq.cloudbreak.aspect.Measure in project cloudbreak by hortonworks.

the class SaltConnector method wheel.

@Measure(SaltConnector.class)
@Retryable(value = ClusterProxyWebApplicationException.class, backoff = @Backoff(delay = 1000))
public <T> T wheel(String fun, Collection<String> match, Class<T> clazz) {
    Form form = new Form();
    form = addAuth(form).param("fun", fun).param("client", "wheel");
    if (match != null && !match.isEmpty()) {
        form.param("match", String.join(",", match));
    }
    Response response = endpointInvocation(SaltEndpoint.SALT_RUN.getContextPath(), toJson(form.asMap()).getBytes()).post(Entity.form(form));
    T responseEntity = JaxRSUtil.response(response, clazz);
    LOGGER.debug("Salt wheel has been executed. fun: {}", fun);
    return responseEntity;
}
Also used : GenericResponse(com.sequenceiq.cloudbreak.orchestrator.model.GenericResponse) Response(javax.ws.rs.core.Response) FingerprintsResponse(com.sequenceiq.cloudbreak.orchestrator.salt.domain.FingerprintsResponse) BOOT_HOSTNAME_ENDPOINT(com.sequenceiq.cloudbreak.orchestrator.salt.client.SaltEndpoint.BOOT_HOSTNAME_ENDPOINT) Form(javax.ws.rs.core.Form) Retryable(org.springframework.retry.annotation.Retryable) Measure(com.sequenceiq.cloudbreak.aspect.Measure)

Aggregations

Measure (com.sequenceiq.cloudbreak.aspect.Measure)15 Retryable (org.springframework.retry.annotation.Retryable)7 GenericResponse (com.sequenceiq.cloudbreak.orchestrator.model.GenericResponse)6 FingerprintsResponse (com.sequenceiq.cloudbreak.orchestrator.salt.domain.FingerprintsResponse)6 Response (javax.ws.rs.core.Response)6 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)4 GenericResponses (com.sequenceiq.cloudbreak.orchestrator.model.GenericResponses)3 BOOT_HOSTNAME_ENDPOINT (com.sequenceiq.cloudbreak.orchestrator.salt.client.SaltEndpoint.BOOT_HOSTNAME_ENDPOINT)3 ValidationResult (com.sequenceiq.cloudbreak.validation.ValidationResult)3 Form (javax.ws.rs.core.Form)3 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 CloudbreakImageCatalogException (com.sequenceiq.cloudbreak.core.CloudbreakImageCatalogException)2 CloudbreakImageNotFoundException (com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException)2 Component (com.sequenceiq.cloudbreak.domain.stack.Component)2 ImageCatalogPlatform (com.sequenceiq.cloudbreak.service.image.catalog.model.ImageCatalogPlatform)2 Benchmark.multiCheckedMeasure (com.sequenceiq.cloudbreak.util.Benchmark.multiCheckedMeasure)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 PkiUtil (com.sequenceiq.cloudbreak.certificate.PkiUtil)1 DisableProxyAuthFeature (com.sequenceiq.cloudbreak.client.DisableProxyAuthFeature)1 RestClientUtil (com.sequenceiq.cloudbreak.client.RestClientUtil)1