Java Code Examples for org.apache.hadoop.yarn.ipc.RPCUtil

The following examples show how to use org.apache.hadoop.yarn.ipc.RPCUtil. 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: ClientRMService.java    License: Apache License 2.0 6 votes vote down vote up
private String checkReservationACLs(String queueName, String auditConstant)
    throws YarnException {
  UserGroupInformation callerUGI;
  try {
    callerUGI = UserGroupInformation.getCurrentUser();
  } catch (IOException ie) {
    RMAuditLogger.logFailure("UNKNOWN", auditConstant, queueName,
        "ClientRMService", "Error getting UGI");
    throw RPCUtil.getRemoteException(ie);
  }
  // Check if user has access on the managed queue
  if (!queueACLsManager.checkAccess(callerUGI, QueueACL.SUBMIT_APPLICATIONS,
      queueName)) {
    RMAuditLogger.logFailure(
        callerUGI.getShortUserName(),
        auditConstant,
        "User doesn't have permissions to "
            + QueueACL.SUBMIT_APPLICATIONS.toString(), "ClientRMService",
        AuditConstants.UNAUTHORIZED_USER);
    throw RPCUtil.getRemoteException(new AccessControlException("User "
        + callerUGI.getShortUserName() + " cannot perform operation "
        + QueueACL.SUBMIT_APPLICATIONS.name() + " on queue" + queueName));
  }
  return callerUGI.getShortUserName();
}
 
Example 2
Source Project: hadoop   Source File: NMClientAsyncImpl.java    License: Apache License 2.0 6 votes vote down vote up
public void startContainerAsync(
    Container container, ContainerLaunchContext containerLaunchContext) {
  if (containers.putIfAbsent(container.getId(),
      new StatefulContainer(this, container.getId())) != null) {
    callbackHandler.onStartContainerError(container.getId(),
        RPCUtil.getRemoteException("Container " + container.getId() +
            " is already started or scheduled to start"));
  }
  try {
    events.put(new StartContainerEvent(container, containerLaunchContext));
  } catch (InterruptedException e) {
    LOG.warn("Exception when scheduling the event of starting Container " +
        container.getId());
    callbackHandler.onStartContainerError(container.getId(), e);
  }
}
 
Example 3
Source Project: hadoop   Source File: TestRPC.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public StartContainersResponse startContainers(
    StartContainersRequest requests) throws YarnException {
  StartContainersResponse response =
      recordFactory.newRecordInstance(StartContainersResponse.class);
  for (StartContainerRequest request : requests.getStartContainerRequests()) {
    Token containerToken = request.getContainerToken();
    ContainerTokenIdentifier tokenId = null;

    try {
      tokenId = newContainerTokenIdentifier(containerToken);
    } catch (IOException e) {
      throw RPCUtil.getRemoteException(e);
    }
    ContainerStatus status =
        recordFactory.newRecordInstance(ContainerStatus.class);
    status.setState(ContainerState.RUNNING);
    status.setContainerId(tokenId.getContainerID());
    status.setExitStatus(0);
    statuses.add(status);

  }
  return response;
}
 
Example 4
Source Project: hadoop   Source File: SCMAdminProtocolService.java    License: Apache License 2.0 6 votes vote down vote up
private void checkAcls(String method) throws YarnException {
  UserGroupInformation user;
  try {
    user = UserGroupInformation.getCurrentUser();
  } catch (IOException ioe) {
    LOG.warn("Couldn't get current user", ioe);
    throw RPCUtil.getRemoteException(ioe);
  }

  if (!authorizer.isAdmin(user)) {
    LOG.warn("User " + user.getShortUserName() + " doesn't have permission" +
        " to call '" + method + "'");

    throw RPCUtil.getRemoteException(
        new AccessControlException("User " + user.getShortUserName() +
        " doesn't have permission" + " to call '" + method + "'"));
  }
  LOG.info("SCM Admin: " + method + " invoked by user " +
      user.getShortUserName());
}
 
