diff --git a/plugins/storage/volume/scaleio/src/main/java/org/apache/cloudstack/storage/datastore/manager/ScaleIOSDCManagerImpl.java b/plugins/storage/volume/scaleio/src/main/java/org/apache/cloudstack/storage/datastore/manager/ScaleIOSDCManagerImpl.java index 92fe1d837618..4d3a78f6875f 100644 --- a/plugins/storage/volume/scaleio/src/main/java/org/apache/cloudstack/storage/datastore/manager/ScaleIOSDCManagerImpl.java +++ b/plugins/storage/volume/scaleio/src/main/java/org/apache/cloudstack/storage/datastore/manager/ScaleIOSDCManagerImpl.java @@ -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; @@ -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 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 @@ -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()); @@ -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; @@ -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()); @@ -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; @@ -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) { @@ -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}; + } }