Java Code Examples for org.apache.hadoop.yarn.ipc.RPCUtil#getRemoteException()

The following examples show how to use org.apache.hadoop.yarn.ipc.RPCUtil#getRemoteException() . 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: ClientRMService.java    From hadoop with 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 2
Source File: ClientRMService.java    From hadoop with 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 3
Source File: ContainerManagerImpl.java    From hadoop with 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 4
Source File: AdminService.java    From hadoop with 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 5
Source File: ClientRMService.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Override
public ReservationUpdateResponse updateReservation(
    ReservationUpdateRequest request) throws YarnException, IOException {
  // Check if reservation system is enabled
  checkReservationSytem(AuditConstants.UPDATE_RESERVATION_REQUEST);
  ReservationUpdateResponse response =
      recordFactory.newRecordInstance(ReservationUpdateResponse.class);
  // Validate the input
  Plan plan =
      rValidator.validateReservationUpdateRequest(reservationSystem, request);
  ReservationId reservationId = request.getReservationId();
  String queueName = reservationSystem.getQueueForReservation(reservationId);
  // Check ACLs
  String user =
      checkReservationACLs(queueName,
          AuditConstants.UPDATE_RESERVATION_REQUEST);
  // Try to update the reservation using default agent
  try {
    boolean result =
        plan.getReservationAgent().updateReservation(reservationId, user,
            plan, request.getReservationDefinition());
    if (!result) {
      String errMsg = "Unable to update reservation: " + reservationId;
      RMAuditLogger.logFailure(user,
          AuditConstants.UPDATE_RESERVATION_REQUEST, errMsg,
          "ClientRMService", errMsg);
      throw RPCUtil.getRemoteException(errMsg);
    }
  } catch (PlanningException e) {
    RMAuditLogger.logFailure(user, AuditConstants.UPDATE_RESERVATION_REQUEST,
        e.getMessage(), "ClientRMService",
        "Unable to update the reservation: " + reservationId);
    throw RPCUtil.getRemoteException(e);
  }
  RMAuditLogger.logSuccess(user, AuditConstants.UPDATE_RESERVATION_REQUEST,
      "ClientRMService: " + reservationId);
  return response;
}
 
Example 6
Source File: ClientRMService.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Override
public GetApplicationAttemptsResponse getApplicationAttempts(
    GetApplicationAttemptsRequest request) throws YarnException, IOException {
  ApplicationId appId = request.getApplicationId();
  UserGroupInformation callerUGI;
  try {
    callerUGI = UserGroupInformation.getCurrentUser();
  } catch (IOException ie) {
    LOG.info("Error getting UGI ", ie);
    throw RPCUtil.getRemoteException(ie);
  }
  RMApp application = this.rmContext.getRMApps().get(appId);
  if (application == null) {
    // If the RM doesn't have the application, throw
    // ApplicationNotFoundException and let client to handle.
    throw new ApplicationNotFoundException("Application with id '" + appId
        + "' doesn't exist in RM.");
  }
  boolean allowAccess = checkAccess(callerUGI, application.getUser(),
      ApplicationAccessType.VIEW_APP, application);
  GetApplicationAttemptsResponse response = null;
  if (allowAccess) {
    Map<ApplicationAttemptId, RMAppAttempt> attempts = application
        .getAppAttempts();
    List<ApplicationAttemptReport> listAttempts = 
      new ArrayList<ApplicationAttemptReport>();
    Iterator<Map.Entry<ApplicationAttemptId, RMAppAttempt>> iter = attempts
        .entrySet().iterator();
    while (iter.hasNext()) {
      listAttempts.add(iter.next().getValue()
          .createApplicationAttemptReport());
    }
    response = GetApplicationAttemptsResponse.newInstance(listAttempts);
  } else {
    throw new YarnException("User " + callerUGI.getShortUserName()
        + " does not have privilage to see this aplication " + appId);
  }
  return response;
}
 
Example 7
Source File: ClientRMService.java    From hadoop with Apache License 2.0 5 votes vote down vote up
/**
 * It gives response which includes application report if the application
 * present otherwise throws ApplicationNotFoundException.
 */
