Java Code Examples for org.apache.helix.InstanceType#CONTROLLER_PARTICIPANT
The following examples show how to use
org.apache.helix.InstanceType#CONTROLLER_PARTICIPANT .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HelixStateMachineEngine.java From helix with Apache License 2.0 | 6 votes |
private void sendNopMessage() { if (_manager.isConnected()) { try { Message nopMsg = new Message(MessageType.NO_OP, UUID.randomUUID().toString()); nopMsg.setSrcName(_manager.getInstanceName()); HelixDataAccessor accessor = _manager.getHelixDataAccessor(); Builder keyBuilder = accessor.keyBuilder(); if (_manager.getInstanceType() == InstanceType.CONTROLLER || _manager.getInstanceType() == InstanceType.CONTROLLER_PARTICIPANT) { nopMsg.setTgtName(InstanceType.CONTROLLER.name()); accessor.setProperty(keyBuilder.controllerMessage(nopMsg.getId()), nopMsg); } if (_manager.getInstanceType() == InstanceType.PARTICIPANT || _manager.getInstanceType() == InstanceType.CONTROLLER_PARTICIPANT) { nopMsg.setTgtName(_manager.getInstanceName()); accessor.setProperty(keyBuilder.message(nopMsg.getTgtName(), nopMsg.getId()), nopMsg); } logger.info("Send NO_OP message to " + nopMsg.getTgtName() + ", msgId: " + nopMsg.getId()); } catch (Exception e) { logger.error(e.toString()); } } }
Example 2
Source File: DefaultMessagingService.java From helix with Apache License 2.0 | 6 votes |
public DefaultMessagingService(HelixManager manager) { _manager = manager; _evaluator = new CriteriaEvaluator(); boolean isParticipant = false; if (manager.getInstanceType() == InstanceType.PARTICIPANT || manager.getInstanceType() == InstanceType.CONTROLLER_PARTICIPANT) { isParticipant = true; } _taskExecutor = new HelixTaskExecutor( new ParticipantStatusMonitor(isParticipant, manager.getInstanceName()), new MessageQueueMonitor(manager.getClusterName(), manager.getInstanceName())); _asyncCallbackService = new AsyncCallbackService(); _taskExecutor.registerMessageHandlerFactory(MessageType.TASK_REPLY.name(), _asyncCallbackService); }
Example 3
Source File: DefaultMessagingService.java From helix with Apache License 2.0 | 6 votes |
private void sendNopMessageInternal() { try { Message nopMsg = new Message(MessageType.NO_OP, UUID.randomUUID().toString()); nopMsg.setSrcName(_manager.getInstanceName()); HelixDataAccessor accessor = _manager.getHelixDataAccessor(); Builder keyBuilder = accessor.keyBuilder(); if (_manager.getInstanceType() == InstanceType.CONTROLLER || _manager.getInstanceType() == InstanceType.CONTROLLER_PARTICIPANT) { nopMsg.setTgtName(InstanceType.CONTROLLER.name()); accessor.setProperty(keyBuilder.controllerMessage(nopMsg.getId()), nopMsg); } if (_manager.getInstanceType() == InstanceType.PARTICIPANT || _manager.getInstanceType() == InstanceType.CONTROLLER_PARTICIPANT) { nopMsg.setTgtName(_manager.getInstanceName()); accessor.setProperty(keyBuilder.message(nopMsg.getTgtName(), nopMsg.getId()), nopMsg); } } catch (Exception e) { _logger.error(e.toString()); } }
Example 4
Source File: ZKHelixManager.java From helix with Apache License 2.0 | 5 votes |
@Override public boolean isLeader() { String warnLogPrefix = String .format("Instance %s is not leader of cluster %s due to", _instanceName, _clusterName); if (_instanceType != InstanceType.CONTROLLER && _instanceType != InstanceType.CONTROLLER_PARTICIPANT) { LOG.warn(String .format("%s instance type %s does not match to CONTROLLER/CONTROLLER_PARTICIPANT", warnLogPrefix, _instanceType.name())); return false; } if (!isConnected()) { LOG.warn(String.format("%s HelixManager is not connected", warnLogPrefix)); return false; } try { LiveInstance leader = _dataAccessor.getProperty(_keyBuilder.controllerLeader()); if (leader != null) { String leaderName = leader.getInstanceName(); String sessionId = leader.getEphemeralOwner(); if (leaderName != null && leaderName.equals(_instanceName) && sessionId .equals(_sessionId)) { return true; } LOG.warn(String .format("%s current session %s does not match leader session %s", warnLogPrefix, _sessionId, sessionId)); } else { LOG.warn(String.format("%s leader ZNode is null", warnLogPrefix)); } } catch (Exception e) { LOG.warn(String.format("%s exception happen when session check", warnLogPrefix), e); } return false; }
Example 5
Source File: DistributedLeaderElection.java From helix with Apache License 2.0 | 5 votes |
public DistributedLeaderElection(HelixManager manager, GenericHelixController controller, List<HelixTimerTask> controllerTimerTasks) { _manager = manager; _controller = controller; _controllerTimerTasks = controllerTimerTasks; InstanceType type = _manager.getInstanceType(); if (type != InstanceType.CONTROLLER && type != InstanceType.CONTROLLER_PARTICIPANT) { throw new HelixException( "fail to become controller because incorrect instanceType (was " + type.toString() + ", requires CONTROLLER | CONTROLLER_PARTICIPANT)"); } }
Example 6
Source File: ZKUtil.java From helix with Apache License 2.0 | 5 votes |
public static boolean isInstanceSetup(RealmAwareZkClient zkclient, String clusterName, String instanceName, InstanceType type) { if (type == InstanceType.PARTICIPANT || type == InstanceType.CONTROLLER_PARTICIPANT) { List<String> requiredPaths = new ArrayList<>(); requiredPaths.add(PropertyPathBuilder.instanceConfig(clusterName, instanceName)); requiredPaths.add(PropertyPathBuilder.instanceMessage(clusterName, instanceName)); requiredPaths.add(PropertyPathBuilder.instanceCurrentState(clusterName, instanceName)); requiredPaths.add(PropertyPathBuilder.instanceStatusUpdate(clusterName, instanceName)); requiredPaths.add(PropertyPathBuilder.instanceError(clusterName, instanceName)); boolean isValid = true; for (String path : requiredPaths) { if (!zkclient.exists(path)) { isValid = false; logger.info("Invalid instance setup, missing znode path: {}", path); } } if (isValid) { // Create the instance history node if it does not exist. // This is for back-compatibility. String historyPath = PropertyPathBuilder.instanceHistory(clusterName, instanceName); if (!zkclient.exists(historyPath)) { zkclient.createPersistent(historyPath, true); } } return isValid; } return true; }
Example 7
Source File: TestParticipantManager.java From helix with Apache License 2.0 | 5 votes |
private void verifyHelixManagerMetrics(InstanceType type, MonitorLevel monitorLevel, String instanceName) throws MalformedObjectNameException { // check HelixCallback Monitor Set<ObjectInstance> objs = _server.queryMBeans(buildCallbackMonitorObjectName(type, clusterName, instanceName), null); Assert.assertEquals(objs.size(), 18); // check HelixZkClient Monitors objs = _server.queryMBeans(buildZkClientMonitorObjectName(type, clusterName, instanceName), null); Assert.assertEquals(objs.size(), 1); objs = _server.queryMBeans(buildZkClientPathMonitorObjectName(type, clusterName, instanceName), null); int expectedZkPathMonitor; switch (monitorLevel) { case ALL: expectedZkPathMonitor = 10; break; case AGGREGATED_ONLY: expectedZkPathMonitor = 1; break; default: expectedZkPathMonitor = type == InstanceType.CONTROLLER || type == InstanceType.CONTROLLER_PARTICIPANT ? 10 : 1; } Assert.assertEquals(objs.size(), expectedZkPathMonitor); }
Example 8
Source File: TestP2PNoDuplicatedMessage.java From helix with Apache License 2.0 | 5 votes |
public MockMessagingService(HelixManager manager) { super(manager); _manager = manager; boolean isParticipant = false; if (manager.getInstanceType() == InstanceType.PARTICIPANT || manager.getInstanceType() == InstanceType.CONTROLLER_PARTICIPANT) { isParticipant = true; } _taskExecutor = new MockHelixTaskExecutor( new ParticipantStatusMonitor(isParticipant, manager.getInstanceName()), new MessageQueueMonitor(manager.getClusterName(), manager.getInstanceName())); }
Example 9
Source File: DefaultMessagingService.java From helix with Apache License 2.0 | 4 votes |
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; // Read the participant config and cluster config for the per-message type thread pool size. // participant config will override the cluster config. 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(); }
Example 10
Source File: TestDistributedControllerManager.java From helix with Apache License 2.0 | 4 votes |
@Test public void simpleIntegrationTest() throws Exception { String className = TestHelper.getTestClassName(); String methodName = TestHelper.getTestMethodName(); String clusterName = className + "_" + methodName; int n = 2; System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis())); TestHelper.setupCluster(clusterName, ZK_ADDR, 12918, // participant port "localhost", // participant name prefix "TestDB", // resource name prefix 1, // resources 4, // partitions per resource n, // number of nodes 2, // replicas "MasterSlave", true); // do rebalance HelixManager[] distributedControllers = new HelixManager[n]; for (int i = 0; i < n; i++) { int port = 12918 + i; distributedControllers[i] = new ZKHelixManager(clusterName, "localhost_" + port, InstanceType.CONTROLLER_PARTICIPANT, ZK_ADDR); distributedControllers[i].getStateMachineEngine().registerStateModelFactory("MasterSlave", new MockMSModelFactory()); distributedControllers[i].connect(); } boolean result = ClusterStateVerifier .verifyByZkCallback(new BestPossAndExtViewZkVerifier(ZK_ADDR, clusterName)); Assert.assertTrue(result); // disconnect first distributed-controller, and verify second takes leadership distributedControllers[0].disconnect(); // verify leader changes to localhost_12919 Thread.sleep(100); result = ClusterStateVerifier .verifyByZkCallback(new BestPossAndExtViewZkVerifier(ZK_ADDR, clusterName)); Assert.assertTrue(result); ZKHelixDataAccessor accessor = new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<>(_gZkClient)); PropertyKey.Builder keyBuilder = accessor.keyBuilder(); Assert.assertNull(accessor.getProperty(keyBuilder.liveInstance("localhost_12918"))); LiveInstance leader = accessor.getProperty(keyBuilder.controllerLeader()); Assert.assertNotNull(leader); Assert.assertEquals(leader.getId(), "localhost_12919"); // clean up distributedControllers[1].disconnect(); Assert.assertNull(accessor.getProperty(keyBuilder.liveInstance("localhost_12919"))); Assert.assertNull(accessor.getProperty(keyBuilder.controllerLeader())); deleteCluster(clusterName); System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis())); }
Example 11
Source File: ClusterDistributedController.java From helix with Apache License 2.0 | 4 votes |
public ClusterDistributedController(String zkAddr, String clusterName, String controllerName) { super(zkAddr, clusterName, controllerName, InstanceType.CONTROLLER_PARTICIPANT); }