Skip to content

Commit e1feb4e

Browse files
committed
YARN-3345. Add non-exclusive node label API. Contributed by Wangda Tan
1 parent 7f1e2f9 commit e1feb4e

File tree

28 files changed

+1084
-51
lines changed

28 files changed

+1084
-51
lines changed

hadoop-yarn-project/CHANGES.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ Release 2.8.0 - UNRELEASED
5454

5555
NEW FEATURES
5656

57+
YARN-3345. Add non-exclusive node label API. (Wangda Tan via jianhe)
58+
5759
IMPROVEMENTS
5860

5961
YARN-3243. CapacityScheduler should pass headroom from parent to children
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/**
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
package org.apache.hadoop.yarn.api.records;
20+
21+
import org.apache.hadoop.classification.InterfaceAudience.Public;
22+
import org.apache.hadoop.classification.InterfaceStability.Stable;
23+
import org.apache.hadoop.classification.InterfaceStability.Unstable;
24+
import org.apache.hadoop.yarn.util.Records;
25+
26+
@Public
27+
@Unstable
28+
public abstract class NodeLabel {
29+
@Public
30+
@Unstable
31+
public static NodeLabel newInstance(String nodeLabel,
32+
boolean isExclusive) {
33+
NodeLabel request =
34+
Records.newRecord(NodeLabel.class);
35+
request.setNodeLabel(nodeLabel);
36+
request.setIsExclusive(isExclusive);
37+
return request;
38+
}
39+
40+
@Public
41+
@Stable
42+
public abstract String getNodeLabel();
43+
44+
@Public
45+
@Unstable
46+
public abstract void setNodeLabel(String nodeLabel);
47+
48+
@Public
49+
@Stable
50+
public abstract boolean getIsExclusive();
51+
52+
@Public
53+
@Unstable
54+
public abstract void setIsExclusive(boolean isExclusive);
55+
}

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/server/api/ResourceManagerAdministrationProtocol.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@
4848
import org.apache.hadoop.yarn.server.api.protocolrecords.RemoveFromClusterNodeLabelsResponse;
4949
import org.apache.hadoop.yarn.server.api.protocolrecords.ReplaceLabelsOnNodeRequest;
5050
import org.apache.hadoop.yarn.server.api.protocolrecords.ReplaceLabelsOnNodeResponse;
51+
import org.apache.hadoop.yarn.server.api.protocolrecords.UpdateNodeLabelsRequest;
52+
import org.apache.hadoop.yarn.server.api.protocolrecords.UpdateNodeLabelsResponse;
5153
import org.apache.hadoop.yarn.server.api.protocolrecords.UpdateNodeResourceRequest;
5254
import org.apache.hadoop.yarn.server.api.protocolrecords.UpdateNodeResourceResponse;
5355

@@ -120,8 +122,8 @@ public UpdateNodeResourceResponse updateNodeResource(
120122
@Public
121123
@Evolving
122124
@Idempotent
123-
public AddToClusterNodeLabelsResponse addToClusterNodeLabels(AddToClusterNodeLabelsRequest request)
124-
throws YarnException, IOException;
125+
public AddToClusterNodeLabelsResponse addToClusterNodeLabels(
126+
AddToClusterNodeLabelsRequest request) throws YarnException, IOException;
125127

126128
@Public
127129
@Evolving
@@ -134,4 +136,10 @@ public RemoveFromClusterNodeLabelsResponse removeFromClusterNodeLabels(
134136
@Idempotent
135137
public ReplaceLabelsOnNodeResponse replaceLabelsOnNode(
136138
ReplaceLabelsOnNodeRequest request) throws YarnException, IOException;
139+
140+
@Public
141+
@Evolving
142+
@Idempotent
143+
public UpdateNodeLabelsResponse updateNodeLabels(
144+
UpdateNodeLabelsRequest request) throws YarnException, IOException;
137145
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/**
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
package org.apache.hadoop.yarn.server.api.protocolrecords;
20+
21+
import java.util.List;
22+
23+
import org.apache.hadoop.classification.InterfaceAudience.Public;
24+
import org.apache.hadoop.classification.InterfaceStability.Unstable;
25+
import org.apache.hadoop.yarn.api.records.NodeLabel;
26+
import org.apache.hadoop.yarn.util.Records;
27+
28+
@Public
29+
@Unstable
30+
public abstract class UpdateNodeLabelsRequest {
31+
@Public
32+
@Unstable
33+
public static UpdateNodeLabelsRequest newInstance(
34+
List<NodeLabel> NodeLabels) {
35+
UpdateNodeLabelsRequest request =
36+
Records.newRecord(UpdateNodeLabelsRequest.class);
37+
request.setNodeLabels(NodeLabels);
38+
return request;
39+
}
40+
41+
@Public
42+
@Unstable
43+
public abstract void setNodeLabels(
44+
List<NodeLabel> NodeLabels);
45+
46+
@Public
47+
@Unstable
48+
public abstract List<NodeLabel> getNodeLabels();
49+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/**
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
package org.apache.hadoop.yarn.server.api.protocolrecords;
20+
21+
import org.apache.hadoop.classification.InterfaceAudience.Private;
22+
import org.apache.hadoop.classification.InterfaceAudience.Public;
23+
import org.apache.hadoop.classification.InterfaceStability.Unstable;
24+
import org.apache.hadoop.yarn.util.Records;
25+
26+
@Public
27+
@Unstable
28+
public class UpdateNodeLabelsResponse {
29+
30+
@Private
31+
@Unstable
32+
public static UpdateNodeLabelsResponse newInstance() {
33+
UpdateNodeLabelsResponse response =
34+
Records.newRecord(UpdateNodeLabelsResponse.class);
35+
return response;
36+
}
37+
}

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/proto/server/resourcemanager_administration_protocol.proto

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,5 @@ service ResourceManagerAdministrationProtocolService {
4242
rpc addToClusterNodeLabels(AddToClusterNodeLabelsRequestProto) returns (AddToClusterNodeLabelsResponseProto);
4343
rpc removeFromClusterNodeLabels(RemoveFromClusterNodeLabelsRequestProto) returns (RemoveFromClusterNodeLabelsResponseProto);
4444
rpc replaceLabelsOnNodes(ReplaceLabelsOnNodeRequestProto) returns (ReplaceLabelsOnNodeResponseProto);
45+
rpc updateNodeLabels(UpdateNodeLabelsRequestProto) returns (UpdateNodeLabelsResponseProto);
4546
}

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/proto/server/yarn_server_resourcemanager_service_protos.proto

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,14 @@ message ReplaceLabelsOnNodeResponseProto {
9797

9898
}
9999

100+
message UpdateNodeLabelsRequestProto {
101+
repeated NodeLabelProto nodeLabels = 1;
102+
}
103+
104+
105+
message UpdateNodeLabelsResponseProto {
106+
}
107+
100108
//////////////////////////////////////////////////////////////////
101109
///////////// RM Failover related records ////////////////////////
102110
//////////////////////////////////////////////////////////////////

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/proto/yarn_protos.proto

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,11 @@ message LabelsToNodeIdsProto {
244244
repeated NodeIdProto nodeId = 2;
245245
}
246246

247+
message NodeLabelProto {
248+
optional string nodeLabel = 1;
249+
optional bool isExclusive = 2 [default = true];
250+
}
251+
247252
////////////////////////////////////////////////////////////////////////
248253
////// From AM_RM_Protocol /////////////////////////////////////////////
249254
////////////////////////////////////////////////////////////////////////
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
/**
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
package org.apache.hadoop.yarn.api.records.impl.pb;
19+
20+
import org.apache.hadoop.yarn.api.records.NodeLabel;
21+
import org.apache.hadoop.yarn.proto.YarnProtos.NodeLabelProto;
22+
import org.apache.hadoop.yarn.proto.YarnProtos.NodeLabelProtoOrBuilder;
23+
24+
public class NodeLabelPBImpl extends NodeLabel {
25+
NodeLabelProto proto =
26+
NodeLabelProto.getDefaultInstance();
27+
NodeLabelProto.Builder builder = null;
28+
boolean viaProto = false;
29+
30+
public NodeLabelPBImpl() {
31+
builder = NodeLabelProto.newBuilder();
32+
}
33+
34+
public NodeLabelPBImpl(NodeLabelProto proto) {
35+
this.proto = proto;
36+
viaProto = true;
37+
}
38+
39+
public NodeLabelProto getProto() {
40+
mergeLocalToProto();
41+
proto = viaProto ? proto : builder.build();
42+
viaProto = true;
43+
return proto;
44+
}
45+
46+
private void mergeLocalToProto() {
47+
if (viaProto)
48+
maybeInitBuilder();
49+
proto = builder.build();
50+
viaProto = true;
51+
}
52+
53+
@Override
54+
public boolean equals(Object other) {
55+
if (other == null)
56+
return false;
57+
if (other.getClass().isAssignableFrom(this.getClass())) {
58+
return this.getProto().equals(this.getClass().cast(other).getProto());
59+
}
60+
return false;
61+
}
62+
63+
private void maybeInitBuilder() {
64+
if (viaProto || builder == null) {
65+
builder = NodeLabelProto.newBuilder(proto);
66+
}
67+
viaProto = false;
68+
}
69+
70+
@Override
71+
public int hashCode() {
72+
return getProto().hashCode();
73+
}
74+
75+
@Override
76+
public String getNodeLabel() {
77+
NodeLabelProtoOrBuilder p = viaProto ? proto : builder;
78+
if (!p.hasNodeLabel()) {
79+
return null;
80+
}
81+
return (p.getNodeLabel());
82+
}
83+
84+
@Override
85+
public void setNodeLabel(String nodeLabel) {
86+
maybeInitBuilder();
87+
if (nodeLabel == null) {
88+
builder.clearNodeLabel();
89+
return;
90+
}
91+
builder.setNodeLabel(nodeLabel);
92+
}
93+
94+
@Override
95+
public boolean getIsExclusive() {
96+
NodeLabelProtoOrBuilder p = viaProto ? proto : builder;
97+
return p.getIsExclusive();
98+
}
99+
100+
@Override
101+
public void setIsExclusive(boolean isExclusive) {
102+
maybeInitBuilder();
103+
builder.setIsExclusive(isExclusive);
104+
}
105+
106+
}

0 commit comments

Comments
 (0)