Writes all updates (events) for a given job since a given time

@param wrt
@param jobId
177249
private void writeJsonUpdatesForJob(PrintWriter wrt, JobID jobId) {
		
		try {
			
			List<AbstractEvent> events = jobmanager.getEvents(jobId);
			
			//Serialize job to json
			wrt.write("{");
			wrt.write("\"jobid\": \"" + jobId + "\",");
			wrt.write("\"timestamp\": \"" + System.currentTimeMillis() + "\",");
			wrt.write("\"recentjobs\": [");
				
			boolean first = true;
			for(RecentJobEvent rje: jobmanager.getRecentJobs()) {
				if(first) {
					first = false;
				} else {
					wrt.write(","); }
				
				wrt.write("\""+rje.getJobID().toString()+"\""); 
			}
					
			wrt.write("],");
			
			wrt.write("\"vertexevents\": [");
		
			first = true;
			for(AbstractEvent event: events) {
				
				if(event instanceof ExecutionStateChangeEvent) {
					
					if(first) {
						first = false;
					} else {
						wrt.write(","); }
					
					ExecutionStateChangeEvent vertexevent = (ExecutionStateChangeEvent) event;
					wrt.write("{");
					wrt.write("\"vertexid\": \"" + vertexevent.getVertexID() + "\",");
					wrt.write("\"newstate\": \"" + vertexevent.getNewExecutionState() + "\",");
					wrt.write("\"timestamp\": \"" + vertexevent.getTimestamp() + "\"");
					wrt.write("}");
				}
			}
			
			wrt.write("],");
			
			wrt.write("\"jobevents\": [");
			
			first = true;
			for(AbstractEvent event: events) {
				
				if( event instanceof JobEvent) {
					
					if(first) {
						first = false;
					} else {
						wrt.write(","); }
					
					JobEvent jobevent = (JobEvent) event;
					wrt.write("{");
					wrt.write("\"newstate\": \"" + jobevent.getCurrentJobStatus() + "\",");
					wrt.write("\"timestamp\": \"" + jobevent.getTimestamp() + "\"");
					wrt.write("}");
				}
			}
			
			wrt.write("]");
			
			wrt.write("}");
			
		
		} catch (EofException eof) { // Connection closed by client
			LOG.info("Info server for jobmanager: Connection closed by client, EofException");
		} catch (IOException ioe) { // Connection closed by client	
			LOG.info("Info server for jobmanager: Connection closed by client, IOException");
		} 
		
	}
554784
@Override
    public WSJobExecution updateJobExecutionAndInstanceNotSetToServerYet(
                                                                         long jobExecutionId, Date date) throws ExecutionAssignedToServerException {
        return updateJobExecutionAndInstanceOnStopBeforeServerAssigned(jobExecutionId, date);
    }
607618
private void writeJsonForJobs(PrintWriter wrt, List<RecentJobEvent> jobs) {
		
		try {
		
			wrt.write("[");
			
			// Loop Jobs
			for (int i = 0; i < jobs.size(); i++) {
				RecentJobEvent jobEvent = jobs.get(i);
	
				writeJsonForJob(wrt, jobEvent);
	
				//Write seperator between json objects
				if(i != jobs.size() - 1) {
					wrt.write(",");
				}
			}
			wrt.write("]");
		
		} catch (EofException eof) { // Connection closed by client
			LOG.info("Info server for jobmanager: Connection closed by client, EofException");
		} catch (IOException ioe) { // Connection closed by client	
			LOG.info("Info server for jobmanager: Connection closed by client, IOException");
		} 
		
	}
1135010
protected function saveJobResult($id, $jobEvent)
    {
        if ($jobEvent) {
            $queueEvent = new QueueSaveJobResultEvent();
            $queueEvent->setId($id);
            $queueEvent->setData($jobEvent);
            $this->dispatcher->dispatch($queueEvent::NAME, $queueEvent);
        }
    }
