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 java.io.IOException;
25 import java.io.UnsupportedEncodingException;
26 import java.lang.annotation.Annotation;
27 import java.lang.reflect.Field;
28 import java.lang.reflect.InvocationTargetException;
29 import java.lang.reflect.Method;
30 import java.net.MalformedURLException;
31 import java.net.URISyntaxException;
33 import java.net.URLDecoder;
34 import java.net.URLEncoder;
35 import java.util.ArrayList;
36 import java.util.Arrays;
37 import java.util.HashMap;
38 import java.util.LinkedList;
39 import java.util.List;
42 import java.util.SortedSet;
43 import java.util.TreeSet;
44 import java.util.regex.Matcher;
45 import java.util.regex.Pattern;
47 import javax.xml.bind.annotation.XmlType;
49 import org.apache.commons.lang.StringUtils;
50 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
51 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
52 import org.onap.ccsdk.sli.core.sli.SvcLogicResource.QueryStatus;
53 import org.openecomp.aai.inventory.v11.Image;
54 import org.openecomp.aai.inventory.v11.GenericVnf;
55 import org.openecomp.aai.inventory.v11.InventoryResponseItem;
56 import org.openecomp.aai.inventory.v11.InventoryResponseItems;
57 import org.openecomp.aai.inventory.v11.L3Network;
58 import org.openecomp.aai.inventory.v11.LogicalLink;
59 import org.openecomp.aai.inventory.v11.Metadata;
60 import org.openecomp.aai.inventory.v11.Metadatum;
61 import org.openecomp.aai.inventory.v11.Pnf;
62 import org.openecomp.aai.inventory.v11.RelatedToProperty;
63 import org.openecomp.aai.inventory.v11.Relationship;
64 import org.openecomp.aai.inventory.v11.RelationshipData;
65 import org.openecomp.aai.inventory.v11.RelationshipList;
66 import org.openecomp.aai.inventory.v11.ResultData;
67 import org.openecomp.aai.inventory.v11.SearchResults;
68 import org.openecomp.aai.inventory.v11.ServiceInstance;
69 import org.openecomp.aai.inventory.v11.Vlan;
70 import org.openecomp.aai.inventory.v11.Vlans;
71 import org.openecomp.aai.inventory.v11.Vserver;
72 import org.onap.ccsdk.sli.adaptors.aai.data.AAIDatum;
73 import org.onap.ccsdk.sli.adaptors.aai.query.FormattedQueryResultList;
74 import org.onap.ccsdk.sli.adaptors.aai.query.InstanceFilter;
75 import org.onap.ccsdk.sli.adaptors.aai.query.InstanceFilters;
76 import org.onap.ccsdk.sli.adaptors.aai.query.NamedQuery;
77 import org.onap.ccsdk.sli.adaptors.aai.query.NamedQueryData;
78 import org.onap.ccsdk.sli.adaptors.aai.query.QueryParameters;
79 import org.onap.ccsdk.sli.adaptors.aai.query.Result;
80 import org.slf4j.Logger;
81 import org.slf4j.LoggerFactory;
83 import com.fasterxml.jackson.core.JsonParseException;
84 import com.fasterxml.jackson.databind.JsonMappingException;
85 import com.fasterxml.jackson.databind.ObjectMapper;
88 public abstract class AAIDeclarations implements AAIClient {
90 public static final String TRUSTSTORE_PATH = "org.onap.ccsdk.sli.adaptors.aai.ssl.trust";
91 public static final String TRUSTSTORE_PSSWD = "org.onap.ccsdk.sli.adaptors.aai.ssl.trust.psswd";
92 public static final String KEYSTORE_PATH = "org.onap.ccsdk.sli.adaptors.aai.ssl.key";
93 public static final String KEYSTORE_PSSWD = "org.onap.ccsdk.sli.adaptors.aai.ssl.key.psswd";
95 public static final String APPLICATION_ID = "org.onap.ccsdk.sli.adaptors.aai.application";
97 public static final String CLIENT_NAME = "org.onap.ccsdk.sli.adaptors.aai.client.name";
98 public static final String CLIENT_PWWD = "org.onap.ccsdk.sli.adaptors.aai.client.psswd";
101 public static final String CONNECTION_TIMEOUT = "connection.timeout";
102 public static final String READ_TIMEOUT = "read.timeout";
104 public static final String TARGET_URI = "org.onap.ccsdk.sli.adaptors.aai.uri";
106 // Availability zones query
107 public static final String QUERY_PATH = "org.onap.ccsdk.sli.adaptors.aai.path.query";
110 public static final String UPDATE_PATH = "org.onap.ccsdk.sli.adaptors.aai.update";
113 public static final String SVC_INSTANCE_PATH = "org.onap.ccsdk.sli.adaptors.aai.path.svcinst";
114 public static final String SVC_INST_QRY_PATH = "org.onap.ccsdk.sli.adaptors.aai.path.svcinst.query";
117 public static final String NETWORK_VSERVER_PATH = "org.onap.ccsdk.sli.adaptors.aai.path.vserver";
119 public static final String VNF_IMAGE_QUERY_PATH = "org.onap.ccsdk.sli.adaptors.aai.path.vnf.image.query";
121 public static final String PARAM_SERVICE_TYPE = "org.onap.ccsdk.sli.adaptors.aai.param.service.type";
122 public static final String CERTIFICATE_HOST_ERROR = "org.onap.ccsdk.sli.adaptors.aai.host.certificate.ignore";
125 public static final String UBB_NOTIFY_PATH = "org.onap.ccsdk.sli.adaptors.aai.path.notify";
126 public static final String SELFLINK_AVPN = "org.onap.ccsdk.sli.adaptors.aai.notify.selflink.avpn";
127 public static final String SELFLINK_FQDN = "org.onap.ccsdk.sli.adaptors.aai.notify.selflink.fqdn";
130 public static final String SERVICE_PATH = "org.onap.ccsdk.sli.adaptors.aai.path.service";
133 public static final String P_INTERFACE_PATH = "org.onap.ccsdk.sli.adaptors.aai.path.pserver.pinterface";
136 public static final String SITE_PAIR_SET_PATH = "org.onap.ccsdk.sli.adaptors.aai.path.site.pair.set";
139 public static final String QUERY_NODES_PATH = "org.onap.ccsdk.sli.adaptors.aai.query.nodes";
142 protected abstract Logger getLogger();
143 public abstract AAIExecutorInterface getExecutor();
147 public QueryStatus query(String resource, boolean localOnly, String select, String key, String prefix, String orderBy, SvcLogicContext ctx)
148 throws SvcLogicException {
150 getLogger().debug("AAIService.query \tresource = "+resource);
153 String vnfName = null;
154 HashMap<String, String> nameValues = AAIServiceUtils.keyToHashMap(key, ctx);
155 getLogger().debug("key = "+ nameValues.toString());
157 if(!AAIServiceUtils.isValidFormat(resource, nameValues)) {
158 ctx.setAttribute(String.format("%s.error.message", prefix), String.format("Resource %s is not supported. Key string contains invaid identifiers", resource));
159 return QueryStatus.FAILURE;
162 if(resource == null || resource.isEmpty() || AAIRequest.createRequest(resource, nameValues) == null) {
163 ctx.setAttribute(String.format("%s.error.message", prefix), String.format("Resource %s is not supported", resource));
164 return QueryStatus.FAILURE;
167 // process data using new model
168 boolean useNewModelProcessing = true;
169 // process server query by name the old way
170 if("vserver".equals(resource) || "vserver2".equals(resource)){
171 if(nameValues.containsKey("vserver_name") || nameValues.containsKey("vserver-name") || nameValues.containsKey("vserver.vserver_name") || nameValues.containsKey("vserver.vserver-name"))
172 useNewModelProcessing = false;
174 if("generic-vnf".equals(resource)){
175 if(nameValues.containsKey("vnf_name") || nameValues.containsKey("vnf-name") || nameValues.containsKey("generic_vnf.vnf_name") || nameValues.containsKey("generic-vnf.vnf-name"))
176 useNewModelProcessing = false;
179 // process data using new model
180 if(useNewModelProcessing && AAIRequest.createRequest(resource, nameValues) != null) {
183 return newModelQuery(resource, localOnly, select, key, prefix, orderBy, ctx);
184 } catch (Exception exc) {
185 getLogger().warn("Failed query - returning FAILURE", exc);
186 return QueryStatus.FAILURE;
190 ObjectMapper mapper = AAIService.getObjectMapper();
191 Map<String,Object> attributes = new HashMap<>();
193 String modifier = null;
195 if(resource.contains(":")) {
196 String[] tokens = resource.split(":");
197 resource = tokens[0];
198 if(tokens.length > 1) {
199 modifier = tokens[1];
203 resource = resource.toLowerCase().replace("-", "_");
209 vnfId = nameValues.get("vnf_id");
210 if(nameValues.containsKey("vnf_id"))
211 vnfId = nameValues.get("vnf_id");
212 else if(nameValues.containsKey("generic_vnf.vnf_name"))
213 vnfId = nameValues.get("generic_vnf.vserver_name");
215 if(nameValues.containsKey("vnf_name"))
216 vnfName = nameValues.get("vnf_name");
217 else if(nameValues.containsKey("generic_vnf.vnf_name"))
218 vnfName = nameValues.get("generic_vnf.vnf_name");
220 if(vnfId != null && !vnfId.isEmpty()) {
221 // at this point of the project this part should not be executed
222 vnfId = vnfId.trim().replace("'", "").replace("$", "").replace("'", "");
223 GenericVnf vnf = this.requestGenericVnfData(vnfId);
225 return QueryStatus.NOT_FOUND;
228 attributes = mapper.convertValue(vnf, attributes.getClass());
229 } else if(vnfName != null && !vnfName.isEmpty()) {
231 vnfName = vnfName.trim().replace("'", "").replace("$", "").replace("'", "");
232 GenericVnf vnf = this.requestGenericVnfeNodeQuery(vnfName);
234 return QueryStatus.NOT_FOUND;
236 vnfId=vnf.getVnfId();
237 nameValues.put("vnf_id", vnfId);
238 attributes = mapper.convertValue(vnf, attributes.getClass());
239 } catch (AAIServiceException exc) {
240 int errorCode = exc.getReturnCode();
247 getLogger().warn("Caught exception trying to refresh generic VNF", exc);
249 ctx.setAttribute(prefix + ".error.message", exc.getMessage());
250 if(errorCode >= 300) {
251 ctx.setAttribute(prefix + ".error.http.response-code",
252 Integer.toString(exc.getReturnCode()));
254 return QueryStatus.FAILURE;
257 getLogger().warn("No arguments are available to process generic VNF");
258 return QueryStatus.FAILURE;
263 String vserverName = null;
264 if(nameValues.containsKey("vserver_name"))
265 vserverName = nameValues.get("vserver_name");
266 else if(nameValues.containsKey("vserver.vserver_name"))
267 vserverName = nameValues.get("vserver.vserver_name");
269 String vserverId = null;
270 if(nameValues.containsKey("vserver_id"))
271 vserverId = nameValues.get("vserver_id");
272 if(nameValues.containsKey("vserver.vserver_id"))
273 vserverId = nameValues.get("vserver.vserver_id");
274 String tenantId = nameValues.get("teannt_id");
276 if(vserverName != null) vserverName = vserverName.trim().replace("'", "").replace("$", "").replace("'", "");
277 if(vserverId != null) vserverId = vserverId.trim().replace("'", "").replace("$", "").replace("'", "");
278 if(tenantId != null) tenantId = tenantId.trim().replace("'", "").replace("$", "").replace("'", "");
280 if (vserverName != null) {
281 URL vserverUrl = null;
283 vserverUrl = this.requestVserverURLNodeQuery(vserverName);
284 } catch (AAIServiceException aaiexc) {
285 ctx.setAttribute(prefix + ".error.message", aaiexc.getMessage());
286 if (aaiexc.getReturnCode() >= 300) {
287 ctx.setAttribute(prefix + ".error.http" + "" + ".response-code", Integer.toString(aaiexc.getReturnCode()));
290 if (aaiexc.getReturnCode() == 404)
291 return QueryStatus.NOT_FOUND;
293 return QueryStatus.FAILURE;
295 if (vserverUrl == null) {
296 return QueryStatus.NOT_FOUND;
299 tenantId = getTenantIdFromVserverUrl(vserverUrl);
300 String cloudOwner = getCloudOwnerFromVserverUrl(vserverUrl);
301 String cloudRegionId = getCloudRegionFromVserverUrl(vserverUrl);
303 Vserver vserver = null;
305 vserver = this.requestVServerDataByURL(vserverUrl);
306 } catch (AAIServiceException aaiexc) {
307 ctx.setAttribute(prefix + ".error.message", aaiexc.getMessage());
308 if (aaiexc.getReturnCode() >= 300) {
309 ctx.setAttribute(prefix + ".error.http" + ".response-code", Integer.toString(aaiexc.getReturnCode()));
312 if (aaiexc.getReturnCode() == 404)
313 return QueryStatus.NOT_FOUND;
315 return QueryStatus.FAILURE;
317 if (vserver == null) {
318 return QueryStatus.NOT_FOUND;
320 attributes = mapper.convertValue(vserver, attributes.getClass());
321 if (!attributes.containsKey("tenant-id") && tenantId != null) {
322 attributes.put("tenant-id", tenantId);
324 if (!attributes.containsKey("cloud-owner") && cloudOwner != null) {
325 attributes.put("cloud-owner", cloudOwner);
327 if (!attributes.containsKey("cloud-region-id") && cloudRegionId != null) {
328 attributes.put("cloud-region-id", cloudRegionId);
330 } else if (vserverId != null && tenantId != null) {
331 Vserver vserver = this.requestVServerData(tenantId, vserverId, "att-aic", "AAIAIC25");
332 if(vserver == null) {
333 return QueryStatus.NOT_FOUND;
335 attributes = mapper.convertValue(vserver, attributes.getClass());
336 if(!attributes.containsKey("tenant-id") && tenantId != null){
337 attributes.put("tenant-id", tenantId);
340 return QueryStatus.FAILURE;
345 return QueryStatus.FAILURE;
348 QueryStatus retval = QueryStatus.SUCCESS;
350 if (attributes == null || attributes.isEmpty()) {
351 retval = QueryStatus.NOT_FOUND;
352 getLogger().debug("No data found");
355 if (prefix != null) {
356 ArrayList<String> keys = new ArrayList<>(attributes.keySet());
358 int numCols = keys.size();
360 for (int i = 0; i < numCols; i++) {
362 String colName = keys.get(i);
363 Object object = attributes.get(colName);
365 if(object != null && object instanceof String) {
366 colValue = (String)object;
368 if (prefix != null) {
369 getLogger().debug("Setting "+prefix + "." + colName.replaceAll("_", "-")+" = "+ colValue);
370 ctx.setAttribute(prefix + "." + colName.replaceAll("_", "-"), colValue);
372 getLogger().debug("Setting " + colValue.replaceAll("_", "-")+" = "+colValue);
373 ctx.setAttribute(colValue.replaceAll("_", "-"), colValue);
375 } else if(object != null && object instanceof Map) {
376 if(colName.equals(modifier) || "relationship-list".equals(colName)){
377 String localNodifier = modifier;
378 if(localNodifier == null)
379 localNodifier = "relationship-list";
380 Map<String, Object> properties = (Map<String, Object>)object;
381 writeMap(properties, prefix+"."+localNodifier, ctx);
388 getLogger().debug("Query - returning " + retval);
391 } catch (Exception exc) {
392 getLogger().warn("Failed query - returning FAILURE", exc);
393 return QueryStatus.FAILURE;
396 // return QueryStatus.SUCCESS;
400 public void writeMap(Map<String, Object> properties, String prefix, SvcLogicContext ctx) {
401 Set<String> mapKeys = properties.keySet();
403 for(String mapKey : mapKeys) {
404 Object entity = properties.get(mapKey);
405 if(entity instanceof ArrayList) {
406 writeList((ArrayList<?>)entity, prefix + "." + mapKey, ctx);
408 if(entity instanceof String || entity instanceof Long || entity instanceof Integer || entity instanceof Boolean) {
409 ctx.setAttribute(prefix + "." + mapKey, entity.toString());
410 getLogger().debug(prefix + "." + mapKey + " : " + entity.toString());
411 } else if(entity instanceof Map) {
412 String localPrefix = prefix;
414 localPrefix = String.format("%s.%s", prefix, mapKey);
416 writeMap( (Map<String, Object>)entity, localPrefix, ctx);
421 private void writeList(ArrayList<?> list, String prefix, SvcLogicContext ctx) {
422 for(int i = 0; i < list.size(); i++ ) {
423 Object entity = list.get(i);
424 if(entity instanceof Map) {
425 writeMap( (Map<String, Object>)entity, prefix + "[" + i + "]", ctx);
427 if(entity instanceof String || entity instanceof Long || entity instanceof Integer || entity instanceof Boolean) {
428 ctx.setAttribute(prefix, entity.toString());
429 getLogger().debug(prefix + " : " + entity.toString());
433 if(!list.isEmpty()) {
434 ctx.setAttribute(prefix + "_length", Integer.toString(list.size()));
435 getLogger().debug(prefix + "_length" + " : " + Integer.toString(list.size()));
440 public QueryStatus save(String resource, boolean force, boolean localOnly, String key, Map<String, String> params, String prefix, SvcLogicContext ctx)
441 throws SvcLogicException {
443 getLogger().debug("AAIService.save\tresource="+resource);
444 HashMap<String, String> nameValues = AAIServiceUtils.keyToHashMap(key, ctx);
446 if(!AAIServiceUtils.isValidFormat(resource, nameValues)) {
447 ctx.setAttribute(String.format("%s.error.message", prefix), String.format("Resource %s is not supported. Key string contains invaid identifiers", resource));
448 return QueryStatus.FAILURE;
451 if(resource == null || resource.isEmpty() || AAIRequest.createRequest(resource, nameValues) == null) {
452 getLogger().warn("AAIService.save has unspecified resource");
453 ctx.setAttribute(String.format("%s.error.message", prefix), String.format("Resource %s is not supported", resource));
454 return QueryStatus.FAILURE;
457 getLogger().debug("key = "+ Arrays.toString(nameValues.entrySet().toArray()));
460 if(params.containsKey("prefix")) {
461 Map<String, String> tmpParams = ctxGetBeginsWith(ctx, params.get("prefix"));
462 if(!tmpParams.isEmpty()) {
463 params.putAll(tmpParams);
464 // params.remove("prefix");
468 getLogger().debug("parms = "+ Arrays.toString(params.entrySet().toArray()));
470 boolean useNewModelProcessing = true;
471 // process server query by name the old way
472 if("vserver".equals(resource) || "vserver2".equals(resource)){
473 if(nameValues.containsKey("vserver-name")) {
474 useNewModelProcessing = false;
477 if(!params.containsKey("vserver-selflink")) {
479 AAIRequest request = AAIRequest.createRequest(resource, nameValues);
482 request.processRequestPathValues(nameValues);
483 path = request.getRequestUrl("GET", null);
484 params.put("vserver-selflink", path.toString());
485 } catch (UnsupportedEncodingException | MalformedURLException | URISyntaxException e) {
487 params.put("vserver-selflink", "/vserver");
492 // process data using new model
493 if(useNewModelProcessing && AAIRequest.createRequest(resource, nameValues) != null) {
496 if(!resource.contains(":")){
497 return newModelSave(resource, force, key, params, prefix, ctx);
499 String[] tokens = resource.split(":");
500 String localResource = tokens[0];
501 String dependency = tokens[1];
503 AAIDatum instance = newModelObjectRequest( localResource, nameValues, prefix, ctx);
504 if(instance == null) {
505 return QueryStatus.NOT_FOUND;
509 case "relationship-list":
510 newModelProcessRelationshipList(instance, params, prefix, ctx);
513 newModelProcessMetadata(instance, params, prefix, ctx);
516 // create a method to update relationship-list
517 AAIRequest request = AAIRequest.createRequest(localResource, nameValues);
518 request.setRequestObject(instance);
519 request.processRequestPathValues(nameValues);
521 getExecutor().post(request);
522 getLogger().debug("Save relationship list - returning SUCCESS");
523 return QueryStatus.SUCCESS;
525 } catch (Exception exc) {
526 ctx.setAttribute(prefix + ".error.message", exc.getMessage());
527 if(exc instanceof AAIServiceException) {
528 AAIServiceException aaiexc = (AAIServiceException)exc;
529 if(aaiexc.getReturnCode() >= 300) {
530 ctx.setAttribute(prefix + ".error.http" + ".response-code", Integer.toString(aaiexc.getReturnCode()));
533 if(aaiexc.getReturnCode() == 404) {
534 return QueryStatus.NOT_FOUND;
537 getLogger().warn("Failed save() - returning FAILURE", exc);
538 return QueryStatus.FAILURE;
541 String reSource = resource.toLowerCase().replace("-", "_");
548 vnfId = nameValues.get("vnf_id");
550 getLogger().debug("Save(generic-vnf) with no vnf-id specified. Returning FAILURE");
551 return QueryStatus.FAILURE;
553 vnfId = vnfId.trim().replace("'", "").replace("$", "").replace("'", "");
554 GenericVnf vnf = this.requestGenericVnfData(vnfId);
555 String status = params.get("prov-status");
556 boolean updated = false;
557 if(status != null && !status.isEmpty()) {
558 vnf.setProvStatus(status);
561 this.postGenericVnfData(vnfId, vnf);
565 return update( resource, key, params, prefix, ctx) ;
568 getLogger().debug("Save() executing default path - returning FAILURE");
569 return QueryStatus.FAILURE;
571 } catch (Exception exc) {
572 getLogger().warn("Failed save - returning FAILURE", exc);
573 ctx.setAttribute(prefix + ".error.message", exc.getMessage());
574 return QueryStatus.FAILURE;
578 getLogger().debug("Save - returning SUCCESS");
579 return QueryStatus.SUCCESS;
583 public QueryStatus update(String resource, String key, Map<String, String> params, String prefix, SvcLogicContext ctx) throws SvcLogicException {
585 resource = resource.toLowerCase();
586 HashMap<String, String> nameValues = AAIServiceUtils.keyToHashMap(key, ctx);
587 getLogger().debug("key = "+ Arrays.toString(nameValues.entrySet().toArray()));
588 if(!AAIServiceUtils.isValidFormat(resource, nameValues)) {
589 ctx.setAttribute(String.format("%s.error.message", prefix), String.format("Resource %s is not supported. Key string contains invaid identifiers", resource));
590 return QueryStatus.FAILURE;
593 if(resource == null || resource.isEmpty() || AAIRequest.createRequest(resource, nameValues) == null) {
594 ctx.setAttribute(String.format("%s.error.message", prefix), String.format("Resource %s is not supported", resource));
595 return QueryStatus.FAILURE;
598 // check if request is for groups
599 if(!AAIServiceUtils.containsResource(resource, nameValues)) {
600 ctx.setAttribute(String.format("%s.error.message", prefix), String.format("Resource %s is not permitted in 'update' operation", resource));
601 return QueryStatus.FAILURE;
604 getLogger().debug("parms = "+ Arrays.toString(params.entrySet().toArray()));
606 AAIRequest request = AAIRequest.createRequest(resource, nameValues);
607 request = new UpdateRequest(request, params);
609 String[] arguments = request.getArgsList();
610 for(String name : arguments) {
611 String modifiedKey = name.replaceAll("-", "_");
612 if(nameValues.containsKey(modifiedKey)) {
613 String argValue = nameValues.get(modifiedKey);
614 if(argValue != null) argValue = argValue.trim().replace("'", "").replace("$", "").replace("'", "");
615 request.addRequestProperty(name, argValue);
620 QueryStatus retval = QueryStatus.SUCCESS;
622 retval = newModelQuery(resource, false, null, key, "tmpDelete", null, ctx);
624 if(retval == null || retval != QueryStatus.SUCCESS) {
628 String resourceVersion = ctx.getAttribute("tmpDelete.resource-version");
629 if(resourceVersion == null) {
630 return QueryStatus.NOT_FOUND;
632 params.put("resource-version", resourceVersion);
634 request.processRequestPathValues(nameValues);
635 getExecutor().patch(request, resourceVersion);
636 } catch(AAIServiceException aaiexc) {
637 if(aaiexc.getReturnCode() == 404)
638 return QueryStatus.NOT_FOUND;
640 return QueryStatus.FAILURE;
641 } catch (Exception exc) {
642 getLogger().warn("Failed update - returning FAILURE", exc);
643 return QueryStatus.FAILURE;
646 getLogger().debug("Update - returning SUCCESS");
647 return QueryStatus.SUCCESS;
651 public QueryStatus delete(String resource, String key, SvcLogicContext ctx) throws SvcLogicException {
652 getLogger().debug("AAIService.delete\tresource="+resource);
653 HashMap<String, String> nameValues = AAIServiceUtils.keyToHashMap(key, ctx);
654 getLogger().debug("key = "+ Arrays.toString(nameValues.entrySet().toArray()));
656 if(!AAIServiceUtils.isValidFormat(resource, nameValues)) {
657 ctx.setAttribute(String.format("%s.error.message", "aaiData"), String.format("Resource %s is not supported. Key string contains invaid identifiers", resource));
658 return QueryStatus.FAILURE;
661 if(resource == null || resource.isEmpty() || AAIRequest.createRequest(resource, nameValues) == null) {
662 ctx.setAttribute(String.format("%s.error.message", "tmpDelete"), String.format("Resource %s is not supported", resource));
663 return QueryStatus.FAILURE;
666 // check if request is for groups
667 if(!AAIServiceUtils.containsResource(resource, nameValues)) {
668 ctx.setAttribute(String.format("%s.error.message", "tmpDelete"), String.format("Resource %s is not permitted in 'delete' operation", resource));
669 return QueryStatus.FAILURE;
672 if(AAIRequest.createRequest(resource, nameValues) != null) {
673 if(resource.contains(":")) {
674 switch (resource.split(":")[1]){
675 case "relationship-list":
676 return processDeleteRelationshipList(resource, key, ctx, nameValues);
678 return processDeleteMetadata(resource, key, ctx, nameValues);
684 QueryStatus retval = QueryStatus.SUCCESS;
686 retval = newModelQuery(resource, false, null, key, "tmpDelete", null, ctx);
688 if(retval == null || retval != QueryStatus.SUCCESS) {
692 String resourceVersion = ctx.getAttribute("tmpDelete.resource-version");
693 if(resourceVersion == null) {
694 return QueryStatus.NOT_FOUND;
698 AAIRequest request = AAIRequest.createRequest(resource, nameValues);
699 if(request == null) {
700 return QueryStatus.FAILURE;
703 request.processRequestPathValues(nameValues);
705 if(getExecutor().delete(request, resourceVersion)) {
706 return QueryStatus.SUCCESS;
708 } catch(AAIServiceException aaiexc) {
709 if(aaiexc.getReturnCode() == 404)
710 return QueryStatus.NOT_FOUND;
712 return QueryStatus.FAILURE;
714 } catch (Exception exc) {
715 getLogger().warn("requestGenericVnfData", exc);
716 return QueryStatus.FAILURE;
719 } catch (Exception exc) {
720 getLogger().warn("Failed delete - returning FAILURE", exc);
721 return QueryStatus.FAILURE;
724 String resourceName = resource;
725 String identifier = null;
727 if(resourceName.contains(":")) {
728 String[] tokens = resourceName.split(":");
729 if(tokens != null && tokens.length > 0) {
730 resourceName = tokens[0];
731 identifier = tokens[1];
734 if("relationship-list".equals(identifier) || "relationshipList".equals(identifier)) {
735 // RelationshipRequest relationshipRequest = new RelationshipRequest();
736 if("generic-vnf".equals(resourceName)){
737 String vnfId = nameValues.get("vnf_id");
738 String relatedTo = nameValues.get("related_to");
739 vnfId = vnfId.trim().replace("'", "").replace("$", "").replace("'", "");
740 relatedTo = relatedTo.trim().replace("'", "").replace("$", "").replace("'", "");
744 vnf = this.requestGenericVnfData(vnfId);
746 return QueryStatus.NOT_FOUND;
747 } catch (AAIServiceException exc) {
748 getLogger().warn("Failed delete - returning NOT_FOUND", exc);
749 return QueryStatus.NOT_FOUND;
751 boolean itemRemoved = false;
752 RelationshipList relationshipList = vnf.getRelationshipList();
753 List<Relationship> relationships = relationshipList.getRelationship();
754 List<Relationship> iterableList = new LinkedList<>(relationships);
755 for(Relationship relationship : iterableList) {
756 if(relationship.getRelatedTo().equals(relatedTo)) {
757 relationships.remove(relationship);
763 return QueryStatus.NOT_FOUND;
765 // AAIRequest masterRequest = new GenericVnfRequest();
766 // masterRequest.addRequestProperty(GenericVnfRequest.VNF_ID, vnfId);
767 // relationshipRequest.addMasterRequest(masterRequest);
768 // Map<String, String> attributes = objectToProperties(vnf);
770 // Boolean result = getExecutor().delete(relationshipRequest, attributes.get(AAIRequest.RESOURCE_VERSION));
771 // } catch (AAIServiceException e) {
772 // return QueryStatus.FAILURE;
776 this.postGenericVnfData(vnf.getVnfId(), vnf);
777 } catch (AAIServiceException exc) {
778 if(exc.getReturnCode() == 404){
779 return QueryStatus.NOT_FOUND;
781 getLogger().warn("Failed delete - returning FAILURE", exc);
782 return QueryStatus.FAILURE;
785 return QueryStatus.SUCCESS;
789 return QueryStatus.FAILURE;
793 public QueryStatus exists(String resource, String key, String prefix, SvcLogicContext ctx) throws SvcLogicException {
794 return query(resource, false, null, key, prefix, null, ctx);
798 public QueryStatus isAvailable(String arg0, String arg1, String arg2, SvcLogicContext arg3)
799 throws SvcLogicException {
800 // TODO Auto-generated method stub
801 throw new SvcLogicException("Method AAIService.isAvailable() has not been implemented yet");
805 public QueryStatus notify(String resource, String action, String key, SvcLogicContext ctx) throws SvcLogicException {
806 // TODO Auto-generated method stub
807 throw new SvcLogicException("Method AAIService.notify() has not been implemented yet");
811 public QueryStatus newModelQuery(String resource, boolean localOnly, String select, String key, String prefix, String orderBy, SvcLogicContext ctx) {
813 Object response = null;
814 QueryStatus retval = QueryStatus.SUCCESS;
815 String modifier = null;
817 HashMap<String, String> nameValues = AAIServiceUtils.keyToHashMap(key, ctx);
818 if(resource.contains(":")) {
819 modifier = resource.split(":")[1];
823 AAIRequest request = AAIRequest.createRequest(resource, nameValues);
824 if(request == null) {
825 return QueryStatus.FAILURE;
828 Map<String, String> params = new HashMap<>();
830 request.processRequestPathValues(nameValues);
831 if(nameValues.containsKey("prefix")){
832 Map<String, String> tmpParams = ctxGetBeginsWith(ctx, nameValues.get("prefix"));
833 if(!tmpParams.isEmpty()) {
834 params.putAll(tmpParams);
836 if("named-query".equals(resource))
837 request.setRequestObject(extractNamedQueryDataFromQueryPrefix(nameValues, params));
839 String rv = getExecutor().get(request);
841 retval = processResponseData(rv, resource, request, prefix, ctx, nameValues, modifier);
843 } catch(AAIServiceException aaiexc) {
844 int errorCode = aaiexc.getReturnCode();
845 ctx.setAttribute(prefix + ".error.message", aaiexc.getMessage());
846 if(errorCode >= 300) {
847 ctx.setAttribute(prefix + ".error.http.response-code",
848 Integer.toString(aaiexc.getReturnCode()));
851 if(aaiexc.getReturnCode() == 404)
852 return QueryStatus.NOT_FOUND;
854 return QueryStatus.FAILURE;
855 } catch (Exception exc) {
856 getLogger().warn("requestGenericVnfData", exc);
857 ctx.setAttribute(prefix + ".error.message", exc.getMessage());
858 return QueryStatus.FAILURE;
864 public QueryStatus processResponseData(String rv, String resource, AAIRequest request, String prefix, SvcLogicContext ctx, HashMap<String, String> nameValues, String modifier) throws JsonParseException, JsonMappingException, IOException, AAIServiceException
869 return QueryStatus.NOT_FOUND;
872 response = request.jsonStringToObject(rv);
873 if(response == null) {
874 return QueryStatus.NOT_FOUND;
877 if("generic-query".equals(resource)) {
878 SearchResults rd = SearchResults.class.cast(response);
879 List<ResultData> rdList = rd.getResultData();
880 if(rdList == null || rdList.isEmpty()) {
881 return QueryStatus.NOT_FOUND;
883 ResultData rDatum = rdList.get(0);
884 nameValues.put("selflink", rDatum.getResourceLink());
885 AAIRequest req2 = AAIRequest.createRequest(rDatum.getResourceType(), nameValues);
886 req2.processRequestPathValues(nameValues);
887 rv = getExecutor().get(req2);
889 return QueryStatus.NOT_FOUND;
892 response = req2.jsonStringToObject(rv);
893 if(response == null) {
894 return QueryStatus.NOT_FOUND;
898 if("named-query".equals(resource)) {
899 InventoryResponseItems rd = InventoryResponseItems.class.cast(response);
900 List<InventoryResponseItem> iRIlist = rd.getInventoryResponseItem();
901 if(iRIlist == null || iRIlist.isEmpty()) {
902 return QueryStatus.NOT_FOUND;
906 if("nodes-query".equals(resource)) {
907 SearchResults rd = SearchResults.class.cast(response);
908 List<ResultData> rdList = rd.getResultData();
909 if(rdList == null || rdList.isEmpty()) {
910 return QueryStatus.NOT_FOUND;
912 ResultData rDatum = rdList.get(0);
916 if("formatted-query".equals(resource) || "custom-query".equals(resource)) {
917 FormattedQueryResultList rd = FormattedQueryResultList.class.cast(response);
918 List<Result> iRIlist = rd.getResults();
919 if(iRIlist == null || iRIlist.isEmpty()) {
920 return QueryStatus.NOT_FOUND;
924 // process relationship list
925 // this is a temporary soluton to address the realationship handling changes added in Release 17.07
927 Class<?> clazz = response.getClass();
928 Method getter = clazz.getMethod("getRelationshipList");
929 Object obj = getter.invoke(response);
930 if(obj != null && obj instanceof RelationshipList) {
931 RelationshipList list = RelationshipList.class.cast(obj);
932 AAIServiceUtils.populateRelationshipDataFromPath(list);
934 } catch(Exception exc) {
935 getLogger().debug("Retrofiting relationship data: " + exc.getMessage());
939 if(prefix == null || prefix.isEmpty()) {
942 preFix = prefix + ".";
945 Map<String,Object> props = objectToProperties(response);
946 Set<String> keys = props.keySet();
947 for(String theKey: keys) {
948 if(getLogger().isTraceEnabled())
949 getLogger().trace(theKey);
951 Object value = props.get(theKey);
954 Object type = value.getClass();
955 if(value instanceof String) {
956 ctx.setAttribute(preFix + theKey, value.toString());
959 if(value instanceof Boolean) {
960 ctx.setAttribute(preFix + theKey, value.toString());
963 if(value instanceof Integer) {
964 ctx.setAttribute(preFix + theKey, value.toString());
967 if(value instanceof Long) {
968 ctx.setAttribute(preFix + theKey, value.toString());
972 if(value instanceof ArrayList) {
973 ArrayList<?> array = ArrayList.class.cast(value);
974 for(int i = 0; i < array.size(); i++) {
975 writeList(array, String.format("%s.%s", prefix, theKey), ctx);
980 if("relationship-list".equals(theKey)){
981 Map<String, Object> relationshipList = (Map<String, Object>)value;
982 // we are interested in seeing just the selected relationship
983 if(theKey.equals(modifier)) {
984 List<?> relationships = (List<?>)relationshipList.get("relationship");
985 if(relationships != null && !relationships.isEmpty()) {
987 List newRelationships = new LinkedList();
988 newRelationships.addAll(relationships);
990 for(Object obj : newRelationships){
991 if(obj instanceof Map<?, ?>) {
992 Map<?, ?> relProperties = (Map<?, ?>)obj;
993 if(relProperties.containsKey("related-to")) {
994 Object relPropsRelatedTo = relProperties.get("related-to");
996 String relatedTo = nameValues.get("related_to");
997 if(relatedTo != null) {
998 relatedTo = relatedTo.trim().replace("'", "").replace("$", "").replace("'", "");
999 if(!relatedTo.equals(relPropsRelatedTo)) {
1000 relationships.remove(relProperties);
1011 writeMap(relationshipList, String.format("%s.%s", prefix, theKey), ctx);
1015 if(value instanceof Map) {
1016 Map<String, Object> subnetsList = (Map<String, Object>)value;
1017 writeMap(subnetsList, String.format("%s.%s", prefix, theKey), ctx);
1022 return QueryStatus.SUCCESS;
1026 public QueryStatus newModelBackupRequest(String resource, Map<String, String> params, String prefix, SvcLogicContext ctx) {
1028 QueryStatus retval = QueryStatus.SUCCESS;
1029 HashMap<String, String> nameValues = new HashMap<>();
1032 AAIRequest request = AAIRequest.createRequest(resource, nameValues);
1033 if(request == null) {
1034 return QueryStatus.FAILURE;
1037 boolean argsFound = false;
1038 String[] arguments = request.getArgsList();
1039 for(String name : arguments) {
1040 String tmpName = name.replaceAll("-", "_");
1041 String value = params.get(tmpName);
1042 if(value != null && !value.isEmpty()) {
1043 value = value.trim().replace("'", "").replace("$", "").replace("'", "");
1044 request.addRequestProperty(name, value);
1049 getLogger().warn("No arguments were found. Terminating backup request.");
1050 return QueryStatus.FAILURE;
1053 String rv = getExecutor().get(request);
1054 ctx.setAttribute(prefix, rv);
1055 } catch(AAIServiceException aaiexc) {
1056 if(aaiexc.getReturnCode() == 404)
1057 return QueryStatus.NOT_FOUND;
1059 return QueryStatus.FAILURE;
1060 } catch (Exception exc) {
1061 getLogger().warn("newModelBackupRequest", exc);
1062 return QueryStatus.FAILURE;
1068 public AAIDatum newModelObjectRequest(String resource, Map<String, String> params, String prefix, SvcLogicContext ctx)
1069 throws AAIServiceException {
1071 AAIDatum response = null;
1074 AAIRequest request = AAIRequest.createRequest(resource, params);
1075 if(request == null) {
1079 request.processRequestPathValues(params);
1080 String rv = getExecutor().get(request);
1081 response = request.jsonStringToObject(rv);
1082 } catch(AAIServiceException aaiexc) {
1084 } catch (Exception exc) {
1085 getLogger().warn("newModelBackupRequest", exc);
1086 throw new AAIServiceException(exc);
1094 public QueryStatus release(String arg0, String arg1, SvcLogicContext arg2) throws SvcLogicException {
1095 // TODO Auto-generated method stub
1096 throw new SvcLogicException("Method AAIService.release() has not been implemented yet");
1100 public QueryStatus reserve(String arg0, String arg1, String arg2, String arg3, SvcLogicContext arg4)
1101 throws SvcLogicException {
1102 // TODO Auto-generated method stub
1103 throw new SvcLogicException("Method AAIService.reserve() has not been implemented yet");
1106 private QueryStatus newModelSave(String resource, boolean force, String key, Map<String, String> params, String prefix, SvcLogicContext ctx) {
1107 getLogger().debug("Executing newModelSave for resource : " + resource);
1108 HashMap<String, String> nameValues = AAIServiceUtils.keyToHashMap(key, ctx);
1111 ArrayList<String> subResources = new ArrayList<>();
1112 Set<String> set = params.keySet();
1113 Map<String, Method> setters = new HashMap<>();
1114 Map<String, Method> getters = new HashMap<>();
1117 AAIRequest request = AAIRequest.createRequest(resource, nameValues);
1118 Class<? extends AAIDatum> resourceClass = request.getModelClass();
1119 getLogger().debug(resourceClass.getName());
1120 AAIDatum instance = resourceClass.newInstance();
1123 Annotation[] annotations = resourceClass.getAnnotations();
1124 for(Annotation annotation : annotations) {
1125 Class<? extends Annotation> anotationType = annotation.annotationType();
1126 String annotationName = anotationType.getName();
1128 // 2. find string property setters and getters for the lists
1129 if("javax.xml.bind.annotation.XmlType".equals(annotationName)){
1130 XmlType order = (XmlType)annotation;
1131 String[] values = order.propOrder();
1132 for(String value : values) {
1133 String id = AAIServiceUtils.camelCaseToDashedString(value);
1134 Field field = resourceClass.getDeclaredField(value);
1135 Class<?> type = field.getType();
1136 Method setter = null;
1138 setter = resourceClass.getMethod("set"+StringUtils.capitalize(value), type);
1139 if(type.getName().startsWith("java.lang") || "boolean".equals(type.getName()) || "long".equals(type.getName())) {
1141 setter.setAccessible(true);
1142 Object arglist[] = new Object[1];
1143 arglist[0] = params.get(id);
1145 if(arglist[0] != null) {
1146 if(!type.getName().equals("java.lang.String")) {
1147 // getLogger().debug(String.format("Processing %s with parameter %s", types[0].getName(), value));
1148 if("boolean".equals(type.getName())) {
1149 arglist[0] = valueOf(Boolean.class, params.get(id));
1150 } else if("long".equals(type.getName())) {
1151 arglist[0] = valueOf(Long.class, params.get(id));
1153 arglist[0] = valueOf(type, params.get(id));
1156 Object o = setter.invoke(instance, arglist);
1160 } catch (Exception x) {
1161 Throwable cause = x.getCause();
1162 getLogger().warn("Failed process for " + resourceClass.getName(), x);
1164 } else if(type.getName().equals("java.util.List")) {
1165 List<String> newValues = new ArrayList<>();
1166 String length = id+"_length";
1167 if(!params.isEmpty() && params.containsKey(length)) {
1168 String tmp = params.get(length);
1169 int count = Integer.parseInt(tmp);
1170 for(int i=0; i<count; i++) {
1171 String tmpValue = params.get(String.format("%s[%d]", id, i));
1172 newValues.add(tmpValue);
1174 if(!newValues.isEmpty()) {
1175 Object o = setter.invoke(instance, newValues);
1180 setters.put(id, setter);
1182 } catch(Exception exc) {
1188 getter = resourceClass.getMethod("get"+StringUtils.capitalize(value));
1189 if(!type.getName().equals("java.lang.String")) {
1190 getters.put(id, getter);
1192 } catch(Exception exc) {
1197 subResources.addAll(Arrays.asList(values));
1202 // remove getters that have matching setter
1203 for(String setKey : setters.keySet()) {
1204 if(getters.containsKey(setKey)) {
1205 getters.remove(setKey);
1209 Set<String> relationshipKeys = new TreeSet<>();
1210 Set<String> vlansKeys = new TreeSet<>();
1211 Set<String> metadataKeys = new TreeSet<>();
1213 for(String attribute : set) {
1214 String value = params.get(attribute);
1215 if(attribute.startsWith("relationship-list")) {
1216 relationshipKeys.add(attribute);
1217 } else if(attribute.startsWith("vlans")) {
1218 vlansKeys.add(attribute);
1219 } else if(attribute.startsWith("metadata")) {
1220 metadataKeys.add(attribute);
1223 // 3. find list property getters
1224 for(String attribute : set) {
1225 String value = params.get(attribute);
1226 Method method = getters.get(attribute);
1227 if(method != null) {
1229 method.setAccessible(true);
1230 Object arglist[] = new Object[0];
1231 // arglist[0] = value;
1232 Class<?>[] types = method.getParameterTypes();
1233 if(types.length == 0){
1234 Object o = method.invoke(instance, arglist);
1235 if(o instanceof ArrayList) {
1236 ArrayList<String> values = (ArrayList<String>)o;
1237 // getLogger().debug(String.format("Processing %s with parameter %s", types[0].getName(), value));
1238 value = value.replace("[", "").replace("]", "");
1239 List<String> items = Arrays.asList(value.split("\\s*,\\s*"));
1240 for(String s : items) {
1241 values.add(s.trim());
1245 } catch (Exception x) {
1246 Throwable cause = x.getCause();
1247 getLogger().warn("Failed process for " + resourceClass.getName(), x);
1251 // 4. Process Relationships
1252 // add relationship list
1253 if( (subResources.contains("relationship-list") || subResources.contains("relationshipList")) && !relationshipKeys.isEmpty()) {
1254 RelationshipList relationshipList = null;
1256 Method getRelationshipListMethod = null;
1258 getRelationshipListMethod = resourceClass.getMethod("getRelationshipList");
1259 } catch(Exception exc) {
1260 getLogger().debug("Retrofiting relationship data: " + exc.getMessage());
1263 if(getRelationshipListMethod != null){
1265 getRelationshipListMethod.setAccessible(true);
1266 obj = getRelationshipListMethod.invoke(instance);
1267 } catch (InvocationTargetException x) {
1268 Throwable cause = x.getCause();
1271 if(obj != null && obj instanceof RelationshipList){
1272 relationshipList = (RelationshipList)obj;
1274 relationshipList = new RelationshipList();
1275 Method setRelationshipListMethod = resourceClass.getMethod("setRelationshipList", RelationshipList.class);
1276 if(setRelationshipListMethod != null){
1278 setRelationshipListMethod.setAccessible(true);
1279 Object arglist[] = new Object[1];
1280 arglist[0] = relationshipList;
1282 obj = setRelationshipListMethod.invoke(instance, arglist);
1283 } catch (InvocationTargetException x) {
1284 Throwable cause = x.getCause();
1289 List<Relationship> relationships = relationshipList.getRelationship();
1293 String searchKey = "relationship-list.relationship[" + i + "].related-to";
1294 if(!params.containsKey(searchKey))
1297 String relatedTo = params.get(searchKey);
1298 String relatedLinkKey = "relationship-list.relationship[" + i + "].related-link";
1299 String relatedLink = null;
1300 if(params.containsKey(relatedLinkKey)) {
1301 relatedLink = params.get(relatedLinkKey);
1303 Relationship relationship = new Relationship();
1304 relationships.add(relationship);
1305 relationship.setRelatedTo(relatedTo);
1306 if(relatedLink != null) {
1307 relationship.setRelatedLink(relatedLink);
1309 Map<String, String> relParams = new HashMap<>();
1312 String searchRelationshipKey = "relationship-list.relationship[" + i + "].relationship-data[" + j + "].relationship-key";
1313 String searchRelationshipValue = "relationship-list.relationship[" + i + "].relationship-data[" + j + "].relationship-value";
1314 if(!params.containsKey(searchRelationshipKey))
1317 relParams.put(params.get(searchRelationshipKey), params.get(searchRelationshipValue));
1320 AAIRequest rlRequest = AAIRequest.createRequest(relatedTo, relParams);
1321 for(Map.Entry<String,String> entry : relParams.entrySet()) {
1322 rlRequest.addRequestProperty(entry.getKey(), entry.getValue());
1324 String path = rlRequest.updatePathDataValues(null);
1325 relationship.setRelatedLink(path);
1329 // process related to properties
1330 Map<String, String> relParams = new HashMap<String, String>();
1333 String searchRelatedToKey = "relationship-list.relationship[" + i + "].related-to-property[" + k + "].property-key";
1334 String searchRelatedToValue = "relationship-list.relationship[" + i + "].related-to-property[" + k + "].property-value";
1335 if(!params.containsKey(searchRelatedToKey))
1338 RelatedToProperty relDatum = new RelatedToProperty();
1339 relDatum.setPropertyKey(params.get(searchRelatedToKey));
1340 relDatum.setPropertyValue(params.get(searchRelatedToValue));
1341 relationship.getRelatedToProperty().add(relDatum);
1343 relParams.put(params.get(searchRelatedToKey), params.get(searchRelatedToValue));
1352 if(subResources.contains("vlans") && !vlansKeys.isEmpty()) {
1354 Vlans vlanList = null;
1355 Method getVLansMethod = resourceClass.getMethod("getVlans");
1356 if(getVLansMethod != null){
1358 getVLansMethod.setAccessible(true);
1359 obj = getVLansMethod.invoke(instance);
1360 } catch (InvocationTargetException x) {
1361 Throwable cause = x.getCause();
1364 if(obj != null && obj instanceof Vlans){
1365 vlanList = (Vlans)obj;
1367 vlanList = new Vlans();
1368 Method setVlansMethod = resourceClass.getMethod("setVlans", Vlans.class);
1369 if(setVlansMethod != null){
1371 setVlansMethod.setAccessible(true);
1372 Object arglist[] = new Object[1];
1373 arglist[0] = vlanList;
1375 obj = setVlansMethod.invoke(instance, arglist);
1376 } catch (InvocationTargetException x) {
1377 Throwable cause = x.getCause();
1384 String searchKey = "vlans.vlan[" + i + "].vlan-interface";
1385 if(!params.containsKey(searchKey))
1388 String vlanInterface = params.get("vlans.vlan[" + i + "].vlan-interface");
1389 String vlanIdInner = params.get("vlans.vlan[" + i + "].vlan-id-inner");
1390 String vlanIdOute = params.get("vlans.vlan[" + i + "].vlan-id-outer");
1391 String speedValue = params.get("vlans.vlan[" + i + "].speed-value");
1392 String speedUnits = params.get("vlans.vlan[" + i + "].speed-units");
1394 Vlan vlan = new Vlan();
1395 vlan.setVlanInterface(vlanInterface);
1397 if(vlanIdInner != null) {
1398 Long iVlanIdInner = Long.parseLong(vlanIdInner);
1399 vlan.setVlanIdInner(iVlanIdInner);
1402 if(vlanIdOute != null) {
1403 Long iVlanIdOuter = Long.parseLong(vlanIdOute);
1404 vlan.setVlanIdOuter(iVlanIdOuter);
1407 if(speedValue != null) {
1408 vlan.setSpeedValue(speedValue);
1409 vlan.setSpeedUnits(speedUnits);
1412 vlanList.getVlan().add(vlan);
1418 if(subResources.contains("metadata") && !metadataKeys.isEmpty()) {
1420 Metadata metadataList = null;
1421 Method getMetadataMethod = resourceClass.getMethod("getMetadata");
1422 if(getMetadataMethod != null){
1424 getMetadataMethod.setAccessible(true);
1425 obj = getMetadataMethod.invoke(instance);
1426 } catch (InvocationTargetException x) {
1427 Throwable cause = x.getCause();
1430 if(obj != null && obj instanceof Metadata){
1431 metadataList = (Metadata)obj;
1433 metadataList = new Metadata();
1434 Method setMetadataMethod = resourceClass.getMethod("setMetadata", Metadata.class);
1435 if(setMetadataMethod != null){
1437 setMetadataMethod.setAccessible(true);
1438 Object arglist[] = new Object[1];
1439 arglist[0] = metadataList;
1441 obj = setMetadataMethod.invoke(instance, arglist);
1442 } catch (InvocationTargetException x) {
1443 Throwable cause = x.getCause();
1448 if(metadataList.getMetadatum() == null) {
1449 // metadataList.setMetadatum(new ArrayList<Metadatum>());
1455 String metaKey = "metadata.metadatum[" + i + "].meta-key";
1456 if(!params.containsKey(metaKey))
1459 String metaValue = params.get("metadata.metadatum[" + i + "].meta-value");
1461 Metadatum vlan = new Metadatum();
1462 vlan.setMetaname(metaKey);
1463 vlan.setMetaval(metaValue);
1465 metadataList.getMetadatum().add(vlan);
1472 // 6. Prepare AAI request
1473 String[] args = request.getArgsList();
1474 for(String arg : args) {
1475 String modifiedKey = arg.replaceAll("-", "_");
1476 if(nameValues.containsKey(modifiedKey)) {
1477 String argValue = nameValues.get(modifiedKey);
1478 if(argValue != null) argValue = argValue.trim().replace("'", "").replace("$", "").replace("'", "");
1479 request.addRequestProperty(arg, argValue);
1483 request.processRequestPathValues(nameValues);
1484 request.setRequestObject(instance);
1485 Object response = getExecutor().post(request);
1486 if(request.expectsDataFromPUTRequest()){
1487 if(response != null && response instanceof String) {
1488 String rv = response.toString();
1489 QueryStatus retval = processResponseData(rv, resource, request, prefix, ctx, nameValues, null);
1490 getLogger().debug("newModelSave - returning " + retval.toString());
1495 } catch(AAIServiceException exc){
1496 ctx.setAttribute(prefix + ".error.message", exc.getMessage());
1497 int returnCode = exc.getReturnCode();
1498 if(returnCode >= 300) {
1499 ctx.setAttribute(prefix + ".error.http.response-code",
1500 Integer.toString(exc.getReturnCode()));
1503 if(returnCode == 400 || returnCode == 412)
1504 return QueryStatus.FAILURE;
1505 else if(returnCode == 404)
1506 return QueryStatus.NOT_FOUND;
1508 getLogger().warn("Failed newModelSave - returning FAILURE", exc);
1509 return QueryStatus.FAILURE;
1511 } catch(Exception exc){
1512 getLogger().warn("Failed newModelSave - returning FAILURE", exc);
1513 ctx.setAttribute(prefix + ".error.message", exc.getMessage());
1514 return QueryStatus.FAILURE;
1517 getLogger().debug("newModelSave - returning SUCCESS");
1518 return QueryStatus.SUCCESS;
1521 private QueryStatus newModelProcessRelationshipList(Object instance, Map<String, String> params, String prefix, SvcLogicContext ctx) throws Exception {
1523 Class resourceClass = instance.getClass();
1525 Set<String> relationshipKeys = new TreeSet<>();
1527 Set<String> set = params.keySet();
1529 for(String attribute : set) {
1530 String value = params.get(attribute);
1532 if(attribute.startsWith("relationship-list")) {
1533 relationshipKeys.add(attribute);
1537 // 3. Process Relationships
1538 // add relationship list
1539 if(!relationshipKeys.isEmpty()) {
1540 RelationshipList relationshipList;
1542 Method getRelationshipListMethod = null;
1544 getRelationshipListMethod = resourceClass.getMethod("getRelationshipList");
1545 } catch(Exception exc) {
1546 getLogger().debug("Retrofiting relationship data: " + exc.getMessage());
1548 if(getRelationshipListMethod != null){
1550 getRelationshipListMethod.setAccessible(true);
1551 obj = getRelationshipListMethod.invoke(instance);
1552 } catch (InvocationTargetException x) {
1553 Throwable cause = x.getCause();
1556 if(obj != null && obj instanceof RelationshipList){
1557 relationshipList = (RelationshipList)obj;
1559 relationshipList = new RelationshipList();
1560 Method setRelationshipListMethod = resourceClass.getMethod("setRelationshipList", RelationshipList.class);
1561 if(setRelationshipListMethod != null){
1563 setRelationshipListMethod.setAccessible(true);
1564 Object arglist[] = new Object[1];
1565 arglist[0] = relationshipList;
1567 obj = setRelationshipListMethod.invoke(instance, arglist);
1568 } catch (InvocationTargetException x) {
1569 Throwable cause = x.getCause();
1574 boolean createdNewRelationships = false;
1575 List<Relationship> relationships = relationshipList.getRelationship();
1576 if(relationships == null) {
1577 relationships = new ArrayList<>();
1578 createdNewRelationships = true;
1583 String searchKey = "relationship-list.relationship[" + i + "].related-to";
1584 if(!params.containsKey(searchKey))
1587 String relatedTo = params.get(searchKey);
1588 String relatedLinkKey = "relationship-list.relationship[" + i + "].related-link";
1589 String relatedLink = null;
1590 if(params.containsKey(relatedLinkKey)) {
1591 relatedLink = params.get(relatedLinkKey);
1594 Relationship relationship = new Relationship();
1595 relationships.add(relationship);
1596 relationship.setRelatedTo(relatedTo);
1597 if (relatedLink != null) {
1598 relationship.setRelatedLink(relatedLink);
1600 Map<String, String> relParams = new HashMap<>();
1604 String searchRelationshipKey = "relationship-list.relationship[" + i + "].relationship-data["
1605 + j + "].relationship-key";
1606 String searchRelationshipValue = "relationship-list.relationship[" + i + "].relationship-data["
1607 + j + "].relationship-value";
1608 if (!params.containsKey(searchRelationshipKey))
1611 RelationshipData relDatum = new RelationshipData();
1612 relDatum.setRelationshipKey(params.get(searchRelationshipKey));
1613 relDatum.setRelationshipValue(params.get(searchRelationshipValue));
1614 relationship.getRelationshipData().add(relDatum);
1616 relParams.put(params.get(searchRelationshipKey), params.get(searchRelationshipValue));
1619 AAIRequest rlRequest = AAIRequest.createRequest(relatedTo, relParams);
1620 for (Map.Entry<String, String> entry : relParams.entrySet()) {
1621 rlRequest.addRequestProperty(entry.getKey(), entry.getValue());
1623 String path = rlRequest.updatePathDataValues(null);
1624 relationship.setRelatedLink(path);
1628 // process related to properties
1629 Map<String, String> relParams = new HashMap<String, String>();
1632 String searchRelatedToKey = "relationship-list.relationship[" + i + "].related-to-property[" + k + "].property-key";
1633 String searchRelatedToValue = "relationship-list.relationship[" + i + "].related-to-property[" + k + "].property-value";
1634 if(!params.containsKey(searchRelatedToKey))
1637 RelatedToProperty relDatum = new RelatedToProperty();
1638 relDatum.setPropertyKey(params.get(searchRelatedToKey));
1639 relDatum.setPropertyValue(params.get(searchRelatedToValue));
1640 relationship.getRelatedToProperty().add(relDatum);
1642 relParams.put(params.get(searchRelatedToKey), params.get(searchRelatedToValue));
1651 return QueryStatus.SUCCESS;
1654 private QueryStatus newModelProcessMetadata(Object instance, Map<String, String> params, String prefix, SvcLogicContext ctx) throws Exception {
1656 if (!(instance instanceof ServiceInstance) && !(instance instanceof Image)) {
1657 throw new IllegalArgumentException("request is not applicable for selected request");
1660 Class resourceClass = instance.getClass();
1661 Set<String> metadataKeys = new TreeSet<String>();
1662 Set<String> set = params.keySet();
1663 for(String attribute : set) {
1664 if(attribute.startsWith("metadata")) {
1665 metadataKeys.add(attribute);
1669 // 3. Process Metadata
1671 if(!metadataKeys.isEmpty()) {
1672 Metadata metadata = null;
1674 Method getMetadataMethod = resourceClass.getMethod("getMetadata");
1675 if(getMetadataMethod != null){
1677 getMetadataMethod.setAccessible(true);
1678 obj = getMetadataMethod.invoke(instance);
1679 } catch (InvocationTargetException x) {
1680 Throwable cause = x.getCause();
1683 if(obj != null && obj instanceof Metadata){
1684 metadata = (Metadata)obj;
1686 metadata = new Metadata();
1687 Method setMetadataMethod = resourceClass.getMethod("setMetadata", Metadata.class);
1688 if(setMetadataMethod != null){
1690 setMetadataMethod.setAccessible(true);
1691 setMetadataMethod.invoke(instance, metadata);
1692 } catch (InvocationTargetException x) {
1697 List<Metadatum> metadatumList = metadata.getMetadatum();
1700 String metaNameKey = "metadata.metadatum[" + i + "].metaname";
1701 String metaValueKey = "metadata.metadatum[" + i + "].metaval";
1702 if(!params.containsKey(metaNameKey) || !params.containsKey(metaValueKey))
1705 Metadatum metadatum = new Metadatum();
1706 metadatum.setMetaname(params.get(metaNameKey));
1707 metadatum.setMetaval(params.get(metaValueKey));
1708 metadatumList.add(metadatum);
1714 return QueryStatus.SUCCESS;
1717 private Relationship findRelationship(List<Relationship> relationships, String relatedTo) {
1718 if(relatedTo == null)
1721 for(Relationship relationship : relationships) {
1722 if(relationship.getRelatedTo().equals(relatedTo)){
1723 return relationship;
1730 public QueryStatus backup(Map<String, String> params, SvcLogicContext ctx) throws SvcLogicException {
1731 String resource = params.get("resource").toLowerCase();
1732 String prefix = params.get("data-key");
1734 HashMap<String, String> nameValues = new HashMap<>();
1735 if(AAIRequest.createRequest(resource, nameValues) != null) {
1738 return newModelBackupRequest(resource, params, prefix, ctx);
1739 } catch (Exception exc) {
1740 getLogger().warn("Failed backup - returning FAILURE", exc);
1741 return QueryStatus.FAILURE;
1745 return QueryStatus.NOT_FOUND;
1749 public QueryStatus restore(Map<String, String> params, SvcLogicContext ctx) throws SvcLogicException {
1751 QueryStatus retval = QueryStatus.SUCCESS;
1752 String resource = params.get("resource").toLowerCase();
1753 String prefix = params.get("data-key");
1755 HashMap<String, String> nameValues = new HashMap<>();
1756 if(AAIRequest.createRequest(resource, nameValues) != null) {
1759 retval = newModelBackupRequest(resource, params, "tmpRestore", ctx);
1760 if(retval == QueryStatus.SUCCESS) {
1761 String current_json = ctx.getAttribute("tmpRestore");
1762 ctx. setAttribute("tmpRestore", null);
1764 String snapshot_json = ctx.getAttribute(prefix);
1766 } catch (Exception exc) {
1767 getLogger().warn("Failed restore - returning FAILURE", exc);
1768 return QueryStatus.FAILURE;
1772 return QueryStatus.NOT_FOUND;
1775 protected Map<String, Object> objectToProperties(Object object) {
1776 ObjectMapper mapper = AAIService.getObjectMapper();
1777 return mapper.convertValue(object, Map.class);
1780 static <T> T valueOf(Class<T> klazz, String arg) {
1781 Exception cause = null;
1784 ret = klazz.cast(klazz.getDeclaredMethod("valueOf", String.class).invoke(null, arg));
1785 } catch (NoSuchMethodException exc) {
1786 LoggerFactory.getLogger(AAIService.class).warn("Wrong data type", exc);
1787 ret = klazz.cast(arg);
1788 } catch (IllegalAccessException e) {
1790 } catch (InvocationTargetException e) {
1793 if (cause == null) {
1796 throw new IllegalArgumentException(cause);
1800 private QueryStatus processDeleteRelationshipList(String resource, String key, SvcLogicContext ctx, HashMap<String, String> nameValues) {
1802 AAIRequest request = AAIRequest.createRequest(resource, nameValues);
1803 if(request == null) {
1804 return QueryStatus.FAILURE;
1807 request.processRequestPathValues(nameValues);
1808 URL url = request.getRequestUrl("GET", null);
1810 Class resourceClass = request.getModelClass();
1811 Object instance = getResource(url.toString(), resourceClass);
1812 if(instance == null)
1813 return QueryStatus.NOT_FOUND;
1815 // get resource version
1816 String resourceVersion = null;
1817 Method getResourceVersionMethod = resourceClass.getMethod("getResourceVersion");
1818 if(getResourceVersionMethod != null){
1820 getResourceVersionMethod.setAccessible(true);
1821 Object object = getResourceVersionMethod.invoke(instance);
1823 resourceVersion = object.toString();
1824 } catch (InvocationTargetException x) {
1825 Throwable cause = x.getCause();
1829 RelationshipList relationshipList = null;
1831 Method getRelationshipListMethod = null;
1833 getRelationshipListMethod = resourceClass.getMethod("getRelationshipList");
1834 } catch(Exception exc) {
1835 getLogger().debug("Retrofiting relationship data: " + exc.getMessage());
1837 if(getRelationshipListMethod != null){
1839 getRelationshipListMethod.setAccessible(true);
1840 obj = getRelationshipListMethod.invoke(instance);
1841 } catch (InvocationTargetException x) {
1842 Throwable cause = x.getCause();
1845 if(obj != null && obj instanceof RelationshipList){
1846 relationshipList = (RelationshipList)obj;
1848 getLogger().debug("No relationships found to process.");
1849 return QueryStatus.NOT_FOUND;
1852 if(relationshipList.getRelationship() == null || relationshipList.getRelationship().isEmpty()) {
1853 return QueryStatus.NOT_FOUND;
1855 String relatedTo = nameValues.get("related_to");
1856 if(relatedTo == null) {
1857 return QueryStatus.FAILURE;
1860 relatedTo = relatedTo.replaceAll("_", "-");
1862 String relatedLink = nameValues.get("relationship.related_link");
1863 if(relatedLink != null) {
1864 relatedLink = URLDecoder.decode(relatedLink, "UTF-8");
1867 List<Relationship> relationships = relationshipList.getRelationship();
1868 List<Relationship> relationshipsToDelete = new LinkedList<>();
1870 for(Relationship relationship : relationships) {
1871 if(relatedTo.equals(relationship.getRelatedTo())) {
1872 if(relatedLink != null) {
1873 if(relationship.getRelatedLink() != null ) {
1874 String localRelatedLink = relationship.getRelatedLink();
1875 localRelatedLink = URLDecoder.decode(localRelatedLink, "UTF-8");
1876 if(localRelatedLink.endsWith(relatedLink)) {
1877 getLogger().debug(String.format("Found relationship of '%s' to keyword '%s'", relationship.getRelatedTo(), relatedTo));
1878 relationshipsToDelete.add(relationship);
1882 getLogger().debug(String.format("Found relationship of '%s' to keyword '%s'", relationship.getRelatedTo(), relatedTo));
1883 relationshipsToDelete.add(relationship);
1887 if(relationshipsToDelete == null || relationshipsToDelete.isEmpty()) {
1888 getLogger().info(String.format("Relationship has not been found for %s", key));
1889 return QueryStatus.NOT_FOUND;
1892 String path = url.toString();
1893 path = path + "/relationship-list/relationship";
1894 URL deleteUrl = new URL(path);
1896 ObjectMapper mapper = AAIService.getObjectMapper();
1898 boolean cumulativeResponse = true;
1900 for(Relationship targetRelationship : relationshipsToDelete) {
1901 String json_text = mapper.writeValueAsString(targetRelationship);
1902 boolean response = deleteList(deleteUrl, json_text);
1904 cumulativeResponse = response;
1908 if(!cumulativeResponse)
1909 return QueryStatus.FAILURE;
1911 return QueryStatus.SUCCESS;
1913 } catch(Exception exc) {
1914 getLogger().warn("processDelete", exc);
1915 return QueryStatus.FAILURE;
1919 private QueryStatus processDeleteMetadata(String resource, String key, SvcLogicContext ctx, HashMap<String, String> nameValues) {
1921 AAIRequest request = AAIRequest.createRequest(resource, nameValues);
1922 if(request == null) {
1923 return QueryStatus.FAILURE;
1926 request.processRequestPathValues(nameValues);
1927 URL url = request.getRequestUrl("GET", null);
1929 Class resourceClass = request.getModelClass();
1930 Object instance = getResource(url.toString(), resourceClass);
1932 // get resource version
1933 String resourceVersion = null;
1934 Method getResourceVersionMethod = resourceClass.getMethod("getResourceVersion");
1935 if(getResourceVersionMethod != null){
1937 getResourceVersionMethod.setAccessible(true);
1938 resourceVersion = (String) getResourceVersionMethod.invoke(instance);
1939 } catch (InvocationTargetException x) {
1943 Metadata metadata = null;
1945 Method getMetadataMethod = resourceClass.getMethod("getMetadata");
1946 if(getMetadataMethod != null){
1948 getMetadataMethod.setAccessible(true);
1949 obj = getMetadataMethod.invoke(instance);
1950 } catch (InvocationTargetException x) {
1951 Throwable cause = x.getCause();
1954 if(obj != null && obj instanceof Metadata){
1955 metadata = (Metadata)obj;
1957 getLogger().debug("No metadata found to process.");
1958 return QueryStatus.NOT_FOUND;
1961 if(metadata.getMetadatum() == null || metadata.getMetadatum().isEmpty()) {
1962 return QueryStatus.NOT_FOUND;
1965 List<Metadatum> metadatumList = metadata.getMetadatum();
1966 Metadatum metadatumToDelete = null;
1968 final String metaname = nameValues.get("metaname");
1970 for(Metadatum metadatum : metadatumList) {
1971 getLogger().debug(String.format("Comparing existing metadatum of '%s' to keyword '%s'", metadatum.getMetaname(), metaname));
1972 if(metaname.equals(metadatum.getMetaname())) {
1973 metadatumToDelete = metadatum;
1977 if(metadatumToDelete == null) {
1978 getLogger().info(String.format("Metadatum has not been found for %s", key));
1979 return QueryStatus.NOT_FOUND;
1982 String path = url.toString();
1983 path = path + "/metadata/metadatum/" + encodeQuery( metadatumToDelete.getMetaname() ) +
1984 "?resource-version=" + metadatumToDelete.getResourceVersion();
1985 URL deleteUrl = new URL(path);
1986 boolean response = deleteList(deleteUrl, null);
1989 return QueryStatus.FAILURE;
1991 return QueryStatus.SUCCESS;
1993 } catch(Exception exc) {
1994 getLogger().warn("processDelete", exc);
1995 return QueryStatus.FAILURE;
1999 protected String encodeQuery(String param) throws UnsupportedEncodingException {
2000 return URLEncoder.encode(param, "UTF-8").replace("+", "%20");
2003 static final Map<String, String> ctxGetBeginsWith( SvcLogicContext ctx, String prefix ) {
2004 Map<String, String> tmpPrefixMap = new HashMap<>();
2006 if(prefix == null || prefix.isEmpty()){
2007 return tmpPrefixMap;
2010 for( String key : ctx.getAttributeKeySet() ) {
2011 if( key.startsWith(prefix) ) {
2012 String tmpKey = key.substring(prefix.length() + 1);
2013 tmpPrefixMap.put( tmpKey, ctx.getAttribute(key));
2017 Map<String, String> prefixMap = new HashMap<>();
2018 Pattern p = Pattern.compile(".*\\[\\d\\]");
2020 SortedSet<String> keys = new TreeSet(tmpPrefixMap.keySet () );
2021 for(String key : keys) {
2022 Matcher m = p.matcher(key);
2025 } else if(key.endsWith("_length")) {
2026 String listKey = key.substring(0, key.indexOf("_length"));
2027 int max = Integer.parseInt(tmpPrefixMap.get(key));
2029 ArrayList<String> data = new ArrayList<>();
2030 for(int x = 0; x < max; x++){
2031 String tmpKey = String.format("%s[%d]", listKey, x);
2032 String tmpValue = tmpPrefixMap.get(tmpKey);
2033 if(tmpValue != null && !tmpValue.isEmpty()) {
2037 if(!data.isEmpty()) {
2038 prefixMap.put(listKey, data.toString());
2040 prefixMap.put(key, tmpPrefixMap.get(key));
2043 prefixMap.put(key, tmpPrefixMap.get(key));
2052 protected NamedQueryData extractNamedQueryDataFromQueryPrefix(HashMap<String, String> nameValues, Map<String, String> parms) {
2053 if(parms.isEmpty()) {
2057 NamedQueryData data = new NamedQueryData();
2060 if(data.getQueryParameters() == null) {
2061 data.setQueryParameters(new QueryParameters());
2063 String namedQueryUuid = nameValues.get("named-query-uuid".replaceAll("-", "_"));
2064 if(namedQueryUuid == null) {
2065 namedQueryUuid = parms.get("query-parameters.named-query.named-query-uuid");
2067 NamedQuery namedQuery = new NamedQuery();
2068 namedQuery.setNamedQueryUuid(namedQueryUuid);
2069 data.getQueryParameters().setNamedQuery(namedQuery);
2072 if(data.getInstanceFilters() == null) {
2073 data.setInstanceFilters(new InstanceFilters());
2077 String quantity = parms.get("instance-filters.instance-filter_length");
2078 if(quantity != null && StringUtils.isNumeric(quantity)) {
2079 int max = Integer.parseInt(quantity);
2080 for(int i = 0; i < max; i++) {
2081 String keyPattern = String.format("instance-filters.instance-filter[%d].", i);
2082 Set<String> keys = parms.keySet();
2083 for(String key: keys) {
2084 if(key.startsWith(keyPattern)){
2085 String value = parms.get(key);
2086 String remainder = key.substring(keyPattern.length());
2087 String[] split = remainder.split("\\.");
2088 getLogger().debug(String.format("%s", remainder));
2089 if("logical-link".equals(split[0])) {
2090 InstanceFilter insf = null;
2091 if(data.getInstanceFilters().getInstanceFilter().isEmpty()) {
2092 insf = new InstanceFilter();
2093 data.getInstanceFilters().getInstanceFilter().add(insf);
2095 insf = data.getInstanceFilters().getInstanceFilter().get(0);
2097 LogicalLink logicalLink = insf.getLogicalLink();
2098 if(logicalLink == null) {
2099 logicalLink = new LogicalLink();
2100 insf.setLogicalLink(logicalLink);
2105 logicalLink.setLinkName(value);
2108 logicalLink.setLinkType(value);
2110 case "operational-state":
2111 logicalLink.setOperationalStatus(value);
2115 } else if("pnf".equals(split[0])) {
2116 Pnf pnf = new Pnf();
2117 pnf.setPnfName(value);
2119 InstanceFilter insf = new InstanceFilter();
2121 data.getInstanceFilters().getInstanceFilter().add(insf);
2123 } else if("service-instance".equals(split[0])) {
2124 ServiceInstance serviceInstance = new ServiceInstance();
2125 serviceInstance.setServiceInstanceId(value);
2127 InstanceFilter insf = new InstanceFilter();
2128 insf.setServiceInstance(serviceInstance);
2129 data.getInstanceFilters().getInstanceFilter().add(insf);
2131 } else if("l3-network".equals(split[0])) {
2132 L3Network l3Network = new L3Network();
2133 if("network-role".equals(split[1])) {
2134 l3Network.setNetworkRole(value);
2137 InstanceFilter insf = new InstanceFilter();
2138 insf.setL3Network(l3Network);
2139 data.getInstanceFilters().getInstanceFilter().add(insf);
2140 } else if("generic-vnf".equals(split[0])) {
2141 GenericVnf vnf = new GenericVnf();
2142 if("vnf-id".equals(split[1])) {
2143 vnf.setVnfId(value);
2146 InstanceFilter insf = new InstanceFilter();
2147 insf.setGenericVnf(vnf);
2148 data.getInstanceFilters().getInstanceFilter().add(insf);
2158 public abstract <T> T getResource(String key, Class<T> type) throws AAIServiceException ;
2159 protected abstract boolean deleteList(URL url, String caller) throws AAIServiceException;