public static FleetStateStats readClusterState(final AmazonEC2 ec2, final String fleetId) {
    String token = null;
    final Set<String> instances = new HashSet<String>();
    do {
      final DescribeSpotFleetInstancesRequest req = new DescribeSpotFleetInstancesRequest();
      req.setSpotFleetRequestId(fleetId);
      req.setNextToken(token);
      final DescribeSpotFleetInstancesResult res = ec2.describeSpotFleetInstances(req);
      for (final ActiveInstance instance : res.getActiveInstances()) {
        instances.add(instance.getInstanceId());
      }

      token = res.getNextToken();
    } while (token != null);

    final DescribeSpotFleetRequestsRequest req = new DescribeSpotFleetRequestsRequest();
    req.setSpotFleetRequestIds(Collections.singleton(fleetId));
    final DescribeSpotFleetRequestsResult fleet = ec2.describeSpotFleetRequests(req);
    if (fleet.getSpotFleetRequestConfigs().isEmpty())
      throw new IllegalStateException("Fleet " + fleetId + " can't be described");

    final SpotFleetRequestConfig fleetConfig = fleet.getSpotFleetRequestConfigs().get(0);

    return new FleetStateStats(
        fleetId,
        fleetConfig.getSpotFleetRequestConfig().getTargetCapacity(),
        fleetConfig.getSpotFleetRequestState(),
        instances);
  }
Exemplo n.º 2
0
  @Override
  public boolean equals(Object obj) {
    if (this == obj) return true;
    if (obj == null) return false;

    if (obj instanceof ActiveInstance == false) return false;
    ActiveInstance other = (ActiveInstance) obj;

    if (other.getInstanceType() == null ^ this.getInstanceType() == null) return false;
    if (other.getInstanceType() != null
        && other.getInstanceType().equals(this.getInstanceType()) == false) return false;
    if (other.getInstanceId() == null ^ this.getInstanceId() == null) return false;
    if (other.getInstanceId() != null
        && other.getInstanceId().equals(this.getInstanceId()) == false) return false;
    if (other.getSpotInstanceRequestId() == null ^ this.getSpotInstanceRequestId() == null)
      return false;
    if (other.getSpotInstanceRequestId() != null
        && other.getSpotInstanceRequestId().equals(this.getSpotInstanceRequestId()) == false)
      return false;
    return true;
  }