106932
public void update( Key job_key ) { 
    Log.debug(Log.Tag.Sys.LOCKS,"update write-locked "+_key+" by job "+job_key);
    new Update(job_key).invoke(_key); 
  }
181208
@Override
  public synchronized void write(DataOutput out) throws IOException {
    out.writeDouble(getCpuTotalGHz());
    out.writeDouble(getMemTotalGB());
    out.writeInt(getNumCpu());
    out.writeInt(getNumRunningJobs());
    out.writeInt(getNumTaskTrackers());
    out.writeDouble(getMemUsageGB());
    out.writeDouble(getCpuUsageGHz());
  }
1018728
private void jobStateChanged(JobStatusChangeEvent event) {
    // Resort the job queue if the job-start-time or job-priority changes
    if (event.getEventType() == EventType.START_TIME_CHANGED
        || event.getEventType() == EventType.PRIORITY_CHANGED) {
      synchronized (jobInitQueue) {
        resortInitQueue();
      }
    }
  }
1252147
public void reconnect(final JobID jobId) {
		Preconditions.checkNotNull(jobId, "JobID must not be null.");

		final Tuple2<LeaderRetrievalService, JobManagerLeaderListener> jobLeaderService = jobLeaderServices.get(jobId);

		if (jobLeaderService != null) {
			jobLeaderService.f1.reconnect();
		} else {
			LOG.info("Cannot reconnect to job {} because it is not registered.", jobId);
		}
	}
1095399
private void submitTaskStateEvents(JobState jobState) {
    // Build Job Metadata applicable for TaskStates
    ImmutableMap.Builder<String, String> jobMetadataBuilder = new ImmutableMap.Builder<>();
    jobMetadataBuilder.put(METADATA_JOB_ID, jobState.getJobId());
    jobMetadataBuilder.put(METADATA_JOB_NAME, jobState.getJobName());
    jobMetadataBuilder.put(METADATA_JOB_TRACKING_URL, jobState.getTrackingURL().or(UNKNOWN_VALUE));
    Map<String, String> jobMetadata = jobMetadataBuilder.build();

    // Submit event for each TaskState
    for (TaskState taskState : jobState.getTaskStates()) {
      submitTaskStateEvent(taskState, jobMetadata);
    }
  }
612726
private void listEvents(JobID jobId, int fromEventId, int numEvents)
    throws IOException {
    TaskCompletionEvent[] events =
      jobSubmitClient.getTaskCompletionEvents(jobId, fromEventId, numEvents);
    System.out.println("Task completion events for " + jobId);
    System.out.println("Number of events (from " + fromEventId +
                       ") are: " + events.length);
    for(TaskCompletionEvent event: events) {
      System.out.println(event.getTaskStatus() + " " + event.getTaskAttemptId() + " " +
                         getTaskLogURL(event.getTaskAttemptId(),
                                       event.getTaskTrackerHttp()));
    }
  }
999402
@Override
  public List<TaskStatusEvent> getJobHistory(final JobId jobId, final String host)
      throws JobDoesNotExistException {
    final Job descriptor = getJob(jobId);
    if (descriptor == null) {
      throw new JobDoesNotExistException(jobId);
    }
    final ZooKeeperClient client = provider.get("getJobHistory");
    final List<String> hosts;

    try {
      hosts = (!isNullOrEmpty(host)) ? singletonList(host) :
              client.getChildren(Paths.historyJobHosts(jobId));
    } catch (NoNodeException e) {
      return emptyList();
    } catch (KeeperException e) {
      throw new RuntimeException(e);
    }

    final List<TaskStatusEvent> jsEvents = Lists.newArrayList();

    for (final String h : hosts) {
      final List<String> events;
      try {
        events = client.getChildren(Paths.historyJobHostEvents(jobId, h));
      } catch (NoNodeException e) {
        continue;
      } catch (KeeperException e) {
        throw new RuntimeException(e);
      }

      for (final String event : events) {
        try {
          final byte[] data = client.getData(Paths.historyJobHostEventsTimestamp(
              jobId, h, Long.valueOf(event)));
          final TaskStatus status = Json.read(data, TaskStatus.class);
          jsEvents.add(new TaskStatusEvent(status, Long.valueOf(event), h));
        } catch (NoNodeException e) { // ignore, it went away before we read it
        } catch (KeeperException | IOException e) {
          throw new RuntimeException(e);
        }
      }
    }

    return Ordering.from(EVENT_COMPARATOR).sortedCopy(jsEvents);
  }
