use of com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionExecutionException in project cloudbreak by hortonworks.
the class StackStartStopService method finishStackStop.
public void finishStackStop(StackStartStopContext context, StopInstancesResult stopInstancesResult) {
Stack stack = context.getStack();
try {
transactionService.required(() -> updateInstancesToStopped(stack, stopInstancesResult.getResults().getResults()));
} catch (TransactionExecutionException e) {
LOGGER.error("Error occurred during the finish stack stop: {}", e.getMessage(), e);
throw new TransactionRuntimeExecutionException(e);
}
validateResourceResults(context.getCloudContext(), stopInstancesResult.getErrorDetails(), stopInstancesResult.getResults(), false);
stackUpdater.updateStackStatus(stack.getId(), DetailedStackStatus.STOPPED, "Cluster infrastructure stopped successfully.");
flowMessageService.fireEventAndLog(stack.getId(), STOPPED.name(), STACK_INFRASTRUCTURE_STOPPED);
}
use of com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionExecutionException in project cloudbreak by hortonworks.
the class TerminationService method finalizeTermination.
public void finalizeTermination(Long stackId, boolean force) {
Stack stack = stackService.getByIdWithListsInTransaction(stackId);
Date now = new Date();
cleanupFreeIpa(stack);
String terminatedName = stack.getName() + DELIMITER + now.getTime();
Cluster cluster = stack.getCluster();
try {
LOGGER.info("Starting to update the stack and cluster to delete completed");
transactionService.required(() -> {
if (cluster != null) {
try {
clusterTerminationService.finalizeClusterTermination(cluster.getId(), force);
} catch (TransactionExecutionException e) {
throw e.getCause();
}
}
terminateInstanceGroups(stack);
terminateMetaDataInstances(stack);
updateToDeleteCompleted(stack.getId(), terminatedName, "Stack was terminated successfully.");
return null;
});
} catch (TransactionExecutionException ex) {
LOGGER.info("Failed to terminate cluster infrastructure. Stack id {}", stack.getId());
deleteOnlyIfForced(stack, force, terminatedName);
throw new TerminationFailedException(ex);
}
}
use of com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionExecutionException in project cloudbreak by hortonworks.
the class ClusterTemplateService method listInWorkspaceAndCleanUpInvalids.
public Set<ClusterTemplateViewV4Response> listInWorkspaceAndCleanUpInvalids(Long workspaceId, String accountId) {
try {
boolean internalTenant = entitlementService.internalTenant(accountId);
Set<ClusterTemplateView> views = transactionService.required(() -> clusterTemplateViewService.findAllActive(workspaceId, internalTenant));
Set<ClusterTemplateViewV4Response> responses = transactionService.required(() -> views.stream().map(v -> clusterTemplateViewToClusterTemplateViewV4ResponseConverter.convert(v)).collect(toSet()));
environmentServiceDecorator.prepareEnvironments(responses);
cleanUpInvalidClusterDefinitions(workspaceId, responses);
return responses.stream().filter(this::isUsableClusterTemplate).filter(this::isClusterTemplateHasValidCloudPlatform).collect(toSet());
} catch (TransactionExecutionException e) {
LOGGER.warn("Unable to find cluster definitions due to {}", e.getMessage());
LOGGER.warn("Unable to find cluster definitions", e);
throw new CloudbreakServiceException("Unable to obtain cluster definitions!");
}
}
use of com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionExecutionException in project cloudbreak by hortonworks.
the class ClusterTemplateService method createForLoggedInUser.
public ClusterTemplate createForLoggedInUser(ClusterTemplate resource, Long workspaceId, String accountId, String creator) {
if (internalClusterTemplateValidator.isInternalTemplateInNotInternalTenant(entitlementService.internalTenant(accountId), resource.getFeatureState())) {
throw new AccessDeniedException("You can not create Internal Template for an outsider organization");
}
resource.setResourceCrn(createCRN(accountId));
try {
return transactionService.required(() -> {
ClusterTemplate created = super.createForLoggedInUser(resource, workspaceId);
ownerAssignmentService.assignResourceOwnerRoleIfEntitled(creator, resource.getResourceCrn(), accountId);
return created;
});
} catch (TransactionExecutionException e) {
if (e.getCause() instanceof BadRequestException) {
throw e.getCause();
}
throw new TransactionService.TransactionRuntimeExecutionException(e);
}
}
use of com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionExecutionException in project cloudbreak by hortonworks.
the class SdxService method createSdx.
private Pair<SdxCluster, FlowIdentifier> createSdx(final String userCrn, final String name, final SdxClusterRequest sdxClusterRequest, final StackV4Request internalStackV4Request, final ImageSettingsV4Request imageSettingsV4Request) {
LOGGER.info("Creating SDX cluster with name {}", name);
String accountId = getAccountIdFromCrn(userCrn);
validateSdxRequest(name, sdxClusterRequest.getEnvironment(), accountId);
DetailedEnvironmentResponse environment = validateAndGetEnvironment(sdxClusterRequest.getEnvironment());
CloudPlatform cloudPlatform = CloudPlatform.valueOf(environment.getCloudPlatform());
ImageV4Response imageV4Response = imageCatalogService.getImageResponseFromImageRequest(imageSettingsV4Request, cloudPlatform);
validateInternalSdxRequest(internalStackV4Request, sdxClusterRequest);
validateRuntimeAndImage(sdxClusterRequest, environment, imageSettingsV4Request, imageV4Response);
String runtimeVersion = getRuntime(sdxClusterRequest, internalStackV4Request, imageV4Response);
validateCcmV2Requirement(environment, runtimeVersion);
SdxCluster sdxCluster = validateAndCreateNewSdxCluster(userCrn, name, runtimeVersion, sdxClusterRequest.getClusterShape(), sdxClusterRequest.isEnableRangerRaz(), sdxClusterRequest.isEnableMultiAz(), environment);
setTagsSafe(sdxClusterRequest, sdxCluster);
if (isCloudStorageConfigured(sdxClusterRequest)) {
validateCloudStorageRequest(sdxClusterRequest.getCloudStorage(), environment);
String trimmedBaseLocation = StringUtils.stripEnd(sdxClusterRequest.getCloudStorage().getBaseLocation(), "/");
sdxCluster.setCloudStorageBaseLocation(trimmedBaseLocation);
sdxCluster.setCloudStorageFileSystemType(sdxClusterRequest.getCloudStorage().getFileSystemType());
sdxClusterRequest.getCloudStorage().setBaseLocation(trimmedBaseLocation);
} else if (!CloudPlatform.YARN.equalsIgnoreCase(cloudPlatform.name()) && !CloudPlatform.GCP.equalsIgnoreCase(cloudPlatform.name()) && !CloudPlatform.MOCK.equalsIgnoreCase(cloudPlatform.name()) && internalStackV4Request == null) {
throw new BadRequestException("Cloud storage parameter is required.");
}
externalDatabaseConfigurer.configure(cloudPlatform, sdxClusterRequest.getExternalDatabase(), sdxCluster);
updateStackV4RequestWithEnvironmentCrnIfNotExistsOnIt(internalStackV4Request, environment.getCrn());
StackV4Request stackRequest = getStackRequest(sdxClusterRequest.getClusterShape(), sdxClusterRequest.isEnableRangerRaz(), internalStackV4Request, cloudPlatform, runtimeVersion, imageSettingsV4Request);
overrideDefaultTemplateValues(stackRequest, sdxClusterRequest.getCustomInstanceGroups(), accountId);
validateRecipes(sdxClusterRequest, stackRequest, userCrn);
prepareCloudStorageForStack(sdxClusterRequest, stackRequest, sdxCluster, environment);
prepareDefaultSecurityConfigs(internalStackV4Request, stackRequest, cloudPlatform);
prepareProviderSpecificParameters(stackRequest, sdxClusterRequest, cloudPlatform);
updateStackV4RequestWithRecipes(sdxClusterRequest, stackRequest);
stackRequest.setResourceCrn(sdxCluster.getCrn());
sdxCluster.setStackRequest(stackRequest);
MDCBuilder.buildMdcContext(sdxCluster);
SdxCluster savedSdxCluster;
try {
savedSdxCluster = transactionService.required(() -> {
SdxCluster created = sdxClusterRepository.save(sdxCluster);
ownerAssignmentService.assignResourceOwnerRoleIfEntitled(created.getInitiatorUserCrn(), created.getCrn(), created.getAccountId());
sdxStatusService.setStatusForDatalakeAndNotify(DatalakeStatusEnum.REQUESTED, "Datalake requested", created);
return created;
});
} catch (TransactionExecutionException e) {
throw new TransactionRuntimeExecutionException(e);
}
FlowIdentifier flowIdentifier = sdxReactorFlowManager.triggerSdxCreation(savedSdxCluster);
return Pair.of(savedSdxCluster, flowIdentifier);
}
Aggregations