List<String> instancesInCluster = zkHelixAdmin.getInstancesInCluster(_clusterName); List<String> tables = zkHelixAdmin.getResourcesInCluster(_clusterName);
@Override public void rebalance(String clusterName, String resourceName, int replica, String keyPrefix, String group) { List<String> instanceNames = new LinkedList<String>(); if (keyPrefix == null || keyPrefix.length() == 0) { keyPrefix = resourceName; } if (group != null && group.length() > 0) { instanceNames = getInstancesInClusterWithTag(clusterName, group); } if (instanceNames.size() == 0) { logger.info("No tags found for resource " + resourceName + ", use all instances"); instanceNames = getInstancesInCluster(clusterName); group = ""; } else { logger.info("Found instances with tag for " + resourceName + " " + instanceNames); } rebalance(clusterName, resourceName, replica, keyPrefix, instanceNames, group); }
/** * Configure the instance, the configuration of each node is available to * other nodes. * @param instanceName */ private void configureInstance(String instanceName) { ZKHelixAdmin helixAdmin = new ZKHelixAdmin(zkAddress); List<String> instancesInCluster = helixAdmin.getInstancesInCluster(clusterName); if (instancesInCluster == null || !instancesInCluster.contains(instanceName)) { InstanceConfig config = new InstanceConfig(instanceName); config.setHostName("localhost"); config.setPort("12000"); helixAdmin.addInstance(clusterName, config); } }
@Override public void rebalance(String clusterName, String resourceName, int replica, String keyPrefix, String group) { List<String> instanceNames = new LinkedList<String>(); if (keyPrefix == null || keyPrefix.length() == 0) { keyPrefix = resourceName; } if (group != null && group.length() > 0) { instanceNames = getInstancesInClusterWithTag(clusterName, group); } if (instanceNames.size() == 0) { logger.info("No tags found for resource " + resourceName + ", use all instances"); instanceNames = getInstancesInCluster(clusterName); group = ""; } else { logger.info("Found instances with tag for " + resourceName + " " + instanceNames); } rebalance(clusterName, resourceName, replica, keyPrefix, instanceNames, group); }
ZKHelixAdmin admin = new ZKHelixAdmin(zkclient); List<String> nodes = admin.getInstancesInCluster(clusterName); if (!nodes.contains("consumer_" + consumerId)) { InstanceConfig config = new InstanceConfig("consumer_" + consumerId);
@Override public void addClusterToGrandCluster(String clusterName, String grandCluster) { logger.info("Add cluster {} to grand cluster {}.", clusterName, grandCluster); if (!ZKUtil.isClusterSetup(grandCluster, _zkClient)) { throw new HelixException("Grand cluster " + grandCluster + " is not setup yet"); } if (!ZKUtil.isClusterSetup(clusterName, _zkClient)) { throw new HelixException("Cluster " + clusterName + " is not setup yet"); } IdealState idealState = new IdealState(clusterName); idealState.setNumPartitions(1); idealState.setStateModelDefRef("LeaderStandby"); List<String> controllers = getInstancesInCluster(grandCluster); if (controllers.size() == 0) { throw new HelixException("Grand cluster " + grandCluster + " has no instances"); } idealState.setReplicas(Integer.toString(controllers.size())); Collections.shuffle(controllers); idealState.getRecord().setListField(clusterName, controllers); idealState.setPartitionState(clusterName, controllers.get(0), "LEADER"); for (int i = 1; i < controllers.size(); i++) { idealState.setPartitionState(clusterName, controllers.get(i), "STANDBY"); } ZKHelixDataAccessor accessor = new ZKHelixDataAccessor(grandCluster, new ZkBaseDataAccessor<ZNRecord>(_zkClient)); Builder keyBuilder = accessor.keyBuilder(); accessor.setProperty(keyBuilder.idealStates(idealState.getResourceName()), idealState); }
@Override public void addClusterToGrandCluster(String clusterName, String grandCluster) { logger.info("Add cluster {} to grand cluster {}.", clusterName, grandCluster); if (!ZKUtil.isClusterSetup(grandCluster, _zkClient)) { throw new HelixException("Grand cluster " + grandCluster + " is not setup yet"); } if (!ZKUtil.isClusterSetup(clusterName, _zkClient)) { throw new HelixException("Cluster " + clusterName + " is not setup yet"); } IdealState idealState = new IdealState(clusterName); idealState.setNumPartitions(1); idealState.setStateModelDefRef("LeaderStandby"); List<String> controllers = getInstancesInCluster(grandCluster); if (controllers.size() == 0) { throw new HelixException("Grand cluster " + grandCluster + " has no instances"); } idealState.setReplicas(Integer.toString(controllers.size())); Collections.shuffle(controllers); idealState.getRecord().setListField(clusterName, controllers); idealState.setPartitionState(clusterName, controllers.get(0), "LEADER"); for (int i = 1; i < controllers.size(); i++) { idealState.setPartitionState(clusterName, controllers.get(i), "STANDBY"); } ZKHelixDataAccessor accessor = new ZKHelixDataAccessor(grandCluster, new ZkBaseDataAccessor<ZNRecord>(_zkClient)); Builder keyBuilder = accessor.keyBuilder(); accessor.setProperty(keyBuilder.idealStates(idealState.getResourceName()), idealState); }