@Override
public GetApplicationReportResponse getApplicationReport(
    GetApplicationReportRequest request) throws YarnException {
  ApplicationId applicationId = request.getApplicationId();

  UserGroupInformation callerUGI;
  try {
    callerUGI = UserGroupInformation.getCurrentUser();
  } catch (IOException ie) {
    LOG.info("Error getting UGI ", ie);
    throw RPCUtil.getRemoteException(ie);
  }

  RMApp application = this.rmContext.getRMApps().get(applicationId);
  if (application == null) {
    // If the RM doesn't have the application, throw
    // ApplicationNotFoundException and let client to handle.
    throw new ApplicationNotFoundException("Application with id '"
        + applicationId + "' doesn't exist in RM.");
  }

  boolean allowAccess = checkAccess(callerUGI, application.getUser(),
      ApplicationAccessType.VIEW_APP, application);
  ApplicationReport report =
      application.createAndGetApplicationReport(callerUGI.getUserName(),
          allowAccess);

  GetApplicationReportResponse response = recordFactory
      .newRecordInstance(GetApplicationReportResponse.class);
  response.setApplicationReport(report);
  return response;
}
 
Example 8
Source File: TestApplicationMasterLauncher.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Override
public StartContainersResponse
    startContainers(StartContainersRequest requests)
        throws YarnException {
  StartContainerRequest request = requests.getStartContainerRequests().get(0);
  LOG.info("Container started by MyContainerManager: " + request);
  launched = true;
  Map<String, String> env =
      request.getContainerLaunchContext().getEnvironment();

  Token containerToken = request.getContainerToken();
  ContainerTokenIdentifier tokenId = null;

  try {
    tokenId = BuilderUtils.newContainerTokenIdentifier(containerToken);
  } catch (IOException e) {
    throw RPCUtil.getRemoteException(e);
  }

  ContainerId containerId = tokenId.getContainerID();
  containerIdAtContainerManager = containerId.toString();
  attemptIdAtContainerManager =
      containerId.getApplicationAttemptId().toString();
  nmHostAtContainerManager = tokenId.getNmHostAddress();
  submitTimeAtContainerManager =
      Long.parseLong(env.get(ApplicationConstants.APP_SUBMIT_TIME_ENV));
  maxAppAttempts =
      Integer.parseInt(env.get(ApplicationConstants.MAX_APP_ATTEMPTS_ENV));
  return StartContainersResponse.newInstance(
    new HashMap<String, ByteBuffer>(), new ArrayList<ContainerId>(),
    new HashMap<ContainerId, SerializedException>());
}
 
Example 9
Source File: AdminService.java    From hadoop with 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 10
Source File: AdminService.java    From hadoop with Apache License 2.0 5 votes vote down vote up
private UserGroupInformation checkAcls(String method) throws YarnException {
  try {
    return checkAccess(method);
  } catch (IOException ioe) {
    throw RPCUtil.getRemoteException(ioe);
  }
}
 
Example 11
Source File: ContainerManagerImpl.java    From hadoop with Apache License 2.0 5 votes vote down vote up
protected UserGroupInformation getRemoteUgi()
    throws YarnException {
  UserGroupInformation remoteUgi;
  try {
    remoteUgi = UserGroupInformation.getCurrentUser();
  } catch (IOException e) {
    String msg = "Cannot obtain the user-name. Got exception: "
        + StringUtils.stringifyException(e);
    LOG.warn(msg);
    throw RPCUtil.getRemoteException(msg);
  }
  return remoteUgi;
}
 
Example 12
Source File: NMClientImpl.java    From hadoop with Apache License 2.0 5 votes vote down vote up
private void addStartingContainer(StartedContainer startedContainer)
    throws YarnException {
  if (startedContainers.putIfAbsent(startedContainer.containerId,
      startedContainer) != null) {
    throw RPCUtil.getRemoteException("Container "
        + startedContainer.containerId.toString() + " is already started");
  }
  startedContainers
      .put(startedContainer.getContainerId(), startedContainer);
}
 
