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);
}
@Override
public Map<NodeId, Set<NodeLabel>> getNodeToLabels() throws YarnException,
public Map<NodeId, Set<String>> getNodeToLabels() throws YarnException,
IOException {
return client.getNodeToLabels();
}
@Override
public Map<NodeLabel, Set<NodeId>> getLabelsToNodes() throws YarnException,
public Map<String, Set<NodeId>> getLabelsToNodes() throws YarnException,
IOException {
return client.getLabelsToNodes();
}
@Override
public Map<NodeLabel, Set<NodeId>> getLabelsToNodes(Set<String> labels)
public Map<String, Set<NodeId>> getLabelsToNodes(Set<String> labels)
throws YarnException, IOException {
return client.getLabelsToNodes(labels);
}

View File

@ -29,7 +29,7 @@ import org.apache.hadoop.yarn.util.Records;
public abstract class GetLabelsToNodesResponse {
public static GetLabelsToNodesResponse newInstance(
Map<NodeLabel, Set<NodeId>> map) {
Map<String, Set<NodeId>> map) {
GetLabelsToNodesResponse response =
Records.newRecord(GetLabelsToNodesResponse.class);
response.setLabelsToNodes(map);
@ -38,9 +38,9 @@ public abstract class GetLabelsToNodesResponse {
@Public
@Evolving
public abstract void setLabelsToNodes(Map<NodeLabel, Set<NodeId>> map);
public abstract void setLabelsToNodes(Map<String, Set<NodeId>> map);
@Public
@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.InterfaceStability.Evolving;
import org.apache.hadoop.yarn.api.records.NodeId;
import org.apache.hadoop.yarn.api.records.NodeLabel;
import org.apache.hadoop.yarn.util.Records;
public abstract class GetNodesToLabelsResponse {
public static GetNodesToLabelsResponse newInstance(
Map<NodeId, Set<NodeLabel>> map) {
Map<NodeId, Set<String>> map) {
GetNodesToLabelsResponse response =
Records.newRecord(GetNodesToLabelsResponse.class);
response.setNodeToLabels(map);
@ -38,9 +37,9 @@ public abstract class GetNodesToLabelsResponse {
@Public
@Evolving
public abstract void setNodeToLabels(Map<NodeId, Set<NodeLabel>> map);
public abstract void setNodeToLabels(Map<NodeId, Set<String>> map);
@Public
@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
@Unstable
public static AddToClusterNodeLabelsRequest newInstance(
List<NodeLabel> NodeLabels) {
AddToClusterNodeLabelsRequest request =
Records.newRecord(AddToClusterNodeLabelsRequest.class);
request.setNodeLabels(NodeLabels);
public static AddToClusterNodeLabelsRequest newInstance(List<NodeLabel> nodeLabels) {
AddToClusterNodeLabelsRequest request = Records
.newRecord(AddToClusterNodeLabelsRequest.class);
request.setNodeLabels(nodeLabels);
return request;
}
@Public
@Unstable
public abstract void setNodeLabels(List<NodeLabel> NodeLabels);
public abstract void setNodeLabels(List<NodeLabel> nodeLabels);
@Public
@Unstable

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -46,7 +46,7 @@ public class GetLabelsToNodesResponsePBImpl extends
GetLabelsToNodesResponseProto.Builder builder = null;
boolean viaProto = false;
private Map<NodeLabel, Set<NodeId>> labelsToNodes;
private Map<String, Set<NodeId>> labelsToNodes;
public GetLabelsToNodesResponsePBImpl() {
this.builder = GetLabelsToNodesResponseProto.newBuilder();
@ -63,7 +63,7 @@ public class GetLabelsToNodesResponsePBImpl extends
}
GetLabelsToNodesResponseProtoOrBuilder p = viaProto ? proto : builder;
List<LabelsToNodeIdsProto> list = p.getLabelsToNodesList();
this.labelsToNodes = new HashMap<NodeLabel, Set<NodeId>>();
this.labelsToNodes = new HashMap<String, Set<NodeId>>();
for (LabelsToNodeIdsProto c : list) {
Set<NodeId> setNodes = new HashSet<NodeId>();
@ -73,7 +73,7 @@ public class GetLabelsToNodesResponsePBImpl extends
}
if (!setNodes.isEmpty()) {
this.labelsToNodes
.put(new NodeLabelPBImpl(c.getNodeLabels()), setNodes);
.put(c.getNodeLabels(), setNodes);
}
}
}
@ -97,7 +97,7 @@ public class GetLabelsToNodesResponsePBImpl extends
public Iterator<LabelsToNodeIdsProto> iterator() {
return new Iterator<LabelsToNodeIdsProto>() {
Iterator<Entry<NodeLabel, Set<NodeId>>> iter =
Iterator<Entry<String, Set<NodeId>>> iter =
labelsToNodes.entrySet().iterator();
@Override
@ -107,13 +107,13 @@ public class GetLabelsToNodesResponsePBImpl extends
@Override
public LabelsToNodeIdsProto next() {
Entry<NodeLabel, Set<NodeId>> now = iter.next();
Entry<String, Set<NodeId>> now = iter.next();
Set<NodeIdProto> nodeProtoSet = new HashSet<NodeIdProto>();
for(NodeId n : now.getValue()) {
nodeProtoSet.add(convertToProtoFormat(n));
}
return LabelsToNodeIdsProto.newBuilder()
.setNodeLabels(convertToProtoFormat(now.getKey()))
.setNodeLabels(now.getKey())
.addAllNodeId(nodeProtoSet)
.build();
}
@ -153,10 +153,6 @@ public class GetLabelsToNodesResponsePBImpl extends
return ((NodeIdPBImpl)t).getProto();
}
private NodeLabelProto convertToProtoFormat(NodeLabel l) {
return ((NodeLabelPBImpl)l).getProto();
}
@Override
public int hashCode() {
assert false : "hashCode not designed";
@ -176,7 +172,7 @@ public class GetLabelsToNodesResponsePBImpl extends
@Override
@Public
@Evolving
public void setLabelsToNodes(Map<NodeLabel, Set<NodeId>> map) {
public void setLabelsToNodes(Map<String, Set<NodeId>> map) {
initLabelsToNodes();
labelsToNodes.clear();
labelsToNodes.putAll(map);
@ -185,7 +181,7 @@ public class GetLabelsToNodesResponsePBImpl extends
@Override
@Public
@Evolving
public Map<NodeLabel, Set<NodeId>> getLabelsToNodes() {
public Map<String, Set<NodeId>> getLabelsToNodes() {
initLabelsToNodes();
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.proto.YarnProtos.NodeIdProto;
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.YarnServiceProtos.GetNodesToLabelsResponseProto;
import org.apache.hadoop.yarn.proto.YarnServiceProtos.GetNodesToLabelsResponseProtoOrBuilder;
import com.google.common.collect.Sets;
public class GetNodesToLabelsResponsePBImpl extends
GetNodesToLabelsResponse {
GetNodesToLabelsResponseProto proto = GetNodesToLabelsResponseProto
@ -44,7 +46,7 @@ public class GetNodesToLabelsResponsePBImpl extends
GetNodesToLabelsResponseProto.Builder builder = null;
boolean viaProto = false;
private Map<NodeId, Set<NodeLabel>> nodeToLabels;
private Map<NodeId, Set<String>> nodeToLabels;
public GetNodesToLabelsResponsePBImpl() {
this.builder = GetNodesToLabelsResponseProto.newBuilder();
@ -60,15 +62,12 @@ public class GetNodesToLabelsResponsePBImpl extends
return;
}
GetNodesToLabelsResponseProtoOrBuilder p = viaProto ? proto : builder;
List<NodeIdToLabelsInfoProto> list = p.getNodeToLabelsList();
this.nodeToLabels = new HashMap<NodeId, Set<NodeLabel>>();
List<NodeIdToLabelsProto> list = p.getNodeToLabelsList();
this.nodeToLabels = new HashMap<NodeId, Set<String>>();
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);
for (NodeIdToLabelsProto c : list) {
this.nodeToLabels.put(new NodeIdPBImpl(c.getNodeId()),
Sets.newHashSet(c.getNodeLabelsList()));
}
}
@ -85,13 +84,13 @@ public class GetNodesToLabelsResponsePBImpl extends
if (nodeToLabels == null) {
return;
}
Iterable<NodeIdToLabelsInfoProto> iterable =
new Iterable<NodeIdToLabelsInfoProto>() {
Iterable<NodeIdToLabelsProto> iterable =
new Iterable<NodeIdToLabelsProto>() {
@Override
public Iterator<NodeIdToLabelsInfoProto> iterator() {
return new Iterator<NodeIdToLabelsInfoProto>() {
public Iterator<NodeIdToLabelsProto> iterator() {
return new Iterator<NodeIdToLabelsProto>() {
Iterator<Entry<NodeId, Set<NodeLabel>>> iter = nodeToLabels
Iterator<Entry<NodeId, Set<String>>> iter = nodeToLabels
.entrySet().iterator();
@Override
@ -100,16 +99,11 @@ public class GetNodesToLabelsResponsePBImpl extends
}
@Override
public NodeIdToLabelsInfoProto next() {
Entry<NodeId, Set<NodeLabel>> now = iter.next();
Set<NodeLabelProto> labelProtoList =
new HashSet<NodeLabelProto>();
for (NodeLabel l : now.getValue()) {
labelProtoList.add(convertToProtoFormat(l));
}
return NodeIdToLabelsInfoProto.newBuilder()
public NodeIdToLabelsProto next() {
Entry<NodeId, Set<String>> now = iter.next();
return NodeIdToLabelsProto.newBuilder()
.setNodeId(convertToProtoFormat(now.getKey()))
.addAllNodeLabels(labelProtoList).build();
.addAllNodeLabels(now.getValue()).build();
}
@Override
@ -144,13 +138,13 @@ public class GetNodesToLabelsResponsePBImpl extends
}
@Override
public Map<NodeId, Set<NodeLabel>> getNodeToLabels() {
public Map<NodeId, Set<String>> getNodeToLabels() {
initNodeToLabels();
return this.nodeToLabels;
}
@Override
public void setNodeToLabels(Map<NodeId, Set<NodeLabel>> map) {
public void setNodeToLabels(Map<NodeId, Set<String>> map) {
initNodeToLabels();
nodeToLabels.clear();
nodeToLabels.putAll(map);
@ -159,10 +153,6 @@ public class GetNodesToLabelsResponsePBImpl extends
private NodeIdProto convertToProtoFormat(NodeId t) {
return ((NodeIdPBImpl)t).getProto();
}
private NodeLabelProto convertToProtoFormat(NodeLabel t) {
return ((NodeLabelPBImpl)t).getProto();
}
@Override
public int hashCode() {

View File

@ -19,7 +19,6 @@
package org.apache.hadoop.yarn.server.api.protocolrecords.impl.pb;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
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;
public class AddToClusterNodeLabelsRequestPBImpl extends
AddToClusterNodeLabelsRequest {
AddToClusterNodeLabelsRequest {
AddToClusterNodeLabelsRequestProto proto = AddToClusterNodeLabelsRequestProto
.getDefaultInstance();
AddToClusterNodeLabelsRequestProto.Builder builder = null;
@ -71,11 +70,15 @@ public class AddToClusterNodeLabelsRequestPBImpl extends
private void addNodeLabelsToProto() {
maybeInitBuilder();
builder.clearNodeLabels();
builder.clearDeprecatedNodeLabels();
List<NodeLabelProto> protoList = new ArrayList<NodeLabelProto>();
List<String> protoListString = new ArrayList<String>();
for (NodeLabel r : this.updatedNodeLabels) {
protoList.add(convertToProtoFormat(r));
protoListString.add(r.getName());
}
builder.addAllNodeLabels(protoList);
builder.addAllDeprecatedNodeLabels(protoListString);
}
@Override
@ -101,17 +104,6 @@ public class AddToClusterNodeLabelsRequestPBImpl extends
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() {
AddToClusterNodeLabelsRequestProtoOrBuilder p = viaProto ? proto : builder;
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) {
return new NodeLabelPBImpl(p);
}
@ -142,4 +125,24 @@ public class AddToClusterNodeLabelsRequestPBImpl extends
public String 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.impl.pb.NodeIdPBImpl;
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.ReplaceLabelsOnNodeRequestProtoOrBuilder;
import org.apache.hadoop.yarn.server.api.protocolrecords.ReplaceLabelsOnNodeRequest;
@ -58,10 +58,10 @@ public class ReplaceLabelsOnNodeRequestPBImpl extends
return;
}
ReplaceLabelsOnNodeRequestProtoOrBuilder p = viaProto ? proto : builder;
List<NodeIdToLabelsNameProto> list = p.getNodeToLabelsList();
List<NodeIdToLabelsProto> list = p.getNodeToLabelsList();
this.nodeIdToLabels = new HashMap<NodeId, Set<String>>();
for (NodeIdToLabelsNameProto c : list) {
for (NodeIdToLabelsProto c : list) {
this.nodeIdToLabels.put(new NodeIdPBImpl(c.getNodeId()),
Sets.newHashSet(c.getNodeLabelsList()));
}
@ -80,11 +80,11 @@ public class ReplaceLabelsOnNodeRequestPBImpl extends
if (nodeIdToLabels == null) {
return;
}
Iterable<NodeIdToLabelsNameProto> iterable =
new Iterable<NodeIdToLabelsNameProto>() {
Iterable<NodeIdToLabelsProto> iterable =
new Iterable<NodeIdToLabelsProto>() {
@Override
public Iterator<NodeIdToLabelsNameProto> iterator() {
return new Iterator<NodeIdToLabelsNameProto>() {
public Iterator<NodeIdToLabelsProto> iterator() {
return new Iterator<NodeIdToLabelsProto>() {
Iterator<Entry<NodeId, Set<String>>> iter = nodeIdToLabels
.entrySet().iterator();
@ -95,9 +95,9 @@ public class ReplaceLabelsOnNodeRequestPBImpl extends
}
@Override
public NodeIdToLabelsNameProto next() {
public NodeIdToLabelsProto next() {
Entry<NodeId, Set<String>> now = iter.next();
return NodeIdToLabelsNameProto.newBuilder()
return NodeIdToLabelsProto.newBuilder()
.setNodeId(convertToProtoFormat(now.getKey())).clearNodeLabels()
.addAllNodeLabels(now.getValue()).build();
}

View File

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

View File

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

View File

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