use of com.sequenceiq.cloudbreak.service.CloudbreakException in project cloudbreak by hortonworks.
the class AmbariDecommissioner method collectDownscaleCandidates.
public Set<String> collectDownscaleCandidates(Stack stack, String hostGroupName, Integer scalingAdjustment) throws CloudbreakException {
Cluster cluster = stack.getCluster();
int adjustment = Math.abs(scalingAdjustment);
Set<String> hostsToRemove = selectHostsToRemove(collectDownscaleCandidates(stack, cluster, hostGroupName, adjustment), adjustment);
if (hostsToRemove.size() != adjustment) {
throw new CloudbreakException(String.format("Only %d hosts found to downscale but %d required.", hostsToRemove.size(), adjustment));
}
return hostsToRemove;
}
use of com.sequenceiq.cloudbreak.service.CloudbreakException in project cloudbreak by hortonworks.
the class AmbariClusterModificationService method startCluster.
@Override
public int startCluster(Stack stack) throws CloudbreakException {
AmbariClient ambariClient = clientFactory.getAmbariClient(stack, stack.getCluster());
PollingResult ambariHealthCheckResult = ambariPollingServiceProvider.ambariHealthChecker(stack, ambariClient);
if (isExited(ambariHealthCheckResult)) {
throw new CancellationException("Cluster was terminated while waiting for Ambari to start.");
} else if (isTimeout(ambariHealthCheckResult)) {
throw new CloudbreakException("Ambari server was not restarted properly.");
}
LOGGER.info("Starting Ambari agents on the hosts.");
Set<HostMetadata> hostsInCluster = hostMetadataRepository.findHostsInCluster(stack.getCluster().getId());
PollingResult hostsJoinedResult = ambariPollingServiceProvider.ambariHostJoin(stack, ambariClient, hostsInCluster);
if (isExited(hostsJoinedResult)) {
throw new CancellationException("Cluster was terminated while starting Ambari agents.");
}
LOGGER.info("Start all Hadoop services");
eventService.fireCloudbreakEvent(stack.getId(), UPDATE_IN_PROGRESS.name(), cloudbreakMessagesService.getMessage(AMBARI_CLUSTER_SERVICES_STARTING.code()));
int requestId = ambariClient.startAllServices();
if (requestId == -1) {
LOGGER.error("Failed to start Hadoop services.");
throw new CloudbreakException("Failed to start Hadoop services.");
}
return requestId;
}
use of com.sequenceiq.cloudbreak.service.CloudbreakException in project cloudbreak by hortonworks.
the class AmbariClusterModificationService method stopCluster.
@Override
public void stopCluster(Stack stack) throws CloudbreakException {
AmbariClient ambariClient = clientFactory.getAmbariClient(stack, stack.getCluster());
try {
boolean stopped = true;
Collection<Map<String, String>> values = ambariClient.getHostComponentsStates().values();
for (Map<String, String> value : values) {
for (String state : value.values()) {
if (!"INSTALLED".equals(state)) {
stopped = false;
}
}
}
if (!stopped) {
LOGGER.info("Stop all Hadoop services");
eventService.fireCloudbreakEvent(stack.getId(), UPDATE_IN_PROGRESS.name(), cloudbreakMessagesService.getMessage(AMBARI_CLUSTER_SERVICES_STOPPING.code()));
int requestId = ambariClient.stopAllServices();
if (requestId != -1) {
LOGGER.info("Waiting for Hadoop services to stop on stack");
PollingResult servicesStopResult = ambariOperationService.waitForOperations(stack, ambariClient, singletonMap("stop services", requestId), STOP_AMBARI_PROGRESS_STATE).getLeft();
if (isExited(servicesStopResult)) {
throw new CancellationException("Cluster was terminated while waiting for Hadoop services to start");
} else if (isTimeout(servicesStopResult)) {
throw new CloudbreakException("Timeout while stopping Ambari services.");
}
} else {
LOGGER.warn("Failed to stop Hadoop services.");
throw new CloudbreakException("Failed to stop Hadoop services.");
}
eventService.fireCloudbreakEvent(stack.getId(), UPDATE_IN_PROGRESS.name(), cloudbreakMessagesService.getMessage(AMBARI_CLUSTER_SERVICES_STOPPED.code()));
}
} catch (AmbariConnectionException ignored) {
LOGGER.debug("Ambari not running on the gateway machine, no need to stop it.");
}
}
use of com.sequenceiq.cloudbreak.service.CloudbreakException in project cloudbreak by hortonworks.
the class ClusterCreationService method handleClusterCreationFailure.
public void handleClusterCreationFailure(StackView stackView, Exception exception) {
if (stackView.getClusterView() != null) {
Cluster cluster = clusterService.getById(stackView.getClusterView().getId());
clusterService.cleanupKerberosCredential(cluster);
String errorMessage = exception instanceof CloudbreakException && exception.getCause() != null ? exception.getCause().getMessage() : exception.getMessage();
clusterService.updateClusterStatusByStackId(stackView.getId(), CREATE_FAILED, errorMessage);
stackUpdater.updateStackStatus(stackView.getId(), DetailedStackStatus.AVAILABLE);
flowMessageService.fireEventAndLog(stackView.getId(), Msg.AMBARI_CLUSTER_CREATE_FAILED, CREATE_FAILED.name(), errorMessage);
try {
OrchestratorType orchestratorType = orchestratorTypeResolver.resolveType(stackView.getOrchestrator().getType());
if (cluster != null && orchestratorType.containerOrchestrator()) {
clusterTerminationService.deleteClusterContainers(cluster);
}
} catch (CloudbreakException | TerminationFailedException ex) {
LOGGER.error("Cluster containers could not be deleted, preparation for reinstall failed: ", ex);
}
if (cluster != null && cluster.getEmailNeeded()) {
emailSenderService.sendProvisioningFailureEmail(cluster.getOwner(), stackView.getClusterView().getEmailTo(), cluster.getName());
flowMessageService.fireEventAndLog(stackView.getId(), Msg.AMBARI_CLUSTER_NOTIFICATION_EMAIL, AVAILABLE.name());
}
} else {
LOGGER.error("Cluster was null. Flow action was not required.");
}
}
use of com.sequenceiq.cloudbreak.service.CloudbreakException in project cloudbreak by hortonworks.
the class ClusterResetService method handleResetClusterFailure.
public void handleResetClusterFailure(StackView stackView, Exception exception) {
Cluster cluster = clusterService.retrieveClusterByStackId(stackView.getId());
clusterService.cleanupKerberosCredential(cluster.getId());
String errorMessage = exception instanceof CloudbreakException && exception.getCause() != null ? exception.getCause().getMessage() : exception.getMessage();
clusterService.updateClusterStatusByStackId(stackView.getId(), Status.CREATE_FAILED, errorMessage);
stackUpdater.updateStackStatus(stackView.getId(), DetailedStackStatus.AVAILABLE);
flowMessageService.fireEventAndLog(stackView.getId(), Msg.AMBARI_CLUSTER_CREATE_FAILED, Status.CREATE_FAILED.name(), errorMessage);
if (cluster.getEmailNeeded()) {
emailSenderService.sendProvisioningFailureEmail(cluster.getOwner(), stackView.getClusterView().getEmailTo(), cluster.getName());
flowMessageService.fireEventAndLog(stackView.getId(), Msg.AMBARI_CLUSTER_NOTIFICATION_EMAIL, Status.AVAILABLE.name());
}
}
Aggregations