本文整理汇总了Java中com.amazonaws.services.ec2.model.Filter类的典型用法代码示例。如果您正苦于以下问题:Java Filter类的具体用法?Java Filter怎么用?Java Filter使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Filter类属于com.amazonaws.services.ec2.model包,在下文中一共展示了Filter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: buildDescribeInstancesRequest
import com.amazonaws.services.ec2.model.Filter; //导入依赖的package包/类
private DescribeInstancesRequest buildDescribeInstancesRequest() {
DescribeInstancesRequest describeInstancesRequest = new DescribeInstancesRequest()
.withFilters(
new Filter("instance-state-name").withValues("running", "pending")
);
for (Map.Entry<String, String> tagFilter : tags.entrySet()) {
// for a given tag key, OR relationship for multiple different values
describeInstancesRequest.withFilters(
new Filter("tag:" + tagFilter.getKey()).withValues(tagFilter.getValue())
);
}
if (!availabilityZones.isEmpty()) {
// OR relationship amongst multiple values of the availability-zone filter
describeInstancesRequest.withFilters(
new Filter("availability-zone").withValues(availabilityZones)
);
}
return describeInstancesRequest;
}
示例2: createSnapshot
import com.amazonaws.services.ec2.model.Filter; //导入依赖的package包/类
/**
* Creates a snapshot and return the snapshot id.
*/
public static String createSnapshot(VerificationHost host, AmazonEC2Client client, String volumeId) {
CreateSnapshotRequest req = new CreateSnapshotRequest()
.withVolumeId(volumeId);
CreateSnapshotResult res = client.createSnapshot(req);
String snapshotId = res.getSnapshot().getSnapshotId();
Filter filter = new Filter().withName(SNAPSHOT_ID_ATTRIBUTE).withValues(snapshotId);
DescribeSnapshotsRequest snapshotsRequest = new DescribeSnapshotsRequest()
.withSnapshotIds(snapshotId)
.withFilters(filter);
host.waitFor("Timeout waiting for creating snapshot", () -> {
DescribeSnapshotsResult snapshotsResult = client.describeSnapshots(snapshotsRequest);
String state = snapshotsResult.getSnapshots().get(0).getState();
if (state.equalsIgnoreCase(SNAPSHOT_STATUS_COMPLETE)) {
return true;
}
return false;
});
return snapshotId;
}
示例3: testResolveAMIFound
import com.amazonaws.services.ec2.model.Filter; //导入依赖的package包/类
@Test
public void testResolveAMIFound() throws Exception {
ec2mock.createDescribeImagesResult("image1");
Image result = ec2comm.resolveAMI("image1");
assertEquals("image1", result.getImageId());
ArgumentCaptor<DescribeImagesRequest> argCaptor = ArgumentCaptor
.forClass(DescribeImagesRequest.class);
verify(ec2).describeImages(argCaptor.capture());
DescribeImagesRequest dir = argCaptor.getValue();
for (Filter filter : dir.getFilters()) {
if (filter.getName().equals("name")) {
assertEquals("image1", filter.getValues().get(0));
}
}
}
示例4: getReservedInstancesForZone
import com.amazonaws.services.ec2.model.Filter; //导入依赖的package包/类
@Override
public Map<AvailabilityZone, List<ReservedInstances>> getReservedInstancesForZone(
AvailabilityZone zone, AmazonEC2Client client) throws Exception {
OperationStats op = new OperationStats("ec2InstanceStore", "getReservedInstancesForZone");
try {
Map<AvailabilityZone, List<ReservedInstances>> ret = new HashMap<>();
DescribeReservedInstancesRequest request = new DescribeReservedInstancesRequest()
.withFilters(new Filter("availability-zone", Arrays.asList(zone.getZoneName())))
.withSdkClientExecutionTimeout(
600 * 1000) //10 minutes time out for total execution including retries
.withSdkRequestTimeout(300 * 1000); //5 minutes time out for a single request
DescribeReservedInstancesResult result = client.describeReservedInstances(request);
ret.put(zone, result.getReservedInstances());
op.succeed();
return ret;
} catch (Exception e) {
op.failed();
logger.error(ExceptionUtils.getRootCauseMessage(e));
throw e;
}
}
示例5: getSecurityGroups
import com.amazonaws.services.ec2.model.Filter; //导入依赖的package包/类
public DeferredResult<DescribeSecurityGroupsResult> getSecurityGroups(List<String> secGroupIds,
String vpcId, String nicName, String vmName) {
DescribeSecurityGroupsRequest req = new DescribeSecurityGroupsRequest()
.withFilters(new Filter(AWS_GROUP_ID_FILTER, secGroupIds))
.withFilters(new Filter(AWS_VPC_ID_FILTER, singletonList(vpcId)));
String msg = "Getting AWS Security Groups by id ["
+ secGroupIds
+ "] for [" + nicName + "] NIC for ["
+ vmName
+ "] VM";
AWSDeferredResultAsyncHandler<DescribeSecurityGroupsRequest, DescribeSecurityGroupsResult>
handler = new AWSDeferredResultAsyncHandler<>(this.service, msg);
this.client.describeSecurityGroupsAsync(req, handler);
return handler.toDeferredResult();
}
示例6: getRemoteInstances
import com.amazonaws.services.ec2.model.Filter; //导入依赖的package包/类
/**
* Get the instances from AWS filtered by the instances Ids known to the local system.
*/
public void getRemoteInstances(EnumerationDeletionContext aws,
AWSEnumerationDeletionSubStage next) {
if (aws.localInstanceIds == null || aws.localInstanceIds.size() == 0) {
logFine(() -> "No local records found. No states need to be fetched from the AWS"
+ " endpoint.");
aws.subStage = next;
deleteResourcesInLocalSystem(aws);
return;
}
DescribeInstancesRequest request = new DescribeInstancesRequest();
Filter runningInstanceFilter = getAWSNonTerminatedInstancesFilter();
request.getFilters().add(runningInstanceFilter);
// Get only the instances from the remote system for which a compute state exists in the
// local system.
logFine(() -> String.format("Fetching instance details for %d instances on the AWS"
+ " endpoint.", aws.localInstanceIds.keySet().size()));
request.getInstanceIds().addAll(new ArrayList<>(aws.localInstanceIds.keySet()));
AsyncHandler<DescribeInstancesRequest, DescribeInstancesResult> resultHandler =
new AWSEnumerationAsyncHandler(this, aws, next);
aws.amazonEC2Client.describeInstancesAsync(request,
resultHandler);
}
示例7: createVolume
import com.amazonaws.services.ec2.model.Filter; //导入依赖的package包/类
/**
* Creates a volume and return the volume id.
*/
public static String createVolume(VerificationHost host, AmazonEC2Client client) {
CreateVolumeRequest req = new CreateVolumeRequest()
.withAvailabilityZone(zoneId + avalabilityZoneIdentifier)
.withSize(1);
CreateVolumeResult res = client.createVolume(req);
String volumeId = res.getVolume().getVolumeId();
Filter filter = new Filter().withName(VOLUME_ID_ATTRIBUTE).withValues(volumeId);
DescribeVolumesRequest volumesRequest = new DescribeVolumesRequest()
.withVolumeIds(volumeId)
.withFilters(filter);
host.waitFor("Timeout waiting for creating volume", () -> {
DescribeVolumesResult volumesResult = client.describeVolumes(volumesRequest);
String state = volumesResult.getVolumes().get(0).getState();
if (state.equalsIgnoreCase(VOLUME_STATUS_AVAILABLE)) {
return true;
}
return false;
});
return volumeId;
}
示例8: getBaseLineInstanceCount
import com.amazonaws.services.ec2.model.Filter; //导入依赖的package包/类
/**
* Gets the instance count of non-terminated instances on the AWS endpoint. This is used to run
* the asserts and validate the results for the data that is collected during enumeration.This
* also calculates the compute descriptions that will be used to represent the instances that
* were discovered on the AWS endpoint. Further factoring in the
*
* @throws Throwable
*/
public static BaseLineState getBaseLineInstanceCount(VerificationHost host,
AmazonEC2AsyncClient client,
List<String> testComputeDescriptions)
throws Throwable {
BaseLineState baseLineState = new BaseLineState();
AWSEnumerationAsyncHandler enumerationHandler = new AWSEnumerationAsyncHandler(host,
AWSEnumerationAsyncHandler.MODE.GET_COUNT, null, null, null,
testComputeDescriptions,
baseLineState);
DescribeInstancesRequest request = new DescribeInstancesRequest();
Filter runningInstanceFilter = getAWSNonTerminatedInstancesFilter();
request.getFilters().add(runningInstanceFilter);
client.describeInstancesAsync(request, enumerationHandler);
host.waitFor("Error waiting to get base line instance count from AWS in test ", () -> {
return baseLineState.isCountPopulated;
});
return baseLineState;
}
示例9: deleteAwsSubnet
import com.amazonaws.services.ec2.model.Filter; //导入依赖的package包/类
public void deleteAwsSubnet() {
if (this.isMock) {
return;
}
DescribeSubnetsRequest subnetRequest = new DescribeSubnetsRequest()
.withFilters(
new Filter(AWS_VPC_ID_FILTER, singletonList(AWS_DEFAULT_VPC_ID)))
.withFilters(
new Filter(AWS_SUBNET_CIDR_FILTER,
singletonList(AWS_NON_EXISTING_SUBNET_CIDR)));
DescribeSubnetsResult subnetResult = this.client.describeSubnets(subnetRequest);
subnetResult.getSubnets().forEach(subnet -> {
DeleteSubnetRequest deleteRequest = new DeleteSubnetRequest(subnet.getSubnetId());
this.client.deleteSubnet(deleteRequest);
});
}
示例10: deleteAwsPublicSubnet
import com.amazonaws.services.ec2.model.Filter; //导入依赖的package包/类
public void deleteAwsPublicSubnet() {
if (this.isMock) {
return;
}
DescribeSubnetsRequest subnetRequest = new DescribeSubnetsRequest()
.withFilters(
new Filter(AWS_VPC_ID_FILTER, singletonList(AWS_DEFAULT_VPC_ID)))
.withFilters(
new Filter(AWS_SUBNET_CIDR_FILTER,
singletonList(AWS_NON_EXISTING_PUBLIC_SUBNET_CIDR)));
DescribeSubnetsResult subnetResult = this.client.describeSubnets(subnetRequest);
subnetResult.getSubnets().forEach(subnet -> {
DeleteSubnetRequest deleteRequest = new DeleteSubnetRequest(subnet.getSubnetId());
this.client.deleteSubnet(deleteRequest);
});
}
示例11: isAmiWithTagExist
import com.amazonaws.services.ec2.model.Filter; //导入依赖的package包/类
/**
* Validates if the given AMI has given tag and value.
*
* @return true if matches otherwise false
*/
public boolean isAmiWithTagExist(final String amiId, final String tagName, final String tagValue) {
final DescribeImagesRequest request = new DescribeImagesRequest()
.withFilters(new Filter().withName(tagName).withValues(tagValue))
.withFilters(new Filter().withName("image-id").withValues(amiId));
try {
final DescribeImagesResult result = ec2Client.describeImages(request);
return result.getImages().size() > 0;
} catch (final AmazonServiceException ase) {
if (ase.getErrorCode() == "InvalidAMIID.NotFound") {
return false;
}
throw ase;
}
}
示例12: getInstancesByTag
import com.amazonaws.services.ec2.model.Filter; //导入依赖的package包/类
/**
* Gets all EC2 instances with the given tag key/value pair
* @param tagKey - Key of the tag
* @param tagValue - Value of the tag
* @param filters - Array of EC2 filters
* @return - List of instances with the given tag
*/
public List<Instance> getInstancesByTag(final String tagKey, final String tagValue, final Filter... filters) {
final String filterName = String.format(FILTER_NAME_TEMPL_FOR_EC2_TAGS, tagKey);
final Filter tagFilter = new Filter().withName(filterName).withValues(tagValue);
final Set<Filter> filterSet = Sets.newHashSet(filters);
filterSet.add(tagFilter);
final DescribeInstancesRequest request = new DescribeInstancesRequest().withFilters(filterSet);
DescribeInstancesResult result = ec2Client.describeInstances(request);
List<Instance> instances = Lists.newArrayList();
result.getReservations().forEach(reservation -> {
instances.addAll(reservation.getInstances());
});
return instances;
}
示例13: isAmiWithTagExistTrue
import com.amazonaws.services.ec2.model.Filter; //导入依赖的package包/类
@Test
public void isAmiWithTagExistTrue() {
AmazonEC2 ec2Client = mock(AmazonEC2.class);
AmiTagCheckService amiTagCheckService = new AmiTagCheckService(ec2Client);
String amiId = "ami-1234abcd";
String tagName = "sometag";
String tagValue = "someval";
when(ec2Client.describeImages(
new DescribeImagesRequest()
.withFilters(new Filter().withName(tagName).withValues(tagValue))
.withFilters(new Filter().withName("image-id").withValues(amiId))
)
).thenReturn(
new DescribeImagesResult().withImages(new Image())
);
// invoke method under test
assertTrue(amiTagCheckService.isAmiWithTagExist(amiId, tagName, tagValue));
}
示例14: isAmiWithTagExistFalse
import com.amazonaws.services.ec2.model.Filter; //导入依赖的package包/类
@Test
public void isAmiWithTagExistFalse() {
AmazonEC2 ec2Client = mock(AmazonEC2.class);
AmiTagCheckService amiTagCheckService = new AmiTagCheckService(ec2Client);
String amiId = "ami-1234abcd";
String tagName = "sometag";
String tagValue = "someval";
when(ec2Client.describeImages(
new DescribeImagesRequest()
.withFilters(new Filter().withName(tagName).withValues(tagValue))
.withFilters(new Filter().withName("image-id").withValues(amiId))
)
).thenReturn(
new DescribeImagesResult()
);
// invoke method under test
assertFalse(amiTagCheckService.isAmiWithTagExist(amiId, tagName, tagValue));
}
示例15: isAmiWithTagExistNotFound
import com.amazonaws.services.ec2.model.Filter; //导入依赖的package包/类
@Test
public void isAmiWithTagExistNotFound() {
AmazonEC2 ec2Client = mock(AmazonEC2.class);
AmiTagCheckService amiTagCheckService = new AmiTagCheckService(ec2Client);
String amiId = "ami-1234abcd";
String tagName = "sometag";
String tagValue = "someval";
AmazonServiceException ex = new AmazonServiceException("fake-exception");
ex.setErrorCode("InvalidAMIID.NotFound");
when(ec2Client.describeImages(
new DescribeImagesRequest()
.withFilters(new Filter().withName(tagName).withValues(tagValue))
.withFilters(new Filter().withName("image-id").withValues(amiId))
)
).thenThrow(ex);
// invoke method under test
assertFalse(amiTagCheckService.isAmiWithTagExist(amiId, tagName, tagValue));
}