com.amazonaws.services.ec2.model.AttachVolumeRequest Java Examples
The following examples show how to use
com.amazonaws.services.ec2.model.AttachVolumeRequest.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AwsVolumeProcess.java From primecloud-controller with GNU General Public License v2.0 | 5 votes |
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); }
Example #2
Source File: VolumeImpl.java From aws-sdk-java-resources with Apache License 2.0 | 5 votes |
@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(); }
Example #3
Source File: VolumeImpl.java From aws-sdk-java-resources with Apache License 2.0 | 5 votes |
@Override public AttachVolumeResult attachToInstance(String device, String instanceId, ResultCapture<AttachVolumeResult> extractor) { AttachVolumeRequest request = new AttachVolumeRequest() .withDevice(device) .withInstanceId(instanceId); return attachToInstance(request, extractor); }
Example #4
Source File: InstanceImpl.java From aws-sdk-java-resources with Apache License 2.0 | 5 votes |
@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(); }
Example #5
Source File: InstanceImpl.java From aws-sdk-java-resources with Apache License 2.0 | 5 votes |
@Override public AttachVolumeResult attachVolume(String device, String volumeId, ResultCapture<AttachVolumeResult> extractor) { AttachVolumeRequest request = new AttachVolumeRequest() .withDevice(device) .withVolumeId(volumeId); return attachVolume(request, extractor); }
Example #6
Source File: AwsAttachmentResourceBuilder.java From cloudbreak with Apache License 2.0 | 5 votes |
@Override public List<CloudResource> build(AwsContext context, long privateId, AuthenticatedContext auth, Group group, List<CloudResource> buildableResource, CloudStack cloudStack) throws Exception { LOGGER.debug("Attach volumes to instance"); CloudResource instance = buildableResource.stream() .filter(cloudResource -> cloudResource.getType().equals(ResourceType.AWS_INSTANCE)) .findFirst() .orElseThrow(() -> new AwsResourceException("Instance resource not found")); Optional<CloudResource> volumeSetOpt = buildableResource.stream() .filter(cloudResource -> cloudResource.getType().equals(ResourceType.AWS_VOLUMESET)) .findFirst(); if (volumeSetOpt.isEmpty()) { LOGGER.debug("No volumes to attach"); return List.of(); } CloudResource volumeSet = volumeSetOpt.get(); AmazonEc2RetryClient client = getAmazonEc2RetryClient(auth); VolumeSetAttributes volumeSetAttributes = volumeSet.getParameter(CloudResource.ATTRIBUTES, VolumeSetAttributes.class); List<Future<?>> futures = volumeSetAttributes.getVolumes().stream() .filter(volume -> !StringUtils.equals(AwsDiskType.Ephemeral.value(), volume.getType())) .map(volume -> new AttachVolumeRequest() .withInstanceId(instance.getInstanceId()) .withVolumeId(volume.getId()) .withDevice(volume.getDevice())) .map(request -> intermediateBuilderExecutor.submit(() -> client.attachVolume(request))) .collect(Collectors.toList()); for (Future<?> future : futures) { future.get(); } volumeSet.setInstanceId(instance.getInstanceId()); volumeSet.setStatus(CommonStatus.CREATED); return List.of(volumeSet); }
Example #7
Source File: Ec2MachineConfigurator.java From roboconf-platform with Apache License 2.0 | 4 votes |
/** * 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; }
Example #8
Source File: VolumeImpl.java From aws-sdk-java-resources with Apache License 2.0 | 4 votes |
@Override public AttachVolumeResult attachToInstance(AttachVolumeRequest request) { return attachToInstance(request, null); }
Example #9
Source File: InstanceImpl.java From aws-sdk-java-resources with Apache License 2.0 | 4 votes |
@Override public AttachVolumeResult attachVolume(AttachVolumeRequest request) { return attachVolume(request, null); }
Example #10
Source File: AmazonEc2RetryClient.java From cloudbreak with Apache License 2.0 | 4 votes |
public AttachVolumeResult attachVolume(AttachVolumeRequest request) { return retry.testWith2SecDelayMax15Times(() -> mapThrottlingError(() -> client.attachVolume(request))); }
Example #11
Source File: Instance.java From aws-sdk-java-resources with Apache License 2.0 | 2 votes |
/** * 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);
Example #12
Source File: Instance.java From aws-sdk-java-resources with Apache License 2.0 | 2 votes |
/** * 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);
Example #13
Source File: Volume.java From aws-sdk-java-resources with Apache License 2.0 | 2 votes |
/** * 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);
Example #14
Source File: Volume.java From aws-sdk-java-resources with Apache License 2.0 | 2 votes |
/** * 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);