@Test public void allocateTarget_BasicTest() throws Exception { final String volId = "vol-0000"; final ISCSIVolumeInfo iscsiVolumeInfo = new ISCSIVolumeInfo(); iscsiVolumeInfo.setVolumeId(volId); final TGTService tgtService = context.mock(TGTService.class); final BlockStorageUtilSvc blockStorageUtilSvc = context.mock(BlockStorageUtilSvc.class); context.checking(new Expectations() { { oneOf(tgtService).targetExists(volId, 1, null, DirectStorageInfo.getStorageInfo().getTimeoutInMillis()); will(returnValue(Boolean.FALSE)); } }); ISCSIMetaInfo metaInfo = new ISCSIMetaInfo(StorageProperties.NAME); metaInfo.setStoreNumber(new Integer(1)); metaInfo.setTid(new Integer(1)); metaInfo.setStorePrefix("foo:"); metaInfo.setStoreUser("unittestuser0"); try (TransactionResource tran = Entities.transactionFor(ISCSIMetaInfo.class)) { metaInfo = Entities.persist(metaInfo); tran.commit(); } ISCSIManager iscsiManager = new ISCSIManager(tgtService, blockStorageUtilSvc); iscsiManager.allocateTarget(iscsiVolumeInfo); List<ISCSIMetaInfo> remaining; try (TransactionResource tran = Entities.transactionFor(ISCSIMetaInfo.class)) { remaining = Entities.query(new ISCSIMetaInfo()); tran.commit(); } assertTrue("expected to have a result set querying the eucalyptus_storage persistence context", remaining != null); ISCSIMetaInfo retrieved = remaining.get(0); assertTrue("expected store number to be 2 but was " + retrieved.getStoreNumber(), retrieved.getStoreNumber().intValue() == 2); assertTrue("expected tid to be 2", retrieved.getTid().intValue() == 2); String storeName = "foo:" + StorageProperties.NAME + ":store2"; assertTrue("expected iscsiVolumeInfo store name to be " + storeName, storeName.equals(iscsiVolumeInfo.getStoreName())); assertTrue("expected iscsiVolumeInfo store user to be unittestuser0 but was " + iscsiVolumeInfo.getStoreUser(), "unittestuser0".equals(iscsiVolumeInfo.getStoreUser())); assertTrue("expected iscsiVolumeInfo tid to be 1 and lun to be 1", iscsiVolumeInfo.getTid().intValue() == 1 && iscsiVolumeInfo.getLun().intValue() == 1); }
@Override public synchronized void allocateTarget(LVMVolumeInfo volumeInfo) throws EucalyptusCloudException { if (volumeInfo instanceof ISCSIVolumeInfo) { ISCSIVolumeInfo iscsiVolumeInfo = (ISCSIVolumeInfo) volumeInfo; LOG.debug("Allocate target: " + iscsiVolumeInfo); if (iscsiVolumeInfo.getTid() > -1) { LOG.info("Volume already associated with a tid: " + iscsiVolumeInfo.getTid()); return; } int tid = -1, storeNumber = -1; List<ISCSIMetaInfo> metaInfoList; try (TransactionResource tran = Entities.transactionFor(ISCSIMetaInfo.class)) { metaInfoList = Entities.query(new ISCSIMetaInfo(StorageProperties.NAME)); if (metaInfoList.size() > 0) { ISCSIMetaInfo foundMetaInfo = metaInfoList.get(0); storeNumber = foundMetaInfo.getStoreNumber(); tid = foundMetaInfo.getTid(); } tran.commit(); } int i = tid; Long timeout = DirectStorageInfo.getStorageInfo().getTimeoutInMillis(); do { if (!tgtService.targetExists(volumeInfo.getVolumeId(), i, null, timeout)) { tid = i; break; } LOG.debug("Target TID " + i + " already exists, trying the next one"); i = (i + 1) % Integer.MAX_VALUE; } while (i != tid); LOG.debug("Volume " + iscsiVolumeInfo.getVolumeId() + " Target allocation found tid: " + tid); if (tid > 0) { try (TransactionResource tran = Entities.transactionFor(ISCSIMetaInfo.class)) { metaInfoList = Entities.query(new ISCSIMetaInfo(StorageProperties.NAME)); if (metaInfoList.size() > 0) { ISCSIMetaInfo foundMetaInfo = metaInfoList.get(0); foundMetaInfo.setStoreNumber(++storeNumber); foundMetaInfo.setTid(tid + 1); iscsiVolumeInfo.setStoreName(foundMetaInfo.getStorePrefix() + StorageProperties.NAME + ":store" + storeNumber); iscsiVolumeInfo.setStoreUser(foundMetaInfo.getStoreUser()); iscsiVolumeInfo.setTid(tid); iscsiVolumeInfo.setLun(1); } tran.commit(); } } else { iscsiVolumeInfo.setTid(-1); LOG.fatal("Unable to allocate ISCSI target id for volume " + iscsiVolumeInfo.getVolumeId()); } } }
ISCSIManager implements StorageExportManager { @Override public synchronized void allocateTarget(LVMVolumeInfo volumeInfo) throws EucalyptusCloudException { if (volumeInfo instanceof ISCSIVolumeInfo) { ISCSIVolumeInfo iscsiVolumeInfo = (ISCSIVolumeInfo) volumeInfo; LOG.debug("Allocate target: " + iscsiVolumeInfo); if (iscsiVolumeInfo.getTid() > -1) { LOG.info("Volume already associated with a tid: " + iscsiVolumeInfo.getTid()); return; } int tid = -1, storeNumber = -1; List<ISCSIMetaInfo> metaInfoList; try (TransactionResource tran = Entities.transactionFor(ISCSIMetaInfo.class)) { metaInfoList = Entities.query(new ISCSIMetaInfo(StorageProperties.NAME)); if (metaInfoList.size() > 0) { ISCSIMetaInfo foundMetaInfo = metaInfoList.get(0); storeNumber = foundMetaInfo.getStoreNumber(); tid = foundMetaInfo.getTid(); } tran.commit(); } int i = tid; Long timeout = DirectStorageInfo.getStorageInfo().getTimeoutInMillis(); do { if (!tgtService.targetExists(volumeInfo.getVolumeId(), i, null, timeout)) { tid = i; break; } LOG.debug("Target TID " + i + " already exists, trying the next one"); i = (i + 1) % Integer.MAX_VALUE; } while (i != tid); LOG.debug("Volume " + iscsiVolumeInfo.getVolumeId() + " Target allocation found tid: " + tid); if (tid > 0) { try (TransactionResource tran = Entities.transactionFor(ISCSIMetaInfo.class)) { metaInfoList = Entities.query(new ISCSIMetaInfo(StorageProperties.NAME)); if (metaInfoList.size() > 0) { ISCSIMetaInfo foundMetaInfo = metaInfoList.get(0); foundMetaInfo.setStoreNumber(++storeNumber); foundMetaInfo.setTid(tid + 1); iscsiVolumeInfo.setStoreName(foundMetaInfo.getStorePrefix() + StorageProperties.NAME + ":store" + storeNumber); iscsiVolumeInfo.setStoreUser(foundMetaInfo.getStoreUser()); iscsiVolumeInfo.setTid(tid); iscsiVolumeInfo.setLun(1); } tran.commit(); } } else { iscsiVolumeInfo.setTid(-1); LOG.fatal("Unable to allocate ISCSI target id for volume " + iscsiVolumeInfo.getVolumeId()); } } } }
ISCSIManager implements StorageExportManager { @Override public synchronized void allocateTarget(LVMVolumeInfo volumeInfo) throws EucalyptusCloudException { if (volumeInfo instanceof ISCSIVolumeInfo) { ISCSIVolumeInfo iscsiVolumeInfo = (ISCSIVolumeInfo) volumeInfo; LOG.debug("Allocate target: " + iscsiVolumeInfo); if (iscsiVolumeInfo.getTid() > -1) { LOG.info("Volume already associated with a tid: " + iscsiVolumeInfo.getTid()); return; } int tid = -1, storeNumber = -1; List<ISCSIMetaInfo> metaInfoList; try (TransactionResource tran = Entities.transactionFor(ISCSIMetaInfo.class)) { metaInfoList = Entities.query(new ISCSIMetaInfo(StorageProperties.NAME)); if (metaInfoList.size() > 0) { ISCSIMetaInfo foundMetaInfo = metaInfoList.get(0); storeNumber = foundMetaInfo.getStoreNumber(); tid = foundMetaInfo.getTid(); } tran.commit(); } int i = tid; Long timeout = DirectStorageInfo.getStorageInfo().getTimeoutInMillis(); do { if (!tgtService.targetExists(volumeInfo.getVolumeId(), i, null, timeout)) { tid = i; break; } LOG.debug("Target TID " + i + " already exists, trying the next one"); i = (i + 1) % Integer.MAX_VALUE; } while (i != tid); LOG.debug("Volume " + iscsiVolumeInfo.getVolumeId() + " Target allocation found tid: " + tid); if (tid > 0) { try (TransactionResource tran = Entities.transactionFor(ISCSIMetaInfo.class)) { metaInfoList = Entities.query(new ISCSIMetaInfo(StorageProperties.NAME)); if (metaInfoList.size() > 0) { ISCSIMetaInfo foundMetaInfo = metaInfoList.get(0); foundMetaInfo.setStoreNumber(++storeNumber); foundMetaInfo.setTid(tid + 1); iscsiVolumeInfo.setStoreName(foundMetaInfo.getStorePrefix() + StorageProperties.NAME + ":store" + storeNumber); iscsiVolumeInfo.setStoreUser(foundMetaInfo.getStoreUser()); iscsiVolumeInfo.setTid(tid); iscsiVolumeInfo.setLun(1); } tran.commit(); } } else { iscsiVolumeInfo.setTid(-1); LOG.fatal("Unable to allocate ISCSI target id for volume " + iscsiVolumeInfo.getVolumeId()); } } } ISCSIManager();  ISCSIManager(TGTService tgtService, BlockStorageUtilSvc blockStorageUtilSvc); }
ISCSIManager implements StorageExportManager { @Override public synchronized void allocateTarget(LVMVolumeInfo volumeInfo) throws EucalyptusCloudException { if (volumeInfo instanceof ISCSIVolumeInfo) { ISCSIVolumeInfo iscsiVolumeInfo = (ISCSIVolumeInfo) volumeInfo; LOG.debug("Allocate target: " + iscsiVolumeInfo); if (iscsiVolumeInfo.getTid() > -1) { LOG.info("Volume already associated with a tid: " + iscsiVolumeInfo.getTid()); return; } int tid = -1, storeNumber = -1; List<ISCSIMetaInfo> metaInfoList; try (TransactionResource tran = Entities.transactionFor(ISCSIMetaInfo.class)) { metaInfoList = Entities.query(new ISCSIMetaInfo(StorageProperties.NAME)); if (metaInfoList.size() > 0) { ISCSIMetaInfo foundMetaInfo = metaInfoList.get(0); storeNumber = foundMetaInfo.getStoreNumber(); tid = foundMetaInfo.getTid(); } tran.commit(); } int i = tid; Long timeout = DirectStorageInfo.getStorageInfo().getTimeoutInMillis(); do { if (!tgtService.targetExists(volumeInfo.getVolumeId(), i, null, timeout)) { tid = i; break; } LOG.debug("Target TID " + i + " already exists, trying the next one"); i = (i + 1) % Integer.MAX_VALUE; } while (i != tid); LOG.debug("Volume " + iscsiVolumeInfo.getVolumeId() + " Target allocation found tid: " + tid); if (tid > 0) { try (TransactionResource tran = Entities.transactionFor(ISCSIMetaInfo.class)) { metaInfoList = Entities.query(new ISCSIMetaInfo(StorageProperties.NAME)); if (metaInfoList.size() > 0) { ISCSIMetaInfo foundMetaInfo = metaInfoList.get(0); foundMetaInfo.setStoreNumber(++storeNumber); foundMetaInfo.setTid(tid + 1); iscsiVolumeInfo.setStoreName(foundMetaInfo.getStorePrefix() + StorageProperties.NAME + ":store" + storeNumber); iscsiVolumeInfo.setStoreUser(foundMetaInfo.getStoreUser()); iscsiVolumeInfo.setTid(tid); iscsiVolumeInfo.setLun(1); } tran.commit(); } } else { iscsiVolumeInfo.setTid(-1); LOG.fatal("Unable to allocate ISCSI target id for volume " + iscsiVolumeInfo.getVolumeId()); } } } ISCSIManager();  ISCSIManager(TGTService tgtService, BlockStorageUtilSvc blockStorageUtilSvc); @Override void checkPreconditions(); @Override void check(); void addUser(String username, String password); void deleteUser(String username); void exportTarget(String volumeId, int tid, String name, int lun, String path, String user); void unexportTarget(String volumeId, int tid, int lun, String path); @Override void configure(); @Override synchronized void allocateTarget(LVMVolumeInfo volumeInfo); String getEncryptedPassword(); void cleanup(LVMVolumeInfo volumeInfo); @Override void stop(); @Override boolean isExported(LVMVolumeInfo volumeInfo); }
ISCSIManager implements StorageExportManager { @Override public synchronized void allocateTarget(LVMVolumeInfo volumeInfo) throws EucalyptusCloudException { if (volumeInfo instanceof ISCSIVolumeInfo) { ISCSIVolumeInfo iscsiVolumeInfo = (ISCSIVolumeInfo) volumeInfo; LOG.debug("Allocate target: " + iscsiVolumeInfo); if (iscsiVolumeInfo.getTid() > -1) { LOG.info("Volume already associated with a tid: " + iscsiVolumeInfo.getTid()); return; } int tid = -1, storeNumber = -1; List<ISCSIMetaInfo> metaInfoList; try (TransactionResource tran = Entities.transactionFor(ISCSIMetaInfo.class)) { metaInfoList = Entities.query(new ISCSIMetaInfo(StorageProperties.NAME)); if (metaInfoList.size() > 0) { ISCSIMetaInfo foundMetaInfo = metaInfoList.get(0); storeNumber = foundMetaInfo.getStoreNumber(); tid = foundMetaInfo.getTid(); } tran.commit(); } int i = tid; Long timeout = DirectStorageInfo.getStorageInfo().getTimeoutInMillis(); do { if (!tgtService.targetExists(volumeInfo.getVolumeId(), i, null, timeout)) { tid = i; break; } LOG.debug("Target TID " + i + " already exists, trying the next one"); i = (i + 1) % Integer.MAX_VALUE; } while (i != tid); LOG.debug("Volume " + iscsiVolumeInfo.getVolumeId() + " Target allocation found tid: " + tid); if (tid > 0) { try (TransactionResource tran = Entities.transactionFor(ISCSIMetaInfo.class)) { metaInfoList = Entities.query(new ISCSIMetaInfo(StorageProperties.NAME)); if (metaInfoList.size() > 0) { ISCSIMetaInfo foundMetaInfo = metaInfoList.get(0); foundMetaInfo.setStoreNumber(++storeNumber); foundMetaInfo.setTid(tid + 1); iscsiVolumeInfo.setStoreName(foundMetaInfo.getStorePrefix() + StorageProperties.NAME + ":store" + storeNumber); iscsiVolumeInfo.setStoreUser(foundMetaInfo.getStoreUser()); iscsiVolumeInfo.setTid(tid); iscsiVolumeInfo.setLun(1); } tran.commit(); } } else { iscsiVolumeInfo.setTid(-1); LOG.fatal("Unable to allocate ISCSI target id for volume " + iscsiVolumeInfo.getVolumeId()); } } } ISCSIManager();  ISCSIManager(TGTService tgtService, BlockStorageUtilSvc blockStorageUtilSvc); @Override void checkPreconditions(); @Override void check(); void addUser(String username, String password); void deleteUser(String username); void exportTarget(String volumeId, int tid, String name, int lun, String path, String user); void unexportTarget(String volumeId, int tid, int lun, String path); @Override void configure(); @Override synchronized void allocateTarget(LVMVolumeInfo volumeInfo); String getEncryptedPassword(); void cleanup(LVMVolumeInfo volumeInfo); @Override void stop(); @Override boolean isExported(LVMVolumeInfo volumeInfo);  }