admin.addCluster(helixClusterName, false);
public static void createHelixClusterIfNeeded(String helixClusterName, String zkPath) { final HelixAdmin admin = new ZKHelixAdmin(zkPath); if (admin.getClusters().contains(helixClusterName)) { LOGGER.info( "cluster already exist, skipping it.. ********************************************* "); return; } LOGGER.info("Creating a new cluster, as the helix cluster : " + helixClusterName + " was not found ********************************************* "); admin.addCluster(helixClusterName, false); LOGGER.info("Enable mirror maker machines auto join."); final HelixConfigScope scope = new HelixConfigScopeBuilder(ConfigScopeProperty.CLUSTER) .forCluster(helixClusterName).build(); final Map<String, String> props = new HashMap<String, String>(); props.put(ZKHelixManager.ALLOW_PARTICIPANT_AUTO_JOIN, String.valueOf(true)); props.put(MessageType.STATE_TRANSITION + "." + HelixTaskExecutor.MAX_THREADS, String.valueOf(100)); admin.setConfig(scope, props); LOGGER.info("Adding state model definition named : OnlineOffline generated using : " + OnlineOfflineStateModel.class.toString() + " ********************************************** "); // add state model definition admin.addStateModelDef(helixClusterName, "OnlineOffline", OnlineOfflineStateModel.build()); LOGGER.info("New Cluster setup completed... ********************************************** "); }
public static void createHelixClusterIfNeeded(String helixClusterName, String zkPath) { final HelixAdmin admin = new ZKHelixAdmin(zkPath); if (admin.getClusters().contains(helixClusterName)) { LOGGER.info("cluster already exist, skipping it.. ********************************************* "); return; } LOGGER.info("Creating a new cluster, as the helix cluster : " + helixClusterName + " was not found ********************************************* "); admin.addCluster(helixClusterName, false); LOGGER.info("Enable mirror maker machines auto join."); final HelixConfigScope scope = new HelixConfigScopeBuilder(ConfigScopeProperty.CLUSTER) .forCluster(helixClusterName).build(); final Map<String, String> props = new HashMap<String, String>(); props.put(ZKHelixManager.ALLOW_PARTICIPANT_AUTO_JOIN, String.valueOf(true)); props.put(MessageType.STATE_TRANSITION + "." + HelixTaskExecutor.MAX_THREADS, String.valueOf(100)); admin.setConfig(scope, props); LOGGER.info("Adding state model definition named : OnlineOffline generated using : " + OnlineOfflineStateModel.class.toString() + " ********************************************** "); // add state model definition admin.addStateModelDef(helixClusterName, "OnlineOffline", OnlineOfflineStateModel.build()); LOGGER.info("New Cluster setup completed... ********************************************** "); }
public void addCluster(String clusterName, boolean overwritePrevious) { _admin.addCluster(clusterName, overwritePrevious); for (BuiltInStateModelDefinitions def : BuiltInStateModelDefinitions.values()) { addStateModelDef(clusterName, def.getStateModelDefinition().getId(), def.getStateModelDefinition(), overwritePrevious); } }
public void addCluster(String clusterName, boolean overwritePrevious) { _admin.addCluster(clusterName, overwritePrevious); for (BuiltInStateModelDefinitions def : BuiltInStateModelDefinitions.values()) { addStateModelDef(clusterName, def.getStateModelDefinition().getId(), def.getStateModelDefinition(), overwritePrevious); } }
startLocalZookeeper(2199); HelixAdmin admin = new ZKHelixAdmin(zkAddress); admin.addCluster(clusterName, true); StateModelConfigGenerator generator = new StateModelConfigGenerator(); admin.addStateModelDef(clusterName, "OnlineOffline",
/** * @return returns true if */ public boolean start() throws Exception { // auto create cluster and allow nodes to automatically join the cluster admin = HelixManagerFactory.getZKHelixManager(cluster, "service-discovery", InstanceType.ADMINISTRATOR, zkAddress); admin.connect(); admin.getClusterManagmentTool().addCluster(cluster, false); HelixConfigScope scope = new HelixConfigScopeBuilder(ConfigScopeProperty.CLUSTER).forCluster(cluster).build(); Map<String, String> properties = new HashMap<String, String>(); properties.put(ZKHelixManager.ALLOW_PARTICIPANT_AUTO_JOIN, String.valueOf(true)); admin.getClusterManagmentTool().setConfig(scope, properties); switch (mode) { case POLL: startBackgroundTask(); break; case WATCH: setupWatcher(); break; case NONE:// dont monitor changes, supports only registration } refreshCache(); return true; }
public void setup() { _clusterName = "testCluster-" + UUID.randomUUID().toString(); manager = new MockManager(_clusterName); accessor = manager.getHelixDataAccessor(); ClusterConfig clusterConfig = new ClusterConfig(_clusterName); setClusterConfig(clusterConfig); admin = new MockHelixAdmin(manager); event = new ClusterEvent(ClusterEventType.Unknown); admin.addCluster(_clusterName); }
public static void setup() { admin = new ZKHelixAdmin(ZK_ADDRESS); // create cluster echo("Creating cluster: " + CLUSTER_NAME); admin.addCluster(CLUSTER_NAME, true); // Add nodes to the cluster echo("Adding " + NUM_NODES + " participants to the cluster"); for (int i = 0; i < NUM_NODES; i++) { admin.addInstance(CLUSTER_NAME, INSTANCE_CONFIG_LIST.get(i)); echo("\t Added participant: " + INSTANCE_CONFIG_LIST.get(i).getInstanceName()); } // Add a state model StateModelDefinition myStateModel = defineStateModel(); echo("Configuring StateModel: " + "MyStateModel with 1 Master and 1 Slave"); admin.addStateModelDef(CLUSTER_NAME, STATE_MODEL_NAME, myStateModel); // Add a resource with 6 partitions and 2 replicas echo("Adding a resource MyResource: " + "with 6 partitions and 2 replicas"); admin.addResource(CLUSTER_NAME, RESOURCE_NAME, NUM_PARTITIONS, STATE_MODEL_NAME, "AUTO"); // this will set up the ideal state, it calculates the preference list for // each partition similar to consistent hashing admin.rebalance(CLUSTER_NAME, RESOURCE_NAME, NUM_REPLICAS); }
public static void setup() { admin = new ZKHelixAdmin(ZK_ADDRESS); // create cluster echo("Creating cluster: " + CLUSTER_NAME); admin.addCluster(CLUSTER_NAME, true); // Add nodes to the cluster echo("Adding " + NUM_NODES + " participants to the cluster"); for (int i = 0; i < NUM_NODES; i++) { admin.addInstance(CLUSTER_NAME, INSTANCE_CONFIG_LIST.get(i)); echo("\t Added participant: " + INSTANCE_CONFIG_LIST.get(i).getInstanceName()); } // Add a state model StateModelDefinition myStateModel = defineStateModel(); echo("Configuring StateModel: " + "MyStateModel with 1 Master and 1 Slave"); admin.addStateModelDef(CLUSTER_NAME, STATE_MODEL_NAME, myStateModel); // Add a resource with 6 partitions and 2 replicas echo("Adding a resource MyResource: " + "with 6 partitions and 2 replicas"); admin.addResource(CLUSTER_NAME, RESOURCE_NAME, NUM_PARTITIONS, STATE_MODEL_NAME, "AUTO"); // this will set up the ideal state, it calculates the preference list for // each partition similar to consistent hashing admin.rebalance(CLUSTER_NAME, RESOURCE_NAME, NUM_REPLICAS); }
@Test public void testEnableDisablePartitions() { String className = TestHelper.getTestClassName(); String methodName = TestHelper.getTestMethodName(); String clusterName = className + "_" + methodName; String instanceName = "TestInstance"; String testResourcePrefix = "TestResource"; System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis())); HelixAdmin admin = new ZKHelixAdmin(_gZkClient); admin.addCluster(clusterName, true); admin.addInstance(clusterName, new InstanceConfig(instanceName)); // Test disable instances with resources admin.enablePartition(false, clusterName, instanceName, testResourcePrefix + "0", Arrays.asList(new String[]{"1", "2"})); admin.enablePartition(false, clusterName, instanceName, testResourcePrefix + "1", Arrays.asList(new String[]{"2", "3", "4"})); InstanceConfig instanceConfig = admin.getInstanceConfig(clusterName, instanceName); Assert.assertEquals(instanceConfig.getDisabledPartitions(testResourcePrefix + "0").size(), 2); Assert.assertEquals(instanceConfig.getDisabledPartitions(testResourcePrefix + "1").size(), 3); // Test disable partition across resources // TODO : Remove this part once setInstanceEnabledForPartition(partition, enabled) is removed instanceConfig.setInstanceEnabledForPartition("10", false); Assert.assertEquals(instanceConfig.getDisabledPartitions(testResourcePrefix + "0").size(), 3); Assert.assertEquals(instanceConfig.getDisabledPartitions(testResourcePrefix + "1").size(), 4); admin.dropCluster(clusterName); }
admin.addCluster(CLUSTER_NAME, true);
admin.addCluster(CLUSTER_NAME, true);
@Test public void testDisableResource() { String className = TestHelper.getTestClassName(); String methodName = TestHelper.getTestMethodName(); String clusterName = className + "_" + methodName; System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis())); HelixAdmin admin = new ZKHelixAdmin(_gZkClient); admin.addCluster(clusterName, true); Assert.assertTrue(ZKUtil.isClusterSetup(clusterName, _gZkClient), "Cluster should be setup"); String resourceName = "TestDB"; admin.addStateModelDef(clusterName, "MasterSlave", new StateModelDefinition( StateModelConfigGenerator.generateConfigForMasterSlave())); admin.addResource(clusterName, resourceName, 4, "MasterSlave"); admin.enableResource(clusterName, resourceName, false); BaseDataAccessor<ZNRecord> baseAccessor = new ZkBaseDataAccessor<ZNRecord>(_gZkClient); HelixDataAccessor accessor = new ZKHelixDataAccessor(clusterName, baseAccessor); PropertyKey.Builder keyBuilder = accessor.keyBuilder(); IdealState idealState = accessor.getProperty(keyBuilder.idealStates(resourceName)); Assert.assertFalse(idealState.isEnabled()); admin.enableResource(clusterName, resourceName, true); idealState = accessor.getProperty(keyBuilder.idealStates(resourceName)); Assert.assertTrue(idealState.isEnabled()); admin.dropCluster(clusterName); System.out.println("END " + clusterName + " at " + new Date(System.currentTimeMillis())); }
admin.addCluster(clusterName); admin.addStateModelDef(clusterName, BuiltInStateModelDefinitions.MasterSlave.getStateModelDefinition().getId(), BuiltInStateModelDefinitions.MasterSlave.getStateModelDefinition());
@Test public void testDropResource() { String className = TestHelper.getTestClassName(); String methodName = TestHelper.getTestMethodName(); String clusterName = className + "_" + methodName; System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis())); HelixAdmin tool = new ZKHelixAdmin(_gZkClient); tool.addCluster(clusterName, true); Assert.assertTrue(ZKUtil.isClusterSetup(clusterName, _gZkClient), "Cluster should be setup"); tool.addStateModelDef(clusterName, "MasterSlave", new StateModelDefinition( StateModelConfigGenerator.generateConfigForMasterSlave())); tool.addResource(clusterName, "test-db", 4, "MasterSlave"); Map<String, String> resourceConfig = new HashMap<String, String>(); resourceConfig.put("key1", "value1"); tool.setConfig(new HelixConfigScopeBuilder(ConfigScopeProperty.RESOURCE) .forCluster(clusterName).forResource("test-db").build(), resourceConfig); PropertyKey.Builder keyBuilder = new PropertyKey.Builder(clusterName); Assert.assertTrue(_gZkClient.exists(keyBuilder.idealStates("test-db").getPath()), "test-db ideal-state should exist"); Assert.assertTrue(_gZkClient.exists(keyBuilder.resourceConfig("test-db").getPath()), "test-db resource config should exist"); tool.dropResource(clusterName, "test-db"); Assert.assertFalse(_gZkClient.exists(keyBuilder.idealStates("test-db").getPath()), "test-db ideal-state should be dropped"); Assert.assertFalse(_gZkClient.exists(keyBuilder.resourceConfig("test-db").getPath()), "test-db resource config should be dropped"); tool.dropCluster(clusterName); System.out.println("END " + clusterName + " at " + new Date(System.currentTimeMillis())); }
tool.addCluster(clusterName, true); Assert.assertTrue(ZKUtil.isClusterSetup(clusterName, _gZkClient), "Cluster should be setup");
admin.addCluster(clusterName, true);
void startAdmin() throws Exception { HelixAdmin admin = new ZKHelixAdmin(ZK_ADDR); // create cluster System.out.println("Creating cluster: " + clusterName); admin.addCluster(clusterName, true); // add MasterSlave state mode definition admin.addStateModelDef(clusterName, "MasterSlave", new StateModelDefinition( generateConfigForMasterSlave())); // ideal-state znrecord ZNRecord record = new ZNRecord(resourceName); record.setSimpleField("IDEAL_STATE_MODE", "AUTO"); record.setSimpleField("NUM_PARTITIONS", "1"); record.setSimpleField("REPLICAS", "2"); record.setSimpleField("STATE_MODEL_DEF_REF", "MasterSlave"); record.setListField(resourceName, Arrays.asList("node1", "node2")); admin.setResourceIdealState(clusterName, resourceName, new IdealState(record)); ConstraintItemBuilder builder = new ConstraintItemBuilder(); // limit one transition message at a time across the entire cluster builder.addConstraintAttribute("MESSAGE_TYPE", "STATE_TRANSITION") // .addConstraintAttribute("INSTANCE", ".*") // un-comment this line if using instance-level // constraint .addConstraintAttribute("CONSTRAINT_VALUE", "1"); admin.setConstraint(clusterName, ClusterConstraints.ConstraintType.MESSAGE_CONSTRAINT, "constraint1", builder.build()); }
tool.addCluster(clusterName, true); Assert.assertTrue(ZKUtil.isClusterSetup(clusterName, _gZkClient));