Esempio n. 1
0
  public ClusterInstance instance(String to) throws URISyntaxException {
    URI uri = new URI(to);
    for (ClusterInstance clusterInstance : instances) {
      URI instanceUri = clusterInstance.uri();
      if (instanceUri.getHost().equals(uri.getHost()) && instanceUri.getPort() == uri.getPort()) {
        return clusterInstance;
      }
    }

    throw new IllegalArgumentException("No instance in cluster at address: " + to);
  }
Esempio n. 2
0
  public ClusterState snapshot() {
    Set<ClusterAction> newPendingActions = new LinkedHashSet<>(pendingActions);

    // Clone the current state & perform the action on it to change it
    List<ClusterInstance> cloneInstances = new ArrayList<>();
    for (ClusterInstance clusterInstance : instances) {
      cloneInstances.add(clusterInstance.newCopy());
    }

    return new ClusterState(cloneInstances, newPendingActions);
  }
Esempio n. 3
0
  public boolean isDeadEnd() {
    if (pendingActions.size() > 0) {
      return false;
    }

    for (ClusterInstance instance : instances) {
      if (instance.hasPendingTimeouts()) {
        return false;
      }
    }

    return true;
  }
 /** Test of getMaster method, of class HadoopCluster. */
 @Test
 public void testGetMaster() {
   System.out.println("getMaster");
   ClusterInstance result = cluster.getMaster();
   assertNotNull(result);
   assertEquals(cluster.getMasterGroupName(), result.getSecurityGroups().get(0));
   Instance slaveInstance = result.getInstance();
   StringBuilder sb = new StringBuilder("\t");
   sb.append(slaveInstance.getInstanceId());
   sb.append(" ");
   sb.append(slaveInstance.getInstanceType());
   sb.append(" ");
   sb.append(slaveInstance.getLaunchTime().toString());
   sb.append(" ");
   sb.append(slaveInstance.getImageId());
   out.println(sb.toString());
 }
Esempio n. 5
0
  /**
   * Managing timeouts is trickier than putting all of them in a long list, like regular message
   * delivery. Timeouts are ordered and can be cancelled, so they need special treatment. Hence a
   * separate method for managing timeouts triggering.
   */
  private Pair<ClusterAction, ClusterState> performNextTimeoutFrom(ClusterInstance instance)
      throws Exception {
    ClusterState newState = snapshot();
    ClusterAction clusterAction = newState.instance(instance.uri().toASCIIString()).popTimeout();
    clusterAction.perform(newState);

    return Pair.of(clusterAction, newState);
  }
 /** Test of getSlaves method, of class HadoopCluster. */
 @Test
 public void testGetSlaves() {
   out.println("getSlaves");
   List<ClusterInstance> result = cluster.getSlaves();
   out.println("found " + result.size() + " slaves for group " + TEST_GROUP);
   assertNotNull(result);
   StringBuilder sb = new StringBuilder("\t");
   for (ClusterInstance slave : result) {
     assertEquals(cluster.getGroupName(), slave.getSecurityGroups().get(0));
     Instance slaveInstance = slave.getInstance();
     if (sb.length() > 1) sb.delete(1, sb.length());
     sb.append(slaveInstance.getInstanceId());
     sb.append(" ");
     sb.append(slaveInstance.getInstanceType());
     sb.append(" ");
     sb.append(slaveInstance.getLaunchTime().toString());
     sb.append(" ");
     sb.append(slaveInstance.getImageId());
     out.println(sb.toString());
   }
 }
Esempio n. 7
0
 @Override
 public boolean accept(ClusterInstance item) {
   return item.hasPendingTimeouts();
 }