@Test(timeout = 5000) public void testPullRMNodeLabelsInfo() throws IOException { mgr.addToCluserNodeLabels(toSet("x", "y", "z")); mgr.activateNode(NodeId.newInstance("n1", 1), Resource.newInstance(10, 0, 0)); mgr.activateNode(NodeId.newInstance("n2", 1), Resource.newInstance(10, 0, 0)); mgr.activateNode(NodeId.newInstance("n3", 1), Resource.newInstance(10, 0, 0)); mgr.activateNode(NodeId.newInstance("n4", 1), Resource.newInstance(10, 0, 0)); mgr.activateNode(NodeId.newInstance("n5", 1), Resource.newInstance(10, 0, 0)); mgr.replaceLabelsOnNode(ImmutableMap.of(toNodeId("n1"), toSet("x"), toNodeId("n2"), toSet("x"), toNodeId("n3"), toSet("y"))); // x, y, z and "" List<NodeLabel> infos = mgr.pullRMNodeLabelsInfo(); Assert.assertEquals(4, infos.size()); checkNodeLabelInfo(infos, RMNodeLabelsManager.NO_LABEL, 2, 20); checkNodeLabelInfo(infos, "x", 2, 20); checkNodeLabelInfo(infos, "y", 1, 10); checkNodeLabelInfo(infos, "z", 0, 0); }
private void checkExclusivityMatch(Collection<NodeLabel> labels) throws IOException { ArrayList<NodeLabel> mismatchlabels = new ArrayList<NodeLabel>(); for (NodeLabel label : labels) { RMNodeLabel rmNodeLabel = this.labelCollections.get(label.getName()); if (rmNodeLabel != null && rmNodeLabel.getIsExclusive() != label.isExclusive()) { mismatchlabels.add(label); } } if (mismatchlabels.size() > 0) { throw new IOException( "Exclusivity cannot be modified for an existing label with : " + StringUtils.join(mismatchlabels.iterator(), ",")); } }
@Test public void testGetClusterNodeLabels() throws Exception { YarnClient client = mock(YarnClient.class); when(client.getClusterNodeLabels()).thenReturn( Arrays.asList(NodeLabel.newInstance("label1"), NodeLabel.newInstance("label2"))); ClusterCLI cli = new ClusterCLI(); cli.setClient(client); cli.setSysOutPrintStream(sysOut); cli.setSysErrPrintStream(sysErr); int rc = cli.run(new String[] { ClusterCLI.CMD, "-" + ClusterCLI.LIST_LABELS_CMD }); assertEquals(0, rc); ByteArrayOutputStream baos = new ByteArrayOutputStream(); PrintWriter pw = new PrintWriter(baos); pw.print("Node Labels: <label1:exclusivity=true>,<label2:exclusivity=true>"); pw.close(); verify(sysOut).println(baos.toString("UTF-8")); }
@Test (timeout = 10000) public void testGetLabelsToNodes() throws YarnException, IOException { Configuration conf = new Configuration(); final YarnClient client = new MockYarnClient(); client.init(conf); client.start(); // Get labels to nodes mapping Map<NodeLabel, Set<NodeId>> expectedLabelsToNodes = ((MockYarnClient)client).getLabelsToNodesMap(); Map<NodeLabel, Set<NodeId>> labelsToNodes = client.getLabelsToNodes(); Assert.assertEquals(labelsToNodes, expectedLabelsToNodes); Assert.assertEquals(labelsToNodes.size(), 3); // Get labels to nodes for selected labels Set<String> setLabels = new HashSet<String>(Arrays.asList("x", "z")); expectedLabelsToNodes = ((MockYarnClient)client).getLabelsToNodesMap(setLabels); labelsToNodes = client.getLabelsToNodes(setLabels); Assert.assertEquals(labelsToNodes, expectedLabelsToNodes); Assert.assertEquals(labelsToNodes.size(), 2); client.stop(); client.close(); }
@Test public void testGetEmptyClusterNodeLabels() throws Exception { YarnClient client = mock(YarnClient.class); when(client.getClusterNodeLabels()).thenReturn(new ArrayList<NodeLabel>()); ClusterCLI cli = new ClusterCLI(); cli.setClient(client); cli.setSysOutPrintStream(sysOut); cli.setSysErrPrintStream(sysErr); int rc = cli.run(new String[] { ClusterCLI.CMD, "-" + ClusterCLI.LIST_LABELS_CMD }); assertEquals(0, rc); ByteArrayOutputStream baos = new ByteArrayOutputStream(); PrintWriter pw = new PrintWriter(baos); pw.print("Node Labels: "); pw.close(); verify(sysOut).println(baos.toString("UTF-8")); }
private void initLabelsToNodes() { if (this.labelsToNodes != null) { return; } GetLabelsToNodesResponseProtoOrBuilder p = viaProto ? proto : builder; List<LabelsToNodeIdsProto> list = p.getLabelsToNodesList(); this.labelsToNodes = new HashMap<NodeLabel, Set<NodeId>>(); for (LabelsToNodeIdsProto c : list) { Set<NodeId> setNodes = new HashSet<NodeId>(); for(NodeIdProto n : c.getNodeIdList()) { NodeId node = new NodeIdPBImpl(n); setNodes.add(node); } if (!setNodes.isEmpty()) { this.labelsToNodes .put(new NodeLabelPBImpl(c.getNodeLabels()), setNodes); } } }
private void initNodeToLabels() { if (this.nodeToLabels != null) { return; } GetNodesToLabelsResponseProtoOrBuilder p = viaProto ? proto : builder; List<NodeIdToLabelsInfoProto> list = p.getNodeToLabelsList(); this.nodeToLabels = new HashMap<NodeId, Set<NodeLabel>>(); for (NodeIdToLabelsInfoProto c : list) { Set<NodeLabel> labels = new HashSet<NodeLabel>(); for (NodeLabelProto l : c.getNodeLabelsList()) { labels.add(new NodeLabelPBImpl(l)); } this.nodeToLabels.put(new NodeIdPBImpl(c.getNodeId()), labels); } }
private void mergeLocalToBuilder() { if (this.nodeStatus != null) { builder.setNodeStatus(convertToProtoFormat(this.nodeStatus)); } if (this.lastKnownContainerTokenMasterKey != null) { builder.setLastKnownContainerTokenMasterKey( convertToProtoFormat(this.lastKnownContainerTokenMasterKey)); } if (this.lastKnownNMTokenMasterKey != null) { builder.setLastKnownNmTokenMasterKey( convertToProtoFormat(this.lastKnownNMTokenMasterKey)); } if (this.labels != null) { builder.clearNodeLabels(); Builder newBuilder = NodeLabelsProto.newBuilder(); for (NodeLabel label : labels) { newBuilder.addNodeLabels(convertToProtoFormat(label)); } builder.setNodeLabels(newBuilder.build()); } if (this.logAggregationReportsForApps != null) { addLogAggregationStatusForAppsToProto(); } }
private void renderCommonLeafQueueInfo(ResponseInfo ri) { ri. _("Num Schedulable Applications:", Integer.toString(lqinfo.getNumActiveApplications())). _("Num Non-Schedulable Applications:", Integer.toString(lqinfo.getNumPendingApplications())). _("Num Containers:", Integer.toString(lqinfo.getNumContainers())). _("Max Applications:", Integer.toString(lqinfo.getMaxApplications())). _("Max Applications Per User:", Integer.toString(lqinfo.getMaxApplicationsPerUser())). _("Max Application Master Resources:", lqinfo.getAMResourceLimit().toString()). _("Used Application Master Resources:", lqinfo.getUsedAMResource().toString()). _("Max Application Master Resources Per User:", lqinfo.getUserAMResourceLimit().toString()). _("Configured Minimum User Limit Percent:", Integer.toString(lqinfo.getUserLimit()) + "%"). _("Configured User Limit Factor:", lqinfo.getUserLimitFactor()). _("Accessible Node Labels:", StringUtils.join(",", lqinfo.getNodeLabels())). _("Ordering Policy: ", lqinfo.getOrderingPolicyInfo()). _("Preemption:", lqinfo.getPreemptionDisabled() ? "disabled" : "enabled"). _("Default Node Label Expression:", lqinfo.getDefaultNodeLabelExpression() == null ? NodeLabel.DEFAULT_NODE_LABEL_PARTITION : lqinfo.getDefaultNodeLabelExpression()). _("Default Application Priority:", Integer.toString(lqinfo.getDefaultApplicationPriority())); }
protected void getPendingAppDiagnosticMessage( StringBuilder diagnosticMessage) { LeafQueue queue = getCSLeafQueue(); diagnosticMessage.append(" Details : AM Partition = "); diagnosticMessage.append(appAMNodePartitionName.isEmpty() ? NodeLabel.DEFAULT_NODE_LABEL_PARTITION : appAMNodePartitionName); diagnosticMessage.append("; "); diagnosticMessage.append("AM Resource Request = "); diagnosticMessage.append(getAMResource(appAMNodePartitionName)); diagnosticMessage.append("; "); diagnosticMessage.append("Queue Resource Limit for AM = "); diagnosticMessage .append(queue.getAMResourceLimitPerPartition(appAMNodePartitionName)); diagnosticMessage.append("; "); diagnosticMessage.append("User AM Resource Limit of the queue = "); diagnosticMessage.append( queue.getUserAMResourceLimitPerPartition(appAMNodePartitionName)); diagnosticMessage.append("; "); diagnosticMessage.append("Queue AM Resource Usage = "); diagnosticMessage.append( queue.getQueueResourceUsage().getAMUsed(appAMNodePartitionName)); diagnosticMessage.append("; "); }
protected void getActivedAppDiagnosticMessage( StringBuilder diagnosticMessage) { LeafQueue queue = getCSLeafQueue(); QueueCapacities queueCapacities = queue.getQueueCapacities(); diagnosticMessage.append(" Details : AM Partition = "); diagnosticMessage.append(appAMNodePartitionName.isEmpty() ? NodeLabel.DEFAULT_NODE_LABEL_PARTITION : appAMNodePartitionName); diagnosticMessage.append(" ; "); diagnosticMessage.append("Partition Resource = "); diagnosticMessage.append(rmContext.getNodeLabelManager() .getResourceByLabel(appAMNodePartitionName, Resources.none())); diagnosticMessage.append(" ; "); diagnosticMessage.append("Queue's Absolute capacity = "); diagnosticMessage.append( queueCapacities.getAbsoluteCapacity(appAMNodePartitionName) * 100); diagnosticMessage.append(" % ; "); diagnosticMessage.append("Queue's Absolute used capacity = "); diagnosticMessage.append( queueCapacities.getAbsoluteUsedCapacity(appAMNodePartitionName) * 100); diagnosticMessage.append(" % ; "); diagnosticMessage.append("Queue's Absolute max capacity = "); diagnosticMessage.append( queueCapacities.getAbsoluteMaximumCapacity(appAMNodePartitionName) * 100); diagnosticMessage.append(" % ; "); }
private void checkNodeLabelInfo(List<NodeLabel> infos, String labelName, int activeNMs, int memory) { for (NodeLabel info : infos) { if (info.getLabelName().equals(labelName)) { Assert.assertEquals(activeNMs, info.getNumActiveNMs()); Assert.assertEquals(memory, info.getResource().getMemory()); return; } } Assert.fail("Failed to find info has label=" + labelName); }
protected RMNodeLabel(String labelName, Resource res, int activeNMs, boolean exclusive) { this.labelName = labelName; this.resource = res; this.numActiveNMs = activeNMs; this.nodeIds = new HashSet<NodeId>(); this.exclusive = exclusive; this.nodeLabel = NodeLabel.newInstance(labelName, exclusive); }
/** * Add multiple node labels to repository * * @param labels * new node labels added */ @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); }
/** * Get mapping of labels to nodes for all the labels. * * @return labels to nodes map */ public Map<NodeLabel, Set<NodeId>> getLabelsInfoToNodes() { try { readLock.lock(); return getLabelsInfoToNodes(labelCollections.keySet()); } finally { readLock.unlock(); } }
public List<NodeLabel> getClusterNodeLabels() { try { readLock.lock(); List<NodeLabel> nodeLabels = new ArrayList<>(); for (RMNodeLabel label : labelCollections.values()) { if (!label.getLabelName().equals(NO_LABEL)) { nodeLabels.add(NodeLabel.newInstance(label.getLabelName(), label.getIsExclusive())); } } return nodeLabels; } finally { readLock.unlock(); } }
public Set<NodeLabel> getLabelsInfoByNode(NodeId nodeId) { try { readLock.lock(); Set<String> labels = getLabelsByNode(nodeId, nodeCollections); if (labels.isEmpty()) { return EMPTY_NODELABEL_SET; } Set<NodeLabel> nodeLabels = createNodeLabelFromLabelNames(labels); return nodeLabels; } finally { readLock.unlock(); } }
private Set<NodeLabel> createNodeLabelFromLabelNames(Set<String> labels) { Set<NodeLabel> nodeLabels = new HashSet<NodeLabel>(); for (String label : labels) { if (label.equals(NO_LABEL)) { continue; } RMNodeLabel rmLabel = labelCollections.get(label); if (rmLabel == null) { continue; } nodeLabels.add(rmLabel.getNodeLabel()); } return nodeLabels; }
@Override public void storeNewClusterNodeLabels(List<NodeLabel> labels) throws IOException { try { ensureAppendEditlogFile(); editlogOs.writeInt(SerializedLogType.ADD_LABELS.ordinal()); ((AddToClusterNodeLabelsRequestPBImpl) AddToClusterNodeLabelsRequest .newInstance(labels)).getProto().writeDelimitedTo(editlogOs); } finally { ensureCloseEditlogFile(); } }
public static GetNodesToLabelsResponse newInstance( Map<NodeId, Set<NodeLabel>> map) { GetNodesToLabelsResponse response = Records.newRecord(GetNodesToLabelsResponse.class); response.setNodeToLabels(map); return response; }
@Override public void initNodeLabelStore(Configuration conf) { this.store = new NodeLabelsStore() { @Override public void recover() throws IOException { // do nothing } @Override public void removeClusterNodeLabels(Collection<String> labels) throws IOException { // do nothing } @Override public void updateNodeToLabelsMappings( Map<NodeId, Set<String>> nodeToLabels) throws IOException { // do nothing } @Override public void storeNewClusterNodeLabels(List<NodeLabel> label) throws IOException { // do nothing } @Override public void close() throws IOException { // do nothing } }; }
@Override public List<NodeLabel> getNodeLabels() { if (this.updatedNodeLabels != null) { return this.updatedNodeLabels; } initLocalNodeLabels(); return this.updatedNodeLabels; }
public static GetLabelsToNodesResponse newInstance( Map<NodeLabel, Set<NodeId>> map) { GetLabelsToNodesResponse response = Records.newRecord(GetLabelsToNodesResponse.class); response.setLabelsToNodes(map); return response; }
@Override @Public @Evolving public void setLabelsToNodes(Map<NodeLabel, Set<NodeId>> map) { initLabelsToNodes(); labelsToNodes.clear(); labelsToNodes.putAll(map); }
@Override @Public @Evolving public Map<NodeLabel, Set<NodeId>> getLabelsToNodes() { initLabelsToNodes(); return this.labelsToNodes; }
@Override public void setNodeLabels(List<NodeLabel> updatedNodeLabels) { maybeInitBuilder(); this.updatedNodeLabels = new ArrayList<>(); if (updatedNodeLabels == null) { builder.clearNodeLabels(); return; } this.updatedNodeLabels.addAll(updatedNodeLabels); }
private void initLocalNodeLabels() { AddToClusterNodeLabelsRequestProtoOrBuilder p = viaProto ? proto : builder; List<NodeLabelProto> attributesProtoList = p.getNodeLabelsList(); this.updatedNodeLabels = new ArrayList<NodeLabel>(); for (NodeLabelProto r : attributesProtoList) { this.updatedNodeLabels.add(convertFromProtoFormat(r)); } }
public static void assertLabelInfoMapEquals( Map<NodeId, Set<NodeLabel>> expected, ImmutableMap<NodeId, Set<NodeLabel>> actual) { Assert.assertEquals(expected.size(), actual.size()); for (NodeId k : expected.keySet()) { Assert.assertTrue(actual.containsKey(k)); assertNLCollectionEquals(expected.get(k), actual.get(k)); } }
public static void assertNLCollectionEquals(Collection<NodeLabel> expected, Collection<NodeLabel> actual) { if (expected == null) { Assert.assertNull(actual); } else { Assert.assertNotNull(actual); } Set<NodeLabel> expectedSet = new HashSet<>(expected); Set<NodeLabel> actualSet = new HashSet<>(actual); Assert.assertEquals(expectedSet, actualSet); Assert.assertTrue(expectedSet.containsAll(actualSet)); }
public static Set<NodeLabel> toNodeLabelSet(String... nodeLabelsStr) { if (null == nodeLabelsStr) { return null; } Set<NodeLabel> labels = new HashSet<>(); for (String label : nodeLabelsStr) { labels.add(NodeLabel.newInstance(label)); } return labels; }
void printClusterNodeLabels() throws YarnException, IOException { List<NodeLabel> nodeLabels = null; if (accessLocal) { nodeLabels = new ArrayList<>(getNodeLabelManagerInstance(getConf()).getClusterNodeLabels()); } else { nodeLabels = new ArrayList<>(client.getClusterNodeLabels()); } sysout.println(String.format("Node Labels: %s", StringUtils.join(nodeLabels.iterator(), ","))); }
@Test(timeout = 5000) public void testAddlabelWithExclusivity() throws Exception { // Add some label, case will not ignore here mgr.addToCluserNodeLabels(Arrays.asList(NodeLabel.newInstance("a", false), NodeLabel.newInstance("b", true))); Assert.assertFalse(mgr.isExclusiveNodeLabel("a")); Assert.assertTrue(mgr.isExclusiveNodeLabel("b")); }
private void verifyNodeLabelAdded(Set<String> expectedAddedLabelNames, Collection<NodeLabel> addedNodeLabels) { Assert.assertEquals(expectedAddedLabelNames.size(), addedNodeLabels.size()); for (NodeLabel label : addedNodeLabels) { Assert.assertTrue(expectedAddedLabelNames.contains(label.getName())); } }
@Test(timeout = 5000) public void testGetNodeLabelsInfo() throws IOException { mgr.addToCluserNodeLabels(Arrays.asList(NodeLabel.newInstance("p1", false), NodeLabel.newInstance("p2", true), NodeLabel.newInstance("p3", false))); mgr.addLabelsToNode(ImmutableMap.of(toNodeId("n1"), toSet("p2"))); mgr.addLabelsToNode(ImmutableMap.of(toNodeId("n2"), toSet("p3"))); assertLabelInfoMapEquals(mgr.getNodeLabelsInfo(), ImmutableMap.of( toNodeId("n1"), toSet(NodeLabel.newInstance("p2", true)), toNodeId("n2"), toSet(NodeLabel.newInstance("p3", false)))); }
@Test public void testGetClusterNodeLabelsWithLocalAccess() throws Exception { YarnClient client = mock(YarnClient.class); when(client.getClusterNodeLabels()).thenReturn( Arrays.asList(NodeLabel.newInstance("remote1"), NodeLabel.newInstance("remote2"))); ClusterCLI cli = new ClusterCLI(); cli.setClient(client); cli.setSysOutPrintStream(sysOut); cli.setSysErrPrintStream(sysErr); ClusterCLI.localNodeLabelsManager = mock(CommonNodeLabelsManager.class); when(ClusterCLI.localNodeLabelsManager.getClusterNodeLabels()).thenReturn( Arrays.asList(NodeLabel.newInstance("local1"), NodeLabel.newInstance("local2"))); int rc = cli.run(new String[] { ClusterCLI.CMD, "-" + ClusterCLI.LIST_LABELS_CMD, "-" + ClusterCLI.DIRECTLY_ACCESS_NODE_LABEL_STORE }); assertEquals(0, rc); ByteArrayOutputStream baos = new ByteArrayOutputStream(); PrintWriter pw = new PrintWriter(baos); // it should return local* instead of remote* pw.print("Node Labels: <local1:exclusivity=true>,<local2:exclusivity=true>"); pw.close(); verify(sysOut).println(baos.toString("UTF-8")); }
public static NodeHeartbeatRequest newInstance(NodeStatus nodeStatus, MasterKey lastKnownContainerTokenMasterKey, MasterKey lastKnownNMTokenMasterKey, Set<NodeLabel> nodeLabels) { NodeHeartbeatRequest nodeHeartbeatRequest = Records.newRecord(NodeHeartbeatRequest.class); nodeHeartbeatRequest.setNodeStatus(nodeStatus); nodeHeartbeatRequest .setLastKnownContainerTokenMasterKey(lastKnownContainerTokenMasterKey); nodeHeartbeatRequest .setLastKnownNMTokenMasterKey(lastKnownNMTokenMasterKey); nodeHeartbeatRequest.setNodeLabels(nodeLabels); return nodeHeartbeatRequest; }
public static RegisterNodeManagerRequest newInstance(NodeId nodeId, int httpPort, Resource resource, String nodeManagerVersionId, List<NMContainerStatus> containerStatuses, List<ApplicationId> runningApplications, Set<NodeLabel> nodeLabels) { RegisterNodeManagerRequest request = Records.newRecord(RegisterNodeManagerRequest.class); request.setHttpPort(httpPort); request.setResource(resource); request.setNodeId(nodeId); request.setNMVersion(nodeManagerVersionId); request.setContainerStatuses(containerStatuses); request.setRunningApplications(runningApplications); request.setNodeLabels(nodeLabels); return request; }
@Override public Map<NodeLabel, Set<NodeId>> getLabelsToNodes(Set<String> labels) throws YarnException, IOException { when(mockLabelsToNodesResponse.getLabelsToNodes()).thenReturn( getLabelsToNodesMap(labels)); return super.getLabelsToNodes(labels); }
private void initNodeLabels() { if (this.labels != null) { return; } NodeHeartbeatRequestProtoOrBuilder p = viaProto ? proto : builder; if (!p.hasNodeLabels()) { labels = null; return; } NodeLabelsProto nodeLabels = p.getNodeLabels(); labels = new HashSet<NodeLabel>(); for(NodeLabelProto nlp : nodeLabels.getNodeLabelsList()) { labels.add(convertFromProtoFormat(nlp)); } }