Search in sources :

Example 1 with Measure

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

the class ClusterCreationSetupService method validate.

@Measure(ClusterCreationSetupService.class)
public void validate(ClusterV4Request request, CloudCredential cloudCredential, Stack stack, User user, Workspace workspace, DetailedEnvironmentResponse environment) {
    MdcContext.builder().userCrn(user.getUserCrn()).tenant(user.getTenant().getName()).buildMdc();
    CloudCredential credential = cloudCredential;
    if (credential == null) {
        credential = stackUtil.getCloudCredential(stack);
    }
    fileSystemValidator.validate(stack.cloudPlatform(), credential, request.getCloudStorage(), stack.getWorkspace().getId());
    rdsConfigValidator.validateRdsConfigs(request, user, workspace);
    ValidationResult.ValidationResultBuilder resultBuilder = ValidationResult.builder();
    environmentValidator.validateRdsConfigNames(request.getDatabases(), resultBuilder, stack.getWorkspace().getId());
    environmentValidator.validateProxyConfig(request.getProxyConfigCrn(), resultBuilder);
    String parentEnvironmentCloudPlatform = environment.getParentEnvironmentCloudPlatform();
    environmentValidator.validateAutoTls(request, stack, resultBuilder, parentEnvironmentCloudPlatform);
    ValidationResult build = resultBuilder.build();
    if (build.hasError()) {
        throw new BadRequestException(build.getFormattedErrors());
    }
}
Also used : CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) ValidationResult(com.sequenceiq.cloudbreak.validation.ValidationResult) Benchmark.multiCheckedMeasure(com.sequenceiq.cloudbreak.util.Benchmark.multiCheckedMeasure) Measure(com.sequenceiq.cloudbreak.aspect.Measure)

Example 2 with Measure

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

the class ClusterCreationSetupService method validate.

@Measure(ClusterCreationSetupService.class)
public void validate(ClusterV4Request request, Stack stack, User user, Workspace workspace, DetailedEnvironmentResponse environment) {
    MdcContext.builder().userCrn(user.getUserCrn()).tenant(user.getTenant().getName()).buildMdc();
    rdsConfigValidator.validateRdsConfigs(request, user, workspace);
    ValidationResult.ValidationResultBuilder resultBuilder = ValidationResult.builder();
    environmentValidator.validateRdsConfigNames(request.getDatabases(), resultBuilder, stack.getWorkspace().getId());
    environmentValidator.validateProxyConfig(request.getProxyConfigCrn(), resultBuilder);
    String parentEnvironmentCloudPlatform = environment.getParentEnvironmentCloudPlatform();
    environmentValidator.validateAutoTls(request, stack, resultBuilder, parentEnvironmentCloudPlatform);
    ValidationResult build = resultBuilder.build();
    if (build.hasError()) {
        throw new BadRequestException(build.getFormattedErrors());
    }
}
Also used : BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) ValidationResult(com.sequenceiq.cloudbreak.validation.ValidationResult) Benchmark.multiCheckedMeasure(com.sequenceiq.cloudbreak.util.Benchmark.multiCheckedMeasure) Measure(com.sequenceiq.cloudbreak.aspect.Measure)

Example 3 with Measure

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

the class ClusterOperationService method create.

@Measure(ClusterOperationService.class)
public Cluster create(Stack stack, Cluster cluster, List<ClusterComponent> components, User user) throws TransactionService.TransactionExecutionException {
    LOGGER.debug("Cluster requested [BlueprintId: {}]", cluster.getBlueprint().getId());
    String stackName = stack.getName();
    if (stack.getCluster() != null) {
        throw new BadRequestException(String.format("A cluster is already created on this stack! [cluster: '%s']", stack.getCluster().getName()));
    }
    long start = System.currentTimeMillis();
    return transactionService.required(() -> {
        setWorkspace(cluster, stack.getWorkspace());
        cluster.setEnvironmentCrn(stack.getEnvironmentCrn());
        if (Status.CREATE_FAILED.equals(stack.getStatus())) {
            throw new BadRequestException("Stack creation failed, cannot create cluster.");
        }
        if (cluster.getFileSystem() != null) {
            cluster.setFileSystem(fileSystemConfigService.createWithMdcContextRestore(cluster.getFileSystem(), cluster.getWorkspace(), user));
        }
        removeGatewayIfNotSupported(cluster, components);
        cluster.setStack(stack);
        stack.setCluster(cluster);
        Cluster savedCluster = measure(() -> clusterService.saveClusterAndComponent(cluster, components, stackName), LOGGER, "saveClusterAndComponent {} ms");
        measure(() -> usageLoggingUtil.logClusterRequestedUsageEvent(cluster), LOGGER, "logClusterRequestedUsageEvent {} ms");
        LOGGER.info("cluster saved {} ms", System.currentTimeMillis() - start);
        return savedCluster;
    });
}
Also used : BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) Measure(com.sequenceiq.cloudbreak.aspect.Measure)

Example 4 with Measure

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

the class StackService method create.

