/** * Wait up to a minute for the nfcLease to become READY. * @throws Exception */ public void awaitReady() throws Exception { int i = 60; while (i-- > 0) { HttpNfcLeaseState state = getState(); if (state.equals(HttpNfcLeaseState.ERROR)) { LocalizedMethodFault leaseError = this.get.entityProp(this.nfcLease, PROP_ERROR); logger.warn("nfcLease error: {}", leaseError.getLocalizedMessage(), leaseError); VimUtils.rethrow(leaseError); } if (state.equals(HttpNfcLeaseState.READY)) { return; } logger.debug("Waiting for nfcLease {}", VimUtils.convertMoRefToString(this.nfcLease), state); Thread.sleep(LEASE_READY_RETRY_MILLIS); } throw new IllegalStateException("Lease not ready within configured timeout"); }
/** * This method never returns but throws an Exception wrapping the fault. * * @param lmf * @param <T> * @return * @throws Exception */ public static <T> T rethrow(LocalizedMethodFault lmf) throws Exception { Class<?> type = lmf.getFault().getClass(); String possibleWrapperType = type.getName() + EXCEPTION_SUFFIX; Exception ex; try { ClassLoader cl = type.getClassLoader(); Class<?> faultClass = cl.loadClass(possibleWrapperType); Constructor<?> ctor = faultClass.getConstructor(String.class, type); ex = (Exception) ctor.newInstance(lmf.getLocalizedMessage(), lmf.getFault()); } catch (ReflectiveOperationException e) { throw new GenericVimFault(lmf.getLocalizedMessage(), lmf.getFault()); } throw ex; }
@Test public void retrhowKnownException() { DuplicateName dn = new DuplicateName(); LocalizedMethodFault lmf = new LocalizedMethodFault(); lmf.setLocalizedMessage("msg"); lmf.setFault(dn); try { VimUtils.rethrow(lmf); fail(); } catch (DuplicateNameFaultMsg msg) { assertSame(dn, msg.getFaultInfo()); assertSame(lmf.getLocalizedMessage(), msg.getMessage()); } catch (Exception e) { fail(); } }
@Test public void retrhowUnknownException() { ConnectedIso dn = new ConnectedIso(); LocalizedMethodFault lmf = new LocalizedMethodFault(); lmf.setLocalizedMessage("msg"); lmf.setFault(dn); try { VimUtils.rethrow(lmf); fail(); } catch (GenericVimFault msg) { assertSame(dn, msg.getFaultInfo()); assertSame(lmf.getLocalizedMessage(), msg.getMessage()); } catch (Exception e) { fail(); } }
/** * 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; }
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(); }
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; }
public void abort(LocalizedMethodFault e) { this.done.set(true); try { getVimPort().httpNfcLeaseAbort(this.nfcLease, e); } catch (RuntimeFaultFaultMsg | TimedoutFaultMsg | InvalidStateFaultMsg ex) { logger.warn("Error aborting nfcLease {}", VimUtils.convertMoRefToString(this.nfcLease), e); } }
@Test public void convertToFault() { DuplicateName fault = new DuplicateName(); String msg = "msg"; Exception e = new DuplicateNameFaultMsg(msg, fault); LocalizedMethodFault lmf = VimUtils.convertExceptionToFault(e); assertSame(fault, lmf.getFault()); assertSame(msg, lmf.getLocalizedMessage()); }
@Test public void convertToFaultGeneric() { String msg = "test"; IOException e = new IOException(msg); LocalizedMethodFault lmf = VimUtils.convertExceptionToFault(e); assertNull(lmf.getFault()); assertSame(msg, lmf.getLocalizedMessage()); }
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); }
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); }
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()); } }
public LocalizedMethodFault getError() { return (LocalizedMethodFault) getCurrentProperty("error"); }
public void httpNfcLeaseAbort(LocalizedMethodFault fault) throws Timedout, InvalidState, RuntimeFault, RemoteException { getVimService().httpNfcLeaseAbort(getMOR(), fault); }
public void setTaskState(TaskInfoState tis, Object result, LocalizedMethodFault fault) throws InvalidState, RuntimeFault, RemoteException { getVimService().setTaskState(getMOR(), tis, result, fault); }
public void setTaskState(TaskInfoState state, Object result, LocalizedMethodFault fault) throws Exception { _context.getService().setTaskState(_mor, state, result, fault); }
public LocalizedMethodFault getLeaseError() throws Exception { return (LocalizedMethodFault)_context.getVimClient().getDynamicProperty(_mor, "error"); }
/** * Gets the value of the warning property. * * <p> * This accessor method returns a reference to the live list, * not a snapshot. Therefore any modification you make to the * returned list will be present inside the JAXB object. * This is why there is not a <CODE>set</CODE> method for the warning property. * * <p> * For example, to add a new item, do as follows: * <pre> * getWarning().add(newItem); * </pre> * * * <p> * Objects of the following type(s) are allowed in the list * {@link LocalizedMethodFault } * * */ public List<LocalizedMethodFault> getWarning() { if (warning == null) { warning = new ArrayList<LocalizedMethodFault>(); } return this.warning; }
/** * Gets the value of the error property. * * <p> * This accessor method returns a reference to the live list, * not a snapshot. Therefore any modification you make to the * returned list will be present inside the JAXB object. * This is why there is not a <CODE>set</CODE> method for the error property. * * <p> * For example, to add a new item, do as follows: * <pre> * getError().add(newItem); * </pre> * * * <p> * Objects of the following type(s) are allowed in the list * {@link LocalizedMethodFault } * * */ public List<LocalizedMethodFault> getError() { if (error == null) { error = new ArrayList<LocalizedMethodFault>(); } return this.error; }
/** * Gets the value of the errorCause property. * * <p> * This accessor method returns a reference to the live list, * not a snapshot. Therefore any modification you make to the * returned list will be present inside the JAXB object. * This is why there is not a <CODE>set</CODE> method for the errorCause property. * * <p> * For example, to add a new item, do as follows: * <pre> * getErrorCause().add(newItem); * </pre> * * * <p> * Objects of the following type(s) are allowed in the list * {@link LocalizedMethodFault } * * */ public List<LocalizedMethodFault> getErrorCause() { if (errorCause == null) { errorCause = new ArrayList<LocalizedMethodFault>(); } return this.errorCause; }
/** * Gets the value of the fault property. * * @return * possible object is * {@link LocalizedMethodFault } * */ public LocalizedMethodFault getFault() { return fault; }
/** * Sets the value of the fault property. * * @param value * allowed object is * {@link LocalizedMethodFault } * */ public void setFault(LocalizedMethodFault value) { this.fault = value; }