private void checkTasks(JobInfo info) {
    if (keep(info)) {
      TaskInfo tinfo = info.getTaskInfo();
      if (tinfo != null) {
        JobTreeElement[] toBeRemoved = null;
        boolean fire = false;
        JobTreeElement element = (JobTreeElement) tinfo.getParent();
        synchronized (keptjobinfos) {
          if (element == info && !keptjobinfos.contains(tinfo)) {
            toBeRemoved = findJobsToRemove(element);
            keptjobinfos.add(tinfo);
            finishedTime.put(tinfo, new Long(System.currentTimeMillis()));
          }
        }

        if (toBeRemoved != null) {
          for (int i = 0; i < toBeRemoved.length; i++) {
            remove(toBeRemoved[i]);
          }
        }

        if (fire) {
          Object l[] = getListeners();
          for (int i = 0; i < l.length; i++) {
            KeptJobsListener jv = (KeptJobsListener) l[i];
            jv.finished(info);
          }
        }
      }
    }
  }
 private boolean allTasksComplete() {
   for (TaskInfo taskInfo : executionPlan.values()) {
     if (!taskInfo.isComplete()) {
       return false;
     }
   }
   return true;
 }
 private void abortExecution() {
   // Allow currently executing tasks to complete, but skip everything else.
   for (TaskInfo taskInfo : executionPlan.values()) {
     if (taskInfo.isReady()) {
       taskInfo.skipExecution();
     }
   }
 }
 private TaskInfo getNextReadyAndMatching(Spec<TaskInfo> criteria) {
   for (TaskInfo taskInfo : executionPlan.values()) {
     if (taskInfo.isReady() && criteria.isSatisfiedBy(taskInfo)) {
       return taskInfo;
     }
   }
   return null;
 }
Beispiel #5
0
 public int getErrorCode() {
   for (String task : failures.keySet()) {
     if (failures.get(task).intValue() == maxFailures) {
       TaskInfo ti = taskIdToInfo.get(task);
       return ti.getErrorCode();
     }
   }
   // Should never reach here unless there were no failed tasks.
   return 0;
 }
 @Override
 public void executeFailedTask(String taskID) {
   // 从失败队列中取出任务
   TaskInfo ti = failedMap.get(taskID);
   if (ti == null) return;
   // 生成新的任务号
   ti.setTaskID(UUID.randomUUID().toString());
   addTask(ti);
   failedMap.remove(taskID);
 }
 @Override
 public void onInterval(TaskInfo info) {
   out.println(
       runningSince()
           + ";"
           + info.currentlyRunningTasks()
           + ";"
           + info.highwaterTasks()
           + ";"
           + info.endedTasks()
           + ";"
           + getEstimatedTasks());
 }
  public void taskComplete(TaskInfo taskInfo) {
    lock.lock();
    try {
      if (taskInfo.isFailed()) {
        handleFailure(taskInfo);
      }

      taskInfo.finishExecution();
      runningProjects.remove(taskInfo.getTask().getProject().getPath());
      condition.signalAll();
    } finally {
      lock.unlock();
    }
  }
Beispiel #9
0
 public String getQuerystatement() {
   if (!this.usepartition()) return this.job.config.getQuerystatement();
   else {
     if (!taskInfo.isIssubpartition())
       return this.job
           .config
           .getQuerystatement()
           .replace("#{partition}", " PARTITION  (" + taskInfo.getPartitionName() + ")");
     else
       return this.job
           .config
           .getQuerystatement()
           .replace("#{partition}", " SUBPARTITION  (" + taskInfo.getSubpartition() + ")");
   }
 }
  @Override
  public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
    if (getTaskFailures() != null && getTaskFailures().size() > 0) {
      builder.startArray("task_failures");
      for (TaskOperationFailure ex : getTaskFailures()) {
        builder.startObject();
        builder.value(ex);
        builder.endObject();
      }
      builder.endArray();
    }

    if (getNodeFailures() != null && getNodeFailures().size() > 0) {
      builder.startArray("node_failures");
      for (FailedNodeException ex : getNodeFailures()) {
        builder.startObject();
        ex.toXContent(builder, params);
        builder.endObject();
      }
      builder.endArray();
    }

    builder.startObject("nodes");
    for (Map.Entry<DiscoveryNode, List<TaskInfo>> entry : getPerNodeTasks().entrySet()) {
      DiscoveryNode node = entry.getKey();
      builder.startObject(node.getId(), XContentBuilder.FieldCaseConversion.NONE);
      builder.field("name", node.name());
      builder.field("transport_address", node.address().toString());
      builder.field("host", node.getHostName());
      builder.field("ip", node.getAddress());

      if (!node.attributes().isEmpty()) {
        builder.startObject("attributes");
        for (ObjectObjectCursor<String, String> attr : node.attributes()) {
          builder.field(attr.key, attr.value, XContentBuilder.FieldCaseConversion.NONE);
        }
        builder.endObject();
      }
      builder.startArray("tasks");
      for (TaskInfo task : entry.getValue()) {
        task.toXContent(builder, params);
      }
      builder.endArray();
      builder.endObject();
    }
    builder.endObject();
    return builder;
  }
