diff options
author | Rich Tabedzki <richard.tabedzki@att.com> | 2017-08-10 02:07:22 +0000 |
---|---|---|
committer | Rich Tabedzki <richard.tabedzki@att.com> | 2017-08-10 02:08:07 +0000 |
commit | f8dd15950ce50855b989bfee6133a91205138042 (patch) | |
tree | effc7768e54edbedbab7c686c3bf6b22b676c4a0 /aai-service/provider/src/main/java/org/openecomp | |
parent | cd20cd38ea261ef7184102db947de4cc245c86e2 (diff) |
[SDNC-30] summary
Updated code to the latest version of AAI model
Change-Id: I7aea6fc44cf1586c5915da1e2cffe15fa666eef0
Signed-off-by: Rich Tabedzki <richard.tabedzki@att.com>
Diffstat (limited to 'aai-service/provider/src/main/java/org/openecomp')
24 files changed, 733 insertions, 482 deletions
diff --git a/aai-service/provider/src/main/java/org/openecomp/sdnc/sli/aai/AAIClient.java b/aai-service/provider/src/main/java/org/openecomp/sdnc/sli/aai/AAIClient.java index fe358df..55c84bc 100644 --- a/aai-service/provider/src/main/java/org/openecomp/sdnc/sli/aai/AAIClient.java +++ b/aai-service/provider/src/main/java/org/openecomp/sdnc/sli/aai/AAIClient.java @@ -22,6 +22,7 @@ package org.openecomp.sdnc.sli.aai; import java.io.IOException; +import java.net.MalformedURLException; import java.net.URL; import java.util.HashMap; import java.util.Map; @@ -37,7 +38,7 @@ import com.fasterxml.jackson.core.JsonParseException; import com.fasterxml.jackson.databind.JsonMappingException; -import org.openecomp.aai.inventory.v10.*; +import org.openecomp.aai.inventory.v11.*; public interface AAIClient extends SvcLogicResource, SvcLogicJavaPlugin { @@ -197,5 +198,7 @@ public interface AAIClient extends SvcLogicResource, SvcLogicJavaPlugin { public void logKeyError(String keys); public QueryStatus processResponseData(String rv, String resource, AAIRequest request, String prefix, SvcLogicContext ctx, HashMap<String, String> nameValues, String modifier) throws JsonParseException, JsonMappingException, IOException, AAIServiceException ; + public String getPathTemplateForResource(String resoourceName, String join, SvcLogicContext ctx) throws MalformedURLException; + public boolean isDeprecatedFormat(String resource, HashMap<String, String> nameValues); } diff --git a/aai-service/provider/src/main/java/org/openecomp/sdnc/sli/aai/AAIDeclarations.java b/aai-service/provider/src/main/java/org/openecomp/sdnc/sli/aai/AAIDeclarations.java index 5d5c6d8..389a330 100644 --- a/aai-service/provider/src/main/java/org/openecomp/sdnc/sli/aai/AAIDeclarations.java +++ b/aai-service/provider/src/main/java/org/openecomp/sdnc/sli/aai/AAIDeclarations.java @@ -64,7 +64,7 @@ import com.fasterxml.jackson.core.JsonParseException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import org.openecomp.aai.inventory.v10.*; +import org.openecomp.aai.inventory.v11.*; public abstract class AAIDeclarations implements AAIClient { @@ -133,10 +133,10 @@ public abstract class AAIDeclarations implements AAIClient { 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; } @@ -377,37 +377,6 @@ public abstract class AAIDeclarations implements AAIClient { // 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(); @@ -453,9 +422,9 @@ public abstract class AAIDeclarations implements AAIClient { 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; } @@ -528,8 +497,11 @@ public abstract class AAIDeclarations implements AAIClient { request.processRequestPathValues(nameValues); getExecutor().post(request); - getLogger().debug("Save relationship list - returning SUCCESS"); - return QueryStatus.SUCCESS; + getLogger().debug("Save relationship list - returning SUCCESS"); + return QueryStatus.SUCCESS; +// } else { +// getLogger().debug("Save relationship list - returning FAILURE"); +// return QueryStatus.FAILURE; } } catch (Exception exc) { ctx.setAttribute(prefix + ".error.message", exc.getMessage()); @@ -592,9 +564,9 @@ public abstract class AAIDeclarations implements AAIClient { 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; } @@ -653,10 +625,10 @@ public abstract class AAIDeclarations implements AAIClient { @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; } @@ -809,7 +781,7 @@ public abstract class AAIDeclarations implements AAIClient { 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]; } @@ -905,101 +877,115 @@ public abstract class AAIDeclarations implements AAIClient { } ResultData rDatum = rdList.get(0); response = rDatum; +// writeList((ArrayList)rdList, prefix, ctx); } - 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()) { return QueryStatus.NOT_FOUND; } } + + // 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 = ""; - } 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; - } - - 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; - } - - 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; + String preFix = null; + 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; + } + + 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; + } + } + } + } + } } + 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; } @@ -1084,13 +1070,13 @@ public abstract class AAIDeclarations implements AAIClient { 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>(); @@ -1105,14 +1091,13 @@ public abstract class AAIDeclarations implements AAIClient { 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; @@ -1122,17 +1107,17 @@ public abstract class AAIDeclarations implements AAIClient { 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); @@ -1146,11 +1131,11 @@ public abstract class AAIDeclarations implements AAIClient { } 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()) { @@ -1193,7 +1178,7 @@ public abstract class AAIDeclarations implements AAIClient { 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")) { @@ -1204,7 +1189,7 @@ public abstract class AAIDeclarations implements AAIClient { } // 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 { @@ -1235,7 +1220,13 @@ public abstract class AAIDeclarations implements AAIClient { 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); @@ -1266,35 +1257,46 @@ public abstract class AAIDeclarations implements AAIClient { 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); -// } - - 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)) - break; - - RelationshipData relDatum = new RelationshipData(); - relDatum.setRelationshipKey(parms.get(searchRelationshipKey)); - relDatum.setRelationshipValue(parms.get(searchRelationshipValue)); - relData.add(relDatum); - j++; + 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(!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 key1 : relParams.keySet()) { + rlRequest.addRequestProperty(key1, relParams.get(key1)); + } + String path = rlRequest.updatePathDataValues(null); + relationship.setRelatedLink(path); } - i++; } } @@ -1333,14 +1335,14 @@ public abstract class AAIDeclarations implements AAIClient { 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); @@ -1404,10 +1406,10 @@ public abstract class AAIDeclarations implements AAIClient { 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); @@ -1442,6 +1444,8 @@ public abstract class AAIDeclarations implements AAIClient { return retval; } } +// } else { +// boolean response = getExecutor().post(request); } catch(AAIServiceException exc){ ctx.setAttribute(prefix + ".error.message", exc.getMessage()); @@ -1468,13 +1472,6 @@ public abstract class AAIDeclarations implements AAIClient { 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(); @@ -1496,7 +1493,12 @@ public abstract class AAIDeclarations implements AAIClient { 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); @@ -1531,13 +1533,12 @@ public abstract class AAIDeclarations implements AAIClient { } 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; @@ -1551,23 +1552,31 @@ public abstract class AAIDeclarations implements AAIClient { if(relatedLink != null) { relationship.setRelatedLink(relatedLink); } else { - List<RelationshipData> relData = relationship.getRelationshipData(); - - 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)) - break; +// List<RelationshipData> relData = relationship.getRelationshipData(); + Map<String, String> relParams = new HashMap<String, String>(); - RelationshipData relDatum = new RelationshipData(); - relDatum.setRelationshipKey(params.get(searchRelationshipKey)); - relDatum.setRelationshipValue(params.get(searchRelationshipValue)); - relData.add(relDatum); - j++; - } + 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)) + 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++; } } @@ -1587,113 +1596,6 @@ public abstract class AAIDeclarations implements AAIClient { 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(); @@ -1796,7 +1698,12 @@ public abstract class AAIDeclarations implements AAIClient { 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); diff --git a/aai-service/provider/src/main/java/org/openecomp/sdnc/sli/aai/AAIRequest.java b/aai-service/provider/src/main/java/org/openecomp/sdnc/sli/aai/AAIRequest.java index 4badf22..8137601 100644 --- a/aai-service/provider/src/main/java/org/openecomp/sdnc/sli/aai/AAIRequest.java +++ b/aai-service/provider/src/main/java/org/openecomp/sdnc/sli/aai/AAIRequest.java @@ -55,7 +55,7 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import org.openecomp.aai.inventory.v10.*; +import org.openecomp.aai.inventory.v11.*; public abstract class AAIRequest { protected static final Logger LOG = LoggerFactory.getLogger(AAIRequest.class); @@ -114,6 +114,7 @@ public abstract class AAIRequest { case "nodes-query": return new NodesQueryRequest(); case "custom-query": + case "formatted-query": return new CustomQueryRequest(); case "linterface": return new LInterfaceRequest(LInterfaceRequest.TYPE.L2_BRIDGE_SBG); @@ -145,6 +146,11 @@ public abstract class AAIRequest { * Map containing bitset value of the path to its path mapping */ private static Map<BitSet, String> bitsetPaths = new LinkedHashMap<BitSet, String>(); + + + public static Set<String> getResourceNames() { + return tagValues.keySet(); + } public static void setProperties(Properties props, AAIService aaiService) { @@ -231,17 +237,23 @@ public abstract class AAIRequest { aaiService.getLogger().warn("Could not deserialize object of type " + lInterfaceRequest.getClass().getSimpleName(), exc) ; } -// public abstract URL getRequestUrl(String method, String resourceVersion) throws UnsupportedEncodingException, MalformedURLException; - public URL getRequestUrl(String method, String resourceVersion) throws UnsupportedEncodingException, MalformedURLException { String request_url = null; - request_url = target_uri + getRequestPath(); + request_url = target_uri + updatePathDataValues(resourceVersion); - Set<String> uniqueResources = extractUniqueResourceSetFromKeys(requestProperties.stringPropertyNames()); + URL http_req_url = new URL(request_url); -// request_url = processPathData(request_url, requestProperties); + aaiService.LOGwriteFirstTrace(method, http_req_url.toString()); + + return http_req_url; + } + + public String updatePathDataValues(Object resourceVersion) throws UnsupportedEncodingException, MalformedURLException { + String request_url = getRequestPath(); + + Set<String> uniqueResources = extractUniqueResourceSetFromKeys(requestProperties.stringPropertyNames()); for(String resoourceName:uniqueResources) { AAIRequest locRequest = AAIRequest.createRequest(resoourceName, new HashMap<String, String>()); @@ -254,19 +266,14 @@ public abstract class AAIRequest { } catch (Exception e) { e.printStackTrace(); } -// request_url = locRequest.processPathData(request_url, requestProperties); } } if(resourceVersion != null) { request_url = request_url +"?resource-version="+resourceVersion; } - URL http_req_url = new URL(request_url); - - aaiService.LOGwriteFirstTrace(method, http_req_url.toString()); - - return http_req_url; + return request_url; } @@ -366,7 +373,7 @@ public abstract class AAIRequest { return AAIService.getObjectMapper(); } - protected static Class<? extends AAIDatum> getClassFromResource(String resoourceName) throws ClassNotFoundException { + public static Class<? extends AAIDatum> getClassFromResource(String resoourceName) throws ClassNotFoundException { String className = GenericVnf.class.getName(); String[] split = resoourceName.split("-"); for(int i = 0; i < split.length; i++) { @@ -415,6 +422,19 @@ public abstract class AAIRequest { return query_pairs; } + public static Map<String, String> splitPath(String path) throws UnsupportedEncodingException { + Map<String, String> query_pairs = new LinkedHashMap<String, String>(); + + if(path != null && !path.isEmpty()) { + String[] pairs = path.split("/"); + for (String pair : pairs) { + int idx = pair.indexOf("="); + query_pairs.put(URLDecoder.decode(pair.substring(0, idx), "UTF-8"), URLDecoder.decode(pair.substring(idx + 1), "UTF-8")); + } + } + return query_pairs; + } + protected boolean expectsDataFromPUTRequest() { return false; } diff --git a/aai-service/provider/src/main/java/org/openecomp/sdnc/sli/aai/AAIService.java b/aai-service/provider/src/main/java/org/openecomp/sdnc/sli/aai/AAIService.java index f316ead..8ecfd8b 100644 --- a/aai-service/provider/src/main/java/org/openecomp/sdnc/sli/aai/AAIService.java +++ b/aai-service/provider/src/main/java/org/openecomp/sdnc/sli/aai/AAIService.java @@ -36,6 +36,7 @@ import java.lang.reflect.Method; import java.lang.reflect.Modifier; import java.net.HttpURLConnection; import java.net.MalformedURLException; +import java.net.URI; import java.net.URISyntaxException; import java.net.URL; import java.net.URLEncoder; @@ -96,7 +97,7 @@ import com.fasterxml.jackson.module.jaxb.JaxbAnnotationIntrospector; import com.sun.jersey.api.client.config.DefaultClientConfig; import com.sun.jersey.client.urlconnection.HTTPSProperties; -import org.openecomp.aai.inventory.v10.*; +import org.openecomp.aai.inventory.v11.*; public class AAIService extends AAIDeclarations implements AAIClient, SvcLogicResource { @@ -363,7 +364,13 @@ public class AAIService extends AAIDeclarations implements AAIClient, SvcLogicRe con.setRequestProperty( "Content-Type", "PATCH".equalsIgnoreCase(method) ? "application/merge-patch+json" : "application/json" ); con.setRequestProperty("X-FromAppId", application_id); con.setRequestProperty("X-TransactionId",TransactionIdTracker.getNextTransactionId()); - con.setRequestProperty(MetricLogger.REQUEST_ID, ml.getRequestID()); + String mlId = ml.getRequestID(); + if(mlId != null && !mlId.isEmpty()) { + LOG.debug(String.format("MetricLogger requestId = %s", mlId)); + con.setRequestProperty(MetricLogger.REQUEST_ID, mlId); + } else { + LOG.debug("MetricLogger requestId is null"); + } if(user_name != null && !user_name.isEmpty() && user_password != null && !user_password.isEmpty()) { String basicAuth = "Basic " + new String(Base64.encodeBase64((user_name + ":" + user_password).getBytes())); @@ -677,7 +684,7 @@ public class AAIService extends AAIDeclarations implements AAIClient, SvcLogicRe { String encrypted_url = selection; String apnpattern = - "/aai/v10/business/customers/customer/(.+)/service-subscriptions/service-subscription/(.+)/service-instances/service-instance/(.+)/"; + "/aai/v11/business/customers/customer/(.+)/service-subscriptions/service-subscription/(.+)/service-instances/service-instance/(.+)/"; Pattern pattern = Pattern.compile(apnpattern); try { @@ -1753,8 +1760,12 @@ public class AAIService extends AAIDeclarations implements AAIClient, SvcLogicRe SvcLogicContext ctx = new SvcLogicContext(); if(!key.contains(" = ") && isValidURL(key)) { key = String.format("selflink = '%s'", key); + } else + if(!key.contains(" = ") && isValidURI(key)) { + key = String.format("resource-path = '%s'", key); } - HashMap<String, String> nameValues = keyToHashMap(key, ctx); + + HashMap<String, String> nameValues = AAIServiceUtils.keyToHashMap(key, ctx); SelfLinkRequest request = new SelfLinkRequest(type); request.processRequestPathValues(nameValues); @@ -1954,12 +1965,12 @@ public class AAIService extends AAIDeclarations implements AAIClient, SvcLogicRe @Override - public VnfImage requestVnfImageData(String att_uuid) throws AAIServiceException { + public VnfImage requestVnfImageData(String vnf_image_uuid) throws AAIServiceException { VnfImage response = null; try { AAIRequest request = AAIRequest.getRequestFromResource("vnf-image"); - request.addRequestProperty("vnf-image.att-uuid", att_uuid); + request.addRequestProperty("vnf-image.vnf-image-uuid", vnf_image_uuid); String rv = executor.get(request); if(rv != null) { @@ -2330,7 +2341,11 @@ public class AAIService extends AAIDeclarations implements AAIClient, SvcLogicRe try { for (ResultData datum : resultDataList) { String data_type = datum.getResourceType(); - entity = new URL(datum.getResourceLink()); + String resourceLink = datum.getResourceLink(); + if(!resourceLink.isEmpty() && !resourceLink.toLowerCase().startsWith("http")) { + resourceLink = (new EchoRequest()).target_uri + resourceLink; + } + entity = new URL(resourceLink); } } catch (Exception e) { throw new AAIServiceException(e); @@ -2348,6 +2363,7 @@ public class AAIService extends AAIDeclarations implements AAIClient, SvcLogicRe URL requestUrl = null; String requestId = UUID.randomUUID().toString(); + StringBuilder errorStringBuilder = new StringBuilder(); try { @@ -2429,16 +2445,14 @@ public class AAIService extends AAIDeclarations implements AAIClient, SvcLogicRe errorresponse.setRequestError(requestError); throw new AAIServiceException(responseCode, errorresponse); } else { -// -// StringBuilder stringBuilder = new StringBuilder("\n"); -// String line = null; -// while( ( line = reader.readLine() ) != null ) { -// stringBuilder.append("\n").append( line ); -// } -// LOG.info(stringBuilder.toString()); -// -// ErrorResponse errorresponse = mapper.readValue(stringBuilder.toString(), ErrorResponse.class); - ErrorResponse errorresponse = mapper.readValue(reader, ErrorResponse.class); +// StringBuilder errorStringBuilder = new StringBuilder(); + String line = null; + while( ( line = reader.readLine() ) != null ) { + errorStringBuilder.append("\n").append( line ); + } + + ErrorResponse errorresponse = mapper.readValue(errorStringBuilder.toString(), ErrorResponse.class); +// ErrorResponse errorresponse = mapper.readValue(reader, ErrorResponse.class); LOGwriteEndingTrace(responseCode, responseMessage, mapper.writeValueAsString(errorresponse)); throw new AAIServiceException(responseCode, errorresponse); } @@ -2446,7 +2460,7 @@ public class AAIService extends AAIDeclarations implements AAIClient, SvcLogicRe } catch(AAIServiceException aaiexc) { throw aaiexc; } catch (Exception exc) { - LOG.warn("GET", exc); + LOG.warn(errorStringBuilder.toString(), exc); throw new AAIServiceException(exc); } finally { if(inputStream != null){ @@ -2963,12 +2977,14 @@ public class AAIService extends AAIDeclarations implements AAIClient, SvcLogicRe if(!key.contains(" = ")) { if(isValidURL(key)) { key = String.format("selflink = '%s'", key); + } else if(isValidURI(key)) { + key = String.format("resource-path = '%s'", key); } else { return response; } } - HashMap<String, String> nameValues = keyToHashMap(key, ctx); + HashMap<String, String> nameValues = AAIServiceUtils.keyToHashMap(key, ctx); AAIRequest request = new SelfLinkRequest(type); if(nameValues.containsKey(PathRequest.RESOURCE_PATH.replaceAll("-", "_"))) { @@ -3001,6 +3017,21 @@ public class AAIService extends AAIDeclarations implements AAIClient, SvcLogicRe return true; } + + public boolean isValidURI(String url) { + + URI u = null; + + try { + u = new URI(url); + } catch (URISyntaxException e) { + return false; + } + + return true; + } + + @Override protected boolean deleteRelationshipList(URL httpReqUrl, String json_text) throws AAIServiceException { if(httpReqUrl == null) { @@ -3126,6 +3157,9 @@ public class AAIService extends AAIDeclarations implements AAIClient, SvcLogicRe break; default: + if(key.contains("selflink =")) { + break; + } if(!key.contains(String.format("%s.", normResource))) { key = rewriteKey(resource, key, ctx); } @@ -3151,6 +3185,9 @@ public class AAIService extends AAIDeclarations implements AAIClient, SvcLogicRe break; default: + if(key.contains("selflink =")) { + break; + } if(!key.contains(String.format("%s.", normResource))) { key = rewriteKey(resource, key, ctx); } @@ -3176,6 +3213,9 @@ public class AAIService extends AAIDeclarations implements AAIClient, SvcLogicRe break; default: + if(key.contains("selflink =")) { + break; + } if(!key.contains(String.format("%s.", normResource))) { key = rewriteKey(resource, key, ctx); } @@ -3201,6 +3241,9 @@ public class AAIService extends AAIDeclarations implements AAIClient, SvcLogicRe break; default: + if(key.contains("selflink =")) { + break; + } if(!key.contains(String.format("%s.", normResource))) { key = rewriteKey(resource, key, ctx); } @@ -3238,15 +3281,16 @@ public class AAIService extends AAIDeclarations implements AAIClient, SvcLogicRe fieldAnnotatedNames.add(primaryId); } - HashMap<String, String> nameValues = keyToHashMap(key, ctx); + HashMap<String, String> nameValues = AAIServiceUtils.keyToHashMap(key, ctx); Set<String> keyset = nameValues.keySet(); for(String keyName : keyset) { if(keyName.contains(".")) continue; else { String tmpKeyName = keyName.replaceAll("_", "-"); - if(fieldAnnotatedNames.contains(tmpKeyName)) { - key = key.replace(tmpKeyName, String.format("%s.%s", normResource, tmpKeyName)); + String valueToSubstitute = String.format("%s =", tmpKeyName); + if(fieldAnnotatedNames.contains(tmpKeyName) && key.contains(valueToSubstitute)) { + key = key.replace(valueToSubstitute, String.format("%s.%s =", normResource, tmpKeyName)); } } } @@ -3255,4 +3299,13 @@ public class AAIService extends AAIDeclarations implements AAIClient, SvcLogicRe return key; } + @Override + public String getPathTemplateForResource(String resoourceName, String keys, SvcLogicContext ctx) throws MalformedURLException { + return AAIServiceUtils.getPathForResource(resoourceName, StringUtils.join(keys, " AND "), ctx); + } + + @Override + public boolean isDeprecatedFormat(String resource, HashMap<String, String> nameValues) { + return !AAIServiceUtils.isValidFormat(resource, nameValues); + } } diff --git a/aai-service/provider/src/main/java/org/openecomp/sdnc/sli/aai/AAIServiceUtils.java b/aai-service/provider/src/main/java/org/openecomp/sdnc/sli/aai/AAIServiceUtils.java new file mode 100644 index 0000000..e68a282 --- /dev/null +++ b/aai-service/provider/src/main/java/org/openecomp/sdnc/sli/aai/AAIServiceUtils.java @@ -0,0 +1,340 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : SDN-C + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights + * reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdnc.sli.aai; + +import java.lang.annotation.Annotation; +import java.net.MalformedURLException; +import java.net.URI; +import java.net.URISyntaxException; +import java.util.Arrays; +import java.util.HashMap; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; +import java.util.Set; + +import javax.xml.bind.annotation.XmlType; + +import org.apache.commons.lang.StringUtils; +import org.openecomp.aai.inventory.v11.Relationship; +import org.openecomp.aai.inventory.v11.RelationshipData; +import org.openecomp.aai.inventory.v11.RelationshipList; +import org.openecomp.sdnc.sli.SvcLogicContext; +import org.openecomp.sdnc.sli.aai.data.AAIDatum; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class AAIServiceUtils { + + private static final Logger LOG = LoggerFactory.getLogger(AAIService.class); + + public static String getPrimaryIdFromClass(Class<? extends AAIDatum> resourceClass){ + // 1. find class + getLogger().debug(resourceClass.getName()); + AAIDatum instance = null; + + try { + instance = resourceClass.newInstance(); + + Annotation[] annotations = resourceClass.getAnnotations(); + for(Annotation annotation : annotations) { + Class<? extends Annotation> anotationType = annotation.annotationType(); + String annotationName = anotationType.getName(); + + // 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); + return id; + } + } + } + } catch(Exception exc) { + + } + return null; + } + + public static String getSecondaryIdFromClass(Class<? extends AAIDatum> resourceClass){ + // 1. find class + getLogger().debug(resourceClass.getName()); + AAIDatum instance = null; + + try { + instance = resourceClass.newInstance(); + + Annotation[] annotations = resourceClass.getAnnotations(); + for(Annotation annotation : annotations) { + Class<? extends Annotation> anotationType = annotation.annotationType(); + String annotationName = anotationType.getName(); + + // 2. find string property setters and getters for the lists + if("javax.xml.bind.annotation.XmlType".equals(annotationName)){ + boolean primaryIdFound = false; + XmlType order = (XmlType)annotation; + String[] values = order.propOrder(); + for(String value : values) { + String id = camelCaseToDashedString(value); + if(primaryIdFound) { + return id; + } else { + primaryIdFound = true; + } + } + } + } + } catch(Exception exc) { + + } + return null; + } + + + private static Logger getLogger() { + return LOG; + } + + + private static final String regex = "([A-Z][a-z,0-9]+)"; + private static final String replacement = "-$1"; + + public static String camelCaseToDashedString(String propOrder) { + return propOrder.replaceAll(regex, replacement).toLowerCase(); + } + + public static 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 static 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 static 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 static void populateRelationshipDataFromPath(RelationshipList rl) throws URISyntaxException { + List<Relationship> list = rl.getRelationship(); + if(list != null && !list.isEmpty()) { + for(Relationship relationship : list) { + if(relationship.getRelationshipData().isEmpty()){ + String link = relationship.getRelatedLink(); + URI uri = new URI(link); + link = uri.getPath(); + HashMap<String,String> contributors = pathToHashMap(link); + for(String key : contributors.keySet()) { + RelationshipData rd = new RelationshipData(); + rd.setRelationshipKey(key); + rd.setRelationshipValue(contributors.get(key)); + relationship.getRelationshipData().add(rd); + } + } + } + } + } + + protected static HashMap<String,String> pathToHashMap(String path) { + HashMap<String, String> nameValues = new HashMap<String, String>(); + + String[] split = path.split("/"); + + LinkedList<String> list = new LinkedList<String>( Arrays.asList(split)); + Iterator<String> it = list.iterator(); + + while(it.hasNext()) { + String tag = it.next(); + if(!tag.isEmpty()) { + if(AAIRequest.getResourceNames().contains(tag)){ + LOG.info(tag); + // get the class from tag + Class<? extends AAIDatum> clazz = null; + try { + clazz = AAIRequest.getClassFromResource(tag); + String fieldName = AAIServiceUtils.getPrimaryIdFromClass(clazz); + + String value = it.next(); + if(!StringUtils.isEmpty(value)){ + nameValues.put(String.format("%s.%s", tag, fieldName), value); + switch(tag) { + case "cloud-region": + case "entitlement": + case "license": + case "route-target": + case "service-capability": + case "ctag-pool": + String secondaryFieldName = AAIServiceUtils.getSecondaryIdFromClass(clazz); + if(secondaryFieldName != null) { + value = it.next(); + nameValues.put(String.format("%s.%s", tag, secondaryFieldName), value); + } + break; + default: + break; + } + } + } catch (ClassNotFoundException exc) { + LOG.info("Caught exception", exc); + } + } + } + } + return nameValues; + } + + public static String getPathForResource(String resource, String key, SvcLogicContext ctx ) throws MalformedURLException{ + HashMap<String, String> nameValues = AAIServiceUtils.keyToHashMap(key, ctx); + AAIRequest request = AAIRequest.createRequest(resource, nameValues); + + for(String name : nameValues.keySet()) { + request.addRequestProperty(name, nameValues.get(name)); + } + return request.getRequestPath(); + } + + public static boolean isValidFormat(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) || "related-link".equals(key) || "related_link".equals(key) || "selflink".equals(key)) + continue; + else { + getLogger().warn(String.format("key %s is incompatible with resource type '%s'", key, resource)); + } + } + } + return true; + } +} diff --git a/aai-service/provider/src/main/java/org/openecomp/sdnc/sli/aai/CloudRegionRequest.java b/aai-service/provider/src/main/java/org/openecomp/sdnc/sli/aai/CloudRegionRequest.java index 5751788..b4eddfa 100644 --- a/aai-service/provider/src/main/java/org/openecomp/sdnc/sli/aai/CloudRegionRequest.java +++ b/aai-service/provider/src/main/java/org/openecomp/sdnc/sli/aai/CloudRegionRequest.java @@ -34,7 +34,7 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import com.google.common.base.Joiner; -import org.openecomp.aai.inventory.v10.CloudRegion; +import org.openecomp.aai.inventory.v11.CloudRegion; public class CloudRegionRequest extends AAIRequest { diff --git a/aai-service/provider/src/main/java/org/openecomp/sdnc/sli/aai/GenericQueryRequest.java b/aai-service/provider/src/main/java/org/openecomp/sdnc/sli/aai/GenericQueryRequest.java index 8756fab..b8f9450 100644 --- a/aai-service/provider/src/main/java/org/openecomp/sdnc/sli/aai/GenericQueryRequest.java +++ b/aai-service/provider/src/main/java/org/openecomp/sdnc/sli/aai/GenericQueryRequest.java @@ -31,7 +31,7 @@ import org.openecomp.sdnc.sli.aai.data.AAIDatum; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; -import org.openecomp.aai.inventory.v10.ResultData; +import org.openecomp.aai.inventory.v11.ResultData; public class GenericQueryRequest extends AAIRequest { diff --git a/aai-service/provider/src/main/java/org/openecomp/sdnc/sli/aai/GenericRequest.java b/aai-service/provider/src/main/java/org/openecomp/sdnc/sli/aai/GenericRequest.java index 1da543b..1d51b82 100644 --- a/aai-service/provider/src/main/java/org/openecomp/sdnc/sli/aai/GenericRequest.java +++ b/aai-service/provider/src/main/java/org/openecomp/sdnc/sli/aai/GenericRequest.java @@ -24,6 +24,7 @@ package org.openecomp.sdnc.sli.aai; import java.io.UnsupportedEncodingException; import java.lang.annotation.Annotation; import java.lang.reflect.Field; +import java.lang.reflect.Method; import java.net.MalformedURLException; import java.net.URL; import java.util.HashMap; @@ -37,8 +38,8 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import com.google.common.base.Joiner; -import org.openecomp.aai.inventory.v10.L3Network; -import org.openecomp.aai.inventory.v10.L3Networks; +import org.openecomp.aai.inventory.v11.L3Network; +import org.openecomp.aai.inventory.v11.L3Networks; public class GenericRequest extends AAIRequest { @@ -50,30 +51,31 @@ public class GenericRequest extends AAIRequest { } @Override - public URL getRequestUrl(String method, String resourceVersion) throws UnsupportedEncodingException, MalformedURLException { + public String updatePathDataValues(Object resourceVersion) throws UnsupportedEncodingException, MalformedURLException { - String request_url = null; String originalPath = null; String pathSubstitute = null; - - request_url = target_uri + getRequestPath(); - + + String request_url = getRequestPath(); + Map<String, String> queryParams = new HashMap<String, String> (); if(resourceVersion != null) { - queryParams.put("resource-version",resourceVersion); + queryParams.put("resource-version", resourceVersion.toString()); } Set<String> uniqueResources = extractUniqueResourceSetFromKeys(requestProperties.stringPropertyNames()); String[] keys = requestProperties.keySet().toArray(new String[0]); for(String key : keys) { - if("cloud-region.cloud-region-id".equals(key)) - continue; - if("entitlement.resource-uuid".equals(key)) - continue; - if("license.resource-uuid".equals(key)) + switch(key) { + case "cloud-region.cloud-region-id": + case "entitlement.resource-uuid": + case "license.resource-uuid": + case "route-target.route-target-role": + case "service-capability.vnf-type": + case "ctag-pool.availability-zone-name": continue; - + } String value = requestProperties.getProperty(key); if(key.contains(".")) { @@ -99,6 +101,27 @@ public class GenericRequest extends AAIRequest { String encoded_owner = encodeQuery(value); String encoded_region = encodeQuery(cloudRegionId); request_url = request_url.replace(token, String.format("%s/%s/%s", splitKey[0], encoded_owner, encoded_region)); + } else if("route-target".equals(splitKey[0])){ + String cloudRegionId = requestProperties.getProperty("route-target.route-target-role"); + aaiService.LOGwriteDateTrace("route-target-role", cloudRegionId); + String token = String.format("%s/{%s}/{route-target-role}", splitKey[0], splitKey[1] ); + String encoded_owner = encodeQuery(value); + String encoded_region = encodeQuery(cloudRegionId); + request_url = request_url.replace(token, String.format("%s/%s/%s", splitKey[0], encoded_owner, encoded_region)); + } else if("service-capability".equals(splitKey[0])){ + String cloudRegionId = requestProperties.getProperty("service-capability.vnf-type"); + aaiService.LOGwriteDateTrace("vnf-type", cloudRegionId); + String token = String.format("%s/{%s}/{vnf-type}", splitKey[0], splitKey[1] ); + String encoded_owner = encodeQuery(value); + String encoded_region = encodeQuery(cloudRegionId); + request_url = request_url.replace(token, String.format("%s/%s/%s", splitKey[0], encoded_owner, encoded_region)); + } else if("ctag-pool".equals(splitKey[0])){ + String cloudRegionId = requestProperties.getProperty("ctag-pool.availability-zone-name"); + aaiService.LOGwriteDateTrace("availability-zone-name", cloudRegionId); + String token = String.format("%s/{%s}/{availability-zone-name}", splitKey[0], splitKey[1] ); + String encoded_owner = encodeQuery(value); + String encoded_region = encodeQuery(cloudRegionId); + request_url = request_url.replace(token, String.format("%s/%s/%s", splitKey[0], encoded_owner, encoded_region)); } else { Class<? extends AAIDatum> clazz = null; try { @@ -164,111 +187,8 @@ public class GenericRequest extends AAIRequest { String queryString = mapJoiner.join(queryParams); request_url = String.format("%s?%s", request_url, queryString); } - - URL http_req_url = new URL(request_url); - - aaiService.LOGwriteFirstTrace(method, http_req_url.toString()); - - - return http_req_url; - } - - - public URL OriginalgetRequestUrl(String method, String resourceVersion) throws UnsupportedEncodingException, MalformedURLException { - - String request_url = null; - - request_url = target_uri + getRequestPath(); - - Map<String, String> keyValuepairs = new HashMap<String, String> (); - Set<String> uniqueResources = extractUniqueResourceSetFromKeys(requestProperties.stringPropertyNames()); - - String[] keys = requestProperties.keySet().toArray(new String[0]); - for(String key : keys) { - if("cloud-region.cloud-region-id".equals(key)) - continue; - if("entitlement.resource-uuid".equals(key)) - continue; - if("license.resource-uuid".equals(key)) - continue; - - - String value = requestProperties.getProperty(key); - if(key.contains(".")) { - String[] splitKey = key.split("\\."); - if("cloud-region".equals(splitKey[0])){ - String cloudRegionId = requestProperties.getProperty("cloud-region.cloud-region-id"); - aaiService.LOGwriteDateTrace("cloud-region-id", cloudRegionId); - String token = String.format("%s/{%s}/{cloud-region-id}", splitKey[0], splitKey[1] ); - String encoded_owner = encodeQuery(value); - String encoded_region = encodeQuery(cloudRegionId); - request_url = request_url.replace(token, String.format("%s/%s/%s", splitKey[0], encoded_owner, encoded_region)); - } else if("entitlement".equals(splitKey[0])){ - String cloudRegionId = requestProperties.getProperty("entitlement.resource-uuid"); - aaiService.LOGwriteDateTrace("resource-uuid", cloudRegionId); - String token = String.format("%s/{%s}/{resource-uuid}", splitKey[0], splitKey[1] ); - String encoded_owner = encodeQuery(value); - String encoded_region = encodeQuery(cloudRegionId); - request_url = request_url.replace(token, String.format("%s/%s/%s", splitKey[0], encoded_owner, encoded_region)); - } else if("license".equals(splitKey[0])){ - String cloudRegionId = requestProperties.getProperty("license.resource-uuid"); - aaiService.LOGwriteDateTrace("resource-uuid", cloudRegionId); - String token = String.format("%s/{%s}/{resource-uuid}", splitKey[0], splitKey[1] ); - String encoded_owner = encodeQuery(value); - String encoded_region = encodeQuery(cloudRegionId); - request_url = request_url.replace(token, String.format("%s/%s/%s", splitKey[0], encoded_owner, encoded_region)); - } else { - Class<? extends AAIDatum> clazz = null; - try { - clazz = getClassFromResource(splitKey[0]); - } catch (ClassNotFoundException exc) { - LOG.warn("AAIRequest does not support class: " + exc.getMessage()); - return null; - } - - if(clazz != null) { - if(clazz == this.model) { - Field[] fields = this.model.getDeclaredFields(); - Field field = fields[0]; - String fieldName = field.getName(); - XmlElement annotation = field.getAnnotation(XmlElement.class); - String primaryId = annotation.name(); - if("##default".equals(primaryId)) { - primaryId = fieldName; - } - - String token = String.format("%s/{%s}", splitKey[0], primaryId); - - if(splitKey[1].equals(primaryId)) { - String encoded_vnf = encodeQuery(value); - request_url = request_url.replace(token, String.format("%s/%s", splitKey[0], encoded_vnf)); - } else { - String replacement = String.format("%s?%s=%s", splitKey[0], splitKey[1], encodeQuery(value)); - if(request_url.contains(token)) - request_url = request_url.replace(token, replacement); - } - } else { - String token = String.format("%s/{%s}", splitKey[0], splitKey[1]); - String encoded_vnf = encodeQuery(value); - request_url = request_url.replace(token, String.format("%s/%s", splitKey[0], encoded_vnf)); - } - } - - } - aaiService.LOGwriteDateTrace(splitKey[1], value); - } - } - - - if(resourceVersion != null) { - request_url = request_url +"?resource-version="+resourceVersion; - } - URL http_req_url = new URL(request_url); - - aaiService.LOGwriteFirstTrace(method, http_req_url.toString()); - - - return http_req_url; + + return request_url; } @Override diff --git a/aai-service/provider/src/main/java/org/openecomp/sdnc/sli/aai/GenericVnfRequest.java b/aai-service/provider/src/main/java/org/openecomp/sdnc/sli/aai/GenericVnfRequest.java index 9951436..cc70adc 100644 --- a/aai-service/provider/src/main/java/org/openecomp/sdnc/sli/aai/GenericVnfRequest.java +++ b/aai-service/provider/src/main/java/org/openecomp/sdnc/sli/aai/GenericVnfRequest.java @@ -31,7 +31,7 @@ import org.openecomp.sdnc.sli.aai.data.AAIDatum; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; -import org.openecomp.aai.inventory.v10.GenericVnf; +import org.openecomp.aai.inventory.v11.GenericVnf; public class GenericVnfRequest extends AAIRequest { diff --git a/aai-service/provider/src/main/java/org/openecomp/sdnc/sli/aai/L3InterfaceIpv4AddressListRequest.java b/aai-service/provider/src/main/java/org/openecomp/sdnc/sli/aai/L3InterfaceIpv4AddressListRequest.java index 86ab2ef..e89c89c 100644 --- a/aai-service/provider/src/main/java/org/openecomp/sdnc/sli/aai/L3InterfaceIpv4AddressListRequest.java +++ b/aai-service/provider/src/main/java/org/openecomp/sdnc/sli/aai/L3InterfaceIpv4AddressListRequest.java @@ -31,7 +31,7 @@ import org.openecomp.sdnc.sli.aai.data.AAIDatum; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; -import org.openecomp.aai.inventory.v10.L3InterfaceIpv4AddressList; +import org.openecomp.aai.inventory.v11.L3InterfaceIpv4AddressList; public class L3InterfaceIpv4AddressListRequest extends AAIRequest { diff --git a/aai-service/provider/src/main/java/org/openecomp/sdnc/sli/aai/L3InterfaceIpv6AddressListRequest.java b/aai-service/provider/src/main/java/org/openecomp/sdnc/sli/aai/L3InterfaceIpv6AddressListRequest.java index 3353b80..84ada8a 100644 --- a/aai-service/provider/src/main/java/org/openecomp/sdnc/sli/aai/L3InterfaceIpv6AddressListRequest.java +++ b/aai-service/provider/src/main/java/org/openecomp/sdnc/sli/aai/L3InterfaceIpv6AddressListRequest.java @@ -31,7 +31,7 @@ import org.openecomp.sdnc.sli.aai.data.AAIDatum; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; -import org.openecomp.aai.inventory.v10.L3InterfaceIpv6AddressList; +import org.openecomp.aai.inventory.v11.L3InterfaceIpv6AddressList; public class L3InterfaceIpv6AddressListRequest extends AAIRequest { diff --git a/aai-service/provider/src/main/java/org/openecomp/sdnc/sli/aai/LInterfaceRequest.java b/aai-service/provider/src/main/java/org/openecomp/sdnc/sli/aai/LInterfaceRequest.java index 25ea900..f2a3d5a 100644 --- a/aai-service/provider/src/main/java/org/openecomp/sdnc/sli/aai/LInterfaceRequest.java +++ b/aai-service/provider/src/main/java/org/openecomp/sdnc/sli/aai/LInterfaceRequest.java @@ -31,7 +31,7 @@ import org.openecomp.sdnc.sli.aai.data.AAIDatum; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; -import org.openecomp.aai.inventory.v10.LInterface; +import org.openecomp.aai.inventory.v11.LInterface; public class LInterfaceRequest extends AAIRequest { diff --git a/aai-service/provider/src/main/java/org/openecomp/sdnc/sli/aai/LagInterfacePnfRequest.java b/aai-service/provider/src/main/java/org/openecomp/sdnc/sli/aai/LagInterfacePnfRequest.java index f42aa8f..5880b7c 100644 --- a/aai-service/provider/src/main/java/org/openecomp/sdnc/sli/aai/LagInterfacePnfRequest.java +++ b/aai-service/provider/src/main/java/org/openecomp/sdnc/sli/aai/LagInterfacePnfRequest.java @@ -33,7 +33,7 @@ import org.slf4j.LoggerFactory; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; -import org.openecomp.aai.inventory.v10.LagInterface; +import org.openecomp.aai.inventory.v11.LagInterface; public class LagInterfacePnfRequest extends AAIRequest { diff --git a/aai-service/provider/src/main/java/org/openecomp/sdnc/sli/aai/NamedQueryRequest.java b/aai-service/provider/src/main/java/org/openecomp/sdnc/sli/aai/NamedQueryRequest.java index 2f3a3df..4ee06a9 100644 --- a/aai-service/provider/src/main/java/org/openecomp/sdnc/sli/aai/NamedQueryRequest.java +++ b/aai-service/provider/src/main/java/org/openecomp/sdnc/sli/aai/NamedQueryRequest.java @@ -42,7 +42,7 @@ import com.fasterxml.jackson.databind.node.ObjectNode; import com.fasterxml.jackson.databind.type.TypeFactory; import com.fasterxml.jackson.module.jaxb.JaxbAnnotationIntrospector; -import org.openecomp.aai.inventory.v10.InventoryResponseItems; +import org.openecomp.aai.inventory.v11.InventoryResponseItems; public class NamedQueryRequest extends AAIRequest { diff --git a/aai-service/provider/src/main/java/org/openecomp/sdnc/sli/aai/NodesQueryRequest.java b/aai-service/provider/src/main/java/org/openecomp/sdnc/sli/aai/NodesQueryRequest.java index da053f5..626165d 100644 --- a/aai-service/provider/src/main/java/org/openecomp/sdnc/sli/aai/NodesQueryRequest.java +++ b/aai-service/provider/src/main/java/org/openecomp/sdnc/sli/aai/NodesQueryRequest.java @@ -31,7 +31,7 @@ import org.openecomp.sdnc.sli.aai.data.AAIDatum; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; -import org.openecomp.aai.inventory.v10.SearchResults; +import org.openecomp.aai.inventory.v11.SearchResults; public class NodesQueryRequest extends AAIRequest { diff --git a/aai-service/provider/src/main/java/org/openecomp/sdnc/sli/aai/PInterfacePnfRequest.java b/aai-service/provider/src/main/java/org/openecomp/sdnc/sli/aai/PInterfacePnfRequest.java index addcc99..1250891 100644 --- a/aai-service/provider/src/main/java/org/openecomp/sdnc/sli/aai/PInterfacePnfRequest.java +++ b/aai-service/provider/src/main/java/org/openecomp/sdnc/sli/aai/PInterfacePnfRequest.java @@ -33,7 +33,7 @@ import org.slf4j.LoggerFactory; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; -import org.openecomp.aai.inventory.v10.PInterface; +import org.openecomp.aai.inventory.v11.PInterface; public class PInterfacePnfRequest extends AAIRequest { diff --git a/aai-service/provider/src/main/java/org/openecomp/sdnc/sli/aai/PInterfaceRequest.java b/aai-service/provider/src/main/java/org/openecomp/sdnc/sli/aai/PInterfaceRequest.java index 0591d8a..41f2965 100644 --- a/aai-service/provider/src/main/java/org/openecomp/sdnc/sli/aai/PInterfaceRequest.java +++ b/aai-service/provider/src/main/java/org/openecomp/sdnc/sli/aai/PInterfaceRequest.java @@ -31,7 +31,7 @@ import org.slf4j.LoggerFactory; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; -import org.openecomp.aai.inventory.v10.PInterface; +import org.openecomp.aai.inventory.v11.PInterface; public class PInterfaceRequest extends AAIRequest { diff --git a/aai-service/provider/src/main/java/org/openecomp/sdnc/sli/aai/PhysicalLinkRequest.java b/aai-service/provider/src/main/java/org/openecomp/sdnc/sli/aai/PhysicalLinkRequest.java index 0d29a72..a8524a0 100644 --- a/aai-service/provider/src/main/java/org/openecomp/sdnc/sli/aai/PhysicalLinkRequest.java +++ b/aai-service/provider/src/main/java/org/openecomp/sdnc/sli/aai/PhysicalLinkRequest.java @@ -30,7 +30,7 @@ import org.openecomp.sdnc.sli.aai.data.AAIDatum; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; -import org.openecomp.aai.inventory.v10.PhysicalLink; +import org.openecomp.aai.inventory.v11.PhysicalLink; public class PhysicalLinkRequest extends AAIRequest { diff --git a/aai-service/provider/src/main/java/org/openecomp/sdnc/sli/aai/RelationshipRequest.java b/aai-service/provider/src/main/java/org/openecomp/sdnc/sli/aai/RelationshipRequest.java index 497efc7..badb8ea 100644 --- a/aai-service/provider/src/main/java/org/openecomp/sdnc/sli/aai/RelationshipRequest.java +++ b/aai-service/provider/src/main/java/org/openecomp/sdnc/sli/aai/RelationshipRequest.java @@ -30,7 +30,7 @@ import org.openecomp.sdnc.sli.aai.data.AAIDatum; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; -import org.openecomp.aai.inventory.v10.RelationshipList; +import org.openecomp.aai.inventory.v11.RelationshipList; public class RelationshipRequest extends AAIRequest { diff --git a/aai-service/provider/src/main/java/org/openecomp/sdnc/sli/aai/SelfLinkRequest.java b/aai-service/provider/src/main/java/org/openecomp/sdnc/sli/aai/SelfLinkRequest.java index baa2b26..07defd3 100644 --- a/aai-service/provider/src/main/java/org/openecomp/sdnc/sli/aai/SelfLinkRequest.java +++ b/aai-service/provider/src/main/java/org/openecomp/sdnc/sli/aai/SelfLinkRequest.java @@ -23,6 +23,7 @@ package org.openecomp.sdnc.sli.aai; import java.io.UnsupportedEncodingException; import java.net.MalformedURLException; +import java.net.URI; import java.net.URL; import org.openecomp.sdnc.sli.aai.data.AAIDatum; @@ -48,7 +49,14 @@ public class SelfLinkRequest extends AAIRequest { String request_url = null; request_url = requestProperties.getProperty(SELFLINK); - + try { + URI uri = new URI(request_url); + if(uri.getHost() == null) { + request_url = target_uri + request_url; + } + } catch(Exception exc) { + LOG.error("SelfLinkRequest.getRequestUrl", exc); + } String query = null; if(request_url.contains("?")) { diff --git a/aai-service/provider/src/main/java/org/openecomp/sdnc/sli/aai/SubInterfaceRequest.java b/aai-service/provider/src/main/java/org/openecomp/sdnc/sli/aai/SubInterfaceRequest.java index 2db1025..134a169 100644 --- a/aai-service/provider/src/main/java/org/openecomp/sdnc/sli/aai/SubInterfaceRequest.java +++ b/aai-service/provider/src/main/java/org/openecomp/sdnc/sli/aai/SubInterfaceRequest.java @@ -31,7 +31,7 @@ import org.openecomp.sdnc.sli.aai.data.AAIDatum; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; -import org.openecomp.aai.inventory.v10.LInterface; +import org.openecomp.aai.inventory.v11.LInterface; public class SubInterfaceRequest extends AAIRequest { diff --git a/aai-service/provider/src/main/java/org/openecomp/sdnc/sli/aai/data/SubInterface.java b/aai-service/provider/src/main/java/org/openecomp/sdnc/sli/aai/data/SubInterface.java index 1c027c9..585fdc1 100644 --- a/aai-service/provider/src/main/java/org/openecomp/sdnc/sli/aai/data/SubInterface.java +++ b/aai-service/provider/src/main/java/org/openecomp/sdnc/sli/aai/data/SubInterface.java @@ -31,8 +31,8 @@ import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonPropertyOrder; -import org.openecomp.aai.inventory.v10.RelationshipList; -import org.openecomp.aai.inventory.v10.Vlans; +import org.openecomp.aai.inventory.v11.RelationshipList; +import org.openecomp.aai.inventory.v11.Vlans; @JsonInclude(JsonInclude.Include.NON_NULL) @Generated("org.jsonschema2pojo") diff --git a/aai-service/provider/src/main/java/org/openecomp/sdnc/sli/aai/query/InstanceFilter.java b/aai-service/provider/src/main/java/org/openecomp/sdnc/sli/aai/query/InstanceFilter.java index a6f5d44..0dbd5ac 100644 --- a/aai-service/provider/src/main/java/org/openecomp/sdnc/sli/aai/query/InstanceFilter.java +++ b/aai-service/provider/src/main/java/org/openecomp/sdnc/sli/aai/query/InstanceFilter.java @@ -33,10 +33,10 @@ import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonPropertyOrder; -import org.openecomp.aai.inventory.v10.L3Network; -import org.openecomp.aai.inventory.v10.Pnf; -import org.openecomp.aai.inventory.v10.LogicalLink; -import org.openecomp.aai.inventory.v10.ServiceInstance; +import org.openecomp.aai.inventory.v11.L3Network; +import org.openecomp.aai.inventory.v11.Pnf; +import org.openecomp.aai.inventory.v11.LogicalLink; +import org.openecomp.aai.inventory.v11.ServiceInstance; @JsonInclude(JsonInclude.Include.NON_NULL) @Generated("org.jsonschema2pojo") diff --git a/aai-service/provider/src/main/java/org/openecomp/sdnc/sli/aai/query/Results.java b/aai-service/provider/src/main/java/org/openecomp/sdnc/sli/aai/query/Results.java index b6f2278..d756d85 100644 --- a/aai-service/provider/src/main/java/org/openecomp/sdnc/sli/aai/query/Results.java +++ b/aai-service/provider/src/main/java/org/openecomp/sdnc/sli/aai/query/Results.java @@ -27,7 +27,7 @@ import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlType; -import org.openecomp.aai.inventory.v10.*; +import org.openecomp.aai.inventory.v11.*; @XmlAccessorType(XmlAccessType.FIELD) |