use of org.apache.helix.model.ClusterConfig in project helix by apache.
the class TestClusterInMaintenanceModeWhenReachingOfflineInstancesLimit method beforeClass.
@BeforeClass
public void beforeClass() throws Exception {
System.out.println("START " + CLASS_NAME + " at " + new Date(System.currentTimeMillis()));
String namespace = "/" + CLUSTER_NAME;
if (_gZkClient.exists(namespace)) {
_gZkClient.deleteRecursively(namespace);
}
_gSetupTool.addCluster(CLUSTER_NAME, true);
for (int i = 0; i < NUM_NODE; i++) {
String instanceName = PARTICIPANT_PREFIX + "_" + (START_PORT + i);
_gSetupTool.addInstanceToCluster(CLUSTER_NAME, instanceName);
// start dummy participants
MockParticipantManager participant = new MockParticipantManager(ZK_ADDR, CLUSTER_NAME, instanceName);
participant.syncStart();
_participants.add(participant);
}
// start controller
String controllerName = CONTROLLER_PREFIX + "_0";
_controller = new ClusterControllerManager(ZK_ADDR, CLUSTER_NAME, controllerName);
_controller.syncStart();
_clusterVerifier = new BestPossibleExternalViewVerifier.Builder(CLUSTER_NAME).setZkAddr(ZK_ADDR).build();
enablePersistBestPossibleAssignment(_gZkClient, CLUSTER_NAME, true);
_dataAccessor = new ZKHelixDataAccessor(CLUSTER_NAME, _baseAccessor);
ConfigAccessor configAccessor = new ConfigAccessor(_gZkClient);
ClusterConfig clusterConfig = configAccessor.getClusterConfig(CLUSTER_NAME);
clusterConfig.setMaxOfflineInstancesAllowed(_maxOfflineInstancesAllowed);
configAccessor.setClusterConfig(CLUSTER_NAME, clusterConfig);
for (int i = 0; i < 3; i++) {
String db = "Test-DB-" + i++;
createResourceWithDelayedRebalance(CLUSTER_NAME, db, BuiltInStateModelDefinitions.MasterSlave.name(), _PARTITIONS, 3, 3, -1);
}
Thread.sleep(100);
Assert.assertTrue(_clusterVerifier.verify());
}
use of org.apache.helix.model.ClusterConfig in project helix by apache.
the class TestJobTimeoutTaskNotStarted method beforeClass.
@BeforeClass
public void beforeClass() throws Exception {
_numDbs = 1;
_numNodes = 1;
_numParitions = 50;
_numReplicas = 1;
_participants = new MockParticipantManager[_numNodes];
String namespace = "/" + CLUSTER_NAME;
if (_gZkClient.exists(namespace)) {
_gZkClient.deleteRecursively(namespace);
}
_setupTool = new ClusterSetup(ZK_ADDR);
_setupTool.addCluster(CLUSTER_NAME, true);
setupParticipants();
setupDBs();
startParticipantsWithStuckTaskStateModelFactory();
createManagers();
_controller = new ClusterControllerManager(ZK_ADDR, CLUSTER_NAME, CONTROLLER_PREFIX);
_controller.syncStart();
// Enable cancellation
ConfigAccessor _configAccessor = new ConfigAccessor(_gZkClient);
ClusterConfig clusterConfig = _configAccessor.getClusterConfig(CLUSTER_NAME);
clusterConfig.stateTransitionCancelEnabled(true);
clusterConfig.setMaxConcurrentTaskPerInstance(_numParitions);
_configAccessor.setClusterConfig(CLUSTER_NAME, clusterConfig);
HelixClusterVerifier clusterVerifier = new BestPossibleExternalViewVerifier.Builder(CLUSTER_NAME).setZkClient(_gZkClient).build();
Assert.assertTrue(clusterVerifier.verify(10000));
}
use of org.apache.helix.model.ClusterConfig in project helix by apache.
the class TestTargetExternalView method testTargetExternalViewEnable.
@Test
public void testTargetExternalViewEnable() throws InterruptedException {
// Before enable target external view
Assert.assertFalse(_gZkClient.exists(_accessor.keyBuilder().targetExternalViews().getPath()));
ClusterConfig clusterConfig = _configAccessor.getClusterConfig(CLUSTER_NAME);
clusterConfig.enableTargetExternalView(true);
clusterConfig.setPersistIntermediateAssignment(true);
_configAccessor.setClusterConfig(CLUSTER_NAME, clusterConfig);
_gSetupTool.getClusterManagementTool().rebalance(CLUSTER_NAME, _testDbs.get(0), 3);
HelixClusterVerifier verifier = new BestPossibleExternalViewVerifier.Builder(CLUSTER_NAME).setZkAddr(ZK_ADDR).build();
Assert.assertTrue(verifier.verify());
Assert.assertEquals(_accessor.getChildNames(_accessor.keyBuilder().targetExternalViews()).size(), 3);
List<ExternalView> targetExternalViews = _accessor.getChildValues(_accessor.keyBuilder().externalViews());
List<IdealState> idealStates = _accessor.getChildValues(_accessor.keyBuilder().idealStates());
for (int i = 0; i < idealStates.size(); i++) {
Assert.assertEquals(targetExternalViews.get(i).getRecord().getMapFields(), idealStates.get(i).getRecord().getMapFields());
Assert.assertEquals(targetExternalViews.get(i).getRecord().getListFields(), idealStates.get(i).getRecord().getListFields());
}
// Disable one instance to see whether the target external views changes.
_gSetupTool.getClusterManagementTool().enableInstance(CLUSTER_NAME, _participants[0].getInstanceName(), false);
Assert.assertTrue(verifier.verify());
targetExternalViews = _accessor.getChildValues(_accessor.keyBuilder().externalViews());
idealStates = _accessor.getChildValues(_accessor.keyBuilder().idealStates());
for (int i = 0; i < idealStates.size(); i++) {
Assert.assertEquals(targetExternalViews.get(i).getRecord().getMapFields(), idealStates.get(i).getRecord().getMapFields());
Assert.assertEquals(targetExternalViews.get(i).getRecord().getListFields(), idealStates.get(i).getRecord().getListFields());
}
}
use of org.apache.helix.model.ClusterConfig in project ambry by linkedin.
the class VcrTestUtil method populateZkInfoAndStartController.
/**
* Populate info on ZooKeeper server and start {@link HelixControllerManager}.
* @param zkConnectString zk connect string to zk server.
* @param vcrClusterName the vcr cluster name.
* @param clusterMap the {@link ClusterMap} to use.
* @param vcrHelixStateModel the state model to use for helix cluster events.
* @return the created {@link HelixControllerManager}.
*/
public static HelixControllerManager populateZkInfoAndStartController(String zkConnectString, String vcrClusterName, ClusterMap clusterMap, String vcrHelixStateModel) {
HelixZkClient zkClient = DedicatedZkClientFactory.getInstance().buildZkClient(new HelixZkClient.ZkConnectionConfig(zkConnectString), new HelixZkClient.ZkClientConfig());
try {
zkClient.setZkSerializer(new ZNRecordSerializer());
ClusterSetup clusterSetup = new ClusterSetup(zkClient);
clusterSetup.addCluster(vcrClusterName, true);
HelixAdmin admin = new ZKHelixAdmin(zkClient);
// set ALLOW_PARTICIPANT_AUTO_JOIN
HelixConfigScope configScope = new HelixConfigScopeBuilder(HelixConfigScope.ConfigScopeProperty.CLUSTER).forCluster(vcrClusterName).build();
Map<String, String> helixClusterProperties = new HashMap<>();
helixClusterProperties.put(ZKHelixManager.ALLOW_PARTICIPANT_AUTO_JOIN, String.valueOf(true));
admin.setConfig(configScope, helixClusterProperties);
// set PersistBestPossibleAssignment
ConfigAccessor configAccessor = new ConfigAccessor(zkClient);
ClusterConfig clusterConfig = configAccessor.getClusterConfig(vcrClusterName);
clusterConfig.setPersistBestPossibleAssignment(true);
configAccessor.setClusterConfig(vcrClusterName, clusterConfig);
FullAutoModeISBuilder builder = new FullAutoModeISBuilder(helixResource);
builder.setStateModel(vcrHelixStateModel);
for (PartitionId partitionId : clusterMap.getAllPartitionIds(null)) {
builder.add(partitionId.toPathString());
}
builder.setMinActiveReplica(MIN_ACTIVE_REPLICAS);
builder.setRebalanceDelay((int) REBALANCE_DELAY_MS);
builder.setRebalancerClass(DelayedAutoRebalancer.class.getName());
builder.setRebalanceStrategy(CrushEdRebalanceStrategy.class.getName());
IdealState idealState = builder.build();
admin.addResource(vcrClusterName, helixResource, idealState);
admin.rebalance(vcrClusterName, helixResource, NUM_REPLICAS, "", "");
HelixControllerManager helixControllerManager = new HelixControllerManager(zkConnectString, vcrClusterName);
helixControllerManager.syncStart();
return helixControllerManager;
} finally {
zkClient.close();
}
}
use of org.apache.helix.model.ClusterConfig in project helix by apache.
the class TestRoutingTableProviderFromTargetEV method testExternalViewDiffFromTargetExternalView.
@Test(dependsOnMethods = "testTargetExternalViewWithoutEnable")
public void testExternalViewDiffFromTargetExternalView() throws InterruptedException {
ClusterConfig clusterConfig = _configAccessor.getClusterConfig(CLUSTER_NAME);
clusterConfig.enableTargetExternalView(true);
clusterConfig.setPersistBestPossibleAssignment(true);
_configAccessor.setClusterConfig(CLUSTER_NAME, clusterConfig);
Thread.sleep(2000);
RoutingTableProvider externalViewProvider = new RoutingTableProvider(_manager, PropertyType.EXTERNALVIEW);
RoutingTableProvider targetExternalViewProvider = new RoutingTableProvider(_manager, PropertyType.TARGETEXTERNALVIEW);
// ExternalView should not contain any MASTERS
// TargetExternalView should contain MASTERS same as the partition number
Set<InstanceConfig> externalViewMasters = externalViewProvider.getInstancesForResource(WorkflowGenerator.DEFAULT_TGT_DB, "MASTER");
Assert.assertEquals(externalViewMasters.size(), 0);
Set<InstanceConfig> targetExternalViewMasters = targetExternalViewProvider.getInstancesForResource(WorkflowGenerator.DEFAULT_TGT_DB, "MASTER");
Assert.assertEquals(targetExternalViewMasters.size(), NUM_NODES);
// TargetExternalView MASTERS mapping should exactly match IdealState MASTERS mapping
Map<String, Map<String, String>> stateMap = _setupTool.getClusterManagementTool().getResourceIdealState(CLUSTER_NAME, WorkflowGenerator.DEFAULT_TGT_DB).getRecord().getMapFields();
Set<String> idealMasters = new HashSet<>();
Set<String> targetMasters = new HashSet<>();
for (Map<String, String> instanceMap : stateMap.values()) {
for (String instance : instanceMap.keySet()) {
if (instanceMap.get(instance).equals("MASTER")) {
idealMasters.add(instance);
}
}
}
for (InstanceConfig instanceConfig : targetExternalViewMasters) {
targetMasters.add(instanceConfig.getInstanceName());
}
Assert.assertTrue(idealMasters.equals(targetMasters));
}
Aggregations