Skip to content

Commit 01f1aae

Browse files
SadiJrSadiJrSadiJr
authored
Improve VMWare logs (#5353)
* Improve VMWare logs * Address reviews * Address reviews and add more logs * Improve VMWare logs * Address reviews * Address reviews and add more logs * Address reviews * Address reviews * Try fix tests * Refactor some logs to try fix tests * Verifying if GSON is the cause of test exceptions * Fix checkstyle Co-authored-by: SadiJr <17a0db2854@firemailbox.club> Co-authored-by: SadiJr <sadi@scclouds.com.br>
1 parent 99313f8 commit 01f1aae

7 files changed

Lines changed: 174 additions & 601 deletions

File tree

core/src/main/java/com/cloud/storage/resource/StorageSubsystemCommandHandlerBase.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import com.cloud.agent.api.to.DiskTO;
4545
import com.cloud.storage.DataStoreRole;
4646
import com.cloud.storage.Volume;
47+
import com.google.gson.Gson;
4748

4849
public class StorageSubsystemCommandHandlerBase implements StorageSubsystemCommandHandler {
4950
private static final Logger s_logger = Logger.getLogger(StorageSubsystemCommandHandlerBase.class);
@@ -55,6 +56,7 @@ public StorageSubsystemCommandHandlerBase(StorageProcessor processor) {
5556

5657
@Override
5758
public Answer handleStorageCommands(StorageSubSystemCommand command) {
59+
logCommand(command);
5860
if (command instanceof CopyCommand) {
5961
return this.execute((CopyCommand)command);
6062
} else if (command instanceof CreateObjectCommand) {
@@ -170,4 +172,12 @@ protected Answer execute(DettachCommand cmd) {
170172
return processor.dettachVolume(cmd);
171173
}
172174
}
175+
176+
private void logCommand(Command cmd) {
177+
try {
178+
s_logger.debug(String.format("Executing command %s: [%s].", cmd.getClass().getSimpleName(), new Gson().toJson(cmd)));
179+
} catch (Exception e) {
180+
s_logger.debug(String.format("Executing command %s.", cmd.getClass().getSimpleName()));
181+
}
182+
}
173183
}

plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/manager/VmwareHostService.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,6 @@ public interface VmwareHostService {
2929
VmwareHypervisorHost getHyperHost(VmwareContext context, Command cmd);
3030

3131
String getWorkerName(VmwareContext context, Command cmd, int workerSequence, DatastoreMO dsMo) throws Exception;
32+
33+
String createLogMessageException(Throwable e, Command command);
3234
}

plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/manager/VmwareStorageManagerImpl.java

Lines changed: 15 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import java.io.FileInputStream;
2222
import java.io.FileOutputStream;
2323
import java.io.OutputStreamWriter;
24-
import java.rmi.RemoteException;
2524
import java.util.ArrayList;
2625
import java.util.HashMap;
2726
import java.util.List;
@@ -85,7 +84,6 @@
8584
import com.cloud.storage.template.OVAProcessor;
8685
import com.cloud.utils.NumbersUtil;
8786
import com.cloud.utils.Pair;
88-
import com.cloud.utils.StringUtils;
8987
import com.cloud.utils.Ternary;
9088
import com.cloud.utils.exception.CloudRuntimeException;
9189
import com.cloud.utils.script.Script;
@@ -96,6 +94,7 @@ public class VmwareStorageManagerImpl implements VmwareStorageManager {
9694

9795
private String _nfsVersion;
9896

97+
9998
@Override
10099
public boolean execute(VmwareHostService hostService, CreateEntityDownloadURLCommand cmd) {
101100
DataTO data = cmd.getData();
@@ -296,13 +295,7 @@ public Answer execute(VmwareHostService hostService, PrimaryStorageDownloadComma
296295

297296
return new PrimaryStorageDownloadAnswer(templateUuidName, 0);
298297
} catch (Throwable e) {
299-
if (e instanceof RemoteException) {
300-
hostService.invalidateServiceContext(context);
301-
}
302-
303-
String msg = "Unable to execute PrimaryStorageDownloadCommand due to exception";
304-
s_logger.error(msg, e);
305-
return new PrimaryStorageDownloadAnswer(msg);
298+
return new PrimaryStorageDownloadAnswer(hostService.createLogMessageException(e, cmd));
306299
}
307300
}
308301

@@ -380,22 +373,14 @@ public Answer execute(VmwareHostService hostService, BackupSnapshotCommand cmd)
380373

381374
try {
382375
if (workerVm != null) {
383-
// detach volume and destroy worker vm
384376
workerVm.detachAllDisksAndDestroy();
385377
}
386378
} catch (Throwable e) {
387-
s_logger.warn("Failed to destroy worker VM: " + workerVMName);
379+
s_logger.warn(String.format("Failed to destroy worker VM [%s] due to: [%s].", workerVMName, e.getMessage()), e);
388380
}
389381
}
390382
} catch (Throwable e) {
391-
if (e instanceof RemoteException) {
392-
hostService.invalidateServiceContext(context);
393-
}
394-
395-
s_logger.error("Unexpecpted exception ", e);
396-
397-
details = "BackupSnapshotCommand exception: " + StringUtils.getExceptionStackInfo(e);
398-
return new BackupSnapshotAnswer(cmd, false, details, snapshotBackupUuid, true);
383+
return new BackupSnapshotAnswer(cmd, false, hostService.createLogMessageException(e, cmd), snapshotBackupUuid, true);
399384
}
400385

401386
return new BackupSnapshotAnswer(cmd, success, details, snapshotBackupUuid, true);
@@ -433,14 +418,7 @@ public Answer execute(VmwareHostService hostService, CreatePrivateTemplateFromVo
433418
return new CreatePrivateTemplateAnswer(cmd, true, null, result.first(), result.third(), result.second(), cmd.getUniqueName(), ImageFormat.OVA);
434419

435420
} catch (Throwable e) {
436-
if (e instanceof RemoteException) {
437-
hostService.invalidateServiceContext(context);
438-
}
439-
440-
s_logger.error("Unexpecpted exception ", e);
441-
442-
details = "CreatePrivateTemplateFromVolumeCommand exception: " + StringUtils.getExceptionStackInfo(e);
443-
return new CreatePrivateTemplateAnswer(cmd, false, details);
421+
return new CreatePrivateTemplateAnswer(cmd, false, hostService.createLogMessageException(e, cmd));
444422
}
445423
}
446424

@@ -461,14 +439,7 @@ public Answer execute(VmwareHostService hostService, CreatePrivateTemplateFromSn
461439

462440
return new CreatePrivateTemplateAnswer(cmd, true, null, result.first(), result.third(), result.second(), uniqeName, ImageFormat.OVA);
463441
} catch (Throwable e) {
464-
if (e instanceof RemoteException) {
465-
hostService.invalidateServiceContext(context);
466-
}
467-
468-
s_logger.error("Unexpecpted exception ", e);
469-
470-
details = "CreatePrivateTemplateFromSnapshotCommand exception: " + StringUtils.getExceptionStackInfo(e);
471-
return new CreatePrivateTemplateAnswer(cmd, false, details);
442+
return new CreatePrivateTemplateAnswer(cmd, false, hostService.createLogMessageException(e, cmd));
472443
}
473444
}
474445

