public List<String> getOnlineInstanceList() { return _helixDataAccessor.getChildNames(_keyBuilder.liveInstances()); }
/** * Computes the broker nodes that are untagged and free to be used. * @return List of online untagged broker instances. */ public List<String> getOnlineUnTaggedBrokerInstanceList() { final List<String> instanceList = HelixHelper.getInstancesWithTag(_helixZkManager, CommonConstants.Helix.UNTAGGED_BROKER_INSTANCE); final List<String> liveInstances = _helixDataAccessor.getChildNames(_keyBuilder.liveInstances()); instanceList.retainAll(liveInstances); return instanceList; }
/** * Computes the server nodes that are untagged and free to be used. * @return List of untagged online server instances. */ public List<String> getOnlineUnTaggedServerInstanceList() { final List<String> instanceList = HelixHelper.getInstancesWithTag(_helixZkManager, CommonConstants.Helix.UNTAGGED_SERVER_INSTANCE); final List<String> liveInstances = _helixDataAccessor.getChildNames(_keyBuilder.liveInstances()); instanceList.retainAll(liveInstances); return instanceList; }
public static List<String> liveInstances(HelixManager helixManager) { HelixDataAccessor helixDataAccessor = helixManager.getHelixDataAccessor(); PropertyKey liveInstancesKey = helixDataAccessor.keyBuilder().liveInstances(); return ImmutableList.copyOf(helixDataAccessor.getChildNames(liveInstancesKey)); }
@Override public boolean verify() throws Exception { List<String> actualLiveNodes = _accessor.getChildNames(_keyBuilder.liveInstances()); Collections.sort(actualLiveNodes); return _expectSortedLiveNodes.equals(actualLiveNodes); }
@Override protected boolean verifyState() throws Exception { Set<String> actualLiveNodes = new HashSet<String>(_accessor.getChildNames(_keyBuilder.liveInstances())); return _expectLiveNodes.equals(actualLiveNodes); }
@Override protected boolean verifyState() throws Exception { Set<String> actualLiveNodes = new HashSet<String>(_accessor.getChildNames(_keyBuilder.liveInstances())); return _expectLiveNodes.equals(actualLiveNodes); }
@Override public boolean verify() throws Exception { List<String> actualLiveNodes = _accessor.getChildNames(_keyBuilder.liveInstances()); Collections.sort(actualLiveNodes); return _expectSortedLiveNodes.equals(actualLiveNodes); }
@GET @Path("{clusterId}/controller/messages") public Response getClusterControllerMessages(@PathParam("clusterId") String clusterId) { HelixDataAccessor dataAccessor = getDataAccssor(clusterId); Map<String, Object> controllerMessages = new HashMap<>(); controllerMessages.put(Properties.id.name(), clusterId); List<String> messages = dataAccessor.getChildNames(dataAccessor.keyBuilder().controllerMessages()); controllerMessages.put(ClusterProperties.messages.name(), messages); controllerMessages.put(Properties.count.name(), messages.size()); return JSONRepresentation(controllerMessages); }
@GET @Path("{clusterId}/statemodeldefs") public Response getClusterStateModelDefinitions(@PathParam("clusterId") String clusterId) { HelixDataAccessor dataAccessor = getDataAccssor(clusterId); List<String> stateModelDefs = dataAccessor.getChildNames(dataAccessor.keyBuilder().stateModelDefs()); Map<String, Object> clusterStateModelDefs = new HashMap<>(); clusterStateModelDefs.put(Properties.id.name(), clusterId); clusterStateModelDefs.put(ClusterProperties.stateModelDefinitions.name(), stateModelDefs); return JSONRepresentation(clusterStateModelDefs); }
public static List<String> liveInstances(HelixManager helixManager) { HelixDataAccessor helixDataAccessor = helixManager.getHelixDataAccessor(); PropertyKey liveInstancesKey = helixDataAccessor.keyBuilder().liveInstances(); return ImmutableList.copyOf(helixDataAccessor.getChildNames(liveInstancesKey)); }
public static List<String> liveInstances(HelixManager helixManager) { HelixDataAccessor helixDataAccessor = helixManager.getHelixDataAccessor(); PropertyKey liveInstancesKey = helixDataAccessor.keyBuilder().liveInstances(); return ImmutableList.copyOf(helixDataAccessor.getChildNames(liveInstancesKey)); }
/** * Throw Exception if children nodes will exceed limitation after adding newNodesCount children. * @param newConfigNodeCount */ private void validateZKNodeLimitation(int newConfigNodeCount) { List<String> resourceConfigs = _accessor.getChildNames(_accessor.keyBuilder().resourceConfigs()); if (resourceConfigs.size() + newConfigNodeCount > _configsLimitation) { throw new HelixException( "Cannot create more workflows or jobs because there are already too many items created in the path CONFIGS."); } } }
/** * Throw Exception if children nodes will exceed limitation after adding newNodesCount children. * @param newConfigNodeCount */ private void validateZKNodeLimitation(int newConfigNodeCount) { List<String> resourceConfigs = _accessor.getChildNames(_accessor.keyBuilder().resourceConfigs()); if (resourceConfigs.size() + newConfigNodeCount > _configsLimitation) { throw new HelixException( "Cannot create more workflows or jobs because there are already too many items created in the path CONFIGS."); } } }
@GET @Path("{instanceName}/resources/{resourceName}") public Response getResourceOnInstance(@PathParam("clusterId") String clusterId, @PathParam("instanceName") String instanceName, @PathParam("resourceName") String resourceName) throws IOException { HelixDataAccessor accessor = getDataAccssor(clusterId); List<String> sessionIds = accessor.getChildNames(accessor.keyBuilder().sessions(instanceName)); if (sessionIds == null || sessionIds.size() == 0) { return notFound(); } // Only get resource list from current session id String currentSessionId = sessionIds.get(0); CurrentState resourceCurrentState = accessor .getProperty(accessor.keyBuilder().currentState(instanceName, currentSessionId, resourceName)); if (resourceCurrentState != null) { return JSONRepresentation(resourceCurrentState.getRecord()); } return notFound(); }
@GET @Path("{instanceName}/healthreports") public Response getHealthReportsOnInstance(@PathParam("clusterId") String clusterId, @PathParam("instanceName") String instanceName) throws IOException { HelixDataAccessor accessor = getDataAccssor(clusterId); ObjectNode root = JsonNodeFactory.instance.objectNode(); root.put(Properties.id.name(), instanceName); ArrayNode healthReportsNode = root.putArray(InstanceProperties.healthreports.name()); List<String> healthReports = accessor.getChildNames(accessor.keyBuilder().healthReports(instanceName)); if (healthReports != null && healthReports.size() > 0) { healthReportsNode.addAll((ArrayNode) OBJECT_MAPPER.valueToTree(healthReports)); } return JSONRepresentation(root); }
@Override public void dropCluster(String clusterName) { logger.info("Deleting cluster {}.", clusterName); HelixDataAccessor accessor = new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<ZNRecord>(_zkClient)); Builder keyBuilder = accessor.keyBuilder(); String root = "/" + clusterName; if (accessor.getChildNames(keyBuilder.liveInstances()).size() > 0) { throw new HelixException( "There are still live instances in the cluster, shut them down first."); } if (accessor.getProperty(keyBuilder.controllerLeader()) != null) { throw new HelixException("There are still LEADER in the cluster, shut them down first."); } _zkClient.deleteRecursively(root); }
@Override public void dropCluster(String clusterName) { logger.info("Deleting cluster {}.", clusterName); HelixDataAccessor accessor = new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<ZNRecord>(_zkClient)); Builder keyBuilder = accessor.keyBuilder(); String root = "/" + clusterName; if (accessor.getChildNames(keyBuilder.liveInstances()).size() > 0) { throw new HelixException( "There are still live instances in the cluster, shut them down first."); } if (accessor.getProperty(keyBuilder.controllerLeader()) != null) { throw new HelixException("There are still LEADER in the cluster, shut them down first."); } _zkClient.deleteRecursively(root); }
private void updateConfigs() throws InterruptedException { final Random r = new Random(System.currentTimeMillis()); // test change content HelixDataAccessor accessor = _manager.getHelixDataAccessor(); Builder keyBuilder = accessor.keyBuilder(); final List<String> instances = accessor.getChildNames(keyBuilder.instanceConfigs()); for (String instance : instances) { InstanceConfig value = accessor.getProperty(keyBuilder.instanceConfig(instance)); value._record.setLongField("TimeStamp", System.currentTimeMillis()); accessor.setProperty(keyBuilder.instanceConfig(instance), value); Thread.sleep(50); } final List<String> resources = accessor.getChildNames(keyBuilder.idealStates()); for (String resource : resources) { IdealState idealState = accessor.getProperty(keyBuilder.idealStates(resource)); idealState.setNumPartitions(r.nextInt(100)); accessor.setProperty(keyBuilder.idealStates(idealState.getId()), idealState); Thread.sleep(20); // wait zk callback } } }
private void updateIdealState() { HelixDataAccessor accessor = _manager.getHelixDataAccessor(); Builder keyBuilder = accessor.keyBuilder(); List<String> idealStates = accessor.getChildNames(keyBuilder.idealStates()); IdealState idealState = accessor.getProperty(keyBuilder.idealStates(idealStates.get(0))); idealState.setNumPartitions((int)(System.currentTimeMillis()%50L)); accessor.setProperty(keyBuilder.idealStates(idealState.getId()), idealState); } }