Commit 8188a96e by Ashutosh Mestry

ATLAS-3315: Database initialization exception handling.

parent 5c002517
......@@ -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();
......
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment