/**
* create a new cluster, fail if it already exists
* @return true if created, false if creation failed
*/
public boolean createCluster(ClusterConfig cluster) {
ClusterConfiguration configuration = _accessor.getProperty(_keyBuilder.clusterConfig());
if (configuration != null && isClusterStructureValid()) {
LOG.error("Cluster already created. Aborting.");
return false;
}
clearClusterStructure();
initClusterStructure();
Map<StateModelDefId, StateModelDefinition> stateModelDefs = cluster.getStateModelMap();
for (StateModelDefinition stateModelDef : stateModelDefs.values()) {
addStateModelDefinition(stateModelDef);
}
Map<ResourceId, ResourceConfig> resources = cluster.getResourceMap();
for (ResourceConfig resource : resources.values()) {
addResource(resource);
}
Map<ParticipantId, ParticipantConfig> participants = cluster.getParticipantMap();
for (ParticipantConfig participant : participants.values()) {
addParticipant(participant);
}
_accessor.createProperty(_keyBuilder.constraints(), null);
for (ClusterConstraints constraints : cluster.getConstraintMap().values()) {
_accessor.setProperty(_keyBuilder.constraint(constraints.getType().toString()), constraints);
}
ClusterConfiguration clusterConfig =
ClusterConfiguration.from(_clusterId, cluster.getUserConfig());
if (cluster.autoJoinAllowed()) {
clusterConfig.setAutoJoinAllowed(cluster.autoJoinAllowed());
}
if (cluster.isPaused()) {
_accessor.createProperty(_keyBuilder.pause(), new PauseSignal("pause"));
}
_accessor.setProperty(_keyBuilder.clusterConfig(), clusterConfig);