Ejemplo n.º 1
0
  private static TimeBox generateTimeSpanForDay(Integer notUsed, Clock clock) {

    DateTime start;
    DateTime end;

    start = clock.getTime().withTime(0, 0, 0, 0);
    end = clock.getTime().withTime(23, 59, 59, 99);

    return new TimeBox(start, end);
  }
Ejemplo n.º 2
0
 /**
  * Clears all the logs in userlog directory.
  *
  * <p>Adds the job directories for deletion with default retain hours. Deletes all other
  * directories, if any. This is usually called on reinit/restart of the TaskTracker
  *
  * @param conf
  * @throws IOException
  */
 void clearOldUserLogs(Configuration conf) throws IOException {
   File userLogDir = TaskLog.getUserLogDir();
   if (userLogDir.exists()) {
     String[] logDirs = userLogDir.list();
     if (logDirs.length > 0) {
       // add all the log dirs to taskLogsMnonitor.
       long now = clock.getTime();
       for (String logDir : logDirs) {
         if (logDir.equals(logAsyncDisk.TOBEDELETED)) {
           // skip this
           continue;
         }
         JobID jobid = null;
         try {
           jobid = JobID.forName(logDir);
         } catch (IllegalArgumentException ie) {
           // if the directory is not a jobid, delete it immediately
           deleteLogPath(new File(userLogDir, logDir).getAbsolutePath());
           continue;
         }
         // add the job log directory with default retain hours, if it is not
         // already added
         if (!completedJobs.containsKey(jobid)) {
           markJobLogsForDeletion(now, conf, jobid);
         }
       }
     }
   }
 }
Ejemplo n.º 3
0
 /**
  * Recompute the internal variables used by the scheduler - per-job weights, fair shares,
  * deficits, minimum slot allocations, and numbers of running and needed tasks of each type.
  */
 protected synchronized void update() {
   // Remove non-running jobs
   List<JobInProgress> toRemove = new ArrayList<JobInProgress>();
   for (JobInProgress job : infos.keySet()) {
     int runState = job.getStatus().getRunState();
     if (runState == JobStatus.SUCCEEDED
         || runState == JobStatus.FAILED
         || runState == JobStatus.KILLED) {
       toRemove.add(job);
     }
   }
   for (JobInProgress job : toRemove) {
     infos.remove(job);
     poolMgr.removeJob(job);
   }
   // Update running jobs with deficits since last update, and compute new
   // slot allocations, weight, shares and task counts
   long now = clock.getTime();
   long timeDelta = now - lastUpdateTime;
   updateDeficits(timeDelta);
   updateRunnability();
   updateTaskCounts();
   updateWeights();
   updateMinSlots();
   updateFairShares();
   lastUpdateTime = now;
 }
  @Override
  public void report(
      SortedMap<String, Gauge> gauges,
      SortedMap<String, Counter> counters,
      SortedMap<String, Histogram> histograms,
      SortedMap<String, Meter> meters,
      SortedMap<String, Timer> timers) {
    final Date timestamp = new Date(clock.getTime());

    List<DBObject> docs =
        Lists.newArrayListWithExpectedSize(
            gauges.size() + counters.size() + histograms.size() + meters.size() + timers.size());

    collectGaugeReports(docs, gauges, timestamp);
    collectCounterReports(docs, counters, timestamp);
    collectHistogramReports(docs, histograms, timestamp);
    collectMeterReports(docs, meters, timestamp);
    collectTimerReports(docs, timers, timestamp);

    try {
      final DBCollection collection =
          mongoConnection.getDatabase().getCollection("graylog2_metrics");
      // don't hang on to the data for too long.
      final BasicDBObject indexField = new BasicDBObject("timestamp", 1);
      final BasicDBObject indexOptions = new BasicDBObject("expireAfterSeconds", 5 * 60);
      collection.createIndex(indexField, indexOptions);

      collection.insert(docs, WriteConcern.UNACKNOWLEDGED);
    } catch (Exception e) {
      LOG.warn("Unable to write graylog2 metrics to mongodb. Ignoring this error.", e);
    }
  }
 @Override
 public void run() {
   try {
     final DateFormat format =
         DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.MEDIUM, locale);
     format.setTimeZone(timeZone);
     final String dateTime = format.format(new Date(clock.getTime()));
     out.print(dateTime);
     out.print(' ');
     for (int i = 0; i < (CONSOLE_WIDTH - dateTime.length() - 1); i++) {
       out.print('=');
     }
     out.println();
     for (Entry<String, SortedMap<MetricName, Metric>> entry :
         getMetricsRegistry().getGroupedMetrics(predicate).entrySet()) {
       out.print(entry.getKey());
       out.println(':');
       for (Entry<MetricName, Metric> subEntry : entry.getValue().entrySet()) {
         out.print("  ");
         out.print(subEntry.getKey().getName());
         out.println(':');
         subEntry.getValue().processWith(this, subEntry.getKey(), out);
         out.println();
       }
       out.println();
     }
     out.println();
     out.flush();
   } catch (Exception e) {
     e.printStackTrace(out);
   }
 }
