Upgrade SDC from Titan to Janus Graph
[sdc.git] / asdctool / src / main / java / org / openecomp / sdc / asdctool / impl / TitanToJanusGraphMigration.groovy
1 /*
2  * Before starting the migration, please make sure to create a backup of sdctitan keyspace in cassandra
3  *
4  * Usage Instructions :
5  * 1. Download JanusGraph gremlin in-built package from below URL;
6  *    https://github.com/JanusGraph/janusgraph/releases/download/v0.3.1/janusgraph-0.3.1-hadoop2.zip
7  * 2. Unzip it and navigate to bin folder.
8  * 3. Run below command.
9  *    Command : ./gremlin.sh -l <LOG_LEVEL> -e <Path_To_This_Script_File> <Path_To_Properties_File>
10  *    Example : ./gremlin.sh -l ERROR -e /data/scripts/TitanToJanusGraphMigration.groovy /data/scripts/titan.properties
11  *
12  *  Note: Please make sure that the above provided property file have the below field present;
13  *  graph.allow-upgrade=true
14 */
15
16 // Check for open database connections; should be only one
17 def Object checkAndCloseMultipleInstances(Object mgmt, Object graph, long sleepTime){
18     if(mgmt.getOpenInstances().size() > 1) {
19         for (String instanceId in mgmt.getOpenInstances())
20             if(!instanceId.contains("current"))
21                 mgmt.forceCloseInstance(instanceId);
22         mgmt.commit();
23         sleep(sleepTime);
24         mgmt = graph.openManagement();
25     }
26     return mgmt;
27 }
28
29 // Update the ID Store
30 def updateGraphIDStore(Object mgmt, long sleepTime){
31     mgmt.set('ids.store-name', 'titan_ids');
32     mgmt.commit();
33     sleep(sleepTime);
34 }
35
36 // Verify the ID Store
37 def verifyUpdatedGraphIDStore(String propertyPath){
38     graph = JanusGraphFactory.open(propertyPath);
39     mgmt = graph.openManagement();
40     if(!mgmt.get('ids.store-name').equals("titan_ids"))
41         throw new GroovyRuntimeException("FAILURE -> Error in setting up the ID Store to titan_ids; please contact system administrator... ");
42     else
43         println("SUCCESS -> Titan ID Store has also been set correctly... ");
44 }
45
46 try {
47     graph = JanusGraphFactory.open(args[0]);
48     mgmt = graph.openManagement();
49
50     // Check if titan graph is upgraded to Janus Graph compatibility
51     if(mgmt.get('graph.titan-version').equals("1.0.0"))
52         throw new GroovyRuntimeException("FAILURE -> Titan graph is not upgraded to Janus. please make sure graph.allow-upgrade property is set to true in properties file and re-run the script.");
53     println("SUCCESS -> Titan Graph data is upgraded to Janus compatible Graph... ");
54
55     // Update the ID Store if required
56     if(mgmt.get('ids.store-name').equals("janusgraph_ids")){
57         mgmt = checkAndCloseMultipleInstances(mgmt, graph,2000l);
58         updateGraphIDStore(mgmt, 2000l);
59         verifyUpdatedGraphIDStore(args[0]);
60     }
61     println("SUCCESS -> Titan to Janus Graph upgrade process is now complete... ");
62
63 } catch(Exception ex){
64     println("FAILURE -> Titan to Janus Graph migration process has failed; please check the exception trace for more details.");
65     throw ex;
66 }