Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

YARN-9708. Yarn Router Support DelegationToken. #4740

Closed
wants to merge 12 commits into from
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,14 @@
import java.io.DataOutputStream;
import java.io.IOException;

import org.apache.hadoop.classification.InterfaceAudience;
import org.apache.hadoop.classification.InterfaceStability;
import org.apache.hadoop.classification.VisibleForTesting;
import org.apache.hadoop.classification.InterfaceAudience.Private;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.security.token.delegation.AbstractDelegationTokenIdentifier;
import org.apache.hadoop.yarn.proto.YarnSecurityTokenProtos.YARNDelegationTokenIdentifierProto;
import org.apache.hadoop.yarn.util.Records;

@Private
public abstract class YARNDelegationTokenIdentifier extends
Expand Down Expand Up @@ -112,4 +115,14 @@ public YARNDelegationTokenIdentifierProto getProto() {
setBuilderFields();
return builder.build();
}

@InterfaceAudience.Private
@InterfaceStability.Unstable
public static YARNDelegationTokenIdentifier newInstance(Text owner, Text renewer, Text realUser) {
YARNDelegationTokenIdentifier policy = Records.newRecord(YARNDelegationTokenIdentifier.class);
policy.setOwner(owner);
policy.setRenewer(renewer);
policy.setRenewer(realUser);
return policy;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,200 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.hadoop.yarn.security.client.impl.pb;

import org.apache.hadoop.classification.InterfaceAudience;
import org.apache.hadoop.classification.InterfaceStability;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.thirdparty.protobuf.TextFormat;
import org.apache.hadoop.yarn.proto.YarnSecurityTokenProtos.YARNDelegationTokenIdentifierProto;
import org.apache.hadoop.yarn.proto.YarnSecurityTokenProtos.YARNDelegationTokenIdentifierProtoOrBuilder;
import org.apache.hadoop.yarn.security.client.YARNDelegationTokenIdentifier;

@InterfaceAudience.Private
@InterfaceStability.Unstable
public class YARNDelegationTokenIdentifierPBImpl extends YARNDelegationTokenIdentifier {

private YARNDelegationTokenIdentifierProto proto =
YARNDelegationTokenIdentifierProto.getDefaultInstance();
private YARNDelegationTokenIdentifierProto.Builder builder = null;
private boolean viaProto = false;

public YARNDelegationTokenIdentifierPBImpl() {
builder = YARNDelegationTokenIdentifierProto.newBuilder();
}

public YARNDelegationTokenIdentifierPBImpl(YARNDelegationTokenIdentifierProto identifierProto) {
this.proto = identifierProto;
viaProto = true;
}

public YARNDelegationTokenIdentifierProto getProto() {
mergeLocalToProto();
proto = viaProto ? proto : builder.build();
viaProto = true;
return proto;
}

private void mergeLocalToProto() {
if (viaProto) {
maybeInitBuilder();
}
// mergeLocalToBuilder();
proto = builder.build();
viaProto = true;
}

@Override
public String toString() {
return TextFormat.shortDebugString(getProto());
}

private void maybeInitBuilder() {
if (viaProto || builder == null) {
if (proto == null) {
proto = YARNDelegationTokenIdentifierProto.getDefaultInstance();
}
builder = YARNDelegationTokenIdentifierProto.newBuilder(proto);
}
viaProto = false;
}

@Override
public Text getOwner() {
YARNDelegationTokenIdentifierProtoOrBuilder p = viaProto ? proto : builder;
return new Text(p.getOwner());
}

@Override
public void setOwner(Text owner) {
super.setOwner(owner);
maybeInitBuilder();
if (owner == null) {
builder.clearOwner();
return;
}
builder.setOwner(owner.toString());
}

@Override
public Text getRenewer() {
YARNDelegationTokenIdentifierProtoOrBuilder p = viaProto ? proto : builder;
return new Text(p.getRenewer());
}

@Override
public void setRenewer(Text renewer) {
super.setRenewer(renewer);
maybeInitBuilder();
if (renewer == null) {
builder.clearRenewer();
return;
}
builder.setOwner(renewer.toString());
}

@Override
public Text getRealUser() {
YARNDelegationTokenIdentifierProtoOrBuilder p = viaProto ? proto : builder;
return new Text(p.getRealUser());
}

@Override
public void setRealUser(Text realUser) {
super.setRealUser(realUser);
maybeInitBuilder();
if (realUser == null) {
builder.clearRealUser();
return;
}
builder.setRealUser(realUser.toString());
}

@Override
public void setIssueDate(long issueDate) {
super.setIssueDate(issueDate);
maybeInitBuilder();
builder.setIssueDate(issueDate);
}

@Override
public long getIssueDate() {
YARNDelegationTokenIdentifierProtoOrBuilder p = viaProto ? proto : builder;
return p.getIssueDate();
}

@Override
public void setMaxDate(long maxDate) {
super.setMaxDate(maxDate);
maybeInitBuilder();
builder.setMaxDate(maxDate);
}

@Override
public long getMaxDate() {
YARNDelegationTokenIdentifierProtoOrBuilder p = viaProto ? proto : builder;
return p.getMaxDate();
}

@Override
public void setSequenceNumber(int seqNum) {
super.setSequenceNumber(seqNum);
maybeInitBuilder();
builder.setSequenceNumber(seqNum);
}

@Override
public int getSequenceNumber() {
YARNDelegationTokenIdentifierProtoOrBuilder p = viaProto ? proto : builder;
return p.getSequenceNumber();
}

@Override
public void setMasterKeyId(int newId) {
super.setMasterKeyId(newId);
maybeInitBuilder();
builder.setMasterKeyId(newId);
}

@Override
public int getMasterKeyId() {
YARNDelegationTokenIdentifierProtoOrBuilder p = viaProto ? proto : builder;
return p.getMasterKeyId();
}

@Override
public Text getKind() {
return null;
}

@Override
public boolean equals(Object other) {
if (other == null) {
return false;
}
if (other.getClass().isAssignableFrom(this.getClass())) {
return this.getProto().equals(this.getClass().cast(other).getProto());
}
return false;
}

@Override
public int hashCode() {
return getProto().hashCode();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
@InterfaceAudience.Public
package org.apache.hadoop.yarn.security.client.impl.pb;
import org.apache.hadoop.classification.InterfaceAudience;
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@
package org.apache.hadoop.yarn.api;

import org.apache.commons.lang3.Range;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.util.Lists;
import org.apache.hadoop.util.Sets;
import org.apache.hadoop.yarn.api.resource.PlacementConstraint;
import org.apache.hadoop.yarn.api.resource.PlacementConstraints;
import org.apache.hadoop.yarn.security.client.YARNDelegationTokenIdentifier;

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

Expand Down Expand Up @@ -80,6 +82,8 @@ private static Object genTypeValue(Type type) {
'a' + rand.nextInt(26));
} else if (type.equals(Float.class)) {
return rand.nextFloat();
} else if (type.equals(Text.class)) {
return new Text('a' + String.valueOf(rand.nextInt(1000000)));
} else if (type instanceof Class) {
Class clazz = (Class)type;
if (clazz.isArray()) {
Expand Down Expand Up @@ -167,7 +171,7 @@ protected static Object generateByNewInstance(Class clazz) throws Exception {
" does not have newInstance method");
}
Object [] args = new Object[paramTypes.length];
for (int i=0;i<args.length;i++) {
for (int i = 0; i < args.length; i++) {
args[i] = genTypeValue(paramTypes[i]);
}
ret = newInstance.invoke(null, args);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,9 @@
<additionalProtoPathElement>
${basedir}/../../hadoop-yarn-api/src/main/proto
</additionalProtoPathElement>
<additionalProtoPathElement>
${basedir}/../../hadoop-yarn-common/src/main/proto
</additionalProtoPathElement>
</additionalProtoPathElements>
</configuration>
</execution>
Expand Down
Loading