Recovers a single segment

@param elf
descriptor of the segment to be recovered
@param task
contains journal description
@throws IOException
165810
void recoverSegments(SyncTask task) throws IOException {
    // obtain the list of segments that are valid
    if (!prepareRecovery(task)) {
      return;
    }

    // iterate through all nodes
    for (InetSocketAddress jn : journalNodes) {
      if (isLocalIpAddress(jn.getAddress())
          && jn.getPort() == journalNode.getPort()) {
        // we do not need to talk to ourselves
        continue;
      }

      try {
        // get manifest for log that we care about
        List<EditLogFile> remoteLogFiles = getManifest(jn, task.journal,
            task.recoveryStartTxid);

        // go through all remote segments
        for (EditLogFile relf : remoteLogFiles) {
          recoverSegment(jn, relf, task);
        }

        // if we are done, there is no need to iterate more
        if (!task.hasMissingValidSegments()) {
          LOG.info(logMsg + "recovery finished.");
          break;
        }
      } catch (Exception e) {
        LOG.error(logMsg + "error", e);
        continue;
      } 
    }
  }
798493
private java.util.Map<JobHistory.Keys, String> getLastSuccessfulTaskAttempt(JobHistory.Task task) {
    
    Map<String, JobHistory.TaskAttempt> taskAttempts = task.getTaskAttempts();
    int size = taskAttempts.size();
    java.util.Iterator<Map.Entry<String, JobHistory.TaskAttempt>> kv = taskAttempts.entrySet().iterator();
    for (int i=0; i<size; i++) {
      // CHECK_IT: Only one SUCCESSFUL TASK ATTEMPT
      Map.Entry<String, JobHistory.TaskAttempt> tae = kv.next();
      JobHistory.TaskAttempt attempt = tae.getValue();
      if (attempt.getValues().get(JobHistory.Keys.TASK_STATUS).equals("SUCCESS")) {
        return attempt.getValues();
      }
    }
    
    return null;
  }
868873
private String taskHelp(SecurityUtilityTask task) {
        StringBuffer taskUsage = new StringBuffer(NL);
        taskUsage.append(task.getTaskHelp());
        taskUsage.append(NL);
        return taskUsage.toString();
    }
16941
@Override
    public void readTask(Task task) {
        super.readTask(task);
        this.description = task.getProperty(DESCRIPTION_KEY);
        this.contentChecksum = task.getProperty(CONTENT_CHECKSUM_KEY);
        this.storeChecksum = task.getProperty(STORE_CHECKSUM_KEY);
        this.storeType = StorageProviderType.valueOf(task.getProperty(STORE_TYPE_KEY));
        this.manifestChecksum = task.getProperty(MANIFEST_CHECKSUM_CHECKSUM_KEY);
    }
35312
protected void transmitAtEndOfTask(final Task<Revision> task,
			final Task<Diff> result)
		throws TimeoutException
	{

		this.processingTimeDiff += System.currentTimeMillis() - startTime;

		if (task.getTaskType() == TaskTypes.TASK_FULL
				|| task.getTaskType() == TaskTypes.TASK_PARTIAL_LAST) {

			diffedSize += result.byteSize();

			ArticleInformation info = result.getHeader();
			info.setRevisionCounter(revisionCounter);
			info.setIgnoredRevisionsCounter(ignoredRevisionsCounter);
			info.setDiffedSize(diffedSize);
			info.setDiffPartCounter(diffPartCounter);
			info.setProcessingTimeRead(task.getHeader().getProcessingTimeRead());
			info.setProcessingTimeDiff(processingTimeDiff);
		}

		super.transmitAtEndOfTask(task, result);
	}
1105444
protected void reportNextRecordRange(final TaskUmbilicalProtocol umbilical, 
      long nextRecIndex) throws IOException{
    //currentRecStartIndex is the start index which has not yet been finished 
    //and is still in task's stomach.
    long len = nextRecIndex - currentRecStartIndex +1;
    SortedRanges.Range range = 
      new SortedRanges.Range(currentRecStartIndex, len);
    taskStatus.setNextRecordRange(range);
    LOG.debug("sending reportNextRecordRange " + range);
    umbilical.reportNextRecordRange(taskId, range);
  }
