From 1320a79c29b2e0bacbf32af1ee348e55ccf08e7c Mon Sep 17 00:00:00 2001 From: Venkata Harish K Kajur Date: Thu, 25 May 2017 10:21:33 -0400 Subject: Update the traversal to the latest internal code Change-Id: I47f3bbbb953f9c1f2247758dda33b90d0aa56074 Signed-off-by: Venkata Harish K Kajur --- .../org/openecomp/aai/dbgraphmap/SearchGraph.java | 84 ++++++++++++---------- .../openecomp/aai/rest/ueb/NotificationEvent.java | 15 ++-- .../openecomp/aai/rest/ueb/UEBNotification.java | 10 ++- .../openecomp/aai/util/StoreNotificationEvent.java | 31 ++------ 4 files changed, 67 insertions(+), 73 deletions(-) (limited to 'aai-traversal/src/main/java/org') diff --git a/aai-traversal/src/main/java/org/openecomp/aai/dbgraphmap/SearchGraph.java b/aai-traversal/src/main/java/org/openecomp/aai/dbgraphmap/SearchGraph.java index f45c3f5..7ffc52e 100644 --- a/aai-traversal/src/main/java/org/openecomp/aai/dbgraphmap/SearchGraph.java +++ b/aai-traversal/src/main/java/org/openecomp/aai/dbgraphmap/SearchGraph.java @@ -33,6 +33,7 @@ import java.util.ListIterator; import java.util.Map; import java.util.Optional; import java.util.Set; +import java.util.stream.Stream; import javax.ws.rs.core.HttpHeaders; import javax.ws.rs.core.MediaType; @@ -79,6 +80,7 @@ import org.openecomp.aai.serialization.db.EdgeRules; import org.openecomp.aai.serialization.engines.QueryStyle; import org.openecomp.aai.serialization.engines.TitanDBEngine; import org.openecomp.aai.serialization.engines.TransactionalGraphEngine; +import org.openecomp.aai.serialization.queryformats.exceptions.AAIFormatVertexException; import org.openecomp.aai.serialization.queryformats.utils.UrlBuilder; import org.openecomp.aai.util.AAIApiServerURLBase; import org.openecomp.aai.util.AAIApiVersion; @@ -152,7 +154,7 @@ public class SearchGraph { // there is an issue with service-instance - it is a unique node but still dependent // for now query it directly without attempting to craft a valid URI - if (startNodeType.equalsIgnoreCase("service-instance")) { + if (startNodeType.equalsIgnoreCase("service-instance") && startNodeKeyParams.size() == 1) { Introspector obj = loader.introspectorFromName(startNodeType); // Build a hash with keys to uniquely identify the start Node String keyName = null; @@ -168,7 +170,6 @@ public class SearchGraph { keyName = keyData.substring(0, colonIndex).split("\\.")[1]; keyValue = keyData.substring(colonIndex + 1); builder.getVerticesByProperty(keyName, keyValue); - } } @@ -212,19 +213,7 @@ public class SearchGraph { } else { - Introspector searchResults = loader.introspectorFromName("search-results"); - List resultDataList = searchResults.getValue("result-data"); - for (Vertex thisNode: queryResults){ - String nodeType = thisNode.property(AAIProperties.NODE_TYPE).orElse(null); - - String thisNodeURL = urlBuilder.pathed(thisNode); - Introspector resultData = loader.introspectorFromName("result-data"); - - resultData.setValue("resource-type", nodeType); - resultData.setValue("resource-link", thisNodeURL); - resultDataList.add(resultData.getUnderlyingObject()); - - } + Introspector searchResults = createSearchResults(loader, urlBuilder, queryResults); String outputMediaType = getMediaType(headers.getAcceptableMediaTypes()); org.openecomp.aai.introspection.MarshallerProperties properties = new org.openecomp.aai.introspection.MarshallerProperties.Builder( @@ -233,7 +222,7 @@ public class SearchGraph { result = searchResults.marshal(properties); response = Response.ok().entity(result).build(); - LOGGER.debug(ver.size() + " node(s) traversed, " + resultDataList.size() + " found"); + LOGGER.debug(ver.size() + " node(s) traversed, " + queryResults.size() + " found"); } success = true; } catch (AAIException e) { @@ -418,7 +407,7 @@ public class SearchGraph { GraphTraversal edgeSearch = __.start(); - edgeSearch.both(edgeLabels); + edgeSearch.both(edgeLabels).has(AAIProperties.NODE_TYPE, nodeType); if (propName != null) { // check for matching property if (propValue != null) { @@ -437,19 +426,7 @@ public class SearchGraph { } List results = traversal.toList(); - Introspector searchResults = loader.introspectorFromName("search-results"); - List resultDataList = searchResults.getValue("result-data"); - for (Vertex thisNode: results){ - String nodeType = thisNode.property(AAIProperties.NODE_TYPE).orElse(null); - - String thisNodeURL = urlBuilder.pathed(thisNode); - Introspector resultData = loader.introspectorFromName("result-data"); - - resultData.setValue("resource-type", nodeType); - resultData.setValue("resource-link", thisNodeURL); - resultDataList.add(resultData.getUnderlyingObject()); - - } + Introspector searchResults = createSearchResults(loader, urlBuilder, results); String outputMediaType = getMediaType(headers.getAcceptableMediaTypes()); org.openecomp.aai.introspection.MarshallerProperties properties = new org.openecomp.aai.introspection.MarshallerProperties.Builder( @@ -478,6 +455,42 @@ public class SearchGraph { return response; } + protected Introspector createSearchResults(Loader loader, UrlBuilder urlBuilder, List results) + throws AAIUnknownObjectException { + Introspector searchResults = loader.introspectorFromName("search-results"); + List resultDataList = searchResults.getValue("result-data"); + Stream stream; + if (results.size() >= 50) { + stream = results.parallelStream(); + } else { + stream = results.stream(); + } + boolean isParallel = stream.isParallel(); + stream.forEach(v -> { + String nodeType = v.property(AAIProperties.NODE_TYPE).orElse(null); + + String thisNodeURL; + try { + thisNodeURL = urlBuilder.pathed(v); + Introspector resultData = loader.introspectorFromName("result-data"); + + resultData.setValue("resource-type", nodeType); + resultData.setValue("resource-link", thisNodeURL); + if (isParallel) { + synchronized (resultDataList) { + resultDataList.add(resultData.getUnderlyingObject()); + } + } else { + resultDataList.add(resultData.getUnderlyingObject()); + } + } catch (AAIException | AAIFormatVertexException e) { + throw new RuntimeException(e); + } + + }); + return searchResults; + } + private String findDbPropName(Introspector obj, String propName) { Optional result = obj.getPropertyMetadata(propName, PropertyMetadata.DB_ALIAS); @@ -487,7 +500,7 @@ public class SearchGraph { return propName; } } - + /** * Gets the edge label. @@ -552,7 +565,7 @@ public class SearchGraph { unmarshaller.setProperty("eclipselink.media-type", "application/json"); unmarshaller.setProperty("eclipselink.json.include-root", false); } - String dynamicClass = "inventory.aai.ecomp.org." + aaiExtMap.getApiVersion() + ".ModelAndNamedQuerySearch"; + String dynamicClass = "inventory.aai.openecomp.org." + aaiExtMap.getApiVersion() + ".ModelAndNamedQuerySearch"; Class resultClass = jaxbContext.newDynamicEntity(dynamicClass).getClass(); StringReader reader = new StringReader(queryParameters); @@ -637,7 +650,6 @@ public class SearchGraph { return getResponseFromIntrospector(inventoryItems, aaiExtMap.getHttpHeaders()); } - /** * Execute model operation. * @@ -823,7 +835,7 @@ public class SearchGraph { notificationHeader.set("sourceName", aaiExtMap.getFromAppId()); notificationHeader.set("version", notificationVersion); - StoreNotificationEvent sne = new StoreNotificationEvent(); + StoreNotificationEvent sne = new StoreNotificationEvent(transId, fromAppId); sne.storeDynamicEvent(notificationJaxbContext, notificationVersion, notificationHeader, inventoryItems); @@ -976,7 +988,7 @@ public class SearchGraph { Map includeTheseVertices, Map objectToVertMap, AAIExtensionMap aaiExtMap) { - DynamicEntity inventoryItem = jaxbContext.newDynamicEntity("inventory.aai.ecomp.org." + aaiExtMap.getApiVersion() + ".InventoryResponseItem"); + DynamicEntity inventoryItem = jaxbContext.newDynamicEntity("inventory.aai.openecomp.org." + aaiExtMap.getApiVersion() + ".InventoryResponseItem"); Object item = invResultItem.get("item"); inventoryItem.set("modelName", invResultItem.get("modelName")); inventoryItem.set("item", item); @@ -991,7 +1003,7 @@ public class SearchGraph { if (includeTheseVertices.containsKey(vertexId)) { if (invResultItem.isSet("inventoryResponseItems")) { List invItemList = new ArrayList(); - DynamicEntity inventoryItems = jaxbContext.newDynamicEntity("inventory.aai.ecomp.org." + aaiExtMap.getApiVersion() + ".InventoryResponseItems"); + DynamicEntity inventoryItems = jaxbContext.newDynamicEntity("inventory.aai.openecomp.org." + aaiExtMap.getApiVersion() + ".InventoryResponseItems"); DynamicEntity subInventoryResponseItems = invResultItem.get("inventoryResponseItems"); List subInventoryResponseItemList = subInventoryResponseItems.get("inventoryResponseItem"); for (DynamicEntity ent : subInventoryResponseItemList) { diff --git a/aai-traversal/src/main/java/org/openecomp/aai/rest/ueb/NotificationEvent.java b/aai-traversal/src/main/java/org/openecomp/aai/rest/ueb/NotificationEvent.java index 389d296..e473e9d 100644 --- a/aai-traversal/src/main/java/org/openecomp/aai/rest/ueb/NotificationEvent.java +++ b/aai-traversal/src/main/java/org/openecomp/aai/rest/ueb/NotificationEvent.java @@ -31,12 +31,13 @@ import org.openecomp.aai.util.StoreNotificationEvent; */ public class NotificationEvent { - private Loader loader = null; + private final Loader loader; - private Introspector eventHeader = null; - - private Introspector obj = null; + private final Introspector eventHeader; + private final Introspector obj; + private final String transactionId; + private final String sourceOfTruth; /** * Instantiates a new notification event. * @@ -44,10 +45,12 @@ public class NotificationEvent { * @param eventHeader the event header * @param obj the obj */ - public NotificationEvent (Loader loader, Introspector eventHeader, Introspector obj) { + public NotificationEvent (Loader loader, Introspector eventHeader, Introspector obj, String transactionId, String sourceOfTruth) { this.loader = loader; this.eventHeader = eventHeader; this.obj = obj; + this.transactionId = transactionId; + this.sourceOfTruth = sourceOfTruth; } /** @@ -57,7 +60,7 @@ public class NotificationEvent { */ public void trigger() throws AAIException { - StoreNotificationEvent sne = new StoreNotificationEvent(); + StoreNotificationEvent sne = new StoreNotificationEvent(transactionId, sourceOfTruth); sne.storeEvent(loader, eventHeader, obj); diff --git a/aai-traversal/src/main/java/org/openecomp/aai/rest/ueb/UEBNotification.java b/aai-traversal/src/main/java/org/openecomp/aai/rest/ueb/UEBNotification.java index 397082f..8cb16e1 100644 --- a/aai-traversal/src/main/java/org/openecomp/aai/rest/ueb/UEBNotification.java +++ b/aai-traversal/src/main/java/org/openecomp/aai/rest/ueb/UEBNotification.java @@ -50,7 +50,6 @@ public class UEBNotification { private Loader currentVersionLoader = null; protected List events = null; - private String urlBase = null; private Version notificationVersion = null; /** @@ -61,7 +60,6 @@ public class UEBNotification { public UEBNotification(Loader loader) { events = new ArrayList<>(); currentVersionLoader = LoaderFactory.createLoaderForVersion(loader.getModelType(), AAIProperties.LATEST); - urlBase = AAIConfig.get("aai.server.url.base",""); notificationVersion = Version.valueOf(AAIConfig.get("aai.notification.current.version","v10")); } @@ -78,7 +76,7 @@ public class UEBNotification { * @throws IllegalArgumentException the illegal argument exception * @throws UnsupportedEncodingException the unsupported encoding exception */ - public void createNotificationEvent(String transactionId, String sourceOfTruth, Status status, URI uri, Introspector obj, HashMap relatedObjects) throws AAIException, IllegalArgumentException, UnsupportedEncodingException { + public void createNotificationEvent(String transactionId, String sourceOfTruth, Status status, URI uri, Introspector obj, HashMap relatedObjects) throws AAIException, UnsupportedEncodingException { String action = "UPDATE"; @@ -96,9 +94,9 @@ public class UEBNotification { String entityLink = ""; if (uri.toString().startsWith("/")) { - entityLink = urlBase + notificationVersion + uri; + entityLink = "/aai/" + notificationVersion + uri; } else { - entityLink = urlBase + notificationVersion + "/" + uri; + entityLink = "/aai/" + notificationVersion + "/" + uri; } @@ -148,7 +146,7 @@ public class UEBNotification { } } - final NotificationEvent event = new NotificationEvent(currentVersionLoader, eventHeader, eventObject); + final NotificationEvent event = new NotificationEvent(currentVersionLoader, eventHeader, eventObject, transactionId, sourceOfTruth); events.add(event); } catch (AAIUnknownObjectException e) { throw new RuntimeException("Fatal error - notification-event-header object not found!"); diff --git a/aai-traversal/src/main/java/org/openecomp/aai/util/StoreNotificationEvent.java b/aai-traversal/src/main/java/org/openecomp/aai/util/StoreNotificationEvent.java index 996abba..181627b 100644 --- a/aai-traversal/src/main/java/org/openecomp/aai/util/StoreNotificationEvent.java +++ b/aai-traversal/src/main/java/org/openecomp/aai/util/StoreNotificationEvent.java @@ -25,15 +25,10 @@ import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Iterator; -import java.util.List; -import java.util.Map; import java.util.UUID; import javax.xml.bind.Marshaller; -import org.apache.cxf.helpers.CastUtils; -import org.apache.cxf.message.Message; -import org.apache.cxf.phase.PhaseInterceptorChain; import org.eclipse.persistence.dynamic.DynamicEntity; import org.eclipse.persistence.jaxb.dynamic.DynamicJAXBContext; import org.json.JSONException; @@ -51,29 +46,15 @@ public class StoreNotificationEvent { private AAIDmaapEventJMSProducer messageProducer; private String fromAppId = ""; private String transId = ""; - + private final String transactionId; + private final String sourceOfTruth; /** * Instantiates a new store notification event. */ - public StoreNotificationEvent() { + public StoreNotificationEvent(String transactionId, String sourceOfTruth) { this.messageProducer = new AAIDmaapEventJMSProducer(); - Message inMessage = PhaseInterceptorChain.getCurrentMessage().getExchange().getInMessage(); - Map> headersList = CastUtils.cast((Map) inMessage.get(Message.PROTOCOL_HEADERS)); - if (headersList != null) { - List xt = headersList.get("X-TransactionId"); - if (xt != null) { - for (String transIdValue : xt) { - transId = transIdValue; - } - } - List fa = headersList.get("X-FromAppId"); - if (fa != null) { - for (String fromAppIdValue : fa) { - - fromAppId = fromAppIdValue; - } - } - } + this.transactionId = transactionId; + this.sourceOfTruth = sourceOfTruth; } /** @@ -170,7 +151,7 @@ public class StoreNotificationEvent { throw new AAIException("AAI_7350"); } - DynamicEntity notificationEvent = notificationJaxbContext.getDynamicType("inventory.aai.inventory.org." + notificationVersion + ".NotificationEvent").newDynamicEntity(); + DynamicEntity notificationEvent = notificationJaxbContext.getDynamicType("inventory.aai.openecomp.org." + notificationVersion + ".NotificationEvent").newDynamicEntity(); if (eventHeader.get("id") == null) { eventHeader.set("id", genDate2() + "-" + UUID.randomUUID().toString()); -- cgit 1.2.3-korg