Java Code Examples for org.apache.helix.tools.ClusterSetup#addInstanceToCluster()
The following examples show how to use
org.apache.helix.tools.ClusterSetup#addInstanceToCluster() .
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: TestAddClusterV2.java From helix with Apache License 2.0 | 5 votes |
protected void setupStorageCluster(ClusterSetup setupTool, String clusterName, String dbName, int partitionNr, String prefix, int startPort, String stateModel, int replica, boolean rebalance) { setupTool.addResourceToCluster(clusterName, dbName, partitionNr, stateModel); for (int i = 0; i < NODE_NR; i++) { String instanceName = prefix + "_" + (startPort + i); setupTool.addInstanceToCluster(clusterName, instanceName); } if (rebalance) { setupTool.rebalanceStorageCluster(clusterName, dbName, replica); } }
Example 2
Source File: TestClusterAggregateMetrics.java From helix with Apache License 2.0 | 5 votes |
@BeforeClass public void beforeClass() throws Exception { System.out.println("START " + CLASS_NAME + " at " + new Date(System.currentTimeMillis())); _setupTool = new ClusterSetup(ZK_ADDR); // setup storage cluster _setupTool.addCluster(CLUSTER_NAME, true); _setupTool.addResourceToCluster(CLUSTER_NAME, TEST_DB, NUM_PARTITIONS, STATE_MODEL); for (int i = 0; i < NUM_PARTICIPANTS; i++) { String storageNodeName = PARTICIPANT_PREFIX + "_" + (START_PORT + i); _setupTool.addInstanceToCluster(CLUSTER_NAME, storageNodeName); } _setupTool.rebalanceStorageCluster(CLUSTER_NAME, TEST_DB, NUM_REPLICAS); // start dummy participants for (int i = 0; i < NUM_PARTICIPANTS; i++) { String instanceName = PARTICIPANT_PREFIX + "_" + (START_PORT + i); _participants[i] = new MockParticipantManager(ZK_ADDR, CLUSTER_NAME, instanceName); _participants[i].syncStart(); } // start controller String controllerName = CONTROLLER_PREFIX + "_0"; _controller = new ClusterControllerManager(ZK_ADDR, CLUSTER_NAME, controllerName); _controller.syncStart(); boolean result = ClusterStateVerifier.verifyByPolling( new ClusterStateVerifier.MasterNbInExtViewVerifier(ZK_ADDR, CLUSTER_NAME), 10000, 100); Assert.assertTrue(result); result = ClusterStateVerifier.verifyByPolling( new ClusterStateVerifier.BestPossAndExtViewZkVerifier(ZK_ADDR, CLUSTER_NAME), 10000, 100); Assert.assertTrue(result); // create cluster manager _manager = HelixManagerFactory.getZKHelixManager(CLUSTER_NAME, "Admin", InstanceType.ADMINISTRATOR, ZK_ADDR); _manager.connect(); }
Example 3
Source File: TestHelper.java From helix with Apache License 2.0 | 5 votes |
public static void setupCluster(String clusterName, String zkAddr, int startPort, String participantNamePrefix, String resourceNamePrefix, int resourceNb, int partitionNb, int nodesNb, int replica, String stateModelDef, RebalanceMode mode, boolean doRebalance) throws Exception { HelixZkClient zkClient = SharedZkClientFactory.getInstance() .buildZkClient(new HelixZkClient.ZkConnectionConfig(zkAddr)); if (zkClient.exists("/" + clusterName)) { LOG.warn("Cluster already exists:" + clusterName + ". Deleting it"); zkClient.deleteRecursively("/" + clusterName); } ClusterSetup setupTool = new ClusterSetup(zkAddr); setupTool.addCluster(clusterName, true); for (int i = 0; i < nodesNb; i++) { int port = startPort + i; setupTool.addInstanceToCluster(clusterName, participantNamePrefix + "_" + port); } for (int i = 0; i < resourceNb; i++) { String resourceName = resourceNamePrefix + i; setupTool.addResourceToCluster(clusterName, resourceName, partitionNb, stateModelDef, mode.toString()); if (doRebalance) { setupTool.rebalanceStorageCluster(clusterName, resourceName, replica); } } zkClient.close(); }
Example 4
Source File: TaskSynchronizedTestBase.java From helix with Apache License 2.0 | 5 votes |
protected void setupParticipants(ClusterSetup setupTool) { _participants = new MockParticipantManager[_numNodes]; for (int i = 0; i < _numNodes; i++) { String storageNodeName = PARTICIPANT_PREFIX + "_" + (_startPort + i); setupTool.addInstanceToCluster(CLUSTER_NAME, storageNodeName); if (_instanceGroupTag) { setupTool.addInstanceTag(CLUSTER_NAME, storageNodeName, "TESTTAG" + i); } } }
Example 5
Source File: TestQuotaBasedScheduling.java From helix with Apache License 2.0 | 4 votes |
@BeforeClass public void beforeClass() throws Exception { _numNodes = 2; // For easier debugging by inspecting ZNodes _participants = new MockParticipantManager[_numNodes]; String namespace = "/" + CLUSTER_NAME; if (_gZkClient.exists(namespace)) { _gZkClient.deleteRecursively(namespace); } // Setup cluster and instances ClusterSetup setupTool = new ClusterSetup(ZK_ADDR); setupTool.addCluster(CLUSTER_NAME, true); for (int i = 0; i < _numNodes; i++) { String storageNodeName = PARTICIPANT_PREFIX + "_" + (_startPort + i); setupTool.addInstanceToCluster(CLUSTER_NAME, storageNodeName); } // start dummy participants for (int i = 0; i < _numNodes; i++) { final String instanceName = PARTICIPANT_PREFIX + "_" + (_startPort + i); // Set task callbacks Map<String, TaskFactory> taskFactoryReg = new HashMap<>(); TaskFactory shortTaskFactory = context -> new ShortTask(context, instanceName); TaskFactory longTaskFactory = context -> new LongTask(context, instanceName); TaskFactory failTaskFactory = context -> new FailTask(context, instanceName); taskFactoryReg.put("ShortTask", shortTaskFactory); taskFactoryReg.put("LongTask", longTaskFactory); taskFactoryReg.put("FailTask", failTaskFactory); _participants[i] = new MockParticipantManager(ZK_ADDR, CLUSTER_NAME, instanceName); // Register a Task state model factory. StateMachineEngine stateMachine = _participants[i].getStateMachineEngine(); stateMachine.registerStateModelFactory("Task", new TaskStateModelFactory(_participants[i], taskFactoryReg)); _participants[i].syncStart(); } // Start controller String controllerName = CONTROLLER_PREFIX + "_0"; _controller = new ClusterControllerManager(ZK_ADDR, CLUSTER_NAME, controllerName); _controller.syncStart(); // Start an admin connection _manager = HelixManagerFactory.getZKHelixManager(CLUSTER_NAME, "Admin", InstanceType.ADMINISTRATOR, ZK_ADDR); _manager.connect(); _driver = new TaskDriver(_manager); _jobCommandMap = Maps.newHashMap(); }
Example 6
Source File: TestDriver.java From helix with Apache License 2.0 | 4 votes |
public static void setupCluster(String uniqClusterName, String zkAddr, int numResources, int numPartitionsPerResource, int numInstances, int replica, boolean doRebalance) throws Exception { HelixZkClient zkClient = SharedZkClientFactory.getInstance() .buildZkClient(new HelixZkClient.ZkConnectionConfig(ZK_ADDR)); try { zkClient.setZkSerializer(new ZNRecordSerializer()); // String clusterName = CLUSTER_PREFIX + "_" + uniqClusterName; String clusterName = uniqClusterName; if (zkClient.exists("/" + clusterName)) { LOG.warn("test cluster already exists:" + clusterName + ", test name:" + uniqClusterName + " is not unique or test has been run without cleaning up zk; deleting it"); zkClient.deleteRecursively("/" + clusterName); } if (_testInfoMap.containsKey(uniqClusterName)) { LOG.warn("test info already exists:" + uniqClusterName + " is not unique or test has been run without cleaning up test info map; removing it"); _testInfoMap.remove(uniqClusterName); } TestInfo testInfo = new TestInfo(clusterName, zkClient, numResources, numPartitionsPerResource, numInstances, replica); _testInfoMap.put(uniqClusterName, testInfo); ClusterSetup setupTool = new ClusterSetup(zkAddr); setupTool.addCluster(clusterName, true); for (int i = 0; i < numInstances; i++) { int port = START_PORT + i; setupTool.addInstanceToCluster(clusterName, PARTICIPANT_PREFIX + "_" + port); } for (int i = 0; i < numResources; i++) { String dbName = TEST_DB_PREFIX + i; setupTool.addResourceToCluster(clusterName, dbName, numPartitionsPerResource, STATE_MODEL); if (doRebalance) { setupTool.rebalanceStorageCluster(clusterName, dbName, replica); // String idealStatePath = "/" + clusterName + "/" + // PropertyType.IDEALSTATES.toString() + "/" // + dbName; // ZNRecord idealState = zkClient.<ZNRecord> readData(idealStatePath); // testInfo._idealStateMap.put(dbName, idealState); } } } finally { zkClient.close(); } }
Example 7
Source File: TestClusterStatusMonitorLifecycle.java From helix with Apache License 2.0 | 4 votes |
@BeforeClass public void beforeClass() throws Exception { String className = TestHelper.getTestClassName(); _clusterNamePrefix = className; System.out .println("START " + _clusterNamePrefix + " at " + new Date(System.currentTimeMillis())); // setup 10 clusters for (int i = 0; i < clusterNb; i++) { String clusterName = _clusterNamePrefix + "0_" + i; String participantName = "localhost" + i; String resourceName = "TestDB" + i; TestHelper.setupCluster(clusterName, ZK_ADDR, 12918, // participant port participantName, // participant name prefix resourceName, // resource name prefix 1, // resources 8, // partitions per resource n, // number of nodes 3, // replicas "MasterSlave", true); // do rebalance _clusters.add(clusterName); } // setup controller cluster _controllerClusterName = "CONTROLLER_" + _clusterNamePrefix; TestHelper.setupCluster(_controllerClusterName, ZK_ADDR, // controller 0, // port "controller", // participant name prefix _clusterNamePrefix, // resource name prefix 1, // resources clusterNb, // partitions per resource n, // number of nodes 3, // replicas "LeaderStandby", true); // do rebalance // start distributed cluster controllers _controllers = new ClusterDistributedController[n + n]; for (int i = 0; i < n; i++) { _controllers[i] = new ClusterDistributedController(ZK_ADDR, _controllerClusterName, "controller_" + i); _controllers[i].syncStart(); } ZkHelixClusterVerifier controllerClusterVerifier = new BestPossibleExternalViewVerifier.Builder(_controllerClusterName).setZkClient(_gZkClient) .build(); Assert.assertTrue(controllerClusterVerifier.verifyByPolling(), "Controller cluster NOT in ideal state"); // start first cluster _participants = new MockParticipantManager[n]; _firstClusterName = _clusterNamePrefix + "0_0"; for (int i = 0; i < n; i++) { String instanceName = "localhost0_" + (12918 + i); _participants[i] = new MockParticipantManager(ZK_ADDR, _firstClusterName, instanceName); _participants[i].syncStart(); } ZkHelixClusterVerifier firstClusterVerifier = new BestPossibleExternalViewVerifier.Builder(_firstClusterName).setZkClient(_gZkClient) .build(); Assert.assertTrue(firstClusterVerifier.verifyByPolling(), "first cluster NOT in ideal state"); // add more controllers to controller cluster ClusterSetup setupTool = new ClusterSetup(ZK_ADDR); for (int i = 0; i < n; i++) { String controller = "controller_" + (n + i); setupTool.addInstanceToCluster(_controllerClusterName, controller); } setupTool.rebalanceStorageCluster(_controllerClusterName, _clusterNamePrefix + "0", 6); for (int i = n; i < 2 * n; i++) { _controllers[i] = new ClusterDistributedController(ZK_ADDR, _controllerClusterName, "controller_" + i); _controllers[i].syncStart(); } // verify controller cluster Assert.assertTrue(controllerClusterVerifier.verifyByPolling(), "Controller cluster NOT in ideal state"); // verify first cluster Assert.assertTrue(firstClusterVerifier.verifyByPolling(), "first cluster NOT in ideal state"); // verify all the rest clusters for (int i = 1; i < clusterNb; i++) { ZkHelixClusterVerifier clusterVerifier = new BestPossibleExternalViewVerifier.Builder(_clusterNamePrefix + "0_" + i) .setZkClient(_gZkClient).build(); Assert.assertTrue(clusterVerifier.verifyByPolling(), "Cluster NOT in ideal state."); } }
Example 8
Source File: TestGetSetUserContentStore.java From helix with Apache License 2.0 | 4 votes |
@BeforeClass public void beforeClass() throws Exception { _participants = new MockParticipantManager[_numNodes]; String namespace = "/" + CLUSTER_NAME; if (_gZkClient.exists(namespace)) { _gZkClient.deleteRecursively(namespace); } // Setup cluster and instances ClusterSetup setupTool = new ClusterSetup(ZK_ADDR); setupTool.addCluster(CLUSTER_NAME, true); for (int i = 0; i < _numNodes; i++) { String storageNodeName = PARTICIPANT_PREFIX + "_" + (_startPort + i); setupTool.addInstanceToCluster(CLUSTER_NAME, storageNodeName); } // start dummy participants for (int i = 0; i < _numNodes; i++) { final String instanceName = PARTICIPANT_PREFIX + "_" + (_startPort + i); // Set task callbacks Map<String, TaskFactory> taskFactoryReg = new HashMap<>(); TaskFactory shortTaskFactory = WriteTask::new; taskFactoryReg.put("WriteTask", shortTaskFactory); _participants[i] = new MockParticipantManager(ZK_ADDR, CLUSTER_NAME, instanceName); // Register a Task state model factory. StateMachineEngine stateMachine = _participants[i].getStateMachineEngine(); stateMachine.registerStateModelFactory("Task", new TaskStateModelFactory(_participants[i], taskFactoryReg)); _participants[i].syncStart(); } // Start controller String controllerName = CONTROLLER_PREFIX + "_0"; _controller = new ClusterControllerManager(ZK_ADDR, CLUSTER_NAME, controllerName); _controller.syncStart(); // Start an admin connection _manager = HelixManagerFactory.getZKHelixManager(CLUSTER_NAME, "Admin", InstanceType.ADMINISTRATOR, ZK_ADDR); _manager.connect(); _driver = new TaskDriver(_manager); _jobCommandMap = new HashMap<>(); }
Example 9
Source File: InstancesResource.java From helix with Apache License 2.0 | 4 votes |
@Override public Representation post(Representation entity) { try { String clusterName = (String) getRequest().getAttributes().get("clusterName"); JsonParameters jsonParameters = new JsonParameters(entity); String command = jsonParameters.getCommand(); ZkClient zkClient = (ZkClient) getContext().getAttributes().get(RestAdminApplication.ZKCLIENT); ClusterSetup setupTool = new ClusterSetup(zkClient); if (command.equalsIgnoreCase(ClusterSetup.addInstance) || JsonParameters.CLUSTERSETUP_COMMAND_ALIASES.get(ClusterSetup.addInstance).contains( command)) { if (jsonParameters.getParameter(JsonParameters.INSTANCE_NAME) != null) { setupTool.addInstanceToCluster(clusterName, jsonParameters.getParameter(JsonParameters.INSTANCE_NAME)); } else if (jsonParameters.getParameter(JsonParameters.INSTANCE_NAMES) != null) { setupTool.addInstancesToCluster(clusterName, jsonParameters.getParameter(JsonParameters.INSTANCE_NAMES).split(";")); } else { throw new HelixException("Missing Json paramaters: '" + JsonParameters.INSTANCE_NAME + "' or '" + JsonParameters.INSTANCE_NAMES + "' "); } } else if (command.equalsIgnoreCase(ClusterSetup.swapInstance)) { if (jsonParameters.getParameter(JsonParameters.NEW_INSTANCE) == null || jsonParameters.getParameter(JsonParameters.OLD_INSTANCE) == null) { throw new HelixException("Missing Json paramaters: '" + JsonParameters.NEW_INSTANCE + "' or '" + JsonParameters.OLD_INSTANCE + "' "); } setupTool.swapInstance(clusterName, jsonParameters.getParameter(JsonParameters.OLD_INSTANCE), jsonParameters.getParameter(JsonParameters.NEW_INSTANCE)); } else { throw new HelixException("Unsupported command: " + command + ". Should be one of [" + ClusterSetup.addInstance + ", " + ClusterSetup.swapInstance + "]"); } getResponse().setEntity(getInstancesRepresentation(clusterName)); getResponse().setStatus(Status.SUCCESS_OK); } catch (Exception e) { getResponse().setEntity(ClusterRepresentationUtil.getErrorAsJsonStringFromException(e), MediaType.APPLICATION_JSON); getResponse().setStatus(Status.SUCCESS_OK); LOG.error("", e); } return null; }