790189
public void removeTask(AgentTask task) {
		final Iterator<WeakReference<AgentTask>> iterator = this.tasks.iterator();
		while (iterator.hasNext()) {
			final WeakReference<AgentTask> reference = iterator.next();
			final AgentTask knownTask = reference.get();
			if (knownTask == null) {
				iterator.remove();
			} else if (Objects.equals(knownTask.getName(), task.getName())) {
				iterator.remove();
				return;
			}
		}
	}
487913
@Override
  public void abortTask(TaskAttemptContext context) throws IOException {
    try {
      if (workPath != null) { 
        context.progress();
        if (!outputFileSystem.delete(workPath, true)) {
          LOG.warn("Deleting output in " + workPath + " returns false");
        }
      }
    } catch (IOException ie) {
      LOG.warn("Error discarding output in " + workPath, ie);
      throw ie;
    }
  }
711933
public void process(final Task<Revision> task)
		throws DiffException, TimeoutException, UnsupportedEncodingException
	{
		// this.startTime = System.currentTimeMillis();
		Revision revision;

		// check if a new task was received
		if (articleID != task.getHeader().getArticleId()) {

			// init settings
			initNewTask(task.getHeader().getArticleId());
			init(task);

			// check if old task was complete
		}
		else if (result == null) {

			init(task);
		}

		Diff diff;

		// TODO: Chronological order hotfix -
		// does not work for articles that are split across multiple tasks
		ArrayList<Revision> list = task.getContainer();
		Collections.sort(list);

		int i, rSize = list.size();

		for (i = 0; i < rSize; i++) {

			if (result.byteSize() > LIMIT_TASK_SIZE_DIFFS) {

				transmitPartialTask(result);
				init(task);
			}

			// Store previous revision
			revPrevious = revCurrent;

			// Process next revision
			revision = list.get(i);

			diff = processRevision(revision);

			if (diff != null) {

				revCurrent = revTemp;

				// Add to result
				revisionCounter++;

				diff.setRevisionCoutner(revisionCounter);
				diff.setRevisionID(revision.getRevisionID());
				diff.setTimeStamp(revision.getTimeStamp());
				diff.setComment(revision.getComment());
				diff.setContributorName(revision.getContributorName());
				diff.setContributorId(revision.getContributorId());
				diff.setContributorIsRegistered(revision.contributorIsRegistered());
				diff.setMinor(revision.isMinor());

				result.add(diff);

				// Verification
				if (VERIFICATION_DIFF) {
					String revC, revP;
					try {
						revC = String.valueOf(revCurrent);
						revP = diff.buildRevision(revPrevious);

						/*
						 * WRONG LOCATION if (notEqual && MODE_SURROGATES ==
						 * SurrogateModes.REPLACE) {
						 *
						 * // TODO: TEST: if (Surrogates.scan(revCurrent)) {
						 *
						 * char[] repCurrent = Surrogates.replace(revCurrent);
						 * char[] repPrevious = Surrogates.replace(revPrevious);
						 *
						 * revC = String.valueOf(repCurrent); revP =
						 * diff.buildRevision(repPrevious);
						 *
						 * notEqual = !revC.equals(revP); } }
						 */

						if (!revC.equals(revP)) {

							if (MODE_DEBUG_OUTPUT_ACTIVATED) {
								WikipediaXMLWriter writer = new WikipediaXMLWriter(
										LOGGING_PATH_DIFFTOOL
												+ LOGGING_PATH_DEBUG
												+ task.getHeader()
														.getArticleName()
												+ ".dbg");

								writer.writeRevision(task);
								writer.close();
							}

							throw ErrorFactory
									.createDiffException(
											ErrorKeys.DIFFTOOL_DIFFCONSUMER_DIFF_VERIFICATION_FAILED,
											"Reconstruction of "
													+ task.toString()
													+ " failed at revision "
													+ revisionCounter + ".");
						}

						// Throw again
					}
					catch (DiffException e) {
						throw e;

						// Catch unexpected exceptions
					}
					catch (Exception e) {
						throw ErrorFactory
								.createDiffException(
										ErrorKeys.DIFFTOOL_DIFFCONSUMER_DIFF_VERIFICATION_FAILED,
										"Reconstruction of " + task.toString()
												+ " failed at revision "
												+ revisionCounter + ".", e);
					}
				}
			}
		}

		transmitAtEndOfTask(task, result);
	}
