diff --git a/plugins/storage/volume/solidfire/src/org/apache/cloudstack/storage/datastore/driver/SolidFirePrimaryDataStoreDriver.java b/plugins/storage/volume/solidfire/src/org/apache/cloudstack/storage/datastore/driver/SolidFirePrimaryDataStoreDriver.java index 124b1172b68..c06a72895ad 100644 --- a/plugins/storage/volume/solidfire/src/org/apache/cloudstack/storage/datastore/driver/SolidFirePrimaryDataStoreDriver.java +++ b/plugins/storage/volume/solidfire/src/org/apache/cloudstack/storage/datastore/driver/SolidFirePrimaryDataStoreDriver.java @@ -195,10 +195,7 @@ public class SolidFirePrimaryDataStoreDriver implements PrimaryDataStoreDriver { return (long)(maxIops * fClusterDefaultBurstIopsPercentOfMaxIops); } - private SolidFireUtil.SolidFireVolume createSolidFireVolume(SolidFireUtil.SolidFireConnection sfConnection, VolumeInfo volumeInfo) { - AccountDetailVO accountDetail = _accountDetailsDao.findDetail(volumeInfo.getAccountId(), SolidFireUtil.ACCOUNT_ID); - long sfAccountId = Long.parseLong(accountDetail.getValue()); - + private SolidFireUtil.SolidFireVolume createSolidFireVolume(SolidFireUtil.SolidFireConnection sfConnection, VolumeInfo volumeInfo, long sfAccountId) { long storagePoolId = volumeInfo.getDataStore().getId(); final Iops iops; @@ -298,15 +295,26 @@ public class SolidFirePrimaryDataStoreDriver implements PrimaryDataStoreDriver { String sfAccountName = SolidFireUtil.getSolidFireAccountName(account.getUuid(), account.getAccountId()); long storagePoolId = dataStore.getId(); + SolidFireUtil.SolidFireConnection sfConnection = SolidFireUtil.getSolidFireConnection(storagePoolId, _storagePoolDetailsDao); - if (SolidFireUtil.getSolidFireAccount(sfConnection, sfAccountName) == null) { - SolidFireUtil.SolidFireAccount sfAccount = createSolidFireAccount(sfConnection, sfAccountName); + AccountDetailVO accountDetail = SolidFireUtil.getAccountDetail(volumeInfo.getAccountId(), storagePoolId, _accountDetailsDao); - SolidFireUtil.updateCsDbWithSolidFireAccountInfo(account.getId(), sfAccount, _accountDetailsDao); + if (accountDetail == null || accountDetail.getValue() == null) { + SolidFireUtil.SolidFireAccount sfAccount = SolidFireUtil.getSolidFireAccount(sfConnection, sfAccountName); + + if (sfAccount == null) { + sfAccount = createSolidFireAccount(sfConnection, sfAccountName); + } + + SolidFireUtil.updateCsDbWithSolidFireAccountInfo(account.getId(), sfAccount, storagePoolId, _accountDetailsDao); + + accountDetail = SolidFireUtil.getAccountDetail(volumeInfo.getAccountId(), storagePoolId, _accountDetailsDao); } - SolidFireUtil.SolidFireVolume sfVolume = createSolidFireVolume(sfConnection, volumeInfo); + long sfAccountId = Long.parseLong(accountDetail.getValue()); + + SolidFireUtil.SolidFireVolume sfVolume = createSolidFireVolume(sfConnection, volumeInfo, sfAccountId); iqn = sfVolume.getIqn(); diff --git a/plugins/storage/volume/solidfire/src/org/apache/cloudstack/storage/datastore/lifecycle/SolidFireSharedPrimaryDataStoreLifeCycle.java b/plugins/storage/volume/solidfire/src/org/apache/cloudstack/storage/datastore/lifecycle/SolidFireSharedPrimaryDataStoreLifeCycle.java index b03634b8fcf..5065822673c 100644 --- a/plugins/storage/volume/solidfire/src/org/apache/cloudstack/storage/datastore/lifecycle/SolidFireSharedPrimaryDataStoreLifeCycle.java +++ b/plugins/storage/volume/solidfire/src/org/apache/cloudstack/storage/datastore/lifecycle/SolidFireSharedPrimaryDataStoreLifeCycle.java @@ -219,7 +219,9 @@ public class SolidFireSharedPrimaryDataStoreLifeCycle implements PrimaryDataStor SolidFireUtil.SolidFireConnection sfConnection = new SolidFireUtil.SolidFireConnection(managementVip, managementPort, clusterAdminUsername, clusterAdminPassword); - SolidFireUtil.SolidFireVolume sfVolume = createSolidFireVolume(sfConnection, storagePoolName, capacityBytes, lMinIops, lMaxIops, lBurstIops); + SolidFireCreateVolume sfCreateVolume = createSolidFireVolume(sfConnection, storagePoolName, capacityBytes, lMinIops, lMaxIops, lBurstIops); + + SolidFireUtil.SolidFireVolume sfVolume = sfCreateVolume.getVolume(); String iqn = sfVolume.getIqn(); @@ -255,6 +257,11 @@ public class SolidFireSharedPrimaryDataStoreLifeCycle implements PrimaryDataStor List hosts = _hostDao.findByClusterId(clusterId); SolidFireUtil.placeVolumeInVolumeAccessGroup(sfConnection, sfVolume.getId(), dataStore.getId(), hosts, _clusterDetailsDao); + + SolidFireUtil.SolidFireAccount sfAccount = sfCreateVolume.getAccount(); + Account csAccount = CallContext.current().getCallingAccount(); + + SolidFireUtil.updateCsDbWithSolidFireAccountInfo(csAccount.getId(), sfAccount, dataStore.getId(), _accountDetailsDao); } catch (Exception ex) { _primaryDataStoreDao.expunge(dataStore.getId()); @@ -286,7 +293,25 @@ public class SolidFireSharedPrimaryDataStoreLifeCycle implements PrimaryDataStor throw new CloudRuntimeException("The 'hypervisor' parameter must be '" + HypervisorType.XenServer + "' or '" + HypervisorType.VMware + "'."); } - private SolidFireUtil.SolidFireVolume createSolidFireVolume(SolidFireUtil.SolidFireConnection sfConnection, + private class SolidFireCreateVolume { + private final SolidFireUtil.SolidFireVolume _sfVolume; + private final SolidFireUtil.SolidFireAccount _sfAccount; + + public SolidFireCreateVolume(SolidFireUtil.SolidFireVolume sfVolume, SolidFireUtil.SolidFireAccount sfAccount) { + _sfVolume = sfVolume; + _sfAccount = sfAccount; + } + + public SolidFireUtil.SolidFireVolume getVolume() { + return _sfVolume; + } + + public SolidFireUtil.SolidFireAccount getAccount() { + return _sfAccount; + } + } + + private SolidFireCreateVolume createSolidFireVolume(SolidFireUtil.SolidFireConnection sfConnection, String volumeName, long volumeSize, long minIops, long maxIops, long burstIops) { try { Account csAccount = CallContext.current().getCallingAccount(); @@ -301,15 +326,13 @@ public class SolidFireSharedPrimaryDataStoreLifeCycle implements PrimaryDataStor long accountNumber = SolidFireUtil.createSolidFireAccount(sfConnection, sfAccountName); sfAccount = SolidFireUtil.getSolidFireAccountById(sfConnection, accountNumber); - - SolidFireUtil.updateCsDbWithSolidFireAccountInfo(csAccountId, sfAccount, _accountDetailsDao); } long sfVolumeId = SolidFireUtil.createSolidFireVolume(sfConnection, SolidFireUtil.getSolidFireVolumeName(volumeName), sfAccount.getId(), volumeSize, true, null, minIops, maxIops, burstIops); SolidFireUtil.SolidFireVolume sfVolume = SolidFireUtil.getSolidFireVolume(sfConnection, sfVolumeId); - return sfVolume; + return new SolidFireCreateVolume(sfVolume, sfAccount); } catch (Throwable e) { throw new CloudRuntimeException("Failed to create a SolidFire volume: " + e.toString()); } diff --git a/plugins/storage/volume/solidfire/src/org/apache/cloudstack/storage/datastore/util/SolidFireUtil.java b/plugins/storage/volume/solidfire/src/org/apache/cloudstack/storage/datastore/util/SolidFireUtil.java index 3f35d71e207..7c09d854939 100644 --- a/plugins/storage/volume/solidfire/src/org/apache/cloudstack/storage/datastore/util/SolidFireUtil.java +++ b/plugins/storage/volume/solidfire/src/org/apache/cloudstack/storage/datastore/util/SolidFireUtil.java @@ -187,13 +187,14 @@ public class SolidFireUtil { } public static void updateCsDbWithSolidFireAccountInfo(long csAccountId, SolidFireUtil.SolidFireAccount sfAccount, - AccountDetailsDao accountDetailsDao) { + long storagePoolId, AccountDetailsDao accountDetailsDao) { AccountDetailVO accountDetail = new AccountDetailVO(csAccountId, - SolidFireUtil.ACCOUNT_ID, + SolidFireUtil.getAccountKey(storagePoolId), String.valueOf(sfAccount.getId())); accountDetailsDao.persist(accountDetail); + /* accountDetail = new AccountDetailVO(csAccountId, SolidFireUtil.CHAP_INITIATOR_USERNAME, String.valueOf(sfAccount.getName())); @@ -217,6 +218,7 @@ public class SolidFireUtil { sfAccount.getTargetSecret()); accountDetailsDao.persist(accountDetail); + */ } public static SolidFireAccount getSolidFireAccount(SolidFireConnection sfConnection, String sfAccountName) { @@ -358,6 +360,20 @@ public class SolidFireUtil { return "sfVolumeAccessGroup_" + storagePoolId; } + private static String getAccountKey(long storagePoolId) { + return SolidFireUtil.ACCOUNT_ID + "_" + storagePoolId; + } + + public static AccountDetailVO getAccountDetail(long csAccountId, long storagePoolId, AccountDetailsDao accountDetailsDao) { + AccountDetailVO accountDetail = accountDetailsDao.findDetail(csAccountId, SolidFireUtil.getAccountKey(storagePoolId)); + + if (accountDetail == null || accountDetail.getValue() == null) { + accountDetail = accountDetailsDao.findDetail(csAccountId, SolidFireUtil.ACCOUNT_ID); + } + + return accountDetail; + } + public static String[] getIqnsFromHosts(List hosts) { if (hosts == null || hosts.size() == 0) { throw new CloudRuntimeException("There do not appear to be any hosts in this cluster.");