use of org.apache.helix.model.builder.FullAutoModeISBuilder in project helix by apache.
the class TestBatchMessageModeConfigs method setupResource.
private void setupResource(String dbName) throws InterruptedException {
IdealState idealState = new FullAutoModeISBuilder(dbName).setStateModel("OnlineOffline").setStateModelFactoryName("TestFactory").setNumPartitions(10).setNumReplica(1).build();
_setupTool.getClusterManagementTool().addResource(CLUSTER_NAME, dbName, idealState);
}
use of org.apache.helix.model.builder.FullAutoModeISBuilder in project helix by apache.
the class TestResourceThreadpoolSize method TestPerStateTransitionTypeThreadPool.
@Test
public void TestPerStateTransitionTypeThreadPool() throws InterruptedException {
String MASTER_SLAVE = "MasterSlave";
int customizedPoolSize = 22;
for (MockParticipantManager participant : _participants) {
participant.getStateMachineEngine().registerStateModelFactory(MASTER_SLAVE, new TestMasterSlaveStateModelFactory(customizedPoolSize), TEST_FACTORY);
}
// add db with customized thread pool
IdealState idealState = new FullAutoModeISBuilder(WorkflowGenerator.DEFAULT_TGT_DB + "4").setStateModel(MASTER_SLAVE).setStateModelFactoryName(TEST_FACTORY).setNumPartitions(10).setNumReplica(1).build();
_setupTool.getClusterManagementTool().addResource(CLUSTER_NAME, WorkflowGenerator.DEFAULT_TGT_DB + "4", idealState);
_setupTool.rebalanceStorageCluster(CLUSTER_NAME, WorkflowGenerator.DEFAULT_TGT_DB + "4", 1);
Thread.sleep(2000);
// Verify OFFLINE -> SLAVE and SLAVE -> MASTER have different threadpool size.
for (int i = 0; i < NODE_NR; i++) {
DefaultMessagingService svc = (DefaultMessagingService) (_participants[i].getMessagingService());
HelixTaskExecutor helixExecutor = svc.getExecutor();
ThreadPoolExecutor executorOfflineToSlave = (ThreadPoolExecutor) (helixExecutor._executorMap.get(MessageType.STATE_TRANSITION + "." + WorkflowGenerator.DEFAULT_TGT_DB + "4" + "." + OFFLINE_TO_SLAVE));
Assert.assertEquals(customizedPoolSize, executorOfflineToSlave.getMaximumPoolSize());
ThreadPoolExecutor executorSlaveToMaster = (ThreadPoolExecutor) (helixExecutor._executorMap.get(MessageType.STATE_TRANSITION + "." + WorkflowGenerator.DEFAULT_TGT_DB + "4" + "." + SLAVE_TO_MASTER));
Assert.assertEquals(customizedPoolSize + 5, executorSlaveToMaster.getMaximumPoolSize());
}
}
use of org.apache.helix.model.builder.FullAutoModeISBuilder in project helix by apache.
the class TestResourceThreadpoolSize method TestCustomizedResourceThreadPool.
@Test
public void TestCustomizedResourceThreadPool() {
int customizedPoolSize = 7;
int configuredPoolSize = 9;
for (MockParticipantManager participant : _participants) {
participant.getStateMachineEngine().registerStateModelFactory(ONLINE_OFFLINE, new TestOnlineOfflineStateModelFactory(customizedPoolSize, 0), TEST_FACTORY);
}
// add db with default thread pool
_setupTool.addResourceToCluster(CLUSTER_NAME, WorkflowGenerator.DEFAULT_TGT_DB + "1", 64, STATE_MODEL);
_setupTool.rebalanceStorageCluster(CLUSTER_NAME, WorkflowGenerator.DEFAULT_TGT_DB + "1", 3);
// add db with customized thread pool
IdealState idealState = new FullAutoModeISBuilder(WorkflowGenerator.DEFAULT_TGT_DB + "2").setStateModel(ONLINE_OFFLINE).setStateModelFactoryName(TEST_FACTORY).setNumPartitions(10).setNumReplica(1).build();
_setupTool.getClusterManagementTool().addResource(CLUSTER_NAME, WorkflowGenerator.DEFAULT_TGT_DB + "2", idealState);
_setupTool.rebalanceStorageCluster(CLUSTER_NAME, WorkflowGenerator.DEFAULT_TGT_DB + "2", 1);
// add db with configured pool size
idealState = new FullAutoModeISBuilder(WorkflowGenerator.DEFAULT_TGT_DB + "3").setStateModel(ONLINE_OFFLINE).setStateModelFactoryName(TEST_FACTORY).setNumPartitions(10).setNumReplica(1).build();
_setupTool.getClusterManagementTool().addResource(CLUSTER_NAME, WorkflowGenerator.DEFAULT_TGT_DB + "3", idealState);
setResourceThreadPoolSize(WorkflowGenerator.DEFAULT_TGT_DB + "3", configuredPoolSize);
_setupTool.rebalanceStorageCluster(CLUSTER_NAME, WorkflowGenerator.DEFAULT_TGT_DB + "3", 1);
boolean result = ClusterStateVerifier.verifyByPolling(new ClusterStateVerifier.BestPossAndExtViewZkVerifier(ZK_ADDR, CLUSTER_NAME));
Assert.assertTrue(result);
for (int i = 0; i < NODE_NR; i++) {
DefaultMessagingService svc = (DefaultMessagingService) (_participants[i].getMessagingService());
HelixTaskExecutor helixExecutor = svc.getExecutor();
ThreadPoolExecutor executor = (ThreadPoolExecutor) (helixExecutor._executorMap.get(MessageType.STATE_TRANSITION + "." + WorkflowGenerator.DEFAULT_TGT_DB + "1"));
Assert.assertNull(executor);
executor = (ThreadPoolExecutor) (helixExecutor._executorMap.get(MessageType.STATE_TRANSITION + "." + WorkflowGenerator.DEFAULT_TGT_DB + "2"));
Assert.assertEquals(customizedPoolSize, executor.getMaximumPoolSize());
executor = (ThreadPoolExecutor) (helixExecutor._executorMap.get(MessageType.STATE_TRANSITION + "." + WorkflowGenerator.DEFAULT_TGT_DB + "3"));
Assert.assertEquals(configuredPoolSize, executor.getMaximumPoolSize());
}
}
use of org.apache.helix.model.builder.FullAutoModeISBuilder in project helix by apache.
the class TestBatchMessageHandling method testSubMessageFailed.
@Test
public void testSubMessageFailed() throws InterruptedException {
TestOnlineOfflineStateModel._numOfSuccessBeforeFail = 6;
// Let one instance handle all the batch messages.
_participants[0].getStateMachineEngine().registerStateModelFactory("OnlineOffline", new TestOnlineOfflineStateModelFactory(), "TestFactory");
for (int i = 1; i < _participants.length; i++) {
_participants[i].syncStop();
}
// Add 1 db with batch message enabled. Each db has 10 partitions.
// So it will have 1 batch message and 10 sub messages.
String dbName = "TestDBSubMessageFail";
IdealState idealState = new FullAutoModeISBuilder(dbName).setStateModel("OnlineOffline").setStateModelFactoryName("TestFactory").setNumPartitions(10).setNumReplica(1).build();
idealState.setBatchMessageMode(true);
_setupTool.getClusterManagementTool().addResource(CLUSTER_NAME, dbName, idealState);
_setupTool.rebalanceStorageCluster(CLUSTER_NAME, dbName, 1);
Thread.sleep(1000L);
int numOfOnlines = 0;
int numOfErrors = 0;
ExternalView externalView = _setupTool.getClusterManagementTool().getResourceExternalView(CLUSTER_NAME, dbName);
for (String partition : externalView.getPartitionSet()) {
if (externalView.getStateMap(partition).values().contains("ONLINE")) {
numOfOnlines++;
}
if (externalView.getStateMap(partition).values().contains("ERROR")) {
numOfErrors++;
}
}
Assert.assertEquals(numOfErrors, 4);
Assert.assertEquals(numOfOnlines, 6);
}
use of org.apache.helix.model.builder.FullAutoModeISBuilder in project helix by apache.
the class TestResourceAccessor method testAddResources.
@Test(dependsOnMethods = "testGetResource")
public void testAddResources() throws IOException {
System.out.println("Start test :" + TestHelper.getTestMethodName());
String newResourceName = "newResource";
IdealState idealState = new IdealState(newResourceName);
idealState.getRecord().getSimpleFields().putAll(_gSetupTool.getClusterManagementTool().getResourceIdealState(CLUSTER_NAME, RESOURCE_NAME).getRecord().getSimpleFields());
// Add resource by IdealState
Entity entity = Entity.entity(OBJECT_MAPPER.writeValueAsString(idealState.getRecord()), MediaType.APPLICATION_JSON_TYPE);
put("clusters/" + CLUSTER_NAME + "/resources/" + newResourceName, null, entity, Response.Status.OK.getStatusCode());
Assert.assertEquals(idealState, _gSetupTool.getClusterManagementTool().getResourceIdealState(CLUSTER_NAME, newResourceName));
// Add resource by query param
entity = Entity.entity("", MediaType.APPLICATION_JSON_TYPE);
put("clusters/" + CLUSTER_NAME + "/resources/" + newResourceName + "0", ImmutableMap.of("numPartitions", "4", "stateModelRef", "OnlineOffline", "rebalancerMode", "FULL_AUTO"), entity, Response.Status.OK.getStatusCode());
IdealState queryIdealState = new FullAutoModeISBuilder(newResourceName + 0).setNumPartitions(4).setStateModel("OnlineOffline").setRebalancerMode(IdealState.RebalanceMode.FULL_AUTO).setRebalanceStrategy("DEFAULT").build();
Assert.assertEquals(queryIdealState, _gSetupTool.getClusterManagementTool().getResourceIdealState(CLUSTER_NAME, newResourceName + "0"));
}
Aggregations