[AAI-178 Amsterdam] Make Edge Properties to be
[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 EELFLogger LOGGER;
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                 LOGGER = EELFManager.getInstance().getLogger(GenTester.class);
54                 boolean addDefaultCR = true;
55                 
56                 try {   
57                         AAIConfig.init();
58                 if (args != null && args.length > 0 ){
59                         if( "genDbRulesOnly".equals(args[0]) ){
60                                 ErrorLogHelper.logError("AAI_3100", 
61                                                 " This option is no longer supported. What was in DbRules is now derived from the OXM files. ");
62                                 return;
63                         }
64                         else if ( "GEN_DB_WITH_NO_SCHEMA".equals(args[0]) ){
65                                 // Note this is done to create an empty DB with no Schema so that
66                                         // an HBase copyTable can be used to set up a copy of the db.
67                                         String imsg = "    ---- NOTE --- about to load a graph without doing any schema processing (takes a little while) --------   ";
68                         System.out.println(imsg);
69                         LOGGER.info(imsg);
70                                         graph = AAIGraph.getInstance().getGraph();
71                                 
72                                if( graph == null ){
73                                            ErrorLogHelper.logError("AAI_5102", "Error creating Titan graph.");
74                                    return;
75                                }
76                                else {
77                                    String amsg = "Successfully loaded a Titan graph without doing any schema work.  ";
78                                    System.out.println(amsg);
79                                    LOGGER.auditEvent(amsg);
80                                    return;
81                                }
82                         } else if ("GEN_DB_WITH_NO_DEFAULT_CR".equals(args[0])) {
83                                 addDefaultCR = false;
84                         }
85                         else {
86                                 ErrorLogHelper.logError("AAI_3000", "Unrecognized argument passed to GenTester.java: [" + args[0] + "]. ");
87                                 
88                                 String emsg = "Unrecognized argument passed to GenTester.java: [" + args[0] + "]. ";
89                                 System.out.println(emsg);
90                                 LOGGER.error(emsg);
91                                 
92                                 emsg = "Either pass no argument for normal processing, or use 'GEN_DB_WITH_NO_SCHEMA'.";
93                                 System.out.println(emsg);
94                                 LOGGER.error(emsg);
95                                 
96                                 return;
97                         }
98                 }
99                 
100                         //AAIConfig.init();
101                         ErrorLogHelper.loadProperties();
102                         String imsg = "    ---- NOTE --- about to open graph (takes a little while)--------;";
103                 System.out.println(imsg);
104                 LOGGER.info(imsg);
105                         graph = AAIGraph.getInstance().getGraph();
106                 
107                         if( graph == null ){
108                                 ErrorLogHelper.logError("AAI_5102", "Error creating Titan graph. ");
109                                 return;
110                         }
111
112                         // Load the propertyKeys, indexes and edge-Labels into the DB
113                         TitanManagement graphMgt = graph.openManagement();
114
115                 imsg = "-- Loading new schema elements into Titan --";
116                 System.out.println(imsg);
117                 LOGGER.info(imsg);
118                 SchemaGenerator.loadSchemaIntoTitan( graph, graphMgt, addDefaultCR );
119
120             } catch(Exception ex) {
121                 ErrorLogHelper.logError("AAI_4000", ex.getMessage());
122             }
123             
124
125             if( graph != null ){
126                     String imsg = "-- graph commit";
127                 System.out.println(imsg);
128                 LOGGER.info(imsg);
129                 graph.tx().commit();
130
131                         imsg = "-- graph shutdown ";
132                 System.out.println(imsg);
133                 LOGGER.info(imsg);
134                 graph.close();
135             }
136             
137             LOGGER.auditEvent("-- all done, if program does not exit, please kill.");
138             System.exit(0);
139     }
140
141 }
142
143