當前位置: 首頁>>代碼示例>>Java>>正文


Java DescribeInstancesResult.getReservations方法代碼示例

本文整理匯總了Java中com.amazonaws.services.ec2.model.DescribeInstancesResult.getReservations方法的典型用法代碼示例。如果您正苦於以下問題:Java DescribeInstancesResult.getReservations方法的具體用法?Java DescribeInstancesResult.getReservations怎麽用?Java DescribeInstancesResult.getReservations使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.amazonaws.services.ec2.model.DescribeInstancesResult的用法示例。


在下文中一共展示了DescribeInstancesResult.getReservations方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getInstanceState

import com.amazonaws.services.ec2.model.DescribeInstancesResult; //導入方法依賴的package包/類
public String getInstanceState(String instanceId) {
    LOGGER.debug("getInstanceState('{}') entered", instanceId);
    DescribeInstancesResult result = getEC2().describeInstances(
            new DescribeInstancesRequest().withInstanceIds(instanceId));
    List<Reservation> reservations = result.getReservations();
    Set<Instance> instances = new HashSet<Instance>();

    for (Reservation reservation : reservations) {
        instances.addAll(reservation.getInstances());
        if (instances.size() > 0) {
            String state = instances.iterator().next().getState().getName();
            LOGGER.debug("  InstanceState: {}", state);
            return state;
        }
    }
    LOGGER.debug("getInstanceState('{}') left", instanceId);
    return null;
}
 
開發者ID:servicecatalog,項目名稱:oscm,代碼行數:19,代碼來源:EC2Communication.java

示例2: processResponse

import com.amazonaws.services.ec2.model.DescribeInstancesResult; //導入方法依賴的package包/類
private List<Instance> processResponse(DescribeInstancesResult response) {
    List<Instance> returnedInstances = new ArrayList<>();

    for (Reservation reservation : response.getReservations()) {
        for (com.amazonaws.services.ec2.model.Instance instance : reservation.getInstances()) {

            // Don't show dead servers or servers not tagged as belonging to Swordfish
            if (instance.getState().getName().equals("terminated") || !instance.getTags().contains(new Tag().withKey("Swordfish").withValue("true"))) {
                continue;
            }

            Instance instanceDetails = getInstanceDetails(instance);
            returnedInstances.add(instanceDetails);
            instanceRepository.save(instanceDetails);
            refreshClient(instanceDetails);
        }
    }

    return returnedInstances;
}
 
開發者ID:peavers,項目名稱:swordfish-service,代碼行數:21,代碼來源:EC2SyncImpl.java

示例3: onSuccess

import com.amazonaws.services.ec2.model.DescribeInstancesResult; //導入方法依賴的package包/類
@Override
public void onSuccess(DescribeInstancesRequest request,
        DescribeInstancesResult result) {
    OperationContext.restoreOperationContext(this.opContext);
    int totalNumberOfInstances = 0;
    // Print the details of the instances discovered on the AWS endpoint
    for (Reservation r : result.getReservations()) {
        for (Instance i : r.getInstances()) {
            ++totalNumberOfInstances;
            final int finalTotal1 = totalNumberOfInstances;
            this.service.logFine(() -> String.format("%d=====Instance details %s =====",
                    finalTotal1, i.getInstanceId()));
            this.aws.remoteInstanceIds.add(i.getInstanceId());
        }
    }
    final int finalTotal2 = totalNumberOfInstances;
    this.service.logFine(() -> String.format("Successfully enumerated %d instances on the"
                    + " AWS host.", finalTotal2));
    this.aws.subStage = this.next;
    ((AWSEnumerationAndDeletionAdapterService) this.service)
            .deleteResourcesInLocalSystem(this.aws);
    return;
}
 
開發者ID:vmware,項目名稱:photon-model,代碼行數:24,代碼來源:AWSEnumerationAndDeletionAdapterService.java

示例4: describeInstances

import com.amazonaws.services.ec2.model.DescribeInstancesResult; //導入方法依賴的package包/類
/**
 * 
 * @{inheritDoc
 */
@Override
public List<VMInformation> describeInstances(String... instanceIds) {
    List<VMInformation> result = new ArrayList<VMInformation>();
    try {

        DescribeInstancesResult results = asynchEc2Client.describeInstances();
        HashSet<String> ids = new HashSet<String>(Arrays.asList(instanceIds));
        for (Reservation reservationDescription : results.getReservations()) {
            for (com.amazonaws.services.ec2.model.Instance instance : reservationDescription.getInstances()) {
                if (ids.contains(instance.getInstanceId())) {
                    result.add(new AmazonDataConverter().instanceToVmInformation(reservationDescription, instance, vmRegion));
                }
            }
            // result.addAll(TypicaDataConverter.processReservationDescription(reservationDescription));
        }
    } catch (Exception e) {
        LOG.error("Failed to retrieve instance from Amazon: " + e.getMessage());
        throw new RuntimeException(e);
    }

    return result;
}
 
