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:25:35 UTC
[05/39] brooklyn-server git commit: support force when wrapping a BOM
support force when wrapping a BOM
new batch of tests around catalog versioning with OSGi
Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/f16bda93
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/f16bda93
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/f16bda93
Branch: refs/heads/master
Commit: f16bda9310469ec35f4de8f3a084746abfe08a44
Parents: e7dc875
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Authored: Tue Jun 27 16:28:33 2017 +0100
Committer: Alex Heneveld <al...@cloudsoftcorp.com>
Committed: Tue Jun 27 16:28:33 2017 +0100
----------------------------------------------------------------------
.../brooklyn/api/catalog/BrooklynCatalog.java | 4 ++
.../catalog/CatalogOsgiYamlVersioningTest.java | 61 ++++++++++++++++++++
.../catalog/CatalogYamlVersioningTest.java | 59 +++++++++++++++++--
.../catalog/internal/BasicBrooklynCatalog.java | 3 +-
.../catalog/internal/CatalogBundleLoader.java | 6 +-
.../core/mgmt/ha/OsgiArchiveInstaller.java | 2 +-
.../brooklyn/core/mgmt/ha/OsgiManager.java | 11 +++-
7 files changed, 134 insertions(+), 12 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/f16bda93/api/src/main/java/org/apache/brooklyn/api/catalog/BrooklynCatalog.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/brooklyn/api/catalog/BrooklynCatalog.java b/api/src/main/java/org/apache/brooklyn/api/catalog/BrooklynCatalog.java
index 75fe634..3e78843 100644
--- a/api/src/main/java/org/apache/brooklyn/api/catalog/BrooklynCatalog.java
+++ b/api/src/main/java/org/apache/brooklyn/api/catalog/BrooklynCatalog.java
@@ -19,6 +19,7 @@
package org.apache.brooklyn.api.catalog;
import java.util.Collection;
+import java.util.List;
import java.util.NoSuchElementException;
import javax.annotation.Nullable;
@@ -137,6 +138,9 @@ public interface BrooklynCatalog {
*/
Iterable<? extends CatalogItem<?,?>> addItems(String yaml, boolean forceUpdate);
+ /** As {@link #addItems(String, ManagedBundle)} but exposing forcing option as per {@link #addItem(String, boolean)}. */
+ Iterable<? extends CatalogItem<?,?>> addItems(String yaml, ManagedBundle bundle, boolean forceUpdate);
+
/**
* adds an item to the 'manual' catalog;
* this does not update the classpath or have a record to the java Class
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/f16bda93/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogOsgiYamlVersioningTest.java
----------------------------------------------------------------------
diff --git a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogOsgiYamlVersioningTest.java b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogOsgiYamlVersioningTest.java
new file mode 100644
index 0000000..aab9920
--- /dev/null
+++ b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogOsgiYamlVersioningTest.java
@@ -0,0 +1,61 @@
+/*
+ * 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.camp.brooklyn.catalog;
+
+import org.apache.brooklyn.test.Asserts;
+import org.testng.annotations.Test;
+
+/** As parent tests, but using OSGi, and some of the additions are stricter / different */
+public class CatalogOsgiYamlVersioningTest extends CatalogYamlVersioningTest {
+
+ @Override
+ protected boolean disableOsgi() {
+ return false;
+ }
+
+ @Override
+ @Test
+ public void testAddSameVersionWithoutBundle() {
+ try {
+ // parent test should fail in OSGi
+ super.testAddSameVersionWithoutBundle();
+ Asserts.shouldHaveFailedPreviously("Expected to fail because containing bundle will be different when using OSGi");
+ } catch (Exception e) {
+ assertExpectedFailureSaysUpdatingExistingItemForbidden(e);
+ assertExpectedFailureIncludesSampleId(e);
+ }
+ }
+
+ @Test
+ public void testAddSameVersionWithoutBundleWorksIfForced() {
+ String symbolicName = "sampleId";
+ String version = "0.1.0";
+ addCatalogEntityWithoutBundle(symbolicName, version);
+ forceCatalogUpdate();
+ addCatalogEntityWithoutBundle(symbolicName, version);
+ }
+
+
+ @Override
+ protected void checkAddSameVersionFailsWhenIconIsDifferent(Exception e) {
+ Asserts.expectedFailureContainsIgnoreCase(e,
+ "cannot install a different bundle at a same non-snapshot version");
+ assertExpectedFailureIncludesSampleId(e);
+ }
+}
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/f16bda93/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogYamlVersioningTest.java
----------------------------------------------------------------------
diff --git a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogYamlVersioningTest.java b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogYamlVersioningTest.java
index bebda6f..cd4525a 100644
--- a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogYamlVersioningTest.java
+++ b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogYamlVersioningTest.java
@@ -21,7 +21,6 @@ package org.apache.brooklyn.camp.brooklyn.catalog;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertTrue;
-import static org.testng.Assert.fail;
import org.apache.brooklyn.api.entity.Entity;
import org.apache.brooklyn.api.typereg.BrooklynTypeRegistry;
@@ -33,6 +32,7 @@ import org.apache.brooklyn.core.typereg.RegisteredTypePredicates;
import org.apache.brooklyn.core.typereg.RegisteredTypes;
import org.apache.brooklyn.entity.stock.BasicApplication;
import org.apache.brooklyn.entity.stock.BasicEntity;
+import org.apache.brooklyn.test.Asserts;
import org.testng.Assert;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
@@ -50,7 +50,7 @@ public class CatalogYamlVersioningTest extends AbstractYamlTest {
super.setUp();
types = mgmt().getTypeRegistry();
}
-
+
@Test
public void testAddItem() {
String symbolicName = "sampleId";
@@ -67,19 +67,43 @@ public class CatalogYamlVersioningTest extends AbstractYamlTest {
}
@Test
- public void testAddSameVersionFailsWhenIconIsDifferent() {
+ public void testAddSameVersionWorksIfSame() {
String symbolicName = "sampleId";
String version = "0.1.0";
addCatalogEntity(symbolicName, version);
+ // works if no different
+ addCatalogEntity(symbolicName, version);
+ }
+
+ @Test
+ public void testAddSameVersionFailsWhenIconIsDifferent() {
+ String symbolicName = "sampleId";
+ String version = "0.1.0";
addCatalogEntity(symbolicName, version);
try {
addCatalogEntity(symbolicName, version, BasicEntity.class.getName(), "classpath:/another/icon.png");
- fail("Expected to fail");
- } catch (IllegalStateException e) {
- assertEquals(e.getMessage(), "Updating existing catalog entries is forbidden: " + symbolicName + ":" + version + ". Use forceUpdate argument to override.");
+ Asserts.shouldHaveFailedPreviously("Expected to fail");
+ } catch (Exception e) {
+ checkAddSameVersionFailsWhenIconIsDifferent(e);
}
}
+ protected void checkAddSameVersionFailsWhenIconIsDifferent(Exception e) {
+ assertExpectedFailureSaysUpdatingExistingItemForbidden(e);
+ assertExpectedFailureIncludesSampleId(e);
+ }
+
+ protected void assertExpectedFailureIncludesSampleId(Exception e) {
+ String symbolicName = "sampleId";
+ String version = "0.1.0";
+ Asserts.expectedFailureContainsIgnoreCase(e,
+ symbolicName + ":" + version);
+ }
+ protected void assertExpectedFailureSaysUpdatingExistingItemForbidden(Exception e) {
+ Asserts.expectedFailureContainsIgnoreCase(e,
+ "Updating existing catalog entries is forbidden");
+ }
+
@Test
public void testAddSameSnapshotVersionSucceedsWhenIconIsDifferent() {
String symbolicName = "sampleId";
@@ -93,6 +117,15 @@ public class CatalogYamlVersioningTest extends AbstractYamlTest {
}
@Test
+ public void testAddSameVersionWithoutBundle() {
+ String symbolicName = "sampleId";
+ String version = "0.1.0";
+ addCatalogEntityWithoutBundle(symbolicName, version);
+ // allowed when not OSGi
+ addCatalogEntityWithoutBundle(symbolicName, version);
+ }
+
+ @Test
public void testAddSameVersionForce() {
String symbolicName = "sampleId";
String version = "0.1.0";
@@ -281,4 +314,18 @@ public class CatalogYamlVersioningTest extends AbstractYamlTest {
" type: " + type);
}
+ protected void addCatalogEntityWithoutBundle(String symbolicName, String version) {
+ addCatalogItems(
+ "brooklyn.catalog:",
+ " items:",
+ " - id: " + symbolicName,
+ (version != null ? " version: " + version : ""),
+ " itemType: entity",
+ " name: My Catalog App",
+ " description: My description",
+ " icon_url: "+"classpath://path/to/myicon.jpg",
+ " item:",
+ " type: " + BasicEntity.class.getName());
+ }
+
}
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/f16bda93/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 9d40e2f..8d36b68 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
@@ -1233,7 +1233,8 @@ public class BasicBrooklynCatalog implements BrooklynCatalog {
return addItems(yaml, bundle, false);
}
- private List<? extends CatalogItem<?,?>> addItems(String yaml, ManagedBundle bundle, boolean forceUpdate) {
+ @Override
+ public List<? extends CatalogItem<?,?>> addItems(String yaml, ManagedBundle bundle, boolean forceUpdate) {
log.debug("Adding manual catalog item to "+mgmt+": "+yaml);
checkNotNull(yaml, "yaml");
List<CatalogItemDtoAbstract<?, ?>> result = collectCatalogItems(yaml, bundle);
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/f16bda93/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogBundleLoader.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogBundleLoader.java b/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogBundleLoader.java
index 8d3179d..cce1258 100644
--- a/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogBundleLoader.java
+++ b/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogBundleLoader.java
@@ -72,6 +72,10 @@ public class CatalogBundleLoader {
* @throws RuntimeException if the catalog items failed to be added to the catalog
*/
public Iterable<? extends CatalogItem<?, ?>> scanForCatalog(Bundle bundle) {
+ return scanForCatalog(bundle, false);
+ }
+
+ public Iterable<? extends CatalogItem<?, ?>> scanForCatalog(Bundle bundle, boolean force) {
ManagedBundle mb = ((ManagementContextInternal)managementContext).getOsgiManager().get().getManagedBundle(
new VersionedName(bundle));
@@ -82,7 +86,7 @@ public class CatalogBundleLoader {
LOG.debug("Found catalog BOM in {} {} {}", CatalogUtils.bundleIds(bundle));
String bomText = readBom(bom);
String bomWithLibraryPath = addLibraryDetails(bundle, bomText);
- catalogItems = this.managementContext.getCatalog().addItems(bomWithLibraryPath, mb);
+ catalogItems = this.managementContext.getCatalog().addItems(bomWithLibraryPath, mb, force);
for (CatalogItem<?, ?> item : catalogItems) {
LOG.debug("Added to catalog: {}, {}", item.getSymbolicName(), item.getVersion());
}
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/f16bda93/core/src/main/java/org/apache/brooklyn/core/mgmt/ha/OsgiArchiveInstaller.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/mgmt/ha/OsgiArchiveInstaller.java b/core/src/main/java/org/apache/brooklyn/core/mgmt/ha/OsgiArchiveInstaller.java
index d15a036..50f8752 100644
--- a/core/src/main/java/org/apache/brooklyn/core/mgmt/ha/OsgiArchiveInstaller.java
+++ b/core/src/main/java/org/apache/brooklyn/core/mgmt/ha/OsgiArchiveInstaller.java
@@ -375,7 +375,7 @@ class OsgiArchiveInstaller {
osgiManager.uninstallCatalogItemsFromBundle( result.getVersionedName() );
// (ideally removal and addition would be atomic)
}
- for (CatalogItem<?,?> ci: osgiManager.loadCatalogBom(result.bundle)) {
+ for (CatalogItem<?,?> ci: osgiManager.loadCatalogBom(result.bundle, force)) {
result.catalogItemsInstalled.add(ci.getId());
}
}
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/f16bda93/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 34a5d0b..77d2a80 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
@@ -375,10 +375,15 @@ public class OsgiManager {
// possibly remove that other capability, so that bundles with BOMs _have_ to be installed via this method.
// (load order gets confusing with auto-scanning...)
public List<? extends CatalogItem<?,?>> loadCatalogBom(Bundle bundle) {
- return MutableList.copyOf(loadCatalogBom(mgmt, bundle));
+ return loadCatalogBom(bundle, false);
}
- private static Iterable<? extends CatalogItem<?, ?>> loadCatalogBom(ManagementContext mgmt, Bundle bundle) {
+ @Beta // as above
+ public List<? extends CatalogItem<?,?>> loadCatalogBom(Bundle bundle, boolean force) {
+ return MutableList.copyOf(loadCatalogBom(mgmt, bundle, force));
+ }
+
+ private static Iterable<? extends CatalogItem<?, ?>> loadCatalogBom(ManagementContext mgmt, Bundle bundle, boolean force) {
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)
@@ -388,7 +393,7 @@ public class OsgiManager {
// here to get back the predicate from it.
final Predicate<Bundle> applicationsPermitted = Predicates.<Bundle>alwaysTrue();
- catalogItems = new CatalogBundleLoader(applicationsPermitted, mgmt).scanForCatalog(bundle);
+ catalogItems = new CatalogBundleLoader(applicationsPermitted, mgmt).scanForCatalog(bundle, force);
} 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