* ============LICENSE_START=======================================================
* openECOMP : SDN-C
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * Copyright (C) 2019 AT&T Intellectual Property. All rights
* reserved.
* ================================================================================
+ * Modifications Copyright (C) 2019 IBM.
+ * ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* ============LICENSE_END=========================================================
*/
+/**
+ * @author Rich Tabedzki
+ *
+ */
package org.onap.ccsdk.sli.adaptors.aai;
import java.io.IOException;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.lang.NoSuchMethodException;
import java.net.MalformedURLException;
import java.net.URISyntaxException;
import java.net.URL;
import org.apache.commons.lang.StringUtils;
import org.onap.ccsdk.sli.adaptors.aai.data.AAIDatum;
import org.onap.ccsdk.sli.adaptors.aai.query.FormattedQueryResultList;
-import org.onap.ccsdk.sli.adaptors.aai.query.InstanceFilter;
-import org.onap.ccsdk.sli.adaptors.aai.query.InstanceFilters;
-import org.onap.ccsdk.sli.adaptors.aai.query.NamedQuery;
-import org.onap.ccsdk.sli.adaptors.aai.query.NamedQueryData;
-import org.onap.ccsdk.sli.adaptors.aai.query.QueryParameters;
import org.onap.ccsdk.sli.adaptors.aai.query.Result;
import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
import org.onap.ccsdk.sli.core.sli.SvcLogicException;
-import org.onap.aai.inventory.v14.GenericVnf;
-import org.onap.aai.inventory.v14.Image;
-import org.onap.aai.inventory.v14.InventoryResponseItem;
-import org.onap.aai.inventory.v14.InventoryResponseItems;
-import org.onap.aai.inventory.v14.L3Network;
-import org.onap.aai.inventory.v14.LogicalLink;
-import org.onap.aai.inventory.v14.Metadata;
-import org.onap.aai.inventory.v14.Metadatum;
-import org.onap.aai.inventory.v14.Pnf;
-import org.onap.aai.inventory.v14.RelatedToProperty;
-import org.onap.aai.inventory.v14.Relationship;
-import org.onap.aai.inventory.v14.RelationshipData;
-import org.onap.aai.inventory.v14.RelationshipList;
-import org.onap.aai.inventory.v14.ResultData;
-import org.onap.aai.inventory.v14.SearchResults;
-import org.onap.aai.inventory.v14.ServiceInstance;
-import org.onap.aai.inventory.v14.Vlan;
-import org.onap.aai.inventory.v14.Vlans;
-import org.onap.aai.inventory.v14.Vserver;
+import org.onap.aai.inventory.v21.GenericVnf;
+import org.onap.aai.inventory.v21.Image;
+import org.onap.aai.inventory.v21.Metadata;
+import org.onap.aai.inventory.v21.Metadatum;
+import org.onap.aai.inventory.v21.RelatedToProperty;
+import org.onap.aai.inventory.v21.Relationship;
+import org.onap.aai.inventory.v21.RelationshipData;
+import org.onap.aai.inventory.v21.RelationshipList;
+import org.onap.aai.inventory.v21.ResultData;
+import org.onap.aai.inventory.v21.SearchResults;
+import org.onap.aai.inventory.v21.ServiceInstance;
+import org.onap.aai.inventory.v21.Vlan;
+import org.onap.aai.inventory.v21.Vlans;
+import org.onap.aai.inventory.v21.Vserver;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
//Service
public static final String SERVICE_PATH = "org.onap.ccsdk.sli.adaptors.aai.path.service";
- // P-Interfaces
- public static final String P_INTERFACE_PATH = "org.onap.ccsdk.sli.adaptors.aai.path.pserver.pinterface";
-
// site-pair-sets
public static final String SITE_PAIR_SET_PATH = "org.onap.ccsdk.sli.adaptors.aai.path.site.pair.set";
private static final String VERSION_PATTERN = "/v$/";
+ private static final String AAI_SERVICE_EXCEPTION = "AAI Service Exception";
protected abstract Logger getLogger();
public abstract AAIExecutorInterface getExecutor();
+ private static final String RELATIONSHIP_DATA= "Retrofitting relationship data: ";
+
@Override
public QueryStatus query(String resource, boolean localOnly, String select, String key, String prefix, String orderBy, SvcLogicContext ctx)
- throws SvcLogicException {
+ throws SvcLogicException {
getLogger().debug("AAIService.query \tresource = "+resource);
} catch (AAIServiceException exc) {
int errorCode = exc.getReturnCode();
switch(errorCode) {
- case 400:
- case 404:
- case 412:
- break;
- default:
- getLogger().warn("Caught exception trying to refresh generic VNF", exc);
+ case 400:
+ case 404:
+ case 412:
+ break;
+ default:
+ getLogger().warn("Caught exception trying to refresh generic VNF", exc);
}
ctx.setAttribute(prefix + ".error.message", exc.getMessage());
if(errorCode >= 300) {
ctx.setAttribute(prefix + ".error.http.response-code",
- Integer.toString(exc.getReturnCode()));
+ Integer.toString(exc.getReturnCode()));
}
return QueryStatus.FAILURE;
}
if(vserverId != null) vserverId = vserverId.trim().replace("'", "").replace("$", "").replace("'", "");
if(tenantId != null) tenantId = tenantId.trim().replace("'", "").replace("$", "").replace("'", "");
- if (vserverName != null) {
- URL vserverUrl = null;
- try {
- vserverUrl = this.requestVserverURLNodeQuery(vserverName);
- } catch (AAIServiceException aaiexc) {
- ctx.setAttribute(prefix + ".error.message", aaiexc.getMessage());
- if (aaiexc.getReturnCode() >= 300) {
- ctx.setAttribute(prefix + ".error.http" + "" + ".response-code", Integer.toString(aaiexc.getReturnCode()));
- }
+ if (vserverName != null) {
+ URL vserverUrl = null;
+ try {
+ vserverUrl = this.requestVserverURLNodeQuery(vserverName);
+ } catch (AAIServiceException aaiexc) {
+ getLogger().warn(AAI_SERVICE_EXCEPTION, aaiexc);
+ ctx.setAttribute(prefix + ".error.message", aaiexc.getMessage());
+ if (aaiexc.getReturnCode() >= 300) {
+ ctx.setAttribute(prefix + ".error.http" + "" + ".response-code", Integer.toString(aaiexc.getReturnCode()));
+ }
- if (aaiexc.getReturnCode() == 404)
+ if (aaiexc.getReturnCode() == 404)
+ return QueryStatus.NOT_FOUND;
+ else
+ return QueryStatus.FAILURE;
+ }
+ if (vserverUrl == null) {
return QueryStatus.NOT_FOUND;
- else
- return QueryStatus.FAILURE;
- }
- if (vserverUrl == null) {
- return QueryStatus.NOT_FOUND;
- }
+ }
- tenantId = getTenantIdFromVserverUrl(vserverUrl);
- String cloudOwner = getCloudOwnerFromVserverUrl(vserverUrl);
- String cloudRegionId = getCloudRegionFromVserverUrl(vserverUrl);
+ tenantId = getTenantIdFromVserverUrl(vserverUrl);
+ String cloudOwner = getCloudOwnerFromVserverUrl(vserverUrl);
+ String cloudRegionId = getCloudRegionFromVserverUrl(vserverUrl);
- Vserver vserver = null;
- try {
- vserver = this.requestVServerDataByURL(vserverUrl);
- } catch (AAIServiceException aaiexc) {
- ctx.setAttribute(prefix + ".error.message", aaiexc.getMessage());
- if (aaiexc.getReturnCode() >= 300) {
- ctx.setAttribute(prefix + ".error.http" + ".response-code", Integer.toString(aaiexc.getReturnCode()));
- }
+ Vserver vserver = null;
+ try {
+ vserver = this.requestVServerDataByURL(vserverUrl);
+ } catch (AAIServiceException aaiexc) {
+ getLogger().warn(AAI_SERVICE_EXCEPTION, aaiexc);
+ ctx.setAttribute(prefix + ".error.message", aaiexc.getMessage());
+ if (aaiexc.getReturnCode() >= 300) {
+ ctx.setAttribute(prefix + ".error.http" + ".response-code", Integer.toString(aaiexc.getReturnCode()));
+ }
- if (aaiexc.getReturnCode() == 404)
+ if (aaiexc.getReturnCode() == 404)
+ return QueryStatus.NOT_FOUND;
+ else
+ return QueryStatus.FAILURE;
+ }
+ if (vserver == null) {
return QueryStatus.NOT_FOUND;
- else
- return QueryStatus.FAILURE;
- }
- if (vserver == null) {
- return QueryStatus.NOT_FOUND;
- }
- attributes = mapper.convertValue(vserver, attributes.getClass());
- if (!attributes.containsKey("tenant-id") && tenantId != null) {
- attributes.put("tenant-id", tenantId);
- }
- if (!attributes.containsKey("cloud-owner") && cloudOwner != null) {
- attributes.put("cloud-owner", cloudOwner);
- }
- if (!attributes.containsKey("cloud-region-id") && cloudRegionId != null) {
- attributes.put("cloud-region-id", cloudRegionId);
- }
- } else if (vserverId != null && tenantId != null) {
+ }
+ attributes = mapper.convertValue(vserver, attributes.getClass());
+ if (!attributes.containsKey("tenant-id") && tenantId != null) {
+ attributes.put("tenant-id", tenantId);
+ }
+ if (!attributes.containsKey("cloud-owner") && cloudOwner != null) {
+ attributes.put("cloud-owner", cloudOwner);
+ }
+ if (!attributes.containsKey("cloud-region-id") && cloudRegionId != null) {
+ attributes.put("cloud-region-id", cloudRegionId);
+ }
+ } else if (vserverId != null && tenantId != null) {
Vserver vserver = this.requestVServerData(tenantId, vserverId, "att-aic", "AAIAIC25");
if(vserver == null) {
return QueryStatus.NOT_FOUND;
if(entity instanceof Map) {
writeMap( (Map<String, Object>)entity, prefix + "[" + i + "]", ctx);
} else
- if(entity instanceof String || entity instanceof Long || entity instanceof Integer || entity instanceof Boolean) {
+ if(entity instanceof String || entity instanceof Long || entity instanceof Integer || entity instanceof Boolean) {
ctx.setAttribute(prefix, entity.toString());
getLogger().debug(prefix + " : " + entity.toString());
}
path = request.getRequestUrl("GET", null);
params.put("vserver-selflink", path.toString());
} catch (UnsupportedEncodingException | MalformedURLException | URISyntaxException e) {
+ getLogger().warn("URL error Exception", e);
params.put("vserver-selflink", "/vserver");
}
}
request.processRequestPathValues(nameValues);
getExecutor().patch(request, resourceVersion);
} catch(AAIServiceException aaiexc) {
+ getLogger().warn(AAI_SERVICE_EXCEPTION, aaiexc);
if(aaiexc.getReturnCode() == 404)
return QueryStatus.NOT_FOUND;
else
return QueryStatus.SUCCESS;
}
} catch(AAIServiceException aaiexc) {
+ getLogger().warn(AAI_SERVICE_EXCEPTION, aaiexc);
if(aaiexc.getReturnCode() == 404)
return QueryStatus.NOT_FOUND;
else
throw new SvcLogicException("Method AAIService.notify() has not been implemented yet");
}
-// @Override
+ // @Override
public QueryStatus newModelQuery(String resource, boolean localOnly, String select, String key, String prefix, String orderBy, SvcLogicContext ctx) {
QueryStatus retval = QueryStatus.SUCCESS;
if(!tmpParams.isEmpty()) {
params.putAll(tmpParams);
}
- if("named-query".equals(resource))
- request.setRequestObject(extractNamedQueryDataFromQueryPrefix(nameValues, params));
}
String rv = getExecutor().get(request);
retval = processResponseData(rv, resource, request, prefix, ctx, nameValues, modifier);
} catch(AAIServiceException aaiexc) {
+ getLogger().warn(AAI_SERVICE_EXCEPTION, aaiexc);
int errorCode = aaiexc.getReturnCode();
ctx.setAttribute(prefix + ".error.message", aaiexc.getMessage());
if(errorCode >= 300) {
{
Object response;
+ if(rv == null) {
+ return QueryStatus.NOT_FOUND;
+ }
+
+ response = request.jsonStringToObject(rv);
+ if(response == null) {
+ return QueryStatus.NOT_FOUND;
+ }
+
+ if("generic-query".equals(resource)) {
+ SearchResults rd = SearchResults.class.cast(response);
+ List<ResultData> rdList = rd.getResultData();
+ if(rdList == null || rdList.isEmpty()) {
+ return QueryStatus.NOT_FOUND;
+ }
+ ResultData rDatum = rdList.get(0);
+ nameValues.put("selflink", rDatum.getResourceLink());
+ AAIRequest req2 = AAIRequest.createRequest(rDatum.getResourceType(), nameValues);
+ req2.processRequestPathValues(nameValues);
+ rv = getExecutor().get(req2);
if(rv == null) {
return QueryStatus.NOT_FOUND;
}
- response = request.jsonStringToObject(rv);
+ response = req2.jsonStringToObject(rv);
if(response == null) {
return QueryStatus.NOT_FOUND;
}
+ }
- if("generic-query".equals(resource)) {
- SearchResults rd = SearchResults.class.cast(response);
- List<ResultData> rdList = rd.getResultData();
- if(rdList == null || rdList.isEmpty()) {
- return QueryStatus.NOT_FOUND;
- }
- ResultData rDatum = rdList.get(0);
- nameValues.put("selflink", rDatum.getResourceLink());
- AAIRequest req2 = AAIRequest.createRequest(rDatum.getResourceType(), nameValues);
- req2.processRequestPathValues(nameValues);
- rv = getExecutor().get(req2);
- if(rv == null) {
- return QueryStatus.NOT_FOUND;
- }
-
- response = req2.jsonStringToObject(rv);
- if(response == null) {
- return QueryStatus.NOT_FOUND;
- }
- }
-
- if("named-query".equals(resource)) {
- InventoryResponseItems rd = InventoryResponseItems.class.cast(response);
- List<InventoryResponseItem> iRIlist = rd.getInventoryResponseItem();
- if(iRIlist == null || iRIlist.isEmpty()) {
- return QueryStatus.NOT_FOUND;
- }
- }
-
- if("nodes-query".equals(resource)) {
- SearchResults rd = SearchResults.class.cast(response);
- List<ResultData> rdList = rd.getResultData();
- if(rdList == null || rdList.isEmpty()) {
- return QueryStatus.NOT_FOUND;
- }
- ResultData rDatum = rdList.get(0);
- response = rDatum;
+ if("nodes-query".equals(resource)) {
+ SearchResults rd = SearchResults.class.cast(response);
+ List<ResultData> rdList = rd.getResultData();
+ if(rdList == null || rdList.isEmpty()) {
+ return QueryStatus.NOT_FOUND;
}
+ ResultData rDatum = rdList.get(0);
+ response = rDatum;
+ }
if("formatted-query".equals(resource) || "custom-query".equals(resource)) {
FormattedQueryResultList rd = FormattedQueryResultList.class.cast(response);
AAIServiceUtils.populateRelationshipDataFromPath(list);
}
} catch(Exception exc) {
- getLogger().debug("Retrofiting relationship data: " + exc.getMessage());
+ getLogger().debug(RELATIONSHIP_DATA + exc.getMessage());
}
- String preFix;
- if(prefix == null || prefix.isEmpty()) {
- preFix = "";
- } else {
- preFix = prefix + ".";
- }
-
- Map<String,Object> props = objectToProperties(response);
- Set<String> keys = props.keySet();
- for(String theKey: keys) {
- if(getLogger().isTraceEnabled())
- getLogger().trace(theKey);
-
- Object value = props.get(theKey);
- if(value == null)
- continue;
- Object type = value.getClass();
- if(value instanceof String) {
- ctx.setAttribute(preFix + theKey, value.toString());
- continue;
- }
- if(value instanceof Boolean) {
- ctx.setAttribute(preFix + theKey, value.toString());
- continue;
- }
- if(value instanceof Integer) {
- ctx.setAttribute(preFix + theKey, value.toString());
- continue;
- }
- if(value instanceof Long) {
- ctx.setAttribute(preFix + theKey, value.toString());
- continue;
- }
+ String preFix;
+ if(prefix == null || prefix.isEmpty()) {
+ preFix = "";
+ } else {
+ preFix = prefix + ".";
+ }
- if(value instanceof ArrayList) {
- ArrayList<?> array = ArrayList.class.cast(value);
- for(int i = 0; i < array.size(); i++) {
- writeList(array, String.format("%s.%s", prefix, theKey), ctx);
- }
- continue;
+ Map<String,Object> props = objectToProperties(response);
+ Set<String> keys = props.keySet();
+ for(String theKey: keys) {
+ if(getLogger().isTraceEnabled())
+ getLogger().trace(theKey);
+
+ Object value = props.get(theKey);
+ if(value == null)
+ continue;
+ Object type = value.getClass();
+ if(value instanceof String) {
+ ctx.setAttribute(preFix + theKey, value.toString());
+ continue;
+ }
+ if(value instanceof Boolean) {
+ ctx.setAttribute(preFix + theKey, value.toString());
+ continue;
+ }
+ if(value instanceof Integer) {
+ ctx.setAttribute(preFix + theKey, value.toString());
+ continue;
+ }
+ if(value instanceof Long) {
+ ctx.setAttribute(preFix + theKey, value.toString());
+ continue;
+ }
+
+ if(value instanceof ArrayList) {
+ ArrayList<?> array = ArrayList.class.cast(value);
+ for(int i = 0; i < array.size(); i++) {
+ writeList(array, String.format("%s.%s", prefix, theKey), ctx);
}
+ continue;
+ }
- if("relationship-list".equals(theKey)){
- Map<String, Object> relationshipList = (Map<String, Object>)value;
- // we are interested in seeing just the selected relationship
- if(theKey.equals(modifier)) {
- List<?> relationships = (List<?>)relationshipList.get("relationship");
- if(relationships != null && !relationships.isEmpty()) {
-
- List newRelationships = new LinkedList();
- newRelationships.addAll(relationships);
-
- for(Object obj : newRelationships){
- if(obj instanceof Map<?, ?>) {
- Map<?, ?> relProperties = (Map<?, ?>)obj;
- if(relProperties.containsKey("related-to")) {
- Object relPropsRelatedTo = relProperties.get("related-to");
-
- String relatedTo = nameValues.get("related_to");
- if(relatedTo != null) {
- relatedTo = relatedTo.trim().replace("'", "").replace("$", "").replace("'", "");
- if(!relatedTo.equals(relPropsRelatedTo)) {
- relationships.remove(relProperties);
- }
- continue;
- } else {
- continue;
+ if("relationship-list".equals(theKey)){
+ Map<String, Object> relationshipList = (Map<String, Object>)value;
+ // we are interested in seeing just the selected relationship
+ if(theKey.equals(modifier)) {
+ List<?> relationships = (List<?>)relationshipList.get("relationship");
+ if(relationships != null && !relationships.isEmpty()) {
+
+ List newRelationships = new LinkedList();
+ newRelationships.addAll(relationships);
+
+ for(Object obj : newRelationships){
+ if(obj instanceof Map<?, ?>) {
+ Map<?, ?> relProperties = (Map<?, ?>)obj;
+ if(relProperties.containsKey("related-to")) {
+ Object relPropsRelatedTo = relProperties.get("related-to");
+
+ String relatedTo = nameValues.get("related_to");
+ if(relatedTo != null) {
+ relatedTo = relatedTo.trim().replace("'", "").replace("$", "").replace("'", "");
+ if(!relatedTo.equals(relPropsRelatedTo)) {
+ relationships.remove(relProperties);
}
+ continue;
+ } else {
+ continue;
}
}
}
}
}
- writeMap(relationshipList, String.format("%s.%s", prefix, theKey), ctx);
- continue;
- }
-
- if(value instanceof Map) {
- Map<String, Object> subnetsList = (Map<String, Object>)value;
- writeMap(subnetsList, String.format("%s.%s", prefix, theKey), ctx);
- continue;
}
+ writeMap(relationshipList, String.format("%s.%s", prefix, theKey), ctx);
+ continue;
+ }
+ if(value instanceof Map) {
+ Map<String, Object> subnetsList = (Map<String, Object>)value;
+ writeMap(subnetsList, String.format("%s.%s", prefix, theKey), ctx);
+ continue;
}
+
+ }
return QueryStatus.SUCCESS;
}
String rv = getExecutor().get(request);
ctx.setAttribute(prefix, rv);
} catch(AAIServiceException aaiexc) {
+ getLogger().warn(AAI_SERVICE_EXCEPTION, aaiexc);
if(aaiexc.getReturnCode() == 404)
return QueryStatus.NOT_FOUND;
String id = AAIServiceUtils.camelCaseToDashedString(value);
Field field = resourceClass.getDeclaredField(value);
Class<?> type = field.getType();
- Method setter = null;
+
try {
- setter = resourceClass.getMethod("set"+StringUtils.capitalize(value), type);
if(type.getName().startsWith("java.lang") || "boolean".equals(type.getName()) || "long".equals(type.getName()) || "int".equals(type.getName())) {
try {
+ Method setter = resourceClass.getMethod("set"+StringUtils.capitalize(value), type);
Object arglist[] = new Object[1];
arglist[0] = params.get(id);
newValues.add(tmpValue);
}
if(!newValues.isEmpty()) {
- Object o = setter.invoke(instance, newValues);
+ Method setter = findSetterFor(resourceClass, value);
+ if(setter != null) {
+ Object o = setter.invoke(instance, newValues);
+ } else {
+ try {
+ Method listGetter = resourceClass.getMethod("get"+StringUtils.capitalize(value));
+ Object o = listGetter.invoke(instance);
+ if(o != null && o instanceof java.util.List ) {
+ List innerList = List.class.cast(o);
+ innerList.addAll(newValues);
+ }
+ } catch(NoSuchMethodException nsme) {
+ getLogger().warn(AAI_SERVICE_EXCEPTION, nsme);
+ }
+ }
}
}
set.remove(id);
} else {
+ Method setter = resourceClass.getMethod("set"+StringUtils.capitalize(value), type);
setters.put(id, setter);
}
} catch(Exception exc) {
-
+ getLogger().warn(AAI_SERVICE_EXCEPTION, exc);
}
Method getter;
if(!type.getName().equals("java.lang.String")) {
getters.put(id, getter);
}
+ } catch(NoSuchMethodException exc) {
+ try {
+ if(type.getName().equals("java.lang.Boolean")) {
+ getter = resourceClass.getMethod("is"+StringUtils.capitalize(value));
+ getters.put(id, getter);
+ } else {
+ getLogger().warn(AAI_SERVICE_EXCEPTION, exc);
+ }
+ } catch(Exception iexc) {
+ getLogger().warn(AAI_SERVICE_EXCEPTION, iexc);
+ }
} catch(Exception exc) {
-
+ getLogger().warn(AAI_SERVICE_EXCEPTION, exc);
}
}
Object o = method.invoke(instance, arglist);
if(o instanceof ArrayList) {
ArrayList<String> values = (ArrayList<String>)o;
-// getLogger().debug(String.format("Processing %s with parameter %s", types[0].getName(), value));
value = value.replace("[", "").replace("]", "");
List<String> items = Arrays.asList(value.split("\\s*,\\s*"));
for(String s : items) {
Object obj = null;
Method getRelationshipListMethod = null;
try {
- getRelationshipListMethod = resourceClass.getMethod("getRelationshipList");
+ getRelationshipListMethod = resourceClass.getMethod("getRelationshipList");
} catch(Exception exc) {
- getLogger().debug("Retrofiting relationship data: " + exc.getMessage());
+ getLogger().debug(RELATIONSHIP_DATA + exc.getMessage());
}
if(getRelationshipListMethod != null){
getLogger().debug("About to process related link of {}", relatedLink);
if(relatedLink != null) {
if(relatedLink.contains("v$"))
- relatedLink = relatedLink.replace(VERSION_PATTERN, "/v14/");
+ relatedLink = relatedLink.replace(VERSION_PATTERN, "/v21/");
relationship.setRelatedLink(relatedLink);
} else {
Map<String, String> relParams = new HashMap<>();
while(true) {
String searchRelationshipKey = "relationship-list.relationship[" + i + "].relationship-data[" + j + "].relationship-key";
String searchRelationshipValue = "relationship-list.relationship[" + i + "].relationship-data[" + j + "].relationship-value";
- if(!params.containsKey(searchRelationshipKey))
+ if(!params.containsKey(searchRelationshipKey))
break;
- relParams.put(params.get(searchRelationshipKey), params.get(searchRelationshipValue));
+ relParams.put(params.get(searchRelationshipKey), params.get(searchRelationshipValue));
j++;
}
AAIRequest rlRequest = AAIRequest.createRequest(relatedTo, relParams);
vlan.setVlanInterface(vlanInterface);
if(vlanIdInner != null) {
- Long iVlanIdInner = Long.parseLong(vlanIdInner);
- vlan.setVlanIdInner(iVlanIdInner);
+ Long iVlanIdInner = Long.parseLong(vlanIdInner);
+ vlan.setVlanIdInner(iVlanIdInner);
}
if(vlanIdOute != null) {
Long iVlanIdOuter = Long.parseLong(vlanIdOute);
- vlan.setVlanIdOuter(iVlanIdOuter);
+ vlan.setVlanIdOuter(iVlanIdOuter);
}
if(speedValue != null) {
- vlan.setSpeedValue(speedValue);
- vlan.setSpeedUnits(speedUnits);
+ vlan.setSpeedValue(speedValue);
+ vlan.setSpeedUnits(speedUnits);
}
vlanList.getVlan().add(vlan);
request.processRequestPathValues(nameValues);
request.setRequestObject(instance);
- Object response = getExecutor().post(request);
- if(request.expectsDataFromPUTRequest()){
- if(response != null && response instanceof String) {
- String rv = response.toString();
- QueryStatus retval = processResponseData(rv, resource, request, prefix, ctx, nameValues, null);
- getLogger().debug("newModelSave - returning " + retval.toString());
- return retval;
- }
+ Object response = getExecutor().post(request);
+ if(request.expectsDataFromPUTRequest()){
+ if(response != null && response instanceof String) {
+ String rv = response.toString();
+ QueryStatus retval = processResponseData(rv, resource, request, prefix, ctx, nameValues, null);
+ getLogger().debug("newModelSave - returning " + retval.toString());
+ return retval;
}
+ }
} catch(AAIServiceException exc){
ctx.setAttribute(prefix + ".error.message", exc.getMessage());
return QueryStatus.SUCCESS;
}
+ private Method findSetterFor(Class<? extends AAIDatum> resourceClass, String value) {
+ try {
+ String setterName = "set"+StringUtils.capitalize(value);
+ for (Method method : resourceClass.getDeclaredMethods()) {
+ int modifiers = method.getModifiers();
+ if (Modifier.isPublic(modifiers) && setterName.contentEquals(method.getName())) {
+ return method;
+ }
+ }
+ } catch(Exception exc) {
+ getLogger().warn("findSetterFor()", exc);
+ }
+ return null;
+ }
+
private QueryStatus newModelProcessRelationshipList(Object instance, Map<String, String> params, String prefix, SvcLogicContext ctx) throws Exception {
Class resourceClass = instance.getClass();
Object obj = null;
Method getRelationshipListMethod = null;
try {
- getRelationshipListMethod = resourceClass.getMethod("getRelationshipList");
+ getRelationshipListMethod = resourceClass.getMethod("getRelationshipList");
} catch(Exception exc) {
- getLogger().debug("Retrofiting relationship data: " + exc.getMessage());
+ getLogger().debug(RELATIONSHIP_DATA + exc.getMessage());
}
if(getRelationshipListMethod != null){
try {
}
Class resourceClass = instance.getClass();
- Set<String> metadataKeys = new TreeSet<String>();
+ Set<String> metadataKeys = new TreeSet<>();
Set<String> set = params.keySet();
for(String attribute : set) {
if(attribute.startsWith("metadata")) {
Object obj = null;
Method getRelationshipListMethod = null;
try {
- getRelationshipListMethod = resourceClass.getMethod("getRelationshipList");
+ getRelationshipListMethod = resourceClass.getMethod("getRelationshipList");
} catch(Exception exc) {
- getLogger().debug("Retrofiting relationship data: " + exc.getMessage());
+ getLogger().debug(RELATIONSHIP_DATA + exc.getMessage());
}
if(getRelationshipListMethod != null){
try {
if(localRelatedLink.endsWith(relatedLink)) {
getLogger().debug(String.format("Found relationship of '%s' to keyword '%s'", relationship.getRelatedTo(), relatedTo));
relationshipsToDelete.add(relationship);
+ }
}
- }
} else {
- getLogger().debug(String.format("Found relationship of '%s' to keyword '%s'", relationship.getRelatedTo(), relatedTo));
- relationshipsToDelete.add(relationship);
+ getLogger().debug(String.format("Found relationship of '%s' to keyword '%s'", relationship.getRelatedTo(), relatedTo));
+ relationshipsToDelete.add(relationship);
+ }
}
}
- }
if(relationshipsToDelete == null || relationshipsToDelete.isEmpty()) {
getLogger().info(String.format("Relationship has not been found for %s", key));
return QueryStatus.NOT_FOUND;
return prefixMap;
}
- /**
- */
- protected NamedQueryData extractNamedQueryDataFromQueryPrefix(HashMap<String, String> nameValues, Map<String, String> parms) {
- if(parms.isEmpty()) {
- return null;
- }
-
- NamedQueryData data = new NamedQueryData();
-
- // query parameters
- if(data.getQueryParameters() == null) {
- data.setQueryParameters(new QueryParameters());
- }
- String namedQueryUuid = nameValues.get("named-query-uuid".replaceAll("-", "_"));
- if(namedQueryUuid == null) {
- namedQueryUuid = parms.get("query-parameters.named-query.named-query-uuid");
- }
- NamedQuery namedQuery = new NamedQuery();
- namedQuery.setNamedQueryUuid(namedQueryUuid);
- data.getQueryParameters().setNamedQuery(namedQuery);
-
- // instance filters
- if(data.getInstanceFilters() == null) {
- data.setInstanceFilters(new InstanceFilters());
- }
-
-
- String quantity = parms.get("instance-filters.instance-filter_length");
- if(quantity != null && StringUtils.isNumeric(quantity)) {
- int max = Integer.parseInt(quantity);
- for(int i = 0; i < max; i++) {
- String keyPattern = String.format("instance-filters.instance-filter[%d].", i);
- Set<String> keys = parms.keySet();
- for(String key: keys) {
- if(key.startsWith(keyPattern)){
- String value = parms.get(key);
- String remainder = key.substring(keyPattern.length());
- String[] split = remainder.split("\\.");
- getLogger().debug(String.format("%s", remainder));
- if("logical-link".equals(split[0])) {
- InstanceFilter insf = null;
- if(data.getInstanceFilters().getInstanceFilter().isEmpty()) {
- insf = new InstanceFilter();
- data.getInstanceFilters().getInstanceFilter().add(insf);
- } else {
- insf = data.getInstanceFilters().getInstanceFilter().get(0);
- }
- LogicalLink logicalLink = insf.getLogicalLink();
- if(logicalLink == null) {
- logicalLink = new LogicalLink();
- insf.setLogicalLink(logicalLink);
- }
-
- switch(split[1]) {
- case "link-name":
- logicalLink.setLinkName(value);
- break;
- case "link-type":
- logicalLink.setLinkType(value);
- break;
- case "operational-state":
- logicalLink.setOperationalStatus(value);
- break;
- }
-
- } else if("pnf".equals(split[0])) {
- Pnf pnf = new Pnf();
- pnf.setPnfName(value);
-
- InstanceFilter insf = new InstanceFilter();
- insf.setPnf(pnf);
- data.getInstanceFilters().getInstanceFilter().add(insf);
-
- } else if("service-instance".equals(split[0])) {
- ServiceInstance serviceInstance = new ServiceInstance();
- serviceInstance.setServiceInstanceId(value);
-
- InstanceFilter insf = new InstanceFilter();
- insf.setServiceInstance(serviceInstance);
- data.getInstanceFilters().getInstanceFilter().add(insf);
-
- } else if("l3-network".equals(split[0])) {
- L3Network l3Network = new L3Network();
- if("network-role".equals(split[1])) {
- l3Network.setNetworkRole(value);
- }
-
- InstanceFilter insf = new InstanceFilter();
- insf.setL3Network(l3Network);
- data.getInstanceFilters().getInstanceFilter().add(insf);
- } else if("generic-vnf".equals(split[0])) {
- GenericVnf vnf = new GenericVnf();
- if("vnf-id".equals(split[1])) {
- vnf.setVnfId(value);
- }
-
- InstanceFilter insf = new InstanceFilter();
- insf.setGenericVnf(vnf);
- data.getInstanceFilters().getInstanceFilter().add(insf);
- }
- }
- }
- }
- }
-
- return data;
- }
-
public abstract <T> T getResource(String key, Class<T> type) throws AAIServiceException ;
protected abstract boolean deleteList(URL url, String caller) throws AAIServiceException;
}