Skip to content

Commit f59fd55

Browse files
[PowerFlex/ScaleIO] Added wait time after SDC service start/restart/stop, and retries to fetch SDC id/guid
1 parent ba0204f commit f59fd55

File tree

4 files changed

+69
-20
lines changed

4 files changed

+69
-20
lines changed

plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/ScaleIOStorageAdaptor.java

Lines changed: 39 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import org.apache.cloudstack.utils.qemu.QemuImgException;
3838
import org.apache.cloudstack.utils.qemu.QemuImgFile;
3939
import org.apache.cloudstack.utils.qemu.QemuObject;
40+
import org.apache.commons.collections.MapUtils;
4041
import org.apache.commons.io.filefilter.WildcardFileFilter;
4142
import org.apache.logging.log4j.Logger;
4243
import org.apache.logging.log4j.LogManager;
@@ -581,14 +582,23 @@ public Ternary<Boolean, Map<String, String>, String> prepareStorageClient(Storag
581582
}
582583

583584
if (!ScaleIOUtil.isSDCServiceActive()) {
585+
logger.debug("SDC service is not active on host, starting it");
584586
if (!ScaleIOUtil.startSDCService()) {
585587
return new Ternary<>(false, null, "Couldn't start SDC service on host");
586588
}
587-
} else if (!ScaleIOUtil.restartSDCService()) {
588-
return new Ternary<>(false, null, "Couldn't restart SDC service on host");
589+
} else {
590+
logger.debug("SDC service is active on host, re-starting it");
591+
if (!ScaleIOUtil.restartSDCService()) {
592+
return new Ternary<>(false, null, "Couldn't restart SDC service on host");
593+
}
594+
}
595+
596+
Map<String, String> sdcDetails = getSDCDetails(details);
597+
if (MapUtils.isEmpty(sdcDetails)) {
598+
return new Ternary<>(false, null, "Couldn't get the SDC details on the host");
589599
}
590600

591-
return new Ternary<>( true, getSDCDetails(details), "Prepared client successfully");
601+
return new Ternary<>( true, sdcDetails, "Prepared client successfully");
592602
}
593603

