geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jensde...@apache.org
Subject incubator-geode git commit: GEODE-749: refactor the code to look for the war file in multiple places w/o version number and look for them in the classpath as well.
Date Thu, 21 Jan 2016 18:42:48 GMT
Repository: incubator-geode
Updated Branches:
  refs/heads/feature/GEODE-749 [created] c0c64de2e


GEODE-749: refactor the code to look for the war file in multiple places w/o version number
and look for them in the classpath as well.

Closes #73


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

Branch: refs/heads/feature/GEODE-749
Commit: c0c64de2e63a922ca4c22311381b1eea2ef4a6fb
Parents: 53e85e7
Author: Jinmei Liao <jiliao@pivotal.io>
Authored: Tue Jan 19 15:16:06 2016 -0800
Committer: Jens Deppe <jdeppe@pivotal.io>
Committed: Thu Jan 21 10:42:21 2016 -0800

----------------------------------------------------------------------
 gemfire-assembly/build.gradle                   |   1 +
 .../management/internal/AgentUtilJUnitTest.java |  24 ++--
 .../gemfire/management/internal/AgentUtil.java  | 110 ++++++++-----------
 .../management/internal/ManagementAgent.java    |  17 +--
 .../gemfire/management/internal/RestAgent.java  |   2 +-
 5 files changed, 61 insertions(+), 93 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/c0c64de2/gemfire-assembly/build.gradle