開發者ID:intuit,項目名稱:Tank,代碼行數:27,代碼來源:AmazonInstance.java

示例5: findInstancesOfType

import com.amazonaws.services.ec2.model.DescribeInstancesResult; //導入方法依賴的package包/類
/**
 * @{inheritDoc
 */
@Override
public List<VMInformation> findInstancesOfType(VMRegion region, VMImageType type) {
    List<VMInformation> ret = new ArrayList<VMInformation>();
    try {
        DescribeInstancesResult instances = asynchEc2Client.describeInstances();
        InstanceDescription instanceForRegionAndType = new TankConfig().getVmManagerConfig().getInstanceForRegionAndType(region, type);
        for (Reservation res : instances.getReservations()) {
            if (res.getInstances() != null) {
                for (com.amazonaws.services.ec2.model.Instance inst : res.getInstances()) {
                    if ((inst.getState().getName().equalsIgnoreCase("running") || inst.getState().getName().equalsIgnoreCase("pending"))
                            && inst.getImageId().equals(instanceForRegionAndType.getAmi())) {
                        ret.add(new AmazonDataConverter().instanceToVmInformation(res, inst, region));
                    }
                }
            }
        }
    } catch (Exception e) {
        LOG.error("Error getting instances: " + e.toString(), e);
        throw new RuntimeException(e);
    }
    return ret;
}
 
開發者ID:intuit,項目名稱:Tank,代碼行數:26,代碼來源:AmazonInstance.java

示例6: findAllInstancesOfType

import com.amazonaws.services.ec2.model.DescribeInstancesResult; //導入方法依賴的package包/類
/**
 * @{inheritDoc
 */
private List<VMInformation> findAllInstancesOfType(VMRegion region, VMImageType type) {
    List<VMInformation> ret = new ArrayList<VMInformation>();
    try {
        DescribeInstancesResult instances = asynchEc2Client.describeInstances();
        InstanceDescription instanceForRegionAndType = new TankConfig().getVmManagerConfig().getInstanceForRegionAndType(region, type);
        for (Reservation res : instances.getReservations()) {
            if (res.getInstances() != null) {
                for (com.amazonaws.services.ec2.model.Instance inst : res.getInstances()) {
                    if (inst.getImageId().equals(instanceForRegionAndType.getAmi())) {
                        ret.add(new AmazonDataConverter().instanceToVmInformation(res, inst, region));
                    }
                }
            }
        }
    } catch (Exception e) {
        LOG.error("Error getting instances: " + e.toString(), e);
        throw new RuntimeException(e);
    }
    return ret;
}
 
開發者ID:intuit,項目名稱:Tank,代碼行數:24,代碼來源:AmazonInstance.java

示例7: getAllRunningInstances

import com.amazonaws.services.ec2.model.DescribeInstancesResult; //導入方法依賴的package包/類
public List<String> getAllRunningInstances() {
	logger.info("Get running instances request");
	DescribeInstancesRequest request = new DescribeInstancesRequest();

	List<String> valuesT1 = new ArrayList<String>();
	valuesT1.add(_defaultTag);
	Filter filter1 = new Filter("tag:" + _tagKey, valuesT1);
	List<String> valuesT2 = new ArrayList<String>();
	valuesT2.add("running"); 
	valuesT2.add("pending");
	Filter filter2 = new Filter("instance-state-name",valuesT2);

	DescribeInstancesResult result = _ec2.describeInstances(request.withFilters(filter1,filter2));
	List<Reservation> reservations = result.getReservations();
	
	List<String> instancesID = new ArrayList<String>();
	for (Reservation reservation : reservations) {
		List<Instance> instances = reservation.getInstances();
		for (Instance instance : instances) {
			instancesID.add(instance.getInstanceId());
		}
	}
	
	return instancesID;
}
 
開發者ID:apelyos,項目名稱:distributed-image-classification,代碼行數:26,代碼來源:NodesMgmt.java

示例8: findInstanceByName

import com.amazonaws.services.ec2.model.DescribeInstancesResult; //導入方法依賴的package包/類
/**
 * Search Ec2 Instance by Name tag.
 * 
 * @param ec2
 * @param targetName
 *            Search Keyword for Name tag
 * @return Instance with Name tag equals targetName. If it does't found,
 *         then return null.
 */
