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


Java AmazonEC2Async類代碼示例

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


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

示例1: process

import com.amazonaws.services.ec2.AmazonEC2Async; //導入依賴的package包/類
@Override
public void process(AmazonEC2Async amazonEC2Async, Instance instance) {
    amazonEC2Async.stopInstancesAsync(
            new StopInstancesRequest().withInstanceIds(instance.getInstanceId()),
            new AsyncHandler<StopInstancesRequest, StopInstancesResult>() {
                @Override
                public void onError(Exception exception) {
                    log.warn("something went wrong stopping the server {}",
                            exception.getLocalizedMessage());
                }

                @Override
                public void onSuccess(StopInstancesRequest request, StopInstancesResult result) {
                    onSuccessStop(instance);
                }
            });
}
 
開發者ID:peavers,項目名稱:swordfish-service,代碼行數:18,代碼來源:EC2StopImpl.java

示例2: amazonEC2Async

import com.amazonaws.services.ec2.AmazonEC2Async; //導入依賴的package包/類
@Override
public AmazonEC2Async amazonEC2Async() {
    User user = authenticationService.getCurrentUser();

    String accessKey = user.getAwsKey();
    String secretKey = user.getAwsSecret();
    String region = user.getAwsRegion();

    if (secretKey.equals("") || accessKey.equals("") || region.equals("")) {
        return null;
    }

    BasicAWSCredentials basicAWSCredentials = new BasicAWSCredentials(
            accessKey, secretKey);

    return AmazonEC2AsyncClientBuilder.standard().withRegion(region)
            .withCredentials(new AWSStaticCredentialsProvider(basicAWSCredentials))
            .build();
}
 
開發者ID:peavers,項目名稱:swordfish-service,代碼行數:20,代碼來源:EC2UserClientImpl.java

示例3: createSnapshotFromTagName

import com.amazonaws.services.ec2.AmazonEC2Async; //導入依賴的package包/類
public void createSnapshotFromTagName(TagNameRequest tagNameRequest, Context context) {

		LambdaLogger logger = context.getLogger();
		logger.log("create ebs snapshot from tag name Start. backup target[" + tagNameRequest + "]");

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

		try {
			List<Volume> volumes = describeBackupVolumes(client, tagNameRequest);

			for (Volume volume : volumes) {
				createSnapshot(volume.getVolumeId(), tagNameRequest.getGenerationCount(), context);
			}
		} finally {
			client.shutdown();
		}
	}
 
開發者ID:uzresk,項目名稱:aws-auto-operations-using-lambda,代碼行數:20,代碼來源:EBSSnapshotFunction.java

示例4: getSnapshotIdsFromImageId

import com.amazonaws.services.ec2.AmazonEC2Async; //導入依賴的package包/類
List<String> getSnapshotIdsFromImageId(AmazonEC2Async client, ImageCreateRequest request, Context context) {

		// LambdaLogger logger = context.getLogger();
		String imageId = request.getImageId();

		DescribeImagesResult result = client.describeImages(new DescribeImagesRequest().withImageIds(imageId));

		List<String> snapshotIds = new ArrayList<String>();

		for (Image image : result.getImages()) {
			for (BlockDeviceMapping block : image.getBlockDeviceMappings()) {
				snapshotIds.add(block.getEbs().getSnapshotId());
			}
		}
		return snapshotIds;
	}
 
開發者ID:uzresk,項目名稱:aws-auto-operations-using-lambda,代碼行數:17,代碼來源:ImageStateCheckAndPargeFunction.java

示例5: getInstanceStateName

import com.amazonaws.services.ec2.AmazonEC2Async; //導入依賴的package包/類
public String getInstanceStateName(InstanceRequest instanceRequest, Context context) {

		AmazonEC2Async client = createEC2Client();
		try {
			DescribeInstancesResult result = client
					.describeInstances(new DescribeInstancesRequest().withInstanceIds(instanceRequest.getInstanceId()));
			List<Instance> instances = result.getReservations().get(0).getInstances();
			if (instances.size() != 1) {
				throw new RuntimeException("instance can not be found.");
			}
			return instances.get(0).getState().getName();

		} finally {
			client.shutdown();
		}
	}
 
開發者ID:uzresk,項目名稱:aws-auto-operations-using-lambda,代碼行數:17,代碼來源:InstanceOperation.java

示例6: stopInstance

import com.amazonaws.services.ec2.AmazonEC2Async; //導入依賴的package包/類
StopInstancesResult stopInstance(InstanceRequest instanceRequest, Context context) {
	AmazonEC2Async client = createEC2Client();
	try {
		StopInstancesRequest req = new StopInstancesRequest();
		req.setInstanceIds(Arrays.asList(instanceRequest.getInstanceId()));
		Future<StopInstancesResult> result = client.stopInstancesAsync(req);
		while (!result.isDone()) {
			Thread.sleep(100);
		}
		return result.get();

	} catch (Exception e) {
		throw new RuntimeException("unexpected error has occured in the stop instance request.", e);
	} finally {
		client.shutdown();
	}
}
 
開發者ID:uzresk,項目名稱:aws-auto-operations-using-lambda,代碼行數:18,代碼來源:InstanceStopFunction.java

示例7: startInstance

