com.vmware.vim25.LocalizedMethodFault Java Examples

The following examples show how to use com.vmware.vim25.LocalizedMethodFault. 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 vote down vote up
/**
 * 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: TaskMO.java    From cloudstack with Apache License 2.0 6 votes vote down vote up
public static String getTaskFailureInfo(VmwareContext context, ManagedObjectReference morTask) {
    StringBuffer sb = new StringBuffer();

    try {
        TaskInfo info = (TaskInfo)context.getVimClient().getDynamicProperty(morTask, "info");
        if (info != null) {
            LocalizedMethodFault fault = info.getError();
            if (fault != null) {
                sb.append(fault.getLocalizedMessage()).append(" ");

                if (fault.getFault() != null)
                    sb.append(fault.getFault().getClass().getName());
            }
        }
    } catch (Exception e) {
        s_logger.info("[ignored]"
                + "error retrieving failure info for task : " + e.getLocalizedMessage());
    }

    return sb.toString();
}
 
Example #3
Source File: VMwareUtil.java    From cloudstack with Apache License 2.0 6 votes vote down vote up
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 #4
Source File: OvfUtils.java    From cs-actions with Apache License 2.0 5 votes vote down vote up
public static String getHttpNfcLeaseErrorState(final ConnectionResources connectionResources, final ManagedObjectReference httpNfcLease) throws Exception {
    final ObjectContent objectContent = GetObjectProperties.getObjectProperty(connectionResources, httpNfcLease, "error");
    final List<DynamicProperty> dynamicProperties = objectContent.getPropSet();
    if (firstElementIsOfClass(dynamicProperties, LocalizedMethodFault.class)) {
        return ((LocalizedMethodFault) dynamicProperties.get(0).getVal()).getLocalizedMessage();
    }
    throw new Exception(LEASE_ERROR_STATE_COULD_NOT_BE_OBTAINED);
}
 
Example #5
Source File: ResponseHelper.java    From cs-actions with Apache License 2.0 5 votes vote down vote up
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 #6
Source File: DeployOvfTemplateService.java    From cs-actions with Apache License 2.0 5 votes vote down vote up
private void checkImportSpecResultForErrors(OvfCreateImportSpecResult importSpecResult) throws Exception {
    if (0 < importSpecResult.getError().size()) {
        StringBuilder stringBuilder = new StringBuilder();
        for (LocalizedMethodFault fault : importSpecResult.getError()) {
            stringBuilder.append(fault.getLocalizedMessage()).append(System.lineSeparator());
        }
        throw new Exception(stringBuilder.toString());
    }
}
 
Example #7
Source File: TaskMO.java    From cloudstack with Apache License 2.0 4 votes vote down vote up
public void setTaskState(TaskInfoState state, Object result, LocalizedMethodFault fault) throws Exception {
    _context.getService().setTaskState(_mor, state, result, fault);
}
 
Example #8
Source File: HttpNfcLeaseMO.java    From cloudstack with Apache License 2.0 4 votes vote down vote up
public LocalizedMethodFault getLeaseError() throws Exception {
    return (LocalizedMethodFault)_context.getVimClient().getDynamicProperty(_mor, "error");
}