1161170
synchronized void setJobPriority(JobID jobId, JobPriority priority) {
    JobInProgress job = jobs.get(jobId);
    if (job != null) {
      synchronized (taskScheduler) {
        JobStatus oldStatus = (JobStatus)job.getStatus().clone();
        job.setPriority(priority);
        JobStatus newStatus = (JobStatus)job.getStatus().clone();
        JobStatusChangeEvent event =
          new JobStatusChangeEvent(job, EventType.PRIORITY_CHANGED, oldStatus,
                                   newStatus);
        updateJobInProgressListeners(event);
      }
    } else {
      LOG.warn("Trying to change the priority of an unknown job: " + jobId);
    }
  }
1123480
@Override
    public void setJobQueue(int jobId, Queue queue)
    {
        JqmClientFactory.getClient().setJobQueue(jobId, queue);
    }
1155231
@Override
    public WSJobInstance updateJobInstanceAndExecutionWithInstanceStateAndBatchStatus(long instanceId, long executionId,
                                                                                      final InstanceState state, final BatchStatus batchStatus) {

        JobInstanceEntity retMe = null;

        //Update the JobInstance
        retMe = (JobInstanceEntity) persistenceManagerService.updateJobInstanceWithInstanceStateAndBatchStatus(instanceId, state, batchStatus, new Date());

        //Update the Job Execution Instance
        persistenceManagerService.updateJobExecutionAndInstanceOnStatusChange(executionId, batchStatus, new Date());

        return retMe;
    }
613264
protected function markJobAsScheduled(Job $job, ?string $externalId = null): void
    {
        $stmt = $this->engine->prepareQuery("UPDATE `#__bpmn_job` SET `scheduled_at` = :scheduled, `external_id` = :ex WHERE `id` = :id");
        $stmt->bindValue('scheduled', \time());
        $stmt->bindValue('ex', $externalId);
        $stmt->bindValue('id', $job->getId());
        $stmt->execute();
    }
241265
public final void update( final long newworked, final String msg) {
    if( newworked > 0 || (msg != null && !msg.equals(_msg)) ) {
      new JAtomic() {
        @Override boolean abort(Job job) { return newworked==0 && ((msg==null && _msg==null) || (msg != null && msg.equals(job._msg))); }
        @Override void update(Job old) { old._worked += newworked; old._msg = msg; }
      }.apply(this);
    }
  }
63014
protected synchronized JobStatus addJob(JobID jobId, JobInProgress job) {
    totalSubmissions++;

    synchronized (jobs) {
      synchronized (taskScheduler) {
        jobs.put(job.getProfile().getJobID(), job);
        for (JobInProgressListener listener : jobInProgressListeners) {
          try {
            listener.jobAdded(job);
          } catch (IOException ioe) {
            LOG.warn("Failed to add and so skipping the job : "
                + job.getJobID() + ". Exception : " + ioe);
          }
        }
      }
    }
    myInstrumentation.submitJob(job.getJobConf(), jobId);
    String jobName = job.getJobConf().getJobName();
    int jobNameLen = 64;
    if (jobName.length() > jobNameLen) {
      jobName = jobName.substring(0, jobNameLen); // Truncate for logging.
    }
    LOG.info("Job " + jobId + "(" + jobName +
             ") added successfully for user '" + job.getJobConf().getUser() +
             "' to queue '" + job.getJobConf().getQueueName() + "'" +
             ", source " + job.getJobConf().getJobSource());
    return job.getStatus();
  }