Ejemplo n.º 6
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;
    }
  }
Ejemplo n.º 7
0
  private static TimeBox generateTimeSpanForWeek(Integer unit, Clock clock) {

    DateTime start;
    DateTime end;

    start = clock.getTime().withDayOfWeek(1).withTime(0, 0, 0, 0);
    end = clock.createDate(start.plusWeeks(unit - 1).withDayOfWeek(5).withTime(23, 59, 59, 99));

    return new TimeBox(start, end);
  }
Ejemplo n.º 8
0
  public static TimeBox generateLastMonth(Clock clock) {

    DateTime start;
    DateTime end;

    start = clock.getTime().minusMonths(1).withDayOfMonth(1).withTime(0, 0, 0, 0);
    end = clock.createDate(start.plusMonths(1).minusDays(1).withTime(23, 59, 59, 99));

    return new TimeBox(start, end);
  }
Ejemplo n.º 9
0
  public static void main(String[] args) {

    Scanner sin = new Scanner(System.in);

    System.out.println("12 hour or 24 hour time?");

    int choice = sin.nextInt();

    if (choice == 12) {

      Clock c = new Clock(00, 00, 00, "AM");
      Clock c2 = new Clock(14, 27, 26, "PM");
      System.out.println(c2.getTime());
      System.out.println(c.getTime());
    } else {
      Clock c = new MilitaryClock(00, 00, 00);
      Clock c2 = new MilitaryClock(14, 27, 26);
      System.out.println(c2.getTime());
      System.out.println(c.getTime());
    }
  }
Ejemplo n.º 10
0
 @Override
 public void start() {
   try {
     Configuration conf = getConf();
     eagerInitListener.start();
     taskTrackerManager.addJobInProgressListener(eagerInitListener);
     taskTrackerManager.addJobInProgressListener(jobListener);
     poolMgr = new PoolManager(conf);
     loadMgr =
         (LoadManager)
             ReflectionUtils.newInstance(
                 conf.getClass(
                     "mapred.fairscheduler.loadmanager",
                     CapBasedLoadManager.class,
                     LoadManager.class),
                 conf);
     loadMgr.setTaskTrackerManager(taskTrackerManager);
     loadMgr.start();
     taskSelector =
         (TaskSelector)
             ReflectionUtils.newInstance(
                 conf.getClass(
                     "mapred.fairscheduler.taskselector",
                     DefaultTaskSelector.class,
                     TaskSelector.class),
                 conf);
     taskSelector.setTaskTrackerManager(taskTrackerManager);
     taskSelector.start();
     Class<?> weightAdjClass = conf.getClass("mapred.fairscheduler.weightadjuster", null);
     if (weightAdjClass != null) {
       weightAdjuster = (WeightAdjuster) ReflectionUtils.newInstance(weightAdjClass, conf);
     }
     assignMultiple = conf.getBoolean("mapred.fairscheduler.assignmultiple", false);
     sizeBasedWeight = conf.getBoolean("mapred.fairscheduler.sizebasedweight", false);
     initialized = true;
     running = true;
     lastUpdateTime = clock.getTime();
     // Start a thread to update deficits every UPDATE_INTERVAL
     if (runBackgroundUpdates) new UpdateThread().start();
     // Register servlet with JobTracker's Jetty server
     if (taskTrackerManager instanceof JobTracker) {
       JobTracker jobTracker = (JobTracker) taskTrackerManager;
       StatusHttpServer infoServer = jobTracker.infoServer;
       infoServer.setAttribute("scheduler", this);
       infoServer.addServlet("scheduler", "/scheduler", FairSchedulerServlet.class);
     }
   } catch (Exception e) {
     // Can't load one of the managers - crash the JobTracker now while it is
     // starting up so that the user notices.
     throw new RuntimeException("Failed to start FairScheduler", e);
   }
   LOG.info("Successfully configured FairScheduler");
 }
