@Test(timeout = 5000) public void testAddInvalidlabel() throws IOException { boolean caught = false; try { Set<String> set = new HashSet<String>(); set.add(null); mgr.addToCluserNodeLabels(set); } catch (IOException e) { caught = true; } Assert.assertTrue("null label should not add to repo", caught); caught = false; try { mgr.addToCluserNodeLabels(ImmutableSet.of(CommonNodeLabelsManager.NO_LABEL)); } catch (IOException e) { caught = true; } Assert.assertTrue("empty label should not add to repo", caught); caught = false; try { mgr.addToCluserNodeLabels(ImmutableSet.of("-?")); } catch (IOException e) { caught = true; } Assert.assertTrue("invalid label charactor should not add to repo", caught); caught = false; try { mgr.addToCluserNodeLabels(ImmutableSet.of(StringUtils.repeat("c", 257))); } catch (IOException e) { caught = true; } Assert.assertTrue("too long label should not add to repo", caught); caught = false; try { mgr.addToCluserNodeLabels(ImmutableSet.of("-aaabbb")); } catch (IOException e) { caught = true; } Assert.assertTrue("label cannot start with \"-\"", caught); caught = false; try { mgr.addToCluserNodeLabels(ImmutableSet.of("_aaabbb")); } catch (IOException e) { caught = true; } Assert.assertTrue("label cannot start with \"_\"", caught); caught = false; try { mgr.addToCluserNodeLabels(ImmutableSet.of("a^aabbb")); } catch (IOException e) { caught = true; } Assert.assertTrue("label cannot contains other chars like ^[] ...", caught); caught = false; try { mgr.addToCluserNodeLabels(ImmutableSet.of("aa[a]bbb")); } catch (IOException e) { caught = true; } Assert.assertTrue("label cannot contains other chars like ^[] ...", caught); }
@SuppressWarnings("unchecked") public void addToCluserNodeLabels(Set<String> labels) throws IOException { if (!nodeLabelsEnabled) { LOG.error(NODE_LABELS_NOT_ENABLED_ERR); throw new IOException(NODE_LABELS_NOT_ENABLED_ERR); } if (null == labels || labels.isEmpty()) { return; } Set<String> newLabels = new HashSet<String>(); labels = normalizeLabels(labels); for (String label : labels) { checkAndThrowLabelName(label); } for (String label : labels) { if (this.labelCollections.get(label) == null) { this.labelCollections.put(label, new NodeLabel(label)); newLabels.add(label); } } if (null != dispatcher && !newLabels.isEmpty()) { dispatcher.getEventHandler().handle( new StoreNewClusterNodeLabels(newLabels)); } LOG.info("Add labels: [" + StringUtils.join(labels.iterator(), ",") + "]"); }
CommonNodeLabelsManager extends AbstractService { @SuppressWarnings("unchecked") public void addToCluserNodeLabels(Set<String> labels) throws IOException { if (!nodeLabelsEnabled) { LOG.error(NODE_LABELS_NOT_ENABLED_ERR); throw new IOException(NODE_LABELS_NOT_ENABLED_ERR); } if (null == labels || labels.isEmpty()) { return; } Set<String> newLabels = new HashSet<String>(); labels = normalizeLabels(labels); for (String label : labels) { checkAndThrowLabelName(label); } for (String label : labels) { if (this.labelCollections.get(label) == null) { this.labelCollections.put(label, new NodeLabel(label)); newLabels.add(label); } } if (null != dispatcher && !newLabels.isEmpty()) { dispatcher.getEventHandler().handle( new StoreNewClusterNodeLabels(newLabels)); } LOG.info("Add labels: [" + StringUtils.join(labels.iterator(), ",") + "]"); } }
CommonNodeLabelsManager extends AbstractService { @SuppressWarnings("unchecked") public void addToCluserNodeLabels(Set<String> labels) throws IOException { if (!nodeLabelsEnabled) { LOG.error(NODE_LABELS_NOT_ENABLED_ERR); throw new IOException(NODE_LABELS_NOT_ENABLED_ERR); } if (null == labels || labels.isEmpty()) { return; } Set<String> newLabels = new HashSet<String>(); labels = normalizeLabels(labels); for (String label : labels) { checkAndThrowLabelName(label); } for (String label : labels) { if (this.labelCollections.get(label) == null) { this.labelCollections.put(label, new NodeLabel(label)); newLabels.add(label); } } if (null != dispatcher && !newLabels.isEmpty()) { dispatcher.getEventHandler().handle( new StoreNewClusterNodeLabels(newLabels)); } LOG.info("Add labels: [" + StringUtils.join(labels.iterator(), ",") + "]"); } CommonNodeLabelsManager(); }
CommonNodeLabelsManager extends AbstractService { @SuppressWarnings("unchecked") public void addToCluserNodeLabels(Set<String> labels) throws IOException { if (!nodeLabelsEnabled) { LOG.error(NODE_LABELS_NOT_ENABLED_ERR); throw new IOException(NODE_LABELS_NOT_ENABLED_ERR); } if (null == labels || labels.isEmpty()) { return; } Set<String> newLabels = new HashSet<String>(); labels = normalizeLabels(labels); for (String label : labels) { checkAndThrowLabelName(label); } for (String label : labels) { if (this.labelCollections.get(label) == null) { this.labelCollections.put(label, new NodeLabel(label)); newLabels.add(label); } } if (null != dispatcher && !newLabels.isEmpty()) { dispatcher.getEventHandler().handle( new StoreNewClusterNodeLabels(newLabels)); } LOG.info("Add labels: [" + StringUtils.join(labels.iterator(), ",") + "]"); } CommonNodeLabelsManager(); @SuppressWarnings("unchecked") void addToCluserNodeLabels(Set<String> labels); void addLabelsToNode(Map<NodeId, Set<String>> addedLabelsToNode); void removeFromClusterNodeLabels(Collection<String> labelsToRemove); void removeLabelsFromNode(Map<NodeId, Set<String>> removeLabelsFromNode); void replaceLabelsOnNode(Map<NodeId, Set<String>> replaceLabelsToNode); Map<NodeId, Set<String>> getNodeLabels(); Map<String, Set<NodeId>> getLabelsToNodes(); Map<String, Set<NodeId>> getLabelsToNodes(Set<String> labels); Set<String> getClusterNodeLabels(); void setInitNodeLabelStoreInProgress(
      boolean initNodeLabelStoreInProgress); }
