Java Code Examples for org.apache.hadoop.security.proto.SecurityProtos.TokenProto

The following examples show how to use org.apache.hadoop.security.proto.SecurityProtos.TokenProto. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: hadoop   Source File: ShuffleHandler.java    License: Apache License 2.0 6 votes vote down vote up
private void recoverJobShuffleInfo(String jobIdStr, byte[] data)
    throws IOException {
  JobID jobId;
  try {
    jobId = JobID.forName(jobIdStr);
  } catch (IllegalArgumentException e) {
    throw new IOException("Bad job ID " + jobIdStr + " in state store", e);
  }

  JobShuffleInfoProto proto = JobShuffleInfoProto.parseFrom(data);
  String user = proto.getUser();
  TokenProto tokenProto = proto.getJobToken();
  Token<JobTokenIdentifier> jobToken = new Token<JobTokenIdentifier>(
      tokenProto.getIdentifier().toByteArray(),
      tokenProto.getPassword().toByteArray(),
      new Text(tokenProto.getKind()), new Text(tokenProto.getService()));
  addJobToken(jobId, user, jobToken);
}
 
Example 2
Source Project: hadoop   Source File: ShuffleHandler.java    License: Apache License 2.0 6 votes vote down vote up
private void recordJobShuffleInfo(JobID jobId, String user,
    Token<JobTokenIdentifier> jobToken) throws IOException {
  if (stateDb != null) {
    TokenProto tokenProto = TokenProto.newBuilder()
        .setIdentifier(ByteString.copyFrom(jobToken.getIdentifier()))
        .setPassword(ByteString.copyFrom(jobToken.getPassword()))
        .setKind(jobToken.getKind().toString())
        .setService(jobToken.getService().toString())
        .build();
    JobShuffleInfoProto proto = JobShuffleInfoProto.newBuilder()
        .setUser(user).setJobToken(tokenProto).build();
    try {
      stateDb.put(bytes(jobId.toString()), proto.toByteArray());
    } catch (DBException e) {
      throw new IOException("Error storing " + jobId, e);
    }
  }
  addJobToken(jobId, user, jobToken);
}
 
Example 3
Source Project: big-c   Source File: ShuffleHandler.java    License: Apache License 2.0 6 votes vote down vote up
private void recoverJobShuffleInfo(String jobIdStr, byte[] data)
    throws IOException {
  JobID jobId;
  try {
    jobId = JobID.forName(jobIdStr);
  } catch (IllegalArgumentException e) {
    throw new IOException("Bad job ID " + jobIdStr + " in state store", e);
  }

  JobShuffleInfoProto proto = JobShuffleInfoProto.parseFrom(data);
  String user = proto.getUser();
  TokenProto tokenProto = proto.getJobToken();
  Token<JobTokenIdentifier> jobToken = new Token<JobTokenIdentifier>(
      tokenProto.getIdentifier().toByteArray(),
      tokenProto.getPassword().toByteArray(),
      new Text(tokenProto.getKind()), new Text(tokenProto.getService()));
  addJobToken(jobId, user, jobToken);
}
 
Example 4
Source Project: big-c   Source File: ShuffleHandler.java    License: Apache License 2.0 6 votes vote down vote up
private void recordJobShuffleInfo(JobID jobId, String user,
    Token<JobTokenIdentifier> jobToken) throws IOException {
  if (stateDb != null) {
    TokenProto tokenProto = TokenProto.newBuilder()
        .setIdentifier(ByteString.copyFrom(jobToken.getIdentifier()))
        .setPassword(ByteString.copyFrom(jobToken.getPassword()))
        .setKind(jobToken.getKind().toString())
        .setService(jobToken.getService().toString())
        .build();
    JobShuffleInfoProto proto = JobShuffleInfoProto.newBuilder()
        .setUser(user).setJobToken(tokenProto).build();
    try {
      stateDb.put(bytes(jobId.toString()), proto.toByteArray());
    } catch (DBException e) {
      throw new IOException("Error storing " + jobId, e);
    }
  }
  addJobToken(jobId, user, jobToken);
}
 