Beispiel #11
0
 public void save(TaskInfo<?> taskInfo) {
   try {
     File taskDirectory = getTaskDirectory(taskInfo.getId());
     FileUtils.forceMkdir(taskDirectory);
     File tmpFile = new File(taskDirectory, UUID.randomUUID().toString());
     File infoFile = getTaskInfoFile(taskInfo.getId());
     objectMapper.writeValue(tmpFile, taskInfo);
     Files.move(
         tmpFile.toPath(),
         infoFile.toPath(),
         StandardCopyOption.ATOMIC_MOVE,
         StandardCopyOption.REPLACE_EXISTING);
   } catch (IOException e) {
     throw Throwables.propagate(e);
   }
 }
Beispiel #12
0
  public void terminate(long id) {
    //
    // Terminate a task. This is most useful with infinite-duration tasks,
    // but
    // it is also handy to delete finite tasks prematurely. It would be a
    // simple
    // matter to add a "suspend task" option which suspends a task instead
    // of
    // removing it.
    //
    // Terminate marks the task for deletion rather than just removing it,
    // since it may be called while ExecuteFrame is iterating through the
    // list.
    // Marked tasks are swept up at the end of each frame.
    //
    // Since all task ID's are unique, this method stops looking after it
    // finds
    // a matching task.
    //
    boolean found = false;

    if (id == RENDER_TASK_ID) {
      renderTask.pTask = null;
      found = true;
    }

    TaskInfo pTaskInfo = m_pTaskList;
    while (pTaskInfo != null && !found) {
      if (pTaskInfo.id == id) {
        pTaskInfo.status = TASK_DELETE;
        pTaskInfo.pTask.finish(pTaskInfo.id, m_clock.getTime(), pTaskInfo.pUser);
        found = true;
        break;
      }
      pTaskInfo = pTaskInfo.pNext;
    }
    pTaskInfo = m_pFrameList;
    while (pTaskInfo != null && !found) {
      if (pTaskInfo.id == id) {
        pTaskInfo.status = TASK_DELETE;
        pTaskInfo.pTask.finish(pTaskInfo.id, m_clock.getTime(), pTaskInfo.pUser);
        found = true;
        break;
      }
      pTaskInfo = pTaskInfo.pNext;
    }
  }
 /**
  * Method to get Info section of Task Details page
  *
  * @return
  */
 public TaskInfo getTaskDetailsInfo() {
   TaskInfo info = new TaskInfo();
   try {
     info.setMessage(
         getElementText(
             By.xpath(
                 "//span[@class='viewmode-label' and contains(text(), 'Message:')]/../span[@class='viewmode-value']")));
     info.setOwner(
         getElementText(
             By.xpath(
                 "//span[@class='viewmode-label' and contains(text(), 'Owner:')]/../span[@class='viewmode-value']")));
     info.setPriority(
         getElementText(
             By.xpath(
                 "//span[@class='viewmode-label' and contains(text(), 'Priority:')]/../span[@class='viewmode-value']")));
     info.setDueDate(
         getElementText(
             By.xpath(
                 "//span[@class='viewmode-label' and contains(text(), 'Due:')]/../span[@class='viewmode-value']")));
     info.setDueString(
         getElementText(
             By.xpath(
                 "//span[@class='viewmode-label' and contains(text(), 'Due:')]/../span[@class='viewmode-value']")));
     info.setIdentifier(
         getElementText(
             By.xpath(
                 "//span[@class='viewmode-label' and contains(text(), 'Identifier:')]/../span[@class='viewmode-value']")));
   } catch (NoSuchElementException nse) {
     throw new PageOperationException("Unable to find More Info element" + nse);
   }
   return info;
 }
