コード例 #1
0
  /*
   * Much of the EC2 data is beyond our direct control, therefore we need to refresh it from time to time to ensure we
   * reflect the reality of the instances.
   */
  protected void fetchLiveInstanceData(boolean force) throws AmazonClientException {
    /*
     * If we've grabbed the data recently, don't bother getting it again unless we are forced
     */
    long now = System.currentTimeMillis();
    if ((lastFetchTime > 0) && (now - lastFetchTime < MIN_FETCH_TIME) && !force) {
      return;
    }

    if (getInstanceId() == null || getInstanceId() == "") {
      /*
       * The getInstanceId() implementation on EC2SpotSlave can return null if the spot request doesn't yet know
       * the instance id that it is starting. What happens is that null is passed to getInstanceId() which
       * searches AWS but without an instanceID the search returns some random box. We then fetch its metadata,
       * including tags, and then later, when the spot request eventually gets the instanceID correctly we push
       * the saved tags from that random box up to the new spot resulting in confusion and delay.
       */
      return;
    }

    Instance i = getInstance(getInstanceId(), getCloud());

    lastFetchTime = now;
    lastFetchInstance = i;
    if (i == null) return;

    publicDNS = i.getPublicDnsName();
    privateDNS = i.getPrivateIpAddress();
    createdTime = i.getLaunchTime().getTime();
    tags = new LinkedList<EC2Tag>();

    for (Tag t : i.getTags()) {
      tags.add(new EC2Tag(t.getKey(), t.getValue()));
    }
  }
コード例 #2
0
 /** 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());
 }
コード例 #3
0
 /** 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());
   }
 }