if (resource.stateModel == null || resource.stateModel.name == null) {
throw new HelixException("Resource must specify a named state model!");
}
// if states is null, assume using a built-in or already-added state model
if (resource.stateModel.states != null) {
StateModelDefinition stateModelDef =
getStateModelDef(resource.stateModel, resource.constraints);
helixAdmin.addStateModelDef(cfg.clusterName, resource.stateModel.name, stateModelDef);
} else {
StateModelDefinition stateModelDef = null;
if (resource.stateModel.name.equals("MasterSlave")) {
stateModelDef =
new StateModelDefinition(StateModelConfigGenerator.generateConfigForMasterSlave());
} else if (resource.stateModel.name.equals("OnlineOffline")) {
stateModelDef =
new StateModelDefinition(StateModelConfigGenerator.generateConfigForOnlineOffline());
} else if (resource.stateModel.name.equals("LeaderStandby")) {
stateModelDef =
new StateModelDefinition(StateModelConfigGenerator.generateConfigForLeaderStandby());
}
if (stateModelDef != null) {
try {
helixAdmin.addStateModelDef(cfg.clusterName, resource.stateModel.name, stateModelDef);
} catch (HelixException e) {