Beispiel #14
0
 private void insertTimeTask(TaskInfo pTaskInfo) {
   //
   // inserted into list in time order
   //
   if (m_pTaskList == null) {
     pTaskInfo.pNext = null;
     m_pTaskList = pTaskInfo;
   } else if (m_pTaskList.time.next > pTaskInfo.time.next) {
     pTaskInfo.pNext = m_pTaskList;
     m_pTaskList = pTaskInfo;
   } else {
     TaskInfo pInfo = m_pTaskList;
     while (pInfo != null) {
       if (pInfo.pNext == null) {
         pTaskInfo.pNext = null;
         pInfo.pNext = pTaskInfo;
         break;
       } else if (pInfo.pNext.time.next > pTaskInfo.time.next) {
         pTaskInfo.pNext = pInfo.pNext;
         pInfo.pNext = pTaskInfo;
         break;
       }
       pInfo = pInfo.pNext;
     }
   }
 }
Beispiel #15
0
 public String toString() {
   SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
   StringBuilder builder = new StringBuilder();
   builder
       .append("taskNo=")
       .append(taskInfo.taskNo)
       .append(",")
       .append("filename=")
       .append(taskInfo.filename)
       .append(",")
       .append("pagesize=")
       .append(taskInfo.pagesize)
       .append(",")
       .append("start=")
       .append(taskInfo.startoffset)
       .append(",")
       .append("end=")
       .append(taskInfo.endoffset)
       .append(",");
   if (taskInfo.getSubpartition() != null) {
     builder.append("subpartition=").append(taskInfo.getSubpartition()).append(",");
   }
   if (taskInfo.getPartitionName() != null) {
     builder.append("partition=").append(taskInfo.getPartitionName()).append(",");
   }
   builder
       .append("gen start timestamp=")
       .append(genstarttimestamp > 0 ? format.format(new Date(genstarttimestamp)) : "")
       .append(",")
       .append("gen end timestamp=")
       .append(genendtimestamp > 0 ? format.format(new Date(genendtimestamp)) : "")
       .append(",");
   if (this.job.genlocalfile()) {
     builder
         .append("up start timestamp=")
         .append(upstarttimestamp > 0 ? format.format(new Date(upstarttimestamp)) : "")
         .append(",")
         .append("up end timestamp=")
         .append(upendtimestamp > 0 ? format.format(new Date(upendtimestamp)) : "")
         .append(",");
   }
   builder.append(" totalrows=").append(rows);
   return builder.toString();
 }
  private void handleFailure(TaskInfo taskInfo) {
    Throwable executionFailure = taskInfo.getExecutionFailure();
    if (executionFailure != null) {
      // Always abort execution for an execution failure (as opposed to a task failure)
      abortExecution();
      this.failures.add(executionFailure);
      return;
    }

    // Task failure
    try {
      failureHandler.onTaskFailure(taskInfo.getTask());
      this.failures.add(taskInfo.getTaskFailure());
    } catch (Exception e) {
      // If the failure handler rethrows exception, then execution of other tasks is aborted.
      // (--continue will collect failures)
      abortExecution();
      this.failures.add(e);
    }
  }