Ejemplo n.º 11
0
  private static TimeBox generateTimeSpanForDay(Integer unit, Clock clock, TimeBox next) {

    DateTime start;
    DateTime end;

    int nextDay = clock.createDate(next.getEnd()).getDayOfWeek();
    if (nextDay > 5)
      start = clock.createDate(next.getEnd().plusWeeks(1).withDayOfWeek(1).withTime(0, 0, 0, 0));
    else start = clock.createDate(next.getEnd().plusDays(1).withTime(0, 0, 0, 0));

    end = clock.getTime().withTime(23, 59, 59, 99);

    return new TimeBox(start, end);
  }
Ejemplo n.º 12
0
 void processCompletedJobs() throws IOException {
   long now = clock.getTime();
   // iterate through completedJobs and remove old logs.
   synchronized (completedJobs) {
     Iterator<Entry<JobID, Long>> completedJobIter = completedJobs.entrySet().iterator();
     while (completedJobIter.hasNext()) {
       Entry<JobID, Long> entry = completedJobIter.next();
       // see if the job is old enough
       if (entry.getValue().longValue() <= now) {
         // add the job logs directory to for delete
         deleteLogPath(TaskLog.getJobDir(entry.getKey()).getAbsolutePath());
         completedJobIter.remove();
       }
     }
   }
 }
Ejemplo n.º 13
0
  // змейка будет двигаться как только нужная задержка была достигнута
  // обрабатывает внесенные изменения и обновляет игровое поле
  @Override
  public void update(long nanosPassed) {

    processInput();
    if (!paused) {
      if (isGameOver()) {
        game.setScene(new GameOverScence(game, panel, delay));
        return;
      }

      if (snakeMoveDelay.updateAndCheck(nanosPassed)) {
        stepsCount++;
        mlSeconds += 200;
        String seconds = Clock.getTime(mlSeconds);
        panel.setData(seconds, stepsCount, appleCount);

        snake.move(); // удлинение змейки, при поедании яблока
        BodyPart head = snake.head();
        if (head.getX() < 1) {
          head.setX(WORLD_WIDTH);
        }
        if (head.getX() > WORLD_WIDTH) {
          head.setX(1);
        }
        if (head.getY() < 1) {
          head.setY(WORLD_HEIGHT);
        }
        if (head.getY() > WORLD_HEIGHT) {
          head.setY(1);
        }
        if (head.getX() == apple.getX() && head.getY() == apple.getY()) {
          List<BodyPart> body = snake.getBody();
          BodyPart lastPart = body.get(body.size() - 1);
          body.add(new BodyPart(lastPart.getX(), lastPart.getY()));
          ++appleCount;
          if (isGameOver()) {
            game.setScene(new GameOverScence(game, panel, delay));
          } else {
            placeApple();
          }
        }
      }
    }
  }
 private long currentTimeInSeconds() {
   return TimeUnit.MILLISECONDS.toSeconds(clock.getTime());
 }
