ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jonathanhur...@apache.org
Subject [14/17] ambari git commit: AMBARI-21020. Support external story locations in Log Search IT framework (oleewere)
Date Tue, 16 May 2017 17:15:24 GMT
AMBARI-21020. Support external story locations in Log Search IT framework (oleewere)


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

Branch: refs/heads/branch-feature-AMBARI-12556
Commit: e54252c829f674919d51d38c33689cce7a17e075
Parents: 38cc334
Author: oleewere <oleewere@gmail.com>
Authored: Mon May 15 12:12:36 2017 +0200
Committer: oleewere <oleewere@gmail.com>
Committed: Tue May 16 11:46:18 2017 +0200

----------------------------------------------------------------------
 ambari-logsearch/README.md                      |  1 +
 ambari-logsearch/ambari-logsearch-it/pom.xml    |  6 ++
 .../story/LogSearchBackendStories.java          | 19 +---
 .../logsearch/story/LogSearchStoryLocator.java  | 97 ++++++++++++++++++++
 .../logsearch/story/LogSearchUIStories.java     | 10 +-
 5 files changed, 114 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/e54252c8/ambari-logsearch/README.md
----------------------------------------------------------------------
diff --git a/ambari-logsearch/README.md b/ambari-logsearch/README.md
index 92b98f9..d05f45a 100644
--- a/ambari-logsearch/README.md
+++ b/ambari-logsearch/README.md
@@ -45,5 +45,6 @@ mvn clean integration-test -Dbackend-tests failsafe:verify
 xquartz
 # then in an another window you can start ui tests
 mvn clean integration-test -Dselenium-tests failsafe:verify
