use of com.sequenceiq.cloudbreak.api.model.Status in project cloudbreak by hortonworks.
the class ClusterMonitor method execute.
@Override
public void execute(JobExecutionContext context) {
evalContext(context);
try {
CloudbreakClient cloudbreakClient = applicationContext.getBean(CloudbreakClientConfiguration.class).cloudbreakClient();
ClusterService clusterService = applicationContext.getBean(ClusterService.class);
List<Cluster> clusters = clusterService.findAll();
Set<AutoscaleStackResponse> allStacks = cloudbreakClient.stackV1Endpoint().getAllForAutoscale();
for (AutoscaleStackResponse stack : allStacks) {
Status clusterStatus = stack.getClusterStatus();
if (clusterStatus != null && AVAILABLE.equals(clusterStatus)) {
String ambariIp = stack.getAmbariServerIp();
Optional<Cluster> clusterOptional = clusters.stream().filter(c -> c.getStackId() != null && c.getStackId().equals(stack.getStackId())).findFirst();
if (ambariIp != null) {
ClusterCreationEvaluator clusterCreationEvaluator = applicationContext.getBean(ClusterCreationEvaluator.class);
clusterCreationEvaluator.setContext(new ClusterCreationEvaluatorContext(stack, clusterOptional));
executorService.submit(clusterCreationEvaluator);
} else {
LOGGER.info("Could not find Ambari for stack: {}(ID:{})", stack.getName(), stack.getStackId());
}
} else {
LOGGER.info("Do not create or update cluster while the Cloudbreak cluster {}(ID:{}) is in '{}' state instead of 'AVAILABLE'!", stack.getName(), stack.getStackId(), stack.getClusterStatus());
}
}
} catch (Exception ex) {
LOGGER.error("New clusters could not be synchronized from Cloudbreak.", ex);
}
}
use of com.sequenceiq.cloudbreak.api.model.Status in project cloudbreak by hortonworks.
the class CloudbreakUtil method waitForStatuses.
private static WaitResult waitForStatuses(CloudbreakClient cloudbreakClient, String stackId, Map<String, String> desiredStatuses) {
WaitResult waitResult = WaitResult.SUCCESSFUL;
Map<String, String> currentStatuses = new HashMap<>();
int retryCount = 0;
do {
LOGGER.info("Waiting for status(es) {}, stack id: {}, current status(es) {} ...", desiredStatuses, stackId, currentStatuses);
sleep();
StackV1Endpoint stackV1Endpoint = cloudbreakClient.stackV1Endpoint();
try {
Map<String, Object> statusResult = stackV1Endpoint.status(Long.valueOf(stackId));
for (String statusPath : desiredStatuses.keySet()) {
currentStatuses.put(statusPath, (String) statusResult.get(statusPath));
}
} catch (RuntimeException ignore) {
continue;
}
retryCount++;
} while (!checkStatuses(currentStatuses, desiredStatuses) && !checkFailedStatuses(currentStatuses) && retryCount < MAX_RETRY);
LOGGER.info("Status(es) {} for {} are in desired status(es) {}", desiredStatuses.keySet(), stackId, currentStatuses.values());
if (currentStatuses.values().stream().anyMatch(cs -> cs.contains("FAILED")) || checkNotExpectedDelete(currentStatuses, desiredStatuses)) {
waitResult = WaitResult.FAILED;
}
if (retryCount == MAX_RETRY) {
waitResult = WaitResult.TIMEOUT;
}
return waitResult;
}
use of com.sequenceiq.cloudbreak.api.model.Status in project cloudbreak by hortonworks.
the class StackStartStopService method handleError.
private void handleError(StackView stackView, Exception exception, DetailedStackStatus detailedStackStatus, Msg msg, String logMessage) {
LOGGER.error(logMessage, exception);
Status stackStatus = detailedStackStatus.getStatus();
stackUpdater.updateStackStatus(stackView.getId(), detailedStackStatus, logMessage + exception.getMessage());
flowMessageService.fireEventAndLog(stackView.getId(), msg, stackStatus.name(), exception.getMessage());
if (stackView.getClusterView() != null) {
clusterService.updateClusterStatusByStackId(stackView.getId(), STOPPED);
if (stackView.getClusterView().getEmailNeeded()) {
emailSenderService.sendStopFailureEmail(stackView.getClusterView().getOwner(), stackView.getClusterView().getEmailTo(), stackUtil.extractAmbariIp(stackView), stackView.getClusterView().getName());
flowMessageService.fireEventAndLog(stackView.getId(), Msg.STACK_NOTIFICATION_EMAIL, stackStatus.name());
}
}
}
use of com.sequenceiq.cloudbreak.api.model.Status in project cloudbreak by hortonworks.
the class AmbariClusterStatusUpdater method updateClusterStatus.
private void updateClusterStatus(Long stackId, Status stackStatus, Cluster cluster, ClusterStatus ambariClusterStatus) {
Status statusInEvent = stackStatus;
String statusReason = ambariClusterStatus.getStatusReason();
if (isUpdateEnabled(ambariClusterStatus)) {
if (updateClusterStatus(stackId, cluster, ambariClusterStatus.getClusterStatus())) {
statusInEvent = ambariClusterStatus.getStackStatus();
statusReason = ambariClusterStatus.getStatusReason();
} else {
statusReason = "The cluster's state is up to date.";
}
}
cloudbreakEventService.fireCloudbreakEvent(stackId, statusInEvent.name(), cloudbreakMessagesService.getMessage(Msg.AMBARI_CLUSTER_SYNCHRONIZED.code(), Collections.singletonList(statusReason)));
}
use of com.sequenceiq.cloudbreak.api.model.Status in project cloudbreak by hortonworks.
the class ClusterDownscaleService method handleClusterDownscaleFailure.
public void handleClusterDownscaleFailure(long stackId, Exception error) {
String errorDetailes = error.getMessage();
LOGGER.error("Error during Cluster downscale flow: ", error);
Status status = UPDATE_FAILED;
if (error instanceof NotEnoughNodeException) {
status = AVAILABLE;
}
clusterService.updateClusterStatusByStackId(stackId, status, errorDetailes);
stackUpdater.updateStackStatus(stackId, DetailedStackStatus.AVAILABLE, "Node(s) could not be removed from the cluster: " + errorDetailes);
flowMessageService.fireEventAndLog(stackId, Msg.AMBARI_CLUSTER_SCALING_FAILED, UPDATE_FAILED.name(), "removed from", errorDetailes);
}
Aggregations