use of com.sequenceiq.periscope.domain.History in project cloudbreak by hortonworks.
the class AutoScaleClusterCommonService method createHistoryAndNotification.
private void createHistoryAndNotification(Cluster cluster) {
History history;
history = cluster.isAutoscalingEnabled() ? historyService.createEntry(ScalingStatus.ENABLED, "Autoscaling has been enabled for the cluster.", 0, cluster) : historyService.createEntry(ScalingStatus.DISABLED, "Autoscaling has been disabled for the cluster.", 0, cluster);
notificationSender.send(history);
}
use of com.sequenceiq.periscope.domain.History in project cloudbreak by hortonworks.
the class ScalingRequest method scaleUp.
private void scaleUp(int scalingAdjustment, int totalNodes) {
String hostGroup = policy.getHostGroup();
String ambari = cluster.getHost();
AmbariAddressJson ambariAddressJson = new AmbariAddressJson();
ambariAddressJson.setAmbariAddress(ambari);
History history = null;
try {
LOGGER.info("Sending request to add {} instance(s) into host group '{}', triggered policy '{}'", scalingAdjustment, hostGroup, policy.getName());
Long stackId = cloudbreakClient.stackV1Endpoint().getStackForAmbari(ambariAddressJson).getId();
UpdateStackJson updateStackJson = new UpdateStackJson();
updateStackJson.setWithClusterEvent(true);
InstanceGroupAdjustmentJson instanceGroupAdjustmentJson = new InstanceGroupAdjustmentJson();
instanceGroupAdjustmentJson.setScalingAdjustment(scalingAdjustment);
instanceGroupAdjustmentJson.setInstanceGroup(hostGroup);
updateStackJson.setInstanceGroupAdjustment(instanceGroupAdjustmentJson);
cloudbreakClient.stackV1Endpoint().put(stackId, updateStackJson);
history = historyService.createEntry(ScalingStatus.SUCCESS, "Upscale successfully triggered", totalNodes, policy);
} catch (RuntimeException e) {
history = historyService.createEntry(ScalingStatus.FAILED, "Couldn't trigger upscaling due to: " + e.getMessage(), totalNodes, policy);
LOGGER.error("Error adding nodes to cluster", e);
} finally {
if (history != null) {
notificationSender.send(history);
}
}
}
use of com.sequenceiq.periscope.domain.History in project cloudbreak by hortonworks.
the class ClusterCreationEvaluator method createOrUpdateCluster.
private void createOrUpdateCluster(AutoscaleStackResponse stack, Optional<Cluster> clusterOptional) {
AmbariStack resolvedAmbari = createAmbariStack(stack);
Cluster cluster;
boolean sendNotification = false;
if (clusterOptional.isPresent()) {
cluster = clusterOptional.get();
MDCBuilder.buildMdcContext(cluster);
if (PENDING.equals(cluster.getState()) || SUSPENDED.equals(cluster.getState())) {
ambariHealthCheck(cluster.getUser(), resolvedAmbari);
LOGGER.info("Update cluster and set it's state to 'RUNNING' for Ambari host: {}", resolvedAmbari.getAmbari().getHost());
cluster = clusterService.update(cluster.getId(), resolvedAmbari, false, RUNNING, cluster.isAutoscalingEnabled());
sendNotification = true;
}
} else {
PeriscopeUser user = new PeriscopeUser(stack.getOwner(), null, stack.getAccount());
MDCBuilder.buildMdcContext(user, stack.getStackId(), null);
LOGGER.info("Creating cluster for Ambari host: {}", resolvedAmbari.getAmbari().getHost());
ambariHealthCheck(user, resolvedAmbari);
cluster = clusterService.create(user, resolvedAmbari, null);
sendNotification = true;
}
if (sendNotification) {
History history = historyService.createEntry(ScalingStatus.ENABLED, "Autoscaling has been enabled for the cluster.", 0, cluster);
notificationSender.send(history);
}
}
use of com.sequenceiq.periscope.domain.History in project cloudbreak by hortonworks.
the class ScalingRequest method scaleDown.
private void scaleDown(int scalingAdjustment, int totalNodes) {
String hostGroup = policy.getHostGroup();
String ambari = cluster.getHost();
AmbariAddressJson ambariAddressJson = new AmbariAddressJson();
ambariAddressJson.setAmbariAddress(ambari);
History history = null;
try {
LOGGER.info("Sending request to remove {} node(s) from host group '{}', triggered policy '{}'", scalingAdjustment, hostGroup, policy.getName());
Long stackId = cloudbreakClient.stackV1Endpoint().getStackForAmbari(ambariAddressJson).getId();
UpdateClusterJson updateClusterJson = new UpdateClusterJson();
HostGroupAdjustmentJson hostGroupAdjustmentJson = new HostGroupAdjustmentJson();
hostGroupAdjustmentJson.setScalingAdjustment(scalingAdjustment);
hostGroupAdjustmentJson.setWithStackUpdate(true);
hostGroupAdjustmentJson.setHostGroup(hostGroup);
updateClusterJson.setHostGroupAdjustment(hostGroupAdjustmentJson);
cloudbreakClient.clusterEndpoint().put(stackId, updateClusterJson);
history = historyService.createEntry(ScalingStatus.SUCCESS, "Downscale successfully triggered", totalNodes, policy);
} catch (Exception e) {
history = historyService.createEntry(ScalingStatus.FAILED, "Couldn't trigger downscaling due to: " + e.getMessage(), totalNodes, policy);
LOGGER.error("Error removing nodes from the cluster", e);
} finally {
if (history != null) {
notificationSender.send(history);
}
}
}
Aggregations