use of com.sequenceiq.cloudbreak.domain.stack.Stack in project cloudbreak by hortonworks.
the class ClusterStartHandler method accept.
@Override
public void accept(Event<ClusterStartRequest> event) {
ClusterStartRequest request = event.getData();
ClusterStartResult result;
int requestId;
try {
Stack stack = stackService.getByIdWithListsInTransaction(request.getResourceId());
Optional<Stack> datalakeStack = datalakeService.getDatalakeStackByDatahubStack(stack);
CmTemplateProcessor blueprintProcessor = getCmTemplateProcessor(stack.getCluster());
if (datalakeStack.isPresent() && clusterServicesRestartService.isRDCRefreshNeeded(stack, datalakeStack.get())) {
requestId = clusterServicesRestartService.refreshClusterOnStart(stack, datalakeStack.get(), blueprintProcessor);
} else {
requestId = apiConnectors.getConnector(stack).startCluster();
}
handleStopStartScalingFeature(stack, blueprintProcessor);
result = new ClusterStartResult(request, requestId);
} catch (Exception e) {
result = new ClusterStartResult(e.getMessage(), e, request);
}
eventBus.notify(result.selector(), new Event<>(event.getHeaders(), result));
}
use of com.sequenceiq.cloudbreak.domain.stack.Stack in project cloudbreak by hortonworks.
the class ClusterStopHandler method accept.
@Override
public void accept(Event<ClusterStopRequest> event) {
ClusterStopRequest request = event.getData();
ClusterStopResult result;
try {
Stack stack = stackService.getByIdWithListsInTransaction(request.getResourceId());
boolean clusterManagerRunning = apiConnectors.getConnector(stack).clusterStatusService().isClusterManagerRunning();
if (clusterManagerRunning) {
apiConnectors.getConnector(stack).stopCluster(true);
} else {
LOGGER.info("Cluster manager isn't running, cannot stop it.");
}
result = new ClusterStopResult(request);
} catch (Exception e) {
LOGGER.warn("Cannot stop the cluster: ", e);
result = new ClusterStopResult(e.getMessage(), e, request);
}
eventBus.notify(result.selector(), new Event<>(event.getHeaders(), result));
}
use of com.sequenceiq.cloudbreak.domain.stack.Stack in project cloudbreak by hortonworks.
the class DeregisterServicesHandler method accept.
@Override
public void accept(Event<DeregisterServicesRequest> event) {
DeregisterServicesResult result;
try {
LOGGER.info("Received DeregisterServicesRequest event: {}", event.getData());
Stack stack = stackService.getByIdWithListsInTransaction(event.getData().getResourceId());
ClusterApi clusterApi = clusterApiConnectors.getConnector(stack);
Optional<DatalakeDto> datalakeDto = Optional.empty();
Optional<Stack> dataLakeOptional = datalakeService.getDatalakeStackByDatahubStack(stack);
if (dataLakeOptional.isPresent()) {
Stack dataLake = dataLakeOptional.get();
HttpClientConfig httpClientConfig = tlsSecurityService.buildTLSClientConfigForPrimaryGateway(dataLake.getId(), dataLake.getClusterManagerIp(), dataLake.cloudPlatform());
datalakeDto = Optional.ofNullable(DatalakeDto.DatalakeDtoBuilder.aDatalakeDto().withGatewayPort(dataLake.getGatewayPort()).withHttpClientConfig(httpClientConfig).withPassword(dataLake.getCluster().getCloudbreakAmbariPassword()).withUser(dataLake.getCluster().getCloudbreakAmbariUser()).withName(dataLake.getName()).build());
}
clusterApi.clusterSecurityService().deregisterServices(stack.getName(), datalakeDto);
LOGGER.info("Finished disabling Security");
result = new DeregisterServicesResult(event.getData());
} catch (Exception e) {
LOGGER.warn("An error has occured during disabling security", e);
result = new DeregisterServicesResult(e.getMessage(), e, event.getData());
}
LOGGER.info("Sending out DeregisterServicesResult: {}", result);
eventBus.notify(result.selector(), new Event<>(event.getHeaders(), result));
LOGGER.info("DeregisterServicesResult has been sent");
}
use of com.sequenceiq.cloudbreak.domain.stack.Stack in project cloudbreak by hortonworks.
the class DatabaseBackupHandler method doAccept.
@Override
protected Selectable doAccept(HandlerEvent<DatabaseBackupRequest> event) {
DatabaseBackupRequest request = event.getData();
Selectable result;
Long stackId = request.getResourceId();
LOGGER.debug("Backing up database on stack {}, backup id {}", stackId, request.getBackupId());
try {
Stack stack = stackService.getByIdWithListsInTransaction(stackId);
Cluster cluster = stack.getCluster();
InstanceMetaData gatewayInstance = stack.getPrimaryGatewayInstance();
GatewayConfig gatewayConfig = gatewayConfigService.getGatewayConfig(stack, gatewayInstance, cluster.hasGateway());
Set<String> gatewayFQDN = Collections.singleton(gatewayInstance.getDiscoveryFQDN());
ExitCriteriaModel exitModel = ClusterDeletionBasedExitCriteriaModel.clusterDeletionBasedModel(stackId, cluster.getId());
String rangerAdminGroup = rangerVirtualGroupService.getRangerVirtualGroup(stack);
SaltConfig saltConfig = saltConfigGenerator.createSaltConfig(request.getBackupLocation(), request.getBackupId(), rangerAdminGroup, request.getCloseConnections(), stack);
hostOrchestrator.backupDatabase(gatewayConfig, gatewayFQDN, stackUtil.collectReachableNodes(stack), saltConfig, exitModel);
result = new DatabaseBackupSuccess(stackId);
} catch (Exception e) {
LOGGER.error("Database backup event failed", e);
result = new DatabaseBackupFailedEvent(stackId, e, DetailedStackStatus.DATABASE_BACKUP_FAILED);
}
return result;
}
use of com.sequenceiq.cloudbreak.domain.stack.Stack in project cloudbreak by hortonworks.
the class AmbariStopServerAndAgentHandler method accept.
@Override
public void accept(Event<AmbariStopServerAndAgentRequest> event) {
AmbariStopServerAndAgentRequest request = event.getData();
Long stackId = request.getResourceId();
AmbariStopServerAndAgentResult result;
try {
Stack stack = stackService.getByIdWithListsInTransaction(stackId);
GatewayConfig primaryGatewayConfig = gatewayConfigService.getPrimaryGatewayConfig(stack);
Set<Node> allNodes = stackUtil.collectNodes(stack);
hostOrchestrator.stopClusterManagerOnMaster(primaryGatewayConfig, allNodes, clusterDeletionBasedModel(stack.getId(), stack.getCluster().getId()));
result = new AmbariStopServerAndAgentResult(request);
} catch (Exception e) {
String message = "Failed to start ambari agent and/or server on new host.";
LOGGER.error(message, e);
result = new AmbariStopServerAndAgentResult(message, e, request);
}
eventBus.notify(result.selector(), new Event<>(event.getHeaders(), result));
}
Aggregations