Skip to content

Commit d02516c

Browse files
author
slfan1989
committed
YARN-9708. Yarn Router Support DelegationToken.
1 parent d55d76e commit d02516c

File tree

35 files changed

+2707
-4
lines changed

35 files changed

+2707
-4
lines changed

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/security/client/YARNDelegationTokenIdentifier.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,14 @@
2222
import java.io.DataOutputStream;
2323
import java.io.IOException;
2424

25+
import org.apache.hadoop.classification.InterfaceAudience;
26+
import org.apache.hadoop.classification.InterfaceStability;
2527
import org.apache.hadoop.classification.VisibleForTesting;
2628
import org.apache.hadoop.classification.InterfaceAudience.Private;
2729
import org.apache.hadoop.io.Text;
2830
import org.apache.hadoop.security.token.delegation.AbstractDelegationTokenIdentifier;
2931
import org.apache.hadoop.yarn.proto.YarnSecurityTokenProtos.YARNDelegationTokenIdentifierProto;
32+
import org.apache.hadoop.yarn.util.Records;
3033

3134
@Private
3235
public abstract class YARNDelegationTokenIdentifier extends
@@ -112,4 +115,14 @@ public YARNDelegationTokenIdentifierProto getProto() {
112115
setBuilderFields();
113116
return builder.build();
114117
}
118+
119+
@InterfaceAudience.Private
120+
@InterfaceStability.Unstable
121+
public static YARNDelegationTokenIdentifier newInstance(Text owner, Text renewer, Text realUser) {
122+
YARNDelegationTokenIdentifier policy = Records.newRecord(YARNDelegationTokenIdentifier.class);
123+
policy.setOwner(owner);
124+
policy.setRenewer(renewer);
125+
policy.setRenewer(realUser);
126+
return policy;
127+
}
115128
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,200 @@
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.security.client.impl.pb;
19+
20+
import org.apache.hadoop.classification.InterfaceAudience;
21+
import org.apache.hadoop.classification.InterfaceStability;
22+
import org.apache.hadoop.io.Text;
23+
import org.apache.hadoop.thirdparty.protobuf.TextFormat;
24+
import org.apache.hadoop.yarn.proto.YarnSecurityTokenProtos.YARNDelegationTokenIdentifierProto;
25+
import org.apache.hadoop.yarn.proto.YarnSecurityTokenProtos.YARNDelegationTokenIdentifierProtoOrBuilder;
26+
import org.apache.hadoop.yarn.security.client.YARNDelegationTokenIdentifier;
27+
28+
@InterfaceAudience.Private
29+
@InterfaceStability.Unstable
30+
public class YARNDelegationTokenIdentifierPBImpl extends YARNDelegationTokenIdentifier {
31+
32+
private YARNDelegationTokenIdentifierProto proto =
33+
YARNDelegationTokenIdentifierProto.getDefaultInstance();
34+
private YARNDelegationTokenIdentifierProto.Builder builder = null;
35+
private boolean viaProto = false;
36+
37+
public YARNDelegationTokenIdentifierPBImpl() {
38+
builder = YARNDelegationTokenIdentifierProto.newBuilder();
39+
}
40+
41+
public YARNDelegationTokenIdentifierPBImpl(YARNDelegationTokenIdentifierProto identifierProto) {
42+
this.proto = identifierProto;
43+
viaProto = true;
44+
}
45+
46+
public YARNDelegationTokenIdentifierProto getProto() {
47+
mergeLocalToProto();
48+
proto = viaProto ? proto : builder.build();
49+
viaProto = true;
50+
return proto;
51+
}
52+
53+
private void mergeLocalToProto() {
54+
if (viaProto) {
55+
maybeInitBuilder();
56+
}
57+
// mergeLocalToBuilder();
58+
proto = builder.build();
59+
viaProto = true;
60+
}
61+
62+
@Override
63+
public String toString() {
64+
return TextFormat.shortDebugString(getProto());
65+
}
66+
67+
private void maybeInitBuilder() {
68+
if (viaProto || builder == null) {
69+
if (proto == null) {
70+
proto = YARNDelegationTokenIdentifierProto.getDefaultInstance();
71+
}
72+
builder = YARNDelegationTokenIdentifierProto.newBuilder(proto);
73+
}
74+
viaProto = false;
75+
}
76+
77+
@Override
78+
public Text getOwner() {
79+
YARNDelegationTokenIdentifierProtoOrBuilder p = viaProto ? proto : builder;
80+
return new Text(p.getOwner());
81+
}
82+
83+
@Override
84+
public void setOwner(Text owner) {
85+
super.setOwner(owner);
86+
maybeInitBuilder();
87+
if (owner == null) {
88+
builder.clearOwner();
89+
return;
90+
}
91+
builder.setOwner(owner.toString());
92+
}
93+
94+
@Override
95+
public Text getRenewer() {
96+
YARNDelegationTokenIdentifierProtoOrBuilder p = viaProto ? proto : builder;
97+
return new Text(p.getRenewer());
98+
}
99+
100+
@Override
101+
public void setRenewer(Text renewer) {
102+
super.setRenewer(renewer);
103+
maybeInitBuilder();
104+
if (renewer == null) {
105+
builder.clearRenewer();
106+
return;
107+
}
108+
builder.setOwner(renewer.toString());
109+
}
110+
111+
@Override
112+
public Text getRealUser() {
113+
YARNDelegationTokenIdentifierProtoOrBuilder p = viaProto ? proto : builder;
114+
return new Text(p.getRealUser());
115+
}
116+
117+
@Override
118+
public void setRealUser(Text realUser) {
119+
super.setRealUser(realUser);
120+
maybeInitBuilder();
121+
if (realUser == null) {
122+
builder.clearRealUser();
123+
return;
124+
}
125+
builder.setRealUser(realUser.toString());
126+
}
127+
128+
@Override
129+
public void setIssueDate(long issueDate) {
130+
super.setIssueDate(issueDate);
131+
maybeInitBuilder();
132+
builder.setIssueDate(issueDate);
133+
}
134+
135+
@Override
136+
public long getIssueDate() {
137+
YARNDelegationTokenIdentifierProtoOrBuilder p = viaProto ? proto : builder;
138+
return p.getIssueDate();
139+
}
140+
141+
@Override
142+
public void setMaxDate(long maxDate) {
143+
super.setMaxDate(maxDate);
144+
maybeInitBuilder();
145+
builder.setMaxDate(maxDate);
146+
}
147+
148+
@Override
149+
public long getMaxDate() {
150+
YARNDelegationTokenIdentifierProtoOrBuilder p = viaProto ? proto : builder;
151+
return p.getMaxDate();
152+
}
153+
154+
@Override
155+
public void setSequenceNumber(int seqNum) {
156+
super.setSequenceNumber(seqNum);
157+
maybeInitBuilder();
158+
builder.setSequenceNumber(seqNum);
159+
}
160+
161+
@Override
162+
public int getSequenceNumber() {
163+
YARNDelegationTokenIdentifierProtoOrBuilder p = viaProto ? proto : builder;
164+
return p.getSequenceNumber();
165+
}
166+
167+
@Override
168+
public void setMasterKeyId(int newId) {
169+
super.setMasterKeyId(newId);
170+
maybeInitBuilder();
171+
builder.setMasterKeyId(newId);
172+
}
173+
174+
@Override
175+
public int getMasterKeyId() {
176+
YARNDelegationTokenIdentifierProtoOrBuilder p = viaProto ? proto : builder;
177+
return p.getMasterKeyId();
178+
}
179+
180+
@Override
181+
public Text getKind() {
182+
return null;
183+
}
184+
185+
@Override
186+
public boolean equals(Object other) {
187+
if (other == null) {
188+
return false;
189+
}
190+
if (other.getClass().isAssignableFrom(this.getClass())) {
191+
return this.getProto().equals(this.getClass().cast(other).getProto());
192+
}
193+
return false;
194+
}
195+
196+
@Override
197+
public int hashCode() {
198+
return getProto().hashCode();
199+
}
200+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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+
@InterfaceAudience.Public
19+
package org.apache.hadoop.yarn.security.client.impl.pb;
20+
import org.apache.hadoop.classification.InterfaceAudience;

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/api/BasePBImplRecordsTest.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,12 @@
1818
package org.apache.hadoop.yarn.api;
1919

2020
import org.apache.commons.lang3.Range;
21+
import org.apache.hadoop.io.Text;
2122
import org.apache.hadoop.util.Lists;
2223
import org.apache.hadoop.util.Sets;
2324
import org.apache.hadoop.yarn.api.resource.PlacementConstraint;
2425
import org.apache.hadoop.yarn.api.resource.PlacementConstraints;
26+
import org.apache.hadoop.yarn.security.client.YARNDelegationTokenIdentifier;
2527

2628
import org.apache.hadoop.thirdparty.com.google.common.collect.Maps;
2729

@@ -80,6 +82,8 @@ private static Object genTypeValue(Type type) {
8082
'a' + rand.nextInt(26));
8183
} else if (type.equals(Float.class)) {
8284
return rand.nextFloat();
85+
} else if (type.equals(Text.class)) {
86+
return new Text('a' + String.valueOf(rand.nextInt(1000000)));
8387
} else if (type instanceof Class) {
8488
Class clazz = (Class)type;
8589
if (clazz.isArray()) {
@@ -167,7 +171,7 @@ protected static Object generateByNewInstance(Class clazz) throws Exception {
167171
" does not have newInstance method");
168172
}
169173
Object [] args = new Object[paramTypes.length];
170-
for (int i=0;i<args.length;i++) {
174+
for (int i = 0; i < args.length; i++) {
171175
args[i] = genTypeValue(paramTypes[i]);
172176
}
173177
ret = newInstance.invoke(null, args);

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/pom.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,9 @@
196196
<additionalProtoPathElement>
197197
${basedir}/../../hadoop-yarn-api/src/main/proto
198198
</additionalProtoPathElement>
199+
<additionalProtoPathElement>
200+
${basedir}/../../hadoop-yarn-common/src/main/proto
201+
</additionalProtoPathElement>
199202
</additionalProtoPathElements>
200203
</configuration>
201204
</execution>

0 commit comments

Comments
 (0)