Example 13
Source File: ClientProtocolService.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Override
public UseSharedCacheResourceResponse use(
    UseSharedCacheResourceRequest request) throws YarnException,
    IOException {

  UseSharedCacheResourceResponse response =
      recordFactory.newRecordInstance(UseSharedCacheResourceResponse.class);

  UserGroupInformation callerUGI;
  try {
    callerUGI = UserGroupInformation.getCurrentUser();
  } catch (IOException ie) {
    LOG.info("Error getting UGI ", ie);
    throw RPCUtil.getRemoteException(ie);
  }

  String fileName =
      this.store.addResourceReference(request.getResourceKey(),
          new SharedCacheResourceReference(request.getAppId(),
              callerUGI.getShortUserName()));

  if (fileName != null) {
    response
        .setPath(getCacheEntryFilePath(request.getResourceKey(), fileName));
    this.metrics.incCacheHitCount();
  } else {
    this.metrics.incCacheMissCount();
  }

  return response;
}
 
Example 14
Source File: ClientRMService.java    From hadoop with Apache License 2.0 4 votes vote down vote up
@Override
public ReservationSubmissionResponse submitReservation(
    ReservationSubmissionRequest request) throws YarnException, IOException {
  // Check if reservation system is enabled
  checkReservationSytem(AuditConstants.SUBMIT_RESERVATION_REQUEST);
  ReservationSubmissionResponse response =
      recordFactory.newRecordInstance(ReservationSubmissionResponse.class);
  // Create a new Reservation Id
  ReservationId reservationId = reservationSystem.getNewReservationId();
  // Validate the input
  Plan plan =
      rValidator.validateReservationSubmissionRequest(reservationSystem,
          request, reservationId);
  // Check ACLs
  String queueName = request.getQueue();
  String user =
      checkReservationACLs(queueName,
          AuditConstants.SUBMIT_RESERVATION_REQUEST);
  try {
    // Try to place the reservation using the agent
    boolean result =
        plan.getReservationAgent().createReservation(reservationId, user,
            plan, request.getReservationDefinition());
    if (result) {
      // add the reservation id to valid ones maintained by reservation
      // system
      reservationSystem.setQueueForReservation(reservationId, queueName);
      // create the reservation synchronously if required
      refreshScheduler(queueName, request.getReservationDefinition(),
          reservationId.toString());
      // return the reservation id
      response.setReservationId(reservationId);
    }
  } catch (PlanningException e) {
    RMAuditLogger.logFailure(user, AuditConstants.SUBMIT_RESERVATION_REQUEST,
        e.getMessage(), "ClientRMService",
        "Unable to create the reservation: " + reservationId);
    throw RPCUtil.getRemoteException(e);
  }
  RMAuditLogger.logSuccess(user, AuditConstants.SUBMIT_RESERVATION_REQUEST,
      "ClientRMService: " + reservationId);
  return response;
}
 
Example 15
Source File: ContainerManagerImpl.java    From hadoop with Apache License 2.0 4 votes vote down vote up
/**
 * @param containerTokenIdentifier
 *          of the container to be started
 * @throws YarnException
 */
@Private
@VisibleForTesting
protected void authorizeStartRequest(NMTokenIdentifier nmTokenIdentifier,
    ContainerTokenIdentifier containerTokenIdentifier) throws YarnException {

  ContainerId containerId = containerTokenIdentifier.getContainerID();
  String containerIDStr = containerId.toString();
  boolean unauthorized = false;
  StringBuilder messageBuilder =
      new StringBuilder("Unauthorized request to start container. ");
  if (!nmTokenIdentifier.getApplicationAttemptId().getApplicationId().
      equals(containerId.getApplicationAttemptId().getApplicationId())) {
    unauthorized = true;
    messageBuilder.append("\nNMToken for application attempt : ")
      .append(nmTokenIdentifier.getApplicationAttemptId())
      .append(" was used for starting container with container token")
      .append(" issued for application attempt : ")
      .append(containerId.getApplicationAttemptId());
  } else if (!this.context.getContainerTokenSecretManager()
      .isValidStartContainerRequest(containerTokenIdentifier)) {
    // Is the container being relaunched? Or RPC layer let startCall with
    // tokens generated off old-secret through?
    unauthorized = true;
    messageBuilder.append("\n Attempt to relaunch the same ")
      .append("container with id ").append(containerIDStr).append(".");
  } else if (containerTokenIdentifier.getExpiryTimeStamp() < System
    .currentTimeMillis()) {
    // Ensure the token is not expired.
    unauthorized = true;
    messageBuilder.append("\nThis token is expired. current time is ")
      .append(System.currentTimeMillis()).append(" found ")
      .append(containerTokenIdentifier.getExpiryTimeStamp());
    messageBuilder.append("\nNote: System times on machines may be out of sync.")
      .append(" Check system time and time zones.");
  }
  if (unauthorized) {
    String msg = messageBuilder.toString();
    LOG.error(msg);
    throw RPCUtil.getRemoteException(msg);
  }
}
 
