Skip to content

Commit 9befbd3

Browse files
Fix wait time for remove PowerFlex MDMs, and some code improvements
1 parent 778a873 commit 9befbd3

File tree

6 files changed

+54
-39
lines changed

6 files changed

+54
-39
lines changed

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

Lines changed: 41 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ public KVMPhysicalDisk getPhysicalDisk(String volumePath, KVMStoragePool pool) {
152152
@Override
153153
public KVMStoragePool createStoragePool(String uuid, String host, int port, String path, String userInfo, Storage.StoragePoolType type, Map<String, String> details, boolean isPrimaryStorage) {
154154
ScaleIOStoragePool storagePool = new ScaleIOStoragePool(uuid, host, port, path, type, details, this);
155-
if (details != null && details.containsKey(ScaleIOSDCManager.ConnectOnDemand.key())) {
155+
if (MapUtils.isNotEmpty(details) && details.containsKey(ScaleIOSDCManager.ConnectOnDemand.key())) {
156156
String connectOnDemand = details.get(ScaleIOSDCManager.ConnectOnDemand.key());
157157
if (connectOnDemand != null && !Boolean.parseBoolean(connectOnDemand)) {
158158
Ternary<Boolean, Map<String, String>, String> prepareStorageClientStatus = prepareStorageClient(uuid, details);
@@ -180,19 +180,24 @@ public KVMStoragePool createStoragePool(String uuid, String host, int port, Stri
180180
*/
181181
private void validateMdmState(Map<String, String> details) {
182182
String configKey = ScaleIOSDCManager.ValidateMdmsOnConnect.key();
183+
if (MapUtils.isEmpty(details) || !details.containsKey(configKey)) {
184+
logger.debug(String.format("Skipped PowerFlex MDMs validation as property %s not sent by Management Server", configKey));
185+
return;
186+
}
187+
183188
String configValue = details.get(configKey);
184189

185190
// be as much verbose as possible, otherwise it will be difficult to troubleshoot operational issue without logs
186191
if (StringUtils.isEmpty(configValue)) {
187-
logger.debug(String.format("Skipped ScaleIO validation as property %s not sent by Management Server", configKey));
192+
logger.debug(String.format("Skipped PowerFlex MDMs validation as property %s sent by Management Server is empty", configKey));
188193
} else if (Boolean.valueOf(configValue).equals(Boolean.FALSE)) {
189-
logger.debug(String.format("Skipped ScaleIO validation as property %s received as %s", configKey, configValue));
194+
logger.debug(String.format("Skipped PowerFlex MDMs validation as property %s received as %s", configKey, configValue));
190195
} else {
191-
Collection<String> mdmsConfig = ScaleIOUtil.getMdmsFromConfig();
192-
Collection<String> mdmsCli = ScaleIOUtil.getMdmsFromCli();
193-
if (!mdmsCli.equals(mdmsConfig)) {
194-
String msg = String.format("MDM addresses from memory and configuration file don't match. " +
195-
"Memory values: %s, configuration file values: %s", mdmsCli, mdmsConfig);
196+
Collection<String> mdmsFromConfigFile = ScaleIOUtil.getMdmsFromConfigFile();
197+
Collection<String> mdmsFromCliCmd = ScaleIOUtil.getMdmsFromCliCmd();
198+
if (!mdmsFromCliCmd.equals(mdmsFromConfigFile)) {
199+
String msg = String.format("PowerFlex MDM addresses from CLI and Configuration File doesn't match. " +
200+
"CLI values: %s, Configuration File values: %s", mdmsFromCliCmd, mdmsFromConfigFile);
196201
logger.warn(msg);
197202
throw new CloudRuntimeException(msg);
198203
}
@@ -210,7 +215,7 @@ public boolean deleteStoragePool(String uuid) {
210215

211216
@Override
212217
public boolean deleteStoragePool(String uuid, Map<String, String> details) {
213-
if (details != null && details.containsKey(ScaleIOSDCManager.ConnectOnDemand.key())) {
218+
if (MapUtils.isNotEmpty(details) && details.containsKey(ScaleIOSDCManager.ConnectOnDemand.key())) {
214219
String connectOnDemand = details.get(ScaleIOSDCManager.ConnectOnDemand.key());
215220
if (connectOnDemand != null && !Boolean.parseBoolean(connectOnDemand)) {
216221
Pair<Boolean, String> unprepareStorageClientStatus = unprepareStorageClient(uuid, details);
@@ -296,7 +301,7 @@ public boolean connectPhysicalDisk(String volumePath, KVMStoragePool pool, Map<S
296301
volumePath = ScaleIOUtil.getVolumePath(volumePath);
297302

298303
int waitTimeInSec = DEFAULT_DISK_WAIT_TIME_IN_SECS;
299-
if (details != null && details.containsKey(StorageManager.STORAGE_POOL_DISK_WAIT.toString())) {
304+
if (MapUtils.isNotEmpty(details) && details.containsKey(StorageManager.STORAGE_POOL_DISK_WAIT.toString())) {
300305
String waitTime = details.get(StorageManager.STORAGE_POOL_DISK_WAIT.toString());
301306
if (StringUtils.isNotEmpty(waitTime)) {
302307
waitTimeInSec = Integer.valueOf(waitTime).intValue();
@@ -664,7 +669,7 @@ public Ternary<Boolean, Map<String, String>, String> prepareStorageClient(String
664669
return new Ternary<>(false, null, "Failed to add MDMs");
665670
} else {
666671
logger.debug(String.format("MDMs %s added to storage pool %s", mdms, uuid));
667-
applyTimeout(details);
672+
applyMdmsChangeWaitTime(details);
668673
}
669674
}
670675
}
@@ -688,7 +693,7 @@ public Pair<Boolean, String> unprepareStorageClient(String uuid, Map<String, Str
688693
return new Pair<>(true, "SDC service not enabled on host, no need to unprepare the SDC client");
689694
}
690695

691-
if (details != null && details.containsKey(ScaleIOGatewayClient.STORAGE_POOL_MDMS)) {
696+
if (MapUtils.isNotEmpty(details) && details.containsKey(ScaleIOGatewayClient.STORAGE_POOL_MDMS)) {
692697
String mdms = details.get(ScaleIOGatewayClient.STORAGE_POOL_MDMS);
693698
String[] mdmAddresses = mdms.split(",");
694699
if (mdmAddresses.length > 0) {
@@ -704,17 +709,22 @@ public Pair<Boolean, String> unprepareStorageClient(String uuid, Map<String, Str
704709
logger.debug(String.format("Configuration key %s provided as %s", configKey, configValue));
705710
}
706711
Boolean blockUnprepare = Boolean.valueOf(configValue);
707-
if (!ScaleIOUtil.isRemoveMdmCliSupported() && !ScaleIOUtil.getVolumeIds().isEmpty() && Boolean.TRUE.equals(blockUnprepare)) {
712+
if (!ScaleIOUtil.isRemoveMdmCliSupported() // scini restart required when --remove_mdm is not supported
713+
&& !ScaleIOUtil.getVolumeIds().isEmpty()
714+
&& Boolean.TRUE.equals(blockUnprepare)) {
708715
return new Pair<>(false, "Failed to remove MDMs, SDC client requires service to be restarted, but there are Volumes attached to the Host");
709716
}
710717
}
711718

719+
// Immediate removal of MDMs after unmapping volume throws Error: "Volume is mappedKernel module rejects removing MDM"
720+
// Wait before removing MDMs for any volumes to get unmapped.
721+
applyMdmsChangeWaitTime(details);
712722
ScaleIOUtil.removeMdms(mdmAddresses);
713723
if (ScaleIOUtil.isMdmPresent(mdmAddresses[0])) {
714724
return new Pair<>(false, "Failed to remove MDMs, unable to unprepare the SDC client");
715725
} else {
716726
logger.debug(String.format("MDMs %s removed from storage pool %s", mdms, uuid));
717-
applyTimeout(details);
727+
applyMdmsChangeWaitTime(details);
718728
}
719729
}
720730
}
@@ -730,36 +740,41 @@ public Pair<Boolean, String> unprepareStorageClient(String uuid, Map<String, Str
730740
}
731741

732742
/**
733-
* Check whether details map has timeout configured and do "apply timeout" pause before returning response
743+
* Check whether details map has wait time configured and do "apply wait time" pause before returning response
734744
* (to have ScaleIO changes applied).
735745
*
736746
* @param details see {@link PrepareStorageClientCommand#getDetails()}
737747
* and {@link @UnprepareStorageClientCommand#getDetails()}, expected to contain
738-
* {@link ScaleIOSDCManager#MdmsChangeApplyTimeout#key()}
748+
* {@link ScaleIOSDCManager#MdmsChangeApplyWaitTime#key()}
739749
*/
740-
private void applyTimeout(Map<String, String> details) {
741-
String configKey = ScaleIOSDCManager.MdmsChangeApplyTimeout.key();
742-
String configValue = details.get(configKey);
750+
private void applyMdmsChangeWaitTime(Map<String, String> details) {
751+
String configKey = ScaleIOSDCManager.MdmsChangeApplyWaitTime.key();
752+
if (MapUtils.isEmpty(details) || !details.containsKey(configKey)) {
753+
logger.debug(String.format("Apply wait time property %s not sent by Management Server, skip", configKey));
754+
return;
755+
}
743756

757+
String configValue = details.get(configKey);
744758
if (StringUtils.isEmpty(configValue)) {
745-
logger.debug(String.format("Apply timeout value not defined in property %s, skip", configKey));
759+
logger.debug(String.format("Apply wait time value not defined in property %s, skip", configKey));
746760
return;
747761
}
748762
long timeoutMs;
749763
try {
750764
timeoutMs = Long.parseLong(configValue);
751765
} catch (NumberFormatException e) {
752-
logger.warn(String.format("Invalid apply timeout value defined in property %s, skip", configKey), e);
766+
logger.warn(String.format("Invalid apply wait time value defined in property %s, skip", configKey), e);
753767
return;
754768
}
755769
if (timeoutMs < 1) {
756-
logger.warn(String.format("Apply timeout value is too small (%s ms), skipping", timeoutMs));
770+
logger.warn(String.format("Apply wait time value is too small (%s ms), skipping", timeoutMs));
757771
return;
758772
}
759773
try {
774+
logger.debug(String.format("Waiting for %d ms as defined in property %s", timeoutMs, configKey));
760775
Thread.sleep(timeoutMs);
761776
} catch (InterruptedException e) {
762-
logger.warn(String.format("Apply timeout %s ms interrupted", timeoutMs), e);
777+
logger.warn(String.format("Waiting for %d ms interrupted", timeoutMs), e);
763778
}
764779
}
765780

@@ -774,7 +789,7 @@ private Map<String, String> getSDCDetails(Map<String, String> details) {
774789
return sdcDetails;
775790
}
776791

777-
int waitTimeInSecs = 5;
792+
int numberOfTries = 5;
778793
int timeBetweenTries = 1000; // Try more frequently (every sec) and return early when SDC Id or Guid found
779794
do {
780795
String sdcId = ScaleIOUtil.getSdcId(storageSystemId);
@@ -793,8 +808,8 @@ private Map<String, String> getSDCDetails(Map<String, String> details) {
793808
Thread.sleep(timeBetweenTries);
794809
} catch (Exception ignore) {
795810
}
796-
waitTimeInSecs--;
797-
} while (waitTimeInSecs > 0);
811+
numberOfTries--;
812+
} while (numberOfTries > 0);
798813

799814
return sdcDetails;
800815
}

plugins/storage/volume/scaleio/src/main/java/org/apache/cloudstack/storage/datastore/lifecycle/ScaleIOPrimaryDataStoreLifeCycle.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ private void populateScaleIOConfiguration(Map<String, String> details, long data
417417
details = new HashMap<>();
418418
}
419419

420-
details.put(ScaleIOSDCManager.MdmsChangeApplyTimeout.key(), String.valueOf(ScaleIOSDCManager.MdmsChangeApplyTimeout.valueIn(dataCenterId)));
420+
details.put(ScaleIOSDCManager.MdmsChangeApplyWaitTime.key(), String.valueOf(ScaleIOSDCManager.MdmsChangeApplyWaitTime.valueIn(dataCenterId)));
421421
details.put(ScaleIOSDCManager.ValidateMdmsOnConnect.key(), String.valueOf(ScaleIOSDCManager.ValidateMdmsOnConnect.valueIn(dataCenterId)));
422422
details.put(ScaleIOSDCManager.BlockSdcUnprepareIfRestartNeededAndVolumesAreAttached.key(), String.valueOf(ScaleIOSDCManager.BlockSdcUnprepareIfRestartNeededAndVolumesAreAttached.valueIn(dataCenterId)));
423423
}

plugins/storage/volume/scaleio/src/main/java/org/apache/cloudstack/storage/datastore/manager/ScaleIOSDCManager.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,27 +36,27 @@ public interface ScaleIOSDCManager {
3636
* Timeout for Host to wait after MDM changes made on Host until changes will be applied.
3737
* Needed to avoid cases when Storage Pool is not connected yet, but Agent already starts to use Storage Pool.
3838
*/
39-
ConfigKey<Integer> MdmsChangeApplyTimeout = new ConfigKey<>("Storage",
39+
ConfigKey<Integer> MdmsChangeApplyWaitTime = new ConfigKey<>("Storage",
4040
Integer.class,
41-
"powerflex.mdm.change.apply.timeout.ms",
41+
"powerflex.mdm.change.apply.wait",
4242
"1000",
43-
"Timeout (in ms) for Host to wait after MDM changes made on Host until changes will be applied, default value: 1000 ms",
43+
"Time (in ms) to wait after MDM addition, and before & after MDM removal changes made on the Host, default value: 1000 ms",
4444
Boolean.TRUE,
4545
ConfigKey.Scope.Zone);
4646

4747
ConfigKey<Boolean> ValidateMdmsOnConnect = new ConfigKey<>("Storage",
4848
Boolean.class,
4949
"powerflex.mdm.validate.on.connect",
5050
Boolean.FALSE.toString(),
51-
"Flag to validate MDMs on Host, present in configuration file and in CLI, default value: false",
51+
"Flag to validate PowerFlex MDMs on the host, present in Configuration File and in CLI during storage pool registration in agent, default value: false",
5252
Boolean.TRUE,
5353
ConfigKey.Scope.Zone);
5454

5555
ConfigKey<Boolean> BlockSdcUnprepareIfRestartNeededAndVolumesAreAttached = new ConfigKey<>("Storage",
5656
Boolean.class,
5757
"powerflex.block.sdc.unprepare",
5858
Boolean.FALSE.toString(),
59-
"Block Storage Client un-preparation if SDC service restart needed but there are Volumes attached to the Host",
59+
"Block storage client un-preparation if SDC service restart needed after PowerFlex MDM removal (i.e. no support for --remove_mdm in drv_cfg cmd) when there are Volumes mapped to the Host",
6060
Boolean.TRUE,
6161
ConfigKey.Scope.Zone);
6262

plugins/storage/volume/scaleio/src/main/java/org/apache/cloudstack/storage/datastore/manager/ScaleIOSDCManagerImpl.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ private String prepareSDCOnHost(Host host, DataStore dataStore, String systemId,
207207
Map<String, String> details = new HashMap<>();
208208
details.put(ScaleIOGatewayClient.STORAGE_POOL_SYSTEM_ID, systemId);
209209
details.put(ScaleIOGatewayClient.STORAGE_POOL_MDMS, mdms);
210-
details.put(MdmsChangeApplyTimeout.key(), String.valueOf(MdmsChangeApplyTimeout.valueIn(host.getDataCenterId())));
210+
details.put(MdmsChangeApplyWaitTime.key(), String.valueOf(MdmsChangeApplyWaitTime.valueIn(host.getDataCenterId())));
211211

212212
PrepareStorageClientCommand cmd = new PrepareStorageClientCommand(((PrimaryDataStore) dataStore).getPoolType(), dataStore.getUuid(), details);
213213
int timeoutSeconds = 60;
@@ -325,7 +325,7 @@ private boolean unprepareSDCOnHost(Host host, DataStore dataStore, String mdms)
325325
logger.debug(String.format("Unpreparing SDC on the host %s (%s)", host.getId(), host.getName()));
326326
Map<String,String> details = new HashMap<>();
327327
details.put(ScaleIOGatewayClient.STORAGE_POOL_MDMS, mdms);
328-
details.put(MdmsChangeApplyTimeout.key(), String.valueOf(MdmsChangeApplyTimeout.valueIn(host.getDataCenterId())));
328+
details.put(MdmsChangeApplyWaitTime.key(), String.valueOf(MdmsChangeApplyWaitTime.valueIn(host.getDataCenterId())));
329329
UnprepareStorageClientCommand cmd = new UnprepareStorageClientCommand(((PrimaryDataStore) dataStore).getPoolType(), dataStore.getUuid(), details);
330330
int timeoutSeconds = 60;
331331
cmd.setWait(timeoutSeconds);
@@ -492,6 +492,6 @@ public String getConfigComponentName() {
492492

493493
@Override
494494
public ConfigKey<?>[] getConfigKeys() {
495-
return new ConfigKey[]{ConnectOnDemand, MdmsChangeApplyTimeout, ValidateMdmsOnConnect, BlockSdcUnprepareIfRestartNeededAndVolumesAreAttached};
495+
return new ConfigKey[]{ConnectOnDemand, MdmsChangeApplyWaitTime, ValidateMdmsOnConnect, BlockSdcUnprepareIfRestartNeededAndVolumesAreAttached};
496496
}
497497
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ private void populateScaleIOConfiguration(Map<String, String> details, long data
253253
details = new HashMap<>();
254254
}
255255

256-
details.put(ScaleIOSDCManager.MdmsChangeApplyTimeout.key(), String.valueOf(ScaleIOSDCManager.MdmsChangeApplyTimeout.valueIn(dataCenterId)));
256+
details.put(ScaleIOSDCManager.MdmsChangeApplyWaitTime.key(), String.valueOf(ScaleIOSDCManager.MdmsChangeApplyWaitTime.valueIn(dataCenterId)));
257257
details.put(ScaleIOSDCManager.ValidateMdmsOnConnect.key(), String.valueOf(ScaleIOSDCManager.ValidateMdmsOnConnect.valueIn(dataCenterId)));
258258
details.put(ScaleIOSDCManager.BlockSdcUnprepareIfRestartNeededAndVolumesAreAttached.key(), String.valueOf(ScaleIOSDCManager.BlockSdcUnprepareIfRestartNeededAndVolumesAreAttached.valueIn(dataCenterId)));
259259
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ public static boolean removeMdms(String... mdmAddresses) {
245245
/**
246246
* Returns MDM entries from {@link ScaleIOUtil#DRV_CFG_FILE}.
247247
*/
248-
public static Collection<String> getMdmsFromConfig() {
248+
public static Collection<String> getMdmsFromConfigFile() {
249249
List<String> configFileLines;
250250
try {
251251
configFileLines = Files.readAllLines(Path.of(DRV_CFG_FILE));
@@ -284,9 +284,9 @@ public static Collection<String> getVolumeIds() {
284284
}
285285

286286
/**
287-
* Returns MDM entries from CLI using {@code --query_mdms}.
287+
* Returns MDM entries from CLI Cmd using {@code --query_mdms}.
288288
*/
289-
public static Collection<String> getMdmsFromCli() {
289+
public static Collection<String> getMdmsFromCliCmd() {
290290
String command = ScaleIOUtil.SDC_HOME_PATH + "/bin/" + ScaleIOUtil.QUERY_MDMS_CMD;
291291
Pair<String, String> result = Script.executeCommand(command);
292292
String stdOut = result.first();

0 commit comments

Comments
 (0)