Example 5
Source Project: tez   Source File: ShuffleHandler.java    License: Apache License 2.0 6 votes vote down vote up
private void recoverJobShuffleInfo(String jobIdStr, byte[] data)
    throws IOException {
  JobID jobId;
  try {
    jobId = JobID.forName(jobIdStr);
  } catch (IllegalArgumentException e) {
    throw new IOException("Bad job ID " + jobIdStr + " in state store", e);
  }

  JobShuffleInfoProto proto = JobShuffleInfoProto.parseFrom(data);
  String user = proto.getUser();
  TokenProto tokenProto = proto.getJobToken();
  Token<JobTokenIdentifier> jobToken = new Token<JobTokenIdentifier>(
      tokenProto.getIdentifier().toByteArray(),
      tokenProto.getPassword().toByteArray(),
      new Text(tokenProto.getKind()), new Text(tokenProto.getService()));
  addJobToken(jobId, user, jobToken);
}
 
Example 6
Source Project: tez   Source File: ShuffleHandler.java    License: Apache License 2.0 6 votes vote down vote up
private void recordJobShuffleInfo(JobID jobId, String user,
    Token<JobTokenIdentifier> jobToken) throws IOException {
  if (stateDb != null) {
    TokenProto tokenProto = TokenProto.newBuilder()
        .setIdentifier(ByteString.copyFrom(jobToken.getIdentifier()))
        .setPassword(ByteString.copyFrom(jobToken.getPassword()))
        .setKind(jobToken.getKind().toString())
        .setService(jobToken.getService().toString())
        .build();
    JobShuffleInfoProto proto = JobShuffleInfoProto.newBuilder()
        .setUser(user).setJobToken(tokenProto).build();
    try {
      stateDb.put(bytes(jobId.toString()), proto.toByteArray());
    } catch (DBException e) {
      throw new IOException("Error storing " + jobId, e);
    }
  }
  addJobToken(jobId, user, jobToken);
}
 
Example 7
Source Project: hadoop-ozone   Source File: OMPBHelper.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Converts Ozone delegation token to @{@link TokenProto}.
 * @return tokenProto
 */
public static TokenProto convertToTokenProto(Token<?> tok) {
  if(tok == null){
    throw new IllegalArgumentException("Invalid argument: token is null");
  }

  return TokenProto.newBuilder().
      setIdentifier(getByteString(tok.getIdentifier())).
      setPassword(getByteString(tok.getPassword())).
      setKind(tok.getKind().toString()).
      setService(tok.getService().toString()).build();
}
 
Example 8
Source Project: hadoop-ozone   Source File: OMPBHelper.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Converts @{@link TokenProto} to Ozone delegation token.
 *
 * @return Ozone
 */
public static Token<OzoneTokenIdentifier> convertToDelegationToken(
    TokenProto tokenProto) {
  return new Token<>(tokenProto.getIdentifier()
      .toByteArray(), tokenProto.getPassword().toByteArray(), new Text(
      tokenProto.getKind()), new Text(tokenProto.getService()));
}
 
Example 9
Source Project: hadoop   Source File: PBHelper.java    License: Apache License 2.0 5 votes vote down vote up
public static TokenProto convert(Token<?> tok) {
  return TokenProto.newBuilder().
            setIdentifier(ByteString.copyFrom(tok.getIdentifier())).
            setPassword(ByteString.copyFrom(tok.getPassword())).
            setKind(tok.getKind().toString()).
            setService(tok.getService().toString()).build(); 
}
 