import com.amazonaws.services.ec2.AmazonEC2Async; //導入依賴的package包/類
StartInstancesResult startInstance(InstanceRequest instanceRequest, Context context) {
	AmazonEC2Async client = createEC2Client();
	try {
		StartInstancesRequest req = new StartInstancesRequest();
		req.setInstanceIds(Arrays.asList(instanceRequest.getInstanceId()));
		Future<StartInstancesResult> result = client.startInstancesAsync(req);
		while (!result.isDone()) {
			Thread.sleep(100);
		}
		return result.get();

	} catch (Exception e) {
		throw new RuntimeException("unexpected error has occured in the start instance request.", e);
	} finally {
		client.shutdown();
	}
}
 
開發者ID:uzresk,項目名稱:aws-auto-operations-using-lambda,代碼行數:18,代碼來源:InstanceStartFunction.java

示例8: 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

示例9: syncAll

import com.amazonaws.services.ec2.AmazonEC2Async; //導入依賴的package包/類
@Override
public Iterable<Instance> syncAll(AmazonEC2Async amazonEC2Async) {
    DescribeInstancesRequest request = new DescribeInstancesRequest();
    DescribeInstancesResult response = amazonEC2Async.describeInstances(request);

    return processResponse(response);
}
 
開發者ID:peavers,項目名稱:swordfish-service,代碼行數:8,代碼來源:EC2SyncImpl.java

示例10: run

import com.amazonaws.services.ec2.AmazonEC2Async; //導入依賴的package包/類
@Override
public void run() {
    for (User user : authenticationService.getLocalUsers()) {

        AmazonEC2Async amazonEC2Async = ec2UserClient.amazonEC2Async(user);

        if (amazonEC2Async != null) {
            Iterable<Instance> instances = ec2Sync.syncAll(amazonEC2Async);
            for (Instance instance : instances) {
                notificationService.send("server_refresh", "server_refresh", jsonTransformService.write(instance));
            }
        }
    }
}
 
開發者ID:peavers,項目名稱:swordfish-service,代碼行數:15,代碼來源:InstanceRefreshTask.java

示例11: run

import com.amazonaws.services.ec2.AmazonEC2Async; //導入依賴的package包/類
@Override
public void run() {
    Iterable<Instance> instances = instanceRepository.findAllByStateAndSwordfishIsTrueAndProductionIsFalse("running");

    for (Instance instance : instances) {
        User user = authenticationService.getLocalUserById(instance.getUserId());
        AmazonEC2Async amazonEC2Async = ec2UserClient.amazonEC2Async(user);

        ec2Stop.process(amazonEC2Async, instance);
    }

}
 
開發者ID:peavers,項目名稱:swordfish-service,代碼行數:13,代碼來源:InstanceShutdownTask.java

示例12: describeBackupVolumes

import com.amazonaws.services.ec2.AmazonEC2Async; //導入依賴的package包/類
List<Volume> describeBackupVolumes(AmazonEC2Async client, TagNameRequest target) {

		Filter tagKey = new Filter().withName("tag-key").withValues("Backup");
		Filter tagValue = new Filter().withName("tag-value").withValues(target.getTagName());
		DescribeVolumesRequest req = new DescribeVolumesRequest().withFilters(tagKey, tagValue);
		DescribeVolumesResult result = client.describeVolumes(req);

		return result.getVolumes();
	}
 
開發者ID:uzresk,項目名稱:aws-auto-operations-using-lambda,代碼行數:10,代碼來源:EBSSnapshotFunction.java

示例13: attachSnapshotTags

import com.amazonaws.services.ec2.AmazonEC2Async; //導入依賴的package包/類
void attachSnapshotTags(AmazonEC2Async client, String volumeId, String snapshotId) {

		List<Tag> tags = new ArrayList<Tag>();
		tags.add(new Tag("VolumeId", volumeId));
		tags.add(new Tag("BackupType", "snapshot"));

		CreateTagsRequest snapshotTagsRequest = new CreateTagsRequest().withResources(snapshotId);
		snapshotTagsRequest.setTags(tags);
		client.createTags(snapshotTagsRequest);
	}
 
開發者ID:uzresk,項目名稱:aws-auto-operations-using-lambda,代碼行數:11,代碼來源:EBSSnapshotFunction.java

示例14: 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

示例15: createAMI

import com.amazonaws.services.ec2.AmazonEC2Async; //導入依賴的package包/類
String createAMI(ImageCreateRequest request, Context context) {

		LambdaLogger logger = context.getLogger();

		AmazonEC2Async client = createEC2Client();

		String imageId = null;
		try {
			Future<CreateImageResult> result = client
					.createImageAsync(new CreateImageRequest(request.getInstanceId(), request.getAmiName())
							.withNoReboot(request.isNoReboot()));
			while (!result.isDone()) {
				Thread.sleep(1000);
			}
			imageId = result.get().getImageId();

			logger.log("AMI Create Request End. instanceId[" + request.getInstanceId() + "] noReboot["
					+ request.isNoReboot() + "] imageId[" + imageId + "]");
		} catch (Exception e) {
			throw new RuntimeException("An unexpected error at the time of AMI creation has occurred", e);
		} finally {
			client.shutdown();
		}
		return imageId;
	}
 
開發者ID:uzresk,項目名稱:aws-auto-operations-using-lambda,代碼行數:26,代碼來源:ImageCreateFunction.java


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