diff options
author | Fiete Ostkamp <Fiete.Ostkamp@telekom.de> | 2024-02-26 14:03:09 +0100 |
---|---|---|
committer | Fiete Ostkamp <fiete.ostkamp@telekom.de> | 2024-02-26 13:08:47 +0000 |
commit | b7ad55e5d91527b259cb9189237b3f01915c31f8 (patch) | |
tree | 4fe3a6f134411450f6b19e07a4b965db580cd912 | |
parent | e190b0b67803241ad3a94a6c6396fc47a94e7fac (diff) |
Only load SchemaService related beans in aai-common when schema.translator.list=schema-service
- conditionally load schema-service related config, otherwise use the ConfigTranslator
- this prepares locally running traversal via mvn spring-boot:run
Issue-ID: AAI-3787
Change-Id: I9415802fb708933e8596b62e7540fa8a156e4cd6
Signed-off-by: Fiete Ostkamp <Fiete.Ostkamp@telekom.de>
9 files changed, 50 insertions, 42 deletions
diff --git a/aai-core/src/main/java/org/onap/aai/config/SchemaConfiguration.java b/aai-core/src/main/java/org/onap/aai/config/SchemaConfiguration.java index 885790ce..9247bc77 100644 --- a/aai-core/src/main/java/org/onap/aai/config/SchemaConfiguration.java +++ b/aai-core/src/main/java/org/onap/aai/config/SchemaConfiguration.java @@ -66,13 +66,6 @@ public class SchemaConfiguration { return nodesConfiguration.nodeIngestor(); } - @Bean(name = "configTranslator") - @ConditionalOnProperty(name = "schema.translator.list", havingValue = "config", matchIfMissing = true) - public ConfigTranslator configTranslator(SchemaLocationsBean schemaLocationsBean, - SchemaConfigVersions schemaVersions) { - return new AAIConfigTranslator(schemaLocationsBean, schemaVersions); - } - @Bean @ConditionalOnProperty(name = "schema.translator.list", havingValue = "config", matchIfMissing = true) public SchemaErrorStrategy schemaErrorStrategy() { diff --git a/aai-core/src/test/java/org/onap/aai/AbstractConfigTranslator.java b/aai-core/src/test/java/org/onap/aai/AbstractConfigTranslator.java index 19b8220b..3df799ba 100644 --- a/aai-core/src/test/java/org/onap/aai/AbstractConfigTranslator.java +++ b/aai-core/src/test/java/org/onap/aai/AbstractConfigTranslator.java @@ -45,7 +45,7 @@ public abstract class AbstractConfigTranslator extends ConfigTranslator { */ @Override public Map<SchemaVersion, List<String>> getNodeFiles() { - String prefix = bean.getNodeDirectory() + AAIConstants.AAI_FILESEP; + String prefix = schemaLocationsBean.getNodeDirectory() + AAIConstants.AAI_FILESEP; String suffix = ".xml"; @@ -65,7 +65,7 @@ public abstract class AbstractConfigTranslator extends ConfigTranslator { List<String> container = new ArrayList<>(); String directoryName = - bean.getNodeDirectory() + AAIConstants.AAI_FILESEP + v.toString() + AAIConstants.AAI_FILESEP; + schemaLocationsBean.getNodeDirectory() + AAIConstants.AAI_FILESEP + v.toString() + AAIConstants.AAI_FILESEP; File[] files = new File(directoryName).listFiles(); for (File f : files) { diff --git a/aai-rest/src/main/java/org/onap/aai/restclient/AAIRestClient.java b/aai-rest/src/main/java/org/onap/aai/restclient/AAIRestClient.java index 05d5ec0f..393c6632 100644 --- a/aai-rest/src/main/java/org/onap/aai/restclient/AAIRestClient.java +++ b/aai-rest/src/main/java/org/onap/aai/restclient/AAIRestClient.java @@ -26,12 +26,16 @@ import java.util.Map; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.context.annotation.Conditional; import org.springframework.http.HttpHeaders; import org.springframework.http.MediaType; import org.springframework.stereotype.Component; import org.springframework.util.MultiValueMap; @Component(value = ClientType.AAI) +@ConditionalOnExpression("${aai-rest-client.enabled:false}") public class AAIRestClient extends TwoWaySSLRestClient { private static Logger logger = LoggerFactory.getLogger(AAIRestClient.class); diff --git a/aai-schema-ingest/src/main/java/org/onap/aai/config/SchemaServiceConfiguration.java b/aai-schema-ingest/src/main/java/org/onap/aai/config/SchemaServiceConfiguration.java index cdd87492..701fd17d 100644 --- a/aai-schema-ingest/src/main/java/org/onap/aai/config/SchemaServiceConfiguration.java +++ b/aai-schema-ingest/src/main/java/org/onap/aai/config/SchemaServiceConfiguration.java @@ -23,13 +23,13 @@ package org.onap.aai.config; import org.onap.aai.setup.*; -import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.PropertySource; @Configuration -@ConditionalOnExpression("'${schema.translator.list}'.contains('schema-service')") +@ConditionalOnProperty(name = "schema.translator.list", havingValue = "schema-service", matchIfMissing = false) @PropertySource(value = "classpath:schema-ingest.properties", ignoreResourceNotFound = true) @PropertySource(value = "file:${schema.ingest.file}", ignoreResourceNotFound = true) public class SchemaServiceConfiguration { diff --git a/aai-schema-ingest/src/main/java/org/onap/aai/setup/AAIConfigTranslator.java b/aai-schema-ingest/src/main/java/org/onap/aai/setup/AAIConfigTranslator.java index 8949891e..66ffcf88 100644 --- a/aai-schema-ingest/src/main/java/org/onap/aai/setup/AAIConfigTranslator.java +++ b/aai-schema-ingest/src/main/java/org/onap/aai/setup/AAIConfigTranslator.java @@ -4,6 +4,8 @@ * ================================================================================ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. * ================================================================================ + * Modifications Copyright © 2024 DEUTSCHE TELEKOM AG. + * ================================================================================ * 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 @@ -24,23 +26,24 @@ import java.io.File; import java.util.Arrays; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.TreeMap; import java.util.function.Supplier; import java.util.stream.Collectors; import java.util.stream.Stream; +import org.springframework.stereotype.Component; + /** * <b>AAIConfigTranslator</b> is responsible for looking at the * schema files and edge files based on the available versions * Also has the ability to exclude them based on the node.exclusion.pattern */ +@Component public class AAIConfigTranslator extends ConfigTranslator { - private static final String FILESEP = - (System.getProperty("file.separator") == null) ? "/" : System.getProperty("file.separator"); - - public AAIConfigTranslator(SchemaLocationsBean bean, SchemaConfigVersions schemaVersions) { - super(bean, schemaVersions); + public AAIConfigTranslator(SchemaLocationsBean schemaLocationsBean, SchemaConfigVersions schemaConfigVersions) { + super(schemaLocationsBean, schemaConfigVersions); } /* @@ -61,8 +64,8 @@ public class AAIConfigTranslator extends ConfigTranslator { } private List<String> getVersionNodeFiles(SchemaVersion v) { - return getVersionFiles(bean.getNodeDirectory(), v, () -> bean.getNodesInclusionPattern().stream(), - () -> bean.getNodesExclusionPattern().stream()); + return getVersionFiles(schemaLocationsBean.getNodeDirectory(), v, () -> schemaLocationsBean.getNodesInclusionPattern().stream(), + () -> schemaLocationsBean.getNodesExclusionPattern().stream()); } /* @@ -84,18 +87,25 @@ public class AAIConfigTranslator extends ConfigTranslator { private List<String> getVersionEdgeFiles(SchemaVersion v) { - return getVersionFiles(bean.getEdgeDirectory(), v, () -> bean.getEdgesInclusionPattern().stream(), - () -> bean.getEdgesExclusionPattern().stream()); + return getVersionFiles(schemaLocationsBean.getEdgeDirectory(), v, () -> schemaLocationsBean.getEdgesInclusionPattern().stream(), + () -> schemaLocationsBean.getEdgesExclusionPattern().stream()); } private List<String> getVersionFiles(String startDirectory, SchemaVersion schemaVersion, - Supplier<Stream<String>> inclusionPattern, Supplier<Stream<String>> exclusionPattern) { - - List<String> container; - final String directoryName = startDirectory + FILESEP + schemaVersion.toString() + FILESEP; - container = Arrays.stream(new File(directoryName).listFiles()).map(File::getName) - .filter(name -> inclusionPattern.get().anyMatch(name::matches)).map(name -> directoryName + name) - .filter(name -> exclusionPattern.get().noneMatch(name::matches)).collect(Collectors.toList()); + Supplier<Stream<String>> inclusionPattern, Supplier<Stream<String>> exclusionPattern) { + + final File versionDirectory = new File(startDirectory + "/" + schemaVersion.toString()); + final List<String> container = Arrays.stream(versionDirectory.listFiles()) + .filter(Objects::nonNull) + .map(File::getName) + .filter(versionFileName -> inclusionPattern + .get() + .anyMatch(versionFileName::matches)) + .map(versionFileName -> versionDirectory.getAbsolutePath() + "/" + versionFileName) + .filter(versionFilePath -> exclusionPattern + .get() + .noneMatch(versionFilePath::matches)) + .collect(Collectors.toList()); return container; } diff --git a/aai-schema-ingest/src/main/java/org/onap/aai/setup/ConfigTranslator.java b/aai-schema-ingest/src/main/java/org/onap/aai/setup/ConfigTranslator.java index e87a05cc..50b9dc2f 100644 --- a/aai-schema-ingest/src/main/java/org/onap/aai/setup/ConfigTranslator.java +++ b/aai-schema-ingest/src/main/java/org/onap/aai/setup/ConfigTranslator.java @@ -1,5 +1,4 @@ -/** - * ============LICENSE_START======================================================= +/** ============LICENSE_START======================================================= * org.onap.aai * ================================================================================ * Copyright © 2017-18 AT&T Intellectual Property. All rights reserved. @@ -16,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. * ============LICENSE_END========================================================= - */ +*/ package org.onap.aai.setup; @@ -45,12 +44,12 @@ import org.springframework.beans.factory.annotation.Autowired; public abstract class ConfigTranslator extends Translator { private static final Logger LOGGER = LoggerFactory.getLogger(ConfigTranslator.class); - protected SchemaLocationsBean bean; + protected SchemaLocationsBean schemaLocationsBean; @Autowired - public ConfigTranslator(SchemaLocationsBean schemaLocationbean, SchemaConfigVersions schemaVersions) { - super(schemaVersions); - this.bean = schemaLocationbean; + public ConfigTranslator(SchemaLocationsBean schemaLocationsBean, SchemaConfigVersions schemaConfigVersions) { + super(schemaConfigVersions); + this.schemaLocationsBean = schemaLocationsBean; } diff --git a/aai-schema-ingest/src/main/java/org/onap/aai/setup/SchemaServiceTranslator.java b/aai-schema-ingest/src/main/java/org/onap/aai/setup/SchemaServiceTranslator.java index 680bdd12..ec6e41a7 100644 --- a/aai-schema-ingest/src/main/java/org/onap/aai/setup/SchemaServiceTranslator.java +++ b/aai-schema-ingest/src/main/java/org/onap/aai/setup/SchemaServiceTranslator.java @@ -22,7 +22,6 @@ package org.onap.aai.setup; import java.io.IOException; import java.io.InputStream; -import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.List; @@ -32,19 +31,22 @@ import org.onap.aai.restclient.RestClient; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.core.io.Resource; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Component; /** * <b>AAIConfigTranslator</b> is responsible for looking at the schema files and * edge files based on the available versions Also has the ability to exclude * them based on the node.exclusion.pattern */ +@Component +@ConditionalOnProperty(name = "schema.translator.list", havingValue = "schema-service", matchIfMissing = false) public class SchemaServiceTranslator extends Translator { private static final Logger LOGGER = LoggerFactory.getLogger(SchemaServiceTranslator.class); diff --git a/aai-schema-ingest/src/main/java/org/onap/aai/setup/Translator.java b/aai-schema-ingest/src/main/java/org/onap/aai/setup/Translator.java index 3d415e62..45ca0cd6 100644 --- a/aai-schema-ingest/src/main/java/org/onap/aai/setup/Translator.java +++ b/aai-schema-ingest/src/main/java/org/onap/aai/setup/Translator.java @@ -45,9 +45,9 @@ public abstract class Translator { * ingested for that version */ - public abstract List<InputStream> getVersionNodeStream(SchemaVersion version) throws IOException; + public abstract List<InputStream> getVersionNodeStream(SchemaVersion schemaVersion) throws IOException; - public abstract List<String> getJsonPayload(SchemaVersion version) throws IOException; + public abstract List<String> getJsonPayload(SchemaVersion schemaVersion) throws IOException; /** * Translates the contents of the schema config file diff --git a/aai-schema-ingest/src/test/java/org/onap/aai/testutils/ConfigTranslatorForWiringTest.java b/aai-schema-ingest/src/test/java/org/onap/aai/testutils/ConfigTranslatorForWiringTest.java index 1d8e4bcb..a7113125 100644 --- a/aai-schema-ingest/src/test/java/org/onap/aai/testutils/ConfigTranslatorForWiringTest.java +++ b/aai-schema-ingest/src/test/java/org/onap/aai/testutils/ConfigTranslatorForWiringTest.java @@ -32,14 +32,14 @@ import org.onap.aai.setup.SchemaVersion; public class ConfigTranslatorForWiringTest extends ConfigTranslator { - public ConfigTranslatorForWiringTest(SchemaLocationsBean bean, SchemaConfigVersions schemaVersions) { - super(bean, schemaVersions); + public ConfigTranslatorForWiringTest(SchemaLocationsBean schemaLocationsBean, SchemaConfigVersions schemaVersions) { + super(schemaLocationsBean, schemaVersions); } @Override public Map<SchemaVersion, List<String>> getNodeFiles() { - String f = bean.getNodeDirectory() + "test_business_v10.xml"; + String f = schemaLocationsBean.getNodeDirectory() + "test_business_v10.xml"; List<String> files = new ArrayList<>(); files.add(f); Map<SchemaVersion, List<String>> mp = new TreeMap<>(); @@ -49,7 +49,7 @@ public class ConfigTranslatorForWiringTest extends ConfigTranslator { @Override public Map<SchemaVersion, List<String>> getEdgeFiles() { - String f = bean.getEdgeDirectory() + "test.json"; + String f = schemaLocationsBean.getEdgeDirectory() + "test.json"; List<String> files = new ArrayList<>(); files.add(f); Map<SchemaVersion, List<String>> mp = new TreeMap<>(); |