|
|
一、概览:
Vsphere的异常机制由两部分构成,一部分是它的API文档中指明的Fault Type类型(如下图所示):
几乎所有的在上图中显示的Fault Type,都有一个API文档中没有,但由JAX自动生成的FaultMsg异常类型。
范例如下图所示:
其中Fault Type是其对应的异常类的成员,如下图所示:
所以我们所接受到的所有异常,其实都只能由FaultMsg对象来抛出。
所有的Fault Type对象,都有一个共同的祖先:MethodFault类。
Name
Type
Description
dynamicProperty*
DynamicProperty[]
Set of dynamic properties. This property is optional because only the properties of an object that are unknown to a client will be part of this set. This property is not readonly just in case we want to send such properties from a client in the future.
dynamicType*
xsd:string
Reserved.
faultCause*
LocalizedMethodFault
Fault which is the cause of this fault.
Since vSphere API 4.0
faultMessage*
LocalizableMessage[]
Message which has details about the error Message can also contain a key to message catalogue which can be used to generate better localized messages.
Since vSphere API 4.0
二、实例:
我们可以执行的Task有两种,一种是以_Task后缀结尾的,另一种是没有_Task后缀结尾的。
其中以_Task后缀结尾的Task都可以抛出一系列异常,而这一系列异常可能包含有更详细的子异常。
以PowerOnVM_Task举例,API文档中指出它可以抛出如下异常:
Faults
Type
Description
DisallowedOperationOnFailoverHost
Thrown if the host specified is a failover host. See ClusterFailoverHostAdmissionControlPolicy.
FileFault
Thrown if there is a problem accessing the virtual machine on the filesystem.
InsufficientResourcesFault
Thrown if this operation would violate a resource usage policy.
InvalidPowerState
Thrown if the power state is poweredOn.
InvalidState
Thrown if the host is in maintenance mode or if the virtual machine's configuration information is not available.
NotEnoughLicenses
Thrown if there are not enough licenses to power on this virtual machine.
NotSupported
Thrown if the virtual machine is marked as a template.
RuntimeFault
Thrown if any type of runtime fault is thrown that is not covered by the other faults; for example, a communication error.
TaskInProgress
Thrown if the virtual machine is busy.
VmConfigFault
Thrown if a configuration issue prevents the power-on. Typically, a more specific fault, such as UnsupportedVmxLocation, is thrown.
其中的FileFault类又被如下类所继承:
Fault - FileFault
Extended by
CannotAccessFile, CannotCreateFile, CannotDeleteFile, DirectoryNotEmpty, FileAlreadyExists, FileLocked, FileNameTooLong, FileNotFound, FileNotWritable, FileTooLarge, IncorrectFileType, NetworkCopyFault, NoDiskSpace, NotADirectory, NotAFile, TooManyConcurrentNativeClones, TooManyNativeCloneLevels, TooManyNativeClonesOnFile
又被如下Task抛出:
Thrown by
ChangeFileAttributesInGuest, ChangeOwner, CloneVApp_Task, CloneVM_Task, ConsolidateVMDisks_Task, CopyDatastoreFile_Task, CopyVirtualDisk_Task, CreateChildVM_Task, CreateDescriptor, CreateImportSpec, CreateScreenshot_Task, CreateSecondaryVM_Task, CreateSnapshot_Task, CreateTemporaryDirectoryInGuest, CreateTemporaryFileInGuest, CreateVirtualDisk_Task, CreateVM_Task, DefragmentAllDisks, DefragmentVirtualDisk_Task, DeleteDatastoreFile_Task, DeleteDirectory, DeleteDirectoryInGuest, DeleteFile, DeleteFileInGuest, DeleteVirtualDisk_Task, EagerZeroVirtualDisk_Task, EstimateStorageForConsolidateSnapshots_Task, ExportSnapshot, ExportVApp, ExportVm, ExtendVirtualDisk_Task, ImportVApp, InflateVirtualDisk_Task, InitiateFileTransferFromGuest, InitiateFileTransferToGuest, ListFilesInGuest, MakeDirectory, MakeDirectoryInGuest, MarkAsTemplate, MarkAsVirtualMachine, MigrateVM_Task, MoveDatastoreFile_Task, MoveDirectoryInGuest, MoveFileInGuest, MoveVirtualDisk_Task, ParseDescriptor, PowerOnVApp_Task, PowerOnVM_Task, QueryChangedDiskAreas, QueryVirtualDiskFragmentation, QueryVirtualDiskGeometry, QueryVirtualDiskUuid, ReconfigVM_Task, RegisterChildVM_Task, RegisterVM_Task, reloadVirtualMachineFromPath_Task, RelocateVM_Task, RestoreFirmwareConfiguration, RevertToSnapshot_Task, SearchDatastore_Task, SearchDatastoreSubFolders_Task, SetVirtualDiskUuid, ShrinkVirtualDisk_Task, StartProgramInGuest, StartRecording_Task, StartReplaying_Task, StopRecording_Task, StopReplaying_Task, UpdateVAppConfig, ValidateHost, ZeroFillVirtualDisk_Task
我们可以看到里面明确将Task分为两类,
一类以_Task后缀结尾,这一类Task抛出的异常,我们不仅可以在Client中监控到:
也可以在控制台中输出:
javax.xml.ws.soap.SOAPFaultException: 指定的参数错误。
而第二个任务,则只能在控制台中输出,不能在Client中监测到。但是否被记入Vcenter的数据库,目前尚不清楚。
对于实际的后台代码编写,建议对于异常的捕获,只用做到子节点这一级别。如果的确是对详细的报错信息有需求,再做到孙子节点这一级别也可以。
注意:
Client对于异常的捕获,是有优先级的,例如:若同时出现任务重名、参数错误两种异常,则优先输出参数错误的异常。
csdn不能直接复制图片,一张张粘贴工作量太多,我醉了。不传图片了。
版权声明:本文为博主原创文章,未经博主允许不得转载。 |
|