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


Java Reservation類代碼示例

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


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

示例1: getInstanceState

import com.amazonaws.services.ec2.model.Reservation; //導入依賴的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.Reservation; //導入依賴的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: get

import com.amazonaws.services.ec2.model.Reservation; //導入依賴的package包/類
/**
 * Gets the list of ec2 instances of a given cluster.
 * @return List of instances.
 */
public List<Instance> get() {
    final ClusterTag tag = new ClusterTag(this.cluster, this.config);
    final String name = tag.name();
    final String value = tag.value();
    InstanceList.LOGGER.info(
        String.format(
            "Looking for instances for '%s' filtering with '%s'='%s'",
            this.cluster,
            name,
            value
        )
    );
    final EC2ToTurbineInstance converter = new EC2ToTurbineInstance(
        this.cluster
    );
    return this.provider.client()
        .describeInstances(this.request(name, value))
        .getReservations()
        .parallelStream()
        .map(Reservation::getInstances)
        .flatMap(List::stream)
        .map(converter::convert)
        .collect(Collectors.toList());
}
 
開發者ID:ContaAzul,項目名稱:turbine-ec2,代碼行數:29,代碼來源:InstanceList.java

示例4: onSuccess

import com.amazonaws.services.ec2.model.Reservation; //導入依賴的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

示例5: testGetInstancesByTagHappy

import com.amazonaws.services.ec2.model.Reservation; //導入依賴的package包/類
@Test
public void testGetInstancesByTagHappy() {

    String tagKey = "tag key";
    String tagValue = "tag value";
    Filter filter = new Filter().withName(INSTANCE_STATE_FILTER_NAME).withValues(INSTANCE_STATE_RUNNING_FILTER_VALUE);
    Instance instance = mock(Instance.class);

    when(ec2Client.describeInstances(new DescribeInstancesRequest()
            .withFilters(
                    filter,
                    new Filter()
                            .withName(String.format(FILTER_NAME_TEMPL_FOR_EC2_TAGS, tagKey))
                            .withValues(tagValue)
            )
    )).thenReturn(
            new DescribeInstancesResult()
                    .withReservations(
                            new Reservation()
                                    .withInstances(instance))
    );

    List<Instance> instances = ec2Service.getInstancesByTag(tagKey, tagValue, filter);

    assertTrue(instances.contains(instance));
}
 
開發者ID:Nike-Inc,項目名稱:cerberus-lifecycle-cli,代碼行數:27,代碼來源:Ec2ServiceTest.java

示例6: forEachInstance

import com.amazonaws.services.ec2.model.Reservation; //導入依賴的package包/類
/**
 * Iterates through the instances in the specified {@code DescribeInstancesResult}
 * and calls the specified handler on each instance. This method will retrieve the
 * follow-on {@code DescribeInstanceResult}s if the result holds a {@code nextToken}.
 *
 * @param result          the {@code DescribeInstancesResult}
 * @param instanceHandler the instance handler
 */
@VisibleForTesting
void forEachInstance(DescribeInstancesResult result, InstanceHandler instanceHandler) {
  List<Reservation> reservations;
  while (!(reservations = result.getReservations()).isEmpty()) {
    for (Reservation reservation : reservations) {
      for (Instance instance : reservation.getInstances()) {
        LOG.debug("Calling instance handler with instance {}", instance);
        instanceHandler.handle(instance);
      }
    }

    if (result.getNextToken() != null) {
      result = client.describeInstances(
          new DescribeInstancesRequest().withNextToken(result.getNextToken()));
    } else {
      break;
    }
  }
}
 
開發者ID:cloudera,項目名稱:director-aws-plugin,代碼行數:28,代碼來源:EC2Provider.java

示例7: describeInstances

import com.amazonaws.services.ec2.model.Reservation; //導入依賴的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

示例8: findInstancesOfType

import com.amazonaws.services.ec2.model.Reservation; //導入依賴的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

示例9: findAllInstancesOfType

import com.amazonaws.services.ec2.model.Reservation; //導入依賴的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

示例10: instanceToVmInformation

import com.amazonaws.services.ec2.model.Reservation; //導入依賴的package包/類
/**
 * @param data
 * @param instance
 * @param region
 * @return
 */
public VMInformation instanceToVmInformation(Reservation data, Instance instance, VMRegion region) {
    VMInformation info = new VMInformation();
    info.setProvider(VMProvider.Amazon);
    info.setRequestId(data.getRequesterId());
    info.setImageId(instance.getImageId());
    info.setInstanceId(instance.getInstanceId());
    info.setKeyName(instance.getKeyName());
    // info.setLaunchTime();
    info.setRegion(region);
    info.setPlatform(instance.getPlatform());
    info.setPrivateDNS(instance.getPrivateDnsName());
    info.setPublicDNS(instance.getPublicDnsName());
    info.setState(instance.getState().getName());
    info.setSize(instance.getInstanceType());
    return info;
}
 
開發者ID:intuit,項目名稱:Tank,代碼行數:23,代碼來源:AmazonDataConverter.java

示例11: getAllRunningInstances

import com.amazonaws.services.ec2.model.Reservation; //導入依賴的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

示例12: findInstanceByName

import com.amazonaws.services.ec2.model.Reservation; //導入依賴的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

示例13: getAmiIdFromEC2Api

import com.amazonaws.services.ec2.model.Reservation; //導入依賴的package包/類
private Optional<String> getAmiIdFromEC2Api(final EC2InstanceContext context) {
    final String instanceId = context.getInstanceId();
    try {
        return context.getClient(AmazonEC2Client.class)
                .describeInstances(new DescribeInstancesRequest().withInstanceIds(instanceId))
                .getReservations()
                .stream()
                .map(Reservation::getInstances)
                .flatMap(Collection::stream)
                .filter(i -> i.getInstanceId().equals(instanceId))
                .map(Instance::getImageId)
                .findFirst();
    } catch (final AmazonClientException e) {
        log.warn("Could not describe instance " + instanceId, e);
        return empty();
    }
}
 
開發者ID:zalando-stups,項目名稱:fullstop,代碼行數:18,代碼來源:AmiIdProviderImpl.java

示例14: getEnvironmentsByTag

import com.amazonaws.services.ec2.model.Reservation; //導入依賴的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

示例15: tagEnvironmentWithVersion

import com.amazonaws.services.ec2.model.Reservation; //導入依賴的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


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