Example 16
Source File: ClientRMService.java    From hadoop with Apache License 2.0 4 votes vote down vote up
@Override
public GetApplicationAttemptReportResponse getApplicationAttemptReport(
    GetApplicationAttemptReportRequest request) throws YarnException,
    IOException {
  ApplicationAttemptId appAttemptId = request.getApplicationAttemptId();
  UserGroupInformation callerUGI;
  try {
    callerUGI = UserGroupInformation.getCurrentUser();
  } catch (IOException ie) {
    LOG.info("Error getting UGI ", ie);
    throw RPCUtil.getRemoteException(ie);
  }
  RMApp application = this.rmContext.getRMApps().get(
      appAttemptId.getApplicationId());
  if (application == null) {
    // If the RM doesn't have the application, throw
    // ApplicationNotFoundException and let client to handle.
    throw new ApplicationNotFoundException("Application with id '"
        + request.getApplicationAttemptId().getApplicationId()
        + "' doesn't exist in RM.");
  }

  boolean allowAccess = checkAccess(callerUGI, application.getUser(),
      ApplicationAccessType.VIEW_APP, application);
  GetApplicationAttemptReportResponse response = null;
  if (allowAccess) {
    RMAppAttempt appAttempt = application.getAppAttempts().get(appAttemptId);
    if (appAttempt == null) {
      throw new ApplicationAttemptNotFoundException(
          "ApplicationAttempt with id '" + appAttemptId +
          "' doesn't exist in RM.");
    }
    ApplicationAttemptReport attemptReport = appAttempt
        .createApplicationAttemptReport();
    response = GetApplicationAttemptReportResponse.newInstance(attemptReport);
  }else{
    throw new YarnException("User " + callerUGI.getShortUserName()
        + " does not have privilage to see this attempt " + appAttemptId);
  }
  return response;
}
 
Example 17
Source File: ClientRMService.java    From hadoop with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public MoveApplicationAcrossQueuesResponse moveApplicationAcrossQueues(
    MoveApplicationAcrossQueuesRequest request) throws YarnException {
  ApplicationId applicationId = request.getApplicationId();

  UserGroupInformation callerUGI;
  try {
    callerUGI = UserGroupInformation.getCurrentUser();
  } catch (IOException ie) {
    LOG.info("Error getting UGI ", ie);
    RMAuditLogger.logFailure("UNKNOWN", AuditConstants.MOVE_APP_REQUEST,
        "UNKNOWN", "ClientRMService" , "Error getting UGI",
        applicationId);
    throw RPCUtil.getRemoteException(ie);
  }

  RMApp application = this.rmContext.getRMApps().get(applicationId);
  if (application == null) {
    RMAuditLogger.logFailure(callerUGI.getUserName(),
        AuditConstants.MOVE_APP_REQUEST, "UNKNOWN", "ClientRMService",
        "Trying to move an absent application", applicationId);
    throw new ApplicationNotFoundException("Trying to move an absent"
        + " application " + applicationId);
  }

  if (!checkAccess(callerUGI, application.getUser(),
      ApplicationAccessType.MODIFY_APP, application)) {
    RMAuditLogger.logFailure(callerUGI.getShortUserName(),
        AuditConstants.MOVE_APP_REQUEST,
        "User doesn't have permissions to "
            + ApplicationAccessType.MODIFY_APP.toString(), "ClientRMService",
        AuditConstants.UNAUTHORIZED_USER, applicationId);
    throw RPCUtil.getRemoteException(new AccessControlException("User "
        + callerUGI.getShortUserName() + " cannot perform operation "
        + ApplicationAccessType.MODIFY_APP.name() + " on " + applicationId));
  }
  
  // Moves only allowed when app is in a state that means it is tracked by
  // the scheduler
  if (EnumSet.of(RMAppState.NEW, RMAppState.NEW_SAVING, RMAppState.FAILED,
      RMAppState.FINAL_SAVING, RMAppState.FINISHING, RMAppState.FINISHED,
      RMAppState.KILLED, RMAppState.KILLING, RMAppState.FAILED)
      .contains(application.getState())) {
    String msg = "App in " + application.getState() + " state cannot be moved.";
    RMAuditLogger.logFailure(callerUGI.getShortUserName(),
        AuditConstants.MOVE_APP_REQUEST, "UNKNOWN", "ClientRMService", msg);
    throw new YarnException(msg);
  }

  SettableFuture<Object> future = SettableFuture.create();
  this.rmContext.getDispatcher().getEventHandler().handle(
      new RMAppMoveEvent(applicationId, request.getTargetQueue(), future));
  
  try {
    Futures.get(future, YarnException.class);
  } catch (YarnException ex) {
    RMAuditLogger.logFailure(callerUGI.getShortUserName(),
        AuditConstants.MOVE_APP_REQUEST, "UNKNOWN", "ClientRMService",
        ex.getMessage());
    throw ex;
  }

  RMAuditLogger.logSuccess(callerUGI.getShortUserName(), 
      AuditConstants.MOVE_APP_REQUEST, "ClientRMService" , applicationId);
  MoveApplicationAcrossQueuesResponse response = recordFactory
      .newRecordInstance(MoveApplicationAcrossQueuesResponse.class);
  return response;
}
 