Beispiel #17
0
  @Test
  public void testAbort() throws Exception {
    SqlTask sqlTask = createInitialTask();

    TaskInfo taskInfo =
        sqlTask.updateTask(
            SESSION,
            PLAN_FRAGMENT,
            ImmutableList.of(new TaskSource(TABLE_SCAN_NODE_ID, ImmutableSet.of(SPLIT), true)),
            INITIAL_EMPTY_OUTPUT_BUFFERS
                .withBuffer("out", new UnpartitionedPagePartitionFunction())
                .withNoMoreBufferIds());
    assertEquals(taskInfo.getState(), TaskState.RUNNING);

    taskInfo = sqlTask.getTaskInfo();
    assertEquals(taskInfo.getState(), TaskState.RUNNING);

    sqlTask.abortTaskResults("out");

    taskInfo = sqlTask.getTaskInfo(taskInfo.getState()).get(1, TimeUnit.SECONDS);
    assertEquals(taskInfo.getState(), TaskState.FINISHED);

    taskInfo = sqlTask.getTaskInfo();
    assertEquals(taskInfo.getState(), TaskState.FINISHED);
  }
  public TaskInfo getTaskToExecute(Spec<TaskInfo> criteria) {
    lock.lock();
    try {

      TaskInfo nextMatching;
      while ((nextMatching = getNextReadyAndMatching(criteria)) != null) {
        while (!nextMatching.allDependenciesComplete()) {
          try {
            condition.await();
          } catch (InterruptedException e) {
            throw new RuntimeException(e);
          }
        }

        // The task state could have been modified while we waited for dependency completion. Check
        // that it is still 'ready'.
        if (!nextMatching.isReady()) {
          continue;
        }

        if (nextMatching.allDependenciesSuccessful()) {
          nextMatching.startExecution();
          return nextMatching;
        } else {
          nextMatching.skipExecution();
          condition.signalAll();
        }
      }

      return null;

    } finally {
      lock.unlock();
    }
  }
 public TaskInfo getTaskToExecute() {
   lock.lock();
   try {
     while (true) {
       TaskInfo nextMatching = null;
       boolean allTasksComplete = true;
       for (TaskInfo taskInfo : executionPlan.values()) {
         allTasksComplete = allTasksComplete && taskInfo.isComplete();
         if (taskInfo.isReady()
             && taskInfo.allDependenciesComplete()
             && !runningProjects.contains(taskInfo.getTask().getProject().getPath())) {
           nextMatching = taskInfo;
           break;
         }
       }
       if (allTasksComplete) {
         return null;
       }
       if (nextMatching == null) {
         try {
           condition.await();
         } catch (InterruptedException e) {
           throw new RuntimeException(e);
         }
       } else {
         if (nextMatching.allDependenciesSuccessful()) {
           nextMatching.startExecution();
           runningProjects.add(nextMatching.getTask().getProject().getPath());
           return nextMatching;
         } else {
           nextMatching.skipExecution();
           condition.signalAll();
         }
       }
     }
   } finally {
     lock.unlock();
   }
 }
  /** Returns the list of tasks by node */
  public Map<DiscoveryNode, List<TaskInfo>> getPerNodeTasks() {
    if (nodes != null) {
      return nodes;
    }
    Map<DiscoveryNode, List<TaskInfo>> nodeTasks = new HashMap<>();

    Set<DiscoveryNode> nodes = new HashSet<>();
    for (TaskInfo shard : tasks) {
      nodes.add(shard.getNode());
    }

    for (DiscoveryNode node : nodes) {
      List<TaskInfo> tasks = new ArrayList<>();
      for (TaskInfo taskInfo : this.tasks) {
        if (taskInfo.getNode().equals(node)) {
          tasks.add(taskInfo);
        }
      }
      nodeTasks.put(node, tasks);
    }
    this.nodes = nodeTasks;
    return nodeTasks;
  }
Beispiel #21
0
  @Test
  public void testEmptyQuery() throws Exception {
    SqlTask sqlTask = createInitialTask();

    TaskInfo taskInfo =
        sqlTask.updateTask(
            SESSION, PLAN_FRAGMENT, ImmutableList.<TaskSource>of(), INITIAL_EMPTY_OUTPUT_BUFFERS);
    assertEquals(taskInfo.getState(), TaskState.RUNNING);

    taskInfo = sqlTask.getTaskInfo();
    assertEquals(taskInfo.getState(), TaskState.RUNNING);

    taskInfo =
        sqlTask.updateTask(
            SESSION,
            PLAN_FRAGMENT,
            ImmutableList.of(
                new TaskSource(TABLE_SCAN_NODE_ID, ImmutableSet.<ScheduledSplit>of(), true)),
            INITIAL_EMPTY_OUTPUT_BUFFERS.withNoMoreBufferIds());
    assertEquals(taskInfo.getState(), TaskState.FINISHED);

    taskInfo = sqlTask.getTaskInfo();
    assertEquals(taskInfo.getState(), TaskState.FINISHED);
  }
