2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017-2018 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 package org.onap.aai.db.schema;
22 import java.io.IOException;
23 import java.util.UUID;
25 import org.apache.commons.configuration.ConfigurationException;
26 import org.codehaus.jackson.JsonGenerationException;
27 import org.codehaus.jackson.map.JsonMappingException;
28 import org.codehaus.jackson.map.ObjectMapper;
29 import org.onap.aai.dbmap.AAIGraphConfig;
30 import org.onap.aai.exceptions.AAIException;
31 import org.onap.aai.introspection.Version;
32 import org.onap.aai.logging.LoggingContext;
33 import org.onap.aai.logging.LoggingContext.StatusCode;
34 import org.onap.aai.util.AAIConfig;
35 import com.beust.jcommander.JCommander;
36 import com.beust.jcommander.Parameter;
37 import com.thinkaurelius.titan.core.TitanFactory;
38 import com.thinkaurelius.titan.core.TitanGraph;
40 public class ScriptDriver {
46 * @param args the arguments
47 * @throws AAIException the AAI exception
48 * @throws JsonGenerationException the json generation exception
49 * @throws JsonMappingException the json mapping exception
50 * @throws IOException Signals that an I/O exception has occurred.
52 public static void main (String[] args) throws AAIException, IOException, ConfigurationException {
53 CommandLineArgs cArgs = new CommandLineArgs();
55 LoggingContext.init();
56 LoggingContext.component("DBSchemaScriptDriver");
57 LoggingContext.partnerName("NA");
58 LoggingContext.targetEntity("AAI");
59 LoggingContext.requestId(UUID.randomUUID().toString());
60 LoggingContext.serviceName("AAI");
61 LoggingContext.targetServiceName("main");
62 LoggingContext.statusCode(StatusCode.COMPLETE);
63 LoggingContext.responseCode(LoggingContext.SUCCESS);
65 new JCommander(cArgs, args);
68 System.out.println("-c [path to graph configuration] -type [what you want to audit - oxm or graph]");
70 String config = cArgs.config;
72 try (TitanGraph graph = TitanFactory.open(new AAIGraphConfig.Builder(config).forService(ScriptDriver.class.getSimpleName()).withGraphType("NA").buildConfiguration())) {
73 if (!("oxm".equals(cArgs.type) || "graph".equals(cArgs.type))) {
74 System.out.println("type: " + cArgs.type + " not recognized.");
79 if ("oxm".equals(cArgs.type)) {
80 doc = AuditorFactory.getOXMAuditor(Version.v8).getAuditDoc();
81 } else if ("graph".equals(cArgs.type)) {
82 doc = AuditorFactory.getGraphAuditor(graph).getAuditDoc();
85 ObjectMapper mapper = new ObjectMapper();
87 String json = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(doc);
88 System.out.println(json);
94 class CommandLineArgs {
96 @Parameter(names = "--help", description = "Help")
97 public boolean help = false;
99 @Parameter(names = "-c", description = "Configuration", required=true)
100 public String config;
102 @Parameter(names = "-type", description = "Type", required=true)
103 public String type = "graph";