Java Code Examples for org.apache.hadoop.yarn.server.utils.BuilderUtils#newDelegationToken()

The following examples show how to use org.apache.hadoop.yarn.server.utils.BuilderUtils#newDelegationToken() . 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 File: TestClientRMService.java    From hadoop with Apache License 2.0 6 votes vote down vote up
private void checkTokenRenewal(UserGroupInformation owner,
    UserGroupInformation renewer) throws IOException, YarnException {
  RMDelegationTokenIdentifier tokenIdentifier =
      new RMDelegationTokenIdentifier(
          new Text(owner.getUserName()), new Text(renewer.getUserName()), null);
  Token<?> token =
      new Token<RMDelegationTokenIdentifier>(tokenIdentifier, dtsm);
  org.apache.hadoop.yarn.api.records.Token dToken = BuilderUtils.newDelegationToken(
      token.getIdentifier(), token.getKind().toString(),
      token.getPassword(), token.getService().toString());
  RenewDelegationTokenRequest request =
      Records.newRecord(RenewDelegationTokenRequest.class);
  request.setDelegationToken(dToken);

  RMContext rmContext = mock(RMContext.class);
  ClientRMService rmService = new ClientRMService(
      rmContext, null, null, null, null, dtsm);
  rmService.renewDelegationToken(request);
}
 
Example 2
Source File: TestClientRMService.java    From hadoop with Apache License 2.0 6 votes vote down vote up
private void checkTokenCancellation(ClientRMService rmService,
    UserGroupInformation owner, UserGroupInformation renewer)
    throws IOException, YarnException {
  RMDelegationTokenIdentifier tokenIdentifier =
      new RMDelegationTokenIdentifier(new Text(owner.getUserName()),
        new Text(renewer.getUserName()), null);
  Token<?> token =
      new Token<RMDelegationTokenIdentifier>(tokenIdentifier, dtsm);
  org.apache.hadoop.yarn.api.records.Token dToken =
      BuilderUtils.newDelegationToken(token.getIdentifier(), token.getKind()
        .toString(), token.getPassword(), token.getService().toString());
  CancelDelegationTokenRequest request =
      Records.newRecord(CancelDelegationTokenRequest.class);
  request.setDelegationToken(dToken);
  rmService.cancelDelegationToken(request);
}
 
Example 3
Source File: TestClientRMService.java    From big-c with Apache License 2.0 6 votes vote down vote up
private void checkTokenRenewal(UserGroupInformation owner,
    UserGroupInformation renewer) throws IOException, YarnException {
  RMDelegationTokenIdentifier tokenIdentifier =
      new RMDelegationTokenIdentifier(
          new Text(owner.getUserName()), new Text(renewer.getUserName()), null);
  Token<?> token =
      new Token<RMDelegationTokenIdentifier>(tokenIdentifier, dtsm);
  org.apache.hadoop.yarn.api.records.Token dToken = BuilderUtils.newDelegationToken(
      token.getIdentifier(), token.getKind().toString(),
      token.getPassword(), token.getService().toString());
  RenewDelegationTokenRequest request =
      Records.newRecord(RenewDelegationTokenRequest.class);
  request.setDelegationToken(dToken);

  RMContext rmContext = mock(RMContext.class);
  ClientRMService rmService = new ClientRMService(
      rmContext, null, null, null, null, dtsm);
  rmService.renewDelegationToken(request);
}
 
Example 4
Source File: TestClientRMService.java    From big-c with Apache License 2.0 6 votes vote down vote up
private void checkTokenCancellation(ClientRMService rmService,
    UserGroupInformation owner, UserGroupInformation renewer)
    throws IOException, YarnException {
  RMDelegationTokenIdentifier tokenIdentifier =
      new RMDelegationTokenIdentifier(new Text(owner.getUserName()),
        new Text(renewer.getUserName()), null);
  Token<?> token =
      new Token<RMDelegationTokenIdentifier>(tokenIdentifier, dtsm);
  org.apache.hadoop.yarn.api.records.Token dToken =
      BuilderUtils.newDelegationToken(token.getIdentifier(), token.getKind()
        .toString(), token.getPassword(), token.getService().toString());
  CancelDelegationTokenRequest request =
      Records.newRecord(CancelDelegationTokenRequest.class);
  request.setDelegationToken(dToken);
  rmService.cancelDelegationToken(request);
}
 
