@Test public void createVolume_FromSnap_CloneDbRecExistsTest() throws Exception { final String volId = "testparentvol"; final String rezPrefix = "fooprefix"; final String rezSuffix = "foosuffix"; final Integer snapSz = new Integer(5); final SANVolumeInfo existing = new SANVolumeInfo(volId).withSanVolumeId(rezPrefix + volId + rezSuffix); existing.setIqn("foo-parent-iqn"); existing.setSize(new Integer(5)); existing.setSnapshotOf("foo-vol"); final SANVolumeInfo existingClone = new SANVolumeInfo("testvol").withSanVolumeId(rezPrefix + "testvol" + rezSuffix); existingClone.setIqn("foo-iqn"); existingClone.setSize(new Integer(5)); SANInfo sanInfo = new SANInfo(StorageProperties.NAME, "foohost", "foouser", "foopassword"); sanInfo.setResourcePrefix(rezPrefix); sanInfo.setResourceSuffix(rezSuffix); try (TransactionResource tran = Entities.transactionFor(SANInfo.class)) { Entities.persist(existing); Entities.persist(existingClone); Entities.persist(sanInfo); tran.commit(); } final SANProvider sanProvider = context.mock(SANProvider.class); context.checking(new Expectations() { { oneOf(sanProvider).volumeExists(existingClone.getSanVolumeId(), existingClone.getIqn()); will(returnValue(Boolean.FALSE)); oneOf(sanProvider).createVolume(rezPrefix + "testvol" + rezSuffix, existingClone.getSanVolumeId(), snapSz.intValue(), snapSz.intValue(), existingClone.getIqn()); will(returnValue("foo-iqn")); } }); SANManager test = new SANManager(sanProvider); test.createVolume("testvol", existingClone.getVolumeId(), snapSz.intValue()); try (TransactionResource tran = Entities.transactionFor(SANVolumeInfo.class)) { List<SANVolumeInfo> results = Entities.query(new SANVolumeInfo()); assertTrue("expected two SANVolumeInfo to exist", results != null && results.size() == 2); } }
public void createVolume(String volumeId, int size) throws EucalyptusCloudException { String sanVolumeId = resourceIdOnSan(volumeId); SANVolumeInfo volumeInfo = new SANVolumeInfo(volumeId); try (TransactionResource tran = Entities.transactionFor(SANVolumeInfo.class)) { SANVolumeInfo existingVol = Entities.uniqueResult(volumeInfo); LOG.info("Checking for " + existingVol.getSanVolumeId() + " on backend"); if (connectionManager.volumeExists(existingVol.getSanVolumeId(), existingVol.getIqn())) { throw new VolumeAlreadyExistsException("Existing resource found on backend for " + existingVol.getSanVolumeId()); } else { LOG.debug("Found database record but resource does not exist on backend. Deleting database record for " + volumeId); Entities.delete(existingVol); tran.commit(); } } catch (NoSuchElementException ex) { } catch (VolumeAlreadyExistsException ex) { throw ex; } catch (Exception ex) { throw new EucalyptusCloudException(ex); } try { Transactions.save(volumeInfo.withSanVolumeId(sanVolumeId).withSize(size)); } catch (Exception ex) { LOG.warn("Failed to persist database record for " + volumeId, ex); throw new EucalyptusCloudException("Failed to persist database record for " + volumeId, ex); } LOG.info("Creating " + sanVolumeId + " on backend"); String iqn = connectionManager.createVolume(sanVolumeId, size); if (iqn != null) { try (TransactionResource tran = Entities.transactionFor(SANVolumeInfo.class)) { SANVolumeInfo existingVol = Entities.uniqueResult(volumeInfo); existingVol.setIqn(iqn); tran.commit(); } catch (Exception ex) { LOG.warn("Failed to update database record with IQN post creation for " + volumeId); throw new EucalyptusCloudException("Failed to update database record with IQN post creation for " + volumeId, ex); } } else { LOG.warn("Invalid IQN from backend for " + sanVolumeId); throw new EucalyptusCloudException("Failed to create " + volumeId + " due to invalid IQN from backend for " + sanVolumeId); } }
SANManager implements LogicalStorageManager { public void createVolume(String volumeId, int size) throws EucalyptusCloudException { String sanVolumeId = resourceIdOnSan(volumeId); SANVolumeInfo volumeInfo = new SANVolumeInfo(volumeId); try (TransactionResource tran = Entities.transactionFor(SANVolumeInfo.class)) { SANVolumeInfo existingVol = Entities.uniqueResult(volumeInfo); LOG.info("Checking for " + existingVol.getSanVolumeId() + " on backend"); if (connectionManager.volumeExists(existingVol.getSanVolumeId(), existingVol.getIqn())) { throw new VolumeAlreadyExistsException("Existing resource found on backend for " + existingVol.getSanVolumeId()); } else { LOG.debug("Found database record but resource does not exist on backend. Deleting database record for " + volumeId); Entities.delete(existingVol); tran.commit(); } } catch (NoSuchElementException ex) { } catch (VolumeAlreadyExistsException ex) { throw ex; } catch (Exception ex) { throw new EucalyptusCloudException(ex); } try { Transactions.save(volumeInfo.withSanVolumeId(sanVolumeId).withSize(size)); } catch (Exception ex) { LOG.warn("Failed to persist database record for " + volumeId, ex); throw new EucalyptusCloudException("Failed to persist database record for " + volumeId, ex); } LOG.info("Creating " + sanVolumeId + " on backend"); String iqn = connectionManager.createVolume(sanVolumeId, size); if (iqn != null) { try (TransactionResource tran = Entities.transactionFor(SANVolumeInfo.class)) { SANVolumeInfo existingVol = Entities.uniqueResult(volumeInfo); existingVol.setIqn(iqn); tran.commit(); } catch (Exception ex) { LOG.warn("Failed to update database record with IQN post creation for " + volumeId); throw new EucalyptusCloudException("Failed to update database record with IQN post creation for " + volumeId, ex); } } else { LOG.warn("Invalid IQN from backend for " + sanVolumeId); throw new EucalyptusCloudException("Failed to create " + volumeId + " due to invalid IQN from backend for " + sanVolumeId); } } }
SANManager implements LogicalStorageManager { public void createVolume(String volumeId, int size) throws EucalyptusCloudException { String sanVolumeId = resourceIdOnSan(volumeId); SANVolumeInfo volumeInfo = new SANVolumeInfo(volumeId); try (TransactionResource tran = Entities.transactionFor(SANVolumeInfo.class)) { SANVolumeInfo existingVol = Entities.uniqueResult(volumeInfo); LOG.info("Checking for " + existingVol.getSanVolumeId() + " on backend"); if (connectionManager.volumeExists(existingVol.getSanVolumeId(), existingVol.getIqn())) { throw new VolumeAlreadyExistsException("Existing resource found on backend for " + existingVol.getSanVolumeId()); } else { LOG.debug("Found database record but resource does not exist on backend. Deleting database record for " + volumeId); Entities.delete(existingVol); tran.commit(); } } catch (NoSuchElementException ex) { } catch (VolumeAlreadyExistsException ex) { throw ex; } catch (Exception ex) { throw new EucalyptusCloudException(ex); } try { Transactions.save(volumeInfo.withSanVolumeId(sanVolumeId).withSize(size)); } catch (Exception ex) { LOG.warn("Failed to persist database record for " + volumeId, ex); throw new EucalyptusCloudException("Failed to persist database record for " + volumeId, ex); } LOG.info("Creating " + sanVolumeId + " on backend"); String iqn = connectionManager.createVolume(sanVolumeId, size); if (iqn != null) { try (TransactionResource tran = Entities.transactionFor(SANVolumeInfo.class)) { SANVolumeInfo existingVol = Entities.uniqueResult(volumeInfo); existingVol.setIqn(iqn); tran.commit(); } catch (Exception ex) { LOG.warn("Failed to update database record with IQN post creation for " + volumeId); throw new EucalyptusCloudException("Failed to update database record with IQN post creation for " + volumeId, ex); } } else { LOG.warn("Invalid IQN from backend for " + sanVolumeId); throw new EucalyptusCloudException("Failed to create " + volumeId + " due to invalid IQN from backend for " + sanVolumeId); } } SANManager();   SANManager(SANProvider connectionManager); }
SANManager implements LogicalStorageManager { public void createVolume(String volumeId, int size) throws EucalyptusCloudException { String sanVolumeId = resourceIdOnSan(volumeId); SANVolumeInfo volumeInfo = new SANVolumeInfo(volumeId); try (TransactionResource tran = Entities.transactionFor(SANVolumeInfo.class)) { SANVolumeInfo existingVol = Entities.uniqueResult(volumeInfo); LOG.info("Checking for " + existingVol.getSanVolumeId() + " on backend"); if (connectionManager.volumeExists(existingVol.getSanVolumeId(), existingVol.getIqn())) { throw new VolumeAlreadyExistsException("Existing resource found on backend for " + existingVol.getSanVolumeId()); } else { LOG.debug("Found database record but resource does not exist on backend. Deleting database record for " + volumeId); Entities.delete(existingVol); tran.commit(); } } catch (NoSuchElementException ex) { } catch (VolumeAlreadyExistsException ex) { throw ex; } catch (Exception ex) { throw new EucalyptusCloudException(ex); } try { Transactions.save(volumeInfo.withSanVolumeId(sanVolumeId).withSize(size)); } catch (Exception ex) { LOG.warn("Failed to persist database record for " + volumeId, ex); throw new EucalyptusCloudException("Failed to persist database record for " + volumeId, ex); } LOG.info("Creating " + sanVolumeId + " on backend"); String iqn = connectionManager.createVolume(sanVolumeId, size); if (iqn != null) { try (TransactionResource tran = Entities.transactionFor(SANVolumeInfo.class)) { SANVolumeInfo existingVol = Entities.uniqueResult(volumeInfo); existingVol.setIqn(iqn); tran.commit(); } catch (Exception ex) { LOG.warn("Failed to update database record with IQN post creation for " + volumeId); throw new EucalyptusCloudException("Failed to update database record with IQN post creation for " + volumeId, ex); } } else { LOG.warn("Invalid IQN from backend for " + sanVolumeId); throw new EucalyptusCloudException("Failed to create " + volumeId + " due to invalid IQN from backend for " + sanVolumeId); } } SANManager();   SANManager(SANProvider connectionManager); static LogicalStorageManager getInstance(); void addSnapshot(String snapshotId); void checkPreconditions(); @Override void cleanSnapshot(String snapshotId, String snapshotPointId); void cleanVolume(String volumeId); void configure(); StorageResource createSnapshot(String volumeId, String snapshotId, String snapshotPointId, Boolean shouldTransferSnapshots); void createSnapshot(String volumeId, String snapshotId, String snapshotPointId); void createVolume(String volumeId, int size); int createVolume(String volumeId, String snapshotId, int size); void cloneVolume(String volumeId, String parentVolumeId); @Override void deleteSnapshot(String snapshotId, String snapshotPointId); void deleteVolume(String volumeId); int getSnapshotSize(String snapshotId); String getVolumeConnectionString(String volumeId); void initialize(); void loadSnapshots(List<String> snapshotSet, List<String> snapshotFileNames); List<String> prepareForTransfer(String snapshotId); void reload(); void startupChecks(); void finishVolume(String snapshotId); StorageResourceWithCallback prepSnapshotForDownload(final String snapshotId, int sizeExpected, long actualSizeInMB); ArrayList<ComponentProperty> getStorageProps(); void setStorageProps(ArrayList<ComponentProperty> storageProps); String getStorageRootDirectory(); String getVolumePath(String volumeId); void importVolume(String volumeId, String volumePath, int size); String getSnapshotPath(String snapshotId); void importSnapshot(String snapshotId, String volumeId, String snapPath, int size); String exportVolume(String volumeId, String nodeIqn); void unexportVolumeFromAll(String volumeId); void unexportVolume(String volumeId, String nodeIqn); void checkReady(); void stop(); void disable(); void enable(); boolean getFromBackend(String snapshotId, int size); void checkVolume(String volumeId); List<CheckerTask> getCheckers(); String createSnapshotPoint(String parentVolumeId, String volumeId); void deleteSnapshotPoint(String parentVolumeId, String volumeId, String snapshotPointId); @Override boolean supportsIncrementalSnapshots(); @Override StorageResourceWithCallback prepIncrementalSnapshotForUpload(String volumeId, String snapshotId, String snapPointId, String prevSnapshotId,
      String prevSnapPointId); @Override StorageResource prepSnapshotForUpload(String volumeId, String snapshotId, String snapPointId); @Override StorageResourceWithCallback prepSnapshotBaseForRestore(final String snapshotId, final int size, final String snapshotPointId); @Override void restoreSnapshotDelta(String currentSnapId, String prevSnapId, String baseId, StorageResource sr); @Override void completeSnapshotRestorationFromDeltas(String snapshotId); @Override T executeCallback(Function<F, T> callback, F input); }
