本文整理汇总了Java中com.amazonaws.services.ec2.model.ResourceType类的典型用法代码示例。如果您正苦于以下问题:Java ResourceType类的具体用法?Java ResourceType怎么用?Java ResourceType使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ResourceType类属于com.amazonaws.services.ec2.model包,在下文中一共展示了ResourceType类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: call
import com.amazonaws.services.ec2.model.ResourceType; //导入依赖的package包/类
@Override
public List<Instance> call() {
RunInstancesRequest request = new RunInstancesRequest();
request.withInstanceType(this.instanceTemplate.getInstanceType());
request.withImageId(this.instanceTemplate.getAmiId());
InstanceNetworkInterfaceSpecification nic = new InstanceNetworkInterfaceSpecification();
nic.withDeviceIndex(0);
// select a subnet at random
nic.withSubnetId(randomSubnet());
nic.withAssociatePublicIpAddress(this.instanceTemplate.isAssignPublicIp());
nic.withGroups(this.instanceTemplate.getSecurityGroupIds());
request.withNetworkInterfaces(nic);
request.withKeyName(this.instanceTemplate.getKeyPair());
request.withIamInstanceProfile(
new IamInstanceProfileSpecification().withArn(this.instanceTemplate.getIamInstanceProfileARN()));
request.withUserData(this.instanceTemplate.getEncodedUserData());
request.withEbsOptimized(this.instanceTemplate.isEbsOptimized());
request.withMinCount(this.count).withMaxCount(this.count);
if (!this.instanceTemplate.getTags().isEmpty()) {
TagSpecification tagSpecifications = new TagSpecification().withResourceType(ResourceType.Instance);
tagSpecifications.withTags(tags());
request.withTagSpecifications(tagSpecifications);
}
RunInstancesResult result = getClient().getApi().runInstances(request);
List<Instance> launchedInstances = result.getReservation().getInstances();
List<String> instanceIds = launchedInstances.stream().map(Instance::getInstanceId).collect(Collectors.toList());
return awaitInstances(instanceIds);
}
示例2: getObject_userTagDataAvailable_objectContainsAllAvailableKeys
import com.amazonaws.services.ec2.model.ResourceType; //导入依赖的package包/类
@Test
public void getObject_userTagDataAvailable_objectContainsAllAvailableKeys() throws Exception {
//Arrange
AmazonEC2 amazonEC2 = mock(AmazonEC2.class);
InstanceIdProvider instanceIdProvider = mock(InstanceIdProvider.class);
when(instanceIdProvider.getCurrentInstanceId()).thenReturn("1234567890");
DescribeTagsRequest describeTagsRequest = new DescribeTagsRequest().withFilters(
new Filter("resource-id", Collections.singletonList("1234567890")),
new Filter("resource-type", Collections.singletonList("instance")));
DescribeTagsResult describeTagsResult = new DescribeTagsResult().withTags(
new TagDescription().withKey("keyA").withResourceType(ResourceType.Instance).withValue("valueA"),
new TagDescription().withKey("keyB").withResourceType(ResourceType.Instance).withValue("valueB")
);
when(amazonEC2.describeTags(describeTagsRequest)).thenReturn(describeTagsResult);
AmazonEc2InstanceUserTagsFactoryBean amazonEc2InstanceUserTagsFactoryBean = new AmazonEc2InstanceUserTagsFactoryBean(amazonEC2, instanceIdProvider);
//Act
amazonEc2InstanceUserTagsFactoryBean.afterPropertiesSet();
Map<String, String> resultMap = amazonEc2InstanceUserTagsFactoryBean.getObject();
//Assert
assertEquals("valueA", resultMap.get("keyA"));
assertEquals("valueB", resultMap.get("keyB"));
assertFalse(resultMap.containsKey("keyC"));
}
示例3: newRunInstancesRequest
import com.amazonaws.services.ec2.model.ResourceType; //导入依赖的package包/类
/**
* Builds a {@code RunInstancesRequest} starting from a template and a virtual instance ID.
* Instances will be tagged as they're created.
*
* @param template the instance template
* @param virtualInstanceId the virtual instance IDs
* @param userDefinedTags user defined tags to attach to the instance
*/
@SuppressWarnings("ConstantConditions")
private RunInstancesRequest newRunInstancesRequest(EC2InstanceTemplate template,
String virtualInstanceId, List<Tag> userDefinedTags) {
String image = template.getImage();
String type = template.getType();
InstanceNetworkInterfaceSpecification network =
getInstanceNetworkInterfaceSpecification(template);
List<BlockDeviceMapping> deviceMappings = getBlockDeviceMappings(template);
LOG.info(">> Instance request type: {}, image: {}", type, image);
List<Tag> tags = ec2TagHelper.getInstanceTags(template, virtualInstanceId, userDefinedTags);
List<TagSpecification> tagSpecifications = Lists.newArrayList(
new TagSpecification().withTags(tags).withResourceType(ResourceType.Instance),
new TagSpecification().withTags(tags).withResourceType(ResourceType.Volume));
RunInstancesRequest request = new RunInstancesRequest()
.withImageId(image)
.withInstanceType(type)
.withMaxCount(1)
.withMinCount(1)
.withClientToken(UUID.randomUUID().toString())
.withNetworkInterfaces(network)
.withTagSpecifications(tagSpecifications)
.withBlockDeviceMappings(deviceMappings)
.withEbsOptimized(template.isEbsOptimized());
if (template.getIamProfileName().isPresent()) {
request.withIamInstanceProfile(new IamInstanceProfileSpecification()
.withName(template.getIamProfileName().get()));
}
if (template.getKeyName().isPresent()) {
request.withKeyName(template.getKeyName().get());
}
Placement placement = null;
if (template.getAvailabilityZone().isPresent()) {
placement = new Placement().withAvailabilityZone(template.getAvailabilityZone().get());
}
if (template.getPlacementGroup().isPresent()) {
placement = (placement == null) ?
new Placement().withGroupName(template.getPlacementGroup().get())
: placement.withGroupName(template.getPlacementGroup().get());
}
placement = (placement == null) ?
new Placement().withTenancy(template.getTenancy())
: placement.withTenancy(template.getTenancy());
request.withPlacement(placement);
Optional<String> userData = template.getUserData();
if (userData.isPresent()) {
request.withUserData(userData.get());
}
return request;
}