aboutsummaryrefslogtreecommitdiffstats
path: root/aai-els-onap-logging
diff options
context:
space:
mode:
Diffstat (limited to 'aai-els-onap-logging')
-rw-r--r--aai-els-onap-logging/src/main/java/org/onap/aai/aailog/logs/AaiDmaapMetricLog.java3
-rw-r--r--aai-els-onap-logging/src/main/java/org/onap/aai/util/AAIApplicationConfig.java108
-rw-r--r--aai-els-onap-logging/src/main/java/org/onap/aai/util/HbaseSaltPrefixer.java21
-rw-r--r--aai-els-onap-logging/src/test/java/org/onap/aai/logging/LoggingContextTest.java8
4 files changed, 91 insertions, 49 deletions
diff --git a/aai-els-onap-logging/src/main/java/org/onap/aai/aailog/logs/AaiDmaapMetricLog.java b/aai-els-onap-logging/src/main/java/org/onap/aai/aailog/logs/AaiDmaapMetricLog.java
index b0fb079c..35d206f0 100644
--- a/aai-els-onap-logging/src/main/java/org/onap/aai/aailog/logs/AaiDmaapMetricLog.java
+++ b/aai-els-onap-logging/src/main/java/org/onap/aai/aailog/logs/AaiDmaapMetricLog.java
@@ -37,6 +37,9 @@ public class AaiDmaapMetricLog extends MDCSetup {
private static final String TARGET_ENTITY = "DMaaP";
public AaiDmaapMetricLog() {
+ if(MDC.get(ONAPLogConstants.MDCs.SERVER_FQDN) == null) {
+ setServerFQDN();
+ }
}
public void pre(String targetServiceName, String event, String transactionId, String serviceName) {
diff --git a/aai-els-onap-logging/src/main/java/org/onap/aai/util/AAIApplicationConfig.java b/aai-els-onap-logging/src/main/java/org/onap/aai/util/AAIApplicationConfig.java
index 7de6af28..9232b1c8 100644
--- a/aai-els-onap-logging/src/main/java/org/onap/aai/util/AAIApplicationConfig.java
+++ b/aai-els-onap-logging/src/main/java/org/onap/aai/util/AAIApplicationConfig.java
@@ -32,7 +32,6 @@ import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.Charset;
import java.util.Properties;
-import java.util.UUID;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -44,9 +43,11 @@ public class AAIApplicationConfig {
private static final String PASSPHRASSES_FILENAME = ".passphrases";
private static final String PASSWORD_FILENAME = ".password";
private static final String TRUSTSTORE_PASSWORD_PROP_NAME = "cadi_truststore_password";
- private static final String SERVER_SSL_KEYSTORE_PROP_NAME = "server.ssl.key-store";
- private static final String SERVER_SSL_KEYSTORE_PKCS12_PROP_NAME = "server.ssl.key-store.pkcs12";
- private static final String SERVER_SSL_TRUSTSTORE_PROP_NAME = "server.ssl.trust-store";
+ public static final String SERVER_SSL_KEYSTORE_PROP_NAME = "server.ssl.key-store";
+ public static final String SERVER_SSL_KEYSTORE_PKCS12_PROP_NAME = "server.ssl.key-store.pkcs12";
+ public static final String SERVER_SSL_TRUSTSTORE_PROP_NAME = "server.ssl.trust-store";
+ public static final String TRUSTSTORE_PASSWORD_NAME = "server.ssl.trust-store-password";
+ public static final String KEYSTORE_PASSWORD_NAME = "server.ssl.key-store-password";
private static Properties serverProps;
private static boolean propsInitialized = false;
private static String TRUSTSTORE_PASSWORD = null;
@@ -66,20 +67,9 @@ public class AAIApplicationConfig {
* @throws AAIException the AAI exception
*/
public synchronized static void init() {
- /*LoggingContext.save();
- LoggingContext.component("config");
- LoggingContext.partnerName("NA");
- LoggingContext.targetEntity("AAI");
- LoggingContext.requestId(UUID.randomUUID().toString());
- LoggingContext.serviceName("AAI");
- LoggingContext.targetServiceName("init");
- LoggingContext.statusCode(StatusCode.COMPLETE);*/
LOGGER.info("Initializing AAIApplicationConfig");
-
AAIApplicationConfig.reloadConfig();
-
- //LoggingContext.restore();
}
/**
@@ -210,6 +200,14 @@ public class AAIApplicationConfig {
catch (AAIException e) {
return null;
}
+ return (retrieveKeystorePasswordWithCertPath(certPath));
+ }
+ /**
+ * Retrieve the keystore password
+ *
+ * @return the password
+ */
+ private static String retrieveKeystorePasswordWithCertPath(String certPath) {
File passwordFile = null;
InputStream passwordStream = null;
@@ -238,7 +236,6 @@ public class AAIApplicationConfig {
}
return keystorePassword;
}
-
/**
* Get the keystore password
*
@@ -247,23 +244,13 @@ public class AAIApplicationConfig {
public static String getKeystorePassword() {
return (KEYSTORE_PASSWORD);
}
-
/**
* Gets the truststore password
*
* @return the password
*/
- private static String retrieveTruststorePassword() {
- String certPath = serverProps.getProperty(SERVER_CERTS_LOCATION_PROP_NAME);
- if (certPath == null) {
- return null;
- }
- try {
- certPath = replaceProperties(certPath);
- }
- catch (AAIException e) {
- return null;
- }
+ private static String retrieveTruststorePasswordWithCertPath(String certPath) {
+
File passphrasesFile = null;
InputStream passphrasesStream = null;
String truststorePassword = null;
@@ -294,6 +281,24 @@ public class AAIApplicationConfig {
return truststorePassword;
}
+ /**
+ * Gets the truststore password
+ *
+ * @return the password
+ */
+ private static String retrieveTruststorePassword() {
+ String certPath = serverProps.getProperty(SERVER_CERTS_LOCATION_PROP_NAME);
+ if (certPath == null) {
+ return null;
+ }
+ try {
+ certPath = replaceProperties(certPath);
+ }
+ catch (AAIException e) {
+ return null;
+ }
+ return (retrieveTruststorePasswordWithCertPath(certPath));
+ }
/**
* Get the trustore password
@@ -359,4 +364,51 @@ public class AAIApplicationConfig {
m.appendTail(sb);
return(sb.toString());
}
+
+ public static Properties retrieveKeystoreProps() throws AAIException {
+
+ Properties props = new Properties();
+ String truststorePath = System.getProperty(SERVER_SSL_TRUSTSTORE_PROP_NAME);
+ String truststorePassword = System.getProperty(TRUSTSTORE_PASSWORD_NAME);
+ String keystorePath = System.getProperty(SERVER_SSL_KEYSTORE_PKCS12_PROP_NAME);
+ String keystorePassword = System.getProperty(KEYSTORE_PASSWORD_NAME);
+ String certLocation = System.getProperty(SERVER_CERTS_LOCATION_PROP_NAME);
+
+ if (truststorePath == null || truststorePath.isEmpty()){
+ truststorePath = AAIApplicationConfig.getTruststore();
+ }
+ if (truststorePath != null) {
+ props.setProperty(SERVER_SSL_TRUSTSTORE_PROP_NAME, truststorePath);
+ }
+ if (truststorePassword == null || truststorePassword.isEmpty()) {
+ if (certLocation != null && (!certLocation.isEmpty())) {
+ truststorePassword = AAIApplicationConfig.retrieveTruststorePasswordWithCertPath(certLocation);
+ }
+ else {
+ truststorePassword = AAIApplicationConfig.getTruststorePassword();
+ }
+
+ }
+ if (truststorePassword != null) {
+ props.setProperty(TRUSTSTORE_PASSWORD_NAME, truststorePassword);
+ }
+ if (keystorePath == null || keystorePath.isEmpty()){
+ keystorePath = AAIApplicationConfig.getKeystorePkcs12();
+ }
+ if (keystorePath != null) {
+ props.setProperty(SERVER_SSL_KEYSTORE_PKCS12_PROP_NAME, keystorePath);
+ }
+ if (keystorePassword == null || keystorePassword.isEmpty()){
+ if (certLocation != null && (!certLocation.isEmpty())) {
+ keystorePassword = AAIApplicationConfig.retrieveKeystorePasswordWithCertPath(certLocation);
+ }
+ else {
+ keystorePassword = AAIApplicationConfig.getKeystorePassword();
+ }
+ }
+ if (keystorePassword != null) {
+ props.setProperty(KEYSTORE_PASSWORD_NAME, keystorePassword);
+ }
+ return(props);
+ }
}
diff --git a/aai-els-onap-logging/src/main/java/org/onap/aai/util/HbaseSaltPrefixer.java b/aai-els-onap-logging/src/main/java/org/onap/aai/util/HbaseSaltPrefixer.java
index a41ad27b..95f9c1b7 100644
--- a/aai-els-onap-logging/src/main/java/org/onap/aai/util/HbaseSaltPrefixer.java
+++ b/aai-els-onap-logging/src/main/java/org/onap/aai/util/HbaseSaltPrefixer.java
@@ -1,4 +1,4 @@
-/**
+/*
* ============LICENSE_START=======================================================
* org.onap.aai
* ================================================================================
@@ -27,35 +27,22 @@ package org.onap.aai.util;
* as these keys are generated in a couple places, I made a class to contain that logic
*/
public class HbaseSaltPrefixer {
- private int NUM_REGION_BUCKETS = 3; // the number of hbase region servers per cluster
+ // the number of hbase region servers per cluster
+ private static int NUM_REGION_BUCKETS = 3;
private static class SingletonHolder {
private static final HbaseSaltPrefixer INSTANCE = new HbaseSaltPrefixer();
}
- /**
- * Instantiates a new hbase salt prefixer.
- */
private HbaseSaltPrefixer() {
}
- /**
- * Gets the single instance of HbaseSaltPrefixer.
- *
- * @return single instance of HbaseSaltPrefixer
- */
public static HbaseSaltPrefixer getInstance() {
return SingletonHolder.INSTANCE;
}
- /**
- * Prepend salt.
- *
- * @param key the key
- * @return the string
- */
public String prependSalt(String key) {
- int salt = key.hashCode() % NUM_REGION_BUCKETS;
+ int salt = Math.abs(key.hashCode()) % NUM_REGION_BUCKETS;
return salt + "-" + key;
}
}
diff --git a/aai-els-onap-logging/src/test/java/org/onap/aai/logging/LoggingContextTest.java b/aai-els-onap-logging/src/test/java/org/onap/aai/logging/LoggingContextTest.java
index 245840bc..4fe60315 100644
--- a/aai-els-onap-logging/src/test/java/org/onap/aai/logging/LoggingContextTest.java
+++ b/aai-els-onap-logging/src/test/java/org/onap/aai/logging/LoggingContextTest.java
@@ -1,4 +1,4 @@
-/**
+/*
* ============LICENSE_START=======================================================
* org.onap.aai
* ================================================================================
@@ -39,7 +39,7 @@ public class LoggingContextTest {
LoggingContext.elapsedTime(300, TimeUnit.MILLISECONDS);
assertEquals(MDC.get(LoggingContext.LoggingField.ELAPSED_TIME.toString()), "300");
LoggingContext.init();
- assertTrue(MDC.get(LoggingContext.LoggingField.ELAPSED_TIME.toString()) == null);
+ assertNull(MDC.get(LoggingContext.LoggingField.ELAPSED_TIME.toString()));
}
@Test
public void stopWatchTest() {
@@ -60,7 +60,7 @@ public class LoggingContextTest {
assertEquals(testServiceName, MDC.get(LoggingContext.LoggingField.SERVICE_NAME.toString()));
LoggingContext.clear();
- assertTrue(MDC.get(LoggingContext.LoggingField.SERVICE_NAME.toString()) == null);
+ assertNull(MDC.get(LoggingContext.LoggingField.SERVICE_NAME.toString()));
}
@@ -71,7 +71,7 @@ public class LoggingContextTest {
assertEquals(testServiceName, MDC.get(LoggingContext.LoggingField.SERVICE_NAME.toString()));
LoggingContext.remove(LoggingContext.LoggingField.SERVICE_NAME.toString());
- assertTrue(MDC.get(LoggingContext.LoggingField.SERVICE_NAME.toString()) == null);
+ assertNull(MDC.get(LoggingContext.LoggingField.SERVICE_NAME.toString()));
}