[1/4] brooklyn-server git commit: Machines.findUniqueElement returns absent when items is null

2017-02-08 Thread sjcorbett
Repository: brooklyn-server
Updated Branches:
  refs/heads/master 984a1e18f -> 6571bab4a


Machines.findUniqueElement returns absent when items is null


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

Branch: refs/heads/master
Commit: 79977e768a88e6e3b36d59adb63c0ca32ad6ebcc
Parents: 15d6c98
Author: Sam Corbett 
Authored: Wed Feb 8 12:22:57 2017 +
Committer: Sam Corbett 
Committed: Wed Feb 8 12:29:31 2017 +

--
 .../main/java/org/apache/brooklyn/core/location/Machines.java | 7 ++-
 .../java/org/apache/brooklyn/core/location/MachinesTest.java  | 5 +
 2 files changed, 11 insertions(+), 1 deletion(-)
--


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/79977e76/core/src/main/java/org/apache/brooklyn/core/location/Machines.java
--
diff --git a/core/src/main/java/org/apache/brooklyn/core/location/Machines.java 
b/core/src/main/java/org/apache/brooklyn/core/location/Machines.java
index 9163694..2a2ccba 100644
--- a/core/src/main/java/org/apache/brooklyn/core/location/Machines.java
+++ b/core/src/main/java/org/apache/brooklyn/core/location/Machines.java
@@ -23,6 +23,8 @@ import java.util.Collection;
 import java.util.Iterator;
 import java.util.Set;
 
+import javax.annotation.Nonnull;
+
 import org.apache.brooklyn.api.entity.Entity;
 import org.apache.brooklyn.api.location.Location;
 import org.apache.brooklyn.api.location.MachineLocation;
@@ -83,9 +85,12 @@ public class Machines {
 return Maybe.fromNullable(result);
 }
 