Example 5
Source Project: hadoop   Source File: ContainerManagerImpl.java    License: Apache License 2.0 6 votes vote down vote up
private ContainerStatus getContainerStatusInternal(ContainerId containerID,
    NMTokenIdentifier nmTokenIdentifier) throws YarnException {
  String containerIDStr = containerID.toString();
  Container container = this.context.getContainers().get(containerID);

  LOG.info("Getting container-status for " + containerIDStr);
  authorizeGetAndStopContainerRequest(containerID, container, false,
    nmTokenIdentifier);

  if (container == null) {
    if (nodeStatusUpdater.isContainerRecentlyStopped(containerID)) {
      throw RPCUtil.getRemoteException("Container " + containerIDStr
        + " was recently stopped on node manager.");
    } else {
      throw RPCUtil.getRemoteException("Container " + containerIDStr
        + " is not handled by this NodeManager");
    }
  }
  ContainerStatus containerStatus = container.cloneAndGetContainerStatus();
  LOG.info("Returning " + containerStatus);
  return containerStatus;
}
 
Example 6
Source Project: hadoop   Source File: ClientRMService.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public RenewDelegationTokenResponse renewDelegationToken(
    RenewDelegationTokenRequest request) throws YarnException {
  try {
    if (!isAllowedDelegationTokenOp()) {
      throw new IOException(
          "Delegation Token can be renewed only with kerberos authentication");
    }
    
    org.apache.hadoop.yarn.api.records.Token protoToken = request.getDelegationToken();
    Token<RMDelegationTokenIdentifier> token = new Token<RMDelegationTokenIdentifier>(
        protoToken.getIdentifier().array(), protoToken.getPassword().array(),
        new Text(protoToken.getKind()), new Text(protoToken.getService()));

    String user = getRenewerForToken(token);
    long nextExpTime = rmDTSecretManager.renewToken(token, user);
    RenewDelegationTokenResponse renewResponse = Records
        .newRecord(RenewDelegationTokenResponse.class);
    renewResponse.setNextExpirationTime(nextExpTime);
    return renewResponse;
  } catch (IOException e) {
    throw RPCUtil.getRemoteException(e);
  }
}
 
Example 7
Source Project: hadoop   Source File: ClientRMService.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public CancelDelegationTokenResponse cancelDelegationToken(
    CancelDelegationTokenRequest request) throws YarnException {
  try {
    if (!isAllowedDelegationTokenOp()) {
      throw new IOException(
          "Delegation Token can be cancelled only with kerberos authentication");
    }
    org.apache.hadoop.yarn.api.records.Token protoToken = request.getDelegationToken();
    Token<RMDelegationTokenIdentifier> token = new Token<RMDelegationTokenIdentifier>(
        protoToken.getIdentifier().array(), protoToken.getPassword().array(),
        new Text(protoToken.getKind()), new Text(protoToken.getService()));

    String user = UserGroupInformation.getCurrentUser().getUserName();
    rmDTSecretManager.cancelToken(token, user);
    return Records.newRecord(CancelDelegationTokenResponse.class);
  } catch (IOException e) {
    throw RPCUtil.getRemoteException(e);
  }
}
 
Example 8
@Override
public GetClusterSpecResponse getClusterSpec(GetClusterSpecRequest request) throws YarnException, IOException {
  GetClusterSpecRequestProto requestProto = ((GetClusterSpecRequestPBImpl) request).getProto();
  try {
    return new GetClusterSpecResponsePBImpl(proxy.getClusterSpec(null, requestProto));
  } catch (ServiceException e) {
    RPCUtil.unwrapAndThrowException(e);
    return null;
  }
}
 
Example 9
@Override
public AllocateResponse allocate(AllocateRequest request)
    throws YarnException, IOException {
  AllocateRequestProto requestProto =
      ((AllocateRequestPBImpl) request).getProto();
  try {
    return new AllocateResponsePBImpl(proxy.allocate(null, requestProto));
  } catch (ServiceException e) {
    RPCUtil.unwrapAndThrowException(e);
    return null;
  }
}
 
Example 10
@Override
public FinishApplicationMasterResponse finishApplicationMaster(
    FinishApplicationMasterRequest request) throws YarnException,
    IOException {
  FinishApplicationMasterRequestProto requestProto =
      ((FinishApplicationMasterRequestPBImpl) request).getProto();
  try {
    return new FinishApplicationMasterResponsePBImpl(
      proxy.finishApplicationMaster(null, requestProto));
  } catch (ServiceException e) {
    RPCUtil.unwrapAndThrowException(e);
    return null;
  }
}
 
Example 11
Source Project: hadoop   Source File: AdminService.java    License: Apache License 2.0 5 votes vote down vote up
private YarnException logAndWrapException(IOException ioe, String user,
    String argName, String msg) throws YarnException {
  LOG.info("Exception " + msg, ioe);
  RMAuditLogger.logFailure(user, argName, "", 
      "AdminService", "Exception " + msg);
  return RPCUtil.getRemoteException(ioe);
}
 