Ejemplo n.º 15
0
  public int executeFrame() {
    // printf("EXEC BEGIN\n");
    //
    // Run one frame. This takes the time stamp marking the end of the frame
    // and then processes events for that frame retroactively. This method
    // has
    // the advantage of flexibility, especially if the frame rate
    // fluctuates.
    // However it is always a little behind, because it can't compute the
    // frame length until the end of the frame is reached. With a fixed
    // known
    // frame rate you could optimize things a bit and make the start/end
    // times
    // correspond exactly with real time.
    //
    m_clock.beginFrame();
    // long started = m_clock.GetSystem();

    //
    // Execute any time-based tasks
    //
    // (1) Pop the next task off the list. Since the list is always
    // sorted, the first item in the list is always the next task.
    // (2) Execute it and update times
    // (3) If it's expired, delete it
    // Otherwise, insert it into the list in its new position
    //
    TaskInfo pTaskInfo = null;
    TaskInfo save = m_pTaskList;
    pTaskInfo = getNextTimeTask(pTaskInfo);
    while (pTaskInfo != null) {
      m_clock.advanceTo(pTaskInfo.time.next);

      pTaskInfo.pTask.execute(pTaskInfo.id, m_clock.getTime(), pTaskInfo.pUser);
      pTaskInfo.time.last = pTaskInfo.time.next;
      pTaskInfo.time.next += pTaskInfo.time.period;
      pTaskInfo = getNextTimeTask(pTaskInfo);
    }
    m_pTaskList = save;
    pTaskInfo = m_pTaskList;
    while (pTaskInfo != null) {

      if (pTaskInfo.time.duration == 0 || pTaskInfo.time.duration >= pTaskInfo.time.next) {
        // re-insert into list with updated time
        // InsertTimeTask(pTaskInfo);
      } else {
        // task is expired, delete it
        // printf("Sched: Expired %d\n",pTaskInfo->id);
        // delete pTaskInfo;
        terminate(pTaskInfo.id);
      }
      pTaskInfo = pTaskInfo.pNext;
    }

    //
    // Advance simulation clock to end of frame
    //
    m_clock.advanceToEnd();

    //
    // Now execute all frame tasks in round-robin fashion.
    // Frame tasks always execute at the end of the frame just
    // before rendering. A priority scheme could be used to
    // control sequence. It would be more efficient to keep the
    // list sorted, the same as with time tasks (exe
    //
    save = m_pFrameList;
    pTaskInfo = m_pFrameList;
    pTaskInfo = getNextFrameTask(pTaskInfo);
    // TaskInfo * pPrev = NULL;
    while (pTaskInfo != null) {
      pTaskInfo.pTask.execute(pTaskInfo.id, m_clock.getFrame(), pTaskInfo.pUser);
      pTaskInfo.time.last = pTaskInfo.time.next;
      pTaskInfo.time.next += pTaskInfo.time.period;
      pTaskInfo = getNextFrameTask(pTaskInfo);
    }
    m_pFrameList = save;
    // 检测是否有到期的任务
    pTaskInfo = m_pFrameList;
    while (pTaskInfo != null) {
      if (pTaskInfo.time.duration == 0 || pTaskInfo.time.duration >= pTaskInfo.time.next) {
        // re-insert into list with updated time
        // InsertFrameTask(pTaskInfo);
      } else {
        // task is expired, delete it
        // printf("Sched: Expired %d\n",pTaskInfo->id);
        // delete pTaskInfo;
        terminate(pTaskInfo.id);
      }
      pTaskInfo = pTaskInfo.pNext;
    }
    m_pFrameList = save;
    //
    // render
    //
    if (renderTask.pTask != null) {
      renderTask.pTask.execute(renderTask.id, m_clock.getFrame(), renderTask.pUser);
    }

    //
    // here is where we could do idle processing or load balancing
    //
    // long elapsed = m_clock.GetSystem() - started;
    // long frameLength = m_clock.GetFrameEnd() - m_clock.GetFrameStart();
    // printf("Busy %u ms, idle %u ms\n", elapsed, frameLength - elapsed);

    //
    // If any tasks are terminated during execution, it is easier to leave
    // them in the list until we're finished iterating through it, then
    // sweep
    // them out later.
    //
    // printf("EXEC END\n");
    for (Long i : queue) {
      terminate(i);
    }
    sweepGarbage();
    return 0;
  }