aboutsummaryrefslogtreecommitdiffstats
path: root/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'src/main')
-rw-r--r--src/main/bin/start.sh2
-rw-r--r--src/main/java/org/onap/aai/datarouter/logging/DataRouterMsgs.java5
-rw-r--r--src/main/java/org/onap/aai/datarouter/policy/AbstractSpikeEntityEventProcessor.java10
-rw-r--r--src/main/java/org/onap/aai/datarouter/policy/EntityEventPolicy.java6
-rw-r--r--src/main/java/org/onap/aai/datarouter/policy/SpikeAutosuggestIndexProcessor.java2
-rw-r--r--src/main/java/org/onap/aai/datarouter/policy/SpikeEntityEventPolicy.java6
-rw-r--r--src/main/java/org/onap/aai/datarouter/schema/OxmConfigTranslator.java98
-rw-r--r--src/main/java/org/onap/aai/datarouter/schema/OxmModelLoader.java101
-rw-r--r--src/main/java/org/onap/aai/datarouter/schema/SchemaIngestPropertiesReader.java88
-rw-r--r--src/main/java/org/onap/aai/datarouter/util/OxmModelLoader.java134
-rw-r--r--src/main/resources/logging/DataRouterMsgs.properties6
11 files changed, 309 insertions, 149 deletions
diff --git a/src/main/bin/start.sh b/src/main/bin/start.sh
index a54059b..ced887a 100644
--- a/src/main/bin/start.sh
+++ b/src/main/bin/start.sh
@@ -29,7 +29,7 @@ keytool -importkeystore -noprompt -deststorepass $PASS -destkeypass $PASS -srcke
## import into cacerts
sudo keytool -importkeystore -noprompt -deststorepass changeit -destkeypass changeit -destkeystore /$JAVA_HOME/jre/lib/security/cacerts -srckeystore $BASEDIR/config/auth/onap.p12 -srcstoretype PKCS12 -srcstorepass $PASS -alias tomcat
-
+PROPS="-DBASEDIR=$BASEDIR"
PROPS="-DAJSC_HOME=$AJSC_HOME"
PROPS="$PROPS -DAJSC_CONF_HOME=$AJSC_CONF_HOME"
PROPS="$PROPS -Dlogging.config=$BASEDIR/bundleconfig/etc/logback.xml"
diff --git a/src/main/java/org/onap/aai/datarouter/logging/DataRouterMsgs.java b/src/main/java/org/onap/aai/datarouter/logging/DataRouterMsgs.java
index 93f4c54..521a7c3 100644
--- a/src/main/java/org/onap/aai/datarouter/logging/DataRouterMsgs.java
+++ b/src/main/java/org/onap/aai/datarouter/logging/DataRouterMsgs.java
@@ -194,7 +194,10 @@ public enum DataRouterMsgs implements LogMessageEnum {
READING_JSON_SCHEMA_ERROR,
/** Arguments: {0} = Error message */
- JSON_CONVERSION_ERROR;
+ JSON_CONVERSION_ERROR,
+
+ /** Failed to load the schemaIngest.properties file */
+ SCHEMA_INGEST_LOAD_ERROR;
/**
* Static initializer to ensure the resource bundles for this class are loaded...
diff --git a/src/main/java/org/onap/aai/datarouter/policy/AbstractSpikeEntityEventProcessor.java b/src/main/java/org/onap/aai/datarouter/policy/AbstractSpikeEntityEventProcessor.java
index 6d04ed6..7a4884a 100644
--- a/src/main/java/org/onap/aai/datarouter/policy/AbstractSpikeEntityEventProcessor.java
+++ b/src/main/java/org/onap/aai/datarouter/policy/AbstractSpikeEntityEventProcessor.java
@@ -43,6 +43,7 @@ import org.json.JSONObject;
import org.onap.aai.cl.api.Logger;
import org.onap.aai.cl.eelf.LoggerFactory;
import org.onap.aai.cl.mdc.MdcContext;
+import org.onap.aai.datarouter.schema.OxmModelLoader;
import org.onap.aai.datarouter.entity.DocumentStoreDataEntity;
import org.onap.aai.datarouter.entity.OxmEntityDescriptor;
import org.onap.aai.datarouter.entity.SpikeEventEntity;
@@ -51,7 +52,6 @@ import org.onap.aai.datarouter.entity.SpikeEventVertex;
import org.onap.aai.datarouter.logging.EntityEventPolicyMsgs;
import org.onap.aai.datarouter.util.EntityOxmReferenceHelper;
import org.onap.aai.datarouter.util.ExternalOxmModelProcessor;
-import org.onap.aai.datarouter.util.OxmModelLoader;
import org.onap.aai.datarouter.util.RouterServiceUtil;
import org.onap.aai.datarouter.util.SearchServiceAgent;
import org.onap.aai.datarouter.util.Version;
@@ -295,7 +295,7 @@ public abstract class AbstractSpikeEntityEventProcessor implements Processor {
}
protected DynamicJAXBContext readOxm(Exchange exchange, String uebPayload) {
- DynamicJAXBContext oxmJaxbContext = loadOxmContext(oxmVersion.toLowerCase());
+ DynamicJAXBContext oxmJaxbContext = loadOxmContext(oxmVersion);
if (oxmJaxbContext == null) {
logger.error(EntityEventPolicyMsgs.OXM_VERSION_NOT_SUPPORTED, oxmVersion);
logger.debug(EntityEventPolicyMsgs.DISCARD_EVENT_VERBOSE, "OXM version mismatch", uebPayload);
@@ -539,7 +539,7 @@ public abstract class AbstractSpikeEntityEventProcessor implements Processor {
private List<String> getOxmAttributes(DynamicJAXBContext oxmJaxbContext, String oxmEntityType,
String entityType, String fieldName) {
- DynamicType entity = (DynamicType) oxmJaxbContext.getDynamicType(oxmEntityType);
+ DynamicType entity = oxmJaxbContext.getDynamicType(oxmEntityType);
if (entity == null) {
return null;
}
@@ -806,7 +806,7 @@ public abstract class AbstractSpikeEntityEventProcessor implements Processor {
meta.setSpikeEventVertex(spikeEventVertex);
- DynamicJAXBContext oxmJaxbContext = loadOxmContext(oxmVersion.toLowerCase());
+ DynamicJAXBContext oxmJaxbContext = loadOxmContext(oxmVersion);
if (oxmJaxbContext == null) {
logger.error(EntityEventPolicyMsgs.OXM_VERSION_NOT_SUPPORTED, oxmVersion);
logger.debug(EntityEventPolicyMsgs.DISCARD_EVENT_VERBOSE, "OXM version mismatch",
@@ -834,7 +834,7 @@ public abstract class AbstractSpikeEntityEventProcessor implements Processor {
*/
VersionedOxmEntities oxmEntities =
- EntityOxmReferenceHelper.getInstance().getVersionedOxmEntities(Version.valueOf(oxmVersion));
+ EntityOxmReferenceHelper.getInstance().getVersionedOxmEntities(Version.valueOf(oxmVersion.toLowerCase()));
if (oxmEntities != null && !oxmEntities.getEntityTypeLookup().containsKey(entityType)) {
logger.debug(EntityEventPolicyMsgs.DISCARD_EVENT_VERBOSE, "No matching OXM Descriptor for entity-type='" + entityType + "'",
diff --git a/src/main/java/org/onap/aai/datarouter/policy/EntityEventPolicy.java b/src/main/java/org/onap/aai/datarouter/policy/EntityEventPolicy.java
index d54fbe7..c1a1f2e 100644
--- a/src/main/java/org/onap/aai/datarouter/policy/EntityEventPolicy.java
+++ b/src/main/java/org/onap/aai/datarouter/policy/EntityEventPolicy.java
@@ -52,7 +52,7 @@ import org.onap.aai.datarouter.util.CrossEntityReference;
import org.onap.aai.datarouter.util.EntityOxmReferenceHelper;
import org.onap.aai.datarouter.util.ExternalOxmModelProcessor;
import org.onap.aai.datarouter.util.NodeUtils;
-import org.onap.aai.datarouter.util.OxmModelLoader;
+import org.onap.aai.datarouter.schema.OxmModelLoader;
import org.onap.aai.datarouter.util.RouterServiceUtil;
import org.onap.aai.datarouter.util.SearchServiceAgent;
import org.onap.aai.datarouter.util.SearchSuggestionPermutation;
@@ -252,7 +252,7 @@ public class EntityEventPolicy implements Processor {
return;
}
- DynamicJAXBContext oxmJaxbContext = loadOxmContext(oxmVersion.toLowerCase());
+ DynamicJAXBContext oxmJaxbContext = loadOxmContext(oxmVersion);
if (oxmJaxbContext == null) {
logger.error(EntityEventPolicyMsgs.OXM_VERSION_NOT_SUPPORTED, oxmVersion);
logger.debug(EntityEventPolicyMsgs.DISCARD_EVENT_VERBOSE, "OXM version mismatch",
@@ -390,7 +390,7 @@ public class EntityEventPolicy implements Processor {
* Use the versioned OXM Entity class to get access to cross-entity reference helper collections
*/
VersionedOxmEntities oxmEntities =
- EntityOxmReferenceHelper.getInstance().getVersionedOxmEntities(Version.valueOf(oxmVersion));
+ EntityOxmReferenceHelper.getInstance().getVersionedOxmEntities(Version.valueOf(oxmVersion.toLowerCase()));
/**
* NOTES:
diff --git a/src/main/java/org/onap/aai/datarouter/policy/SpikeAutosuggestIndexProcessor.java b/src/main/java/org/onap/aai/datarouter/policy/SpikeAutosuggestIndexProcessor.java
index c33e668..8b56f99 100644
--- a/src/main/java/org/onap/aai/datarouter/policy/SpikeAutosuggestIndexProcessor.java
+++ b/src/main/java/org/onap/aai/datarouter/policy/SpikeAutosuggestIndexProcessor.java
@@ -75,7 +75,7 @@ public class SpikeAutosuggestIndexProcessor extends AbstractSpikeEntityEventProc
* Use the versioned OXM Entity class to get access to cross-entity reference helper collections
*/
VersionedOxmEntities oxmEntities =
- EntityOxmReferenceHelper.getInstance().getVersionedOxmEntities(Version.valueOf(oxmVersion));
+ EntityOxmReferenceHelper.getInstance().getVersionedOxmEntities(Version.valueOf(oxmVersion.toLowerCase()));
if (oxmEntities != null) {
Map<String, OxmEntityDescriptor> rootDescriptor =
diff --git a/src/main/java/org/onap/aai/datarouter/policy/SpikeEntityEventPolicy.java b/src/main/java/org/onap/aai/datarouter/policy/SpikeEntityEventPolicy.java
index caee8b4..8f0e426 100644
--- a/src/main/java/org/onap/aai/datarouter/policy/SpikeEntityEventPolicy.java
+++ b/src/main/java/org/onap/aai/datarouter/policy/SpikeEntityEventPolicy.java
@@ -50,7 +50,7 @@ import org.onap.aai.datarouter.entity.SpikeEventVertex;
import org.onap.aai.datarouter.logging.EntityEventPolicyMsgs;
import org.onap.aai.datarouter.util.EntityOxmReferenceHelper;
import org.onap.aai.datarouter.util.ExternalOxmModelProcessor;
-import org.onap.aai.datarouter.util.OxmModelLoader;
+import org.onap.aai.datarouter.schema.OxmModelLoader;
import org.onap.aai.datarouter.util.RouterServiceUtil;
import org.onap.aai.datarouter.util.SearchServiceAgent;
import org.onap.aai.restclient.client.Headers;
@@ -291,7 +291,7 @@ public class SpikeEntityEventPolicy implements Processor {
return;
}
- DynamicJAXBContext oxmJaxbContext = loadOxmContext(oxmVersion.toLowerCase());
+ DynamicJAXBContext oxmJaxbContext = loadOxmContext(oxmVersion);
if (oxmJaxbContext == null) {
logger.error(EntityEventPolicyMsgs.OXM_VERSION_NOT_SUPPORTED, oxmVersion);
logger.debug(EntityEventPolicyMsgs.DISCARD_EVENT_VERBOSE, "OXM version mismatch", eventPayload);
@@ -526,7 +526,7 @@ public class SpikeEntityEventPolicy implements Processor {
private List<String> getOxmAttributes(DynamicJAXBContext oxmJaxbContext, String oxmEntityType,
String entityType, String fieldName) {
- DynamicType entity = (DynamicType) oxmJaxbContext.getDynamicType(oxmEntityType);
+ DynamicType entity = oxmJaxbContext.getDynamicType(oxmEntityType);
if (entity == null) {
return null;
}
diff --git a/src/main/java/org/onap/aai/datarouter/schema/OxmConfigTranslator.java b/src/main/java/org/onap/aai/datarouter/schema/OxmConfigTranslator.java
new file mode 100644
index 0000000..ee2c5dc
--- /dev/null
+++ b/src/main/java/org/onap/aai/datarouter/schema/OxmConfigTranslator.java
@@ -0,0 +1,98 @@
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright © 2017-2018 Amdocs
+ * ================================================================================
+ * 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
+ *
+ * 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,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+package org.onap.aai.datarouter.schema;
+
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.PathMatcher;
+import java.nio.file.Paths;
+import java.util.List;
+import java.util.Map;
+import java.util.ServiceConfigurationError;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+import org.onap.aai.setup.ConfigTranslator;
+import org.onap.aai.setup.SchemaLocationsBean;
+import org.onap.aai.setup.Version;
+
+public class OxmConfigTranslator extends ConfigTranslator {
+ public OxmConfigTranslator(SchemaLocationsBean bean) {
+ super(bean);
+ }
+
+ @Override
+ public Map<Version, List<String>> getNodeFiles() {
+ String nodeDirectory = bean.getNodeDirectory();
+ if (nodeDirectory == null) {
+ throw new ServiceConfigurationError(
+ "Node(s) directory is empty in the schema location bean (" + bean.getSchemaConfigLocation() + ")");
+ }
+ try {
+ return getVersionMap(Paths.get(nodeDirectory), "*_v*.xml");
+ } catch (IOException e) {
+ throw new ServiceConfigurationError("Failed to read node(s) directory " + getPath(nodeDirectory), e);
+ }
+ }
+
+ @Override
+ public Map<Version, List<String>> getEdgeFiles() {
+ String edgeDirectory = bean.getEdgeDirectory();
+ if (edgeDirectory == null) {
+ throw new ServiceConfigurationError(
+ "Edge(s) directory is empty in the schema location bean (" + bean.getSchemaConfigLocation() + ")");
+ }
+ try {
+ return getVersionMap(Paths.get(edgeDirectory), "*_v*.json");
+ } catch (IOException e) {
+ throw new ServiceConfigurationError("Failed to read edge(s) directory " + getPath(edgeDirectory), e);
+ }
+ }
+
+ private String getPath(String nodeDirectory) {
+ return Paths.get(nodeDirectory).toAbsolutePath().toString();
+ }
+
+ /**
+ * Creates a map containing each OXM Version and the matching OXM file path(s)
+ *
+ * @param folderPath the folder/directory containing the OXM files
+ * @param fileSuffix
+ * @return a new Map object (may be empty)
+ * @throws IOException if there is a problem reading the specified directory path
+ */
+ private Map<Version, List<String>> getVersionMap(Path folderPath, String globPattern) throws IOException {
+ final PathMatcher filter = folderPath.getFileSystem().getPathMatcher("glob:**/" + globPattern);
+ try (final Stream<Path> stream = Files.list(folderPath)) {
+ return stream.filter(filter::matches).map(Path::toString).filter(p -> getVersionFromPath(p) != null)
+ .collect(Collectors.groupingBy(this::getVersionFromPath));
+ }
+ }
+
+ private Version getVersionFromPath(String pathName) {
+ String version = "V" + pathName.replaceAll("^.*\\/", "").replaceAll("\\D+", "");
+ try {
+ return Version.valueOf(version);
+ } catch (IllegalArgumentException e) {
+ return null;
+ }
+ }
+}
diff --git a/src/main/java/org/onap/aai/datarouter/schema/OxmModelLoader.java b/src/main/java/org/onap/aai/datarouter/schema/OxmModelLoader.java
new file mode 100644
index 0000000..93854d8
--- /dev/null
+++ b/src/main/java/org/onap/aai/datarouter/schema/OxmModelLoader.java
@@ -0,0 +1,101 @@
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright © 2017-2018 Amdocs
+ * ================================================================================
+ * 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
+ *
+ * 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,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+package org.onap.aai.datarouter.schema;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+import java.util.NoSuchElementException;
+import java.util.concurrent.ConcurrentHashMap;
+import javax.ws.rs.core.Response.Status;
+import org.eclipse.persistence.jaxb.dynamic.DynamicJAXBContext;
+import org.onap.aai.cl.eelf.LoggerFactory;
+import org.onap.aai.datarouter.logging.DataRouterMsgs;
+import org.onap.aai.datarouter.util.ExternalOxmModelProcessor;
+import org.onap.aai.nodes.NodeIngestor;
+import org.onap.aai.setup.ConfigTranslator;
+import org.onap.aai.setup.SchemaLocationsBean;
+import org.onap.aai.setup.Version;
+
+public class OxmModelLoader {
+
+ private static Map<String, DynamicJAXBContext> versionContextMap = new ConcurrentHashMap<>();
+ private static List<ExternalOxmModelProcessor> oxmModelProcessorRegistry = new ArrayList<>();
+
+ private static final org.onap.aai.cl.api.Logger logger =
+ LoggerFactory.getInstance().getLogger(OxmModelLoader.class.getName());
+
+ private OxmModelLoader() {
+ throw new IllegalStateException("Utility class");
+ }
+
+ public static synchronized void loadModels() {
+ SchemaIngestPropertiesReader schemaIngestPropReader = new SchemaIngestPropertiesReader();
+ SchemaLocationsBean schemaLocationsBean = new SchemaLocationsBean();
+ schemaLocationsBean.setNodeDirectory(schemaIngestPropReader.getNodeDir());
+ ConfigTranslator configTranslator = new OxmConfigTranslator(schemaLocationsBean);
+ NodeIngestor nodeIngestor = new NodeIngestor(configTranslator);
+
+ for (Version oxmVersion : Version.values()) {
+ DynamicJAXBContext jaxbContext = nodeIngestor.getContextForVersion(oxmVersion);
+ if (jaxbContext != null) {
+ loadModel(oxmVersion.toString(), jaxbContext);
+ }
+ }
+ }
+
+ public static DynamicJAXBContext getContextForVersion(String version) {
+ if (versionContextMap == null || versionContextMap.isEmpty()) {
+ loadModels();
+ } else if (!versionContextMap.containsKey(version)) {
+ throw new NoSuchElementException(Status.NOT_FOUND.toString());
+ }
+ return versionContextMap.get(version);
+ }
+
+ public static synchronized void registerExternalOxmModelProcessors(
+ Collection<ExternalOxmModelProcessor> processors) {
+ if (processors != null) {
+ for (ExternalOxmModelProcessor processor : processors) {
+ if (!oxmModelProcessorRegistry.contains(processor)) {
+ oxmModelProcessorRegistry.add(processor);
+ }
+ }
+ }
+ }
+
+ public static Map<String, DynamicJAXBContext> getVersionContextMap() {
+ return versionContextMap;
+ }
+
+ private static synchronized void loadModel(String oxmVersion, DynamicJAXBContext jaxbContext) {
+ versionContextMap.put(oxmVersion, jaxbContext);
+ if (oxmModelProcessorRegistry != null) {
+ for (ExternalOxmModelProcessor processor : oxmModelProcessorRegistry) {
+ processor.onOxmVersionChange(org.onap.aai.datarouter.util.Version.valueOf(oxmVersion.toLowerCase()),
+ jaxbContext);
+ }
+ }
+ logger.info(DataRouterMsgs.LOADED_OXM_FILE, oxmVersion);
+ }
+
+}
diff --git a/src/main/java/org/onap/aai/datarouter/schema/SchemaIngestPropertiesReader.java b/src/main/java/org/onap/aai/datarouter/schema/SchemaIngestPropertiesReader.java
new file mode 100644
index 0000000..76530ae
--- /dev/null
+++ b/src/main/java/org/onap/aai/datarouter/schema/SchemaIngestPropertiesReader.java
@@ -0,0 +1,88 @@
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright © 2017-2018 Amdocs
+ * ================================================================================
+ * 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
+ *
+ * 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,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+package org.onap.aai.datarouter.schema;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URISyntaxException;
+import java.nio.file.Files;
+import java.nio.file.NoSuchFileException;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.Properties;
+import org.onap.aai.cl.eelf.LoggerFactory;
+import org.onap.aai.datarouter.logging.DataRouterMsgs;
+
+public class SchemaIngestPropertiesReader {
+
+ private static final String SCHEMA_INGEST_PROPERTIES_FILE = "schemaIngest.properties";
+ private static final String MSG_FAILED_LOAD_SCHEMA_INGEST_PROPERTIES = "Failed to load " + SCHEMA_INGEST_PROPERTIES_FILE;
+
+ private static final String SCHEMA_INGEST_PROPERTIES_LOCATION =
+ System.getProperty("CONFIG_HOME") + "/" + SCHEMA_INGEST_PROPERTIES_FILE;
+
+ private static org.onap.aai.cl.api.Logger logger =
+ LoggerFactory.getInstance().getLogger(SchemaIngestPropertiesReader.class.getName());
+
+ /**
+ * Gets the location of the OXM.
+ *
+ * @return the directory containing the OXM files
+ */
+ public String getNodeDir() {
+
+ Properties prop = new Properties();
+ try {
+ prop = loadFromFile(SCHEMA_INGEST_PROPERTIES_LOCATION);
+ } catch (NoSuchFileException e) {
+ try {
+ prop = loadFromClasspath(SCHEMA_INGEST_PROPERTIES_FILE);
+ } catch (URISyntaxException | IOException ef) {
+ logger.error(DataRouterMsgs.SCHEMA_INGEST_LOAD_ERROR, ef.getMessage());
+ throw new RuntimeException(MSG_FAILED_LOAD_SCHEMA_INGEST_PROPERTIES);
+ }
+ } catch (IOException ec) {
+ logger.error(DataRouterMsgs.SCHEMA_INGEST_LOAD_ERROR, ec.getMessage());
+ throw new RuntimeException(MSG_FAILED_LOAD_SCHEMA_INGEST_PROPERTIES);
+ }
+ return prop.getProperty("nodeDir");
+ }
+
+ private Properties loadFromFile(String filename) throws IOException {
+ Path configLocation = Paths.get(filename);
+ try (InputStream stream = Files.newInputStream(configLocation)) {
+ return loadProperties(stream);
+ }
+ }
+
+ private Properties loadFromClasspath(String resourceName) throws URISyntaxException, IOException {
+ Path path = Paths.get(ClassLoader.getSystemResource(resourceName).toURI());
+ try (InputStream stream = Files.newInputStream(path)) {
+ return loadProperties(stream);
+ }
+ }
+
+ private Properties loadProperties(InputStream stream) throws IOException {
+ Properties config = new Properties();
+ config.load(stream);
+ return config;
+ }
+}
diff --git a/src/main/java/org/onap/aai/datarouter/util/OxmModelLoader.java b/src/main/java/org/onap/aai/datarouter/util/OxmModelLoader.java
deleted file mode 100644
index 345bc48..0000000
--- a/src/main/java/org/onap/aai/datarouter/util/OxmModelLoader.java
+++ /dev/null
@@ -1,134 +0,0 @@
-/**
- * ============LICENSE_START=======================================================
- * org.onap.aai
- * ================================================================================
- * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
- * Copyright © 2017-2018 Amdocs
- * ================================================================================
- * 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
- *
- * 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,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-package org.onap.aai.datarouter.util;
-
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Collection;
-import java.util.NoSuchElementException;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-import javax.ws.rs.core.Response.Status;
-import javax.xml.bind.JAXBException;
-
-import org.eclipse.persistence.jaxb.JAXBContextProperties;
-import org.eclipse.persistence.jaxb.dynamic.DynamicJAXBContext;
-import org.eclipse.persistence.jaxb.dynamic.DynamicJAXBContextFactory;
-import org.onap.aai.cl.eelf.LoggerFactory;
-import org.onap.aai.datarouter.logging.DataRouterMsgs;
-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<>();
- private static List<ExternalOxmModelProcessor> oxmModelProcessorRegistry = new ArrayList<>();
- static final Pattern p = Pattern.compile("aai_oxm_(.*).xml");
-
- private static org.onap.aai.cl.api.Logger logger = LoggerFactory.getInstance()
- .getLogger(OxmModelLoader.class.getName());
-
- public static synchronized 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());
- }
- }
- }
-
-
- }
-
-
- private static synchronized void loadModel(String version,String resourceName,InputStream inputStream) throws JAXBException {
- Map<String, Object> properties = new HashMap<>();
- properties.put(JAXBContextProperties.OXM_METADATA_SOURCE, inputStream);
- final DynamicJAXBContext jaxbContext = DynamicJAXBContextFactory
- .createContextFromOXM(Thread.currentThread().getContextClassLoader(), properties);
- versionContextMap.put(version, jaxbContext);
- if ( oxmModelProcessorRegistry != null) {
- for ( ExternalOxmModelProcessor processor : oxmModelProcessorRegistry ) {
- processor.onOxmVersionChange(Version.valueOf(version), jaxbContext );
- }
- }
- logger.info(DataRouterMsgs.LOADED_OXM_FILE, resourceName);
- }
-
- public static DynamicJAXBContext getContextForVersion(String version) throws NoSuchElementException, FileNotFoundException {
- if (versionContextMap == null || versionContextMap.isEmpty()) {
- loadModels();
- } else if (!versionContextMap.containsKey(version)) {
- throw new NoSuchElementException(Status.NOT_FOUND.toString());
-
- }
-
- return versionContextMap.get(version);
- }
-
- public static Map<String, DynamicJAXBContext> getVersionContextMap() {
- return versionContextMap;
- }
-
- public static void setVersionContextMap(Map<String, DynamicJAXBContext> versionContextMap) {
- OxmModelLoader.versionContextMap = versionContextMap;
- }
-
- public static synchronized void registerExternalOxmModelProcessors(Collection<ExternalOxmModelProcessor> processors) {
- if(processors != null) {
- for(ExternalOxmModelProcessor processor : processors) {
- if(!oxmModelProcessorRegistry.contains(processor)) {
- oxmModelProcessorRegistry.add(processor);
- }
- }
- }
- }
-
-}
diff --git a/src/main/resources/logging/DataRouterMsgs.properties b/src/main/resources/logging/DataRouterMsgs.properties
index fff262c..d922a7f 100644
--- a/src/main/resources/logging/DataRouterMsgs.properties
+++ b/src/main/resources/logging/DataRouterMsgs.properties
@@ -170,4 +170,8 @@ FAIL_TO_CREATE_UPDATE_DOC=\
Failed to create or update document in index {0}. Cause: {1}
LOAD_OXM_ERROR=\
DR5000E|\
- Unable to load Oxm model: {0}\
+ Unable to load Oxm model: {0}\
+
+SCHEMA_INGEST_LOAD_ERROR=\
+ DR5001E|\
+ Unable to load schema ingest properties file due to : {0}