----------------------------------------------------------------------
diff --git a/gemfire-assembly/build.gradle b/gemfire-assembly/build.gradle
index 5930f13..7d40c83 100755
--- a/gemfire-assembly/build.gradle
+++ b/gemfire-assembly/build.gradle
@@ -293,6 +293,7 @@ def dependOnInstalledProduct = {
 // Add the configuration closure to the test targets so they depend on the install directory
 test dependOnInstalledProduct
 distributedTest dependOnInstalledProduct
+integrationTest dependOnInstalledProduct
 
 // Make build final task to generate all test and product resources
 build.dependsOn installDist

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/c0c64de2/gemfire-assembly/src/test/java/com/gemstone/gemfire/management/internal/AgentUtilJUnitTest.java
----------------------------------------------------------------------
diff --git a/gemfire-assembly/src/test/java/com/gemstone/gemfire/management/internal/AgentUtilJUnitTest.java
b/gemfire-assembly/src/test/java/com/gemstone/gemfire/management/internal/AgentUtilJUnitTest.java
index cd2c429..c404283 100644
--- a/gemfire-assembly/src/test/java/com/gemstone/gemfire/management/internal/AgentUtilJUnitTest.java
+++ b/gemfire-assembly/src/test/java/com/gemstone/gemfire/management/internal/AgentUtilJUnitTest.java
@@ -21,8 +21,12 @@ import com.gemstone.gemfire.test.junit.categories.IntegrationTest;
 
 import org.junit.Before;
 import org.junit.Ignore;
+import org.junit.Rule;
 import org.junit.Test;
+import org.junit.contrib.java.lang.system.ClearSystemProperties;
+import org.junit.contrib.java.lang.system.RestoreSystemProperties;
 import org.junit.experimental.categories.Category;
+import org.junit.rules.TestRule;
 
 import java.io.File;
 import java.io.FileInputStream;
@@ -47,15 +51,15 @@ public class AgentUtilJUnitTest {
 
   @Test
   public void testRESTApiExists() {
-    String gemFireWarLocation = agentUtil.getGemFireWebApiWarLocation();
-    assertNotNull(gemFireWarLocation, "GemFire REST API WAR File was not found");
+    String gemFireWarLocation = agentUtil.findWarLocation("gemfire-web-api");
+    assertNotNull("GemFire REST API WAR File was not found", gemFireWarLocation);
   }
 
   @Ignore("This test should be activated when pulse gets added to Geode")
   @Test
   public void testPulseWarExists() {
-    String gemFireWarLocation = agentUtil.getPulseWarLocation();
-    assertNotNull(gemFireWarLocation, "Pulse WAR File was not found");
+    String gemFireWarLocation = agentUtil.findWarLocation("gemfire-pulse");
+    assertNotNull("Pulse WAR File was not found", gemFireWarLocation);
   }
 
   private String getGemfireVersion() {
@@ -78,7 +82,7 @@ public class AgentUtilJUnitTest {
     if (inputStream != null) {
       try {
         prop.load(inputStream);
-        version = prop.getProperty("version");
+        version = prop.getProperty("versionNumber")+"-"+prop.getProperty("releaseType");
       } catch (FileNotFoundException e) {
       } catch (IOException e) {
       }
@@ -95,12 +99,8 @@ public class AgentUtilJUnitTest {
       return pathPrefix;
     }
 
-    String pathFromRoot = currentDirectoryPath.substring(gemfireCoreLocationIx);
-    int segmentsCount = pathFromRoot.split("/").length - 1;
-
-    for (int i = 0; i < segmentsCount; i++) {
-      pathPrefix = pathPrefix + "../";
-    }
-    return pathPrefix;
+    return currentDirectoryPath.substring(0, gemfireCoreLocationIx);
   }
+
+
 }

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/c0c64de2/gemfire-core/src/main/java/com/gemstone/gemfire/management/internal/AgentUtil.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/management/internal/AgentUtil.java
b/gemfire-core/src/main/java/com/gemstone/gemfire/management/internal/AgentUtil.java
index bb160ea..fcc078a 100644
--- a/gemfire-core/src/main/java/com/gemstone/gemfire/management/internal/AgentUtil.java
+++ b/gemfire-core/src/main/java/com/gemstone/gemfire/management/internal/AgentUtil.java
@@ -18,6 +18,7 @@
 package com.gemstone.gemfire.management.internal;
 
 import java.io.File;
+import java.net.URL;
 
 import org.apache.logging.log4j.Logger;
 
@@ -34,12 +35,7 @@ import com.gemstone.gemfire.internal.logging.LogService;
 public class AgentUtil {
 
   private static final Logger logger = LogService.getLogger();
-  private static final String TOOLS_WEB_API_WAR = "/tools/Extensions/gemfire-web-api-";
-  private static final String LIB_WEB_API_WAR = "/lib/gemfire-web-api-";
-  private static final String TOOLS_WEB_WAR = "/tools/Extensions/gemfire-web-";
-  private static final String LIB_WEB_WAR = "/lib/gemfire-web-";
-  private static final String TOOLS_PULSE_WAR = "/tools/Pulse/pulse.war";
-  private static final String LIB_PULSE_WAR = "/lib/pulse.war";
+
   public static final String ERROR_VARIABLE_NOT_SET = "The GEMFIRE environment variable must
be set!";
 
   private String gemfireVersion = null;
@@ -48,71 +44,53 @@ public class AgentUtil {
     this.gemfireVersion = gemfireVersion;
   }
 
-  public String getGemFireWebApiWarLocation() {
+  /**
+   * this method will try to find the named war files in the following order:
+   * 1. if GEMFIRE is defined, it will look under tools/Extensions, tools/Pulse and lib folder
(in this order) to find
+   *    either the name-version.war or the name.war file
+   * 2. If GEMFIRE is not defined, it will try to find either the name-version.war/name.war
(in that order) on the
+   *    classpath
+   *
+   * @param warFilePrefix : the prefix of the war file, e.g. gemfire-web, gemfire-pulse,
or gemfire-web-api
+   * @return
+     */
+  public String findWarLocation(String warFilePrefix) {
     String gemfireHome = getGemFireHome();
-    assert !StringUtils.isBlank(gemfireHome) : ERROR_VARIABLE_NOT_SET;
-
-    String toolsWebApiWar = gemfireHome + TOOLS_WEB_API_WAR + gemfireVersion + ".war";
-    String libWebApiWar = gemfireHome + LIB_WEB_API_WAR + gemfireVersion + ".war";
-
-    if (new File(toolsWebApiWar).isFile()) {
-      logger.info("GemFire Dev REST API war: {}", toolsWebApiWar);
-      return toolsWebApiWar;
-    } else if (new File(libWebApiWar).isFile()) {
-      logger.info("GemFire Dev REST API war: {}", libWebApiWar);
-      return libWebApiWar;
-    } else {
-      logger.warn("GemFire Dev REST API war not found - neither {} or {} exist", toolsWebApiWar,
libWebApiWar);
-      return null;
+    if(!StringUtils.isBlank(gemfireHome)) {
+      String[] possibleFiles = {
+              gemfireHome + "/tools/Extensions/" + warFilePrefix + "-" + gemfireVersion +
".war",
+              gemfireHome + "/tools/Pulse/" + warFilePrefix + "-" + gemfireVersion + ".war",
+              gemfireHome + "/lib/" + warFilePrefix + "-" + gemfireVersion + ".war",
+              gemfireHome + "/tools/Extensions/" + warFilePrefix + ".war",
+              gemfireHome + "/tools/Pulse/" + warFilePrefix + ".war",
+              gemfireHome + "/lib/" + warFilePrefix + ".war"
+      };
+      for (String possibleFile : possibleFiles) {
+        if (new File(possibleFile).isFile()) {
+          logger.info(warFilePrefix + " war found: {}", possibleFile);
+          return possibleFile;
+        }
+      }
     }
-  }
 
-  /*
-   * Use the GEMFIRE environment variable to find the GemFire product tree.
-   * First, look in the $GEMFIRE/tools/Management directory Second, look in the
-   * $GEMFIRE/lib directory Finally, if we cannot find Management WAR file then
-   * return null...
-   */
-  public String getGemFireWebWarLocation() {
-    String gemfireHome = getGemFireHome();
-    assert !StringUtils.isBlank(gemfireHome) : ERROR_VARIABLE_NOT_SET;
-
-    String toolsWebWar = gemfireHome + TOOLS_WEB_WAR + gemfireVersion + ".war";
-    String libWebWar = gemfireHome + LIB_WEB_WAR + gemfireVersion + ".war";
-
-    if (new File(toolsWebWar).isFile()) {
-      logger.info("GemFire Admin REST war: {}", toolsWebWar);
-      return toolsWebWar;
-    } else if (new File(libWebWar).isFile()) {
-      logger.info("GemFire Admin REST war: {}", libWebWar);
-      return libWebWar;
-    } else {
-      logger.warn("GemFire Admin REST war not found - neither {} or {} exist", toolsWebWar,
libWebWar);
-      return null;
+    // if $GEMFIRE is not set or we are not able to find it in all the possible locations
under $GEMFIRE, try to
+    // find in the classpath
+    String[] possibleFiles = {
+            warFilePrefix + "-" + gemfireVersion + ".war",
+            warFilePrefix + ".war"
+    };
+    for(String possibleFile:possibleFiles){
+      URL url = this.getClass().getClassLoader().getResource(possibleFile);
+      if(url!=null){
+        // found the war file
+        logger.info(warFilePrefix + " war found: {}", possibleFile);
+        return url.getPath();
+      }
     }
-  }
 
-  // Use the GEMFIRE environment variable to find the GemFire product tree.
-  // First, look in the $GEMFIRE/tools/Pulse directory
-  // Second, look in the $GEMFIRE/lib directory
-  // Finally, if we cannot find the Management WAR file then return null...
-  public String getPulseWarLocation() {
-    String gemfireHome = getGemFireHome();
-    assert !StringUtils.isBlank(gemfireHome) : ERROR_VARIABLE_NOT_SET;
-
-    String toolsPulseWar = gemfireHome + TOOLS_PULSE_WAR;
-    String libPulseWar = gemfireHome + LIB_PULSE_WAR;
-
-    if (new File(toolsPulseWar).isFile()) {
-      logger.info("GemFire Pulse war: {}", toolsPulseWar);
-      return toolsPulseWar;
-    } else if (new File(libPulseWar).isFile()) {
-      logger.info("GemFire Pulse war: {}", libPulseWar);
-      return libPulseWar;
-    } else {
-      logger.warn("GemFire Pulse war not found - neither {} or {} exist", toolsPulseWar,
libPulseWar);
-      return null;
-    }
+    // we still couldn't find the war file
+    logger.warn(warFilePrefix+" war file was not found");
+    return null;
   }
 
   public boolean isWebApplicationAvailable(final String warFileLocation) {

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/c0c64de2/gemfire-core/src/main/java/com/gemstone/gemfire/management/internal/ManagementAgent.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/management/internal/ManagementAgent.java
b/gemfire-core/src/main/java/com/gemstone/gemfire/management/internal/ManagementAgent.java
index 055c3a5..001e205 100755
--- a/gemfire-core/src/main/java/com/gemstone/gemfire/management/internal/ManagementAgent.java
+++ b/gemfire-core/src/main/java/com/gemstone/gemfire/management/internal/ManagementAgent.java
@@ -176,19 +176,8 @@ public class ManagementAgent {
             this.config.getHttpServicePort(), this.config.getHttpServiceBindAddress());
       }
 
-      // Check for empty variable. if empty, then log message and exit HTTP
-      // server startup
-      if (!agentUtil.isGemfireHomeDefined()) {
-        final String message = "GEMFIRE environment variable not set; HTTP service will not
start.";
-        setStatusMessage(managerBean, message);
-        if (logger.isDebugEnabled()) {
-          logger.debug(message);
-        }
-        return;
-      }
-
       // Find the Management WAR file
-      final String gemfireWar = agentUtil.getGemFireWebWarLocation();
+      final String gemfireWar = agentUtil.findWarLocation("gemfire-web");
       if (gemfireWar == null) {
         if (logger.isDebugEnabled()) {
           logger.debug("Unable to find GemFire Management REST API WAR file; the Management
REST Interface for GemFire will not be accessible.");
@@ -196,7 +185,7 @@ public class ManagementAgent {
       }
 
       // Find the Pulse WAR file
-      final String pulseWar = agentUtil.getPulseWarLocation();
+      final String pulseWar = agentUtil.findWarLocation("gemfire-pulse");
 
       if (pulseWar == null) {
         final String message = "Unable to find Pulse web application WAR file; Pulse for
GemFire will not be accessible";
@@ -207,7 +196,7 @@ public class ManagementAgent {
       }
 
       // Find developer REST WAR file
-      final String gemfireAPIWar = agentUtil.getGemFireWebApiWarLocation();
+      final String gemfireAPIWar = agentUtil.findWarLocation("gemfire-web-api");
       if (gemfireAPIWar == null) {
         final String message = "Unable to find GemFire Developer REST API WAR file; the Developer
REST Interface for GemFire will not be accessible.";
         setStatusMessage(managerBean, message);

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/c0c64de2/gemfire-core/src/main/java/com/gemstone/gemfire/management/internal/RestAgent.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/management/internal/RestAgent.java
b/gemfire-core/src/main/java/com/gemstone/gemfire/management/internal/RestAgent.java
index 2e9e03a..489ebf0 100755
--- a/gemfire-core/src/main/java/com/gemstone/gemfire/management/internal/RestAgent.java
+++ b/gemfire-core/src/main/java/com/gemstone/gemfire/management/internal/RestAgent.java
@@ -114,7 +114,7 @@ public class RestAgent {
         this.config.getHttpServicePort(), this.config.getHttpServiceBindAddress());
 
     // Find the developer REST WAR file
-    final String gemfireAPIWar = agentUtil.getGemFireWebApiWarLocation();
+    final String gemfireAPIWar = agentUtil.findWarLocation("gemfire-web-api");
     if (gemfireAPIWar == null) {
       logger.info("Unable to find GemFire Developer REST API WAR file; the Developer REST
Interface for GemFire will not be accessible.");
     }


Mime
View raw message