当前位置: 首页>>代码示例>>Java>>正文


Java AmazonEC2Async.describeSnapshots方法代码示例

本文整理汇总了Java中com.amazonaws.services.ec2.AmazonEC2Async.describeSnapshots方法的典型用法代码示例。如果您正苦于以下问题:Java AmazonEC2Async.describeSnapshots方法的具体用法?Java AmazonEC2Async.describeSnapshots怎么用?Java AmazonEC2Async.describeSnapshots使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.amazonaws.services.ec2.AmazonEC2Async的用法示例。


在下文中一共展示了AmazonEC2Async.describeSnapshots方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: attachSnapshotTags

import com.amazonaws.services.ec2.AmazonEC2Async; //导入方法依赖的package包/类
void attachSnapshotTags(AmazonEC2Async client, String sourceSnapshotId, String snapshotId) {

		DescribeSnapshotsResult result = client
				.describeSnapshots(new DescribeSnapshotsRequest().withSnapshotIds(sourceSnapshotId));
		List<Snapshot> snapshots = result.getSnapshots();
		if (snapshots.size() != 1) {
			throw new RuntimeException("snapshot can not found. sourceSnapshotId[" + snapshotId + "]");
		}
		List<Tag> sourceSnapshotTags = snapshots.get(0).getTags();

		List<Tag> tags = new ArrayList<Tag>();
		tags.addAll(sourceSnapshotTags);
		tags.add(new Tag("SourceSnapshotId", sourceSnapshotId));
		tags.add(new Tag("BackupType", "copy-snapshot")); // overwrite

		CreateTagsRequest snapshotTagsRequest = new CreateTagsRequest().withResources(snapshotId);
		snapshotTagsRequest.setTags(tags);
		client.createTags(snapshotTagsRequest);
	}
 
开发者ID:uzresk,项目名称:aws-auto-operations-using-lambda,代码行数:20,代码来源:EBSCopySnapshotFunction.java

示例2: pargeEbsSnapshot

import com.amazonaws.services.ec2.AmazonEC2Async; //导入方法依赖的package包/类
void pargeEbsSnapshot(AmazonEC2Async client, String volumeId, int generationCount, Context context) {

		LambdaLogger logger = context.getLogger();
		logger.log("Parge snapshot start. VolumeId[" + volumeId + "] generationCount[" + generationCount + "]");

		List<Filter> filters = new ArrayList<>();
		filters.add(new Filter().withName("volume-id").withValues(volumeId));
		filters.add(new Filter().withName("tag:VolumeId").withValues(volumeId));
		filters.add(new Filter().withName("tag:BackupType").withValues("snapshot"));
		DescribeSnapshotsRequest snapshotRequest = new DescribeSnapshotsRequest().withFilters(filters);
		DescribeSnapshotsResult snapshotResult = client.describeSnapshots(snapshotRequest);

		List<Snapshot> snapshots = snapshotResult.getSnapshots();
		Collections.sort(snapshots, new SnapshotComparator());

		int snapshotSize = snapshots.size();
		if (generationCount < snapshotSize) {
			for (int i = 0; i < snapshotSize - generationCount; i++) {
				Snapshot snapshot = snapshots.get(i);
				if (SnapshotState.Completed.toString().equals(snapshot.getState())) {
					String snapshotId = snapshot.getSnapshotId();
					pargeSnapshot(client, snapshotId);
					logger.log("Parge EBS snapshot. snapshotId[" + snapshotId + "] volumeId[" + volumeId + "]");
				}
			}
		}
	}
 
开发者ID:uzresk,项目名称:aws-auto-operations-using-lambda,代码行数:28,代码来源:EBSSnapshotFunction.java

示例3: describeSnapshot

import com.amazonaws.services.ec2.AmazonEC2Async; //导入方法依赖的package包/类
private List<Snapshot> describeSnapshot(AmazonEC2Async client, String imageId, Context context) {

		Filter filter = new Filter().withName("description")
				.withValues("Created by CreateImage(*) for " + imageId + " from *");
		DescribeSnapshotsRequest request = new DescribeSnapshotsRequest().withFilters(filter);
		DescribeSnapshotsResult result = client.describeSnapshots(request);
		return result.getSnapshots();
	}
 
开发者ID:uzresk,项目名称:aws-auto-operations-using-lambda,代码行数:9,代码来源:DeregisterImageFunction.java

示例4: pargeEbsSnapshot

