@SuppressWarnings({ "unchecked", "rawtypes" }) protected <D extends EntityDriver> ReferenceWithError<Class<? extends D>> loadClass(String className, ClassLoader classLoader) { try { return (ReferenceWithError) ReferenceWithError.newInstanceWithoutError((Class<? extends EntityDriver>)classLoader.loadClass(className)); } catch (Exception e) { Exceptions.propagateIfFatal(e); return ReferenceWithError.newInstanceThrowingError(null, e); } } }
@Override public <D extends EntityDriver> ReferenceWithError<Class<? extends D>> resolve(DriverDependentEntity<D> entity, Class<D> driverInterface, Location location) { try { String newName = inferDriverClassName(entity, driverInterface, location); if (newName==null) return null; return loadDriverClass(newName, entity, driverInterface); } catch (Exception e) { Exceptions.propagateIfFatal(e); return ReferenceWithError.newInstanceThrowingError(null, e); } }
protected ReferenceWithError<Optional<Entity>> addInSingleLocation(@Nullable Location location, Map<?,?> flags) { ReferenceWithError<Collection<Entity>> added = addInEachLocation(Arrays.asList(location), flags); Optional<Entity> result = Iterables.isEmpty(added.getWithoutError()) ? Optional.<Entity>absent() : Optional.of(Iterables.getOnlyElement(added.get())); if (!added.hasError()) { return ReferenceWithError.newInstanceWithoutError( result ); } else { if (added.masksErrorIfPresent()) { return ReferenceWithError.newInstanceMaskingError( result, added.getError() ); } else { return ReferenceWithError.newInstanceThrowingError( result, added.getError() ); } } }
} catch (Exception e) { Exceptions.propagateIfFatal(e); return ReferenceWithError.newInstanceThrowingError(null, new IllegalStateException("Problem installing extension bundle " + manifestUrl + ": "+e, e));
/** Starts hot standby or hot backup, in foreground * <p> * In the case of the former, the caller is responsible for publishing health afterwards, * but if it fails, this method will {@link #demoteTo(ManagementNodeState)} {@link ManagementNodeState#FAILED}. * <p> * @return whether the requested {@link ManagementNodeState} was possible; * (if not, errors should be stored elsewhere), callers may want to rethrow */ protected ReferenceWithError<Boolean> activateHotProxy(ManagementNodeState toState) { try { Preconditions.checkState(nodeStateTransitionComplete==false, "Must be in transitioning state to go into "+toState); setInternalNodeState(toState); managementContext.getRebindManager().startReadOnly(toState); return ReferenceWithError.newInstanceWithoutError(true); } catch (Exception e) { Exceptions.propagateIfFatal(e); LOG.warn("Unable to change "+ownNodeId+" to "+toState+", switching to FAILED: "+e, e); demoteTo(ManagementNodeState.FAILED); return ReferenceWithError.newInstanceThrowingError(false, e); } }
protected <T> ReferenceWithError<ConfigValueAtContainer<TContainer,T>> getConfigImpl(final ConfigKey<T> queryKey, final boolean raw) { if (queryKey==null) { return ReferenceWithError.newInstanceThrowingError(new BasicConfigValueAtContainer<TContainer,T>(getContainer(), null, null, false, null), new NullPointerException("Query key cannot be null")); String message = "Config key "+ownKey+" of "+getBrooklynObject()+" is not a ConfigKeySelfExtracting; cannot retrieve value; returning default"; LOG.warn(message); return ReferenceWithError.newInstanceThrowingError(new BasicConfigValueAtContainer<TContainer,T>(getContainer(), ownKey, null, false, defaultValue), new IllegalStateException(message));
@SuppressWarnings("unchecked") public static <T> ReferenceWithError<InterruptingImmediateSupplier<T>> ofSafe(final Object o) { if (o instanceof Supplier) { return ReferenceWithError.newInstanceWithoutError(new InterruptingImmediateSupplier<T>((Supplier<T>)o)); } else if (o instanceof Callable) { return ReferenceWithError.newInstanceWithoutError(new InterruptingImmediateSupplier<T>(new Supplier<T>() { @Override public T get() { try { return ((Callable<T>)o).call(); } catch (Exception e) { throw Exceptions.propagate(e); } } })); } else if (o instanceof Runnable) { return ReferenceWithError.newInstanceWithoutError(new InterruptingImmediateSupplier<T>(new Supplier<T>() { @Override public T get() { ((Runnable)o).run(); return null; } })); } else { return ReferenceWithError.newInstanceThrowingError(null, new InterruptingImmediateSupplierNotSupportedForObject(o)); } }
@Override @Beta public Response createFromArchive(byte[] zipInput, boolean detail, boolean forceUpdate) { if (!Entitlements.isEntitled(mgmt().getEntitlementManager(), Entitlements.ROOT, null)) { throw WebResourceUtils.forbidden("User '%s' is not authorized to add catalog item", Entitlements.getEntitlementContext().user()); } ReferenceWithError<OsgiBundleInstallationResult> result = ((ManagementContextInternal)mgmt()).getOsgiManager().get() .install(null, new ByteArrayInputStream(zipInput), true, true, forceUpdate); if (OsgiBundleInstallationResult.ResultCode.IGNORING_BUNDLE_AREADY_INSTALLED.equals(result.getWithoutError().getCode())) { result = ReferenceWithError.newInstanceThrowingError(result.getWithoutError(), new IllegalStateException( "Cannot add bundle" + result.getWithoutError().getMetadata().getVersionedName() + "; different bundle with same name already installed")); } if (result.hasError()) { // (rollback already done as part of install, if necessary) if (log.isTraceEnabled()) { log.trace("Unable to create from archive, returning 400: "+result.getError().getMessage(), result.getError()); } return ApiError.builder().errorCode(Status.BAD_REQUEST).message(result.getWithoutError().getMessage()) .data(BundleInstallationRestResult.of(result.getWithoutError(), mgmt(), brooklyn(), ui)).build().asJsonResponse(); } BundleInstallationRestResult resultR = BundleInstallationRestResult.of(result.get(), mgmt(), brooklyn(), ui); return Response.status(Status.CREATED).entity( detail ? resultR : resultR.types ).build(); }
.appendIfNotNull(beanError) .appendIfNotNull(specError); return ReferenceWithError.newInstanceThrowingError(null, Exceptions.create("Could not resolve "+typeToValidate, errors));
private static <T> ReferenceWithError<Maybe<? extends T>> deepMerge(Maybe<? extends T> val1, Maybe<? extends T> val2) { if (val2.isAbsent() || val2.isNull()) { return ReferenceWithError.newInstanceWithoutError(val1); } else if (val1.isAbsent()) { return ReferenceWithError.newInstanceWithoutError(val2); } else if (val1.isNull()) { return ReferenceWithError.newInstanceWithoutError(val1); // an explicit null means an override; don't merge } else if (val1.get() instanceof Map && val2.get() instanceof Map) { @SuppressWarnings({ "unchecked", "rawtypes" }) Maybe<T> result = (Maybe)Maybe.of(CollectionMerger.builder().build().merge((Map<?,?>)val1.get(), (Map<?,?>)val2.get())); return ReferenceWithError.newInstanceWithoutError(result); } else { // cannot merge; just return val1 return ReferenceWithError.newInstanceThrowingError(val1, new IllegalArgumentException("Cannot merge '"+val1.get()+"' and '"+val2.get()+"'")); } }
result.message = "Bundle "+inferredMetadata+" failed "+ (startedInstallation ? "installation" : "preparation") + ": " + Exceptions.collapseText(e); return ReferenceWithError.newInstanceThrowingError(result, new IllegalStateException(result.message, e)); } finally { close();
if (resultWithParent.getWithoutError()!=null && resultWithParent.getWithoutError().isValueExplicitlySet()) { if (!resultWithParent.hasError() && parentResult!=null && parentResult.hasError()) { return ReferenceWithError.newInstanceThrowingError(resultWithParent.getWithoutError(), parentResult.getError());
getAncestorDefaultInheritable() ? parent.getDefaultValue() : Maybe.<TValue>absent()); result.setValue(resolvedValue.getWithoutError()); return ReferenceWithError.newInstanceThrowingError(result, resolvedValue.getError());