use of com.sequenceiq.cloudbreak.api.endpoint.v4.common.StackType in project cloudbreak by hortonworks.
the class ValidateCloudConfigHandler method doAccept.
@Override
protected Selectable doAccept(HandlerEvent<ValidateCloudConfigRequest> event) {
ValidateCloudConfigRequest data = event.getData();
Stack stack = stackService.getByIdWithLists(data.getResourceId());
String name = stack.getName();
DetailedEnvironmentResponse environment = environmentClientService.getByCrn(stack.getEnvironmentCrn());
Credential credential = credentialConverter.convert(environment.getCredential());
CloudCredential cloudCredential = credentialToCloudCredentialConverter.convert(credential);
ValidationResult.ValidationResultBuilder validationBuilder = ValidationResult.builder();
stackValidator.validate(stack, validationBuilder);
Set<InstanceGroup> instanceGroups = stack.getInstanceGroups();
measure(() -> {
for (InstanceGroup instanceGroup : instanceGroups) {
LOGGER.info("Validate template for {} name with {} instanceGroup.", name, instanceGroup.toString());
StackType type = stack.getType();
templateValidator.validate(credential, instanceGroup, stack, fromStackType(type == null ? null : type.name()), Optional.of(stack.getCreator()), validationBuilder);
}
}, LOGGER, "Stack's instance templates have been validated in {} ms for stack {}", name);
multiAzValidator.validateMultiAzForStack(stack.getPlatformVariant(), instanceGroups, validationBuilder);
ParametersValidationRequest parametersValidationRequest = parametersValidator.validate(stack.getCloudPlatform(), cloudCredential, stack.getParameters(), stack.getWorkspace().getId());
parametersValidator.waitResult(parametersValidationRequest, validationBuilder);
if (!StackType.LEGACY.equals(stack.getType())) {
dataLakeValidator.validate(stack, validationBuilder);
}
environmentValidator.validate(stack, environment, stack.getType().equals(StackType.WORKLOAD), validationBuilder);
ValidationResult validationResult = validationBuilder.build();
if (validationResult.getState() == ValidationResult.State.ERROR || validationResult.hasError()) {
LOGGER.debug("Stack request has validation error(s): {}.", validationResult.getFormattedErrors());
throw new IllegalStateException(validationResult.getFormattedErrors());
} else {
LOGGER.debug("Stack validation has been finished without any error.");
return new StackEvent(CloudConfigValidationEvent.VALIDATE_CLOUD_CONFIG_FINISHED_EVENT.selector(), data.getResourceId());
}
}
use of com.sequenceiq.cloudbreak.api.endpoint.v4.common.StackType in project cloudbreak by hortonworks.
the class StackService method getByNameInWorkspaceWithEntries.
public StackV4Response getByNameInWorkspaceWithEntries(String name, Long workspaceId, Set<String> entries, User user, StackType stackType) {
try {
return transactionService.required(() -> {
Workspace workspace = workspaceService.get(workspaceId, user);
ShowTerminatedClustersAfterConfig showTerminatedClustersAfterConfig = showTerminatedClusterConfigService.get();
Optional<Stack> stack = findByNameAndWorkspaceIdWithLists(name, workspace.getId(), stackType, showTerminatedClustersAfterConfig);
if (stack.isEmpty()) {
throw new NotFoundException(format(STACK_NOT_FOUND_BY_NAME_EXCEPTION_MESSAGE, name));
}
StackV4Response stackResponse = stackToStackV4ResponseConverter.convert(stack.get());
stackResponse = stackResponseDecorator.decorate(stackResponse, stack.get(), entries);
return stackResponse;
});
} catch (TransactionExecutionException e) {
throw new TransactionRuntimeExecutionException(e);
}
}
use of com.sequenceiq.cloudbreak.api.endpoint.v4.common.StackType in project cloudbreak by hortonworks.
the class ClouderaManagerSetupService method updateConfig.
@Override
public void updateConfig() {
com.sequenceiq.cloudbreak.api.endpoint.v4.common.StackType stackType = stack.getType();
try {
ClouderaManagerResourceApi clouderaManagerResourceApi = clouderaManagerApiFactory.getClouderaManagerResourceApi(apiClient);
ApiConfigList apiConfigList = new ApiConfigList().addItemsItem(removeRemoteParcelRepos()).addItemsItem(setHeader(stackType));
clouderaManagerResourceApi.updateConfig("Updated configurations.", apiConfigList);
} catch (ApiException e) {
throw mapApiException(e);
} catch (Exception e) {
throw mapException(e);
}
}
use of com.sequenceiq.cloudbreak.api.endpoint.v4.common.StackType in project cloudbreak by hortonworks.
the class StackCreatorService method determineStackTypeBasedOnTheUsedApi.
StackType determineStackTypeBasedOnTheUsedApi(Stack stack, boolean distroxRequest) {
StackType stackType = stack.getType();
boolean stackTypeIsWorkloadAndNotDistroXRequest = stack.getType() != null && StackType.WORKLOAD.equals(stack.getType()) && !distroxRequest;
boolean stackTypeIsNullAndNotDistroXRequest = stack.getType() == null && !distroxRequest;
if (stackTypeIsWorkloadAndNotDistroXRequest || stackTypeIsNullAndNotDistroXRequest) {
stackType = StackType.LEGACY;
}
return stackType;
}
use of com.sequenceiq.cloudbreak.api.endpoint.v4.common.StackType in project cloudbreak by hortonworks.
the class StackCreatorService method createStack.
public StackV4Response createStack(User user, Workspace workspace, StackV4Request stackRequest, boolean distroxRequest) {
long start = System.currentTimeMillis();
String stackName = stackRequest.getName();
nodeCountLimitValidator.validateProvision(stackRequest);
measure(() -> validateRecipeExistenceOnInstanceGroups(stackRequest.getInstanceGroups(), workspace.getId()), LOGGER, "Check that recipes do exist took {} ms");
measure(() -> ensureStackDoesNotExists(stackName, workspace), LOGGER, "Stack does not exist check took {} ms");
Stack stackStub = measure(() -> stackV4RequestToStackConverter.convert(stackRequest), LOGGER, "Stack request converted to stack took {} ms for stack {}", stackName);
stackStub.setWorkspace(workspace);
stackStub.setCreator(user);
StackType stackType = determineStackTypeBasedOnTheUsedApi(stackStub, distroxRequest);
stackStub.setType(stackType);
String platformString = stackStub.getCloudPlatform().toLowerCase();
MDCBuilder.buildMdcContext(stackStub);
Stack savedStack;
try {
Blueprint blueprint = measure(() -> determineBlueprint(stackRequest, workspace), LOGGER, "Blueprint determined in {} ms for stack {}", stackName);
Future<StatedImage> imgFromCatalogFuture = determineImageCatalog(stackName, platformString, stackRequest, blueprint, user, workspace);
hueWorkaroundValidatorService.validateForStackRequest(getHueHostGroups(blueprint.getBlueprintText()), stackStub.getName());
savedStack = transactionService.required(() -> {
Stack stack = measure(() -> stackDecorator.decorate(stackStub, stackRequest, user, workspace), LOGGER, "Decorate Stack with data took {} ms");
DetailedEnvironmentResponse environment = measure(() -> ThreadBasedUserCrnProvider.doAsInternalActor(regionAwareInternalCrnGeneratorFactory.iam().getInternalCrnForServiceAsString(), () -> environmentClientService.getByCrn(stack.getEnvironmentCrn())), LOGGER, "Get Environment from Environment service took {} ms");
if (stack.getOrchestrator() != null && stack.getOrchestrator().getApiEndpoint() != null) {
measure(() -> stackService.validateOrchestrator(stack.getOrchestrator()), LOGGER, "Validate orchestrator took {} ms");
}
stack.setUseCcm(environment.getTunnel().useCcm());
stack.setTunnel(environment.getTunnel());
if (stackRequest.getCluster() != null) {
measure(() -> setStackType(stack, blueprint), LOGGER, "Set stacktype for stack object took {} ms");
measure(() -> clusterCreationService.validate(stackRequest.getCluster(), stack, user, workspace, environment), LOGGER, "Validate cluster rds and autotls took {} ms");
}
measure(() -> fillInstanceMetadata(environment, stack), LOGGER, "Fill up instance metadata took {} ms");
StatedImage imgFromCatalog = measure(() -> getImageCatalog(imgFromCatalogFuture), LOGGER, "Select the correct image took {} ms");
stackRuntimeVersionValidator.validate(stackRequest, imgFromCatalog.getImage(), stackType);
Stack newStack = measure(() -> stackService.create(stack, platformString, imgFromCatalog, user, workspace, Optional.ofNullable(stackRequest.getResourceCrn())), LOGGER, "Save the remaining stack data took {} ms");
try {
LOGGER.info("Create cluster entity in the database with name {}.", stackName);
long clusterSaveStart = System.currentTimeMillis();
createClusterIfNeeded(user, stackRequest, newStack, stackName, blueprint);
LOGGER.info("Cluster save took {} ms", System.currentTimeMillis() - clusterSaveStart);
} catch (CloudbreakImageCatalogException | IOException | TransactionExecutionException e) {
throw new RuntimeException(e.getMessage(), e);
}
measure(() -> assignOwnerRoleOnDataHub(user, stackRequest, newStack), LOGGER, "assignOwnerRoleOnDataHub to stack took {} ms with name {}.", stackName);
return newStack;
});
} catch (TransactionExecutionException e) {
stackUnderOperationService.off();
if (e.getCause() instanceof DataIntegrityViolationException) {
String msg = String.format("Error with resource [%s], error: [%s]", APIResourceType.STACK, getProperSqlErrorMessage((DataIntegrityViolationException) e.getCause()));
throw new BadRequestException(msg, e.getCause());
}
throw new TransactionRuntimeExecutionException(e);
}
StackV4Response response = measure(() -> stackToStackV4ResponseConverter.convert(savedStack), LOGGER, "Stack response has been created for stack took {} ms with name {}", stackName);
LOGGER.info("Generated stack response after creation: {}", JsonUtil.writeValueAsStringSilentSafe(response));
FlowIdentifier flowIdentifier = measure(() -> flowManager.triggerProvisioning(savedStack.getId()), LOGGER, "Stack triggerProvisioning took {} ms with name {}", stackName);
response.setFlowIdentifier(flowIdentifier);
metricService.submit(STACK_PREPARATION, System.currentTimeMillis() - start);
return response;
}
Aggregations