You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by al...@apache.org on 2015/10/21 00:17:53 UTC
[2/3] incubator-brooklyn git commit: Live test for openiptables
stdout/stderr - name refactoring
Live test for openiptables stdout/stderr - name refactoring
Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/bb92fad5
Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/bb92fad5
Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/bb92fad5
Branch: refs/heads/master
Commit: bb92fad5a574d68f1666d506aa0cd9172855a9e1
Parents: 892ff79
Author: Ivana Yovcheva <iv...@gmail.com>
Authored: Fri Oct 16 12:10:41 2015 +0300
Committer: Ivana Yovcheva <iv...@gmail.com>
Committed: Fri Oct 16 12:10:41 2015 +0300
----------------------------------------------------------------------
...twareProcessOpenIptablesStreamsLiveTest.java | 113 +++++++++++++++++++
1 file changed, 113 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/bb92fad5/software/base/src/test/java/org/apache/brooklyn/entity/software/base/SoftwareProcessOpenIptablesStreamsLiveTest.java
----------------------------------------------------------------------
diff --git a/software/base/src/test/java/org/apache/brooklyn/entity/software/base/SoftwareProcessOpenIptablesStreamsLiveTest.java b/software/base/src/test/java/org/apache/brooklyn/entity/software/base/SoftwareProcessOpenIptablesStreamsLiveTest.java
new file mode 100644
index 0000000..ae25aa8
--- /dev/null
+++ b/software/base/src/test/java/org/apache/brooklyn/entity/software/base/SoftwareProcessOpenIptablesStreamsLiveTest.java
@@ -0,0 +1,113 @@
+/*
+ * 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.entity.software.base;
+
+import com.google.common.base.Optional;
+import com.google.common.base.Predicate;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableMap;
+import org.apache.brooklyn.api.entity.EntitySpec;
+import org.apache.brooklyn.api.location.Location;
+import org.apache.brooklyn.api.mgmt.HasTaskChildren;
+import org.apache.brooklyn.api.mgmt.Task;
+import org.apache.brooklyn.core.entity.factory.ApplicationBuilder;
+import org.apache.brooklyn.core.internal.BrooklynProperties;
+import org.apache.brooklyn.core.mgmt.BrooklynTaskTags;
+import org.apache.brooklyn.core.test.BrooklynAppLiveTestSupport;
+import org.apache.brooklyn.core.test.entity.LocalManagementContextForTests;
+import org.apache.brooklyn.core.test.entity.TestApplication;
+import org.apache.brooklyn.util.core.task.TaskPredicates;
+import org.apache.brooklyn.util.text.StringPredicates;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+import java.util.Set;
+
+import static org.testng.Assert.assertNotEquals;
+
+public class SoftwareProcessOpenIptablesStreamsLiveTest extends BrooklynAppLiveTestSupport {
+
+ private static final Logger LOG = LoggerFactory.getLogger(SoftwareProcessOpenIptablesStreamsLiveTest.class);
+
+ protected BrooklynProperties brooklynProperties;
+
+ protected Location jcloudsLocation;
+
+ protected TestApplication app;
+
+ @BeforeMethod(alwaysRun=true)
+ public void setUp() throws Exception {
+
+ mgmt = new LocalManagementContextForTests(BrooklynProperties.Factory.newDefault());
+
+ jcloudsLocation = mgmt.getLocationRegistry().resolve("jclouds:aws-ec2:us-west-1", ImmutableMap.<String, Object>builder()
+ .put("osFamily", "centos")
+ .put("osVersionRegex", "6\\..*")
+ .put("inboundPorts", ImmutableList.of(22, 31880, 31001, 8080, 8443, 1099))
+ .build());
+
+ app = ApplicationBuilder.newManagedApp(newAppSpec(), mgmt);
+ }
+
+ @Test(groups = "Live")
+ public void testGetsStreams() {
+ EmptySoftwareProcess entity = app.createAndManageChild(EntitySpec.create(EmptySoftwareProcess.class)
+ .configure(EmptySoftwareProcess.OPEN_IPTABLES, true));
+
+ app.start(ImmutableList.of(jcloudsLocation));
+ assertStreams(entity);
+ }
+
+ private <T extends SoftwareProcess> void assertStreams(T softwareProcessEntity) {
+
+ Set<Task<?>> tasks = BrooklynTaskTags.getTasksInEntityContext(mgmt.getExecutionManager(), softwareProcessEntity);
+
+ Task<?> subTask = findTaskOrSubTask(tasks, TaskPredicates.displayNameMatches(StringPredicates.matchesRegex("open iptables.*"))).get();
+
+ String stdout = AbstractSoftwareProcessStreamsTest.getStreamOrFail(subTask, BrooklynTaskTags.STREAM_STDOUT);
+ String msg = "stdout="+stdout;
+
+ assertNotEquals(stdout, "", msg);
+ }
+
+ protected Optional<Task<?>> findTaskOrSubTask(Iterable<? extends Task<?>> tasks, Predicate<? super Task<?>> matcher) {
+ Optional<Task<?>> result = findTaskOrSubTaskImpl(tasks, matcher);
+ if (!result.isPresent() && LOG.isDebugEnabled()) {
+ LOG.debug("Task not found matching "+matcher);
+ }
+ return result;
+ }
+
+ protected Optional<Task<?>> findTaskOrSubTaskImpl(Iterable<? extends Task<?>> tasks, Predicate<? super Task<?>> matcher) {
+ for (Task<?> task : tasks) {
+ if (matcher.apply(task)) return Optional.<Task<?>>of(task);
+
+ if (!(task instanceof HasTaskChildren)) {
+ return Optional.absent();
+ } else {
+ Optional<Task<?>> subResult = findTaskOrSubTask(((HasTaskChildren) task).getChildren(), matcher);
+ if (subResult.isPresent()) return subResult;
+ }
+ }
+
+ return Optional.<Task<?>>absent();
+ }
+}