YARN-6143. Fix incompatible issue caused by YARN-3583. (Sunil G via wangda)

This commit is contained in:
Wangda Tan 2017-02-22 11:17:09 -08:00
parent cfcd527323
commit 1a6ca75f38
18 changed files with 135 additions and 166 deletions

View File

@ -476,19 +476,19 @@ public class ResourceMgrDelegate extends YarnClient {
return client.listReservations(request); return client.listReservations(request);
} }
@Override @Override
public Map<NodeId, Set<NodeLabel>> getNodeToLabels() throws YarnException, public Map<NodeId, Set<String>> getNodeToLabels() throws YarnException,
IOException { IOException {
return client.getNodeToLabels(); return client.getNodeToLabels();
} }
@Override @Override
public Map<NodeLabel, Set<NodeId>> getLabelsToNodes() throws YarnException, public Map<String, Set<NodeId>> getLabelsToNodes() throws YarnException,
IOException { IOException {
return client.getLabelsToNodes(); return client.getLabelsToNodes();
} }
@Override @Override
public Map<NodeLabel, Set<NodeId>> getLabelsToNodes(Set<String> labels) public Map<String, Set<NodeId>> getLabelsToNodes(Set<String> labels)
throws YarnException, IOException { throws YarnException, IOException {
return client.getLabelsToNodes(labels); return client.getLabelsToNodes(labels);
} }

View File

