You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by he...@apache.org on 2014/07/18 19:15:25 UTC

[1/2] git commit: rat fix, support period, and fix broken test (patching #48)

Repository: incubator-brooklyn
Updated Branches:
  refs/heads/master 82f850665 -> cfb7a0cd8


rat fix, support period, and fix broken test (patching #48)


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

Branch: refs/heads/master
Commit: cfb7a0cd8f5e09117d0deb2321a0e32d4d37d0fc
Parents: 33aa6b6
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Authored: Fri Jul 18 13:00:00 2014 -0400
Committer: Alex Heneveld <al...@cloudsoftcorp.com>
Committed: Fri Jul 18 13:13:26 2014 -0400

----------------------------------------------------------------------
 .../brooklyn/entity/effector/AddSensor.java     |  1 +
 .../event/feed/http/JsonFunctionsTest.java      | 14 +++++++--
 .../entity/software/http/HttpRequestSensor.java | 23 +++++++++++++-
 .../software/http/HttpRequestSensorTest.java    | 33 +++++++++++++++-----
 4 files changed, 60 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/cfb7a0cd/core/src/main/java/brooklyn/entity/effector/AddSensor.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/entity/effector/AddSensor.java b/core/src/main/java/brooklyn/entity/effector/AddSensor.java
index 8043c64..cdaa5df 100644
--- a/core/src/main/java/brooklyn/entity/effector/AddSensor.java
+++ b/core/src/main/java/brooklyn/entity/effector/AddSensor.java
@@ -59,6 +59,7 @@ public class AddSensor<RT,T extends Sensor<RT>> implements EntityInitializer {
         return Sensors.newSensor(type, name);
     }
 
+    @SuppressWarnings("unchecked")
     public static <T> AttributeSensor<T> newSensor(ConfigBag params) {
         String name = Preconditions.checkNotNull(params.get(SENSOR_NAME), "name must be supplied when defining a sensor");
         String className = getFullClassName(params.get(SENSOR_TYPE));

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/cfb7a0cd/core/src/test/java/brooklyn/event/feed/http/JsonFunctionsTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/brooklyn/event/feed/http/JsonFunctionsTest.java b/core/src/test/java/brooklyn/event/feed/http/JsonFunctionsTest.java
index 5aaa47e..e0140a6 100644
--- a/core/src/test/java/brooklyn/event/feed/http/JsonFunctionsTest.java
+++ b/core/src/test/java/brooklyn/event/feed/http/JsonFunctionsTest.java
@@ -31,6 +31,7 @@ import brooklyn.util.guava.Maybe;
 
 import com.google.gson.JsonElement;
 import com.google.gson.JsonParser;
+import com.jayway.jsonpath.PathNotFoundException;
 
 public class JsonFunctionsTest {
 
@@ -115,8 +116,15 @@ public class JsonFunctionsTest {
     }
 
     @Test
-    public void testGetPathWrong(){
-        Object obj = JsonFunctions.getPath("$.europe.spain.malaga").apply(europeMap());
-        Assert.assertNull(obj);
+    public void testGetMissingPathIsNullOrThrows(){
+        try {
+            // TODO is there a way to force this to return null if not found?
+            // for me (Alex) it throws but for others it seems to return null
+            Object obj = JsonFunctions.getPath("$.europe.spain.malaga").apply(europeMap());
+            Assert.assertNull(obj);
+        } catch (PathNotFoundException e) {
+            // not unexpected
+        }
     }
+    
 }

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/cfb7a0cd/software/base/src/main/java/brooklyn/entity/software/http/HttpRequestSensor.java
----------------------------------------------------------------------
diff --git a/software/base/src/main/java/brooklyn/entity/software/http/HttpRequestSensor.java b/software/base/src/main/java/brooklyn/entity/software/http/HttpRequestSensor.java
index c16a739..cf78126 100644
--- a/software/base/src/main/java/brooklyn/entity/software/http/HttpRequestSensor.java
+++ b/software/base/src/main/java/brooklyn/entity/software/http/HttpRequestSensor.java
@@ -1,3 +1,21 @@
+/*
+ * 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 brooklyn.entity.software.http;
 
 import brooklyn.config.ConfigKey;
@@ -47,8 +65,11 @@ public final class HttpRequestSensor<T> extends AddSensor<T, AttributeSensor<T>>
     public void apply(final EntityLocal entity) {
         super.apply(entity);
 
-        Duration period = Duration.ONE_SECOND;
+        Duration period = entity.getConfig(SENSOR_PERIOD);
+        if (period==null) period = Duration.ONE_SECOND;
 
+        log.debug("Adding sensor "+sensor+" to "+entity+" polling "+uri+" for "+jsonPath);
+        
         HttpPollConfig<T> pollConfig = new HttpPollConfig<T>(sensor)
                 .checkSuccess(HttpValueFunctions.responseCodeEquals(200))
                 .onFailureOrException(Functions.constant((T) null))

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/cfb7a0cd/software/base/src/test/java/brooklyn/entity/software/http/HttpRequestSensorTest.java
----------------------------------------------------------------------
diff --git a/software/base/src/test/java/brooklyn/entity/software/http/HttpRequestSensorTest.java b/software/base/src/test/java/brooklyn/entity/software/http/HttpRequestSensorTest.java
index 5f29e5d..8c796da 100644
--- a/software/base/src/test/java/brooklyn/entity/software/http/HttpRequestSensorTest.java
+++ b/software/base/src/test/java/brooklyn/entity/software/http/HttpRequestSensorTest.java
@@ -1,6 +1,29 @@
+/*
+ * 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 brooklyn.entity.software.http;
 
-import brooklyn.entity.basic.ApplicationBuilder;
+import static org.testng.Assert.assertEquals;
+
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
 import brooklyn.entity.basic.Attributes;
 import brooklyn.entity.basic.Entities;
 import brooklyn.entity.basic.EntityLocal;
@@ -12,12 +35,8 @@ import brooklyn.test.EntityTestUtils;
 import brooklyn.test.entity.TestApplication;
 import brooklyn.test.entity.TestEntity;
 import brooklyn.util.config.ConfigBag;
-import com.google.common.collect.ImmutableList;
-import org.testng.annotations.AfterMethod;
-import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.Test;
 
-import static org.testng.Assert.assertEquals;
+import com.google.common.collect.ImmutableList;
 
 public class HttpRequestSensorTest {
     final static AttributeSensor<String> SENSOR_STRING = Sensors.newStringSensor("aString");
@@ -28,7 +47,7 @@ public class HttpRequestSensorTest {
 
     @BeforeMethod(alwaysRun=true)
     public void setUp() throws Exception {
-        app = ApplicationBuilder.newManagedApp(TestApplication.class);
+        app = TestApplication.Factory.newManagedInstanceForTests();
         entity = app.createAndManageChild(EntitySpec.create(TestEntity.class).location(app.newLocalhostProvisioningLocation().obtain()));
         app.start(ImmutableList.<Location>of());
     }


[2/2] git commit: rat fix, and add one more (overlooked previously) integration test for BrooklynEntityMirror

Posted by he...@apache.org.
rat fix, and add one more (overlooked previously) integration test for BrooklynEntityMirror


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

Branch: refs/heads/master
Commit: 33aa6b69dd3c9dfcceb005342a63b95b69a5e174
Parents: 82f8506
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Authored: Fri Jul 18 12:50:15 2014 -0400
Committer: Alex Heneveld <al...@cloudsoftcorp.com>
Committed: Fri Jul 18 13:13:26 2014 -0400

----------------------------------------------------------------------
 .../entity/basic/EntityInitializers.java        |  18 +++
 .../brooklynnode/BrooklynEntityMirror.java      |   5 +-
 .../BrooklynEntityMirrorIntegrationTest.java    | 162 +++++++++++++++++++
 3 files changed, 184 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/33aa6b69/core/src/main/java/brooklyn/entity/basic/EntityInitializers.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/entity/basic/EntityInitializers.java b/core/src/main/java/brooklyn/entity/basic/EntityInitializers.java
index 62db62e..3571b5a 100644
--- a/core/src/main/java/brooklyn/entity/basic/EntityInitializers.java
+++ b/core/src/main/java/brooklyn/entity/basic/EntityInitializers.java
@@ -1,3 +1,21 @@
+/*
+ * 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 brooklyn.entity.basic;
 
 import java.util.List;

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/33aa6b69/software/base/src/main/java/brooklyn/entity/brooklynnode/BrooklynEntityMirror.java
----------------------------------------------------------------------
diff --git a/software/base/src/main/java/brooklyn/entity/brooklynnode/BrooklynEntityMirror.java b/software/base/src/main/java/brooklyn/entity/brooklynnode/BrooklynEntityMirror.java
index 2773793..dd01394 100644
--- a/software/base/src/main/java/brooklyn/entity/brooklynnode/BrooklynEntityMirror.java
+++ b/software/base/src/main/java/brooklyn/entity/brooklynnode/BrooklynEntityMirror.java
@@ -28,7 +28,10 @@ import brooklyn.event.basic.Sensors;
 import brooklyn.util.time.Duration;
 
 /** Provides an entity which can sit in one brooklyn domain and reflect the status of an entity 
- * via the REST API of another domain */
+ * via the REST API of another domain.
+ * <p>
+ * Note tests for this depend on a REST server so are in other projects; search for *Mirror*Test,
+ * as well as *BrooklynNode*Test. */
 @ImplementedBy(BrooklynEntityMirrorImpl.class)
 public interface BrooklynEntityMirror extends Entity {
 

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/33aa6b69/usage/launcher/src/test/java/brooklyn/entity/brooklynnode/BrooklynEntityMirrorIntegrationTest.java
----------------------------------------------------------------------
diff --git a/usage/launcher/src/test/java/brooklyn/entity/brooklynnode/BrooklynEntityMirrorIntegrationTest.java b/usage/launcher/src/test/java/brooklyn/entity/brooklynnode/BrooklynEntityMirrorIntegrationTest.java
new file mode 100644
index 0000000..bb54d06
--- /dev/null
+++ b/usage/launcher/src/test/java/brooklyn/entity/brooklynnode/BrooklynEntityMirrorIntegrationTest.java
@@ -0,0 +1,162 @@
+/*
+ * 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 brooklyn.entity.brooklynnode;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.testng.Assert;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+import brooklyn.entity.Entity;
+import brooklyn.entity.basic.ApplicationBuilder;
+import brooklyn.entity.basic.Attributes;
+import brooklyn.entity.basic.Entities;
+import brooklyn.entity.basic.EntityInternal;
+import brooklyn.entity.basic.Lifecycle;
+import brooklyn.entity.brooklynnode.BrooklynEntityMirror;
+import brooklyn.entity.proxying.EntitySpec;
+import brooklyn.launcher.BrooklynWebServer;
+import brooklyn.management.ManagementContext;
+import brooklyn.rest.security.BrooklynPropertiesSecurityFilter;
+import brooklyn.test.EntityTestUtils;
+import brooklyn.test.HttpTestUtils;
+import brooklyn.test.entity.LocalManagementContextForTests;
+import brooklyn.test.entity.TestApplication;
+import brooklyn.util.exceptions.Exceptions;
+import brooklyn.util.time.Duration;
+
+/**
+ * Test for EntityMirror, launching an in-memory server and ensuring we can mirror.
+ * Here so that we can access the REST server.
+ * <p>
+ * May require <code>-Dbrooklyn.localhost.address=127.0.0.1</code> so that the console which binds to localhost is addressible.
+ * (That and the time it takes to run are the only reasons this is Integration.)
+ */
+@Test
+public class BrooklynEntityMirrorIntegrationTest {
+
+    private static final Logger log = LoggerFactory.getLogger(BrooklynEntityMirrorIntegrationTest.class);
+    
+    private BrooklynWebServer server;
+    private TestApplication serverApp;
+    private ManagementContext serverMgmt;
+    
+    private TestApplication localApp;
+    private ManagementContext localMgmt;
+
+    @BeforeMethod(alwaysRun=true)
+    public void setUp() throws Exception {
+        localApp = TestApplication.Factory.newManagedInstanceForTests();
+        localMgmt = localApp.getManagementContext();
+    }
+
+    @AfterMethod(alwaysRun=true)
+    public void tearDown() throws Exception {
+        if (serverMgmt!=null) Entities.destroyAll(serverMgmt);
+        if (server!=null) server.stop();
+        if (localMgmt!=null) Entities.destroyAll(localMgmt);
+        
+        serverMgmt = null;
+    }
+
+    
+    protected void setUpServer() {
+        setUpServer(new LocalManagementContextForTests(), false);
+    }
+    protected void setUpServer(ManagementContext mgmt, boolean useSecurityFilter) {
+        try {
+            if (serverMgmt!=null) throw new IllegalStateException("server already set up");
+            
+            serverMgmt = mgmt;
+            server = new BrooklynWebServer(mgmt);
+            if (useSecurityFilter) server.setSecurityFilter(BrooklynPropertiesSecurityFilter.class);
+            server.start();
+            
+            serverApp = ApplicationBuilder.newManagedApp(TestApplication.class, serverMgmt);
+        } catch (Exception e) {
+            throw Exceptions.propagate(e);
+        }
+    }
+
+    protected String getBaseUri() {
+        return server.getRootUrl();
+    }
+    
+    @Test(groups="Integration")
+    public void testServiceMirroring() throws Exception {
+        setUpServer();
+        
+        serverApp.setAttribute(TestApplication.MY_ATTRIBUTE, "austria");
+
+        String serviceId = serverApp.getId();
+        Entity mirror = localApp.addChild(EntitySpec.create(BrooklynEntityMirror.class)
+            .configure(BrooklynEntityMirror.POLL_PERIOD, Duration.millis(100))
+            .configure(BrooklynEntityMirror.MIRRORED_ENTITY_ID, serviceId)
+            .configure(BrooklynEntityMirror.MIRRORED_ENTITY_URL, 
+                getBaseUri()+"/v1/applications/"+serviceId+"/entities/"+serviceId)
+        );
+
+        EntityTestUtils.assertAttributeEqualsEventually(mirror, TestApplication.MY_ATTRIBUTE, "austria");
+        log.info("Sensors mirrored are: "+((EntityInternal)mirror).getAllAttributes());
+        
+        serverApp.setAttribute(TestApplication.MY_ATTRIBUTE, "bermuda");
+        EntityTestUtils.assertAttributeEqualsEventually(mirror, TestApplication.MY_ATTRIBUTE, "bermuda");
+
+        serverApp.stop();
+        EntityTestUtils.assertAttributeEqualsEventually(mirror, Attributes.SERVICE_STATE, Lifecycle.ON_FIRE);
+    }
+
+    
+    @Test(groups="Integration")
+    public void testServiceMirroringHttps() throws Exception {
+        LocalManagementContextForTests mgmtHttps = new LocalManagementContextForTests();
+        mgmtHttps.getBrooklynProperties().put("brooklyn.webconsole.security.https.required", true);
+        mgmtHttps.getBrooklynProperties().put("brooklyn.webconsole.security.users", "admin");
+        mgmtHttps.getBrooklynProperties().put("brooklyn.webconsole.security.user.admin.password", "P5ssW0rd");
+
+        setUpServer(mgmtHttps, true);
+        Assert.assertTrue(getBaseUri().startsWith("https:"), "URL is not https: "+getBaseUri());
+        // check auth is required
+        HttpTestUtils.assertHttpStatusCodeEquals(getBaseUri(), 401);
+        
+        serverApp.setAttribute(TestApplication.MY_ATTRIBUTE, "austria");
+
+        String serviceId = serverApp.getId();
+        Entity mirror = localApp.addChild(EntitySpec.create(BrooklynEntityMirror.class)
+            .configure(BrooklynEntityMirror.POLL_PERIOD, Duration.millis(100))
+            .configure(BrooklynEntityMirror.MANAGEMENT_USER, "admin")
+            .configure(BrooklynEntityMirror.MANAGEMENT_PASSWORD, "P5ssW0rd")
+            .configure(BrooklynEntityMirror.MIRRORED_ENTITY_ID, serviceId)
+            .configure(BrooklynEntityMirror.MIRRORED_ENTITY_URL, 
+                getBaseUri()+"/v1/applications/"+serviceId+"/entities/"+serviceId)
+        );
+
+        EntityTestUtils.assertAttributeEqualsEventually(mirror, TestApplication.MY_ATTRIBUTE, "austria");
+        log.info("Sensors mirrored are: "+((EntityInternal)mirror).getAllAttributes());
+        
+        serverApp.setAttribute(TestApplication.MY_ATTRIBUTE, "bermuda");
+        EntityTestUtils.assertAttributeEqualsEventually(mirror, TestApplication.MY_ATTRIBUTE, "bermuda");
+
+        serverApp.stop();
+        EntityTestUtils.assertAttributeEqualsEventually(mirror, Attributes.SERVICE_STATE, Lifecycle.ON_FIRE);
+    }
+
+}