Skip to content

PowerFlex/ScaleIO - Wait after SDC service start/restart/stop, and retry to fetch SDC id/guid #11099

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: 4.20
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -823,7 +823,7 @@ public static class Property <T>{
private T defaultValue;
private Class<T> typeClass;

Property(String name, T value) {
public Property(String name, T value) {
init(name, value);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.apache.cloudstack.utils.qemu.QemuImgException;
import org.apache.cloudstack.utils.qemu.QemuImgFile;
import org.apache.cloudstack.utils.qemu.QemuObject;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.io.filefilter.WildcardFileFilter;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager;
Expand Down Expand Up @@ -581,14 +582,23 @@
}

if (!ScaleIOUtil.isSDCServiceActive()) {
logger.debug("SDC service is not active on host, starting it");
if (!ScaleIOUtil.startSDCService()) {
return new Ternary<>(false, null, "Couldn't start SDC service on host");
}
} else if (!ScaleIOUtil.restartSDCService()) {
return new Ternary<>(false, null, "Couldn't restart SDC service on host");
} else {
logger.debug("SDC service is active on host, re-starting it");
if (!ScaleIOUtil.restartSDCService()) {
return new Ternary<>(false, null, "Couldn't restart SDC service on host");
}
}

Map<String, String> sdcDetails = getSDCDetails(details);
if (MapUtils.isEmpty(sdcDetails)) {
return new Ternary<>(false, null, "Couldn't get the SDC details on the host");
}

return new Ternary<>( true, getSDCDetails(details), "Prepared client successfully");
return new Ternary<>( true, sdcDetails, "Prepared client successfully");
}

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

private Map<String, String> getSDCDetails(Map<String, String> details) {
Map<String, String> sdcDetails = new HashMap<String, String>();
if (details == null || !details.containsKey(ScaleIOGatewayClient.STORAGE_POOL_SYSTEM_ID)) {
if (MapUtils.isEmpty(details) || !details.containsKey(ScaleIOGatewayClient.STORAGE_POOL_SYSTEM_ID)) {
return sdcDetails;
}

String storageSystemId = details.get(ScaleIOGatewayClient.STORAGE_POOL_SYSTEM_ID);
String sdcId = ScaleIOUtil.getSdcId(storageSystemId);
if (sdcId != null) {
sdcDetails.put(ScaleIOGatewayClient.SDC_ID, sdcId);
} else {
String sdcGuId = ScaleIOUtil.getSdcGuid();
if (sdcGuId != null) {
sdcDetails.put(ScaleIOGatewayClient.SDC_GUID, sdcGuId);
}
if (StringUtils.isEmpty(storageSystemId)) {
return sdcDetails;

Check warning on line 630 in plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/ScaleIOStorageAdaptor.java

View check run for this annotation

Codecov / codecov/patch

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

Added line #L630 was not covered by tests
}

int numberOfTries = 5;
int timeBetweenTries = 1000; // Try more frequently (every sec) and return early when SDC Id or Guid found
do {
String sdcId = ScaleIOUtil.getSdcId(storageSystemId);
if (sdcId != null) {
sdcDetails.put(ScaleIOGatewayClient.SDC_ID, sdcId);
return sdcDetails;
} else {
String sdcGuId = ScaleIOUtil.getSdcGuid();
if (sdcGuId != null) {
sdcDetails.put(ScaleIOGatewayClient.SDC_GUID, sdcGuId);
return sdcDetails;
}
}

try {
Thread.sleep(timeBetweenTries);
} catch (Exception ignore) {
}
numberOfTries--;

Check warning on line 652 in plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/ScaleIOStorageAdaptor.java

View check run for this annotation

Codecov / codecov/patch

plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/ScaleIOStorageAdaptor.java#L648-L652

Added lines #L648 - L652 were not covered by tests
} while (numberOfTries > 0);

return sdcDetails;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,9 @@ public void testPrepareStorageClient_SDCServiceRestarted() {

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

Assert.assertTrue(result.first());
Assert.assertNotNull(result.second());
Assert.assertTrue(result.second().isEmpty());
Assert.assertFalse(result.first());
Assert.assertNull(result.second());
Assert.assertEquals("Couldn't get the SDC details on the host", result.third());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,9 @@

private ScaleIOGatewayClient getScaleIOClient(final Long storagePoolId) throws Exception {
StoragePoolVO storagePool = storagePoolDao.findById(storagePoolId);
if (storagePool == null) {
throw new CloudRuntimeException("Unable to find the storage pool with id " + storagePoolId);

Check warning on line 385 in plugins/storage/volume/scaleio/src/main/java/org/apache/cloudstack/storage/datastore/manager/ScaleIOSDCManagerImpl.java

View check run for this annotation

Codecov / codecov/patch

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

Added line #L385 was not covered by tests
}
return ScaleIOGatewayClientConnectionPool.getInstance().getClient(storagePool, storagePoolDetailsDao);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,12 @@
if (systemId == null) {
throw new CloudRuntimeException("Failed to get the system id for PowerFlex storage pool " + storagePool.getName());
}
Map<String,String> details = new HashMap<>();
Map<String, String> details = new HashMap<>();

Check warning on line 105 in plugins/storage/volume/scaleio/src/main/java/org/apache/cloudstack/storage/datastore/provider/ScaleIOHostListener.java

View check run for this annotation

Codecov / codecov/patch

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

Added line #L105 was not covered by tests
details.put(ScaleIOGatewayClient.STORAGE_POOL_SYSTEM_ID, systemId);

ModifyStoragePoolCommand cmd = new ModifyStoragePoolCommand(true, storagePool, storagePool.getPath(), details);
ModifyStoragePoolAnswer answer = sendModifyStoragePoolCommand(cmd, storagePool, host);
Map<String,String> poolDetails = answer.getPoolInfo().getDetails();
Map<String, String> poolDetails = answer.getPoolInfo().getDetails();

Check warning on line 110 in plugins/storage/volume/scaleio/src/main/java/org/apache/cloudstack/storage/datastore/provider/ScaleIOHostListener.java

View check run for this annotation

Codecov / codecov/patch

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

Added line #L110 was not covered by tests
if (MapUtils.isEmpty(poolDetails)) {
String msg = String.format("PowerFlex storage SDC details not found on the host: %s, (re)install SDC and restart agent", host);
logger.warn(msg);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

package org.apache.cloudstack.storage.datastore.util;

import com.cloud.agent.properties.AgentProperties;
import com.cloud.agent.properties.AgentPropertiesFileHandler;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager;

Expand Down Expand Up @@ -60,6 +62,14 @@
private static final String SDC_SERVICE_ENABLE_CMD = "systemctl enable scini";

public static final String CONNECTED_SDC_COUNT_STAT = "ConnectedSDCCount";

/**
* Time (in seconds) to wait after SDC service 'scini' start/restart/stop.<br>
* Data type: Integer.<br>
* Default value: <code>3</code>
*/
public static final AgentProperties.Property<Integer> SDC_SERVICE_ACTION_WAIT = new AgentProperties.Property<>("powerflex.sdc.service.wait", 3);

/**
* Cmd for querying volumes in SDC
* Sample output for cmd: drv_cfg --query_vols:
Expand Down Expand Up @@ -216,16 +226,41 @@

public static boolean startSDCService() {
int exitValue = Script.runSimpleBashScriptForExitValue(SDC_SERVICE_START_CMD);
return exitValue == 0;
if (exitValue != 0) {
return false;
}
waitForSdcServiceActionToComplete();
return true;

Check warning on line 233 in plugins/storage/volume/scaleio/src/main/java/org/apache/cloudstack/storage/datastore/util/ScaleIOUtil.java

View check run for this annotation

Codecov / codecov/patch

plugins/storage/volume/scaleio/src/main/java/org/apache/cloudstack/storage/datastore/util/ScaleIOUtil.java#L232-L233

Added lines #L232 - L233 were not covered by tests
}

public static boolean stopSDCService() {
int exitValue = Script.runSimpleBashScriptForExitValue(SDC_SERVICE_STOP_CMD);
return exitValue == 0;
if (exitValue != 0) {
return false;
}
waitForSdcServiceActionToComplete();
return true;
}

public static boolean restartSDCService() {
int exitValue = Script.runSimpleBashScriptForExitValue(SDC_SERVICE_RESTART_CMD);
return exitValue == 0;
if (exitValue != 0) {
return false;
}
waitForSdcServiceActionToComplete();
return true;
}

Check warning on line 252 in plugins/storage/volume/scaleio/src/main/java/org/apache/cloudstack/storage/datastore/util/ScaleIOUtil.java

View check run for this annotation

Codecov / codecov/patch

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

Added line #L252 was not covered by tests

private static void waitForSdcServiceActionToComplete() {

Check warning on line 254 in plugins/storage/volume/scaleio/src/main/java/org/apache/cloudstack/storage/datastore/util/ScaleIOUtil.java

View check run for this annotation

Codecov / codecov/patch

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

Added line #L254 was not covered by tests
// Wait for the SDC service to settle after start/restart/stop and reaches a stable state
int waitTimeInSecs = AgentPropertiesFileHandler.getPropertyValue(SDC_SERVICE_ACTION_WAIT);
if (waitTimeInSecs < 0) {
waitTimeInSecs = SDC_SERVICE_ACTION_WAIT.getDefaultValue();

Check warning on line 258 in plugins/storage/volume/scaleio/src/main/java/org/apache/cloudstack/storage/datastore/util/ScaleIOUtil.java

View check run for this annotation

Codecov / codecov/patch

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

Added line #L258 was not covered by tests
}
try {

Check warning on line 260 in plugins/storage/volume/scaleio/src/main/java/org/apache/cloudstack/storage/datastore/util/ScaleIOUtil.java

View check run for this annotation

Codecov / codecov/patch

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

Added line #L260 was not covered by tests
LOGGER.debug(String.format("Waiting for %d secs after SDC service action, to reach a stable state", waitTimeInSecs));
Thread.sleep(waitTimeInSecs * 1000L);
} catch (InterruptedException ignore) {

Check warning on line 263 in plugins/storage/volume/scaleio/src/main/java/org/apache/cloudstack/storage/datastore/util/ScaleIOUtil.java

View check run for this annotation

Codecov / codecov/patch

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

Added line #L263 was not covered by tests
}
}
}
Loading