* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.aai.dbmap;
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
+
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import org.apache.commons.lang.exception.ExceptionUtils;
import org.apache.tinkerpop.gremlin.structure.Graph;
import org.apache.tinkerpop.gremlin.structure.io.IoCore;
+import org.janusgraph.core.JanusGraph;
+import org.janusgraph.core.JanusGraphFactory;
+import org.janusgraph.core.schema.JanusGraphManagement;
import org.onap.aai.dbgen.SchemaGenerator;
import org.onap.aai.exceptions.AAIException;
import org.onap.aai.util.AAIConstants;
-import com.att.eelf.configuration.EELFLogger;
-import com.att.eelf.configuration.EELFManager;
-import org.janusgraph.core.JanusGraphFactory;
-import org.janusgraph.core.JanusGraph;
-import org.janusgraph.core.schema.JanusGraphManagement;
-
/**
* Database Mapping class which acts as the middle man between the REST
* interface objects and JanusGraph DB objects. This class provides methods to commit
* rules such as keys/required properties are handled by calling DBMeth methods
* which are driven by a specification file in json.
*
-
+ *
*/
public class AAIGraph {
private static final String CACHED_DB = "cached";
private static boolean isInit = false;
-
-
/**
* Instantiates a new AAI graph.
*/
throw new RuntimeException("Failed to instantiate graphs", e);
}
}
-
+
private static class Helper {
private static final AAIGraph INSTANCE = new AAIGraph();
+
private Helper() {
-
+
}
}
-
+
/**
* Gets the single instance of AAIGraph.
*
public static boolean isInit() {
return isInit;
}
-
+
private void loadGraph(String name, String configPath, String serviceName) throws Exception {
// Graph being opened by JanusGraphFactory is being placed in hashmap to be used later
// These graphs shouldn't be closed until the application shutdown
try {
- PropertiesConfiguration propertiesConfiguration = new AAIGraphConfig.Builder(configPath).forService(serviceName).withGraphType(name).buildConfiguration();
+ PropertiesConfiguration propertiesConfiguration = new AAIGraphConfig.Builder(configPath)
+ .forService(serviceName).withGraphType(name).buildConfiguration();
JanusGraph graph = JanusGraphFactory.open(propertiesConfiguration);
Properties graphProps = new Properties();
- propertiesConfiguration.getKeys().forEachRemaining(k -> graphProps.setProperty(k, propertiesConfiguration.getString(k)));
+ propertiesConfiguration.getKeys()
+ .forEachRemaining(k -> graphProps.setProperty(k, propertiesConfiguration.getString(k)));
if ("inmemory".equals(graphProps.get("storage.backend"))) {
// Load the propertyKeys, indexes and edge-Labels into the DB
transaction.tx().commit();
logAndPrint(logger, "Snapshot loaded to inmemory graph.");
} catch (Exception e) {
- logAndPrint(logger,
- "ERROR: Could not load datasnapshot to in memory graph. \n"
+ logAndPrint(logger, "ERROR: Could not load datasnapshot to in memory graph. \n"
+ ExceptionUtils.getFullStackTrace(e));
throw new RuntimeException(e);
}
private void loadSchema(JanusGraph graph) {
// Load the propertyKeys, indexes and edge-Labels into the DB
JanusGraphManagement graphMgt = graph.openManagement();
-
+
System.out.println("-- loading schema into JanusGraph");
- SchemaGenerator.loadSchemaIntoJanusGraph( graph, graphMgt, "inmemory");
+ SchemaGenerator.loadSchemaIntoJanusGraph(graph, graphMgt, "inmemory");
}
/**
public JanusGraph getGraph() {
return graphs.get(REALTIME_DB);
}
-
+
public void graphShutdown(DBConnectionType connectionType) {
-
+
graphs.get(this.getGraphName(connectionType)).close();
}
-
+
public JanusGraph getGraph(DBConnectionType connectionType) {
return graphs.get(this.getGraphName(connectionType));
}
-
+
private String getGraphName(DBConnectionType connectionType) {
String graphName = "";
if (DBConnectionType.CACHED.equals(connectionType)) {
} else if (DBConnectionType.REALTIME.equals(connectionType)) {
graphName = this.REALTIME_DB;
}
-
+
return graphName;
}
-
+
private void logAndPrint(EELFLogger logger, String msg) {
System.out.println(msg);
logger.info(msg);