You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by dg...@apache.org on 2019/06/11 08:58:22 UTC
[ignite] branch master updated: IGNITE-10281 Log to file all jars
in classpath on start node - Fixes #6545.
This is an automated email from the ASF dual-hosted git repository.
dgovorukhin pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ignite.git
The following commit(s) were added to refs/heads/master by this push:
new d15ca45 IGNITE-10281 Log to file all jars in classpath on start node - Fixes #6545.
d15ca45 is described below
commit d15ca454c8c31a8a943282661bd84c4c4287045c
Author: denis-chudov <dc...@gridgain.com>
AuthorDate: Tue Jun 11 11:57:49 2019 +0300
IGNITE-10281 Log to file all jars in classpath on start node - Fixes #6545.
Signed-off-by: Dmitriy Govorukhin <dm...@gmail.com>
---
.../org/apache/ignite/IgniteSystemProperties.java | 5 +
.../org/apache/ignite/internal/IgniteKernal.java | 113 +++++++++++++++++++
.../apache/ignite/ClassPathContentLoggingTest.java | 123 +++++++++++++++++++++
.../apache/ignite/testframework/LogListener.java | 9 ++
.../testframework/junits/GridAbstractTest.java | 4 +-
.../ignite/testsuites/IgniteBasicTestSuite.java | 3 +
modules/platforms/cpp/core-test/src/test_utils.cpp | 1 +
modules/platforms/cpp/odbc-test/src/test_utils.cpp | 1 +
.../cpp/thin-client-test/src/test_utils.cpp | 1 +
.../Apache.Ignite.Core.Tests/TestUtils.Common.cs | 6 +-
10 files changed, 262 insertions(+), 4 deletions(-)
diff --git a/modules/core/src/main/java/org/apache/ignite/IgniteSystemProperties.java b/modules/core/src/main/java/org/apache/ignite/IgniteSystemProperties.java
index 9854867..0be44c0 100644
--- a/modules/core/src/main/java/org/apache/ignite/IgniteSystemProperties.java
+++ b/modules/core/src/main/java/org/apache/ignite/IgniteSystemProperties.java
@@ -1222,6 +1222,11 @@ public final class IgniteSystemProperties {
public static final String IGNITE_DUMP_PAGE_LOCK_ON_FAILURE = "IGNITE_DUMP_PAGE_LOCK_ON_FAILURE";
/**
+ * Scan the classpath on startup and log all the files containing in it.
+ */
+ public static final String IGNITE_LOG_CLASSPATH_CONTENT_ON_STARTUP = "IGNITE_LOG_CLASSPATH_CONTENT_ON_STARTUP";
+
+ /**
* Enforces singleton.
*/
private IgniteSystemProperties() {
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java b/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java
index 2b714f3..bda34b9 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java
@@ -17,6 +17,13 @@
package org.apache.ignite.internal;
+import java.io.UncheckedIOException;
+import java.nio.file.DirectoryStream;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import javax.cache.CacheException;
+import javax.management.JMException;
import java.io.Externalizable;
import java.io.File;
import java.io.IOException;
@@ -219,6 +226,7 @@ import static org.apache.ignite.IgniteSystemProperties.IGNITE_BINARY_MARSHALLER_
import static org.apache.ignite.IgniteSystemProperties.IGNITE_CONFIG_URL;
import static org.apache.ignite.IgniteSystemProperties.IGNITE_DAEMON;
import static org.apache.ignite.IgniteSystemProperties.IGNITE_EVENT_DRIVEN_SERVICE_PROCESSOR_ENABLED;
+import static org.apache.ignite.IgniteSystemProperties.IGNITE_LOG_CLASSPATH_CONTENT_ON_STARTUP;
import static org.apache.ignite.IgniteSystemProperties.IGNITE_NO_ASCII;
import static org.apache.ignite.IgniteSystemProperties.IGNITE_OPTIMIZED_MARSHALLER_USE_DEFAULT_SUID;
import static org.apache.ignite.IgniteSystemProperties.IGNITE_REST_START_ON_CLIENT;
@@ -750,6 +758,109 @@ public class IgniteKernal implements IgniteEx, IgniteMXBean, Externalizable {
}
}
+ /** */
+ private void ackClassPathElementRecursive(File clsPathEntry, SB clsPathContent) {
+ if (clsPathEntry.isDirectory()) {
+ String[] list = clsPathEntry.list();
+
+ for (String listElement : list)
+ ackClassPathElementRecursive(new File(clsPathEntry, listElement), clsPathContent);
+ }
+ else {
+ String path = clsPathEntry.getAbsolutePath();
+
+ if (path.endsWith(".class"))
+ clsPathContent.a(path).a(";");
+ }
+ }
+
+ /** */
+ private void ackClassPathEntry(String clsPathEntry, SB clsPathContent) {
+ File clsPathElementFile = new File(clsPathEntry);
+
+ if (clsPathElementFile.isDirectory())
+ ackClassPathElementRecursive(clsPathElementFile, clsPathContent);
+ else {
+ String extension = clsPathEntry.length() >= 4
+ ? clsPathEntry.substring(clsPathEntry.length() - 4).toLowerCase()
+ : null;
+
+ if (".jar".equals(extension) || ".zip".equals(extension))
+ clsPathContent.a(clsPathEntry).a(";");
+ }
+ }
+
+ /** */
+ private void ackClassPathWildCard(String clsPathEntry, SB clsPathContent) {
+ final int lastSeparatorIdx = clsPathEntry.lastIndexOf(File.separator);
+
+ final int asteriskIdx = clsPathEntry.indexOf('*');
+
+ //just to log possibly incorrent entries to err
+ if (asteriskIdx >= 0 && asteriskIdx < lastSeparatorIdx)
+ throw new RuntimeException("Could not parse classpath entry");
+
+ final int fileMaskFirstIdx = lastSeparatorIdx + 1;
+
+ final String fileMask =
+ (fileMaskFirstIdx >= clsPathEntry.length()) ? "*.jar" : clsPathEntry.substring(fileMaskFirstIdx);
+
+ Path path = Paths.get(lastSeparatorIdx > 0 ? clsPathEntry.substring(0, lastSeparatorIdx) : ".")
+ .toAbsolutePath()
+ .normalize();
+
+ if (lastSeparatorIdx == 0)
+ path = path.getRoot();
+
+ try {
+ DirectoryStream<Path> files =
+ Files.newDirectoryStream(path, fileMask);
+
+ for (Path f : files) {
+ String s = f.toString();
+
+ if (s.toLowerCase().endsWith(".jar"))
+ clsPathContent.a(f.toString()).a(";");
+ }
+ }
+ catch (IOException e) {
+ throw new UncheckedIOException(e);
+ }
+ }
+
+ /**
+ * Prints the list of *.jar and *.class files containing in classpath.
+ */
+ private void ackClassPathContent() {
+ assert log != null;
+
+ boolean enabled = IgniteSystemProperties.getBoolean(IGNITE_LOG_CLASSPATH_CONTENT_ON_STARTUP, true);
+
+ if (enabled) {
+ String clsPath = System.getProperty("java.class.path", ".");
+
+ String[] clsPathElements = clsPath.split(File.pathSeparator);
+
+ U.log(log, "Classpath value: " + clsPath);
+
+ SB clsPathContent = new SB("List of files containing in classpath: ");
+
+ for (String clsPathEntry : clsPathElements) {
+ try {
+ if (clsPathEntry.contains("*"))
+ ackClassPathWildCard(clsPathEntry, clsPathContent);
+ else
+ ackClassPathEntry(clsPathEntry, clsPathContent);
+ }
+ catch (Exception e) {
+ U.warn(log, String.format("Could not log class path entry '%s': %s", clsPathEntry, e.getMessage()));
+ }
+ }
+
+ U.log(log, clsPathContent.toString());
+ }
+ }
+
/**
* @param cfg Configuration to use.
* @param utilityCachePool Utility cache pool.
@@ -1291,6 +1402,8 @@ public class IgniteKernal implements IgniteEx, IgniteMXBean, Externalizable {
U.quietAndInfo(log, "To start Console Management & Monitoring run ignitevisorcmd.{sh|bat}");
+ ackClassPathContent();
+
ackStart(rtBean);
if (!isDaemon())
diff --git a/modules/core/src/test/java/org/apache/ignite/ClassPathContentLoggingTest.java b/modules/core/src/test/java/org/apache/ignite/ClassPathContentLoggingTest.java
new file mode 100644
index 0000000..ee2260d
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/ClassPathContentLoggingTest.java
@@ -0,0 +1,123 @@
+/*
+ * 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.ignite;
+
+import java.io.File;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.testframework.ListeningTestLogger;
+import org.apache.ignite.testframework.LogListener;
+import org.apache.ignite.testframework.junits.WithSystemProperty;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.junit.Test;
+
+import static org.apache.ignite.IgniteSystemProperties.IGNITE_LOG_CLASSPATH_CONTENT_ON_STARTUP;
+
+/**
+ *
+ */
+@WithSystemProperty(key = IGNITE_LOG_CLASSPATH_CONTENT_ON_STARTUP, value = "true")
+public class ClassPathContentLoggingTest extends GridCommonAbstractTest {
+ /** */
+ private final ListeningTestLogger listeningLog = new ListeningTestLogger(false, log);
+
+ /** */
+ private String javaClassPath;
+
+ /** */
+ private static String javaHome = System.getenv("JAVA_HOME");
+
+ /** {@inheritDoc} */
+ @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
+ return super.getConfiguration(igniteInstanceName)
+ .setGridLogger(listeningLog);
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void beforeTestsStarted() throws Exception {
+ super.beforeTestsStarted();
+
+ javaClassPath = System.getProperty("java.class.path", ".");
+
+ assertNotNull(javaHome);
+
+ StringBuilder jarPath = new StringBuilder(javaHome)
+ .append(javaHome.endsWith(File.separator) ? "" : File.separator)
+ .append("lib")
+ .append(File.separator)
+ .append("*");
+
+ System.setProperty("java.class.path", javaClassPath + File.pathSeparator + jarPath.toString());
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void afterTestsStopped() throws Exception {
+ System.setProperty("java.class.path", javaClassPath);
+
+ super.afterTestsStopped();
+ }
+
+ /**
+ * Checks the presence of class path content message in log when enabled.
+ *
+ * @throws Exception if failed.
+ */
+ @Test
+ public void testClassPathContentLogging() throws Exception {
+ LogListener lsnr = LogListener
+ .matches("List of files containing in classpath")
+ .build();
+
+ LogListener clsPathValuelsnr = LogListener
+ .matches("Classpath value")
+ .build();
+
+ LogListener errLsnr = LogListener
+ .matches("Could not log class path entry")
+ .build();
+
+ LogListener.Builder jarLsnrBuilder = LogListener.builder();
+
+ String jarPath = new StringBuilder(javaHome)
+ .append(javaHome.endsWith(File.separator) ? "" : File.separator)
+ .append("lib")
+ .append(File.separator)
+ .toString();
+
+ Iterable<Path> jars = Files.newDirectoryStream(Paths.get(jarPath), "*.jar");
+
+ for (Path jar : jars)
+ jarLsnrBuilder.andMatches(jar.getFileName().toString());
+
+ LogListener jarLsnr = jarLsnrBuilder.build();
+
+ listeningLog.registerListener(lsnr);
+ listeningLog.registerListener(clsPathValuelsnr);
+ listeningLog.registerListener(errLsnr);
+ listeningLog.registerListener(jarLsnr);
+
+ startGrid(0);
+
+ assertTrue(lsnr.check());
+ assertTrue(clsPathValuelsnr.check());
+ assertTrue(jarLsnr.check());
+
+ assertFalse(errLsnr.check());
+ }
+}
diff --git a/modules/core/src/test/java/org/apache/ignite/testframework/LogListener.java b/modules/core/src/test/java/org/apache/ignite/testframework/LogListener.java
index 45845c6..64616db 100644
--- a/modules/core/src/test/java/org/apache/ignite/testframework/LogListener.java
+++ b/modules/core/src/test/java/org/apache/ignite/testframework/LogListener.java
@@ -93,6 +93,15 @@ public abstract class LogListener implements Consumer<String> {
public abstract void reset();
/**
+ * Creates new builder.
+ *
+ * @return new builder.
+ */
+ public static Builder builder() {
+ return new Builder();
+ }
+
+ /**
* Creates new listener builder.
*
* @param substr Substring to search for in a log message.
diff --git a/modules/core/src/test/java/org/apache/ignite/testframework/junits/GridAbstractTest.java b/modules/core/src/test/java/org/apache/ignite/testframework/junits/GridAbstractTest.java
index ff67a9e..0d845b3 100755
--- a/modules/core/src/test/java/org/apache/ignite/testframework/junits/GridAbstractTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/testframework/junits/GridAbstractTest.java
@@ -139,6 +139,7 @@ import org.springframework.context.support.FileSystemXmlApplicationContext;
import static org.apache.ignite.IgniteSystemProperties.IGNITE_CLIENT_CACHE_CHANGE_MESSAGE_TIMEOUT;
import static org.apache.ignite.IgniteSystemProperties.IGNITE_DISCO_FAILED_CLIENT_RECONNECT_DELAY;
+import static org.apache.ignite.IgniteSystemProperties.IGNITE_LOG_CLASSPATH_CONTENT_ON_STARTUP;
import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL;
import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL_SNAPSHOT;
import static org.apache.ignite.cache.CacheWriteSynchronizationMode.FULL_SYNC;
@@ -248,6 +249,7 @@ public abstract class GridAbstractTest extends JUnitAssertAware {
System.setProperty(IgniteSystemProperties.IGNITE_UPDATE_NOTIFIER, "false");
System.setProperty(IGNITE_DISCO_FAILED_CLIENT_RECONNECT_DELAY, "1");
System.setProperty(IGNITE_CLIENT_CACHE_CHANGE_MESSAGE_TIMEOUT, "1000");
+ System.setProperty(IGNITE_LOG_CLASSPATH_CONTENT_ON_STARTUP, "false");
if (GridTestClockTimer.startTestTimer()) {
Thread timer = new Thread(new GridTestClockTimer(), "ignite-clock-for-tests");
@@ -2138,7 +2140,7 @@ public abstract class GridAbstractTest extends JUnitAssertAware {
/** Runs test with the provided scenario. */
private void runTest(Statement testRoutine) throws Throwable {
prepareTestEnviroment();
-
+
try {
final AtomicReference<Throwable> ex = new AtomicReference<>();
diff --git a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBasicTestSuite.java b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBasicTestSuite.java
index 30be078..fca2b47 100644
--- a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBasicTestSuite.java
+++ b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBasicTestSuite.java
@@ -17,6 +17,7 @@
package org.apache.ignite.testsuites;
+import org.apache.ignite.ClassPathContentLoggingTest;
import org.apache.ignite.GridSuppressedExceptionSelfTest;
import org.apache.ignite.failure.FailureHandlerTriggeredTest;
import org.apache.ignite.failure.OomFailureHandlerTest;
@@ -238,6 +239,8 @@ import org.junit.runners.Suite;
ConfigVariationsTestSuiteBuilderTest.class,
DeadLockOnNodeLeftExchangeTest.class,
+
+ ClassPathContentLoggingTest.class
})
public class IgniteBasicTestSuite {
}
diff --git a/modules/platforms/cpp/core-test/src/test_utils.cpp b/modules/platforms/cpp/core-test/src/test_utils.cpp
index b843a25..48f5ce3 100644
--- a/modules/platforms/cpp/core-test/src/test_utils.cpp
+++ b/modules/platforms/cpp/core-test/src/test_utils.cpp
@@ -38,6 +38,7 @@ namespace ignite_test
cfg.jvmOpts.push_back("-DIGNITE_QUIET=false");
cfg.jvmOpts.push_back("-DIGNITE_CONSOLE_APPENDER=false");
cfg.jvmOpts.push_back("-DIGNITE_UPDATE_NOTIFIER=false");
+ cfg.jvmOpts.push_back("-DIGNITE_LOG_CLASSPATH_CONTENT_ON_STARTUP=false");
cfg.jvmOpts.push_back("-Duser.language=en");
cfg.igniteHome = jni::ResolveIgniteHome();
diff --git a/modules/platforms/cpp/odbc-test/src/test_utils.cpp b/modules/platforms/cpp/odbc-test/src/test_utils.cpp
index efe6d7a..6cdaed2 100644
--- a/modules/platforms/cpp/odbc-test/src/test_utils.cpp
+++ b/modules/platforms/cpp/odbc-test/src/test_utils.cpp
@@ -93,6 +93,7 @@ namespace ignite_test
cfg.jvmOpts.push_back("-DIGNITE_QUIET=false");
cfg.jvmOpts.push_back("-DIGNITE_CONSOLE_APPENDER=false");
cfg.jvmOpts.push_back("-DIGNITE_UPDATE_NOTIFIER=false");
+ cfg.jvmOpts.push_back("-DIGNITE_LOG_CLASSPATH_CONTENT_ON_STARTUP=false");
cfg.jvmOpts.push_back("-Duser.language=en");
// Un-comment to debug SSL
//cfg.jvmOpts.push_back("-Djavax.net.debug=ssl");
diff --git a/modules/platforms/cpp/thin-client-test/src/test_utils.cpp b/modules/platforms/cpp/thin-client-test/src/test_utils.cpp
index 0789581..b6fef63 100644
--- a/modules/platforms/cpp/thin-client-test/src/test_utils.cpp
+++ b/modules/platforms/cpp/thin-client-test/src/test_utils.cpp
@@ -45,6 +45,7 @@ namespace ignite_test
cfg.jvmOpts.push_back("-DIGNITE_QUIET=false");
cfg.jvmOpts.push_back("-DIGNITE_CONSOLE_APPENDER=false");
cfg.jvmOpts.push_back("-DIGNITE_UPDATE_NOTIFIER=false");
+ cfg.jvmOpts.push_back("-DIGNITE_LOG_CLASSPATH_CONTENT_ON_STARTUP=false");
cfg.jvmOpts.push_back("-Duser.language=en");
// Un-comment to debug SSL
//cfg.jvmOpts.push_back("-Djavax.net.debug=ssl");
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/TestUtils.Common.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/TestUtils.Common.cs
index bf2849e..ef8c1a6 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/TestUtils.Common.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/TestUtils.Common.cs
@@ -47,7 +47,7 @@ namespace Apache.Ignite.Core.Tests
private const int DfltBusywaitSleepInterval = 200;
/** Work dir. */
- private static readonly string WorkDir =
+ private static readonly string WorkDir =
// ReSharper disable once AssignNullToNotNullAttribute
Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "ignite_work");
@@ -75,7 +75,7 @@ namespace Apache.Ignite.Core.Tests
/** */
private static readonly IList<string> JvmDebugOpts =
- new List<string> { "-Xdebug", "-Xnoagent", "-Djava.compiler=NONE", "-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005" };
+ new List<string> { "-Xdebug", "-Xnoagent", "-Djava.compiler=NONE", "-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005", "-DIGNITE_LOG_CLASSPATH_CONTENT_ON_STARTUP=false" };
/** */
public static bool JvmDebug = true;
@@ -143,7 +143,7 @@ namespace Apache.Ignite.Core.Tests
foreach (Thread thread in threads)
thread.Join();
-
+
foreach (var ex in errors)
Assert.Fail("Unexpected exception: " + ex);
}