a3273fb3ddb00a65e8ee7c9d843e0f4a1282c172
[aai/aai-common.git] / aai-core / src / main / java / org / openecomp / aai / dbgen / GenTester.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * org.openecomp.aai
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.openecomp.aai.dbgen;
22
23 import com.att.eelf.configuration.Configuration;
24 import com.att.eelf.configuration.EELFLogger;
25 import com.att.eelf.configuration.EELFManager;
26 import com.thinkaurelius.titan.core.TitanGraph;
27 import com.thinkaurelius.titan.core.schema.TitanManagement;
28 import org.openecomp.aai.dbmap.AAIGraph;
29 import org.openecomp.aai.logging.ErrorLogHelper;
30 import org.openecomp.aai.util.AAIConfig;
31 import org.openecomp.aai.util.AAIConstants;
32
33 import java.util.Properties;
34
35
36 public class GenTester {
37
38         private static final EELFLogger LOGGER = EELFManager.getInstance().getLogger(GenTester.class);
39         
40         /**
41          * The main method.
42          *
43          * @param args the arguments
44          */
45         public static void main(String[] args) {
46            
47                 TitanGraph graph = null;
48                 
49                 // Set the logging file properties to be used by EELFManager
50                 Properties props = System.getProperties();
51                 props.setProperty(Configuration.PROPERTY_LOGGING_FILE_NAME, AAIConstants.AAI_CREATE_DB_SCHEMA_LOGBACK_PROPS);
52                 props.setProperty(Configuration.PROPERTY_LOGGING_FILE_PATH, AAIConstants.AAI_HOME_ETC_APP_PROPERTIES);
53                 boolean addDefaultCR = true;
54                 
55                 try {   
56                         AAIConfig.init();
57                 if (args != null && args.length > 0 ){
58                         if( "genDbRulesOnly".equals(args[0]) ){
59                                 ErrorLogHelper.logError("AAI_3100",
60                                                 " This option is no longer supported. What was in DbRules is now derived from the OXM files. ");
61                                 return;
62                         }
63                         else if ( "GEN_DB_WITH_NO_SCHEMA".equals(args[0]) ){
64                                 // Note this is done to create an empty DB with no Schema so that
65                                         // an HBase copyTable can be used to set up a copy of the db.
66                                         LOGGER.info("    ---- NOTE --- about to load a graph without doing any schema processing (takes a little while) --------   ");
67                                         graph = AAIGraph.getInstance().getGraph();
68                                 
69                                if( graph == null ){
70                                            ErrorLogHelper.logError("AAI_5102", "Error creating Titan graph.");
71                                    return;
72                                }
73                                else {
74                                    LOGGER.auditEvent("Successfully loaded a Titan graph without doing any schema work.  ");
75                                    return;
76                                }
77                         } else if ("GEN_DB_WITH_NO_DEFAULT_CR".equals(args[0])) {
78                                 addDefaultCR = false;
79                         }
80                         else {
81                                 ErrorLogHelper.logError("AAI_3000", "Unrecognized argument passed to GenTester.java: [" + args[0] + "]. ");
82                                 LOGGER.error("Unrecognized argument passed to GenTester.java: [" + args[0] + "]. ");
83                                 LOGGER.error("Either pass no argument for normal processing, or use 'GEN_DB_WITH_NO_SCHEMA'.");
84                                 return;
85                         }
86                 }
87                 
88                         //AAIConfig.init();
89                         ErrorLogHelper.loadProperties();
90                         LOGGER.info("    ---- NOTE --- about to open graph (takes a little while)--------;");
91                         graph = AAIGraph.getInstance().getGraph();
92                 
93                         if( graph == null ){
94                                 ErrorLogHelper.logError("AAI_5102", "Error creating Titan graph. ");
95                                 return;
96                         }
97
98                // Load the propertyKeys, indexes and edge-Labels into the DB
99                TitanManagement graphMgt = graph.openManagement();
100
101                LOGGER.info("-- Loading new schema elements into Titan --");
102                SchemaGenerator.loadSchemaIntoTitan( graph, graphMgt, addDefaultCR );
103
104             } catch(Exception ex) {
105                 ErrorLogHelper.logError("AAI_4000", ex.getMessage());
106             }
107             
108
109             if( graph != null ){
110                     LOGGER.info("-- graph commit");
111                 graph.tx().commit();
112
113                         LOGGER.info("-- graph shutdown ");
114                 graph.close();
115             }
116             
117             LOGGER.auditEvent("-- all done, if program does not exit, please kill.");
118             System.exit(0);
119     }
120
121 }
122
123