use of com.sequenceiq.periscope.domain.UpdateFailedDetails in project cloudbreak by hortonworks.
the class UpdateFailedHandlerTest method getARunningCluster.
private Cluster getARunningCluster() {
Cluster cluster = new Cluster();
cluster.setId(AUTOSCALE_CLUSTER_ID);
cluster.setStackCrn(CLOUDBREAK_STACK_CRN);
cluster.setState(ClusterState.RUNNING);
ClusterPertain clusterPertain = new ClusterPertain();
cluster.setClusterPertain(clusterPertain);
UpdateFailedDetails updateFailedDetails = new UpdateFailedDetails(Instant.now().minus(45, ChronoUnit.MINUTES).toEpochMilli(), 3L, true);
cluster.setUpdateFailedDetails(updateFailedDetails);
return cluster;
}
use of com.sequenceiq.periscope.domain.UpdateFailedDetails in project cloudbreak by hortonworks.
the class UpdateFailedHandler method onApplicationEvent.
@Override
public void onApplicationEvent(UpdateFailedEvent event) {
long autoscaleClusterId = event.getClusterId();
Cluster cluster = clusterService.findById(autoscaleClusterId);
LoggingUtils.buildMdcContext(cluster);
Integer failed = Optional.ofNullable(updateFailures.get(autoscaleClusterId)).map(failedCount -> failedCount + 1).orElse(1);
if (failed < RETRY_THRESHOLD) {
updateFailures.put(autoscaleClusterId, failed);
LOGGER.debug("Increased failed count '{}' for cluster '{}'", failed, cluster.getStackCrn());
if (event.getCausedBy() instanceof ForbiddenException && event.isWithMachineUser()) {
Integer forbiddencount = getForbiddenFailureCount(cluster) + 1;
UpdateFailedDetails updateFailedDetails = new UpdateFailedDetails(event.getLastExceptionTimestamp(), forbiddencount.longValue(), event.isWithMachineUser());
clusterService.setUpdateFailedDetails(cluster.getId(), updateFailedDetails);
LOGGER.debug("Increased forbidden count '{}' for cluster '{}' with failure details: {}, and machine user: {}", forbiddencount, cluster.getStackCrn(), updateFailedDetails, cluster.getMachineUserCrn());
}
} else {
if (getForbiddenFailureCount(cluster) > 0) {
LOGGER.info("Forbidden(403) failure(s) are present for cluster: {}, re-initialising polling machine user", cluster.getStackCrn());
altusMachineUserService.initializeMachineUserForEnvironment(cluster);
clusterService.setUpdateFailedDetails(cluster.getId(), null);
}
suspendCluster(cluster);
updateFailures.remove(autoscaleClusterId);
historyService.createEntry(ScalingStatus.TRIGGER_FAILED, messagesService.getMessage(MessageCode.AUTOSCALING_TRIGGER_FAILURE), cluster);
LOGGER.debug("Suspended cluster monitoring for cluster '{}' due to failing update attempts", cluster.getStackCrn());
}
}
Aggregations