+# you can specify story file folde location with -Dbackend.stories.location and -Dui.stories.location
(absolute file path) in the commands
 ```
 Also you can run from the IDE, but make sure all of the ambari logsearch modules are built.

http://git-wip-us.apache.org/repos/asf/ambari/blob/e54252c8/ambari-logsearch/ambari-logsearch-it/pom.xml
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-it/pom.xml b/ambari-logsearch/ambari-logsearch-it/pom.xml
index 0058c80..81af9e8 100644
--- a/ambari-logsearch/ambari-logsearch-it/pom.xml
+++ b/ambari-logsearch/ambari-logsearch-it/pom.xml
@@ -39,6 +39,8 @@
     <failsafe-plugin.version>2.20</failsafe-plugin.version>
     <forkCount>1</forkCount>
     <docker.host>localhost</docker.host>
+    <backend.stories.location>NONE</backend.stories.location>
+    <ui.stories.location>NONE</ui.stories.location>
   </properties>
 
   <dependencies>
@@ -162,6 +164,7 @@
                   <systemPropertyVariables>
                     <log4j.configuration>file:${project.build.testOutputDirectory}/log4j.properties</log4j.configuration>
                     <docker.host>${docker.host}</docker.host>
+                    <ui.stories.location>${ui.stories.location}</ui.stories.location>
                   </systemPropertyVariables>
                 </configuration>
               </execution>
@@ -204,6 +207,7 @@
                   <systemPropertyVariables>
                     <log4j.configuration>file:${project.build.testOutputDirectory}/log4j.properties</log4j.configuration>
                     <docker.host>${docker.host}</docker.host>
+                    <backend.stories.location>${backend.stories.location}</backend.stories.location>
                   </systemPropertyVariables>
                 </configuration>
               </execution>
@@ -246,6 +250,8 @@
                   <systemPropertyVariables>
                     <log4j.configuration>file:${project.build.testOutputDirectory}/log4j.properties</log4j.configuration>
                     <docker.host>${docker.host}</docker.host>
+                    <backend.stories.location>${backend.stories.location}</backend.stories.location>
+                    <ui.stories.location>${ui.stories.location}</ui.stories.location>
                   </systemPropertyVariables>
                 </configuration>
               </execution>

http://git-wip-us.apache.org/repos/asf/ambari/blob/e54252c8/ambari-logsearch/ambari-logsearch-it/src/test/java/org/apache/ambari/logsearch/story/LogSearchBackendStories.java
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-it/src/test/java/org/apache/ambari/logsearch/story/LogSearchBackendStories.java
b/ambari-logsearch/ambari-logsearch-it/src/test/java/org/apache/ambari/logsearch/story/LogSearchBackendStories.java
index 46f2928..fa7a527 100644
--- a/ambari-logsearch/ambari-logsearch-it/src/test/java/org/apache/ambari/logsearch/story/LogSearchBackendStories.java
+++ b/ambari-logsearch/ambari-logsearch-it/src/test/java/org/apache/ambari/logsearch/story/LogSearchBackendStories.java
@@ -18,7 +18,6 @@
  */
 package org.apache.ambari.logsearch.story;
 
-import com.google.common.base.Function;
 import com.google.common.base.Predicate;
 import com.google.common.collect.Collections2;
 import com.google.common.collect.Lists;
@@ -27,31 +26,24 @@ import org.apache.ambari.logsearch.steps.SolrSteps;
 import org.apache.ambari.logsearch.steps.LogSearchDockerSteps;
 import org.jbehave.core.configuration.Configuration;
 import org.jbehave.core.configuration.MostUsefulConfiguration;
-import org.jbehave.core.embedder.executors.SameThreadExecutors;
-import org.jbehave.core.io.LoadFromClasspath;
-import org.jbehave.core.io.StoryFinder;
-import org.jbehave.core.io.StoryPathResolver;
-import org.jbehave.core.io.UnderscoredCamelCaseResolver;
 import org.jbehave.core.junit.JUnitStories;
-import org.jbehave.core.junit.JUnitStory;
 import org.jbehave.core.reporters.Format;
 import org.jbehave.core.reporters.StoryReporterBuilder;
 import org.jbehave.core.steps.InjectableStepsFactory;
 import org.jbehave.core.steps.InstanceStepsFactory;
 import org.junit.Test;
 
-import javax.annotation.Nullable;
-import java.util.Arrays;
 import java.util.List;
 
-import static org.jbehave.core.io.CodeLocations.codeLocationFromClass;
-
 public class LogSearchBackendStories extends JUnitStories {
 
+  private static final String BACKEND_STORIES_LOCATION_PROPERTY = "backend.stories.location";
+  private static final String STORY_SUFFIX = ".story";
+
   @Override
   public Configuration configuration() {
     return new MostUsefulConfiguration()
-      .useStoryLoader(new LoadFromClasspath(this.getClass()))
+      .useStoryLoader(LogSearchStoryLocator.getStoryLoader(BACKEND_STORIES_LOCATION_PROPERTY,
this.getClass()))
       .useStoryReporterBuilder(
         new StoryReporterBuilder().withFailureTrace(true).withDefaultFormats().withFormats(Format.CONSOLE,
Format.TXT));
   }
@@ -71,8 +63,7 @@ public class LogSearchBackendStories extends JUnitStories {
 
   @Override
   protected List<String> storyPaths() {
-    List<String> backendStories = new StoryFinder()
-      .findPaths(codeLocationFromClass(this.getClass()).getFile(), Arrays.asList("**/*.story"),
null);
+    List<String> backendStories = LogSearchStoryLocator.findStories(BACKEND_STORIES_LOCATION_PROPERTY,
STORY_SUFFIX, this.getClass());
     return Lists.newArrayList(Collections2.filter(backendStories, new Predicate<String>()
{
       @Override
       public boolean apply(String storyFileName) {

http://git-wip-us.apache.org/repos/asf/ambari/blob/e54252c8/ambari-logsearch/ambari-logsearch-it/src/test/java/org/apache/ambari/logsearch/story/LogSearchStoryLocator.java
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-it/src/test/java/org/apache/ambari/logsearch/story/LogSearchStoryLocator.java
b/ambari-logsearch/ambari-logsearch-it/src/test/java/org/apache/ambari/logsearch/story/LogSearchStoryLocator.java
new file mode 100644
index 0000000..bed7999
--- /dev/null
+++ b/ambari-logsearch/ambari-logsearch-it/src/test/java/org/apache/ambari/logsearch/story/LogSearchStoryLocator.java
@@ -0,0 +1,97 @@
+/*
+ * 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.ambari.logsearch.story;
+
+import com.google.common.collect.Lists;
+import org.apache.commons.lang.StringUtils;
+import org.jbehave.core.io.LoadFromClasspath;
+import org.jbehave.core.io.LoadFromRelativeFile;
+import org.jbehave.core.io.StoryFinder;
+import org.jbehave.core.io.StoryLoader;
+
+import java.io.File;
+import java.net.URL;
+import java.util.Arrays;
+import java.util.List;
+
+import static org.jbehave.core.io.CodeLocations.codeLocationFromClass;
+
+/**
+ * Helper class for loading story files from the classpath or externally - based on system
properties
+ */
+public class LogSearchStoryLocator {
+
+  private LogSearchStoryLocator() {
+  }
+
+  /**
+   * Get the proper story loader based on story location property (if empty or NONE - use
story loading from classpath)
+   * @param property Story location property (absolute path - folder)
+   * @param clazz Class of the *Stories object
+   */
+  public static StoryLoader getStoryLoader(String property, Class clazz) {
+    boolean useExternalStoryLocation = useExternalStoryLocation(property);
+    if (useExternalStoryLocation) {
+      try {
+        return new LoadFromRelativeFile(new URL("file://" + System.getProperty(property)));
+      } catch (Exception e) {
+        throw new RuntimeException("Cannot load story files from url: file://" + System.getProperty(property));
+      }
+    } else {
+      return new LoadFromClasspath(clazz);
+    }
+  }
+
+
+  /**
+   * Find stories based on story location property, if the property is not set or NONE, then
the story files will be loaded from the classpath
+   * @param property Story location property (absolute path - folder)
+   * @param suffix Story suffix for specific stories - i.e. : .ui.story
+   * @param clazz Class of the *Stories object
+   */
+  public static List<String> findStories(String property, String suffix, Class clazz)
{
+    List<String> stories = null;
+    if (useExternalStoryLocation(property)) {
+      stories = findStoriesInFolder(System.getProperty(property), suffix);
+    } else {
+      stories = new StoryFinder()
+        .findPaths(codeLocationFromClass(clazz).getFile(), Arrays.asList(String.format("**/*%s",
suffix)), null);
+    }
+    return stories;
+  }
+
+  private static List<String> findStoriesInFolder(String folderAbsolutePath, String
suffix) {
+    List<String> results = Lists.newArrayList();
+    File folder = new File(folderAbsolutePath);
+    File[] listOfFiles = folder.listFiles();
+    if (listOfFiles != null) {
+      for (File file : listOfFiles) {
+        if (file.getName().endsWith(suffix)) {
+          results.add(file.getName());
+        }
+      }
+    }
+    return results;
+  }
+
+  private static boolean useExternalStoryLocation(String property) {
+    String storyLocationProp = System.getProperty(property);
+    return StringUtils.isNotEmpty(storyLocationProp) && !"NONE".equals(storyLocationProp);
+  }
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/e54252c8/ambari-logsearch/ambari-logsearch-it/src/test/java/org/apache/ambari/logsearch/story/LogSearchUIStories.java
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-it/src/test/java/org/apache/ambari/logsearch/story/LogSearchUIStories.java
b/ambari-logsearch/ambari-logsearch-it/src/test/java/org/apache/ambari/logsearch/story/LogSearchUIStories.java
index 217c50f..5417ab1 100644
--- a/ambari-logsearch/ambari-logsearch-it/src/test/java/org/apache/ambari/logsearch/story/LogSearchUIStories.java
+++ b/ambari-logsearch/ambari-logsearch-it/src/test/java/org/apache/ambari/logsearch/story/LogSearchUIStories.java
@@ -24,8 +24,6 @@ import org.apache.ambari.logsearch.steps.LogSearchUISteps;
 import org.jbehave.core.configuration.Configuration;
 import org.jbehave.core.Embeddable;
 import org.jbehave.core.embedder.executors.SameThreadExecutors;
-import org.jbehave.core.io.LoadFromClasspath;
-import org.jbehave.core.io.StoryFinder;
 import org.jbehave.core.junit.JUnitStories;
 import org.jbehave.core.reporters.StoryReporterBuilder;
 import org.jbehave.core.steps.InjectableStepsFactory;
@@ -52,6 +50,9 @@ public class LogSearchUIStories extends JUnitStories {
   private WebDriverProvider driverProvider;
   private SeleniumContext context;
 
+  private static final String UI_STORIES_LOCATION_PROPERTY = "ui.stories.location";
+  private static final String STORY_SUFFIX = ".ui.story";
+
   public LogSearchUIStories() {
     String dockerHost = System.getProperty("docker.host") != null ? System.getProperty("docker.host")
: "localhost";
     System.setProperty("REMOTE_WEBDRIVER_URL", String.format("http://%s:4444/wd/hub", dockerHost));
@@ -70,7 +71,7 @@ public class LogSearchUIStories extends JUnitStories {
     return new SeleniumConfiguration()
       .useSeleniumContext(context)
       .useWebDriverProvider(driverProvider)
-      .useStoryLoader(new LoadFromClasspath(embeddableClass))
+      .useStoryLoader(LogSearchStoryLocator.getStoryLoader(UI_STORIES_LOCATION_PROPERTY,
this.getClass()))
       .useStoryReporterBuilder(new StoryReporterBuilder()
         .withCodeLocation(codeLocationFromClass(embeddableClass))
         .withDefaultFormats()
@@ -86,7 +87,6 @@ public class LogSearchUIStories extends JUnitStories {
 
   @Override
   protected List<String> storyPaths() {
-    return new StoryFinder()
-      .findPaths(codeLocationFromClass(this.getClass()).getFile(), Arrays.asList("**/*.ui.story"),
null);
+    return LogSearchStoryLocator.findStories(UI_STORIES_LOCATION_PROPERTY, STORY_SUFFIX,
this.getClass());
   }
 }


Mime
View raw message