geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kl...@apache.org
Subject geode git commit: Remove Attach API usage from AbstractLauncher and LauncherLifecycleCommands
Date Wed, 08 Mar 2017 21:59:06 GMT
Repository: geode
Updated Branches:
  refs/heads/feature/GEODE-2594 a0716a57b -> 902cbe79e


Remove Attach API usage from AbstractLauncher and LauncherLifecycleCommands


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

Branch: refs/heads/feature/GEODE-2594
Commit: 902cbe79ee71dd7c4810548958fff91dff48ab4f
Parents: a0716a5
Author: Kirk Lund <klund@apache.org>
Authored: Wed Mar 8 13:58:32 2017 -0800
Committer: Kirk Lund <klund@apache.org>
Committed: Wed Mar 8 13:58:32 2017 -0800

----------------------------------------------------------------------
 .../geode/distributed/AbstractLauncher.java     | 57 ++-----------------
 .../cli/commands/LauncherLifecycleCommands.java | 59 +-------------------
 .../geode/distributed/AbstractLauncherTest.java | 34 +++--------
 3 files changed, 17 insertions(+), 133 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/geode/blob/902cbe79/geode-core/src/main/java/org/apache/geode/distributed/AbstractLauncher.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/distributed/AbstractLauncher.java b/geode-core/src/main/java/org/apache/geode/distributed/AbstractLauncher.java
index 64e20f3..a307b9c 100644
--- a/geode-core/src/main/java/org/apache/geode/distributed/AbstractLauncher.java
+++ b/geode-core/src/main/java/org/apache/geode/distributed/AbstractLauncher.java
@@ -37,14 +37,11 @@ import org.apache.geode.management.internal.cli.json.GfJsonObject;
 import java.io.File;
 import java.io.FileReader;
 import java.io.IOException;
-import java.io.PrintWriter;
-import java.io.StringWriter;
 import java.net.BindException;
 import java.net.InetAddress;
 import java.net.URL;
 import java.sql.Timestamp;
 import java.text.SimpleDateFormat;
-import java.util.Arrays;
 import java.util.Collections;
 import java.util.Date;
 import java.util.HashMap;
@@ -72,31 +69,21 @@ public abstract class AbstractLauncher<T extends Comparable<T>>
implements Runna
 
   protected static final long READ_PID_FILE_TIMEOUT_MILLIS = 2 * 1000;
 
-  // @see
-  // http://publib.boulder.ibm.com/infocenter/javasdk/v6r0/index.jsp?topic=%2Fcom.ibm.java.doc.user.lnx.60%2Fuser%2Fattachapi.html
-  // @see
-  // http://docs.oracle.com/cd/E13150_01/jrockit_jvm/jrockit/geninfo/diagnos/aboutjrockit.html#wp1083571
-  private static final List<String> ATTACH_API_PACKAGES = Arrays.asList("com.sun.tools.attach",
-      "com/sun/tools/attach", "com.ibm.tools.attach", "com/ibm/tools/attach");
-
   public static final String DEFAULT_WORKING_DIRECTORY = SystemUtils.CURRENT_DIRECTORY;
+
   public static final String SIGNAL_HANDLER_REGISTRATION_SYSTEM_PROPERTY =
       DistributionConfig.GEMFIRE_PREFIX + "launcher.registerSignalHandlers";
 
   protected static final String OPTION_PREFIX = "-";
 
-  private static final String IBM_ATTACH_API_CLASS_NAME =
-      "com.ibm.tools.attach.AgentNotSupportedException";
-  private static final String SUN_ATTACH_API_CLASS_NAME =
-      "com.sun.tools.attach.AttachNotSupportedException";
   private static final String SUN_SIGNAL_API_CLASS_NAME = "sun.misc.Signal";
 
   private volatile boolean debug;
 
   protected final transient AtomicBoolean running = new AtomicBoolean(false);
 