CommonNodeLabelsManager extends AbstractService { @SuppressWarnings("unchecked") public void addToCluserNodeLabels(Set<String> labels) throws IOException { if (!nodeLabelsEnabled) { LOG.error(NODE_LABELS_NOT_ENABLED_ERR); throw new IOException(NODE_LABELS_NOT_ENABLED_ERR); } if (null == labels || labels.isEmpty()) { return; } Set<String> newLabels = new HashSet<String>(); labels = normalizeLabels(labels); for (String label : labels) { checkAndThrowLabelName(label); } for (String label : labels) { if (this.labelCollections.get(label) == null) { this.labelCollections.put(label, new NodeLabel(label)); newLabels.add(label); } } if (null != dispatcher && !newLabels.isEmpty()) { dispatcher.getEventHandler().handle( new StoreNewClusterNodeLabels(newLabels)); } LOG.info("Add labels: [" + StringUtils.join(labels.iterator(), ",") + "]"); } CommonNodeLabelsManager(); @SuppressWarnings("unchecked") void addToCluserNodeLabels(Set<String> labels); void addLabelsToNode(Map<NodeId, Set<String>> addedLabelsToNode); void removeFromClusterNodeLabels(Collection<String> labelsToRemove); void removeLabelsFromNode(Map<NodeId, Set<String>> removeLabelsFromNode); void replaceLabelsOnNode(Map<NodeId, Set<String>> replaceLabelsToNode); Map<NodeId, Set<String>> getNodeLabels(); Map<String, Set<NodeId>> getLabelsToNodes(); Map<String, Set<NodeId>> getLabelsToNodes(Set<String> labels); Set<String> getClusterNodeLabels(); void setInitNodeLabelStoreInProgress(
      boolean initNodeLabelStoreInProgress); static final Set<String> EMPTY_STRING_SET; static final String ANY; static final Set<String> ACCESS_ANY_LABEL_SET; static final int WILDCARD_PORT; @VisibleForTesting
  static final String NODE_LABELS_NOT_ENABLED_ERR; static final String NO_LABEL; }