You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by ge...@apache.org on 2017/07/19 16:26:01 UTC
[31/39] brooklyn-server git commit: remove CatalogBomScanner
remove CatalogBomScanner
Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/5868124a
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/5868124a
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/5868124a
Branch: refs/heads/master
Commit: 5868124a4eba5e02847479178bfa7415340ffc0a
Parents: d0183c2
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Authored: Wed Jul 12 09:23:37 2017 +0100
Committer: Alex Heneveld <al...@cloudsoftcorp.com>
Committed: Wed Jul 12 09:27:44 2017 +0100
----------------------------------------------------------------------
.../catalog/CatalogMakeOsgiBundleTest.java | 20 ---
.../core/BrooklynFeatureEnablement.java | 12 --
.../catalog/internal/BasicBrooklynCatalog.java | 2 +-
.../catalog/internal/CatalogBomScanner.java | 136 -------------------
.../catalog/internal/CatalogBundleTracker.java | 71 ----------
.../brooklyn/core/mgmt/ha/OsgiManager.java | 40 +++---
6 files changed, 18 insertions(+), 263 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/5868124a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogMakeOsgiBundleTest.java
----------------------------------------------------------------------
diff --git a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogMakeOsgiBundleTest.java b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogMakeOsgiBundleTest.java
index 397bcf7..290c9e8 100644
--- a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogMakeOsgiBundleTest.java
+++ b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogMakeOsgiBundleTest.java
@@ -29,12 +29,10 @@ import java.util.zip.ZipEntry;
import org.apache.brooklyn.api.entity.Application;
import org.apache.brooklyn.api.entity.Entity;
-import org.apache.brooklyn.api.mgmt.ManagementContext;
import org.apache.brooklyn.api.typereg.OsgiBundleWithUrl;
import org.apache.brooklyn.api.typereg.RegisteredType;
import org.apache.brooklyn.camp.brooklyn.AbstractYamlTest;
import org.apache.brooklyn.core.BrooklynFeatureEnablement;
-import org.apache.brooklyn.core.catalog.internal.CatalogBomScanner;
import org.apache.brooklyn.core.entity.Entities;
import org.apache.brooklyn.core.entity.EntityAsserts;
import org.apache.brooklyn.core.mgmt.ha.OsgiBundleInstallationResult;
@@ -53,8 +51,6 @@ import org.apache.brooklyn.util.osgi.VersionedName;
import org.apache.brooklyn.util.text.Identifiers;
import org.apache.brooklyn.util.text.Strings;
import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.ServiceReference;
import org.testng.Assert;
import org.testng.annotations.AfterClass;
import org.testng.annotations.AfterMethod;
@@ -80,7 +76,6 @@ public class CatalogMakeOsgiBundleTest extends AbstractYamlTest {
@BeforeClass(alwaysRun = true)
public void setUp() throws Exception {
super.setUp();
- manuallyEnableBomScanner(mgmt());
bm = new BundleMaker( ((LocalManagementContext)mgmt()).getOsgiManager().get().getFramework(), ResourceUtils.create(this) );
}
@@ -102,21 +97,6 @@ public class CatalogMakeOsgiBundleTest extends AbstractYamlTest {
super.tearDown();
}
- public static void manuallyEnableBomScanner(ManagementContext mgmt) {
- BrooklynFeatureEnablement.enable(BrooklynFeatureEnablement.FEATURE_LOAD_BUNDLE_CATALOG_BOM);
-
- CatalogBomScanner scanner = new CatalogBomScanner();
- BundleContext context = ((LocalManagementContext)mgmt).getOsgiManager().get().getFramework().getBundleContext();
-
- context.registerService(ManagementContext.class.getName(), mgmt, null);
- ServiceReference<ManagementContext> ref = context.getServiceReference(ManagementContext.class);
- try {
- scanner.bind(ref);
- } catch (Exception e) {
- throw Exceptions.propagate(e);
- }
- }
-
@AfterMethod(alwaysRun=true)
public void clearFeatureEnablement() throws Exception {
BrooklynFeatureEnablement.clearCache();
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/5868124a/core/src/main/java/org/apache/brooklyn/core/BrooklynFeatureEnablement.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/BrooklynFeatureEnablement.java b/core/src/main/java/org/apache/brooklyn/core/BrooklynFeatureEnablement.java
index 2776d9b..8bbe2a4 100644
--- a/core/src/main/java/org/apache/brooklyn/core/BrooklynFeatureEnablement.java
+++ b/core/src/main/java/org/apache/brooklyn/core/BrooklynFeatureEnablement.java
@@ -115,17 +115,6 @@ public class BrooklynFeatureEnablement {
public static final String FEATURE_VALIDATE_LOCATION_SSH_KEYS = "brooklyn.validate.locationSshKeys";
/**
- * Whether to scan newly loaded bundles for catalog.bom and load it.
- *
- * The functionality loads catalog items regardless of the persistence state so best used with persistence disabled.
- * If a bundle is uploaded its BOM is scanned regardless of this property (this only applies to bundles
- * installed through a non-brooklyn method, eg karaf.)
- *
- * This installs legacy items and so should be deprecated in favour of uploading BOMs which Brooklyn manages.
- */
- public static final String FEATURE_LOAD_BUNDLE_CATALOG_BOM = FEATURE_PROPERTY_PREFIX+".osgi.catalog_bom";
-
- /**
* Values explicitly set by Java calls.
*/
private static final Map<String, Boolean> FEATURE_ENABLEMENTS = Maps.newLinkedHashMap();
@@ -161,7 +150,6 @@ public class BrooklynFeatureEnablement {
setDefault(FEATURE_AUTO_FIX_CATALOG_REF_ON_REBIND, false);
setDefault(FEATURE_SSH_ASYNC_EXEC, false);
setDefault(FEATURE_VALIDATE_LOCATION_SSH_KEYS, true);
- setDefault(FEATURE_LOAD_BUNDLE_CATALOG_BOM, false);
}
static {
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/5868124a/core/src/main/java/org/apache/brooklyn/core/catalog/internal/BasicBrooklynCatalog.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/catalog/internal/BasicBrooklynCatalog.java b/core/src/main/java/org/apache/brooklyn/core/catalog/internal/BasicBrooklynCatalog.java
index 046543b..739f225 100644
--- a/core/src/main/java/org/apache/brooklyn/core/catalog/internal/BasicBrooklynCatalog.java
+++ b/core/src/main/java/org/apache/brooklyn/core/catalog/internal/BasicBrooklynCatalog.java
@@ -1416,7 +1416,7 @@ public class BasicBrooklynCatalog implements BrooklynCatalog {
log.debug("Adding catalog item to "+mgmt+": "+yaml);
checkNotNull(yaml, "yaml");
List<CatalogItemDtoAbstract<?, ?>> result = MutableList.of();
- collectCatalogItemsFromCatalogBomRoot(yaml, bundle, result, true, ImmutableMap.of(), 0, false);
+ collectCatalogItemsFromCatalogBomRoot(yaml, bundle, result, true, ImmutableMap.of(), 0, forceUpdate);
// do this at the end for atomic updates; if there are intra-yaml references, we handle them specially
for (CatalogItemDtoAbstract<?, ?> item: result) {
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/5868124a/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogBomScanner.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogBomScanner.java b/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogBomScanner.java
deleted file mode 100644
index 90efaa2..0000000
--- a/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogBomScanner.java
+++ /dev/null
@@ -1,136 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.brooklyn.core.catalog.internal;
-
-import java.util.List;
-
-import javax.annotation.Nullable;
-
-import org.apache.brooklyn.api.mgmt.ManagementContext;
-import org.apache.brooklyn.core.BrooklynFeatureEnablement;
-import org.apache.brooklyn.util.text.Strings;
-import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.ServiceReference;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import com.google.common.annotations.Beta;
-import com.google.common.base.Predicate;
-import com.google.common.collect.ImmutableList;
-
-/** Scans bundles being added to add their catalog.bom to Brooklyn,
- * filtering which bundles are allowed add _applications_ through a whitelist and blacklist.
- * (All bundles are allowed to add other types.)
- * See karaf blueprint.xml for configuration, and tests in dist project. */
-// TODO AH: i wonder if we can remove this or generalize it; disallowing just app/templates seems a little weird
-// (makes sense as those appear more prominently in some displays, but feels like there'd be a better way
-// to customize; intercepting at this particular point is surprising)
-@Beta
-public class CatalogBomScanner {
-
- private final String ACCEPT_ALL_BY_DEFAULT = ".*";
-
- private static final Logger LOG = LoggerFactory.getLogger(CatalogBomScanner.class);
-
- // configured by `brooklyn.catalog.osgi.application.{white,black}list`
- private List<String> bundlesAllowedToAddAppsWhitelist = ImmutableList.of(ACCEPT_ALL_BY_DEFAULT);
- private List<String> bundlesAllowedToAddAppsBlacklist = ImmutableList.of();
-
- private CatalogBundleTracker catalogBundleTracker;
-
- public void bind(ServiceReference<ManagementContext> mgmtContextReference) throws Exception {
- if (isEnabled()) {
- LOG.debug("Binding management context with whiteList [{}] and blacklist [{}]",
- Strings.join(getWhiteList(), "; "),
- Strings.join(getBlackList(), "; "));
-
- final BundleContext bundleContext = mgmtContextReference.getBundle().getBundleContext();
- ManagementContext mgmt = bundleContext.getService(mgmtContextReference);
- CatalogBundleLoader bundleLoader = new CatalogBundleLoader(new BundlesAllowedToAddAddsFilter(), mgmt);
-
- catalogBundleTracker = new CatalogBundleTracker(bundleContext, bundleLoader);
- catalogBundleTracker.open();
- }
- }
-
- public void unbind(ServiceReference<ManagementContext> mgmtContextReference) throws Exception {
- if (isEnabled()) {
- LOG.debug("Unbinding management context");
- if (null != catalogBundleTracker) {
- CatalogBundleTracker temp = catalogBundleTracker;
- catalogBundleTracker = null;
- temp.close();
- }
- mgmtContextReference.getBundle().getBundleContext().ungetService(mgmtContextReference);
- }
- }
-
- private boolean isEnabled() {
- return BrooklynFeatureEnablement.isEnabled(BrooklynFeatureEnablement.FEATURE_LOAD_BUNDLE_CATALOG_BOM);
- }
-
- public List<String> getWhiteList() {
- return bundlesAllowedToAddAppsWhitelist;
- }
-
- public void setWhiteList(List<String> whiteList) {
- this.bundlesAllowedToAddAppsWhitelist = whiteList;
- }
-
- public void setWhiteList(String whiteListText) {
- LOG.debug("Setting whiteList to ", whiteListText);
- this.bundlesAllowedToAddAppsWhitelist = Strings.parseCsv(whiteListText);
- }
-
- public List<String> getBlackList() {
- return bundlesAllowedToAddAppsBlacklist;
- }
-
- public void setBlackList(List<String> blackList) {
- this.bundlesAllowedToAddAppsBlacklist = blackList;
- }
-
- public void setBlackList(String blackListText) {
- LOG.debug("Setting blackList to ", blackListText);
- this.bundlesAllowedToAddAppsBlacklist = Strings.parseCsv(blackListText);
- }
-
- public class BundlesAllowedToAddAddsFilter implements Predicate<Bundle> {
- @Override
- public boolean apply(@Nullable Bundle input) {
- return passesWhiteAndBlacklists(input);
- }
- }
-
- private boolean passesWhiteAndBlacklists(Bundle bundle) {
- return on(bundle, getWhiteList()) && !on(bundle, getBlackList());
- }
-
- private boolean on(Bundle bundle, List<String> list) {
- for (String candidate : list) {
- final String symbolicName = bundle.getSymbolicName();
- if (symbolicName.matches(candidate.trim())) {
- return true;
- }
- }
- return false;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/5868124a/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogBundleTracker.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogBundleTracker.java b/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogBundleTracker.java
deleted file mode 100644
index 1ec4cd2..0000000
--- a/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogBundleTracker.java
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.brooklyn.core.catalog.internal;
-
-import org.apache.brooklyn.util.osgi.VersionedName;
-import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.BundleEvent;
-import org.osgi.util.tracker.BundleTracker;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import com.google.common.annotations.Beta;
-
-@Beta
-public class CatalogBundleTracker extends BundleTracker<Object> {
-
- private static final Logger LOG = LoggerFactory.getLogger(CatalogBundleTracker.class);
-
- private CatalogBundleLoader catalogBundleLoader;
-
- public CatalogBundleTracker(BundleContext bundleContext, CatalogBundleLoader catalogBundleLoader) {
- super(bundleContext, Bundle.ACTIVE, null);
- this.catalogBundleLoader = catalogBundleLoader;
- }
-
- /**
- * Scans the bundle being added for a catalog.bom file and adds any entries in it to the catalog.
- *
- * @param bundle The bundle being added to the bundle context.
- * @param bundleEvent The event of the addition.
- * @return null
- * @throws RuntimeException if the catalog items failed to be added to the catalog
- */
- @Override
- public Object addingBundle(Bundle bundle, BundleEvent bundleEvent) {
- catalogBundleLoader.scanForCatalog(bundle, false, true);
- return null;
- }
-
- /**
- * Remove the given entries from the catalog, related to the given bundle.
- *
- * @param bundle The bundle being removed to the bundle context.
- * @param bundleEvent The event of the removal.
- * @param callback Ignored
- * @throws RuntimeException if the catalog items failed to be added to the catalog
- */
- @Override
- public void removedBundle(Bundle bundle, BundleEvent bundleEvent, Object callback) {
- LOG.debug("Unloading catalog BOM entries from {} {} {}", CatalogUtils.bundleIds(bundle));
- catalogBundleLoader.removeFromCatalog(new VersionedName(bundle));
- }
-}
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/5868124a/core/src/main/java/org/apache/brooklyn/core/mgmt/ha/OsgiManager.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/mgmt/ha/OsgiManager.java b/core/src/main/java/org/apache/brooklyn/core/mgmt/ha/OsgiManager.java
index 9b92a8c..9d6587c 100644
--- a/core/src/main/java/org/apache/brooklyn/core/mgmt/ha/OsgiManager.java
+++ b/core/src/main/java/org/apache/brooklyn/core/mgmt/ha/OsgiManager.java
@@ -41,11 +41,9 @@ import org.apache.brooklyn.api.typereg.ManagedBundle;
import org.apache.brooklyn.api.typereg.OsgiBundleWithUrl;
import org.apache.brooklyn.api.typereg.RegisteredType;
import org.apache.brooklyn.config.ConfigKey;
-import org.apache.brooklyn.core.BrooklynFeatureEnablement;
import org.apache.brooklyn.core.BrooklynVersion;
import org.apache.brooklyn.core.catalog.internal.CatalogBundleLoader;
import org.apache.brooklyn.core.config.ConfigKeys;
-import org.apache.brooklyn.core.mgmt.internal.ManagementContextInternal;
import org.apache.brooklyn.core.server.BrooklynServerConfig;
import org.apache.brooklyn.core.server.BrooklynServerPaths;
import org.apache.brooklyn.core.typereg.RegisteredTypePredicates;
@@ -395,33 +393,29 @@ public class OsgiManager {
private static Iterable<? extends CatalogItem<?, ?>> loadCatalogBomInternal(ManagementContext mgmt, Bundle bundle, boolean force, boolean validate, boolean legacy) {
Iterable<? extends CatalogItem<?, ?>> catalogItems = MutableList.of();
- if (!BrooklynFeatureEnablement.isEnabled(BrooklynFeatureEnablement.FEATURE_LOAD_BUNDLE_CATALOG_BOM)) {
- // if the above feature is not enabled, let's do it manually (as a contract of this method)
- try {
- // TODO improve on this - it ignores the configuration of whitelists, see CatalogBomScanner.
- // One way would be to add the CatalogBomScanner to the new Scratchpad area, then retrieving the singleton
- // here to get back the predicate from it.
- final Predicate<Bundle> applicationsPermitted = Predicates.<Bundle>alwaysTrue();
-
- CatalogBundleLoader cl = new CatalogBundleLoader(applicationsPermitted, mgmt);
- if (legacy) {
- catalogItems = cl.scanForCatalogLegacy(bundle, force);
- } else {
- cl.scanForCatalog(bundle, force, validate);
- catalogItems = null;
- }
- } catch (RuntimeException ex) {
- // TODO confirm -- as of May 2017 we no longer uninstall the bundle if install of catalog items fails;
- // caller needs to upgrade, or uninstall then reinstall
- // (this uninstall wouldn't have unmanaged it in brooklyn in any case)
+
+ try {
+ final Predicate<Bundle> applicationsPermitted = Predicates.<Bundle>alwaysTrue();
+
+ CatalogBundleLoader cl = new CatalogBundleLoader(applicationsPermitted, mgmt);
+ if (legacy) {
+ catalogItems = cl.scanForCatalogLegacy(bundle, force);
+ } else {
+ cl.scanForCatalog(bundle, force, validate);
+ catalogItems = null;
+ }
+ } catch (RuntimeException ex) {
+ // TODO confirm -- as of May 2017 we no longer uninstall the bundle if install of catalog items fails;
+ // caller needs to upgrade, or uninstall then reinstall
+ // (this uninstall wouldn't have unmanaged it in brooklyn in any case)
// try {
// bundle.uninstall();
// } catch (BundleException e) {
// log.error("Cannot uninstall bundle " + bundle.getSymbolicName() + ":" + bundle.getVersion()+" (after error installing catalog items)", e);
// }
- throw new IllegalArgumentException("Error installing catalog items", ex);
- }
+ throw new IllegalArgumentException("Error installing catalog items", ex);
}
+
return catalogItems;
}