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>
This commit is contained in:
SadiJr 2021-12-22 09:56:00 -03:00 committed by GitHub
parent 99313f8eae
commit 01f1aaee60
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 174 additions and 601 deletions

View File

@ -44,6 +44,7 @@ import com.cloud.agent.api.to.DataTO;
import com.cloud.agent.api.to.DiskTO; import com.cloud.agent.api.to.DiskTO;
import com.cloud.storage.DataStoreRole; import com.cloud.storage.DataStoreRole;
import com.cloud.storage.Volume; import com.cloud.storage.Volume;
import com.google.gson.Gson;
public class StorageSubsystemCommandHandlerBase implements StorageSubsystemCommandHandler { public class StorageSubsystemCommandHandlerBase implements StorageSubsystemCommandHandler {
private static final Logger s_logger = Logger.getLogger(StorageSubsystemCommandHandlerBase.class); private static final Logger s_logger = Logger.getLogger(StorageSubsystemCommandHandlerBase.class);
@ -55,6 +56,7 @@ public class StorageSubsystemCommandHandlerBase implements StorageSubsystemComma
@Override @Override
public Answer handleStorageCommands(StorageSubSystemCommand command) { public Answer handleStorageCommands(StorageSubSystemCommand command) {
logCommand(command);
if (command instanceof CopyCommand) { if (command instanceof CopyCommand) {
return this.execute((CopyCommand)command); return this.execute((CopyCommand)command);
} else if (command instanceof CreateObjectCommand) { } else if (command instanceof CreateObjectCommand) {
@ -170,4 +172,12 @@ public class StorageSubsystemCommandHandlerBase implements StorageSubsystemComma
return processor.dettachVolume(cmd); return processor.dettachVolume(cmd);
} }
} }
private void logCommand(Command cmd) {
try {
s_logger.debug(String.format("Executing command %s: [%s].", cmd.getClass().getSimpleName(), new Gson().toJson(cmd)));
} catch (Exception e) {
s_logger.debug(String.format("Executing command %s.", cmd.getClass().getSimpleName()));
}
}
} }

View File

@ -29,4 +29,6 @@ public interface VmwareHostService {
VmwareHypervisorHost getHyperHost(VmwareContext context, Command cmd); VmwareHypervisorHost getHyperHost(VmwareContext context, Command cmd);
String getWorkerName(VmwareContext context, Command cmd, int workerSequence, DatastoreMO dsMo) throws Exception; String getWorkerName(VmwareContext context, Command cmd, int workerSequence, DatastoreMO dsMo) throws Exception;
String createLogMessageException(Throwable e, Command command);
} }

View File

