CommonNodeLabelsManager extends AbstractService { @VisibleForTesting public void addToCluserNodeLabelsWithDefaultExclusivity(Set<String> labels) throws IOException { Set<NodeLabel> nodeLabels = new HashSet<NodeLabel>(); for (String label : labels) { nodeLabels.add(NodeLabel.newInstance(label)); } addToCluserNodeLabels(nodeLabels); } CommonNodeLabelsManager(); boolean isCentralizedConfiguration(); @SuppressWarnings("unchecked") void addToCluserNodeLabels(Collection<NodeLabel> labels); @VisibleForTesting void addToCluserNodeLabelsWithDefaultExclusivity(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<NodeId, Set<NodeLabel>> getNodeLabelsInfo(); Set<NodeId> getNodesWithoutALabel(); Map<String, Set<NodeId>> getLabelsToNodes(); Map<String, Set<NodeId>> getLabelsToNodes(Set<String> labels); Map<NodeLabel, Set<NodeId>> getLabelsInfoToNodes(); Map<NodeLabel, Set<NodeId>> getLabelsInfoToNodes(Set<String> labels); Set<String> getClusterNodeLabelNames(); List<NodeLabel> getClusterNodeLabels(); boolean isExclusiveNodeLabel(String nodeLabel); Set<NodeLabel> getLabelsInfoByNode(NodeId nodeId); void setInitNodeLabelStoreInProgress(
      boolean initNodeLabelStoreInProgress); static final Set<String> EMPTY_STRING_SET; static final Set<NodeLabel> EMPTY_NODELABEL_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; }
@Test(timeout = 5000) public void testAddInvalidlabel() throws IOException { boolean caught = false; try { Set<String> set = new HashSet<String>(); set.add(null); mgr.addToCluserNodeLabelsWithDefaultExclusivity(set); } catch (IOException e) { caught = true; } Assert.assertTrue("null label should not add to repo", caught); caught = false; try { mgr.addToCluserNodeLabelsWithDefaultExclusivity(ImmutableSet.of(CommonNodeLabelsManager.NO_LABEL)); } catch (IOException e) { caught = true; } Assert.assertTrue("empty label should not add to repo", caught); caught = false; try { mgr.addToCluserNodeLabelsWithDefaultExclusivity(ImmutableSet.of("-?")); } catch (IOException e) { caught = true; } Assert.assertTrue("invalid label character should not add to repo", caught); caught = false; try { mgr.addToCluserNodeLabelsWithDefaultExclusivity(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.addToCluserNodeLabelsWithDefaultExclusivity(ImmutableSet.of("-aaabbb")); } catch (IOException e) { caught = true; } Assert.assertTrue("label cannot start with \"-\"", caught); caught = false; try { mgr.addToCluserNodeLabelsWithDefaultExclusivity(ImmutableSet.of("_aaabbb")); } catch (IOException e) { caught = true; } Assert.assertTrue("label cannot start with \"_\"", caught); caught = false; try { mgr.addToCluserNodeLabelsWithDefaultExclusivity(ImmutableSet.of("a^aabbb")); } catch (IOException e) { caught = true; } Assert.assertTrue("label cannot contains other chars like ^[] ...", caught); caught = false; try { mgr.addToCluserNodeLabelsWithDefaultExclusivity(ImmutableSet.of("aa[a]bbb")); } catch (IOException e) { caught = true; } Assert.assertTrue("label cannot contains other chars like ^[] ...", caught); }