OsgiArchiveInstaller { @VisibleForTesting boolean isBlacklistedForPersistence(ManagedBundle managedBundle) { if (blacklistBundlePersistencePredicate == null) { String whitelistRegex = mgmt().getConfig().getConfig(PERSIST_MANAGED_BUNDLE_WHITELIST_REGEX); String blacklistRegex = mgmt().getConfig().getConfig(PERSIST_MANAGED_BUNDLE_BLACKLIST_REGEX); final Pattern whitelistPattern = (whitelistRegex != null) ? Pattern.compile(whitelistRegex) : null; final Pattern blacklistPattern = (blacklistRegex != null) ? Pattern.compile(blacklistRegex) : null; blacklistBundlePersistencePredicate = new Predicate<ManagedBundle>() { @Override public boolean apply(ManagedBundle input) { String bundleName = input.getSymbolicName(); if (whitelistPattern != null && whitelistPattern.matcher(bundleName).matches()) { return false; } if (blacklistPattern != null && blacklistPattern.matcher(bundleName).matches()) { return true; } return false; } }; } return blacklistBundlePersistencePredicate.apply(managedBundle); } OsgiArchiveInstaller(OsgiManager osgiManager, ManagedBundle knownBundleMetadata, InputStream zipIn); void setStart(boolean start); void setLoadCatalogBom(boolean loadCatalogBom); void setForce(boolean force); void setDeferredStart(boolean deferredStart); void setValidateTypes(boolean validateTypes); ReferenceWithError<OsgiBundleInstallationResult> install(); static final ConfigKey<String> PERSIST_MANAGED_BUNDLE_WHITELIST_REGEX; static final ConfigKey<String> PERSIST_MANAGED_BUNDLE_BLACKLIST_REGEX; }
@Test public void testBlacklistPersistingOrgApacheBrooklyn() throws Exception { OsgiManager osgiManager = newMockOsgiManager(mgmt); OsgiArchiveInstaller installer = new OsgiArchiveInstaller(osgiManager, Mockito.mock(ManagedBundle.class), new ByteArrayInputStream(new byte[0])); assertTrue(installer.isBlacklistedForPersistence(newMockManagedBundle("org.apache.brooklyn.core", "1.0.0"))); assertTrue(installer.isBlacklistedForPersistence(newMockManagedBundle("org.apache.brooklyn.mybundle", "1.0.0"))); assertFalse(installer.isBlacklistedForPersistence(newMockManagedBundle("org.apache.different", "1.0.0"))); }
@Test public void testWhitelistPersistingBundle() throws Exception { mgmt.getBrooklynProperties().put(BrooklynServerConfig.PERSIST_MANAGED_BUNDLE_WHITELIST_REGEX, "org\\.apache\\.brooklyn\\.mywhitelistedbundle"); OsgiManager osgiManager = newMockOsgiManager(mgmt); OsgiArchiveInstaller installer = new OsgiArchiveInstaller(osgiManager, Mockito.mock(ManagedBundle.class), new ByteArrayInputStream(new byte[0])); assertTrue(installer.isBlacklistedForPersistence(newMockManagedBundle("org.apache.brooklyn.core", "1.0.0"))); assertFalse(installer.isBlacklistedForPersistence(newMockManagedBundle("org.apache.brooklyn.mywhitelistedbundle", "1.0.0"))); }
@Test public void testCustomBlacklistPersistingBundle() throws Exception { mgmt.getBrooklynProperties().put(BrooklynServerConfig.PERSIST_MANAGED_BUNDLE_BLACKLIST_REGEX, "org\\.example\\.myblacklistprefix.*"); OsgiManager osgiManager = newMockOsgiManager(mgmt); OsgiArchiveInstaller installer = new OsgiArchiveInstaller(osgiManager, Mockito.mock(ManagedBundle.class), new ByteArrayInputStream(new byte[0])); assertTrue(installer.isBlacklistedForPersistence(newMockManagedBundle("org.example.myblacklistprefix.mysuffix", "1.0.0"))); assertFalse(installer.isBlacklistedForPersistence(newMockManagedBundle("org.apache.brooklyn.core", "1.0.0"))); }