Skip to content

Commit 05a5ead

Browse files
committed
Update logging for scaleio plugin
1 parent b8d91ef commit 05a5ead

File tree

13 files changed

+182
-113
lines changed

13 files changed

+182
-113
lines changed

engine/schema/src/main/java/com/cloud/storage/VolumeVO.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,10 @@ public void setUpdated(Date updated) {
511511

512512
@Override
513513
public String toString() {
514-
return String.format("StoragePool %s", ReflectionToStringBuilderUtils.reflectOnlySelectedFields(this, "id", "name", "uuid", "volumeType", "instanceId"));
514+
return String.format("StoragePool %s",
515+
ReflectionToStringBuilderUtils.reflectOnlySelectedFields(
516+
this, "id", "name",
517+
"uuid", "volumeType", "instanceId", "path"));
515518
}
516519

517520
@Override

engine/storage/snapshot/src/main/java/org/apache/cloudstack/storage/snapshot/SnapshotObject.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@
4141
import org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreDao;
4242
import org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreVO;
4343
import org.apache.cloudstack.storage.to.SnapshotObjectTO;
44+
import org.apache.commons.lang3.builder.ToStringBuilder;
45+
import org.apache.commons.lang3.builder.ToStringStyle;
4446
import org.apache.logging.log4j.Logger;
4547
import org.apache.logging.log4j.LogManager;
4648

@@ -466,4 +468,10 @@ public boolean delete() {
466468
public Class<?> getEntityType() {
467469
return Snapshot.class;
468470
}
471+
472+
@Override
473+
public String toString() {
474+
return String.format("Snapshot %s", new ToStringBuilder(this, ToStringStyle.JSON_STYLE).append("uuid", getUuid()).append("name", getName())
475+
.append("volumeId", getVolumeId()).append("path", getPath()).toString());
476+
}
469477
}

engine/storage/snapshot/src/main/java/org/apache/cloudstack/storage/vmsnapshot/ScaleIOVMSnapshotStrategy.java

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import javax.inject.Inject;
2727
import javax.naming.ConfigurationException;
2828

29+
import com.cloud.storage.StoragePool;
2930
import org.apache.cloudstack.engine.subsystem.api.storage.StrategyPriority;
3031
import org.apache.cloudstack.engine.subsystem.api.storage.VMSnapshotStrategy;
3132
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
@@ -162,8 +163,7 @@ public VMSnapshot takeVMSnapshot(VMSnapshot vmSnapshot) {
162163
Map<String, String> srcVolumeDestSnapshotMap = new HashMap<>();
163164
List<VolumeObjectTO> volumeTOs = vmSnapshotHelper.getVolumeTOList(userVm.getId());
164165

165-
final Long storagePoolId = vmSnapshotHelper.getStoragePoolForVM(userVm.getId());
166-
StoragePoolVO storagePool = storagePoolDao.findById(storagePoolId);
166+
StoragePoolVO storagePool = vmSnapshotHelper.getStoragePoolForVM(userVm.getId());
167167
long prev_chain_size = 0;
168168
long virtual_size=0;
169169
for (VolumeObjectTO volume : volumeTOs) {
@@ -188,7 +188,7 @@ public VMSnapshot takeVMSnapshot(VMSnapshot vmSnapshot) {
188188
vmSnapshotVO.setParent(current.getId());
189189

190190
try {
191-
final ScaleIOGatewayClient client = getScaleIOClient(storagePoolId);
191+
final ScaleIOGatewayClient client = getScaleIOClient(storagePool);
192192
SnapshotGroup snapshotGroup = client.takeSnapshot(srcVolumeDestSnapshotMap);
193193
if (snapshotGroup == null) {
194194
throw new CloudRuntimeException("Failed to take VM snapshot on PowerFlex storage pool");
@@ -291,7 +291,8 @@ public boolean revertVMSnapshot(VMSnapshot vmSnapshot) {
291291
boolean result = false;
292292
try {
293293
List<VolumeObjectTO> volumeTOs = vmSnapshotHelper.getVolumeTOList(userVm.getId());
294-
Long storagePoolId = vmSnapshotHelper.getStoragePoolForVM(userVm.getId());
294+
StoragePoolVO storagePool = vmSnapshotHelper.getStoragePoolForVM(userVm.getId());
295+
Long storagePoolId = storagePool.getId();
295296
Map<String, String> srcSnapshotDestVolumeMap = new HashMap<>();
296297
for (VolumeObjectTO volume : volumeTOs) {
297298
VMSnapshotDetailsVO vmSnapshotDetail = vmSnapshotDetailsDao.findDetail(vmSnapshotVO.getId(), "Vol_" + volume.getId() + "_Snapshot");
@@ -305,7 +306,7 @@ public boolean revertVMSnapshot(VMSnapshot vmSnapshot) {
305306
throw new CloudRuntimeException("Failed to get the system id for PowerFlex storage pool for reverting VM snapshot: " + vmSnapshot.getName());
306307
}
307308

308-
final ScaleIOGatewayClient client = getScaleIOClient(storagePoolId);
309+
final ScaleIOGatewayClient client = getScaleIOClient(storagePool);
309310
result = client.revertSnapshot(systemId, srcSnapshotDestVolumeMap);
310311
if (!result) {
311312
throw new CloudRuntimeException("Failed to revert VM snapshot on PowerFlex storage pool");
@@ -314,7 +315,7 @@ public boolean revertVMSnapshot(VMSnapshot vmSnapshot) {
314315
finalizeRevert(vmSnapshotVO, volumeTOs);
315316
result = true;
316317
} catch (Exception e) {
317-
String errMsg = "Revert VM: " + userVm.getInstanceName() + " to snapshot: " + vmSnapshotVO.getName() + " failed due to " + e.getMessage();
318+
String errMsg = String.format("Revert VM: %s to snapshot: %s failed due to %s", userVm, vmSnapshotVO, e.getMessage());
318319
logger.error(errMsg, e);
319320
throw new CloudRuntimeException(errMsg);
320321
} finally {
@@ -378,8 +379,8 @@ public boolean deleteVMSnapshot(VMSnapshot vmSnapshot) {
378379

379380
try {
380381
List<VolumeObjectTO> volumeTOs = vmSnapshotHelper.getVolumeTOList(vmSnapshot.getVmId());
381-
Long storagePoolId = vmSnapshotHelper.getStoragePoolForVM(userVm.getId());
382-
String systemId = storagePoolDetailsDao.findDetail(storagePoolId, ScaleIOGatewayClient.STORAGE_POOL_SYSTEM_ID).getValue();
382+
StoragePoolVO storagePool = vmSnapshotHelper.getStoragePoolForVM(userVm.getId());
383+
String systemId = storagePoolDetailsDao.findDetail(storagePool.getId(), ScaleIOGatewayClient.STORAGE_POOL_SYSTEM_ID).getValue();
383384
if (systemId == null) {
384385
throw new CloudRuntimeException("Failed to get the system id for PowerFlex storage pool for deleting VM snapshot: " + vmSnapshot.getName());
385386
}
@@ -390,7 +391,7 @@ public boolean deleteVMSnapshot(VMSnapshot vmSnapshot) {
390391
}
391392

392393
String snapshotGroupId = vmSnapshotDetailsVO.getValue();
393-
final ScaleIOGatewayClient client = getScaleIOClient(storagePoolId);
394+
final ScaleIOGatewayClient client = getScaleIOClient(storagePool);
394395
int volumesDeleted = client.deleteSnapshotGroup(systemId, snapshotGroupId);
395396
if (volumesDeleted <= 0) {
396397
throw new CloudRuntimeException("Failed to delete VM snapshot: " + vmSnapshot.getName());
@@ -509,7 +510,7 @@ private void publishUsageEvent(String type, VMSnapshot vmSnapshot, UserVm userVm
509510
}
510511
}
511512

512-
private ScaleIOGatewayClient getScaleIOClient(final Long storagePoolId) throws Exception {
513-
return ScaleIOGatewayClientConnectionPool.getInstance().getClient(storagePoolId, storagePoolDetailsDao);
513+
private ScaleIOGatewayClient getScaleIOClient(final StoragePool storagePool) throws Exception {
514+
return ScaleIOGatewayClientConnectionPool.getInstance().getClient(storagePool, storagePoolDetailsDao);
514515
}
515516
}

engine/storage/src/main/java/org/apache/cloudstack/storage/helper/VMSnapshotHelperImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ public VMSnapshotTO getSnapshotWithParents(VMSnapshotVO snapshot) {
150150
}
151151

152152
@Override
153-
public Long getStoragePoolForVM(Long vmId) {
153+
public StoragePoolVO getStoragePoolForVM(Long vmId) {
154154
List<VolumeVO> rootVolumes = volumeDao.findReadyRootVolumesByInstance(vmId);
155155
if (rootVolumes == null || rootVolumes.isEmpty()) {
156156
throw new InvalidParameterValueException("Failed to find root volume for the user vm:" + vmId);
@@ -166,7 +166,7 @@ public Long getStoragePoolForVM(Long vmId) {
166166
throw new InvalidParameterValueException("Storage pool for the user vm:" + vmId + " is in maintenance");
167167
}
168168

169-
return rootVolumePool.getId();
169+
return rootVolumePool;
170170
}
171171

172172
@Override

engine/storage/src/main/java/org/apache/cloudstack/storage/vmsnapshot/VMSnapshotHelper.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
import java.util.List;
2222

23+
import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
2324
import org.apache.cloudstack.storage.to.VolumeObjectTO;
2425

2526
import com.cloud.agent.api.VMSnapshotTO;
@@ -37,7 +38,7 @@ public interface VMSnapshotHelper {
3738

3839
VMSnapshotTO getSnapshotWithParents(VMSnapshotVO snapshot);
3940

40-
Long getStoragePoolForVM(Long vmId);
41+
StoragePoolVO getStoragePoolForVM(Long vmId);
4142

4243
Storage.StoragePoolType getStoragePoolType(Long poolId);
4344
}

engine/storage/volume/src/main/java/org/apache/cloudstack/storage/datastore/PrimaryDataStoreImpl.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,7 @@ public StoragePoolType getParentPoolType() {
469469

470470
@Override
471471
public String toString() {
472-
return ReflectionToStringBuilderUtils.reflectOnlySelectedFields(this, "name", "uuid");
472+
return ReflectionToStringBuilderUtils.reflectOnlySelectedFields(this,
473+
"id", "name", "uuid");
473474
}
474475
}

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

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
import java.security.NoSuchAlgorithmException;
2323
import java.util.concurrent.ConcurrentHashMap;
2424

25+
import com.cloud.storage.StoragePool;
26+
import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
2527
import org.apache.cloudstack.storage.datastore.db.StoragePoolDetailsDao;
2628
import org.apache.logging.log4j.Logger;
2729
import org.apache.logging.log4j.LogManager;
@@ -49,9 +51,26 @@ private ScaleIOGatewayClientConnectionPool() {
4951
gatewayClients = new ConcurrentHashMap<Long, ScaleIOGatewayClient>();
5052
}
5153

52-
public ScaleIOGatewayClient getClient(Long storagePoolId, StoragePoolDetailsDao storagePoolDetailsDao)
54+
public ScaleIOGatewayClient getClient(StoragePool storagePool,
55+
StoragePoolDetailsDao storagePoolDetailsDao)
5356
throws NoSuchAlgorithmException, KeyManagementException, URISyntaxException {
54-
Preconditions.checkArgument(storagePoolId != null && storagePoolId > 0, "Invalid storage pool id");
57+
return getClient(storagePool.getId(), storagePool.getUuid(), storagePoolDetailsDao);
58+
}
59+
60+
61+
public ScaleIOGatewayClient getClient(DataStore dataStore,
62+
StoragePoolDetailsDao storagePoolDetailsDao)
63+
throws NoSuchAlgorithmException, KeyManagementException, URISyntaxException {
64+
return getClient(dataStore.getId(), dataStore.getUuid(), storagePoolDetailsDao);
65+
}
66+
67+
68+
private ScaleIOGatewayClient getClient(Long storagePoolId, String storagePoolUuid,
69+
StoragePoolDetailsDao storagePoolDetailsDao)
70+
throws NoSuchAlgorithmException, KeyManagementException, URISyntaxException {
71+
72+
Preconditions.checkArgument(storagePoolId != null && storagePoolId > 0,
73+
"Invalid storage pool id");
5574

5675
ScaleIOGatewayClient client = null;
5776
synchronized (gatewayClients) {
@@ -67,23 +86,24 @@ public ScaleIOGatewayClient getClient(Long storagePoolId, StoragePoolDetailsDao
6786

6887
client = new ScaleIOGatewayClientImpl(url, username, password, false, clientTimeout, clientMaxConnections);
6988
gatewayClients.put(storagePoolId, client);
70-
logger.debug("Added gateway client for the storage pool: " + storagePoolId);
89+
logger.debug("Added gateway client for the storage pool [id: {}, uuid: {}]", storagePoolId, storagePoolUuid);
7190
}
7291
}
7392

7493
return client;
7594
}
7695

77-
public boolean removeClient(Long storagePoolId) {
78-
Preconditions.checkArgument(storagePoolId != null && storagePoolId > 0, "Invalid storage pool id");
96+
public boolean removeClient(DataStore dataStore) {
97+
Preconditions.checkArgument(dataStore != null && dataStore.getId() > 0,
98+
"Invalid storage pool id");
7999

80100
ScaleIOGatewayClient client = null;
81101
synchronized (gatewayClients) {
82-
client = gatewayClients.remove(storagePoolId);
102+
client = gatewayClients.remove(dataStore.getId());
83103
}
84104

85105
if (client != null) {
86-
logger.debug("Removed gateway client for the storage pool: " + storagePoolId);
106+
logger.debug("Removed gateway client for the storage pool: {}", dataStore);
87107
return true;
88108
}
89109

0 commit comments

Comments
 (0)