602198
@Override
  public void recordTaskId(TaskEntity task) {
    if (isHistoryLevelAtLeast(HistoryLevel.ACTIVITY)) {
      ExecutionEntity execution = task.getExecution();
      if (execution != null) {
        HistoricActivityInstanceEntity historicActivityInstance = findActivityInstance(execution, false, true);
        if (historicActivityInstance != null) {
          historicActivityInstance.setTaskId(task.getId());
        }
      }
    }
  }
439015
public void registerTask(Task task) throws IOException {
		final ResultPartition[] producedPartitions = task.getProducedPartitions();

		synchronized (lock) {
			if (isShutdown) {
				throw new IllegalStateException("NetworkEnvironment is shut down");
			}

			for (final ResultPartition partition : producedPartitions) {
				setupPartition(partition);
			}

			// Setup the buffer pool for each buffer reader
			final SingleInputGate[] inputGates = task.getAllInputGates();
			for (SingleInputGate gate : inputGates) {
				setupInputGate(gate);
			}
		}
	}
1040980
void registerTaskEnded(Task task) {
        synchronized (m_activeTasks) {
            String mapKey = createMapKey(task.getTenant(), task.getTaskID());
            if (m_activeTasks.remove(mapKey) == null) {
                m_logger.warn("Task {} registered as ended but was not running", mapKey);
            }
        }
    }
509609
private synchronized void runTask(Task task) {
        if (taskThread == null) {
            taskThread = new TaskThread();
        }
        taskThread.runTask(task);
    }