-  protected Logger logger = Logger.getLogger(getClass().getName()); // TODO:KIRK: does this
need
-  // log4j2?
+  // TODO: use log4j instead of JUL
+  protected Logger logger = Logger.getLogger(getClass().getName());
 
   public AbstractLauncher() {
     try {
@@ -203,43 +190,11 @@ public abstract class AbstractLauncher<T extends Comparable<T>>
implements Runna
    * @param t the Throwable being evaluated for missing Attach API classes.
    * @return a boolean indicating whether the Exception or Error condition is a result of
the Attach
    *         API missing from the classpath.
+   * @deprecated Attach API is no longer supported and isAttachAPINotFound will throw
+   *             UnsupportedOperationException
    */
   protected boolean isAttachAPINotFound(final Throwable t) {
-    boolean missing = false;
-
-    // NOTE prerequisite, Throwable must be a ClassNotFoundException or NoClassDefFoundError
-    if (t instanceof ClassNotFoundException || t instanceof NoClassDefFoundError) {
-      // NOTE the use of the 'testing' class member variable, yuck!
-      if (!isAttachAPIOnClasspath()) {
-        // NOTE ok, the Attach API is not available, however we still do not know whether
an user
-        // application class
-        // caused the ClassNotFoundException or NoClassDefFoundError.
-        final StringWriter stackTraceWriter = new StringWriter();
-
-        // NOTE the full stack trace includes the Throwable message, which typically indicates
the
-        // Exception/Error
-        // thrown and the reason (as in which class was not found).
-        t.printStackTrace(new PrintWriter(stackTraceWriter));
-
-        final String stackTrace = stackTraceWriter.toString();
-
-        for (String attachApiPackage : ATTACH_API_PACKAGES) {
-          missing |= stackTrace.contains(attachApiPackage);
-        }
-      }
-    }
-
-    return missing;
-  }
-
-  /**
-   * Determines if the Attach API is on the classpath.
-   *
-   * @return a boolean value indicating if the Attach API is on the classpath.
-   */
-  boolean isAttachAPIOnClasspath() {
-    return (ClassUtils.isClassAvailable(SUN_ATTACH_API_CLASS_NAME)
-        || ClassUtils.isClassAvailable(IBM_ATTACH_API_CLASS_NAME));
+    throw new UnsupportedOperationException("Attach API is no longer supported");
   }
 
   /**

http://git-wip-us.apache.org/repos/asf/geode/blob/902cbe79/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/LauncherLifecycleCommands.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/LauncherLifecycleCommands.java
b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/LauncherLifecycleCommands.java
index e677ba3..243823e 100755
--- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/LauncherLifecycleCommands.java
+++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/LauncherLifecycleCommands.java
@@ -58,7 +58,6 @@ import org.apache.geode.internal.GemFireVersion;
 import org.apache.geode.internal.OSProcess;
 import org.apache.geode.internal.cache.persistence.PersistentMemberPattern;
 import org.apache.geode.internal.i18n.LocalizedStrings;
-import org.apache.geode.internal.lang.ClassUtils;
 import org.apache.geode.internal.lang.ObjectUtils;
 import org.apache.geode.internal.lang.StringUtils;
 import org.apache.geode.internal.lang.SystemUtils;
@@ -74,7 +73,6 @@ import org.apache.geode.internal.process.signal.SignalEvent;
 import org.apache.geode.internal.process.signal.SignalListener;
 import org.apache.geode.internal.util.IOUtils;
 import org.apache.geode.internal.util.StopWatch;
-import org.apache.geode.lang.AttachAPINotFoundException;
 import org.apache.geode.management.DistributedSystemMXBean;
 import org.apache.geode.management.MemberMXBean;
 import org.apache.geode.management.cli.CliMetaData;
@@ -169,11 +167,6 @@ public class LauncherLifecycleCommands extends AbstractCommandsSupport
{
   protected static final int MINIMUM_HEAP_FREE_RATIO = 10;
   protected static final int NUM_ATTEMPTS_FOR_SHARED_CONFIGURATION_STATUS = 3;
 
-  protected static final AtomicReference<Boolean> ATTACH_API_AVAILABLE =
-      new AtomicReference<>(null);
-
-  protected static final String ATTACH_API_CLASS_NAME =
-      "com.sun.tools.attach.AttachNotSupportedException";
   protected static final String GEODE_HOME = System.getenv("GEODE_HOME");
   protected static final String JAVA_HOME = System.getProperty("java.home");
   protected static final String LOCALHOST = "localhost";
@@ -185,19 +178,6 @@ public class LauncherLifecycleCommands extends AbstractCommandsSupport
{
   protected static final String CORE_DEPENDENCIES_JAR_PATHNAME =
       IOUtils.appendToPath(GEODE_HOME, "lib", "geode-dependencies.jar");
 
-  protected static boolean isAttachApiAvailable() {
-    if (ATTACH_API_AVAILABLE.get() == null) {
-      try {
-        ClassUtils.forName(ATTACH_API_CLASS_NAME, new AttachAPINotFoundException());
-        ATTACH_API_AVAILABLE.set(Boolean.TRUE);
-      } catch (AttachAPINotFoundException ignore) {
-        ATTACH_API_AVAILABLE.set(Boolean.FALSE);
-      }
-    }
-
-    return ATTACH_API_AVAILABLE.get();
-  }
-
   private final ThreePhraseGenerator nameGenerator;
 
   public LauncherLifecycleCommands() {
@@ -424,9 +404,7 @@ public class LauncherLifecycleCommands extends AbstractCommandsSupport
{
               TimeUnit.MILLISECONDS.timedWait(this, 500);
             }
 
-            locatorState = (ProcessUtils.isAttachApiAvailable()
-                ? locatorStatus(locatorPidFile, oldPid, memberName)
-                : locatorStatus(workingDirectory, memberName));
+            locatorState = locatorStatus(workingDirectory, memberName);
 
             String currentLocatorStatusMessage = locatorState.getStatusMessage();
 
@@ -1222,29 +1200,6 @@ public class LauncherLifecycleCommands extends AbstractCommandsSupport
{
     return new File(new File(JAVA_HOME, "bin"), "java").getPath();
   }
 
-  @Deprecated
-  protected String getToolsJarPath() throws AttachAPINotFoundException {
-    String toolsJarPathname = null;
-
-    if (!SystemUtils.isMacOSX()) {
-      toolsJarPathname = IOUtils.appendToPath(JAVA_HOME, "lib", "tools.jar");
-
-      if (!IOUtils.isExistingPathname(toolsJarPathname)) {
-        // perhaps the java.home System property refers to the JRE ($JAVA_HOME/jre)...
-        String JDK_HOME = new File(JAVA_HOME).getParentFile().getPath();
-        toolsJarPathname = IOUtils.appendToPath(JDK_HOME, "lib", "tools.jar");
-      }
-
-      try {
-        IOUtils.verifyPathnameExists(toolsJarPathname);
-      } catch (IOException e) {
-        throw new AttachAPINotFoundException(getAttachAPINotFoundMessage());
-      }
-    }
-
-    return toolsJarPathname;
-  }
-
   // TODO refactor the following method into a common base class or utility class
   protected String getLocalHost() {
     try {
@@ -1254,11 +1209,6 @@ public class LauncherLifecycleCommands extends AbstractCommandsSupport
{
     }
   }
 
-  protected String getAttachAPINotFoundMessage() {
-    return CliStrings.format(CliStrings.ATTACH_API_IN_0_NOT_FOUND_ERROR_MESSAGE,
-        ((SystemUtils.isMacOSX() && SystemUtils.isAppleJVM()) ? "classes.jar" : "tools.jar"));
-  }
-
   protected String getLocatorId(final String host, final Integer port) {
     final String locatorHost = (host != null ? host : getLocalHost());
     final String locatorPort =
@@ -1347,8 +1297,7 @@ public class LauncherLifecycleCommands extends AbstractCommandsSupport
{
   }
 
   protected boolean isVmWithProcessIdRunning(final Integer pid) {
-    // note: this will use JNA if available or Attach if available or return false if neither
is
-    // available
+    // note: this will use JNA if available or return false
     return ProcessUtils.isProcessAlive(pid);
   }
 
@@ -1717,9 +1666,7 @@ public class LauncherLifecycleCommands extends AbstractCommandsSupport
{
               TimeUnit.MILLISECONDS.timedWait(this, 500);
             }
 
-            serverState = (ProcessUtils.isAttachApiAvailable()
-                ? serverStatus(serverPidFile, oldPid, memberName)
-                : serverStatus(workingDirectory, memberName));
+            serverState = serverStatus(workingDirectory, memberName);
 
             String currentServerStatusMessage = serverState.getStatusMessage();
 

http://git-wip-us.apache.org/repos/asf/geode/blob/902cbe79/geode-core/src/test/java/org/apache/geode/distributed/AbstractLauncherTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/distributed/AbstractLauncherTest.java
b/geode-core/src/test/java/org/apache/geode/distributed/AbstractLauncherTest.java
index f487df9..eaa88f1 100644
--- a/geode-core/src/test/java/org/apache/geode/distributed/AbstractLauncherTest.java
+++ b/geode-core/src/test/java/org/apache/geode/distributed/AbstractLauncherTest.java
@@ -14,6 +14,10 @@
  */
 package org.apache.geode.distributed;
 
+import static org.apache.geode.distributed.ConfigurationProperties.*;
+import static org.assertj.core.api.Assertions.*;
+import static org.junit.Assert.*;
+
 import org.apache.geode.internal.lang.StringUtils;
 import org.apache.geode.test.junit.categories.UnitTest;
 import org.junit.Test;
@@ -24,9 +28,6 @@ import java.net.URL;
 import java.util.Properties;
 import java.util.concurrent.TimeUnit;
 
-import static org.junit.Assert.*;
-import static org.apache.geode.distributed.ConfigurationProperties.*;
-
 /**
  * The AbstractLauncherTest class is a test suite of unit tests testing the contract and
  * functionality of the AbstractLauncher class.
@@ -47,24 +48,10 @@ public class AbstractLauncherTest {
 
   @Test
   public void testIsAttachAPINotFound() {
-    final AbstractLauncher<?> launcher = createAbstractLauncher("012", "TestMember");
-
-    assertTrue(launcher.isAttachAPINotFound(new NoClassDefFoundError(
-        "Exception in thread \"main\" java.lang.NoClassDefFoundError: com/sun/tools/attach/AttachNotSupportedException")));
-    assertTrue(launcher.isAttachAPINotFound(new ClassNotFoundException(
-        "Caused by: java.lang.ClassNotFoundException: com.sun.tools.attach.AttachNotSupportedException")));
-    assertTrue(launcher.isAttachAPINotFound(new NoClassDefFoundError(
-        "Exception in thread \"main\" java.lang.NoClassDefFoundError: com/ibm/tools/attach/AgentNotSupportedException")));
-    assertTrue(launcher.isAttachAPINotFound(new ClassNotFoundException(
-        "Caused by: java.lang.ClassNotFoundException: com.ibm.tools.attach.AgentNotSupportedException")));
-    assertFalse(launcher.isAttachAPINotFound(new IllegalArgumentException(
-        "Caused by: java.lang.ClassNotFoundException: com.sun.tools.attach.AttachNotSupportedException")));
-    assertFalse(launcher.isAttachAPINotFound(new IllegalStateException(
-        "Caused by: java.lang.ClassNotFoundException: com.ibm.tools.attach.AgentNotSupportedException")));
-    assertFalse(launcher.isAttachAPINotFound(new NoClassDefFoundError(
-        "Exception in thread \"main\" java.lang.NoClassDefFoundError: com/companyx/app/service/MyServiceClass")));
-    assertFalse(launcher.isAttachAPINotFound(new ClassNotFoundException(
-        "Caused by: java.lang.ClassNotFoundException: com.companyx.app.attach.NutsNotAttachedException")));
+    AbstractLauncher<?> launcher = createAbstractLauncher("memberOne", "1");
+
+    assertThatThrownBy(() -> launcher.isAttachAPINotFound(null))
+      .isInstanceOf(UnsupportedOperationException.class);
   }
 
   @Test
@@ -282,11 +269,6 @@ public class AbstractLauncherTest {
     }
 
     @Override
-    boolean isAttachAPIOnClasspath() {
-      return false;
-    }
-
-    @Override
     public String getLogFileName() {
       throw new UnsupportedOperationException("Not Implemented!");
     }


Mime
View raw message