[NO ISSUE][OTR] Dynamically Determine Default Config File

- user model changes: no
- storage format changes: no
- interface changes: no

Details:
- Dynamically determine default config file
  in AsterixHyracksIntegrationUtil.
- Use Log4j2 as JUL LogManager.

Change-Id: I56a596bec63b4347a1db6660c4d57fc662fff0fc
Reviewed-on: https://asterix-gerrit.ics.uci.edu/2239
Sonar-Qube: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Integration-Tests: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Tested-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Contrib: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Reviewed-by: Till Westmann <tillw@apache.org>
diff --git a/asterixdb/asterix-app/pom.xml b/asterixdb/asterix-app/pom.xml
index 0785056..2ca748f 100644
--- a/asterixdb/asterix-app/pom.xml
+++ b/asterixdb/asterix-app/pom.xml
@@ -578,5 +578,10 @@
       <groupId>org.apache.logging.log4j</groupId>
       <artifactId>log4j-core</artifactId>
     </dependency>
+    <dependency>
+      <groupId>org.apache.logging.log4j</groupId>
+      <artifactId>log4j-jul</artifactId>
+      <version>2.10.0</version>
+    </dependency>
   </dependencies>
 </project>
diff --git a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/common/AsterixHyracksIntegrationUtil.java b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/common/AsterixHyracksIntegrationUtil.java
index 54dc064..97079eb 100644
--- a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/common/AsterixHyracksIntegrationUtil.java
+++ b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/common/AsterixHyracksIntegrationUtil.java
@@ -24,8 +24,14 @@
 import java.io.File;
 import java.io.IOException;
 import java.net.Inet4Address;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.nio.file.attribute.BasicFileAttributes;
 import java.util.ArrayList;
 import java.util.List;
+import java.util.function.BiPredicate;
+import java.util.stream.Stream;
 
 import org.apache.asterix.app.external.ExternalUDFLibrarian;
 import org.apache.asterix.common.api.IClusterManagementWork.ClusterState;
@@ -54,15 +60,20 @@
 import org.apache.logging.log4j.Logger;
 import org.kohsuke.args4j.CmdLineException;
 
-@SuppressWarnings({"squid:ClassVariableVisibilityCheck","squid:S00112"})
+@SuppressWarnings({ "squid:ClassVariableVisibilityCheck", "squid:S00112" })
 public class AsterixHyracksIntegrationUtil {
 
     public static final int DEFAULT_HYRACKS_CC_CLIENT_PORT = 1098;
     public static final int DEFAULT_HYRACKS_CC_CLUSTER_PORT = 1099;
-    public static final String DEFAULT_CONF_FILE = joinPath("asterixdb", "asterix-app", "src", "test", "resources",
+    public static final String DEFAULT_CONF_FILE = joinPath(getProjectPath().toString(), "src", "test", "resources",
             "cc.conf");
     private static final String DEFAULT_STORAGE_PATH = joinPath("target", "io", "dir");
     private static String storagePath = DEFAULT_STORAGE_PATH;
+
+    static {
+        System.setProperty("java.util.logging.manager", org.apache.logging.log4j.jul.LogManager.class.getName());
+    }
+
     public ClusterControllerService cc;
     public NodeControllerService[] ncs = new NodeControllerService[2];
     public IHyracksClientConnection hcc;
@@ -83,8 +94,7 @@
      * main method to run a simple 2 node cluster in-process
      * suggested VM arguments: <code>-enableassertions -Xmx2048m -Dfile.encoding=UTF-8</code>
      *
-     * @param args
-     *            unused
+     * @param args unused
      */
     public static void main(String[] args) throws Exception {
         AsterixHyracksIntegrationUtil integrationUtil = new AsterixHyracksIntegrationUtil();
@@ -125,9 +135,9 @@
                 ncConfigManager = new ConfigManager(new String[] { "-config-file", confFile });
             }
             ncApplication.registerConfig(ncConfigManager);
-            nodeControllers.add(
-                    new NodeControllerService(fixupIODevices(createNCConfig(nodeId, ncConfigManager)), ncApplication));
-        } ;
+            nodeControllers.add(new NodeControllerService(fixupIODevices(createNCConfig(nodeId, ncConfigManager)),
+                    ncApplication));
+        }
 
         opts.stream().forEach(opt -> configManager.set(opt.getLeft(), opt.getRight()));
         cc.start();
@@ -347,6 +357,21 @@
         opts.add(Pair.of(name, value));
     }
 
+    /**
+     * @return the asterix-app absolute path if found, otherwise the default user path.
+     */
+    private static Path getProjectPath() {
+        final String targetDir = "asterix-app";
+        final BiPredicate<Path, BasicFileAttributes> matcher =
+                (path, attributes) -> path.getFileName().toString().equals(targetDir) && path.toFile().isDirectory();
+        final Path currentPath = Paths.get(System.getProperty("user.dir"));
+        try (Stream<Path> pathStream = Files.find(currentPath, 10, matcher)) {
+            return pathStream.findFirst().orElse(currentPath);
+        } catch (IOException e) {
+            throw new IllegalStateException(e);
+        }
+    }
+
     static class LoggerHolder {
         static final Logger LOGGER = LogManager.getLogger();