@ -21,7 +21,6 @@ import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.OutputStreamWriter; import java.io.OutputStreamWriter;
import java.rmi.RemoteException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
@ -85,7 +84,6 @@ import com.cloud.storage.Volume;
import com.cloud.storage.template.OVAProcessor; import com.cloud.storage.template.OVAProcessor;
import com.cloud.utils.NumbersUtil; import com.cloud.utils.NumbersUtil;
import com.cloud.utils.Pair; import com.cloud.utils.Pair;
import com.cloud.utils.StringUtils;
import com.cloud.utils.Ternary; import com.cloud.utils.Ternary;
import com.cloud.utils.exception.CloudRuntimeException; import com.cloud.utils.exception.CloudRuntimeException;
import com.cloud.utils.script.Script; import com.cloud.utils.script.Script;
@ -96,6 +94,7 @@ public class VmwareStorageManagerImpl implements VmwareStorageManager {
private String _nfsVersion; private String _nfsVersion;
@Override @Override
public boolean execute(VmwareHostService hostService, CreateEntityDownloadURLCommand cmd) { public boolean execute(VmwareHostService hostService, CreateEntityDownloadURLCommand cmd) {
DataTO data = cmd.getData(); DataTO data = cmd.getData();
@ -296,13 +295,7 @@ public class VmwareStorageManagerImpl implements VmwareStorageManager {
return new PrimaryStorageDownloadAnswer(templateUuidName, 0); return new PrimaryStorageDownloadAnswer(templateUuidName, 0);
} catch (Throwable e) { } catch (Throwable e) {
if (e instanceof RemoteException) { return new PrimaryStorageDownloadAnswer(hostService.createLogMessageException(e, cmd));
hostService.invalidateServiceContext(context);
}
String msg = "Unable to execute PrimaryStorageDownloadCommand due to exception";
s_logger.error(msg, e);
return new PrimaryStorageDownloadAnswer(msg);
} }
} }
@ -380,22 +373,14 @@ public class VmwareStorageManagerImpl implements VmwareStorageManager {
try { try {
if (workerVm != null) { if (workerVm != null) {
// detach volume and destroy worker vm
workerVm.detachAllDisksAndDestroy(); workerVm.detachAllDisksAndDestroy();
} }
} catch (Throwable e) { } catch (Throwable e) {
s_logger.warn("Failed to destroy worker VM: " + workerVMName); s_logger.warn(String.format("Failed to destroy worker VM [%s] due to: [%s].", workerVMName, e.getMessage()), e);
} }
} }
} catch (Throwable e) { } catch (Throwable e) {
if (e instanceof RemoteException) { return new BackupSnapshotAnswer(cmd, false, hostService.createLogMessageException(e, cmd), snapshotBackupUuid, true);
hostService.invalidateServiceContext(context);
}
s_logger.error("Unexpecpted exception ", e);
details = "BackupSnapshotCommand exception: " + StringUtils.getExceptionStackInfo(e);
return new BackupSnapshotAnswer(cmd, false, details, snapshotBackupUuid, true);
} }
return new BackupSnapshotAnswer(cmd, success, details, snapshotBackupUuid, true); return new BackupSnapshotAnswer(cmd, success, details, snapshotBackupUuid, true);
@ -433,14 +418,7 @@ public class VmwareStorageManagerImpl implements VmwareStorageManager {
return new CreatePrivateTemplateAnswer(cmd, true, null, result.first(), result.third(), result.second(), cmd.getUniqueName(), ImageFormat.OVA); return new CreatePrivateTemplateAnswer(cmd, true, null, result.first(), result.third(), result.second(), cmd.getUniqueName(), ImageFormat.OVA);
} catch (Throwable e) { } catch (Throwable e) {
if (e instanceof RemoteException) { return new CreatePrivateTemplateAnswer(cmd, false, hostService.createLogMessageException(e, cmd));
hostService.invalidateServiceContext(context);
}
s_logger.error("Unexpecpted exception ", e);
details = "CreatePrivateTemplateFromVolumeCommand exception: " + StringUtils.getExceptionStackInfo(e);
return new CreatePrivateTemplateAnswer(cmd, false, details);
} }
} }
@ -461,14 +439,7 @@ public class VmwareStorageManagerImpl implements VmwareStorageManager {
return new CreatePrivateTemplateAnswer(cmd, true, null, result.first(), result.third(), result.second(), uniqeName, ImageFormat.OVA); return new CreatePrivateTemplateAnswer(cmd, true, null, result.first(), result.third(), result.second(), uniqeName, ImageFormat.OVA);
} catch (Throwable e) { } catch (Throwable e) {
if (e instanceof RemoteException) { return new CreatePrivateTemplateAnswer(cmd, false, hostService.createLogMessageException(e, cmd));
hostService.invalidateServiceContext(context);
}
s_logger.error("Unexpecpted exception ", e);
details = "CreatePrivateTemplateFromSnapshotCommand exception: " + StringUtils.getExceptionStackInfo(e);
return new CreatePrivateTemplateAnswer(cmd, false, details);
} }
} }
@ -504,13 +475,7 @@ public class VmwareStorageManagerImpl implements VmwareStorageManager {
} }
return new CopyVolumeAnswer(cmd, true, null, result.first(), result.second()); return new CopyVolumeAnswer(cmd, true, null, result.first(), result.second());
} catch (Throwable e) { } catch (Throwable e) {
if (e instanceof RemoteException) { return new CopyVolumeAnswer(cmd, false, hostService.createLogMessageException(e, cmd), null, null);
hostService.invalidateServiceContext(context);
}
String msg = "Unable to execute CopyVolumeCommand due to exception";
s_logger.error(msg, e);
return new CopyVolumeAnswer(cmd, false, "CopyVolumeCommand failed due to exception: " + StringUtils.getExceptionStackInfo(e), null, null);
} }
} }
@ -543,12 +508,7 @@ public class VmwareStorageManagerImpl implements VmwareStorageManager {
success = true; success = true;
} }
} catch (Throwable e) { } catch (Throwable e) {
if (e instanceof RemoteException) { details = hostService.createLogMessageException(e, cmd);
hostService.invalidateServiceContext(context);
}
s_logger.error("Unexpecpted exception ", e);
details = "CreateVolumeFromSnapshotCommand exception: " + StringUtils.getExceptionStackInfo(e);
} }
return new CreateVolumeFromSnapshotAnswer(cmd, success, details, newVolumeName); return new CreateVolumeFromSnapshotAnswer(cmd, success, details, newVolumeName);
@ -946,8 +906,12 @@ public class VmwareStorageManagerImpl implements VmwareStorageManager {
Script command = new Script(false, "mkdir", _timeout, s_logger); Script command = new Script(false, "mkdir", _timeout, s_logger);
command.add("-p"); command.add("-p");
command.add(exportPath); command.add(exportPath);
if (command.execute() != null) {
throw new Exception("unable to prepare snapshot backup directory"); String result = command.execute();
if (result != null) {
String errorMessage = String.format("Unable to prepare snapshot backup directory: [%s] due to [%s].", exportPath, result);
s_logger.error(errorMessage);
throw new Exception(errorMessage);
} }
} }
} }
@ -968,7 +932,7 @@ public class VmwareStorageManagerImpl implements VmwareStorageManager {
vmMo.cloneFromCurrentSnapshot(workerVmName, 0, 4, volumeDeviceInfo.second(), VmwareHelper.getDiskDeviceDatastore(volumeDeviceInfo.first()), vmxFormattedVirtualHardwareVersion); vmMo.cloneFromCurrentSnapshot(workerVmName, 0, 4, volumeDeviceInfo.second(), VmwareHelper.getDiskDeviceDatastore(volumeDeviceInfo.first()), vmxFormattedVirtualHardwareVersion);
clonedVm = vmMo.getRunningHost().findVmOnHyperHost(workerVmName); clonedVm = vmMo.getRunningHost().findVmOnHyperHost(workerVmName);
if (clonedVm == null) { if (clonedVm == null) {
String msg = "Unable to create dummy VM to export volume. volume path: " + volumePath; String msg = String.format("Unable to create dummy VM to export volume. volume path: [%s].", volumePath);
s_logger.error(msg); s_logger.error(msg);
throw new Exception(msg); throw new Exception(msg);
} }
@ -1033,7 +997,6 @@ public class VmwareStorageManagerImpl implements VmwareStorageManager {
vmMo.removeSnapshot(exportName, false); vmMo.removeSnapshot(exportName, false);
} }
if (workerVm != null) { if (workerVm != null) {
//detach volume and destroy worker vm
workerVm.detachAllDisksAndDestroy(); workerVm.detachAllDisksAndDestroy();
} }
} }

