You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by dr...@apache.org on 2017/05/08 09:00:20 UTC

[1/5] brooklyn-server git commit: Delete brooklyn-storage-hazelcast

Repository: brooklyn-server
Updated Branches:
  refs/heads/master 5b6bf73a8 -> 48933eb6b


Delete brooklyn-storage-hazelcast

This has not been documented, used or recommended ever! It was more
experimental, as an approach that might have replaced the existing
persisted state approach but never did.


Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/3c1a7805
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/3c1a7805
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/3c1a7805

Branch: refs/heads/master
Commit: 3c1a7805add0dd584a26b1a0174d8ced44b5c014
Parents: a32cdd6
Author: Aled Sage <al...@gmail.com>
Authored: Wed May 3 20:43:23 2017 +0100
Committer: Aled Sage <al...@gmail.com>
Committed: Wed May 3 20:46:36 2017 +0100

----------------------------------------------------------------------
 .../deserializingClassRenames.properties        |   4 -
 pom.xml                                         |   2 -
 storage/hazelcast/pom.xml                       |  88 ---------------
 .../storage/impl/hazelcast/EntityId.java        |  36 -------
 .../impl/hazelcast/EntityStreamSerializer.java  |  68 ------------
 .../impl/hazelcast/HazelcastDataGrid.java       |  89 ---------------
 .../hazelcast/HazelcastDataGridFactory.java     |  42 --------
 .../impl/hazelcast/HazelcastStorageTest.java    | 107 -------------------
 8 files changed, 436 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/3c1a7805/core/src/main/resources/org/apache/brooklyn/core/mgmt/persist/deserializingClassRenames.properties
----------------------------------------------------------------------
diff --git a/core/src/main/resources/org/apache/brooklyn/core/mgmt/persist/deserializingClassRenames.properties b/core/src/main/resources/org/apache/brooklyn/core/mgmt/persist/deserializingClassRenames.properties
index 992d9e5..8a6a7a4 100644
--- a/core/src/main/resources/org/apache/brooklyn/core/mgmt/persist/deserializingClassRenames.properties
+++ b/core/src/main/resources/org/apache/brooklyn/core/mgmt/persist/deserializingClassRenames.properties
@@ -1103,10 +1103,6 @@ brooklyn.entity.webapp.tomcat.TomcatDriver
 brooklyn.entity.webapp.tomcat.TomcatServer                                       : org.apache.brooklyn.entity.webapp.tomcat.TomcatServer
 brooklyn.entity.webapp.tomcat.TomcatServerImpl                                   : org.apache.brooklyn.entity.webapp.tomcat.TomcatServerImpl
 brooklyn.entity.webapp.tomcat.TomcatSshDriver                                    : org.apache.brooklyn.entity.webapp.tomcat.TomcatSshDriver
-brooklyn.internal.storage.impl.hazelcast.EntityId                                : org.apache.brooklyn.internal.storage.impl.hazelcast.EntityId
-brooklyn.internal.storage.impl.hazelcast.EntityStreamSerializer                  : org.apache.brooklyn.internal.storage.impl.hazelcast.EntityStreamSerializer
-brooklyn.internal.storage.impl.hazelcast.HazelcastDataGrid                       : org.apache.brooklyn.internal.storage.impl.hazelcast.HazelcastDataGrid
-brooklyn.internal.storage.impl.hazelcast.HazelcastDataGridFactory                : org.apache.brooklyn.internal.storage.impl.hazelcast.HazelcastDataGridFactory
 io.brooklyn.camp.brooklyn.BrooklynCampConstants                                  : org.apache.brooklyn.camp.brooklyn.BrooklynCampConstants
 io.brooklyn.camp.brooklyn.BrooklynCampPlatform                                   : org.apache.brooklyn.camp.brooklyn.BrooklynCampPlatform
 io.brooklyn.camp.brooklyn.BrooklynCampPlatformLauncherAbstract                   : org.apache.brooklyn.camp.brooklyn.BrooklynCampPlatformLauncherAbstract

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/3c1a7805/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index d2809f3..450e154 100644
--- a/pom.xml
+++ b/pom.xml
@@ -221,8 +221,6 @@
         <module>software/base</module>
         <module>software/winrm</module>
 
