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); }
@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(); }
@Override public AttachVolumeResult attachToInstance(String device, String instanceId) { return attachToInstance(device, instanceId, (ResultCapture<AttachVolumeResult>)null); }
@Override public AttachVolumeResult attachToInstance(String device, String instanceId, ResultCapture<AttachVolumeResult> extractor) { AttachVolumeRequest request = new AttachVolumeRequest() .withDevice(device) .withInstanceId(instanceId); return attachToInstance(request, extractor); }
@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(); }
@Override public AttachVolumeResult attachVolume(String device, String volumeId, ResultCapture<AttachVolumeResult> extractor) { AttachVolumeRequest request = new AttachVolumeRequest() .withDevice(device) .withVolumeId(volumeId); return attachVolume(request, extractor); }
@Override public AttachVolumeResult attachVolume(AttachVolumeRequest attachVolumeRequest) throws AmazonServiceException, AmazonClientException { throw new UnsupportedOperationException("Not supported in mock"); }
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()); } }); }
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; }
@Override protected void handleSuccess(AttachVolumeRequest request, AttachVolumeResult result) { updateComputeAndDiskState(this.dr, this.context); }
@Override public AttachVolumeResult attachToInstance(AttachVolumeRequest request) { return attachToInstance(request, null); }
@Override public AttachVolumeResult attachVolume(AttachVolumeRequest request) { return attachVolume(request, null); }
@Override public AttachVolumeResult attachVolume(String device, String volumeId) { return attachVolume(device, volumeId, (ResultCapture<AttachVolumeResult>)null); }
/** * 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);
/** * 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);
/** * The convenient method form for the <code>AttachVolume</code> action. * * @see #attachVolume(AttachVolumeRequest) */ AttachVolumeResult attachVolume(String device, String volumeId);
/** * The convenient method form for the <code>AttachVolume</code> action. * * @see #attachVolume(AttachVolumeRequest, ResultCapture) */ AttachVolumeResult attachVolume(String device, String volumeId, ResultCapture<AttachVolumeResult> extractor);
/** * 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);
/** * 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);
/** * The convenient method form for the <code>AttachToInstance</code> action. * * @see #attachToInstance(AttachVolumeRequest) */ AttachVolumeResult attachToInstance(String device, String instanceId);
/** * The convenient method form for the <code>AttachToInstance</code> action. * * @see #attachToInstance(AttachVolumeRequest, ResultCapture) */ AttachVolumeResult attachToInstance(String device, String instanceId, ResultCapture<AttachVolumeResult> extractor);