View File

@ -47,6 +47,7 @@ import com.cloud.hypervisor.vmware.mo.VmwareHostType;
import com.cloud.hypervisor.vmware.mo.VmwareHypervisorHost; import com.cloud.hypervisor.vmware.mo.VmwareHypervisorHost;
import com.cloud.hypervisor.vmware.mo.VmwareHypervisorHostNetworkSummary; import com.cloud.hypervisor.vmware.mo.VmwareHypervisorHostNetworkSummary;
import com.cloud.hypervisor.vmware.util.VmwareContext; import com.cloud.hypervisor.vmware.util.VmwareContext;
import com.cloud.hypervisor.vmware.util.VmwareHelper;
import com.cloud.serializer.GsonHelper; import com.cloud.serializer.GsonHelper;
import com.cloud.utils.NumbersUtil; import com.cloud.utils.NumbersUtil;
import com.cloud.utils.Pair; import com.cloud.utils.Pair;
@ -96,9 +97,7 @@ public class VmwareSecondaryStorageResourceHandler implements SecondaryStorageRe
try { try {
Answer answer; Answer answer;
NDC.push(getCommandLogTitle(cmd)); NDC.push(getCommandLogTitle(cmd));
logCommand(cmd);
if (s_logger.isDebugEnabled())
s_logger.debug("Executing " + _gson.toJson(cmd));
if (cmd instanceof PrimaryStorageDownloadCommand) { if (cmd instanceof PrimaryStorageDownloadCommand) {
answer = execute((PrimaryStorageDownloadCommand)cmd); answer = execute((PrimaryStorageDownloadCommand)cmd);
@ -145,6 +144,14 @@ public class VmwareSecondaryStorageResourceHandler implements SecondaryStorageRe
} }
} }
private void logCommand(Command cmd) {
try {
s_logger.debug(String.format("Executing command: [%s].", _gson.toJson(cmd)));
} catch (Exception e) {
s_logger.debug(String.format("Executing command: [%s].", cmd.getClass().getSimpleName()));
}
}
protected Answer execute(CreateEntityDownloadURLCommand cmd) { protected Answer execute(CreateEntityDownloadURLCommand cmd) {
boolean success = _storageMgr.execute(this, cmd); boolean success = _storageMgr.execute(this, cmd);
if (success) { if (success) {
@ -311,4 +318,12 @@ public class VmwareSecondaryStorageResourceHandler implements SecondaryStorageRe
public String getMountPoint(String storageUrl, String nfsVersion) { public String getMountPoint(String storageUrl, String nfsVersion) {
return _resource.getRootDir(storageUrl, nfsVersion); return _resource.getRootDir(storageUrl, nfsVersion);
} }
@Override
public String createLogMessageException(Throwable e, Command command) {
String message = String.format("%s failed due to [%s].", command.getClass().getSimpleName(), VmwareHelper.getExceptionMessage(e));
s_logger.error(message, e);
return message;
}
} }

View File

@ -302,7 +302,7 @@ public class VmwareStorageProcessor implements StorageProcessor {
return answer; return answer;
} }
catch (Exception ex) { catch (Exception ex) {
s_logger.debug(ex.getMessage()); s_logger.error(String.format("Command %s failed due to: [%s].", cmd.getClass().getSimpleName(), ex.getMessage()), ex);
throw new CloudRuntimeException(ex.getMessage()); throw new CloudRuntimeException(ex.getMessage());
} }
@ -313,8 +313,8 @@ public class VmwareStorageProcessor implements StorageProcessor {
if (extents != null) { if (extents != null) {
for (HostUnresolvedVmfsExtent extent : extents) { for (HostUnresolvedVmfsExtent extent : extents) {
s_logger.debug("extent devicePath=" + extent.getDevicePath() + ", ordinal=" + extent.getOrdinal() s_logger.debug(String.format("HostUnresolvedVmfsExtent details: [devicePath: %s, ordinal: %s, reason: %s, isHeadExtent: %s].", extent.getDevicePath(),
+ ", reason=" + extent.getReason() + ", isHeadExtent=" + extent.isIsHeadExtent()); extent.getOrdinal(), extent.getReason(), extent.isIsHeadExtent()));
String extentDevicePath = extent.getDevicePath(); String extentDevicePath = extent.getDevicePath();
@ -380,6 +380,7 @@ public class VmwareStorageProcessor implements StorageProcessor {
* Returns the (potentially new) name of the VMDK file. * Returns the (potentially new) name of the VMDK file.
*/ */
private String cleanUpDatastore(Command cmd, HostDatastoreSystemMO hostDatastoreSystem, DatastoreMO dsMo, Map<String, String> details) throws Exception { private String cleanUpDatastore(Command cmd, HostDatastoreSystemMO hostDatastoreSystem, DatastoreMO dsMo, Map<String, String> details) throws Exception {
s_logger.debug(String.format("Executing clean up in DataStore: [%s].", dsMo.getName()));
boolean expandDatastore = Boolean.parseBoolean(details.get(DiskTO.EXPAND_DATASTORE)); boolean expandDatastore = Boolean.parseBoolean(details.get(DiskTO.EXPAND_DATASTORE));
// A volume on the storage system holding a template uses a minimum hypervisor snapshot reserve value. // A volume on the storage system holding a template uses a minimum hypervisor snapshot reserve value.
@ -488,11 +489,10 @@ public class VmwareStorageProcessor implements StorageProcessor {
private Pair<VirtualMachineMO, Long> copyTemplateFromSecondaryToPrimary(VmwareHypervisorHost hyperHost, DatastoreMO datastoreMo, String secondaryStorageUrl, private Pair<VirtualMachineMO, Long> copyTemplateFromSecondaryToPrimary(VmwareHypervisorHost hyperHost, DatastoreMO datastoreMo, String secondaryStorageUrl,
String templatePathAtSecondaryStorage, String templateName, String templateUuid, String templatePathAtSecondaryStorage, String templateName, String templateUuid,
boolean createSnapshot, String nfsVersion, String configuration) throws Exception { boolean createSnapshot, String nfsVersion, String configuration) throws Exception {
s_logger.info("Executing copyTemplateFromSecondaryToPrimary. secondaryStorage: " + secondaryStorageUrl + ", templatePathAtSecondaryStorage: " +
templatePathAtSecondaryStorage + ", templateName: " + templateName + ", configuration: " + configuration);
String secondaryMountPoint = mountService.getMountPoint(secondaryStorageUrl, nfsVersion); String secondaryMountPoint = mountService.getMountPoint(secondaryStorageUrl, nfsVersion);
s_logger.info("Secondary storage mount point: " + secondaryMountPoint);
s_logger.info(String.format("Init copy of template [name: %s, path in secondary storage: %s, configuration: %s] in secondary storage [url: %s, mount point: %s] to primary storage.",
templateName, templatePathAtSecondaryStorage, configuration, secondaryStorageUrl, secondaryMountPoint));
String srcOVAFileName = String srcOVAFileName =
VmwareStorageLayoutHelper.getTemplateOnSecStorageFilePath(secondaryMountPoint, templatePathAtSecondaryStorage, templateName, VmwareStorageLayoutHelper.getTemplateOnSecStorageFilePath(secondaryMountPoint, templatePathAtSecondaryStorage, templateName,
@ -525,9 +525,7 @@ public class VmwareStorageProcessor implements StorageProcessor {
} }
VmConfigInfo vAppConfig; VmConfigInfo vAppConfig;
if (s_logger.isDebugEnabled()) { s_logger.debug(String.format("Deploying OVF template %s with configuration %s.", templateName, configuration));
s_logger.debug(String.format("Deploying OVF template %s with configuration %s", templateName, configuration));
}
hyperHost.importVmFromOVF(srcFileName, templateUuid, datastoreMo, "thin", configuration); hyperHost.importVmFromOVF(srcFileName, templateUuid, datastoreMo, "thin", configuration);
VirtualMachineMO vmMo = hyperHost.findVmOnHyperHost(templateUuid); VirtualMachineMO vmMo = hyperHost.findVmOnHyperHost(templateUuid);
if (vmMo == null) { if (vmMo == null) {
@ -720,15 +718,7 @@ public class VmwareStorageProcessor implements StorageProcessor {
return new CopyCmdAnswer(newTemplate); return new CopyCmdAnswer(newTemplate);
} catch (Throwable e) { } catch (Throwable e) {
if (e instanceof RemoteException) { return new CopyCmdAnswer(hostService.createLogMessageException(e, cmd));
hostService.invalidateServiceContext(context);
}
String msg = "Unable to copy template to primary storage due to exception:" + VmwareHelper.getExceptionMessage(e);
s_logger.error(msg, e);
return new CopyCmdAnswer(msg);
} }
finally { finally {
if (dsMo != null && managedStoragePoolName != null) { if (dsMo != null && managedStoragePoolName != null) {
@ -818,7 +808,7 @@ public class VmwareStorageProcessor implements StorageProcessor {
VirtualMachineMO existingVm = dcMo.findVm(vmName); VirtualMachineMO existingVm = dcMo.findVm(vmName);
if (volume.getDeviceId().equals(0L)) { if (volume.getDeviceId().equals(0L)) {
if (existingVm != null) { if (existingVm != null) {
s_logger.info("Found existing VM " + vmName + " before cloning from template, destroying it"); s_logger.info(String.format("Found existing VM wth name [%s] before cloning from template, destroying it", vmName));
existingVm.detachAllDisksAndDestroy(); existingVm.detachAllDisksAndDestroy();
} }
s_logger.info("ROOT Volume from deploy-as-is template, cloning template"); s_logger.info("ROOT Volume from deploy-as-is template, cloning template");
@ -890,14 +880,7 @@ public class VmwareStorageProcessor implements StorageProcessor {
} }
return new CopyCmdAnswer(newVol); return new CopyCmdAnswer(newVol);
} catch (Throwable e) { } catch (Throwable e) {
if (e instanceof RemoteException) { return new CopyCmdAnswer(hostService.createLogMessageException(e, cmd));
s_logger.warn("Encounter remote exception to vCenter, invalidate VMware session context");
hostService.invalidateServiceContext(null);
}
String msg = "clone volume from base image failed due to " + VmwareHelper.getExceptionMessage(e);
s_logger.error(msg, e);
return new CopyCmdAnswer(e.toString());
} }
} }
@ -1074,13 +1057,7 @@ public class VmwareStorageProcessor implements StorageProcessor {
newVolume.setPath(result.second()); newVolume.setPath(result.second());
return new CopyCmdAnswer(newVolume); return new CopyCmdAnswer(newVolume);
} catch (Throwable t) { } catch (Throwable t) {
if (t instanceof RemoteException) { return new CopyCmdAnswer(hostService.createLogMessageException(t, cmd));
hostService.invalidateServiceContext(context);
}
String msg = "Unable to execute CopyVolumeCommand due to exception";
s_logger.error(msg, t);
return new CopyCmdAnswer("copy volume secondary to primary failed due to exception: " + VmwareHelper.getExceptionMessage(t));
} }
} }
@ -1135,7 +1112,6 @@ public class VmwareStorageProcessor implements StorageProcessor {
vmMo.removeSnapshot(exportName, false); vmMo.removeSnapshot(exportName, false);
} }
if (workerVm != null) { if (workerVm != null) {
//detach volume and destroy worker vm
workerVm.detachAllDisksAndDestroy(); workerVm.detachAllDisksAndDestroy();
} }
} }
@ -1162,13 +1138,7 @@ public class VmwareStorageProcessor implements StorageProcessor {
newVolume.setPath(result.first() + File.separator + result.second()); newVolume.setPath(result.first() + File.separator + result.second());
return new CopyCmdAnswer(newVolume); return new CopyCmdAnswer(newVolume);
} catch (Throwable e) { } catch (Throwable e) {
if (e instanceof RemoteException) { return new CopyCmdAnswer(hostService.createLogMessageException(e, cmd));
hostService.invalidateServiceContext(context);
}
String msg = "Unable to execute CopyVolumeCommand due to exception";
s_logger.error(msg, e);
return new CopyCmdAnswer("copy volume from primary to secondary failed due to exception: " + VmwareHelper.getExceptionMessage(e));
} }
} }
@ -1345,14 +1315,7 @@ public class VmwareStorageProcessor implements StorageProcessor {
return new CopyCmdAnswer(newTemplate); return new CopyCmdAnswer(newTemplate);
} catch (Throwable e) { } catch (Throwable e) {
if (e instanceof RemoteException) { return new CopyCmdAnswer(hostService.createLogMessageException(e, cmd));
hostService.invalidateServiceContext(context);
}
s_logger.error("Unexpecpted exception ", e);
details = "create template from volume exception: " + VmwareHelper.getExceptionMessage(e);
return new CopyCmdAnswer(details);
} finally { } finally {
try { try {
if (volume.getVmName() == null && workerVmMo != null) { if (volume.getVmName() == null && workerVmMo != null) {
@ -1780,15 +1743,7 @@ public class VmwareStorageProcessor implements StorageProcessor {
return new CopyCmdAnswer(newTemplate); return new CopyCmdAnswer(newTemplate);
} catch (Throwable e) { } catch (Throwable e) {
if (e instanceof RemoteException) { return new CopyCmdAnswer(hostService.createLogMessageException(e, cmd));
hostService.invalidateServiceContext(context);
}
s_logger.error("Unexpected exception ", e);
details = "create template from snapshot exception: " + VmwareHelper.getExceptionMessage(e);
return new CopyCmdAnswer(details);
} }
} }
@ -1804,8 +1759,11 @@ public class VmwareStorageProcessor implements StorageProcessor {
Script command = new Script(false, "mkdir", _timeout, s_logger); Script command = new Script(false, "mkdir", _timeout, s_logger);
command.add("-p"); command.add("-p");
command.add(exportPath); command.add(exportPath);
if (command.execute() != null) { String result = command.execute();
throw new Exception("unable to prepare snapshot backup directory"); if (result != null) {
String errorMessage = String.format("Unable to prepare snapshot backup directory: [%s] due to [%s].", exportPath, result);
s_logger.error(errorMessage);
throw new Exception(errorMessage);
} }
} }
} }
@ -1835,8 +1793,8 @@ public class VmwareStorageProcessor implements StorageProcessor {
} }
vmMo = clonedVm; vmMo = clonedVm;
} }
vmMo.exportVm(exportPath, exportName, false, false);
vmMo.exportVm(exportPath, exportName, false, false);
return new Pair<>(diskDevice, disks); return new Pair<>(diskDevice, disks);
} finally { } finally {
if (clonedVm != null) { if (clonedVm != null) {
@ -1921,6 +1879,7 @@ public class VmwareStorageProcessor implements StorageProcessor {
hasOwnerVm = true; hasOwnerVm = true;
} }
s_logger.debug(String.format("Executing backup snapshot with UUID [%s] to secondary storage.", snapshotUuid));
backupResult = backupResult =
backupSnapshotToSecondaryStorage(context, vmMo, hyperHost, destSnapshot.getPath(), srcSnapshot.getVolume().getPath(), snapshotUuid, secondaryStorageUrl, backupSnapshotToSecondaryStorage(context, vmMo, hyperHost, destSnapshot.getPath(), srcSnapshot.getVolume().getPath(), snapshotUuid, secondaryStorageUrl,
prevSnapshotUuid, prevBackupUuid, hostService.getWorkerName(context, cmd, 1, null), _nfsVersion); prevSnapshotUuid, prevBackupUuid, hostService.getWorkerName(context, cmd, 1, null), _nfsVersion);
@ -2009,24 +1968,16 @@ public class VmwareStorageProcessor implements StorageProcessor {
try { try {
if (workerVm != null) { if (workerVm != null) {
// detach volume and destroy worker vm
workerVm.detachAllDisksAndDestroy(); workerVm.detachAllDisksAndDestroy();
} }
} catch (Throwable e) { } catch (Throwable e) {
s_logger.warn("Failed to destroy worker VM: " + workerVMName); s_logger.warn(String.format("Failed to destroy worker VM [%s] due to: [%s]", workerVMName, e.getMessage()), e);
} }
} }
return answer; return answer;
} catch (Throwable e) { } catch (Throwable e) {
if (e instanceof RemoteException) { return new CopyCmdAnswer(hostService.createLogMessageException(e, cmd));
hostService.invalidateServiceContext(context);
}
s_logger.error("Unexpecpted exception ", e);
details = "backup snapshot exception: " + VmwareHelper.getExceptionMessage(e);
return new CopyCmdAnswer(details);
} }
} }
@ -2226,23 +2177,9 @@ public class VmwareStorageProcessor implements StorageProcessor {
return answer; return answer;
} catch (Throwable e) { } catch (Throwable e) {
if (e instanceof RemoteException) { String msg = String.format("Failed to %s volume!", isAttach? "attach" : "detach");
s_logger.warn("Encounter remote exception to vCenter, invalidate VMware session context"); s_logger.error(msg, e);
hostService.createLogMessageException(e, cmd);
hostService.invalidateServiceContext(null);
}
String msg = "";
if (isAttach) {
msg += "Failed to attach volume: ";
}
else {
msg += "Failed to detach volume: ";
}
s_logger.error(msg + e.getMessage(), e);
// Sending empty error message - too many duplicate errors in UI // Sending empty error message - too many duplicate errors in UI
return new AttachAnswer(""); return new AttachAnswer("");
} }
@ -2468,17 +2405,9 @@ public class VmwareStorageProcessor implements StorageProcessor {
hostService.invalidateServiceContext(null); hostService.invalidateServiceContext(null);
} }
if (isAttach) { String message = String.format("AttachIsoCommand(%s) failed due to: [%s]. Also check if your guest os is a supported version", isAttach? "attach" : "detach", VmwareHelper.getExceptionMessage(e));
String msg = "AttachIsoCommand(attach) failed due to " + VmwareHelper.getExceptionMessage(e); s_logger.error(message, e);
msg = msg + " Also check if your guest os is a supported version"; return new AttachAnswer(message);
s_logger.error(msg, e);
return new AttachAnswer(msg);
} else {
String msg = "AttachIsoCommand(detach) failed due to " + VmwareHelper.getExceptionMessage(e);
msg = msg + " Also check if your guest os is a supported version";
s_logger.warn(msg, e);
return new AttachAnswer(msg);
}
} }
} }
@ -2558,14 +2487,7 @@ public class VmwareStorageProcessor implements StorageProcessor {
} }
return new CreateObjectAnswer(newVol); return new CreateObjectAnswer(newVol);
} catch (Throwable e) { } catch (Throwable e) {
if (e instanceof RemoteException) { return new CreateObjectAnswer(hostService.createLogMessageException(e, cmd));
s_logger.warn("Encounter remote exception to vCenter, invalidate VMware session context");
hostService.invalidateServiceContext(null);
}
String msg = "create volume failed due to " + VmwareHelper.getExceptionMessage(e);
s_logger.error(msg, e);
return new CreateObjectAnswer(e.toString());
} }
} }
@ -2588,10 +2510,6 @@ public class VmwareStorageProcessor implements StorageProcessor {
@Override @Override
public Answer deleteVolume(DeleteCommand cmd) { public Answer deleteVolume(DeleteCommand cmd) {
if (s_logger.isInfoEnabled()) {
s_logger.info("Executing resource DeleteCommand: " + _gson.toJson(cmd));
}
try { try {
VmwareContext context = hostService.getServiceContext(null); VmwareContext context = hostService.getServiceContext(null);
VmwareHypervisorHost hyperHost = hostService.getHyperHost(context, null); VmwareHypervisorHost hyperHost = hostService.getHyperHost(context, null);
@ -2735,14 +2653,7 @@ public class VmwareStorageProcessor implements StorageProcessor {
return new Answer(cmd, true, "Success"); return new Answer(cmd, true, "Success");
} catch (Throwable e) { } catch (Throwable e) {
if (e instanceof RemoteException) { return new Answer(cmd, false, hostService.createLogMessageException(e, cmd));
s_logger.warn("Encounter remote exception to vCenter, invalidate VMware session context");
hostService.invalidateServiceContext(null);
}
String msg = "delete volume failed due to " + VmwareHelper.getExceptionMessage(e);
s_logger.error(msg, e);
return new Answer(cmd, false, msg);
} }
} }
@ -3816,12 +3727,8 @@ public class VmwareStorageProcessor implements StorageProcessor {
newVol.setPath(newVolumeName); newVol.setPath(newVolumeName);
return new CopyCmdAnswer(newVol); return new CopyCmdAnswer(newVol);
} catch (Throwable e) { } catch (Throwable e) {
if (e instanceof RemoteException) { hostService.createLogMessageException(e, cmd);
hostService.invalidateServiceContext(context); details = String.format("Failed to create volume from snapshot due to exception: [%s]", VmwareHelper.getExceptionMessage(e));
}
s_logger.error("Unexpecpted exception ", e);
details = "create volume from snapshot exception: " + VmwareHelper.getExceptionMessage(e);
} }
return new CopyCmdAnswer(details); return new CopyCmdAnswer(details);
} }
@ -3907,11 +3814,8 @@ public class VmwareStorageProcessor implements StorageProcessor {
else else
return new Answer(cmd, isDatastoreStoragePolicyComplaint, null); return new Answer(cmd, isDatastoreStoragePolicyComplaint, null);
} catch (Throwable e) { } catch (Throwable e) {
if (e instanceof RemoteException) { hostService.createLogMessageException(e, cmd);
hostService.invalidateServiceContext(context); String details = String.format("Exception while checking if datastore [%s] is storage policy [%s] complaince due to: [%s]", primaryStorageNameLabel, storagePolicyId, VmwareHelper.getExceptionMessage(e));
}
String details = String.format("Exception while checking if datastore %s is storage policy %s complaince : %s", primaryStorageNameLabel, storagePolicyId, VmwareHelper.getExceptionMessage(e));
s_logger.error(details, e);
return new Answer(cmd, false, details); return new Answer(cmd, false, details);
} }
} }
@ -4023,13 +3927,7 @@ public class VmwareStorageProcessor implements StorageProcessor {
return answer; return answer;
} catch (Throwable e) { } catch (Throwable e) {
if (e instanceof RemoteException) { return new SyncVolumePathAnswer(hostService.createLogMessageException(e, cmd));
s_logger.warn("Encounter remote exception to vCenter, invalidate VMware session context");
hostService.invalidateServiceContext(null);
}
return new SyncVolumePathAnswer("Failed to process SyncVolumePathCommand due to " + e.getMessage());
} }
} }
} }

