本文整理汇总了Java中com.amazonaws.services.ec2.model.AttachVolumeRequest类的典型用法代码示例。如果您正苦于以下问题:Java AttachVolumeRequest类的具体用法?Java AttachVolumeRequest怎么用?Java AttachVolumeRequest使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
AttachVolumeRequest类属于com.amazonaws.services.ec2.model包,在下文中一共展示了AttachVolumeRequest类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: attachVolume
import com.amazonaws.services.ec2.model.AttachVolumeRequest; //导入依赖的package包/类
public void attachVolume(String volumneId, String instanceId, String device) {
AttachVolumeRequest attachVolumeRequest = new AttachVolumeRequest(volumneId, instanceId, device);
asynchEc2Client.attachVolume(attachVolumeRequest);
RebootInstancesRequest rebootInstancesRequest = new RebootInstancesRequest();
rebootInstancesRequest.withInstanceIds(instanceId);
asynchEc2Client.rebootInstances(rebootInstancesRequest);
}
示例2: attachVolume
import com.amazonaws.services.ec2.model.AttachVolumeRequest; //导入依赖的package包/类
public void attachVolume(AwsProcessClient awsProcessClient, Long instanceNo, Long volumeNo) {
AwsInstance awsInstance = awsInstanceDao.read(instanceNo);
AwsVolume awsVolume = awsVolumeDao.read(volumeNo);
String volumeId = awsVolume.getVolumeId();
//イベントログ出力
Component component = null;
if (awsVolume.getComponentNo() != null) {
component = componentDao.read(awsVolume.getComponentNo());
}
Instance instance = instanceDao.read(instanceNo);
processLogger.debug(component, instance, "AwsEbsAttach",
new Object[] { instance.getInstanceName(), awsVolume.getVolumeId(), awsVolume.getDevice() });
// ボリュームのアタッチ
AttachVolumeRequest request = new AttachVolumeRequest();
request.withVolumeId(volumeId);
request.withInstanceId(awsInstance.getInstanceId());
request.withDevice(awsVolume.getDevice());
AttachVolumeResult result = awsProcessClient.getEc2Client().attachVolume(request);
VolumeAttachment attachment = result.getAttachment();
// ログ出力
if (log.isInfoEnabled()) {
log.info(MessageUtils.getMessage("IPROCESS-100123", volumeId, attachment.getInstanceId()));
}
// データベースの更新
awsVolume.setInstanceId(attachment.getInstanceId());
awsVolumeDao.update(awsVolume);
}
示例3: attachToInstance
import com.amazonaws.services.ec2.model.AttachVolumeRequest; //导入依赖的package包/类
@Override
public AttachVolumeResult attachToInstance(AttachVolumeRequest request,
ResultCapture<AttachVolumeResult> extractor) {
ActionResult result = resource.performAction("AttachToInstance",
request, extractor);
if (result == null) return null;
return (AttachVolumeResult) result.getData();
}
示例4: attachVolume
import com.amazonaws.services.ec2.model.AttachVolumeRequest; //导入依赖的package包/类
@Override
public AttachVolumeResult attachVolume(AttachVolumeRequest request,
ResultCapture<AttachVolumeResult> extractor) {
ActionResult result = resource.performAction("AttachVolume", request,
extractor);
if (result == null) return null;
return (AttachVolumeResult) result.getData();
}
示例5: attachVolume
import com.amazonaws.services.ec2.model.AttachVolumeRequest; //导入依赖的package包/类
@Override
public AttachVolumeResult attachVolume(AttachVolumeRequest attachVolumeRequest) throws AmazonServiceException, AmazonClientException {
throw new UnsupportedOperationException("Not supported in mock");
}
示例6: attachExternalDisks
import com.amazonaws.services.ec2.model.AttachVolumeRequest; //导入依赖的package包/类
private DeferredResult<DiskState> attachExternalDisks( String id,
List<DiskState> externalDisks, List<String> availableEbsDiskNames,
AmazonEC2AsyncClient client) {
List<DeferredResult<Pair<DiskState, Throwable>>> diskStateResults =
externalDisks.stream().map(externalDisk -> {
String deviceName = availableEbsDiskNames.get(0);
availableEbsDiskNames.remove(0);
externalDisk.customProperties.put(DEVICE_NAME, deviceName);
AttachVolumeRequest attachVolumeRequest = new AttachVolumeRequest()
.withInstanceId(id)
.withVolumeId(externalDisk.id)
.withDevice(deviceName);
DeferredResult<DiskState> diskDr = new DeferredResult<>();
AWSAsyncHandler<AttachVolumeRequest, AttachVolumeResult> attachDiskHandler =
new AWSAsyncHandler<AttachVolumeRequest, AttachVolumeResult>() {
@Override protected void handleError(
Exception exception) {
diskDr.fail(exception);
}
@Override protected void handleSuccess(
AttachVolumeRequest request,
AttachVolumeResult result) {
diskDr.complete(externalDisk);
}
};
client.attachVolumeAsync(attachVolumeRequest, attachDiskHandler);
return diskDr;
}).map(diskDr -> diskDr
.thenApply(
diskState -> Pair.of(diskState, (Throwable) null))
.exceptionally(ex -> Pair.of(null, ex.getCause())))
.collect(Collectors.toList());
return DeferredResult.allOf(diskStateResults)
.thenCompose(pairs -> {
// Collect error messages if any for all the external disks.
StringJoiner stringJoiner = new StringJoiner(",");
pairs.stream().filter(p -> p.left == null)
.forEach(p -> stringJoiner.add(p.right.getMessage()));
if (stringJoiner.length() > 0) {
return DeferredResult.failed(new Throwable(stringJoiner
.toString()));
} else {
return DeferredResult.completed(new DiskState());
}
});
}
示例7: performAttachOperation
import com.amazonaws.services.ec2.model.AttachVolumeRequest; //导入依赖的package包/类
private DeferredResult<DiskContext> performAttachOperation(DiskContext context) {
DeferredResult<DiskContext> dr = new DeferredResult();
try {
if (context.request.isMockRequest) {
updateComputeAndDiskState(dr, context);
return dr;
}
String instanceId = context.computeState.id;
if (instanceId == null || !instanceId.startsWith(AWS_INSTANCE_ID_PREFIX)) {
return failTask(context, "compute id cannot be empty");
}
String diskId = context.diskState.id;
if (diskId == null || !diskId.startsWith(AWS_VOLUME_ID_PREFIX)) {
return failTask(context, "disk id cannot be empty");
}
String deviceName = getAvailableDeviceName(context, instanceId);
if (deviceName == null) {
return failTask(context, "No device name is available for attaching new disk");
}
context.diskState.customProperties.put(DEVICE_NAME, deviceName);
AttachVolumeRequest attachVolumeRequest = new AttachVolumeRequest()
.withInstanceId(instanceId)
.withVolumeId(diskId)
.withDevice(deviceName);
AWSAsyncHandler<AttachVolumeRequest, AttachVolumeResult> attachDiskHandler = new AWSAttachDiskHandler(
this, dr, context);
context.amazonEC2Client.attachVolumeAsync(attachVolumeRequest, attachDiskHandler);
} catch (Exception e) {
return failTask(context, e);
}
return dr;
}
示例8: handleSuccess
import com.amazonaws.services.ec2.model.AttachVolumeRequest; //导入依赖的package包/类
@Override
protected void handleSuccess(AttachVolumeRequest request, AttachVolumeResult result) {
updateComputeAndDiskState(this.dr, this.context);
}
示例9: attachVolumes
import com.amazonaws.services.ec2.model.AttachVolumeRequest; //导入依赖的package包/类
/**
* Attaches volume(s) for EBS.
* @return true if successful attachment, or nothing to do. false otherwise
*/
private boolean attachVolumes() {
// If volume is found in map, it has been successfully created (no need to check here)
for( Map.Entry<String,String> entry : this.storageIdToVolumeId.entrySet()) {
String volumeId = entry.getValue();
String storageId = entry.getKey();
// Give a name to the volume before attaching
String nameTemplate = Ec2IaasHandler.findStorageProperty(this.targetProperties, storageId, VOLUME_NAME_PREFIX);
String name = Ec2IaasHandler.expandVolumeName(
nameTemplate, this.applicationName, this.scopedInstance.getName());
if(Utils.isEmptyOrWhitespaces(name)) name = "Created by Roboconf for " + this.tagName;
tagResource(volumeId, name);
// Attach volume now
String mountPoint = Ec2IaasHandler.findStorageProperty(this.targetProperties, storageId, VOLUME_MOUNT_POINT_PREFIX);
if(Utils.isEmptyOrWhitespaces(mountPoint)) mountPoint = "/dev/sdf";
AttachVolumeRequest attachRequest = new AttachVolumeRequest()
.withInstanceId(this.machineId)
.withDevice(mountPoint)
.withVolumeId(volumeId);
try {
this.ec2Api.attachVolume(attachRequest);
} catch(Exception e) {
this.logger.warning("EBS Volume attachment error: " + e);
}
// Set deleteOnTermination flag ?
if(Boolean.parseBoolean(Ec2IaasHandler.findStorageProperty(this.targetProperties, storageId, VOLUME_DELETE_OT_PREFIX))) {
EbsInstanceBlockDeviceSpecification ebsSpecification = new EbsInstanceBlockDeviceSpecification()
.withVolumeId(volumeId)
.withDeleteOnTermination(true);
InstanceBlockDeviceMappingSpecification mappingSpecification = new InstanceBlockDeviceMappingSpecification()
.withDeviceName(mountPoint)
.withEbs(ebsSpecification);
ModifyInstanceAttributeRequest request = new ModifyInstanceAttributeRequest()
.withInstanceId(this.machineId)
.withBlockDeviceMappings(mappingSpecification);
this.ec2Api.modifyInstanceAttribute(request);
}
}
return true;
}
示例10: attachVolume
import com.amazonaws.services.ec2.model.AttachVolumeRequest; //导入依赖的package包/类
/**
* Performs the <code>AttachVolume</code> action.
*
* <p>
* The following request parameters will be populated from the data of this
* <code>Instance</code> resource, and any conflicting parameter value set
* in the request will be overridden:
* <ul>
* <li>
* <b><code>InstanceId</code></b>
* - mapped from the <code>Id</code> identifier.
* </li>
* </ul>
*
* <p>
*
* @return The response of the low-level client operation associated with
* this resource action.
* @see AttachVolumeRequest
*/
AttachVolumeResult attachVolume(AttachVolumeRequest request);
示例11: attachToInstance
import com.amazonaws.services.ec2.model.AttachVolumeRequest; //导入依赖的package包/类
/**
* Performs the <code>AttachToInstance</code> action.
*
* <p>
* The following request parameters will be populated from the data of this
* <code>Volume</code> resource, and any conflicting parameter value set in
* the request will be overridden:
* <ul>
* <li>
* <b><code>VolumeId</code></b>
* - mapped from the <code>Id</code> identifier.
* </li>
* </ul>
*
* <p>
*
* @return The response of the low-level client operation associated with
* this resource action.
* @see AttachVolumeRequest
*/
AttachVolumeResult attachToInstance(AttachVolumeRequest request);