Beispiel #22
0
  @Test
  public void testCancel() throws Exception {
    SqlTask sqlTask = createInitialTask();

    TaskInfo taskInfo =
        sqlTask.updateTask(
            SESSION, PLAN_FRAGMENT, ImmutableList.<TaskSource>of(), INITIAL_EMPTY_OUTPUT_BUFFERS);
    assertEquals(taskInfo.getState(), TaskState.RUNNING);
    assertNull(taskInfo.getStats().getEndTime());

    taskInfo = sqlTask.getTaskInfo();
    assertEquals(taskInfo.getState(), TaskState.RUNNING);
    assertNull(taskInfo.getStats().getEndTime());

    taskInfo = sqlTask.cancel();
    assertEquals(taskInfo.getState(), TaskState.CANCELED);
    assertNotNull(taskInfo.getStats().getEndTime());

    taskInfo = sqlTask.getTaskInfo();
    assertEquals(taskInfo.getState(), TaskState.CANCELED);
    assertNotNull(taskInfo.getStats().getEndTime());
  }
Beispiel #23
0
  /** 删除被停止的任务 */
  private void sweepGarbage() {
    //
    // Check both task list and frame list for tasks that were marked
    // for deletion by the Terminate() method. This implementation is
    // pretty brute-force; garbage collection could be run as an
    // idle processing task.
    //
    // printf("SWEEP BEGIN\n");
    TaskInfo pTaskInfo = m_pTaskList;
    TaskInfo pPrev = null;
    while (pTaskInfo != null) {
      if (pTaskInfo.status == TASK_DELETE) {
        TaskInfo pTemp = pTaskInfo;
        pTaskInfo = pTaskInfo.pNext;
        if (pTemp.equals(m_pTaskList)) {
          m_pTaskList = pTaskInfo;
        } else {
          pPrev.pNext = pTaskInfo;
          // printf("Sched: Deleted %d\n",pTemp->id);
          // delete pTemp;
        }
      } else {
        pPrev = pTaskInfo;
        pTaskInfo = pTaskInfo.pNext;
      }
    }

    pTaskInfo = m_pFrameList;
    pPrev = null;
    while (pTaskInfo != null) {
      if (pTaskInfo.status == TASK_DELETE) {
        TaskInfo pTemp = pTaskInfo;
        pTaskInfo = pTaskInfo.pNext;
        if (pTemp.equals(m_pFrameList)) {
          m_pFrameList = pTaskInfo;
        } else {
          pPrev.pNext = pTaskInfo;
          // printf("Sched: Deleted %d\n",pTemp->id);
          // delete pTemp;
        }
      } else {
        pPrev = pTaskInfo;
        pTaskInfo = pTaskInfo.pNext;
      }
    }
    // printf("SWEEP END\n");
  }
 public void run() {
   LOGGER.info("Running tasks");
   /*
    * while (true) { Task task = getTask(); IDataPlugin plugin =
    * task.getPlugin(); Settings settings = task.getSettings();
    * plugin.doJob(_dataEngine, _environment, settings);
    */
   TaskInfo taskInfo = null;
   for (ITask task : _tasks) {
     try {
       taskInfo = ((Task) task).getInfo();
       LOGGER.info("task: " + taskInfo.getName());
       ISettings settings = task.getSettings();
       taskInfo.setStatus(TaskInfo.REALIZATION);
       // changing status
       taskInfo.save();
       _dbManager.commit();
       //
       // processing task
       //
       ILocalPlugin plugin = task.getPlugin();
       LOGGER.debug("plugin: " + plugin + " id: " + plugin.getInfo().getId());
       IResult result = plugin.doJob(getDataEngine(), _environment, settings);
       //
       // saving result of its execution
       //
       task.setResult(result);
       taskInfo.save();
       _dbManager.commit();
       //
       // if task was not processed correctly
       // exception is caught and shoul be handled here
       //
     } catch (Exception e) {
       LOGGER.fatal("TASK PROCESSING ERROR", e);
       try {
         taskInfo.setStatus(TaskInfo.EXCEPTION);
         taskInfo.save();
       } catch (Exception ex) {
         LOGGER.fatal("", ex);
       }
       _dbManager.commit();
     }
   }
 }
