Repository: brooklyn-server Updated Branches: refs/heads/master 48933eb6b -> fc575d77b
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/e0feddb7/core/src/test/java/org/apache/brooklyn/core/catalog/internal/CatalogScanTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/brooklyn/core/catalog/internal/CatalogScanTest.java b/core/src/test/java/org/apache/brooklyn/core/catalog/internal/CatalogScanTest.java deleted file mode 100644 index f08b771..0000000 --- a/core/src/test/java/org/apache/brooklyn/core/catalog/internal/CatalogScanTest.java +++ /dev/null @@ -1,199 +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.net.URLEncoder; -import java.util.List; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.testng.Assert; -import org.testng.annotations.AfterMethod; -import org.testng.annotations.Test; -import org.apache.brooklyn.api.catalog.BrooklynCatalog; -import org.apache.brooklyn.api.catalog.CatalogItem; -import org.apache.brooklyn.api.entity.Application; -import org.apache.brooklyn.api.entity.EntitySpec; -import org.apache.brooklyn.core.catalog.CatalogPredicates; -import org.apache.brooklyn.core.catalog.internal.BasicBrooklynCatalog; -import org.apache.brooklyn.core.catalog.internal.MyCatalogItems.MySillyAppTemplate; -import org.apache.brooklyn.core.entity.Entities; -import org.apache.brooklyn.core.internal.BrooklynProperties; -import org.apache.brooklyn.core.mgmt.internal.LocalManagementContext; -import org.apache.brooklyn.core.server.BrooklynServerConfig; -import org.apache.brooklyn.util.core.ResourceUtils; -import org.apache.brooklyn.util.net.Urls; -import org.apache.brooklyn.util.text.Strings; - -import com.google.common.base.Predicates; -import com.google.common.collect.Iterables; -import com.google.common.collect.Lists; - -public class CatalogScanTest { - - private static final Logger log = LoggerFactory.getLogger(CatalogScanTest.class); - - private BrooklynCatalog defaultCatalog, annotsCatalog, fullCatalog; - - private List<LocalManagementContext> managementContexts = Lists.newCopyOnWriteArrayList(); - - @AfterMethod(alwaysRun = true) - public void tearDown(){ - for (LocalManagementContext managementContext : managementContexts) { - Entities.destroyAll(managementContext); - } - managementContexts.clear(); - } - - private LocalManagementContext newManagementContext(BrooklynProperties props) { - LocalManagementContext result = new LocalManagementContext(props); - managementContexts.add(result); - return result; - } - - private synchronized void loadFullCatalog() { - if (fullCatalog!=null) return; - BrooklynProperties props = BrooklynProperties.Factory.newEmpty(); - props.put(BrooklynServerConfig.BROOKLYN_CATALOG_URL.getName(), - "data:,"+Urls.encode("<catalog><classpath scan=\"types\"/></catalog>")); - fullCatalog = newManagementContext(props).getCatalog(); - log.info("ENTITIES loaded for FULL: "+fullCatalog.getCatalogItems(Predicates.alwaysTrue())); - } - - private synchronized void loadTheDefaultCatalog(boolean lookOnDiskForDefaultCatalog) { - if (defaultCatalog!=null) return; - BrooklynProperties props = BrooklynProperties.Factory.newEmpty(); - props.put(BrooklynServerConfig.BROOKLYN_CATALOG_URL.getName(), - // if default catalog is picked up from the system, we might get random stuff from ~/.brooklyn/ instead of the default; - // useful as an integration check that we default correctly, but irritating for people to use if they have such a catalog installed - (lookOnDiskForDefaultCatalog ? "" : - "data:,"+Urls.encode(new ResourceUtils(this).getResourceAsString("classpath:/brooklyn/default.catalog.bom")))); - LocalManagementContext managementContext = newManagementContext(props); - defaultCatalog = managementContext.getCatalog(); - log.info("ENTITIES loaded for DEFAULT: "+defaultCatalog.getCatalogItems(Predicates.alwaysTrue())); - } - - @SuppressWarnings("deprecation") - private synchronized void loadAnnotationsOnlyCatalog() { - if (annotsCatalog!=null) return; - BrooklynProperties props = BrooklynProperties.Factory.newEmpty(); - props.put(BrooklynServerConfig.BROOKLYN_CATALOG_URL.getName(), - "data:,"+URLEncoder.encode("<catalog><classpath scan=\"annotations\"/></catalog>")); - LocalManagementContext managementContext = newManagementContext(props); - annotsCatalog = managementContext.getCatalog(); - log.info("ENTITIES loaded with annotation: "+annotsCatalog.getCatalogItems(Predicates.alwaysTrue())); - } - - @Test - public void testLoadAnnotations() { - loadAnnotationsOnlyCatalog(); - BrooklynCatalog c = annotsCatalog; - - Iterable<CatalogItem<Object,Object>> bases = c.getCatalogItems(CatalogPredicates.displayName(Predicates.containsPattern("MyBaseEntity"))); - Assert.assertEquals(Iterables.size(bases), 0, "should have been empty: "+bases); - - Iterable<CatalogItem<Object,Object>> asdfjkls = c.getCatalogItems(CatalogPredicates.displayName(Predicates.containsPattern("__asdfjkls__shouldnotbefound"))); - Assert.assertEquals(Iterables.size(asdfjkls), 0); - - Iterable<CatalogItem<Object,Object>> silly1 = c.getCatalogItems(CatalogPredicates.displayName(Predicates.equalTo("MySillyAppTemplate"))); - Iterable<CatalogItem<Object,Object>> silly2 = c.getCatalogItems(CatalogPredicates.javaType(Predicates.equalTo(MySillyAppTemplate.class.getName()))); - CatalogItem<Object, Object> silly1El = Iterables.getOnlyElement(silly1); - Assert.assertEquals(silly1El, Iterables.getOnlyElement(silly2)); - - CatalogItem<Application,EntitySpec<? extends Application>> s1 = c.getCatalogItem(Application.class, silly1El.getSymbolicName(), silly1El.getVersion()); - Assert.assertEquals(s1, silly1El); - - Assert.assertEquals(s1.getDescription(), "Some silly app test"); - - Class<?> app = c.peekSpec(s1).getType(); - Assert.assertEquals(MySillyAppTemplate.class, app); - - String xml = ((BasicBrooklynCatalog)c).toXmlString(); - log.info("Catalog is:\n"+xml); - Assert.assertTrue(xml.indexOf("Some silly app test") >= 0); - } - - @Test - public void testAnnotationLoadsSomeApps() { - loadAnnotationsOnlyCatalog(); - Iterable<CatalogItem<Object,Object>> silly1 = annotsCatalog.getCatalogItems(CatalogPredicates.displayName(Predicates.equalTo("MySillyAppTemplate"))); - Assert.assertEquals(Iterables.getOnlyElement(silly1).getDescription(), "Some silly app test"); - } - - @Test - public void testAnnotationLoadsSomeAppBuilders() { - loadAnnotationsOnlyCatalog(); - Iterable<CatalogItem<Object,Object>> silly1 = annotsCatalog.getCatalogItems(CatalogPredicates.displayName(Predicates.equalTo("MySillyAppBuilderTemplate"))); - Assert.assertEquals(Iterables.getOnlyElement(silly1).getDescription(), "Some silly app builder test"); - } - - @Test - public void testMoreTypesThanAnnotations() { - loadAnnotationsOnlyCatalog(); - loadFullCatalog(); - - int numFromAnnots = Iterables.size(annotsCatalog.getCatalogItems(Predicates.alwaysTrue())); - int numFromTypes = Iterables.size(fullCatalog.getCatalogItems(Predicates.alwaysTrue())); - - Assert.assertTrue(numFromAnnots < numFromTypes, "full="+numFromTypes+" annots="+numFromAnnots); - } - - @Test - public void testMoreTypesThanAnnotationsForApps() { - loadAnnotationsOnlyCatalog(); - loadFullCatalog(); - - int numFromAnnots = Iterables.size(annotsCatalog.getCatalogItems(CatalogPredicates.IS_TEMPLATE)); - int numFromTypes = Iterables.size(fullCatalog.getCatalogItems(CatalogPredicates.IS_TEMPLATE)); - - Assert.assertTrue(numFromAnnots < numFromTypes, "full="+numFromTypes+" annots="+numFromAnnots); - } - - @Test - public void testAnnotationIsDefault() { - doTestAnnotationIsDefault(false); - } - - // see comment in load method; likely fails if a custom catalog is installed in ~/.brooklyn/ - @Test(groups="Integration", enabled=false) - public void testAnnotationIsDefaultOnDisk() { - doTestAnnotationIsDefault(true); - } - - private void doTestAnnotationIsDefault(boolean lookOnDiskForDefaultCatalog) { - loadTheDefaultCatalog(false); - int numInDefault = Iterables.size(defaultCatalog.getCatalogItems(Predicates.alwaysTrue())); - - loadAnnotationsOnlyCatalog(); - int numFromAnnots = Iterables.size(annotsCatalog.getCatalogItems(Predicates.alwaysTrue())); - - Assert.assertEquals(numInDefault, numFromAnnots); - Assert.assertTrue(numInDefault>0, "Expected more than 0 entries"); - } - - // a simple test asserting no errors when listing the real catalog, and listing them for reference - // also useful to test variants in a stored catalog to assert they all load - // TODO integration tests which build up catalogs assuming other things are installed - @Test - public void testListCurrentCatalogItems() { - LocalManagementContext mgmt = newManagementContext(BrooklynProperties.Factory.newDefault()); - log.info("ITEMS\n"+Strings.join(mgmt.getCatalog().getCatalogItems(), "\n")); - } - -} http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/e0feddb7/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindCatalogItemTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindCatalogItemTest.java b/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindCatalogItemTest.java index 6fbffdd..292d0f4 100644 --- a/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindCatalogItemTest.java +++ b/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindCatalogItemTest.java @@ -19,6 +19,7 @@ package org.apache.brooklyn.core.mgmt.rebind; import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertFalse; import static org.testng.Assert.assertNotNull; import static org.testng.Assert.assertTrue; import static org.testng.Assert.fail; @@ -33,8 +34,8 @@ import org.apache.brooklyn.api.mgmt.ManagementContext; import org.apache.brooklyn.api.mgmt.ha.HighAvailabilityMode; import org.apache.brooklyn.api.typereg.RegisteredType; import org.apache.brooklyn.core.BrooklynFeatureEnablement; +import org.apache.brooklyn.core.catalog.CatalogPredicates; import org.apache.brooklyn.core.catalog.internal.BasicBrooklynCatalog; -import org.apache.brooklyn.core.catalog.internal.CatalogDto; import org.apache.brooklyn.core.catalog.internal.CatalogEntityItemDto; import org.apache.brooklyn.core.catalog.internal.CatalogItemBuilder; import org.apache.brooklyn.core.catalog.internal.CatalogLocationItemDto; @@ -54,11 +55,20 @@ import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; import com.google.common.base.Joiner; +import com.google.common.base.Optional; +import com.google.common.base.Predicates; import com.google.common.base.Throwables; import com.google.common.collect.Iterables; public class RebindCatalogItemTest extends RebindTestFixtureWithApp { + // FIXME Can we delete all of this? + // Is testing now sufficiently covered by brooklyn-camp module, such as o.a.b.camp.brooklyn.catalog.CatalogYamlRebindTest? + // + // This tests at a slightly different level (calling `mgmt.getCatalog().addItem(item)` directly, and + // asserting `mgmt.getCatalog().getCatalogItems()` is the same before and after rebind. Therefore + // keeping it for now. + private static final String TEST_VERSION = "0.0.1"; private static final Logger LOG = LoggerFactory.getLogger(RebindCatalogItemTest.class); @@ -84,7 +94,6 @@ public class RebindCatalogItemTest extends RebindTestFixtureWithApp { @Override protected LocalManagementContext createOrigManagementContext() { BrooklynProperties properties = BrooklynProperties.Factory.newDefault(); - properties.put(BrooklynServerConfig.BROOKLYN_CATALOG_URL, "classpath://brooklyn/entity/rebind/rebind-catalog-item-test-catalog.xml"); properties.put(BrooklynServerConfig.CATALOG_LOAD_MODE, org.apache.brooklyn.core.catalog.CatalogLoadMode.LOAD_BROOKLYN_CATALOG_URL); return RebindTestUtils.managementContextBuilder(mementoDir, classLoader) .properties(properties) @@ -96,7 +105,6 @@ public class RebindCatalogItemTest extends RebindTestFixtureWithApp { @Override protected LocalManagementContext createNewManagementContext(File mementoDir, HighAvailabilityMode haMode, Map<?, ?> additionalProperties) { BrooklynProperties properties = BrooklynProperties.Factory.newDefault(); - properties.put(BrooklynServerConfig.BROOKLYN_CATALOG_URL, "classpath://brooklyn/entity/rebind/rebind-catalog-item-test-catalog.xml"); return RebindTestUtils.managementContextBuilder(mementoDir, classLoader) .properties(properties) .forLive(useLiveManagementContext()) @@ -106,12 +114,6 @@ public class RebindCatalogItemTest extends RebindTestFixtureWithApp { } @Test - public void testPersistsEntityFromCatalogXml() { - assertEquals(Iterables.size(origManagementContext.getCatalog().getCatalogItems()), 1); - rebindAndAssertCatalogsAreEqual(); - } - - @Test public void testAddAndRebindEntity() throws Exception { String symbolicName = "rebind-yaml-catalog-item-test"; String yaml = Joiner.on("\n").join( @@ -237,31 +239,71 @@ public class RebindCatalogItemTest extends RebindTestFixtureWithApp { @Test(invocationCount = 3) public void testDeletedCatalogItemIsNotPersisted() { - assertEquals(Iterables.size(origManagementContext.getCatalog().getCatalogItems()), 1); - CatalogItem<Object, Object> toRemove = Iterables.getOnlyElement(origManagementContext.getCatalog().getCatalogItems()); + String symbolicName = "rebind-yaml-catalog-item-test"; + String yaml = Joiner.on("\n").join( + "brooklyn.catalog:", + " items:", + " - id: " + symbolicName, + " version: " + TEST_VERSION, + " itemType: entity", + " item:", + " type: io.camp.mock:AppServer"); + CatalogEntityItemDto item = + CatalogItemBuilder.newEntity(symbolicName, TEST_VERSION) + .displayName(symbolicName) + .plan(yaml) + .build(); + origManagementContext.getCatalog().addItem(item); + LOG.info("Added item to catalog: {}, id={}", item, item.getId()); + // Must make sure that the original catalogue item is not managed and unmanaged in the same // persistence window. Because BrooklynMementoPersisterToObjectStore applies writes/deletes // asynchronously the winner is down to a race and the test might pass or fail. origManagementContext.getRebindManager().forcePersistNow(false, null); - origManagementContext.getCatalog().deleteCatalogItem(toRemove.getSymbolicName(), toRemove.getVersion()); - assertEquals(Iterables.size(origManagementContext.getCatalog().getCatalogItems()), 0); + + origManagementContext.getCatalog().deleteCatalogItem(symbolicName, TEST_VERSION); + + Iterable<CatalogItem<Object, Object>> items = origManagementContext.getCatalog().getCatalogItems(); + Optional<CatalogItem<Object, Object>> itemPostDelete = Iterables.tryFind(items, CatalogPredicates.symbolicName(Predicates.equalTo(symbolicName))); + assertFalse(itemPostDelete.isPresent(), "item="+itemPostDelete); + rebindAndAssertCatalogsAreEqual(); - assertEquals(Iterables.size(newManagementContext.getCatalog().getCatalogItems()), 0); + + Iterable<CatalogItem<Object, Object>> newItems = newManagementContext.getCatalog().getCatalogItems(); + Optional<CatalogItem<Object, Object>> itemPostRebind = Iterables.tryFind(newItems, CatalogPredicates.symbolicName(Predicates.equalTo(symbolicName))); + assertFalse(itemPostRebind.isPresent(), "item="+itemPostRebind); } @Test(invocationCount = 3) public void testCanTagCatalogItemAfterRebind() { + String symbolicName = "rebind-yaml-catalog-item-test"; + String yaml = Joiner.on("\n").join( + "brooklyn.catalog:", + " items:", + " - id: " + symbolicName, + " version: " + TEST_VERSION, + " itemType: entity", + " item:", + " type: io.camp.mock:AppServer"); + CatalogEntityItemDto item = + CatalogItemBuilder.newEntity(symbolicName, TEST_VERSION) + .displayName(symbolicName) + .plan(yaml) + .build(); + origManagementContext.getCatalog().addItem(item); + LOG.info("Added item to catalog: {}, id={}", item, item.getId()); + assertEquals(Iterables.size(origManagementContext.getCatalog().getCatalogItems()), 1); - CatalogItem<Object, Object> toTag = Iterables.getOnlyElement(origManagementContext.getCatalog().getCatalogItems()); + CatalogItem<?,?> origItem = origManagementContext.getCatalog().getCatalogItem(symbolicName, TEST_VERSION); final String tag = "tag1"; - toTag.tags().addTag(tag); - assertTrue(toTag.tags().containsTag(tag)); + origItem.tags().addTag(tag); + assertTrue(origItem.tags().containsTag(tag)); rebindAndAssertCatalogsAreEqual(); - toTag = Iterables.getOnlyElement(newManagementContext.getCatalog().getCatalogItems()); - assertTrue(toTag.tags().containsTag(tag)); - toTag.tags().removeTag(tag); + CatalogItem<?, ?> newItem = newManagementContext.getCatalog().getCatalogItem(symbolicName, TEST_VERSION); + assertTrue(newItem.tags().containsTag(tag)); + newItem.tags().removeTag(tag); } @Test @@ -285,8 +327,6 @@ public class RebindCatalogItemTest extends RebindTestFixtureWithApp { .plan(yaml) .build(); catalog.addItem(item); - String catalogXml = catalog.toXmlString(); - catalog.reset(CatalogDto.newDtoFromXmlContents(catalogXml, "Test reset")); rebindAndAssertCatalogsAreEqual(); } http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/e0feddb7/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindCatalogWhenCatalogPersistenceDisabledTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindCatalogWhenCatalogPersistenceDisabledTest.java b/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindCatalogWhenCatalogPersistenceDisabledTest.java index 69940ab..425d520 100644 --- a/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindCatalogWhenCatalogPersistenceDisabledTest.java +++ b/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindCatalogWhenCatalogPersistenceDisabledTest.java @@ -18,23 +18,26 @@ */ package org.apache.brooklyn.core.mgmt.rebind; -import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotNull; +import static org.testng.Assert.assertNull; -import org.apache.brooklyn.api.catalog.CatalogItem; import org.apache.brooklyn.api.entity.EntitySpec; import org.apache.brooklyn.core.BrooklynFeatureEnablement; -import org.apache.brooklyn.core.internal.BrooklynProperties; -import org.apache.brooklyn.core.server.BrooklynServerConfig; +import org.apache.brooklyn.core.catalog.internal.CatalogEntityItemDto; +import org.apache.brooklyn.core.catalog.internal.CatalogItemBuilder; import org.apache.brooklyn.core.test.entity.TestEntity; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.testng.annotations.AfterMethod; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; -import com.google.common.collect.Iterables; +import com.google.common.base.Joiner; public class RebindCatalogWhenCatalogPersistenceDisabledTest extends RebindTestFixtureWithApp { - private static final String TEST_CATALOG = "classpath://brooklyn/entity/rebind/rebind-catalog-item-test-catalog.xml"; + private static final Logger LOG = LoggerFactory.getLogger(RebindCatalogWhenCatalogPersistenceDisabledTest.class); + private boolean catalogPersistenceWasPreviouslyEnabled; @BeforeMethod(alwaysRun = true) @@ -53,24 +56,30 @@ public class RebindCatalogWhenCatalogPersistenceDisabledTest extends RebindTestF BrooklynFeatureEnablement.setEnablement(BrooklynFeatureEnablement.FEATURE_CATALOG_PERSISTENCE_PROPERTY, catalogPersistenceWasPreviouslyEnabled); } - @Override - protected BrooklynProperties createBrooklynProperties() { - BrooklynProperties properties = super.createBrooklynProperties(); - properties.put(BrooklynServerConfig.BROOKLYN_CATALOG_URL, TEST_CATALOG); - return properties; - } - @Test public void testModificationsToCatalogAreNotPersistedWhenCatalogPersistenceFeatureIsDisabled() throws Exception { - assertEquals(Iterables.size(origManagementContext.getCatalog().getCatalogItems()), 1); - CatalogItem<Object, Object> toRemove = Iterables.getOnlyElement(origManagementContext.getCatalog().getCatalogItems()); - origManagementContext.getCatalog().deleteCatalogItem(toRemove.getSymbolicName(), toRemove.getVersion()); - assertEquals(Iterables.size(origManagementContext.getCatalog().getCatalogItems()), 0); + String symbolicName = "rebind-yaml-catalog-item-test"; + String version = "1.2.3"; + String yaml = Joiner.on("\n").join( + "brooklyn.catalog:", + " items:", + " - id: " + symbolicName, + " version: " + version, + " itemType: entity", + " item:", + " type: io.camp.mock:AppServer"); + CatalogEntityItemDto item = + CatalogItemBuilder.newEntity(symbolicName, version) + .displayName(symbolicName) + .plan(yaml) + .build(); + origManagementContext.getCatalog().addItem(item); + LOG.info("Added item to catalog: {}, id={}", item, item.getId()); + + assertNotNull(origManagementContext.getCatalog().getCatalogItem(symbolicName, version)); rebind(); - assertEquals(Iterables.size(newManagementContext.getCatalog().getCatalogItems()), 1); - assertCatalogItemsEqual(Iterables.getOnlyElement(newManagementContext.getCatalog().getCatalogItems()), toRemove); + assertNull(newManagementContext.getCatalog().getCatalogItem(symbolicName, version)); } - } http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/e0feddb7/core/src/test/java/org/apache/brooklyn/core/test/BrooklynAppLiveTestSupport.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/brooklyn/core/test/BrooklynAppLiveTestSupport.java b/core/src/test/java/org/apache/brooklyn/core/test/BrooklynAppLiveTestSupport.java index d48f1bf..2e9fb43 100644 --- a/core/src/test/java/org/apache/brooklyn/core/test/BrooklynAppLiveTestSupport.java +++ b/core/src/test/java/org/apache/brooklyn/core/test/BrooklynAppLiveTestSupport.java @@ -27,8 +27,7 @@ import org.testng.annotations.BeforeMethod; /** * To be extended by live tests. * <p> - * Uses a management context that will not load {@code ~/.brooklyn/catalog.xml} but will - * read from the default {@code ~/.brooklyn/brooklyn.properties}. + * Uses a management context that will read from the default {@code ~/.brooklyn/brooklyn.properties}. */ public class BrooklynAppLiveTestSupport extends BrooklynMgmtUnitTestSupport { http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/e0feddb7/core/src/test/resources/brooklyn/catalog/internal/osgi-catalog.xml ---------------------------------------------------------------------- diff --git a/core/src/test/resources/brooklyn/catalog/internal/osgi-catalog.xml b/core/src/test/resources/brooklyn/catalog/internal/osgi-catalog.xml deleted file mode 100644 index 651dfc5..0000000 --- a/core/src/test/resources/brooklyn/catalog/internal/osgi-catalog.xml +++ /dev/null @@ -1,31 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- - 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. ---> - -<catalog> - <name>OSGi catalogue</name> - - <template name="Entity name" version="9.1.3" type="com.example.ExampleApp"> - <description>An example application</description> - <libraries> - <bundle><url>file://path/to/bundle.jar</url></bundle> - <bundle><url>http://www.url.com/for/bundle.jar</url></bundle> - </libraries> - </template> -</catalog> http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/e0feddb7/core/src/test/resources/brooklyn/entity/rebind/rebind-catalog-item-test-catalog.xml ---------------------------------------------------------------------- diff --git a/core/src/test/resources/brooklyn/entity/rebind/rebind-catalog-item-test-catalog.xml b/core/src/test/resources/brooklyn/entity/rebind/rebind-catalog-item-test-catalog.xml deleted file mode 100644 index 6208f45..0000000 --- a/core/src/test/resources/brooklyn/entity/rebind/rebind-catalog-item-test-catalog.xml +++ /dev/null @@ -1,28 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- - 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. ---> -<catalog> - <name>Rebind catalog item test</name> - - <template name="Entity name" version="9.1.3" type="com.example.ExampleApp"> - <description>An example application</description> - <iconUrl>http://www.example.com/icon.jpg</iconUrl> - </template> - -</catalog> http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/e0feddb7/rest/rest-api/src/main/java/org/apache/brooklyn/rest/api/CatalogApi.java ---------------------------------------------------------------------- diff --git a/rest/rest-api/src/main/java/org/apache/brooklyn/rest/api/CatalogApi.java b/rest/rest-api/src/main/java/org/apache/brooklyn/rest/api/CatalogApi.java index dbdc847..a891a18 100644 --- a/rest/rest-api/src/main/java/org/apache/brooklyn/rest/api/CatalogApi.java +++ b/rest/rest-api/src/main/java/org/apache/brooklyn/rest/api/CatalogApi.java @@ -129,17 +129,6 @@ public interface CatalogApi { required = true) byte[] item); - @POST - @Consumes(MediaType.APPLICATION_XML) - @Path("/reset") - @ApiOperation(value = "Resets the catalog to the given (XML) format") - public Response resetXml( - @ApiParam(name = "xml", value = "XML descriptor of the entire catalog to install", required = true) - @Valid String xml, - @ApiParam(name ="ignoreErrors", value ="Don't fail on invalid bundles, log the errors only") - @QueryParam("ignoreErrors") @DefaultValue("false") - boolean ignoreErrors); - @DELETE @Path("/applications/{symbolicName}/{version}") @ApiOperation( http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/e0feddb7/rest/rest-resources/src/main/java/org/apache/brooklyn/rest/resources/CatalogResource.java ---------------------------------------------------------------------- diff --git a/rest/rest-resources/src/main/java/org/apache/brooklyn/rest/resources/CatalogResource.java b/rest/rest-resources/src/main/java/org/apache/brooklyn/rest/resources/CatalogResource.java index e03bd41..0c487e8 100644 --- a/rest/rest-resources/src/main/java/org/apache/brooklyn/rest/resources/CatalogResource.java +++ b/rest/rest-resources/src/main/java/org/apache/brooklyn/rest/resources/CatalogResource.java @@ -49,7 +49,6 @@ import org.apache.brooklyn.api.policy.PolicySpec; import org.apache.brooklyn.api.typereg.RegisteredType; import org.apache.brooklyn.core.catalog.CatalogPredicates; import org.apache.brooklyn.core.catalog.internal.BasicBrooklynCatalog; -import org.apache.brooklyn.core.catalog.internal.CatalogDto; import org.apache.brooklyn.core.catalog.internal.CatalogItemComparator; import org.apache.brooklyn.core.catalog.internal.CatalogUtils; import org.apache.brooklyn.core.mgmt.entitlement.Entitlements; @@ -58,14 +57,12 @@ import org.apache.brooklyn.core.mgmt.internal.ManagementContextInternal; import org.apache.brooklyn.core.typereg.BasicManagedBundle; import org.apache.brooklyn.core.typereg.RegisteredTypePredicates; import org.apache.brooklyn.rest.api.CatalogApi; -import org.apache.brooklyn.rest.domain.ApiError; import org.apache.brooklyn.rest.domain.CatalogEntitySummary; import org.apache.brooklyn.rest.domain.CatalogItemSummary; import org.apache.brooklyn.rest.domain.CatalogLocationSummary; import org.apache.brooklyn.rest.domain.CatalogPolicySummary; import org.apache.brooklyn.rest.filter.HaHotStateRequired; import org.apache.brooklyn.rest.transform.CatalogTransformer; -import org.apache.brooklyn.rest.util.DefaultExceptionMapper; import org.apache.brooklyn.rest.util.WebResourceUtils; import org.apache.brooklyn.util.collections.MutableList; import org.apache.brooklyn.util.collections.MutableMap; @@ -270,19 +267,6 @@ public class CatalogResource extends AbstractBrooklynRestResource implements Cat } return Response.status(Status.CREATED).entity(result).build(); } - - @SuppressWarnings("deprecation") - @Override - public Response resetXml(String xml, boolean ignoreErrors) { - if (!Entitlements.isEntitled(mgmt().getEntitlementManager(), Entitlements.MODIFY_CATALOG_ITEM, null) || - !Entitlements.isEntitled(mgmt().getEntitlementManager(), Entitlements.ADD_CATALOG_ITEM, null)) { - throw WebResourceUtils.forbidden("User '%s' is not authorized to modify catalog", - Entitlements.getEntitlementContext().user()); - } - - ((BasicBrooklynCatalog)mgmt().getCatalog()).reset(CatalogDto.newDtoFromXmlContents(xml, "REST reset"), !ignoreErrors); - return Response.ok().build(); - } @Override public void deleteApplication(String symbolicName, String version) throws Exception { @@ -459,9 +443,9 @@ public class CatalogResource extends AbstractBrooklynRestResource implements Cat List filters = new ArrayList(); filters.add(type); if (Strings.isNonEmpty(regex)) - filters.add(CatalogPredicates.xml(StringPredicates.containsRegex(regex))); + filters.add(CatalogPredicates.stringRepresentationMatches(StringPredicates.containsRegex(regex))); if (Strings.isNonEmpty(fragment)) - filters.add(CatalogPredicates.xml(StringPredicates.containsLiteralIgnoreCase(fragment))); + filters.add(CatalogPredicates.stringRepresentationMatches(StringPredicates.containsLiteralIgnoreCase(fragment))); if (!allVersions) filters.add(CatalogPredicates.isBestVersion(mgmt())); @@ -567,4 +551,4 @@ public class CatalogResource extends AbstractBrooklynRestResource implements Cat return result; } } - \ No newline at end of file + http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/e0feddb7/rest/rest-resources/src/test/java/org/apache/brooklyn/rest/resources/CatalogResetTest.java ---------------------------------------------------------------------- diff --git a/rest/rest-resources/src/test/java/org/apache/brooklyn/rest/resources/CatalogResetTest.java b/rest/rest-resources/src/test/java/org/apache/brooklyn/rest/resources/CatalogResetTest.java deleted file mode 100644 index 55e536c..0000000 --- a/rest/rest-resources/src/test/java/org/apache/brooklyn/rest/resources/CatalogResetTest.java +++ /dev/null @@ -1,118 +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.rest.resources; - -import static org.testng.Assert.assertNotNull; - -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; - -import org.testng.annotations.AfterClass; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; -import org.apache.brooklyn.api.catalog.BrooklynCatalog; -import org.apache.brooklyn.api.typereg.BrooklynTypeRegistry; -import org.apache.brooklyn.test.http.TestHttpRequestHandler; -import org.apache.brooklyn.test.http.TestHttpServer; -import org.apache.brooklyn.rest.testing.BrooklynRestResourceTest; -import org.apache.brooklyn.util.core.ResourceUtils; -import org.apache.brooklyn.util.http.HttpTool; -import static org.testng.Assert.assertEquals; - -@Test( // by using a different suite name we disallow interleaving other tests between the methods of this test class, which wrecks the test fixtures - suiteName = "CatalogResetTest") -public class CatalogResetTest extends BrooklynRestResourceTest { - - private TestHttpServer server; - private String serverUrl; - - @BeforeClass(alwaysRun=true) - public void setUp() throws Exception { - server = new TestHttpServer() - .handler("/404", new TestHttpRequestHandler().code(Response.Status.NOT_FOUND.getStatusCode()).response("Not Found")) - .handler("/200", new TestHttpRequestHandler().response("OK")) - .start(); - serverUrl = server.getUrl(); - } - - @Override - protected boolean useLocalScannedCatalog() { - return true; - } - - @AfterClass(alwaysRun=true) - public void tearDown() throws Exception { - if (server != null) - server.stop(); - } - - @Test - public void testConnectionError() throws Exception { - Response response = reset("http://0.0.0.0/can-not-connect", false); - assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatus()); - } - - @Test - public void testConnectionErrorIgnore() throws Exception { - reset("http://0.0.0.0/can-not-connect", true); - } - - @Test - public void testResourceMissingError() throws Exception { - Response response = reset(serverUrl + "/404", false); - assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatus()); - } - - @Test - public void testResourceMissingIgnore() throws Exception { - reset(serverUrl + "/404", true); - } - - @Test - public void testResourceInvalidError() throws Exception { - Response response = reset(serverUrl + "/200", false); - assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatus()); - } - - @Test - public void testResourceInvalidIgnore() throws Exception { - reset(serverUrl + "/200", true); - } - - private Response reset(String bundleLocation, boolean ignoreErrors) throws Exception { - String xml = ResourceUtils.create(this).getResourceAsString("classpath://reset-catalog.xml"); - Response response = client().path("/catalog/reset") - .query("ignoreErrors", Boolean.toString(ignoreErrors)) - .header("Content-type", MediaType.APPLICATION_XML) - .post(xml.replace("${bundle-location}", bundleLocation)); - - //if above succeeds assert catalog contents - if (HttpTool.isStatusCodeHealthy(response.getStatus())) - assertItems(); - - return response; - } - - private void assertItems() { - BrooklynTypeRegistry types = getManagementContext().getTypeRegistry(); - assertNotNull(types.get("org.apache.brooklyn.entity.stock.BasicApplication", BrooklynCatalog.DEFAULT_VERSION)); - assertNotNull(types.get("org.apache.brooklyn.test.osgi.entities.SimpleApplication", BrooklynCatalog.DEFAULT_VERSION)); - } - -} http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/e0feddb7/rest/rest-resources/src/test/resources/reset-catalog.xml ---------------------------------------------------------------------- diff --git a/rest/rest-resources/src/test/resources/reset-catalog.xml b/rest/rest-resources/src/test/resources/reset-catalog.xml deleted file mode 100644 index adef40a..0000000 --- a/rest/rest-resources/src/test/resources/reset-catalog.xml +++ /dev/null @@ -1,37 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- - 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. ---> -<catalog> - <name>Brooklyn Demos</name> - - <template type="org.apache.brooklyn.entity.stock.BasicApplication" name="Basic application" /> - <template type="org.apache.brooklyn.test.osgi.entities.SimpleApplication" name="Simple OSGi application"> - <libraries> - <bundle>${bundle-location}</bundle> - </libraries> - </template> - <catalog> - <name>Nested catalog</name> - <template type="org.apache.brooklyn.test.osgi.entities.SimpleApplication" name="Simple OSGi application"> - <libraries> - <bundle>${bundle-location}</bundle> - </libraries> - </template> - </catalog> -</catalog> http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/e0feddb7/software/base/src/main/java/org/apache/brooklyn/entity/brooklynnode/BrooklynNode.java ---------------------------------------------------------------------- diff --git a/software/base/src/main/java/org/apache/brooklyn/entity/brooklynnode/BrooklynNode.java b/software/base/src/main/java/org/apache/brooklyn/entity/brooklynnode/BrooklynNode.java index de251d4..3df2b26 100644 --- a/software/base/src/main/java/org/apache/brooklyn/entity/brooklynnode/BrooklynNode.java +++ b/software/base/src/main/java/org/apache/brooklyn/entity/brooklynnode/BrooklynNode.java @@ -169,25 +169,6 @@ public interface BrooklynNode extends SoftwareProcess, UsesJava { public static final ConfigKey<String> BROOKLYN_LOCAL_PROPERTIES_CONTENTS = ConfigKeys.newStringConfigKey( "brooklynnode.brooklynproperties.local.contents", "Contents for the launch-specific brooklyn properties file", null); - // For use in testing primarily - /** @deprecated since 0.7.0; instead set the catalog initial bom */ - @Deprecated - @SetFromFlag("brooklynCatalogRemotePath") - public static final ConfigKey<String> BROOKLYN_CATALOG_REMOTE_PATH = ConfigKeys.newStringConfigKey( - "brooklynnode.brooklyncatalog.remotepath", "Remote path for the brooklyn catalog.xml file to be uploaded", "${HOME}/.brooklyn/catalog.xml"); - - /** @deprecated since 0.7.0; instead use {@link #BROOKLYN_CATALOG_INITIAL_BOM_URI} */ - @Deprecated - @SetFromFlag("brooklynCatalogUri") - public static final ConfigKey<String> BROOKLYN_CATALOG_URI = ConfigKeys.newStringConfigKey( - "brooklynnode.brooklyncatalog.uri", "URI for the brooklyn catalog.xml file (uploaded to ~/.brooklyn/catalog.xml)", null); - - /** @deprecated since 0.7.0; instead use {@link #BROOKLYN_CATALOG_INITIAL_BOM_CONTENTS} */ - @Deprecated - @SetFromFlag("brooklynCatalogContents") - public static final ConfigKey<String> BROOKLYN_CATALOG_CONTENTS = ConfigKeys.newStringConfigKey( - "brooklynnode.brooklyncatalog.contents", "Contents for the brooklyn catalog.xml file (uploaded to ~/.brooklyn/catalog.xml)", null); - public static final ConfigKey<String> BROOKLYN_CATALOG_INITIAL_BOM_REMOTE_PATH = ConfigKeys.newStringConfigKey( "brooklynnode.catalog.initial.bom.remotepath", "Remote path for the launch-specific initial catalog file to be uploaded", http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/e0feddb7/software/base/src/main/java/org/apache/brooklyn/entity/brooklynnode/BrooklynNodeSshDriver.java ---------------------------------------------------------------------- diff --git a/software/base/src/main/java/org/apache/brooklyn/entity/brooklynnode/BrooklynNodeSshDriver.java b/software/base/src/main/java/org/apache/brooklyn/entity/brooklynnode/BrooklynNodeSshDriver.java index c112488..a0f92aa 100644 --- a/software/base/src/main/java/org/apache/brooklyn/entity/brooklynnode/BrooklynNodeSshDriver.java +++ b/software/base/src/main/java/org/apache/brooklyn/entity/brooklynnode/BrooklynNodeSshDriver.java @@ -191,10 +191,6 @@ public class BrooklynNodeSshDriver extends JavaSoftwareProcessSshDriver implemen String brooklynLocalPropertiesContents = entity.getConfig(BrooklynNode.BROOKLYN_LOCAL_PROPERTIES_CONTENTS); String brooklynLocalPropertiesUri = entity.getConfig(BrooklynNode.BROOKLYN_LOCAL_PROPERTIES_URI); - String brooklynCatalogRemotePath = entity.getConfig(BrooklynNode.BROOKLYN_CATALOG_REMOTE_PATH); - String brooklynCatalogContents = entity.getConfig(BrooklynNode.BROOKLYN_CATALOG_CONTENTS); - String brooklynCatalogUri = entity.getConfig(BrooklynNode.BROOKLYN_CATALOG_URI); - String brooklynCatalogInitialBomRemotePath = processTemplateContents(entity.getConfig(BrooklynNode.BROOKLYN_CATALOG_INITIAL_BOM_REMOTE_PATH)); String brooklynCatalogInitialBomUri = entity.getConfig(BrooklynNode.BROOKLYN_CATALOG_INITIAL_BOM_URI); String brooklynCatalogInitialBomContents = entity.getConfig(BrooklynNode.BROOKLYN_CATALOG_INITIAL_BOM_CONTENTS); @@ -236,16 +232,6 @@ public class BrooklynNodeSshDriver extends JavaSoftwareProcessSshDriver implemen uploadFileContents(brooklynCatalogInitialBomContents, brooklynCatalogInitialBomUri, brooklynCatalogInitialBomRemotePath); } - // Override the ~/.brooklyn/catalog.xml if required - if (brooklynCatalogContents != null || brooklynCatalogUri != null) { - log.warn("Deprecated (since 0.7.0) use of config" - + (brooklynCatalogContents != null ? " [" + BrooklynNode.BROOKLYN_CATALOG_CONTENTS.getName() + "]" : "") - + (brooklynCatalogUri != null ? " [" + BrooklynNode.BROOKLYN_CATALOG_URI.getName() + "]" : "") - + "; instead use "+BrooklynNode.BROOKLYN_CATALOG_INITIAL_BOM_URI.getName() - + " or "+BrooklynNode.BROOKLYN_CATALOG_INITIAL_BOM_CONTENTS.getName()); - uploadFileContents(brooklynCatalogContents, brooklynCatalogUri, brooklynCatalogRemotePath); - } - // Copy additional resources to the server for (Map.Entry<String,String> entry : getEntity().getAttribute(BrooklynNode.COPY_TO_RUNDIR).entrySet()) { Map<String, String> substitutions = ImmutableMap.of("RUN", getRunDir()); http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/e0feddb7/software/base/src/test/java/org/apache/brooklyn/entity/brooklynnode/BrooklynNodeIntegrationTest.java ---------------------------------------------------------------------- diff --git a/software/base/src/test/java/org/apache/brooklyn/entity/brooklynnode/BrooklynNodeIntegrationTest.java b/software/base/src/test/java/org/apache/brooklyn/entity/brooklynnode/BrooklynNodeIntegrationTest.java index 540981b..7f2e6ed 100644 --- a/software/base/src/test/java/org/apache/brooklyn/entity/brooklynnode/BrooklynNodeIntegrationTest.java +++ b/software/base/src/test/java/org/apache/brooklyn/entity/brooklynnode/BrooklynNodeIntegrationTest.java @@ -220,30 +220,6 @@ services: } @Test(groups={"Integration", "Broken"}) - public void testSetsBrooklynCatalogFromContents() throws Exception { - BrooklynNode brooklynNode = app.createAndManageChild(newBrooklynNodeSpecForTest() - .configure(BrooklynNode.BROOKLYN_CATALOG_REMOTE_PATH, pseudoBrooklynCatalogFile.getAbsolutePath()) - .configure(BrooklynNode.BROOKLYN_CATALOG_CONTENTS, "<catalog/>")); - app.start(locs); - log.info("started "+app+" containing "+brooklynNode+" for "+JavaClassNames.niceClassAndMethod()); - - assertEquals(Files.readLines(pseudoBrooklynCatalogFile, Charsets.UTF_8), ImmutableList.of("<catalog/>")); - } - - @Test(groups={"Integration", "Broken"}) - public void testSetsBrooklynCatalogFromUri() throws Exception { - Files.write("abc=def", brooklynCatalogSourceFile, Charsets.UTF_8); - - BrooklynNode brooklynNode = app.createAndManageChild(newBrooklynNodeSpecForTest() - .configure(BrooklynNode.BROOKLYN_CATALOG_REMOTE_PATH, pseudoBrooklynCatalogFile.getAbsolutePath()) - .configure(BrooklynNode.BROOKLYN_CATALOG_URI, brooklynCatalogSourceFile.toURI().toString())); - app.start(locs); - log.info("started "+app+" containing "+brooklynNode+" for "+JavaClassNames.niceClassAndMethod()); - - assertEquals(Files.readLines(pseudoBrooklynCatalogFile, Charsets.UTF_8), ImmutableList.of("abc=def")); - } - - @Test(groups={"Integration", "Broken"}) public void testSetsBrooklynCatalogInitialBomFromContents() throws Exception { runBrooklynCatalogInitialBom(false); }