594604
public Pair<Boolean, String> unprepareStorageClient(Storage.StoragePoolType type, String uuid) {
@@ -611,20 +621,37 @@ public Pair<Boolean, String> unprepareStorageClient(Storage.StoragePoolType type
611621

612622
private Map<String, String> getSDCDetails(Map<String, String> details) {
613623
Map<String, String> sdcDetails = new HashMap<String, String>();
614-
if (details == null || !details.containsKey(ScaleIOGatewayClient.STORAGE_POOL_SYSTEM_ID)) {
624+
if (MapUtils.isEmpty(details) || !details.containsKey(ScaleIOGatewayClient.STORAGE_POOL_SYSTEM_ID)) {
615625
return sdcDetails;
616626
}
617627

618628
String storageSystemId = details.get(ScaleIOGatewayClient.STORAGE_POOL_SYSTEM_ID);
619-
String sdcId = ScaleIOUtil.getSdcId(storageSystemId);
620-
if (sdcId != null) {
621-
sdcDetails.put(ScaleIOGatewayClient.SDC_ID, sdcId);
622-
} else {
623-
String sdcGuId = ScaleIOUtil.getSdcGuid();
624-
if (sdcGuId != null) {
625-
sdcDetails.put(ScaleIOGatewayClient.SDC_GUID, sdcGuId);
626-
}
629+
if (StringUtils.isEmpty(storageSystemId)) {
630+
return sdcDetails;
627631
}
632+
633+
int waitTimeInSecs = 5;
634+
int timeBetweenTries = 1000; // Try more frequently (every sec) and return early when SDC Id or Guid found
635+
do {
636+
String sdcId = ScaleIOUtil.getSdcId(storageSystemId);
637+
if (sdcId != null) {
638+
sdcDetails.put(ScaleIOGatewayClient.SDC_ID, sdcId);
639+
return sdcDetails;
640+
} else {
641+
String sdcGuId = ScaleIOUtil.getSdcGuid();
642+
if (sdcGuId != null) {
643+
sdcDetails.put(ScaleIOGatewayClient.SDC_GUID, sdcGuId);
644+
return sdcDetails;
645+
}
646+
}
647+
648+
try {
649+
Thread.sleep(timeBetweenTries);
650+
} catch (Exception ignore) {
651+
}
652+
waitTimeInSecs--;
653+
} while (waitTimeInSecs > 0);
654+
628655
return sdcDetails;
629656
}
630657

plugins/hypervisors/kvm/src/test/java/com/cloud/hypervisor/kvm/storage/ScaleIOStorageAdaptorTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,9 @@ public void testPrepareStorageClient_SDCServiceRestarted() {
116116

117117
Ternary<Boolean, Map<String, String>, String> result = scaleIOStorageAdaptor.prepareStorageClient(Storage.StoragePoolType.PowerFlex, poolUuid, new HashMap<>());
118118

119-
Assert.assertTrue(result.first());
120-
Assert.assertNotNull(result.second());
121-
Assert.assertTrue(result.second().isEmpty());
119+
Assert.assertFalse(result.first());
120+
Assert.assertNull(result.second());
121+
Assert.assertEquals("Couldn't get the SDC details on the host", result.third());
122122
}
123123

124124
@Test

plugins/storage/volume/scaleio/src/main/java/org/apache/cloudstack/storage/datastore/provider/ScaleIOHostListener.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,12 +102,12 @@ private String getSdcIdOfHost(HostVO host, StoragePool storagePool) {
102102
if (systemId == null) {
103103
throw new CloudRuntimeException("Failed to get the system id for PowerFlex storage pool " + storagePool.getName());
104104
}
105-
Map<String,String> details = new HashMap<>();
105+
Map<String, String> details = new HashMap<>();
106106
details.put(ScaleIOGatewayClient.STORAGE_POOL_SYSTEM_ID, systemId);
107107

108108
ModifyStoragePoolCommand cmd = new ModifyStoragePoolCommand(true, storagePool, storagePool.getPath(), details);
109109
ModifyStoragePoolAnswer answer = sendModifyStoragePoolCommand(cmd, storagePool, host);
110-
Map<String,String> poolDetails = answer.getPoolInfo().getDetails();
110+
Map<String, String> poolDetails = answer.getPoolInfo().getDetails();
111111
if (MapUtils.isEmpty(poolDetails)) {
112112
String msg = String.format("PowerFlex storage SDC details not found on the host: %s, (re)install SDC and restart agent", host);
113113
logger.warn(msg);

plugins/storage/volume/scaleio/src/main/java/org/apache/cloudstack/storage/datastore/util/ScaleIOUtil.java

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -216,16 +216,38 @@ public static boolean enableSDCService() {
216216

217217
public static boolean startSDCService() {
218218
int exitValue = Script.runSimpleBashScriptForExitValue(SDC_SERVICE_START_CMD);
219-
return exitValue == 0;
219+
if (exitValue != 0) {
220+
return false;
221+
}
222+
waitForSecs(3);
223+
return true;
220224
}
221225

222226
public static boolean stopSDCService() {
223227
int exitValue = Script.runSimpleBashScriptForExitValue(SDC_SERVICE_STOP_CMD);
224-
return exitValue == 0;
228+
if (exitValue != 0) {
229+
return false;
230+
}
231+
waitForSecs(1);
232+
return true;
225233
}
226234

227235
public static boolean restartSDCService() {
228236
int exitValue = Script.runSimpleBashScriptForExitValue(SDC_SERVICE_RESTART_CMD);
229-
return exitValue == 0;
237+
if (exitValue != 0) {
238+
return false;
239+
}
240+
waitForSecs(3);
241+
return true;
242+
}
243+
244+
private static void waitForSecs(long waitTimeInSecs) {
245+
if (waitTimeInSecs < 0) {
246+
waitTimeInSecs = 1;
247+
}
248+
try {
249+
Thread.sleep(waitTimeInSecs * 1000);
250+
} catch (InterruptedException ignore) {
251+
}
230252
}
231253
}

0 commit comments

Comments
 (0)