Example 12
@Override
public GetApplicationsResponse
    getApplications(GetApplicationsRequest request) throws YarnException,
        IOException {
  GetApplicationsRequestProto requestProto =
      ((GetApplicationsRequestPBImpl) request).getProto();
  try {
    return new GetApplicationsResponsePBImpl(proxy.getApplications(null,
      requestProto));
  } catch (ServiceException e) {
    RPCUtil.unwrapAndThrowException(e);
    return null;
  }
}
 
Example 13
@Override
public GetApplicationAttemptReportResponse getApplicationAttemptReport(
    GetApplicationAttemptReportRequest request) throws YarnException,
    IOException {
  GetApplicationAttemptReportRequestProto requestProto =
      ((GetApplicationAttemptReportRequestPBImpl) request).getProto();
  try {
    return new GetApplicationAttemptReportResponsePBImpl(
      proxy.getApplicationAttemptReport(null, requestProto));
  } catch (ServiceException e) {
    RPCUtil.unwrapAndThrowException(e);
    return null;
  }
}
 
Example 14
@Override
public GetApplicationAttemptsResponse getApplicationAttempts(
    GetApplicationAttemptsRequest request) throws YarnException, IOException {
  GetApplicationAttemptsRequestProto requestProto =
      ((GetApplicationAttemptsRequestPBImpl) request).getProto();
  try {
    return new GetApplicationAttemptsResponsePBImpl(
      proxy.getApplicationAttempts(null, requestProto));
  } catch (ServiceException e) {
    RPCUtil.unwrapAndThrowException(e);
    return null;
  }
}
 
Example 15
@Override
public GetContainerReportResponse getContainerReport(
    GetContainerReportRequest request) throws YarnException, IOException {
  GetContainerReportRequestProto requestProto =
      ((GetContainerReportRequestPBImpl) request).getProto();
  try {
    return new GetContainerReportResponsePBImpl(proxy.getContainerReport(
      null, requestProto));
  } catch (ServiceException e) {
    RPCUtil.unwrapAndThrowException(e);
    return null;
  }
}
 
Example 16
@Override
public GetContainersResponse getContainers(GetContainersRequest request)
    throws YarnException, IOException {
  GetContainersRequestProto requestProto =
      ((GetContainersRequestPBImpl) request).getProto();
  try {
    return new GetContainersResponsePBImpl(proxy.getContainers(null,
      requestProto));
  } catch (ServiceException e) {
    RPCUtil.unwrapAndThrowException(e);
    return null;
  }
}
 
Example 17
Source Project: hadoop   Source File: TestNMClientAsync.java    License: Apache License 2.0 5 votes vote down vote up
private NMClient mockNMClient(int mode)
    throws YarnException, IOException {
  NMClient client = mock(NMClient.class);
  switch (mode) {
    case 0:
      when(client.startContainer(any(Container.class),
          any(ContainerLaunchContext.class))).thenReturn(
              Collections.<String, ByteBuffer>emptyMap());
      when(client.getContainerStatus(any(ContainerId.class),
          any(NodeId.class))).thenReturn(
              recordFactory.newRecordInstance(ContainerStatus.class));
      doNothing().when(client).stopContainer(any(ContainerId.class),
          any(NodeId.class));
      break;
    case 1:
      doThrow(RPCUtil.getRemoteException("Start Exception")).when(client)
          .startContainer(any(Container.class),
              any(ContainerLaunchContext.class));
      doThrow(RPCUtil.getRemoteException("Query Exception")).when(client)
          .getContainerStatus(any(ContainerId.class), any(NodeId.class));
      doThrow(RPCUtil.getRemoteException("Stop Exception")).when(client)
          .stopContainer(any(ContainerId.class), any(NodeId.class));
      break;
    case 2:
      when(client.startContainer(any(Container.class),
          any(ContainerLaunchContext.class))).thenReturn(
              Collections.<String, ByteBuffer>emptyMap());
      when(client.getContainerStatus(any(ContainerId.class),
          any(NodeId.class))).thenReturn(
              recordFactory.newRecordInstance(ContainerStatus.class));
      doThrow(RPCUtil.getRemoteException("Stop Exception")).when(client)
          .stopContainer(any(ContainerId.class), any(NodeId.class));
  }
  return client;
}
 