@@ -504,13 +475,7 @@ public Answer execute(VmwareHostService hostService, CopyVolumeCommand cmd) {
504475
}
505476
return new CopyVolumeAnswer(cmd, true, null, result.first(), result.second());
506477
} catch (Throwable e) {
507-
if (e instanceof RemoteException) {
508-
hostService.invalidateServiceContext(context);
509-
}
510-
511-
String msg = "Unable to execute CopyVolumeCommand due to exception";
512-
s_logger.error(msg, e);
513-
return new CopyVolumeAnswer(cmd, false, "CopyVolumeCommand failed due to exception: " + StringUtils.getExceptionStackInfo(e), null, null);
478+
return new CopyVolumeAnswer(cmd, false, hostService.createLogMessageException(e, cmd), null, null);
514479
}
515480
}
516481

@@ -543,12 +508,7 @@ public Answer execute(VmwareHostService hostService, CreateVolumeFromSnapshotCom
543508
success = true;
544509
}
545510
} catch (Throwable e) {
546-
if (e instanceof RemoteException) {
547-
hostService.invalidateServiceContext(context);
548-
}
549-
550-
s_logger.error("Unexpecpted exception ", e);
551-
details = "CreateVolumeFromSnapshotCommand exception: " + StringUtils.getExceptionStackInfo(e);
511+
details = hostService.createLogMessageException(e, cmd);
552512
}
553513

554514
return new CreateVolumeFromSnapshotAnswer(cmd, success, details, newVolumeName);
@@ -946,8 +906,12 @@ private void exportVolumeToSecondaryStorage(VirtualMachineMO vmMo, String volume
946906
Script command = new Script(false, "mkdir", _timeout, s_logger);
947907
command.add("-p");
948908
command.add(exportPath);
949-
if (command.execute() != null) {
950-
throw new Exception("unable to prepare snapshot backup directory");
909+
910+
String result = command.execute();
911+
if (result != null) {
912+
String errorMessage = String.format("Unable to prepare snapshot backup directory: [%s] due to [%s].", exportPath, result);
913+
s_logger.error(errorMessage);
914+
throw new Exception(errorMessage);
951915
}
952916
}
953917
}
@@ -968,7 +932,7 @@ private void exportVolumeToSecondaryStorage(VirtualMachineMO vmMo, String volume
968932
vmMo.cloneFromCurrentSnapshot(workerVmName, 0, 4, volumeDeviceInfo.second(), VmwareHelper.getDiskDeviceDatastore(volumeDeviceInfo.first()), vmxFormattedVirtualHardwareVersion);
969933
clonedVm = vmMo.getRunningHost().findVmOnHyperHost(workerVmName);
970934
if (clonedVm == null) {
971-
String msg = "Unable to create dummy VM to export volume. volume path: " + volumePath;
935+
String msg = String.format("Unable to create dummy VM to export volume. volume path: [%s].", volumePath);
972936
s_logger.error(msg);
973937
throw new Exception(msg);
974938
}
@@ -1033,7 +997,6 @@ private Pair<String, String> copyVolumeToSecStorage(VmwareHostService hostServic
1033997
vmMo.removeSnapshot(exportName, false);
1034998
}
1035999
if (workerVm != null) {
1036-
//detach volume and destroy worker vm
10371000
workerVm.detachAllDisksAndDestroy();
10381001
}
10391002
}

0 commit comments

Comments
 (0)