Пример #1
0
  private void initState() {

    int numNodes = state.getNodeMap().size();
    int numSlots = numNodes * slotsPerNode;

    this.legend = new Legend(null, null, 0);

    int latSides = (int) Math.ceil(Math.pow(numNodes, 1 / 3.0));
    log.info("Lattice of " + numNodes + " requires " + latSides + " per side");
    this.lattice = new Lattice<Lattice<Void>>(latSides);

    List<String> nodeNames = new ArrayList<String>();
    List<Lattice<Void>> nodeLatti = new ArrayList<Lattice<Void>>();
    for (GridNode node : state.getNodeMap().values()) {
      Lattice<Void> nodeLattice = new Lattice<Void>(nodeLatSides);

      List<String> slotNames = new ArrayList<String>();
      List<Void> slots = new ArrayList<Void>();
      for (int i = 0; i < slotsPerNode; i++) {
        slotNames.add("" + i);
        slots.add(null);
      }
      nodeLattice.addItems(slotNames, slots);

      nodeNames.add(node.getShortName());
      nodeLatti.add(nodeLattice);
      // log.warn("Adding lattice for node "+node.getShortName());
    }

    lattice.addItems(nodeNames, nodeLatti);

    // Initialize actors from the grid state
    for (GridNode node : state.getNodeMap().values()) {

      int s = 0;
      for (GridJob job : node.getSlots()) {
        if (job == null) continue;
        String slotName = s + "";
        JobActor jobActor = createJobActor(job);
        jobActor.pos = getLatticePos(node.getShortName(), slotName);
        log.info(
            "Starting job {} on slot: {}",
            job.getFullJobId(),
            node.getShortName() + "#" + slotName);
        addJobActor(job.getFullJobId(), jobActor);
        s++;
      }
    }
  }
Пример #2
0
  private List<GridEvent> getNextSlice(long elapsed) {

    List<GridEvent> slice = new ArrayList<GridEvent>();
    if (elapsed <= 0) return slice;

    this.totalElapsed += elapsed;

    log.trace("getNextSlice, prevElapsed={}, totalElapsed={}", prevElapsed, totalElapsed);

    if (prevElapsed >= totalElapsed) {
      log.warn(
          "No slice possible with (prevElapsed={}, totalElapsed={})", prevElapsed, totalElapsed);
      return slice;
    }

    long start = prevElapsed;
    long end = totalElapsed;

    SortedMap<Long, List<Event>> eventSlice = timeline.getEvents(start, end);

    if (!eventSlice.isEmpty()) {
      // We only move the start of the window up when we find an event. This done because the
      // database might
      // have gaps if the incoming events cannot be processed in real-time. In that case, we don't
      // want to
      // miss any events if they come late.
      this.prevElapsed = totalElapsed;

      log.trace("Timeline has {} offset buckets", timeline.getNumOffsets());
      log.info(
          "Requested slice where {}<=t<{} and got " + eventSlice.size() + " buckets", start, end);
    }

    if (!eventSlice.isEmpty()) {
      for (Long offset : eventSlice.keySet()) {
        log.trace("Got offset bucket {}", offset);
        if (offset >= totalElapsed) {
          log.warn(
              "Timeline returned grid events outside the requested frame: {}>{}",
              offset,
              totalElapsed);
          break;
        }
        List<Event> events = eventSlice.get(offset);
        synchronized (events) {
          if (events.isEmpty()) {
            log.trace("Got empty offset bucket for offset {}", offset);
          }
          for (Event event : events) {
            if (event instanceof GridEvent) {
              GridEvent gridEvent = (GridEvent) event;
              log.trace("Got grid event {}", gridEvent);
              slice.add(gridEvent);
            } else if (event instanceof SnapshotEvent) {
              SnapshotEvent gridEvent = (SnapshotEvent) event;
              log.trace("Got snapshot event {}", gridEvent);
            } else {
              log.trace("Got unrecognized event {}", event);
            }
          }
        }
      }
    }

    return slice;
  }