Example 10
Source Project: hadoop   Source File: ClientDatanodeProtocolTranslatorPB.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public HdfsBlocksMetadata getHdfsBlocksMetadata(String blockPoolId,
    long[] blockIds,
    List<Token<BlockTokenIdentifier>> tokens) throws IOException {
  List<TokenProto> tokensProtos = 
      new ArrayList<TokenProto>(tokens.size());
  for (Token<BlockTokenIdentifier> t : tokens) {
    tokensProtos.add(PBHelper.convert(t));
  }
  // Build the request
  GetHdfsBlockLocationsRequestProto request = 
      GetHdfsBlockLocationsRequestProto.newBuilder()
      .setBlockPoolId(blockPoolId)
      .addAllBlockIds(Longs.asList(blockIds))
      .addAllTokens(tokensProtos)
      .build();
  // Send the RPC
  GetHdfsBlockLocationsResponseProto response;
  try {
    response = rpcProxy.getHdfsBlockLocations(NULL_CONTROLLER, request);
  } catch (ServiceException e) {
    throw ProtobufHelper.getRemoteException(e);
  }
  // List of volumes in the response
  List<ByteString> volumeIdsByteStrings = response.getVolumeIdsList();
  List<byte[]> volumeIds = new ArrayList<byte[]>(volumeIdsByteStrings.size());
  for (ByteString bs : volumeIdsByteStrings) {
    volumeIds.add(bs.toByteArray());
  }
  // Array of indexes into the list of volumes, one per block
  List<Integer> volumeIndexes = response.getVolumeIndexesList();
  // Parsed HdfsVolumeId values, one per block
  return new HdfsBlocksMetadata(blockPoolId, blockIds,
      volumeIds, volumeIndexes);
}
 
Example 11
Source Project: hadoop   Source File: TestPBHelper.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testConvertBlockToken() {
  Token<BlockTokenIdentifier> token = new Token<BlockTokenIdentifier>(
      "identifier".getBytes(), "password".getBytes(), new Text("kind"),
      new Text("service"));
  TokenProto tokenProto = PBHelper.convert(token);
  Token<BlockTokenIdentifier> token2 = PBHelper.convert(tokenProto);
  compare(token, token2);
}
 
Example 12
Source Project: big-c   Source File: PBHelper.java    License: Apache License 2.0 5 votes vote down vote up
public static TokenProto convert(Token<?> tok) {
  return TokenProto.newBuilder().
            setIdentifier(ByteString.copyFrom(tok.getIdentifier())).
            setPassword(ByteString.copyFrom(tok.getPassword())).
            setKind(tok.getKind().toString()).
            setService(tok.getService().toString()).build(); 
}
 
Example 13
Source Project: big-c   Source File: ClientDatanodeProtocolTranslatorPB.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public HdfsBlocksMetadata getHdfsBlocksMetadata(String blockPoolId,
    long[] blockIds,
    List<Token<BlockTokenIdentifier>> tokens) throws IOException {
  List<TokenProto> tokensProtos = 
      new ArrayList<TokenProto>(tokens.size());
  for (Token<BlockTokenIdentifier> t : tokens) {
    tokensProtos.add(PBHelper.convert(t));
  }
  // Build the request
  GetHdfsBlockLocationsRequestProto request = 
      GetHdfsBlockLocationsRequestProto.newBuilder()
      .setBlockPoolId(blockPoolId)
      .addAllBlockIds(Longs.asList(blockIds))
      .addAllTokens(tokensProtos)
      .build();
  // Send the RPC
  GetHdfsBlockLocationsResponseProto response;
  try {
    response = rpcProxy.getHdfsBlockLocations(NULL_CONTROLLER, request);
  } catch (ServiceException e) {
    throw ProtobufHelper.getRemoteException(e);
  }
  // List of volumes in the response
  List<ByteString> volumeIdsByteStrings = response.getVolumeIdsList();
  List<byte[]> volumeIds = new ArrayList<byte[]>(volumeIdsByteStrings.size());
  for (ByteString bs : volumeIdsByteStrings) {
    volumeIds.add(bs.toByteArray());
  }
  // Array of indexes into the list of volumes, one per block
  List<Integer> volumeIndexes = response.getVolumeIndexesList();
  // Parsed HdfsVolumeId values, one per block
  return new HdfsBlocksMetadata(blockPoolId, blockIds,
      volumeIds, volumeIndexes);
}
 
Example 14
Source Project: big-c   Source File: TestPBHelper.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testConvertBlockToken() {
  Token<BlockTokenIdentifier> token = new Token<BlockTokenIdentifier>(
      "identifier".getBytes(), "password".getBytes(), new Text("kind"),
      new Text("service"));
  TokenProto tokenProto = PBHelper.convert(token);
  Token<BlockTokenIdentifier> token2 = PBHelper.convert(tokenProto);
  compare(token, token2);
}
 
