You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nemo.apache.org by je...@apache.org on 2019/11/05 07:37:43 UTC
[incubator-nemo] branch master updated: [NEMO-422] Sonarcloud issue
(#246)
This is an automated email from the ASF dual-hosted git repository.
jeongyoon pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nemo.git
The following commit(s) were added to refs/heads/master by this push:
new 0c1a23c [NEMO-422] Sonarcloud issue (#246)
0c1a23c is described below
commit 0c1a23c2dd2ecc7b8430505db18a6cc2c629ba5f
Author: Won Wook SONG <ws...@gmail.com>
AuthorDate: Tue Nov 5 16:37:34 2019 +0900
[NEMO-422] Sonarcloud issue (#246)
JIRA: [NEMO-422: Sonarcloud issue](https://issues.apache.org/jira/projects/NEMO/issues/NEMO-422)
**Major changes:**
- None
**Minor changes to note:**
- Gets rid of the hard-coded fake password, and handles it with Base64 decoding method.
**Tests for the changes:**
- Existing tests confirm the changes
**Other comments:**
- None
Closes #246
---
.../nemo/runtime/common/metric/MetricUtils.java | 20 ++++++++++++++++++--
1 file changed, 18 insertions(+), 2 deletions(-)
diff --git a/runtime/common/src/main/java/org/apache/nemo/runtime/common/metric/MetricUtils.java b/runtime/common/src/main/java/org/apache/nemo/runtime/common/metric/MetricUtils.java
index d9864a4..00c1f52 100644
--- a/runtime/common/src/main/java/org/apache/nemo/runtime/common/metric/MetricUtils.java
+++ b/runtime/common/src/main/java/org/apache/nemo/runtime/common/metric/MetricUtils.java
@@ -33,9 +33,11 @@ import org.slf4j.LoggerFactory;
import java.io.ByteArrayInputStream;
import java.io.Serializable;
+import java.io.UnsupportedEncodingException;
import java.lang.reflect.Method;
import java.sql.*;
import java.util.Arrays;
+import java.util.Base64;
import java.util.Optional;
import java.util.concurrent.CountDownLatch;
import java.util.function.Supplier;
@@ -80,13 +82,27 @@ public final class MetricUtils {
}
/**
+ * Method to derive db credentials. This method is not for real authentication. Please change the method accordingly.
+ * @return db credentials.
+ */
+ private static String getCreds() {
+ try {
+ final String str = "ZmFrZV9wYXNzd29yZA==";
+ byte[] decodedBytes = Base64.getDecoder().decode(str.getBytes("UTF-8"));
+ return new String(decodedBytes);
+ } catch (UnsupportedEncodingException e) {
+ throw new MetricException(e);
+ }
+ }
+
+ /**
* Load the BiMaps (lightweight) Metadata from the DB.
*
* @return Whether or not the metadata has been successfully loaded from the DB.
*/
public static Boolean loadMetaData() {
try (Connection c = DriverManager.getConnection(MetricUtils.POSTGRESQL_METADATA_DB_NAME,
- "postgres", "fake_password")) {
+ "postgres", getCreds())) {
try (Statement statement = c.createStatement()) {
statement.setQueryTimeout(30); // set timeout to 30 sec.
@@ -141,7 +157,7 @@ public final class MetricUtils {
LOG.info("Saving Metadata..");
try (Connection c = DriverManager.getConnection(MetricUtils.POSTGRESQL_METADATA_DB_NAME,
- "postgres", "fake_password")) {
+ "postgres", getCreds())) {
try (Statement statement = c.createStatement()) {
statement.setQueryTimeout(30); // set timeout to 30 sec.