Example 18
@Override
public RenewDelegationTokenResponse renewDelegationToken(
    RenewDelegationTokenRequest request) throws YarnException, IOException {
  RenewDelegationTokenRequestProto requestProto =
      ((RenewDelegationTokenRequestPBImpl) request).getProto();
  try {
    return new RenewDelegationTokenResponsePBImpl(proxy.renewDelegationToken(
      null, requestProto));
  } catch (ServiceException e) {
    RPCUtil.unwrapAndThrowException(e);
    return null;
  }
}
 
Example 19
@Override
public CancelDelegationTokenResponse cancelDelegationToken(
    CancelDelegationTokenRequest request) throws YarnException, IOException {
  CancelDelegationTokenRequestProto requestProto =
      ((CancelDelegationTokenRequestPBImpl) request).getProto();
  try {
    return new CancelDelegationTokenResponsePBImpl(
      proxy.cancelDelegationToken(null, requestProto));

  } catch (ServiceException e) {
    RPCUtil.unwrapAndThrowException(e);
    return null;
  }
}
 
Example 20
Source Project: hadoop   Source File: ClientSCMProtocolPBClientImpl.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public UseSharedCacheResourceResponse use(
    UseSharedCacheResourceRequest request) throws YarnException, IOException {
  UseSharedCacheResourceRequestProto requestProto =
      ((UseSharedCacheResourceRequestPBImpl) request).getProto();
  try {
    return new UseSharedCacheResourceResponsePBImpl(proxy.use(null,
        requestProto));
  } catch (ServiceException e) {
    RPCUtil.unwrapAndThrowException(e);
    return null;
  }
}
 
Example 21
Source Project: hadoop   Source File: ClientSCMProtocolPBClientImpl.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public ReleaseSharedCacheResourceResponse release(
    ReleaseSharedCacheResourceRequest request) throws YarnException,
    IOException {
  ReleaseSharedCacheResourceRequestProto requestProto =
      ((ReleaseSharedCacheResourceRequestPBImpl) request).getProto();
  try {
    return new ReleaseSharedCacheResourceResponsePBImpl(proxy.release(null,
        requestProto));
  } catch (ServiceException e) {
    RPCUtil.unwrapAndThrowException(e);
    return null;
  }
}
 
Example 22
@Override
public StartContainersResponse
    startContainers(StartContainersRequest requests) throws YarnException,
        IOException {
  StartContainersRequestProto requestProto =
      ((StartContainersRequestPBImpl) requests).getProto();
  try {
    return new StartContainersResponsePBImpl(proxy.startContainers(null,
      requestProto));
  } catch (ServiceException e) {
    RPCUtil.unwrapAndThrowException(e);
    return null;
  }
}
 
Example 23
@Override
public StopContainersResponse stopContainers(StopContainersRequest requests)
    throws YarnException, IOException {
  StopContainersRequestProto requestProto =
      ((StopContainersRequestPBImpl) requests).getProto();
  try {
    return new StopContainersResponsePBImpl(proxy.stopContainers(null,
      requestProto));
  } catch (ServiceException e) {
    RPCUtil.unwrapAndThrowException(e);
    return null;
  }
}
 
Example 24
@Override
public GetContainerStatusesResponse getContainerStatuses(
    GetContainerStatusesRequest request) throws YarnException, IOException {
  GetContainerStatusesRequestProto requestProto =
      ((GetContainerStatusesRequestPBImpl) request).getProto();
  try {
    return new GetContainerStatusesResponsePBImpl(proxy.getContainerStatuses(
      null, requestProto));
  } catch (ServiceException e) {
    RPCUtil.unwrapAndThrowException(e);
    return null;
  }
}
 
Example 25
@Override
public KillApplicationResponse forceKillApplication(
    KillApplicationRequest request) throws YarnException, IOException {
  KillApplicationRequestProto requestProto =
      ((KillApplicationRequestPBImpl) request).getProto();
  try {
    return new KillApplicationResponsePBImpl(proxy.forceKillApplication(null,
      requestProto));
  } catch (ServiceException e) {
    RPCUtil.unwrapAndThrowException(e);
    return null;
  }
}
 
