Creates a slave job by copying the original job and adding a
{@link MaxRowsFilter} as a default requirement.

@param job
@param firstRow
@param maxRows
@return
779282
private AnalysisJob buildSlaveJob(final AnalysisJob job, final int slaveJobIndex, final int firstRow,
            final int maxRows) {
        logger.info("Building slave job {} with firstRow={} and maxRow={}", slaveJobIndex + 1, firstRow, maxRows);

        try (AnalysisJobBuilder jobBuilder = new AnalysisJobBuilder(_configuration, job)) {

            final FilterComponentBuilder<MaxRowsFilter, Category> maxRowsFilter =
                    jobBuilder.addFilter(MaxRowsFilter.class);
            maxRowsFilter.getComponentInstance().setFirstRow(firstRow);
            maxRowsFilter.getComponentInstance().setMaxRows(maxRows);

            final boolean naturalRecordOrderConsistent =
                    jobBuilder.getDatastore().getPerformanceCharacteristics().isNaturalRecordOrderConsistent();
            if (!naturalRecordOrderConsistent) {
                final InputColumn<?> orderColumn = findOrderByColumn(jobBuilder);
                maxRowsFilter.getComponentInstance().setOrderColumn(orderColumn);
            }

            jobBuilder.setDefaultRequirement(maxRowsFilter, MaxRowsFilter.Category.VALID);

            // in assertion/test mode do an early validation
            assert jobBuilder.isConfigured(true);

            return jobBuilder.toAnalysisJob();
        }
    }
672844
public boolean newrow(String rowdata[]) {
	if (rowdata != null) {
	    if (maxrows > 0 && nrows >= maxrows) {
		atmaxrows = true;
		return true;
	    }
	    rows.addElement(rowdata);
	    nrows++;
	}
	return false;
    }
1021459
public AnalysisResultFuture runJob(final AnalysisJob job, final String slaveJobId) {
        return runJob(job, slaveJobId, new AnalysisListener[0]);
    }
979494
@Override
	public RuntimeJobExecution createJobExecution(JobInstance jobInstance, Properties jobParameters, BatchStatus batchStatus) {
		Timestamp now = new Timestamp(System.currentTimeMillis());
		long newExecutionId = createRuntimeJobExecutionEntry(jobInstance, jobParameters, batchStatus, now);
		RuntimeJobExecution jobExecution = new RuntimeJobExecution(jobInstance, newExecutionId);
		jobExecution.setBatchStatus(batchStatus.name());
		jobExecution.setCreateTime(now);
		jobExecution.setLastUpdateTime(now);
		return jobExecution;
	}
1269847
public synchronized void addJob(JobInProgress job) {
    String poolName = getPoolName(job);
    LOG.info("Adding job " + job.getJobID() + " to pool " + poolName +
             ", originally from pool " +
             job.getJobConf().get(EXPLICIT_POOL_PROPERTY));
    getPool(poolName).addJob(job);
  }
1168118
public void configure(JobConf job) {
    this.inputFile = job.get("map.input.file");
    maxNumItems = job.getLong("aggregate.max.num.unique.values",
                              Long.MAX_VALUE);
  }
28605
public boolean createJob(Map<Integer, BaseContainer> jobDefinition) {
    synchronized (this) {
      if (isTerminated) {
        LOG.severe("Job has been killed");
        return false;
      }

      // Record the jobDefinition
      containersInfo.putAll(jobDefinition);

      // To scheduler them with 0 attempt
      for (Map.Entry<Integer, BaseContainer> entry : jobDefinition.entrySet()) {
        Integer containerIndex = entry.getKey();
        BaseContainer container = entry.getValue();
        String taskId = TaskUtils.getTaskId(container.name, 0);
        scheduleNewTask(taskId);
      }
    }

    return true;
  }
1254426
public JobReport execute(Job job) {
        try {
            return executorService.submit(job).get();
        } catch (InterruptedException | ExecutionException e) {
            throw new RuntimeException("Unable to execute job " + job.getName(), e);
        }
    }
822870
protected Object execute(final Job job, final String curQueue, final Object instance) throws Exception {
        final Object result;
        if (instance instanceof WorkerAware) {
            ((WorkerAware) instance).setWorker(this.workerRef.get());
        }
        if (instance instanceof Callable) {
            result = ((Callable<?>) instance).call(); // The job is executing!
        } else if (instance instanceof Runnable) {
            ((Runnable) instance).run(); // The job is executing!
            result = null;
        } else { // Should never happen since we're testing the class earlier
            throw new ClassCastException("instance must be a Runnable or a Callable: " + instance.getClass().getName() 
                    + " - " + instance);
        }
        return result;
    }
330747
public Flow<JobXMLDescriptor> getOrCreateFlow()
   {
      List<Node> nodeList = model.get("flow");
      if (nodeList != null &&  nodeList.size() > 0)
      {
         return new FlowImpl<JobXMLDescriptor>(this, "flow", model, nodeList.get(0));
      }
      return createFlow();
   }
1245114
public DataRow createRow() {
		DataRow row = new DataRow(columns);
		rows.add(row);
		return row;
	}
872056
@Nonnull
  @Nonempty
  public String onStartJob (@Nonnull final ILongRunningJob aJob, @Nullable final String sStartingUserID)
  {
    ValueEnforcer.notNull (aJob, "Job");

    // Create a new unique in-memory ID
    final String sJobID = GlobalIDFactory.getNewStringID ();
    final LongRunningJobData aJobData = new LongRunningJobData (sJobID, aJob.getJobDescription (), sStartingUserID);
    m_aRWLock.writeLocked ( () -> m_aRunningJobs.put (sJobID, aJobData));
    return sJobID;
  }