@ -29,7 +29,7 @@ import org.apache.hadoop.yarn.util.Records;
public abstract class GetLabelsToNodesResponse { public abstract class GetLabelsToNodesResponse {
public static GetLabelsToNodesResponse newInstance( public static GetLabelsToNodesResponse newInstance(
Map<NodeLabel, Set<NodeId>> map) { Map<String, Set<NodeId>> map) {
GetLabelsToNodesResponse response = GetLabelsToNodesResponse response =
Records.newRecord(GetLabelsToNodesResponse.class); Records.newRecord(GetLabelsToNodesResponse.class);
response.setLabelsToNodes(map); response.setLabelsToNodes(map);
@ -38,9 +38,9 @@ public abstract class GetLabelsToNodesResponse {
@Public @Public
@Evolving @Evolving
public abstract void setLabelsToNodes(Map<NodeLabel, Set<NodeId>> map); public abstract void setLabelsToNodes(Map<String, Set<NodeId>> map);
@Public @Public
@Evolving @Evolving
public abstract Map<NodeLabel, Set<NodeId>> getLabelsToNodes(); public abstract Map<String, Set<NodeId>> getLabelsToNodes();
} }

View File

@ -24,12 +24,11 @@ import java.util.Set;
import org.apache.hadoop.classification.InterfaceAudience.Public; import org.apache.hadoop.classification.InterfaceAudience.Public;
import org.apache.hadoop.classification.InterfaceStability.Evolving; import org.apache.hadoop.classification.InterfaceStability.Evolving;
import org.apache.hadoop.yarn.api.records.NodeId; import org.apache.hadoop.yarn.api.records.NodeId;
import org.apache.hadoop.yarn.api.records.NodeLabel;
import org.apache.hadoop.yarn.util.Records; import org.apache.hadoop.yarn.util.Records;
public abstract class GetNodesToLabelsResponse { public abstract class GetNodesToLabelsResponse {
public static GetNodesToLabelsResponse newInstance( public static GetNodesToLabelsResponse newInstance(
Map<NodeId, Set<NodeLabel>> map) { Map<NodeId, Set<String>> map) {
GetNodesToLabelsResponse response = GetNodesToLabelsResponse response =
Records.newRecord(GetNodesToLabelsResponse.class); Records.newRecord(GetNodesToLabelsResponse.class);
response.setNodeToLabels(map); response.setNodeToLabels(map);
@ -38,9 +37,9 @@ public abstract class GetNodesToLabelsResponse {
@Public @Public
@Evolving @Evolving
public abstract void setNodeToLabels(Map<NodeId, Set<NodeLabel>> map); public abstract void setNodeToLabels(Map<NodeId, Set<String>> map);
@Public @Public
@Evolving @Evolving
public abstract Map<NodeId, Set<NodeLabel>> getNodeToLabels(); public abstract Map<NodeId, Set<String>> getNodeToLabels();
} }

View File

@ -30,17 +30,16 @@ import org.apache.hadoop.yarn.util.Records;
public abstract class AddToClusterNodeLabelsRequest { public abstract class AddToClusterNodeLabelsRequest {
@Public @Public
@Unstable @Unstable
public static AddToClusterNodeLabelsRequest newInstance( public static AddToClusterNodeLabelsRequest newInstance(List<NodeLabel> nodeLabels) {
List<NodeLabel> NodeLabels) { AddToClusterNodeLabelsRequest request = Records
AddToClusterNodeLabelsRequest request = .newRecord(AddToClusterNodeLabelsRequest.class);
Records.newRecord(AddToClusterNodeLabelsRequest.class); request.setNodeLabels(nodeLabels);
request.setNodeLabels(NodeLabels);
return request; return request;
} }
@Public @Public
@Unstable @Unstable
public abstract void setNodeLabels(List<NodeLabel> NodeLabels); public abstract void setNodeLabels(List<NodeLabel> nodeLabels);
@Public @Public
@Unstable @Unstable

View File

@ -84,7 +84,8 @@ message RefreshNodesResourcesResponseProto {
} }
message AddToClusterNodeLabelsRequestProto { message AddToClusterNodeLabelsRequestProto {
repeated NodeLabelProto nodeLabels = 1; repeated string deprecatedNodeLabels = 1;
repeated NodeLabelProto nodeLabels = 2;
} }
message AddToClusterNodeLabelsResponseProto { message AddToClusterNodeLabelsResponseProto {
@ -98,7 +99,7 @@ message RemoveFromClusterNodeLabelsResponseProto {
} }
message ReplaceLabelsOnNodeRequestProto { message ReplaceLabelsOnNodeRequestProto {
repeated NodeIdToLabelsNameProto nodeToLabels = 1; repeated NodeIdToLabelsProto nodeToLabels = 1;
optional bool failOnUnknownNodes = 2; optional bool failOnUnknownNodes = 2;
} }

View File

@ -282,13 +282,13 @@ message NodeReportProto {
optional ResourceUtilizationProto node_utilization = 12; optional ResourceUtilizationProto node_utilization = 12;
} }
message NodeIdToLabelsInfoProto { message NodeIdToLabelsProto {
optional NodeIdProto nodeId = 1; optional NodeIdProto nodeId = 1;
repeated NodeLabelProto nodeLabels = 2; repeated string nodeLabels = 2;
} }
message LabelsToNodeIdsProto { message LabelsToNodeIdsProto {
optional NodeLabelProto nodeLabels = 1; optional string nodeLabels = 1;
repeated NodeIdProto nodeId = 2; repeated NodeIdProto nodeId = 2;
} }

View File

@ -234,7 +234,7 @@ message GetNodesToLabelsRequestProto {
} }
message GetNodesToLabelsResponseProto { message GetNodesToLabelsResponseProto {
repeated NodeIdToLabelsInfoProto nodeToLabels = 1; repeated NodeIdToLabelsProto nodeToLabels = 1;
} }
message GetLabelsToNodesRequestProto { message GetLabelsToNodesRequestProto {
@ -249,7 +249,8 @@ message GetClusterNodeLabelsRequestProto {
} }
message GetClusterNodeLabelsResponseProto { message GetClusterNodeLabelsResponseProto {
repeated NodeLabelProto nodeLabels = 1; repeated string deprecatedNodeLabels = 1;
repeated NodeLabelProto nodeLabels = 2;
} }
message UpdateApplicationPriorityRequestProto { message UpdateApplicationPriorityRequestProto {

View File

@ -767,7 +767,7 @@ public abstract class YarnClient extends AbstractService {
*/ */
@Public @Public
@Unstable @Unstable
public abstract Map<NodeId, Set<NodeLabel>> getNodeToLabels() public abstract Map<NodeId, Set<String>> getNodeToLabels()
throws YarnException, IOException; throws YarnException, IOException;
/** /**
@ -782,7 +782,7 @@ public abstract class YarnClient extends AbstractService {
*/ */
@Public @Public
@Unstable @Unstable
public abstract Map<NodeLabel, Set<NodeId>> getLabelsToNodes() public abstract Map<String, Set<NodeId>> getLabelsToNodes()
throws YarnException, IOException; throws YarnException, IOException;
/** /**
@ -798,7 +798,7 @@ public abstract class YarnClient extends AbstractService {
*/ */
@Public @Public
@Unstable @Unstable
public abstract Map<NodeLabel, Set<NodeId>> getLabelsToNodes( public abstract Map<String, Set<NodeId>> getLabelsToNodes(
Set<String> labels) throws YarnException, IOException; Set<String> labels) throws YarnException, IOException;
/** /**

View File

@ -883,21 +883,21 @@ public class YarnClientImpl extends YarnClient {
} }
@Override @Override
public Map<NodeId, Set<NodeLabel>> getNodeToLabels() throws YarnException, public Map<NodeId, Set<String>> getNodeToLabels() throws YarnException,
IOException { IOException {
return rmClient.getNodeToLabels(GetNodesToLabelsRequest.newInstance()) return rmClient.getNodeToLabels(GetNodesToLabelsRequest.newInstance())
.getNodeToLabels(); .getNodeToLabels();
} }
@Override @Override
public Map<NodeLabel, Set<NodeId>> getLabelsToNodes() throws YarnException, public Map<String, Set<NodeId>> getLabelsToNodes() throws YarnException,
IOException { IOException {
return rmClient.getLabelsToNodes(GetLabelsToNodesRequest.newInstance()) return rmClient.getLabelsToNodes(GetLabelsToNodesRequest.newInstance())
.getLabelsToNodes(); .getLabelsToNodes();
} }
@Override @Override
public Map<NodeLabel, Set<NodeId>> getLabelsToNodes(Set<String> labels) public Map<String, Set<NodeId>> getLabelsToNodes(Set<String> labels)
throws YarnException, IOException { throws YarnException, IOException {
return rmClient.getLabelsToNodes( return rmClient.getLabelsToNodes(
GetLabelsToNodesRequest.newInstance(labels)).getLabelsToNodes(); GetLabelsToNodesRequest.newInstance(labels)).getLabelsToNodes();

View File

@ -609,9 +609,9 @@ public class TestYarnClient {
client.start(); client.start();
// Get labels to nodes mapping // Get labels to nodes mapping
Map<NodeLabel, Set<NodeId>> expectedLabelsToNodes = Map<String, Set<NodeId>> expectedLabelsToNodes =
((MockYarnClient)client).getLabelsToNodesMap(); ((MockYarnClient)client).getLabelsToNodesMap();
Map<NodeLabel, Set<NodeId>> labelsToNodes = client.getLabelsToNodes(); Map<String, Set<NodeId>> labelsToNodes = client.getLabelsToNodes();
Assert.assertEquals(labelsToNodes, expectedLabelsToNodes); Assert.assertEquals(labelsToNodes, expectedLabelsToNodes);
Assert.assertEquals(labelsToNodes.size(), 3); Assert.assertEquals(labelsToNodes.size(), 3);
@ -635,18 +635,12 @@ public class TestYarnClient {
client.start(); client.start();
// Get labels to nodes mapping // Get labels to nodes mapping
Map<NodeId, Set<NodeLabel>> expectedNodesToLabels = ((MockYarnClient) client) Map<NodeId, Set<String>> expectedNodesToLabels = ((MockYarnClient) client)
.getNodeToLabelsMap(); .getNodeToLabelsMap();
Map<NodeId, Set<NodeLabel>> nodesToLabels = client.getNodeToLabels(); Map<NodeId, Set<String>> nodesToLabels = client.getNodeToLabels();
Assert.assertEquals(nodesToLabels, expectedNodesToLabels); Assert.assertEquals(nodesToLabels, expectedNodesToLabels);
Assert.assertEquals(nodesToLabels.size(), 1); Assert.assertEquals(nodesToLabels.size(), 1);
// Verify exclusivity
Set<NodeLabel> labels = nodesToLabels.get(NodeId.newInstance("host", 0));
for (NodeLabel label : labels) {
Assert.assertFalse(label.isExclusive());
}
client.stop(); client.stop();
client.close(); client.close();
} }
@ -884,7 +878,7 @@ public class TestYarnClient {
} }
@Override @Override
public Map<NodeLabel, Set<NodeId>> getLabelsToNodes() public Map<String, Set<NodeId>> getLabelsToNodes()
throws YarnException, IOException { throws YarnException, IOException {
when(mockLabelsToNodesResponse.getLabelsToNodes()).thenReturn( when(mockLabelsToNodesResponse.getLabelsToNodes()).thenReturn(
getLabelsToNodesMap()); getLabelsToNodesMap());
@ -892,48 +886,45 @@ public class TestYarnClient {
} }
@Override @Override
public Map<NodeLabel, Set<NodeId>> getLabelsToNodes(Set<String> labels) public Map<String, Set<NodeId>> getLabelsToNodes(Set<String> labels)
throws YarnException, IOException { throws YarnException, IOException {
when(mockLabelsToNodesResponse.getLabelsToNodes()).thenReturn( when(mockLabelsToNodesResponse.getLabelsToNodes()).thenReturn(
getLabelsToNodesMap(labels)); getLabelsToNodesMap(labels));
return super.getLabelsToNodes(labels); return super.getLabelsToNodes(labels);
} }
public Map<NodeLabel, Set<NodeId>> getLabelsToNodesMap() { public Map<String, Set<NodeId>> getLabelsToNodesMap() {
Map<NodeLabel, Set<NodeId>> map = new HashMap<NodeLabel, Set<NodeId>>(); Map<String, Set<NodeId>> map = new HashMap<String, Set<NodeId>>();
Set<NodeId> setNodeIds = Set<NodeId> setNodeIds =
new HashSet<NodeId>(Arrays.asList( new HashSet<NodeId>(Arrays.asList(
NodeId.newInstance("host1", 0), NodeId.newInstance("host2", 0))); NodeId.newInstance("host1", 0), NodeId.newInstance("host2", 0)));
map.put(NodeLabel.newInstance("x"), setNodeIds); map.put("x", setNodeIds);
map.put(NodeLabel.newInstance("y"), setNodeIds); map.put("y", setNodeIds);
map.put(NodeLabel.newInstance("z"), setNodeIds); map.put("z", setNodeIds);
return map; return map;
} }
public Map<NodeLabel, Set<NodeId>> getLabelsToNodesMap(Set<String> labels) { public Map<String, Set<NodeId>> getLabelsToNodesMap(Set<String> labels) {
Map<NodeLabel, Set<NodeId>> map = new HashMap<NodeLabel, Set<NodeId>>(); Map<String, Set<NodeId>> map = new HashMap<String, Set<NodeId>>();
Set<NodeId> setNodeIds = Set<NodeId> setNodeIds = new HashSet<NodeId>(Arrays.asList(
new HashSet<NodeId>(Arrays.asList(
NodeId.newInstance("host1", 0), NodeId.newInstance("host2", 0))); NodeId.newInstance("host1", 0), NodeId.newInstance("host2", 0)));
for(String label : labels) { for (String label : labels) {
map.put(NodeLabel.newInstance(label), setNodeIds); map.put(label, setNodeIds);
} }
return map; return map;
} }
@Override @Override
public Map<NodeId, Set<NodeLabel>> getNodeToLabels() throws YarnException, public Map<NodeId, Set<String>> getNodeToLabels() throws YarnException,
IOException { IOException {
when(mockNodeToLabelsResponse.getNodeToLabels()).thenReturn( when(mockNodeToLabelsResponse.getNodeToLabels()).thenReturn(
getNodeToLabelsMap()); getNodeToLabelsMap());
return super.getNodeToLabels(); return super.getNodeToLabels();
} }
public Map<NodeId, Set<NodeLabel>> getNodeToLabelsMap() { public Map<NodeId, Set<String>> getNodeToLabelsMap() {
Map<NodeId, Set<NodeLabel>> map = new HashMap<NodeId, Set<NodeLabel>>(); Map<NodeId, Set<String>> map = new HashMap<NodeId, Set<String>>();
Set<NodeLabel> setNodeLabels = new HashSet<NodeLabel>(Arrays.asList( Set<String> setNodeLabels = new HashSet<String>(Arrays.asList("x", "y"));
NodeLabel.newInstance("x", false),
NodeLabel.newInstance("y", false)));
map.put(NodeId.newInstance("host", 0), setNodeLabels); map.put(NodeId.newInstance("host", 0), setNodeLabels);
return map; return map;
} }

View File

@ -72,11 +72,15 @@ public class GetClusterNodeLabelsResponsePBImpl extends
private void addNodeLabelsToProto() { private void addNodeLabelsToProto() {
maybeInitBuilder(); maybeInitBuilder();
builder.clearNodeLabels(); builder.clearNodeLabels();
builder.clearDeprecatedNodeLabels();
List<NodeLabelProto> protoList = new ArrayList<NodeLabelProto>(); List<NodeLabelProto> protoList = new ArrayList<NodeLabelProto>();
List<String> protoListString = new ArrayList<String>();
for (NodeLabel r : this.updatedNodeLabels) { for (NodeLabel r : this.updatedNodeLabels) {
protoList.add(convertToProtoFormat(r)); protoList.add(convertToProtoFormat(r));
protoListString.add(r.getName());
} }
builder.addAllNodeLabels(protoList); builder.addAllNodeLabels(protoList);
builder.addAllDeprecatedNodeLabels(protoListString);
} }
@Override @Override

View File

@ -46,7 +46,7 @@ public class GetLabelsToNodesResponsePBImpl extends
GetLabelsToNodesResponseProto.Builder builder = null; GetLabelsToNodesResponseProto.Builder builder = null;
boolean viaProto = false; boolean viaProto = false;
private Map<NodeLabel, Set<NodeId>> labelsToNodes; private Map<String, Set<NodeId>> labelsToNodes;
public GetLabelsToNodesResponsePBImpl() { public GetLabelsToNodesResponsePBImpl() {
this.builder = GetLabelsToNodesResponseProto.newBuilder(); this.builder = GetLabelsToNodesResponseProto.newBuilder();
@ -63,7 +63,7 @@ public class GetLabelsToNodesResponsePBImpl extends
} }
GetLabelsToNodesResponseProtoOrBuilder p = viaProto ? proto : builder; GetLabelsToNodesResponseProtoOrBuilder p = viaProto ? proto : builder;
List<LabelsToNodeIdsProto> list = p.getLabelsToNodesList(); List<LabelsToNodeIdsProto> list = p.getLabelsToNodesList();
this.labelsToNodes = new HashMap<NodeLabel, Set<NodeId>>(); this.labelsToNodes = new HashMap<String, Set<NodeId>>();
for (LabelsToNodeIdsProto c : list) { for (LabelsToNodeIdsProto c : list) {
Set<NodeId> setNodes = new HashSet<NodeId>(); Set<NodeId> setNodes = new HashSet<NodeId>();
@ -73,7 +73,7 @@ public class GetLabelsToNodesResponsePBImpl extends
} }
if (!setNodes.isEmpty()) { if (!setNodes.isEmpty()) {
this.labelsToNodes this.labelsToNodes
.put(new NodeLabelPBImpl(c.getNodeLabels()), setNodes); .put(c.getNodeLabels(), setNodes);
} }
} }
} }
@ -97,7 +97,7 @@ public class GetLabelsToNodesResponsePBImpl extends
public Iterator<LabelsToNodeIdsProto> iterator() { public Iterator<LabelsToNodeIdsProto> iterator() {
return new Iterator<LabelsToNodeIdsProto>() { return new Iterator<LabelsToNodeIdsProto>() {
Iterator<Entry<NodeLabel, Set<NodeId>>> iter = Iterator<Entry<String, Set<NodeId>>> iter =
labelsToNodes.entrySet().iterator(); labelsToNodes.entrySet().iterator();
@Override @Override
@ -107,13 +107,13 @@ public class GetLabelsToNodesResponsePBImpl extends
@Override @Override
public LabelsToNodeIdsProto next() { public LabelsToNodeIdsProto next() {
Entry<NodeLabel, Set<NodeId>> now = iter.next(); Entry<String, Set<NodeId>> now = iter.next();
Set<NodeIdProto> nodeProtoSet = new HashSet<NodeIdProto>(); Set<NodeIdProto> nodeProtoSet = new HashSet<NodeIdProto>();
for(NodeId n : now.getValue()) { for(NodeId n : now.getValue()) {
nodeProtoSet.add(convertToProtoFormat(n)); nodeProtoSet.add(convertToProtoFormat(n));
} }
return LabelsToNodeIdsProto.newBuilder() return LabelsToNodeIdsProto.newBuilder()
.setNodeLabels(convertToProtoFormat(now.getKey())) .setNodeLabels(now.getKey())
.addAllNodeId(nodeProtoSet) .addAllNodeId(nodeProtoSet)
.build(); .build();
} }
@ -153,10 +153,6 @@ public class GetLabelsToNodesResponsePBImpl extends
return ((NodeIdPBImpl)t).getProto(); return ((NodeIdPBImpl)t).getProto();
} }
private NodeLabelProto convertToProtoFormat(NodeLabel l) {
return ((NodeLabelPBImpl)l).getProto();
}
@Override @Override
public int hashCode() { public int hashCode() {
assert false : "hashCode not designed"; assert false : "hashCode not designed";
@ -176,7 +172,7 @@ public class GetLabelsToNodesResponsePBImpl extends
@Override @Override
@Public @Public
@Evolving @Evolving
public void setLabelsToNodes(Map<NodeLabel, Set<NodeId>> map) { public void setLabelsToNodes(Map<String, Set<NodeId>> map) {
initLabelsToNodes(); initLabelsToNodes();
labelsToNodes.clear(); labelsToNodes.clear();
labelsToNodes.putAll(map); labelsToNodes.putAll(map);
@ -185,7 +181,7 @@ public class GetLabelsToNodesResponsePBImpl extends
@Override @Override
@Public @Public
@Evolving @Evolving
public Map<NodeLabel, Set<NodeId>> getLabelsToNodes() { public Map<String, Set<NodeId>> getLabelsToNodes() {
initLabelsToNodes(); initLabelsToNodes();
return this.labelsToNodes; return this.labelsToNodes;
} }

View File

@ -32,11 +32,13 @@ import org.apache.hadoop.yarn.api.records.impl.pb.NodeIdPBImpl;
import org.apache.hadoop.yarn.api.records.impl.pb.NodeLabelPBImpl; import org.apache.hadoop.yarn.api.records.impl.pb.NodeLabelPBImpl;
import org.apache.hadoop.yarn.proto.YarnProtos.NodeIdProto; import org.apache.hadoop.yarn.proto.YarnProtos.NodeIdProto;
import org.apache.hadoop.yarn.api.protocolrecords.GetNodesToLabelsResponse; import org.apache.hadoop.yarn.api.protocolrecords.GetNodesToLabelsResponse;
import org.apache.hadoop.yarn.proto.YarnProtos.NodeIdToLabelsInfoProto; import org.apache.hadoop.yarn.proto.YarnProtos.NodeIdToLabelsProto;
import org.apache.hadoop.yarn.proto.YarnProtos.NodeLabelProto; import org.apache.hadoop.yarn.proto.YarnProtos.NodeLabelProto;
import org.apache.hadoop.yarn.proto.YarnServiceProtos.GetNodesToLabelsResponseProto; import org.apache.hadoop.yarn.proto.YarnServiceProtos.GetNodesToLabelsResponseProto;
import org.apache.hadoop.yarn.proto.YarnServiceProtos.GetNodesToLabelsResponseProtoOrBuilder; import org.apache.hadoop.yarn.proto.YarnServiceProtos.GetNodesToLabelsResponseProtoOrBuilder;
import com.google.common.collect.Sets;
public class GetNodesToLabelsResponsePBImpl extends public class GetNodesToLabelsResponsePBImpl extends
GetNodesToLabelsResponse { GetNodesToLabelsResponse {
GetNodesToLabelsResponseProto proto = GetNodesToLabelsResponseProto GetNodesToLabelsResponseProto proto = GetNodesToLabelsResponseProto
@ -44,7 +46,7 @@ public class GetNodesToLabelsResponsePBImpl extends
GetNodesToLabelsResponseProto.Builder builder = null; GetNodesToLabelsResponseProto.Builder builder = null;
boolean viaProto = false; boolean viaProto = false;
private Map<NodeId, Set<NodeLabel>> nodeToLabels; private Map<NodeId, Set<String>> nodeToLabels;
public GetNodesToLabelsResponsePBImpl() { public GetNodesToLabelsResponsePBImpl() {
this.builder = GetNodesToLabelsResponseProto.newBuilder(); this.builder = GetNodesToLabelsResponseProto.newBuilder();
@ -60,15 +62,12 @@ public class GetNodesToLabelsResponsePBImpl extends
return; return;
} }
GetNodesToLabelsResponseProtoOrBuilder p = viaProto ? proto : builder; GetNodesToLabelsResponseProtoOrBuilder p = viaProto ? proto : builder;
List<NodeIdToLabelsInfoProto> list = p.getNodeToLabelsList(); List<NodeIdToLabelsProto> list = p.getNodeToLabelsList();
this.nodeToLabels = new HashMap<NodeId, Set<NodeLabel>>(); this.nodeToLabels = new HashMap<NodeId, Set<String>>();
for (NodeIdToLabelsInfoProto c : list) { for (NodeIdToLabelsProto c : list) {
Set<NodeLabel> labels = new HashSet<NodeLabel>(); this.nodeToLabels.put(new NodeIdPBImpl(c.getNodeId()),
for (NodeLabelProto l : c.getNodeLabelsList()) { Sets.newHashSet(c.getNodeLabelsList()));
labels.add(new NodeLabelPBImpl(l));
}
this.nodeToLabels.put(new NodeIdPBImpl(c.getNodeId()), labels);
} }
} }
@ -85,13 +84,13 @@ public class GetNodesToLabelsResponsePBImpl extends
if (nodeToLabels == null) { if (nodeToLabels == null) {
return; return;
} }
Iterable<NodeIdToLabelsInfoProto> iterable = Iterable<NodeIdToLabelsProto> iterable =
new Iterable<NodeIdToLabelsInfoProto>() { new Iterable<NodeIdToLabelsProto>() {
@Override @Override
public Iterator<NodeIdToLabelsInfoProto> iterator() { public Iterator<NodeIdToLabelsProto> iterator() {
return new Iterator<NodeIdToLabelsInfoProto>() { return new Iterator<NodeIdToLabelsProto>() {
Iterator<Entry<NodeId, Set<NodeLabel>>> iter = nodeToLabels Iterator<Entry<NodeId, Set<String>>> iter = nodeToLabels
.entrySet().iterator(); .entrySet().iterator();
@Override @Override
@ -100,16 +99,11 @@ public class GetNodesToLabelsResponsePBImpl extends
} }
@Override @Override
public NodeIdToLabelsInfoProto next() { public NodeIdToLabelsProto next() {
Entry<NodeId, Set<NodeLabel>> now = iter.next(); Entry<NodeId, Set<String>> now = iter.next();
Set<NodeLabelProto> labelProtoList = return NodeIdToLabelsProto.newBuilder()
new HashSet<NodeLabelProto>();
for (NodeLabel l : now.getValue()) {
labelProtoList.add(convertToProtoFormat(l));
}
return NodeIdToLabelsInfoProto.newBuilder()
.setNodeId(convertToProtoFormat(now.getKey())) .setNodeId(convertToProtoFormat(now.getKey()))
.addAllNodeLabels(labelProtoList).build(); .addAllNodeLabels(now.getValue()).build();
} }
@Override @Override
@ -144,13 +138,13 @@ public class GetNodesToLabelsResponsePBImpl extends
} }
@Override @Override
public Map<NodeId, Set<NodeLabel>> getNodeToLabels() { public Map<NodeId, Set<String>> getNodeToLabels() {
initNodeToLabels(); initNodeToLabels();
return this.nodeToLabels; return this.nodeToLabels;
} }
@Override @Override
public void setNodeToLabels(Map<NodeId, Set<NodeLabel>> map) { public void setNodeToLabels(Map<NodeId, Set<String>> map) {
initNodeToLabels(); initNodeToLabels();
nodeToLabels.clear(); nodeToLabels.clear();
nodeToLabels.putAll(map); nodeToLabels.putAll(map);
@ -159,10 +153,6 @@ public class GetNodesToLabelsResponsePBImpl extends
private NodeIdProto convertToProtoFormat(NodeId t) { private NodeIdProto convertToProtoFormat(NodeId t) {
return ((NodeIdPBImpl)t).getProto(); return ((NodeIdPBImpl)t).getProto();
} }
private NodeLabelProto convertToProtoFormat(NodeLabel t) {
return ((NodeLabelPBImpl)t).getProto();
}
@Override @Override
public int hashCode() { public int hashCode() {

View File

@ -19,7 +19,6 @@
package org.apache.hadoop.yarn.server.api.protocolrecords.impl.pb; package org.apache.hadoop.yarn.server.api.protocolrecords.impl.pb;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection;
import java.util.List; import java.util.List;
import org.apache.hadoop.yarn.api.records.NodeLabel; import org.apache.hadoop.yarn.api.records.NodeLabel;
@ -30,7 +29,7 @@ import org.apache.hadoop.yarn.proto.YarnServerResourceManagerServiceProtos.AddTo
import org.apache.hadoop.yarn.server.api.protocolrecords.AddToClusterNodeLabelsRequest; import org.apache.hadoop.yarn.server.api.protocolrecords.AddToClusterNodeLabelsRequest;
public class AddToClusterNodeLabelsRequestPBImpl extends public class AddToClusterNodeLabelsRequestPBImpl extends
AddToClusterNodeLabelsRequest { AddToClusterNodeLabelsRequest {
AddToClusterNodeLabelsRequestProto proto = AddToClusterNodeLabelsRequestProto AddToClusterNodeLabelsRequestProto proto = AddToClusterNodeLabelsRequestProto
.getDefaultInstance(); .getDefaultInstance();
AddToClusterNodeLabelsRequestProto.Builder builder = null; AddToClusterNodeLabelsRequestProto.Builder builder = null;
@ -71,11 +70,15 @@ public class AddToClusterNodeLabelsRequestPBImpl extends
private void addNodeLabelsToProto() { private void addNodeLabelsToProto() {
maybeInitBuilder(); maybeInitBuilder();
builder.clearNodeLabels(); builder.clearNodeLabels();
builder.clearDeprecatedNodeLabels();
List<NodeLabelProto> protoList = new ArrayList<NodeLabelProto>(); List<NodeLabelProto> protoList = new ArrayList<NodeLabelProto>();
List<String> protoListString = new ArrayList<String>();
for (NodeLabel r : this.updatedNodeLabels) { for (NodeLabel r : this.updatedNodeLabels) {
protoList.add(convertToProtoFormat(r)); protoList.add(convertToProtoFormat(r));
protoListString.add(r.getName());
} }
builder.addAllNodeLabels(protoList); builder.addAllNodeLabels(protoList);
builder.addAllDeprecatedNodeLabels(protoListString);
} }
@Override @Override
@ -101,17 +104,6 @@ public class AddToClusterNodeLabelsRequestPBImpl extends
viaProto = false; viaProto = false;
} }
@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() { private void initLocalNodeLabels() {
AddToClusterNodeLabelsRequestProtoOrBuilder p = viaProto ? proto : builder; AddToClusterNodeLabelsRequestProtoOrBuilder p = viaProto ? proto : builder;
List<NodeLabelProto> attributesProtoList = p.getNodeLabelsList(); List<NodeLabelProto> attributesProtoList = p.getNodeLabelsList();
@ -121,15 +113,6 @@ public class AddToClusterNodeLabelsRequestPBImpl extends
} }
} }
@Override
public List<NodeLabel> getNodeLabels() {
if (this.updatedNodeLabels != null) {
return this.updatedNodeLabels;
}
initLocalNodeLabels();
return this.updatedNodeLabels;
}
private NodeLabel convertFromProtoFormat(NodeLabelProto p) { private NodeLabel convertFromProtoFormat(NodeLabelProto p) {
return new NodeLabelPBImpl(p); return new NodeLabelPBImpl(p);
} }
@ -142,4 +125,24 @@ public class AddToClusterNodeLabelsRequestPBImpl extends
public String toString() { public String toString() {
return getProto().toString(); return getProto().toString();
} }
@Override
public void setNodeLabels(List<NodeLabel> nodeLabels) {
maybeInitBuilder();
this.updatedNodeLabels = new ArrayList<>();
if (nodeLabels == null) {
builder.clearNodeLabels();
return;
}
this.updatedNodeLabels.addAll(nodeLabels);
}
@Override
public List<NodeLabel> getNodeLabels() {
if (this.updatedNodeLabels != null) {
return this.updatedNodeLabels;
}
initLocalNodeLabels();
return this.updatedNodeLabels;
}
} }

View File

@ -28,7 +28,7 @@ import java.util.Set;
import org.apache.hadoop.yarn.api.records.NodeId; import org.apache.hadoop.yarn.api.records.NodeId;
import org.apache.hadoop.yarn.api.records.impl.pb.NodeIdPBImpl; import org.apache.hadoop.yarn.api.records.impl.pb.NodeIdPBImpl;
import org.apache.hadoop.yarn.proto.YarnProtos.NodeIdProto; import org.apache.hadoop.yarn.proto.YarnProtos.NodeIdProto;
import org.apache.hadoop.yarn.proto.YarnServerResourceManagerServiceProtos.NodeIdToLabelsNameProto; import org.apache.hadoop.yarn.proto.YarnProtos.NodeIdToLabelsProto;
import org.apache.hadoop.yarn.proto.YarnServerResourceManagerServiceProtos.ReplaceLabelsOnNodeRequestProto; import org.apache.hadoop.yarn.proto.YarnServerResourceManagerServiceProtos.ReplaceLabelsOnNodeRequestProto;
import org.apache.hadoop.yarn.proto.YarnServerResourceManagerServiceProtos.ReplaceLabelsOnNodeRequestProtoOrBuilder; import org.apache.hadoop.yarn.proto.YarnServerResourceManagerServiceProtos.ReplaceLabelsOnNodeRequestProtoOrBuilder;
import org.apache.hadoop.yarn.server.api.protocolrecords.ReplaceLabelsOnNodeRequest; import org.apache.hadoop.yarn.server.api.protocolrecords.ReplaceLabelsOnNodeRequest;
@ -58,10 +58,10 @@ public class ReplaceLabelsOnNodeRequestPBImpl extends
return; return;
} }
ReplaceLabelsOnNodeRequestProtoOrBuilder p = viaProto ? proto : builder; ReplaceLabelsOnNodeRequestProtoOrBuilder p = viaProto ? proto : builder;
List<NodeIdToLabelsNameProto> list = p.getNodeToLabelsList(); List<NodeIdToLabelsProto> list = p.getNodeToLabelsList();
this.nodeIdToLabels = new HashMap<NodeId, Set<String>>(); this.nodeIdToLabels = new HashMap<NodeId, Set<String>>();
for (NodeIdToLabelsNameProto c : list) { for (NodeIdToLabelsProto c : list) {
this.nodeIdToLabels.put(new NodeIdPBImpl(c.getNodeId()), this.nodeIdToLabels.put(new NodeIdPBImpl(c.getNodeId()),
Sets.newHashSet(c.getNodeLabelsList())); Sets.newHashSet(c.getNodeLabelsList()));
} }
@ -80,11 +80,11 @@ public class ReplaceLabelsOnNodeRequestPBImpl extends
if (nodeIdToLabels == null) { if (nodeIdToLabels == null) {
return; return;
} }
Iterable<NodeIdToLabelsNameProto> iterable = Iterable<NodeIdToLabelsProto> iterable =
new Iterable<NodeIdToLabelsNameProto>() { new Iterable<NodeIdToLabelsProto>() {
@Override @Override
public Iterator<NodeIdToLabelsNameProto> iterator() { public Iterator<NodeIdToLabelsProto> iterator() {
return new Iterator<NodeIdToLabelsNameProto>() { return new Iterator<NodeIdToLabelsProto>() {
Iterator<Entry<NodeId, Set<String>>> iter = nodeIdToLabels Iterator<Entry<NodeId, Set<String>>> iter = nodeIdToLabels
.entrySet().iterator(); .entrySet().iterator();
@ -95,9 +95,9 @@ public class ReplaceLabelsOnNodeRequestPBImpl extends
} }
@Override @Override
public NodeIdToLabelsNameProto next() { public NodeIdToLabelsProto next() {
Entry<NodeId, Set<String>> now = iter.next(); Entry<NodeId, Set<String>> now = iter.next();
return NodeIdToLabelsNameProto.newBuilder() return NodeIdToLabelsProto.newBuilder()
.setNodeId(convertToProtoFormat(now.getKey())).clearNodeLabels() .setNodeId(convertToProtoFormat(now.getKey())).clearNodeLabels()
.addAllNodeLabels(now.getValue()).build(); .addAllNodeLabels(now.getValue()).build();
} }

View File

@ -735,9 +735,10 @@ public class AdminService extends CompositeService implements
AddToClusterNodeLabelsResponse response = AddToClusterNodeLabelsResponse response =
recordFactory.newRecordInstance(AddToClusterNodeLabelsResponse.class); recordFactory.newRecordInstance(AddToClusterNodeLabelsResponse.class);
try { try {
rmContext.getNodeLabelManager().addToCluserNodeLabels(request.getNodeLabels()); rmContext.getNodeLabelManager()
RMAuditLogger .addToCluserNodeLabels(request.getNodeLabels());
.logSuccess(user.getShortUserName(), operation, "AdminService"); RMAuditLogger.logSuccess(user.getShortUserName(), operation,
"AdminService");
return response; return response;
} catch (IOException ioe) { } catch (IOException ioe) {
throw logAndWrapException(ioe, user.getShortUserName(), operation, msg); throw logAndWrapException(ioe, user.getShortUserName(), operation, msg);

View File

@ -1490,7 +1490,7 @@ public class ClientRMService extends AbstractService implements
GetNodesToLabelsRequest request) throws YarnException, IOException { GetNodesToLabelsRequest request) throws YarnException, IOException {
RMNodeLabelsManager labelsMgr = rmContext.getNodeLabelManager(); RMNodeLabelsManager labelsMgr = rmContext.getNodeLabelManager();
GetNodesToLabelsResponse response = GetNodesToLabelsResponse response =
GetNodesToLabelsResponse.newInstance(labelsMgr.getNodeLabelsInfo()); GetNodesToLabelsResponse.newInstance(labelsMgr.getNodeLabels());
return response; return response;
} }
@ -1500,10 +1500,10 @@ public class ClientRMService extends AbstractService implements
RMNodeLabelsManager labelsMgr = rmContext.getNodeLabelManager(); RMNodeLabelsManager labelsMgr = rmContext.getNodeLabelManager();
if (request.getNodeLabels() == null || request.getNodeLabels().isEmpty()) { if (request.getNodeLabels() == null || request.getNodeLabels().isEmpty()) {
return GetLabelsToNodesResponse.newInstance( return GetLabelsToNodesResponse.newInstance(
labelsMgr.getLabelsInfoToNodes()); labelsMgr.getLabelsToNodes());
} else { } else {
return GetLabelsToNodesResponse.newInstance( return GetLabelsToNodesResponse.newInstance(
labelsMgr.getLabelsInfoToNodes(request.getNodeLabels())); labelsMgr.getLabelsToNodes(request.getNodeLabels()));
} }
} }

View File

@ -1799,27 +1799,19 @@ public class TestClientRMService {
// Get node labels mapping // Get node labels mapping
GetNodesToLabelsResponse response1 = client GetNodesToLabelsResponse response1 = client
.getNodeToLabels(GetNodesToLabelsRequest.newInstance()); .getNodeToLabels(GetNodesToLabelsRequest.newInstance());
Map<NodeId, Set<NodeLabel>> nodeToLabels = response1.getNodeToLabels(); Map<NodeId, Set<String>> nodeToLabels = response1.getNodeToLabels();
Assert.assertTrue(nodeToLabels.keySet().containsAll( Assert.assertTrue(nodeToLabels.keySet().containsAll(
Arrays.asList(node1, node2))); Arrays.asList(node1, node2)));
Assert.assertTrue(nodeToLabels.get(node1) Assert.assertTrue(nodeToLabels.get(node1)
.containsAll(Arrays.asList(labelX))); .containsAll(Arrays.asList(labelX.getName())));
Assert.assertTrue(nodeToLabels.get(node2) Assert.assertTrue(nodeToLabels.get(node2)
.containsAll(Arrays.asList(labelY))); .containsAll(Arrays.asList(labelY.getName())));
// Verify whether labelX's exclusivity is false
for (NodeLabel x : nodeToLabels.get(node1)) {
Assert.assertFalse(x.isExclusive());
}
// Verify whether labelY's exclusivity is true
for (NodeLabel y : nodeToLabels.get(node2)) {
Assert.assertTrue(y.isExclusive());
}
// Below label "x" is not present in the response as exclusivity is true // Below label "x" is not present in the response as exclusivity is true
Assert.assertFalse(nodeToLabels.get(node1).containsAll( Assert.assertFalse(nodeToLabels.get(node1).containsAll(
Arrays.asList(NodeLabel.newInstance("x")))); Arrays.asList(NodeLabel.newInstance("x"))));
rpc.stopProxy(client, conf); rpc.stopProxy(client, conf);
rm.close(); rm.stop();
} }
@Test @Test
@ -1870,18 +1862,14 @@ public class TestClientRMService {
// Get labels to nodes mapping // Get labels to nodes mapping
GetLabelsToNodesResponse response1 = client GetLabelsToNodesResponse response1 = client
.getLabelsToNodes(GetLabelsToNodesRequest.newInstance()); .getLabelsToNodes(GetLabelsToNodesRequest.newInstance());
Map<NodeLabel, Set<NodeId>> labelsToNodes = response1.getLabelsToNodes(); Map<String, Set<NodeId>> labelsToNodes = response1.getLabelsToNodes();
// Verify whether all NodeLabel's exclusivity are false
for (Map.Entry<NodeLabel, Set<NodeId>> nltn : labelsToNodes.entrySet()) {
Assert.assertFalse(nltn.getKey().isExclusive());
}
Assert.assertTrue(labelsToNodes.keySet().containsAll( Assert.assertTrue(labelsToNodes.keySet().containsAll(
Arrays.asList(labelX, labelY, labelZ))); Arrays.asList(labelX.getName(), labelY.getName(), labelZ.getName())));
Assert.assertTrue(labelsToNodes.get(labelX).containsAll( Assert.assertTrue(labelsToNodes.get(labelX.getName()).containsAll(
Arrays.asList(node1A))); Arrays.asList(node1A)));
Assert.assertTrue(labelsToNodes.get(labelY).containsAll( Assert.assertTrue(labelsToNodes.get(labelY.getName()).containsAll(
Arrays.asList(node2A, node3A))); Arrays.asList(node2A, node3A)));
Assert.assertTrue(labelsToNodes.get(labelZ).containsAll( Assert.assertTrue(labelsToNodes.get(labelZ.getName()).containsAll(
Arrays.asList(node1B, node3B))); Arrays.asList(node1B, node3B)));
// Get labels to nodes mapping for specific labels // Get labels to nodes mapping for specific labels
@ -1890,17 +1878,13 @@ public class TestClientRMService {
GetLabelsToNodesResponse response2 = client GetLabelsToNodesResponse response2 = client
.getLabelsToNodes(GetLabelsToNodesRequest.newInstance(setlabels)); .getLabelsToNodes(GetLabelsToNodesRequest.newInstance(setlabels));
labelsToNodes = response2.getLabelsToNodes(); labelsToNodes = response2.getLabelsToNodes();
// Verify whether all NodeLabel's exclusivity are false
for (Map.Entry<NodeLabel, Set<NodeId>> nltn : labelsToNodes.entrySet()) {
Assert.assertFalse(nltn.getKey().isExclusive());
}
Assert.assertTrue(labelsToNodes.keySet().containsAll( Assert.assertTrue(labelsToNodes.keySet().containsAll(
Arrays.asList(labelX, labelZ))); Arrays.asList(labelX.getName(), labelZ.getName())));
Assert.assertTrue(labelsToNodes.get(labelX).containsAll( Assert.assertTrue(labelsToNodes.get(labelX.getName()).containsAll(
Arrays.asList(node1A))); Arrays.asList(node1A)));
Assert.assertTrue(labelsToNodes.get(labelZ).containsAll( Assert.assertTrue(labelsToNodes.get(labelZ.getName()).containsAll(
Arrays.asList(node1B, node3B))); Arrays.asList(node1B, node3B)));
Assert.assertEquals(labelsToNodes.get(labelY), null); Assert.assertEquals(labelsToNodes.get(labelY.getName()), null);
rpc.stopProxy(client, conf); rpc.stopProxy(client, conf);
rm.close(); rm.close();