com.vmware.vim25.TaskInfoState Java Examples
The following examples show how to use
com.vmware.vim25.TaskInfoState.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: WaitForValues.java From vsphere-automation-sdk-java with MIT License | 6 votes |
/** * 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; }
Example #2
Source File: VMwareUtil.java From cloudstack with Apache License 2.0 | 6 votes |
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; }
Example #3
Source File: VMPropertyHandler.java From development with Apache License 2.0 | 5 votes |
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); }
Example #4
Source File: VSphereInfrastructure.java From chaos-lemur with Apache License 2.0 | 5 votes |
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()); } }
Example #5
Source File: VSphereInfrastructureTest.java From chaos-lemur with Apache License 2.0 | 5 votes |
@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(); }
Example #6
Source File: VSphereInfrastructureTest.java From chaos-lemur with Apache License 2.0 | 5 votes |
@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); }
Example #7
Source File: ResponseHelper.java From cs-actions with Apache License 2.0 | 5 votes |
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); }
Example #8
Source File: Actions.java From development with Apache License 2.0 | 4 votes |
private void logTaskInfo(TaskInfo info) { String key = info.getKey(); String name = info.getName(); String target = info.getEntityName(); 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() : ""; TaskReason reason = info.getReason(); String initiatedBy = ""; if (reason != null) { if (reason instanceof TaskReasonUser) { initiatedBy = ((TaskReasonUser) reason).getUserName(); } else if (reason instanceof TaskReasonSystem) { initiatedBy = "System"; } else if (reason instanceof TaskReasonSchedule) { initiatedBy = ((TaskReasonSchedule) reason).getName(); } else if (reason instanceof TaskReasonAlarm) { initiatedBy = ((TaskReasonAlarm) reason).getAlarmName(); } } 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(key + " name: " + name + " target: " + target + " state: " + state + " progress: " + progress + "% description: " + description + " initiated: " + initiatedBy + " queue-time: " + queueTime + " start-time: " + startTime + " complete-time: " + completeTime); }
Example #9
Source File: TaskMO.java From cloudstack with Apache License 2.0 | 4 votes |
public void setTaskState(TaskInfoState state, Object result, LocalizedMethodFault fault) throws Exception { _context.getService().setTaskState(_mor, state, result, fault); }