@Test public void DeleteStorageVolume_BasicTest() throws Exception { VolumeInfo volOne = new VolumeInfo(); volOne.setStatus(StorageProperties.Status.available.toString()); volOne.setSize(new Integer(1)); volOne.setUserName("unittestuser0"); volOne.setVolumeId("vol-0000"); volOne.setSnapshotId("snap-0000"); volOne.setCreateTime(new Date()); volOne.setZone("eucalyptus"); try (TransactionResource tran = Entities.transactionFor(VolumeInfo.class)) { Entities.persist(volOne); tran.commit(); } final LogicalStorageManager storageManager = context.mock(LogicalStorageManager.class); context.checking(new Expectations() { { } }); StorageProperties.enableStorage = true; BlockStorageController bsc = new BlockStorageController(storageManager); DeleteStorageVolumeType request = new DeleteStorageVolumeType(); request.setVolumeId("vol-0000"); DeleteStorageVolumeResponseType response = bsc.DeleteStorageVolume(request); VolumeInfo retrieved; try (TransactionResource tran = Entities.transactionFor(VolumeInfo.class)) { retrieved = Entities.uniqueResult(new VolumeInfo("vol-0000")); tran.commit(); } assertTrue("expected to find volume after execution", "vol-0000".equals(retrieved.getVolumeId())); assertTrue("expected retrieved volume to be 'deleting'", StorageProperties.Status.deleting.toString().equals(retrieved.getStatus())); }
@Override public DeleteStorageVolumeResponseType DeleteStorageVolume(DeleteStorageVolumeType request) throws EucalyptusCloudException { final long startTime = System.currentTimeMillis(); DeleteStorageVolumeResponseType reply = (DeleteStorageVolumeResponseType) request.getReply(); if (!StorageProperties.enableStorage) { LOG.error("BlockStorage has been disabled. Please check your setup"); return reply; } String volumeId = request.getVolumeId(); LOG.info("Processing DeleteStorageVolume request for volume " + volumeId); VolumeInfo volumeInfo = new VolumeInfo(); volumeInfo.setVolumeId(volumeId); try (TransactionResource tran = Entities.transactionFor(VolumeInfo.class)) { VolumeInfo foundVolume = Entities.uniqueResult(volumeInfo); String status = foundVolume.getStatus(); if (status == null) { throw new EucalyptusCloudException("Invalid volume status: null"); } else if (status.equals(StorageProperties.Status.available.toString())) { LOG.trace("Marking volume " + volumeId + " for deletion"); ThruputMetrics.startOperation(MonitoredAction.DELETE_VOLUME, volumeId, startTime); foundVolume.setStatus(StorageProperties.Status.deleting.toString()); } else if (status.equals(StorageProperties.Status.deleting.toString()) || status.equals(StorageProperties.Status.deleted.toString()) || status.equals(StorageProperties.Status.failed.toString())) { LOG.debug("Volume " + volumeId + " already in deleting/deleted/failed. No-op for delete request."); } else { throw new EucalyptusCloudException("Cannot delete volume in state: " + status + ". Please retry later"); } reply.set_return(Boolean.TRUE); tran.commit(); } catch (NoSuchElementException e) { LOG.warn("Got delete request, but unable to find volume in SC database: " + volumeId); reply.set_return(Boolean.TRUE); } catch (EucalyptusCloudException e) { LOG.error("Error marking volume " + volumeId + " for deletion: " + e.getMessage()); throw e; } catch (final Throwable e) { LOG.error("Exception looking up volume: " + volumeId, e); throw new EucalyptusCloudException(e); } return reply; }
BlockStorageController implements BlockStorageService { @Override public DeleteStorageVolumeResponseType DeleteStorageVolume(DeleteStorageVolumeType request) throws EucalyptusCloudException { final long startTime = System.currentTimeMillis(); DeleteStorageVolumeResponseType reply = (DeleteStorageVolumeResponseType) request.getReply(); if (!StorageProperties.enableStorage) { LOG.error("BlockStorage has been disabled. Please check your setup"); return reply; } String volumeId = request.getVolumeId(); LOG.info("Processing DeleteStorageVolume request for volume " + volumeId); VolumeInfo volumeInfo = new VolumeInfo(); volumeInfo.setVolumeId(volumeId); try (TransactionResource tran = Entities.transactionFor(VolumeInfo.class)) { VolumeInfo foundVolume = Entities.uniqueResult(volumeInfo); String status = foundVolume.getStatus(); if (status == null) { throw new EucalyptusCloudException("Invalid volume status: null"); } else if (status.equals(StorageProperties.Status.available.toString())) { LOG.trace("Marking volume " + volumeId + " for deletion"); ThruputMetrics.startOperation(MonitoredAction.DELETE_VOLUME, volumeId, startTime); foundVolume.setStatus(StorageProperties.Status.deleting.toString()); } else if (status.equals(StorageProperties.Status.deleting.toString()) || status.equals(StorageProperties.Status.deleted.toString()) || status.equals(StorageProperties.Status.failed.toString())) { LOG.debug("Volume " + volumeId + " already in deleting/deleted/failed. No-op for delete request."); } else { throw new EucalyptusCloudException("Cannot delete volume in state: " + status + ". Please retry later"); } reply.set_return(Boolean.TRUE); tran.commit(); } catch (NoSuchElementException e) { LOG.warn("Got delete request, but unable to find volume in SC database: " + volumeId); reply.set_return(Boolean.TRUE); } catch (EucalyptusCloudException e) { LOG.error("Error marking volume " + volumeId + " for deletion: " + e.getMessage()); throw e; } catch (final Throwable e) { LOG.error("Exception looking up volume: " + volumeId, e); throw new EucalyptusCloudException(e); } return reply; } }
BlockStorageController implements BlockStorageService { @Override public DeleteStorageVolumeResponseType DeleteStorageVolume(DeleteStorageVolumeType request) throws EucalyptusCloudException { final long startTime = System.currentTimeMillis(); DeleteStorageVolumeResponseType reply = (DeleteStorageVolumeResponseType) request.getReply(); if (!StorageProperties.enableStorage) { LOG.error("BlockStorage has been disabled. Please check your setup"); return reply; } String volumeId = request.getVolumeId(); LOG.info("Processing DeleteStorageVolume request for volume " + volumeId); VolumeInfo volumeInfo = new VolumeInfo(); volumeInfo.setVolumeId(volumeId); try (TransactionResource tran = Entities.transactionFor(VolumeInfo.class)) { VolumeInfo foundVolume = Entities.uniqueResult(volumeInfo); String status = foundVolume.getStatus(); if (status == null) { throw new EucalyptusCloudException("Invalid volume status: null"); } else if (status.equals(StorageProperties.Status.available.toString())) { LOG.trace("Marking volume " + volumeId + " for deletion"); ThruputMetrics.startOperation(MonitoredAction.DELETE_VOLUME, volumeId, startTime); foundVolume.setStatus(StorageProperties.Status.deleting.toString()); } else if (status.equals(StorageProperties.Status.deleting.toString()) || status.equals(StorageProperties.Status.deleted.toString()) || status.equals(StorageProperties.Status.failed.toString())) { LOG.debug("Volume " + volumeId + " already in deleting/deleted/failed. No-op for delete request."); } else { throw new EucalyptusCloudException("Cannot delete volume in state: " + status + ". Please retry later"); } reply.set_return(Boolean.TRUE); tran.commit(); } catch (NoSuchElementException e) { LOG.warn("Got delete request, but unable to find volume in SC database: " + volumeId); reply.set_return(Boolean.TRUE); } catch (EucalyptusCloudException e) { LOG.error("Error marking volume " + volumeId + " for deletion: " + e.getMessage()); throw e; } catch (final Throwable e) { LOG.error("Exception looking up volume: " + volumeId, e); throw new EucalyptusCloudException(e); } return reply; } BlockStorageController();  BlockStorageController(LogicalStorageManager blockManager); }
BlockStorageController implements BlockStorageService { @Override public DeleteStorageVolumeResponseType DeleteStorageVolume(DeleteStorageVolumeType request) throws EucalyptusCloudException { final long startTime = System.currentTimeMillis(); DeleteStorageVolumeResponseType reply = (DeleteStorageVolumeResponseType) request.getReply(); if (!StorageProperties.enableStorage) { LOG.error("BlockStorage has been disabled. Please check your setup"); return reply; } String volumeId = request.getVolumeId(); LOG.info("Processing DeleteStorageVolume request for volume " + volumeId); VolumeInfo volumeInfo = new VolumeInfo(); volumeInfo.setVolumeId(volumeId); try (TransactionResource tran = Entities.transactionFor(VolumeInfo.class)) { VolumeInfo foundVolume = Entities.uniqueResult(volumeInfo); String status = foundVolume.getStatus(); if (status == null) { throw new EucalyptusCloudException("Invalid volume status: null"); } else if (status.equals(StorageProperties.Status.available.toString())) { LOG.trace("Marking volume " + volumeId + " for deletion"); ThruputMetrics.startOperation(MonitoredAction.DELETE_VOLUME, volumeId, startTime); foundVolume.setStatus(StorageProperties.Status.deleting.toString()); } else if (status.equals(StorageProperties.Status.deleting.toString()) || status.equals(StorageProperties.Status.deleted.toString()) || status.equals(StorageProperties.Status.failed.toString())) { LOG.debug("Volume " + volumeId + " already in deleting/deleted/failed. No-op for delete request."); } else { throw new EucalyptusCloudException("Cannot delete volume in state: " + status + ". Please retry later"); } reply.set_return(Boolean.TRUE); tran.commit(); } catch (NoSuchElementException e) { LOG.warn("Got delete request, but unable to find volume in SC database: " + volumeId); reply.set_return(Boolean.TRUE); } catch (EucalyptusCloudException e) { LOG.error("Error marking volume " + volumeId + " for deletion: " + e.getMessage()); throw e; } catch (final Throwable e) { LOG.error("Exception looking up volume: " + volumeId, e); throw new EucalyptusCloudException(e); } return reply; } BlockStorageController();  BlockStorageController(LogicalStorageManager blockManager); static void configure(); static void check(); static void stop(); static void enable(); static void disable(); static void updateStuckVolumes(); static void updateStuckSnapshots(); @Override UpdateStorageConfigurationResponseType UpdateStorageConfiguration(UpdateStorageConfigurationType request); @Override GetStorageConfigurationResponseType GetStorageConfiguration(GetStorageConfigurationType request); @Override GetVolumeTokenResponseType GetVolumeToken(GetVolumeTokenType request); @Override UnexportVolumeResponseType UnexportVolume(UnexportVolumeType request); @Override ExportVolumeResponseType ExportVolume(ExportVolumeType request); @Override GetStorageVolumeResponseType GetStorageVolume(GetStorageVolumeType request); @Override DeleteStorageVolumeResponseType DeleteStorageVolume(DeleteStorageVolumeType request); @Override CreateStorageSnapshotResponseType CreateStorageSnapshot(CreateStorageSnapshotType request); @Override DescribeStorageSnapshotsResponseType DescribeStorageSnapshots(DescribeStorageSnapshotsType request); @Override DeleteStorageSnapshotResponseType DeleteStorageSnapshot(DeleteStorageSnapshotType request); @Override CreateStorageVolumeResponseType CreateStorageVolume(CreateStorageVolumeType request); @Override DescribeStorageVolumesResponseType DescribeStorageVolumes(DescribeStorageVolumesType request); @Override ConvertVolumesResponseType ConvertVolumes(ConvertVolumesType request); @Override AttachStorageVolumeResponseType attachVolume(AttachStorageVolumeType request); @Override DetachStorageVolumeResponseType detachVolume(DetachStorageVolumeType request); @Override CloneVolumeResponseType CloneVolume(CloneVolumeType request); }
BlockStorageController implements BlockStorageService { @Override public DeleteStorageVolumeResponseType DeleteStorageVolume(DeleteStorageVolumeType request) throws EucalyptusCloudException { final long startTime = System.currentTimeMillis(); DeleteStorageVolumeResponseType reply = (DeleteStorageVolumeResponseType) request.getReply(); if (!StorageProperties.enableStorage) { LOG.error("BlockStorage has been disabled. Please check your setup"); return reply; } String volumeId = request.getVolumeId(); LOG.info("Processing DeleteStorageVolume request for volume " + volumeId); VolumeInfo volumeInfo = new VolumeInfo(); volumeInfo.setVolumeId(volumeId); try (TransactionResource tran = Entities.transactionFor(VolumeInfo.class)) { VolumeInfo foundVolume = Entities.uniqueResult(volumeInfo); String status = foundVolume.getStatus(); if (status == null) { throw new EucalyptusCloudException("Invalid volume status: null"); } else if (status.equals(StorageProperties.Status.available.toString())) { LOG.trace("Marking volume " + volumeId + " for deletion"); ThruputMetrics.startOperation(MonitoredAction.DELETE_VOLUME, volumeId, startTime); foundVolume.setStatus(StorageProperties.Status.deleting.toString()); } else if (status.equals(StorageProperties.Status.deleting.toString()) || status.equals(StorageProperties.Status.deleted.toString()) || status.equals(StorageProperties.Status.failed.toString())) { LOG.debug("Volume " + volumeId + " already in deleting/deleted/failed. No-op for delete request."); } else { throw new EucalyptusCloudException("Cannot delete volume in state: " + status + ". Please retry later"); } reply.set_return(Boolean.TRUE); tran.commit(); } catch (NoSuchElementException e) { LOG.warn("Got delete request, but unable to find volume in SC database: " + volumeId); reply.set_return(Boolean.TRUE); } catch (EucalyptusCloudException e) { LOG.error("Error marking volume " + volumeId + " for deletion: " + e.getMessage()); throw e; } catch (final Throwable e) { LOG.error("Exception looking up volume: " + volumeId, e); throw new EucalyptusCloudException(e); } return reply; } BlockStorageController();  BlockStorageController(LogicalStorageManager blockManager); static void configure(); static void check(); static void stop(); static void enable(); static void disable(); static void updateStuckVolumes(); static void updateStuckSnapshots(); @Override UpdateStorageConfigurationResponseType UpdateStorageConfiguration(UpdateStorageConfigurationType request); @Override GetStorageConfigurationResponseType GetStorageConfiguration(GetStorageConfigurationType request); @Override GetVolumeTokenResponseType GetVolumeToken(GetVolumeTokenType request); @Override UnexportVolumeResponseType UnexportVolume(UnexportVolumeType request); @Override ExportVolumeResponseType ExportVolume(ExportVolumeType request); @Override GetStorageVolumeResponseType GetStorageVolume(GetStorageVolumeType request); @Override DeleteStorageVolumeResponseType DeleteStorageVolume(DeleteStorageVolumeType request); @Override CreateStorageSnapshotResponseType CreateStorageSnapshot(CreateStorageSnapshotType request); @Override DescribeStorageSnapshotsResponseType DescribeStorageSnapshots(DescribeStorageSnapshotsType request); @Override DeleteStorageSnapshotResponseType DeleteStorageSnapshot(DeleteStorageSnapshotType request); @Override CreateStorageVolumeResponseType CreateStorageVolume(CreateStorageVolumeType request); @Override DescribeStorageVolumesResponseType DescribeStorageVolumes(DescribeStorageVolumesType request); @Override ConvertVolumesResponseType ConvertVolumes(ConvertVolumesType request); @Override AttachStorageVolumeResponseType attachVolume(AttachStorageVolumeType request); @Override DetachStorageVolumeResponseType detachVolume(DetachStorageVolumeType request); @Override CloneVolumeResponseType CloneVolume(CloneVolumeType request);  }