/** * Tries to find a bundle in the given framework with name matching either `name' or `name:version'. * @deprecated since 0.7.0 use {@link #bundleFinder(Framework)} */ @Deprecated public static Maybe<Bundle> getBundle(Framework framework, String symbolicNameOptionallyWithVersion) { return bundleFinder(framework).id(symbolicNameOptionallyWithVersion).find(); }
/** installs the given JAR file as an OSGi bundle; all manifest info should be already set up. * bundle-start semantics are TBD. * * @deprecated since 0.12.0, use {@link OsgiManager#installUploadedBundle(org.apache.brooklyn.api.typereg.ManagedBundle, InputStream)}*/ @Deprecated public Bundle installBundle(File f, boolean start) { try { Bundle b = Osgis.install( framework, "file://"+f.getAbsolutePath() ); if (start) { // benefits of start: // a) we get wiring issues thrown here, and // b) catalog.bom in root will be scanned synchronously here // however drawbacks: // c) other code doesn't always do it (method above) // d) heavier-weight earlier // e) tests in IDE break (but mvn fine) b.start(); } return b; } catch (Exception e) { throw Exceptions.propagateAnnotated("Error starting bundle from "+f, e); } }
public Optional<String> getPrefix(Class<?> type) { Optional<Bundle> bundle = (bundleRetriever != null) ? bundleRetriever.apply(type) : Osgis.getBundleOf(type); if (bundle.isPresent()) { // Previously we didn't include the bundle prefix for whitelisted bundles. However, // that means once a bundle is whitelisted it must always be whitelisted. That is // annoying for customer-upgrades of persisted state created pre-karaf. For those // upgrades, the temporary whitelist is a useful way to allow rebind to complete // successfully. The persisted state will then be re-written with the appropriate // prefixes. It is also better that we treat persistence/rebind of classes from // Brooklyn bundles in the same way as customer bundles. return Optional.of(bundle.get().getSymbolicName() + DELIMITER); } return Optional.absent(); }
boolean isLocal = isLocalUrl(url); String localUrl = url; if (!isLocal) { localUrl = cacheFile(url); Bundle bundle = getInstalledBundle(framework, localUrl); if (bundle != null) { return bundle; InputStream stream = getUrlStream(localUrl); Bundle installedBundle = framework.getBundleContext().installBundle(url, stream);
Framework framework = Osgis.getFramework(storageTempDir.getAbsolutePath(), true); InternalEntityFactory factory = new InternalEntityFactory(managementContext, managementContext.getEntityManager().getEntityTypeRegistry(), policyFactory); Bundle bundle = Osgis.install(framework, BROOKLYN_TEST_OSGI_ENTITIES_PATH); @SuppressWarnings("unchecked") Class<? extends Entity> bundleCls = (Class<? extends Entity>) bundle.loadClass("org.apache.brooklyn.test.osgi.entities.SimpleEntityImpl");
/** @deprecated since 0.9.0, replaced by {@link #getFramework(java.lang.String, boolean) } */ @Deprecated public static Framework newFrameworkStarted(String felixCacheDir, boolean clean, Map<?,?> extraStartupConfig) { return getFramework(felixCacheDir, clean); }
public static void tearDownOsgiFramework(Framework framework, File storageTempDir) throws BundleException, InterruptedException, IOException { Osgis.ungetFramework(framework); framework = null; if (storageTempDir != null) { FileUtils.deleteDirectory(storageTempDir); storageTempDir = null; } }
private static String cacheFile(String url) { InputStream in = getUrlStream(url); File cache = Os.writeToTempFile(in, "bundle-cache", "jar"); return cache.toURI().toString(); }
@BeforeMethod(alwaysRun = true) public void setUp() throws Exception { storageTempDir = Os.newTempDir("osgi-standalone"); framework = Osgis.getFramework(storageTempDir.getAbsolutePath(), true); }
Osgis.ungetFramework(framework);
stream = new JarInputStream(getUrlStream(url)); } catch (IOException e) { throw Exceptions.propagate(e);
/** @deprecated since 0.7.0 use {@link #bundleFinder(Framework)} */ @Deprecated public static List<Bundle> getBundlesByName(Framework framework, String symbolicName) { return bundleFinder(framework).symbolicName(symbolicName).findAll(); }
protected Bundle install(String url) throws BundleException { try { return Osgis.install(framework, url); } catch (Exception e) { throw new IllegalStateException("test resources not available; may be an IDE issue, so try a mvn rebuild of this project", e); } }
framework = Osgis.getFramework(osgiFrameworkCacheDir.getAbsolutePath(), false); log.debug("OSGi framework container created in "+osgiFrameworkCacheDir+" mgmt node "+mgmt.getManagementNodeId()+ (reuseFramework ? "(reusable, "+numberOfReusableFrameworksCreated.get()+" total)" : "") );
protected void assertBundleVersionOf(Object obj, String expectedVersion) { assertNotNull(obj); Class<?> clazz = (obj instanceof Class) ? (Class<?>)obj : obj.getClass(); assertEquals(Osgis.getBundleOf(clazz).get().getVersion().toString(), expectedVersion); } }
void checkCorrectlyInstalled(OsgiBundleWithUrl bundle, Bundle b) { String nv = b.getSymbolicName()+":"+b.getVersion().toString(); if (!isBundleNameEqualOrAbsent(bundle, b)) { throw new IllegalStateException("Bundle already installed as "+nv+" but user explicitly requested "+bundle); } List<Bundle> matches = Osgis.bundleFinder(framework) .symbolicName(b.getSymbolicName()) .version(b.getVersion().toString()) .findAll(); if (matches.isEmpty()) { log.error("OSGi could not find bundle "+nv+" in search after installing it from "+bundle); } else if (matches.size()==1) { log.debug("Bundle from "+bundle.getUrl()+" successfully installed as " + nv + " ("+b+")"); } else { log.warn("OSGi has multiple bundles matching "+nv+", when installing "+bundle+"; not guaranteed which versions will be consumed"); // TODO for snapshot versions we should indicate which one is best to use } }
/** @deprecated since 0.12.0 use {@link #install(ManagedBundle, InputStream, boolean, boolean)} */ @Deprecated public synchronized Bundle registerBundle(CatalogBundle bundleMetadata) { try { Bundle alreadyBundle = checkBundleInstalledThrowIfInconsistent(bundleMetadata, true); if (alreadyBundle!=null) { return alreadyBundle; } Bundle bundleInstalled = Osgis.install(framework, bundleMetadata.getUrl()); checkCorrectlyInstalled(bundleMetadata, bundleInstalled); return bundleInstalled; } catch (Exception e) { Exceptions.propagateIfFatal(e); throw new IllegalStateException("Bundle from "+bundleMetadata.getUrl()+" failed to install: " + e.getMessage(), e); } }
/** @deprecated since 0.7.0 use {@link #bundleFinder(Framework)} */ @Deprecated public static List<Bundle> getBundlesByName(Framework framework, String symbolicName, Predicate<Version> versionMatcher) { return bundleFinder(framework).symbolicName(symbolicName).version(versionMatcher).findAll(); }
protected Bundle installFromClasspath(String resourceName) throws BundleException { TestResourceUnavailableException.throwIfResourceUnavailable(getClass(), resourceName); try { return Osgis.install(framework, String.format("classpath:%s", resourceName)); } catch (Exception e) { throw Exceptions.propagate(e); } }
/** @deprecated since 0.7.0 use {@link #bundleFinder(Framework)} */ @Deprecated public static Maybe<Bundle> getBundle(Framework framework, String symbolicName, Version version) { return bundleFinder(framework).symbolicName(symbolicName).version(Predicates.equalTo(version)).findUnique(); }