You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@atlas.apache.org by am...@apache.org on 2019/07/10 16:07:01 UTC

[atlas] branch master updated: ATLAS-3315: Database initialization exception handling.

This is an automated email from the ASF dual-hosted git repository.

amestry pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/atlas.git


The following commit(s) were added to refs/heads/master by this push:
     new 8188a96  ATLAS-3315: Database initialization exception handling.
8188a96 is described below

commit 8188a96e2aa3114502098eced91edfe3b1fb3674
Author: Ashutosh Mestry <am...@hortonworks.com>
AuthorDate: Mon Jul 8 11:14:31 2019 -0700

    ATLAS-3315: Database initialization exception handling.
---
 .../graphdb/janus/AtlasJanusGraphDatabase.java     | 32 +++++++++++--------
 .../graphdb/janus/AtlasJanusDatabaseTest.java      | 36 +++++++++++++++++++++-
 2 files changed, 54 insertions(+), 14 deletions(-)

diff --git a/graphdb/janus/src/main/java/org/apache/atlas/repository/graphdb/janus/AtlasJanusGraphDatabase.java b/graphdb/janus/src/main/java/org/apache/atlas/repository/graphdb/janus/AtlasJanusGraphDatabase.java
index c8c6a52..e9b4b09 100644
--- a/graphdb/janus/src/main/java/org/apache/atlas/repository/graphdb/janus/AtlasJanusGraphDatabase.java
+++ b/graphdb/janus/src/main/java/org/apache/atlas/repository/graphdb/janus/AtlasJanusGraphDatabase.java
@@ -18,6 +18,7 @@
 
 package org.apache.atlas.repository.graphdb.janus;
 
+import com.google.common.annotations.VisibleForTesting;
 import com.google.common.collect.ImmutableMap;
 import org.apache.atlas.ApplicationProperties;
 import org.apache.atlas.AtlasException;
@@ -165,27 +166,32 @@ public class AtlasJanusGraphDatabase implements GraphDatabase<AtlasJanusVertex,
                         throw new RuntimeException(e);
                     }
 
-                    try {
-                        graphInstance = JanusGraphFactory.open(config);
-                    } catch (JanusGraphException e) {
-                        LOG.warn("JanusGraphException: {}", e.getMessage());
-                        if (e.getMessage().startsWith(OLDER_STORAGE_EXCEPTION)) {
-                            LOG.info("Newer client is being used with older janus storage version. Setting allow-upgrade=true and reattempting connection");
-                            config.addProperty("graph.allow-upgrade", true);
-                            graphInstance = JanusGraphFactory.open(config);
-                        }
-                        else {
-                            throw new RuntimeException(e);
-                        }
-                    }
+                    graphInstance = initJanusGraph(config);
                     atlasGraphInstance = new AtlasJanusGraph();
                     validateIndexBackend(config);
+
                 }
             }
         }
         return graphInstance;
     }
 
+    @VisibleForTesting
+    static JanusGraph initJanusGraph(Configuration config) {
+        try {
+            return JanusGraphFactory.open(config);
+        } catch (JanusGraphException e) {
+            LOG.warn("JanusGraphException: {}", e.getMessage());
+            if (e.getMessage().startsWith(OLDER_STORAGE_EXCEPTION)) {
+                LOG.info("Newer client is being used with older janus storage version. Setting allow-upgrade=true and reattempting connection");
+                config.addProperty("graph.allow-upgrade", true);
+                return JanusGraphFactory.open(config);
+            } else {
+                throw new RuntimeException(e);
+            }
+        }
+    }
+
     public static JanusGraph getBulkLoadingGraphInstance() {
         try {
             Configuration cfg = getConfiguration();
diff --git a/graphdb/janus/src/test/java/org/apache/atlas/repository/graphdb/janus/AtlasJanusDatabaseTest.java b/graphdb/janus/src/test/java/org/apache/atlas/repository/graphdb/janus/AtlasJanusDatabaseTest.java
index 3ab3c1e..5cd5509 100644
--- a/graphdb/janus/src/test/java/org/apache/atlas/repository/graphdb/janus/AtlasJanusDatabaseTest.java
+++ b/graphdb/janus/src/test/java/org/apache/atlas/repository/graphdb/janus/AtlasJanusDatabaseTest.java
@@ -31,6 +31,7 @@ import org.apache.atlas.repository.graphdb.AtlasGraphQuery.ComparisionOperator;
 import org.apache.atlas.repository.graphdb.AtlasPropertyKey;
 import org.apache.atlas.repository.graphdb.AtlasVertex;
 import org.apache.atlas.typesystem.types.DataTypes.TypeCategory;
+import org.apache.commons.configuration.Configuration;
 import org.testng.annotations.AfterClass;
 import org.testng.annotations.Test;
 
@@ -39,9 +40,18 @@ import java.math.BigInteger;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
 import java.util.List;
+import java.util.Map;
 
-import static org.testng.Assert.*;
+import static org.apache.atlas.repository.graphdb.janus.AtlasJanusGraphDatabase.initJanusGraph;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertNotNull;
+import static org.testng.Assert.assertNull;
+import static org.testng.Assert.assertTrue;
+import static org.testng.Assert.fail;
 
 /**
  * Sanity test of basic graph operations using the Janus graphdb
@@ -81,6 +91,30 @@ public class AtlasJanusDatabaseTest {
     }
 
     @Test
+    public void initializationFailureShouldThrowRuntimeException() throws AtlasException {
+        Configuration cfg = AtlasJanusGraphDatabase.getConfiguration();
+        Map<String, Object> cfgBackup = new HashMap<>();
+        Iterator<String> keys = cfg.getKeys();
+        while(keys.hasNext()) {
+            String key = keys.next();
+            cfgBackup.put(key, cfg.getProperty(key));
+        }
+
+        try {
+            cfg.clear();
+            initJanusGraph(cfg);
+
+            fail("Should have thrown an exception!");
+        }
+        catch (RuntimeException ex) {
+            assertTrue(true);
+            for (Map.Entry<String, Object> entry : cfgBackup.entrySet()) {
+                cfg.setProperty(entry.getKey(), entry.getValue());
+            }
+        }
+    }
+
+    @Test
     public <V, E> void testPropertyDataTypes() {
 
         // primitives