use of org.apache.helix.model.builder.ConfigScopeBuilder in project helix by apache.
the class DefaultMessagingService method registerMessageHandlerFactoryInternal.
void registerMessageHandlerFactoryInternal(String type, MessageHandlerFactory factory) {
_logger.info("registering msg factory for type " + type);
int threadpoolSize = HelixTaskExecutor.DEFAULT_PARALLEL_TASKS;
String threadpoolSizeStr = null;
String key = type + "." + HelixTaskExecutor.MAX_THREADS;
ConfigAccessor configAccessor = _manager.getConfigAccessor();
if (configAccessor != null) {
ConfigScope scope = null;
if (_manager.getInstanceType() == InstanceType.PARTICIPANT || _manager.getInstanceType() == InstanceType.CONTROLLER_PARTICIPANT) {
scope = new ConfigScopeBuilder().forCluster(_manager.getClusterName()).forParticipant(_manager.getInstanceName()).build();
threadpoolSizeStr = configAccessor.get(scope, key);
}
if (threadpoolSizeStr == null) {
scope = new ConfigScopeBuilder().forCluster(_manager.getClusterName()).build();
threadpoolSizeStr = configAccessor.get(scope, key);
}
}
if (threadpoolSizeStr != null) {
try {
threadpoolSize = Integer.parseInt(threadpoolSizeStr);
if (threadpoolSize <= 0) {
threadpoolSize = 1;
}
} catch (Exception e) {
_logger.error("", e);
}
}
_taskExecutor.registerMessageHandlerFactory(type, factory, threadpoolSize);
// Self-send a no-op message, so that the onMessage() call will be invoked
// again, and
// we have a chance to process the message that we received with the new
// added MessageHandlerFactory
// before the factory is added.
sendNopMessageInternal();
}
use of org.apache.helix.model.builder.ConfigScopeBuilder in project helix by apache.
the class TestInstanceAutoJoin method testInstanceAutoJoin.
@Test
public void testInstanceAutoJoin() throws Exception {
HelixManager manager = _participants[0];
HelixDataAccessor accessor = manager.getHelixDataAccessor();
_setupTool.addResourceToCluster(CLUSTER_NAME, db2, 60, "OnlineOffline", RebalanceMode.FULL_AUTO + "");
_setupTool.rebalanceStorageCluster(CLUSTER_NAME, db2, 1);
String instance2 = "localhost_279699";
// StartCMResult result = TestHelper.startDummyProcess(ZK_ADDR, CLUSTER_NAME, instance2);
MockParticipantManager newParticipant = new MockParticipantManager(ZK_ADDR, CLUSTER_NAME, instance2);
newParticipant.syncStart();
Thread.sleep(500);
// Assert.assertFalse(result._thread.isAlive());
Assert.assertTrue(null == manager.getHelixDataAccessor().getProperty(accessor.keyBuilder().liveInstance(instance2)));
ConfigScope scope = new ConfigScopeBuilder().forCluster(CLUSTER_NAME).build();
manager.getConfigAccessor().set(scope, ZKHelixManager.ALLOW_PARTICIPANT_AUTO_JOIN, "true");
newParticipant = new MockParticipantManager(ZK_ADDR, CLUSTER_NAME, instance2);
newParticipant.syncStart();
Thread.sleep(500);
// Assert.assertTrue(result._thread.isAlive() || result2._thread.isAlive());
for (int i = 0; i < 20; i++) {
if (null == manager.getHelixDataAccessor().getProperty(accessor.keyBuilder().liveInstance(instance2))) {
Thread.sleep(100);
} else
break;
}
Assert.assertTrue(null != manager.getHelixDataAccessor().getProperty(accessor.keyBuilder().liveInstance(instance2)));
newParticipant.syncStop();
}
use of org.apache.helix.model.builder.ConfigScopeBuilder in project helix by apache.
the class TestConfigAccessor method testSetNonexistentParticipantConfig.
// HELIX-25: set participant Config should check existence of instance
@Test
public void testSetNonexistentParticipantConfig() throws Exception {
String className = TestHelper.getTestClassName();
String methodName = TestHelper.getTestMethodName();
String clusterName = className + "_" + methodName;
System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis()));
ZKHelixAdmin admin = new ZKHelixAdmin(_gZkClient);
admin.addCluster(clusterName, true);
ConfigAccessor configAccessor = new ConfigAccessor(_gZkClient);
ConfigScope participantScope = new ConfigScopeBuilder().forCluster(clusterName).forParticipant("localhost_12918").build();
try {
configAccessor.set(participantScope, "participantConfigKey", "participantConfigValue");
Assert.fail("Except fail to set participant-config because participant: localhost_12918 is not added to cluster yet");
} catch (HelixException e) {
// OK
}
admin.addInstance(clusterName, new InstanceConfig("localhost_12918"));
try {
configAccessor.set(participantScope, "participantConfigKey", "participantConfigValue");
} catch (Exception e) {
Assert.fail("Except succeed to set participant-config because participant: localhost_12918 has been added to cluster");
}
String participantConfigValue = configAccessor.get(participantScope, "participantConfigKey");
Assert.assertEquals(participantConfigValue, "participantConfigValue");
System.out.println("END " + clusterName + " at " + new Date(System.currentTimeMillis()));
}
use of org.apache.helix.model.builder.ConfigScopeBuilder in project helix by apache.
the class TestConfigAccessor method testBasic.
@Test
public void testBasic() throws Exception {
String className = TestHelper.getTestClassName();
String methodName = TestHelper.getTestMethodName();
String clusterName = className + "_" + methodName;
System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis()));
TestHelper.setupCluster(clusterName, ZK_ADDR, 12918, "localhost", "TestDB", 1, 10, 5, 3, "MasterSlave", true);
ConfigAccessor configAccessor = new ConfigAccessor(_gZkClient);
ConfigScope clusterScope = new ConfigScopeBuilder().forCluster(clusterName).build();
// cluster scope config
String clusterConfigValue = configAccessor.get(clusterScope, "clusterConfigKey");
Assert.assertNull(clusterConfigValue);
configAccessor.set(clusterScope, "clusterConfigKey", "clusterConfigValue");
clusterConfigValue = configAccessor.get(clusterScope, "clusterConfigKey");
Assert.assertEquals(clusterConfigValue, "clusterConfigValue");
// resource scope config
ConfigScope resourceScope = new ConfigScopeBuilder().forCluster(clusterName).forResource("testResource").build();
configAccessor.set(resourceScope, "resourceConfigKey", "resourceConfigValue");
String resourceConfigValue = configAccessor.get(resourceScope, "resourceConfigKey");
Assert.assertEquals(resourceConfigValue, "resourceConfigValue");
// partition scope config
ConfigScope partitionScope = new ConfigScopeBuilder().forCluster(clusterName).forResource("testResource").forPartition("testPartition").build();
configAccessor.set(partitionScope, "partitionConfigKey", "partitionConfigValue");
String partitionConfigValue = configAccessor.get(partitionScope, "partitionConfigKey");
Assert.assertEquals(partitionConfigValue, "partitionConfigValue");
// participant scope config
ConfigScope participantScope = new ConfigScopeBuilder().forCluster(clusterName).forParticipant("localhost_12918").build();
configAccessor.set(participantScope, "participantConfigKey", "participantConfigValue");
String participantConfigValue = configAccessor.get(participantScope, "participantConfigKey");
Assert.assertEquals(participantConfigValue, "participantConfigValue");
List<String> keys = configAccessor.getKeys(ConfigScopeProperty.RESOURCE, clusterName);
Assert.assertEquals(keys.size(), 1, "should be [testResource]");
Assert.assertEquals(keys.get(0), "testResource");
keys = configAccessor.getKeys(ConfigScopeProperty.CLUSTER, clusterName);
Assert.assertEquals(keys.size(), 1, "should be [" + clusterName + "]");
Assert.assertEquals(keys.get(0), clusterName);
keys = configAccessor.getKeys(ConfigScopeProperty.PARTICIPANT, clusterName);
Assert.assertEquals(keys.size(), 5, "should be [localhost_12918~22] sorted");
Assert.assertEquals(keys.get(0), "localhost_12918");
Assert.assertEquals(keys.get(4), "localhost_12922");
keys = configAccessor.getKeys(ConfigScopeProperty.PARTITION, clusterName, "testResource");
Assert.assertEquals(keys.size(), 1, "should be [testPartition]");
Assert.assertEquals(keys.get(0), "testPartition");
keys = configAccessor.getKeys(ConfigScopeProperty.RESOURCE, clusterName, "testResource");
Assert.assertEquals(keys.size(), 1, "should be [resourceConfigKey]");
Assert.assertEquals(keys.get(0), "resourceConfigKey");
keys = configAccessor.getKeys(ConfigScopeProperty.CLUSTER, clusterName, clusterName);
Assert.assertEquals(keys.size(), 1, "should be [clusterConfigKey]");
Assert.assertEquals(keys.get(0), "clusterConfigKey");
keys = configAccessor.getKeys(ConfigScopeProperty.PARTICIPANT, clusterName, "localhost_12918");
System.out.println((keys));
Assert.assertEquals(keys.size(), 5, "should be [HELIX_ENABLED, HELIX_ENABLED_TIMESTAMP, HELIX_HOST, HELIX_PORT, participantConfigKey]");
Assert.assertEquals(keys.get(4), "participantConfigKey");
keys = configAccessor.getKeys(ConfigScopeProperty.PARTITION, clusterName, "testResource", "testPartition");
Assert.assertEquals(keys.size(), 1, "should be [partitionConfigKey]");
Assert.assertEquals(keys.get(0), "partitionConfigKey");
// test configAccessor.remove()
configAccessor.remove(clusterScope, "clusterConfigKey");
clusterConfigValue = configAccessor.get(clusterScope, "clusterConfigKey");
Assert.assertNull(clusterConfigValue, "Should be null since it's removed");
configAccessor.remove(resourceScope, "resourceConfigKey");
resourceConfigValue = configAccessor.get(resourceScope, "resourceConfigKey");
Assert.assertNull(resourceConfigValue, "Should be null since it's removed");
configAccessor.remove(partitionScope, "partitionConfigKey");
partitionConfigValue = configAccessor.get(partitionScope, "partitionConfigKey");
Assert.assertNull(partitionConfigValue, "Should be null since it's removed");
configAccessor.remove(participantScope, "participantConfigKey");
participantConfigValue = configAccessor.get(partitionScope, "participantConfigKey");
Assert.assertNull(participantConfigValue, "Should be null since it's removed");
// negative tests
try {
new ConfigScopeBuilder().forPartition("testPartition").build();
Assert.fail("Should fail since cluster name is not set");
} catch (Exception e) {
// OK
}
try {
new ConfigScopeBuilder().forCluster("testCluster").forPartition("testPartition").build();
Assert.fail("Should fail since resource name is not set");
} catch (Exception e) {
// OK
}
try {
new ConfigScopeBuilder().forParticipant("testParticipant").build();
Assert.fail("Should fail since cluster name is not set");
} catch (Exception e) {
// OK
}
System.out.println("END " + clusterName + " at " + new Date(System.currentTimeMillis()));
}
use of org.apache.helix.model.builder.ConfigScopeBuilder in project helix by apache.
the class ZkIntegrationTestBase method enableHealthCheck.
protected void enableHealthCheck(String clusterName) {
ConfigScope scope = new ConfigScopeBuilder().forCluster(clusterName).build();
new ConfigAccessor(_gZkClient).set(scope, "healthChange" + ".enabled", "" + true);
}
Aggregations