public static Instance findInstanceByName(AmazonEC2 ec2, String targetName) {
	DescribeInstancesResult instanceResult = ec2.describeInstances();
	List<Reservation> reservations = instanceResult.getReservations();
	for (Reservation reservation : reservations) {
		List<Instance> instances = reservation.getInstances();
		for (Instance instance : instances) {
			List<Tag> tagList = instance.getTags();
			String name = "";
			for (Tag tag : tagList) {
				String tagKey = tag.getKey();
				String tagValue = tag.getValue();
				if (tagKey.contains("Name")) {
					name = tagValue;
					if (targetName.equals(name)) {
						return instance;
					}
					break;
				}
			}
		}
	}
	return null;
}
 
開發者ID:betahikaru,項目名稱:ec2-util,代碼行數:33,代碼來源:AwsEc2Client.java

示例9: getEnvironmentsByTag

import com.amazonaws.services.ec2.model.DescribeInstancesResult; //導入方法依賴的package包/類
public List<ServerEnvironment> getEnvironmentsByTag(Region region, String searchTag) {
    LOGGER.info("getEnvironmentsByTag " + region + " tag: " + searchTag);
    List<ServerEnvironment> environments = new ArrayList<ServerEnvironment>();

    ec2.setRegion(region);
    DescribeInstancesResult instances = ec2.describeInstances();
    for (Reservation reservation : instances.getReservations()) {
        for (Instance instance : reservation.getInstances()) {
            for (Tag tag : instance.getTags()) {
                if (tag.getValue().equalsIgnoreCase(searchTag)) {
                    environments.add(getEnvironmentFromInstance(instance));
                }
            }
        }
    }
    return environments;
}
 
開發者ID:codecentric,項目名稱:jenkins-deployment-dashboard-plugin,代碼行數:18,代碼來源:EC2Connector.java

示例10: tagEnvironmentWithVersion

import com.amazonaws.services.ec2.model.DescribeInstancesResult; //導入方法依賴的package包/類
@Override
public boolean tagEnvironmentWithVersion(Region region, DeployJobVariables jobVariables) {
    String searchTag = jobVariables.getEnvironment();
    String version = jobVariables.getVersion();
    LOGGER.info("tagEnvironmentWithVersion " + region + " Tag " + searchTag + " version " + version);

    boolean environmentSuccessfulTagged = false;
    ec2.setRegion(region);
    DescribeInstancesResult instances = ec2.describeInstances();
    for (Reservation reservation : instances.getReservations()) {
        for (Instance instance : reservation.getInstances()) {
            for (Tag tag : instance.getTags()) {
                if (tag.getValue().equalsIgnoreCase(searchTag)) {
                    CreateTagsRequest createTagsRequest = new CreateTagsRequest();
                    createTagsRequest.withResources(instance.getInstanceId()).withTags(new Tag(VERSION_TAG, version));
                    LOGGER.info("Create Tag " + version + " for instance " + instance.getInstanceId());
                    ec2.createTags(createTagsRequest);
                    environmentSuccessfulTagged = true;
                }
            }
        }
    }
    return environmentSuccessfulTagged;
}
 
開發者ID:codecentric,項目名稱:jenkins-deployment-dashboard-plugin,代碼行數:25,代碼來源:EC2Connector.java

示例11: describeInstances

import com.amazonaws.services.ec2.model.DescribeInstancesResult; //導入方法依賴的package包/類
private Instances describeInstances(DescribeInstancesRequest request)
{
    final Instances instances = new Instances();

    DescribeInstancesResult result = ec2_.describeInstances(request);

    for (Reservation reservation : result.getReservations())
    {
        for (Instance instance : reservation.getInstances())
        {
            instances.addInstance(toExcaliburInstance(instance, null));
        }
    }

    return instances;
}
 
開發者ID:alessandroleite,項目名稱:dohko,代碼行數:17,代碼來源:EC2.java

示例12: getInstancesForGroup

import com.amazonaws.services.ec2.model.DescribeInstancesResult; //導入方法依賴的package包/類
/***
 * Get list of EC2 {@link Instance}s for a auto scaling group
 *
 * @param groupName Auto scaling group name
 * @param status Instance status (eg. running)
 * @return List of EC2 instances found for the input auto scaling group
 */
public List<Instance> getInstancesForGroup(String groupName,
    String status) {

  final AmazonEC2 amazonEC2 = getEc2Client();

  final DescribeInstancesResult instancesResult = amazonEC2.describeInstances(new DescribeInstancesRequest()
      .withFilters(new Filter().withName("tag:aws:autoscaling:groupName").withValues(groupName)));

  final List<Instance> instances = new ArrayList<>();
  for (Reservation reservation : instancesResult.getReservations()) {
    for (Instance instance : reservation.getInstances()) {
      if (null == status|| null == instance.getState()
          || status.equals(instance.getState().getName())) {
        instances.add(instance);
        LOGGER.info("Found instance: " + instance + " which qualified filter: " + status);
      } else {
        LOGGER.info("Found instance: " + instance + " but did not qualify for filter: " + status);
      }
    }
  }

  return instances;
}
 