Beispiel #25
0
  @Test
  public void testSimpleQuery() throws Exception {
    SqlTask sqlTask = createInitialTask();

    TaskInfo taskInfo =
        sqlTask.updateTask(
            SESSION,
            PLAN_FRAGMENT,
            ImmutableList.of(new TaskSource(TABLE_SCAN_NODE_ID, ImmutableSet.of(SPLIT), true)),
            INITIAL_EMPTY_OUTPUT_BUFFERS
                .withBuffer("out", new UnpartitionedPagePartitionFunction())
                .withNoMoreBufferIds());
    assertEquals(taskInfo.getState(), TaskState.RUNNING);

    taskInfo = sqlTask.getTaskInfo();
    assertEquals(taskInfo.getState(), TaskState.RUNNING);

    BufferResult results = sqlTask.getTaskResults("out", 0, new DataSize(1, Unit.MEGABYTE)).get();
    assertEquals(results.isBufferClosed(), false);
    assertEquals(results.getPages().size(), 1);
    assertEquals(results.getPages().get(0).getPositionCount(), 1);

    results =
        sqlTask
            .getTaskResults(
                "out",
                results.getToken() + results.getPages().size(),
                new DataSize(1, Unit.MEGABYTE))
            .get();
    assertEquals(results.isBufferClosed(), true);
    assertEquals(results.getPages().size(), 0);

    taskInfo = sqlTask.getTaskInfo(taskInfo.getState()).get(1, TimeUnit.SECONDS);
    assertEquals(taskInfo.getState(), TaskState.FINISHED);
    taskInfo = sqlTask.getTaskInfo();
    assertEquals(taskInfo.getState(), TaskState.FINISHED);
  }
Beispiel #26
0
  private String showJobFailDebugInfo() throws IOException {
    console.printError("Error during job, obtaining debugging information...");
    if (!conf.get("mapred.job.tracker", "local").equals("local")) {
      // Show Tracking URL for remotely running jobs.
      console.printError("Job Tracking URL: " + rj.getTrackingURL());
    }
    // Loop to get all task completion events because getTaskCompletionEvents
    // only returns a subset per call
    TaskInfoGrabber tlg = new TaskInfoGrabber();
    Thread t = new Thread(tlg);
    try {
      t.start();
      t.join(HiveConf.getIntVar(conf, HiveConf.ConfVars.TASKLOG_DEBUG_TIMEOUT));
    } catch (InterruptedException e) {
      console.printError(
          "Timed out trying to finish grabbing task log URLs, " + "some task info may be missing");
    }

    // Remove failures for tasks that succeeded
    for (String task : successes) {
      failures.remove(task);
    }

    if (failures.keySet().size() == 0) {
      return null;
    }
    // Find the highest failure count
    computeMaxFailures();

    // Display Error Message for tasks with the highest failure count
    String jtUrl = null;
    try {
      jtUrl = JobTrackerURLResolver.getURL(conf);
    } catch (Exception e) {
      console.printError("Unable to retrieve URL for Hadoop Task logs. " + e.getMessage());
    }

    String msg = null;
    for (String task : failures.keySet()) {
      if (failures.get(task).intValue() == maxFailures) {
        TaskInfo ti = taskIdToInfo.get(task);
        String jobId = ti.getJobId();
        String taskUrl =
            (jtUrl == null)
                ? null
                : jtUrl + "/taskdetails.jsp?jobid=" + jobId + "&tipid=" + task.toString();

        TaskLogProcessor tlp = new TaskLogProcessor(conf);
        for (String logUrl : ti.getLogUrls()) {
          tlp.addTaskAttemptLogUrl(logUrl);
        }

        if (HiveConf.getBoolVar(conf, HiveConf.ConfVars.JOB_DEBUG_CAPTURE_STACKTRACES)
            && stackTraces != null) {
          if (!stackTraces.containsKey(jobId)) {
            stackTraces.put(jobId, new ArrayList<List<String>>());
          }
          stackTraces.get(jobId).addAll(tlp.getStackTraces());
        }

        if (HiveConf.getBoolVar(conf, HiveConf.ConfVars.SHOW_JOB_FAIL_DEBUG_INFO)) {
          List<ErrorAndSolution> errors = tlp.getErrors();

          StringBuilder sb = new StringBuilder();
          // We use a StringBuilder and then call printError only once as
          // printError will write to both stderr and the error log file. In
          // situations where both the stderr and the log file output is
          // simultaneously output to a single stream, this will look cleaner.
          sb.append("\n");
          sb.append("Task with the most failures(" + maxFailures + "): \n");
          sb.append("-----\n");
          sb.append("Task ID:\n  " + task + "\n\n");
          if (taskUrl != null) {
            sb.append("URL:\n  " + taskUrl + "\n");
          }

          for (ErrorAndSolution e : errors) {
            sb.append("\n");
            sb.append("Possible error:\n  " + e.getError() + "\n\n");
            sb.append("Solution:\n  " + e.getSolution() + "\n");
          }
          sb.append("-----\n");

          sb.append("Diagnostic Messages for this Task:\n");
          String[] diagMesgs = ti.getDiagnosticMesgs();
          for (String mesg : diagMesgs) {
            sb.append(mesg + "\n");
          }
          msg = sb.toString();
          console.printError(msg);
        }

        // Only print out one task because that's good enough for debugging.
        break;
      }
    }
    return msg;
  }
