private Volume createVolume(String volId, String snapId, Date createDate, String zone, int size, String state, List<Tag> tags, String instance_id) { Volume volume = new Volume(); volume.setVolumeId(volId); volume.setSnapshotId(snapId); volume.setCreateTime(createDate); volume.setAvailabilityZone(zone); volume.setState(state); volume.setSize(size); volume.setTags(tags); if (instance_id != null) { List<VolumeAttachment> volumeAttachmentList = new ArrayList(); VolumeAttachment volumeAttachment = new VolumeAttachment(); volumeAttachment.setInstanceId(instance_id); volumeAttachmentList.add(volumeAttachment); volume.setAttachments(volumeAttachmentList); } return volume; }
public void detachVolume(AwsProcessClient awsProcessClient, Long instanceNo, Long volumeNo) { 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, "AwsEbsDetach", new Object[] { instance.getInstanceName(), awsVolume.getVolumeId(), awsVolume.getDevice() }); // ボリュームのデタッチ DetachVolumeRequest request = new DetachVolumeRequest(); request.withVolumeId(volumeId); request.withInstanceId(awsVolume.getInstanceId()); request.withDevice(awsVolume.getDevice()); DetachVolumeResult result = awsProcessClient.getEc2Client().detachVolume(request); VolumeAttachment attachment = result.getAttachment(); // ログ出力 if (log.isInfoEnabled()) { log.info(MessageUtils.getMessage("IPROCESS-100125", volumeId, attachment.getInstanceId())); } }
@Override protected VolumeAttachment convertObject(AttachmentInfo from) { VolumeAttachment to = new VolumeAttachment(); to.setVolumeId(from.getVolumeId()); to.setInstanceId(from.getInstanceId()); to.setDevice(from.getDevice()); to.setState(from.getStatus()); to.setAttachTime(from.getAttachTime().getTime()); // 未実装 to.setDeleteOnTermination(false); return to; }
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); }
/** * Wait for the specified list of volumes to be attached within a timeout. * * @param volumeIds collection of volume ids to wait for * @return collection of volumes that were successfully attached * @throws InterruptedException if the operation is interrupted */ private Collection<String> waitUntilVolumesAttached(Collection<String> volumeIds) throws InterruptedException { checkNotNull(volumeIds); if (volumeIds.isEmpty()) { LOG.info("No volumes are being attached, skipping wait"); return Collections.emptySet(); } Set<String> unattachedVolumes = Sets.newHashSet(volumeIds); Set<String> attachedVolumes = Sets.newHashSet(); LOG.info("Waiting for a maximum of {} seconds for volumes to be attached", attachTimeoutSeconds); Stopwatch watch = Stopwatch.createStarted(); while (watch.elapsed(TimeUnit.SECONDS) < attachTimeoutSeconds) { DescribeVolumesRequest volumeRequest = new DescribeVolumesRequest().withVolumeIds(unattachedVolumes); List<Volume> volumes = client.describeVolumes(volumeRequest).getVolumes(); for (Volume volume : volumes) { VolumeAttachment attachment = Iterables.getOnlyElement(volume.getAttachments()); VolumeAttachmentState state = VolumeAttachmentState.fromValue(attachment.getState()); if (state == VolumeAttachmentState.Attached) { unattachedVolumes.remove(volume.getVolumeId()); attachedVolumes.add(volume.getVolumeId()); } } if (unattachedVolumes.isEmpty()) { return attachedVolumes; } LOG.info("Waiting on {} out of {} volumes to be attached, next check in {} seconds", unattachedVolumes.size(), volumeIds.size(), WAIT_UNTIL_ATTACHED_INTERVAL_SECONDS); TimeUnit.SECONDS.sleep(WAIT_UNTIL_ATTACHED_INTERVAL_SECONDS); } LOG.error("Timed out while waiting for all volumes to be attached, {} out of {} volumes were attached", attachedVolumes.size(), volumeIds.size()); return attachedVolumes; }
@Override public List<VolumeAttachment> getAttachments() { return (List<VolumeAttachment>) resource.getAttribute("Attachments"); }
/** * Gets the value of the Attachments attribute. If this resource is not yet * loaded, a call to {@code load()} is made to retrieve the value of the * attribute. */ List<VolumeAttachment> getAttachments();