diff options
author | Tian Lee <TianL@amdocs.com> | 2018-12-20 14:38:19 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2018-12-20 14:38:19 +0000 |
commit | 897f00995fe962d4c2ebce8a95491352b1ec51d7 (patch) | |
tree | 2b6cc9b2f561ce70a5d85cf0fd10dc9053d6cd75 /src/main/java/org | |
parent | a2cea50220ccf3ebb12496029c5ac3a57ea17603 (diff) | |
parent | f6a319cdda918e33c1bf5cffbb356dd0b9feb069 (diff) |
Merge "Update to use Schema Service"
Diffstat (limited to 'src/main/java/org')
7 files changed, 86 insertions, 83 deletions
diff --git a/src/main/java/org/onap/crud/CrudApplication.java b/src/main/java/org/onap/crud/CrudApplication.java index b2b2611..b91794d 100644 --- a/src/main/java/org/onap/crud/CrudApplication.java +++ b/src/main/java/org/onap/crud/CrudApplication.java @@ -22,18 +22,14 @@ package org.onap.crud; import java.util.Collections; import java.util.HashMap; - import javax.annotation.PostConstruct; - import org.eclipse.jetty.util.security.Password; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.boot.web.support.SpringBootServletInitializer; -import org.springframework.context.annotation.Import; import org.springframework.context.annotation.ImportResource; import org.springframework.core.env.Environment; - import springfox.documentation.builders.PathSelectors; import springfox.documentation.builders.RequestHandlerSelectors; import springfox.documentation.service.ApiInfo; @@ -47,7 +43,6 @@ import springfox.documentation.swagger2.annotations.EnableSwagger2; */ @SpringBootApplication @EnableSwagger2 -@Import({SchemaIngestConfiguration.class, SchemaLoaderConfiguration.class}) @ImportResource({"file:${SERVICE_BEANS}/*.xml"}) public class CrudApplication extends SpringBootServletInitializer{// NOSONAR @Autowired @@ -59,8 +54,13 @@ public class CrudApplication extends SpringBootServletInitializer{// NOSONAR throw new RuntimeException("Env property KEY_STORE_PASSWORD not set"); } HashMap<String, Object> props = new HashMap<>(); - props.put("server.ssl.key-store-password", Password.deobfuscate(keyStorePassword)); - new CrudApplication().configure(new SpringApplicationBuilder(SchemaIngestConfiguration.class, SchemaLoaderConfiguration.class).child(CrudApplication.class).properties(props)).run(args); + String deobfuscatedKeyStorePassword = Password.deobfuscate(keyStorePassword); + props.put("server.ssl.key-store-password", deobfuscatedKeyStorePassword); + props.put("schema.service.ssl.key-store-password", deobfuscatedKeyStorePassword); + props.put("schema.service.ssl.trust-store-password", deobfuscatedKeyStorePassword); + new CrudApplication() + .configure(new SpringApplicationBuilder(CrudApplication.class).properties(props)) + .run(args); } /** @@ -85,8 +85,6 @@ public class CrudApplication extends SpringBootServletInitializer{// NOSONAR public static final ApiInfo DEFAULT_API_INFO = new ApiInfo("AAI NCSO Adapter Service", "AAI NCSO Adapter Service.", "1.0", "urn:tos", DEFAULT_CONTACT, "Apache 2.0", "API license URL", Collections.emptyList()); - - public Docket api() { return new Docket(DocumentationType.SWAGGER_2).apiInfo(DEFAULT_API_INFO).select().paths(PathSelectors.any()) .apis(RequestHandlerSelectors.basePackage("org.onap.crud")).build(); diff --git a/src/main/java/org/onap/crud/SchemaIngestConfiguration.java b/src/main/java/org/onap/crud/SchemaIngestConfiguration.java index ee050dd..ca76dbd 100644 --- a/src/main/java/org/onap/crud/SchemaIngestConfiguration.java +++ b/src/main/java/org/onap/crud/SchemaIngestConfiguration.java @@ -26,37 +26,44 @@ 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.onap.aai.setup.Translator; +import org.onap.schema.EdgePropsConfiguration; +import org.onap.schema.EdgeRulesLoader; +import org.onap.schema.OxmModelLoader; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.PropertySource; @Configuration +@ComponentScan(basePackages = {"org.onap.aai.config", "org.onap.aai.setup"}) @PropertySource(value = "file:${schema.ingest.file}", ignoreResourceNotFound = true) +@PropertySource(value = "file:${edgeprops.ingest.file}", ignoreResourceNotFound = true) public class SchemaIngestConfiguration { - @Bean - public SchemaVersions schemaVersions() { - return new SchemaVersions(); - } + @Autowired + private Translator translator; @Bean - public SchemaLocationsBean schemaLocationsBean() { - return new SchemaLocationsBean(); + public OxmModelLoader oxmModelLoader(NodeIngestor nodeIngestor) { + return new OxmModelLoader(translator, nodeIngestor ); } @Bean - public ConfigTranslator configTranslator() { - return new AAIConfigTranslator(schemaLocationsBean(), schemaVersions()); + public EdgeRulesLoader edgeRulesLoader(EdgeIngestor edgeIngestor) { + return new EdgeRulesLoader(translator, edgeIngestor, edgePropsConfiguration() ); } @Bean - public NodeIngestor nodeIngestor() { - return new NodeIngestor(configTranslator()); + public EdgePropsConfiguration edgePropsConfiguration() { + return new EdgePropsConfiguration(); } @Bean - public EdgeIngestor edgeIngestor() { - return new EdgeIngestor(configTranslator(), schemaVersions()); + @ConditionalOnExpression("'${schema.translator.list}'.contains('config')") + public ConfigTranslator configTranslator(SchemaLocationsBean schemaLocationsBean, SchemaVersions schemaVersions) { + return new AAIConfigTranslator(schemaLocationsBean, schemaVersions); } - }
\ No newline at end of file diff --git a/src/main/java/org/onap/crud/dao/champ/ChampDao.java b/src/main/java/org/onap/crud/dao/champ/ChampDao.java index 81980cc..8563807 100644 --- a/src/main/java/org/onap/crud/dao/champ/ChampDao.java +++ b/src/main/java/org/onap/crud/dao/champ/ChampDao.java @@ -35,7 +35,6 @@ import org.apache.http.client.utils.URLEncodedUtils; import org.apache.http.message.BasicNameValuePair; import org.eclipse.jetty.util.security.Password; import org.onap.aai.cl.mdc.MdcContext; -import org.onap.aai.logging.LoggingContext; import org.onap.aai.restclient.client.OperationResult; import org.onap.aai.restclient.client.RestClient; import org.onap.aai.restclient.enums.RestAuthenticationMode; @@ -411,7 +410,7 @@ public class ChampDao implements GraphDao { String url = baseTransactionUrl + "/" + id; Map<String, List<String>> headers = new HashMap<>(); headers.put(HEADER_FROM_APP, Arrays.asList("Gizmo")); - headers.put(HEADER_TRANS_ID, Arrays.asList(MDC.get(LoggingContext.LoggingField.REQUEST_ID.toString()))); + headers.put(HEADER_TRANS_ID, Arrays.asList(MDC.get(MdcContext.MDC_REQUEST_ID))); OperationResult getResult = client.get(url, headers, MediaType.APPLICATION_JSON_TYPE); @@ -550,7 +549,7 @@ public class ChampDao implements GraphDao { throw createErrorException(getResult, javax.ws.rs.core.Response.Status.NOT_FOUND, "No edge with id " + id + " found in graph"); } } - + @Override public Edge getEdge(String id) throws CrudException { String url = baseRelationshipUrl + "/" + id; diff --git a/src/main/java/org/onap/crud/service/AbstractGraphDataService.java b/src/main/java/org/onap/crud/service/AbstractGraphDataService.java index db4c4d8..14ea242 100644 --- a/src/main/java/org/onap/crud/service/AbstractGraphDataService.java +++ b/src/main/java/org/onap/crud/service/AbstractGraphDataService.java @@ -20,6 +20,10 @@ */ package org.onap.crud.service; +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.gson.JsonElement; +import com.google.gson.reflect.TypeToken; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -28,6 +32,7 @@ import java.util.Set; import javax.ws.rs.core.EntityTag; import javax.ws.rs.core.HttpHeaders; import javax.ws.rs.core.Response.Status; +import net.dongliu.gson.GsonJava8TypeAdapterFactory; import org.apache.commons.lang3.tuple.ImmutablePair; import org.onap.aai.restclient.client.OperationResult; import org.onap.crud.dao.GraphDao; @@ -44,18 +49,12 @@ import org.onap.crud.parser.util.EdgePayloadUtil; import org.onap.crud.util.CrudServiceUtil; import org.onap.schema.validation.OxmModelValidator; import org.onap.schema.validation.RelationshipSchemaValidator; -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; -import com.google.gson.JsonElement; -import com.google.gson.reflect.TypeToken; -import net.dongliu.gson.GsonJava8TypeAdapterFactory; public abstract class AbstractGraphDataService { protected GraphDao daoForGet; protected GraphDao dao; public AbstractGraphDataService() throws CrudException { - CrudServiceUtil.loadModels(); } public ImmutablePair<EntityTag, String> getEdge(String version, String id, String type, Map<String, String> queryParams) throws CrudException { diff --git a/src/main/java/org/onap/crud/util/CrudServiceUtil.java b/src/main/java/org/onap/crud/util/CrudServiceUtil.java index 5eeb38e..2441776 100644 --- a/src/main/java/org/onap/crud/util/CrudServiceUtil.java +++ b/src/main/java/org/onap/crud/util/CrudServiceUtil.java @@ -20,6 +20,9 @@ */ package org.onap.crud.util; +import com.google.gson.Gson; +import com.google.gson.JsonElement; +import com.google.gson.JsonPrimitive; import java.util.AbstractMap; import java.util.HashSet; import java.util.Map; @@ -29,22 +32,18 @@ import javax.ws.rs.core.EntityTag; import javax.ws.rs.core.HttpHeaders; import javax.ws.rs.core.MultivaluedMap; import javax.ws.rs.core.Response.Status; -import org.onap.aai.db.props.AAIProperties; import org.onap.crud.exception.CrudException; import org.onap.crud.parser.EdgePayload; import org.onap.crud.parser.util.EdgePayloadUtil; import org.onap.schema.EdgeRulesLoader; -import org.onap.schema.OxmModelLoader; import org.onap.schema.RelationshipSchema; -import com.google.gson.Gson; -import com.google.gson.JsonElement; -import com.google.gson.JsonPrimitive; - public class CrudServiceUtil { private static Gson gson = new Gson(); - + public static final java.lang.String LAST_MOD_SOURCE_OF_TRUTH = "last-mod-source-of-truth"; + public static final java.lang.String SOURCE_OF_TRUTH = "source-of-truth"; + @SuppressWarnings({"unchecked", "rawtypes"}) public static Object validateFieldType(String value, Class clazz) throws CrudException { try { @@ -76,16 +75,6 @@ public class CrudServiceUtil { } } - public static void loadModels() throws CrudException { - // load the schemas - try { - OxmModelLoader.loadModels(); - EdgeRulesLoader.loadModels (); - } catch (Exception e) { - throw new CrudException(e); - } - } - /** * This method will merge header property from app id in request payload if not already populated * @param propertiesFromRequest @@ -96,22 +85,22 @@ public class CrudServiceUtil { @SuppressWarnings("unchecked") public static JsonElement mergeHeaderInFoToPayload(JsonElement propertiesFromRequest, HttpHeaders headers, boolean isAdd) { - String sourceOfTruth = headers.getRequestHeaders().getFirst("X-FromAppId"); + String sourceOfTruth = headers.getRequestHeaders().getFirst("X-FromAppId"); Set<Map.Entry<String, JsonElement>> properties = new HashSet<Map.Entry<String, JsonElement>>(); properties.addAll(propertiesFromRequest.getAsJsonObject().entrySet()); - + Set<String> propertyKeys = new HashSet<String>(); for(Map.Entry<String, JsonElement> property : properties) { propertyKeys.add(property.getKey()); } - - if(!propertyKeys.contains(AAIProperties.LAST_MOD_SOURCE_OF_TRUTH)) { - properties.add(new AbstractMap.SimpleEntry<String, JsonElement>(AAIProperties.LAST_MOD_SOURCE_OF_TRUTH, + + if(!propertyKeys.contains(LAST_MOD_SOURCE_OF_TRUTH)) { + properties.add(new AbstractMap.SimpleEntry<String, JsonElement>(LAST_MOD_SOURCE_OF_TRUTH, (new JsonPrimitive(sourceOfTruth)))); } - - if(isAdd && !propertyKeys.contains(AAIProperties.SOURCE_OF_TRUTH)) { - properties.add(new AbstractMap.SimpleEntry<String, JsonElement>(AAIProperties.SOURCE_OF_TRUTH, + + if(isAdd && !propertyKeys.contains(SOURCE_OF_TRUTH)) { + properties.add(new AbstractMap.SimpleEntry<String, JsonElement>(SOURCE_OF_TRUTH, (new JsonPrimitive(sourceOfTruth)))); } @@ -144,23 +133,22 @@ public class CrudServiceUtil { public static String determineEdgeType(EdgePayload payload, String version) throws CrudException { RelationshipSchema schema = EdgeRulesLoader.getSchemaForVersion(version); - + if (payload.getSource() == null || payload.getTarget() == null) { throw new CrudException("Source/Target not specified", Status.BAD_REQUEST); } - - Set<String> edgeTypes = schema.getValidRelationTypes(EdgePayloadUtil.getVertexNodeType(payload.getSource()), + + Set<String> edgeTypes = schema.getValidRelationTypes(EdgePayloadUtil.getVertexNodeType(payload.getSource()), EdgePayloadUtil.getVertexNodeType(payload.getTarget())); - + if (edgeTypes.size() == 0) { throw new CrudException("No valid relationship types from " + payload.getSource() + " to " + payload.getTarget(), Status.BAD_REQUEST); } - + if (edgeTypes.size() > 1) { throw new CrudException("Multiple possible relationship types from " + payload.getSource() + " to " + payload.getTarget(), Status.BAD_REQUEST); } - + return edgeTypes.iterator().next(); } - } diff --git a/src/main/java/org/onap/schema/EdgeRulesLoader.java b/src/main/java/org/onap/schema/EdgeRulesLoader.java index 2c139a7..47be12b 100644 --- a/src/main/java/org/onap/schema/EdgeRulesLoader.java +++ b/src/main/java/org/onap/schema/EdgeRulesLoader.java @@ -32,6 +32,7 @@ import java.util.regex.Matcher; import java.util.regex.Pattern;
import java.util.stream.Collectors;
+import javax.annotation.PostConstruct;
import javax.ws.rs.core.Response.Status;
import org.apache.commons.io.IOUtils;
@@ -39,8 +40,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.crud.exception.CrudException;
import org.onap.crud.logging.CrudServiceMsgs;
import org.springframework.beans.factory.annotation.Autowired;
@@ -48,8 +49,8 @@ import org.springframework.beans.factory.annotation.Autowired; import com.google.common.collect.Multimap;
public class EdgeRulesLoader {
-
- private static ConfigTranslator configTranslator;
+
+ private static Translator translator;
private static EdgeIngestor edgeIngestor;
private static EdgePropsConfiguration edgePropsConfiguration;
@@ -67,14 +68,19 @@ public class EdgeRulesLoader { LoggerFactory.getInstance ().getLogger ( EdgeRulesLoader.class.getName () );
private EdgeRulesLoader () { }
-
+
@Autowired
- public EdgeRulesLoader(ConfigTranslator configTranslator, EdgeIngestor edgeIngestor, EdgePropsConfiguration edgePropsConfiguration) {
- EdgeRulesLoader.configTranslator = configTranslator;
+ public EdgeRulesLoader(Translator translator, EdgeIngestor edgeIngestor, EdgePropsConfiguration edgePropsConfiguration) {
+ EdgeRulesLoader.translator = translator;
EdgeRulesLoader.edgeIngestor = edgeIngestor;
EdgeRulesLoader.edgePropsConfiguration = edgePropsConfiguration;
}
+ @PostConstruct
+ public void init() throws CrudException {
+ EdgeRulesLoader.loadModels();
+ }
+
/**
* Finds all DB Edge Rules and Edge Properties files for all OXM models.
*
@@ -89,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) {
@@ -112,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/schema/OxmModelLoader.java b/src/main/java/org/onap/schema/OxmModelLoader.java index 12f8f09..fb41fc9 100644 --- a/src/main/java/org/onap/schema/OxmModelLoader.java +++ b/src/main/java/org/onap/schema/OxmModelLoader.java @@ -29,14 +29,15 @@ import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import java.util.regex.Matcher; import java.util.regex.Pattern; +import javax.annotation.PostConstruct; import javax.ws.rs.core.Response.Status; import org.eclipse.persistence.dynamic.DynamicType; 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.crud.exception.CrudException; import org.onap.crud.logging.CrudServiceMsgs; import org.springframework.beans.factory.annotation.Autowired; @@ -45,9 +46,9 @@ 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<>(); private static Map<String, HashMap<String, DynamicType>> xmlElementLookup = new ConcurrentHashMap<>(); @@ -57,13 +58,18 @@ public class OxmModelLoader { LoggerFactory.getInstance().getLogger(OxmModelLoader.class.getName()); private OxmModelLoader() { } - + @Autowired - public OxmModelLoader(ConfigTranslator configTranslator, NodeIngestor nodeIngestor) { - OxmModelLoader.configTranslator = configTranslator; + public OxmModelLoader(Translator translator, NodeIngestor nodeIngestor) { + OxmModelLoader.translator = translator; OxmModelLoader.nodeIngestor = nodeIngestor; } + @PostConstruct + public void init() throws CrudException { + OxmModelLoader.loadModels(); + } + /** * Finds all OXM model files * @@ -77,7 +83,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); @@ -166,8 +172,8 @@ public class OxmModelLoader { public static void setVersionContextMap(Map<String, DynamicJAXBContext> versionContextMap) { OxmModelLoader.versionContextMap = versionContextMap; } - - + + public static void loadXmlLookupMap(String version, DynamicJAXBContext jaxbContext ) { @SuppressWarnings("rawtypes") @@ -183,8 +189,8 @@ public class OxmModelLoader { } xmlElementLookup.put(version, types); } - - + + public static DynamicType getDynamicTypeForVersion(String version, String type) throws CrudException { DynamicType dynamicType; @@ -220,7 +226,7 @@ public class OxmModelLoader { return dynamicType; } - + /** * Retrieves the list of all Loaded OXM versions. * |