if (request.getStackVersion() == null
|| request.getStackVersion().isEmpty()) {
throw new IllegalArgumentException("Stack information should be"
+ " provided when creating a cluster");
}
StackId stackId = new StackId(request.getStackVersion());
StackInfo stackInfo = ambariMetaInfo.getStackInfo(stackId.getStackName(),
stackId.getStackVersion());
if (stackInfo == null) {
throw new StackAccessException("stackName=" + stackId.getStackName() + ", stackVersion=" + stackId.getStackVersion());
}
// FIXME add support for desired configs at cluster level
boolean foundInvalidHosts = false;
StringBuilder invalidHostsStr = new StringBuilder();
if (request.getHostNames() != null) {
for (String hostname : request.getHostNames()) {
try {
clusters.getHost(hostname);
} catch (HostNotFoundException e) {
if (foundInvalidHosts) {
invalidHostsStr.append(",");
}
foundInvalidHosts = true;
invalidHostsStr.append(hostname);
}
}
}
if (foundInvalidHosts) {
throw new HostNotFoundException(invalidHostsStr.toString());
}
clusters.addCluster(request.getClusterName());
Cluster c = clusters.getCluster(request.getClusterName());
if (request.getStackVersion() != null) {
StackId newStackId = new StackId(request.getStackVersion());
c.setDesiredStackVersion(newStackId);
clusters.setCurrentStackVersion(request.getClusterName(), newStackId);
}
if (request.getHostNames() != null) {