Java 类com.amazonaws.services.ec2.model.AttachVolumeRequest 实例源码

项目:Tank    文件:AmazonInstance.java   
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);
}
项目:primecloud-controller    文件:AwsVolumeProcess.java   
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);
}
项目:aws-sdk-java-resources    文件:VolumeImpl.java   
@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();
}
项目:aws-sdk-java-resources    文件:VolumeImpl.java   
@Override
public AttachVolumeResult attachToInstance(String device, String instanceId,
        ResultCapture<AttachVolumeResult> extractor) {

    AttachVolumeRequest request = new AttachVolumeRequest()
        .withDevice(device)
        .withInstanceId(instanceId);
    return attachToInstance(request, extractor);
}
项目:aws-sdk-java-resources    文件:InstanceImpl.java   
@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();
}
项目:aws-sdk-java-resources    文件:InstanceImpl.java   
@Override
public AttachVolumeResult attachVolume(String device, String volumeId,
        ResultCapture<AttachVolumeResult> extractor) {

    AttachVolumeRequest request = new AttachVolumeRequest()
        .withDevice(device)
        .withVolumeId(volumeId);
    return attachVolume(request, extractor);
}
项目:elasticsearch_my    文件:AmazonEC2Mock.java   
@Override
public AttachVolumeResult attachVolume(AttachVolumeRequest attachVolumeRequest) throws AmazonServiceException, AmazonClientException {
    throw new UnsupportedOperationException("Not supported in mock");
}
项目:photon-model    文件:AWSInstanceService.java   
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());
                }
            });
}
项目:photon-model    文件:AWSComputeDiskDay2Service.java   
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;
}
项目:photon-model    文件:AWSComputeDiskDay2Service.java   
@Override
protected void handleSuccess(AttachVolumeRequest request, AttachVolumeResult result) {
    updateComputeAndDiskState(this.dr, this.context);
}
项目:roboconf-platform    文件:Ec2MachineConfigurator.java   
/**
 * 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;
}
项目:aws-sdk-java-resources    文件:VolumeImpl.java   
@Override
public AttachVolumeResult attachToInstance(AttachVolumeRequest request) {
    return attachToInstance(request, null);
}
项目:aws-sdk-java-resources    文件:InstanceImpl.java   
@Override
public AttachVolumeResult attachVolume(AttachVolumeRequest request) {
    return attachVolume(request, null);
}
项目:aws-sdk-java-resources    文件:Instance.java   
/**
 * 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);
项目:aws-sdk-java-resources    文件:Instance.java   
/**
 * Performs the <code>AttachVolume</code> action and use a ResultCapture to
 * retrieve the low-level client response.
 *
 * <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,
        ResultCapture<AttachVolumeResult> extractor);
项目:aws-sdk-java-resources    文件:Volume.java   
/**
 * 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);
项目:aws-sdk-java-resources    文件:Volume.java   
/**
 * Performs the <code>AttachToInstance</code> action and use a ResultCapture
 * to retrieve the low-level client response.
 *
 * <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,
        ResultCapture<AttachVolumeResult> extractor);