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());
}
}
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());
}
}
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;
});
}
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;
}
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);
}
Aggregations