2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
22 package org.onap.ccsdk.sli.adaptors.aai;
24 import static org.junit.Assert.assertTrue;
25 import static org.junit.Assert.fail;
28 import java.io.IOException;
29 import java.lang.annotation.Annotation;
30 import java.lang.reflect.Field;
31 import java.lang.reflect.Method;
32 import java.lang.reflect.Modifier;
34 import java.util.ArrayList;
35 import java.util.Arrays;
36 import java.util.HashMap;
37 import java.util.List;
39 import java.util.Scanner;
41 import java.util.Stack;
42 import java.util.UUID;
44 import javax.xml.bind.SchemaOutputResolver;
45 import javax.xml.bind.annotation.XmlElement;
46 import javax.xml.parsers.DocumentBuilder;
47 import javax.xml.parsers.DocumentBuilderFactory;
48 import javax.xml.transform.Result;
49 import javax.xml.transform.stream.StreamResult;
50 import javax.xml.xpath.XPath;
51 import javax.xml.xpath.XPathConstants;
52 import javax.xml.xpath.XPathExpression;
53 import javax.xml.xpath.XPathFactory;
55 import org.apache.commons.lang.RandomStringUtils;
56 import org.apache.commons.lang.StringUtils;
57 import org.junit.AfterClass;
58 import org.junit.BeforeClass;
59 import org.junit.FixMethodOrder;
60 import org.junit.Test;
61 import org.junit.runners.MethodSorters;
62 import org.onap.ccsdk.sli.adaptors.aai.data.AAIDatum;
63 import org.onap.ccsdk.sli.adaptors.aai.query.NamedQueryData;
64 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
65 import org.onap.ccsdk.sli.core.sli.SvcLogicResource.QueryStatus;
66 import org.openecomp.aai.inventory.v11.GenericVnf;
67 import org.slf4j.Logger;
68 import org.slf4j.LoggerFactory;
69 import org.springframework.core.annotation.AnnotationUtils;
70 import org.w3c.dom.Document;
71 import org.w3c.dom.Element;
72 import org.w3c.dom.Node;
73 import org.w3c.dom.NodeList;
75 import com.fasterxml.jackson.annotation.JsonProperty;
76 import com.fasterxml.jackson.databind.ObjectMapper;
79 @FixMethodOrder(MethodSorters.NAME_ASCENDING)
80 public class AutoGeneratedRegressionTest {
83 System.setProperty(org.slf4j.impl.SimpleLogger.DEFAULT_LOG_LEVEL_KEY, "INFO");
84 System.setProperty(org.slf4j.impl.SimpleLogger.LOG_FILE_KEY, String.format("AutoGeneratedRegressionTest-%d.txt", System.currentTimeMillis()));
86 private static final Logger LOG = LoggerFactory.getLogger(AutoGeneratedRegressionTest.class);
89 protected static AAIClient client;
91 protected Map<String, String> cache = new HashMap<String, String>();
94 public static void setUp() throws Exception {
95 URL url = AAIService.class.getResource(AAIService.AAICLIENT_PROPERTIES);
96 client = new AAIService(url);
97 LOG.info("----------------------- aicAAIResourceTest.setUp -----------------------");
101 public static void tearDown() throws Exception {
103 LOG.info("----------------------- AAIResourceTest.tearDown -----------------------");
108 public void mainLoadTest ()
112 String currentDir = System.getProperty("user.dir");
113 File dir = new File(currentDir);
117 dir = new File(dir, "src/main/resources");
121 // parse the document
122 File file = new File(dir, "aai_schema_v11.xsd");
128 DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
129 DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
130 Document doc = dBuilder.parse(file);
132 Stack<String> stack = new Stack<String>();
133 List<String> commands = new ArrayList<String>();
134 listSubNodes("network", doc, stack, commands);
135 listSubNodes("cloud-infrastructure", doc, stack, commands);
136 listSubNodes("service-design-and-creation", doc, stack, commands);
137 listSubNodes("license-management", doc, stack, commands);
138 listSubNodes("business", doc, stack, commands);
140 String[] requestDefinition = commands.toArray(new String[0]);
141 LOG.info("\n----------------------------");
143 executeTests(requestDefinition);
152 public void testFromFile() {
153 String filename = "testCommands.txt";
154 List<String> lines = new ArrayList<String>();
155 Scanner scanner = null;
158 File testFile = new File(filename);
159 if(!testFile.exists())
161 scanner = new Scanner(testFile);
162 while (scanner.hasNextLine()) {
163 lines.add(scanner.nextLine());
165 } catch (Exception exc) {
172 String[] requestDefinition = lines.toArray(new String[0]);
173 executeTests(requestDefinition);
178 public void test01AutoGeneratedRequest() {
180 String[] requestDefinition = {
181 "save|generic-vnf|generic-vnf.vnf-id:assign:value:adb28ac0-a260-4b7d-9ce5-adf15733c458",
182 "update|generic-vnf|generic-vnf.vnf-id:assign:value:adb28ac0-a260-4b7d-9ce5-adf15733c458",
183 "query|generic-vnf|generic-vnf.vnf-id:assign:value:adb28ac0-a260-4b7d-9ce5-adf15733c458",
184 "delete|generic-vnf|generic-vnf.vnf-id:assign:value:adb28ac0-a260-4b7d-9ce5-adf15733c458"
187 executeTests(requestDefinition);
190 public void executeTests(String[] requestDefinition) {
192 for(String line : requestDefinition){
193 LOG.info("Executing: " + line);
195 // parse request line resource | key structure
196 String[] segments = line.split("\\|");
197 String action = segments[0];
198 String resource = segments[1];
199 String[] tmpKeys = segments[2].split("&");
200 // String array keyStructure can be tmpKey.
201 // options :assign:uuid:cache
206 String localId = null;
208 List<String> keys = new ArrayList<String>();
209 String keyLine = null;
211 for(String instruction : tmpKeys) {
212 String[] parts = instruction.split(":");
213 String identifier = parts[0];
214 String method = parts[2];
216 if(identifier.startsWith(resource)) {
217 localId = identifier;
218 } else if(identifier.startsWith("l-interface") && "l2-bridge-bgf".equals(resource)) {
219 localId = identifier;
220 } else if(identifier.startsWith("l-interface") && "l2-bridge-sbg".equals(resource)) {
221 localId = identifier;
222 } else if("nodes-query".equals(resource)) {
223 localId = identifier;
228 String postProcesss = parts[3];
229 keyLine = processAssign(identifier, method, postProcesss);
230 if(keyLine != null && !keyLine.trim().isEmpty()) {
235 keyLine = processCached(identifier, method);
236 if(keyLine != null && !keyLine.trim().isEmpty()) {
244 List<String> x = Arrays.asList(localId.split("\\."));
247 testAutoGeneratedSaveRequest(resource, keys, x.get(x.size() - 1), cache.get(localId));
250 testAutoGeneratedUpdateRequest(resource, keys, x.get(x.size() - 1), cache.get(localId));
254 test03AutoGeneratedQueryRequest(resource, keys);
257 test03AutoGeneratedDeleteRequest(resource, keys);
266 public void testAutoGeneratedSaveRequest(String resource, List<String> requestKeys, String identifier, String idValue) {
267 LOG.info("----------------------- Test: " + new Object(){}.getClass().getEnclosingMethod().getName() + " -----------------------");
271 Map<String, String> nameValues = keyToHashMap(StringUtils.join(requestKeys, " AND "), new SvcLogicContext());
272 AAIRequest request = AAIRequest.createRequest(resource, nameValues);
273 Class<AAIDatum> resourceClass = (Class<AAIDatum>) (request==null ? GenericVnf.class : request.getModelClass());
275 Map<String, String> data = new HashMap<String, String>();
277 for(Field field : resourceClass.getDeclaredFields()) {
278 String type = field.getType().getName();
282 type = Boolean.class.getName();
285 type = Integer.class.getName();
288 type = Long.class.getName();
292 if(type.startsWith("java.lang.")){
293 Annotation[] fieldAnnotations = field.getAnnotations();
294 for(int i = 0; i < fieldAnnotations.length; i++) {
295 Annotation a = fieldAnnotations[i];
296 if(a instanceof JsonProperty){
297 JsonProperty pa = (JsonProperty)a;
298 String name = pa.value();
301 case "java.lang.Integer":
302 case "java.lang.Long":
303 value = RandomStringUtils.random(6, false, true);
305 case "java.lang.Boolean":
309 if(name.equals(identifier)) {
312 value = RandomStringUtils.random(10, true, false);
315 data.put(name, value);
317 if(a instanceof javax.xml.bind.annotation.XmlElement) {
318 XmlElement xe = (XmlElement)a;
319 String name = xe.name();
320 if("model-version-id".equals(name)) {
323 if("model-invariant-id".equals(name)) {
326 if("link-type".equals(name)){
327 data.put(name, "roadmTail");
330 if("operational-status".equals(name)){
331 data.put(name, "available");
334 if(name.equals(identifier)) {
335 data.put(name, idValue);
341 case "java.lang.Integer":
342 case "java.lang.Long":
343 value = RandomStringUtils.random(6, false, true);
345 case "java.lang.Boolean":
349 if(name.equals(identifier)) {
352 value = RandomStringUtils.random(10, true, false);
355 data.put(name, value);
361 SvcLogicContext ctx = new SvcLogicContext();
363 data.remove("resource-version");
365 QueryStatus resp = null;
367 //(String resource, boolean force, boolean localOnly, String key, Map<String, String> parms, String prefix, SvcLogicContext ctx)
368 resp = client.save(resource, false, false, StringUtils.join(requestKeys, " AND "), data, "aaidata", ctx);
369 if(resp == QueryStatus.SUCCESS) {
370 LOG.info(String.format("Save %s successfull", resource));
372 LOG.info(String.format("Save %s failed due to : %s", resource, ctx.getAttribute("aaidata.error.message")));
377 LOG.error("Caught exception", e);
378 fail("Caught exception");
382 public void test03AutoGeneratedQueryRequest(String resource, List<String> requestKeys) {
383 LOG.info("----------------------- Test: " + new Object(){}.getClass().getEnclosingMethod().getName() + " -----------------------");
385 SvcLogicContext ctx = new SvcLogicContext();
389 QueryStatus response = null;
391 response = client.query(resource, false, null, StringUtils.join(requestKeys, " AND "), "aaiTest", null, ctx);
392 if(response == QueryStatus.SUCCESS) {
393 LOG.info(String.format("Query %s successfull", resource));
394 Set<String> tokens = ctx.getAttributeKeySet();
395 Map<String, String> reponseData = new HashMap<String, String>();
397 String responsePrefix = String.format("%s", "aaiTest");
399 for(String token : tokens) {
400 if(token.startsWith(responsePrefix)){
401 reponseData.put(token, ctx.getAttribute(token));
403 LOG.info(String.format("%s = ", token, ctx.getAttribute(token)));
407 LOG.info("AAIResponse: " + response.toString());
408 assertTrue("AAIRequest:"+resource, reponseData.size() > 0);
410 LOG.info(String.format("Query %s failed due to : %s", resource, ctx.getAttribute("aaidata.error.message")));
416 LOG.error("Caught exception", e);
421 public void test03AutoGeneratedDeleteRequest(String resource, List<String> requestKeys) {
422 LOG.info("----------------------- Test: " + new Object(){}.getClass().getEnclosingMethod().getName() + " -----------------------");
426 SvcLogicContext ctx = new SvcLogicContext();
428 QueryStatus response = null;
430 response = client.delete(resource, StringUtils.join(requestKeys, " AND "), ctx);
431 if(response == QueryStatus.SUCCESS) {
432 LOG.info(String.format("Delete %s successfull", resource));
434 LOG.info(String.format("Delete %s failed due to : %s", resource, ctx.getAttribute("aaiDelete.error.message")));
439 LOG.error("Caught exception", e);
440 fail("Caught exception");
444 public void testAutoGeneratedUpdateRequest(String resource, List<String> requestKeys, String identifier, String idValue) {
445 LOG.info("----------------------- Test: " + new Object(){}.getClass().getEnclosingMethod().getName() + " -----------------------");
449 Map<String, String> nameValues = keyToHashMap(StringUtils.join(requestKeys, " AND "), new SvcLogicContext());
450 AAIRequest request = AAIRequest.createRequest(resource, nameValues);
451 Class<AAIDatum> resourceClass = (Class<AAIDatum>) (request==null ? GenericVnf.class : request.getModelClass());
453 Map<String, String> data = new HashMap<String, String>();
455 boolean skipFirst = true;
456 boolean breakLoop = false;
457 for(Field field : resourceClass.getDeclaredFields()) {
465 String type = field.getType().getName();
466 if(type.startsWith("java.lang.")){
467 Annotation[] fieldAnnotations = field.getAnnotations();
468 for(int i = 0; i < fieldAnnotations.length; i++) {
469 Annotation a = fieldAnnotations[i];
470 if(a instanceof JsonProperty){
471 JsonProperty pa = (JsonProperty)a;
472 String name = pa.value();
475 case "java.lang.Integer":
476 case "java.lang.Long":
477 value = RandomStringUtils.random(6, false, true);
479 case "java.lang.Boolean":
483 if(name.equals(identifier)) {
486 value = RandomStringUtils.random(10, true, false);
489 data.put(name, value);
492 if(a instanceof javax.xml.bind.annotation.XmlElement) {
493 XmlElement xe = (XmlElement)a;
494 String name = xe.name();
495 if("link-type".equals(name)){
496 data.put(name, "roadmTail");
499 if("operational-status".equals(name)){
500 data.put(name, "available");
505 case "java.lang.Integer":
506 case "java.lang.Long":
507 value = RandomStringUtils.random(6, false, true);
509 case "java.lang.Boolean":
513 if(name.equals(identifier)) {
516 value = RandomStringUtils.random(10, true, false);
519 data.put(name, value);
526 SvcLogicContext ctx = new SvcLogicContext();
528 data.remove("resource-version");
530 QueryStatus resp = null;
532 //client.update("ipsec-configuration", "ipsec-configuration.ipsec-configuration-id = 'testConfigurationId01'", data, "aaiTest", ctx);
533 resp = client.update(resource, StringUtils.join(requestKeys, " AND "), data, "aaidata", ctx);
534 if(resp == QueryStatus.SUCCESS) {
535 LOG.info(String.format("Update %s successfull", resource));
537 LOG.info(String.format("Update %s failed due to : %s", resource, ctx.getAttribute("aaidata.error.message")));
543 LOG.error("Caught exception", e);
544 fail("Caught exception");
548 static ArrayList<Method> findSetters(Class<?> c) {
549 ArrayList<Method> list = new ArrayList<Method>();
550 Method[] methods = c.getDeclaredMethods();
551 for (Method method : methods)
552 if (isGetter(method))
558 public static boolean isGetter(Method method) {
559 if (Modifier.isPublic(method.getModifiers()) &&
560 method.getParameterTypes().length == 0) {
561 if (method.getName().matches("^get[A-Z].*") &&
562 !method.getReturnType().equals(void.class))
564 if (method.getName().matches("^is[A-Z].*") &&
565 method.getReturnType().equals(boolean.class))
571 public static boolean isSetter(Method method) {
572 return Modifier.isPublic(method.getModifiers()) &&
573 method.getReturnType().equals(void.class) &&
574 method.getParameterTypes().length == 1 &&
575 method.getName().matches("^set[A-Z].*");
578 private String processAssign(String identifier, String method, String postProcess) {
580 if("uuid".equals(method)) {
581 value = UUID.randomUUID().toString();
584 if("cache".equals(postProcess)) {
585 cache.put(identifier, value);
588 if("value".equals(method)) {
589 cache.put(identifier, postProcess);
593 String key = String.format("%s = '%s'", identifier, value);
597 private String processCached(String identifier, String method) {
598 String value = cache.get(identifier);
600 String key = String.format("%s = '%s'", identifier, value);
604 protected HashMap<String,String> keyToHashMap(String key, SvcLogicContext ctx) {
609 LOG.debug("Converting key [" + key + "] to where clause");
611 if (key.startsWith("'") && key.endsWith("'")) {
612 key = key.substring(1, key.length() - 1);
614 LOG.debug("Stripped outer single quotes - key is now [" + key + "]");
617 String[] keyTerms = key.split("\\s+");
622 HashMap<String, String> results = new HashMap<String, String>();
624 for (int i = 0; i < keyTerms.length; i++) {
626 if ("and".equalsIgnoreCase(keyTerms[i])
627 || "or".equalsIgnoreCase(keyTerms[i])) {
630 term1 = resolveTerm(keyTerms[i], ctx);
632 } else if (op == null) {
633 if ("==".equals(keyTerms[i])) {
639 term2 = resolveTerm(keyTerms[i], ctx);
640 term2 = term2.trim().replace("'", "").replace("$", "").replace("'", "");
641 results.put(term1, term2);
652 private String resolveTerm(String term, SvcLogicContext ctx) {
657 LOG.debug("resolveTerm: term is " + term);
659 if (term.startsWith("$") && (ctx != null)) {
660 // Resolve any index variables.
662 return ("'" + resolveCtxVariable(term.substring(1), ctx) + "'");
663 } else if (term.startsWith("'") || term.startsWith("\"")) {
666 return (term.replaceAll("-", "_"));
672 private String resolveCtxVariable(String ctxVarName, SvcLogicContext ctx) {
674 if (ctxVarName.indexOf('[') == -1) {
675 // Ctx variable contains no arrays
676 return (ctx.getAttribute(ctxVarName));
679 // Resolve any array references
680 StringBuffer sbuff = new StringBuffer();
681 String[] ctxVarParts = ctxVarName.split("\\[");
682 sbuff.append(ctxVarParts[0]);
683 for (int i = 1; i < ctxVarParts.length; i++) {
684 if (ctxVarParts[i].startsWith("$")) {
685 int endBracketLoc = ctxVarParts[i].indexOf("]");
686 if (endBracketLoc == -1) {
687 // Missing end bracket ... give up parsing
688 LOG.warn("Variable reference " + ctxVarName
689 + " seems to be missing a ']'");
690 return (ctx.getAttribute(ctxVarName));
693 String idxVarName = ctxVarParts[i].substring(1, endBracketLoc);
694 String remainder = ctxVarParts[i].substring(endBracketLoc);
697 sbuff.append(ctx.getAttribute(idxVarName));
698 sbuff.append(remainder);
701 // Index is not a variable reference
703 sbuff.append(ctxVarParts[i]);
707 return (ctx.getAttribute(sbuff.toString()));
711 public void test90QueryTenantRequest()
713 LOG.info("----------------------- Test: " + new Object(){}.getClass().getEnclosingMethod().getName() + " -----------------------");
718 url = client.requestVserverURLNodeQuery("bpsx0001vm001bps001");
719 url = new URL("https://mtanjv9aaas03.aic.cip.att.com:8443/aai/v4/cloud-infrastructure/tenants/tenant/6b012c07bdf1427190ae58f794a86344/vservers/vserver/5acfe828-82e9-swgk092815-13-4d2c-85bb-9c2c1fafcce6");
720 client.getTenantIdFromVserverUrl(url);
721 } catch (Exception e) {
722 // TODO Auto-generated catch block
728 public void R1702NamedQueryRequest()
730 LOG.info("----------------------- Test: " + new Object(){}.getClass().getEnclosingMethod().getName() + " -----------------------");
733 SvcLogicContext ctx = new SvcLogicContext();
734 URL resource = this.getClass().getResource("/json/nquery2.json");
736 LOG.info("Resource is " + resource.getFile());
737 File requestFile = new File(resource.getFile());
738 if(!requestFile.exists()) {
739 fail("Test file does not exist");
741 ObjectMapper mapper = AAIService.getObjectMapper();
742 NamedQueryData request = mapper.readValue(requestFile, NamedQueryData.class);
743 Map<String, Object> map = mapper.convertValue(request, Map.class);
745 ctx.setAttribute("namedQueryData.instance-filters.instance-filter[0].l3-network.network-role", "example-network-role-val-432223");
746 ctx.setAttribute("namedQueryData.instance-filters.instance-filter_length", "1");
747 QueryStatus resp = client.query("named-query", false, null, "named-query-uuid = '4f448e43-339f-4c1c-85f6-896c444e25ca' AND prefix = 'namedQueryData' ", "zdzich", null, ctx);
749 LOG.info("AAIResponse: " + resp.toString());
758 static class MySchemaOutputResolver extends SchemaOutputResolver {
760 public Result createOutput(String namespaceURI, String suggestedFileName) throws IOException {
761 File file = new File(suggestedFileName);
762 StreamResult result = new StreamResult(file);
763 result.setSystemId(file.getAbsolutePath());
769 private static void listSubNodes(String parent, Document doc, Stack<String> stack, List<String> commands) throws Exception {
770 XPathFactory xFactory = XPathFactory.newInstance();
771 XPath xPath = xFactory.newXPath();
772 String format = "/schema/element[@name='%s']/complexType/sequence/element[@ref]";
774 String path = String.format(format, parent);
776 // XPathExpression exp = xPath.compile("/schema/element[@name='generic-vnf']/complexType/sequence/element[@ref]");
777 XPathExpression exp = xPath.compile(path);
779 NodeList nl = (NodeList)exp.evaluate(doc.getFirstChild(), XPathConstants.NODESET);
780 LOG.debug("Nodes to process : "+nl.getLength());
781 for (int index = 0; index < nl.getLength(); index++) {
783 Node node = nl.item(index);
785 if(!(node instanceof Element))
788 String classAlias = null;
790 if(node.hasAttributes())
792 String nm = ((Element)node).getAttribute("ref");
793 if(nm != null && !nm.isEmpty()) {
794 String[] split = nm.split(":");
795 classAlias = split[split.length - 1];
796 if("relationship-list".equals(classAlias))
798 if("metadata".equals(classAlias))
800 if("classes-of-service".equals(classAlias)) {
801 classAlias = "class-of-service";
802 } else if("l3-interface-ipv4-address-list".equals(classAlias)) {
804 } else if("l3-interface-ipv6-address-list".equals(classAlias)) {
806 } else if("cvlan-tags".equals(classAlias)) {
807 classAlias = "cvlan-tag-entry";
808 } else if("network-policies".equals(classAlias)) {
809 classAlias = "network-policy";
810 } else if("complexes".equals(classAlias)) {
811 classAlias = "complex";
812 } else if("dvs-switches".equals(classAlias)) {
813 classAlias = "dvs-switch";
814 } else if("service-capabilities".equals(classAlias)) {
815 classAlias = "service-capability";
817 classAlias = classAlias.substring(0, classAlias.length() -1);
819 AAIRequest request = AAIRequest.createRequest(classAlias, new HashMap<String, String>());
820 if(request != null) {
821 Class<?> clazz = request.getModelClass();
822 Field[] fieldz = clazz.getDeclaredFields();
823 Field field = fieldz[0];
824 String fieldName = field.getName();
825 XmlElement annotation = field.getAnnotation(XmlElement.class);
827 Map<String, Object> map = AnnotationUtils.getAnnotationAttributes(annotation);
828 String id = (String)map.get("name");
829 if("##default".equals(id)) {
833 if("cloud-region".equals(classAlias)) {
834 String keystring = "cloud-region.cloud-owner:assign:value:att-aic&cloud-region.cloud-region-id:assign:value:AAIAIC25";
835 stack.push(keystring);
836 String[] array = stack.toArray(new String[0]);
837 String key = StringUtils.join(array, "&");
839 String query = String.format("query|%s|%s", classAlias, key);
841 listSubNodes(classAlias, doc, stack, commands);
843 } else if("entitlement".equals(classAlias)) {
844 String keystring = "entitlement.group-uuid:assign:value:"+UUID.randomUUID()+"&entitlement.resource-uuid:assign:value:"+UUID.randomUUID();
845 stack.push(keystring);
846 String[] array = stack.toArray(new String[0]);
847 String key = StringUtils.join(array, "&");
849 String query = String.format("query|%s|%s", classAlias, key);
851 listSubNodes(classAlias, doc, stack, commands);
853 } else if("license".equals(classAlias)) {
854 String keystring = "license.group-uuid:assign:value:"+UUID.randomUUID()+"&license.resource-uuid:assign:value:"+UUID.randomUUID();
855 stack.push(keystring);
856 String[] array = stack.toArray(new String[0]);
857 String key = StringUtils.join(array, "&");
859 String query = String.format("query|%s|%s", classAlias, key);
861 listSubNodes(classAlias, doc, stack, commands);
863 } else if("route-target".equals(classAlias)) {
864 String keystring = "route-target.global-route-target:assign:value:"+UUID.randomUUID()+"&route-target.route-target-role:assign:value:"+UUID.randomUUID();
865 stack.push(keystring);
866 String[] array = stack.toArray(new String[0]);
867 String key = StringUtils.join(array, "&");
869 String query = String.format("query|%s|%s", classAlias, key);
871 listSubNodes(classAlias, doc, stack, commands);
873 } else if("service-capability".equals(classAlias)) {
874 String keystring = "service-capability.service-type:assign:value:"+UUID.randomUUID()+"&service-capability.vnf-type:assign:value:"+UUID.randomUUID();
875 stack.push(keystring);
876 String[] array = stack.toArray(new String[0]);
877 String key = StringUtils.join(array, "&");
879 String query = String.format("query|%s|%s", classAlias, key);
881 listSubNodes(classAlias, doc, stack, commands);
883 } else if("ctag-pool".equals(classAlias)) {
884 String keystring = "ctag-pool.target-pe:assign:value:"+UUID.randomUUID()+"&ctag-pool.availability-zone-name:assign:value:"+UUID.randomUUID();
885 stack.push(keystring);
886 String[] array = stack.toArray(new String[0]);
887 String key = StringUtils.join(array, "&");
889 String query = String.format("query|%s|%s", classAlias, key);
891 listSubNodes(classAlias, doc, stack, commands);
894 String keystring = String.format("%s.%s:assign:value:%s", classAlias, id, UUID.randomUUID());
895 stack.push(keystring);
896 String[] array = stack.toArray(new String[0]);
897 String key = StringUtils.join(array, "&");
899 String save = String.format("save|%s|%s", classAlias, key);
902 String query = String.format("query|%s|%s", classAlias, key);
905 String update = String.format("update|%s|%s", classAlias, key);
906 commands.add(update);
908 if(!parent.equals(classAlias) && !containsCircular(classAlias, id, stack)) {
909 listSubNodes(classAlias, doc, stack, commands);
911 String delete = String.format("delete|%s|%s", classAlias, key);
912 commands.add(delete);
921 public static boolean containsCircular(String classAlias, String id, Stack<String> stack) {
922 String keystring = String.format("%s.%s", classAlias, id);
924 Stack<String> localStack = new Stack<String>();
925 localStack.addAll(stack);
929 while(!localStack.isEmpty()) {
930 String instruction = localStack.pop();
931 if(instruction.contains(keystring)) {