import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
import org.onap.ccsdk.sli.core.sli.SvcLogicException;
import org.onap.ccsdk.sli.core.sli.SvcLogicResource.QueryStatus;
-import org.openecomp.aai.inventory.v10.GenericVnf;
-import org.openecomp.aai.inventory.v10.InventoryResponseItem;
-import org.openecomp.aai.inventory.v10.InventoryResponseItems;
-import org.openecomp.aai.inventory.v10.L3Network;
-import org.openecomp.aai.inventory.v10.LogicalLink;
-import org.openecomp.aai.inventory.v10.Metadata;
-import org.openecomp.aai.inventory.v10.Metadatum;
-import org.openecomp.aai.inventory.v10.Pnf;
-import org.openecomp.aai.inventory.v10.Relationship;
-import org.openecomp.aai.inventory.v10.RelationshipData;
-import org.openecomp.aai.inventory.v10.RelationshipList;
-import org.openecomp.aai.inventory.v10.ResultData;
-import org.openecomp.aai.inventory.v10.SearchResults;
-import org.openecomp.aai.inventory.v10.ServiceInstance;
-import org.openecomp.aai.inventory.v10.Vlan;
-import org.openecomp.aai.inventory.v10.Vlans;
-import org.openecomp.aai.inventory.v10.Vserver;
+import org.openecomp.aai.inventory.v11.GenericVnf;
+import org.openecomp.aai.inventory.v11.InventoryResponseItem;
+import org.openecomp.aai.inventory.v11.InventoryResponseItems;
+import org.openecomp.aai.inventory.v11.L3Network;
+import org.openecomp.aai.inventory.v11.LogicalLink;
+import org.openecomp.aai.inventory.v11.Metadata;
+import org.openecomp.aai.inventory.v11.Metadatum;
+import org.openecomp.aai.inventory.v11.Pnf;
+import org.openecomp.aai.inventory.v11.Relationship;
+import org.openecomp.aai.inventory.v11.RelationshipData;
+import org.openecomp.aai.inventory.v11.RelationshipList;
+import org.openecomp.aai.inventory.v11.ResultData;
+import org.openecomp.aai.inventory.v11.SearchResults;
+import org.openecomp.aai.inventory.v11.ServiceInstance;
+import org.openecomp.aai.inventory.v11.Vlan;
+import org.openecomp.aai.inventory.v11.Vlans;
+import org.openecomp.aai.inventory.v11.Vserver;
import org.onap.ccsdk.sli.adaptors.aai.AAIService.AAIRequestExecutor;
import org.onap.ccsdk.sli.adaptors.aai.data.AAIDatum;
import org.onap.ccsdk.sli.adaptors.aai.query.FormattedQueryResultList;
String vnfId = null;
String vnfName = null;
- HashMap<String, String> nameValues = keyToHashMap(key, ctx);
+ HashMap<String, String> nameValues = AAIServiceUtils.keyToHashMap(key, ctx);
getLogger().debug("key = "+ nameValues.toString());
- if(!checkOldFormat(resource, nameValues)) {
+ if(!AAIServiceUtils.isValidFormat(resource, nameValues)) {
ctx.setAttribute(String.format("%s.error.message", prefix), String.format("Resource %s is not supported. Key string contains invaid identifiers", resource));
return QueryStatus.FAILURE;
}
// return QueryStatus.SUCCESS;
}
- private boolean checkOldFormat(String resource, HashMap<String, String> nameValues) {
-
- switch(resource){
- case "formatted-query":
- case "generic-query":
- case "named-query":
- case "nodes-query":
- case "linterface":
- case "l2-bridge-sbg":
- case "l2-bridge-bgf":
- case "echo":
- case "test":
- return true;
- }
- if(resource.contains(":")) {
- resource = resource.substring(0, resource.indexOf(":"));
- }
-
- Set<String> keys = nameValues.keySet();
- for(String key : keys) {
- if(!key.contains(".")) {
- if("depth".equals(key) || "related-to".equals(key) || "related_to".equals(key))
- continue;
- else {
- getLogger().warn(String.format("key %s is incompatible with resource type '%s'", key, resource));
- return false;
- }
- }
- }
- return true;
- }
public void writeMap(Map<String, Object> properties, String prefix, SvcLogicContext ctx) {
Set<String> mapKeys = properties.keySet();
throws SvcLogicException {
getLogger().debug("AAIService.save\tresource="+resource);
- HashMap<String, String> nameValues = keyToHashMap(key, ctx);
+ HashMap<String, String> nameValues = AAIServiceUtils.keyToHashMap(key, ctx);
- if(!checkOldFormat(resource, nameValues)) {
+ if(!AAIServiceUtils.isValidFormat(resource, nameValues)) {
ctx.setAttribute(String.format("%s.error.message", prefix), String.format("Resource %s is not supported. Key string contains invaid identifiers", resource));
return QueryStatus.FAILURE;
}
public QueryStatus update(String resource, String key, Map<String, String> params, String prefix, SvcLogicContext ctx) throws SvcLogicException {
resource = resource.toLowerCase();
- HashMap<String, String> nameValues = keyToHashMap(key, ctx);
+ HashMap<String, String> nameValues = AAIServiceUtils.keyToHashMap(key, ctx);
getLogger().debug("key = "+ Arrays.toString(nameValues.entrySet().toArray()));
- if(!checkOldFormat(resource, nameValues)) {
+ if(!AAIServiceUtils.isValidFormat(resource, nameValues)) {
ctx.setAttribute(String.format("%s.error.message", prefix), String.format("Resource %s is not supported. Key string contains invaid identifiers", resource));
return QueryStatus.FAILURE;
}
@Override
public QueryStatus delete(String resource, String key, SvcLogicContext ctx) throws SvcLogicException {
getLogger().debug("AAIService.delete\tresource="+resource);
- HashMap<String, String> nameValues = keyToHashMap(key, ctx);
+ HashMap<String, String> nameValues = AAIServiceUtils.keyToHashMap(key, ctx);
getLogger().debug("key = "+ Arrays.toString(nameValues.entrySet().toArray()));
- if(!checkOldFormat(resource, nameValues)) {
+ if(!AAIServiceUtils.isValidFormat(resource, nameValues)) {
ctx.setAttribute(String.format("%s.error.message", "aaiData"), String.format("Resource %s is not supported. Key string contains invaid identifiers", resource));
return QueryStatus.FAILURE;
}
QueryStatus retval = QueryStatus.SUCCESS;
String modifier = null;
- HashMap<String, String> nameValues = keyToHashMap(key, ctx);
+ HashMap<String, String> nameValues = AAIServiceUtils.keyToHashMap(key, ctx);
if(resource.contains(":")) {
modifier = resource.split(":")[1];
}
response = rDatum;
}
- if("formatted-query".equals(resource)) {
+ if("formatted-query".equals(resource) || "custom-query".equals(resource)) {
FormattedQueryResultList rd = FormattedQueryResultList.class.cast(response);
List<Results> iRIlist = rd.getResults();
if(iRIlist == null || iRIlist.isEmpty()) {
}
}
+ // process relationship list
+ // this is a temporary soluton to address the realationship handling changes added in Release 17.07
+ try {
+ Class<?> clazz = response.getClass();
+ Method getter = clazz.getMethod("getRelationshipList");
+ Object obj = getter.invoke(response);
+ if(obj != null && obj instanceof RelationshipList) {
+ RelationshipList list = RelationshipList.class.cast(obj);
+ AAIServiceUtils.populateRelationshipDataFromPath(list);
+ }
+ } catch(Exception exc) {
+ getLogger().debug("Retrofiting relationship data: " + exc.getMessage());
+ }
+
String preFix = null;
if(prefix == null || prefix.isEmpty()) {
preFix = "";
if(value instanceof ArrayList) {
ArrayList<?> array = ArrayList.class.cast(value);
for(int i = 0; i < array.size(); i++) {
-// ctx.setAttribute(String.format("%s%s[%d]", preFix, theKey, i), array.get(i).toString());
writeList(array, String.format("%s.%s", prefix, theKey), ctx);
}
continue;
throw new SvcLogicException("Method AAIService.reserve() has not been implemented yet");
}
- private QueryStatus newModelSave(String resource, boolean force, String key, Map<String, String> parms, String prefix, SvcLogicContext ctx) {
+ private QueryStatus newModelSave(String resource, boolean force, String key, Map<String, String> params, String prefix, SvcLogicContext ctx) {
getLogger().debug("Executing newModelSave for resource : " + resource);
- HashMap<String, String> nameValues = keyToHashMap(key, ctx);
+ HashMap<String, String> nameValues = AAIServiceUtils.keyToHashMap(key, ctx);
try {
ArrayList<String> subResources = new ArrayList<String>();
- Set<String> set = parms.keySet();
+ Set<String> set = params.keySet();
Map<String, Method> setters = new HashMap<String, Method>();
Map<String, Method> getters = new HashMap<String, Method>();
for(Annotation annotation : annotations) {
Class<? extends Annotation> anotationType = annotation.annotationType();
String annotationName = anotationType.getName();
-// if("com.fasterxml.jackson.annotation.JsonPropertyOrder".equals(annotationName)){
// 2. find string property setters and getters for the lists
if("javax.xml.bind.annotation.XmlType".equals(annotationName)){
XmlType order = (XmlType)annotation;
String[] values = order.propOrder();
for(String value : values) {
- String id = camelCaseToDashedString(value);
+ String id = AAIServiceUtils.camelCaseToDashedString(value);
Field field = resourceClass.getDeclaredField(value);
Class<?> type = field.getType();
Method setter = null;
try {
setter.setAccessible(true);
Object arglist[] = new Object[1];
- arglist[0] = parms.get(id);
+ arglist[0] = params.get(id);
if(arglist[0] != null) {
if(!type.getName().equals("java.lang.String")) {
// getLogger().debug(String.format("Processing %s with parameter %s", types[0].getName(), value));
if("boolean".equals(type.getName())) {
- arglist[0] = valueOf(Boolean.class, parms.get(id));
+ arglist[0] = valueOf(Boolean.class, params.get(id));
} else if("long".equals(type.getName())) {
- arglist[0] = valueOf(Long.class, parms.get(id));
+ arglist[0] = valueOf(Long.class, params.get(id));
} else {
- arglist[0] = valueOf(type, parms.get(id));
+ arglist[0] = valueOf(type, params.get(id));
}
}
Object o = setter.invoke(instance, arglist);
} else if(type.getName().equals("java.util.List")) {
List<String> newValues = new ArrayList<String>();
String length = id+"_length";
- if(!parms.isEmpty() && parms.containsKey(length)) {
- String tmp = parms.get(length).toString();
+ if(!params.isEmpty() && params.containsKey(length)) {
+ String tmp = params.get(length).toString();
int count = Integer.valueOf(tmp);
for(int i=0; i<count; i++) {
- String tmpValue = parms.get(String.format("%s[%d]", id, i));
+ String tmpValue = params.get(String.format("%s[%d]", id, i));
newValues.add(tmpValue);
}
if(!newValues.isEmpty()) {
Set<String> metadataKeys = new TreeSet<String>();
for(String attribute : set) {
- String value = parms.get(attribute);
+ String value = params.get(attribute);
if(attribute.startsWith("relationship-list")) {
relationshipKeys.add(attribute);
} else if(attribute.startsWith("vlans")) {
}
// 3. find list property getters
for(String attribute : set) {
- String value = parms.get(attribute);
+ String value = params.get(attribute);
Method method = getters.get(attribute);
if(method != null) {
try {
if( (subResources.contains("relationship-list") || subResources.contains("relationshipList")) && !relationshipKeys.isEmpty()) {
RelationshipList relationshipList = null;
Object obj = null;
- Method getRelationshipListMethod = resourceClass.getMethod("getRelationshipList");
+ Method getRelationshipListMethod = null;
+ try {
+ getRelationshipListMethod = resourceClass.getMethod("getRelationshipList");
+ } catch(Exception exc) {
+ getLogger().debug("Retrofiting relationship data: " + exc.getMessage());
+ }
+
if(getRelationshipListMethod != null){
try {
getRelationshipListMethod.setAccessible(true);
int i = 0;
while(true){
- int j = 0;
String searchKey = "relationship-list.relationship[" + i + "].related-to";
- if(!parms.containsKey(searchKey))
+ if(!params.containsKey(searchKey))
break;
+ int j = 0;
+ String relatedTo = params.get(searchKey);
+ String relatedLinkKey = "relationship-list.relationship[" + i + "].related-link";
+ String relatedLink = null;
+ if(params.containsKey(relatedLinkKey)) {
+ relatedLink = params.get(relatedLinkKey);
+ }
Relationship relationship = new Relationship();
relationships.add(relationship);
-
- String relatedTo = parms.get(searchKey);
relationship.setRelatedTo(relatedTo);
-
- List<RelationshipData> relData = relationship.getRelationshipData();
-// if(relData == null) {
-// relData = new LinkedList<RelationshipData>();
-// relationship.setRelationshipData(relData);
-// }
+ if(relatedLink != null) {
+ relationship.setRelatedLink(relatedLink);
+ } else {
+// List<RelationshipData> relData = relationship.getRelationshipData();
+ Map<String, String> relParams = new HashMap<String, String>();
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(!parms.containsKey(searchRelationshipKey))
+ if(!params.containsKey(searchRelationshipKey))
break;
- RelationshipData relDatum = new RelationshipData();
- relDatum.setRelationshipKey(parms.get(searchRelationshipKey));
- relDatum.setRelationshipValue(parms.get(searchRelationshipValue));
- relData.add(relDatum);
+ relParams.put(params.get(searchRelationshipKey), params.get(searchRelationshipValue));
j++;
}
-
+ AAIRequest rlRequest = AAIRequest.createRequest(relatedTo, relParams);
+ for(String key1 : relParams.keySet()) {
+ rlRequest.addRequestProperty(key1, relParams.get(key1));
+ }
+ String path = rlRequest.updatePathDataValues(null);
+ relationship.setRelatedLink(path);
+ }
i++;
}
}
int i = 0;
while(true){
String searchKey = "vlans.vlan[" + i + "].vlan-interface";
- if(!parms.containsKey(searchKey))
+ if(!params.containsKey(searchKey))
break;
- String vlanInterface = parms.get("vlans.vlan[" + i + "].vlan-interface");
- String vlanIdInner = parms.get("vlans.vlan[" + i + "].vlan-id-inner");
- String vlanIdOute = parms.get("vlans.vlan[" + i + "].vlan-id-outer");
- String speedValue = parms.get("vlans.vlan[" + i + "].speed-value");
- String speedUnits = parms.get("vlans.vlan[" + i + "].speed-units");
+ String vlanInterface = params.get("vlans.vlan[" + i + "].vlan-interface");
+ String vlanIdInner = params.get("vlans.vlan[" + i + "].vlan-id-inner");
+ String vlanIdOute = params.get("vlans.vlan[" + i + "].vlan-id-outer");
+ String speedValue = params.get("vlans.vlan[" + i + "].speed-value");
+ String speedUnits = params.get("vlans.vlan[" + i + "].speed-units");
Vlan vlan = new Vlan();
vlan.setVlanInterface(vlanInterface);
int i = 0;
while(true){
String metaKey = "metadata.metadatum[" + i + "].meta-key";
- if(!parms.containsKey(metaKey))
+ if(!params.containsKey(metaKey))
break;
- String metaValue = parms.get("metadata.metadatum[" + i + "].meta-value");
+ String metaValue = params.get("metadata.metadatum[" + i + "].meta-value");
Metadatum vlan = new Metadatum();
vlan.setMetaname(metaKey);
return QueryStatus.SUCCESS;
}
- private static final String regex = "([A-Z][a-z,0-9]+)";
- private static final String replacement = "-$1";
-
- private String camelCaseToDashedString(String propOrder) {
- return propOrder.replaceAll(regex, replacement).toLowerCase();
- }
-
private QueryStatus newModelProcessRelationshipList(Object instance, Map<String, String> params, String prefix, SvcLogicContext ctx) throws Exception {
Class resourceClass = instance.getClass();
if(!relationshipKeys.isEmpty()) {
RelationshipList relationshipList = null;
Object obj = null;
- Method getRelationshipListMethod = resourceClass.getMethod("getRelationshipList");
+ Method getRelationshipListMethod = null;
+ try {
+ getRelationshipListMethod = resourceClass.getMethod("getRelationshipList");
+ } catch(Exception exc) {
+ getLogger().debug("Retrofiting relationship data: " + exc.getMessage());
+ }
if(getRelationshipListMethod != null){
try {
getRelationshipListMethod.setAccessible(true);
}
int i = 0;
- int j = 0;
while(true){
String searchKey = "relationship-list.relationship[" + i + "].related-to";
if(!params.containsKey(searchKey))
break;
- j = 0;
+ int j = 0;
String relatedTo = params.get(searchKey);
String relatedLinkKey = "relationship-list.relationship[" + i + "].related-link";
String relatedLink = null;
if(relatedLink != null) {
relationship.setRelatedLink(relatedLink);
} else {
- List<RelationshipData> relData = relationship.getRelationshipData();
+ Map<String, String> relParams = new HashMap<String, String>();
while(true) {
String searchRelationshipKey = "relationship-list.relationship[" + i + "].relationship-data[" + j + "].relationship-key";
if(!params.containsKey(searchRelationshipKey))
break;
- RelationshipData relDatum = new RelationshipData();
- relDatum.setRelationshipKey(params.get(searchRelationshipKey));
- relDatum.setRelationshipValue(params.get(searchRelationshipValue));
- relData.add(relDatum);
+ relParams.put(params.get(searchRelationshipKey), params.get(searchRelationshipValue));
j++;
}
+ AAIRequest rlRequest = AAIRequest.createRequest(relatedTo, relParams);
+ for(String key : relParams.keySet()) {
+ rlRequest.addRequestProperty(key, relParams.get(key));
+ }
+ String path = rlRequest.updatePathDataValues(null);
+ relationship.setRelatedLink(path);
}
-
i++;
}
}
return null;
}
- protected HashMap<String,String> keyToHashMap(String key, SvcLogicContext ctx) {
- if (key == null) {
- return (null);
- }
-
- getLogger().debug("Converting key [" + key + "] to where clause");
-
- if (key.startsWith("'") && key.endsWith("'")) {
- key = key.substring(1, key.length() - 1);
-
- getLogger().debug("Stripped outer single quotes - key is now [" + key + "]");
- }
-
- String[] keyTerms = key.split("\\s+");
-
- StringBuffer whereBuff = new StringBuffer();
- String term1 = null;
- String op = null;
- String term2 = null;
- HashMap<String, String> results = new HashMap<String, String>();
-
- for (int i = 0; i < keyTerms.length; i++) {
- if (term1 == null) {
- if ("and".equalsIgnoreCase(keyTerms[i])
- || "or".equalsIgnoreCase(keyTerms[i])) {
- // Skip over ADD/OR
- } else {
- term1 = resolveTerm(keyTerms[i], ctx);
- }
- } else if (op == null) {
- if ("==".equals(keyTerms[i])) {
- op = "=";
- } else {
- op = keyTerms[i];
- }
- } else {
- term2 = resolveTerm(keyTerms[i], ctx);
- term2 = term2.trim().replace("'", "").replace("$", "").replace("'", "");
- results.put(term1, term2);
-
- term1 = null;
- op = null;
- term2 = null;
- }
- }
-
- return (results);
- }
-
- private String resolveTerm(String term, SvcLogicContext ctx) {
- if (term == null) {
- return (null);
- }
-
- getLogger().debug("resolveTerm: term is " + term);
-
- if (term.startsWith("$") && (ctx != null)) {
- // Resolve any index variables.
-
- return ("'" + resolveCtxVariable(term.substring(1), ctx) + "'");
- } else if (term.startsWith("'") || term.startsWith("\"")) {
- return (term);
- } else {
- return (term.replaceAll("-", "_"));
-
- }
-
- }
-
- private String resolveCtxVariable(String ctxVarName, SvcLogicContext ctx) {
-
- if (ctxVarName.indexOf('[') == -1) {
- // Ctx variable contains no arrays
- return (ctx.getAttribute(ctxVarName));
- }
-
- // Resolve any array references
- StringBuffer sbuff = new StringBuffer();
- String[] ctxVarParts = ctxVarName.split("\\[");
- sbuff.append(ctxVarParts[0]);
- for (int i = 1; i < ctxVarParts.length; i++) {
- if (ctxVarParts[i].startsWith("$")) {
- int endBracketLoc = ctxVarParts[i].indexOf("]");
- if (endBracketLoc == -1) {
- // Missing end bracket ... give up parsing
- getLogger().warn("Variable reference " + ctxVarName
- + " seems to be missing a ']'");
- return (ctx.getAttribute(ctxVarName));
- }
-
- String idxVarName = ctxVarParts[i].substring(1, endBracketLoc);
- String remainder = ctxVarParts[i].substring(endBracketLoc);
-
- sbuff.append("[");
- sbuff.append(ctx.getAttribute(idxVarName));
- sbuff.append(remainder);
-
- } else {
- // Index is not a variable reference
- sbuff.append("[");
- sbuff.append(ctxVarParts[i]);
- }
- }
-
- return (ctx.getAttribute(sbuff.toString()));
- }
-
public QueryStatus backup(Map<String, String> params, SvcLogicContext ctx) throws SvcLogicException {
String resource = params.get("resource").toLowerCase();
RelationshipList relationshipList = null;
Object obj = null;
- Method getRelationshipListMethod = resourceClass.getMethod("getRelationshipList");
+ Method getRelationshipListMethod = null;
+ try {
+ getRelationshipListMethod = resourceClass.getMethod("getRelationshipList");
+ } catch(Exception exc) {
+ getLogger().debug("Retrofiting relationship data: " + exc.getMessage());
+ }
if(getRelationshipListMethod != null){
try {
getRelationshipListMethod.setAccessible(true);