import com.amazonaws.services.ec2.AmazonEC2Async; //导入方法依赖的package包/类
void pargeEbsSnapshot(AmazonEC2Async client, String sourceSnapshotId, String snapshotId, int generationCount,
		Context context) {

	LambdaLogger logger = context.getLogger();
	logger.log(
			"Parge snapshot start. SnapshotId[" + sourceSnapshotId + "] generationCount[" + generationCount + "]");

	// get volumeId from tags
	String volumeId = getVolumeIdFromTag(client, snapshotId);

	// describe filter tag VolumeId
	List<Filter> filters = new ArrayList<>();
	filters.add(new Filter().withName("tag:VolumeId").withValues(volumeId));
	filters.add(new Filter().withName("tag:BackupType").withValues("copy-snapshot"));
	DescribeSnapshotsRequest snapshotRequest = new DescribeSnapshotsRequest().withFilters(filters);
	DescribeSnapshotsResult snapshotResult = client.describeSnapshots(snapshotRequest);

	// snapshot作成開始日でソートします。(古い→新しい)
	List<Snapshot> snapshots = snapshotResult.getSnapshots();
	Collections.sort(snapshots, new SnapshotComparator());

	// 世代管理保持数 < snapshotの数の場合、対象をpargeします。
	int snapshotSize = snapshots.size();
	if (generationCount < snapshotSize) {
		for (int i = 0; i < snapshotSize - generationCount; i++) {
			Snapshot snapshot = snapshots.get(i);
			// (念のため)snapshotのステータスが完了しているものだけをparge対象とする。
			if (SnapshotState.Completed.toString().equals(snapshot.getState())) {
				String pargeSnapshotId = snapshot.getSnapshotId();
				pargeSnapshot(client, pargeSnapshotId);
				logger.log("Parge EBS snapshot. snapshotId[" + pargeSnapshotId + "]");
			}
		}
	}
}
 
开发者ID:uzresk,项目名称:aws-auto-operations-using-lambda,代码行数:36,代码来源:EBSCopySnapshotFunction.java

示例5: copySnapshotFromVolumeId

import com.amazonaws.services.ec2.AmazonEC2Async; //导入方法依赖的package包/类
/**
 * Find the snapshot the volumeId the key, to get a copy of the latest
 * Snapshot
 *
 * @param volumeIdRequest
 *            VolumeIdRequest
 * @param context
 *            Context
 */
public void copySnapshotFromVolumeId(VolumeIdRequest volumeIdRequest, Context context) {

	LambdaLogger logger = context.getLogger();

	String regionName = System.getenv("AWS_DEFAULT_REGION");
	AmazonEC2Async client = RegionUtils.getRegion(regionName).createClient(AmazonEC2AsyncClient.class,
			new DefaultAWSCredentialsProviderChain(), cc);

	try {
		String volumeId = volumeIdRequest.getVolumeId();

		boolean isLockAcquisition = new LambdaLock().lock(volumeId, context);
		if (!isLockAcquisition) {
			logger.log("[ERROR][EBSCopySnapshot][" + volumeId + "]You can not acquire a lock.");
			return;
		}

		List<Filter> filters = new ArrayList<>();
		filters.add(new Filter().withName("volume-id").withValues(volumeId));
		filters.add(new Filter().withName("tag:VolumeId").withValues(volumeId));
		filters.add(new Filter().withName("tag:BackupType").withValues("snapshot"));
		DescribeSnapshotsRequest snapshotRequest = new DescribeSnapshotsRequest().withFilters(filters);
		DescribeSnapshotsResult snapshotResult = client.describeSnapshots(snapshotRequest);

		// sort and get latest snapshot
		List<Snapshot> snapshots = snapshotResult.getSnapshots();
		Collections.sort(snapshots, new SnapshotComparator());
		int snapshotsSize = snapshots.size();
		if (snapshotsSize == 0) {
			throw new RuntimeException("The copy source snapshot can not be found");
		}
		Snapshot snapshot = snapshots.get(snapshots.size() - 1);

		String sourceSnapshotId = snapshot.getSnapshotId();

		copySnapshot(sourceSnapshotId, volumeIdRequest.getDestinationRegion(), volumeIdRequest.getGenerationCount(),
				context);

	} catch (Exception e) {
		logger.log("[ERROR][EBSCopySnapshot][" + volumeIdRequest.getVolumeId() + "] message[" + e.getMessage()
				+ "] stackTrace[" + getStackTrace(e) + "]");
	} finally {
		client.shutdown();
	}
}
 
开发者ID:uzresk,项目名称:aws-auto-operations-using-lambda,代码行数:55,代码来源:EBSCopySnapshotFunction.java


注:本文中的com.amazonaws.services.ec2.AmazonEC2Async.describeSnapshots方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。