From 86e7411b128bd7db440eceff7265533844e577bb Mon Sep 17 00:00:00 2001 From: "LaMont, William(wl2432)" Date: Tue, 14 Apr 2020 14:00:00 -0400 Subject: schema-service processing for v19 Issue-ID: AAI-2864 Change-Id: I41a430ec9c9fd69be75bd9d01693249895e0928b Signed-off-by: LaMont, William(wl2432) --- .../org/onap/aai/queries/CustomQueryConfig.java | 53 +++++ .../org/onap/aai/queries/GetCustomQueryConfig.java | 149 +++++++++++++ .../onap/aai/queries/GremlinServerSingleton.java | 117 +++++++++++ .../main/resources/etc/appprops/error.properties | 167 +++++++++++++++ .../test/java/org/onap/aai/queries/AAISetup.java | 132 ++++++++++++ .../java/org/onap/aai/queries/OnapQueryTest.java | 230 +++++++++++++++++++++ .../aai/queries/VnfToEsrSystemInfoQueryTest.java | 96 +++++++++ .../resources/application-onap-test.properties | 33 +++ .../src/test/resources/application-test.properties | 34 +++ aai-queries/src/test/resources/logback.xml | 81 ++++++++ .../src/test/resources/schema-ingest.properties | 10 + 11 files changed, 1102 insertions(+) create mode 100644 aai-queries/src/main/java/org/onap/aai/queries/CustomQueryConfig.java create mode 100644 aai-queries/src/main/java/org/onap/aai/queries/GetCustomQueryConfig.java create mode 100644 aai-queries/src/main/java/org/onap/aai/queries/GremlinServerSingleton.java create mode 100644 aai-queries/src/main/resources/etc/appprops/error.properties create mode 100644 aai-queries/src/test/java/org/onap/aai/queries/AAISetup.java create mode 100644 aai-queries/src/test/java/org/onap/aai/queries/OnapQueryTest.java create mode 100644 aai-queries/src/test/java/org/onap/aai/queries/VnfToEsrSystemInfoQueryTest.java create mode 100644 aai-queries/src/test/resources/application-onap-test.properties create mode 100644 aai-queries/src/test/resources/application-test.properties create mode 100644 aai-queries/src/test/resources/logback.xml create mode 100644 aai-queries/src/test/resources/schema-ingest.properties (limited to 'aai-queries/src') diff --git a/aai-queries/src/main/java/org/onap/aai/queries/CustomQueryConfig.java b/aai-queries/src/main/java/org/onap/aai/queries/CustomQueryConfig.java new file mode 100644 index 0000000..5a58923 --- /dev/null +++ b/aai-queries/src/main/java/org/onap/aai/queries/CustomQueryConfig.java @@ -0,0 +1,53 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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.queries; + +import java.util.List; + +public class CustomQueryConfig { + public CustomQueryConfig() { + // used by GetCustomQueryConfig + } + + + private String query; + private List queryOptionalProperties; + private List queryRequiredProperties; + + public void setQuery(String query) { + this.query = query; + } + public String getQuery() { + return this.query; + } + + public void setQueryOptionalProperties( List queryOptionalProperties) { + this.queryOptionalProperties = queryOptionalProperties; + } + public List getQueryOptionalProperties( ) { + return queryOptionalProperties; + } + public void setQueryRequiredProperties( List queryRequiredProperties) { + this.queryRequiredProperties = queryRequiredProperties; + } + public List getQueryRequiredProperties( ) { + return queryRequiredProperties; + } +} diff --git a/aai-queries/src/main/java/org/onap/aai/queries/GetCustomQueryConfig.java b/aai-queries/src/main/java/org/onap/aai/queries/GetCustomQueryConfig.java new file mode 100644 index 0000000..ed4ff99 --- /dev/null +++ b/aai-queries/src/main/java/org/onap/aai/queries/GetCustomQueryConfig.java @@ -0,0 +1,149 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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.queries; + +import com.google.gson.*; +import com.google.gson.reflect.TypeToken; + +import java.lang.reflect.Type; +import java.util.ArrayList; +import java.util.List; + +public class GetCustomQueryConfig { + + private JsonArray storedQueries = null; + private CustomQueryConfig customQueryConfig; + + + private final static String QUERY_CONFIG = "query"; + private final static String REQUIRED_CONFIG = "required-properties"; + private final static String OPTIONAL_CONFIG = "optional-properties"; + private final static String STORED_QUERIES_CONFIG = "stored-queries"; + private final static String STORED_QUERY_CONFIG = "stored-query"; + +// public static final String AAI_HOME_ETC_QUERY_JSON = AAIConstants.AAI_HOME_ETC + "query" + AAIConstants.AAI_FILESEP + "stored-queries.json"; + + public GetCustomQueryConfig(String customQueryJson ) { + init(customQueryJson); + } + + private void init( String customQueryJson) { + JsonParser parser = new JsonParser(); + JsonObject queriesObject = parser.parse(customQueryJson).getAsJsonObject(); + if (queriesObject.has(STORED_QUERIES_CONFIG)) { + + storedQueries = queriesObject.getAsJsonArray(STORED_QUERIES_CONFIG); + } + } + + private List toStringList(JsonArray array) { + Gson converter = new Gson(); + Type listType = new TypeToken>() {}.getType(); + return converter.fromJson(array, listType); + } + + private List getPropertyList(JsonObject configObject, String config ) { + JsonElement subqueryConfig; + JsonArray props; + + if ( configObject.has(config)) { + subqueryConfig = configObject.get(config); + if ( subqueryConfig != null && !subqueryConfig.isJsonNull() ) { + props = subqueryConfig.getAsJsonArray(); + if ( props != null ) { + return toStringList(props); + } + } + } + return toStringList(null); + } + + private String getPropertyString(JsonObject configObject, String config) { + JsonElement subqueryConfig; + + if ( configObject.has(config)) { + subqueryConfig = configObject.get(config); + if ( subqueryConfig != null && !subqueryConfig.isJsonNull() ) { + return subqueryConfig.getAsString(); + } + } + return null; + } + + private void getStoredQueryBlock( JsonObject configObject, String config ) { + if ( !configObject.has(config)) { + customQueryConfig.setQueryRequiredProperties( new ArrayList() ); + customQueryConfig.setQueryOptionalProperties( new ArrayList() ); + return; + } + + JsonElement queryConfig; + JsonObject subObject; + String multipleStartNodes; + List propertyList; + + queryConfig = configObject.get(config); + subObject = queryConfig.getAsJsonObject(); + propertyList = getPropertyList(subObject, REQUIRED_CONFIG); + if ( propertyList == null ) { + propertyList = new ArrayList(); + } + customQueryConfig.setQueryRequiredProperties( propertyList ); + propertyList = getPropertyList(subObject, OPTIONAL_CONFIG); + if ( propertyList == null ) { + propertyList = new ArrayList(); + } + customQueryConfig.setQueryOptionalProperties( propertyList ); + + } + + + public CustomQueryConfig getStoredQuery(String queryName ) { + + customQueryConfig = null; + JsonObject configObject; + JsonElement query; + JsonElement queryConfig; + String queryString; + + for (JsonElement storedQuery : storedQueries) { + if (storedQuery.isJsonObject()) { + JsonObject queryObject = storedQuery.getAsJsonObject(); + query = queryObject.get(queryName); + if ( query != null ) { + customQueryConfig = new CustomQueryConfig(); + configObject = query.getAsJsonObject(); + getStoredQueryBlock(configObject, QUERY_CONFIG); + if ( configObject.has(STORED_QUERY_CONFIG)) { + queryConfig = configObject.get(STORED_QUERY_CONFIG); + customQueryConfig.setQuery(queryConfig.getAsString()); + } + break; + } + } + } + + return customQueryConfig; + + } + + + +} diff --git a/aai-queries/src/main/java/org/onap/aai/queries/GremlinServerSingleton.java b/aai-queries/src/main/java/org/onap/aai/queries/GremlinServerSingleton.java new file mode 100644 index 0000000..3b4a406 --- /dev/null +++ b/aai-queries/src/main/java/org/onap/aai/queries/GremlinServerSingleton.java @@ -0,0 +1,117 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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.queries; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import org.onap.aai.aaf.auth.FileWatcher; +import org.onap.aai.logging.LogFormatTools; +import org.onap.aai.util.AAIConstants; + +import org.springframework.beans.factory.annotation.Value; +import javax.annotation.PostConstruct; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.Date; +import java.util.Timer; +import java.util.TimerTask; + +public class GremlinServerSingleton { + + private static Logger logger = LoggerFactory.getLogger(GremlinServerSingleton.class); + + private boolean timerSet; + private Timer timer; + + private GetCustomQueryConfig queryConfig; + + @Value("${schema.queries.location}") + private String storedQueriesLocation; + + /** + * Initializes the gremlin server singleton + * Loads the configuration of the gremlin server and creates a cluster + * Loads the gremlin query file into the properties object + * Then creates a file watcher to watch the file every ten seconds + * and if there is a change in the file, then reloads the file into + * the properties object + * + */ + @PostConstruct + public void init() { + + try { + String filepath = storedQueriesLocation + AAIConstants.AAI_FILESEP + "stored-queries.json"; + Path path = Paths.get(filepath); + String customQueryConfigJson = new String(Files.readAllBytes(path)); + + + queryConfig = new GetCustomQueryConfig(customQueryConfigJson); + } catch (IOException e) { + logger.error("Error occurred during the processing of query json file: " + LogFormatTools.getStackTop(e)); + } + + + TimerTask task = new FileWatcher(new File(storedQueriesLocation)) { + @Override + protected void onChange(File file) { + try { + String filepath = storedQueriesLocation; + Path path = Paths.get(filepath); + String customQueryConfigJson = new String(Files.readAllBytes(path)); + queryConfig = new GetCustomQueryConfig(customQueryConfigJson); + } catch (IOException e) { + logger.error("Error occurred during the processing of query json file: " + LogFormatTools.getStackTop(e)); + } + } + }; + + if (!timerSet) { + timerSet = true; + timer = new Timer(); + timer.schedule( task , new Date(), 10000 ); + } + + } + + /** + * Gets the query using CustomQueryConfig + * @param key + * @return + */ + public String getStoredQueryFromConfig(String key){ + CustomQueryConfig customQueryConfig = queryConfig.getStoredQuery(key); + if ( customQueryConfig == null ) { + return null; + } + return customQueryConfig.getQuery(); + } + + public CustomQueryConfig getCustomQueryConfig(String key) { + return queryConfig.getStoredQuery(key); + } + + +} diff --git a/aai-queries/src/main/resources/etc/appprops/error.properties b/aai-queries/src/main/resources/etc/appprops/error.properties new file mode 100644 index 0000000..fc8bcde --- /dev/null +++ b/aai-queries/src/main/resources/etc/appprops/error.properties @@ -0,0 +1,167 @@ +# Adding comment trying to trigger a build +#------------------------------------------------------------------------------- ---------- +#Key=Disposition:Category:Severity:Error Code:HTTP ResponseCode:RESTError Code:Error Message +#------------------------------------------------------------------------------- ---------- +# testing code, please don't change unless error utility source code changes +AAI_TESTING=5:2:WARN:0000:400:0001:Error code for testing +# General success +AAI_0000=0:0:INFO:0000:200:0000:Success +# health check success +AAI_0001=0:0:INFO:0001:200:0001:Success X-FromAppId=%1 X-TransactionId=%2 +AAI_0002=0:0:INFO:0002:200:0001:Successful health check +# Success with additional info +AAI_0003=0:3:INFO:0003:202:0003:Success with additional info performing %1 on %2. Added %3 with key %4 +AAI_0004=0:3:INFO:0004:202:0003:Added prerequisite object to db +#--- aairest: 3000-3299 +# svc errors +AAI_3000=5:2:INFO:3000:400:3000:Invalid input performing %1 on %2 +AAI_3001=5:6:INFO:3001:404:3001:Resource not found for %1 using id %2 +AAI_3002=5:1:WARN:3002:400:3002:Error writing output performing %1 on %2 +AAI_3003=5:1:WARN:3003:400:3003:Failed to make edge to missing target node of type %3 with keys %4 performing %1 on %2 +AAI_3005=5:6:WARN:3005:404:3001:Node cannot be directly accessed for read, must be accessed via ancestor(s) +AAI_3006=5:6:WARN:3006:404:3001:Node cannot be directly accessed for write, must be accessed via ancestor(s) +AAI_3007=5:6:INFO:3007:410:3007:This version (%1) of the API is retired, please migrate to %2 +AAI_3008=5:6:WARN:3008:400:3008:URI is not encoded in UTF-8 +AAI_3009=5:6:WARN:3009:400:3002:Malformed URL +AAI_3010=5:6:WARN:3010:400:3002:Cannot write via this URL +AAI_3011=5:6:WARN:3011:400:3000:Unknown XML namespace used in payload +AAI_3012=5:6:WARN:3012:400:3012:Unrecognized AAI function +AAI_3013=5:6:WARN:3013:400:3013:Query payload missing required parameters %1 +AAI_3014=5:6:WARN:3014:400:3014:Query payload is invalid %1 +AAI_3015=5:6:INFO:3015:410:3015:The %1 capability is retired, please contact the A&AI SE team to identify a replacement query +AAI_3016=5:6:INFO:3007:400:3016:Request uri is not valid, please check the version %1 +AAI_3017=5:6:INFO:3007:400:3016:Request uri is not valid, please check the uri %1 +AAI_3018=5:6:INFO:3018:400:3018:Request schema version %1 is not valid, please check the schema version +AAI_3050=5:1:WARN:3002:400:3002:Invalid request, missing or empty query parameter version +AAI_3051=5:1:WARN:3002:400:3002:Invalid request, version parameter %1 passed is not conforming to the following pattern v[1-9][0-9]* +# pol errors +AAI_3100=5:1:WARN:3100:400:3100:Unsupported operation %1 +AAI_3101=5:1:WARN:3101:403:3101:Attempt by client %1 to execute API %2 +AAI_3102=5:1:WARN:3102:400:3102:Error parsing input performing %1 on %2 +AAI_3300=5:1:WARN:3300:403:3300:Unauthorized +AAI_3301=5:1:WARN:3301:401:3301:Stale credentials +AAI_3302=5:1:WARN:3302:401:3301:Not authenticated +AAI_3303=5:1:WARN:3303:403:3300:Too many objects would be returned by this request, please refine your request and retry +#--- aaigen: 4000-4099 +AAI_4000=5:4:ERROR:4000:500:3002:Internal Error +AAI_4001=5:4:FATAL:4001:500:3002:Configuration file not found +AAI_4002=5:4:FATAL:4002:500:3002:Error reading Configuration file +AAI_4003=5:4:ERROR:4003:500:3002:Error writing to log file +AAI_4004=5:4:FATAL:4004:500:3002:Error reading/parsing the error properties file +AAI_4005=5:4:FATAL:4005:500:3002:Missing or invalid configuration parameter +AAI_4006=5:4:FATAL:4006:500:3002:Unexpected error in service +AAI_4007=5:4:WARN:4007:500:3102:Input parsing error +AAI_4008=5:4:ERROR:4008:500:3002:Output parsing error +AAI_4009=4:0:WARN:4009:400:3000:Invalid X-FromAppId in header +AAI_4010=4:0:WARN:4010:400:3000:Invalid X-TransactionId in header +AAI_4011=5:4:ERROR:4011:500:3002:Missing data for REST error response +AAI_4014=4:0:WARN:4014:400:3000:Invalid Accept header +AAI_4015=4:0:WARN:4015:400:3000:You must provide at least one indexed property +AAI_4016=4:0:WARN:4016:400:3000:The depth parameter must be a number or the string "all" +AAI_4017=5:2:INFO:4017:400:3000:Could not set property +AAI_4018=5:2:WARN:4018:400:3000:Unable to convert the string to integer +#--- aaidbmap: 5102-5199 +AAI_5102=5:4:FATAL:5102:500:3002:Graph database is null after open +AAI_5105=5:4:ERROR:5105:500:3002:Unexpected error reading/updating database +AAI_5106=5:4:WARN:5106:404:3001:Node not found +AAI_5107=5:2:WARN:5107:400:3000:Required information missing +AAI_5108=5:2:WARN:5108:200:0:Unexpected information in request being ignored +#--- aaidbgen: 6101-6199 +AAI_6101=5:4:ERROR:6101:500:3002:null JanusGraph object passed +AAI_6102=5:4:WARN:6102:400:3000:Passed-in property is not valid for this nodeType +AAI_6103=5:4:WARN:6103:400:3000:Required Node-property not found in input data +AAI_6104=5:4:WARN:6104:400:3000:Required Node-property was passed with no data +AAI_6105=5:4:WARN:6105:400:3000:Node-Key-Property not defined in DbMaps +AAI_6106=5:4:WARN:6106:400:3000:Passed-in property is not valid for this edgeType +AAI_6107=5:4:WARN:6107:400:3000:Required Edge-property not found in input data +AAI_6108=5:4:WARN:6108:400:3000:Required Edge-property was passed with no data +AAI_6109=5:4:WARN:6109:400:3000:Bad dependent Node value +AAI_6110=5:4:ERROR:6110:400:3100:Node cannot be deleted +AAI_6111=5:4:WARN:6111:400:3000:JSON processing error +AAI_6112=5:4:ERROR:6112:400:3000:More than one node found by getUniqueNode() +AAI_6114=5:4:INFO:6114:404:3001:Node Not Found +AAI_6115=5:4:ERROR:6115:400:3000:Unrecognized NodeType +AAI_6116=5:4:ERROR:6116:400:3000:Unrecognized Property +AAI_6117=5:4:ERROR:6117:400:3000:Uniqueness constraint violated +AAI_6118=5:4:WARN:6118:400:3000:Required Field not passed. +AAI_6120=5:4:WARN:6120:400:3000:Bad Parameter Passed +AAI_6121=5:4:ERROR:6121:400:3000:Problem with internal AAI reference data +AAI_6122=5:4:ERROR:6122:400:3000:Data Set not complete in DB for this request +AAI_6123=5:4:ERROR:6123:500:3000:Bad Data found by DataGrooming Tool - Investigate +AAI_6124=5:4:ERROR:6124:500:3000:File read/write error +AAI_6125=5:4:WARN:6125:500:3000:Problem Pulling Data Set +AAI_6126=5:4:ERROR:6126:400:3000:Edge cannot be deleted +AAI_6127=5:4:INFO:6127:404:3001:Edge Not Found +AAI_6128=5:4:INFO:6128:500:3000:Unexpected error +AAI_6129=5:4:INFO:6129:404:3003:Error making edge to target node +AAI_6130=5:4:WARN:6130:412:3000:Precondition Required +AAI_6131=5:4:WARN:6131:412:3000:Precondition Failed +AAI_6132=5:4:WARN:6132:400:3000:Bad Model Definition +AAI_6133=5:4:WARN:6133:400:3000:Bad Named Query Definition +AAI_6134=5:4:ERROR:6134:500:6134:Could not persist transaction to storage back end. Exhausted retry amount +AAI_6135=5:4:WARN:6135:412:3000:Resource version specified on create +AAI_6136=5:4:ERROR:6136:400:3000:Object cannot hold multiple items +AAI_6137=5:4:ERROR:6137:400:3000:Cannot perform writes on multiple vertices +AAI_6138=5:4:ERROR:6138:400:3000:Cannot delete multiple vertices +AAI_6139=5:4:ERROR:6139:404:3000:Attempted to add edge to vertex that does not exist +AAI_6140=5:4:ERROR:6140:400:3000:Edge multiplicity violated +AAI_6141=5:4:WARN:6141:400:3000:Please Refine Query +AAI_6142=5:4:INFO:6142:400:3000:Retrying transaction +AAI_6143=5:4:INFO:6143:400:3000:Ghost vertex found +AAI_6144=5:4:WARN:6144:400:3000:Cycle found in graph +AAI_6145=5:4:ERROR:6145:400:3000:Cannot create a nested/containment edge via relationship +AAI_6146=5:4:ERROR:6146:400:3000:Ambiguous identity map found, use a URI instead +AAI_6147=5:4:ERROR:6147:400:3000:Payload Limit Reached, reduce payload +#--- aaicsvp: 7101-7199 +AAI_7101=5:4:ERROR:7101:500:3002:Unexpected error in CSV file processing +AAI_7102=5:4:ERROR:7102:500:3002:Error in cleanup temporary directory +#AAI_7103=4:2:ERROR:7103:500:3002:Unsupported user +AAI_7104=5:4:ERROR:7104:500:3002:Failed to create directory +AAI_7105=5:4:ERROR:7105:500:3002:Temporary directory exists +AAI_7106=5:4:ERROR:7106:500:3002:Cannot delete +AAI_7107=5:4:ERROR:7107:500:3002:Input file does not exist +AAI_7108=5:4:ERROR:7108:500:3002:Output file does not exist +AAI_7109=5:4:ERROR:7109:500:3002:Error closing file +AAI_7110=5:4:ERROR:7110:500:3002:Error loading/reading properties file +AAI_7111=5:4:ERROR:7111:500:3002:Error executing shell script +AAI_7112=5:4:ERROR:7112:500:3002:Error creating output file +AAI_7113=5:4:ERROR:7113:500:3002:Trailer record error +AAI_7114=5:4:ERROR:7114:500:3002:Input file error +AAI_7115=5:4:ERROR:7115:500:3002:Unexpected error +AAI_7116=5:4:ERROR:7116:500:3002:Request error +AAI_7117=5:4:ERROR:7117:500:3002:Error in get http client object +AAI_7118=5:4:ERROR:7118:500:3002:Script Error +AAI_7119=5:4:ERROR:7119:500:3002:Unknown host +#--- aaisdnc: 7201-7299 +AAI_7202=5:4:ERROR:7202:500:3002:Error getting connection to odl +#AAI_7206=5:4:ERROR:7206:500:3002:Invalid data returned from ODL +#--- NotificationEvent, using UEB space +AAI_7350=5:4:ERROR:7305:500:3002:Notification event creation failed +#--- aairestctlr: 7401-7499 +AAI_7401=5:4:ERROR:7401:500:3002:Error connecting to AAI REST API +AAI_7402=5:4:ERROR:7402:500:3002:Unexpected error +AAI_7403=5:4:WARN:7403:400:3001:Request error +AAI_7404=5:4:INFO:7404:404:3001:Node not found +AAI_7405=5:4:WARN:7405:200:0:UUID not formatted correctly, generating UUID +AAI_7406=5:4:ERROR:7406:400:7406:Request Timed Out +#--- aaicsiovals: 7501-7599 +#AAI_7501=5:4:WARN:7501:500:3002:Error getting connection to CSI-OVALS +AAI_7502=5:4:WARN:7502:500:3002:Bad parameter when trying to build request for CSI-OVALS +AAI_7503=5:4:WARN:7503:500:3002:Error returned by CSI-OVALS +#--- aaiauth: 9101-9199 +AAI_9101=5:0:WARN:9101:403:3300:User is not authorized to perform function +#AAI_9102=5:0:WARN:9102:401:3301:Refresh credentials from source +#AAI_9103=5:0:WARN:9103:403:3300:User not found +#AAI_9104=5:0:WARN:9104:401:3302:Authentication error +#AAI_9105=5:0:WARN:9105:403:3300:Authorization error +#AAI_9106=5:0:WARN:9106:403:3300:Invalid AppId +#AAI_9107=5:0:WARN:9107:403:3300:No Username in Request +AAI_9107=5:0:WARN:9107:403:3300:SSL is not provided in request, please contact admin +AAI_9108=5:0:WARN:9107:403:3300:Basic auth credentials is not provided in the request +#--- aaiinstar: 9201-9299 +#AAI_9201=5:4:ERROR:9201:500:3002:Unable to send notification +AAI_9202=5:4:ERROR:9202:500:3002:Unable to start a thread +#--- GRM DME2: 9501-9599 +AAI_9501=5:4:WARN:9501:500:3002:Unable to register with GRM retrying +AAI_9502=5:4:ERROR:9502:500:3002:Unable to register with GRM after exhausting all retries +AAI_9503=5:4:WARN:9503:500:3002:Unable to successfully unpublish with GRM, recommend manual cleanup but not necessary diff --git a/aai-queries/src/test/java/org/onap/aai/queries/AAISetup.java b/aai-queries/src/test/java/org/onap/aai/queries/AAISetup.java new file mode 100644 index 0000000..551c10d --- /dev/null +++ b/aai-queries/src/test/java/org/onap/aai/queries/AAISetup.java @@ -0,0 +1,132 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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.queries; + +import org.apache.commons.io.IOUtils; +import org.junit.BeforeClass; +import org.junit.ClassRule; +import org.junit.Rule; +import org.onap.aai.config.IntrospectionConfig; +import org.onap.aai.config.RestBeanConfig; +import org.onap.aai.config.SpringContextAware; +import org.onap.aai.edges.EdgeIngestor; +import org.onap.aai.introspection.LoaderFactory; +import org.onap.aai.introspection.MoxyLoader; +import org.onap.aai.nodes.NodeIngestor; +import org.onap.aai.rest.db.HttpEntry; +import org.onap.aai.serialization.db.EdgeSerializer; +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.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit4.rules.SpringClassRule; +import org.springframework.test.context.junit4.rules.SpringMethodRule; + +import java.io.IOException; +import java.io.InputStream; +import java.util.Map; + +import static org.junit.Assert.assertNotNull; + +@ContextConfiguration(classes = { + SchemaLocationsBean.class, + SchemaVersions.class, + AAIConfigTranslator.class, + EdgeIngestor.class, + EdgeSerializer.class, + NodeIngestor.class, + SpringContextAware.class, + IntrospectionConfig.class , + RestBeanConfig.class, + GremlinServerSingleton.class +}) +@TestPropertySource(properties = { + "schema.uri.base.path = /aai", + "schema.ingest.file = src/test/resources/application-test.properties" +}) +public abstract class AAISetup { + @Autowired + protected NodeIngestor nodeIngestor; + + @Autowired + protected LoaderFactory loaderFactory; + + @Autowired + protected Map moxyLoaderInstance; + + @Autowired + protected HttpEntry traversalHttpEntry; + + @Autowired + protected HttpEntry traversalUriHttpEntry; + + @Autowired + protected EdgeSerializer edgeSer; + + @Autowired + protected EdgeIngestor edgeIngestor; + + @Autowired + protected SchemaVersions schemaVersions; + + @Autowired + protected GremlinServerSingleton gremlinServerSingleton; + + @Value("${schema.uri.base.path}") + protected String basePath; + + @ClassRule + public static final SpringClassRule springClassRule = new SpringClassRule(); + + @Rule + public final SpringMethodRule springMethodRule = new SpringMethodRule(); + + @BeforeClass + public static void setupBundleconfig() throws Exception { + System.setProperty("AJSC_HOME", "./"); + System.setProperty("BUNDLECONFIG_DIR", "src/main/resources/"); + + } + + public String getPayload(String filename) throws IOException { + + InputStream inputStream = getClass() + .getClassLoader() + .getResourceAsStream(filename); + + String message = String.format("Unable to find the %s in src/test/resources", filename); + assertNotNull(message, inputStream); + + String resource = IOUtils.toString(inputStream); + return resource; + } +} + + + + + + + + diff --git a/aai-queries/src/test/java/org/onap/aai/queries/OnapQueryTest.java b/aai-queries/src/test/java/org/onap/aai/queries/OnapQueryTest.java new file mode 100644 index 0000000..d25aff6 --- /dev/null +++ b/aai-queries/src/test/java/org/onap/aai/queries/OnapQueryTest.java @@ -0,0 +1,230 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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.queries; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import com.google.gson.Gson; +import com.google.gson.stream.JsonReader; +import com.jayway.jsonpath.JsonPath; + +import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal; +import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; +import org.apache.tinkerpop.gremlin.structure.Graph; +import org.apache.tinkerpop.gremlin.structure.Vertex; +import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerGraph; +import org.json.JSONObject; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.ClassRule; +import org.junit.Rule; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import org.onap.aai.config.IntrospectionConfig; +import org.onap.aai.config.SpringContextAware; +import org.onap.aai.edges.EdgeIngestor; +import org.onap.aai.edges.exceptions.AmbiguousRuleChoiceException; +import org.onap.aai.edges.exceptions.EdgeRuleNotFoundException; +import org.onap.aai.exceptions.AAIException; +import org.onap.aai.introspection.Loader; +import org.onap.aai.introspection.LoaderFactory; +import org.onap.aai.introspection.ModelType; +import org.onap.aai.nodes.NodeIngestor; +import org.onap.aai.queries.GremlinServerSingleton; +import org.onap.aai.query.builder.GremlinTraversal; +import org.onap.aai.restcore.search.GremlinGroovyShell; +import org.onap.aai.restcore.search.GroovyQueryBuilder; +import org.onap.aai.serialization.db.EdgeSerializer; +import org.onap.aai.serialization.db.exceptions.NoEdgeRuleFoundException; +import org.onap.aai.serialization.engines.QueryStyle; +import org.onap.aai.serialization.engines.TransactionalGraphEngine; +import org.onap.aai.setup.*; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.core.env.Environment; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit4.rules.SpringClassRule; +import org.springframework.test.context.junit4.rules.SpringMethodRule; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.IOException; +import java.nio.charset.Charset; +import java.nio.file.Files; +import java.util.*; +import java.util.stream.Collectors; + +import static org.junit.Assert.assertEquals; +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.when; + +@RunWith(Parameterized.class) +@ContextConfiguration(classes = { + SchemaLocationsBean.class, + SchemaConfigVersions.class, + AAIConfigTranslator.class, + EdgeIngestor.class, + EdgeSerializer.class, + NodeIngestor.class, + SpringContextAware.class, + GremlinServerSingleton.class, + IntrospectionConfig.class +}) +@TestPropertySource(properties = { + "schema.uri.base.path = /aai", + "schema.source.name = onap", + "schema.ingest.file = src/test/resources/application-test.properties" +}) +public abstract class OnapQueryTest { + + @ClassRule + public static final SpringClassRule springClassRule = new SpringClassRule(); + + @Rule + public final SpringMethodRule springMethodRule = new SpringMethodRule(); + + protected Logger logger; + protected Graph graph; + protected GremlinGroovyShell shell; + @Mock protected TransactionalGraphEngine dbEngine; + protected final List expectedResult = new ArrayList<>(); + + @Autowired + protected EdgeIngestor edgeRules; + + @Autowired + protected EdgeSerializer rules; + + @Autowired + protected LoaderFactory loaderFactory; + + @Autowired + protected SchemaVersions schemaVersions; + + protected Loader loader; + protected GraphTraversalSource gts; + + @Autowired + protected GremlinServerSingleton gremlinServerSingleton; + + @Parameterized.Parameter(value = 0) + public SchemaVersion version; + + @Parameterized.Parameters(name = "Version.{0}") + public static Collection data() { + return Arrays.asList(new Object[][]{ + {new SchemaVersion("v11")}, + {new SchemaVersion("v12")}, + {new SchemaVersion("v13")}, + {new SchemaVersion("v14")}, + {new SchemaVersion("v15")}, + {new SchemaVersion("v16")}, + {new SchemaVersion("v17")}, + {new SchemaVersion("v18")}, + {new SchemaVersion("v19")} + }); + } + + protected String query; + + LinkedHashMap params; + + @Autowired + private Environment env; + + @BeforeClass + public static void setupBundleconfig() { + System.setProperty("AJSC_HOME", "./"); + System.setProperty("BUNDLECONFIG_DIR", "src/main/resources/"); + } + + @Before + public void setUp() throws AAIException, NoEdgeRuleFoundException, EdgeRuleNotFoundException, AmbiguousRuleChoiceException, IOException { + System.setProperty("AJSC_HOME", "."); + System.setProperty("BUNDLECONFIG_DIR", "src/main/resources"); + logger = LoggerFactory.getLogger(getClass()); + MockitoAnnotations.initMocks(this); + graph = TinkerGraph.open(); + gts = graph.traversal(); + createGraph(); + shell = new GremlinGroovyShell(); + loader = loaderFactory.createLoaderForVersion(ModelType.MOXY, version); + setUpQuery(); + } + + + protected void setUpQuery() { + query = gremlinServerSingleton.getStoredQueryFromConfig(getQueryName()); + params = new LinkedHashMap <>(); + addParam(params); + when(dbEngine.getQueryBuilder(any(QueryStyle.class))).thenReturn(new GremlinTraversal<>(loader, graph.traversal())); + logger.info("Stored query in abstraction form {}", query); + query = new GroovyQueryBuilder().executeTraversal(dbEngine, query, params); + logger.info("After converting to gremlin query {}", query); + query = "g" + query; + GraphTraversal g = graph.traversal().V(); + addStartNode(g); + params.put("g", g); + } + + public void run() { + + GraphTraversal result = (GraphTraversal)shell.executeTraversal(query, params); + + List vertices = result.toList(); + + logger.info("Expected result set of vertexes [{}]", convert(expectedResult)); + logger.info("Actual Result set of vertexes [{}]", convert(vertices)); + + List nonDuplicateExpectedResult = new ArrayList<>(new HashSet<>(expectedResult)); + vertices = new ArrayList<>(new HashSet<>(vertices)); + + nonDuplicateExpectedResult.sort(Comparator.comparing(vertex -> vertex.id().toString())); + vertices.sort(Comparator.comparing(vertex -> vertex.id().toString())); + + + // Use this instead of the assertTrue as this provides more useful + // debugging information such as this when expected and actual differ: + // java.lang.AssertionError: Expected all the vertices to be found + // Expected :[v[2], v[3], v[4], v[5], v[6], v[7], v[8], v[9], v[10], v[11], v[12]] + // Actual :[v[1], v[2], v[3], v[4], v[5], v[6], v[7], v[8], v[9], v[10], v[11], v[12]] + assertEquals("Expected all the vertices to be found", nonDuplicateExpectedResult, vertices); + + } + + protected String convert(List vertices){ + return vertices + .stream() + .map(vertex -> vertex.property("aai-node-type").value().toString()) + .collect(Collectors.joining(",")); + } + + protected abstract void createGraph() throws AAIException, NoEdgeRuleFoundException, EdgeRuleNotFoundException, AmbiguousRuleChoiceException; + + protected abstract String getQueryName(); + + protected abstract void addStartNode(GraphTraversal g); + + protected abstract void addParam(Map params); + +} diff --git a/aai-queries/src/test/java/org/onap/aai/queries/VnfToEsrSystemInfoQueryTest.java b/aai-queries/src/test/java/org/onap/aai/queries/VnfToEsrSystemInfoQueryTest.java new file mode 100644 index 0000000..9b6a0e8 --- /dev/null +++ b/aai-queries/src/test/java/org/onap/aai/queries/VnfToEsrSystemInfoQueryTest.java @@ -0,0 +1,96 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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.queries; + +import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal; +import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; +import org.apache.tinkerpop.gremlin.structure.T; +import org.apache.tinkerpop.gremlin.structure.Vertex; +import org.junit.Test; +import org.onap.aai.exceptions.AAIException; +import org.onap.aai.serialization.db.exceptions.NoEdgeRuleFoundException; + +import java.util.Map; + +public class VnfToEsrSystemInfoQueryTest extends OnapQueryTest { + public VnfToEsrSystemInfoQueryTest() { + super(); + } + + @Test + public void run() { + super.run(); + } + + @Override + protected void createGraph() throws AAIException, NoEdgeRuleFoundException { + + + Vertex gnvf = graph.addVertex(T.label, "generic-vnf", T.id, "2", "aai-node-type", "generic-vnf", "vnf-id", "vnf-id-1"); + Vertex vserver = graph.addVertex(T.label, "vserver", T.id, "3", "aai-node-type", "vserver", "vserver-id", "vserver-id-1","vserver-name","vserver-name-1"); + Vertex tenant = graph.addVertex(T.label, "tenant", T.id, "4", "aai-node-type", "tenant", "tenant-id", "tenantid01", "tenant-name", "tenantName01"); + Vertex cloudregion = graph.addVertex(T.label, "cloud-region", T.id, "5", "aai-node-type", "cloud-region", "cloud-region-id", "cloud-region-id-1", "cloud-region-owner", "cloud-owner-name-1"); + Vertex esr = graph.addVertex(T.label, "esr-system-info", T.id, "6", "aai-node-type", "esr-system-info", "esr-system-info-id", "esr-system-info-1"); + + Vertex gnvf1 = graph.addVertex(T.label, "generic-vnf", T.id, "8", "aai-node-type", "generic-vnf", "vnf-id", "vnf-id-2"); + Vertex vserver1 = graph.addVertex(T.label, "vserver", T.id, "9", "aai-node-type", "vserver", "vserver-id", "vserver-id-2","vserver-name","vserver-name-2"); + Vertex tenant1 = graph.addVertex(T.label, "tenant", T.id, "10", "aai-node-type", "tenant", "tenant-id", "tenantid02", "tenant-name", "tenantName02"); + Vertex cloudregion1 = graph.addVertex(T.label, "cloud-region", T.id, "11", "aai-node-type", "cloud-region", "cloud-region-id", "cloud-region-id-2", "cloud-region-owner", "cloud-owner-name-2"); + Vertex esr1 = graph.addVertex(T.label, "esr-system-info", T.id, "12", "aai-node-type", "esr-system-info", "esr-system-info-id", "esr-system-info-2"); + + + + + GraphTraversalSource g = graph.traversal(); + rules.addEdge(g, gnvf, vserver); + rules.addTreeEdge(g, vserver,tenant); + rules.addTreeEdge(g, tenant,cloudregion); + rules.addTreeEdge(g, cloudregion, esr); + + //Not expected in result + rules.addEdge(g, gnvf1, vserver1); + rules.addTreeEdge(g, vserver1,tenant1); + rules.addTreeEdge(g, tenant1,cloudregion1); + rules.addTreeEdge(g, cloudregion1, esr1); + //Not expected in result + + expectedResult.add(gnvf); + expectedResult.add(vserver); + expectedResult.add(tenant); + expectedResult.add(cloudregion); + expectedResult.add(esr); + + + } + + @Override + protected String getQueryName() { + return "vnf-to-esr-system-info"; + } + @Override + protected void addStartNode(GraphTraversal g) { + g.has("aai-node-type", "generic-vnf").has("vnf-id", "vnf-id-1"); + + } + @Override + protected void addParam(Map params) { + return; + } +} diff --git a/aai-queries/src/test/resources/application-onap-test.properties b/aai-queries/src/test/resources/application-onap-test.properties new file mode 100644 index 0000000..697c4a8 --- /dev/null +++ b/aai-queries/src/test/resources/application-onap-test.properties @@ -0,0 +1,33 @@ +server.local.startpath=src/main/resources/ +# Schema related attributes for the oxm and edges +# Any additional schema related attributes should start with prefix schema +schema.configuration.location=N/A +# Choose if the oxm schema is onap or other system +schema.source.name=onap +# Location of where the oxm files are +schema.nodes.location=${server.local.startpath}/schema/${schema.source.name}/oxm/ +# Location of where the dbedgerules files are +schema.edges.location=${server.local.startpath}/schema/${schema.source.name}/dbedgerules/ +# Location of where the stored queries are +schema.queries.location=${server.local.startpath}/schema/${schema.source.name}/query/ + +schema.ingest.file=${server.local.startpath}/application-test.properties + +# Schema Version Related Attributes +schema.uri.base.path=/aai +# Lists all of the versions in the schema +schema.version.list=v10,v11,v12,v13,v14,v15,v16,v17 +# Specifies from which version should the depth parameter to default to zero +schema.version.depth.start=v10 +# Specifies from which version should the related link be displayed in response payload +schema.version.related.link.start=v10 +# Specifies from which version should the client see only the uri excluding host info +# Before this version server base will also be included +schema.version.app.root.start=v11 +# Specifies from which version should the namespace be changed +schema.version.namespace.change.start=v12 +# Specifies from which version should the client start seeing the edge label in payload +schema.version.edge.label.start=v12 +# Specifies the version that the application should default to +schema.version.api.default=v17 +schema.translator.list=config \ No newline at end of file diff --git a/aai-queries/src/test/resources/application-test.properties b/aai-queries/src/test/resources/application-test.properties new file mode 100644 index 0000000..b6aafc7 --- /dev/null +++ b/aai-queries/src/test/resources/application-test.properties @@ -0,0 +1,34 @@ +server.local.startpath=src/main/resources +# Schema related attributes for the oxm and edges +# Any additional schema related attributes should start with prefix schema +schema.configuration.location=N/A +# Choose if the oxm schema is onap or other system +schema.source.name=ecomp +# Location of where the oxm files are +schema.nodes.location=${server.local.startpath}/schema/${schema.source.name}/oxm/ +# Location of where the dbedgerules files are +schema.edges.location=${server.local.startpath}/schema/${schema.source.name}/dbedgerules/ +# Location of where the stored queries are +schema.queries.location=${server.local.startpath}/schema/${schema.source.name}/query/ + +schema.ingest.file=${server.local.startpath}/application-test.properties + +# Schema Version Related Attributes +schema.uri.base.path=/aai +# Lists all of the versions in the schema +schema.version.list=v10,v11,v12,v13,v14,v15,v16,v17,v18,v19 +# Specifies from which version should the depth parameter to default to zero +schema.version.depth.start=v10 +# Specifies from which version should the related link be displayed in response payload +schema.version.related.link.start=v10 +# Specifies from which version should the client see only the uri excluding host info +# Before this version server base will also be included +schema.version.app.root.start=v11 +# Specifies from which version should the namespace be changed +schema.version.namespace.change.start=v12 +# Specifies from which version should the client start seeing the edge label in payload +schema.version.edge.label.start=v12 +# Specifies the version that the application should default to +schema.version.api.default=v19 + +schema.translator.list=config diff --git a/aai-queries/src/test/resources/logback.xml b/aai-queries/src/test/resources/logback.xml new file mode 100644 index 0000000..795533f --- /dev/null +++ b/aai-queries/src/test/resources/logback.xml @@ -0,0 +1,81 @@ + + + + + + + + + + + + + + + + + + %clr(%d{yyyy-MM-dd HH:mm:ss.SSS}){faint} %clr(${LOG_LEVEL_PATTERN:-%5p}) %clr(${PID:- }){magenta} %clr(---){faint} %clr([%15.15t]){faint} %clr(%-40.40logger{39}){cyan} %clr(:){faint} %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/aai-queries/src/test/resources/schema-ingest.properties b/aai-queries/src/test/resources/schema-ingest.properties new file mode 100644 index 0000000..95846ea --- /dev/null +++ b/aai-queries/src/test/resources/schema-ingest.properties @@ -0,0 +1,10 @@ +schema.configuration.location=N/A +schema.nodes.location=src/main/resources/schema/oxm/ +schema.edges.location=src/main/resources/schema/dbedgerules/ + +schema.version.list=v10,v11,v12,v13,v14,v15,v16,v17 +schema.version.depth.start=v10 +schema.version.related.link.start=v10 +schema.version.app.root.start=v11 +schema.version.edge.label.start=v12 +schema.version.api.default=v17 -- cgit 1.2.3-korg