Skip to content

Commit f788f82

Browse files
committed
Improve logging to include more identifiable information for default volume storage plugin
1 parent 05a5ead commit f788f82

File tree

9 files changed

+46
-19
lines changed

9 files changed

+46
-19
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ public Class<?> getEntityType() {
283283

284284
@Override
285285
public String toString() {
286-
return String.format("Snapshot %s", new ToStringBuilder(this, ToStringStyle.JSON_STYLE).append("uuid", getUuid()).append("name", getName())
286+
return String.format("Snapshot %s", new ToStringBuilder(this, ToStringStyle.JSON_STYLE).append("id", getId()).append("uuid", getUuid()).append("name", getName())
287287
.append("volumeId", getVolumeId()).toString());
288288
}
289289
}

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

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

512512
@Override
513513
public String toString() {
514-
return String.format("StoragePool %s",
514+
return String.format("Volume %s",
515515
ReflectionToStringBuilderUtils.reflectOnlySelectedFields(
516516
this, "id", "name",
517-
"uuid", "volumeType", "instanceId", "path"));
517+
"uuid", "volumeType", "instanceId"));
518518
}
519519

520520
@Override

engine/schema/src/main/java/org/apache/cloudstack/storage/datastore/db/ImageStoreVO.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import com.cloud.storage.ScopeType;
3434
import com.cloud.utils.UriUtils;
3535
import com.cloud.utils.db.GenericDao;
36+
import org.apache.cloudstack.utils.reflectiontostringbuilderutils.ReflectionToStringBuilderUtils;
3637

3738
@Entity
3839
@Table(name = "image_store")
@@ -215,4 +216,11 @@ public Long getUsedBytes() {
215216
public void setUsedBytes(Long usedBytes) {
216217
this.usedBytes = usedBytes;
217218
}
219+
220+
@Override
221+
public String toString() {
222+
return String.format("ImageStoreVO %s",
223+
ReflectionToStringBuilderUtils.reflectOnlySelectedFields(
224+
this, "id", "name", "uuid"));
225+
}
218226
}

engine/storage/image/src/main/java/org/apache/cloudstack/storage/image/store/ImageStoreImpl.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,4 +228,9 @@ public Void createDataDiskTemplateAsync(TemplateInfo dataDiskTemplate, String pa
228228
return driver.createDataDiskTemplateAsync(dataDiskTemplate, path, diskId, bootable, fileSize, callback);
229229
}
230230

231+
@Override
232+
public String toString() {
233+
return imageDataStoreVO.toString();
234+
}
235+
231236
}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@
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;
4644
import org.apache.logging.log4j.Logger;
4745
import org.apache.logging.log4j.LogManager;
4846

@@ -471,7 +469,9 @@ public Class<?> getEntityType() {
471469

472470
@Override
473471
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());
472+
return "VolumeObject{" +
473+
"snapshotVO=" + getSnapshotVO() +
474+
", dataStore=" + getDataStore() +
475+
'}';
476476
}
477477
}

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

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

470470
@Override
471471
public String toString() {
472-
return ReflectionToStringBuilderUtils.reflectOnlySelectedFields(this,
472+
return ReflectionToStringBuilderUtils.reflectOnlySelectedFields(pdsv,
473473
"id", "name", "uuid");
474474
}
475475
}

engine/storage/volume/src/main/java/org/apache/cloudstack/storage/volume/VolumeObject.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -944,4 +944,12 @@ public boolean isDeleteProtection() {
944944
public boolean isFollowRedirects() {
945945
return followRedirects;
946946
}
947+
948+
@Override
949+
public String toString() {
950+
return "VolumeObject{" +
951+
"volumeVO=" + volumeVO +
952+
", dataStore=" + dataStore +
953+
'}';
954+
}
947955
}

plugins/storage/volume/default/src/main/java/org/apache/cloudstack/storage/datastore/driver/CloudStackPrimaryDataStoreDriverImpl.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -256,15 +256,20 @@ public void deleteAsync(DataStore dataStore, DataObject data, AsyncCompletionCal
256256
}
257257
}
258258
} catch (Exception ex) {
259-
logger.debug("Unable to destroy volume" + data.getId(), ex);
259+
logger.debug(String.format(
260+
"Unable to destroy volume [id: %d, uuid: %s]",
261+
data.getId(), data.getUuid()), ex);
260262
result.setResult(ex.toString());
261263
}
262264
callback.complete(result);
263265
}
264266

