示例#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 PVector getLatticePos(String nodeName, String slotName) {

    PVector nodeLoc = lattice.getLocation(nodeName);
    Lattice<Void> slotLat = lattice.getContents(nodeName);

    if (slotLat == null) {
      log.warn("No slot lattice for node " + nodeName);
      return new PVector(0, 0, 0);
    }

    // Node position within the lattice, natural coordinates
    float nodeOffset = nodeSize + 2 * nodePadding;
    PVector nodePos = nodeLoc.get();
    nodePos.mult(nodeOffset);
    nodePos.add(nodePadding, nodePadding, nodePadding);

    PVector slotLoc = slotLat.getLocation(slotName);
    if (slotLoc == null) {
      log.warn("No slot location for slot " + slotName + " in node " + nodeName);
      return nodePos.get();
    }

    // TODO: cache these calculations

    // Slot position within the node, natural coordinates
    float slotOffset = jobSize + 2 * jobPadding;
    PVector slotPos = slotLoc.get();
    slotPos.mult(slotOffset);
    slotPos.add(jobPadding, jobPadding, jobPadding);

    // Combine node and slot position, natural coordinates
    PVector pos = slotPos.get();
    pos.add(nodePos);

    // Convert into central coordinate system
    float latticeWidth = lattice.size * nodeOffset;
    float t = latticeWidth / 2;
    pos.sub(t, t, t);

    return pos;
  }