SANManager implements LogicalStorageManager { public void createVolume(String volumeId, int size) throws EucalyptusCloudException { String sanVolumeId = resourceIdOnSan(volumeId); SANVolumeInfo volumeInfo = new SANVolumeInfo(volumeId); try (TransactionResource tran = Entities.transactionFor(SANVolumeInfo.class)) { SANVolumeInfo existingVol = Entities.uniqueResult(volumeInfo); LOG.info("Checking for " + existingVol.getSanVolumeId() + " on backend"); if (connectionManager.volumeExists(existingVol.getSanVolumeId(), existingVol.getIqn())) { throw new VolumeAlreadyExistsException("Existing resource found on backend for " + existingVol.getSanVolumeId()); } else { LOG.debug("Found database record but resource does not exist on backend. Deleting database record for " + volumeId); Entities.delete(existingVol); tran.commit(); } } catch (NoSuchElementException ex) { } catch (VolumeAlreadyExistsException ex) { throw ex; } catch (Exception ex) { throw new EucalyptusCloudException(ex); } try { Transactions.save(volumeInfo.withSanVolumeId(sanVolumeId).withSize(size)); } catch (Exception ex) { LOG.warn("Failed to persist database record for " + volumeId, ex); throw new EucalyptusCloudException("Failed to persist database record for " + volumeId, ex); } LOG.info("Creating " + sanVolumeId + " on backend"); String iqn = connectionManager.createVolume(sanVolumeId, size); if (iqn != null) { try (TransactionResource tran = Entities.transactionFor(SANVolumeInfo.class)) { SANVolumeInfo existingVol = Entities.uniqueResult(volumeInfo); existingVol.setIqn(iqn); tran.commit(); } catch (Exception ex) { LOG.warn("Failed to update database record with IQN post creation for " + volumeId); throw new EucalyptusCloudException("Failed to update database record with IQN post creation for " + volumeId, ex); } } else { LOG.warn("Invalid IQN from backend for " + sanVolumeId); throw new EucalyptusCloudException("Failed to create " + volumeId + " due to invalid IQN from backend for " + sanVolumeId); } } SANManager();   SANManager(SANProvider connectionManager); static LogicalStorageManager getInstance(); void addSnapshot(String snapshotId); void checkPreconditions(); @Override void cleanSnapshot(String snapshotId, String snapshotPointId); void cleanVolume(String volumeId); void configure(); StorageResource createSnapshot(String volumeId, String snapshotId, String snapshotPointId, Boolean shouldTransferSnapshots); void createSnapshot(String volumeId, String snapshotId, String snapshotPointId); void createVolume(String volumeId, int size); int createVolume(String volumeId, String snapshotId, int size); void cloneVolume(String volumeId, String parentVolumeId); @Override void deleteSnapshot(String snapshotId, String snapshotPointId); void deleteVolume(String volumeId); int getSnapshotSize(String snapshotId); String getVolumeConnectionString(String volumeId); void initialize(); void loadSnapshots(List<String> snapshotSet, List<String> snapshotFileNames); List<String> prepareForTransfer(String snapshotId); void reload(); void startupChecks(); void finishVolume(String snapshotId); StorageResourceWithCallback prepSnapshotForDownload(final String snapshotId, int sizeExpected, long actualSizeInMB); ArrayList<ComponentProperty> getStorageProps(); void setStorageProps(ArrayList<ComponentProperty> storageProps); String getStorageRootDirectory(); String getVolumePath(String volumeId); void importVolume(String volumeId, String volumePath, int size); String getSnapshotPath(String snapshotId); void importSnapshot(String snapshotId, String volumeId, String snapPath, int size); String exportVolume(String volumeId, String nodeIqn); void unexportVolumeFromAll(String volumeId); void unexportVolume(String volumeId, String nodeIqn); void checkReady(); void stop(); void disable(); void enable(); boolean getFromBackend(String snapshotId, int size); void checkVolume(String volumeId); List<CheckerTask> getCheckers(); String createSnapshotPoint(String parentVolumeId, String volumeId); void deleteSnapshotPoint(String parentVolumeId, String volumeId, String snapshotPointId); @Override boolean supportsIncrementalSnapshots(); @Override StorageResourceWithCallback prepIncrementalSnapshotForUpload(String volumeId, String snapshotId, String snapPointId, String prevSnapshotId,
      String prevSnapPointId); @Override StorageResource prepSnapshotForUpload(String volumeId, String snapshotId, String snapPointId); @Override StorageResourceWithCallback prepSnapshotBaseForRestore(final String snapshotId, final int size, final String snapshotPointId); @Override void restoreSnapshotDelta(String currentSnapId, String prevSnapId, String baseId, StorageResource sr); @Override void completeSnapshotRestorationFromDeltas(String snapshotId); @Override T executeCallback(Function<F, T> callback, F input);  }