Esempio n. 1
0
 /** Finds a job with given dest key or returns null */
 public static Job findJobByDest(final Key destKey) {
   Job job = null;
   for (Job current : Job.all()) {
     if (current.dest().equals(destKey)) {
       job = current;
       break;
     }
   }
   return job;
 }
Esempio n. 2
0
  // Expand grid search related argument sets
  @Override
  protected NanoHTTPD.Response serveGrid(NanoHTTPD server, Properties parms, RequestType type) {
    String[][] values = new String[_arguments.size()][];
    boolean gridSearch = false;
    for (int i = 0; i < _arguments.size(); i++) {
      Argument arg = _arguments.get(i);
      if (arg._gridable) {
        String value = _parms.getProperty(arg._name);
        if (value != null) {
          // Skips grid if argument is an array, except if imbricated expression
          // Little hackish, waiting for real language
          boolean imbricated = value.contains("(");
          if (!arg._field.getType().isArray() || imbricated) {
            values[i] = split(value);
            if (values[i] != null && values[i].length > 1) gridSearch = true;
          } else if (arg._field.getType().isArray()
              && !imbricated) { // Copy values which are arrays
            values[i] = new String[] {value};
          }
        }
      }
    }
    if (!gridSearch) return superServeGrid(server, parms, type);

    // Ignore destination key so that each job gets its own
    _parms.remove("destination_key");
    for (int i = 0; i < _arguments.size(); i++)
      if (_arguments.get(i)._name.equals("destination_key")) values[i] = null;

    // Iterate over all argument combinations
    int[] counters = new int[values.length];
    ArrayList<Job> jobs = new ArrayList<Job>();
    for (; ; ) {
      Job job = (Job) create(_parms);
      Properties combination = new Properties();
      for (int i = 0; i < values.length; i++) {
        if (values[i] != null) {
          String value = values[i][counters[i]];
          value = value.trim();
          combination.setProperty(_arguments.get(i)._name, value);
          _arguments.get(i).reset();
          _arguments.get(i).check(job, value);
        }
      }
      job._parms = combination;
      jobs.add(job);
      if (!increment(counters, values)) break;
    }
    GridSearch grid = new GridSearch();
    grid.jobs = jobs.toArray(new Job[jobs.size()]);
    return grid.superServeGrid(server, parms, type);
  }
Esempio n. 3
0
  /**
   * Block synchronously waiting for a job to end, success or not.
   *
   * @param jobkey Job to wait for.
   * @param pollingIntervalMillis Polling interval sleep time.
   */
  public static void waitUntilJobEnded(Key jobkey, int pollingIntervalMillis) {
    while (true) {
      if (Job.isEnded(jobkey)) {
        return;
      }

      try {
        Thread.sleep(pollingIntervalMillis);
      } catch (Exception ignore) {
      }
    }
  }
Esempio n. 4
0
 @Override
 public float progress() {
   double d = 0.1;
   for (Job job : jobs) d += job.progress();
   return Math.min(1f, (float) (d / jobs.length));
 }
Esempio n. 5
0
 @Override
 protected void onCancelled() {
   for (Job job : jobs) job.cancel();
 }
Esempio n. 6
0
 @Override
 public void remove() {
   super.remove();
   UKV.remove(_progress);
 }
Esempio n. 7
0
 /**
  * Check if given job is running.
  *
  * @param job_key job key
  * @return true if job is still running else returns false.
  */
 public static boolean isRunning(Key job_key) {
   Job j = UKV.get(job_key);
   assert j != null : "Job should be always in DKV!";
   return j.isRunning();
 }