Merge "Sync up the changes between ecomp and onap"
authorJames Forsyth <jf2512@att.com>
Thu, 6 Sep 2018 14:52:47 +0000 (14:52 +0000)
committerGerrit Code Review <gerrit@onap.org>
Thu, 6 Sep 2018 14:52:47 +0000 (14:52 +0000)
aai-core/src/main/java/org/onap/aai/config/IntrospectionConfig.java
aai-core/src/main/java/org/onap/aai/config/RestBeanConfig.java
aai-core/src/main/java/org/onap/aai/config/SchemaConfiguration.java
aai-core/src/main/java/org/onap/aai/config/SwaggerGenerationConfiguration.java
aai-core/src/main/java/org/onap/aai/db/props/AAIProperties.java
aai-core/src/main/java/org/onap/aai/dbmap/AAIGraph.java

index e0ce203..aa4ec1a 100644 (file)
@@ -4,6 +4,8 @@
  * ================================================================================
  * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
  * ================================================================================
+ * Modifications Copyright © 2018 IBM.
+ * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
@@ -35,23 +37,22 @@ import org.onap.aai.nodes.NodeIngestor;
 @Configuration
 public class IntrospectionConfig {
 
-       private Map<SchemaVersion, MoxyLoader> MOXYINSTANCEMAP = new ConcurrentHashMap<>();
-       @Autowired
-       NodeIngestor nodeIngestor;
+    private Map<SchemaVersion, MoxyLoader> moxyInstanceMap = new ConcurrentHashMap<>();
+    @Autowired
+    NodeIngestor nodeIngestor;
 
-       @Bean
-       public LoaderFactory loaderFactory(SchemaVersions schemaVersions) {
-               LoaderFactory loaderFactory = new LoaderFactory(moxyLoaderInstance(schemaVersions));
-               return loaderFactory;
-       }
+    @Bean
+    public LoaderFactory loaderFactory(SchemaVersions schemaVersions) {
+        return new LoaderFactory(moxyLoaderInstance(schemaVersions));
+    }
 
-       @Bean
-       public Map<SchemaVersion, MoxyLoader> moxyLoaderInstance(SchemaVersions schemaVersions) {
-           for(SchemaVersion version : schemaVersions.getVersions()){
-                       if (!MOXYINSTANCEMAP.containsKey(version)) {
-                               MOXYINSTANCEMAP.put(version, new MoxyLoader(version, nodeIngestor));
-                       }
-               }
-               return MOXYINSTANCEMAP;
-       }
+    @Bean
+    public Map<SchemaVersion, MoxyLoader> moxyLoaderInstance(SchemaVersions schemaVersions) {
+        for(SchemaVersion version : schemaVersions.getVersions()){
+            if (!moxyInstanceMap.containsKey(version)) {
+                moxyInstanceMap.put(version, new MoxyLoader(version, nodeIngestor));
+            }
+        }
+        return moxyInstanceMap;
+    }
 }
index 2976329..6c56ff6 100644 (file)
@@ -4,6 +4,8 @@
  * ================================================================================
  * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
  * ================================================================================
