use of com.sequenceiq.periscope.api.model.ScalingStatus in project cloudbreak by hortonworks.
the class AutoScaleClusterCommonService method createAutoscalingConfigChangedHistoryAndNotify.
protected void createAutoscalingConfigChangedHistoryAndNotify(Cluster cluster) {
ScalingStatus scalingStatus = ScalingStatus.DISABLED;
String statusMessage = messagesService.getMessage(MessageCode.AUTOSCALING_DISABLED);
if (!cluster.getLoadAlerts().isEmpty()) {
String loadBasedHostGroups = cluster.getLoadAlerts().stream().map(loadAlert -> loadAlert.getScalingPolicy().getHostGroup()).collect(Collectors.joining(","));
statusMessage = messagesService.getMessage(MessageCode.AUTOSCALING_CONFIG_UPDATED, List.of(AlertType.LOAD, loadBasedHostGroups));
scalingStatus = ScalingStatus.CONFIG_UPDATED;
} else if (!cluster.getTimeAlerts().isEmpty()) {
String timeBasedHostGroups = cluster.getTimeAlerts().stream().map(timeAlert -> timeAlert.getScalingPolicy().getHostGroup()).distinct().collect(Collectors.joining(","));
statusMessage = messagesService.getMessage(MessageCode.AUTOSCALING_CONFIG_UPDATED, List.of(AlertType.TIME, timeBasedHostGroups));
scalingStatus = ScalingStatus.CONFIG_UPDATED;
}
notificationSender.sendConfigUpdateNotification(cluster);
notificationSender.sendHistoryUpdateNotification(historyService.createEntry(scalingStatus, statusMessage, cluster), cluster);
}
use of com.sequenceiq.periscope.api.model.ScalingStatus in project cloudbreak by hortonworks.
the class ScalingRequest method scaleUp.
private void scaleUp(int scalingAdjustment, int hostGroupNodeCount) {
metricService.incrementMetricCounter(MetricType.CLUSTER_UPSCALE_TRIGGERED);
if (scalingHardLimitsService.isViolatingAutoscaleMaxStepInNodeCount(scalingAdjustment)) {
LOGGER.info("Upscale requested for '{}' nodes. Upscaling with the maximum allowed step size of '{}' node(s)", scalingAdjustment, scalingHardLimitsService.getMaxAutoscaleStepInNodeCount());
scalingAdjustment = scalingHardLimitsService.getMaxAutoscaleStepInNodeCount();
}
String hostGroup = policy.getHostGroup();
String statusReason = null;
ScalingStatus scalingStatus = null;
String stackCrn = cluster.getStackCrn();
String userCrn = cluster.getClusterPertain().getUserCrn();
try {
LOGGER.info("Sending request to add '{}' instance(s) into host group '{}', triggered adjustmentType '{}', cluster '{}', user '{}'", scalingAdjustment, hostGroup, policy.getAdjustmentType(), stackCrn, userCrn);
UpdateStackV4Request updateStackJson = new UpdateStackV4Request();
updateStackJson.setWithClusterEvent(true);
InstanceGroupAdjustmentV4Request instanceGroupAdjustmentJson = new InstanceGroupAdjustmentV4Request();
instanceGroupAdjustmentJson.setScalingAdjustment(scalingAdjustment);
instanceGroupAdjustmentJson.setInstanceGroup(hostGroup);
updateStackJson.setInstanceGroupAdjustment(instanceGroupAdjustmentJson);
if (Boolean.TRUE.equals(cluster.isStopStartScalingEnabled())) {
cloudbreakCrnClient.withInternalCrn().autoscaleEndpoint().putStackStartInstancesByCrn(stackCrn, updateStackJson);
} else {
cloudbreakCrnClient.withInternalCrn().autoscaleEndpoint().putStack(stackCrn, cluster.getClusterPertain().getUserId(), updateStackJson);
}
scalingStatus = ScalingStatus.SUCCESS;
statusReason = getMessageForCBSuccess();
metricService.incrementMetricCounter(MetricType.CLUSTER_UPSCALE_SUCCESSFUL);
} catch (RuntimeException e) {
scalingStatus = ScalingStatus.FAILED;
statusReason = getMessageForCBException(e);
LOGGER.error("Couldn't trigger upscaling for host group '{}', cluster '{}', desiredNodeCount '{}', error '{}' ", hostGroup, cluster.getStackCrn(), desiredHostGroupNodeCount, statusReason, e);
metricService.incrementMetricCounter(MetricType.CLUSTER_UPSCALE_FAILED);
} finally {
processAutoscalingTriggered(scalingAdjustment, hostGroupNodeCount, statusReason, scalingStatus);
}
}
use of com.sequenceiq.periscope.api.model.ScalingStatus in project cloudbreak by hortonworks.
the class ScalingRequest method scaleDownByNodeIds.
private void scaleDownByNodeIds(List<String> decommissionNodeIds) {
metricService.incrementMetricCounter(MetricType.CLUSTER_DOWNSCALE_TRIGGERED);
String hostGroup = policy.getHostGroup();
String statusReason = null;
ScalingStatus scalingStatus = null;
try {
LOGGER.info("Sending request to remove nodeIdCount '{}', nodeId(s) '{}' from host group '{}', cluster '{}', user '{}'", decommissionNodeIds.size(), decommissionNodeIds, hostGroup, cluster.getStackCrn(), cluster.getClusterPertain().getUserCrn());
cloudbreakCommunicator.decommissionInstancesForCluster(cluster, decommissionNodeIds);
scalingStatus = ScalingStatus.SUCCESS;
statusReason = getMessageForCBSuccess();
metricService.incrementMetricCounter(MetricType.CLUSTER_DOWNSCALE_SUCCESSFUL);
} catch (Exception e) {
scalingStatus = ScalingStatus.FAILED;
metricService.incrementMetricCounter(MetricType.CLUSTER_DOWNSCALE_FAILED);
statusReason = getMessageForCBException(e);
LOGGER.error("Couldn't trigger decommissioning for host group '{}', cluster '{}', decommissionNodeCount '{}', " + "decommissionNodeIds '{}', error '{}' ", hostGroup, cluster.getStackCrn(), decommissionNodeIds.size(), decommissionNodeIds, statusReason, e);
} finally {
processAutoscalingTriggered(-decommissionNodeIds.size(), existingHostGroupNodeCount, statusReason, scalingStatus);
}
}
use of com.sequenceiq.periscope.api.model.ScalingStatus in project cloudbreak by hortonworks.
the class ScalingRequest method scaleDown.
private void scaleDown(int scalingAdjustment, int totalNodes) {
metricService.incrementMetricCounter(MetricType.CLUSTER_DOWNSCALE_TRIGGERED);
String hostGroup = policy.getHostGroup();
String statusReason = null;
ScalingStatus scalingStatus = null;
String stackCrn = cluster.getStackCrn();
String userCrn = cluster.getClusterPertain().getUserCrn();
try {
LOGGER.info("Sending request to remove '{}' node(s) from host group '{}', triggered adjustmentType '{}', cluster '{}', user '{}'", scalingAdjustment, hostGroup, policy.getAdjustmentType(), stackCrn, userCrn);
UpdateClusterV4Request updateClusterJson = new UpdateClusterV4Request();
HostGroupAdjustmentV4Request hostGroupAdjustmentJson = new HostGroupAdjustmentV4Request();
hostGroupAdjustmentJson.setScalingAdjustment(scalingAdjustment);
hostGroupAdjustmentJson.setWithStackUpdate(true);
hostGroupAdjustmentJson.setHostGroup(hostGroup);
hostGroupAdjustmentJson.setValidateNodeCount(false);
updateClusterJson.setHostGroupAdjustment(hostGroupAdjustmentJson);
// TODO CB-14929: CB-15153 List of nodes not provided. Do we really need to support this? Can Periscope always specify the list of nodes?
cloudbreakCrnClient.withInternalCrn().autoscaleEndpoint().putCluster(stackCrn, cluster.getClusterPertain().getUserId(), updateClusterJson);
scalingStatus = ScalingStatus.SUCCESS;
statusReason = getMessageForCBSuccess();
metricService.incrementMetricCounter(MetricType.CLUSTER_DOWNSCALE_SUCCESSFUL);
} catch (Exception e) {
scalingStatus = ScalingStatus.FAILED;
metricService.incrementMetricCounter(MetricType.CLUSTER_DOWNSCALE_FAILED);
statusReason = getMessageForCBException(e);
LOGGER.error("Couldn't trigger downscaling for host group '{}', cluster '{}', desiredNodeCount '{}', error '{}' ", hostGroup, cluster.getStackCrn(), desiredHostGroupNodeCount, statusReason, e);
} finally {
processAutoscalingTriggered(scalingAdjustment, totalNodes, statusReason, scalingStatus);
}
}
Aggregations