use of com.sequenceiq.flow.api.model.FlowIdentifier in project cloudbreak by hortonworks.
the class SdxBackupRestoreService method triggerDatalakeDatabaseBackupFlow.
private SdxDatabaseBackupResponse triggerDatalakeDatabaseBackupFlow(Long clusterId, SdxDatabaseBackupRequest backupRequest) {
String selector = DATALAKE_DATABASE_BACKUP_EVENT.event();
String userId = ThreadBasedUserCrnProvider.getUserCrn();
DatalakeDatabaseBackupStartEvent startEvent = new DatalakeDatabaseBackupStartEvent(selector, clusterId, userId, backupRequest);
FlowIdentifier flowIdentifier = sdxReactorFlowManager.triggerDatalakeDatabaseBackupFlow(startEvent);
return new SdxDatabaseBackupResponse(startEvent.getDrStatus().getOperationId(), flowIdentifier);
}
use of com.sequenceiq.flow.api.model.FlowIdentifier in project cloudbreak by hortonworks.
the class ClusterCommonService method put.
public FlowIdentifier put(String crn, UpdateClusterV4Request updateJson) {
Stack stack = stackService.getByCrnWithLists(crn);
Long stackId = stack.getId();
MDCBuilder.buildMdcContext(stack);
UserNamePasswordV4Request userNamePasswordJson = updateJson.getUserNamePassword();
FlowIdentifier flowIdentifier;
if (userNamePasswordJson != null) {
flowIdentifier = clusterManagerUserNamePasswordChange(stack, userNamePasswordJson);
} else if (updateJson.getStatus() != null) {
LOGGER.debug("Cluster status update request received. Stack id: {}, status: {} ", stackId, updateJson.getStatus());
flowIdentifier = clusterOperationService.updateStatus(stackId, updateJson.getStatus());
} else if (updateJson.getBlueprintName() != null && updateJson.getHostgroups() != null && stack.getCluster().isCreateFailed()) {
LOGGER.debug("Cluster rebuild request received. Stack id: {}", stackId);
try {
flowIdentifier = recreateCluster(stack, updateJson);
} catch (TransactionExecutionException e) {
throw new TransactionRuntimeExecutionException(e);
}
} else if (updateJson.getHostGroupAdjustment() != null) {
environmentService.checkEnvironmentStatus(stack, EnvironmentStatus.upscalable());
flowIdentifier = clusterHostgroupAdjustmentChange(stackId, updateJson, stack);
} else {
LOGGER.info("Invalid cluster update request received. Stack id: {}", stackId);
throw new BadRequestException("Invalid update cluster request!");
}
return flowIdentifier;
}
use of com.sequenceiq.flow.api.model.FlowIdentifier in project cloudbreak by hortonworks.
the class ClusterCommonService method setMaintenanceMode.
public FlowIdentifier setMaintenanceMode(Stack stack, MaintenanceModeStatus maintenanceMode) {
Cluster cluster = stack.getCluster();
if (cluster == null) {
throw new BadRequestException(String.format("Cluster does not exist on stack with '%s' id.", stack.getId()));
} else if (!stack.isAvailable() && !stack.isMaintenanceModeEnabled()) {
throw new BadRequestException(String.format("Cluster '%s' is currently in '%s' state. Maintenance mode can be set to a cluster if it is 'AVAILABLE'.", stack.getId(), stack.getStatus()));
}
FlowIdentifier flowIdentifier = FlowIdentifier.notTriggered();
switch(maintenanceMode) {
case ENABLED:
saveAndFireEventOnClusterStatusChange(stack, DetailedStackStatus.MAINTENANCE_MODE_ENABLED, ResourceEvent.MAINTENANCE_MODE_ENABLED);
break;
case DISABLED:
saveAndFireEventOnClusterStatusChange(stack, DetailedStackStatus.AVAILABLE, ResourceEvent.MAINTENANCE_MODE_DISABLED);
break;
case VALIDATION_REQUESTED:
if (!MAINTENANCE_MODE_ENABLED.equals(stack.getStatus())) {
throw new BadRequestException(String.format("Maintenance mode is not enabled for cluster '%s' (status:'%s'), it should be enabled before validation.", cluster.getId(), stack.getStatus()));
}
flowIdentifier = clusterOperationService.triggerMaintenanceModeValidation(stack);
clusterService.save(cluster);
break;
default:
// Nothing to do here
break;
}
return flowIdentifier;
}
use of com.sequenceiq.flow.api.model.FlowIdentifier in project cloudbreak by hortonworks.
the class ClusterOperationService method stop.
private FlowIdentifier stop(Stack stack) {
StopRestrictionReason reason = stackStopRestrictionService.isInfrastructureStoppable(stack);
FlowIdentifier flowIdentifier = FlowIdentifier.notTriggered();
if (stack.isStopped()) {
eventService.fireCloudbreakEvent(stack.getId(), stack.getStatus().name(), CLUSTER_STOP_IGNORED);
} else if (reason != StopRestrictionReason.NONE) {
throw new BadRequestException(String.format("Cannot stop the cluster. Reason: %s", reason.getReason()));
} else if (!stack.isReadyForStop() && !stack.isStopFailed()) {
throw NotAllowedStatusUpdate.cluster(stack).to(STOPPED).expectedIn(AVAILABLE).badRequest();
} else {
flowIdentifier = flowManager.triggerClusterStop(stack.getId());
}
return flowIdentifier;
}
use of com.sequenceiq.flow.api.model.FlowIdentifier 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