List of usage examples for org.apache.hadoop.mapreduce JobStatus getJobID
public JobID getJobID()
From source file:com.cloudera.oryx.computation.common.DistributedGenerationRunner.java
License:Open Source License
private static Collection<String> find(String instanceDir) throws IOException, InterruptedException { Collection<String> result = Lists.newArrayList(); // This is where we will see Hadoop config problems first, so log extra info Cluster cluster;//ww w . j av a2 s .c o m try { cluster = new Cluster(OryxConfiguration.get()); } catch (IOException ioe) { log.error("Unable to init the Hadoop cluster. Check that an MR2, not MR1, cluster is configured."); throw ioe; } try { JobStatus[] statuses = cluster.getAllJobStatuses(); if (statuses != null) { for (JobStatus jobStatus : statuses) { JobStatus.State state = jobStatus.getState(); if (state == JobStatus.State.RUNNING || state == JobStatus.State.PREP) { Job job = cluster.getJob(jobStatus.getJobID()); if (job != null) { String jobName = job.getJobName(); log.info("Found running job {}", jobName); if (jobName.startsWith("Oryx-" + instanceDir + '-')) { result.add(jobName); } } } } } } finally { cluster.close(); } return result; }
From source file:org.apache.ignite.client.hadoop.GridHadoopClientProtocolSelfTest.java
License:Apache License
/** * Check job status.//from w w w .ja v a 2 s. c o m * * @param status Job status. * @param expJobId Expected job ID. * @param expJobName Expected job name. * @param expState Expected state. * @param expCleanupProgress Expected cleanup progress. * @throws Exception If failed. */ private static void checkJobStatus(JobStatus status, JobID expJobId, String expJobName, JobStatus.State expState, float expCleanupProgress) throws Exception { assert F.eq(status.getJobID(), expJobId) : "Expected=" + expJobId + ", actual=" + status.getJobID(); assert F.eq(status.getJobName(), expJobName) : "Expected=" + expJobName + ", actual=" + status.getJobName(); assert F.eq(status.getState(), expState) : "Expected=" + expState + ", actual=" + status.getState(); assert F.eq(status.getCleanupProgress(), expCleanupProgress) : "Expected=" + expCleanupProgress + ", actual=" + status.getCleanupProgress(); }
From source file:org.huahinframework.manager.rest.service.JobService.java
License:Apache License
/** * @return {@link JSONObject}// w w w .j a va 2s.c o m */ @Path("/kill/id/{" + JOBID + "}") @DELETE @Produces(MediaType.APPLICATION_JSON) public JSONObject killJobId(@PathParam(JOBID) String jobId) { Map<String, String> status = new HashMap<String, String>(); try { Cluster cluster = new Cluster(getJobConf()); for (JobStatus jobStatus : cluster.getAllJobStatuses()) { if (jobStatus.getJobID().toString().equals(jobId)) { Job job = cluster.getJob(jobStatus.getJobID()); if (job == null) { break; } job.killJob(); status.put(Response.STATUS, "Killed job " + jobId); break; } } } catch (Exception e) { e.printStackTrace(); log.error(e); status.put(Response.STATUS, e.getMessage()); } if (status.isEmpty()) { status.put(Response.STATUS, "Could not find job " + jobId); } return new JSONObject(status); }
From source file:org.huahinframework.manager.rest.service.JobService.java
License:Apache License
/** * @return {@link JSONObject}//from w w w . j av a2 s .com */ @Path("/kill/name/{" + JOBNAME + "}") @DELETE @Produces(MediaType.APPLICATION_JSON) public JSONObject killJobName(@PathParam(JOBNAME) String jobName) { Map<String, String> status = new HashMap<String, String>(); try { Cluster cluster = new Cluster(getJobConf()); for (JobStatus jobStatus : cluster.getAllJobStatuses()) { Job job = cluster.getJob(jobStatus.getJobID()); if (job == null) { break; } if (job.getJobName().equals(jobName)) { job.killJob(); status.put(Response.STATUS, "Killed job " + jobName); break; } } } catch (Exception e) { e.printStackTrace(); log.error(e); status.put(Response.STATUS, e.getMessage()); } if (status.isEmpty()) { status.put(Response.STATUS, "Could not find job " + jobName); } return new JSONObject(status); }
From source file:org.huahinframework.manager.rest.service.JobService.java
License:Apache License
/** * @param jobId//from w w w. j a va 2 s. c om * @return {@link JSONObject} * @throws IOException * @throws InterruptedException */ private Map<String, Object> getStatus(String jobId) throws IOException, InterruptedException { Map<String, Object> job = null; Cluster cluster = new Cluster(getJobConf()); for (JobStatus jobStatus : cluster.getAllJobStatuses()) { if (jobStatus.getJobID().toString().equals(jobId)) { job = JobUtils.getJob(jobStatus); Job j = cluster.getJob(jobStatus.getJobID()); if (j == null) { break; } Calendar finishTime = Calendar.getInstance(); finishTime.setTimeInMillis(j.getFinishTime()); job.put(Response.FINISH_TIME, finishTime.getTime().toString()); Map<String, Map<String, Long>> groups = new HashMap<String, Map<String, Long>>(); for (String s : j.getCounters().getGroupNames()) { CounterGroup counterGroup = j.getCounters().getGroup(s); Iterator<Counter> ite = counterGroup.iterator(); Map<String, Long> counters = new HashMap<String, Long>(); groups.put(counterGroup.getDisplayName(), counters); while (ite.hasNext()) { Counter counter = (Counter) ite.next(); counters.put(counter.getDisplayName(), counter.getValue()); } } job.put(Response.GROUPS, groups); break; } } return job; }
From source file:org.huahinframework.manager.util.JobUtils.java
License:Apache License
/** * @param jobStatus//from www . j a v a2 s . c om * @return JSON map * @throws IOException */ public static Map<String, Object> getJob(JobStatus jobStatus) throws IOException { int numUsedSlots = jobStatus.getNumUsedSlots(); int numReservedSlots = jobStatus.getNumReservedSlots(); int usedMem = jobStatus.getUsedMem(); int rsvdMem = jobStatus.getReservedMem(); int neededMem = jobStatus.getNeededMem(); Map<String, Object> m = new HashMap<String, Object>(); m.put(Response.JOBID, jobStatus.getJobID().toString()); m.put(Response.NAME, jobStatus.getJobName()); m.put(Response.STATE, jobStatus.getState()); Calendar startTime = Calendar.getInstance(); startTime.setTimeInMillis(jobStatus.getStartTime()); m.put(Response.START_TIME, startTime.getTime().toString()); m.put(Response.USER, jobStatus.getUsername()); m.put(Response.QUEUE, jobStatus.getQueue()); m.put(Response.PRIORITY, jobStatus.getPriority().name()); m.put(Response.USED_CONTAINERS, numUsedSlots < 0 ? UNAVAILABLE : numUsedSlots); m.put(Response.RSVD_CONTAINERS, numReservedSlots < 0 ? UNAVAILABLE : numReservedSlots); m.put(Response.USED_MEM, usedMem < 0 ? UNAVAILABLE : String.format(memPattern, usedMem)); m.put(Response.RSVD_MEM, rsvdMem < 0 ? UNAVAILABLE : String.format(memPattern, rsvdMem)); m.put(Response.NEEDED_MEM, neededMem < 0 ? UNAVAILABLE : String.format(memPattern, neededMem)); m.put(Response.AM_INFO, jobStatus.getSchedulingInfo()); return m; }