Skip to content

Commit 2efe61d

Browse files
author
Mike Tutkowski
committed
CLOUDSTACK-4810: Enable hypervisor snapshots for CloudStack-managed storage (for XenServer and VMware)
1 parent ce9760f commit 2efe61d

2 files changed

Lines changed: 141 additions & 21 deletions

File tree

‎plugins/storage/volume/solidfire/src/org/apache/cloudstack/storage/datastore/driver/SolidfirePrimaryDataStoreDriver.java‎

Lines changed: 95 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -133,18 +133,15 @@ private SolidFireConnection getSolidFireConnection(long storagePoolId) {
133133
return new SolidFireConnection(mVip, mPort, clusterAdminUsername, clusterAdminPassword);
134134
}
135135

136-
private SolidFireUtil.SolidFireAccount createSolidFireAccount(String sfAccountName,
137-
SolidFireConnection sfConnection) {
136+
private SolidFireUtil.SolidFireAccount createSolidFireAccount(String sfAccountName, SolidFireConnection sfConnection) {
138137
String mVip = sfConnection.getManagementVip();
139138
int mPort = sfConnection.getManagementPort();
140139
String clusterAdminUsername = sfConnection.getClusterAdminUsername();
141140
String clusterAdminPassword = sfConnection.getClusterAdminPassword();
142141

143-
long accountNumber = SolidFireUtil.createSolidFireAccount(mVip, mPort,
144-
clusterAdminUsername, clusterAdminPassword, sfAccountName);
142+
long accountNumber = SolidFireUtil.createSolidFireAccount(mVip, mPort, clusterAdminUsername, clusterAdminPassword, sfAccountName);
145143

146-
return SolidFireUtil.getSolidFireAccountById(mVip, mPort,
147-
clusterAdminUsername, clusterAdminPassword, accountNumber);
144+
return SolidFireUtil.getSolidFireAccountById(mVip, mPort, clusterAdminUsername, clusterAdminPassword, accountNumber);
148145
}
149146

150147
private void updateCsDbWithAccountInfo(long csAccountId, SolidFireUtil.SolidFireAccount sfAccount) {
@@ -185,8 +182,7 @@ private class ChapInfoImpl implements ChapInfo {
185182
private final String _targetUsername;
186183
private final String _targetSecret;
187184

188-
public ChapInfoImpl(String initiatorUsername, String initiatorSecret,
189-
String targetUsername, String targetSecret) {
185+
public ChapInfoImpl(String initiatorUsername, String initiatorSecret, String targetUsername, String targetSecret) {
190186
_initiatorUsername = initiatorUsername;
191187
_initiatorSecret = initiatorSecret;
192188
_targetUsername = targetUsername;
@@ -269,16 +265,39 @@ public boolean connectVolumeToHost(VolumeInfo volumeInfo, Host host, DataStore d
269265
SolidFireUtil.SolidFireVag sfVag = SolidFireUtil.getSolidFireVag(sfConnection.getManagementVip(), sfConnection.getManagementPort(),
270266
sfConnection.getClusterAdminUsername(), sfConnection.getClusterAdminPassword(), Long.parseLong(vagId));
271267

268+
String[] hostIqns = getNewHostIqns(sfVag.getInitiators(), getIqnsFromHosts(hosts));
272269
long[] volumeIds = getNewVolumeIds(sfVag.getVolumeIds(), sfVolumeId, true);
273270

274271
SolidFireUtil.modifySolidFireVag(sfConnection.getManagementVip(), sfConnection.getManagementPort(),
275272
sfConnection.getClusterAdminUsername(), sfConnection.getClusterAdminPassword(), sfVag.getId(),
276-
getIqnsFromHosts(hosts), volumeIds);
273+
hostIqns, volumeIds);
277274
}
278275
else {
279-
long lVagId = SolidFireUtil.createSolidFireVag(sfConnection.getManagementVip(), sfConnection.getManagementPort(),
280-
sfConnection.getClusterAdminUsername(), sfConnection.getClusterAdminPassword(), "CloudStack-" + UUID.randomUUID().toString(),
281-
getIqnsFromHosts(hosts), new long[] { sfVolumeId });
276+
long lVagId;
277+
278+
try {
279+
lVagId = SolidFireUtil.createSolidFireVag(sfConnection.getManagementVip(), sfConnection.getManagementPort(),
280+
sfConnection.getClusterAdminUsername(), sfConnection.getClusterAdminPassword(), "CloudStack-" + UUID.randomUUID().toString(),
281+
getIqnsFromHosts(hosts), new long[] { sfVolumeId });
282+
}
283+
catch (Exception ex) {
284+
String iqnInVagAlready = "Exceeded maximum number of Volume Access Groups per initiator";
285+
286+
if (!ex.getMessage().contains(iqnInVagAlready)) {
287+
throw new CloudRuntimeException(ex.getMessage());
288+
}
289+
290+
// getCompatibleVag throws an exception if an existing VAG can't be located
291+
SolidFireUtil.SolidFireVag sfVag = getCompatibleVag(hosts, sfConnection);
292+
293+
long[] volumeIds = getNewVolumeIds(sfVag.getVolumeIds(), sfVolumeId, true);
294+
295+
SolidFireUtil.modifySolidFireVag(sfConnection.getManagementVip(), sfConnection.getManagementPort(),
296+
sfConnection.getClusterAdminUsername(), sfConnection.getClusterAdminPassword(), sfVag.getId(),
297+
sfVag.getInitiators(), volumeIds);
298+
299+
lVagId = sfVag.getId();
300+
}
282301

283302
clusterDetail = new ClusterDetailsVO(clusterId, getVagKey(storagePoolId), String.valueOf(lVagId));
284303

@@ -288,6 +307,48 @@ public boolean connectVolumeToHost(VolumeInfo volumeInfo, Host host, DataStore d
288307
return true;
289308
}
290309

310+
// this method takes in a collection of hosts and tries to find an existing VAG that has all three of them in it
311+
// if successful, the VAG is returned; else, a CloudRuntimeException is thrown and this issue should be corrected by an admin
312+
private SolidFireUtil.SolidFireVag getCompatibleVag(List<HostVO> hosts, SolidFireConnection sfConnection) {
313+
List<SolidFireUtil.SolidFireVag> sfVags = SolidFireUtil.getAllSolidFireVags(sfConnection.getManagementVip(), sfConnection.getManagementPort(),
314+
sfConnection.getClusterAdminUsername(), sfConnection.getClusterAdminPassword());
315+
316+
if (sfVags != null) {
317+
List<String> hostIqns = new ArrayList<String>();
318+
319+
// where the method we're in is called, hosts should not be null
320+
for (HostVO host : hosts) {
321+
// where the method we're in is called, host.getStorageUrl() should not be null (it actually should start with "iqn")
322+
hostIqns.add(host.getStorageUrl().toLowerCase());
323+
}
324+
325+
for (SolidFireUtil.SolidFireVag sfVag : sfVags) {
326+
List<String> lstInitiators = getStringArrayAsLowerCaseStringList(sfVag.getInitiators());
327+
328+
// lstInitiators should not be returned from getStringArrayAsLowerCaseStringList as null
329+
if (lstInitiators.containsAll(hostIqns)) {
330+
return sfVag;
331+
}
332+
}
333+
}
334+
335+
throw new CloudRuntimeException("Unable to locate the appropriate SolidFire Volume Access Group");
336+
}
337+
338+
private List<String> getStringArrayAsLowerCaseStringList(String[] aString) {
339+
List<String> lstLowerCaseString = new ArrayList<String>();
340+
341+
if (aString != null) {
342+
for (String str : aString) {
343+
if (str != null) {
344+
lstLowerCaseString.add(str.toLowerCase());
345+
}
346+
}
347+
}
348+
349+
return lstLowerCaseString;
350+
}
351+
291352
// get the VAG associated with volumeInfo's cluster, if any (ListVolumeAccessGroups) // might not exist if using CHAP
292353
// if the VAG exists
293354
// remove the ID of volumeInfo from the VAG (ModifyVolumeAccessGroup)
@@ -314,11 +375,12 @@ public void disconnectVolumeFromHost(VolumeInfo volumeInfo, Host host, DataStore
314375
SolidFireUtil.SolidFireVag sfVag = SolidFireUtil.getSolidFireVag(sfConnection.getManagementVip(), sfConnection.getManagementPort(),
315376
sfConnection.getClusterAdminUsername(), sfConnection.getClusterAdminPassword(), Long.parseLong(vagId));
316377

378+
String[] hostIqns = getNewHostIqns(sfVag.getInitiators(), getIqnsFromHosts(hosts));
317379
long[] volumeIds = getNewVolumeIds(sfVag.getVolumeIds(), sfVolumeId, false);
318380

319381
SolidFireUtil.modifySolidFireVag(sfConnection.getManagementVip(), sfConnection.getManagementPort(),
320382
sfConnection.getClusterAdminUsername(), sfConnection.getClusterAdminPassword(), sfVag.getId(),
321-
getIqnsFromHosts(hosts), volumeIds);
383+
hostIqns, volumeIds);
322384
}
323385
}
324386

@@ -336,6 +398,26 @@ private boolean hostsSupport_iScsi(List<HostVO> hosts) {
336398
return true;
337399
}
338400

401+
private String[] getNewHostIqns(String[] currentIqns, String[] newIqns) {
402+
List<String> lstIqns = new ArrayList<String>();
403+
404+
if (currentIqns != null) {
405+
for (String currentIqn : currentIqns) {
406+
lstIqns.add(currentIqn);
407+
}
408+
}
409+
410+
if (newIqns != null) {
411+
for (String newIqn : newIqns) {
412+
if (!lstIqns.contains(newIqn)) {
413+
lstIqns.add(newIqn);
414+
}
415+
}
416+
}
417+
418+
return lstIqns.toArray(new String[0]);
419+
}
420+
339421
private long[] getNewVolumeIds(long[] volumeIds, long volumeIdToAddOrRemove, boolean add) {
340422
if (add) {
341423
return getNewVolumeIdsAdd(volumeIds, volumeIdToAddOrRemove);

‎plugins/storage/volume/solidfire/src/org/apache/cloudstack/storage/datastore/util/SolidFireUtil.java‎

Lines changed: 46 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -276,8 +276,7 @@ public boolean equals(Object obj) {
276276
}
277277
}
278278

279-
public static long createSolidFireAccount(String strSfMvip, int iSfPort, String strSfAdmin, String strSfPassword,
280-
String strAccountName)
279+
public static long createSolidFireAccount(String strSfMvip, int iSfPort, String strSfAdmin, String strSfPassword, String strAccountName)
281280
{
282281
final Gson gson = new GsonBuilder().create();
283282

@@ -294,8 +293,7 @@ public static long createSolidFireAccount(String strSfMvip, int iSfPort, String
294293
return accountAddResult.result.accountID;
295294
}
296295

297-
public static SolidFireAccount getSolidFireAccountById(String strSfMvip, int iSfPort, String strSfAdmin, String strSfPassword,
298-
long lSfAccountId)
296+
public static SolidFireAccount getSolidFireAccountById(String strSfMvip, int iSfPort, String strSfAdmin, String strSfPassword, long lSfAccountId)
299297
{
300298
final Gson gson = new GsonBuilder().create();
301299

@@ -316,8 +314,7 @@ public static SolidFireAccount getSolidFireAccountById(String strSfMvip, int iSf
316314
return new SolidFireAccount(lSfAccountId, strSfAccountName, strSfAccountInitiatorSecret, strSfAccountTargetSecret);
317315
}
318316

319-
public static SolidFireAccount getSolidFireAccountByName(String strSfMvip, int iSfPort, String strSfAdmin, String strSfPassword,
320-
String strSfAccountName)
317+
public static SolidFireAccount getSolidFireAccountByName(String strSfMvip, int iSfPort, String strSfAdmin, String strSfPassword, String strSfAccountName)
321318
{
322319
final Gson gson = new GsonBuilder().create();
323320

@@ -338,8 +335,7 @@ public static SolidFireAccount getSolidFireAccountByName(String strSfMvip, int i
338335
return new SolidFireAccount(lSfAccountId, strSfAccountName, strSfAccountInitiatorSecret, strSfAccountTargetSecret);
339336
}
340337

341-
public static void deleteSolidFireAccount(String strSfMvip, int iSfPort, String strSfAdmin, String strSfPassword,
342-
long lAccountId)
338+
public static void deleteSolidFireAccount(String strSfMvip, int iSfPort, String strSfAdmin, String strSfPassword, long lAccountId)
343339
{
344340
final Gson gson = new GsonBuilder().create();
345341

@@ -467,6 +463,33 @@ public static SolidFireVag getSolidFireVag(String strSfMvip, int iSfPort, String
467463
return new SolidFireVag(lVagId, vagIqns, vagVolumeIds);
468464
}
469465

466+
public static List<SolidFireVag> getAllSolidFireVags(String strSfMvip, int iSfPort, String strSfAdmin, String strSfPassword)
467+
{
468+
final Gson gson = new GsonBuilder().create();
469+
470+
AllVags allVags = new AllVags();
471+
472+
String strAllVagsJson = gson.toJson(allVags);
473+
474+
String strAllVagsGetResultJson = executeJsonRpc(strAllVagsJson, strSfMvip, iSfPort, strSfAdmin, strSfPassword);
475+
476+
VagGetResult allVagsGetResult = gson.fromJson(strAllVagsGetResultJson, VagGetResult.class);
477+
478+
verifyResult(allVagsGetResult.result, strAllVagsGetResultJson, gson);
479+
480+
List<SolidFireVag> lstSolidFireVags = new ArrayList<SolidFireVag>();
481+
482+
if (allVagsGetResult.result.volumeAccessGroups != null ) {
483+
for (VagGetResult.Result.Vag vag : allVagsGetResult.result.volumeAccessGroups) {
484+
SolidFireVag sfVag = new SolidFireVag(vag.volumeAccessGroupID, vag.initiators, vag.volumes);
485+
486+
lstSolidFireVags.add(sfVag);
487+
}
488+
}
489+
490+
return lstSolidFireVags;
491+
}
492+
470493
public static void deleteSolidFireVag(String strSfMvip, int iSfPort, String strSfAdmin, String strSfPassword, long lVagId)
471494
{
472495
final Gson gson = new GsonBuilder().create();
@@ -854,6 +877,21 @@ private VagToGetParams(final long lVagId)
854877
}
855878
}
856879

880+
@SuppressWarnings("unused")
881+
private static final class AllVags
882+
{
883+
private final String method = "ListVolumeAccessGroups";
884+
private final VagToGetParams params;
885+
886+
private AllVags()
887+
{
888+
params = new VagToGetParams();
889+
}
890+
891+
private static final class VagToGetParams
892+
{}
893+
}
894+
857895
@SuppressWarnings("unused")
858896
private static final class VagToDelete
859897
{

0 commit comments

Comments
 (0)