Beispiel #27
0
    private void getTaskInfos() throws IOException, MalformedURLException {
      int startIndex = 0;
      while (true) {
        TaskCompletionEvent[] taskCompletions = rj.getTaskCompletionEvents(startIndex);

        if (taskCompletions == null || taskCompletions.length == 0) {
          break;
        }

        boolean more = true;
        boolean firstError = true;
        for (TaskCompletionEvent t : taskCompletions) {
          // For each task completion event, get the associated task id, job id
          // and the logs
          String taskId = t.getTaskAttemptId().getTaskID().toString();
          String jobId = t.getTaskAttemptId().getJobID().toString();
          if (firstError) {
            console.printError("Examining task ID: " + taskId + " (and more) from job " + jobId);
            firstError = false;
          }

          TaskInfo ti = taskIdToInfo.get(taskId);
          if (ti == null) {
            ti = new TaskInfo(jobId);
            taskIdToInfo.put(taskId, ti);
          }
          // These tasks should have come from the same job.
          assert (ti.getJobId() != null && ti.getJobId().equals(jobId));
          String taskAttemptLogUrl =
              ShimLoader.getHadoopShims()
                  .getTaskAttemptLogUrl(conf, t.getTaskTrackerHttp(), t.getTaskId());
          if (taskAttemptLogUrl != null) {
            ti.getLogUrls().add(taskAttemptLogUrl);
          }

          // If a task failed, fetch its error code (if available).
          // Also keep track of the total number of failures for that
          // task (typically, a task gets re-run up to 4 times if it fails.
          if (t.getTaskStatus() != TaskCompletionEvent.Status.SUCCEEDED) {
            String[] diags = rj.getTaskDiagnostics(t.getTaskAttemptId());
            ti.setDiagnosticMesgs(diags);
            if (ti.getErrorCode() == 0) {
              ti.setErrorCode(extractErrorCode(diags));
            }

            Integer failAttempts = failures.get(taskId);
            if (failAttempts == null) {
              failAttempts = Integer.valueOf(0);
            }
            failAttempts = Integer.valueOf(failAttempts.intValue() + 1);
            failures.put(taskId, failAttempts);
          } else {
            successes.add(taskId);
          }
        }
        if (!more) {
          break;
        }
        startIndex += taskCompletions.length;
      }
    }
Beispiel #28
0
  /**
   * @param type 任务类型(TASK_TIME,TASK_RENDER,TASK_FRAME)
   * @param start 任务开始时间或者帧
   * @param period 任务间隔触发时间或者帧数
   * @param duration 任务持续时间或者帧数
   * @param pTask 请求任务
   * @param pUser 用户数据
   * @return 系统生成任务ID
   */
  public long schedule(int type, long start, int period, int duration, ITask pTask, Object pUser) {
    //
    // this schedules a task of the appropriate type (RENDER, FRAME, or
    // TIME). Time tasks and
    // frame tasks are kept in separate lists for ease of handling.
    // Render tasks are stored as a single special-case entry.
    //
    // time and frame tasks have a start time, a duration, and a period.
    // 时间和帧任务都有一个开始时间,持续时间,时间间隔。
    // the duration is relative to the start time, except for duration 0
    // which is a special case.
    // 如果持续时间为0,那么就是一个无限循环的任务
    // since the scheduler doesn't care about the duration itself, it
    // converts it into an end time
    // and stores that instead. the render task does ignores
    // start/duration/end.
    //
    // pUser is a user data pointer.
    //
    // a unique task id is generated and returned in pID. if you don't care
    // about an ID,
    // pass in NULL instead.
    //
    if (type == TASK_RENDER) {
      renderTask.pTask = pTask;
      renderTask.pUser = pUser;
      renderTask.id = RENDER_TASK_ID;
      return RENDER_TASK_ID;
    } else {
      //
      // Allocating memory like this has high overhead. It would be much
      // better to use a
      // fast allocator which preallocates and/or reuses TaskInfo
      // structures.
      //
      TaskInfo pTaskInfo = new TaskInfo();

      {
        pTaskInfo.pTask = pTask;
        pTaskInfo.pNext = m_pTaskList;
        pTaskInfo.status = TASK_ACTIVE;
        pTaskInfo.id = m_nextId++;
        // if (pID != 0)
        // pID = pTaskInfo.id;
        pTaskInfo.pUser = pUser;
        pTaskInfo.time.start = start;
        pTaskInfo.time.period = period;
        if (duration == 0) {
          pTaskInfo.time.duration = 0; // infinite
        } else {
          pTaskInfo.time.duration = start + duration - 1; // compute
        }
        // end time
        pTaskInfo.time.next = start;
        // printf("Scheduling %s task %u from %3u to %3u, every %2u %s\n",
        // type==TASK_TIME?"time ":"frame",
        // pTaskInfo.id,
        // pTaskInfo.time.start,
        // pTaskInfo.time.duration,
        // pTaskInfo.time.period,
        // type==TASK_TIME?"ms":"frames");

        if (type == TASK_TIME) {
          insertTimeTask(pTaskInfo);
        } else if (type == TASK_FRAME) {
          insertFrameTask(pTaskInfo);
        }
        return pTaskInfo.id;
      }
    }
  }
