// create connection
HelixConnection connection = new ZkHelixConnection(zkAddr);
connection.connect();
// setup cluster
ClusterAccessor clusterAccessor = connection.createClusterAccessor(clusterId);
clusterAccessor.dropCluster();
StateModelDefinition stateModelDef =
new StateModelDefinition.Builder(stateModelDefId).addState(master, 1).addState(slave, 2)
.addState(offline, 3).addState(dropped).addTransition(offline, slave, 3)
.addTransition(slave, offline, 4).addTransition(slave, master, 2)
.addTransition(master, slave, 1).addTransition(offline, dropped).initialState(offline)
.upperBound(master, 1).dynamicUpperBound(slave, "R").build();
RebalancerContext rebalancerCtx =
new SemiAutoRebalancerContext.Builder(resourceId).addPartitions(1).replicaCount(1)
.stateModelDefId(stateModelDefId)
.preferenceList(PartitionId.from("testDB_0"), Arrays.asList(participantId)).build();
clusterAccessor.createCluster(new ClusterConfig.Builder(clusterId).addStateModelDefinition(
stateModelDef).build());
clusterAccessor.addResourceToCluster(new ResourceConfig.Builder(resourceId).rebalancerContext(
rebalancerCtx).build());
clusterAccessor.addParticipantToCluster(new ParticipantConfig.Builder(participantId).build());
// start controller
HelixController controller = connection.createController(clusterId, controllerId);
controller.startAsync();