if(enableAuto != null || activeComputeNodeNum != null ||
maxComputeNodeNum != null || minComputeNodeNum != null) {
opsBlocker.blockUnsupportedOpsByCluster("syncSetElasticity", clusterName);
}
ClusterEntity cluster = clusterEntityMgr.findByName(clusterName);
ClusterRead clusterRead = getClusterByName(clusterName, false);
if (cluster == null) {
logger.error("cluster " + clusterName + " does not exist");
throw BddException.NOT_FOUND("Cluster", clusterName);
}
ValidationUtils.validateVersion(clusterEntityMgr, clusterName);
clusterEntityMgr.cleanupActionError(clusterName);
//update vm ioshares
if (ioPriority != null) {
prioritizeCluster(clusterName, ioPriority);
}
// as prioritizeCluster will update clusterEntity, here we need to refresh to avoid overriding
cluster = clusterEntityMgr.findByName(clusterName);
if (enableAuto != null && enableAuto != cluster.getAutomationEnable()) {
if (enableAuto && cluster.getDistroVendor().equalsIgnoreCase(Constants.MAPR_VENDOR)) {
logger.error("cluster " + clusterName + " is a MAPR distro, which cannot be auto scaled");
throw BddException.NOT_ALLOWED_SCALING("cluster", clusterName);
}
cluster.setAutomationEnable(enableAuto);
}
if (minComputeNodeNum != null
&& minComputeNodeNum != cluster.getVhmMinNum()) {
cluster.setVhmMinNum(minComputeNodeNum);
}
if (maxComputeNodeNum != null
&& maxComputeNodeNum != cluster.getVhmMaxNum()) {
cluster.setVhmMaxNum(maxComputeNodeNum);
}
List<String> nodeGroupNames = new ArrayList<String>();
if ((enableAuto != null || minComputeNodeNum != null || maxComputeNodeNum != null || activeComputeNodeNum != null)
&& !clusterRead.validateSetManualElasticity(nodeGroupNames)) {
throw BddException.INVALID_PARAMETER("cluster", clusterName);
}
if (activeComputeNodeNum != null) {
if (!activeComputeNodeNum.equals(cluster.getVhmTargetNum())) {
cluster.setVhmTargetNum(activeComputeNodeNum);
}
}
//enableAuto is only set during cluster running status and
//other elasticity attributes are only set during cluster running/stop status
if ((enableAuto != null)
&& !cluster.getStatus().isActiveServiceStatus()) {
logger.error("Cannot change elasticity mode, when cluster "
+ clusterName + " is in " + cluster.getStatus() + " status");
throw ClusterManagerException.SET_AUTO_ELASTICITY_NOT_ALLOWED_ERROR(
clusterName, "The cluster's status must be RUNNING");
}
if (!cluster.getStatus().isActiveServiceStatus()
&& !ClusterStatus.SERVICE_STOPPED.equals(cluster.getStatus())
&& !ClusterStatus.STOPPED.equals(cluster.getStatus())) {
logger.error("Cannot change elasticity parameters, when cluster "
+ clusterName + " is in " + cluster.getStatus() + " status");
throw ClusterManagerException.SET_AUTO_ELASTICITY_NOT_ALLOWED_ERROR(
clusterName, "The cluster's status must be RUNNING, SERVICE_WARNING, SERVICE_ERROR or STOPPED");
}
clusterEntityMgr.update(cluster);
//update vhm extra config file
if (enableAuto != null || minComputeNodeNum != null || maxComputeNodeNum != null) {
boolean success =
clusteringService.setAutoElasticity(clusterName, false);
if (!success) {
throw ClusterManagerException
.FAILED_TO_SET_AUTO_ELASTICITY_ERROR(clusterName,
"Could not update elasticity configuration file");
}
}
//waitForManual if switch to Manual and targetNodeNum is null
if (enableAuto != null && !enableAuto
&& cluster.getVhmTargetNum() == null) {
JobUtils.waitForManual(clusterName, executionService);
}
return nodeGroupNames;
}