Example 15
Source Project: hadoop   Source File: CancelDelegationTokenRequestPBImpl.java    License: Apache License 2.0 4 votes vote down vote up
private TokenPBImpl convertFromProtoFormat(TokenProto p) {
  return new TokenPBImpl(p);
}
 
Example 16
Source Project: hadoop   Source File: CancelDelegationTokenRequestPBImpl.java    License: Apache License 2.0 4 votes vote down vote up
private TokenProto convertToProtoFormat(Token t) {
  return ((TokenPBImpl) t).getProto();
}
 
Example 17
Source Project: hadoop   Source File: GetDelegationTokenResponsePBImpl.java    License: Apache License 2.0 4 votes vote down vote up
private TokenPBImpl convertFromProtoFormat(TokenProto p) {
  return new TokenPBImpl(p);
}
 
Example 18
Source Project: hadoop   Source File: GetDelegationTokenResponsePBImpl.java    License: Apache License 2.0 4 votes vote down vote up
private TokenProto convertToProtoFormat(Token t) {
  return ((TokenPBImpl)t).getProto();
}
 
Example 19
Source Project: hadoop   Source File: RenewDelegationTokenRequestPBImpl.java    License: Apache License 2.0 4 votes vote down vote up
private TokenPBImpl convertFromProtoFormat(TokenProto p) {
  return new TokenPBImpl(p);
}
 
Example 20
Source Project: hadoop   Source File: RenewDelegationTokenRequestPBImpl.java    License: Apache License 2.0 4 votes vote down vote up
private TokenProto convertToProtoFormat(Token t) {
  return ((TokenPBImpl)t).getProto();
}
 
Example 21
Source Project: hadoop   Source File: StartContainerRequestPBImpl.java    License: Apache License 2.0 4 votes vote down vote up
private TokenPBImpl convertFromProtoFormat(TokenProto containerProto) {
  return new TokenPBImpl(containerProto);
}
 
Example 22
Source Project: hadoop   Source File: StartContainerRequestPBImpl.java    License: Apache License 2.0 4 votes vote down vote up
private TokenProto convertToProtoFormat(Token container) {
  return ((TokenPBImpl)container).getProto();
}
 
Example 23
Source Project: hadoop   Source File: AllocateResponsePBImpl.java    License: Apache License 2.0 4 votes vote down vote up
private TokenPBImpl convertFromProtoFormat(TokenProto p) {
  return new TokenPBImpl(p);
}
 
Example 24
Source Project: hadoop   Source File: AllocateResponsePBImpl.java    License: Apache License 2.0 4 votes vote down vote up
private TokenProto convertToProtoFormat(Token t) {
  return ((TokenPBImpl)t).getProto();
}
 
Example 25
Source Project: hadoop   Source File: ContainerPBImpl.java    License: Apache License 2.0 4 votes vote down vote up
private TokenPBImpl convertFromProtoFormat(TokenProto p) {
  return new TokenPBImpl(p);
}
 
Example 26
Source Project: hadoop   Source File: ContainerPBImpl.java    License: Apache License 2.0 4 votes vote down vote up
private TokenProto convertToProtoFormat(Token t) {
  return ((TokenPBImpl)t).getProto();
}
 
Example 27
Source Project: hadoop   Source File: TokenPBImpl.java    License: Apache License 2.0 4 votes vote down vote up
public TokenPBImpl() {
  builder = TokenProto.newBuilder();
}
 
Example 28
Source Project: hadoop   Source File: TokenPBImpl.java    License: Apache License 2.0 4 votes vote down vote up
public TokenPBImpl(TokenProto proto) {
  this.proto = proto;
  viaProto = true;
}
 
Example 29
Source Project: hadoop   Source File: TokenPBImpl.java    License: Apache License 2.0 4 votes vote down vote up
public synchronized TokenProto getProto() {
  mergeLocalToProto();
  proto = viaProto ? proto : builder.build();
  viaProto = true;
  return proto;
}
 
Example 30
Source Project: hadoop   Source File: TokenPBImpl.java    License: Apache License 2.0 4 votes vote down vote up
private synchronized void maybeInitBuilder() {
  if (viaProto || builder == null) {
    builder = TokenProto.newBuilder(proto);
  }
  viaProto = false;
}