public static <T> InterruptingImmediateSupplier<T> of(final Object o) { return InterruptingImmediateSupplier.<T>ofSafe(o).get(); }
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() ); } } }
@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(); }
new ResourceUtils(getClass()).getResourceFromUrl(BROOKLYN_TEST_MORE_ENTITIES_V2_URL) ).get(); new ResourceUtils(getClass()).getResourceFromUrl(BROOKLYN_TEST_MORE_ENTITIES_V2_EVIL_TWIN_URL), true, true, true).get(); Assert.assertEquals(b2a.getBundle(), b2b.getBundle()); Assert.assertEquals(b2b.getCode(), OsgiBundleInstallationResult.ResultCode.UPDATED_EXISTING_BUNDLE);
@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(); }
public void runRequiringTrue() { Stopwatch timer = Stopwatch.createStarted(); ReferenceWithError<Boolean> result = runKeepingError(); result.checkNoError(); if (!result.get()) { throw new IllegalStateException(description+" unsatisfied after "+Duration.of(timer)); } }
if (clazzR!=null) { if (!clazzR.hasError()) { Class<? extends D> clazz = clazzR.get(); if (clazz!=null) { driverClass = clazz;
/** install the bundles into brooklyn and osgi, but do not start nor validate; * caller (rebind) will do that manually, doing each step across all bundles before proceeding * to prevent reference errors */ public OsgiBundleInstallationResult installBundle(ManagedBundle bundle, InputStream zipInput) { return ((ManagementContextInternal)mgmt).getOsgiManager().get().installDeferredStart(bundle, zipInput, false).get(); } public void startBundle(OsgiBundleInstallationResult br) throws BundleException {
public void waitForExitCondition(ExitCondition exitCondition, Duration initial, Duration duration) { ReferenceWithError<Boolean> result = Repeater.create() .backoff(initial, 1.2, duration) .limitTimeTo(duration) .until(exitCondition) .runKeepingError(); if (!result.get()) { String err = "Exit condition unsatisfied after " + duration + ": " + exitCondition.getFailureMessage(); LOG.info(err + " (rethrowing)"); throw new IllegalStateException(err); } }
List<OsgiBundleInstallationResult> results = MutableList.of(); for (CatalogBundle bundleUrl : libraries) { OsgiBundleInstallationResult result = osgi.get().installDeferredStart(BasicManagedBundle.of(bundleUrl), null, true).get(); if (log.isDebugEnabled()) { logDebugOrTraceIfRebinding(log, "Installation of library "+bundleUrl+": "+result);
result = osgiManager.get().install(null, new FileInputStream(bf), true, true, forceUpdate).get(); } catch (FileNotFoundException e) { throw Exceptions.propagate(e);
nodeStateTransitionComplete = false; try { activateHotProxy(toState).get(); } finally { nodeStateTransitionComplete = true;
private void installBundle(File jf) { try (FileInputStream fin = new FileInputStream(jf)) { OsgiBundleInstallationResult br = ((ManagementContextInternal)mgmt()).getOsgiManager().get().install(fin).get(); bundlesToRemove.add(br.getBundle()); } catch (Exception e) { throw Exceptions.propagate(e); } }
public static void installWithoutCatalogBom(ManagementContext mgmt, String bundleUrl) { // install bundle for class access but without loading its catalog.bom, // since we only have mock matchers here // (if we don't do this, the default routines install it and try to process the catalog.bom, failing) ((ManagementContextInternal)mgmt).getOsgiManager().get().installDeferredStart(new BasicManagedBundle(null, null, bundleUrl), null, false).get(); }
public static void addCatalogItemsAsOsgiWithoutStartingBundles(ManagementContext mgmt, String catalogYaml, VersionedName bundleName, boolean force) { try { BundleMaker bundleMaker = new BundleMaker(mgmt); File bf = bundleMaker.createTempZip("test", MutableMap.of( new ZipEntry(BasicBrooklynCatalog.CATALOG_BOM), new ByteArrayInputStream(catalogYaml.getBytes()))); ReferenceWithError<OsgiBundleInstallationResult> b = ((ManagementContextInternal)mgmt).getOsgiManager().get().installDeferredStart( new BasicManagedBundle(bundleName.getSymbolicName(), bundleName.getVersionString(), null), new FileInputStream(bf), false); // bundle not started (no need, and can break), and BOM not installed nor validated above; // do BOM install and validation below manually to test the type registry approach // but skipping the rollback / uninstall mgmt.getCatalog().addTypesFromBundleBom(catalogYaml, b.get().getMetadata(), force, null); Map<RegisteredType, Collection<Throwable>> validation = mgmt.getCatalog().validateTypes( mgmt.getTypeRegistry().getMatching(RegisteredTypePredicates.containingBundle(b.get().getVersionedName())) ); if (!validation.isEmpty()) { throw Exceptions.propagate("Brooklyn failed to load types (in tests, skipping rollback): "+validation.keySet(), Iterables.concat(validation.values())); } } catch (Exception e) { throw Exceptions.propagate(e); } }
@Test public void testBrooklynManagedBundleInstall() throws Exception { TestResourceUnavailableException.throwIfResourceUnavailable(getClass(), BROOKLYN_TEST_MORE_ENTITIES_V1_PATH); OsgiBundleInstallationResult br = ((ManagementContextInternal)mgmt()).getOsgiManager().get().install( new ResourceUtils(getClass()).getResourceFromUrl(BROOKLYN_TEST_MORE_ENTITIES_V1_URL) ).get(); Assert.assertEquals(br.getVersionedName().toString(), BROOKLYN_TEST_MORE_ENTITIES_SYMBOLIC_NAME_FULL+":"+"0.1.0"); // bundle installed Map<String, ManagedBundle> bundles = ((ManagementContextInternal)mgmt()).getOsgiManager().get().getManagedBundles(); Asserts.assertSize(bundles.keySet(), 1); Assert.assertTrue(bundles.keySet().contains( br.getMetadata().getId() )); // types installed RegisteredType t = mgmt().getTypeRegistry().get(BROOKLYN_TEST_MORE_ENTITIES_MORE_ENTITY); Assert.assertNotNull(t); Assert.assertEquals(t.getContainingBundle(), br.getVersionedName().toString()); // can deploy createAndStartApplication("services: [ { type: "+BROOKLYN_TEST_MORE_ENTITIES_MORE_ENTITY+" } ]"); }
protected RegisteredType installWrappedMoreEntity() throws Exception { TestResourceUnavailableException.throwIfResourceUnavailable(getClass(), BROOKLYN_TEST_OSGI_ENTITIES_PATH); TestResourceUnavailableException.throwIfResourceUnavailable(getClass(), BROOKLYN_TEST_MORE_ENTITIES_V2_PATH); ((ManagementContextInternal)mgmt()).getOsgiManager().get().install( new ResourceUtils(getClass()).getResourceFromUrl(BROOKLYN_TEST_OSGI_ENTITIES_URL) ).checkNoError(); ((ManagementContextInternal)mgmt()).getOsgiManager().get().install( new ResourceUtils(getClass()).getResourceFromUrl(BROOKLYN_TEST_MORE_ENTITIES_V2_URL) ).get(); addCatalogItems( "brooklyn.catalog:", " id: wrapped-more-entity", " version: 1.0", " item:", " services:", " - type: " + BROOKLYN_TEST_MORE_ENTITIES_MORE_ENTITY); RegisteredType ci = Preconditions.checkNotNull( mgmt().getTypeRegistry().get("wrapped-more-entity") ); return ci; }
activateHotProxy(ManagementNodeState.of(startMode).get()).get();
@Test public void testClusterWithEntitySpecFromOsgi() throws Exception { TestResourceUnavailableException.throwIfResourceUnavailable(getClass(), BROOKLYN_TEST_OSGI_ENTITIES_PATH); TestResourceUnavailableException.throwIfResourceUnavailable(getClass(), BROOKLYN_TEST_MORE_ENTITIES_V2_PATH); // install dependencies ((ManagementContextInternal)mgmt()).getOsgiManager().get().install( new ResourceUtils(getClass()).getResourceFromUrl(BROOKLYN_TEST_OSGI_ENTITIES_URL) ).checkNoError(); ((ManagementContextInternal)mgmt()).getOsgiManager().get().install( new ResourceUtils(getClass()).getResourceFromUrl(BROOKLYN_TEST_MORE_ENTITIES_V2_URL) ).get(); RegisteredType ci = Preconditions.checkNotNull( mgmt().getTypeRegistry().get(BROOKLYN_TEST_MORE_ENTITIES_MORE_ENTITY) ); EntitySpec<DynamicCluster> clusterSpec = EntitySpec.create(DynamicCluster.class) .configure(DynamicCluster.INITIAL_SIZE, 1) .configure(DynamicCluster.MEMBER_SPEC, origManagementContext.getTypeRegistry().createSpec(ci, null, EntitySpec.class)); final Entity app = mgmt().getEntityManager().createEntity(EntitySpec.create(BasicApplication.class).child(clusterSpec)); app.invoke(Startable.START, MutableMap.of()).get(); rebind(); }
new ResourceUtils(getClass()).getResourceFromUrl(BROOKLYN_TEST_MORE_ENTITIES_V2_URL) ).get();