2 * ============LICENSE_START=======================================================
\r
4 * ================================================================================
\r
5 * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
\r
6 * ================================================================================
\r
7 * Licensed under the Apache License, Version 2.0 (the "License");
\r
8 * you may not use this file except in compliance with the License.
\r
9 * You may obtain a copy of the License at
\r
11 * http://www.apache.org/licenses/LICENSE-2.0
\r
13 * Unless required by applicable law or agreed to in writing, software
\r
14 * distributed under the License is distributed on an "AS IS" BASIS,
\r
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
16 * See the License for the specific language governing permissions and
\r
17 * limitations under the License.
\r
18 * ============LICENSE_END=========================================================
\r
20 package org.onap.aai.db.schema;
\r
22 import java.io.IOException;
\r
23 import java.util.UUID;
\r
25 import com.fasterxml.jackson.databind.ObjectMapper;
\r
26 import org.apache.commons.configuration.ConfigurationException;
\r
27 import org.apache.commons.configuration.PropertiesConfiguration;
\r
28 import org.codehaus.jackson.JsonGenerationException;
\r
29 import org.onap.aai.dbmap.AAIGraphConfig;
\r
30 import org.onap.aai.edges.EdgeIngestor;
\r
31 import org.onap.aai.exceptions.AAIException;
\r
32 import org.onap.aai.setup.SchemaVersions;
\r
33 import org.onap.aai.logging.LoggingContext;
\r
34 import org.onap.aai.logging.LoggingContext.StatusCode;
\r
35 import org.onap.aai.util.AAIConfig;
\r
36 import com.beust.jcommander.JCommander;
\r
37 import com.beust.jcommander.Parameter;
\r
38 import org.janusgraph.core.JanusGraphFactory;
\r
39 import org.janusgraph.core.JanusGraph;
\r
40 import org.springframework.context.annotation.AnnotationConfigApplicationContext;
\r
42 public class ScriptDriver {
\r
47 * @param args the arguments
\r
48 * @throws AAIException the AAI exception
\r
49 * @throws JsonGenerationException the json generation exception
\r
50 * @throws IOException Signals that an I/O exception has occurred.
\r
52 public static void main (String[] args) throws AAIException, IOException, ConfigurationException {
\r
53 CommandLineArgs cArgs = new CommandLineArgs();
\r
55 LoggingContext.init();
\r
56 LoggingContext.component("DBSchemaScriptDriver");
\r
57 LoggingContext.partnerName("NA");
\r
58 LoggingContext.targetEntity("AAI");
\r
59 LoggingContext.requestId(UUID.randomUUID().toString());
\r
60 LoggingContext.serviceName("AAI");
\r
61 LoggingContext.targetServiceName("main");
\r
62 LoggingContext.statusCode(StatusCode.COMPLETE);
\r
63 LoggingContext.responseCode(LoggingContext.SUCCESS);
\r
65 new JCommander(cArgs, args);
\r
68 System.out.println("-c [path to graph configuration] -type [what you want to audit - oxm or graph]");
\r
71 AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(
\r
72 "org.onap.aai.config",
\r
73 "org.onap.aai.setup"
\r
76 AuditorFactory auditorFactory = ctx.getBean(AuditorFactory.class);
\r
77 SchemaVersions schemaVersions = ctx.getBean(SchemaVersions.class);
\r
78 EdgeIngestor edgeIngestor = ctx.getBean(EdgeIngestor.class);
\r
80 String config = cArgs.config;
\r
83 PropertiesConfiguration graphConfiguration = new AAIGraphConfig
\r
85 .forService(ScriptDriver.class.getSimpleName())
\r
86 .withGraphType("NA")
\r
87 .buildConfiguration();
\r
89 try (JanusGraph graph = JanusGraphFactory.open(graphConfiguration)) {
\r
90 if (!("oxm".equals(cArgs.type) || "graph".equals(cArgs.type))) {
\r
91 System.out.println("type: " + cArgs.type + " not recognized.");
\r
95 AuditDoc doc = null;
\r
96 if ("oxm".equals(cArgs.type)) {
\r
97 doc = auditorFactory.getOXMAuditor(schemaVersions.getDefaultVersion(), edgeIngestor).getAuditDoc();
\r
98 } else if ("graph".equals(cArgs.type)) {
\r
99 doc = auditorFactory.getGraphAuditor(graph).getAuditDoc();
\r
102 ObjectMapper mapper = new ObjectMapper();
\r
104 String json = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(doc);
\r
105 System.out.println(json);
\r
111 class CommandLineArgs {
\r
113 @Parameter(names = "--help", description = "Help")
\r
114 public boolean help = false;
\r
116 @Parameter(names = "-c", description = "Configuration", required=true)
\r
117 public String config;
\r
119 @Parameter(names = "-type", description = "Type", required=true)
\r
120 public String type = "graph";
\r