Skip to content

Commit

Permalink
YARN-9708. Fix CodeStyle.
Browse files Browse the repository at this point in the history
  • Loading branch information
slfan1989 committed Aug 24, 2022
1 parent e945c64 commit c970950
Show file tree
Hide file tree
Showing 11 changed files with 187 additions and 151 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,9 @@
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.classification.InterfaceStability.Unstable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.security.token.delegation.AbstractDelegationTokenIdentifier;
import org.apache.hadoop.yarn.proto.YarnSecurityTokenProtos.YARNDelegationTokenIdentifierProto;
Expand Down Expand Up @@ -116,8 +115,8 @@ public YARNDelegationTokenIdentifierProto getProto() {
return builder.build();
}

@InterfaceAudience.Private
@InterfaceStability.Unstable
@Private
@Unstable
public static YARNDelegationTokenIdentifier newInstance(Text owner, Text renewer, Text realUser) {
YARNDelegationTokenIdentifier policy = Records.newRecord(YARNDelegationTokenIdentifier.class);
policy.setOwner(owner);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -391,11 +391,7 @@ public RouterMasterKeyResponse storeNewMasterKey(RouterMasterKeyRequest request)

// Restore the DelegationKey from the request
RouterMasterKey masterKey = request.getRouterMasterKey();
ByteBuffer keyByteBuf = masterKey.getKeyBytes();
byte[] keyBytes = new byte[keyByteBuf.remaining()];
keyByteBuf.get(keyBytes);
DelegationKey delegationKey =
new DelegationKey(masterKey.getKeyId(), masterKey.getExpiryDate(), keyBytes);
DelegationKey delegationKey = getDelegationKeyByMasterKey(masterKey);

Set<DelegationKey> rmDTMasterKeyState = routerRMSecretManagerState.getMasterKeyState();
if (rmDTMasterKeyState.contains(delegationKey)) {
Expand All @@ -417,11 +413,7 @@ public RouterMasterKeyResponse removeStoredMasterKey(RouterMasterKeyRequest requ

// Restore the DelegationKey from the request
RouterMasterKey masterKey = request.getRouterMasterKey();
ByteBuffer keyByteBuf = masterKey.getKeyBytes();
byte[] keyBytes = new byte[keyByteBuf.remaining()];
keyByteBuf.get(keyBytes);
DelegationKey delegationKey =
new DelegationKey(masterKey.getKeyId(), masterKey.getExpiryDate(), keyBytes);
DelegationKey delegationKey = getDelegationKeyByMasterKey(masterKey);

LOG.info("Remove Router-RMDT master key with key id: {}.", delegationKey.getKeyId());
Set<DelegationKey> rmDTMasterKeyState = routerRMSecretManagerState.getMasterKeyState();
Expand All @@ -433,13 +425,10 @@ public RouterMasterKeyResponse removeStoredMasterKey(RouterMasterKeyRequest requ
@Override
public RouterMasterKeyResponse getMasterKeyByDelegationKey(RouterMasterKeyRequest request)
throws YarnException, IOException {

// Restore the DelegationKey from the request
RouterMasterKey masterKey = request.getRouterMasterKey();
ByteBuffer keyByteBuf = masterKey.getKeyBytes();
byte[] keyBytes = new byte[keyByteBuf.remaining()];
keyByteBuf.get(keyBytes);
DelegationKey delegationKey =
new DelegationKey(masterKey.getKeyId(), masterKey.getExpiryDate(), keyBytes);
DelegationKey delegationKey = getDelegationKeyByMasterKey(masterKey);

Set<DelegationKey> rmDTMasterKeyState = routerRMSecretManagerState.getMasterKeyState();
if (!rmDTMasterKeyState.contains(delegationKey)) {
Expand Down Expand Up @@ -547,4 +536,17 @@ public DeleteReservationHomeSubClusterResponse deleteReservationHomeSubCluster(
reservations.remove(reservationId);
return DeleteReservationHomeSubClusterResponse.newInstance();
}

/**
* Get DelegationKey By based on MasterKey.
*
* @param masterKey masterKey
* @return DelegationKey
*/
private DelegationKey getDelegationKeyByMasterKey(RouterMasterKey masterKey) {
ByteBuffer keyByteBuf = masterKey.getKeyBytes();
byte[] keyBytes = new byte[keyByteBuf.remaining()];
keyByteBuf.get(keyBytes);
return new DelegationKey(masterKey.getKeyId(), masterKey.getExpiryDate(), keyBytes);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,21 @@
*/
package org.apache.hadoop.yarn.server.federation.store.records;

import org.apache.hadoop.classification.InterfaceAudience;
import org.apache.hadoop.classification.InterfaceStability;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.apache.hadoop.classification.InterfaceAudience.Private;
import org.apache.hadoop.classification.InterfaceAudience.Public;
import org.apache.hadoop.classification.InterfaceStability.Unstable;
import org.apache.hadoop.yarn.util.Records;

import java.nio.ByteBuffer;
import java.util.Arrays;

@InterfaceAudience.Private
@InterfaceStability.Unstable
@Private
@Unstable
public abstract class RouterMasterKey {

@InterfaceAudience.Private
@InterfaceStability.Unstable
@Private
@Unstable
public static RouterMasterKey newInstance(Integer keyId, ByteBuffer keyBytes, Long expiryDate) {
RouterMasterKey policy = Records.newRecord(RouterMasterKey.class);
policy.setKeyId(keyId);
Expand All @@ -38,8 +40,8 @@ public static RouterMasterKey newInstance(Integer keyId, ByteBuffer keyBytes, Lo
return policy;
}

@InterfaceAudience.Private
@InterfaceStability.Unstable
@Private
@Unstable
public static RouterMasterKey newInstance(RouterMasterKey masterKey) {
RouterMasterKey routerMasterKey = Records.newRecord(RouterMasterKey.class);
routerMasterKey.setKeyId(masterKey.getKeyId());
Expand All @@ -53,63 +55,62 @@ public static RouterMasterKey newInstance(RouterMasterKey masterKey) {
*
* @return MasterKeyId.
*/
@InterfaceAudience.Public
@InterfaceStability.Unstable
@Public
@Unstable
public abstract Integer getKeyId();

/**
* Set the keyId of the MasterKey.
*
* @param keyId MasterKeyId.
*/
@InterfaceAudience.Private
@InterfaceStability.Unstable
@Private
@Unstable
public abstract void setKeyId(Integer keyId);

/**
* Get the keyBytes of the DelegationKey.
*
* @return KeyBytes of the DelegationKey.
*/
@InterfaceAudience.Private
@InterfaceStability.Unstable
@Public
@Unstable
public abstract ByteBuffer getKeyBytes();

/**
* Set the keyBytes of the DelegationKey.
*
* @param keyBytes KeyBytes of the DelegationKey.
*/
@InterfaceAudience.Private
@InterfaceStability.Unstable
@Private
@Unstable
public abstract void setKeyBytes(ByteBuffer keyBytes);

/**
* Get the ExpiryDate of the DelegationKey.
*
* @return ExpiryDate of the DelegationKey.
*/
@InterfaceAudience.Private
@InterfaceStability.Unstable
@Private
@Unstable
public abstract Long getExpiryDate();

/**
* Set the expiryDate of the DelegationKey.
*
* @param expiryDate expiryDate of the DelegationKey.
*/
@InterfaceAudience.Private
@InterfaceStability.Unstable
@Private
@Unstable
public abstract void setExpiryDate(Long expiryDate);

@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + (int) (getExpiryDate() ^ (getExpiryDate() >>> 32));
result = prime * result + Arrays.hashCode(getKeyBytes().array());
result = prime * result + getKeyId();
return result;
return new HashCodeBuilder()
.append(this.getExpiryDate().longValue())
.append(this.getKeyId().intValue())
.append(getKeyBytes().array())
.hashCode();
}

@Override
Expand All @@ -120,9 +121,11 @@ public boolean equals(Object right) {
return false;
} else {
RouterMasterKey r = (RouterMasterKey) right;
return getKeyId().intValue() == r.getKeyId().intValue() &&
getExpiryDate().longValue() == r.getExpiryDate().longValue() &&
Arrays.equals(getKeyBytes().array(), r.getKeyBytes().array());
return new EqualsBuilder()
.append(this.getKeyId().intValue(), r.getKeyId().intValue())
.append(this.getExpiryDate().longValue(), this.getExpiryDate().longValue())
.append(getKeyBytes().array(),r.getKeyBytes())
.isEquals();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,28 @@
*/
package org.apache.hadoop.yarn.server.federation.store.records;

import org.apache.hadoop.classification.InterfaceAudience;
import org.apache.hadoop.classification.InterfaceStability;
import org.apache.hadoop.classification.InterfaceAudience.Private;
import org.apache.hadoop.classification.InterfaceAudience.Public;
import org.apache.hadoop.classification.InterfaceStability.Unstable;
import org.apache.hadoop.yarn.util.Records;

@InterfaceAudience.Private
@InterfaceStability.Unstable
@Private
@Unstable
public abstract class RouterMasterKeyRequest {

@InterfaceAudience.Private
@InterfaceStability.Unstable
@Private
@Unstable
public static RouterMasterKeyRequest newInstance(RouterMasterKey routerMasterKey) {
RouterMasterKeyRequest request = Records.newRecord(RouterMasterKeyRequest.class);
request.setRouterMasterKey(routerMasterKey);
return request;
}

@InterfaceAudience.Public
@InterfaceStability.Unstable
@Public
@Unstable
public abstract RouterMasterKey getRouterMasterKey();

@InterfaceAudience.Private
@InterfaceStability.Unstable
@Private
@Unstable
public abstract void setRouterMasterKey(RouterMasterKey routerMasterKey);

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,28 @@
*/
package org.apache.hadoop.yarn.server.federation.store.records;

import org.apache.hadoop.classification.InterfaceAudience;
import org.apache.hadoop.classification.InterfaceStability;
import org.apache.hadoop.classification.InterfaceAudience.Private;
import org.apache.hadoop.classification.InterfaceAudience.Public;
import org.apache.hadoop.classification.InterfaceStability.Unstable;
import org.apache.hadoop.yarn.util.Records;

@InterfaceAudience.Private
@InterfaceStability.Unstable
@Private
@Unstable
public abstract class RouterMasterKeyResponse {

@InterfaceAudience.Private
@InterfaceStability.Unstable
@Private
@Unstable
public static RouterMasterKeyResponse newInstance(RouterMasterKey masterKey) {
RouterMasterKeyResponse request =
Records.newRecord(RouterMasterKeyResponse.class);
RouterMasterKeyResponse request = Records.newRecord(RouterMasterKeyResponse.class);
request.setRouterMasterKey(masterKey);
return request;
}

@InterfaceAudience.Public
@InterfaceStability.Unstable
@Public
@Unstable
public abstract RouterMasterKey getRouterMasterKey();

@InterfaceAudience.Private
@InterfaceStability.Unstable
@Private
@Unstable
public abstract void setRouterMasterKey(RouterMasterKey masterKey);
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,9 @@
public class RouterRMDTSecretManagerState {

// DTIdentifier -> renewDate
private Map<RMDelegationTokenIdentifier, Long> delegationTokenState =
new HashMap<RMDelegationTokenIdentifier, Long>();
private Map<RMDelegationTokenIdentifier, Long> delegationTokenState = new HashMap<>();

private Set<DelegationKey> masterKeyState = new HashSet<DelegationKey>();
private Set<DelegationKey> masterKeyState = new HashSet<>();

private int dtSequenceNumber = 0;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,28 @@
*/
package org.apache.hadoop.yarn.server.federation.store.records;

import org.apache.hadoop.classification.InterfaceAudience;
import org.apache.hadoop.classification.InterfaceStability;
import org.apache.hadoop.classification.InterfaceAudience.Private;
import org.apache.hadoop.classification.InterfaceAudience.Public;
import org.apache.hadoop.classification.InterfaceStability.Unstable;
import org.apache.hadoop.yarn.util.Records;

@InterfaceAudience.Private
@InterfaceStability.Unstable
@Private
@Unstable
public abstract class RouterRMTokenRequest {

@InterfaceAudience.Private
@InterfaceStability.Unstable
@Private
@Unstable
public static RouterRMTokenRequest newInstance(RouterStoreToken routerStoreToken) {
RouterRMTokenRequest request = Records.newRecord(RouterRMTokenRequest.class);
request.setRouterStoreToken(routerStoreToken);
return request;
}

@InterfaceAudience.Public
@InterfaceStability.Unstable
@Public
@Unstable
public abstract RouterStoreToken getRouterStoreToken();

@InterfaceAudience.Private
@InterfaceStability.Unstable
@Private
@Unstable
public abstract void setRouterStoreToken(RouterStoreToken routerStoreToken);
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,28 @@
*/
package org.apache.hadoop.yarn.server.federation.store.records;

import org.apache.hadoop.classification.InterfaceAudience;
import org.apache.hadoop.classification.InterfaceStability;
import org.apache.hadoop.classification.InterfaceAudience.Private;
import org.apache.hadoop.classification.InterfaceAudience.Public;
import org.apache.hadoop.classification.InterfaceStability.Unstable;
import org.apache.hadoop.yarn.util.Records;

@InterfaceAudience.Private
@InterfaceStability.Unstable
@Private
@Unstable
public abstract class RouterRMTokenResponse {

@InterfaceAudience.Private
@InterfaceStability.Unstable
@Private
@Unstable
public static RouterRMTokenResponse newInstance(RouterStoreToken routerStoreToken) {
RouterRMTokenResponse request = Records.newRecord(RouterRMTokenResponse.class);
request.setRouterStoreToken(routerStoreToken);
return request;
}

@InterfaceAudience.Public
@InterfaceStability.Unstable
@Public
@Unstable
public abstract RouterStoreToken getRouterStoreToken();

@InterfaceAudience.Private
@InterfaceStability.Unstable
@Private
@Unstable
public abstract void setRouterStoreToken(RouterStoreToken routerStoreToken);
}
Loading

0 comments on commit c970950

Please sign in to comment.