summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorManisha Aggarwal <ma9181@att.com>2017-08-03 05:35:56 +0000
committerGerrit Code Review <gerrit@onap.org>2017-08-03 05:35:56 +0000
commit72c57e8251e724c609a9a1c64fa7d0f56446ee36 (patch)
tree2b7c8314cb8fc0bbcd191250081b3d87816f5bc9 /src
parentb23528b8b1f60ff4f2f87a654f7a5d3f3edbbd0f (diff)
parent02780597dbdf84a3b7d9d399a8e7da18a83da074 (diff)
Merge "[AAI-125] DataRouter to consume aai-schema jar"
Diffstat (limited to 'src')
-rw-r--r--src/main/java/org/openecomp/datarouter/logging/DataRouterMsgs.java8
-rw-r--r--src/main/java/org/openecomp/datarouter/policy/EntityEventPolicy.java3
-rw-r--r--src/main/java/org/openecomp/datarouter/util/OxmModelLoader.java108
-rw-r--r--src/main/java/org/openecomp/datarouter/util/Version.java2
-rw-r--r--src/main/resources/logging/DataRouterMsgs.properties7
5 files changed, 60 insertions, 68 deletions
diff --git a/src/main/java/org/openecomp/datarouter/logging/DataRouterMsgs.java b/src/main/java/org/openecomp/datarouter/logging/DataRouterMsgs.java
index 701c74e..b59721c 100644
--- a/src/main/java/org/openecomp/datarouter/logging/DataRouterMsgs.java
+++ b/src/main/java/org/openecomp/datarouter/logging/DataRouterMsgs.java
@@ -154,6 +154,14 @@ public enum DataRouterMsgs implements LogMessageEnum {
INVALID_OXM_FILE,
INVALID_OXM_DIR,
+ LOAD_OXM_ERROR,
+ /**
+ * Successfully loaded schema: {0}
+ *
+ * <p>Arguments:
+ * {0} = oxm filename
+ */
+ LOADED_OXM_FILE,
/**
* Arguments: {0} = origin payload
diff --git a/src/main/java/org/openecomp/datarouter/policy/EntityEventPolicy.java b/src/main/java/org/openecomp/datarouter/policy/EntityEventPolicy.java
index 1cb8a67..7b57cc0 100644
--- a/src/main/java/org/openecomp/datarouter/policy/EntityEventPolicy.java
+++ b/src/main/java/org/openecomp/datarouter/policy/EntityEventPolicy.java
@@ -23,6 +23,7 @@
package org.openecomp.datarouter.policy;
import java.io.BufferedReader;
+import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
@@ -132,7 +133,7 @@ public class EntityEventPolicy implements Processor {
SUCCESS, PARTIAL_SUCCESS, FAILURE;
};
- public EntityEventPolicy(EntityEventPolicyConfig config) {
+ public EntityEventPolicy(EntityEventPolicyConfig config) throws FileNotFoundException {
LoggerFactory loggerFactoryInstance = LoggerFactory.getInstance();
logger = loggerFactoryInstance.getLogger(EntityEventPolicy.class.getName());
metricsLogger = loggerFactoryInstance.getMetricsLogger(EntityEventPolicy.class.getName());
diff --git a/src/main/java/org/openecomp/datarouter/util/OxmModelLoader.java b/src/main/java/org/openecomp/datarouter/util/OxmModelLoader.java
index af78a09..4fb1ca7 100644
--- a/src/main/java/org/openecomp/datarouter/util/OxmModelLoader.java
+++ b/src/main/java/org/openecomp/datarouter/util/OxmModelLoader.java
@@ -22,18 +22,14 @@
*/
package org.openecomp.datarouter.util;
-import java.io.File;
-import java.io.FileInputStream;
import java.io.FileNotFoundException;
+import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Collection;
-import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import java.util.Timer;
-import java.util.TimerTask;
import java.util.concurrent.ConcurrentHashMap;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -48,11 +44,13 @@ import org.openecomp.cl.eelf.LoggerFactory;
import org.openecomp.datarouter.logging.DataRouterMsgs;
import org.openecomp.datarouter.util.ExternalOxmModelProcessor;
+import org.springframework.core.io.Resource;
+import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
+import org.springframework.core.io.support.ResourcePatternResolver;
public class OxmModelLoader {
- private static Map<String, DynamicJAXBContext> versionContextMap = new ConcurrentHashMap<String, DynamicJAXBContext>();
- private static Map<String, Timer> timers = new ConcurrentHashMap<String, Timer>();
+ private static Map<String, DynamicJAXBContext> versionContextMap = new ConcurrentHashMap<String, DynamicJAXBContext>();
private static List<ExternalOxmModelProcessor> oxmModelProcessorRegistry = new ArrayList<ExternalOxmModelProcessor>();
final static Pattern p = Pattern.compile("aai_oxm_(.*).xml");
@@ -61,62 +59,44 @@ public class OxmModelLoader {
private static org.openecomp.cl.api.Logger logger = LoggerFactory.getInstance()
.getLogger(OxmModelLoader.class.getName());
- public synchronized static void loadModels() {
+ public synchronized static void loadModels() throws FileNotFoundException {
+
+ ClassLoader cl = OxmModelLoader.class.getClassLoader();
+ ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(cl);
+ Resource[] resources;
+ try {
+ resources = resolver.getResources("classpath*:/oxm/aai_oxm*.xml");
+ } catch (IOException ex) {
+ logger.error(DataRouterMsgs.LOAD_OXM_ERROR, ex.getMessage());
+ throw new FileNotFoundException("Unable to load OXM models from schema path : /oxm/aai_oxm*.xml");
+ }
+
+ if (resources.length == 0) {
+ logger.error(DataRouterMsgs.LOAD_OXM_ERROR, "No OXM schema files found on classpath");
+ throw new FileNotFoundException("Unable to load OXM models from schema path : /oxm/aai_oxm*.xml");
+ }
+
+ for (Resource resource : resources) {
+ Matcher matcher = p.matcher(resource.getFilename());
+
+ if (matcher.matches()) {
+ try {
+ OxmModelLoader.loadModel(matcher.group(1), resource.getFilename(),resource.getInputStream());
+ } catch (Exception e) {
+ logger.error(DataRouterMsgs.LOAD_OXM_ERROR, "Failed to load " + resource.getFilename()
+ + ": " + e.getMessage());
+ }
+ }
+ }
+
- File[] listOfFiles = new File(DataRouterConstants.DR_HOME_MODEL).listFiles();
-
- if (listOfFiles != null) {
- for (File file : listOfFiles) {
- if (file.isFile()) {
- Matcher m = p.matcher(file.getName());
- if (m.matches()) {
- try {
- OxmModelLoader.loadModel(m.group(1), file);
- } catch (Exception e) {
- logger.error(DataRouterMsgs.INVALID_OXM_FILE, file.getName(), e.getMessage());
- }
- }
-
- }
- }
- } else {
- logger.error(DataRouterMsgs.INVALID_OXM_DIR, DataRouterConstants.DR_HOME_MODEL);
- }
-
-
}
- private static void addtimer(String version,File file){
- TimerTask task = null;
- task = new FileWatcher(
- file) {
- protected void onChange(File file) {
- // here we implement the onChange
- logger.info(DataRouterMsgs.FILE_CHANGED, file.getName());
-
- try {
- OxmModelLoader.loadModel(version,file);
- } catch (Exception e) {
- e.printStackTrace();
- }
-
- }
- };
-
- if (!timers.containsKey(version)) {
- Timer timer = new Timer("oxm-"+version);
- timer.schedule(task, new Date(), 10000);
- timers.put(version, timer);
-
- }
- }
-
- private synchronized static void loadModel(String version,File file) throws JAXBException, FileNotFoundException {
+
-
- InputStream iStream = new FileInputStream(file);
+ private synchronized static void loadModel(String version,String resourceName,InputStream inputStream) throws JAXBException, FileNotFoundException {
Map<String, Object> properties = new HashMap<String, Object>();
- properties.put(JAXBContextProperties.OXM_METADATA_SOURCE, iStream);
+ properties.put(JAXBContextProperties.OXM_METADATA_SOURCE, inputStream);
final DynamicJAXBContext jaxbContext = DynamicJAXBContextFactory
.createContextFromOXM(Thread.currentThread().getContextClassLoader(), properties);
versionContextMap.put(version, jaxbContext);
@@ -124,20 +104,16 @@ public class OxmModelLoader {
for ( ExternalOxmModelProcessor processor : oxmModelProcessorRegistry ) {
processor.onOxmVersionChange(Version.valueOf(version), jaxbContext );
}
- }
- addtimer(version,file);
-
+ }
+ logger.info(DataRouterMsgs.LOADED_OXM_FILE, resourceName);
}
public static DynamicJAXBContext getContextForVersion(String version) throws Exception {
if (versionContextMap == null || versionContextMap.isEmpty()) {
loadModels();
- } else if (!versionContextMap.containsKey(version)) {
- try {
- loadModel(version,new File (DataRouterConstants.DR_HOME_MODEL + "aai_oxm_" + version + ".xml"));
- } catch (Exception e) {
+ } else if (!versionContextMap.containsKey(version)) {
throw new Exception(Status.NOT_FOUND.toString());
- }
+
}
return versionContextMap.get(version);
diff --git a/src/main/java/org/openecomp/datarouter/util/Version.java b/src/main/java/org/openecomp/datarouter/util/Version.java
index 5d74254..7ffce94 100644
--- a/src/main/java/org/openecomp/datarouter/util/Version.java
+++ b/src/main/java/org/openecomp/datarouter/util/Version.java
@@ -23,5 +23,5 @@
package org.openecomp.datarouter.util;
public enum Version {
- v2, v3, v4, v5, v6, v7, v8, v9, v10;
+ v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20;
} \ No newline at end of file
diff --git a/src/main/resources/logging/DataRouterMsgs.properties b/src/main/resources/logging/DataRouterMsgs.properties
index fbb24c4..fff262c 100644
--- a/src/main/resources/logging/DataRouterMsgs.properties
+++ b/src/main/resources/logging/DataRouterMsgs.properties
@@ -96,6 +96,10 @@ ROUTING_RESPONSE=\
OP_TIME=\
DR0013I|\
{0} took {1} ms.
+
+LOADED_OXM_FILE=\
+ DR0014I|\
+ Successfully loaded schema: {0}
STARTUP_FAILURE=\
DR2001E|\
@@ -164,3 +168,6 @@ JSON_CONVERSION_ERROR=\
FAIL_TO_CREATE_UPDATE_DOC=\
DR3015E|\
Failed to create or update document in index {0}. Cause: {1}
+LOAD_OXM_ERROR=\
+ DR5000E|\
+ Unable to load Oxm model: {0}\