resumeCreateCluster(name);
return;
}
// build ClusterCreate object
ClusterCreate clusterCreate = new ClusterCreate();
clusterCreate.setName(name);
if (!CommandsUtils.isBlank(appManager)
&& !Constants.IRONFAN.equalsIgnoreCase(appManager)) {
AppManagerRead appManagerRead = appManagerRestClient.get(appManager);
if (appManagerRead == null) {
CommandsUtils
.printCmdFailure(
Constants.OUTPUT_OBJECT_CLUSTER,
name,
Constants.OUTPUT_OP_CREATE,
Constants.OUTPUT_OP_RESULT_FAIL,
appManager
+ " cannot be found in the list of application managers.");
return;
}
}
if (CommandsUtils.isBlank(appManager)) {
clusterCreate.setAppManager(Constants.IRONFAN);
} else {
clusterCreate.setAppManager(appManager);
// local yum repo url for 3rd party app managers like ClouderaMgr, Ambari etc.
if (!CommandsUtils.isBlank(localRepoURL)) {
clusterCreate.setLocalRepoURL(localRepoURL);
}
}
if (setClusterPassword) {
String password = getPassword();
//user would like to set password, but failed to enter
//a valid one, quit cluster create
if (password == null) {
return;
} else {
clusterCreate.setPassword(password);
}
}
if (type != null) {
ClusterType clusterType = ClusterType.getByDescription(type);
if (clusterType == null) {
CommandsUtils.printCmdFailure(Constants.OUTPUT_OBJECT_CLUSTER,
name, Constants.OUTPUT_OP_CREATE,
Constants.OUTPUT_OP_RESULT_FAIL, Constants.INVALID_VALUE
+ " " + "type=" + type);
return;
}
clusterCreate.setType(clusterType);
} else if (specFilePath == null) {
// create Hadoop (HDFS + MapReduce) cluster as default
clusterCreate.setType(ClusterType.HDFS_MAPRED);
}
TopologyType policy = null;
if (topology != null) {
policy = validateTopologyValue(name, topology);
if (policy == null) {
return;
}
} else {
policy = TopologyType.NONE;
}
clusterCreate.setTopologyPolicy(policy);
DistroRead distroRead4Create;
try {
if (distro != null) {
DistroRead[] distroReads =
appManagerRestClient
.getDistros(clusterCreate.getAppManager());
distroRead4Create = getDistroByName(distroReads, distro);
if (distroRead4Create == null) {
CommandsUtils.printCmdFailure(Constants.OUTPUT_OBJECT_CLUSTER,
name, Constants.OUTPUT_OP_CREATE,
Constants.OUTPUT_OP_RESULT_FAIL, Constants.PARAM_DISTRO
+ Constants.PARAM_NOT_SUPPORTED
+ getDistroNames(distroReads));
return;
}
} else {
distroRead4Create =
appManagerRestClient.getDefaultDistro(clusterCreate
.getAppManager());
if (distroRead4Create == null
|| CommandsUtils.isBlank(distroRead4Create.getName())) {
CommandsUtils.printCmdFailure(Constants.OUTPUT_OBJECT_CLUSTER,
name, Constants.OUTPUT_OP_CREATE,
Constants.OUTPUT_OP_RESULT_FAIL,
Constants.PARAM_NO_DEFAULT_DISTRO);
return;
}
}
} catch (CliRestException e) {
CommandsUtils.printCmdFailure(Constants.OUTPUT_OBJECT_CLUSTER, name,
Constants.OUTPUT_OP_CREATE, Constants.OUTPUT_OP_RESULT_FAIL,
e.getMessage());
return;
}
clusterCreate.setDistro(distroRead4Create.getName());
clusterCreate.setDistroVendor(distroRead4Create.getVendor());
clusterCreate.setDistroVersion(distroRead4Create.getVersion());
if (rpNames != null) {
List<String> rpNamesList = CommandsUtils.inputsConvert(rpNames);
if (rpNamesList.isEmpty()) {
CommandsUtils.printCmdFailure(Constants.OUTPUT_OBJECT_CLUSTER,
name, Constants.OUTPUT_OP_CREATE,
Constants.OUTPUT_OP_RESULT_FAIL,
Constants.INPUT_RPNAMES_PARAM + Constants.MULTI_INPUTS_CHECK);
return;
} else {
clusterCreate.setRpNames(rpNamesList);
}
}
if (dsNames != null) {
List<String> dsNamesList = CommandsUtils.inputsConvert(dsNames);
if (dsNamesList.isEmpty()) {
CommandsUtils.printCmdFailure(Constants.OUTPUT_OBJECT_CLUSTER,
name, Constants.OUTPUT_OP_CREATE,
Constants.OUTPUT_OP_RESULT_FAIL,
Constants.INPUT_DSNAMES_PARAM + Constants.MULTI_INPUTS_CHECK);
return;
} else {
clusterCreate.setDsNames(dsNamesList);
}
}
List<String> failedMsgList = new ArrayList<String>();
List<String> warningMsgList = new ArrayList<String>();
Set<String> allNetworkNames = new HashSet<String>();
try {
if (specFilePath != null) {
ClusterCreate clusterSpec =
CommandsUtils.getObjectByJsonString(ClusterCreate.class,
CommandsUtils.dataFromFile(specFilePath));
clusterCreate.setSpecFile(true);
clusterCreate.setExternalHDFS(clusterSpec.getExternalHDFS());
clusterCreate.setExternalMapReduce(clusterSpec
.getExternalMapReduce());
clusterCreate.setNodeGroups(clusterSpec.getNodeGroups());
clusterCreate.setConfiguration(clusterSpec.getConfiguration());
// TODO: W'd better merge validateConfiguration with validateClusterSpec to avoid repeated validation.
if (CommandsUtils.isBlank(appManager)
|| Constants.IRONFAN.equalsIgnoreCase(appManager)) {
validateConfiguration(clusterCreate, skipConfigValidation,
warningMsgList, failedMsgList);