Example 18
Source File: ClientRMService.java    From hadoop with Apache License 2.0 4 votes vote down vote up
@Override
public SubmitApplicationResponse submitApplication(
    SubmitApplicationRequest request) throws YarnException {
  ApplicationSubmissionContext submissionContext = request
      .getApplicationSubmissionContext();
  ApplicationId applicationId = submissionContext.getApplicationId();

  // ApplicationSubmissionContext needs to be validated for safety - only
  // those fields that are independent of the RM's configuration will be
  // checked here, those that are dependent on RM configuration are validated
  // in RMAppManager.

  String user = null;
  try {
    // Safety
    user = UserGroupInformation.getCurrentUser().getShortUserName();
  } catch (IOException ie) {
    LOG.warn("Unable to get the current user.", ie);
    RMAuditLogger.logFailure(user, AuditConstants.SUBMIT_APP_REQUEST,
        ie.getMessage(), "ClientRMService",
        "Exception in submitting application", applicationId);
    throw RPCUtil.getRemoteException(ie);
  }

  // Check whether app has already been put into rmContext,
  // If it is, simply return the response
  if (rmContext.getRMApps().get(applicationId) != null) {
    LOG.info("This is an earlier submitted application: " + applicationId);
    return SubmitApplicationResponse.newInstance();
  }

  if (submissionContext.getQueue() == null) {
    submissionContext.setQueue(YarnConfiguration.DEFAULT_QUEUE_NAME);
  }
  if (submissionContext.getApplicationName() == null) {
    submissionContext.setApplicationName(
        YarnConfiguration.DEFAULT_APPLICATION_NAME);
  }
  if (submissionContext.getApplicationType() == null) {
    submissionContext
      .setApplicationType(YarnConfiguration.DEFAULT_APPLICATION_TYPE);
  } else {
    if (submissionContext.getApplicationType().length() > YarnConfiguration.APPLICATION_TYPE_LENGTH) {
      submissionContext.setApplicationType(submissionContext
        .getApplicationType().substring(0,
          YarnConfiguration.APPLICATION_TYPE_LENGTH));
    }
  }

  try {
    // call RMAppManager to submit application directly
    rmAppManager.submitApplication(submissionContext,
        System.currentTimeMillis(), user);

    LOG.info("Application with id " + applicationId.getId() + 
        " submitted by user " + user);
    RMAuditLogger.logSuccess(user, AuditConstants.SUBMIT_APP_REQUEST,
        "ClientRMService", applicationId);
  } catch (YarnException e) {
    LOG.info("Exception in submitting application with id " +
        applicationId.getId(), e);
    RMAuditLogger.logFailure(user, AuditConstants.SUBMIT_APP_REQUEST,
        e.getMessage(), "ClientRMService",
        "Exception in submitting application", applicationId);
    throw e;
  }

  SubmitApplicationResponse response = recordFactory
      .newRecordInstance(SubmitApplicationResponse.class);
  return response;
}
 