806022
protected Object execute(final Job job, final String curQueue, final Object instance) throws Exception {
        if (instance instanceof WorkerAware) {
            ((WorkerAware) instance).setWorker(this);
        }
        this.listenerDelegate.fireEvent(JOB_EXECUTE, this, curQueue, job, instance, null, null);
        final Object result;
        if (instance instanceof Callable) {
            result = ((Callable<?>) instance).call(); // The job is executing!
        } else if (instance instanceof Runnable) {
            ((Runnable) instance).run(); // The job is executing!
            result = null;
        } else { // Should never happen since we're testing the class earlier
            throw new ClassCastException(
                    "Instance must be a Runnable or a Callable: " + instance.getClass().getName() + " - " + instance);
        }
        return result;
    }
146552
private List<Flow> createFromResults(Scan scan, boolean populateTasks,
      int maxCount) throws IOException {
    List<Flow> flows = new ArrayList<Flow>();
    ResultScanner scanner = null;
    try {
      Stopwatch timer = new Stopwatch().start();
      Stopwatch timerJob = new Stopwatch();
      int rowCount = 0;
      long colCount = 0;
      long resultSize = 0;
      int jobCount = 0;
      Table historyTable =
          hbaseConnection.getTable(TableName.valueOf(Constants.HISTORY_TABLE));
      scanner = historyTable.getScanner(scan);
      Flow currentFlow = null;
      for (Result result : scanner) {
        if (result != null && !result.isEmpty()) {
          rowCount++;
          colCount += result.size();
          // TODO dogpiledays resultSize += result.getWritableSize();
          JobKey currentKey = jobKeyConv.fromBytes(result.getRow());
          // empty runId is special cased -- we need to treat each job as it's
          // own flow
          if (currentFlow == null || !currentFlow.contains(currentKey)
              || currentKey.getRunId() == 0) {
            // return if we've already hit the limit
            if (flows.size() >= maxCount) {
              break;
            }
            currentFlow = new Flow(new FlowKey(currentKey));
            flows.add(currentFlow);
          }
          timerJob.start();
          JobDetails job = new JobDetails(currentKey);
          job.populate(result);
          currentFlow.addJob(job);
          jobCount++;
          timerJob.stop();
        }
      }
      historyTable.close();
      timer.stop();
      LOG.info("Fetched from hbase " + rowCount + " rows, " + colCount
          + " columns, " + flows.size() + " flows and " + jobCount
          + " jobs taking up " + resultSize + " bytes ( "
          + resultSize / (1024.0 * 1024.0) + " atomic double: "
          + new AtomicDouble(resultSize / (1024.0 * 1024.0))
          + ") MB, in total time of " + timer + " with  " + timerJob
          + " spent inJobDetails & Flow population");

      // export the size of data fetched from hbase as a metric
      HravenResponseMetrics.FLOW_HBASE_RESULT_SIZE_VALUE
          .set(resultSize / (1024.0 * 1024.0));
    } finally {
      if (scanner != null) {
        scanner.close();
      }
    }

    if (populateTasks) {
      populateTasks(flows);
    }

    return flows;
  }
524373
public static Job startOneJob(Worker newWorker, 
      Priority pri, Set<String> jobFiles, long detectTime, 
      AtomicLong numFilesSubmitted, AtomicLong lastCheckingTime,
      long maxPendingJobs) 
          throws IOException, InterruptedException, ClassNotFoundException {
    if (lastCheckingTime != null) {
      lastCheckingTime.set(System.currentTimeMillis());
    }
    String startTimeStr = dateFormat.format(new Date());
    String jobName = newWorker.JOB_NAME_PREFIX + "." + newWorker.jobCounter + 
        "." + pri + "-pri" + "." + startTimeStr;
    Job job = null;
    synchronized(jobFiles) {
      if (jobFiles.size() == 0) {
        return null;
      }
      newWorker.jobCounter++;
      
      synchronized(newWorker.jobIndex) {
        if (newWorker.jobIndex.size() >= maxPendingJobs) {
          // full 
          return null;
        }
        job = newWorker.startJob(jobName, jobFiles, pri, detectTime);
      }
      numFilesSubmitted.addAndGet(jobFiles.size());
      jobFiles.clear();
      
    }
    return job;
  }
698361
public JenkinsServer createJob(String jobName, String jobXml) throws IOException {
        return createJob(null, jobName, jobXml, false);
    }
86759
@SuppressWarnings("unchecked")
  private static <E> Dataset<E> loadOrCreateJobDataset(JobContext jobContext) {
    Dataset<Object> dataset = load(jobContext).getDataset();
    String jobDatasetName = getJobDatasetName(jobContext);
    DatasetRepository repo = getDatasetRepository(jobContext);
    if (repo.exists(TEMP_NAMESPACE, jobDatasetName)) {
      Dataset<E> tempDataset = repo.load(TEMP_NAMESPACE, jobDatasetName,
        DatasetKeyOutputFormat.<E>getType(jobContext));
      try {
        Compatibility.checkCompatible(dataset.getDescriptor(),
          tempDataset.getDescriptor());
        return tempDataset;
      } catch (RuntimeException ex) {
        // swallow
      }
    }

    return repo.create(TEMP_NAMESPACE, jobDatasetName,
        copy(dataset.getDescriptor()),
        DatasetKeyOutputFormat.<E>getType(jobContext));
  }