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:26 UTC
[2/2] git commit: rat fix,
and add one more (overlooked previously) integration test for
BrooklynEntityMirror
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);
+ }
+
+}