LOG.info("Received a cluster update request"
+ ", clusterName=" + request.getClusterName()
+ ", request=" + request);
requestedVersion = new StackId(requestedVersionString);
if (!requestedVersion.getStackName().equals(currentVersion.getStackName())) {
throw new AmbariException("Upgrade not possible between different stacks.");
}
requiresVersionUpdate = !currentVersion.equals(requestedVersion);
if(!requiresVersionUpdate) {
LOG.info("The cluster is already at " + currentVersion);
}
}
if (requiresVersionUpdate && requiresHostListUpdate) {
throw new IllegalArgumentException("Invalid arguments, "
+ "cluster version cannot be upgraded"
+ " along with host list modifications");
}
if (requiresHostListUpdate) {
clusters.mapHostsToCluster(
request.getHostNames(), request.getClusterName());
}
if (requiresVersionUpdate) {
LOG.info("Upgrade cluster request received for stack " + requestedVersion);
boolean retry = false;
if (0 == currentVersion.compareTo(desiredVersion)) {
if (1 != requestedVersion.compareTo(currentVersion)) {
throw new AmbariException("Target version : " + requestedVersion
+ " must be greater than current version : " + currentVersion);
} else {
StackInfo stackInfo =
ambariMetaInfo.getStackInfo(requestedVersion.getStackName(), requestedVersion.getStackVersion());
if (stackInfo == null) {
throw new AmbariException("Target version : " + requestedVersion
+ " is not a recognized version");
}
if(!isUpgradeAllowed(stackInfo, currentVersion))
{
throw new AmbariException("Upgrade is not allowed from " + currentVersion
+ " to the target version " + requestedVersion);
}
}
} else {
retry = true;
LOG.info("Received upgrade request is a retry.");
if (0 != requestedVersion.compareTo(desiredVersion)) {
throw new AmbariException("Upgrade in progress to target version : "
+ desiredVersion
+ ". Illegal request to upgrade to : " + requestedVersion);
}
}