@Measure(StackService.class)
public Stack create(Stack stack, String platformString, StatedImage imgFromCatalog, User user, Workspace workspace, Optional<String> externalCrn) {
    if (stack.getGatewayPort() == null) {
        stack.setGatewayPort(nginxPort);
    }
    stack.setCreator(user);
    stack.setWorkspace(workspace);
    setPlatformVariant(stack);
    String stackName = stack.getName();
    MDCBuilder.buildMdcContext(stack);
    GetPlatformTemplateRequest templateRequest = connector.triggerGetTemplate(stack);
    if (!stack.getStackAuthentication().passwordAuthenticationRequired() && !Strings.isNullOrEmpty(stack.getStackAuthentication().getPublicKey())) {
        rsaPublicKeyValidator.validate(stack.getStackAuthentication().getPublicKey());
    }
    if (stack.getOrchestrator() != null) {
        orchestratorService.save(stack.getOrchestrator());
    }
    stack.getStackAuthentication().setLoginUserName(SSH_USER_CB);
    String accountId = ThreadBasedUserCrnProvider.getAccountId();
    if (externalCrn.isPresent()) {
        // it means it is a DL cluster, double check it in sdx service
        sdxClientService.getByCrn(externalCrn.get());
        stack.setResourceCrn(externalCrn.get());
    } else {
        stack.setResourceCrn(createCRN(accountId));
    }
    setDefaultTags(stack);
    Stack savedStack = measure(() -> stackRepository.save(stack), LOGGER, "Stackrepository save took {} ms for stack {}", stackName);
    MDCBuilder.buildMdcContext(savedStack);
    measure(() -> addCloudbreakDetailsForStack(savedStack), LOGGER, "Add Cloudbreak details took {} ms for stack {}", stackName);
    measure(() -> storeTelemetryForStack(savedStack), LOGGER, "Add Telemetry settings took {} ms for stack {}", stackName);
    measure(() -> instanceGroupService.saveAll(savedStack.getInstanceGroups()), LOGGER, "Instance groups saved in {} ms for stack {}", stackName);
    measure(() -> instanceMetaDataService.saveAll(savedStack.getInstanceMetaDataAsList()), LOGGER, "Instance metadatas saved in {} ms for stack {}", stackName);
    measure(() -> loadBalancerPersistenceService.saveAll(savedStack.getLoadBalancers()), LOGGER, "Load balancers saved in {} ms for stack {}", stackName);
    measure(() -> targetGroupPersistenceService.saveAll(savedStack.getTargetGroupAsList()), LOGGER, "Target groups saved in {} ms for stack {}", stackName);
    try {
        Set<Component> components = imageService.create(stack, imgFromCatalog);
        setRuntime(stack, components);
    } catch (CloudbreakImageNotFoundException e) {
        LOGGER.info("Cloudbreak Image not found", e);
        throw new CloudbreakApiException(e.getMessage(), e);
    } catch (CloudbreakImageCatalogException e) {
        LOGGER.info("Cloudbreak Image Catalog error", e);
        throw new CloudbreakApiException(e.getMessage(), e);
    }
    measure(() -> addTemplateForStack(savedStack, connector.waitGetTemplate(templateRequest)), LOGGER, "Save cluster template took {} ms for stack {}", stackName);
    return savedStack;
}
Also used : CloudbreakImageNotFoundException(com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException) Component(com.sequenceiq.cloudbreak.domain.stack.Component) CloudbreakApiException(com.sequenceiq.cloudbreak.exception.CloudbreakApiException) GetPlatformTemplateRequest(com.sequenceiq.cloudbreak.cloud.event.platform.GetPlatformTemplateRequest) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) AutoscaleStack(com.sequenceiq.cloudbreak.domain.projection.AutoscaleStack) CloudbreakImageCatalogException(com.sequenceiq.cloudbreak.core.CloudbreakImageCatalogException) Measure(com.sequenceiq.cloudbreak.aspect.Measure)

Example 5 with Measure

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

the class SaltConnector method pillar.

@Measure(SaltConnector.class)
@Retryable(value = ClusterProxyWebApplicationException.class, backoff = @Backoff(delay = 1000))
public GenericResponses pillar(Iterable<String> targets, Pillar pillar) {
    Response distributeResponse = postSignedJsonSaltRequest(SaltEndpoint.BOOT_PILLAR_DISTRIBUTE, pillar);
    if (distributeResponse.getStatus() == HttpStatus.SC_NOT_FOUND) {
        // simple pillar save for CB <= 1.14
        distributeResponse.close();
        try (Response singleResponse = postSignedJsonSaltRequest(SaltEndpoint.BOOT_PILLAR_SAVE, pillar)) {
            GenericResponses genericResponses = new GenericResponses();
            GenericResponse genericResponse = new GenericResponse();
            genericResponse.setAddress(targets.iterator().next());
            genericResponse.setStatusCode(singleResponse.getStatus());
            genericResponses.setResponses(Collections.singletonList(genericResponse));
            return genericResponses;
        }
    }
    return JaxRSUtil.response(distributeResponse, GenericResponses.class);
}
Also used : GenericResponse(com.sequenceiq.cloudbreak.orchestrator.model.GenericResponse) Response(javax.ws.rs.core.Response) FingerprintsResponse(com.sequenceiq.cloudbreak.orchestrator.salt.domain.FingerprintsResponse) GenericResponse(com.sequenceiq.cloudbreak.orchestrator.model.GenericResponse) GenericResponses(com.sequenceiq.cloudbreak.orchestrator.model.GenericResponses) 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