-        <module>storage/hazelcast</module>
-
         <module>server-cli</module>
         <module>launcher-common</module>
         <module>launcher</module>

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/3c1a7805/storage/hazelcast/pom.xml
----------------------------------------------------------------------
diff --git a/storage/hazelcast/pom.xml b/storage/hazelcast/pom.xml
deleted file mode 100644
index 1017f3c..0000000
--- a/storage/hazelcast/pom.xml
+++ /dev/null
@@ -1,88 +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.
--->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
-    <modelVersion>4.0.0</modelVersion>
-    <artifactId>brooklyn-storage-hazelcast</artifactId>
-    <packaging>jar</packaging>
-    <name>Brooklyn Hazelcast Storage</name>
-    <description>
-        Provides a Hazelcast implementation of Storage
-    </description>
-
-    <parent>
-        <groupId>org.apache.brooklyn</groupId>
-        <artifactId>brooklyn-parent</artifactId>
-        <version>0.12.0-SNAPSHOT</version>  <!-- BROOKLYN_VERSION -->
-        <relativePath>../../parent/pom.xml</relativePath>
-    </parent>
-
-    <properties>
-        <hazelcast.version>3.5.4</hazelcast.version>
-    </properties>
-	
-    <dependencies>
-        <dependency>
-            <groupId>org.apache.brooklyn</groupId>
-            <artifactId>brooklyn-core</artifactId>
-            <version>${project.version}</version>
-        </dependency>
-        <dependency>
-            <groupId>org.apache.brooklyn</groupId>
-            <artifactId>brooklyn-utils-common</artifactId>
-            <version>${project.version}</version>
-        </dependency>
-        <dependency>
-            <groupId>org.apache.brooklyn</groupId>
-            <artifactId>brooklyn-api</artifactId>
-            <version>${project.version}</version>
-        </dependency>
-        <dependency>
-            <groupId>com.google.guava</groupId>
-            <artifactId>guava</artifactId>
-        </dependency>
-
-        <dependency>
-            <groupId>com.hazelcast</groupId>
-            <artifactId>hazelcast</artifactId>
-            <version>${hazelcast.version}</version>
-        </dependency>
-
-        <!-- test dependencies -->
-        <dependency>
-            <groupId>org.testng</groupId>
-            <artifactId>testng</artifactId>
-            <scope>test</scope>
-        </dependency>
-        <dependency>
-            <groupId>org.apache.brooklyn</groupId>
-            <artifactId>brooklyn-test-support</artifactId>
-            <version>${project.version}</version>
-            <scope>test</scope>
-        </dependency>
-<!--         <dependency>
-            <groupId>org.apache.brooklyn</groupId>
-            <artifactId>brooklyn-core</artifactId>
-            <version>${project.version}</version>
-            <classifier>tests</classifier>
-            <scope>test</scope>
-        </dependency> -->
-    </dependencies>
-
-</project>

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/3c1a7805/storage/hazelcast/src/main/java/org/apache/brooklyn/internal/storage/impl/hazelcast/EntityId.java
----------------------------------------------------------------------
diff --git a/storage/hazelcast/src/main/java/org/apache/brooklyn/internal/storage/impl/hazelcast/EntityId.java b/storage/hazelcast/src/main/java/org/apache/brooklyn/internal/storage/impl/hazelcast/EntityId.java
deleted file mode 100644
index db7f283..0000000
--- a/storage/hazelcast/src/main/java/org/apache/brooklyn/internal/storage/impl/hazelcast/EntityId.java
+++ /dev/null
@@ -1,36 +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.internal.storage.impl.hazelcast;
-
-import java.io.Serializable;
-
-class EntityId implements Serializable {
-
-    private static final long serialVersionUID = 1L;
-
-    private final String id;
-
-    EntityId(String id) {
-        this.id = id;
-    }
-
-    String getId() {
-        return id;
-    }
-}

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/3c1a7805/storage/hazelcast/src/main/java/org/apache/brooklyn/internal/storage/impl/hazelcast/EntityStreamSerializer.java
----------------------------------------------------------------------
diff --git a/storage/hazelcast/src/main/java/org/apache/brooklyn/internal/storage/impl/hazelcast/EntityStreamSerializer.java b/storage/hazelcast/src/main/java/org/apache/brooklyn/internal/storage/impl/hazelcast/EntityStreamSerializer.java
deleted file mode 100644
index 5cea12b..0000000
--- a/storage/hazelcast/src/main/java/org/apache/brooklyn/internal/storage/impl/hazelcast/EntityStreamSerializer.java
+++ /dev/null
@@ -1,68 +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.internal.storage.impl.hazelcast;
-
-import com.hazelcast.nio.ObjectDataInput;
-import com.hazelcast.nio.ObjectDataOutput;
-import com.hazelcast.nio.serialization.StreamSerializer;
-
-import java.io.IOException;
-
-import org.apache.brooklyn.api.entity.Entity;
-import org.apache.brooklyn.core.objs.proxy.EntityProxyImpl;
-
-import static java.lang.String.format;
-
-class EntityStreamSerializer implements StreamSerializer {
-
-    private HazelcastDataGrid hazelcastDataGrid;
-
-    public EntityStreamSerializer(HazelcastDataGrid hazelcastDataGrid) {
-        this.hazelcastDataGrid = hazelcastDataGrid;
-    }
-
-    @Override
-    public Object read(ObjectDataInput in) throws IOException {
-        EntityId id = in.readObject();
-        Entity entity = hazelcastDataGrid.getManagementContext().getEntityManager().getEntity(id.getId());
-        if (entity == null) {
-            throw new IllegalStateException(format("Entity with id [%s] is not found", id));
-        }
-        return java.lang.reflect.Proxy.newProxyInstance(
-                entity.getClass().getClassLoader(),
-                entity.getClass().getInterfaces(),
-                new EntityProxyImpl(entity));
-    }
-
-    @Override
-    public void write(ObjectDataOutput out, Object object) throws IOException {
-        Entity entity = (Entity) object;
-        out.writeObject(new EntityId(entity.getId()));
-    }
-
-    @Override
-    public int getTypeId() {
-        return 5000;
-    }
-
-    @Override
-    public void destroy() {
-        //no-op
-    }
-}

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/3c1a7805/storage/hazelcast/src/main/java/org/apache/brooklyn/internal/storage/impl/hazelcast/HazelcastDataGrid.java
----------------------------------------------------------------------
diff --git a/storage/hazelcast/src/main/java/org/apache/brooklyn/internal/storage/impl/hazelcast/HazelcastDataGrid.java b/storage/hazelcast/src/main/java/org/apache/brooklyn/internal/storage/impl/hazelcast/HazelcastDataGrid.java
deleted file mode 100644
index 0219f10..0000000
--- a/storage/hazelcast/src/main/java/org/apache/brooklyn/internal/storage/impl/hazelcast/HazelcastDataGrid.java
+++ /dev/null
@@ -1,89 +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.internal.storage.impl.hazelcast;
-
-import java.util.Collections;
-import java.util.Map;
-import java.util.Set;
-import java.util.concurrent.ConcurrentMap;
-
-import org.apache.brooklyn.api.entity.Entity;
-import org.apache.brooklyn.core.internal.storage.DataGrid;
-import org.apache.brooklyn.core.mgmt.internal.ManagementContextInternal;
-
-import com.google.common.collect.ImmutableMap;
-import com.hazelcast.config.Config;
-import com.hazelcast.config.SerializerConfig;
-import com.hazelcast.core.Hazelcast;
-import com.hazelcast.core.HazelcastInstance;
-import com.hazelcast.core.HazelcastInstanceNotActiveException;
-
-public class HazelcastDataGrid implements DataGrid {
-
-    private final HazelcastInstance hz;
-    private final ManagementContextInternal managementContext;
-
-    public HazelcastDataGrid(ManagementContextInternal managementContext, HazelcastInstance hazelcastInstance) {
-        this.managementContext = managementContext;
-        if (hazelcastInstance == null) {
-            Config config = new Config();
-            SerializerConfig entitySerializeConfig = new SerializerConfig();
-            entitySerializeConfig.setTypeClassName(Entity.class.getName());
-            entitySerializeConfig.setImplementation(new EntityStreamSerializer(this));
-            config.getSerializationConfig().addSerializerConfig(entitySerializeConfig);
-            this.hz = Hazelcast.newHazelcastInstance(config);
-        } else {
-            this.hz = hazelcastInstance;
-        }
-    }
-
-    public ManagementContextInternal getManagementContext() {
-        return managementContext;
-    }
-
-    @Override
-    public <K, V> ConcurrentMap<K, V> getMap(String id) {
-        return hz.getMap(id);
-    }
-
-    @Override
-    public void remove(String id) {
-        hz.getMap(id).destroy();
-    }
-
-    @Override
-    public void terminate() {
-        try {
-            hz.getLifecycleService().shutdown();
-        } catch (HazelcastInstanceNotActiveException ignore) {
-        }
-    }
-    
-    @Override
-    public Map<String, Object> getDatagridMetrics() {
-        // TODO would like to have better metrics
-        return ImmutableMap.<String,Object>of("name", hz.getName(), "isRunning", hz.getLifecycleService().isRunning());
-    }
-    
-    @Override
-    public Set<String> getKeys() {
-        // TODO would like to have all known keys (for tests)
-        return Collections.emptySet();
-    }
-}

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/3c1a7805/storage/hazelcast/src/main/java/org/apache/brooklyn/internal/storage/impl/hazelcast/HazelcastDataGridFactory.java
----------------------------------------------------------------------
diff --git a/storage/hazelcast/src/main/java/org/apache/brooklyn/internal/storage/impl/hazelcast/HazelcastDataGridFactory.java b/storage/hazelcast/src/main/java/org/apache/brooklyn/internal/storage/impl/hazelcast/HazelcastDataGridFactory.java
deleted file mode 100644
index fa15fc7..0000000
--- a/storage/hazelcast/src/main/java/org/apache/brooklyn/internal/storage/impl/hazelcast/HazelcastDataGridFactory.java
+++ /dev/null
@@ -1,42 +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.internal.storage.impl.hazelcast;
-
-import org.apache.brooklyn.core.internal.storage.DataGrid;
-import org.apache.brooklyn.core.internal.storage.DataGridFactory;
-import org.apache.brooklyn.core.mgmt.internal.ManagementContextInternal;
-
-import com.hazelcast.core.HazelcastInstance;
-
-public class HazelcastDataGridFactory implements DataGridFactory {
-
-    private HazelcastInstance hazelcastInstance;
-
-    public HazelcastDataGridFactory() {
-    }
-
-    public HazelcastDataGridFactory(HazelcastInstance hazelcastInstance) {
-        this.hazelcastInstance = hazelcastInstance;
-    }
-
-    @Override
-    public DataGrid newDataGrid(ManagementContextInternal managementContext) {
-        return new HazelcastDataGrid(managementContext,hazelcastInstance);
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/3c1a7805/storage/hazelcast/src/test/java/org/apache/brooklyn/storage/impl/hazelcast/HazelcastStorageTest.java
----------------------------------------------------------------------
diff --git a/storage/hazelcast/src/test/java/org/apache/brooklyn/storage/impl/hazelcast/HazelcastStorageTest.java b/storage/hazelcast/src/test/java/org/apache/brooklyn/storage/impl/hazelcast/HazelcastStorageTest.java
deleted file mode 100644
index 4c43e1c..0000000
--- a/storage/hazelcast/src/test/java/org/apache/brooklyn/storage/impl/hazelcast/HazelcastStorageTest.java
+++ /dev/null
@@ -1,107 +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.storage.impl.hazelcast;
-
-import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertTrue;
-
-import java.util.List;
-import java.util.Map;
-
-import org.testng.annotations.AfterMethod;
-import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.Test;
-import org.apache.brooklyn.core.internal.BrooklynProperties;
-import org.apache.brooklyn.core.internal.storage.BrooklynStorage;
-import org.apache.brooklyn.core.internal.storage.DataGridFactory;
-import org.apache.brooklyn.core.internal.storage.Reference;
-import org.apache.brooklyn.core.internal.storage.impl.BrooklynStorageImpl;
-import org.apache.brooklyn.core.mgmt.internal.LocalManagementContext;
-import org.apache.brooklyn.internal.storage.impl.hazelcast.HazelcastDataGrid;
-import org.apache.brooklyn.internal.storage.impl.hazelcast.HazelcastDataGridFactory;
-import org.apache.brooklyn.util.collections.MutableList;
-
-import com.hazelcast.core.Hazelcast;
-
-@Test(groups="Integration")
-public class HazelcastStorageTest {
-
-    private LocalManagementContext managementContext;
-    private BrooklynStorage storage;
-
-    @BeforeMethod(alwaysRun = true)
-    public void setUp() {
-        BrooklynProperties properties = BrooklynProperties.Factory.newDefault();
-        properties.put(DataGridFactory.class.getName(), HazelcastDataGridFactory.class.getName());
-        managementContext = new LocalManagementContext(properties);
-        storage = managementContext.getStorage();
-    }
-
-    @AfterMethod(alwaysRun = true)
-    public void tearDown() {
-        if (managementContext != null) managementContext.terminate();
-        Hazelcast.shutdownAll();
-    }
-
-    //test to verify that our HazelcastDatagrid really is being picked up.
-    @Test
-    public void testPickUp(){
-       assertTrue(storage instanceof BrooklynStorageImpl,"storage should be instance of BrooklynStorageImpl");
-       BrooklynStorageImpl brooklynStorageImpl = (BrooklynStorageImpl)storage;
-       assertTrue(brooklynStorageImpl.getDataGrid() instanceof HazelcastDataGrid,"storage should be instanceof HazelcastDataGrid");
-    }
-
-    @Test
-    public void testGetMap() {
-        Map<String,String> map = storage.getMap("somemap");
-        map.put("foo", "bar");
-        assertEquals( map.get("foo"),"bar");
-    }
-
-    @Test
-    public void testGetReference() {
-        Reference<String> ref = storage.getReference("someReference");
-        ref.set("bar");
-        assertEquals(ref.get(), "bar");
-    }
-
-    @Test
-    public void testNonConcurrentList(){
-        Reference<List<String>> ref = storage.getNonConcurrentList("someReference");
-        ref.set(MutableList.of("bar"));
-
-        assertEquals(ref.get().get(0),"bar");
-    }
-
-    @Test
-    public void testRemoveReference(){
-        Reference<String> ref = storage.getReference("someReference");
-        ref.set("bar");
-        storage.remove("someReference");
-        assertEquals(ref.get(), null);
-    }
-
-    @Test
-    public void testRemoveMap(){
-        Map<String,String> map = storage.getMap("somemap");
-        map.put("foo", "bar");
-        storage.remove("somemap");
-        assertEquals(null, map.get("foo"));
-    }
-}


[4/5] brooklyn-server git commit: Hide DataGrid inside BrooklynStorageImpl

Posted by dr...@apache.org.
Hide DataGrid inside BrooklynStorageImpl

Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/6b59fcb6
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/6b59fcb6
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/6b59fcb6

Branch: refs/heads/master
Commit: 6b59fcb6a0c8e57dcdd00b8c95ea2b410c8fcf2d
Parents: 21c40ba
Author: Aled Sage <al...@gmail.com>
Authored: Thu May 4 11:40:03 2017 +0100
Committer: Aled Sage <al...@gmail.com>
Committed: Fri May 5 11:23:52 2017 +0100

----------------------------------------------------------------------
 .../core/internal/storage/DataGrid.java         | 52 -----------
 .../storage/impl/BrooklynStorageImpl.java       | 18 +---
 .../internal/storage/impl/InmemoryDatagrid.java | 86 ++++++++++++++++++
 .../storage/impl/inmemory/InmemoryDatagrid.java | 93 --------------------
 .../internal/AbstractManagementContext.java     |  3 +-
 .../storage/impl/BrooklynStorageImplTest.java   |  6 +-
 .../longevity/EntityCleanupLongevityTest.java   |  2 +-
 .../EntityCleanupLongevityTestFixture.java      | 48 +++++-----
 8 files changed, 120 insertions(+), 188 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/6b59fcb6/core/src/main/java/org/apache/brooklyn/core/internal/storage/DataGrid.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/internal/storage/DataGrid.java b/core/src/main/java/org/apache/brooklyn/core/internal/storage/DataGrid.java
deleted file mode 100644
index 09f50fb..0000000
--- a/core/src/main/java/org/apache/brooklyn/core/internal/storage/DataGrid.java
+++ /dev/null
@@ -1,52 +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.internal.storage;
-
-import java.util.Map;
-import java.util.Set;
-import java.util.concurrent.ConcurrentMap;
-
-import com.google.common.annotations.VisibleForTesting;
-
-public interface DataGrid {
-
-    /**
-     * If a map already exists with this id, returns it; otherwise creates a new map stored
-     * in the datagrid.
-     */
-    <K,V> ConcurrentMap<K,V> getMap(String id);
-
-    /**
-     * Deletes the map for this id, if it exists; otherwise a no-op.
-     */
-    void remove(String id);
-
-    /**
-     * Terminates the DataGrid. If there is a real datagrid with multiple machines running, it doesn't mean that the
-     * datagrid is going to be terminated; it only means that all local resources of the datagrid are released.
-     */
-    void terminate();
-    
-    Map<String, Object> getDatagridMetrics();
-
-    /** Returns snapshot of known keys at this datagrid */
-    @VisibleForTesting
-    Set<String> getKeys();
-    
-}

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/6b59fcb6/core/src/main/java/org/apache/brooklyn/core/internal/storage/impl/BrooklynStorageImpl.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/internal/storage/impl/BrooklynStorageImpl.java b/core/src/main/java/org/apache/brooklyn/core/internal/storage/impl/BrooklynStorageImpl.java
index 60a1e7e..5436b15 100644
--- a/core/src/main/java/org/apache/brooklyn/core/internal/storage/impl/BrooklynStorageImpl.java
+++ b/core/src/main/java/org/apache/brooklyn/core/internal/storage/impl/BrooklynStorageImpl.java
@@ -25,40 +25,28 @@ import java.util.Map;
 import java.util.concurrent.ConcurrentMap;
 
 import org.apache.brooklyn.core.internal.storage.BrooklynStorage;
-import org.apache.brooklyn.core.internal.storage.DataGrid;
 import org.apache.brooklyn.core.internal.storage.Reference;
 
-import com.google.common.annotations.VisibleForTesting;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.Maps;
 
 public class BrooklynStorageImpl implements BrooklynStorage {
 
-    private final DataGrid datagrid;
+    private final InmemoryDatagrid datagrid;
     private final ConcurrentMap<String, Object> refsMap;
     private final ConcurrentMap<String, Object> listsMap;
     private final ConcurrentMap<String, WeakReference<Reference<?>>> refsCache;
     private final ConcurrentMap<String, WeakReference<Reference<?>>> listRefsCache;
     
-    public BrooklynStorageImpl(DataGrid datagrid) {
-        this.datagrid = datagrid;
+    public BrooklynStorageImpl() {
+        this.datagrid = new InmemoryDatagrid();
         this.refsMap = datagrid.getMap("refs");
         this.listsMap = datagrid.getMap("lists");
         this.refsCache = Maps.newConcurrentMap();
         this.listRefsCache = Maps.newConcurrentMap();
     }
 
-    /**
-     * Returns the DataGrid used by this  BrooklynStorageImpl
-     *
-     * @return the DataGrid.
-     */
-    @VisibleForTesting
-    public DataGrid getDataGrid() {
-        return datagrid;
-    }
-
     @Override
     public <T> Reference<T> getReference(final String id) {
         // Can use different ref instances; no need to always return same one. Caching is an

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/6b59fcb6/core/src/main/java/org/apache/brooklyn/core/internal/storage/impl/InmemoryDatagrid.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/internal/storage/impl/InmemoryDatagrid.java b/core/src/main/java/org/apache/brooklyn/core/internal/storage/impl/InmemoryDatagrid.java
new file mode 100644
index 0000000..a63fa3d
--- /dev/null
+++ b/core/src/main/java/org/apache/brooklyn/core/internal/storage/impl/InmemoryDatagrid.java
@@ -0,0 +1,86 @@
+/*
+ * 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.internal.storage.impl;
+
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ConcurrentMap;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import org.apache.brooklyn.core.internal.storage.impl.ConcurrentMapAcceptingNullVals;
+
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.Maps;
+
+/**
+ * A simple implementation of datagrid backed by in-memory (unpersisted) maps, within a single JVM.
+ * 
+ * @author aled
+ */
+class InmemoryDatagrid {
+
+    private final Map<String,Map<?,?>> maps = Maps.newLinkedHashMap();
+    private final AtomicInteger creationCounter = new AtomicInteger();
+    
+    @SuppressWarnings("unchecked")
+    public <K, V> ConcurrentMap<K, V> getMap(String id) {
+        synchronized (maps) {
+            ConcurrentMap<K, V> result = (ConcurrentMap<K, V>) maps.get(id);
+            if (result == null) {
+                result = newMap();
+                maps.put(id, result);
+                creationCounter.incrementAndGet();
+            }
+            return result;
+        }
+    }
+    
+    // TODO Not doing Maps.newConcurrentMap() because needs to store null values.
+    // Easy to avoid for Refererence<?> but harder for entity ConfigMap where the user
+    // can insert null values.
+    // 
+    // Could write a decorator that switches null values for a null marker, and back again.
+    //
+    private <K,V> ConcurrentMap<K,V> newMap() {
+        //return Collections.synchronizedMap(new HashMap<K, V>());
+        return new ConcurrentMapAcceptingNullVals<K,V>(Maps.<K,V>newConcurrentMap());
+    }
+
+    public void remove(String id) {
+        synchronized (maps) {
+            maps.remove(id);
+        }
+    }
+
+    public void terminate() {
+        synchronized (maps) {
+            maps.clear();
+        }
+    }
+
+    public Map<String, Object> getDatagridMetrics() {
+        synchronized (maps) {
+            return ImmutableMap.<String, Object>of("size", maps.size(), "createCount", creationCounter.get());
+        }
+    }
+
+    public Set<String> getKeys() {
+        return maps.keySet();
+    }
+}

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/6b59fcb6/core/src/main/java/org/apache/brooklyn/core/internal/storage/impl/inmemory/InmemoryDatagrid.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/internal/storage/impl/inmemory/InmemoryDatagrid.java b/core/src/main/java/org/apache/brooklyn/core/internal/storage/impl/inmemory/InmemoryDatagrid.java
deleted file mode 100644
index 48600d9..0000000
--- a/core/src/main/java/org/apache/brooklyn/core/internal/storage/impl/inmemory/InmemoryDatagrid.java
+++ /dev/null
@@ -1,93 +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.internal.storage.impl.inmemory;
-
-import java.util.Map;
-import java.util.Set;
-import java.util.concurrent.ConcurrentMap;
-import java.util.concurrent.atomic.AtomicInteger;
-
-import org.apache.brooklyn.core.internal.storage.DataGrid;
-import org.apache.brooklyn.core.internal.storage.impl.ConcurrentMapAcceptingNullVals;
-
-import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.Maps;
-
-/**
- * A simple implementation of datagrid backed by in-memory (unpersisted) maps, within a single JVM.
- * 
- * @author aled
- */
-public class InmemoryDatagrid implements DataGrid {
-
-    private final Map<String,Map<?,?>> maps = Maps.newLinkedHashMap();
-    private final AtomicInteger creationCounter = new AtomicInteger();
-    
-    @SuppressWarnings("unchecked")
-    @Override
-    public <K, V> ConcurrentMap<K, V> getMap(String id) {
-        synchronized (maps) {
-            ConcurrentMap<K, V> result = (ConcurrentMap<K, V>) maps.get(id);
-            if (result == null) {
-                result = newMap();
-                maps.put(id, result);
-                creationCounter.incrementAndGet();
-            }
-            return result;
-        }
-    }
-    
-    // TODO Not doing Maps.newConcurrentMap() because needs to store null values.
-    // Easy to avoid for Refererence<?> but harder for entity ConfigMap where the user
-    // can insert null values.
-    // 
-    // Could write a decorator that switches null values for a null marker, and back again.
-    //
-    private <K,V> ConcurrentMap<K,V> newMap() {
-        //return Collections.synchronizedMap(new HashMap<K, V>());
-        return new ConcurrentMapAcceptingNullVals<K,V>(Maps.<K,V>newConcurrentMap());
-    }
-
-    @Override
-    public void remove(String id) {
-        synchronized (maps) {
-            maps.remove(id);
-        }
-    }
-
-    @Override
-    public void terminate() {
-        synchronized (maps) {
-            maps.clear();
-        }
-    }
-
-    @Override
-    public Map<String, Object> getDatagridMetrics() {
-        synchronized (maps) {
-            return ImmutableMap.<String, Object>of("size", maps.size(), "createCount", creationCounter.get());
-        }
-    }
-
-    @Override
-    public Set<String> getKeys() {
-        return maps.keySet();
-    }
-    
-}

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/6b59fcb6/core/src/main/java/org/apache/brooklyn/core/mgmt/internal/AbstractManagementContext.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/mgmt/internal/AbstractManagementContext.java b/core/src/main/java/org/apache/brooklyn/core/mgmt/internal/AbstractManagementContext.java
index 45a45d7..c009437 100644
--- a/core/src/main/java/org/apache/brooklyn/core/mgmt/internal/AbstractManagementContext.java
+++ b/core/src/main/java/org/apache/brooklyn/core/mgmt/internal/AbstractManagementContext.java
@@ -61,7 +61,6 @@ import org.apache.brooklyn.core.entity.drivers.downloads.BasicDownloadsManager;
 import org.apache.brooklyn.core.internal.BrooklynProperties;
 import org.apache.brooklyn.core.internal.storage.BrooklynStorage;
 import org.apache.brooklyn.core.internal.storage.impl.BrooklynStorageImpl;
-import org.apache.brooklyn.core.internal.storage.impl.inmemory.InmemoryDatagrid;
 import org.apache.brooklyn.core.location.BasicLocationRegistry;
 import org.apache.brooklyn.core.mgmt.BrooklynTaskTags;
 import org.apache.brooklyn.core.mgmt.classloading.BrooklynClassLoadingContextSequential;
@@ -169,7 +168,7 @@ public abstract class AbstractManagementContext implements ManagementContextInte
         this.catalog = new BasicBrooklynCatalog(this);
         this.typeRegistry = new BasicBrooklynTypeRegistry(this);
         
-        this.storage = new BrooklynStorageImpl(new InmemoryDatagrid());
+        this.storage = new BrooklynStorageImpl();
         this.rebindManager = new RebindManagerImpl(this); // TODO leaking "this" reference; yuck
         this.highAvailabilityManager = new HighAvailabilityManagerImpl(this); // TODO leaking "this" reference; yuck
         

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/6b59fcb6/core/src/test/java/org/apache/brooklyn/core/internal/storage/impl/BrooklynStorageImplTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/core/internal/storage/impl/BrooklynStorageImplTest.java b/core/src/test/java/org/apache/brooklyn/core/internal/storage/impl/BrooklynStorageImplTest.java
index 9dc02c5..c90a206 100644
--- a/core/src/test/java/org/apache/brooklyn/core/internal/storage/impl/BrooklynStorageImplTest.java
+++ b/core/src/test/java/org/apache/brooklyn/core/internal/storage/impl/BrooklynStorageImplTest.java
@@ -29,10 +29,8 @@ import java.util.List;
 import java.util.Map;
 
 import org.apache.brooklyn.core.internal.storage.BrooklynStorage;
-import org.apache.brooklyn.core.internal.storage.DataGrid;
 import org.apache.brooklyn.core.internal.storage.Reference;
 import org.apache.brooklyn.core.internal.storage.impl.BrooklynStorageImpl;
-import org.apache.brooklyn.core.internal.storage.impl.inmemory.InmemoryDatagrid;
 import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
 
@@ -43,15 +41,13 @@ import com.google.common.collect.Lists;
 
 public class BrooklynStorageImplTest {
     
-    private DataGrid datagrid;
     private BrooklynStorage storage;
 
     @BeforeMethod(alwaysRun=true)
     public void setUp() throws Exception {
         // TODO Note that InmemoryDatagrid's ConcurrentMap currently returns snapshot for entrySet() and values()
         // so the tests here aren't particularly good for confirming it'll work against a real datagrid...
-        datagrid = new InmemoryDatagrid();
-        storage = new BrooklynStorageImpl(datagrid);
+        storage = new BrooklynStorageImpl();
     }
 
     @Test

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/6b59fcb6/core/src/test/java/org/apache/brooklyn/core/test/qa/longevity/EntityCleanupLongevityTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/core/test/qa/longevity/EntityCleanupLongevityTest.java b/core/src/test/java/org/apache/brooklyn/core/test/qa/longevity/EntityCleanupLongevityTest.java
index 26a45fa..bdc56cf 100644
--- a/core/src/test/java/org/apache/brooklyn/core/test/qa/longevity/EntityCleanupLongevityTest.java
+++ b/core/src/test/java/org/apache/brooklyn/core/test/qa/longevity/EntityCleanupLongevityTest.java
@@ -53,7 +53,7 @@ public class EntityCleanupLongevityTest extends EntityCleanupLongevityTestFixtur
         doTestManyTimesAndAssertNoMemoryLeak(JavaClassNames.niceClassAndMethod(), new Runnable() {
             @Override
             public void run() {
-                loc = managementContext.getLocationManager().createLocation(LocationSpec.create(SimulatedLocation.class));
+                loc = newLoc();
                 managementContext.getLocationManager().unmanage(loc);
             }
         });

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/6b59fcb6/core/src/test/java/org/apache/brooklyn/core/test/qa/longevity/EntityCleanupLongevityTestFixture.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/core/test/qa/longevity/EntityCleanupLongevityTestFixture.java b/core/src/test/java/org/apache/brooklyn/core/test/qa/longevity/EntityCleanupLongevityTestFixture.java
index 8eeb29e..e8544d8 100644
--- a/core/src/test/java/org/apache/brooklyn/core/test/qa/longevity/EntityCleanupLongevityTestFixture.java
+++ b/core/src/test/java/org/apache/brooklyn/core/test/qa/longevity/EntityCleanupLongevityTestFixture.java
@@ -18,7 +18,9 @@
  */
 package org.apache.brooklyn.core.test.qa.longevity;
 
-import java.util.Set;
+import static org.testng.Assert.assertTrue;
+
+import java.util.WeakHashMap;
 import java.util.concurrent.ConcurrentMap;
 import java.util.concurrent.TimeUnit;
 
@@ -29,8 +31,6 @@ import org.apache.brooklyn.api.sensor.SensorEventListener;
 import org.apache.brooklyn.core.entity.Entities;
 import org.apache.brooklyn.core.entity.factory.ApplicationBuilder;
 import org.apache.brooklyn.core.internal.storage.BrooklynStorage;
-import org.apache.brooklyn.core.internal.storage.DataGrid;
-import org.apache.brooklyn.core.internal.storage.impl.BrooklynStorageImpl;
 import org.apache.brooklyn.core.location.SimulatedLocation;
 import org.apache.brooklyn.core.mgmt.internal.AbstractManagementContext;
 import org.apache.brooklyn.core.mgmt.internal.LocalManagementContext;
@@ -50,6 +50,7 @@ import org.testng.annotations.BeforeMethod;
 
 import com.google.common.base.Stopwatch;
 import com.google.common.collect.ImmutableList;
+import com.google.common.collect.Iterables;
 
 public abstract class EntityCleanupLongevityTestFixture {
 
@@ -59,6 +60,9 @@ public abstract class EntityCleanupLongevityTestFixture {
     protected SimulatedLocation loc;
     protected TestApplication app;
 
+    protected WeakHashMap<TestApplication, Void> weakApps;
+    protected WeakHashMap<SimulatedLocation, Void> weakLocs;
+    
     // since GC is not definitive (would that it were!)
     final static long MEMORY_MARGIN_OF_ERROR = 10*1024*1024;
 
@@ -76,6 +80,9 @@ public abstract class EntityCleanupLongevityTestFixture {
         
         // do this to ensure GC is initialized
         managementContext.getExecutionManager();
+        
+        weakApps = new WeakHashMap<>();
+        weakLocs = new WeakHashMap<>();
     }
     
     @AfterMethod(alwaysRun=true)
@@ -98,7 +105,8 @@ public abstract class EntityCleanupLongevityTestFixture {
                 long now = timer.elapsed(TimeUnit.MILLISECONDS);
                 System.gc(); System.gc();
                 String msg = testName+" iteration " + i + " at " + Time.makeTimeStringRounded(now) + " (delta "+Time.makeTimeStringRounded(now-last)+"), using "+
-                    ((AbstractManagementContext)managementContext).getGarbageCollector().getUsageString();
+                    ((AbstractManagementContext)managementContext).getGarbageCollector().getUsageString()+
+                    "; weak-refs app="+Iterables.size(weakApps.keySet())+" and locs="+Iterables.size(weakLocs.keySet());
                 LOG.info(msg);
                 if (i>=100 && memUsedNearStart<0) {
                     // set this the first time we've run 100 times (let that create a baseline with classes loaded etc)
@@ -112,20 +120,6 @@ public abstract class EntityCleanupLongevityTestFixture {
         BrooklynStorage storage = ((ManagementContextInternal)managementContext).getStorage();
         Assert.assertTrue(storage.isMostlyEmpty(), "Not empty storage: "+storage);
         
-        DataGrid dg = ((BrooklynStorageImpl)storage).getDataGrid();
-        Set<String> keys = dg.getKeys();
-        for (String key: keys) {
-            ConcurrentMap<Object, Object> v = dg.getMap(key);
-            if (v.isEmpty()) continue;
-            // TODO currently we remember ApplicationUsage
-            if (key.contains("usage-application")) {
-                Assert.assertTrue(v.size() <= iterations, "Too many usage-application entries: "+v.size());
-                continue;
-            }
-            
-            Assert.fail("Non-empty key in datagrid: "+key+" ("+v+")");
-        }
-
         ConcurrentMap<Object, TaskScheduler> schedulers = ((BasicExecutionManager)managementContext.getExecutionManager()).getSchedulerByTag();
         // TODO would like to assert this
 //        Assert.assertTrue( schedulers.isEmpty(), "Not empty schedulers: "+schedulers);
@@ -134,14 +128,21 @@ public abstract class EntityCleanupLongevityTestFixture {
         
         // memory leak detection only applies to subclasses who run lots of iterations
         if (checkMemoryLeaks())
-            assertNoMemoryLeak(memUsedNearStart);
+            assertNoMemoryLeak(memUsedNearStart, iterations);
     }
 
-    protected void assertNoMemoryLeak(long memUsedPreviously) {
+    protected void assertNoMemoryLeak(long memUsedPreviously, int iterations) {
         System.gc(); System.gc();
         long memUsedAfter = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory();
         long memChange = memUsedAfter - memUsedPreviously;
         Assert.assertTrue(memChange < numIterations()*ACCEPTABLE_LEAK_PER_ITERATION + MEMORY_MARGIN_OF_ERROR, "Leaked too much memory: "+Strings.makeJavaSizeString(memChange));
+        
+        // TODO Want a stronger assertion than this - it just says we don't have more apps than we created! 
+        int numApps = Iterables.size(weakApps.keySet());
+        assertTrue(numApps <= iterations, "numApps="+numApps+"; iterations="+iterations);
+        
+        int numLocs = Iterables.size(weakLocs.keySet());
+        assertTrue(numLocs <= iterations, "numLocs="+numLocs+"; iterations="+iterations);
     }
     
     protected void doTestStartAppThenThrowAway(String testName, final boolean stop) {
@@ -164,6 +165,7 @@ public abstract class EntityCleanupLongevityTestFixture {
 
     protected TestApplication newApp() {
         final TestApplication result = ApplicationBuilder.newManagedApp(TestApplication.class, managementContext);
+        weakApps.put(app, null);
         TestEntity entity = result.createAndManageChild(EntitySpec.create(TestEntity.class));
         result.subscriptions().subscribe(entity, TestEntity.NAME, new SensorEventListener<String>() {
             @Override public void onEvent(SensorEvent<String> event) {
@@ -172,4 +174,10 @@ public abstract class EntityCleanupLongevityTestFixture {
         entity.sensors().set(TestEntity.NAME, "myname");
         return result;
     }
+    
+    protected SimulatedLocation newLoc() {
+        SimulatedLocation result = managementContext.getLocationManager().createLocation(LocationSpec.create(SimulatedLocation.class));
+        weakLocs.put(result, null);
+        return result;
+    }
 }


[5/5] brooklyn-server git commit: This closes #669

Posted by dr...@apache.org.
This closes #669


Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/48933eb6
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/48933eb6
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/48933eb6

Branch: refs/heads/master
Commit: 48933eb6bddc0365a8dd20ca6ed28e5a03daceee
Parents: 5b6bf73 6b59fcb
Author: Duncan Godwin <dr...@googlemail.com>
Authored: Mon May 8 09:59:56 2017 +0100
Committer: Duncan Godwin <dr...@googlemail.com>
Committed: Mon May 8 09:59:56 2017 +0100

----------------------------------------------------------------------
 .../core/internal/storage/DataGrid.java         |  52 ---------
 .../core/internal/storage/DataGridFactory.java  |  38 -------
 .../storage/impl/BrooklynStorageImpl.java       |  18 +---
 .../internal/storage/impl/InmemoryDatagrid.java |  86 +++++++++++++++
 .../impl/inmemory/InMemoryDataGridFactory.java  |  40 -------
 .../storage/impl/inmemory/InmemoryDatagrid.java |  93 ----------------
 .../internal/AbstractManagementContext.java     |  49 +--------
 .../mgmt/internal/LocalManagementContext.java   |  28 ++---
 .../deserializingClassRenames.properties        |   4 -
 .../storage/impl/BrooklynStorageImplTest.java   |   6 +-
 .../longevity/EntityCleanupLongevityTest.java   |   2 +-
 .../EntityCleanupLongevityTestFixture.java      |  48 +++++----
 pom.xml                                         |   2 -
 storage/hazelcast/pom.xml                       |  88 ---------------
 .../storage/impl/hazelcast/EntityId.java        |  36 -------
 .../impl/hazelcast/EntityStreamSerializer.java  |  68 ------------
 .../impl/hazelcast/HazelcastDataGrid.java       |  89 ---------------
 .../hazelcast/HazelcastDataGridFactory.java     |  42 --------
 .../impl/hazelcast/HazelcastStorageTest.java    | 107 -------------------
 19 files changed, 128 insertions(+), 768 deletions(-)
----------------------------------------------------------------------



[3/5] brooklyn-server git commit: ManagementContext.dataGrid not configurable

Posted by dr...@apache.org.
ManagementContext.dataGrid not configurable


Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/236afd7a
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/236afd7a
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/236afd7a

Branch: refs/heads/master
Commit: 236afd7ab95a27e3a74fd28dc0337250c880ec32
Parents: 3c1a780
Author: Aled Sage <al...@gmail.com>
Authored: Wed May 3 20:53:42 2017 +0100
Committer: Aled Sage <al...@gmail.com>
Committed: Fri May 5 11:23:51 2017 +0100

----------------------------------------------------------------------
 .../internal/AbstractManagementContext.java     | 48 ++------------------
 .../mgmt/internal/LocalManagementContext.java   | 28 +++---------
 2 files changed, 9 insertions(+), 67 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/236afd7a/core/src/main/java/org/apache/brooklyn/core/mgmt/internal/AbstractManagementContext.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/mgmt/internal/AbstractManagementContext.java b/core/src/main/java/org/apache/brooklyn/core/mgmt/internal/AbstractManagementContext.java
index eed121d..193f328 100644
--- a/core/src/main/java/org/apache/brooklyn/core/mgmt/internal/AbstractManagementContext.java
+++ b/core/src/main/java/org/apache/brooklyn/core/mgmt/internal/AbstractManagementContext.java
@@ -19,7 +19,6 @@
 package org.apache.brooklyn.core.mgmt.internal;
 
 import static com.google.common.base.Preconditions.checkNotNull;
-import static java.lang.String.format;
 import static org.apache.brooklyn.core.catalog.internal.CatalogUtils.newClassLoadingContextForCatalogItems;
 
 import java.net.URI;
@@ -61,8 +60,6 @@ import org.apache.brooklyn.core.entity.drivers.BasicEntityDriverManager;
 import org.apache.brooklyn.core.entity.drivers.downloads.BasicDownloadsManager;
 import org.apache.brooklyn.core.internal.BrooklynProperties;
 import org.apache.brooklyn.core.internal.storage.BrooklynStorage;
-import org.apache.brooklyn.core.internal.storage.DataGrid;
-import org.apache.brooklyn.core.internal.storage.DataGridFactory;
 import org.apache.brooklyn.core.internal.storage.impl.BrooklynStorageImpl;
 import org.apache.brooklyn.core.internal.storage.impl.inmemory.InMemoryDataGridFactory;
 import org.apache.brooklyn.core.location.BasicLocationRegistry;
@@ -75,7 +72,6 @@ import org.apache.brooklyn.core.mgmt.rebind.RebindManagerImpl;
 import org.apache.brooklyn.core.typereg.BasicBrooklynTypeRegistry;
 import org.apache.brooklyn.util.collections.MutableList;
 import org.apache.brooklyn.util.collections.MutableMap;
-import org.apache.brooklyn.util.core.ClassLoaderUtils;
 import org.apache.brooklyn.util.core.ResourceUtils;
 import org.apache.brooklyn.util.core.config.ConfigBag;
 import org.apache.brooklyn.util.core.task.BasicExecutionContext;
@@ -95,36 +91,6 @@ import com.google.common.collect.ImmutableSet;
 public abstract class AbstractManagementContext implements ManagementContextInternal {
     private static final Logger log = LoggerFactory.getLogger(AbstractManagementContext.class);
 
-    private static DataGridFactory loadDataGridFactory(BrooklynProperties properties) {
-        String clazzName = properties.getFirst(DataGridFactory.class.getName());
-        if(clazzName == null){
-            clazzName = InMemoryDataGridFactory.class.getName();
-        }
-
-        Class<?> clazz;
-        try{
-            //todo: which classloader should we use?
-            clazz = new ClassLoaderUtils(AbstractManagementContext.class).loadClass(clazzName);
-        }catch(ClassNotFoundException e){
-            throw new IllegalStateException(format("Could not load class [%s]",clazzName),e);
-        }
-
-        Object instance;
-        try {
-            instance = clazz.newInstance();
-        } catch (InstantiationException e) {
-            throw new IllegalStateException(format("Could not instantiate class [%s]",clazzName),e);
-        } catch (IllegalAccessException e) {
-            throw new IllegalStateException(format("Could not instantiate class [%s]",clazzName),e);
-        }
-
-        if(!(instance instanceof DataGridFactory)){
-            throw new IllegalStateException(format("Class [%s] not an instantiate of class [%s]",clazzName, DataGridFactory.class.getName()));
-        }
-
-        return (DataGridFactory)instance;
-    }
-
     static {
         ResourceUtils.addClassLoaderProvider(new Function<Object, BrooklynClassLoadingContext>() {
             @Override
@@ -194,24 +160,16 @@ public abstract class AbstractManagementContext implements ManagementContextInte
     protected Maybe<URI> uri = Maybe.absent();
     protected CatalogInitialization catalogInitialization;
 
-    public AbstractManagementContext(BrooklynProperties brooklynProperties){
-        this(brooklynProperties, null);
-    }
-
-    public AbstractManagementContext(BrooklynProperties brooklynProperties, DataGridFactory datagridFactory) {
+    public AbstractManagementContext(BrooklynProperties brooklynProperties) {
         this.configMap = new DeferredBrooklynProperties(brooklynProperties, this);
         this.scratchpad = new BasicScratchpad();
         this.entityDriverManager = new BasicEntityDriverManager();
         this.downloadsManager = BasicDownloadsManager.newDefault(configMap);
-        if (datagridFactory == null) {
-            datagridFactory = loadDataGridFactory(brooklynProperties);
-        }
-        DataGrid datagrid = datagridFactory.newDataGrid(this);
-
+        
         this.catalog = new BasicBrooklynCatalog(this);
         this.typeRegistry = new BasicBrooklynTypeRegistry(this);
         
-        this.storage = new BrooklynStorageImpl(datagrid);
+        this.storage = new BrooklynStorageImpl(new InMemoryDataGridFactory().newDataGrid(this));
         this.rebindManager = new RebindManagerImpl(this); // TODO leaking "this" reference; yuck
         this.highAvailabilityManager = new HighAvailabilityManagerImpl(this); // TODO leaking "this" reference; yuck
         

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/236afd7a/core/src/main/java/org/apache/brooklyn/core/mgmt/internal/LocalManagementContext.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/mgmt/internal/LocalManagementContext.java b/core/src/main/java/org/apache/brooklyn/core/mgmt/internal/LocalManagementContext.java
index bdb6302..3e3b776 100644
--- a/core/src/main/java/org/apache/brooklyn/core/mgmt/internal/LocalManagementContext.java
+++ b/core/src/main/java/org/apache/brooklyn/core/mgmt/internal/LocalManagementContext.java
@@ -49,7 +49,6 @@ import org.apache.brooklyn.core.entity.drivers.downloads.BasicDownloadsManager;
 import org.apache.brooklyn.core.internal.BrooklynInitialization;
 import org.apache.brooklyn.core.internal.BrooklynProperties;
 import org.apache.brooklyn.core.internal.BrooklynProperties.Factory.Builder;
-import org.apache.brooklyn.core.internal.storage.DataGridFactory;
 import org.apache.brooklyn.core.mgmt.entitlement.Entitlements;
 import org.apache.brooklyn.core.mgmt.ha.OsgiManager;
 import org.apache.brooklyn.core.objs.proxy.InternalEntityFactory;
@@ -150,41 +149,26 @@ public class LocalManagementContext extends AbstractManagementContext {
         this(BrooklynProperties.Factory.builderDefault());
     }
 
-    public LocalManagementContext(BrooklynProperties brooklynProperties) {
-        this(brooklynProperties, (DataGridFactory)null);
-    }
-
     /**
      * Creates a new LocalManagementContext.
      *
      * @param brooklynProperties the BrooklynProperties.
-     * @param datagridFactory the DataGridFactory to use. If this instance is null, it means that the system
-     *                        is going to use BrooklynProperties to figure out which instance to load or otherwise
-     *                        use a default instance.
      */
     @VisibleForTesting
-    public LocalManagementContext(BrooklynProperties brooklynProperties, DataGridFactory datagridFactory) {
-        this(Builder.fromProperties(brooklynProperties), datagridFactory);
+    public LocalManagementContext(BrooklynProperties brooklynProperties) {
+        this(Builder.fromProperties(brooklynProperties));
     }
     
     public LocalManagementContext(Builder builder) {
-        this(builder, null, null);
-    }
-    
-    public LocalManagementContext(Builder builder, DataGridFactory datagridFactory) {
-        this(builder, null, datagridFactory);
-    }
-
-    public LocalManagementContext(Builder builder, Map<String, Object> brooklynAdditionalProperties) {
-        this(builder, brooklynAdditionalProperties, null);
+        this(builder, null);
     }
     
     public LocalManagementContext(BrooklynProperties brooklynProperties, Map<String, Object> brooklynAdditionalProperties) {
-        this(Builder.fromProperties(brooklynProperties), brooklynAdditionalProperties, null);
+        this(Builder.fromProperties(brooklynProperties), brooklynAdditionalProperties);
     }
     
-    public LocalManagementContext(Builder builder, Map<String, Object> brooklynAdditionalProperties, DataGridFactory datagridFactory) {
-        super(builder.build(), datagridFactory);
+    public LocalManagementContext(Builder builder, Map<String, Object> brooklynAdditionalProperties) {
+        super(builder.build());
         
         checkNotNull(configMap, "brooklynProperties");
         


[2/5] brooklyn-server git commit: Delete DataGridFactory

Posted by dr...@apache.org.
Delete DataGridFactory


Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/21c40ba0
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/21c40ba0
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/21c40ba0

Branch: refs/heads/master
Commit: 21c40ba0b9ab2eabe76ce834117964a1613a4677
Parents: 236afd7
Author: Aled Sage <al...@gmail.com>
Authored: Wed May 3 20:59:47 2017 +0100
Committer: Aled Sage <al...@gmail.com>
Committed: Fri May 5 11:23:51 2017 +0100

----------------------------------------------------------------------
 .../core/internal/storage/DataGridFactory.java  | 38 -------------------
 .../impl/inmemory/InMemoryDataGridFactory.java  | 40 --------------------
 .../internal/AbstractManagementContext.java     |  4 +-
 3 files changed, 2 insertions(+), 80 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/21c40ba0/core/src/main/java/org/apache/brooklyn/core/internal/storage/DataGridFactory.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/internal/storage/DataGridFactory.java b/core/src/main/java/org/apache/brooklyn/core/internal/storage/DataGridFactory.java
deleted file mode 100644
index 45c696b..0000000
--- a/core/src/main/java/org/apache/brooklyn/core/internal/storage/DataGridFactory.java
+++ /dev/null
@@ -1,38 +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.internal.storage;
-
-import org.apache.brooklyn.core.mgmt.internal.ManagementContextInternal;
-
-/**
- * A factory for creating a {@link DataGrid}.
- *
- * Implementations of this interface should have a public no arg constructor; this constructor will be
- * called through reflection in the {@link org.apache.brooklyn.core.mgmt.internal.LocalManagementContext}.
- */
-public interface DataGridFactory {
-
-    /**
-     * Creates a {@link BrooklynStorage} instance.
-     *
-     * @param managementContext the ManagementContextInternal
-     * @return the created BrooklynStorage.
-     */
-    DataGrid newDataGrid(ManagementContextInternal managementContext);
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/21c40ba0/core/src/main/java/org/apache/brooklyn/core/internal/storage/impl/inmemory/InMemoryDataGridFactory.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/internal/storage/impl/inmemory/InMemoryDataGridFactory.java b/core/src/main/java/org/apache/brooklyn/core/internal/storage/impl/inmemory/InMemoryDataGridFactory.java
deleted file mode 100644
index 0ce0aa7..0000000
--- a/core/src/main/java/org/apache/brooklyn/core/internal/storage/impl/inmemory/InMemoryDataGridFactory.java
+++ /dev/null
@@ -1,40 +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.internal.storage.impl.inmemory;
-
-import org.apache.brooklyn.core.internal.storage.DataGrid;
-import org.apache.brooklyn.core.internal.storage.DataGridFactory;
-import org.apache.brooklyn.core.mgmt.internal.ManagementContextInternal;
-
-public class InMemoryDataGridFactory implements DataGridFactory {
-    
-    public static DataGridFactory ofInstance(final DataGrid datagrid) {
-        return new DataGridFactory() {
-            @Override
-            public DataGrid newDataGrid(ManagementContextInternal managementContext) {
-                return datagrid;
-            }
-        };
-    }
-    
-    @Override
-    public DataGrid newDataGrid(ManagementContextInternal managementContext) {
-        return new InmemoryDatagrid();
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/21c40ba0/core/src/main/java/org/apache/brooklyn/core/mgmt/internal/AbstractManagementContext.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/mgmt/internal/AbstractManagementContext.java b/core/src/main/java/org/apache/brooklyn/core/mgmt/internal/AbstractManagementContext.java
index 193f328..45a45d7 100644
--- a/core/src/main/java/org/apache/brooklyn/core/mgmt/internal/AbstractManagementContext.java
+++ b/core/src/main/java/org/apache/brooklyn/core/mgmt/internal/AbstractManagementContext.java
@@ -61,7 +61,7 @@ import org.apache.brooklyn.core.entity.drivers.downloads.BasicDownloadsManager;
 import org.apache.brooklyn.core.internal.BrooklynProperties;
 import org.apache.brooklyn.core.internal.storage.BrooklynStorage;
 import org.apache.brooklyn.core.internal.storage.impl.BrooklynStorageImpl;
-import org.apache.brooklyn.core.internal.storage.impl.inmemory.InMemoryDataGridFactory;
+import org.apache.brooklyn.core.internal.storage.impl.inmemory.InmemoryDatagrid;
 import org.apache.brooklyn.core.location.BasicLocationRegistry;
 import org.apache.brooklyn.core.mgmt.BrooklynTaskTags;
 import org.apache.brooklyn.core.mgmt.classloading.BrooklynClassLoadingContextSequential;
@@ -169,7 +169,7 @@ public abstract class AbstractManagementContext implements ManagementContextInte
         this.catalog = new BasicBrooklynCatalog(this);
         this.typeRegistry = new BasicBrooklynTypeRegistry(this);
         
-        this.storage = new BrooklynStorageImpl(new InMemoryDataGridFactory().newDataGrid(this));
+        this.storage = new BrooklynStorageImpl(new InmemoryDatagrid());
         this.rebindManager = new RebindManagerImpl(this); // TODO leaking "this" reference; yuck
         this.highAvailabilityManager = new HighAvailabilityManagerImpl(this); // TODO leaking "this" reference; yuck