diff options
author | Muller, Andrew (am8383) <am8383@us.att.com> | 2017-08-11 15:20:22 -0400 |
---|---|---|
committer | Venkata Harish K Kajur <vk250x@att.com> | 2017-08-08 00:42:29 +0000 |
commit | 475beb0e12a1a36deac965a9197ba9af966b6c8a (patch) | |
tree | 87ee10a71a7fc08bd8a8cb1f22349d8882bc10fa /aai-traversal | |
parent | 072afa5431c667dc979763af76e82de27450350c (diff) |
[AAI-154 Amsterdam] Check in titan refactor
Change-Id: I136eca1c2dbc337f9f6019e52cfe60b15ebfbe7d
Signed-off-by: Muller, Andrew (am8383) <am8383@us.att.com>
Diffstat (limited to 'aai-traversal')
10 files changed, 424 insertions, 41 deletions
diff --git a/aai-traversal/bundleconfig-local/etc/query/stored-queries.properties b/aai-traversal/bundleconfig-local/etc/query/stored-queries.properties index 1fb25a1..46e2148 100644 --- a/aai-traversal/bundleconfig-local/etc/query/stored-queries.properties +++ b/aai-traversal/bundleconfig-local/etc/query/stored-queries.properties @@ -92,10 +92,10 @@ pservers-fromVnf=union(\ __.out('runsOnPserver').store('x'),\ __.out('runsOnVserver').out('runsOnPserver').store('x')\ ).cap('x').unfold().dedup() - + cloudRegion-fromNfType=out('runsOnVserver').in('owns').has('aai-node-type', 'tenant').in('has').has('aai-node-type','cloud-region')\ .store('x').cap('x').unfold().dedup() - + nfType-fromCloudRegion=out('has').has('aai-node-type','tenant').out('owns').has('aai-node-type','vserver').in('runsOnVserver').has('aai-node-type','generic-vnf')\ .store('x').cap('x').unfold().dedup() @@ -117,7 +117,7 @@ vnf-topology-fromServiceInstance=store('x').union(\ )\ )\ ).cap('x').unfold().dedup() - + vnf-topology-fromVnf=store('x').union(\ __.out('hasInstance').has('aai-node-type', 'service-instance').store('x').union(\ __.in('hasInstance').has('aai-node-type', 'service-subscription').in('subscribesTo').has('aai-node-type','customer').store('x'),\ diff --git a/aai-traversal/src/main/java/org/openecomp/aai/dbgraphgen/ModelBasedProcessing.java b/aai-traversal/src/main/java/org/openecomp/aai/dbgraphgen/ModelBasedProcessing.java index d3b44a3..282f5d3 100644 --- a/aai-traversal/src/main/java/org/openecomp/aai/dbgraphgen/ModelBasedProcessing.java +++ b/aai-traversal/src/main/java/org/openecomp/aai/dbgraphgen/ModelBasedProcessing.java @@ -58,7 +58,6 @@ 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 com.thinkaurelius.titan.core.TitanVertex; /** * Utility class that uses Model/Named-Query definitions to navigate the graph. @@ -824,13 +823,13 @@ public class ModelBasedProcessing{ return retHash; } - TitanVertex thisVtx = resSet.getVert(); + Vertex thisVtx = resSet.getVert(); String thisGuyId = ""; String thisNT = ""; String thisGuyStr = ""; try { - if( thisVtx != null && !thisVtx.isRemoved() ){ + if( thisVtx != null){ thisGuyId = thisVtx.id().toString(); thisNT = thisVtx.<String>property(AAIProperties.NODE_TYPE).orElse(null); thisGuyStr = thisGuyId + "[" + thisNT + " found at:" + resSet.getLocationInModelSubGraph() + "]"; @@ -1488,7 +1487,7 @@ public class ModelBasedProcessing{ rs.setExtraPropertyHash(tmpExtraPropHash); } - rs.setVert((TitanVertex)thisLevelElemVtx); + rs.setVert(thisLevelElemVtx); rs.setLocationInModelSubGraph(thisVertsTrail); if( delKeyHash.containsKey(thisVertsTrail) && delKeyHash.get(thisVertsTrail).equals("T") ){ rs.setNewDataDelFlag("T"); diff --git a/aai-traversal/src/main/java/org/openecomp/aai/dbgraphgen/ResultSet.java b/aai-traversal/src/main/java/org/openecomp/aai/dbgraphgen/ResultSet.java index 46c9b5e..c66772d 100644 --- a/aai-traversal/src/main/java/org/openecomp/aai/dbgraphgen/ResultSet.java +++ b/aai-traversal/src/main/java/org/openecomp/aai/dbgraphgen/ResultSet.java @@ -25,11 +25,11 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import org.apache.tinkerpop.gremlin.structure.Vertex; import org.openecomp.aai.dbgen.PropertyLimitDesc; -import com.thinkaurelius.titan.core.TitanVertex; public class ResultSet { - private TitanVertex vert; + private Vertex vert; private String newDataDelFlag; private String doNotOutputFlag; private String locationInModelSubGraph; @@ -62,7 +62,7 @@ public class ResultSet { * * @return the vert */ - public TitanVertex getVert(){ + public Vertex getVert(){ return this.vert; } @@ -130,7 +130,7 @@ public class ResultSet { } - public void setVert(TitanVertex vert) { + public void setVert(Vertex vert) { this.vert = vert; } 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 8821f07..e68ab1a 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 @@ -77,8 +77,6 @@ import org.openecomp.aai.util.StoreNotificationEvent; import com.att.eelf.configuration.EELFLogger; import com.att.eelf.configuration.EELFManager; import com.google.common.base.CaseFormat; -import com.thinkaurelius.titan.core.TitanTransaction; -import com.thinkaurelius.titan.core.TitanVertex; import edu.emory.mathcs.backport.java.util.Collections; @@ -519,7 +517,6 @@ public class SearchGraph { Introspector inventoryItems; boolean success = true; - TitanTransaction g = null; TransactionalGraphEngine dbEngine = null; try { @@ -532,7 +529,7 @@ public class SearchGraph { DBSerializer serializer = new DBSerializer(AAIProperties.LATEST, dbEngine, ModelType.MOXY, fromAppId); ModelBasedProcessing processor = new ModelBasedProcessing(loader, dbEngine, serializer); - g = dbEngine.startTransaction(); + dbEngine.startTransaction(); org.openecomp.aai.restcore.MediaType mediaType = org.openecomp.aai.restcore.MediaType.APPLICATION_JSON_TYPE; String contentType = aaiExtMap.getHttpServletRequest().getContentType(); if (contentType != null && contentType.contains("application/xml")) { @@ -609,11 +606,11 @@ public class SearchGraph { success = false; throw new AAIException("AAI_5105", e); } finally { - if (g != null) { + if (dbEngine != null) { if (success) { - g.commit(); + dbEngine.commit(); } else { - g.rollback(); + dbEngine.rollback(); } } } @@ -641,7 +638,6 @@ public class SearchGraph { AAIExtensionMap aaiExtMap) throws JAXBException, AAIException, DynamicException, UnsupportedEncodingException { Response response; boolean success = true; - TitanTransaction g = null; TransactionalGraphEngine dbEngine = null; try { @@ -653,7 +649,7 @@ public class SearchGraph { loader); DBSerializer serializer = new DBSerializer(AAIProperties.LATEST, dbEngine, ModelType.MOXY, fromAppId); ModelBasedProcessing processor = new ModelBasedProcessing(loader, dbEngine, serializer); - g = dbEngine.startTransaction(); + dbEngine.startTransaction(); org.openecomp.aai.restcore.MediaType mediaType = org.openecomp.aai.restcore.MediaType.APPLICATION_JSON_TYPE; @@ -757,7 +753,7 @@ public class SearchGraph { ResultSet rs = resultSet.get(0); - TitanVertex firstVert = rs.getVert(); + Vertex firstVert = rs.getVert(); String restURI = serializer.getURIForVertex(firstVert).toString(); String notificationVersion = AAIProperties.LATEST.toString(); if (restURI.startsWith("/")) { @@ -816,11 +812,11 @@ public class SearchGraph { success = false; throw new AAIException("AAI_5105", e); } finally { - if (g != null) { + if (dbEngine != null) { if (success) { - g.commit(); + dbEngine.commit(); } else { - g.rollback(); + dbEngine.rollback(); } } } @@ -1007,14 +1003,10 @@ public class SearchGraph { // add this inventoryItem to the resultList for this level resultList.add(inventoryItem.getUnderlyingObject()); - TitanVertex vert = resultSet.getVert(); - - Long vertId = (Long)vert.longId(); + Vertex vert = resultSet.getVert(); String aaiNodeType = vert.<String>property("aai-node-type").orElse(null); - - if (aaiNodeType != null) { Introspector thisObj = loader.introspectorFromName(aaiNodeType); diff --git a/aai-traversal/src/main/java/org/openecomp/aai/extensions/AAIExtensionMap.java b/aai-traversal/src/main/java/org/openecomp/aai/extensions/AAIExtensionMap.java index 167dae4..d61aa6c 100644 --- a/aai-traversal/src/main/java/org/openecomp/aai/extensions/AAIExtensionMap.java +++ b/aai-traversal/src/main/java/org/openecomp/aai/extensions/AAIExtensionMap.java @@ -28,15 +28,14 @@ import javax.servlet.http.HttpServletRequest; import javax.ws.rs.core.HttpHeaders; import javax.ws.rs.core.UriInfo; +import org.apache.tinkerpop.gremlin.structure.Graph; +import org.apache.tinkerpop.gremlin.structure.Vertex; import org.eclipse.persistence.jaxb.dynamic.DynamicJAXBContext; - import org.openecomp.aai.domain.responseMessage.AAIResponseMessages; import org.openecomp.aai.introspection.Loader; import org.openecomp.aai.rest.db.DBRequest; import org.openecomp.aai.rest.db.HttpEntry; import org.openecomp.aai.serialization.engines.TransactionalGraphEngine; -import com.thinkaurelius.titan.core.TitanTransaction; -import com.thinkaurelius.titan.core.TitanVertex; public class AAIExtensionMap { // ======================================================================= @@ -95,13 +94,13 @@ public class AAIExtensionMap { private boolean postExtSkipErrorCallback = true; private String fromAppId; private String transId; - private TitanTransaction graph; + private Graph graph; private Object objectFromResponse; private HashMap<String, Object> lookupHashMap; private HashMap<String, ArrayList<String>> precheckAddedList; private AAIResponseMessages precheckResponseMessages; private HashMap<String, Object> topology; - private HashMap<String, TitanVertex> vertexCache; + private HashMap<String, Vertex> vertexCache; private String baseObject; private String namespace; private String fullResourceName; @@ -435,7 +434,7 @@ public class AAIExtensionMap { * * @return the graph */ - public TitanTransaction getGraph() { + public Graph getGraph() { return graph; } @@ -444,7 +443,7 @@ public class AAIExtensionMap { * * @param graph the new graph */ - public void setGraph(TitanTransaction graph) { + public void setGraph(Graph graph) { this.graph = graph; } @@ -546,9 +545,9 @@ public class AAIExtensionMap { * * @return the vertex cache */ - public HashMap<String, TitanVertex> getVertexCache() { + public HashMap<String, Vertex> getVertexCache() { if (this.vertexCache == null) { - this.vertexCache = new HashMap<String, TitanVertex>(); + this.vertexCache = new HashMap<String, Vertex>(); } return vertexCache; } diff --git a/aai-traversal/src/main/java/org/openecomp/aai/rest/db/HttpEntry.java b/aai-traversal/src/main/java/org/openecomp/aai/rest/db/HttpEntry.java index 60438de..36b82b7 100644 --- a/aai-traversal/src/main/java/org/openecomp/aai/rest/db/HttpEntry.java +++ b/aai-traversal/src/main/java/org/openecomp/aai/rest/db/HttpEntry.java @@ -39,6 +39,7 @@ import javax.ws.rs.core.Response.Status; import javax.ws.rs.core.UriBuilder; import org.apache.commons.lang.StringUtils; +import org.apache.tinkerpop.gremlin.structure.Graph; import org.apache.tinkerpop.gremlin.structure.Vertex; import org.javatuples.Pair; @@ -75,7 +76,6 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.github.fge.jsonpatch.JsonPatchException; import com.github.fge.jsonpatch.mergepatch.JsonMergePatch; import com.thinkaurelius.titan.core.TitanException; -import com.thinkaurelius.titan.core.TitanTransaction; /** * The Class HttpEntry. @@ -499,7 +499,7 @@ public class HttpEntry { * @throws UnsupportedEncodingException the unsupported encoding exception * @throws AAIException the AAI exception */ - private Response invokeExtension(TransactionalGraphEngine dbEngine, TitanTransaction g, HttpMethod httpMethod, DBRequest request, String fromAppId, Version apiVersion, Loader loader, Introspector obj, URI uri, boolean isPreprocess) throws IllegalArgumentException, UnsupportedEncodingException, AAIException { + private Response invokeExtension(TransactionalGraphEngine dbEngine, Graph g, HttpMethod httpMethod, DBRequest request, String fromAppId, Version apiVersion, Loader loader, Introspector obj, URI uri, boolean isPreprocess) throws IllegalArgumentException, UnsupportedEncodingException, AAIException { AAIExtensionMap aaiExtMap = new AAIExtensionMap(); ModelInjestor injestor = ModelInjestor.getInstance(); Response response = null; diff --git a/aai-traversal/src/test/java/org/openecomp/aai/rest/search/VnfInstancesFromServiceInstancebyModelVersionTest.java b/aai-traversal/src/test/java/org/openecomp/aai/rest/search/VnfInstancesFromServiceInstancebyModelVersionTest.java index b462288..bbc20d8 100644 --- a/aai-traversal/src/test/java/org/openecomp/aai/rest/search/VnfInstancesFromServiceInstancebyModelVersionTest.java +++ b/aai-traversal/src/test/java/org/openecomp/aai/rest/search/VnfInstancesFromServiceInstancebyModelVersionTest.java @@ -49,10 +49,12 @@ public class VnfInstancesFromServiceInstancebyModelVersionTest extends QueryTest Vertex servicesubscription = graph.addVertex(T.label, "service-subscription", T.id, "2", "aai-node-type", "service-subscription", "service-subscription-id", "service-subscription-id-1","service-subscription-name","service-subscription-name1"); Vertex customer = graph.addVertex(T.label, "customer", T.id, "3", "aai-node-type", "customer", "customer-id", "customer-id-1", "customer-name", "customer-name1"); - Vertex model1 = graph.addVertex(T.label, "model", T.id, "4", "aai-node-type", "model", "model-invariant-id", "modinvariant-id1", "model-type", "modtype"); + Vertex model1 = graph.addVertex(T.label, "model", T.id, "4", "aai-node-type", "model", "model-invariant-id", "modinvariant-id1", "model-invariant-id-local", "modinvariant-id1", "model-type", "modtype"); Vertex modelver1 = graph.addVertex(T.label, "model-ver", T.id, "5", "aai-node-type", "model-ver", "model-version-id", "modver-id1", "model-name", "modname1", "model-version", "v1.0"); Vertex vnf1 = graph.addVertex(T.label, "generic-vnf", T.id, "6", "aai-node-type", "generic-vnf", "vnf-id", "vnfid1", "vnf-name", "vnfname1", "vnf-type", "vnftype1", "model-invariant-id", "modinvariant-id1","model-invariant-id-local", "modinvariant-id1", "model-version-id", "modver-id1", "model-version-id-local", "modver-id1"); +// Vertex model2 = graph.addVertex(T.label, "model", T.id, "7", "aai-node-type", "model", "model-invariant-id", "modinvariant-id2", "model-type", "modtype"); +// Vertex modelver2 = graph.addVertex(T.label, "model-ver", T.id, "8", "aai-node-type", "model-ver", "model-version-id", "modver-id2", "model-name", "modname2", "model-version", "v1.0"); Vertex vnf2 = graph.addVertex(T.label, "generic-vnf", T.id, "9", "aai-node-type", "generic-vnf", "vnf-id", "vnfid2", "vnf-name", "vnfname2", "vnf-type", "vnftype2", "model-invariant-id", "modinvariant-id1", "model-invariant-id-local", "modinvariant-id1", "model-version-id", "modver-id1", "model-version-id-local", "modver-id1"); diff --git a/aai-traversal/src/test/java/org/openecomp/aai/rest/search/VnfTopologyFromServiceInstanceTest.java b/aai-traversal/src/test/java/org/openecomp/aai/rest/search/VnfTopologyFromServiceInstanceTest.java new file mode 100644 index 0000000..6417173 --- /dev/null +++ b/aai-traversal/src/test/java/org/openecomp/aai/rest/search/VnfTopologyFromServiceInstanceTest.java @@ -0,0 +1,129 @@ +/*-
+ * ============LICENSE_START=======================================================
+ * org.openecomp.aai
+ * ================================================================================
+ * Copyright (C) 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=========================================================
+ */
+
+package org.openecomp.aai.rest.search;
+
+import java.util.Map;
+
+import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal;
+import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
+import org.apache.tinkerpop.gremlin.structure.T;
+import org.apache.tinkerpop.gremlin.structure.Vertex;
+import org.junit.Test;
+
+import org.openecomp.aai.exceptions.AAIException;
+import org.openecomp.aai.serialization.db.exceptions.NoEdgeRuleFoundException;
+
+public class VnfTopologyFromServiceInstanceTest extends QueryTest {
+ public VnfTopologyFromServiceInstanceTest() throws AAIException, NoEdgeRuleFoundException {
+ super();
+ }
+
+ @Test
+ public void run() {
+ super.run();
+ }
+
+ @Override
+ protected void createGraph() throws AAIException, NoEdgeRuleFoundException {
+ //Set up the test graph
+ Vertex gnvf1 = graph.addVertex(T.label, "generic-vnf", T.id, "0", "aai-node-type", "generic-vnf", "vnf-id", "vnf-id-1", "vnf-name", "vnf-name-1");
+ Vertex serviceinstance = graph.addVertex(T.label, "service-instance", T.id, "1", "aai-node-type", "service-instance", "service-instance-id", "service-instance-id-1", "service-instance-name", "service-instance-name-1");
+ Vertex servicesubscription = graph.addVertex(T.label, "service-subscription", T.id, "2", "aai-node-type", "service-subscription", "service-subscription-id", "service-subscription-id-1","service-subscription-name","service-subscription-name1");
+ Vertex customer = graph.addVertex(T.label, "customer", T.id, "3", "aai-node-type", "customer", "customer-id", "customer-id-1", "customer-name", "customer-name1");
+ Vertex allottedresource = graph.addVertex(T.label, "allotted-resource", T.id, "4", "aai-node-type", "allotted-resource", "allotted-resource-id", "allotted-resource-id-1", "allotted-resource-name", "allotted-resource-name1");
+ Vertex vfmodule = graph.addVertex(T.label, "vf-module", T.id, "5", "aai-node-type", "vf-module", "vf-module-id", "vf-module-id-1", "vf-module-name", "vf-module-name1");
+ Vertex volumegroup = graph.addVertex(T.label, "volume-group", T.id, "6", "aai-node-type", "volume-group", "volume-group-id", "volume-group-id-1", "volume-group-name", "volume-group-name1");
+ Vertex linter1 = graph.addVertex(T.label, "l-interface", T.id, "7", "aai-node-type", "l-interface", "l-interface-id", "l-interface-id-1", "l-interface-name", "l-interface-name1");
+ Vertex l3inter1ipv4addresslist = graph.addVertex(T.label, "interface-ipv4-address-list", T.id, "8", "aai-node-type", "l3-interface-ipv4-address-list", "l3-interface-ipv4-address-list-id", "l3-interface-ipv4-address-list-id-1", "l3-interface-ipv6-address-list-name", "l3-interface-ipv6-address-list-name1");
+ Vertex l3network1 = graph.addVertex(T.label, "l3-network", T.id, "9", "aai-node-type", "l3-network", "ll3-network-id", "l3-network-id-1", "l3-network-name", "l3-network-name1");
+ Vertex l3inter1ipv6addresslist = graph.addVertex(T.label, "l3-interface-ipv6-address-list", T.id, "10", "aai-node-type", "l3-interface-ipv6-address-list", "l3-interface-ipv6-address-list-id", "l3-interface-ipv6-address-list-id-1", "l3-interface-ipv6-address-list-name", "l3-interface-ipv6-address-list-name1");
+ Vertex vserver = graph.addVertex(T.label, "vserver", T.id, "11", "aai-node-type", "vserver", "vserver-name1", "vservername1");
+ Vertex tenant = graph.addVertex(T.label, "tenant", T.id, "12", "aai-node-type", "tenant", "tenant-name1", "tenant-name-1","tenant-id", "tenant-id-1");
+ Vertex region1 = graph.addVertex(T.label, "cloud-region", T.id, "13", "aai-node-type", "cloud-region", "cloud-owner", "cloudOwner1");
+ Vertex pserver = graph.addVertex(T.label, "pserver", T.id, "14", "aai-node-type", "pserver", "hostname", "pservername");
+ Vertex linter2 = graph.addVertex(T.label, "l-interface", T.id, "15", "aai-node-type", "l-interface", "l-interface-id", "l-interface-id-2", "l-interface-name", "l-interface-name2");
+ Vertex l3inter2ipv4addresslist = graph.addVertex(T.label, "interface-ipv6-address-list", T.id, "16", "aai-node-type", "l3-interface-ipv6-address-list", "l3-interface-ipv6-address-list-id", "l3-interface-ipv6-address-list-id-2", "l3-interface-ipv6-address-list-name", "l3-interface-ipv6-address-list-name2");
+ Vertex l3network2 = graph.addVertex(T.label, "l3-network", T.id, "17", "aai-node-type", "l3-network", "ll3-network-id", "l3-network-id-2", "l3-network-name", "l3-network-name2");
+ Vertex l3inter2ipv6addresslist = graph.addVertex(T.label, "l3-interface-ipv6-address-list", T.id, "18", "aai-node-type", "l3-interface-ipv6-address-list", "l3-interface-ipv6-address-list-id", "l3-interface-ipv6-address-list-id-2", "l3-interface-ipv6-address-list-name", "l3-interface-ipv6-address-list-name2");
+ Vertex l3network3 = graph.addVertex(T.label, "l3-network", T.id, "19", "aai-node-type", "l3-network", "ll3-network-id", "l3-network-id-3", "l3-network-name", "l3-network-name3");
+ Vertex l3network4 = graph.addVertex(T.label, "l3-network", T.id, "20", "aai-node-type", "l3-network", "ll3-network-id", "l3-network-id-4", "l3-network-name", "l3-network-name4");
+
+
+
+ GraphTraversalSource g = graph.traversal();
+ rules.addEdge(g, gnvf1, serviceinstance);//false
+ rules.addTreeEdge(g, serviceinstance, servicesubscription);//true
+ rules.addTreeEdge(g, servicesubscription, customer);//true
+ rules.addTreeEdge(g, serviceinstance, allottedresource);//true
+ rules.addTreeEdge(g, gnvf1, vfmodule);//true
+ rules.addEdge(g, gnvf1, volumegroup);//false
+ rules.addTreeEdge(g, gnvf1, linter1);//true
+ rules.addTreeEdge(g, linter1, l3inter1ipv4addresslist);//true
+ rules.addEdge(g, l3inter1ipv4addresslist, l3network1);//false
+ rules.addTreeEdge(g, linter1, l3inter1ipv6addresslist);//true
+ rules.addEdge(g, l3inter1ipv6addresslist, l3network2);//false
+ rules.addEdge(g, gnvf1, vserver);//false
+ rules.addTreeEdge(g, vserver, tenant);//true
+ rules.addTreeEdge(g, tenant, region1);//true
+ rules.addEdge(g, vserver, pserver);//false
+ rules.addTreeEdge(g, vserver, linter2);//false
+ rules.addTreeEdge(g, linter2, l3inter2ipv4addresslist);//false
+ rules.addEdge(g, l3inter2ipv4addresslist, l3network3);//false
+ rules.addTreeEdge(g, linter2, l3inter2ipv6addresslist);//true
+ rules.addEdge(g, l3inter2ipv6addresslist, l3network4);//true
+
+
+ expectedResult.add(gnvf1);
+ expectedResult.add(serviceinstance);
+ expectedResult.add(customer);
+ expectedResult.add(allottedresource);
+ expectedResult.add(vfmodule);
+ expectedResult.add(volumegroup);
+ expectedResult.add(l3inter1ipv4addresslist);
+ expectedResult.add(l3network1);
+ expectedResult.add(l3inter1ipv6addresslist);
+ expectedResult.add(l3network2);
+ expectedResult.add(vserver);
+ expectedResult.add(tenant);
+ expectedResult.add(region1);
+ expectedResult.add(pserver);
+ expectedResult.add(vserver);
+ expectedResult.add(l3inter2ipv4addresslist);
+ expectedResult.add(l3network3);
+ expectedResult.add(l3inter2ipv6addresslist);
+ expectedResult.add(l3network4);
+
+ }
+
+ @Override
+ protected String getQueryName() {
+ return "vnf-topology-fromServiceInstance";
+ }
+ @Override
+ protected void addStartNode(GraphTraversal<Vertex, Vertex> g) {
+ g.has("service-instance-name", "service-instance-name-1");
+
+ }
+ @Override
+ protected void addParam(Map<String, Object> params) {
+ return;
+ }
+}
diff --git a/aai-traversal/src/test/java/org/openecomp/aai/rest/search/VnfTopologyFromVfModuleTest.java b/aai-traversal/src/test/java/org/openecomp/aai/rest/search/VnfTopologyFromVfModuleTest.java new file mode 100644 index 0000000..43ad843 --- /dev/null +++ b/aai-traversal/src/test/java/org/openecomp/aai/rest/search/VnfTopologyFromVfModuleTest.java @@ -0,0 +1,133 @@ +/*- + * ============LICENSE_START======================================================= + * org.openecomp.aai + * ================================================================================ + * Copyright (C) 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========================================================= + */ + +package org.openecomp.aai.rest.search; + +import java.util.Map; + +import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal; +import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; +import org.apache.tinkerpop.gremlin.structure.T; +import org.apache.tinkerpop.gremlin.structure.Vertex; +import org.junit.Test; + +import org.openecomp.aai.exceptions.AAIException; +import org.openecomp.aai.serialization.db.exceptions.NoEdgeRuleFoundException; + +public class VnfTopologyFromVfModuleTest extends QueryTest { + public VnfTopologyFromVfModuleTest() throws AAIException, NoEdgeRuleFoundException { + super(); + } + + @Test + public void run() { + super.run(); + } + + @Override + protected void createGraph() throws AAIException, NoEdgeRuleFoundException { + //Set up the test graph + + + Vertex gnvf1 = graph.addVertex(T.label, "generic-vnf", T.id, "0", "aai-node-type", "generic-vnf", "vnf-id", "vnf-id-1", "vnf-name", "vnf-name-1"); + Vertex serviceinstance = graph.addVertex(T.label, "service-instance", T.id, "1", "aai-node-type", "service-instance", "service-instance-id", "service-instance-id-1", "service-instance-name", "service-instance-name-1"); + Vertex servicesubscription = graph.addVertex(T.label, "service-subscription", T.id, "2", "aai-node-type", "service-subscription", "service-subscription-id", "service-subscription-id-1","service-subscription-name","service-subscription-name1"); + Vertex customer = graph.addVertex(T.label, "customer", T.id, "3", "aai-node-type", "customer", "customer-id", "customer-id-1", "customer-name", "customer-name1"); + Vertex allottedresource = graph.addVertex(T.label, "allotted-resource", T.id, "4", "aai-node-type", "allotted-resource", "allotted-resource-id", "allotted-resource-id-1", "allotted-resource-name", "allotted-resource-name1"); + Vertex vfmodule = graph.addVertex(T.label, "vf-module", T.id, "5", "aai-node-type", "vf-module", "vf-module-id", "vf-module-id-1", "vf-module-name", "vf-module-name1"); + Vertex volumegroup = graph.addVertex(T.label, "volume-group", T.id, "6", "aai-node-type", "volume-group", "volume-group-id", "volume-group-id-1", "volume-group-name", "volume-group-name1"); + Vertex linter1 = graph.addVertex(T.label, "l-interface", T.id, "7", "aai-node-type", "l-interface", "l-interface-id", "l-interface-id-1", "l-interface-name", "l-interface-name1"); + Vertex l3inter1ipv4addresslist = graph.addVertex(T.label, "interface-ipv4-address-list", T.id, "8", "aai-node-type", "l3-interface-ipv4-address-list", "l3-interface-ipv4-address-list-id", "l3-interface-ipv4-address-list-id-1", "l3-interface-ipv6-address-list-name", "l3-interface-ipv6-address-list-name1"); + Vertex l3network1 = graph.addVertex(T.label, "l3-network", T.id, "9", "aai-node-type", "l3-network", "ll3-network-id", "l3-network-id-1", "l3-network-name", "l3-network-name1"); + Vertex l3inter1ipv6addresslist = graph.addVertex(T.label, "l3-interface-ipv6-address-list", T.id, "10", "aai-node-type", "l3-interface-ipv6-address-list", "l3-interface-ipv6-address-list-id", "l3-interface-ipv6-address-list-id-1", "l3-interface-ipv6-address-list-name", "l3-interface-ipv6-address-list-name1"); + Vertex vserver = graph.addVertex(T.label, "vserver", T.id, "11", "aai-node-type", "vserver", "vserver-name1", "vservername1"); + Vertex tenant = graph.addVertex(T.label, "tenant", T.id, "12", "aai-node-type", "tenant", "tenant-name1", "tenant-name-1","tenant-id", "tenant-id-1"); + Vertex region1 = graph.addVertex(T.label, "cloud-region", T.id, "13", "aai-node-type", "cloud-region", "cloud-owner", "cloudOwner1"); + Vertex pserver = graph.addVertex(T.label, "pserver", T.id, "14", "aai-node-type", "pserver", "hostname", "pservername"); + Vertex linter2 = graph.addVertex(T.label, "l-interface", T.id, "15", "aai-node-type", "l-interface", "l-interface-id", "l-interface-id-2", "l-interface-name", "l-interface-name2"); + Vertex l3inter2ipv4addresslist = graph.addVertex(T.label, "interface-ipv6-address-list", T.id, "16", "aai-node-type", "l3-interface-ipv6-address-list", "l3-interface-ipv6-address-list-id", "l3-interface-ipv6-address-list-id-2", "l3-interface-ipv6-address-list-name", "l3-interface-ipv6-address-list-name2"); + Vertex l3network2 = graph.addVertex(T.label, "l3-network", T.id, "17", "aai-node-type", "l3-network", "ll3-network-id", "l3-network-id-2", "l3-network-name", "l3-network-name2"); + Vertex l3inter2ipv6addresslist = graph.addVertex(T.label, "l3-interface-ipv6-address-list", T.id, "18", "aai-node-type", "l3-interface-ipv6-address-list", "l3-interface-ipv6-address-list-id", "l3-interface-ipv6-address-list-id-2", "l3-interface-ipv6-address-list-name", "l3-interface-ipv6-address-list-name2"); + Vertex l3network3 = graph.addVertex(T.label, "l3-network", T.id, "19", "aai-node-type", "l3-network", "ll3-network-id", "l3-network-id-3", "l3-network-name", "l3-network-name3"); + Vertex l3network4 = graph.addVertex(T.label, "l3-network", T.id, "20", "aai-node-type", "l3-network", "ll3-network-id", "l3-network-id-4", "l3-network-name", "l3-network-name4"); + Vertex vfmoduleStart = graph.addVertex(T.label, "vf-module", T.id, "21", "aai-node-type", "vf-module", "vf-module-id", "vf-module-id-2", "vf-module-name", "vf-module-name2"); + + + + GraphTraversalSource g = graph.traversal(); + rules.addTreeEdge(g, gnvf1, vfmoduleStart);//true + rules.addEdge(g, gnvf1, serviceinstance);//false + rules.addTreeEdge(g, serviceinstance, servicesubscription);//true + rules.addTreeEdge(g, servicesubscription, customer);//true + rules.addTreeEdge(g, serviceinstance, allottedresource);//true + rules.addTreeEdge(g, gnvf1, vfmodule);//true + rules.addEdge(g, gnvf1, volumegroup);//false + rules.addTreeEdge(g, gnvf1, linter1);//true + rules.addTreeEdge(g, linter1, l3inter1ipv4addresslist);//true + rules.addEdge(g, l3inter1ipv4addresslist, l3network1);//false + rules.addTreeEdge(g, linter1, l3inter1ipv6addresslist);//true + rules.addEdge(g, l3inter1ipv6addresslist, l3network2);//false + rules.addEdge(g, gnvf1, vserver);//false + rules.addTreeEdge(g, vserver, tenant);//true + rules.addTreeEdge(g, tenant, region1);//true + rules.addEdge(g, vserver, pserver);//false + rules.addTreeEdge(g, vserver, linter2);//false + rules.addTreeEdge(g, linter2, l3inter2ipv4addresslist);//false + rules.addEdge(g, l3inter2ipv4addresslist, l3network3);//false + rules.addTreeEdge(g, linter2, l3inter2ipv6addresslist);//true + rules.addEdge(g, l3inter2ipv6addresslist, l3network4);//true + + + expectedResult.add(gnvf1); + expectedResult.add(serviceinstance); + expectedResult.add(customer); + expectedResult.add(allottedresource); + expectedResult.add(vfmodule); + expectedResult.add(vfmoduleStart); + expectedResult.add(volumegroup); + expectedResult.add(l3inter1ipv4addresslist); + expectedResult.add(l3network1); + expectedResult.add(l3inter1ipv6addresslist); + expectedResult.add(l3network2); + expectedResult.add(vserver); + expectedResult.add(tenant); + expectedResult.add(region1); + expectedResult.add(pserver); + expectedResult.add(l3inter2ipv4addresslist); + expectedResult.add(l3network3); + expectedResult.add(l3inter2ipv6addresslist); + expectedResult.add(l3network4); + + } + + @Override + protected String getQueryName() { + return "vnf-topology-fromVfModule"; + } + @Override + protected void addStartNode(GraphTraversal<Vertex, Vertex> g) { + g.has("vf-module-name", "vf-module-name2"); + + } + @Override + protected void addParam(Map<String, Object> params) { + return; + } +} diff --git a/aai-traversal/src/test/java/org/openecomp/aai/rest/search/VnfTopologyFromVnfTest.java b/aai-traversal/src/test/java/org/openecomp/aai/rest/search/VnfTopologyFromVnfTest.java new file mode 100644 index 0000000..c678be5 --- /dev/null +++ b/aai-traversal/src/test/java/org/openecomp/aai/rest/search/VnfTopologyFromVnfTest.java @@ -0,0 +1,129 @@ +/*- + * ============LICENSE_START======================================================= + * org.openecomp.aai + * ================================================================================ + * Copyright (C) 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========================================================= + */ + +package org.openecomp.aai.rest.search; + +import java.util.Map; + +import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal; +import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; +import org.apache.tinkerpop.gremlin.structure.T; +import org.apache.tinkerpop.gremlin.structure.Vertex; +import org.junit.Test; + +import org.openecomp.aai.exceptions.AAIException; +import org.openecomp.aai.serialization.db.exceptions.NoEdgeRuleFoundException; + +public class VnfTopologyFromVnfTest extends QueryTest { + public VnfTopologyFromVnfTest() throws AAIException, NoEdgeRuleFoundException { + super(); + } + + @Test + public void run() { + super.run(); + } + + @Override + protected void createGraph() throws AAIException, NoEdgeRuleFoundException { + //Set up the test graph + Vertex gnvf1 = graph.addVertex(T.label, "generic-vnf", T.id, "0", "aai-node-type", "generic-vnf", "vnf-id", "vnf-id-1", "vnf-name", "vnf-name-1"); + Vertex serviceinstance = graph.addVertex(T.label, "service-instance", T.id, "1", "aai-node-type", "service-instance", "service-instance-id", "service-instance-id-1", "service-instance-name", "service-instance-name-1"); + Vertex servicesubscription = graph.addVertex(T.label, "service-subscription", T.id, "2", "aai-node-type", "service-subscription", "service-subscription-id", "service-subscription-id-1","service-subscription-name","service-subscription-name1"); + Vertex customer = graph.addVertex(T.label, "customer", T.id, "3", "aai-node-type", "customer", "customer-id", "customer-id-1", "customer-name", "customer-name1"); + Vertex allottedresource = graph.addVertex(T.label, "allotted-resource", T.id, "4", "aai-node-type", "allotted-resource", "allotted-resource-id", "allotted-resource-id-1", "allotted-resource-name", "allotted-resource-name1"); + Vertex vfmodule = graph.addVertex(T.label, "vf-module", T.id, "5", "aai-node-type", "vf-module", "vf-module-id", "vf-module-id-1", "vf-module-name", "vf-module-name1"); + Vertex volumegroup = graph.addVertex(T.label, "volume-group", T.id, "6", "aai-node-type", "volume-group", "volume-group-id", "volume-group-id-1", "volume-group-name", "volume-group-name1"); + Vertex linter1 = graph.addVertex(T.label, "l-interface", T.id, "7", "aai-node-type", "l-interface", "l-interface-id", "l-interface-id-1", "l-interface-name", "l-interface-name1"); + Vertex l3inter1ipv4addresslist = graph.addVertex(T.label, "interface-ipv4-address-list", T.id, "8", "aai-node-type", "l3-interface-ipv4-address-list", "l3-interface-ipv4-address-list-id", "l3-interface-ipv4-address-list-id-1", "l3-interface-ipv6-address-list-name", "l3-interface-ipv6-address-list-name1"); + Vertex l3network1 = graph.addVertex(T.label, "l3-network", T.id, "9", "aai-node-type", "l3-network", "ll3-network-id", "l3-network-id-1", "l3-network-name", "l3-network-name1"); + Vertex l3inter1ipv6addresslist = graph.addVertex(T.label, "l3-interface-ipv6-address-list", T.id, "10", "aai-node-type", "l3-interface-ipv6-address-list", "l3-interface-ipv6-address-list-id", "l3-interface-ipv6-address-list-id-1", "l3-interface-ipv6-address-list-name", "l3-interface-ipv6-address-list-name1"); + Vertex vserver = graph.addVertex(T.label, "vserver", T.id, "11", "aai-node-type", "vserver", "vserver-name1", "vservername1"); + Vertex tenant = graph.addVertex(T.label, "tenant", T.id, "12", "aai-node-type", "tenant", "tenant-name1", "tenant-name-1","tenant-id", "tenant-id-1"); + Vertex region1 = graph.addVertex(T.label, "cloud-region", T.id, "13", "aai-node-type", "cloud-region", "cloud-owner", "cloudOwner1"); + Vertex pserver = graph.addVertex(T.label, "pserver", T.id, "14", "aai-node-type", "pserver", "hostname", "pservername"); + Vertex linter2 = graph.addVertex(T.label, "l-interface", T.id, "15", "aai-node-type", "l-interface", "l-interface-id", "l-interface-id-2", "l-interface-name", "l-interface-name2"); + Vertex l3inter2ipv4addresslist = graph.addVertex(T.label, "interface-ipv6-address-list", T.id, "16", "aai-node-type", "l3-interface-ipv6-address-list", "l3-interface-ipv6-address-list-id", "l3-interface-ipv6-address-list-id-2", "l3-interface-ipv6-address-list-name", "l3-interface-ipv6-address-list-name2"); + Vertex l3network2 = graph.addVertex(T.label, "l3-network", T.id, "17", "aai-node-type", "l3-network", "ll3-network-id", "l3-network-id-2", "l3-network-name", "l3-network-name2"); + Vertex l3inter2ipv6addresslist = graph.addVertex(T.label, "l3-interface-ipv6-address-list", T.id, "18", "aai-node-type", "l3-interface-ipv6-address-list", "l3-interface-ipv6-address-list-id", "l3-interface-ipv6-address-list-id-2", "l3-interface-ipv6-address-list-name", "l3-interface-ipv6-address-list-name2"); + Vertex l3network3 = graph.addVertex(T.label, "l3-network", T.id, "19", "aai-node-type", "l3-network", "ll3-network-id", "l3-network-id-3", "l3-network-name", "l3-network-name3"); + Vertex l3network4 = graph.addVertex(T.label, "l3-network", T.id, "20", "aai-node-type", "l3-network", "ll3-network-id", "l3-network-id-4", "l3-network-name", "l3-network-name4"); + + + + GraphTraversalSource g = graph.traversal(); + rules.addEdge(g, gnvf1, serviceinstance);//false + rules.addTreeEdge(g, serviceinstance, servicesubscription);//true + rules.addTreeEdge(g, servicesubscription, customer);//true + rules.addTreeEdge(g, serviceinstance, allottedresource);//true + rules.addTreeEdge(g, gnvf1, vfmodule);//true + rules.addEdge(g, gnvf1, volumegroup);//false + rules.addTreeEdge(g, gnvf1, linter1);//true + rules.addTreeEdge(g, linter1, l3inter1ipv4addresslist);//true + rules.addEdge(g, l3inter1ipv4addresslist, l3network1);//false + rules.addTreeEdge(g, linter1, l3inter1ipv6addresslist);//true + rules.addEdge(g, l3inter1ipv6addresslist, l3network2);//false + rules.addEdge(g, gnvf1, vserver);//false + rules.addTreeEdge(g, vserver, tenant);//true + rules.addTreeEdge(g, tenant, region1);//true + rules.addEdge(g, vserver, pserver);//false + rules.addTreeEdge(g, vserver, linter2);//false + rules.addTreeEdge(g, linter2, l3inter2ipv4addresslist);//false + rules.addEdge(g, l3inter2ipv4addresslist, l3network3);//false + rules.addTreeEdge(g, linter2, l3inter2ipv6addresslist);//true + rules.addEdge(g, l3inter2ipv6addresslist, l3network4);//true + + + expectedResult.add(gnvf1); + expectedResult.add(serviceinstance); + expectedResult.add(customer); + expectedResult.add(allottedresource); + expectedResult.add(vfmodule); + expectedResult.add(volumegroup); + expectedResult.add(l3inter1ipv4addresslist); + expectedResult.add(l3network1); + expectedResult.add(l3inter1ipv6addresslist); + expectedResult.add(l3network2); + expectedResult.add(vserver); + expectedResult.add(tenant); + expectedResult.add(region1); + expectedResult.add(pserver); + expectedResult.add(vserver); + expectedResult.add(l3inter2ipv4addresslist); + expectedResult.add(l3network3); + expectedResult.add(l3inter2ipv6addresslist); + expectedResult.add(l3network4); + + } + + @Override + protected String getQueryName() { + return "vnf-topology-fromVnf"; + } + @Override + protected void addStartNode(GraphTraversal<Vertex, Vertex> g) { + g.has("vnf-name", "vnf-name-1"); + + } + @Override + protected void addParam(Map<String, Object> params) { + return; + } +} |