@Override @Beta public Collection<Throwable> validateType(RegisteredType typeToValidate, RegisteredTypeLoadingContext constraint) { ReferenceWithError<RegisteredType> result = resolve(typeToValidate, constraint); if (result.hasError()) { if (RegisteredTypes.isTemplate(typeToValidate)) { // ignore for templates return Collections.emptySet(); } if (result.getError() instanceof CompoundRuntimeException) { return ((CompoundRuntimeException)result.getError()).getAllCauses(); } return Collections.singleton(result.getError()); } // replace what's in catalog with resolved+validated version ((BasicBrooklynTypeRegistry) mgmt.getTypeRegistry()).addToLocalUnpersistedTypeRegistry(result.get(), true); return Collections.emptySet(); }
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() ); } } }
if (installResult.hasError() && !installResult.masksErrorIfPresent()) { LOG.warn("Unable to install manifest from "+url+": "+installResult.getError(), installResult.getError()); } else { Object result = installResult.getWithoutError(); SYSTEM_BUNDLES.add(v); if (installResult.hasError()) { LOG.debug(installResult.getError().getMessage()+(result!=null ? " ("+result+"/"+v+")" : "")); } else { LOG.debug("Installed "+v+" from "+url); LOG.debug(installResult.getError().getMessage());
/** * @throws StopFailedRuntimeException If stop failed, after successfully starting replacement */ protected Entity replaceMember(Entity member, @Nullable Location memberLoc, Map<?, ?> extraFlags) { synchronized (mutex) { ReferenceWithError<Optional<Entity>> added = addInSingleLocation(memberLoc, extraFlags); if (!added.getWithoutError().isPresent()) { String msg = String.format("In %s, failed to grow, to replace %s; not removing", this, member); if (added.hasError()) throw new IllegalStateException(msg, added.getError()); throw new IllegalStateException(msg); } try { stopAndRemoveNode(member); } catch (Exception e) { Exceptions.propagateIfFatal(e); throw new StopFailedRuntimeException("replaceMember failed to stop and remove old member "+member.getId(), e); } return added.getWithError().get(); } }
exceptions.add(clazzR.getError());
protected void waitForSshable(final SshMachineLocation machine, Duration timeout) { Callable<Boolean> checker = new Callable<Boolean>() { public Boolean call() { int exitstatus = machine.execScript( ImmutableMap.of( // TODO investigate why SSH connection does not time out with this config SshTool.PROP_CONNECT_TIMEOUT.getName(), Duration.TEN_SECONDS.toMilliseconds(), SshTool.PROP_SESSION_TIMEOUT.getName(), Duration.TEN_SECONDS.toMilliseconds(), SshTool.PROP_SSH_TRIES_TIMEOUT.getName(), Duration.TEN_SECONDS.toMilliseconds(), SshTool.PROP_SSH_TRIES.getName(), 1), "check-sshable", ImmutableList.of("true")); boolean success = (exitstatus == 0); return success; } }; Stopwatch stopwatch = Stopwatch.createStarted(); ReferenceWithError<Boolean> reachable = Repeater.create("reachable") .threaded() .backoff(Duration.FIVE_SECONDS, 2, Duration.TEN_SECONDS) // Exponential backoff, to 10 seconds .until(checker) .limitTimeTo(timeout) .runKeepingError(); if (!reachable.getWithoutError()) { throw new IllegalStateException("Connection failed for " + machine.getSshHostAndPort() + " after waiting " + stopwatch.elapsed(TimeUnit.SECONDS), reachable.getError()); } else { LOG.debug("Connection succeeded for {} after {}", machine.getSshHostAndPort(), stopwatch.elapsed(TimeUnit.SECONDS)); } }
@Override public Boolean call() { ReferenceWithError<Boolean> result; Tasks.setBlockingDetails(repeater.getDescription()); try { result = repeater.runKeepingError(); } finally { Tasks.resetBlockingDetails(); } if (Boolean.TRUE.equals(result.getWithoutError())) return true; if (result.hasError()) throw Exceptions.propagate(result.getError()); if (requireTrue) throw new IllegalStateException("timeout - "+repeater.getDescription()); return false; } }
@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(); }
if (resultWithParent.getWithoutError()!=null && resultWithParent.getWithoutError().isValueExplicitlySet()) { if (!resultWithParent.hasError() && parentResult!=null && parentResult.hasError()) { return ReferenceWithError.newInstanceThrowingError(resultWithParent.getWithoutError(), parentResult.getError());
} else { setUpAndRunState(false, ON_FIRE); Throwable error = result.getError(); if (error instanceof MarkerException) { error = error.getCause();
} else { setUpAndRunState(false, ON_FIRE); Throwable error = result.getError(); if (error instanceof MarkerException) { error = error.getCause();
getAncestorDefaultInheritable() ? parent.getDefaultValue() : Maybe.<TValue>absent()); result.setValue(resolvedValue.getWithoutError()); return ReferenceWithError.newInstanceThrowingError(result, resolvedValue.getError());