You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hop.apache.org by ha...@apache.org on 2021/07/29 13:41:30 UTC
[incubator-hop] branch master updated: HOP-3132 Added new method to
HopConfig to easily retrieve a variable's value. Fixed an issue that
prevented HOP_LOG_MARKS_MAPPING=Y to work properly.
This is an automated email from the ASF dual-hosted git repository.
hansva pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-hop.git
The following commit(s) were added to refs/heads/master by this push:
new dab7426 HOP-3132 Added new method to HopConfig to easily retrieve a variable's value. Fixed an issue that prevented HOP_LOG_MARKS_MAPPING=Y to work properly.
dab7426 is described below
commit dab7426efa6d21234064ab70fcc94e6b39502b75
Author: Sergio Ramazzina <se...@serasoft.it>
AuthorDate: Thu Jul 29 15:41:26 2021 +0200
HOP-3132 Added new method to HopConfig to easily retrieve a variable's value. Fixed an issue that prevented HOP_LOG_MARKS_MAPPING=Y to work properly.
* HOP-3132 Added new method to HopConfig to easily retrieve a variable's value. Fixed an issue that prevented HOP_LOG_MARKS_MAPPING=Y to work properly.
* HOP-3132 Fixed unit tests
* HOP-3132 Fixed unit tests
---
core/pom.xml | 2 +-
.../java/org/apache/hop/core/config/HopConfig.java | 31 ++++++++++++++++++----
.../org/apache/hop/core/logging/LogMessage.java | 6 ++++-
engine/src/main/resources/hop-variables.xml | 8 ++++++
.../apache/hop/core/logging/LogMessageTest.java | 6 +++--
5 files changed, 44 insertions(+), 9 deletions(-)
diff --git a/core/pom.xml b/core/pom.xml
index bd4ff88..be0418a 100644
--- a/core/pom.xml
+++ b/core/pom.xml
@@ -498,7 +498,7 @@
<version>${jackson.version}</version>
<scope>compile</scope>
</dependency>
- <dependency>
+ <dependency>
<groupId>xerces</groupId>
<artifactId>xercesImpl</artifactId>
<version>2.12.0</version>
diff --git a/core/src/main/java/org/apache/hop/core/config/HopConfig.java b/core/src/main/java/org/apache/hop/core/config/HopConfig.java
index 3229c00..35c6c46 100644
--- a/core/src/main/java/org/apache/hop/core/config/HopConfig.java
+++ b/core/src/main/java/org/apache/hop/core/config/HopConfig.java
@@ -21,12 +21,9 @@ import com.fasterxml.jackson.annotation.JsonIgnore;
import org.apache.hop.core.Const;
import org.apache.hop.core.config.plugin.ConfigFile;
import org.apache.hop.core.util.Utils;
+import sun.security.krb5.internal.crypto.Des;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
/**
* This class keeps track of storing and retrieving all the configuration options in Hop.
@@ -155,6 +152,30 @@ public class HopConfig extends ConfigFile implements IConfigFile {
}
}
+ /**
+ * This method returns the value of a Hop named string variable.
+ *
+ * @param key - variable name
+ * @param defaultValue - default value
+ * @return the value associated to the variable
+ */
+ public static String readStringVariable(String key, String defaultValue) {
+ String value = null;
+
+ ArrayList<DescribedVariable> variables = (ArrayList<DescribedVariable>) getInstance().configMap.get( HOP_VARIABLES_KEY );
+ if ( variables != null ) {
+ Iterator<DescribedVariable> i = variables.iterator();
+
+ while(i.hasNext() && value == null) {
+ DescribedVariable v = i.next();
+ if (v.getName().equals(key))
+ value = v.getValue();
+ }
+ }
+
+ return value == null ? defaultValue : value;
+ }
+
public static void setGuiProperty( String key, String value ) {
readGuiProperties().put( key, value );
}
diff --git a/core/src/main/java/org/apache/hop/core/logging/LogMessage.java b/core/src/main/java/org/apache/hop/core/logging/LogMessage.java
index 7cdccc5..54e9c04 100644
--- a/core/src/main/java/org/apache/hop/core/logging/LogMessage.java
+++ b/core/src/main/java/org/apache/hop/core/logging/LogMessage.java
@@ -19,8 +19,10 @@ package org.apache.hop.core.logging;
import org.apache.commons.lang.StringUtils;
import org.apache.hop.core.Const;
+import org.apache.hop.core.config.HopConfig;
import org.apache.hop.core.util.EnvUtil;
import org.apache.hop.core.util.StringUtil;
+import org.apache.hop.metadata.api.HopMetadata;
import java.text.MessageFormat;
import java.util.ArrayList;
@@ -71,7 +73,9 @@ public class LogMessage implements ILogMessage {
// Derive the subject from the registry
//
ILoggingObject loggingObject = LoggingRegistry.getInstance().getLoggingObject( logChannelId );
- boolean detailedLogTurnOn = "Y".equals( EnvUtil.getSystemProperty( Const.HOP_LOG_MARK_MAPPINGS ) ) ? true : false;
+
+ // boolean detailedLogTurnOn = "Y".equals( EnvUtil.getSystemProperty( Const.HOP_LOG_MARK_MAPPINGS ) ) ? true : false;
+ boolean detailedLogTurnOn = "Y".equals( HopConfig.readStringVariable( Const.HOP_LOG_MARK_MAPPINGS, "N" ) ) ? true : false;
if ( loggingObject != null ) {
if ( !detailedLogTurnOn ) {
subject = loggingObject.getObjectName();
diff --git a/engine/src/main/resources/hop-variables.xml b/engine/src/main/resources/hop-variables.xml
index 393943a..54c5dbb 100644
--- a/engine/src/main/resources/hop-variables.xml
+++ b/engine/src/main/resources/hop-variables.xml
@@ -328,5 +328,13 @@
<default-value></default-value>
</hop-variable>
+ <hop-variable>
+ <description>Set this variable to Y to precede transform/action name in log lines with the complete path to the transform/action. Useful
+ o perfectly identify where a problem happened in our process.
+ </description>
+ <variable>HOP_LOG_MARK_MAPPINGS</variable>
+ <default-value>N</default-value>
+ </hop-variable>
+
</hop-variables>
diff --git a/core/src/test/java/org/apache/hop/core/logging/LogMessageTest.java b/engine/src/test/java/org/apache/hop/core/logging/LogMessageTest.java
similarity index 94%
rename from core/src/test/java/org/apache/hop/core/logging/LogMessageTest.java
rename to engine/src/test/java/org/apache/hop/core/logging/LogMessageTest.java
index 684629b..301e88b 100644
--- a/core/src/test/java/org/apache/hop/core/logging/LogMessageTest.java
+++ b/engine/src/test/java/org/apache/hop/core/logging/LogMessageTest.java
@@ -18,6 +18,8 @@
package org.apache.hop.core.logging;
import org.apache.hop.core.Const;
+import org.apache.hop.core.config.DescribedVariable;
+import org.apache.hop.core.config.HopConfig;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -119,11 +121,11 @@ public class LogMessageTest {
}
private void turnOnLogMarkMapping() {
- System.getProperties().put( Const.HOP_LOG_MARK_MAPPINGS, "Y" );
+ HopConfig.getInstance().setDescribedVariable(new DescribedVariable(Const.HOP_LOG_MARK_MAPPINGS, "Y", ""));
}
private void turnOffLogMarkMapping() {
- System.getProperties().put( Const.HOP_LOG_MARK_MAPPINGS, "N" );
+ HopConfig.getInstance().setDescribedVariable(new DescribedVariable(Const.HOP_LOG_MARK_MAPPINGS, "N", ""));
}
private static ILoggingObject getTreeLoggingObject() {