List of usage examples for org.apache.hadoop.yarn.api.records ContainerReport getLogUrl
@Public @Unstable public abstract String getLogUrl();
From source file:probos.TestProblem.java
License:Open Source License
void dotest(int N, String defn) throws Exception { if (System.getenv("HADOOP_HOME") == null && System.getenv("HADOOP_COMMON_HOME") == null) fail("HADOOP_HOME must be set"); if (System.getenv("JAVA_HOME") == null) fail("JAVA_HOME must be set"); File luaFile = File.createTempFile("kittenFile", ".lua"); FileWriter w = new FileWriter(luaFile); w.write(defn);//from w w w . j a va 2 s . com w.close(); Map<String, Object> extraLuaValues = ImmutableMap.<String, Object>of(); Map<String, String> extraLocalResources = ImmutableMap.<String, String>of(); YarnClientParameters params = new LuaYarnClientParameters(luaFile.toString(), "probos", yConf, extraLuaValues, extraLocalResources); YarnClientService service = new YarnClientServiceImpl(params); service.startAndWait(); while (!service.isApplicationFinished()) { Thread.sleep(1000); } assertEquals(FinalApplicationStatus.SUCCEEDED, service.getFinalReport().getFinalApplicationStatus()); ApplicationAttemptId aaid = service.getFinalReport().getCurrentApplicationAttemptId(); YarnClient yc = new YarnClientFactory(this.yConf).connect(); List<ContainerReport> lcr = yc.getContainers(aaid); for (ContainerReport cr : lcr) { String stdErrURL = "http:" + cr.getLogUrl() + "/stderr?start=0"; System.err.println(cr.getContainerId().toString() + " " + stdErrURL); String stderr = getURL(stdErrURL); System.err.println(stderr); assertFalse("Container" + cr.getContainerId().toString() + " " + stderr, stderr.contains("ArrayIndexOutOfBoundsException")); } //service.getFinalReport().get System.err.println(); Thread.sleep(60000); for (int id = 1; id <= N; id++) for (String type : new String[] { "o", "e" }) { String file = HERE + "/testHostname." + type + "1-" + id; assertTrue("File not found " + file, new File(file).exists()); } }
From source file:uk.ac.gla.terrier.probos.controller.ControllerServer.java
License:Open Source License
@Override public byte[] jobLog(int jobid, int arrayId, boolean stdout, long start, boolean URLonly) throws Exception { boolean masterRequest = false; if (jobid < 0) { masterRequest = true;//www . jav a 2 s . c om jobid = -1 * jobid; } JobInformation ji = jobArray.get(jobid); if (ji == null) return new byte[0]; if (ji.kitten == null || ji.taskContainerId == null) return new byte[0]; String containerId = null; //either its a master request, an array request, or the main job task if (masterRequest) { containerId = ji.masterContainerId; } else if (ji.jobSpec.getArrayTaskIds() == null)//basic job { containerId = ji.taskContainerId; } else { containerId = ji.array2Container.get(arrayId); } if (containerId == null || containerId.equals("DONE") || containerId.equals("ABORTED")) { return new byte[0]; } byte[] bytes = new byte[0]; try { ContainerReport cs = yClient.getContainerReport(ContainerId.fromString(containerId)); String url = "http:" + cs.getLogUrl() + (stdout ? "/stdout" : "/stderr") + "?start=" + start; if (!URLonly) { //System.err.println(url); InputStream is = new URL(url).openStream(); bytes = IOUtils.toByteArray(is); is.close(); //convoluted process to re-obtain raw byte form //TODO: some wild assumptions about encoding here. String htmlPage = new String(bytes); htmlPage = REPLACE_PRE_PRE.matcher(htmlPage).replaceAll(""); htmlPage = REPLACE_POST_PRE.matcher(htmlPage).replaceAll(""); htmlPage.replaceAll(".*<pre>", "").replaceAll("</pre>.*", ""); htmlPage = StringEscapeUtils.unescapeHtml(htmlPage); bytes = htmlPage.getBytes(); } else { bytes = url.getBytes(); } } catch (ContainerNotFoundException ce) { LOG.warn("Too late to get job log for " + containerId); } catch (Exception e) { LOG.warn("Failed to get job log for " + containerId, e); } return bytes; }