Skip to content

Commit 7562030

Browse files
Merge branch '4.22'
2 parents 9cc6c09 + 65e5409 commit 7562030

File tree

19 files changed

+225
-122
lines changed

19 files changed

+225
-122
lines changed

api/src/main/java/org/apache/cloudstack/api/ApiServerService.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,5 +49,7 @@ public ResponseObject loginUser(HttpSession session, String username, String pas
4949

5050
boolean resetPassword(UserAccount userAccount, String token, String password);
5151

52+
String getDomainId(Map<String, Object[]> params);
53+
5254
boolean isPostRequestsAndTimestampsEnforced();
5355
}

engine/schema/src/main/java/com/cloud/vm/dao/VMInstanceDaoImpl.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -846,15 +846,18 @@ public HashMap<String, Long> countVgpuVMs(Long dcId, Long podId, Long clusterId)
846846

847847
try {
848848
pstmtLegacy = txn.prepareAutoCloseStatement(finalQueryLegacy.toString());
849-
pstmt = txn.prepareAutoCloseStatement(finalQuery.toString());
850849
for (int i = 0; i < resourceIdList.size(); i++) {
851850
pstmtLegacy.setLong(1 + i, resourceIdList.get(i));
852-
pstmt.setLong(1 + i, resourceIdList.get(i));
853851
}
854852
ResultSet rs = pstmtLegacy.executeQuery();
855853
while (rs.next()) {
856854
result.put(rs.getString(1).concat(rs.getString(2)), rs.getLong(3));
857855
}
856+
857+
pstmt = txn.prepareAutoCloseStatement(finalQuery.toString());
858+
for (int i = 0; i < resourceIdList.size(); i++) {
859+
pstmt.setLong(1 + i, resourceIdList.get(i));
860+
}
858861
rs = pstmt.executeQuery();
859862
while (rs.next()) {
860863
result.put(rs.getString(1).concat(rs.getString(2)), rs.getLong(3));

engine/storage/datamotion/src/main/java/org/apache/cloudstack/storage/motion/StorageSystemDataMotionStrategy.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2565,8 +2565,7 @@ protected void verifyLiveMigrationForKVM(Map<VolumeInfo, DataStore> volumeDataSt
25652565
throw new CloudRuntimeException("Destination storage pool with ID " + dataStore.getId() + " was not located.");
25662566
}
25672567

2568-
boolean isSrcAndDestPoolPowerFlexStorage = srcStoragePoolVO.getPoolType().equals(Storage.StoragePoolType.PowerFlex) && destStoragePoolVO.getPoolType().equals(Storage.StoragePoolType.PowerFlex);
2569-
if (srcStoragePoolVO.isManaged() && !isSrcAndDestPoolPowerFlexStorage && srcStoragePoolVO.getId() != destStoragePoolVO.getId()) {
2568+
if (srcStoragePoolVO.isManaged() && srcStoragePoolVO.getId() != destStoragePoolVO.getId()) {
25702569
throw new CloudRuntimeException("Migrating a volume online with KVM from managed storage is not currently supported.");
25712570
}
25722571

framework/config/src/main/java/org/apache/cloudstack/framework/config/ConfigKey.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,14 @@ protected T valueInGlobalOrAvailableParentScope(Scope scope, Long id) {
420420
return value();
421421
}
422422

423+
/**
424+
* @deprecated
425+
* Still used by some external code, but use {@link ConfigKey#valueInScope(Scope, Long)} instead.
426+
*/
427+
public T valueInDomain(Long domainId) {
428+
return valueInScope(Scope.Domain, domainId);
429+
}
430+
423431
public T valueInScope(Scope scope, Long id) {
424432
if (id == null) {
425433
return value();

plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -884,7 +884,7 @@ protected enum HealthCheckResult {
884884
protected StorageSubsystemCommandHandler storageHandler;
885885

886886
private boolean convertInstanceVerboseMode = false;
887-
private String[] convertInstanceEnv = null;
887+
private Map<String, String> convertInstanceEnv = null;
888888
protected boolean dpdkSupport = false;
889889
protected String dpdkOvsPath;
890890
protected String directDownloadTemporaryDownloadPath;
@@ -949,7 +949,7 @@ public boolean isConvertInstanceVerboseModeEnabled() {
949949
return convertInstanceVerboseMode;
950950
}
951951

952-
public String[] getConvertInstanceEnv() {
952+
public Map<String, String> getConvertInstanceEnv() {
953953
return convertInstanceEnv;
954954
}
955955

@@ -1439,14 +1439,14 @@ private void setConvertInstanceEnv(String convertEnvTmpDir, String convertEnvVir
14391439
return;
14401440
}
14411441
if (StringUtils.isNotBlank(convertEnvTmpDir) && StringUtils.isNotBlank(convertEnvVirtv2vTmpDir)) {
1442-
convertInstanceEnv = new String[2];
1443-
convertInstanceEnv[0] = String.format("%s=%s", "TMPDIR", convertEnvTmpDir);
1444-
convertInstanceEnv[1] = String.format("%s=%s", "VIRT_V2V_TMPDIR", convertEnvVirtv2vTmpDir);
1442+
convertInstanceEnv = new HashMap<>(2);
1443+
convertInstanceEnv.put("TMPDIR", convertEnvTmpDir);
1444+
convertInstanceEnv.put("VIRT_V2V_TMPDIR", convertEnvVirtv2vTmpDir);
14451445
} else {
1446-
convertInstanceEnv = new String[1];
1446+
convertInstanceEnv = new HashMap<>(1);
14471447
String key = StringUtils.isNotBlank(convertEnvTmpDir) ? "TMPDIR" : "VIRT_V2V_TMPDIR";
14481448
String value = StringUtils.isNotBlank(convertEnvTmpDir) ? convertEnvTmpDir : convertEnvVirtv2vTmpDir;
1449-
convertInstanceEnv[0] = String.format("%s=%s", key, value);
1449+
convertInstanceEnv.put(key, value);
14501450
}
14511451
}
14521452

plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtConvertInstanceCommandWrapper.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,11 @@
2222
import java.nio.charset.Charset;
2323
import java.util.Arrays;
2424
import java.util.List;
25+
import java.util.Map;
2526
import java.util.UUID;
2627

2728
import org.apache.cloudstack.storage.to.PrimaryDataStoreTO;
29+
import org.apache.commons.collections4.MapUtils;
2830
import org.apache.commons.lang3.StringUtils;
2931

3032
import com.cloud.agent.api.Answer;
@@ -244,7 +246,12 @@ protected boolean performInstanceConversion(String originalVMName, String source
244246

245247
String logPrefix = String.format("(%s) virt-v2v ovf source: %s progress", originalVMName, sourceOVFDirPath);
246248
OutputInterpreter.LineByLineOutputLogger outputLogger = new OutputInterpreter.LineByLineOutputLogger(logger, logPrefix);
247-
script.execute(outputLogger);
249+
Map<String, String> convertInstanceEnv = serverResource.getConvertInstanceEnv();
250+
if (MapUtils.isEmpty(convertInstanceEnv)) {
251+
script.execute(outputLogger);
252+
} else {
253+
script.execute(outputLogger, convertInstanceEnv);
254+
}
248255
int exitValue = script.getExitValue();
249256
return exitValue == 0;
250257
}

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,8 @@ public void testUnprepareStorageClient_MDMNotAdded() {
180180
details.put(ScaleIOGatewayClient.STORAGE_POOL_MDMS, "1.1.1.1,2.2.2.2");
181181
when(Script.runSimpleBashScriptForExitValue(Mockito.eq("systemctl status scini"))).thenReturn(3);
182182
when(Script.runSimpleBashScriptForExitValue(Mockito.eq("systemctl is-enabled scini"))).thenReturn(0);
183-
when(Script.runSimpleBashScript(Mockito.eq("/opt/emc/scaleio/sdc/bin/drv_cfg --query_mdms|grep 1.1.1.1"))).thenReturn("MDM-ID 71fd458f0775010f SDC ID 4421a91a00000000 INSTALLATION ID 204930df2cbcaf8e IPs [0]-3.3.3.3 [1]-4.4.4.4");
183+
when(Script.runSimpleBashScript(Mockito.eq("/opt/emc/scaleio/sdc/bin/drv_cfg --query_mdms|grep 1.1.1.1"), Mockito.eq(ScaleIOUtil.DEFAULT_TIMEOUT_MS)))
184+
.thenReturn("MDM-ID 71fd458f0775010f SDC ID 4421a91a00000000 INSTALLATION ID 204930df2cbcaf8e IPs [0]-3.3.3.3 [1]-4.4.4.4");
184185

185186
Pair<Boolean, String> result = scaleIOStorageAdaptor.unprepareStorageClient(poolUuid, details);
186187

@@ -196,11 +197,11 @@ public void testUnprepareStorageClient_RemoveMDMFailed() {
196197
when(Script.runSimpleBashScriptForExitValue(Mockito.eq("systemctl is-enabled scini"))).thenReturn(0);
197198
when(Script.executeCommand(Mockito.eq("sed -i '/1.1.1.1\\,/d' /etc/emc/scaleio/drv_cfg.txt"))).thenReturn(new Pair<>(null, null));
198199
when(Script.runSimpleBashScriptForExitValue(Mockito.eq("systemctl restart scini"))).thenReturn(0);
199-
when(Script.runSimpleBashScript(Mockito.eq("/opt/emc/scaleio/sdc/bin/drv_cfg --query_mdms|grep 1.1.1.1"))).thenReturn("MDM-ID 71fd458f0775010f SDC ID 4421a91a00000000 INSTALLATION ID 204930df2cbcaf8e IPs [0]-1.1.1.1 [1]-2.2.2.2");
200+
when(Script.runSimpleBashScript(Mockito.eq("/opt/emc/scaleio/sdc/bin/drv_cfg --query_mdms --file /etc/emc/scaleio/drv_cfg.txt|grep 1.1.1.1"), Mockito.eq(ScaleIOUtil.DEFAULT_TIMEOUT_MS)))
201+
.thenReturn("MDM-ID 71fd458f0775010f SDC ID 4421a91a00000000 INSTALLATION ID 204930df2cbcaf8e IPs [0]-1.1.1.1 [1]-2.2.2.2");
200202
when(Script.executeCommand(Mockito.eq("/opt/emc/scaleio/sdc/bin/drv_cfg"))).thenReturn(new Pair<>(null, null));
201203
when(Script.executeCommand(Mockito.eq("/opt/emc/scaleio/sdc/bin/drv_cfg --query_vols"))).thenReturn(new Pair<>("", null));
202204

203-
204205
Pair<Boolean, String> result = scaleIOStorageAdaptor.unprepareStorageClient(poolUuid, details);
205206

206207
Assert.assertFalse(result.first());

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

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,8 @@ public void testSdcIdAttribute() {
9595
details.put(ScaleIOGatewayClient.STORAGE_POOL_SYSTEM_ID, systemId);
9696

9797
try (MockedStatic<Script> ignored = Mockito.mockStatic(Script.class)) {
98-
when(Script.runSimpleBashScript(
99-
"/opt/emc/scaleio/sdc/bin/drv_cfg --query_mdms|grep 218ce1797566a00f|awk '{print $5}'")).thenReturn(
100-
sdcId);
98+
when(Script.runSimpleBashScript(Mockito.eq("/opt/emc/scaleio/sdc/bin/drv_cfg --query_mdms --file /etc/emc/scaleio/drv_cfg.txt|grep 218ce1797566a00f|awk '{print $5}'"), Mockito.eq(ScaleIOUtil.DEFAULT_TIMEOUT_MS)))
99+
.thenReturn(sdcId);
101100

102101
ScaleIOStoragePool pool1 = new ScaleIOStoragePool(uuid, "192.168.1.19", 443, "a519be2f00000000", type,
103102
details, adapter);
@@ -116,10 +115,10 @@ public void testSdcGuidAttribute() {
116115
details.put(ScaleIOGatewayClient.STORAGE_POOL_SYSTEM_ID, systemId);
117116

118117
try (MockedStatic<Script> ignored = Mockito.mockStatic(Script.class)) {
119-
when(Script.runSimpleBashScript(
120-
"/opt/emc/scaleio/sdc/bin/drv_cfg --query_mdms|grep 218ce1797566a00f|awk '{print $5}'")).thenReturn(
121-
null);
122-
when(Script.runSimpleBashScript("/opt/emc/scaleio/sdc/bin/drv_cfg --query_guid")).thenReturn(sdcGuid);
118+
when(Script.runSimpleBashScript(Mockito.eq("/opt/emc/scaleio/sdc/bin/drv_cfg --query_mdms --file /etc/emc/scaleio/drv_cfg.txt|grep 218ce1797566a00f|awk '{print $5}'"), Mockito.eq(ScaleIOUtil.DEFAULT_TIMEOUT_MS)))
119+
.thenReturn(null);
120+
when(Script.runSimpleBashScript(Mockito.eq("/opt/emc/scaleio/sdc/bin/drv_cfg --query_guid --file /etc/emc/scaleio/drv_cfg.txt"), Mockito.eq(ScaleIOUtil.DEFAULT_TIMEOUT_MS)))
121+
.thenReturn(sdcGuid);
123122

124123
ScaleIOStoragePool pool1 = new ScaleIOStoragePool(uuid, "192.168.1.19", 443, "a519be2f00000000", type,
125124
details, adapter);

plugins/storage/volume/scaleio/src/main/java/org/apache/cloudstack/storage/datastore/client/ScaleIOGatewayClientConnectionPool.java

Lines changed: 48 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@
1717

1818
package org.apache.cloudstack.storage.datastore.client;
1919

20-
import java.net.URISyntaxException;
21-
import java.security.KeyManagementException;
22-
import java.security.NoSuchAlgorithmException;
20+
import java.util.Map;
21+
import java.util.Optional;
2322
import java.util.concurrent.ConcurrentHashMap;
2423

2524
import com.cloud.storage.StoragePool;
25+
import com.cloud.utils.exception.CloudRuntimeException;
2626
import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
2727
import org.apache.cloudstack.storage.datastore.db.StoragePoolDetailVO;
2828
import org.apache.cloudstack.storage.datastore.db.StoragePoolDetailsDao;
@@ -36,9 +36,9 @@
3636
public class ScaleIOGatewayClientConnectionPool {
3737
protected Logger logger = LogManager.getLogger(getClass());
3838

39-
private ConcurrentHashMap<Long, ScaleIOGatewayClient> gatewayClients;
40-
39+
private Map<Long, ScaleIOGatewayClient> gatewayClients;
4140
private static final ScaleIOGatewayClientConnectionPool instance;
41+
private final Object lock = new Object();
4242

4343
static {
4444
instance = new ScaleIOGatewayClientConnectionPool();
@@ -49,69 +49,76 @@ public static ScaleIOGatewayClientConnectionPool getInstance() {
4949
}
5050

5151
private ScaleIOGatewayClientConnectionPool() {
52-
gatewayClients = new ConcurrentHashMap<Long, ScaleIOGatewayClient>();
52+
gatewayClients = new ConcurrentHashMap<>();
5353
}
5454

5555
public ScaleIOGatewayClient getClient(StoragePool storagePool,
56-
StoragePoolDetailsDao storagePoolDetailsDao)
57-
throws NoSuchAlgorithmException, KeyManagementException, URISyntaxException {
56+
StoragePoolDetailsDao storagePoolDetailsDao) {
5857
return getClient(storagePool.getId(), storagePool.getUuid(), storagePoolDetailsDao);
5958
}
6059

6160

6261
public ScaleIOGatewayClient getClient(DataStore dataStore,
63-
StoragePoolDetailsDao storagePoolDetailsDao)
64-
throws NoSuchAlgorithmException, KeyManagementException, URISyntaxException {
62+
StoragePoolDetailsDao storagePoolDetailsDao) {
6563
return getClient(dataStore.getId(), dataStore.getUuid(), storagePoolDetailsDao);
6664
}
6765

68-
6966
private ScaleIOGatewayClient getClient(Long storagePoolId, String storagePoolUuid,
70-
StoragePoolDetailsDao storagePoolDetailsDao)
71-
throws NoSuchAlgorithmException, KeyManagementException, URISyntaxException {
67+
StoragePoolDetailsDao storagePoolDetailsDao) {
7268

7369
Preconditions.checkArgument(storagePoolId != null && storagePoolId > 0,
7470
"Invalid storage pool id");
7571

76-
ScaleIOGatewayClient client = null;
77-
synchronized (gatewayClients) {
78-
client = gatewayClients.get(storagePoolId);
79-
if (client == null) {
80-
String url = null;
81-
StoragePoolDetailVO urlDetail = storagePoolDetailsDao.findDetail(storagePoolId, ScaleIOGatewayClient.GATEWAY_API_ENDPOINT);
82-
if (urlDetail != null) {
83-
url = urlDetail.getValue();
84-
}
85-
String username = null;
86-
StoragePoolDetailVO encryptedUsernameDetail = storagePoolDetailsDao.findDetail(storagePoolId, ScaleIOGatewayClient.GATEWAY_API_USERNAME);
87-
if (encryptedUsernameDetail != null) {
88-
final String encryptedUsername = encryptedUsernameDetail.getValue();
89-
username = DBEncryptionUtil.decrypt(encryptedUsername);
72+
logger.debug("Getting ScaleIO client for {} ({})", storagePoolId, storagePoolUuid);
73+
74+
ScaleIOGatewayClient client = gatewayClients.get(storagePoolId);
75+
if (client == null) {
76+
logger.debug("Before acquiring lock to create ScaleIO client for {} ({})", storagePoolId, storagePoolUuid);
77+
synchronized (lock) {
78+
logger.debug("Acquired lock to create ScaleIO client for {} ({})", storagePoolId, storagePoolUuid);
79+
client = gatewayClients.get(storagePoolId);
80+
if (client == null) {
81+
logger.debug("Initializing ScaleIO client for {} ({})", storagePoolId, storagePoolUuid);
82+
83+
String url = Optional.ofNullable(storagePoolDetailsDao.findDetail(storagePoolId, ScaleIOGatewayClient.GATEWAY_API_ENDPOINT))
84+
.map(StoragePoolDetailVO::getValue)
85+
.orElse(null);
86+
87+
String username = Optional.ofNullable(storagePoolDetailsDao.findDetail(storagePoolId, ScaleIOGatewayClient.GATEWAY_API_USERNAME))
88+
.map(StoragePoolDetailVO::getValue)
89+
.map(DBEncryptionUtil::decrypt)
90+
.orElse(null);
91+
92+
String password = Optional.ofNullable(storagePoolDetailsDao.findDetail(storagePoolId, ScaleIOGatewayClient.GATEWAY_API_PASSWORD))
93+
.map(StoragePoolDetailVO::getValue)
94+
.map(DBEncryptionUtil::decrypt)
95+
.orElse(null);
96+
97+
int clientTimeout = StorageManager.STORAGE_POOL_CLIENT_TIMEOUT.valueIn(storagePoolId);
98+
int clientMaxConnections = StorageManager.STORAGE_POOL_CLIENT_MAX_CONNECTIONS.valueIn(storagePoolId);
99+
100+
try {
101+
client = new ScaleIOGatewayClientImpl(url, username, password, false, clientTimeout, clientMaxConnections);
102+
logger.debug("Created ScaleIO client for the storage pool [id: {}, uuid: {}]", storagePoolId, storagePoolUuid);
103+
gatewayClients.put(storagePoolId, client);
104+
} catch (Exception e) {
105+
String msg = String.format("Failed to create ScaleIO client for the storage pool [id: %d, uuid: %s]", storagePoolId, storagePoolUuid);
106+
throw new CloudRuntimeException(msg, e);
107+
}
90108
}
91-
String password = null;
92-
StoragePoolDetailVO encryptedPasswordDetail = storagePoolDetailsDao.findDetail(storagePoolId, ScaleIOGatewayClient.GATEWAY_API_PASSWORD);
93-
if (encryptedPasswordDetail != null) {
94-
final String encryptedPassword = encryptedPasswordDetail.getValue();
95-
password = DBEncryptionUtil.decrypt(encryptedPassword);
96-
}
97-
final int clientTimeout = StorageManager.STORAGE_POOL_CLIENT_TIMEOUT.valueIn(storagePoolId);
98-
final int clientMaxConnections = StorageManager.STORAGE_POOL_CLIENT_MAX_CONNECTIONS.valueIn(storagePoolId);
99-
100-
client = new ScaleIOGatewayClientImpl(url, username, password, false, clientTimeout, clientMaxConnections);
101-
gatewayClients.put(storagePoolId, client);
102-
logger.debug("Added gateway client for the storage pool [id: {}, uuid: {}]", storagePoolId, storagePoolUuid);
103109
}
104110
}
105111

112+
logger.debug("Returning ScaleIO client for {} ({})", storagePoolId, storagePoolUuid);
106113
return client;
107114
}
108115

109116
public boolean removeClient(DataStore dataStore) {
110117
Preconditions.checkArgument(dataStore != null && dataStore.getId() > 0,
111118
"Invalid storage pool id");
112119

113-
ScaleIOGatewayClient client = null;
114-
synchronized (gatewayClients) {
120+
ScaleIOGatewayClient client;
121+
synchronized (lock) {
115122
client = gatewayClients.remove(dataStore.getId());
116123
}
117124

0 commit comments

Comments
 (0)