Example #1
0
 // ejecting a ball will eject the ball from the machine add it to the rack.
 public Ball ejectBall() {
   // we check not to get null reference balls while we are ejecting from machine.
   if (machine.getNoOfBalls() > 0 && rack.getNoOfBalls() < rack.getSize()) {
     Ball ejectedBall = machine.ejectBall();
     rack.addBall(ejectedBall);
     return ejectedBall;
   } // if
   else return null;
 } // ejectBall
Example #2
0
  @Override
  public PhysicalmachineHB toPojoHB() {
    PhysicalmachineHB physicalMachineHB = new PhysicalmachineHB();

    physicalMachineHB.setDataCenter(getDataCenter().toPojoHB());

    physicalMachineHB.setIdPhysicalMachine(getId());
    physicalMachineHB.setName(StringUtils.substring(getName(), 0, 255)); // a fully qualified
    // domain name (FQDN)
    // is 255 octets -
    // where any one label
    // can be 63 octets
    // long at most (RFC
    // 2181)
    physicalMachineHB.setDescription(getDescription());
    physicalMachineHB.setCpu(getCpu());
    physicalMachineHB.setCpuUsed(getCpuUsed());
    physicalMachineHB.setRam(getRam());
    physicalMachineHB.setRamUsed(getRamUsed());
    Rack rack = (Rack) getAssignedTo();
    physicalMachineHB.setRack(rack.toPojoHB());
    physicalMachineHB.setIdState(getIdState());
    physicalMachineHB.setVswitchName(vswitchName);
    physicalMachineHB.setInitiatorIQN(initiatorIQN);
    physicalMachineHB.setIpmiIp(ipmiIp);
    physicalMachineHB.setIpmiPort(ipmiPort);
    physicalMachineHB.setIpmiUser(ipmiUser);
    physicalMachineHB.setIpmiPassword(ipmiPassword);
    Set<DatastoreHB> datastoresHB = new HashSet<DatastoreHB>();
    if (datastores != null) {
      for (Datastore datastore : datastores) {
        datastoresHB.add(datastore.toPojoHB());
      }
    }
    physicalMachineHB.setDatastoresHB(datastoresHB);
    if (idEnterprise != null) {
      physicalMachineHB.setIdEnterprise(idEnterprise.intValue() != 0 ? idEnterprise : null);
    }

    if (hypervisor != null) {
      physicalMachineHB.setHypervisor(hypervisor.toPojoHB(physicalMachineHB));
    }

    return physicalMachineHB;
  }
Example #3
0
  public boolean rackIsInDatacenter(final Rack rack) {
    assert rack != null;

    return getDatacenter().getId() == rack.getDatacenter().getId();
  }
Example #4
0
    private List<Node> selectCandidateNodes(NodeMap nodeMap, Split split) {
      Set<Node> chosen = new LinkedHashSet<>(minCandidates);

      // first look for nodes that match the hint
      for (HostAddress hint : split.getAddresses()) {
        for (Node node : nodeMap.getNodesByHostAndPort().get(hint)) {
          if (chosen.add(node)) {
            scheduleLocal.incrementAndGet();
          }
        }

        InetAddress address;
        try {
          address = hint.toInetAddress();
        } catch (UnknownHostException e) {
          // skip addresses that don't resolve
          continue;
        }

        // consider a split with a host hint without a port as being accessible
        // by all nodes in that host
        if (!hint.hasPort() || split.isRemotelyAccessible()) {
          for (Node node : nodeMap.getNodesByHost().get(address)) {
            if (chosen.add(node)) {
              scheduleLocal.incrementAndGet();
            }
          }
        }
      }

      // add nodes in same rack, if below the minimum count
      if (split.isRemotelyAccessible() && chosen.size() < minCandidates) {
        for (HostAddress hint : split.getAddresses()) {
          InetAddress address;
          try {
            address = hint.toInetAddress();
          } catch (UnknownHostException e) {
            // skip addresses that don't resolve
            continue;
          }
          for (Node node : nodeMap.getNodesByRack().get(Rack.of(address))) {
            if (chosen.add(node)) {
              scheduleRack.incrementAndGet();
            }
            if (chosen.size() == minCandidates) {
              break;
            }
          }
          if (chosen.size() == minCandidates) {
            break;
          }
        }
      }

      // add some random nodes if below the minimum count
      if (split.isRemotelyAccessible()) {
        if (chosen.size() < minCandidates) {
          for (Node node : lazyShuffle(nodeMap.getNodesByHost().values())) {
            if (chosen.add(node)) {
              scheduleRandom.incrementAndGet();
            }

            if (chosen.size() == minCandidates) {
              break;
            }
          }
        }
      }

      return ImmutableList.copyOf(chosen);
    }
Example #5
0
 // The end user can want to sort the balls in the rack.
 public void rackSortBalls() {
   rack.sortBalls();
 } // rackSortBalls
Example #6
0
 // CleverPunter objects probably will want to check that their is contained in the rack.
 public boolean rackContains(int value) {
   return rack.contains(value);
 } // rackContains
Example #7
0
 public int getRackNoOfBalls() {
   return rack.getNoOfBalls();
 } // getRackNoOfBalls
Example #8
0
 public int getRackSize() {
   return rack.getSize();
 } // getRackSize