本文整理汇总了Java中com.vmware.vim25.TaskInfoState类的典型用法代码示例。如果您正苦于以下问题:Java TaskInfoState类的具体用法?Java TaskInfoState怎么用?Java TaskInfoState使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
TaskInfoState类属于com.vmware.vim25包,在下文中一共展示了TaskInfoState类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: detachDiskFromVM
import com.vmware.vim25.TaskInfoState; //导入依赖的package包/类
public void detachDiskFromVM() throws Exception {
ArrayOfVirtualDevice devices = this.get
.entityProp(this.vm, VimPath.vm_config_hardware_device);
VirtualDisk vd = (VirtualDisk) findMatchingVirtualDevice(getListOfVirtualDisk(devices));
if (vd == null) {
throw new IllegalStateException(
String.format(
"Matching Virtual Disk is not for disk %s.",
this.diskState.documentSelfLink));
}
// Detach the disk from VM.
VirtualDeviceConfigSpec deviceConfigSpec = new VirtualDeviceConfigSpec();
deviceConfigSpec.setOperation(VirtualDeviceConfigSpecOperation.REMOVE);
deviceConfigSpec.setDevice(vd);
VirtualMachineConfigSpec spec = new VirtualMachineConfigSpec();
spec.getDeviceChange().add(deviceConfigSpec);
ManagedObjectReference reconfigureTask = getVimPort().reconfigVMTask(this.vm, spec);
TaskInfo info = VimUtils.waitTaskEnd(this.connection, reconfigureTask);
if (info.getState() == TaskInfoState.ERROR) {
VimUtils.rethrow(info.getError());
}
}
示例2: getTaskResultAfterDone
import com.vmware.vim25.TaskInfoState; //导入依赖的package包/类
/**
* This method returns a boolean value specifying whether the Task is
* succeeded or failed.
*
* @param task
* ManagedObjectReference representing the Task.
* @return boolean value representing the Task result.
* @throws InvalidCollectorVersionFaultMsg
*
* @throws RuntimeFaultFaultMsg
* @throws InvalidPropertyFaultMsg
*/
public boolean getTaskResultAfterDone(ManagedObjectReference task)
throws InvalidPropertyFaultMsg, RuntimeFaultFaultMsg,
InvalidCollectorVersionFaultMsg {
boolean retVal = false;
// info has a property - state for state of the task
Object[] result = wait(task,
new String[] { "info.state", "info.error" },
new String[] { "state" }, new Object[][] { new Object[] {
TaskInfoState.SUCCESS, TaskInfoState.ERROR } });
if (result[0].equals(TaskInfoState.SUCCESS)) {
retVal = true;
}
if (result[1] instanceof LocalizedMethodFault) {
throw new RuntimeException(
((LocalizedMethodFault) result[1]).getLocalizedMessage());
}
return retVal;
}
示例3: waitForTask
import com.vmware.vim25.TaskInfoState; //导入依赖的package包/类
public static boolean waitForTask(VMwareConnection connection, ManagedObjectReference task) throws Exception {
try {
Object[] result = waitForValues(connection, task, new String[] { "info.state", "info.error" }, new String[] { "state" },
new Object[][] { new Object[] { TaskInfoState.SUCCESS, TaskInfoState.ERROR } });
if (result[0].equals(TaskInfoState.SUCCESS)) {
return true;
}
if (result[1] instanceof LocalizedMethodFault) {
throw new Exception(((LocalizedMethodFault)result[1]).getLocalizedMessage());
}
} catch (WebServiceException we) {
s_logger.debug("Cancelling vCenter task because the task failed with the following error: " + we.getLocalizedMessage());
connection.getVimPortType().cancelTask(task);
throw new Exception("The vCenter task failed due to the following error: " + we.getLocalizedMessage());
}
return false;
}
示例4: logTaskInfo
import com.vmware.vim25.TaskInfoState; //导入依赖的package包/类
private void logTaskInfo(TaskInfo info) {
if (info == null) {
logger.debug("Deleted task info key");
return;
}
TaskInfoState state = info.getState();
Integer progress = info.getProgress();
if (state == TaskInfoState.SUCCESS) {
progress = Integer.valueOf(100);
} else if (progress == null) {
progress = Integer.valueOf(0);
}
LocalizableMessage desc = info.getDescription();
String description = desc != null ? desc.getMessage() : "";
XMLGregorianCalendar queueT = info.getQueueTime();
String queueTime = queueT != null
? queueT.toGregorianCalendar().getTime().toString() : "";
XMLGregorianCalendar startT = info.getStartTime();
String startTime = startT != null
? startT.toGregorianCalendar().getTime().toString() : "";
XMLGregorianCalendar completeT = info.getCompleteTime();
String completeTime = completeT != null
? completeT.toGregorianCalendar().getTime().toString() : "";
logger.debug("Save task info key: " + info.getKey() + " name: "
+ info.getName() + " target: " + info.getEntityName()
+ " state: " + state.name() + " progress: " + progress
+ "% description: " + description + " queue-time: " + queueTime
+ " start-time: " + startTime + " complete-time: "
+ completeTime);
}
示例5: powerOffVM
import com.vmware.vim25.TaskInfoState; //导入依赖的package包/类
/**
* Power off virtual machine
*/
public static void powerOffVM(final Connection connection, final VimPortType vimPort,
final ManagedObjectReference vm) throws Exception {
ManagedObjectReference powerTask = vimPort.powerOffVMTask(vm);
TaskInfo info = VimUtils.waitTaskEnd(connection, powerTask);
if (info.getState() == TaskInfoState.ERROR) {
VimUtils.rethrow(info.getError());
}
}
示例6: powerOnVM
import com.vmware.vim25.TaskInfoState; //导入依赖的package包/类
/**
* Power on virtual machine
*/
public static void powerOnVM(final Connection connection, final VimPortType vimPort,
final ManagedObjectReference vm) throws Exception {
ManagedObjectReference powerTask = vimPort.powerOnVMTask(vm, null);
TaskInfo info = VimUtils.waitTaskEnd(connection, powerTask);
if (info.getState() == TaskInfoState.ERROR) {
VimUtils.rethrow(info.getError());
}
}
示例7: reconfigureBootDisk
import com.vmware.vim25.TaskInfoState; //导入依赖的package包/类
/**
* Reconfigure image disk with the customizations
*/
private void reconfigureBootDisk(ManagedObjectReference vmMoref,
List<VirtualDeviceConfigSpec> deviceConfigSpecs) throws Exception {
if (deviceConfigSpecs != null && !deviceConfigSpecs.isEmpty()) {
VirtualMachineConfigSpec bootDiskSpec = new VirtualMachineConfigSpec();
bootDiskSpec.getDeviceChange().addAll(deviceConfigSpecs);
ManagedObjectReference task = getVimPort().reconfigVMTask(vmMoref, bootDiskSpec);
TaskInfo info = waitTaskEnd(task);
if (info.getState() == TaskInfoState.ERROR) {
VimUtils.rethrow(info.getError());
}
}
}
示例8: createVirtualDisk
import com.vmware.vim25.TaskInfoState; //导入依赖的package包/类
/**
* Create Virtual Disk
*/
public void createVirtualDisk() throws Exception {
ManagedObjectReference diskManager = this.connection.getServiceContent()
.getVirtualDiskManager();
List<VirtualMachineDefinedProfileSpec> pbmSpec = getPbmProfileSpec(this.diskState);
String dsName = this.diskContext.datastoreName != null && !this.diskContext.datastoreName
.isEmpty() ? this.diskContext.datastoreName : ClientUtils.getDefaultDatastore(this.finder);
String diskName = getUniqueDiskName();
// Create the parent folder before creation of the disk file
String parentDir = String.format(VM_PATH_FORMAT, dsName, diskName);
createParentFolder(parentDir);
String diskFullPath = constructDiskFullPath(dsName, diskName);
ManagedObjectReference createTask = getVimPort().createVirtualDiskTask(diskManager,
diskFullPath, this.diskContext.datacenterMoRef,
createVirtualDiskSpec(this.diskState, pbmSpec));
TaskInfo info = waitTaskEnd(createTask);
if (info.getState() == TaskInfoState.ERROR) {
VimUtils.rethrow(info.getError());
}
// Update the details of the disk
CustomProperties.of(this.diskState)
.put(DISK_FULL_PATH, diskFullPath)
.put(DISK_PARENT_DIRECTORY, parentDir)
.put(DISK_DATASTORE_NAME, dsName);
this.diskState.status = DiskService.DiskStatus.AVAILABLE;
this.diskState.id = diskName;
}
示例9: deleteVirtualDisk
import com.vmware.vim25.TaskInfoState; //导入依赖的package包/类
/**
* Delete Virtual disk.
*/
public void deleteVirtualDisk()
throws Exception {
ManagedObjectReference diskManager = this.connection.getServiceContent()
.getVirtualDiskManager();
if (this.diskState.status != DiskService.DiskStatus.AVAILABLE) {
throw new IllegalArgumentException("Only disk with status AVAILABLE can be deleted, as it is not attached to any VM.");
}
String diskFullPath = CustomProperties.of(this.diskState).getString(DISK_FULL_PATH, null);
if (diskFullPath == null) {
throw new IllegalArgumentException("Disk full path to issue delete request is empty.");
}
// Delete the vmdk file
ManagedObjectReference deleteTask = getVimPort().deleteVirtualDiskTask(diskManager,
diskFullPath, this.diskContext.datacenterMoRef);
TaskInfo info = waitTaskEnd(deleteTask);
if (info.getState() == TaskInfoState.ERROR) {
VimUtils.rethrow(info.getError());
}
// Delete the folder that holds the vmdk file
String dirName = CustomProperties.of(this.diskState).getString(DISK_PARENT_DIRECTORY, null);
if (dirName != null) {
ManagedObjectReference fileManager = this.connection.getServiceContent()
.getFileManager();
ManagedObjectReference deleteFile = getVimPort().deleteDatastoreFileTask(fileManager, dirName, this.diskContext
.datacenterMoRef);
info = waitTaskEnd(deleteFile);
if (info.getState() == TaskInfoState.ERROR) {
VimUtils.rethrow(info.getError());
}
} else {
Utils.logWarning("Disk parent directory is null, hence couldn't cleanup disk directory in the datastore");
}
}
示例10: waitTaskEnd
import com.vmware.vim25.TaskInfoState; //导入依赖的package包/类
public static TaskInfo waitTaskEnd(Connection connection, ManagedObjectReference task)
throws InvalidCollectorVersionFaultMsg, InvalidPropertyFaultMsg, RuntimeFaultFaultMsg {
WaitForValues waitForValues = new WaitForValues(connection);
Object[] info = waitForValues.wait(task,
new String[] { VimPath.task_info },
new String[] { VimPath.task_info_state },
new Object[][] { new Object[] {
TaskInfoState.SUCCESS,
TaskInfoState.ERROR
} });
return (TaskInfo) info[0];
}
示例11: handleTask
import com.vmware.vim25.TaskInfoState; //导入依赖的package包/类
private void handleTask(Task task) throws DestructionException, InterruptedException, RemoteException {
task.waitForTask();
TaskInfo taskInfo = task.getTaskInfo();
if (TaskInfoState.error == taskInfo.getState()) {
throw new DestructionException(taskInfo.getError().getLocalizedMessage());
}
}
示例12: destroy
import com.vmware.vim25.TaskInfoState; //导入依赖的package包/类
@Test
public void destroy() throws DestructionException, IOException {
when(this.inventoryNavigatorFactory.create()).thenReturn(this.inventoryNavigator);
when(this.inventoryNavigator.searchManagedEntity("VirtualMachine", "test-id")).thenReturn(this.virtualMachine);
when(this.virtualMachine.powerOffVM_Task()).thenReturn(this.task);
when(this.virtualMachine.destroy_Task()).thenReturn(this.task);
when(this.task.getTaskInfo()).thenReturn(this.taskInfo);
when(this.taskInfo.getState()).thenReturn(TaskInfoState.success);
this.infrastructure.destroy(this.member);
verify(this.virtualMachine).powerOffVM_Task();
}
示例13: taskFailure
import com.vmware.vim25.TaskInfoState; //导入依赖的package包/类
@Test(expected = DestructionException.class)
public void taskFailure() throws DestructionException, IOException {
when(this.inventoryNavigatorFactory.create()).thenReturn(this.inventoryNavigator);
when(this.inventoryNavigator.searchManagedEntity("VirtualMachine", "test-id")).thenReturn(this.virtualMachine);
when(this.virtualMachine.powerOffVM_Task()).thenReturn(this.task);
when(this.task.getTaskInfo()).thenReturn(this.taskInfo);
when(this.taskInfo.getState()).thenReturn(TaskInfoState.error);
when(this.taskInfo.getError()).thenReturn(this.localizedMethodFault);
this.infrastructure.destroy(this.member);
}
示例14: createTaskFilterSpec
import com.vmware.vim25.TaskInfoState; //导入依赖的package包/类
static TaskFilterSpec createTaskFilterSpec(ManagedEntity ent)
{
TaskFilterSpec tfs = new TaskFilterSpec();
// only the root initiated tasks
TaskFilterSpecByUsername nameFilter
= new TaskFilterSpecByUsername();
nameFilter.setUserList(new String[] {"Administrator"});
// include tasks initiated by non-users,
// for example, by ScheduledTaskManager.
nameFilter.setSystemUser(true);
tfs.setUserName(nameFilter);
// only the tasks with one entity itself
TaskFilterSpecByEntity entFilter =
new TaskFilterSpecByEntity();
entFilter.setEntity(ent.getMOR());
entFilter.setRecursion(TaskFilterSpecRecursionOption.all);
tfs.setEntity(entFilter);
// only successfully finished tasks
tfs.setState(new TaskInfoState[]{TaskInfoState.success });
// only tasks started within last one month
// strictly speaking, time should be retrieved from server
TaskFilterSpecByTime tFilter =new TaskFilterSpecByTime();
Calendar cal = Calendar.getInstance();
cal.roll(Calendar.MONTH, -1);
tFilter.setBeginTime(cal);
//we ignore the end time here so it gets the latest.
tFilter.setTimeType(TaskFilterSpecTimeOption.startedTime);
tfs.setTime(tFilter);
// Optionally, you limits tasks initiated by scheduled task
// with the setScheduledTask() method.
return tfs;
}
示例15: getTaskResultAfterDone
import com.vmware.vim25.TaskInfoState; //导入依赖的package包/类
protected boolean getTaskResultAfterDone(ConnectionResources connectionResources, ManagedObjectReference task)
throws InvalidPropertyFaultMsg, RuntimeFaultFaultMsg, InvalidCollectorVersionFaultMsg {
WaitForValues waitForValues = new WaitForValues(connectionResources.getConnection());
Object[] result = waitForValues.wait(task, new String[]{ManagedObjectType.INFO_STATE.getValue(),
ManagedObjectType.INFO_ERROR.getValue()}, new String[]{ManagedObjectType.STATE.getValue()},
new Object[][]{new Object[]{TaskInfoState.SUCCESS, TaskInfoState.ERROR}});
if (result[1] instanceof LocalizedMethodFault) {
throw new RuntimeException(((LocalizedMethodFault) result[1]).getLocalizedMessage());
}
return result[0].equals(TaskInfoState.SUCCESS);
}