Example 5
Source File: RMWebServices.java    From hadoop with Apache License 2.0 4 votes vote down vote up
private Response renewDelegationToken(DelegationToken tokenData,
    HttpServletRequest hsr, UserGroupInformation callerUGI)
    throws AuthorizationException, IOException, InterruptedException,
    Exception {

  Token<RMDelegationTokenIdentifier> token =
      extractToken(tokenData.getToken());

  org.apache.hadoop.yarn.api.records.Token dToken =
      BuilderUtils.newDelegationToken(token.getIdentifier(), token.getKind()
        .toString(), token.getPassword(), token.getService().toString());
  final RenewDelegationTokenRequest req =
      RenewDelegationTokenRequest.newInstance(dToken);

  RenewDelegationTokenResponse resp;
  try {
    resp =
        callerUGI
          .doAs(new PrivilegedExceptionAction<RenewDelegationTokenResponse>() {
            @Override
            public RenewDelegationTokenResponse run() throws IOException,
                YarnException {
              return rm.getClientRMService().renewDelegationToken(req);
            }
          });
  } catch (UndeclaredThrowableException ue) {
    if (ue.getCause() instanceof YarnException) {
      if (ue.getCause().getCause() instanceof InvalidToken) {
        throw new BadRequestException(ue.getCause().getCause().getMessage());
      } else if (ue.getCause().getCause() instanceof org.apache.hadoop.security.AccessControlException) {
        return Response.status(Status.FORBIDDEN)
          .entity(ue.getCause().getCause().getMessage()).build();
      }
      LOG.info("Renew delegation token request failed", ue);
      throw ue;
    }
    LOG.info("Renew delegation token request failed", ue);
    throw ue;
  } catch (Exception e) {
    LOG.info("Renew delegation token request failed", e);
    throw e;
  }
  long renewTime = resp.getNextExpirationTime();

  DelegationToken respToken = new DelegationToken();
  respToken.setNextExpirationTime(renewTime);
  return Response.status(Status.OK).entity(respToken).build();
}
 
Example 6
Source File: RMWebServices.java    From hadoop with Apache License 2.0 4 votes vote down vote up
@DELETE
@Path("/delegation-token")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response cancelDelegationToken(@Context HttpServletRequest hsr)
    throws AuthorizationException, IOException, InterruptedException,
    Exception {

  init();
  UserGroupInformation callerUGI;
  try {
    callerUGI = createKerberosUserGroupInformation(hsr);
  } catch (YarnException ye) {
    return Response.status(Status.FORBIDDEN).entity(ye.getMessage()).build();
  }

  Token<RMDelegationTokenIdentifier> token = extractToken(hsr);

  org.apache.hadoop.yarn.api.records.Token dToken =
      BuilderUtils.newDelegationToken(token.getIdentifier(), token.getKind()
        .toString(), token.getPassword(), token.getService().toString());
  final CancelDelegationTokenRequest req =
      CancelDelegationTokenRequest.newInstance(dToken);

  try {
    callerUGI
      .doAs(new PrivilegedExceptionAction<CancelDelegationTokenResponse>() {
        @Override
        public CancelDelegationTokenResponse run() throws IOException,
            YarnException {
          return rm.getClientRMService().cancelDelegationToken(req);
        }
      });
  } catch (UndeclaredThrowableException ue) {
    if (ue.getCause() instanceof YarnException) {
      if (ue.getCause().getCause() instanceof InvalidToken) {
        throw new BadRequestException(ue.getCause().getCause().getMessage());
      } else if (ue.getCause().getCause() instanceof org.apache.hadoop.security.AccessControlException) {
        return Response.status(Status.FORBIDDEN)
          .entity(ue.getCause().getCause().getMessage()).build();
      }
      LOG.info("Renew delegation token request failed", ue);
      throw ue;
    }
    LOG.info("Renew delegation token request failed", ue);
    throw ue;
  } catch (Exception e) {
    LOG.info("Renew delegation token request failed", e);
    throw e;
  }

  return Response.status(Status.OK).build();
}
 
