aboutsummaryrefslogtreecommitdiffstats
path: root/aai-traversal/src/main/java/org
diff options
context:
space:
mode:
authorVenkata Harish K Kajur <vk250x@att.com>2018-01-18 11:04:20 -0500
committerVenkata Harish K Kajur <vk250x@att.com>2018-02-15 11:43:25 -0500
commitf702ccd5b3f92fabfe21a1d3f3af762b6c628b88 (patch)
tree19204529e31d9393f5eb6e496a4ce2a6857d22ac /aai-traversal/src/main/java/org
parent0de265c8b69c955c296f368c2875e9845bb824e4 (diff)
Sync logging context changes
Issue-ID: AAI-493 Change-Id: I8c460cce840b4fe46ff4deacbe3a770755a4c677 Signed-off-by: Venkata Harish K Kajur <vk250x@att.com>
Diffstat (limited to 'aai-traversal/src/main/java/org')
-rw-r--r--aai-traversal/src/main/java/org/onap/aai/dbgraphgen/ModelBasedProcessing.java376
-rw-r--r--aai-traversal/src/main/java/org/onap/aai/dbgraphmap/SearchGraph.java27
-rw-r--r--aai-traversal/src/main/java/org/onap/aai/interceptors/PostAaiAjscInterceptor.java14
-rw-r--r--aai-traversal/src/main/java/org/onap/aai/interceptors/PreAaiAjscInterceptor.java14
-rw-r--r--aai-traversal/src/main/java/org/onap/aai/rest/QueryConsumer.java82
-rw-r--r--aai-traversal/src/main/java/org/onap/aai/rest/dsl/DslListener.java306
-rw-r--r--aai-traversal/src/main/java/org/onap/aai/rest/dsl/DslQueryProcessor.java99
-rw-r--r--aai-traversal/src/main/java/org/onap/aai/rest/search/GenericQueryProcessor.java80
-rw-r--r--aai-traversal/src/main/java/org/onap/aai/rest/search/GetCustomQueryConfig.java18
-rw-r--r--aai-traversal/src/main/java/org/onap/aai/rest/search/GremlinServerSingleton.java10
-rw-r--r--aai-traversal/src/main/java/org/onap/aai/rest/search/ModelAndNamedQueryRestProvider.java127
-rw-r--r--aai-traversal/src/main/java/org/onap/aai/rest/search/SearchProvider.java118
-rw-r--r--aai-traversal/src/main/java/org/onap/aai/util/AAIAppServletContextListener.java84
13 files changed, 1018 insertions, 337 deletions
diff --git a/aai-traversal/src/main/java/org/onap/aai/dbgraphgen/ModelBasedProcessing.java b/aai-traversal/src/main/java/org/onap/aai/dbgraphgen/ModelBasedProcessing.java
index 5e7f9d9..aeeac2e 100644
--- a/aai-traversal/src/main/java/org/onap/aai/dbgraphgen/ModelBasedProcessing.java
+++ b/aai-traversal/src/main/java/org/onap/aai/dbgraphgen/ModelBasedProcessing.java
@@ -21,19 +21,13 @@
*/
package org.onap.aai.dbgraphgen;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.ListIterator;
-import java.util.Map;
-import java.util.Optional;
-import java.util.Set;
-import java.util.concurrent.Callable;
-import java.util.concurrent.TimeUnit;
-
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
+import com.google.common.collect.ArrayListMultimap;
+import com.google.common.collect.Multimap;
+import com.google.common.util.concurrent.SimpleTimeLimiter;
+import com.google.common.util.concurrent.TimeLimiter;
+import com.google.common.util.concurrent.UncheckedTimeoutException;
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal;
import org.apache.tinkerpop.gremlin.structure.Vertex;
import org.apache.tinkerpop.gremlin.structure.VertexProperty;
@@ -52,18 +46,14 @@ import org.onap.aai.serialization.db.EdgeType;
import org.onap.aai.serialization.engines.TransactionalGraphEngine;
import org.onap.aai.util.AAIConfig;
-import com.att.eelf.configuration.EELFLogger;
-import com.att.eelf.configuration.EELFManager;
-import com.google.common.collect.ArrayListMultimap;
-import com.google.common.collect.Multimap;
-import com.google.common.util.concurrent.SimpleTimeLimiter;
-import com.google.common.util.concurrent.TimeLimiter;
-import com.google.common.util.concurrent.UncheckedTimeoutException;
+import java.util.*;
+import java.util.concurrent.Callable;
+import java.util.concurrent.TimeUnit;
/**
* Utility class that uses Model/Named-Query definitions to navigate the graph.
*/
-public class ModelBasedProcessing{
+public class ModelBasedProcessing {
private EELFLogger LOGGER = EELFManager.getInstance().getLogger(ModelBasedProcessing.class);
private final int MAX_LEVELS = 50; // max depth allowed for our model - to protect against infinite loop problems
@@ -103,7 +93,7 @@ public class ModelBasedProcessing{
String passedTopNodeType,
List<Map<String,Object>> startNodeFilterArrayOfHashes,
String apiVer )
- throws AAIException{
+ throws AAIException {
// ----------------------------------------------------------------------------------------------------
// Get a hash for all start-nodes (key = vtxId, val = modelVersionId that applies)
// If no start-node-key info is passed, then use either the passed modelVersion or
@@ -122,14 +112,14 @@ public class ModelBasedProcessing{
if( (passedModelVersionId == null || passedModelVersionId.equals(""))
&& (passedModelInvId == null || passedModelInvId.equals(""))
&& (passedModelName == null || passedModelName.equals(""))){
- throw new AAIException("AAI_6118", "ModelInvariantId or ModelName or ModelVersionId required if no startNodeFilter data passed.");
+ throw new AAIException("AAI_6118", "ModelInvariantId or ModelName or ModelVersionId required if no startNodeFilter data passed.");
}
else {
// Use whatever model info they pass to find start-node instances
// Get the first/top named-query-element used by this query
if( passedModelVersionId != null && !passedModelVersionId.equals("") ){
// Need to look up the model-invariant-id and model-version to check against persona data
- Vertex modVerVtx = getNodeUsingUniqueId(transId, fromAppId, "model-ver",
+ Vertex modVerVtx = getNodeUsingUniqueId(transId, fromAppId, "model-ver",
"model-version-id", passedModelVersionId);
Vertex modVtx = getModelGivenModelVer( modVerVtx, "" );
String calcModId = modVtx.<String>property("model-invariant-id").orElse(null);
@@ -218,7 +208,7 @@ public class ModelBasedProcessing{
// the passsed-in one (if there is one)
if( passedTopNodeType != null && !passedTopNodeType.equals("")
&& !passedTopNodeType.equals(modTopNodeType) ){
- throw new AAIException("AAI_6120", "topNodeType passed in [" + passedTopNodeType
+ throw new AAIException("AAI_6120", "topNodeType passed in [" + passedTopNodeType
+ "] does not match nodeType derived for model info passed in: ["
+ modTopNodeType + "]");
}
@@ -330,14 +320,14 @@ public class ModelBasedProcessing{
* @return resultSet
* @throws AAIException the AAI exception
*/
- public List<ResultSet> queryByModel( String transId, String fromAppId,
- String modelVersionId,
- String modelInvariantId,
- String modelName,
- String topNodeType,
- List<Map<String,Object>> startNodeFilterArrayOfHashes,
- String apiVer )
- throws AAIException{
+ public List<ResultSet> queryByModel(String transId, String fromAppId,
+ String modelVersionId,
+ String modelInvariantId,
+ String modelName,
+ String topNodeType,
+ List<Map<String,Object>> startNodeFilterArrayOfHashes,
+ String apiVer )
+ throws AAIException {
final String transId_f = transId;
final String fromAppId_f = fromAppId;
@@ -415,14 +405,14 @@ public class ModelBasedProcessing{
* @return the array list
* @throws AAIException the AAI exception
*/
- public List<ResultSet> queryByModel_Timed( String transId, String fromAppId,
- String modelVersionId,
- String modelInvariantId,
- String modelName,
- String topNodeType,
- List<Map<String,Object>> startNodeFilterArrayOfHashesVal,
- String apiVer )
- throws AAIException{
+ public List<ResultSet> queryByModel_Timed(String transId, String fromAppId,
+ String modelVersionId,
+ String modelInvariantId,
+ String modelName,
+ String topNodeType,
+ List<Map<String,Object>> startNodeFilterArrayOfHashesVal,
+ String apiVer )
+ throws AAIException {
List<ResultSet> resultArray = new ArrayList<>();
@@ -472,7 +462,7 @@ public class ModelBasedProcessing{
// Figure out what-all models (model-ver nodes) we will be dealing with
// Note - Instances must all use the same type of start-node, but do not have to all use the same model-ver.
// --------------------------------------------------------------------------------------------------------
- Map<String, Vertex> distinctModelVersHash = new HashMap<>();
+ Map<String, Vertex> distinctModelVersHash = new HashMap<>();
// For distinctModelVersHash: key = modelVersionId, val= modelVerVertex
String startNodeType = "";
if( topNodeType != null && !topNodeType.equals("") ){
@@ -488,7 +478,7 @@ public class ModelBasedProcessing{
String modVerId = startNode2ModelVerHash.get(modVerIdKey);
if( !distinctModelVersHash.containsKey(modVerId) ){
// First time seeing this model-version-id
- Vertex modVerVtx = getNodeUsingUniqueId(transId, fromAppId, "model-ver",
+ Vertex modVerVtx = getNodeUsingUniqueId(transId, fromAppId, "model-ver",
"model-version-id", modVerId);
String tmpNodeType = "";
try {
@@ -524,7 +514,7 @@ public class ModelBasedProcessing{
// While we're at it, get a mapping of model-invariant-id|model-version to model-version-id for
// the model-vers being used
// ------------------------------------------------------------------------------------------------------
- Map<String, Multimap<String, String>> validNextStepHash = new HashMap<>();
+ Map<String, Multimap<String, String>> validNextStepHash = new HashMap<>();
// validNextStepHash: key = modelVerId, value = nextStepMap
Set <String> keySet = distinctModelVersHash.keySet();
Iterator<String> modelVerIterator = keySet.iterator();
@@ -631,7 +621,7 @@ public class ModelBasedProcessing{
List<String> vidsTraversed = new ArrayList<>();
Map<String,String> emptyDelKeyHash = new HashMap<>();
Map<String,String> emptyNQElementHash = new HashMap<>(); // Only applies to Named Queries
- ResultSet tmpResSet = collectInstanceData( transId, fromAppId,
+ ResultSet tmpResSet = collectInstanceData( transId, fromAppId,
tmpStartVtx, elementLocationTrail,
validNextStepMap, vidsTraversed, 0, emptyDelKeyHash, emptyNQElementHash, apiVer );
@@ -659,7 +649,7 @@ public class ModelBasedProcessing{
*/
public Map<String,String> runDeleteByModel( String transId, String fromAppId,
String modelVersionId, String topNodeTypeVal, Map<String,Object> startNodeFilterHash, String apiVer, String resVersion )
- throws AAIException{
+ throws AAIException {
Map<String,String> retHash = new HashMap<>();
@@ -721,7 +711,7 @@ public class ModelBasedProcessing{
String chkFirstNodePersonaModInvId = "";
String chkFirstNodePersonaModVerId = "";
String personaData = "";
- Vertex firstModElementVertex = getTopElementForSvcOrResModelVer( modelVerVtx, "" );
+ Vertex firstModElementVertex = getTopElementForSvcOrResModelVer( modelVerVtx, "" );
topNType = getModElementWidgetType( firstModElementVertex, "" );
if( (topNType == null) || topNType.equals("") ){
String msg = "Could not determine the top-node nodeType for model-version-id: [" + modelVersionId + "]";
@@ -771,7 +761,7 @@ public class ModelBasedProcessing{
String topVid = startVtx.id().toString();
// Read the model-ver into a Map for processing
- Multimap <String, String> validNextStepMap = genTopoMap4ModelVer(transId, fromAppId,
+ Multimap<String, String> validNextStepMap = genTopoMap4ModelVer(transId, fromAppId,
modelVerVtx, modelVersionId);
// Collect the data
@@ -780,7 +770,7 @@ public class ModelBasedProcessing{
Map<String,String> emptyHash = new HashMap<>();
// Pass emptyHash for the NQElement hash since that parameter only applies to Named Queries
- ResultSet retResSet = collectInstanceData( transId, fromAppId,
+ ResultSet retResSet = collectInstanceData( transId, fromAppId,
startVtx, elementLocationTrail,
validNextStepMap, vidsTraversed, 0, delKeyHash, emptyHash, apiVer );
@@ -812,8 +802,8 @@ public class ModelBasedProcessing{
* @return String
* @throws AAIException the AAI exception
*/
- public Map<String,String> deleteAsNeededFromResultSet( String transId, String fromAppId,
- ResultSet resSet, String vidToResCheck, String apiVer, String resVersion, Map<String,String> hashSoFar )
+ public Map<String,String> deleteAsNeededFromResultSet(String transId, String fromAppId,
+ ResultSet resSet, String vidToResCheck, String apiVer, String resVersion, Map<String,String> hashSoFar )
throws AAIException
{
Map<String,String> retHash = new HashMap<>();
@@ -842,7 +832,7 @@ public class ModelBasedProcessing{
// "vtx.isRemoved()" but that was a Titan-only feature and is not available anymore since
// we no longer use Titan vertices.
// If we don't do this check, we get errors later when we try to delete the node.
- thisVtx.property(AAIProperties.NODE_TYPE, thisNT);
+ thisVtx.property(AAIProperties.NODE_TYPE, thisNT);
gotVtxOK = true;
}
}
@@ -905,7 +895,7 @@ public class ModelBasedProcessing{
}
// Now call this routine for the sub-resultSets
- List <ResultSet> subResultSetList = resSet.getSubResultSet();
+ List <ResultSet> subResultSetList = resSet.getSubResultSet();
Iterator <ResultSet> subResSetIter = subResultSetList.iterator();
while( subResSetIter.hasNext() ){
ResultSet tmpSubResSet = subResSetIter.next();
@@ -934,11 +924,11 @@ public class ModelBasedProcessing{
* @return resultSet
* @throws AAIException the AAI exception
*/
- public List<ResultSet> queryByNamedQuery( String transId, String fromAppId,
- String namedQueryUuid,
- ArrayList <Map<String,Object>> startNodeFilterArrayOfHashes,
- String apiVer )
- throws AAIException{
+ public List<ResultSet> queryByNamedQuery(String transId, String fromAppId,
+ String namedQueryUuid,
+ ArrayList <Map<String,Object>> startNodeFilterArrayOfHashes,
+ String apiVer )
+ throws AAIException {
String dummyCutPoint = null;
Map<String,Object> dummySecondaryFilterHash = null;
@@ -965,13 +955,13 @@ public class ModelBasedProcessing{
* @return resultSet
* @throws AAIException the AAI exception
*/
- public List<ResultSet> queryByNamedQuery( String transId, String fromAppId,
- String namedQueryUuid,
- List<Map<String,Object>> startNodeFilterArrayOfHashes,
- String apiVer,
- String secondaryFilterCutPoint,
- Map<String,Object> secondaryFilterHash )
- throws AAIException{
+ public List<ResultSet> queryByNamedQuery(String transId, String fromAppId,
+ String namedQueryUuid,
+ List<Map<String,Object>> startNodeFilterArrayOfHashes,
+ String apiVer,
+ String secondaryFilterCutPoint,
+ Map<String,Object> secondaryFilterHash )
+ throws AAIException {
final String transId_f = transId;
final String fromAppId_f = fromAppId;
@@ -1046,17 +1036,17 @@ public class ModelBasedProcessing{
* @return resultSet
* @throws AAIException the AAI exception
*/
- public List<ResultSet> queryByNamedQuery_Timed( String transId, String fromAppId,
- String namedQueryUuid,
- List<Map<String,Object>> startNodeFilterArrayOfHashes,
- String apiVer,
- String secondaryFilterCutPoint,
- Map<String,Object> secondaryFilterHash
+ public List<ResultSet> queryByNamedQuery_Timed(String transId, String fromAppId,
+ String namedQueryUuid,
+ List<Map<String,Object>> startNodeFilterArrayOfHashes,
+ String apiVer,
+ String secondaryFilterCutPoint,
+ Map<String,Object> secondaryFilterHash
)
- throws AAIException{
+ throws AAIException {
// Locate the Query to be used
- Vertex queryVtx = getNodeUsingUniqueId(transId, fromAppId, "named-query",
+ Vertex queryVtx = getNodeUsingUniqueId(transId, fromAppId, "named-query",
"named-query-uuid", namedQueryUuid);
// Get the first/top named-query-element used by this query
@@ -1084,7 +1074,7 @@ public class ModelBasedProcessing{
}
// Read the topology into a hash for processing
- Multimap <String, String> validNextStepMap = genTopoMap4NamedQ(transId, fromAppId, queryVtx, namedQueryUuid);
+ Multimap<String, String> validNextStepMap = genTopoMap4NamedQ(transId, fromAppId, queryVtx, namedQueryUuid);
List<Vertex> startVertList = new ArrayList<>();
if( startNodeFilterArrayOfHashes.size() == 1 ){
@@ -1174,7 +1164,7 @@ public class ModelBasedProcessing{
firstNqElementVert, incomingTrail, currentHash, vidsTraversed, 0 );
vidsTraversed = new ArrayList<>();
- ResultSet tmpResSet = collectInstanceData( transId, fromAppId,
+ ResultSet tmpResSet = collectInstanceData( transId, fromAppId,
startVtx, elementLocationTrail,
validNextStepMap, vidsTraversed, 0, emptyDelKeyHash, namedQueryElementHash, apiVer );
resSetList.add(tmpResSet);
@@ -1232,7 +1222,7 @@ public class ModelBasedProcessing{
* @return pruned result set
* @throws AAIException the AAI exception
*/
- public ResultSet pruneResultSet( ResultSet resSetVal, String cutPointType, Map<String,Object> secFilterHash )
+ public ResultSet pruneResultSet(ResultSet resSetVal, String cutPointType, Map<String,Object> secFilterHash )
throws AAIException {
// Given a ResultSet and some secondary filter info, do pruning as needed
@@ -1286,7 +1276,7 @@ public class ModelBasedProcessing{
* @return true, if successful
* @throws AAIException the AAI exception
*/
- public boolean satisfiesFilters( ResultSet resSet, Map<String,Object> filterHash )
+ public boolean satisfiesFilters(ResultSet resSet, Map<String,Object> filterHash )
throws AAIException {
if( filterHash.isEmpty() ){
@@ -1303,7 +1293,7 @@ public class ModelBasedProcessing{
int periodLoc = propNodeTypeDotName.indexOf(".");
if( periodLoc <= 0 ){
String emsg = "Bad filter param key passed in: [" + propNodeTypeDotName + "]. Expected format = [nodeName.paramName]\n";
- throw new AAIException("AAI_6120", emsg);
+ throw new AAIException("AAI_6120", emsg);
}
else {
String fnt = propNodeTypeDotName.substring(0,periodLoc);
@@ -1333,7 +1323,7 @@ public class ModelBasedProcessing{
* @param filtPropVal the filt prop val
* @return true, if successful
*/
- public boolean filterMetByThisSet( ResultSet resSet, String filtNodeType, String filtPropName, String filtPropVal ) {
+ public boolean filterMetByThisSet(ResultSet resSet, String filtNodeType, String filtPropName, String filtPropVal ) {
// Note - we are just looking for a positive match for one filter for this resultSet
// NOTE: we're expecting the filter to have a format like this: "nodeType.parameterName:parameterValue"
@@ -1386,7 +1376,7 @@ public class ModelBasedProcessing{
* @return the array list
* @throws AAIException the AAI exception
*/
- public List<ResultSet> collapseForDoNotOutput( ResultSet resSetVal )
+ public List<ResultSet> collapseForDoNotOutput(ResultSet resSetVal )
throws AAIException {
// Given a ResultSet -- if it is tagged to NOT be output, then replace it with
@@ -1441,15 +1431,15 @@ public class ModelBasedProcessing{
* @return resultSet
* @throws AAIException the AAI exception
*/
- public ResultSet collectInstanceData( String transId, String fromAppId,
- Vertex thisLevelElemVtx,
- String thisVertsTrail,
- Multimap <String,String> validNextStepMap,
- List<String> vidsTraversed,
- int levelCounter,
- Map<String,String> delKeyHash, // only applies when collecting data using the default model for delete
- Map<String,String> namedQueryElementHash, // only applies to named-query data collecting
- String apiVer
+ public ResultSet collectInstanceData(String transId, String fromAppId,
+ Vertex thisLevelElemVtx,
+ String thisVertsTrail,
+ Multimap<String,String> validNextStepMap,
+ List<String> vidsTraversed,
+ int levelCounter,
+ Map<String,String> delKeyHash, // only applies when collecting data using the default model for delete
+ Map<String,String> namedQueryElementHash, // only applies to named-query data collecting
+ String apiVer
) throws AAIException {
levelCounter++;
@@ -1457,14 +1447,14 @@ public class ModelBasedProcessing{
String thisElemVid = thisLevelElemVtx.id().toString();
if( levelCounter > MAX_LEVELS ) {
- throw new AAIException("AAI_6125", "collectInstanceData() has looped across more levels than allowed: " + MAX_LEVELS + ". ");
+ throw new AAIException("AAI_6125", "collectInstanceData() has looped across more levels than allowed: " + MAX_LEVELS + ". ");
}
ResultSet rs = new ResultSet();
if( namedQueryElementHash.containsKey(thisVertsTrail) ){
// We're collecting data for a named-query, so need to see if we need to do anything special
String nqElUuid = namedQueryElementHash.get(thisVertsTrail);
- Vertex nqElementVtx = getNodeUsingUniqueId(transId, fromAppId, "named-query-element",
+ Vertex nqElementVtx = getNodeUsingUniqueId(transId, fromAppId, "named-query-element",
"named-query-element-uuid", nqElUuid);
String tmpDoNotShow = nqElementVtx.<String>property("do-not-output").orElse(null);
@@ -1542,7 +1532,7 @@ public class ModelBasedProcessing{
stepIsJustNT = false;
String[] pieces = targetStep.split(",");
if( pieces.length != 3 ){
- throw new AAIException("AAI_6128", "Unexpected format for nextStep in model processing = ["
+ throw new AAIException("AAI_6128", "Unexpected format for nextStep in model processing = ["
+ targetStep + "]. ");
}
else {
@@ -1574,7 +1564,7 @@ public class ModelBasedProcessing{
String tmpTrail = thisVertsTrail + "|" + targetStep;
if( !vidsTraversed.contains(tmpVid) ){
// This is one we would like to use - so we'll include the result set we get for it
- ResultSet tmpResSet = collectInstanceData( transId, fromAppId,
+ ResultSet tmpResSet = collectInstanceData( transId, fromAppId,
tmpVert, tmpTrail,
validNextStepMap, tmpVidsTraversedList,
levelCounter, delKeyHash, namedQueryElementHash, apiVer );
@@ -1601,15 +1591,15 @@ public class ModelBasedProcessing{
* @return MultiMap of valid next steps for each potential model-element
* @throws AAIException the AAI exception
*/
- public Multimap<String, String> genTopoMap4ModelVer( String transId, String fromAppId,
- Vertex modelVerVertex, String modelVerId)
+ public Multimap<String, String> genTopoMap4ModelVer(String transId, String fromAppId,
+ Vertex modelVerVertex, String modelVerId)
throws AAIException {
if( modelVerVertex == null ){
throw new AAIException("AAI_6114", "null modelVerVertex passed to genTopoMap4ModelVer()");
}
- Multimap <String, String> initialEmptyMap = ArrayListMultimap.create();
+ Multimap<String, String> initialEmptyMap = ArrayListMultimap.create();
List<String> vidsTraversed = new ArrayList<>();
String modelType = getModelTypeFromModelVer( modelVerVertex, "" );
if( modelType.equals("widget") ){
@@ -1618,7 +1608,7 @@ public class ModelBasedProcessing{
// an aai-node-type
Iterator<Vertex> vertI= this.traverseIncidentEdges(EdgeType.TREE, modelVerVertex, "model-element");
if( vertI != null && vertI.hasNext() ){
- throw new AAIException("AAI_6132", "Bad Model Definition: Widget Model has a startsWith edge to a model-element. "
+ throw new AAIException("AAI_6132", "Bad Model Definition: Widget Model has a startsWith edge to a model-element. "
+ " model-version-id = " + modelVerId);
}
else {
@@ -1629,7 +1619,7 @@ public class ModelBasedProcessing{
String firstModelVerId = modelVerVertex.<String>property("model-version-id").orElse(null);
String firstModelVersion = modelVerVertex.<String>property("model-version").orElse(null);
if( firstModelVerId == null || firstModelVerId.equals("") || firstModelVersion == null || firstModelVersion.equals("") ){
- throw new AAIException("AAI_6132", "Bad Model Definition: Bad model-version-id or model-version. model-version-id = "
+ throw new AAIException("AAI_6132", "Bad Model Definition: Bad model-version-id or model-version. model-version-id = "
+ modelVerId);
}
@@ -1637,18 +1627,18 @@ public class ModelBasedProcessing{
Vertex firstEleModVerVtx = getModelVerThatElementRepresents( firstElementVertex, "" );
String firstElemModelType = getModelTypeFromModelVer( firstEleModVerVtx, "" );
if( ! firstElemModelType.equals("widget") ){
- throw new AAIException("AAI_6132", "Bad Model Definition: First element must correspond to a widget type model. Model UUID = "
+ throw new AAIException("AAI_6132", "Bad Model Definition: First element must correspond to a widget type model. Model UUID = "
+ modelVerId);
}
Vertex firstModVtx = getModelGivenModelVer( modelVerVertex, "" );
String firstModelInvId = firstModVtx.<String>property("model-invariant-id").orElse(null);
if( firstModelInvId == null || firstModelInvId.equals("") ){
- throw new AAIException("AAI_6132", "Bad Model Definition: Could not find model.model-invariant-id given model-ver.model-version-id = "
+ throw new AAIException("AAI_6132", "Bad Model Definition: Could not find model.model-invariant-id given model-ver.model-version-id = "
+ modelVerId);
}
- Multimap <String, String> collectedMap = collectTopology4ModelVer( transId, fromAppId,
+ Multimap<String, String> collectedMap = collectTopology4ModelVer( transId, fromAppId,
firstElementVertex, "", initialEmptyMap, vidsTraversed, 0, null, firstModelInvId, firstModelVersion );
return collectedMap;
@@ -1686,7 +1676,7 @@ public class ModelBasedProcessing{
* @return HashMap of model-constraints that will be looked at for this model-element and what's "below" it.
* @throws AAIException the AAI exception
*/
- public Map<String, Vertex> getModConstraintHash( Vertex modelElementVtx, Map<String, Vertex> currentHash )
+ public Map<String, Vertex> getModConstraintHash(Vertex modelElementVtx, Map<String, Vertex> currentHash )
throws AAIException {
// For a given model-element vertex, look to see if there are any "model-constraint" elements that is has
@@ -1762,7 +1752,7 @@ public class ModelBasedProcessing{
* @return first element pointed to by this model-ver
* @throws AAIException the AAI exception
*/
- public Vertex getTopElementForSvcOrResModelVer( Vertex modelVerVtx, String trail )
+ public Vertex getTopElementForSvcOrResModelVer(Vertex modelVerVtx, String trail )
throws AAIException {
// For a "resource" or "service" type model, return the "top" element in that model
@@ -1819,8 +1809,8 @@ public class ModelBasedProcessing{
* @return HashMap of alternate properties to return for this element
* @throws AAIException the AAI exception
*/
- public Map<String,Object> getNamedQueryPropOverRide( String transId, String fromAppId,
- Vertex namedQueryElementVertex, Vertex instanceVertex, String apiVer )
+ public Map<String,Object> getNamedQueryPropOverRide(String transId, String fromAppId,
+ Vertex namedQueryElementVertex, Vertex instanceVertex, String apiVer )
throws AAIException {
// If this model-element says that they want an alternative set of properties returned, then pull that
@@ -1861,8 +1851,8 @@ public class ModelBasedProcessing{
* @return true - if a constraint was defined that has not been met by the passed instanceVertex
* @throws AAIException the AAI exception
*/
- public Boolean namedQueryConstraintSaysStop( String transId, String fromAppId,
- Vertex namedQueryElementVertex, Vertex instanceVertex, String apiVer )
+ public Boolean namedQueryConstraintSaysStop(String transId, String fromAppId,
+ Vertex namedQueryElementVertex, Vertex instanceVertex, String apiVer )
throws AAIException {
// For each (if any) property-constraint defined for this named-query-element, we will evaluate if
@@ -1943,8 +1933,8 @@ public class ModelBasedProcessing{
* @return HashMap of alternate properties to return for this element
* @throws AAIException the AAI exception
*/
- public Map<String,Object> getNamedQueryExtraDataLookup( String transId, String fromAppId,
- Vertex namedQueryElementVertex, Vertex instanceVertex, String apiVer )
+ public Map<String,Object> getNamedQueryExtraDataLookup(String transId, String fromAppId,
+ Vertex namedQueryElementVertex, Vertex instanceVertex, String apiVer )
throws AAIException {
// For each (if any) related-lookup defined for this named-query-element, we will go and
@@ -2053,10 +2043,10 @@ public class ModelBasedProcessing{
* @return HashMap of all widget-points on a namedQuery topology with the value being the "named-query-element-uuid" for that spot.
* @throws AAIException the AAI exception
*/
- public Map<String, String> collectNQElementHash( String transId, String fromAppId,
- Vertex thisLevelElemVtx, String incomingTrail,
- Map<String,String> currentHash, ArrayList <String> vidsTraversed,
- int levelCounter ) throws AAIException {
+ public Map<String, String> collectNQElementHash(String transId, String fromAppId,
+ Vertex thisLevelElemVtx, String incomingTrail,
+ Map<String,String> currentHash, ArrayList <String> vidsTraversed,
+ int levelCounter ) throws AAIException {
levelCounter++;
@@ -2064,7 +2054,7 @@ public class ModelBasedProcessing{
thisHash.putAll(currentHash);
if( levelCounter > MAX_LEVELS ) {
- throw new AAIException("AAI_6125", "collectNQElementHash() has looped across more levels than allowed: " + MAX_LEVELS + ". ");
+ throw new AAIException("AAI_6125", "collectNQElementHash() has looped across more levels than allowed: " + MAX_LEVELS + ". ");
}
String thisGuysTrail = "";
String thisElemVid = thisLevelElemVtx.id().toString();
@@ -2139,11 +2129,11 @@ public class ModelBasedProcessing{
* @return HashMap of all widget-points on a model topology with the value being the "newDataDelFlag" for that spot.
* @throws AAIException the AAI exception
*/
- public Map<String, String> collectDeleteKeyHash( String transId, String fromAppId,
- Vertex thisLevelElemVtx, String incomingTrail,
- Map<String,String> currentHash, ArrayList <String> vidsTraversed,
- int levelCounter, Map<String, Vertex> modConstraintHash,
- String overRideModelId, String overRideModelVersionId )
+ public Map<String, String> collectDeleteKeyHash(String transId, String fromAppId,
+ Vertex thisLevelElemVtx, String incomingTrail,
+ Map<String,String> currentHash, ArrayList <String> vidsTraversed,
+ int levelCounter, Map<String, Vertex> modConstraintHash,
+ String overRideModelId, String overRideModelVersionId )
throws AAIException {
levelCounter++;
@@ -2152,7 +2142,7 @@ public class ModelBasedProcessing{
thisHash.putAll(currentHash);
if( levelCounter > MAX_LEVELS ) {
- throw new AAIException("AAI_6125", "collectDeleteKeyHash() has looped across more levels than allowed: " + MAX_LEVELS + ". ");
+ throw new AAIException("AAI_6125", "collectDeleteKeyHash() has looped across more levels than allowed: " + MAX_LEVELS + ". ");
}
String thisGuysTrail = "";
String thisElemVid = thisLevelElemVtx.id().toString();
@@ -2374,14 +2364,14 @@ public class ModelBasedProcessing{
if( linkagePtList == null ){
String detail = " Bad (null) linkagePtList passed to getLinkageConnectNodeTypes() ";
- throw new AAIException("AAI_6125", detail);
+ throw new AAIException("AAI_6125", detail);
}
for( int i = 0; i < linkagePtList.size(); i++ ){
String [] trailSteps = linkagePtList.get(i).split("\\|");
if( trailSteps == null || trailSteps.length == 0 ){
String detail = " Bad incomingTrail passed to getLinkageConnectNodeTypes(): [" + linkagePtList + "] ";
- throw new AAIException("AAI_6125", detail);
+ throw new AAIException("AAI_6125", detail);
}
String lastStepNT = trailSteps[trailSteps.length - 1];
linkPtSet.add(lastStepNT);
@@ -2409,20 +2399,20 @@ public class ModelBasedProcessing{
* @return Map of the topology
* @throws AAIException the AAI exception
*/
- public Multimap<String, String> collectTopology4ModelVer( String transId, String fromAppId,
- Vertex thisLevelElemVtx, String incomingTrail,
- Multimap <String,String> currentMap, List<String> vidsTraversed,
- int levelCounter, Map<String, Vertex> modConstraintHash,
- String overRideModelInvId, String overRideModelVersionId )
+ public Multimap<String, String> collectTopology4ModelVer(String transId, String fromAppId,
+ Vertex thisLevelElemVtx, String incomingTrail,
+ Multimap<String,String> currentMap, List<String> vidsTraversed,
+ int levelCounter, Map<String, Vertex> modConstraintHash,
+ String overRideModelInvId, String overRideModelVersionId )
throws AAIException {
levelCounter++;
- Multimap <String, String> thisMap = ArrayListMultimap.create();
+ Multimap<String, String> thisMap = ArrayListMultimap.create();
thisMap.putAll(currentMap);
if( levelCounter > MAX_LEVELS ) {
- throw new AAIException("AAI_6125", "collectTopology4ModelVer() has looped across more levels than allowed: " + MAX_LEVELS + ". ");
+ throw new AAIException("AAI_6125", "collectTopology4ModelVer() has looped across more levels than allowed: " + MAX_LEVELS + ". ");
}
String thisGuysTrail = "";
String thisElemVid = thisLevelElemVtx.id().toString();
@@ -2543,7 +2533,7 @@ public class ModelBasedProcessing{
// This is as far as we can go, we will use the linkage point info to define the
// rest of this "trail"
for( int i = 0; i < linkagePtList.size(); i++ ){
- Multimap<String, String> tmpMap = collectTopology4LinkagePoint( transId, fromAppId,
+ Multimap<String, String> tmpMap = collectTopology4LinkagePoint( transId, fromAppId,
linkagePtList.get(i), thisGuysTrail, currentMap);
thisMap.putAll(tmpMap);
}
@@ -2553,7 +2543,7 @@ public class ModelBasedProcessing{
thisMap.put(thisGuysTrail, tmpElStepName);
if( !thisTrailsVidsTraversed.contains(tmpElVid) ){
// This is one we would like to use - so we'll recursively get it's result set to add to ours
- Multimap<String, String> tmpMap = collectTopology4ModelVer( transId, fromAppId,
+ Multimap<String, String> tmpMap = collectTopology4ModelVer( transId, fromAppId,
elVert, thisGuysTrail,
currentMap, thisTrailsVidsTraversed, levelCounter,
modConstraintHash2Use, subModelFirstModInvId, subModelFirstModVerId );
@@ -2597,13 +2587,13 @@ public class ModelBasedProcessing{
loader.introspectorFromName(nodeTypeA);
} catch (AAIUnknownObjectException e) {
String emsg = " Unrecognized nodeType aa [" + nodeTypeA + "]\n";
- throw new AAIException("AAI_6115", emsg);
+ throw new AAIException("AAI_6115", emsg);
}
try {
loader.introspectorFromName(nodeTypeB);
} catch (AAIUnknownObjectException e) {
String emsg = " Unrecognized nodeType bb [" + nodeTypeB + "]\n";
- throw new AAIException("AAI_6115", emsg);
+ throw new AAIException("AAI_6115", emsg);
}
String msg = " No Edge Rule found for this pair of nodeTypes (order does not matter) ["
@@ -2627,11 +2617,11 @@ public class ModelBasedProcessing{
* @return Map of the topology
* @throws AAIException the AAI exception
*/
- public Multimap<String, String> collectTopology4LinkagePoint( String transId, String fromAppId,
- String linkagePointStrVal, String incomingTrail, Multimap <String,String> currentMap)
+ public Multimap<String, String> collectTopology4LinkagePoint(String transId, String fromAppId,
+ String linkagePointStrVal, String incomingTrail, Multimap<String,String> currentMap)
throws AAIException {
- Multimap <String, String> thisMap = ArrayListMultimap.create();
+ Multimap<String, String> thisMap = ArrayListMultimap.create();
thisMap.putAll(currentMap);
String thisGuysTrail = incomingTrail;
@@ -2641,7 +2631,7 @@ public class ModelBasedProcessing{
String [] trailSteps = thisGuysTrail.split("\\|");
if( trailSteps == null || trailSteps.length == 0 ){
- throw new AAIException("AAI_6125", "Bad incomingTrail passed to collectTopology4LinkagePoint(): [" + incomingTrail + "] ");
+ throw new AAIException("AAI_6125", "Bad incomingTrail passed to collectTopology4LinkagePoint(): [" + incomingTrail + "] ");
}
String lastStepString = trailSteps[trailSteps.length - 1];
String [] stepPieces = lastStepString.split(",");
@@ -2666,7 +2656,7 @@ public class ModelBasedProcessing{
String thisStepNT = "";
String [] linkageSteps = linkage[x].split("\\|");
if( linkageSteps == null || linkageSteps.length == 0 ){
- throw new AAIException("AAI_6125", "Bad linkagePointStr passed to collectTopology4LinkagePoint(): [" + linkagePointStr + "] ");
+ throw new AAIException("AAI_6125", "Bad linkagePointStr passed to collectTopology4LinkagePoint(): [" + linkagePointStr + "] ");
}
for( int i=(linkageSteps.length - 1); i >= 0; i-- ){
thisStepNT = linkageSteps[i];
@@ -2688,7 +2678,7 @@ public class ModelBasedProcessing{
* @return Hash of the set of model-elements this set represents
* @throws AAIException the AAI exception
*/
- public Map<String,Object> getNextStepElementsFromSet( Vertex constrElemSetVtx )
+ public Map<String,Object> getNextStepElementsFromSet( Vertex constrElemSetVtx )
throws AAIException {
// Take a constrained-element-set and figure out the total set of all the possible elements that it
// represents and return them as a Hash.
@@ -2767,15 +2757,15 @@ public class ModelBasedProcessing{
* @return MultiMap of valid next steps for each potential query-element
* @throws AAIException the AAI exception
*/
- public Multimap<String, String> genTopoMap4NamedQ( String transId, String fromAppId,
- Vertex queryVertex, String namedQueryUuid )
+ public Multimap<String, String> genTopoMap4NamedQ(String transId, String fromAppId,
+ Vertex queryVertex, String namedQueryUuid )
throws AAIException {
if( queryVertex == null ){
throw new AAIException("AAI_6125", "null queryVertex passed to genTopoMap4NamedQ()");
}
- Multimap <String, String> initialEmptyMap = ArrayListMultimap.create();
+ Multimap<String, String> initialEmptyMap = ArrayListMultimap.create();
List<String> vidsTraversed = new ArrayList<>();
Vertex firstElementVertex = null;
@@ -2797,11 +2787,11 @@ public class ModelBasedProcessing{
Vertex modVtx = getModelThatNqElementRepresents( firstElementVertex, "" );
String modelType = getModelTypeFromModel( modVtx, "" );
if( ! modelType.equals("widget") ){
- throw new AAIException("AAI_6133", "Bad Named Query Definition: First element must correspond to a widget type model. Named Query UUID = "
+ throw new AAIException("AAI_6133", "Bad Named Query Definition: First element must correspond to a widget type model. Named Query UUID = "
+ namedQueryUuid);
}
- Multimap <String, String> collectedMap = collectTopology4NamedQ( transId, fromAppId,
+ Multimap<String, String> collectedMap = collectTopology4NamedQ( transId, fromAppId,
firstElementVertex, "",
initialEmptyMap, vidsTraversed, 0);
@@ -2821,19 +2811,19 @@ public class ModelBasedProcessing{
* @return resultSet
* @throws AAIException the AAI exception
*/
- public Multimap<String, String> collectTopology4NamedQ( String transId, String fromAppId,
- Vertex thisLevelElemVtx, String incomingTrail,
- Multimap <String,String> currentMap, List<String> vidsTraversed, int levelCounter )
+ public Multimap<String, String> collectTopology4NamedQ(String transId, String fromAppId,
+ Vertex thisLevelElemVtx, String incomingTrail,
+ Multimap<String,String> currentMap, List<String> vidsTraversed, int levelCounter )
throws AAIException {
levelCounter++;
- Multimap <String, String> thisMap = ArrayListMultimap.create();
+ Multimap<String, String> thisMap = ArrayListMultimap.create();
thisMap.putAll(currentMap);
String thisElemVid = thisLevelElemVtx.id().toString();
if( levelCounter > MAX_LEVELS ) {
- throw new AAIException("AAI_6125", "collectModelStructure() has looped across more levels than allowed: " + MAX_LEVELS + ". ");
+ throw new AAIException("AAI_6125", "collectModelStructure() has looped across more levels than allowed: " + MAX_LEVELS + ". ");
}
String thisGuysTrail = "";
@@ -2859,7 +2849,7 @@ public class ModelBasedProcessing{
thisMap.put(thisGuysTrail, tmpElNT);
if( !vidsTraversed.contains(tmpVid) ){
// This is one we would like to use - so we'll recursively get it's result set to add to ours
- Multimap<String, String> tmpMap = collectTopology4NamedQ( transId, fromAppId,
+ Multimap<String, String> tmpMap = collectTopology4NamedQ( transId, fromAppId,
tmpVert, thisGuysTrail,
currentMap, vidsTraversed, levelCounter);
thisMap.putAll(tmpMap);
@@ -2879,7 +2869,7 @@ public class ModelBasedProcessing{
* @return the model that element represents
* @throws AAIException the AAI exception
*/
- public Vertex getModelThatNqElementRepresents( Vertex elementVtx, String elementTrail )
+ public Vertex getModelThatNqElementRepresents(Vertex elementVtx, String elementTrail )
throws AAIException {
// Get the model that a named-query element represents
@@ -2926,7 +2916,7 @@ public class ModelBasedProcessing{
* @return the model-ver that element represents
* @throws AAIException the AAI exception
*/
- public Vertex getModelVerThatElementRepresents( Vertex elementVtx, String elementTrail )
+ public Vertex getModelVerThatElementRepresents(Vertex elementVtx, String elementTrail )
throws AAIException {
// Get the model-ver that an element represents
@@ -2974,7 +2964,7 @@ public class ModelBasedProcessing{
* @return the model that element represents
* @throws AAIException the AAI exception
*/
- public Vertex getModelGivenModelVer( Vertex modVerVtx, String elementTrail )
+ public Vertex getModelGivenModelVer(Vertex modVerVtx, String elementTrail )
throws AAIException {
// Get the parent model for this "model-ver" node
@@ -3025,7 +3015,7 @@ public class ModelBasedProcessing{
* @return the model type
* @throws AAIException the AAI exception
*/
- public String getModelTypeFromModel( Vertex modelVtx, String elementTrail )
+ public String getModelTypeFromModel(Vertex modelVtx, String elementTrail )
throws AAIException {
// Get the model-type from a model vertex
@@ -3059,7 +3049,7 @@ public class ModelBasedProcessing{
* @return the model type
* @throws AAIException the AAI exception
*/
- public String getModelTypeFromModelVer( Vertex modelVerVtx, String elementTrail )
+ public String getModelTypeFromModelVer(Vertex modelVerVtx, String elementTrail )
throws AAIException {
// Get the model-type given a model-ver vertex
@@ -3095,7 +3085,7 @@ public class ModelBasedProcessing{
* @return the element step name
* @throws AAIException the AAI exception
*/
- public String getModelElementStepName( Vertex elementVtx, String elementTrail)
+ public String getModelElementStepName(Vertex elementVtx, String elementTrail)
throws AAIException {
// Get the "step name" for a model-element
@@ -3195,8 +3185,8 @@ public class ModelBasedProcessing{
* @return the element widget type
* @throws AAIException the AAI exception
*/
- public String getNqElementWidgetType( String transId, String fromAppId,
- Vertex elementVtx, String elementTrail )
+ public String getNqElementWidgetType(String transId, String fromAppId,
+ Vertex elementVtx, String elementTrail )
throws AAIException {
String thisNqElementWidgetType = "";
@@ -3209,7 +3199,7 @@ public class ModelBasedProcessing{
if( modelType == null || !modelType.equals("widget") ){
String emsg = " Model Type must be 'widget' for NamedQuery elements. Found [" + modelType + "] at [" +
elementTrail + "]\n";
- throw new AAIException("AAI_6132", emsg);
+ throw new AAIException("AAI_6132", emsg);
}
else {
// For a Widget model, the nodeType is just mapped to the model-element.model-name
@@ -3219,7 +3209,7 @@ public class ModelBasedProcessing{
}
if( thisNqElementWidgetType == null || thisNqElementWidgetType.equals("") ){
String emsg = " Widget type could not be determined at [" + elementTrail + "]\n";
- throw new AAIException("AAI_6132", emsg);
+ throw new AAIException("AAI_6132", emsg);
}
else {
return thisNqElementWidgetType;
@@ -3238,7 +3228,7 @@ public class ModelBasedProcessing{
* @return the element widget type
* @throws AAIException the AAI exception
*/
- public String getModElementWidgetType( Vertex elementVtx, String elementTrail )
+ public String getModElementWidgetType(Vertex elementVtx, String elementTrail )
throws AAIException {
// Get the associated node-type for the model-ver pointed to by a model-element.
@@ -3262,27 +3252,27 @@ public class ModelBasedProcessing{
* @return unique vertex found using UUID
* @throws AAIException the AAI exception
*/
- public Vertex getNodeUsingUniqueId( String transId, String fromAppId,
- String nodeType, String idPropertyName, String uniqueIdVal )
+ public Vertex getNodeUsingUniqueId(String transId, String fromAppId,
+ String nodeType, String idPropertyName, String uniqueIdVal )
throws AAIException {
// Given a unique identifier, get the Vertex
if( uniqueIdVal == null || uniqueIdVal.equals("") ){
String emsg = " Bad uniqueIdVal passed to getNodeUsingUniqueId(): ["
+ uniqueIdVal + "]\n";
- throw new AAIException("AAI_6118", emsg);
+ throw new AAIException("AAI_6118", emsg);
}
if( idPropertyName == null || idPropertyName.equals("") ){
String emsg = " Bad idPropertyName passed to getNodeUsingUniqueId(): ["
+ idPropertyName + "]\n";
- throw new AAIException("AAI_6118", emsg);
+ throw new AAIException("AAI_6118", emsg);
}
if( nodeType == null || nodeType.equals("") ){
String emsg = " Bad nodeType passed to getNodeUsingUniqueId(): ["
+ nodeType + "]\n";
- throw new AAIException("AAI_6118", emsg);
+ throw new AAIException("AAI_6118", emsg);
}
Vertex uniqVtx = null;
@@ -3292,7 +3282,7 @@ public class ModelBasedProcessing{
String emsg = "Node could not be found for nodeType = [" + nodeType
+ "], propertyName = [" + idPropertyName
+ "], propertyValue = [" + uniqueIdVal + "]\n";
- throw new AAIException("AAI_6114", emsg);
+ throw new AAIException("AAI_6114", emsg);
}
else {
int count = 0;
@@ -3301,7 +3291,7 @@ public class ModelBasedProcessing{
String emsg = "Node could not be found for nodeType = [" + nodeType
+ "], propertyName = [" + idPropertyName
+ "], propertyValue = [" + uniqueIdVal + "]\n";
- throw new AAIException("AAI_6114", emsg);
+ throw new AAIException("AAI_6114", emsg);
}
else {
while( uniqVertsIter.hasNext() ){
@@ -3311,7 +3301,7 @@ public class ModelBasedProcessing{
String emsg = "More than one node found for nodeType = [" + nodeType
+ "], propertyName = [" + idPropertyName
+ "], propertyValue = [" + uniqueIdVal + "]\n";
- throw new AAIException("AAI_6132", emsg);
+ throw new AAIException("AAI_6132", emsg);
}
}
}
@@ -3330,15 +3320,15 @@ public class ModelBasedProcessing{
* @return the model-ver's that use this name
* @throws AAIException the AAI exception
*/
- public List<Vertex> getModelVersUsingName( String transId, String fromAppId,
- String modelName )
+ public List<Vertex> getModelVersUsingName(String transId, String fromAppId,
+ String modelName )
throws AAIException {
// Given a "model-name", find the model-ver vertices that this maps to
if( modelName == null || modelName.equals("") ){
String emsg = " Bad modelName passed to getModelVersUsingName(): ["
+ modelName + "]\n";
- throw new AAIException("AAI_6118", emsg);
+ throw new AAIException("AAI_6118", emsg);
}
List<Vertex> retVtxArr = new ArrayList<>();
@@ -3346,7 +3336,7 @@ public class ModelBasedProcessing{
if( !modVertsIter.hasNext() ){
String emsg = "Model-ver record(s) could not be found for model-ver data passed. model-name = [" +
modelName + "]\n";
- throw new AAIException("AAI_6132", emsg);
+ throw new AAIException("AAI_6132", emsg);
}
else {
while( modVertsIter.hasNext() ){
@@ -3369,15 +3359,15 @@ public class ModelBasedProcessing{
* @return the model-ver's defined for the corresponding model
* @throws AAIException the AAI exception
*/
- public Iterator<Vertex> getModVersUsingModelInvId( String transId, String fromAppId,
- String modelInvId )
+ public Iterator<Vertex> getModVersUsingModelInvId(String transId, String fromAppId,
+ String modelInvId )
throws AAIException {
// Given a "model-invariant-id", find the model-ver nodes that this maps to
if( modelInvId == null || modelInvId.equals("") ){
String emsg = " Bad model-invariant-id passed to getModVersUsingModelInvId(): ["
+ modelInvId + "]\n";
- throw new AAIException("AAI_6118", emsg);
+ throw new AAIException("AAI_6118", emsg);
}
Vertex modVtx = getNodeUsingUniqueId(transId, fromAppId, "model", "model-invariant-id", modelInvId);
@@ -3385,7 +3375,7 @@ public class ModelBasedProcessing{
if( retVtxArr == null || retVtxArr.isEmpty() ){
String emsg = " Model-ver record(s) could not be found attached to model with model-invariant-id = [" +
modelInvId + "]\n";
- throw new AAIException("AAI_6132", emsg);
+ throw new AAIException("AAI_6132", emsg);
}
return retVtxArr.iterator();
@@ -3401,13 +3391,13 @@ public class ModelBasedProcessing{
* @return the model-ver's defined for the corresponding model
* @throws AAIException the AAI exception
*/
- public List<Vertex> getModVersUsingModel( String transId, String fromAppId,
- Vertex modVtx )
+ public List<Vertex> getModVersUsingModel(String transId, String fromAppId,
+ Vertex modVtx )
throws AAIException {
if( modVtx == null ){
String emsg = " Null model vertex passed to getModVersUsingModel(): ";
- throw new AAIException("AAI_6118", emsg);
+ throw new AAIException("AAI_6118", emsg);
}
List<Vertex> retVtxArr = new ArrayList<>();
@@ -3416,7 +3406,7 @@ public class ModelBasedProcessing{
String modelInvId = modVtx.<String>property("model-invariant-id").orElse(null);
String emsg = "Model-ver record(s) could not be found attached to model with model-invariant-id = [" +
modelInvId + "]\n";
- throw new AAIException("AAI_6132", emsg);
+ throw new AAIException("AAI_6132", emsg);
}
else {
while( modVerVertsIter.hasNext() ){
@@ -3446,7 +3436,7 @@ public class ModelBasedProcessing{
if( modelName == null || modelName.equals("") ){
String emsg = " Bad modelName passed to getModelVerIdsUsingName(): ["
+ modelName + "]\n";
- throw new AAIException("AAI_6118", emsg);
+ throw new AAIException("AAI_6118", emsg);
}
List<String> retArr = new ArrayList<>();
@@ -3454,7 +3444,7 @@ public class ModelBasedProcessing{
if( !modVerVertsIter.hasNext() ){
String emsg = " model-ver record(s) could not be found for model data passed. model-name = [" +
modelName + "]\n";
- throw new AAIException("AAI_6114", emsg);
+ throw new AAIException("AAI_6114", emsg);
}
else {
while( modVerVertsIter.hasNext() ){
@@ -3469,7 +3459,7 @@ public class ModelBasedProcessing{
if( retArr.isEmpty() ){
String emsg = "No model-ver record found for model-name = ["
+ modelName + "]\n";
- throw new AAIException("AAI_6132", emsg);
+ throw new AAIException("AAI_6132", emsg);
}
return retArr;
@@ -3516,14 +3506,14 @@ public class ModelBasedProcessing{
if( !modVerVertsIter.hasNext() ){
String emsg = "model-ver record(s) could not be found for model data passed: modelInvariantId = [" + modelInvId +
"], modeVersionId = [" + modelVersionId + "], modelName = [" + modelName + "]\n";
- throw new AAIException("AAI_6114", emsg);
+ throw new AAIException("AAI_6114", emsg);
}
else {
String lastNT = "";
if( !modVerVertsIter.hasNext() ){
String emsg = "model-ver record(s) could not be found for model data passed: modelInvariantId = [" + modelInvId +
"], modeVersionId = [" + modelVersionId + "], modelName = [" + modelName + "]\n";
- throw new AAIException("AAI_6114", emsg);
+ throw new AAIException("AAI_6114", emsg);
}
while( modVerVertsIter.hasNext() ){
Vertex tmpModVerVtx = (Vertex) modVerVertsIter.next();
@@ -3536,7 +3526,7 @@ public class ModelBasedProcessing{
"], modelId = [" + modelInvId +
"], modelName = [" + modelName +
"])\n";
- throw new AAIException("AAI_6114", emsg);
+ throw new AAIException("AAI_6114", emsg);
}
}
lastNT = tmpNT;
@@ -3557,7 +3547,7 @@ public class ModelBasedProcessing{
* @return the widget type of the starting node of this model
* @throws AAIException the AAI exception
*/
- public String getModelVerTopWidgetType( Vertex modVerVtx, String elementTrail )
+ public String getModelVerTopWidgetType(Vertex modVerVtx, String elementTrail )
throws AAIException {
// Get the associated nodeType (Ie. aai-node-type / widget-type) for a model-ver.
// NOTE -- if the element points to a resource or service model, then we'll return the
@@ -3608,11 +3598,11 @@ public class ModelBasedProcessing{
* @throws AAIException the AAI exception
*/
public void validateModel(String transId, String fromAppId, String modelVersionIdVal, String apiVersion )
- throws AAIException{
+ throws AAIException {
// Note - this will throw an exception if the model either can't be found, or if
// we can't figure out its topology map.
- Vertex modelVerVtx = getNodeUsingUniqueId(transId, fromAppId, "model-ver",
+ Vertex modelVerVtx = getNodeUsingUniqueId(transId, fromAppId, "model-ver",
"model-version-id", modelVersionIdVal);
if( modelVerVtx == null ){
String msg = " Could not find model-ver with modelVersionId = [" + modelVersionIdVal + "].";
@@ -3639,11 +3629,11 @@ public class ModelBasedProcessing{
* @throws AAIException the AAI exception
*/
public void validateNamedQuery(String transId, String fromAppId, String namedQueryUuid, String apiVersion )
- throws AAIException{
+ throws AAIException {
// Note - this will throw an exception if the named query either can't be found, or if
// we can't figure out its topology map.
- Vertex nqVtx = getNodeUsingUniqueId(transId, fromAppId, "named-query",
+ Vertex nqVtx = getNodeUsingUniqueId(transId, fromAppId, "named-query",
"named-query-uuid", namedQueryUuid);
if( nqVtx == null ){
@@ -3667,7 +3657,7 @@ public class ModelBasedProcessing{
* @param resSet the res set
* @param levelCount the level count
*/
- public void showResultSet( ResultSet resSet, int levelCount ) {
+ public void showResultSet(ResultSet resSet, int levelCount ) {
levelCount++;
String propsStr = "";
diff --git a/aai-traversal/src/main/java/org/onap/aai/dbgraphmap/SearchGraph.java b/aai-traversal/src/main/java/org/onap/aai/dbgraphmap/SearchGraph.java
index ab986a2..f140bcd 100644
--- a/aai-traversal/src/main/java/org/onap/aai/dbgraphmap/SearchGraph.java
+++ b/aai-traversal/src/main/java/org/onap/aai/dbgraphmap/SearchGraph.java
@@ -1063,37 +1063,28 @@ public class SearchGraph {
String modelName = null;
try {
+ // Try to get the modelName if we can. Otherwise, do not fail, just return what we have already.
String modelInvariantIdLocal = (String)vert.<String>property("model-invariant-id-local").orElse(null); // this one points at a model
String modelVersionIdLocal = (String)vert.<String>property("model-version-id-local").orElse(null); // this one points at a model-ver
if ( (modelInvariantIdLocal != null && modelVersionIdLocal != null)
&& (modelInvariantIdLocal.length() > 0 && modelVersionIdLocal.length() > 0) ) {
- HashMap<String,Object> modelLookupHash = new HashMap<String,Object>();
-
Introspector modelVer = loader.introspectorFromName("model-ver");
modelVer.setValue("model-version-id", modelVersionIdLocal);
QueryBuilder builder = engine.getQueryBuilder().createDBQuery(modelVer);
-
List<Vertex> modelVerVerts = builder.toList();
- if (modelVerVerts.size() != 1) {
- throw new AAIException("AAI_6112");
- }
- Vertex modelVerVert = modelVerVerts.get(0);
-
- modelName = modelVerVert.<String>property("model-name").orElse(null);
-
- if (modelName != null && modelName.length() > 0) {
- inventoryItem.setValue("model-name", modelName);
+ if( (modelVerVerts != null) && (modelVerVerts.size() == 1) ) {
+ Vertex modelVerVert = modelVerVerts.get(0);
+ modelName = modelVerVert.<String>property("model-name").orElse(null);
+ if (modelName != null && modelName.length() > 0) {
+ inventoryItem.setValue("model-name", modelName);
+ }
}
}
} catch (DynamicException e) {
; // it's ok, dynamic object might not have these fields
- } catch (AAIException e) {
- if (e.getErrorObject().getErrorCode().equals("6114")) {
- // it's ok, couldn't find a matching model
- } else {
- throw e;
- }
+ } catch (Exception e) {
+ ; // it's ok, couldn't find a matching model
}
if (resultSet.getSubResultSet() != null) {
diff --git a/aai-traversal/src/main/java/org/onap/aai/interceptors/PostAaiAjscInterceptor.java b/aai-traversal/src/main/java/org/onap/aai/interceptors/PostAaiAjscInterceptor.java
index 30382e4..1849b10 100644
--- a/aai-traversal/src/main/java/org/onap/aai/interceptors/PostAaiAjscInterceptor.java
+++ b/aai-traversal/src/main/java/org/onap/aai/interceptors/PostAaiAjscInterceptor.java
@@ -48,16 +48,18 @@ public class PostAaiAjscInterceptor implements AjscInterceptor {
@Override
public boolean allowOrReject(HttpServletRequest req, HttpServletResponse resp, Map<?, ?> paramMap)
throws Exception {
- final String responseCode = LoggingContext.responseCode();
-
- if (responseCode != null && responseCode.startsWith("ERR.")) {
+ final int httpStatusCode = resp.getStatus();
+ LoggingContext.responseCode(Integer.toString(httpStatusCode));
+ if ( httpStatusCode < 200 || httpStatusCode > 299 ) {
LoggingContext.statusCode(StatusCode.ERROR);
- LOGGER.error(req.getRequestURL() + " call failed with responseCode=" + responseCode);
- } else {
+ LoggingContext.responseDescription("Error");
+ LOGGER.error(req.getRequestURL() + " call failed with responseCode=" + httpStatusCode);
+ }
+ else {
+ LoggingContext.responseDescription(LoggingContext.responseMap.get(LoggingContext.SUCCESS));
LoggingContext.statusCode(StatusCode.COMPLETE);
LOGGER.info(req.getRequestURL() + " call succeeded");
}
-
LoggingContext.clear();
return true;
}
diff --git a/aai-traversal/src/main/java/org/onap/aai/interceptors/PreAaiAjscInterceptor.java b/aai-traversal/src/main/java/org/onap/aai/interceptors/PreAaiAjscInterceptor.java
index 7d1ae73..b510d4b 100644
--- a/aai-traversal/src/main/java/org/onap/aai/interceptors/PreAaiAjscInterceptor.java
+++ b/aai-traversal/src/main/java/org/onap/aai/interceptors/PreAaiAjscInterceptor.java
@@ -31,6 +31,7 @@ import org.onap.aai.logging.LoggingContext;
import ajsc.beans.interceptors.AjscInterceptor;
public class PreAaiAjscInterceptor implements AjscInterceptor {
+ private final static String TARGET_ENTITY = "aai-traversal";
private static class LazyAaiAjscInterceptor {
public static final PreAaiAjscInterceptor INSTANCE = new PreAaiAjscInterceptor();
@@ -46,10 +47,17 @@ public class PreAaiAjscInterceptor implements AjscInterceptor {
LoggingContext.init();
- LoggingContext.requestId(req.getHeader("X-TransactionId"));
+ String serviceName = req.getMethod() + " " + req.getRequestURI().toString();
LoggingContext.partnerName(req.getHeader("X-FromAppId"));
- LoggingContext.serviceName(req.getMethod() + " " + req.getRequestURI().toString());
-
+ String queryStr = req.getQueryString();
+ if ( queryStr != null ) {
+ serviceName = serviceName + "?" + queryStr;
+ }
+ LoggingContext.serviceName(serviceName);
+ LoggingContext.targetEntity(TARGET_ENTITY);
+ LoggingContext.targetServiceName("allowOrReject");
+ LoggingContext.requestId(req.getHeader("X-TransactionId"));
+ LoggingContext.successStatusFields();
return true;
}
}
diff --git a/aai-traversal/src/main/java/org/onap/aai/rest/QueryConsumer.java b/aai-traversal/src/main/java/org/onap/aai/rest/QueryConsumer.java
index 1f4f359..57e4188 100644
--- a/aai-traversal/src/main/java/org/onap/aai/rest/QueryConsumer.java
+++ b/aai-traversal/src/main/java/org/onap/aai/rest/QueryConsumer.java
@@ -7,9 +7,9 @@
* 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.
@@ -23,10 +23,11 @@ package org.onap.aai.rest;
import java.net.URI;
import java.util.ArrayList;
-import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.Callable;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.Consumes;
@@ -67,10 +68,16 @@ import org.onap.aai.serialization.queryformats.Format;
import org.onap.aai.serialization.queryformats.FormatFactory;
import org.onap.aai.serialization.queryformats.Formatter;
import org.onap.aai.serialization.queryformats.SubGraphStyle;
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
+import org.onap.aai.logging.LoggingContext;
+import org.onap.aai.logging.LoggingContext.StatusCode;
+import org.onap.aai.logging.StopWatch;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
+import org.onap.aai.util.AAIConstants;
@Path("{version: v9|v1[012]}/query")
public class QueryConsumer extends RESTAPI {
@@ -83,11 +90,32 @@ public class QueryConsumer extends RESTAPI {
private QueryProcessorType processorType = QueryProcessorType.LOCAL_GROOVY;
/** The query style. */
private QueryStyle queryStyle = QueryStyle.TRAVERSAL;
+
+ private static final String TARGET_ENTITY = "DB";
+ private static final EELFLogger LOGGER = EELFManager.getInstance().getLogger(QueryConsumer.class);
+
@PUT
@Consumes({ MediaType.APPLICATION_JSON})
@Produces({ MediaType.APPLICATION_JSON})
- public Response executeQuery(String content, @PathParam("version")String versionParam, @PathParam("uri") @Encoded String uri, @DefaultValue("graphson") @QueryParam("format") String queryFormat,@DefaultValue("no_op") @QueryParam("subgraph") String subgraph, @Context HttpHeaders headers, @Context UriInfo info, @Context HttpServletRequest req) {
-
+ public Response executeQuery(String content, @PathParam("version")String versionParam, @PathParam("uri") @Encoded String uri, @DefaultValue("graphson") @QueryParam("format") String queryFormat,@DefaultValue("no_op") @QueryParam("subgraph") String subgraph, @Context HttpHeaders headers, @Context UriInfo info, @Context HttpServletRequest req){
+ return runner(AAIConstants.AAI_TRAVERSAL_TIMEOUT_ENABLED,
+ AAIConstants.AAI_TRAVERSAL_TIMEOUT_APP,
+ AAIConstants.AAI_TRAVERSAL_TIMEOUT_LIMIT,
+ headers,
+ info,
+ HttpMethod.GET,
+ new Callable<Response>() {
+ @Override
+ public Response call() {
+ return processExecuteQuery(content, versionParam, uri, queryFormat, subgraph, headers, info, req);
+ }
+ }
+ );
+ }
+
+ public Response processExecuteQuery(String content, @PathParam("version")String versionParam, @PathParam("uri") @Encoded String uri, @DefaultValue("graphson") @QueryParam("format") String queryFormat,@DefaultValue("no_op") @QueryParam("subgraph") String subgraph, @Context HttpHeaders headers, @Context UriInfo info, @Context HttpServletRequest req) {
+
+ String methodName = "executeQuery";
String sourceOfTruth = headers.getRequestHeaders().getFirst("X-FromAppId");
String realTime = headers.getRequestHeaders().getFirst("Real-Time");
String queryProcessor = headers.getRequestHeaders().getFirst("QueryProcessor");
@@ -95,6 +123,7 @@ public class QueryConsumer extends RESTAPI {
Response response = null;
TransactionalGraphEngine dbEngine = null;
try {
+ LoggingContext.save();
this.checkQueryParams(info.getQueryParameters());
Format format = Format.valueOf(queryFormat);
if (queryProcessor != null) {
@@ -108,9 +137,11 @@ public class QueryConsumer extends RESTAPI {
JsonElement startElement = input.get("start");
JsonElement queryElement = input.get("query");
JsonElement gremlinElement = input.get("gremlin");
+ JsonElement dslElement = input.get("dsl");
List<URI> startURIs = new ArrayList<>();
String queryURI = "";
String gremlin = "";
+ String dsl = "";
Version version = Version.valueOf(versionParam);
DBConnectionType type = this.determineConnectionType(sourceOfTruth, realTime);
@@ -133,6 +164,9 @@ public class QueryConsumer extends RESTAPI {
if (gremlinElement != null) {
gremlin = gremlinElement.getAsString();
}
+ if (dslElement != null) {
+ dsl = dslElement.getAsString();
+ }
URI queryURIObj = new URI(queryURI);
CustomQueryConfig customQueryConfig = getCustomQueryConfig(queryURIObj);
@@ -148,6 +182,11 @@ public class QueryConsumer extends RESTAPI {
GenericQueryProcessor processor = null;
+ LoggingContext.targetEntity(TARGET_ENTITY);
+ LoggingContext.targetServiceName(methodName);
+ LoggingContext.startTime();
+ StopWatch.conditionalStart();
+
if (!startURIs.isEmpty()) {
Set<Vertex> vertexSet = new LinkedHashSet<>();
QueryParser uriQuery;
@@ -165,13 +204,18 @@ public class QueryConsumer extends RESTAPI {
processor = new GenericQueryProcessor.Builder(dbEngine)
.queryFrom(queryURIObj)
.processWith(processorType).create();
- } else {
+ } else if(!dsl.equals("")){
+ processor = new GenericQueryProcessor.Builder(dbEngine)
+ .queryFrom(dsl, "dsl")
+ .processWith(processorType).create();
+ }else {
processor = new GenericQueryProcessor.Builder(dbEngine)
- .queryFrom(gremlin)
+ .queryFrom(gremlin, "gremlin")
.processWith(processorType).create();
}
String result = "";
List<Object> vertices = processor.execute(subGraphStyle);
+
DBSerializer serializer = new DBSerializer(version, dbEngine, introspectorFactoryType, sourceOfTruth);
FormatFactory ff = new FormatFactory(httpEntry.getLoader(), serializer);
@@ -179,6 +223,12 @@ public class QueryConsumer extends RESTAPI {
result = formater.output(vertices).toString();
+ double msecs = StopWatch.stopIfStarted();
+ LoggingContext.elapsedTime((long)msecs,TimeUnit.MILLISECONDS);
+ LoggingContext.successStatusFields();
+ LOGGER.info ("Completed");
+
+
response = Response.status(Status.OK)
.type(MediaType.APPLICATION_JSON)
.entity(result).build();
@@ -187,12 +237,14 @@ public class QueryConsumer extends RESTAPI {
response = consumerExceptionResponseGenerator(headers, info, HttpMethod.GET, e);
} catch (Exception e ) {
AAIException ex = new AAIException("AAI_4000", e);
-
response = consumerExceptionResponseGenerator(headers, info, HttpMethod.GET, ex);
} finally {
+ LoggingContext.restoreIfPossible();
+ LoggingContext.successStatusFields();
if (dbEngine != null) {
dbEngine.rollback();
}
+
}
return response;
@@ -213,10 +265,8 @@ public class QueryConsumer extends RESTAPI {
private List<String> checkForMissingQueryParameters( List<String> requiredParameters, MultivaluedMap<String, String> queryParams ) {
List<String> result = new ArrayList<>();
- Iterator it = requiredParameters.iterator();
- String param;
- while(it.hasNext()) {
- param = (String)it.next();
+
+ for ( String param : requiredParameters ) {
if ( !queryParams.containsKey(param)) {
result.add(param);
}
@@ -254,16 +304,12 @@ public class QueryConsumer extends RESTAPI {
if (templateVars.isEmpty()) {
templateVars.add(missingRequiredQueryParams.toString());
}
- Status s = e.getErrorObject().getHTTPResponseCode();
- String errorResponse = ErrorLogHelper.getRESTAPIErrorResponse(headers.getAcceptableMediaTypes(), e,
- templateVars);
- Response response = Response.status(s).entity(errorResponse).build();
- /*
+
Response response = Response
.status(e.getErrorObject().getHTTPResponseCode())
.entity(ErrorLogHelper.getRESTAPIErrorResponse(headers.getAcceptableMediaTypes(), e,
templateVars)).build();
- */
+
return response;
}
diff --git a/aai-traversal/src/main/java/org/onap/aai/rest/dsl/DslListener.java b/aai-traversal/src/main/java/org/onap/aai/rest/dsl/DslListener.java
new file mode 100644
index 0000000..0685674
--- /dev/null
+++ b/aai-traversal/src/main/java/org/onap/aai/rest/dsl/DslListener.java
@@ -0,0 +1,306 @@
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2017 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=========================================================
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ */
+package org.onap.aai.rest.dsl;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.List;
+
+import org.antlr.v4.runtime.tree.TerminalNode;
+
+import org.onap.aai.AAIDslParser;
+import org.onap.aai.serialization.db.EdgeRules;
+import org.onap.aai.AAIDslBaseListener;
+
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
+
+/**
+ * The Class DslListener.
+ */
+public class DslListener extends AAIDslBaseListener {
+
+ private static final EELFLogger LOGGER = EELFManager.getInstance().getLogger(DslQueryProcessor.class);
+ private final EdgeRules edgeRules = EdgeRules.getInstance();
+
+ protected List<String> list = null;
+ //TODO Use StringBuilder to build the query than concat
+ String query = "";
+
+ Map<Integer, String> unionMap = new HashMap<>();
+ Map<String, String> flags = new HashMap<>();
+
+ String currentNode = "";
+ String prevsNode = "";
+ int commas = 0;
+
+ int unionKey = 0;
+ int unionMembers = 0;
+ boolean isUnionBeg = false;
+ boolean isUnionTraversal = false;
+
+ boolean isTraversal = false;
+ boolean isWhereTraversal = false;
+ String whereTraversalNode = "";
+
+ String limitQuery = "";
+ boolean isNot = false;
+
+ /**
+ * Instantiates a new DslListener.
+ */
+
+ public DslListener() {
+ list = new ArrayList<>();
+ }
+
+ @Override
+ public void enterAaiquery(AAIDslParser.AaiqueryContext ctx) {
+ query += "builder";
+ }
+
+ @Override
+ public void enterDslStatement(AAIDslParser.DslStatementContext ctx) {
+ // LOGGER.info("Statement Enter"+ctx.getText());
+ /*
+ * This block of code is entered for every query statement
+ */
+ if (isUnionBeg) {
+ isUnionBeg = false;
+ isUnionTraversal = true;
+
+ } else if (unionMembers > 0) {
+ unionMembers--;
+ query += ",builder.newInstance()";
+ isUnionTraversal = true;
+ }
+
+ }
+
+ @Override
+ public void exitDslStatement(AAIDslParser.DslStatementContext ctx) {
+ /*
+ * Nothing to be done here for now
+ * LOGGER.info("Statement Exit"+ctx.getText());
+ */
+ }
+
+ @Override
+ public void exitAaiquery(AAIDslParser.AaiqueryContext ctx) {
+ /*
+ * dedup is by default for all queries If the query has limit in it
+ * include this as well LOGGER.info("Statement Exit"+ctx.getText());
+ */
+
+ query += ".cap('x').unfold().dedup()" + limitQuery;
+ }
+
+ /*
+ * TODO: The contexts are not inherited from a single parent in AAIDslParser
+ * Need to find a way to do that
+ */
+ @Override
+ public void enterSingleNodeStep(AAIDslParser.SingleNodeStepContext ctx) {
+
+ prevsNode = currentNode;
+ currentNode = ctx.NODE().getText();
+
+ this.generateQuery();
+ if (ctx.STORE() != null && ctx.STORE().getText().equals("*")) {
+ flags.put(currentNode, "store");
+ }
+
+ }
+
+ @Override
+ public void enterSingleQueryStep(AAIDslParser.SingleQueryStepContext ctx) {
+
+ prevsNode = currentNode;
+ currentNode = ctx.NODE().getText();
+ this.generateQuery();
+
+ if (ctx.STORE() != null && ctx.STORE().getText().equals("*")) {
+ flags.put(currentNode, "store");
+ }
+ }
+
+ @Override
+ public void enterMultiQueryStep(AAIDslParser.MultiQueryStepContext ctx) {
+
+ prevsNode = currentNode;
+ currentNode = ctx.NODE().getText();
+ this.generateQuery();
+
+ if (ctx.STORE() != null && ctx.STORE().getText().equals("*")) {
+ flags.put(currentNode, "store");
+ }
+
+ }
+
+ /*
+ * Generates the QueryBuilder syntax for the dsl query
+ */
+ private void generateQuery() {
+ String edgeType = "";
+
+ if (isUnionTraversal || isTraversal || isWhereTraversal) {
+ String previousNode = prevsNode;
+ if (isUnionTraversal) {
+ previousNode = unionMap.get(unionKey);
+ isUnionTraversal = false;
+ }
+
+ if (edgeRules.hasTreeEdgeRule(previousNode, currentNode)) {
+ edgeType = "EdgeType.TREE";
+ }else if (edgeRules.hasCousinEdgeRule(previousNode, currentNode, "")) {
+ edgeType = "EdgeType.COUSIN";
+ } else
+ edgeType = "EdgeType.COUSIN";
+
+ query += ".createEdgeTraversal(" + edgeType + ", '" + previousNode + "','" + currentNode + "')";
+
+ }
+
+ else
+ query += ".getVerticesByProperty('aai-node-type', '" + currentNode + "')";
+ }
+
+ @Override
+ public void exitSingleNodeStep(AAIDslParser.SingleNodeStepContext ctx) {
+
+ generateExitStep();
+ }
+
+ @Override
+ public void exitSingleQueryStep(AAIDslParser.SingleQueryStepContext ctx) {
+ generateExitStep();
+ }
+
+ @Override
+ public void exitMultiQueryStep(AAIDslParser.MultiQueryStepContext ctx) {
+ generateExitStep();
+
+ }
+
+ private void generateExitStep() {
+ if (flags.containsKey(currentNode)) {
+ String storeFlag = flags.get(currentNode);
+ if (storeFlag != null && storeFlag.equals("store"))
+ query += ".store('x')";
+ flags.remove(currentNode);
+ }
+ }
+
+ @Override
+ public void enterUnionQueryStep(AAIDslParser.UnionQueryStepContext ctx) {
+ isUnionBeg = true;
+
+ unionKey++;
+ unionMap.put(unionKey, currentNode);
+ query += ".union(builder.newInstance()";
+
+ List<TerminalNode> commaNodes = ctx.COMMA();
+
+ for (TerminalNode node : commaNodes) {
+ unionMembers++;
+ }
+ }
+
+ @Override
+ public void exitUnionQueryStep(AAIDslParser.UnionQueryStepContext ctx) {
+ isUnionBeg = false;
+ unionMap.remove(unionKey);
+
+ query += ")";
+ unionKey--;
+
+ }
+
+ @Override
+ public void enterFilterTraverseStep(AAIDslParser.FilterTraverseStepContext ctx) {
+ isWhereTraversal = true;
+ whereTraversalNode = currentNode;
+ query += ".where(builder.newInstance()";
+ }
+
+ @Override
+ public void exitFilterTraverseStep(AAIDslParser.FilterTraverseStepContext ctx) {
+ query += ")";
+ isWhereTraversal = false;
+ currentNode = whereTraversalNode;
+ }
+
+ @Override
+ public void enterFilterStep(AAIDslParser.FilterStepContext ctx) {
+ if (ctx.NOT() != null && ctx.NOT().getText().equals("!"))
+ isNot = true;
+
+ List<TerminalNode> nodes = ctx.KEY();
+ String key = ctx.KEY(0).getText();
+
+ if (isNot) {
+ query += ".getVerticesExcludeByProperty(";
+ isNot = false;
+ } else
+ query += ".getVerticesByProperty(";
+
+ if (nodes.size() == 2) {
+ query += key + "," + ctx.KEY(1).getText();
+ query += ")";
+ }
+
+ if (nodes.size() > 2) {
+
+ for (TerminalNode node : nodes) {
+ if (node.getText().equals(key))
+ continue;
+
+ query += key + "," + node.getText();
+ query += ")";
+ }
+
+ }
+
+ }
+
+ @Override
+ public void exitFilterStep(AAIDslParser.FilterStepContext ctx) {
+ // For now do nothing
+ }
+
+ @Override
+ public void enterTraverseStep(AAIDslParser.TraverseStepContext ctx) {
+ isTraversal = true;
+ }
+
+ @Override
+ public void exitTraverseStep(AAIDslParser.TraverseStepContext ctx) {
+ isTraversal = false;
+ }
+
+ @Override
+ public void enterLimitStep(AAIDslParser.LimitStepContext ctx) {
+ String value = ctx.NODE().getText();
+ limitQuery += ".limit(" + value + ")";
+ }
+}
diff --git a/aai-traversal/src/main/java/org/onap/aai/rest/dsl/DslQueryProcessor.java b/aai-traversal/src/main/java/org/onap/aai/rest/dsl/DslQueryProcessor.java
new file mode 100644
index 0000000..f88f8c0
--- /dev/null
+++ b/aai-traversal/src/main/java/org/onap/aai/rest/dsl/DslQueryProcessor.java
@@ -0,0 +1,99 @@
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2017 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=========================================================
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ */
+package org.onap.aai.rest.dsl;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.nio.charset.StandardCharsets;
+
+import org.antlr.v4.runtime.CharStreams;
+import org.antlr.v4.runtime.CommonTokenStream;
+import org.antlr.v4.runtime.tree.ParseTree;
+import org.antlr.v4.runtime.tree.ParseTreeWalker;
+
+import org.onap.aai.AAIDslLexer;
+import org.onap.aai.AAIDslParser;
+
+import org.onap.aai.rest.dsl.DslListener;
+import org.antlr.v4.runtime.Token;
+
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
+/**
+ * The Class DslQueryProcessor.
+ */
+public class DslQueryProcessor {
+
+ private static final EELFLogger LOGGER = EELFManager.getInstance().getLogger(DslQueryProcessor.class);
+
+ public String parseAaiQuery(String aaiQuery) {
+ try {
+ // Create a input stream that reads our string
+ InputStream stream = new ByteArrayInputStream(aaiQuery.getBytes(StandardCharsets.UTF_8));
+
+ // Create a lexer from the input CharStream
+ AAIDslLexer lexer = new AAIDslLexer(CharStreams.fromStream(stream, StandardCharsets.UTF_8));
+
+ // Get a list of tokens pulled from the lexer
+ CommonTokenStream tokens = new CommonTokenStream(lexer);
+
+
+ // Parser that feeds off of the tokens buffer
+ AAIDslParser parser = new AAIDslParser(tokens);
+
+ // Specify our entry point
+ ParseTree ptree = parser.aaiquery();
+ LOGGER.info("QUERY-interim" + ptree.toStringTree(parser));
+
+ // Walk it and attach our listener
+ ParseTreeWalker walker = new ParseTreeWalker();
+ DslListener listener = new DslListener();
+ walker.walk(listener, ptree);
+ LOGGER.info("Final QUERY" + listener.query);
+
+ /*
+ * TODO - Visitor patternQueryDslVisitor visitor = new
+ * QueryDslVisitor(); String query = visitor.visit(ptree);
+ *
+ */
+ return listener.query;
+ } catch (Exception e) {
+ LOGGER.error("Error while processing the query"+e.getMessage());
+ }
+ return "";
+ }
+
+ public static class Builder {
+
+ /*
+ * Builder constructor doesnt do anything
+ */
+ public Builder() {
+ // Do nothing
+ }
+
+ public String build(String aaiQuery) {
+
+ return new DslQueryProcessor().parseAaiQuery(aaiQuery);
+ }
+ }
+}
diff --git a/aai-traversal/src/main/java/org/onap/aai/rest/search/GenericQueryProcessor.java b/aai-traversal/src/main/java/org/onap/aai/rest/search/GenericQueryProcessor.java
index 14e218f..a230dfa 100644
--- a/aai-traversal/src/main/java/org/onap/aai/rest/search/GenericQueryProcessor.java
+++ b/aai-traversal/src/main/java/org/onap/aai/rest/search/GenericQueryProcessor.java
@@ -23,14 +23,7 @@ package org.onap.aai.rest.search;
import java.io.FileNotFoundException;
import java.net.URI;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Optional;
-import java.util.Vector;
+import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -44,6 +37,7 @@ import org.apache.tinkerpop.gremlin.structure.Graph;
import org.apache.tinkerpop.gremlin.structure.Vertex;
import org.javatuples.Pair;
import org.onap.aai.query.builder.MissingOptionalParameter;
+import org.onap.aai.rest.dsl.DslQueryProcessor;
import org.onap.aai.restcore.util.URITools;
import org.onap.aai.serialization.engines.TransactionalGraphEngine;
import org.onap.aai.serialization.queryformats.SubGraphStyle;
@@ -61,6 +55,11 @@ public abstract class GenericQueryProcessor {
protected static GremlinServerSingleton gremlinServerSingleton = GremlinServerSingleton.getInstance();
protected static GroovyQueryBuilderSingleton queryBuilderSingleton = GroovyQueryBuilderSingleton.getInstance();
protected final boolean isGremlin;
+ /* dsl parameters to store dsl query and to check
+ * if this is a DSL request
+ */
+ protected Optional<String> dsl;
+ protected final boolean isDsl ;
protected GenericQueryProcessor(Builder builder) {
this.uri = builder.getUri();
@@ -68,6 +67,9 @@ public abstract class GenericQueryProcessor {
this.vertices = builder.getVertices();
this.gremlin = builder.getGremlin();
this.isGremlin = builder.isGremlin();
+ this.dsl = builder.getDsl();
+ this.isDsl = builder.isDsl();
+
if (uri.isPresent()) {
queryParams = URITools.getQueryMap(uri.get());
} else {
@@ -116,7 +118,18 @@ public abstract class GenericQueryProcessor {
protected Pair<String, Map<String, Object>> createQuery() {
Map<String, Object> params = new HashMap<>();
String query = "";
- if (!this.isGremlin) {
+ if (this.isGremlin) {
+ query = gremlin.get();
+
+ }else if (this.isDsl) {
+ String dslUserQuery = dsl.get();
+ String dslQuery = new DslQueryProcessor.Builder().build(dslUserQuery);
+
+ query = queryBuilderSingleton.executeTraversal(dbEngine, dslQuery, params);
+ String startPrefix = "g.V()";
+ query = startPrefix + query;
+
+ }else {
Matcher m = p.matcher(uri.get().getPath());
String queryName = "";
List<String> optionalParameters = Collections.emptyList();
@@ -143,22 +156,25 @@ public abstract class GenericQueryProcessor {
}
}
- List<Object> ids = new ArrayList<>();
-
if (vertices.isPresent() && !vertices.get().isEmpty()) {
- for (Vertex v : vertices.get()) {
- ids.add(v.id());
- }
+
+ // Get the vertices and convert them into object array
+ // The reason for this was .V() takes in an array of objects
+ // not a list of objects so that needs to be converted
+ // Also instead of statically creating the list which is a bad practice
+ // We are binding the array dynamically to the groovy processor correctly
+ // This will fix the memory issue of the method size too big
+ // as statically creating a list string and passing is not appropriate
+ params.put("startVertexes", vertices.get().toArray());
+
if (query == null) {
query = "";
} else {
query = queryBuilderSingleton.executeTraversal(dbEngine, query, params);
}
- StringBuilder sb = new StringBuilder();
- sb.append("[");
- sb.append(Joiner.on(",").join(ids));
- sb.append("]");
- String startPrefix = "aaiStartQuery = " + sb.toString() + " as Object[];g.V(aaiStartQuery)";
+
+ String startPrefix = "g.V(startVertexes)";
+
if (!"".equals(query)) {
query = startPrefix + query;
} else {
@@ -166,8 +182,6 @@ public abstract class GenericQueryProcessor {
}
}
- } else {
- query = gremlin.get();
}
return new Pair<>(query, params);
@@ -182,6 +196,9 @@ public abstract class GenericQueryProcessor {
private Optional<Collection<Vertex>> vertices = Optional.empty();
private QueryProcessorType processorType = QueryProcessorType.GREMLIN_SERVER;
+ private Optional<String> dsl = Optional.empty();
+ private boolean isDsl = false;
+
public Builder(TransactionalGraphEngine dbEngine) {
this.dbEngine = dbEngine;
}
@@ -197,9 +214,16 @@ public abstract class GenericQueryProcessor {
return this;
}
- public Builder queryFrom(String gremlin) {
- this.gremlin = Optional.of(gremlin);
- this.isGremlin = true;
+ public Builder queryFrom( String query, String queryType) {
+
+ if(queryType.equals("gremlin")){
+ this.gremlin = Optional.of(query);
+ this.isGremlin = true;
+ }
+ if(queryType.equals("dsl")){
+ this.dsl = Optional.of(query);
+ this.isDsl = true;
+ }
return this;
}
@@ -222,6 +246,14 @@ public abstract class GenericQueryProcessor {
public boolean isGremlin() {
return isGremlin;
}
+
+ public Optional<String> getDsl() {
+ return dsl;
+ }
+
+ public boolean isDsl() {
+ return isDsl;
+ }
public Optional<Collection<Vertex>> getVertices() {
return vertices;
diff --git a/aai-traversal/src/main/java/org/onap/aai/rest/search/GetCustomQueryConfig.java b/aai-traversal/src/main/java/org/onap/aai/rest/search/GetCustomQueryConfig.java
index 9ea0b1d..760146e 100644
--- a/aai-traversal/src/main/java/org/onap/aai/rest/search/GetCustomQueryConfig.java
+++ b/aai-traversal/src/main/java/org/onap/aai/rest/search/GetCustomQueryConfig.java
@@ -24,6 +24,7 @@ import java.io.IOException;
import java.lang.reflect.Type;
import java.nio.file.Files;
import java.nio.file.Paths;
+import java.util.ArrayList;
import java.util.List;
import org.onap.aai.util.AAIConstants;
@@ -98,6 +99,8 @@ public class GetCustomQueryConfig {
private void getStoredQueryBlock( JsonObject configObject, String config ) {
if ( !configObject.has(config)) {
+ customQueryConfig.setQueryRequiredProperties( new ArrayList<String>() );
+ customQueryConfig.setQueryOptionalProperties( new ArrayList<String>() );
return;
}
@@ -109,18 +112,15 @@ public class GetCustomQueryConfig {
queryConfig = configObject.get(config);
subObject = queryConfig.getAsJsonObject();
propertyList = getPropertyList(subObject, REQUIRED_CONFIG);
- if ( QUERY_CONFIG.equals(config)) {
- customQueryConfig.setQueryRequiredProperties( propertyList );
- } else {
- customQueryConfig.setQueryRequiredProperties( null );
+ if ( propertyList == null ) {
+ propertyList = new ArrayList<String>();
}
-
+ customQueryConfig.setQueryRequiredProperties( propertyList );
propertyList = getPropertyList(subObject, OPTIONAL_CONFIG);
- if ( QUERY_CONFIG.equals(config)) {
- customQueryConfig.setQueryOptionalProperties( propertyList );
- } else {
- customQueryConfig.setQueryOptionalProperties( null );
+ if ( propertyList == null ) {
+ propertyList = new ArrayList<String>();
}
+ customQueryConfig.setQueryOptionalProperties( propertyList );
}
diff --git a/aai-traversal/src/main/java/org/onap/aai/rest/search/GremlinServerSingleton.java b/aai-traversal/src/main/java/org/onap/aai/rest/search/GremlinServerSingleton.java
index 2265680..b1d68bc 100644
--- a/aai-traversal/src/main/java/org/onap/aai/rest/search/GremlinServerSingleton.java
+++ b/aai-traversal/src/main/java/org/onap/aai/rest/search/GremlinServerSingleton.java
@@ -21,6 +21,7 @@
*/
package org.onap.aai.rest.search;
+import org.onap.aai.logging.LogFormatTools;
import org.onap.aai.util.AAIConstants;
import org.onap.aai.util.FileWatcher;
import com.att.eelf.configuration.EELFLogger;
@@ -79,7 +80,7 @@ public class GremlinServerSingleton {
.maxContentLength(6537920)
.create();
} catch (FileNotFoundException e) {
- logger.error("Unable to find the file: " + e);
+ logger.error("Unable to find the file: " + LogFormatTools.getStackTop(e));
}
try {
@@ -90,7 +91,7 @@ public class GremlinServerSingleton {
queryConfig = new GetCustomQueryConfig(customQueryConfigJson);
} catch (IOException e) {
- logger.error("Error occurred during the processing of query json file: " + e);
+ logger.error("Error occurred during the processing of query json file: " + LogFormatTools.getStackTop(e));
}
@@ -103,7 +104,7 @@ public class GremlinServerSingleton {
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: " + e);
+ logger.error("Error occurred during the processing of query json file: " + LogFormatTools.getStackTop(e));
}
}
};
@@ -127,6 +128,9 @@ public class GremlinServerSingleton {
*/
public String getStoredQueryFromConfig(String key){
CustomQueryConfig customQueryConfig = queryConfig.getStoredQuery(key);
+ if ( customQueryConfig == null ) {
+ return null;
+ }
return customQueryConfig.getQuery();
}
diff --git a/aai-traversal/src/main/java/org/onap/aai/rest/search/ModelAndNamedQueryRestProvider.java b/aai-traversal/src/main/java/org/onap/aai/rest/search/ModelAndNamedQueryRestProvider.java
index 49d9dc5..67883fb 100644
--- a/aai-traversal/src/main/java/org/onap/aai/rest/search/ModelAndNamedQueryRestProvider.java
+++ b/aai-traversal/src/main/java/org/onap/aai/rest/search/ModelAndNamedQueryRestProvider.java
@@ -21,26 +21,30 @@
*/
package org.onap.aai.rest.search;
-import java.util.ArrayList;
-
-import javax.servlet.http.HttpServletRequest;
-import javax.ws.rs.POST;
-import javax.ws.rs.Path;
-import javax.ws.rs.Produces;
-import javax.ws.rs.QueryParam;
-import javax.ws.rs.core.Context;
-import javax.ws.rs.core.HttpHeaders;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.Response;
-import javax.ws.rs.core.Response.Status;
-
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
import org.onap.aai.dbgraphmap.SearchGraph;
import org.onap.aai.dbmap.DBConnectionType;
import org.onap.aai.exceptions.AAIException;
import org.onap.aai.extensions.AAIExtensionMap;
import org.onap.aai.logging.ErrorLogHelper;
+import org.onap.aai.logging.LoggingContext;
+import org.onap.aai.logging.StopWatch;
+import org.onap.aai.restcore.HttpMethod;
import org.onap.aai.restcore.RESTAPI;
import org.onap.aai.util.AAIApiVersion;
+import org.onap.aai.util.AAIConstants;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.core.*;
+import javax.ws.rs.core.Response.Status;
+import java.util.ArrayList;
+import java.util.concurrent.Callable;
+import java.util.concurrent.TimeUnit;
/**
* Implements the search subdomain in the REST API. All API calls must include
@@ -59,6 +63,9 @@ public class ModelAndNamedQueryRestProvider extends RESTAPI {
public static final String MODEL_QUERY = "/model";
+ public static final String TARGET_ENTITY = "DB";
+ private static final EELFLogger LOGGER = EELFManager.getInstance().getLogger(ModelAndNamedQueryRestProvider.class);
+
/**
* Gets the named query response.
*
@@ -72,19 +79,44 @@ public class ModelAndNamedQueryRestProvider extends RESTAPI {
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Path(NAMED_QUERY)
public Response getNamedQueryResponse(@Context HttpHeaders headers,
- @Context HttpServletRequest req,
- String queryParameters) {
+ @Context HttpServletRequest req,
+ String queryParameters,
+ @Context UriInfo info) {
+ return runner(AAIConstants.AAI_TRAVERSAL_TIMEOUT_ENABLED,
+ AAIConstants.AAI_TRAVERSAL_TIMEOUT_APP,
+ AAIConstants.AAI_TRAVERSAL_TIMEOUT_LIMIT,
+ headers,
+ info,
+ HttpMethod.GET,
+ new Callable<Response>() {
+ @Override
+ public Response call() {
+ return processNamedQueryResponse(headers, req, queryParameters);
+ }
+ }
+ );
+ }
+
+ public Response processNamedQueryResponse(@Context HttpHeaders headers,
+ @Context HttpServletRequest req,
+ String queryParameters) {
+ String methodName = "getNamedQueryResponse";
AAIException ex = null;
Response response = null;
String fromAppId = null;
String transId = null;
+ double dbTimeMsecs = 0;
String rqstTm = genDate();
ArrayList<String> templateVars = new ArrayList<String>();
try {
+ LoggingContext.save();
+ LoggingContext.targetEntity(TARGET_ENTITY);
+ LoggingContext.targetServiceName(methodName);
+
fromAppId = getFromAppId(headers);
transId = getTransId(headers);
- AAIExtensionMap aaiExtMap = new AAIExtensionMap();
+ AAIExtensionMap aaiExtMap = new AAIExtensionMap();
aaiExtMap.setHttpHeaders(headers);
aaiExtMap.setServletRequest(req);
aaiExtMap.setApiVersion(AAIApiVersion.get());
@@ -93,11 +125,25 @@ public class ModelAndNamedQueryRestProvider extends RESTAPI {
DBConnectionType type = this.determineConnectionType("force-cache", realTime);
SearchGraph searchGraph = new SearchGraph();
+ LoggingContext.startTime();
+ StopWatch.conditionalStart();
+
response = searchGraph.runNamedQuery(fromAppId, transId, queryParameters, type, aaiExtMap);
+ dbTimeMsecs += StopWatch.stopIfStarted();
+ LoggingContext.elapsedTime((long)dbTimeMsecs,TimeUnit.MILLISECONDS);
+ LoggingContext.successStatusFields();
+
+
+ LOGGER.info ("Completed");
+
+ LoggingContext.restoreIfPossible();
+ LoggingContext.successStatusFields();
+
String respTm = genDate();
} catch (AAIException e) {
+ LoggingContext.restoreIfPossible();
// send error response
ex = e;
templateVars.add("POST Search");
@@ -107,6 +153,7 @@ public class ModelAndNamedQueryRestProvider extends RESTAPI {
.entity(ErrorLogHelper.getRESTAPIErrorResponse(headers.getAcceptableMediaTypes(), e, templateVars))
.build();
} catch (Exception e) {
+ LoggingContext.restoreIfPossible();
// send error response
ex = new AAIException("AAI_4000", e);
templateVars.add("POST Search");
@@ -138,20 +185,47 @@ public class ModelAndNamedQueryRestProvider extends RESTAPI {
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Path(MODEL_QUERY)
public Response getModelQueryResponse(@Context HttpHeaders headers,
- @Context HttpServletRequest req,
- String inboundPayload,
- @QueryParam("action") String action) {
+ @Context HttpServletRequest req,
+ String inboundPayload,
+ @QueryParam("action") String action,
+ @Context UriInfo info) {
+ return runner(AAIConstants.AAI_TRAVERSAL_TIMEOUT_ENABLED,
+ AAIConstants.AAI_TRAVERSAL_TIMEOUT_APP,
+ AAIConstants.AAI_TRAVERSAL_TIMEOUT_LIMIT,
+ headers,
+ info,
+ HttpMethod.GET,
+ new Callable<Response>() {
+ @Override
+ public Response call() {
+ return processModelQueryResponse(headers, req, inboundPayload, action);
+ }
+ }
+ );
+ }
+
+ public Response processModelQueryResponse(@Context HttpHeaders headers,
+ @Context HttpServletRequest req,
+ String inboundPayload,
+ @QueryParam("action") String action) {
+ String methodName = "getModelQueryResponse";
AAIException ex = null;
Response response = null;
String fromAppId = null;
String transId = null;
+ double dbTimeMsecs = 0;
+
String rqstTm = genDate();
ArrayList<String> templateVars = new ArrayList<String>();
try {
+ LoggingContext.save();
+ LoggingContext.targetEntity(TARGET_ENTITY);
+ LoggingContext.targetServiceName(methodName);
+
fromAppId = getFromAppId(headers);
transId = getTransId(headers);
- AAIExtensionMap aaiExtMap = new AAIExtensionMap();
+ AAIExtensionMap aaiExtMap = new AAIExtensionMap();
aaiExtMap.setHttpHeaders(headers);
aaiExtMap.setServletRequest(req);
aaiExtMap.setApiVersion(AAIApiVersion.get());
@@ -163,14 +237,26 @@ public class ModelAndNamedQueryRestProvider extends RESTAPI {
DBConnectionType type = this.determineConnectionType("force-cache", realTime);
SearchGraph searchGraph = new SearchGraph();
+ LoggingContext.startTime();
+ StopWatch.conditionalStart();
+
if (action != null && action.equalsIgnoreCase("DELETE")) {
response = searchGraph.executeModelOperation(fromAppId, transId, inboundPayload, type, true, aaiExtMap);
} else {
response = searchGraph.executeModelOperation(fromAppId, transId, inboundPayload, type, false, aaiExtMap);
}
+ dbTimeMsecs += StopWatch.stopIfStarted();
+ LoggingContext.elapsedTime((long)dbTimeMsecs,TimeUnit.MILLISECONDS);
+ LoggingContext.successStatusFields();
+
+ LOGGER.info ("Completed");
+
+ LoggingContext.restoreIfPossible();
+ LoggingContext.successStatusFields();
String respTm = genDate();
} catch (AAIException e) {
+ LoggingContext.restoreIfPossible();
// send error response
ex = e;
templateVars.add("POST Search");
@@ -180,6 +266,7 @@ public class ModelAndNamedQueryRestProvider extends RESTAPI {
.entity(ErrorLogHelper.getRESTAPIErrorResponse(headers.getAcceptableMediaTypes(), e, templateVars))
.build();
} catch (Exception e) {
+ LoggingContext.restoreIfPossible();
// send error response
ex = new AAIException("AAI_4000", e);
templateVars.add("POST Search");
diff --git a/aai-traversal/src/main/java/org/onap/aai/rest/search/SearchProvider.java b/aai-traversal/src/main/java/org/onap/aai/rest/search/SearchProvider.java
index dbc618e..501e019 100644
--- a/aai-traversal/src/main/java/org/onap/aai/rest/search/SearchProvider.java
+++ b/aai-traversal/src/main/java/org/onap/aai/rest/search/SearchProvider.java
@@ -7,9 +7,9 @@
* 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.
@@ -23,6 +23,8 @@ package org.onap.aai.rest.search;
import java.util.ArrayList;
import java.util.List;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.Callable;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.GET;
@@ -35,6 +37,7 @@ import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
+import javax.ws.rs.core.UriInfo;
import org.onap.aai.db.props.AAIProperties;
import org.onap.aai.dbgraphmap.SearchGraph;
@@ -45,13 +48,20 @@ import org.onap.aai.introspection.LoaderFactory;
import org.onap.aai.introspection.ModelType;
import org.onap.aai.introspection.Version;
import org.onap.aai.logging.ErrorLogHelper;
+import org.onap.aai.logging.LoggingContext;
+import org.onap.aai.logging.StopWatch;
+import org.onap.aai.logging.LoggingContext.StatusCode;
+import org.onap.aai.restcore.HttpMethod;
import org.onap.aai.restcore.RESTAPI;
import org.onap.aai.serialization.db.DBSerializer;
import org.onap.aai.serialization.engines.QueryStyle;
import org.onap.aai.serialization.engines.TitanDBEngine;
import org.onap.aai.serialization.engines.TransactionalGraphEngine;
import org.onap.aai.serialization.queryformats.utils.UrlBuilder;
+import org.onap.aai.util.AAIConstants;
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
/**
* Implements the search subdomain in the REST API. All API calls must include
* X-FromAppId and X-TransactionId in the header.
@@ -60,7 +70,7 @@ import org.onap.aai.serialization.queryformats.utils.UrlBuilder;
*
*/
-@Path("/{version: v2|v[789]|v1[012]|latest}/search")
+@Path("/{version: v[789]|v1[012]|latest}/search")
public class SearchProvider extends RESTAPI {
protected static String authPolicyFunctionName = "search";
@@ -69,6 +79,8 @@ public class SearchProvider extends RESTAPI {
public static final String NODES_QUERY = "/nodes-query";
+ public static final String TARGET_ENTITY = "DB";
+ private static final EELFLogger LOGGER = EELFManager.getInstance().getLogger(SearchProvider.class);
/**
* Gets the generic query response.
*
@@ -90,16 +102,46 @@ public class SearchProvider extends RESTAPI {
@QueryParam("key") final List<String> startNodeKeyParams,
@QueryParam("include") final List<String> includeNodeTypes,
@QueryParam("depth") final int depth,
- @PathParam("version")String versionParam
+ @PathParam("version")String versionParam,
+ @Context UriInfo info
+ ) {
+ return runner(AAIConstants.AAI_TRAVERSAL_TIMEOUT_ENABLED,
+ AAIConstants.AAI_TRAVERSAL_TIMEOUT_APP,
+ AAIConstants.AAI_TRAVERSAL_TIMEOUT_LIMIT,
+ headers,
+ info,
+ HttpMethod.GET,
+ new Callable<Response>() {
+ @Override
+ public Response call() {
+ return processGenericQueryResponse(headers, req, startNodeType, startNodeKeyParams, includeNodeTypes, depth, versionParam);
+ }
+ }
+ );
+ }
+
+ public Response processGenericQueryResponse(@Context HttpHeaders headers,
+ @Context HttpServletRequest req,
+ @QueryParam("start-node-type") final String startNodeType,
+ @QueryParam("key") final List<String> startNodeKeyParams,
+ @QueryParam("include") final List<String> includeNodeTypes,
+ @QueryParam("depth") final int depth,
+ @PathParam("version")String versionParam
) {
+ String methodName = "getGenericQueryResponse";
AAIException ex = null;
Response searchResult = null;
String fromAppId = null;
String transId = null;
String rqstTm = genDate();
ArrayList<String> templateVars = new ArrayList<String>();
+ double dbTimeMsecs = 0;
try {
+ LoggingContext.save();
+ LoggingContext.targetEntity(TARGET_ENTITY);
+ LoggingContext.targetServiceName(methodName);
+
fromAppId = getFromAppId(headers);
transId = getTransId(headers);
String realTime = headers.getRequestHeaders().getFirst("Real-Time");
@@ -120,6 +162,9 @@ public class SearchProvider extends RESTAPI {
DBSerializer dbSerializer = new DBSerializer(version, dbEngine, factoryType, fromAppId);
UrlBuilder urlBuilder = new UrlBuilder(version, dbSerializer);
SearchGraph searchGraph = new SearchGraph();
+
+ LoggingContext.startTime();
+ StopWatch.conditionalStart();
searchResult = searchGraph.runGenericQuery(
headers,
startNodeType,
@@ -131,10 +176,19 @@ public class SearchProvider extends RESTAPI {
urlBuilder
);
+ dbTimeMsecs += StopWatch.stopIfStarted();
+
+ LoggingContext.successStatusFields();
+ LoggingContext.elapsedTime((long)dbTimeMsecs,TimeUnit.MILLISECONDS);
+
+ LOGGER.info ("Completed");
+ LoggingContext.restoreIfPossible();
+ LoggingContext.successStatusFields();
String respTm = genDate();
-
+
} catch (AAIException e) {
+ LoggingContext.restoreIfPossible();
// send error response
ex = e;
templateVars.add("GET Search");
@@ -144,6 +198,7 @@ public class SearchProvider extends RESTAPI {
.entity(ErrorLogHelper.getRESTAPIErrorResponse(headers.getAcceptableMediaTypes(), e, templateVars))
.build();
} catch (Exception e) {
+ LoggingContext.restoreIfPossible();
// send error response
ex = new AAIException("AAI_4000", e);
templateVars.add("GET Search");
@@ -179,18 +234,47 @@ public class SearchProvider extends RESTAPI {
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Path(NODES_QUERY)
public Response getNodesQueryResponse(@Context HttpHeaders headers,
- @Context HttpServletRequest req,
- @QueryParam("search-node-type") final String searchNodeType,
- @QueryParam("edge-filter") final List<String> edgeFilterList,
- @QueryParam("filter") final List<String> filterList,
- @PathParam("version")String versionParam) {
+ @Context HttpServletRequest req,
+ @QueryParam("search-node-type") final String searchNodeType,
+ @QueryParam("edge-filter") final List<String> edgeFilterList,
+ @QueryParam("filter") final List<String> filterList,
+ @PathParam("version")String versionParam,
+ @Context UriInfo info)
+
+ {
+ return runner(AAIConstants.AAI_TRAVERSAL_TIMEOUT_ENABLED,
+ AAIConstants.AAI_TRAVERSAL_TIMEOUT_APP,
+ AAIConstants.AAI_TRAVERSAL_TIMEOUT_LIMIT,
+ headers,
+ info,
+ HttpMethod.GET,
+ new Callable<Response>() {
+ @Override
+ public Response call() {
+ return processNodesQueryResponse(headers, req, searchNodeType, edgeFilterList, filterList, versionParam);
+ }
+ }
+ );
+ }
+ public Response processNodesQueryResponse(@Context HttpHeaders headers,
+ @Context HttpServletRequest req,
+ @QueryParam("search-node-type") final String searchNodeType,
+ @QueryParam("edge-filter") final List<String> edgeFilterList,
+ @QueryParam("filter") final List<String> filterList,
+ @PathParam("version")String versionParam) {
+ String methodName = "getNodesQueryResponse";
AAIException ex = null;
Response searchResult = null;
String fromAppId = null;
String transId = null;
String rqstTm = genDate();
ArrayList<String> templateVars = new ArrayList<String>();
+ double dbTimeMsecs = 0;
try {
+ LoggingContext.save();
+ LoggingContext.targetEntity(TARGET_ENTITY);
+ LoggingContext.targetServiceName(methodName);
+
fromAppId = getFromAppId(headers);
transId = getTransId(headers);
String realTime = headers.getRequestHeaders().getFirst("Real-Time");
@@ -213,6 +297,9 @@ public class SearchProvider extends RESTAPI {
UrlBuilder urlBuilder = new UrlBuilder(version, dbSerializer);
SearchGraph searchGraph = new SearchGraph();
+ LoggingContext.startTime();
+ StopWatch.conditionalStart();
+
searchResult = searchGraph.runNodesQuery(headers,
searchNodeType,
edgeFilterList,
@@ -220,9 +307,17 @@ public class SearchProvider extends RESTAPI {
dbEngine,
loader,
urlBuilder);
+ dbTimeMsecs += StopWatch.stopIfStarted();
+ LoggingContext.elapsedTime((long)dbTimeMsecs,TimeUnit.MILLISECONDS);
+ LoggingContext.successStatusFields();
+ LOGGER.info ("Completed");
+
+ LoggingContext.restoreIfPossible();
+ LoggingContext.successStatusFields();
String respTm = genDate();
- } catch (AAIException e) {
+ } catch (AAIException e) {
+ LoggingContext.restoreIfPossible();
// send error response
ex = e;
templateVars.add("GET Search");
@@ -232,6 +327,7 @@ public class SearchProvider extends RESTAPI {
.entity(ErrorLogHelper.getRESTAPIErrorResponse(headers.getAcceptableMediaTypes(), e, templateVars))
.build();
} catch (Exception e) {
+ LoggingContext.restoreIfPossible();
// send error response
ex = new AAIException("AAI_4000", e);
templateVars.add("GET Search");
diff --git a/aai-traversal/src/main/java/org/onap/aai/util/AAIAppServletContextListener.java b/aai-traversal/src/main/java/org/onap/aai/util/AAIAppServletContextListener.java
index 49a77d8..86fefdd 100644
--- a/aai-traversal/src/main/java/org/onap/aai/util/AAIAppServletContextListener.java
+++ b/aai-traversal/src/main/java/org/onap/aai/util/AAIAppServletContextListener.java
@@ -7,9 +7,9 @@
* 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
- *
+ *
+ * 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.
@@ -19,27 +19,33 @@
*
* ECOMP is a trademark and service mark of AT&T Intellectual Property.
*/
+
package org.onap.aai.util;
import java.io.IOException;
-
+import java.util.UUID;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
-//import org.apache.activemq.broker.BrokerService;
+import org.apache.activemq.broker.BrokerService;
import org.onap.aai.dbmap.AAIGraph;
import org.onap.aai.exceptions.AAIException;
import org.onap.aai.introspection.ModelInjestor;
import org.onap.aai.logging.ErrorLogHelper;
+import org.onap.aai.logging.LogFormatTools;
+import org.onap.aai.logging.LoggingContext;
+import org.onap.aai.logging.LoggingContext.StatusCode;
+
import com.att.eelf.configuration.EELFLogger;
import com.att.eelf.configuration.EELFManager;
public class AAIAppServletContextListener implements ServletContextListener {
+ private static final String MICRO_SVC="aai-traversal";
+ private static final String ACTIVEMQ_TCP_URL = "tcp://localhost:61446";
private static final EELFLogger LOGGER = EELFManager.getInstance().getLogger(AAIAppServletContextListener.class.getName());
-
- //private BrokerService broker = new BrokerService();
+ private BrokerService broker = new BrokerService();
/**
* Destroys Context
@@ -47,16 +53,6 @@ public class AAIAppServletContextListener implements ServletContextListener {
* @param arg0 the ServletContextEvent
*/
public void contextDestroyed(ServletContextEvent arg0) {
- LOGGER.info("AAIGraph shutting down");
- AAIGraph.getInstance().graphShutdown();
- LOGGER.info("AAIGraph shutdown");
-
- //try {
- ////broker.stop();
- //} catch (Exception e) {
- //// TODO Auto-generated catch block
- //e.printStackTrace();
- //}
}
/**
@@ -66,8 +62,17 @@ public class AAIAppServletContextListener implements ServletContextListener {
*/
public void contextInitialized(ServletContextEvent arg0) {
System.setProperty("org.onap.aai.serverStarted", "false");
- LOGGER.info("***AAI Server initialization started...");
-
+ System.setProperty("aai.service.name", "traversal");
+
+ LoggingContext.save();
+ LoggingContext.component("init");
+ LoggingContext.partnerName("NA");
+ LoggingContext.targetEntity(MICRO_SVC);
+ LoggingContext.requestId(UUID.randomUUID().toString());
+ LoggingContext.serviceName(MICRO_SVC);
+ LoggingContext.targetServiceName("contextInitialized");
+ LoggingContext.statusCode(StatusCode.COMPLETE);
+ LOGGER.info("AAI Server initialization started...");
try {
LOGGER.info("Loading aaiconfig.properties");
AAIConfig.init();
@@ -81,30 +86,45 @@ public class AAIAppServletContextListener implements ServletContextListener {
ModelInjestor.getInstance();
// Jsm internal broker for aai events
- //broker = new BrokerService();
- //broker.addConnector("tcp://localhost:61446");
- //broker.setPersistent(false);
- //broker.setUseJmx(false);
- //broker.setSchedulerSupport(false);
- //broker.start();
-
- LOGGER.info("AAI Server initialization succcessful.");
+ broker = new BrokerService();
+ broker.addConnector(ACTIVEMQ_TCP_URL);
+ broker.setPersistent(false);
+ broker.setUseJmx(false);
+ broker.setSchedulerSupport(false);
+ broker.start();
+
+ LOGGER.info("A&AI Server initialization succcessful.");
+ System.setProperty("activemq.tcp.url", ACTIVEMQ_TCP_URL);
System.setProperty("org.onap.aai.serverStarted", "true");
+ Runtime.getRuntime().addShutdownHook(new Thread() {
+ public void run() {
+ LOGGER.info("AAIGraph shutting down");
+ AAIGraph.getInstance().graphShutdown();
+ LOGGER.info("AAIGraph shutdown");
+ try {
+ broker.stop();
+ } catch (Exception e) {
+ LOGGER.error("Issue closing broker " + LogFormatTools.getStackTop(e));
+ }
+ System.out.println("Shutdown hook triggered.");
+ }
+ });
+
} catch (AAIException e) {
ErrorLogHelper.logException(e);
- throw new RuntimeException("AAIException caught while initializing AAI server", e);
+ throw new RuntimeException("AAIException caught while initializing A&AI server", e);
} catch (IOException e) {
ErrorLogHelper.logError("AAI_4000", e.getMessage());
- throw new RuntimeException("IOException caught while initializing AAI server", e);
+ throw new RuntimeException("IOException caught while initializing A&AI server", e);
} catch (Exception e) {
- LOGGER.error("Unknown failure while initializing AAI Server", e);
- throw new RuntimeException("Unknown failure while initializing AAI server", e);
+ LOGGER.error("Unknown failure while initializing A&AI Server" + LogFormatTools.getStackTop(e));
+ throw new RuntimeException("Unknown failure while initializing A&AI server", e);
}
LOGGER.info("Graph-Query MicroService Started");
- LOGGER.error("Graph-Query MicroService Started");
LOGGER.debug("Graph-Query MicroService Started");
+ LoggingContext.restore();
}
}