Skip to content

Commit

Permalink
PowerFlex on demand disable config key (#9664)
Browse files Browse the repository at this point in the history
* Introduced configuration key "powerflex.connect.on.demand" to enable/disable PowerFlex on-demand connection from Host to Storage Pool feature.

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

---------

Co-authored-by: Suresh Kumar Anaparti <[email protected]>
  • Loading branch information
mprokopchuk and sureshanaparti authored Sep 26, 2024
1 parent 21d107c commit 4ce8671
Showing 1 changed file with 38 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@

import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStore;
import org.apache.cloudstack.framework.config.ConfigKey;
import org.apache.cloudstack.framework.config.Configurable;
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
import org.apache.cloudstack.storage.datastore.client.ScaleIOGatewayClient;
import org.apache.cloudstack.storage.datastore.client.ScaleIOGatewayClientConnectionPool;
Expand Down Expand Up @@ -51,9 +53,18 @@
import com.cloud.utils.exception.CloudRuntimeException;

@Component
public class ScaleIOSDCManagerImpl implements ScaleIOSDCManager {
public class ScaleIOSDCManagerImpl implements ScaleIOSDCManager, Configurable {
private Logger logger = LogManager.getLogger(getClass());

static ConfigKey<Boolean> ConnectOnDemand = new ConfigKey<>("Storage",
Boolean.class,
"powerflex.connect.on.demand",
Boolean.FALSE.toString(),
"Connect PowerFlex client on Host when first Volume is mapped to SDC and disconnect when last Volume is unmapped from SDC," +
" otherwise no action (that is connection remains in the same state whichever it is, connected or disconnected).",
Boolean.TRUE,
ConfigKey.Scope.Zone);

@Inject
AgentManager agentManager;
@Inject
Expand Down Expand Up @@ -94,6 +105,11 @@ public boolean areSDCConnectionsWithinLimit(Long storagePoolId) {

@Override
public String prepareSDC(Host host, DataStore dataStore) {
if (Boolean.FALSE.equals(ConnectOnDemand.valueIn(host.getDataCenterId()))) {
logger.debug(String.format("On-demand connect/disconnect config %s disabled in the zone %d, no need to prepare SDC (check for connected SDC)", ConnectOnDemand.key(), host.getDataCenterId()));
return getConnectedSdc(host, dataStore);
}

String systemId = storagePoolDetailsDao.findDetail(dataStore.getId(), ScaleIOGatewayClient.STORAGE_POOL_SYSTEM_ID).getValue();
if (systemId == null) {
throw new CloudRuntimeException("Unable to prepare SDC, failed to get the system id for PowerFlex storage pool: " + dataStore.getName());
Expand All @@ -116,7 +132,7 @@ public String prepareSDC(Host host, DataStore dataStore) {

long poolId = dataStore.getId();
long hostId = host.getId();
String sdcId = getConnectedSdc(poolId, hostId);
String sdcId = getConnectedSdc(host, dataStore);
if (StringUtils.isNotBlank(sdcId)) {
logger.debug(String.format("SDC %s already connected for the pool: %d on host: %d, no need to prepare/start it", sdcId, poolId, hostId));
return sdcId;
Expand Down Expand Up @@ -227,6 +243,11 @@ private String prepareSDCOnHost(Host host, DataStore dataStore, String systemId)

@Override
public boolean stopSDC(Host host, DataStore dataStore) {
if (Boolean.FALSE.equals(ConnectOnDemand.valueIn(host.getDataCenterId()))) {
logger.debug(String.format("On-demand connect/disconnect config %s disabled in the zone %d, no need to unprepare SDC", ConnectOnDemand.key(), host.getDataCenterId()));
return true;
}

String systemId = storagePoolDetailsDao.findDetail(dataStore.getId(), ScaleIOGatewayClient.STORAGE_POOL_SYSTEM_ID).getValue();
if (systemId == null) {
throw new CloudRuntimeException("Unable to unprepare SDC, failed to get the system id for PowerFlex storage pool: " + dataStore.getName());
Expand All @@ -248,7 +269,7 @@ public boolean stopSDC(Host host, DataStore dataStore) {

long poolId = dataStore.getId();
long hostId = host.getId();
String sdcId = getConnectedSdc(poolId, hostId);
String sdcId = getConnectedSdc(host, dataStore);
if (StringUtils.isBlank(sdcId)) {
logger.debug("SDC not connected, no need to unprepare it");
return true;
Expand Down Expand Up @@ -297,7 +318,10 @@ private String getHostSdcId(String sdcGuid, long poolId) {
}
}

private String getConnectedSdc(long poolId, long hostId) {
private String getConnectedSdc(Host host, DataStore dataStore) {
long poolId = dataStore.getId();
long hostId = host.getId();

try {
StoragePoolHostVO poolHostVO = storagePoolHostDao.findByPoolHost(poolId, hostId);
if (poolHostVO == null) {
Expand Down Expand Up @@ -344,4 +368,14 @@ private boolean isHostSdcConnected(String sdcId, long poolId) {
private ScaleIOGatewayClient getScaleIOClient(final Long storagePoolId) throws Exception {
return ScaleIOGatewayClientConnectionPool.getInstance().getClient(storagePoolId, storagePoolDetailsDao);
}

@Override
public String getConfigComponentName() {
return ScaleIOSDCManager.class.getSimpleName();
}

@Override
public ConfigKey<?>[] getConfigKeys() {
return new ConfigKey[]{ConnectOnDemand};
}
}

0 comments on commit 4ce8671

Please sign in to comment.