+@Nonnull
 @SuppressWarnings("unchecked")
 public static  Maybe findUniqueElement(Iterable items, Class 
type) {
-if (items==null) return null;
+if (items == null) {
+return Maybe.absent(new NullPointerException("Null iterable"));
+}
 Iterator i = items.iterator();
 T result = null;
 while (i.hasNext()) {

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/79977e76/core/src/test/java/org/apache/brooklyn/core/location/MachinesTest.java
--
diff --git 
a/core/src/test/java/org/apache/brooklyn/core/location/MachinesTest.java 
b/core/src/test/java/org/apache/brooklyn/core/location/MachinesTest.java
index bc578bd..3e36f7a 100644
--- a/core/src/test/java/org/apache/brooklyn/core/location/MachinesTest.java
+++ b/core/src/test/java/org/apache/brooklyn/core/location/MachinesTest.java
@@ -90,6 +90,11 @@ public class MachinesTest extends BrooklynAppUnitTestSupport 
{
 }
 
 @Test
+public void testFindUniqueElementAbsentWhenItemsNull() throws Exception {
+assertTrue(Machines.findUniqueElement(null, 
SshMachineLocation.class).isAbsent());
+}
+
+@Test
 public void testFindSubnetIpFromAttribute() throws Exception {
 TestEntity entity = app.addChild(EntitySpec.create(TestEntity.class)
 .location(sshMachineSpec));



[4/4] brooklyn-server git commit: This closes #553

2017-02-08 Thread sjcorbett
This closes #553

MultimapSerializer works with non-String keys


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

Branch: refs/heads/master
Commit: 6571bab4a91c6a038c5bb564173e9a8101d417a3
Parents: 984a1e1 148ac04
Author: Sam Corbett 
Authored: Wed Feb 8 15:21:45 2017 +
Committer: Sam Corbett 
Committed: Wed Feb 8 15:21:45 2017 +

--
 .../apache/brooklyn/core/location/Machines.java |  7 +-
 .../util/core/json/MultimapSerializer.java  |  2 +-
 .../brooklyn/core/location/MachinesTest.java|  5 ++
 .../util/core/json/MultimapSerializerTest.java  | 72 
 .../jclouds/networking/SecurityGroupEditor.java | 18 ++---
 5 files changed, 90 insertions(+), 14 deletions(-)
--




[3/4] brooklyn-server git commit: MultimapSerializer works with non-String keys

2017-02-08 Thread sjcorbett
MultimapSerializer works with non-String keys


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

Branch: refs/heads/master
Commit: 148ac04c0655e2207171073f7bf4e5d1dba7e751
Parents: 79977e7
Author: Sam Corbett 
Authored: Wed Feb 8 12:22:28 2017 +
Committer: Sam Corbett 
Committed: Wed Feb 8 14:21:00 2017 +

--
 .../util/core/json/MultimapSerializer.java  |  2 +-
 .../util/core/json/MultimapSerializerTest.java  | 72 
 2 files changed, 73 insertions(+), 1 deletion(-)
--


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/148ac04c/core/src/main/java/org/apache/brooklyn/util/core/json/MultimapSerializer.java
--
diff --git 
a/core/src/main/java/org/apache/brooklyn/util/core/json/MultimapSerializer.java 
b/core/src/main/java/org/apache/brooklyn/util/core/json/MultimapSerializer.java
index 53ce3f5..a6522fa 100644
--- 
a/core/src/main/java/org/apache/brooklyn/util/core/json/MultimapSerializer.java
+++ 
b/core/src/main/java/org/apache/brooklyn/util/core/json/MultimapSerializer.java
@@ -56,7 +56,7 @@ public class MultimapSerializer extends 
StdSerializer {
 
 private void writeEntries(Multimap value, JsonGenerator jgen, 
SerializerProvider provider) throws IOException {
 for (Map.Entry> entry : 
value.asMap().entrySet()) {
-provider.findKeySerializer(provider.constructType(String.class), 
null)
+provider.findKeySerializer(provider.constructType(Object.class), 
null)
 .serialize(entry.getKey(), jgen, provider);
 
provider.defaultSerializeValue(Lists.newArrayList(entry.getValue()), jgen);
 }

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/148ac04c/core/src/test/java/org/apache/brooklyn/util/core/json/MultimapSerializerTest.java
--
diff --git 
a/core/src/test/java/org/apache/brooklyn/util/core/json/MultimapSerializerTest.java
 
b/core/src/test/java/org/apache/brooklyn/util/core/json/MultimapSerializerTest.java
new file mode 100644
index 000..902e377
--- /dev/null
+++ 
b/core/src/test/java/org/apache/brooklyn/util/core/json/MultimapSerializerTest.java
@@ -0,0 +1,72 @@
+/*
+ * 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.util.core.json;
+
+import static org.testng.Assert.assertEquals;
+
+import org.apache.brooklyn.api.entity.Entity;
+import org.apache.brooklyn.api.entity.EntitySpec;
+import org.apache.brooklyn.core.test.BrooklynAppUnitTestSupport;
+import org.apache.brooklyn.entity.stock.BasicEntity;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+import com.fasterxml.jackson.core.Version;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.module.SimpleModule;
+import com.google.common.collect.Multimap;
+import com.google.common.collect.MultimapBuilder;
+
+public class MultimapSerializerTest extends BrooklynAppUnitTestSupport {
+
+ObjectMapper mapper;
+
+@Override
+@BeforeMethod(alwaysRun = true)
+public void setUp() throws Exception {
+super.setUp();
+mapper = new ObjectMapper();
+SimpleModule mapperModule = new SimpleModule("MultimapSerializerTest", 
new Version(0, 0, 0, "ignored", null, null));
+mapperModule.addSerializer(new MultimapSerializer());
+mapper.registerModule(mapperModule);
+}
+
+@Test
+public void testSerializeStringKey() throws Exception {
+Multimap map = 
MultimapBuilder.hashKeys().arrayListValues().build();
+map.put("a", 1);
+map.put("a", 2);
+map.put("a", 3);
+String json = 

[1/2] brooklyn-server git commit: Adds DynamicCluster.testClustersHaveIndependentCounters

2017-02-08 Thread drigodwin
Repository: brooklyn-server
Updated Branches:
  refs/heads/master c62f84a95 -> 984a1e18f


Adds DynamicCluster.testClustersHaveIndependentCounters

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

Branch: refs/heads/master
Commit: ef96aed188412a0f1c4a8b2df4fb3394e766e5c2
Parents: c62f84a
Author: Aled Sage 
Authored: Wed Feb 8 10:43:47 2017 +
Committer: Aled Sage 
Committed: Wed Feb 8 10:46:42 2017 +

--
 .../entity/group/DynamicClusterTest.java| 55 ++--
 1 file changed, 38 insertions(+), 17 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/ef96aed1/core/src/test/java/org/apache/brooklyn/entity/group/DynamicClusterTest.java
--
diff --git 
a/core/src/test/java/org/apache/brooklyn/entity/group/DynamicClusterTest.java 
b/core/src/test/java/org/apache/brooklyn/entity/group/DynamicClusterTest.java
index 3c827f6..f2d74dc 100644
--- 
a/core/src/test/java/org/apache/brooklyn/entity/group/DynamicClusterTest.java
+++ 
b/core/src/test/java/org/apache/brooklyn/entity/group/DynamicClusterTest.java
@@ -1042,12 +1042,7 @@ public class DynamicClusterTest extends 
BrooklynAppUnitTestSupport {
 
 cluster.start(ImmutableList.of(loc));
 
-Iterator clusterMembersIterator = 
cluster.getMembers().iterator();
-
-for (Integer expectedClusterMemberId = 0; expectedClusterMemberId < 
clusterSize; expectedClusterMemberId++) {
-Entity clusterMember = clusterMembersIterator.next();
-assertEquals(clusterMember.config().get(CLUSTER_MEMBER_ID), 
expectedClusterMemberId);
-}
+assertMemberIdSensors(cluster, ImmutableList.of(0, 1, 2, 3, 4));
 }
 
 @Test
@@ -1063,12 +1058,7 @@ public class DynamicClusterTest extends 
BrooklynAppUnitTestSupport {
 int positiveResizeDelta = 3;
 cluster.resizeByDelta(positiveResizeDelta);
 
-Iterator clusterMembersIterator = 
cluster.getMembers().iterator();
-
-for (Integer expectedClusterMemberId = 0; expectedClusterMemberId < 
clusterSize + positiveResizeDelta; expectedClusterMemberId++) {
-Entity clusterMember = clusterMembersIterator.next();
-assertEquals(clusterMember.config().get(CLUSTER_MEMBER_ID), 
expectedClusterMemberId);
-}
+assertMemberIdSensors(cluster, ImmutableList.of(0, 1, 2, 3, 4, 5, 6, 
7));
 }
 
 @Test
@@ -1087,16 +1077,47 @@ public class DynamicClusterTest extends 
BrooklynAppUnitTestSupport {
 int positiveResizeDelta = 2;
 cluster.resizeByDelta(positiveResizeDelta);
 
-Iterator clusterMembersIterator = 
cluster.getMembers().iterator();
+assertMemberIdSensors(cluster, ImmutableList.of(0, 1, 5, 6));
+}
 
-Integer[] expectedClusterMemberIds = {0, 1, 5, 6};
+@Test
+public void testClustersHaveIndependentCounters() throws Exception {
+int numClusters = 2;
+int clusterInitialSize = 1;
+int clusterSizeDelta = 1;
+List clusters = Lists.newArrayList();
+for (int i = 0; i < numClusters; i++) {
+DynamicCluster cluster = 
app.addChild(EntitySpec.create(DynamicCluster.class)
+.configure("memberSpec", 
EntitySpec.create(TestEntity.class))
+.configure("initialSize", clusterInitialSize));
+cluster.start(ImmutableList.of(loc));
+clusters.add(cluster);
+}
 
-for (Integer expectedClusterMemberId : expectedClusterMemberIds) {
-Entity clusterMember = clusterMembersIterator.next();
-assertEquals(clusterMember.config().get(CLUSTER_MEMBER_ID), 
expectedClusterMemberId);
+// Each cluster has its own independent count, so should start with 0.
+for (DynamicCluster cluster : clusters) {
+List expectedIds = ImmutableList.of(0);
+assertMemberIdSensors(cluster, expectedIds);
+}
+
+// Each cluster should continue using its own independent count when 
resized.
+for (DynamicCluster cluster : clusters) {
+cluster.resizeByDelta(clusterSizeDelta);
+}
+for (DynamicCluster cluster : clusters) {
+List expectedIds = ImmutableList.of(0, 1);
+assertMemberIdSensors(cluster, expectedIds);
 }
 }
 
+private void assertMemberIdSensors(DynamicCluster cluster, List 
expectedIds) {
+List members = ImmutableList.copyOf(cluster.getMembers());
+assertEquals(members.size(), expectedIds.size(), 

[2/2] brooklyn-server git commit: This closes #552

2017-02-08 Thread drigodwin
This closes #552


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

Branch: refs/heads/master
Commit: 984a1e18fa0ec4ffb1cab533bd74b6aac0d8916d
Parents: c62f84a ef96aed
Author: Duncan Godwin 
Authored: Wed Feb 8 11:59:19 2017 +
Committer: Duncan Godwin 
Committed: Wed Feb 8 11:59:19 2017 +

--
 .../entity/group/DynamicClusterTest.java| 55 ++--
 1 file changed, 38 insertions(+), 17 deletions(-)
--