Beispiel #29
0
 void setTaskInfo(TaskInfo taskInfo) {
   Preconditions.checkArgument(taskInfo != null, "Provide valid taskInfo");
   this.taskInfo = taskInfo;
   taskInfo.addTaskAttemptInfo(this);
 }
Beispiel #30
0
    @SuppressLint("NewApi")
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
      ViewHolder holder;
      if (convertView == null) {
        holder = new ViewHolder();
        convertView = mInflater.inflate(R.layout.order_item, null);
        holder.date = (TextView) convertView.findViewById(R.id.item_date);
        holder.location = (TextView) convertView.findViewById(R.id.item_location);
        holder.name = (TextView) convertView.findViewById(R.id.item_name);
        holder.time = (TextView) convertView.findViewById(R.id.item_time);
        holder.type = (TextView) convertView.findViewById(R.id.item_type);
        holder.company = (TextView) convertView.findViewById(R.id.item_company);
        holder.isDone = (TextView) convertView.findViewById(R.id.item_isDone);
        convertView.setTag(holder);
      } else {
        holder = (ViewHolder) convertView.getTag();
      }
      TaskInfo taskInfo = tasklist.get(position);
      String ServiceDate = null;
      String serviceBegin = taskInfo.ServiceBegin();
      String serviceEnd = taskInfo.ServiceEnd();
      if (serviceBegin.equals(serviceEnd)) {
        ServiceDate = serviceBegin;
      } else {
        ServiceDate = serviceBegin + "-" + serviceEnd;
      }
      holder.time.setText(taskInfo.OnboardTime());
      holder.date.setText(ServiceDate);
      holder.location.setText(taskInfo.PickupAddress());
      holder.name.setText(taskInfo.Customer());
      holder.type.setText(taskInfo.ServiceTypeName());
      holder.company.setText(taskInfo.getCustomerCompany());
      String isUpdate = taskInfo.getIsUpdate();
      int readmark = taskInfo.getReadmark();
      if (taskInfo.getRouteNoteCount() > 0) {
        holder.isDone.setVisibility(View.VISIBLE);
        holder.isDone.setText("已完成");
        holder.isDone.setBackgroundColor(Color.parseColor("#009944"));
      } else if (null != pauseNote && pauseNote.getTaskID().equals(taskInfo.TaskID())) {
        holder.isDone.setVisibility(View.VISIBLE);
        holder.isDone.setText("暂停中");
        holder.isDone.setBackgroundColor(Color.parseColor("#eb6100"));

        //				holder.isDone.setBackground(getResources().getColor(R.color.colorYellow));
      } else if (readmark == 1) {
        holder.isDone.setVisibility(View.GONE);
      } else if (readmark == 0) {
        holder.isDone.setVisibility(View.VISIBLE);
        holder.isDone.setBackground(getResources().getDrawable(R.drawable.bg_red));
        if (isUpdate.equals("0")) {
          holder.isDone.setText("新增");
        } else {
          holder.isDone.setText("修改");
        }
      } else {
        holder.isDone.setVisibility(View.GONE);
      }
      return convertView;
    }