diff options
Diffstat (limited to 'aai-traversal/src/main/java/org/onap/aai/rest/search/GremlinServerSingleton.java')
-rw-r--r-- | aai-traversal/src/main/java/org/onap/aai/rest/search/GremlinServerSingleton.java | 93 |
1 files changed, 39 insertions, 54 deletions
diff --git a/aai-traversal/src/main/java/org/onap/aai/rest/search/GremlinServerSingleton.java b/aai-traversal/src/main/java/org/onap/aai/rest/search/GremlinServerSingleton.java index a39bc03..20a18d9 100644 --- a/aai-traversal/src/main/java/org/onap/aai/rest/search/GremlinServerSingleton.java +++ b/aai-traversal/src/main/java/org/onap/aai/rest/search/GremlinServerSingleton.java @@ -8,7 +8,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -25,7 +25,9 @@ import org.onap.aai.util.FileWatcher; import com.att.eelf.configuration.EELFLogger; import com.att.eelf.configuration.EELFManager; import org.apache.tinkerpop.gremlin.driver.Cluster; +import org.springframework.beans.factory.annotation.Value; +import javax.annotation.PostConstruct; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; @@ -42,23 +44,13 @@ public class GremlinServerSingleton { private static EELFLogger logger = EELFManager.getInstance().getLogger(GremlinServerSingleton.class); - private Cluster cluster; private boolean timerSet; private Timer timer; - private GetCustomQueryConfig queryConfig; - - private static class Helper { - - private static final GremlinServerSingleton INSTANCE = new GremlinServerSingleton(); - } - private GremlinServerSingleton() { - init(); - } + private GetCustomQueryConfig queryConfig; - public static GremlinServerSingleton getInstance() { - return Helper.INSTANCE; - } + @Value("${schema.queries.location}") + private String storedQueriesLocation; /** * Initializes the gremlin server singleton @@ -67,67 +59,60 @@ public class GremlinServerSingleton { * Then creates a file watcher to watch the file every ten seconds * and if there is a change in the file, then reloads the file into * the properties object + * */ - private void init() { - - try { - cluster = Cluster.build(new File(AAIConstants.AAI_HOME_ETC_APP_PROPERTIES + "gremlin-server-config.yaml")) - .maxContentLength(6537920) - .create(); - } catch (FileNotFoundException e) { - logger.error("Unable to find the file: " + LogFormatTools.getStackTop(e)); - } + @PostConstruct + public void init() { - try { - String filepath = GetCustomQueryConfig.AAI_HOME_ETC_QUERY_JSON; - Path path = Paths.get(filepath); - String customQueryConfigJson = new String(Files.readAllBytes(path)); + try { + String filepath = storedQueriesLocation + AAIConstants.AAI_FILESEP + "stored-queries.json"; + Path path = Paths.get(filepath); + String customQueryConfigJson = new String(Files.readAllBytes(path)); + - queryConfig = new GetCustomQueryConfig(customQueryConfigJson); - } catch (IOException e) { - logger.error("Error occurred during the processing of query json file: " + LogFormatTools.getStackTop(e)); - } + queryConfig = new GetCustomQueryConfig(customQueryConfigJson); + } catch (IOException e) { + logger.error("Error occurred during the processing of query json file: " + LogFormatTools.getStackTop(e)); + } - TimerTask task = new FileWatcher(new File(GetCustomQueryConfig.AAI_HOME_ETC_QUERY_JSON)) { + + TimerTask task = new FileWatcher(new File(storedQueriesLocation)) { @Override protected void onChange(File file) { - try { - String filepath = GetCustomQueryConfig.AAI_HOME_ETC_QUERY_JSON; - Path path = Paths.get(filepath); - String customQueryConfigJson = new String(Files.readAllBytes(path)); - queryConfig = new GetCustomQueryConfig(customQueryConfigJson); - } catch (IOException e) { - logger.error( - "Error occurred during the processing of query json file: " + LogFormatTools.getStackTop(e)); - } + try { + String filepath = storedQueriesLocation; + Path path = Paths.get(filepath); + String customQueryConfigJson = new String(Files.readAllBytes(path)); + queryConfig = new GetCustomQueryConfig(customQueryConfigJson); + } catch (IOException e) { + logger.error("Error occurred during the processing of query json file: " + LogFormatTools.getStackTop(e)); + } } }; if (!timerSet) { timerSet = true; timer = new Timer(); - timer.schedule(task, new Date(), 10000); + timer.schedule( task , new Date(), 10000 ); } } - public Cluster getCluster() { - return cluster; - } - /** * Gets the query using CustomQueryConfig + * @param key + * @return */ - public String getStoredQueryFromConfig(String key) { - CustomQueryConfig customQueryConfig = queryConfig.getStoredQuery(key); - if (customQueryConfig == null) { - return null; - } - return customQueryConfig.getQuery(); + public String getStoredQueryFromConfig(String key){ + CustomQueryConfig customQueryConfig = queryConfig.getStoredQuery(key); + if ( customQueryConfig == null ) { + return null; + } + return customQueryConfig.getQuery(); } - + public CustomQueryConfig getCustomQueryConfig(String key) { - return queryConfig.getStoredQuery(key); + return queryConfig.getStoredQuery(key); } |