+ * Modifications Copyright © 2018 IBM.
+ * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
@@ -31,21 +33,18 @@ import org.springframework.context.annotation.Scope;
 
 @Configuration
 public class RestBeanConfig {
-       @Bean(name = "traversalUriHttpEntry")
-       @Scope(scopeName = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
-       public HttpEntry traversalUriHttpEntry() {
-               HttpEntry httpEntry = new HttpEntry(ModelType.MOXY, QueryStyle.TRAVERSAL_URI);
-               return httpEntry;
-       }
-       
-       @Bean(name = "traversalHttpEntry")
-       @Scope(scopeName = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
-       public HttpEntry traversalHttpEntry() {
-               HttpEntry httpEntry = new HttpEntry(ModelType.MOXY, QueryStyle.TRAVERSAL);
-               
-               return httpEntry;
-       }
-       
-       
+    @Bean(name = "traversalUriHttpEntry")
+    @Scope(scopeName = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
+    public HttpEntry traversalUriHttpEntry() {
+        return new HttpEntry(ModelType.MOXY, QueryStyle.TRAVERSAL_URI);
+    }
+    
+    @Bean(name = "traversalHttpEntry")
+    @Scope(scopeName = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
+    public HttpEntry traversalHttpEntry() {
+        return new HttpEntry(ModelType.MOXY, QueryStyle.TRAVERSAL);
+    }
+    
+    
     
 }
index 20112bd..b00ecfb 100644 (file)
@@ -4,6 +4,8 @@
  * ================================================================================
  * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
  * ================================================================================
+ * Modifications Copyright © 2018 IBM.
+ * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
@@ -43,20 +45,18 @@ public class SchemaConfiguration {
         return new EdgeSerializer(edgeIngestor);
     }
     
-       @Bean(name = "nodeIngestor")
-       public NodeIngestor nodeIngestor(ConfigTranslator configTranslator) {
-               NodeIngestor nodeIngestor = new NodeIngestor(configTranslator);
-               return nodeIngestor;
-       }
+    @Bean(name = "nodeIngestor")
+    public NodeIngestor nodeIngestor(ConfigTranslator configTranslator) {
+        return new NodeIngestor(configTranslator);
+    }
 
-       @Bean(name = "configTranslator")
-       public ConfigTranslator configTranslator(SchemaLocationsBean schemaLocationsBean, SchemaVersions schemaVersions) {
-               ConfigTranslator aaiConfigTranslator = new AAIConfigTranslator(schemaLocationsBean, schemaVersions);
-               return aaiConfigTranslator;
-       }
+    @Bean(name = "configTranslator")
+    public ConfigTranslator configTranslator(SchemaLocationsBean schemaLocationsBean, SchemaVersions schemaVersions) {
+        return new AAIConfigTranslator(schemaLocationsBean, schemaVersions);
+    }
 
-       @Bean
-       public SchemaErrorStrategy schemaErrorStrategy(){
+    @Bean
+    public SchemaErrorStrategy schemaErrorStrategy(){
         return new CheckEverythingStrategy();
-       }
+    }
 }
index a09018a..fbbb703 100644 (file)
@@ -4,6 +4,8 @@
  * ================================================================================
  * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
  * ================================================================================
+ * Modifications Copyright © 2018 IBM.
+ * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
@@ -35,28 +37,25 @@ import org.springframework.context.annotation.Scope;
 @Configuration
 public class SwaggerGenerationConfiguration {
 
-       @Value("${schema.uri.base.path}")
-       private String basePath;
+    @Value("${schema.uri.base.path}")
+    private String basePath;
 
-       @Bean
-       @Scope(scopeName = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
-       public NodesYAMLfromOXM nodesYamlFromOXM(SchemaVersions schemaVersions, NodeIngestor nodeIngestor, EdgeIngestor edgeIngestor) {
-               NodesYAMLfromOXM nodesYamlFromOXM = new NodesYAMLfromOXM(basePath, schemaVersions, nodeIngestor, edgeIngestor);
-               return nodesYamlFromOXM;
-       }
-       
-       @Bean
-       @Scope(scopeName = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
-       public HTMLfromOXM htmlFromOXM(SchemaVersions schemaVersions, NodeIngestor nodeIngestor, EdgeIngestor edgeIngestor) {
-               HTMLfromOXM htmlFromOXM = new HTMLfromOXM(schemaVersions, nodeIngestor, edgeIngestor);
-               return htmlFromOXM;
-       }
-       
-       @Bean
-       @Scope(scopeName = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
-       public YAMLfromOXM yamlFromOXM(SchemaVersions schemaVersions, NodeIngestor nodeIngestor, EdgeIngestor edgeIngestor) {
-               YAMLfromOXM yamlFromOXM = new YAMLfromOXM(basePath, schemaVersions, nodeIngestor, edgeIngestor);
-               return yamlFromOXM;
-       }
+    @Bean
+    @Scope(scopeName = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
+    public NodesYAMLfromOXM nodesYamlFromOXM(SchemaVersions schemaVersions, NodeIngestor nodeIngestor, EdgeIngestor edgeIngestor) {
+        return new NodesYAMLfromOXM(basePath, schemaVersions, nodeIngestor, edgeIngestor);
+    }
+    
+    @Bean
+    @Scope(scopeName = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
+    public HTMLfromOXM htmlFromOXM(SchemaVersions schemaVersions, NodeIngestor nodeIngestor, EdgeIngestor edgeIngestor) {
+        return new HTMLfromOXM(schemaVersions, nodeIngestor, edgeIngestor);
+    }
+    
+    @Bean
+    @Scope(scopeName = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
+    public YAMLfromOXM yamlFromOXM(SchemaVersions schemaVersions, NodeIngestor nodeIngestor, EdgeIngestor edgeIngestor) {
+        return new YAMLfromOXM(basePath, schemaVersions, nodeIngestor, edgeIngestor);
+    }
     
 }
index 47e79a3..6b4035c 100644 (file)
@@ -4,6 +4,8 @@
  * ================================================================================
  * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
  * ================================================================================
+ *  Modifications Copyright © 2018 IBM.
+ * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
 package org.onap.aai.db.props;
 
 public class AAIProperties {
-       public static final String NODE_TYPE = "aai-node-type";
-       public static final String LAST_MOD_SOURCE_OF_TRUTH = "last-mod-source-of-truth";
-       public static final String SOURCE_OF_TRUTH = "source-of-truth";
-       public static final String LAST_MOD_TS = "aai-last-mod-ts";
-       public static final String UNIQUE_KEY = "aai-unique-key";
-       public static final String CREATED_TS = "aai-created-ts";
-       public static final String RESOURCE_VERSION = "resource-version";
-       public static final String AAI_URI = "aai-uri";
-       public static final Integer MAXIMUM_DEPTH = 10000;
-       public static final String LINKED = "linked";
-       public static final String DB_ALIAS_SUFFIX = "-local";
-       public static final String AAI_UUID = "aai-uuid";
+    public static final String NODE_TYPE = "aai-node-type";
+    public static final String LAST_MOD_SOURCE_OF_TRUTH = "last-mod-source-of-truth";
+    public static final String SOURCE_OF_TRUTH = "source-of-truth";
+    public static final String LAST_MOD_TS = "aai-last-mod-ts";
+    public static final String UNIQUE_KEY = "aai-unique-key";
+    public static final String CREATED_TS = "aai-created-ts";
+    public static final String RESOURCE_VERSION = "resource-version";
+    public static final String AAI_URI = "aai-uri";
+    public static final Integer MAXIMUM_DEPTH = 10000;
+    public static final String LINKED = "linked";
+    public static final String DB_ALIAS_SUFFIX = "-local";
+    public static final String AAI_UUID = "aai-uuid";
+    
+    private AAIProperties() {
+        
+    }
 
 }
index aae3aaa..84218e8 100644 (file)
@@ -4,6 +4,8 @@
  * ================================================================================
  * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
  * ================================================================================
+ *  Modifications Copyright © 2018 IBM.
+ * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
@@ -54,151 +56,154 @@ import org.janusgraph.core.schema.JanusGraphManagement;
  */
 public class AAIGraph {
 
-       private static final EELFLogger logger = EELFManager.getInstance().getLogger(AAIGraph.class);
-       protected static final String COMPONENT = "aaidbmap";
-       protected Map<String, JanusGraph> graphs = new HashMap<>();
-       private static final String REALTIME_DB = "realtime";
-       private static final String CACHED_DB = "cached";
-       private static boolean isInit = false;
-
-
-
-       /**
-        * Instantiates a new AAI graph.
-        */
-       private AAIGraph() {
-               try {
-                       String serviceName = System.getProperty("aai.service.name", "NA");
-                       String rtConfig = System.getProperty("realtime.db.config");
-                       String cachedConfig = System.getProperty("cached.db.config");
-                       if (rtConfig == null) {
-                               rtConfig = AAIConstants.REALTIME_DB_CONFIG;
-                       }
-                       if (cachedConfig == null) {
-                               cachedConfig = AAIConstants.CACHED_DB_CONFIG;
-                       }
-                       this.loadGraph(REALTIME_DB, rtConfig, serviceName);
-                       this.loadGraph(CACHED_DB, cachedConfig, serviceName);
-               } catch (Exception e) {
-                       throw new RuntimeException("Failed to instantiate graphs", e);
-               }
-       }
-       
-       private static class Helper {
-               private static final AAIGraph INSTANCE = new AAIGraph();
-       }
-       
-       /**
-        * Gets the single instance of AAIGraph.
-        *
-        * @return single instance of AAIGraph
-        */
-       public static AAIGraph getInstance() {
-               isInit = true;
-               return Helper.INSTANCE;
-       }
-
-       public static boolean isInit() {
-               return isInit;
-       }
-       
-       private void loadGraph(String name, String configPath, String serviceName) throws Exception {
-           // Graph being opened by JanusGraphFactory is being placed in hashmap to be used later
-               // These graphs shouldn't be closed until the application shutdown
-               try {
-                       PropertiesConfiguration propertiesConfiguration = new AAIGraphConfig.Builder(configPath).forService(serviceName).withGraphType(name).buildConfiguration();
-                       JanusGraph graph = JanusGraphFactory.open(propertiesConfiguration);
-
-                       Properties graphProps = new Properties();
-                       propertiesConfiguration.getKeys().forEachRemaining(k -> graphProps.setProperty(k, propertiesConfiguration.getString(k)));
-
-                       if ("inmemory".equals(graphProps.get("storage.backend"))) {
-                               // Load the propertyKeys, indexes and edge-Labels into the DB
-                               loadSchema(graph);
-                               loadSnapShotToInMemoryGraph(graph, graphProps);
-                       }
-
-                       if (graph == null) {
-                               throw new AAIException("AAI_5102");
-                       }
-
-                       graphs.put(name, graph);
-               } catch (FileNotFoundException fnfe) {
-                       throw new AAIException("AAI_4001");
-           } catch (IOException e) {
-                       throw new AAIException("AAI_4002");
-           }
-       }
-
-       private void loadSnapShotToInMemoryGraph(JanusGraph graph, Properties graphProps) {
-               if (logger.isDebugEnabled()) {
-                       logger.debug("Load Snapshot to InMemory Graph");
-               }
-               if (graphProps.containsKey("load.snapshot.file")) {
-                       String value = graphProps.getProperty("load.snapshot.file");
-                       if ("true".equals(value)) {
-                               try (Graph transaction = graph.newTransaction()) {
-                                       String location = System.getProperty("snapshot.location");
-                                       logAndPrint(logger, "Loading snapshot to inmemory graph.");
-                                       transaction.io(IoCore.graphson()).readGraph(location);
-                                       transaction.tx().commit();
-                                       logAndPrint(logger, "Snapshot loaded to inmemory graph.");
-                               } catch (Exception e) {
-                                       logAndPrint(logger,
-                                               "ERROR: Could not load datasnapshot to in memory graph. \n"
-                                                       + ExceptionUtils.getFullStackTrace(e));
-                                       throw new RuntimeException(e);
-                               }
-                       }
-               }
-       }
-
-       private void loadSchema(JanusGraph graph) {
-               // Load the propertyKeys, indexes and edge-Labels into the DB
-               JanusGraphManagement graphMgt = graph.openManagement();
-               
-               System.out.println("-- loading schema into JanusGraph");
-               SchemaGenerator.loadSchemaIntoJanusGraph( graph, graphMgt, "inmemory");
-       }
-
-       /**
-        * Close all of the graph connections made in the instance.
-        */
-       public void graphShutdown() {
-               graphs.values().stream().filter(JanusGraph::isOpen).forEach(JanusGraph::close);
-       }
-
-       /**
-        * Gets the graph.
-        *
-        * @return the graph
-        */
-       public JanusGraph getGraph() {
-               return graphs.get(REALTIME_DB);
-       }
-       
-       public void graphShutdown(DBConnectionType connectionType) {
-               
-               graphs.get(this.getGraphName(connectionType)).close();
-       }
-       
-       public JanusGraph getGraph(DBConnectionType connectionType) {
-               return graphs.get(this.getGraphName(connectionType));
-       }
-       
-       private String getGraphName(DBConnectionType connectionType) {
-               String graphName = "";
-               if (DBConnectionType.CACHED.equals(connectionType)) {
-                       graphName = this.CACHED_DB;
-               } else if (DBConnectionType.REALTIME.equals(connectionType)) {
-                       graphName = this.REALTIME_DB;
-               }
-               
-               return graphName;
-       }
-       
-       private void logAndPrint(EELFLogger logger, String msg) {
-               System.out.println(msg);
-               logger.info(msg);
-       }
+    private static final EELFLogger logger = EELFManager.getInstance().getLogger(AAIGraph.class);
+    protected static final String COMPONENT = "aaidbmap";
+    protected Map<String, JanusGraph> graphs = new HashMap<>();
+    private static final String REALTIME_DB = "realtime";
+    private static final String CACHED_DB = "cached";
+    private static boolean isInit = false;
+
+
+
+    /**
+     * Instantiates a new AAI graph.
+     */
+    private AAIGraph() {
+        try {
+            String serviceName = System.getProperty("aai.service.name", "NA");
+            String rtConfig = System.getProperty("realtime.db.config");
+            String cachedConfig = System.getProperty("cached.db.config");
+            if (rtConfig == null) {
+                rtConfig = AAIConstants.REALTIME_DB_CONFIG;
+            }
+            if (cachedConfig == null) {
+                cachedConfig = AAIConstants.CACHED_DB_CONFIG;
+            }
+            this.loadGraph(REALTIME_DB, rtConfig, serviceName);
+            this.loadGraph(CACHED_DB, cachedConfig, serviceName);
+        } catch (Exception e) {
+            throw new RuntimeException("Failed to instantiate graphs", e);
+        }
+    }
+    
+    private static class Helper {
+        private static final AAIGraph INSTANCE = new AAIGraph();
+        private Helper() {
+            
+        }
+    }
+    
+    /**
+     * Gets the single instance of AAIGraph.
+     *
+     * @return single instance of AAIGraph
+     */
+    public static AAIGraph getInstance() {
+        isInit = true;
+        return Helper.INSTANCE;
+    }
+
+    public static boolean isInit() {
+        return isInit;
+    }
+    
+    private void loadGraph(String name, String configPath, String serviceName) throws Exception {
+        // Graph being opened by JanusGraphFactory is being placed in hashmap to be used later
+        // These graphs shouldn't be closed until the application shutdown
+        try {
+            PropertiesConfiguration propertiesConfiguration = new AAIGraphConfig.Builder(configPath).forService(serviceName).withGraphType(name).buildConfiguration();
+            JanusGraph graph = JanusGraphFactory.open(propertiesConfiguration);
+
+            Properties graphProps = new Properties();
+            propertiesConfiguration.getKeys().forEachRemaining(k -> graphProps.setProperty(k, propertiesConfiguration.getString(k)));
+
+            if ("inmemory".equals(graphProps.get("storage.backend"))) {
+                // Load the propertyKeys, indexes and edge-Labels into the DB
+                loadSchema(graph);
+                loadSnapShotToInMemoryGraph(graph, graphProps);
+            }
+
+            if (graph == null) {
+                throw new AAIException("AAI_5102");
+            }
+
+            graphs.put(name, graph);
+        } catch (FileNotFoundException fnfe) {
+            throw new AAIException("AAI_4001");
+        } catch (IOException e) {
+            throw new AAIException("AAI_4002");
+        }
+    }
+
+    private void loadSnapShotToInMemoryGraph(JanusGraph graph, Properties graphProps) {
+        if (logger.isDebugEnabled()) {
+            logger.debug("Load Snapshot to InMemory Graph");
+        }
+        if (graphProps.containsKey("load.snapshot.file")) {
+            String value = graphProps.getProperty("load.snapshot.file");
+            if ("true".equals(value)) {
+                try (Graph transaction = graph.newTransaction()) {
+                    String location = System.getProperty("snapshot.location");
+                    logAndPrint(logger, "Loading snapshot to inmemory graph.");
+                    transaction.io(IoCore.graphson()).readGraph(location);
+                    transaction.tx().commit();
+                    logAndPrint(logger, "Snapshot loaded to inmemory graph.");
+                } catch (Exception e) {
+                    logAndPrint(logger,
+                        "ERROR: Could not load datasnapshot to in memory graph. \n"
+                            + ExceptionUtils.getFullStackTrace(e));
+                    throw new RuntimeException(e);
+                }
+            }
+        }
+    }
+
+    private void loadSchema(JanusGraph graph) {
+        // Load the propertyKeys, indexes and edge-Labels into the DB
+        JanusGraphManagement graphMgt = graph.openManagement();
+        
+        System.out.println("-- loading schema into JanusGraph");
+        SchemaGenerator.loadSchemaIntoJanusGraph( graph, graphMgt, "inmemory");
+    }
+
+    /**
+     * Close all of the graph connections made in the instance.
+     */
+    public void graphShutdown() {
+        graphs.values().stream().filter(JanusGraph::isOpen).forEach(JanusGraph::close);
+    }
+
+    /**
+     * Gets the graph.
+     *
+     * @return the graph
+     */
+    public JanusGraph getGraph() {
+        return graphs.get(REALTIME_DB);
+    }
+    
+    public void graphShutdown(DBConnectionType connectionType) {
+        
+        graphs.get(this.getGraphName(connectionType)).close();
+    }
+    
+    public JanusGraph getGraph(DBConnectionType connectionType) {
+        return graphs.get(this.getGraphName(connectionType));
+    }
+    
+    private String getGraphName(DBConnectionType connectionType) {
+        String graphName = "";
+        if (DBConnectionType.CACHED.equals(connectionType)) {
+            graphName = this.CACHED_DB;
+        } else if (DBConnectionType.REALTIME.equals(connectionType)) {
+            graphName = this.REALTIME_DB;
+        }
+        
+        return graphName;
+    }
+    
+    private void logAndPrint(EELFLogger logger, String msg) {
+        System.out.println(msg);
+        logger.info(msg);
+    }
 }