Example 26
Source Project: hadoop   Source File: ClientRMService.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public ReservationDeleteResponse deleteReservation(
    ReservationDeleteRequest request) throws YarnException, IOException {
  // Check if reservation system is enabled
  checkReservationSytem(AuditConstants.DELETE_RESERVATION_REQUEST);
  ReservationDeleteResponse response =
      recordFactory.newRecordInstance(ReservationDeleteResponse.class);
  // Validate the input
  Plan plan =
      rValidator.validateReservationDeleteRequest(reservationSystem, request);
  ReservationId reservationId = request.getReservationId();
  String queueName = reservationSystem.getQueueForReservation(reservationId);
  // Check ACLs
  String user =
      checkReservationACLs(queueName,
          AuditConstants.DELETE_RESERVATION_REQUEST);
  // Try to update the reservation using default agent
  try {
    boolean result =
        plan.getReservationAgent().deleteReservation(reservationId, user,
            plan);
    if (!result) {
      String errMsg = "Could not delete reservation: " + reservationId;
      RMAuditLogger.logFailure(user,
          AuditConstants.DELETE_RESERVATION_REQUEST, errMsg,
          "ClientRMService", errMsg);
      throw RPCUtil.getRemoteException(errMsg);
    }
  } catch (PlanningException e) {
    RMAuditLogger.logFailure(user, AuditConstants.DELETE_RESERVATION_REQUEST,
        e.getMessage(), "ClientRMService",
        "Unable to delete the reservation: " + reservationId);
    throw RPCUtil.getRemoteException(e);
  }
  RMAuditLogger.logSuccess(user, AuditConstants.DELETE_RESERVATION_REQUEST,
      "ClientRMService: " + reservationId);
  return response;
}
 
Example 27
Source Project: hadoop   Source File: AdminService.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public RefreshServiceAclsResponse refreshServiceAcls(
    RefreshServiceAclsRequest request) throws YarnException, IOException {
  if (!getConfig().getBoolean(
           CommonConfigurationKeysPublic.HADOOP_SECURITY_AUTHORIZATION, 
           false)) {
    throw RPCUtil.getRemoteException(
        new IOException("Service Authorization (" + 
            CommonConfigurationKeysPublic.HADOOP_SECURITY_AUTHORIZATION + 
            ") not enabled."));
  }

  String argName = "refreshServiceAcls";
  UserGroupInformation user = checkAcls(argName);

  checkRMStatus(user.getShortUserName(), argName, "refresh Service ACLs.");

  PolicyProvider policyProvider = RMPolicyProvider.getInstance();
  Configuration conf =
      getConfiguration(new Configuration(false),
          YarnConfiguration.HADOOP_POLICY_CONFIGURATION_FILE);

  refreshServiceAcls(conf, policyProvider);
  rmContext.getClientRMService().refreshServiceAcls(conf, policyProvider);
  rmContext.getApplicationMasterService().refreshServiceAcls(
      conf, policyProvider);
  rmContext.getResourceTrackerService().refreshServiceAcls(
      conf, policyProvider);

  RMAuditLogger.logSuccess(user.getShortUserName(), argName, "AdminService");

  return recordFactory.newRecordInstance(RefreshServiceAclsResponse.class);
}
 
Example 28
@Override
public SubmitApplicationResponse submitApplication(
    SubmitApplicationRequest request) throws YarnException,
    IOException {
  SubmitApplicationRequestProto requestProto =
      ((SubmitApplicationRequestPBImpl) request).getProto();
  try {
    return new SubmitApplicationResponsePBImpl(proxy.submitApplication(null,
      requestProto));
  } catch (ServiceException e) {
    RPCUtil.unwrapAndThrowException(e);
    return null;
  }
}
 
Example 29
@Override
public GetApplicationsResponse getApplications(
    GetApplicationsRequest request) throws YarnException,
    IOException {
  GetApplicationsRequestProto requestProto =
      ((GetApplicationsRequestPBImpl) request).getProto();
  try {
    return new GetApplicationsResponsePBImpl(proxy.getApplications(
      null, requestProto));
  } catch (ServiceException e) {
    RPCUtil.unwrapAndThrowException(e);
    return null;
  }
}
 
Example 30
@Override
public GetClusterNodesResponse
    getClusterNodes(GetClusterNodesRequest request)
        throws YarnException, IOException {
  GetClusterNodesRequestProto requestProto =
      ((GetClusterNodesRequestPBImpl) request).getProto();
  try {
    return new GetClusterNodesResponsePBImpl(proxy.getClusterNodes(null,
      requestProto));
  } catch (ServiceException e) {
    RPCUtil.unwrapAndThrowException(e);
    return null;
  }
}