View File

@ -127,6 +127,7 @@ import com.vmware.vim25.VirtualSCSISharing;
public class VirtualMachineMO extends BaseMO { public class VirtualMachineMO extends BaseMO {
private static final Logger s_logger = Logger.getLogger(VirtualMachineMO.class); private static final Logger s_logger = Logger.getLogger(VirtualMachineMO.class);
private static final ExecutorService MonitorServiceExecutor = Executors.newCachedThreadPool(new NamedThreadFactory("VM-Question-Monitor")); private static final ExecutorService MonitorServiceExecutor = Executors.newCachedThreadPool(new NamedThreadFactory("VM-Question-Monitor"));
private static final Gson GSON = new Gson();
public static final String ANSWER_YES = "0"; public static final String ANSWER_YES = "0";
public static final String ANSWER_NO = "1"; public static final String ANSWER_NO = "1";
@ -1402,7 +1403,7 @@ public class VirtualMachineMO extends BaseMO {
if(s_logger.isTraceEnabled()) if(s_logger.isTraceEnabled())
s_logger.trace("vCenter API trace - attachDisk(). target MOR: " + _mor.getValue() + ", vmdkDatastorePath: " s_logger.trace("vCenter API trace - attachDisk(). target MOR: " + _mor.getValue() + ", vmdkDatastorePath: "
+ new Gson().toJson(vmdkDatastorePathChain) + ", datastore: " + morDs.getValue()); + GSON.toJson(vmdkDatastorePathChain) + ", datastore: " + morDs.getValue());
int controllerKey = 0; int controllerKey = 0;
int unitNumber = 0; int unitNumber = 0;
@ -1800,7 +1801,7 @@ public class VirtualMachineMO extends BaseMO {
Pair<VmdkFileDescriptor, byte[]> result = new Pair<VmdkFileDescriptor, byte[]>(descriptor, content); Pair<VmdkFileDescriptor, byte[]> result = new Pair<VmdkFileDescriptor, byte[]>(descriptor, content);
if (s_logger.isTraceEnabled()) { if (s_logger.isTraceEnabled()) {
s_logger.trace("vCenter API trace - getVmdkFileInfo() done"); s_logger.trace("vCenter API trace - getVmdkFileInfo() done");
s_logger.trace("VMDK file descriptor: " + new Gson().toJson(result.first())); s_logger.trace("VMDK file descriptor: " + GSON.toJson(result.first()));
} }
return result; return result;
} }