265267
@Override
266268
public void copyAsync(DataObject srcdata, DataObject destData, AsyncCompletionCallback<CopyCommandResult> callback) {
267-
logger.debug(String.format("Copying volume %s(%s) to %s(%s)", srcdata.getId(), srcdata.getType(), destData.getId(), destData.getType()));
269+
logger.debug(
270+
"Copying volume [id: {}, uuid: {}, type:{}] to [id: {} uuid: {}, type: {}]",
271+
srcdata.getId(), srcdata.getUuid(), srcdata.getType(),
272+
destData.getId(), destData.getUuid(), destData.getType());
268273
boolean encryptionRequired = anyVolumeRequiresEncryption(srcdata, destData);
269274
DataStore store = destData.getDataStore();
270275
if (store.getRole() == DataStoreRole.Primary) {
@@ -381,7 +386,7 @@ public void takeSnapshot(SnapshotInfo snapshot, AsyncCompletionCallback<CreateCm
381386
callback.complete(result);
382387
return;
383388
} catch (Exception e) {
384-
logger.debug("Failed to take snapshot: " + snapshot.getId(), e);
389+
logger.debug(String.format("Failed to take snapshot: %s", snapshot), e);
385390
result = new CreateCmdResult(null, null);
386391
result.setResult(e.toString());
387392
}
@@ -416,7 +421,7 @@ public void revertSnapshot(SnapshotInfo snapshot, SnapshotInfo snapshotOnPrimary
416421
}
417422
}
418423
} catch (Exception ex) {
419-
logger.debug("Unable to revert snapshot " + snapshot.getId(), ex);
424+
logger.debug(String.format("Unable to revert snapshot %s", snapshot), ex);
420425
result.setResult(ex.toString());
421426
}
422427
callback.complete(result);
@@ -476,7 +481,7 @@ private void updateVolumePathDetails(VolumeObject vol, ResizeVolumeAnswer answer
476481
if (storagePoolVO != null) {
477482
volumeVO.setPoolId(storagePoolVO.getId());
478483
} else {
479-
logger.warn(String.format("Unable to find datastore %s while updating the new datastore of the volume %d", datastoreUUID, vol.getId()));
484+
logger.warn("Unable to find datastore {} while updating the new datastore of the volume {}", datastoreUUID, vol);
480485
}
481486
}
482487

plugins/storage/volume/default/src/main/java/org/apache/cloudstack/storage/datastore/lifecycle/CloudStackPrimaryDataStoreLifeCycleImpl.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -335,16 +335,17 @@ private void validateVcenterDetails(Long zoneId, Long podId, Long clusterId, Str
335335
if (answer != null) {
336336
throw new InvalidParameterValueException("Provided vCenter server details does not match with the existing vCenter in zone id: " + zoneId);
337337
} else {
338-
String msg = "Can not validate vCenter through host " + h.getId() + " due to ValidateVcenterDetailsCommand returns null";
338+
String msg = "Can not validate vCenter through host " + h + " due to ValidateVcenterDetailsCommand returns null";
339339
logger.warn(msg);
340340
}
341341
}
342342
}
343343
throw new CloudRuntimeException("Could not validate vCenter details through any of the hosts with in zone: " + zoneId + ", pod: " + podId + ", cluster: " + clusterId);
344344
}
345345

346-
protected boolean createStoragePool(long hostId, StoragePool pool) {
347-
logger.debug("creating pool " + pool.getName() + " on host " + hostId);
346+
protected boolean createStoragePool(HostVO host, StoragePool pool) {
347+
long hostId = host.getId();
348+
logger.debug("creating pool {} on host {}", pool.getName(), host);
348349

349350
if (pool.getPoolType() != StoragePoolType.NetworkFilesystem && pool.getPoolType() != StoragePoolType.Filesystem &&
350351
pool.getPoolType() != StoragePoolType.IscsiLUN && pool.getPoolType() != StoragePoolType.Iscsi && pool.getPoolType() != StoragePoolType.VMFS &&
@@ -363,10 +364,10 @@ protected boolean createStoragePool(long hostId, StoragePool pool) {
363364
primaryDataStoreDao.expunge(pool.getId());
364365
String msg = "";
365366
if (answer != null) {
366-
msg = "Can not create storage pool through host " + hostId + " due to " + answer.getDetails();
367+
msg = "Can not create storage pool through host " + host + " due to " + answer.getDetails();
367368
logger.warn(msg);
368369
} else {
369-
msg = "Can not create storage pool through host " + hostId + " due to CreateStoragePoolCommand returns null";
370+
msg = "Can not create storage pool through host " + host + " due to CreateStoragePoolCommand returns null";
370371
logger.warn(msg);
371372
}
372373
throw new CloudRuntimeException(msg);
@@ -392,7 +393,7 @@ public boolean attachCluster(DataStore store, ClusterScope scope) {
392393

393394
boolean success = false;
394395
for (HostVO h : allHosts) {
395-
success = createStoragePool(h.getId(), primarystore);
396+
success = createStoragePool(h, primarystore);
396397
if (success) {
397398
break;
398399
}

0 commit comments

Comments
 (0)