YARNRunner implements ClientProtocol { @Override public JobStatus submitJob(JobID jobId, String jobSubmitDir, Credentials ts) throws IOException, InterruptedException { addHistoryToken(ts); ApplicationSubmissionContext appContext = createApplicationSubmissionContext(conf, jobSubmitDir, ts); try { ApplicationId applicationId = resMgrDelegate.submitApplication(appContext); ApplicationReport appMaster = resMgrDelegate .getApplicationReport(applicationId); String diagnostics = (appMaster == null ? "application report is null" : appMaster.getDiagnostics()); if (appMaster == null || appMaster.getYarnApplicationState() == YarnApplicationState.FAILED || appMaster.getYarnApplicationState() == YarnApplicationState.KILLED) { throw new IOException("Failed to run job : " + diagnostics); } return clientCache.getClient(jobId).getJobStatus(jobId); } catch (YarnException e) { throw new IOException(e); } } YARNRunner(Configuration conf);  YARNRunner(Configuration conf, ResourceMgrDelegate resMgrDelegate);  YARNRunner(Configuration conf, ResourceMgrDelegate resMgrDelegate,
      ClientCache clientCache); @Private /** * Used for testing mostly. * @param resMgrDelegate the resource manager delegate to set to. */ void setResourceMgrDelegate(ResourceMgrDelegate resMgrDelegate); @Override void cancelDelegationToken(Token<DelegationTokenIdentifier> arg0); @Override TaskTrackerInfo[] getActiveTrackers(); @Override JobStatus[] getAllJobs(); @Override TaskTrackerInfo[] getBlacklistedTrackers(); @Override ClusterMetrics getClusterMetrics(); @Override Token<DelegationTokenIdentifier> getDelegationToken(Text renewer); @Override String getFilesystemName(); @Override JobID getNewJobID(); @Override QueueInfo getQueue(String queueName); @Override QueueAclsInfo[] getQueueAclsForCurrentUser(); @Override QueueInfo[] getQueues(); @Override QueueInfo[] getRootQueues(); @Override QueueInfo[] getChildQueues(String parent); @Override String getStagingAreaDir(); @Override String getSystemDir(); @Override long getTaskTrackerExpiryInterval(); @Override JobStatus submitJob(JobID jobId, String jobSubmitDir, Credentials ts); ApplicationSubmissionContext createApplicationSubmissionContext(
      Configuration jobConf,
      String jobSubmitDir, Credentials ts); @Override void setJobPriority(JobID arg0, String arg1); @Override long getProtocolVersion(String arg0, long arg1); @Override long renewDelegationToken(Token<DelegationTokenIdentifier> arg0); @Override Counters getJobCounters(JobID arg0); @Override String getJobHistoryDir(); @Override JobStatus getJobStatus(JobID jobID); @Override TaskCompletionEvent[] getTaskCompletionEvents(JobID arg0, int arg1,
      int arg2); @Override String[] getTaskDiagnostics(TaskAttemptID arg0); @Override TaskReport[] getTaskReports(JobID jobID, TaskType taskType); @Override void killJob(JobID arg0); @Override boolean killTask(TaskAttemptID arg0, boolean arg1); @Override AccessControlList getQueueAdmins(String arg0); @Override JobTrackerStatus getJobTrackerStatus(); @Override ProtocolSignature getProtocolSignature(String protocol,
      long clientVersion, int clientMethodsHash); @Override LogParams getLogFileParams(JobID jobID, TaskAttemptID taskAttemptID); final static Priority AM_CONTAINER_PRIORITY; }
@Test(timeout=20000) public void testJobSubmissionFailure() throws Exception { when(resourceMgrDelegate.submitApplication(any(ApplicationSubmissionContext.class))). thenReturn(appId); ApplicationReport report = mock(ApplicationReport.class); when(report.getApplicationId()).thenReturn(appId); when(report.getDiagnostics()).thenReturn(failString); when(report.getYarnApplicationState()).thenReturn(YarnApplicationState.FAILED); when(resourceMgrDelegate.getApplicationReport(appId)).thenReturn(report); Credentials credentials = new Credentials(); File jobxml = new File(testWorkDir, "job.xml"); OutputStream out = new FileOutputStream(jobxml); conf.writeXml(out); out.close(); try { yarnRunner.submitJob(jobId, testWorkDir.getAbsolutePath().toString(), credentials); } catch(IOException io) { LOG.info("Logging exception:", io); assertTrue(io.getLocalizedMessage().contains(failString)); } }