Example 19
Source File: ClientRMService.java    From hadoop with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public KillApplicationResponse forceKillApplication(
    KillApplicationRequest request) throws YarnException {

  ApplicationId applicationId = request.getApplicationId();

  UserGroupInformation callerUGI;
  try {
    callerUGI = UserGroupInformation.getCurrentUser();
  } catch (IOException ie) {
    LOG.info("Error getting UGI ", ie);
    RMAuditLogger.logFailure("UNKNOWN", AuditConstants.KILL_APP_REQUEST,
        "UNKNOWN", "ClientRMService" , "Error getting UGI",
        applicationId);
    throw RPCUtil.getRemoteException(ie);
  }

  RMApp application = this.rmContext.getRMApps().get(applicationId);
  if (application == null) {
    RMAuditLogger.logFailure(callerUGI.getUserName(),
        AuditConstants.KILL_APP_REQUEST, "UNKNOWN", "ClientRMService",
        "Trying to kill an absent application", applicationId);
    throw new ApplicationNotFoundException("Trying to kill an absent"
        + " application " + applicationId);
  }

  if (!checkAccess(callerUGI, application.getUser(),
      ApplicationAccessType.MODIFY_APP, application)) {
    RMAuditLogger.logFailure(callerUGI.getShortUserName(),
        AuditConstants.KILL_APP_REQUEST,
        "User doesn't have permissions to "
            + ApplicationAccessType.MODIFY_APP.toString(), "ClientRMService",
        AuditConstants.UNAUTHORIZED_USER, applicationId);
    throw RPCUtil.getRemoteException(new AccessControlException("User "
        + callerUGI.getShortUserName() + " cannot perform operation "
        + ApplicationAccessType.MODIFY_APP.name() + " on " + applicationId));
  }

  if (application.isAppFinalStateStored()) {
    RMAuditLogger.logSuccess(callerUGI.getShortUserName(),
        AuditConstants.KILL_APP_REQUEST, "ClientRMService", applicationId);
    return KillApplicationResponse.newInstance(true);
  }

  this.rmContext.getDispatcher().getEventHandler()
      .handle(new RMAppEvent(applicationId, RMAppEventType.KILL));

  // For UnmanagedAMs, return true so they don't retry
  return KillApplicationResponse.newInstance(
      application.getApplicationSubmissionContext().getUnmanagedAM());
}
 
Example 20
Source File: ClientRMService.java    From hadoop with Apache License 2.0 4 votes vote down vote up
@Override
public GetQueueInfoResponse getQueueInfo(GetQueueInfoRequest request)
    throws YarnException {
  UserGroupInformation callerUGI;
  try {
    callerUGI = UserGroupInformation.getCurrentUser();
  } catch (IOException ie) {
    LOG.info("Error getting UGI ", ie);
    throw RPCUtil.getRemoteException(ie);
  }

  GetQueueInfoResponse response =
    recordFactory.newRecordInstance(GetQueueInfoResponse.class);
  try {
    QueueInfo queueInfo = 
      scheduler.getQueueInfo(request.getQueueName(),  
          request.getIncludeChildQueues(), 
          request.getRecursive());
    List<ApplicationReport> appReports = EMPTY_APPS_REPORT;
    if (request.getIncludeApplications()) {
      List<ApplicationAttemptId> apps =
          scheduler.getAppsInQueue(request.getQueueName());
      appReports = new ArrayList<ApplicationReport>(apps.size());
      for (ApplicationAttemptId app : apps) {
        RMApp rmApp = rmContext.getRMApps().get(app.getApplicationId());
        if (rmApp != null) {
          // Check if user is allowed access to this app
          if (!checkAccess(callerUGI, rmApp.getUser(),
              ApplicationAccessType.VIEW_APP, rmApp)) {
            continue;
          }
          appReports.add(
              rmApp.createAndGetApplicationReport(
                  callerUGI.getUserName(), true));
        }          
      }
    }
    queueInfo.setApplications(appReports);
    response.setQueueInfo(queueInfo);
  } catch (IOException ioe) {
    LOG.info("Failed to getQueueInfo for " + request.getQueueName(), ioe);
  }
  
  return response;
}