446347
public void writeRevision(final Task<Revision> task)
		throws IOException
	{

		if (task.getTaskType() == TaskTypes.TASK_PARTIAL_FIRST
				|| task.getTaskType() == TaskTypes.TASK_FULL) {

			this.writer.write(WikipediaXMLKeys.KEY_START_PAGE.getKeyword()
					+ "\r\n");

			ArticleInformation header = task.getHeader();

			this.writer.write("\t"
					+ WikipediaXMLKeys.KEY_START_TITLE.getKeyword());
			this.writer.write(header.getArticleName());
			this.writer.write(WikipediaXMLKeys.KEY_END_TITLE.getKeyword()
					+ "\r\n");

			this.writer
					.write("\t" + WikipediaXMLKeys.KEY_START_ID.getKeyword());
			this.writer.write(Integer.toString(header.getArticleId()));
			this.writer
					.write(WikipediaXMLKeys.KEY_END_ID.getKeyword() + "\r\n");
		}

		Revision rev;
		Iterator<Revision> revIt = task.iterator();
		while (revIt.hasNext()) {

			this.writer
					.write("\t"
							+ WikipediaXMLKeys.KEY_START_REVISION.getKeyword()
							+ "\r\n");
			rev = revIt.next();

			this.writer.write("\t\t"
					+ WikipediaXMLKeys.KEY_START_ID.getKeyword());
			this.writer.write(Integer.toString(rev.getRevisionID()));
			this.writer
					.write(WikipediaXMLKeys.KEY_END_ID.getKeyword() + "\r\n");

			this.writer.write("\t\t<revCount>");
			this.writer.write(Integer.toString(rev.getRevisionCounter()));
			this.writer.write("</revCount>\r\n");

			this.writer.write("\t\t"
					+ WikipediaXMLKeys.KEY_START_TIMESTAMP.getKeyword());
			this.writer.write(rev.getTimeStamp().toString());
			this.writer.write(WikipediaXMLKeys.KEY_END_TIMESTAMP.getKeyword()
					+ "\r\n");

			this.writer.write("\t\t"
					+ WikipediaXMLKeys.KEY_START_CONTRIBUTOR.getKeyword());
			if(rev.contributorIsRegistered()){
				this.writer.write("\t\t"
						+ WikipediaXMLKeys.KEY_START_USERNAME.getKeyword());
				this.writer.write(rev.getContributorName());
				this.writer.write(WikipediaXMLKeys.KEY_END_USERNAME.getKeyword()
						+ "\r\n");

				this.writer.write("\t\t"
						+ WikipediaXMLKeys.KEY_START_ID.getKeyword());
				this.writer.write(rev.getContributorId());
				this.writer.write(WikipediaXMLKeys.KEY_END_ID.getKeyword()
						+ "\r\n");
			}
			else{
				this.writer.write("\t\t"
						+ WikipediaXMLKeys.KEY_START_IP.getKeyword());
				this.writer.write(rev.getContributorName());
				this.writer.write(WikipediaXMLKeys.KEY_END_IP.getKeyword()
						+ "\r\n");
			}

			this.writer.write(WikipediaXMLKeys.KEY_END_CONTRIBUTOR.getKeyword()
					+ "\r\n");

			if(rev.isMinor()){
				this.writer.write("\t\t"+WikipediaXMLKeys.KEY_MINOR_FLAG.getKeyword()
						+ "\r\n");
			}

			this.writer.write("\t\t"
					+ WikipediaXMLKeys.KEY_START_COMMENT.getKeyword());
			this.writer.write(rev.getComment());
			this.writer.write(WikipediaXMLKeys.KEY_END_COMMENT.getKeyword()
					+ "\r\n");




			this.writer.write("\t\t"
					+ WikipediaXMLKeys.KEY_START_TEXT.getKeyword());
			if (rev.getRevisionText() != null) {
				this.writer.write(rev.getRevisionText());
			}
			this.writer.write(WikipediaXMLKeys.KEY_END_TEXT.getKeyword()
					+ "\r\n");

			this.writer.write("\t"
					+ WikipediaXMLKeys.KEY_END_REVISION.getKeyword() + "\r\n");
		}

		if (task.getTaskType() == TaskTypes.TASK_PARTIAL_LAST
				|| task.getTaskType() == TaskTypes.TASK_FULL) {

			this.writer.write(WikipediaXMLKeys.KEY_END_PAGE.getKeyword()
					+ "\r\n");
		}
		this.writer.flush();
	}
256317
private void writeTask(Task task)
   {
      if (!task.getNull())
      {
         if (extractAndConvertTaskType(task) == null || task.getSummary())
         {
            writeWBS(task);
         }
         else
         {
            writeActivity(task);
         }
      }
   }
620237
public ItemRequest<Task> removeDependents(String task) {
    
        String path = String.format("/tasks/%s/removeDependents", task);
        return new ItemRequest<Task>(this, Task.class, path, "POST");
    }
458527
public Task obtainTaskCleanupTask(TaskTrackerStatus tts,
                                                 boolean isMapSlot)
  throws IOException {
    if (!tasksInited.get()) {
      return null;
    }

    if (this.status.getRunState() != JobStatus.RUNNING ||
        jobFailed || jobKilled) {
      return null;
    }

    if (isMapSlot) {
      if (mapCleanupTasks.isEmpty())
        return null;
    } else {
      if (reduceCleanupTasks.isEmpty())
        return null;
    }

    synchronized (this) {
      if (this.status.getRunState() != JobStatus.RUNNING ||
          jobFailed || jobKilled) {
        return null;
      }
      String taskTracker = tts.getTrackerName();
      if (!shouldRunOnTaskTracker(taskTracker)) {
        return null;
      }
      TaskAttemptID taskid = null;
      TaskInProgress tip = null;
      if (isMapSlot) {
        if (!mapCleanupTasks.isEmpty()) {
          taskid = mapCleanupTasks.remove(0);
          tip = maps[taskid.getTaskID().getId()];
        }
      } else {
        if (!reduceCleanupTasks.isEmpty()) {
          taskid = reduceCleanupTasks.remove(0);
          tip = reduces[taskid.getTaskID().getId()];
        }
      }
      if (tip != null) {
        return tip.addRunningTask(taskid, taskTracker, true);
      }
      return null;
    }
  }