Example 7
Source File: RMWebServices.java    From big-c with Apache License 2.0 4 votes vote down vote up
private Response renewDelegationToken(DelegationToken tokenData,
    HttpServletRequest hsr, UserGroupInformation callerUGI)
    throws AuthorizationException, IOException, InterruptedException,
    Exception {

  Token<RMDelegationTokenIdentifier> token =
      extractToken(tokenData.getToken());

  org.apache.hadoop.yarn.api.records.Token dToken =
      BuilderUtils.newDelegationToken(token.getIdentifier(), token.getKind()
        .toString(), token.getPassword(), token.getService().toString());
  final RenewDelegationTokenRequest req =
      RenewDelegationTokenRequest.newInstance(dToken);

  RenewDelegationTokenResponse resp;
  try {
    resp =
        callerUGI
          .doAs(new PrivilegedExceptionAction<RenewDelegationTokenResponse>() {
            @Override
            public RenewDelegationTokenResponse run() throws IOException,
                YarnException {
              return rm.getClientRMService().renewDelegationToken(req);
            }
          });
  } catch (UndeclaredThrowableException ue) {
    if (ue.getCause() instanceof YarnException) {
      if (ue.getCause().getCause() instanceof InvalidToken) {
        throw new BadRequestException(ue.getCause().getCause().getMessage());
      } else if (ue.getCause().getCause() instanceof org.apache.hadoop.security.AccessControlException) {
        return Response.status(Status.FORBIDDEN)
          .entity(ue.getCause().getCause().getMessage()).build();
      }
      LOG.info("Renew delegation token request failed", ue);
      throw ue;
    }
    LOG.info("Renew delegation token request failed", ue);
    throw ue;
  } catch (Exception e) {
    LOG.info("Renew delegation token request failed", e);
    throw e;
  }
  long renewTime = resp.getNextExpirationTime();

  DelegationToken respToken = new DelegationToken();
  respToken.setNextExpirationTime(renewTime);
  return Response.status(Status.OK).entity(respToken).build();
}
 
Example 8
Source File: RMWebServices.java    From big-c with Apache License 2.0 4 votes vote down vote up
@DELETE
@Path("/delegation-token")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response cancelDelegationToken(@Context HttpServletRequest hsr)
    throws AuthorizationException, IOException, InterruptedException,
    Exception {

  init();
  UserGroupInformation callerUGI;
  try {
    callerUGI = createKerberosUserGroupInformation(hsr);
  } catch (YarnException ye) {
    return Response.status(Status.FORBIDDEN).entity(ye.getMessage()).build();
  }

  Token<RMDelegationTokenIdentifier> token = extractToken(hsr);

  org.apache.hadoop.yarn.api.records.Token dToken =
      BuilderUtils.newDelegationToken(token.getIdentifier(), token.getKind()
        .toString(), token.getPassword(), token.getService().toString());
  final CancelDelegationTokenRequest req =
      CancelDelegationTokenRequest.newInstance(dToken);

  try {
    callerUGI
      .doAs(new PrivilegedExceptionAction<CancelDelegationTokenResponse>() {
        @Override
        public CancelDelegationTokenResponse run() throws IOException,
            YarnException {
          return rm.getClientRMService().cancelDelegationToken(req);
        }
      });
  } catch (UndeclaredThrowableException ue) {
    if (ue.getCause() instanceof YarnException) {
      if (ue.getCause().getCause() instanceof InvalidToken) {
        throw new BadRequestException(ue.getCause().getCause().getMessage());
      } else if (ue.getCause().getCause() instanceof org.apache.hadoop.security.AccessControlException) {
        return Response.status(Status.FORBIDDEN)
          .entity(ue.getCause().getCause().getMessage()).build();
      }
      LOG.info("Renew delegation token request failed", ue);
      throw ue;
    }
    LOG.info("Renew delegation token request failed", ue);
    throw ue;
  } catch (Exception e) {
    LOG.info("Renew delegation token request failed", e);
    throw e;
  }

  return Response.status(Status.OK).build();
}