2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
20 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22 package org.onap.aai.db.schema;
24 import java.io.IOException;
25 import java.util.UUID;
27 import org.apache.commons.configuration.ConfigurationException;
28 import org.codehaus.jackson.JsonGenerationException;
29 import org.codehaus.jackson.map.JsonMappingException;
30 import org.codehaus.jackson.map.ObjectMapper;
31 import org.onap.aai.dbmap.AAIGraphConfig;
32 import org.onap.aai.exceptions.AAIException;
33 import org.onap.aai.introspection.Version;
34 import org.onap.aai.logging.LoggingContext;
35 import org.onap.aai.logging.LoggingContext.StatusCode;
36 import org.onap.aai.util.AAIConfig;
37 import com.beust.jcommander.JCommander;
38 import com.beust.jcommander.Parameter;
39 import com.thinkaurelius.titan.core.TitanFactory;
40 import com.thinkaurelius.titan.core.TitanGraph;
42 public class ScriptDriver {
48 * @param args the arguments
49 * @throws AAIException the AAI exception
50 * @throws JsonGenerationException the json generation exception
51 * @throws JsonMappingException the json mapping exception
52 * @throws IOException Signals that an I/O exception has occurred.
54 public static void main (String[] args) throws AAIException, IOException, ConfigurationException {
55 CommandLineArgs cArgs = new CommandLineArgs();
57 LoggingContext.init();
58 LoggingContext.component("DBSchemaScriptDriver");
59 LoggingContext.partnerName("NA");
60 LoggingContext.targetEntity("AAI");
61 LoggingContext.requestId(UUID.randomUUID().toString());
62 LoggingContext.serviceName("AAI");
63 LoggingContext.targetServiceName("main");
64 LoggingContext.statusCode(StatusCode.COMPLETE);
65 LoggingContext.responseCode(LoggingContext.SUCCESS);
67 new JCommander(cArgs, args);
70 System.out.println("-c [path to graph configuration] -type [what you want to audit - oxm or graph]");
72 String config = cArgs.config;
74 try (TitanGraph graph = TitanFactory.open(new AAIGraphConfig.Builder(config).forService(ScriptDriver.class.getSimpleName()).withGraphType("NA").buildConfiguration())) {
75 if (!("oxm".equals(cArgs.type) || "graph".equals(cArgs.type))) {
76 System.out.println("type: " + cArgs.type + " not recognized.");
81 if ("oxm".equals(cArgs.type)) {
82 doc = AuditorFactory.getOXMAuditor(Version.v8).getAuditDoc();
83 } else if ("graph".equals(cArgs.type)) {
84 doc = AuditorFactory.getGraphAuditor(graph).getAuditDoc();
87 ObjectMapper mapper = new ObjectMapper();
89 String json = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(doc);
90 System.out.println(json);
96 class CommandLineArgs {
98 @Parameter(names = "--help", description = "Help")
99 public boolean help = false;
101 @Parameter(names = "-c", description = "Configuration", required=true)
102 public String config;
104 @Parameter(names = "-type", description = "Type", required=true)
105 public String type = "graph";