開發者ID:apache,項目名稱:incubator-gobblin,代碼行數:31,代碼來源:AWSSdkClient.java

示例13: checkTagsAws

import com.amazonaws.services.ec2.model.DescribeInstancesResult; //導入方法依賴的package包/類
protected static void checkTagsAws(Regions region, List<String> instanceIdList, Map<String, String> tagsToCheckMap) {
    Map<String, String> extractedTagsToCheck = new HashMap<>();
    List<Tag> extractedTags;
    AmazonEC2 ec2 = AmazonEC2ClientBuilder.standard().withRegion(region).build();
    DescribeInstancesRequest describeInstancesRequest = new DescribeInstancesRequest();
    describeInstancesRequest.withInstanceIds(instanceIdList);
    DescribeInstancesResult describeInstancesResultAll = ec2.describeInstances(describeInstancesRequest);
    List<Reservation> reservationsAll = describeInstancesResultAll.getReservations();
    for (Reservation reservation : reservationsAll) {
        for (Instance instance : reservation.getInstances()) {
            extractedTags = instance.getTags();
            Assert.assertNotNull(extractedTags);
            for (Tag tag : extractedTags) {
                extractedTagsToCheck.put(tag.getKey(), tag.getValue());
            }
            checkTags(tagsToCheckMap, extractedTagsToCheck);
            extractedTags.clear();
        }
    }
}
 
開發者ID:hortonworks,項目名稱:cloudbreak,代碼行數:21,代碼來源:TagsUtil.java

示例14: check

import com.amazonaws.services.ec2.model.DescribeInstancesResult; //導入方法依賴的package包/類
@Override
public List<CloudVmInstanceStatus> check(AuthenticatedContext ac, List<CloudInstance> vms) {
    List<CloudVmInstanceStatus> cloudVmInstanceStatuses = new ArrayList<>();
    for (CloudInstance vm : vms) {
        DescribeInstancesResult result = awsClient.createAccess(new AwsCredentialView(ac.getCloudCredential()),
                ac.getCloudContext().getLocation().getRegion().value())
                .describeInstances(new DescribeInstancesRequest().withInstanceIds(vm.getInstanceId()));
        for (Reservation reservation : result.getReservations()) {
            for (Instance instance : reservation.getInstances()) {
                if ("Stopped".equalsIgnoreCase(instance.getState().getName())) {
                    LOGGER.info("AWS instance is in Stopped state, polling stack.");
                    cloudVmInstanceStatuses.add(new CloudVmInstanceStatus(vm, InstanceStatus.STOPPED));
                } else if ("Running".equalsIgnoreCase(instance.getState().getName())) {
                    LOGGER.info("AWS instance is in Started state, polling stack.");
                    cloudVmInstanceStatuses.add(new CloudVmInstanceStatus(vm, InstanceStatus.STARTED));
                } else if ("Terminated".equalsIgnoreCase(instance.getState().getName())) {
                    LOGGER.info("AWS instance is in Terminated state, polling stack.");
                    cloudVmInstanceStatuses.add(new CloudVmInstanceStatus(vm, InstanceStatus.TERMINATED));
                } else {
                    cloudVmInstanceStatuses.add(new CloudVmInstanceStatus(vm, InstanceStatus.IN_PROGRESS));
                }
            }
        }
    }
    return cloudVmInstanceStatuses;
}
 
開發者ID:hortonworks,項目名稱:cloudbreak,代碼行數:27,代碼來源:AwsInstanceConnector.java

示例15: getEc2Instance

import com.amazonaws.services.ec2.model.DescribeInstancesResult; //導入方法依賴的package包/類
private Instance getEc2Instance(IMachine machine, AmazonEC2 connector) throws ConnectorException {
    DescribeInstancesResult describeInstancesResult = null;
    try {
        DescribeInstancesRequest describeInstancesRequest = new DescribeInstancesRequest();
        describeInstancesResult = connector.describeInstances(describeInstancesRequest.withInstanceIds(machine.getName()));
        List<Reservation> reservations = describeInstancesResult.getReservations();
        if (reservations.size() == 0) {
            // machine not found MUST have been terminated
            return null;
        }

        // always it will be in the first reservation as the query is on
        // only one machine
        List<Instance> instances = reservations.get(0).getInstances();
        for (Instance instance : instances) {
            if (instance.getInstanceId().equals(machine.getName())) {
                // found the machine
                return instance;
            }
        }
    } catch (Exception e) {
        throw new ConnectorException(e);
    }

    return null;
}
 
開發者ID:Appdynamics,項目名稱:aws-connector-extension,代碼行數:27,代碼來源:AWSConnector.java


注:本文中的com.amazonaws.services.ec2.model.DescribeInstancesResult.getReservations方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。