diff options
author | Michael Arrastia <MArrasti@amdocs.com> | 2018-12-17 17:34:37 +0000 |
---|---|---|
committer | Michael Arrastia <MArrasti@amdocs.com> | 2018-12-17 18:27:04 +0000 |
commit | 69d4c0a747053473355ee82aa426589324e50d82 (patch) | |
tree | 735d591809d861326ee7e3ec93ad8a49bd0d101e /src | |
parent | 9a6079fe14815e6f247268ce32b3157cf95d734b (diff) |
Use Schema Service for model ingestion
Change-Id: Id2531c52491c135ae000223caf7ce79f95a9cb43
Issue-ID: AAI-2010
Signed-off-by: Michael Arrastia <MArrasti@amdocs.com>
Diffstat (limited to 'src')
7 files changed, 48 insertions, 85 deletions
diff --git a/src/main/java/org/onap/aai/spike/SchemaIngestConfiguration.java b/src/main/java/org/onap/aai/spike/SchemaIngestConfiguration.java deleted file mode 100644 index fcb1e71..0000000 --- a/src/main/java/org/onap/aai/spike/SchemaIngestConfiguration.java +++ /dev/null @@ -1,62 +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.spike; - -import org.onap.aai.edges.EdgeIngestor; -import org.onap.aai.nodes.NodeIngestor; -import org.onap.aai.setup.AAIConfigTranslator; -import org.onap.aai.setup.ConfigTranslator; -import org.onap.aai.setup.SchemaLocationsBean; -import org.onap.aai.setup.SchemaVersions; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.PropertySource; - -@Configuration -@PropertySource(value = "file:${schema.ingest.file}", ignoreResourceNotFound = true) -public class SchemaIngestConfiguration { - - @Bean - public SchemaVersions schemaVersions() { - return new SchemaVersions(); - } - - @Bean - public SchemaLocationsBean schemaLocationsBean() { - return new SchemaLocationsBean(); - } - - @Bean - public ConfigTranslator configTranslator() { - return new AAIConfigTranslator(schemaLocationsBean(), schemaVersions()); - } - - @Bean - public NodeIngestor nodeIngestor() { - return new NodeIngestor(configTranslator()); - } - - @Bean - public EdgeIngestor edgeIngestor() { - return new EdgeIngestor(configTranslator(), schemaVersions()); - } - -} diff --git a/src/main/java/org/onap/aai/spike/SpikeApplication.java b/src/main/java/org/onap/aai/spike/SpikeApplication.java index 2768c24..fed74af 100644 --- a/src/main/java/org/onap/aai/spike/SpikeApplication.java +++ b/src/main/java/org/onap/aai/spike/SpikeApplication.java @@ -23,19 +23,28 @@ package org.onap.aai.spike; import java.util.HashMap; import javax.annotation.PostConstruct; import org.eclipse.jetty.util.security.Password; +import org.onap.aai.setup.AAIConfigTranslator; +import org.onap.aai.setup.ConfigTranslator; +import org.onap.aai.setup.SchemaLocationsBean; +import org.onap.aai.setup.SchemaVersions; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; import org.springframework.boot.builder.SpringApplicationBuilder; -import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; -import org.springframework.context.annotation.Import; +import org.springframework.boot.web.support.SpringBootServletInitializer; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.ImportResource; +import org.springframework.context.annotation.PropertySource; import org.springframework.core.env.Environment; /** * Spike service Spring Boot Application */ @SpringBootApplication -@Import({SchemaIngestConfiguration.class}) +@ComponentScan(basePackages = {"org.onap.aai.config", "org.onap.aai.setup", "org.onap.aai.spike"}) +@PropertySource(value = "file:${schema.ingest.file}", ignoreResourceNotFound = true) +@PropertySource(value = "file:${edgeprops.ingest.file}", ignoreResourceNotFound = true) @ImportResource({"file:${SERVICE_BEANS}/*.xml"}) public class SpikeApplication extends SpringBootServletInitializer { @Autowired @@ -49,9 +58,11 @@ public class SpikeApplication extends SpringBootServletInitializer { HashMap<String, Object> props = new HashMap<>(); props.put("server.ssl.key-store-password", Password.deobfuscate(keyStorePassword)); + props.put("schema.service.ssl.key-store-password", Password.deobfuscate(keyStorePassword)); + props.put("schema.service.ssl.trust-store-password", Password.deobfuscate(keyStorePassword)); - new SpikeApplication().configure(new SpringApplicationBuilder(SchemaIngestConfiguration.class) - .child(SpikeApplication.class).properties(props)).run(args); + new SpikeApplication().configure(new SpringApplicationBuilder(SpikeApplication.class).properties(props)) + .run(args); } /** @@ -72,4 +83,10 @@ public class SpikeApplication extends SpringBootServletInitializer { } } + @Bean + @ConditionalOnExpression("'${schema.translator.list}'.contains('config')") + public ConfigTranslator configTranslator(SchemaLocationsBean schemaLocationsBean, SchemaVersions schemaVersions) { + return new AAIConfigTranslator(schemaLocationsBean, schemaVersions); + } + } diff --git a/src/main/java/org/onap/aai/spike/schema/EdgeRulesLoader.java b/src/main/java/org/onap/aai/spike/schema/EdgeRulesLoader.java index be303f5..93e4a6c 100644 --- a/src/main/java/org/onap/aai/spike/schema/EdgeRulesLoader.java +++ b/src/main/java/org/onap/aai/spike/schema/EdgeRulesLoader.java @@ -37,8 +37,8 @@ import org.onap.aai.cl.eelf.LoggerFactory; import org.onap.aai.edges.EdgeIngestor; import org.onap.aai.edges.EdgeRule; import org.onap.aai.edges.exceptions.EdgeRuleNotFoundException; -import org.onap.aai.setup.ConfigTranslator; import org.onap.aai.setup.SchemaVersion; +import org.onap.aai.setup.Translator; import org.onap.aai.spike.exception.SpikeException; import org.onap.aai.spike.logging.SpikeMsgs; import org.springframework.beans.factory.annotation.Autowired; @@ -47,7 +47,7 @@ import org.springframework.stereotype.Component; @Component public class EdgeRulesLoader { - private static ConfigTranslator configTranslator; + private static Translator translator; private static EdgeIngestor edgeIngestor; private static EdgePropsConfiguration edgePropsConfiguration; @@ -69,14 +69,14 @@ public class EdgeRulesLoader { * This constructor presents an awkward marrying of Spring bean creation and static method use. This * is technical debt that will need fixing. * - * @param configTranslator contains schema versions configuration + * @param translator contains schema versions configuration * @param edgeIngestor provides edge rules * @param edgePropsConfiguration edge property validation configuration */ @Autowired - public EdgeRulesLoader(ConfigTranslator configTranslator, EdgeIngestor edgeIngestor, + public EdgeRulesLoader(Translator translator, EdgeIngestor edgeIngestor, EdgePropsConfiguration edgePropsConfiguration) { - EdgeRulesLoader.configTranslator = configTranslator; + EdgeRulesLoader.translator = translator; EdgeRulesLoader.edgeIngestor = edgeIngestor; EdgeRulesLoader.edgePropsConfiguration = edgePropsConfiguration; } @@ -95,7 +95,7 @@ public class EdgeRulesLoader { for (String version : OXMModelLoader.getLoadedOXMVersions()) { try { - SchemaVersion schemaVersion = configTranslator.getSchemaVersions().getVersions().stream() + SchemaVersion schemaVersion = translator.getSchemaVersions().getVersions().stream() .filter(s -> s.toString().equalsIgnoreCase(version)).findAny().orElse(null); loadModel(schemaVersion, edgeIngestor, propFiles); } catch (IOException | EdgeRuleNotFoundException e) { @@ -118,7 +118,7 @@ public class EdgeRulesLoader { } try { - SchemaVersion schemaVersion = configTranslator.getSchemaVersions().getVersions().stream() + SchemaVersion schemaVersion = translator.getSchemaVersions().getVersions().stream() .filter(s -> s.toString().equalsIgnoreCase(v)).findAny().orElse(null); loadModel(schemaVersion, edgeIngestor, propFiles); diff --git a/src/main/java/org/onap/aai/spike/schema/OXMModelLoader.java b/src/main/java/org/onap/aai/spike/schema/OXMModelLoader.java index 7f41d8c..47288c6 100644 --- a/src/main/java/org/onap/aai/spike/schema/OXMModelLoader.java +++ b/src/main/java/org/onap/aai/spike/schema/OXMModelLoader.java @@ -34,8 +34,8 @@ import org.eclipse.persistence.internal.oxm.mappings.Descriptor; import org.eclipse.persistence.jaxb.dynamic.DynamicJAXBContext; import org.onap.aai.cl.eelf.LoggerFactory; import org.onap.aai.nodes.NodeIngestor; -import org.onap.aai.setup.ConfigTranslator; import org.onap.aai.setup.SchemaVersion; +import org.onap.aai.setup.Translator; import org.onap.aai.spike.exception.SpikeException; import org.onap.aai.spike.logging.SpikeMsgs; import org.springframework.beans.factory.annotation.Autowired; @@ -48,7 +48,7 @@ import org.springframework.stereotype.Component; @Component public class OXMModelLoader { - private static ConfigTranslator configTranslator; + private static Translator translator; private static NodeIngestor nodeIngestor; private static Map<String, DynamicJAXBContext> versionContextMap = new ConcurrentHashMap<>(); @@ -65,12 +65,12 @@ public class OXMModelLoader { * This constructor presents an awkward marrying of Spring bean creation and static method use. This * is technical debt that will need fixing. * - * @param configTranslator contains schema versions configuration + * @param translator contains schema versions configuration * @param nodeIngestor provides DynamicJAXBContext for the OXM version */ @Autowired - public OXMModelLoader(ConfigTranslator configTranslator, NodeIngestor nodeIngestor) { - OXMModelLoader.configTranslator = configTranslator; + public OXMModelLoader(Translator translator, NodeIngestor nodeIngestor) { + OXMModelLoader.translator = translator; OXMModelLoader.nodeIngestor = nodeIngestor; } @@ -86,7 +86,7 @@ public class OXMModelLoader { logger.debug("Loading OXM Models"); } - for (SchemaVersion oxmVersion : configTranslator.getSchemaVersions().getVersions()) { + for (SchemaVersion oxmVersion : translator.getSchemaVersions().getVersions()) { DynamicJAXBContext jaxbContext = nodeIngestor.getContextForVersion(oxmVersion); if (jaxbContext != null) { loadModel(oxmVersion.toString(), jaxbContext); diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index a205500..2baa523 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1,3 +1,4 @@ +spring.application.name=spike server.port=9518 SERVICE_BEANS=dynamic/conf diff --git a/src/test/java/org/onap/aai/spike/OXMModelLoaderSetup.java b/src/test/java/org/onap/aai/spike/OXMModelLoaderSetup.java index 9315df8..837fa12 100644 --- a/src/test/java/org/onap/aai/spike/OXMModelLoaderSetup.java +++ b/src/test/java/org/onap/aai/spike/OXMModelLoaderSetup.java @@ -22,7 +22,9 @@ package org.onap.aai.spike; import java.util.ArrayList; import java.util.Arrays; +import java.util.HashSet; import java.util.List; +import java.util.Set; import org.junit.Before; import org.mockito.Mock; import org.mockito.Mockito; @@ -32,6 +34,7 @@ import org.onap.aai.setup.AAIConfigTranslator; import org.onap.aai.setup.SchemaLocationsBean; import org.onap.aai.setup.SchemaVersion; import org.onap.aai.setup.SchemaVersions; +import org.onap.aai.setup.Translator; import org.onap.aai.spike.schema.EdgePropsConfiguration; import org.onap.aai.spike.schema.EdgeRulesLoader; import org.onap.aai.spike.schema.OXMModelLoader; @@ -67,8 +70,12 @@ public class OXMModelLoaderSetup { Mockito.when(edgePropsConfiguration.getEdgePropsDir()).thenReturn("src/test/resources/edgeProps/"); AAIConfigTranslator aaiConfigTranslator = new AAIConfigTranslator(schemaLocationsBean, schemaVersions); - NodeIngestor nodeIngestor = new NodeIngestor(aaiConfigTranslator); - EdgeIngestor edgeIngestor = new EdgeIngestor(aaiConfigTranslator, schemaVersions); + Set<Translator> translators = new HashSet<>(); + translators.add(aaiConfigTranslator); + NodeIngestor nodeIngestor = new NodeIngestor(translators); + nodeIngestor.initialize(); + EdgeIngestor edgeIngestor = new EdgeIngestor(translators); + edgeIngestor.initialize(); edgeRulesLoader = new EdgeRulesLoader(aaiConfigTranslator, edgeIngestor, edgePropsConfiguration); oxmModelLoader = new OXMModelLoader(aaiConfigTranslator, nodeIngestor); } diff --git a/src/test/java/org/onap/aai/spike/event/incoming/OffsetManagerTest.java b/src/test/java/org/onap/aai/spike/event/incoming/OffsetManagerTest.java index 2190942..1ee106c 100644 --- a/src/test/java/org/onap/aai/spike/event/incoming/OffsetManagerTest.java +++ b/src/test/java/org/onap/aai/spike/event/incoming/OffsetManagerTest.java @@ -1,5 +1,5 @@ /** - * ============LICENSE_START======================================================= + * ============LICENSE_START======================================================= * org.onap.aai * ================================================================================ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. @@ -33,10 +33,10 @@ public class OffsetManagerTest { @Test public void testOffsetAdvancement() throws Exception { - final Long offsetPeriod = 500L; // ms + final Long offsetPeriod = 100L; // ms // Create an instance of the offset manager. - OffsetManager offsetManager = new OffsetManager(10, offsetPeriod); + OffsetManager offsetManager = new OffsetManager(5, offsetPeriod); // Now, cache some events as if we had consumed them and they // are in flight. |