import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.MalformedURLException;
+import java.net.URISyntaxException;
import java.net.URL;
import java.net.URLDecoder;
import java.net.URLEncoder;
import javax.xml.bind.annotation.XmlType;
import org.apache.commons.lang.StringUtils;
-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.v11.Image;
-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;
import org.onap.ccsdk.sli.adaptors.aai.query.InstanceFilter;
import org.onap.ccsdk.sli.adaptors.aai.query.NamedQueryData;
import org.onap.ccsdk.sli.adaptors.aai.query.QueryParameters;
import org.onap.ccsdk.sli.adaptors.aai.query.Result;
+import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
+import org.onap.ccsdk.sli.core.sli.SvcLogicException;
+import org.openecomp.aai.inventory.v13.GenericVnf;
+import org.openecomp.aai.inventory.v13.Image;
+import org.openecomp.aai.inventory.v13.InventoryResponseItem;
+import org.openecomp.aai.inventory.v13.InventoryResponseItems;
+import org.openecomp.aai.inventory.v13.L3Network;
+import org.openecomp.aai.inventory.v13.LogicalLink;
+import org.openecomp.aai.inventory.v13.Metadata;
+import org.openecomp.aai.inventory.v13.Metadatum;
+import org.openecomp.aai.inventory.v13.Pnf;
+import org.openecomp.aai.inventory.v13.RelatedToProperty;
+import org.openecomp.aai.inventory.v13.Relationship;
+import org.openecomp.aai.inventory.v13.RelationshipData;
+import org.openecomp.aai.inventory.v13.RelationshipList;
+import org.openecomp.aai.inventory.v13.ResultData;
+import org.openecomp.aai.inventory.v13.SearchResults;
+import org.openecomp.aai.inventory.v13.ServiceInstance;
+import org.openecomp.aai.inventory.v13.Vlan;
+import org.openecomp.aai.inventory.v13.Vlans;
+import org.openecomp.aai.inventory.v13.Vserver;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
protected abstract Logger getLogger();
- public abstract AAIRequestExecutor getExecutor();
+ public abstract AAIExecutorInterface getExecutor();
@Override
getLogger().warn("Failed query - returning FAILURE", exc);
return QueryStatus.FAILURE;
}
-
-// return QueryStatus.SUCCESS;
}
request.processRequestPathValues(nameValues);
path = request.getRequestUrl("GET", null);
params.put("vserver-selflink", path.toString());
- } catch (UnsupportedEncodingException | MalformedURLException e) {
- // TODO : Fix this
+ } catch (UnsupportedEncodingException | MalformedURLException | URISyntaxException e) {
params.put("vserver-selflink", "/vserver");
}
}
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;
}
} catch (Exception exc) {
ctx.setAttribute(prefix + ".error.message", exc.getMessage());
return QueryStatus.FAILURE;
}
} else {
- String reSource = resource.toLowerCase().replace("-", "_");
- String vnfId;
-
- try {
- switch(reSource) {
- case "generic_vnf":
- case "generic-vnf":
- vnfId = nameValues.get("vnf_id");
- if(vnfId == null) {
- getLogger().debug("Save(generic-vnf) with no vnf-id specified. Returning FAILURE");
- return QueryStatus.FAILURE;
- }
- vnfId = vnfId.trim().replace("'", "").replace("$", "").replace("'", "");
- GenericVnf vnf = this.requestGenericVnfData(vnfId);
- String status = params.get("prov-status");
- boolean updated = false;
- if(status != null && !status.isEmpty()) {
- vnf.setProvStatus(status);
- }
- if(updated) {
- this.postGenericVnfData(vnfId, vnf);
- }
- break;
- case "vpe":
- return update( resource, key, params, prefix, ctx) ;
-
- default:
- getLogger().debug("Save() executing default path - returning FAILURE");
- return QueryStatus.FAILURE;
- }
- } catch (Exception exc) {
- getLogger().warn("Failed save - returning FAILURE", exc);
- ctx.setAttribute(prefix + ".error.message", exc.getMessage());
- return QueryStatus.FAILURE;
- }
+ getLogger().debug("Save() request for {} is not supported- returning FAILURE", resource);
+ return QueryStatus.FAILURE;
}
-
- getLogger().debug("Save - returning SUCCESS");
- return QueryStatus.SUCCESS;
}
@Override
if(!itemRemoved)
return QueryStatus.NOT_FOUND;
-
-// AAIRequest masterRequest = new GenericVnfRequest();
-// masterRequest.addRequestProperty(GenericVnfRequest.VNF_ID, vnfId);
-// relationshipRequest.addMasterRequest(masterRequest);
-// Map<String, String> attributes = objectToProperties(vnf);
-// try {
-// Boolean result = getExecutor().delete(relationshipRequest, attributes.get(AAIRequest.RESOURCE_VERSION));
-// } catch (AAIServiceException e) {
-// return QueryStatus.FAILURE;
-// }
-
try {
this.postGenericVnfData(vnf.getVnfId(), vnf);
} catch (AAIServiceException exc) {
@Override
public QueryStatus isAvailable(String arg0, String arg1, String arg2, SvcLogicContext arg3)
throws SvcLogicException {
- // TODO Auto-generated method stub
throw new SvcLogicException("Method AAIService.isAvailable() has not been implemented yet");
}
@Override
public QueryStatus notify(String resource, String action, String key, SvcLogicContext ctx) throws SvcLogicException {
- // TODO Auto-generated method stub
throw new SvcLogicException("Method AAIService.notify() has not been implemented yet");
}
// @Override
public QueryStatus newModelQuery(String resource, boolean localOnly, String select, String key, String prefix, String orderBy, SvcLogicContext ctx) {
- Object response = null;
QueryStatus retval = QueryStatus.SUCCESS;
String modifier = null;
return retval;
}
- 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 QueryStatus processResponseData(String rv, String resource, AAIRequest request, String prefix, SvcLogicContext ctx, Map<String, String> nameValues, String modifier) throws JsonParseException, JsonMappingException, IOException, AAIServiceException
{
Object response;
@Override
public QueryStatus release(String arg0, String arg1, SvcLogicContext arg2) throws SvcLogicException {
- // TODO Auto-generated method stub
throw new SvcLogicException("Method AAIService.release() has not been implemented yet");
}
@Override
public QueryStatus reserve(String arg0, String arg1, String arg2, String arg3, SvcLogicContext arg4)
throws SvcLogicException {
- // TODO Auto-generated method stub
throw new SvcLogicException("Method AAIService.reserve() has not been implemented yet");
}
Method setter = null;
try {
setter = resourceClass.getMethod("set"+StringUtils.capitalize(value), type);
- if(type.getName().startsWith("java.lang") || "boolean".equals(type.getName()) || "long".equals(type.getName())) {
+ if(type.getName().startsWith("java.lang") || "boolean".equals(type.getName()) || "long".equals(type.getName()) || "int".equals(type.getName())) {
try {
- setter.setAccessible(true);
Object arglist[] = new Object[1];
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())) {
+ if("java.lang.Long".equals(type.getName()) || "java.lang.Integer".equals(type.getName())) {
+ String fv = params.get(id);
+ if(fv == null || fv.isEmpty()) {
+ arglist[0] = null;
+ } else {
+ arglist[0] = valueOf(type, params.get(id));
+ }
+ } else if("boolean".equals(type.getName())) {
arglist[0] = valueOf(Boolean.class, params.get(id));
+ } else if("int".equals(type.getName())) {
+ arglist[0] = valueOf(Integer.class, params.get(id));
} else if("long".equals(type.getName())) {
+ String fv = params.get(id);
+ if(fv == null || fv.isEmpty()) {
+ arglist[0] = null;
+ } else {
arglist[0] = valueOf(Long.class, params.get(id));
+ }
} else {
arglist[0] = valueOf(type, params.get(id));
}
}
- Object o = setter.invoke(instance, arglist);
+ Object obj = setter.invoke(instance, arglist);
}
set.remove(id);
Throwable cause = x.getCause();
getLogger().warn("Failed process for " + resourceClass.getName(), x);
}
- } else if(type.getName().equals("java.util.List")) {
+ } else if("java.util.List".equals(type.getName())) {
List<String> newValues = new ArrayList<>();
String length = id+"_length";
if(!params.isEmpty() && params.containsKey(length)) {
Method method = getters.get(attribute);
if(method != null) {
try {
- method.setAccessible(true);
Object arglist[] = new Object[0];
// arglist[0] = value;
Class<?>[] types = method.getParameterTypes();
if(getRelationshipListMethod != null){
try {
- getRelationshipListMethod.setAccessible(true);
obj = getRelationshipListMethod.invoke(instance);
} catch (InvocationTargetException x) {
Throwable cause = x.getCause();
Method setRelationshipListMethod = resourceClass.getMethod("setRelationshipList", RelationshipList.class);
if(setRelationshipListMethod != null){
try {
- setRelationshipListMethod.setAccessible(true);
Object arglist[] = new Object[1];
arglist[0] = relationshipList;
Relationship relationship = new Relationship();
relationships.add(relationship);
relationship.setRelatedTo(relatedTo);
+ String relationshipLabel = "relationship-list.relationship[" + i + "].relationship-label";
+ if(params.containsKey(searchKey)) {
+ relationship.setRelationshipLabel(params.get(relationshipLabel));
+ }
+ getLogger().debug("About to process related link of {}", relatedLink);
if(relatedLink != null) {
+ if(relatedLink.contains("v$"))
+ relatedLink = relatedLink.replace("v$", "v13");
relationship.setRelatedLink(relatedLink);
} else {
-// List<RelationshipData> relData = relationship.getRelationshipData();
Map<String, String> relParams = new HashMap<>();
- while(true) {
- String searchRelationshipKey = "relationship-list.relationship[" + i + "].relationship-data[" + j + "].relationship-key";
- String searchRelationshipValue = "relationship-list.relationship[" + i + "].relationship-data[" + j + "].relationship-value";
- if(!params.containsKey(searchRelationshipKey))
- break;
+ 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;
- relParams.put(params.get(searchRelationshipKey), params.get(searchRelationshipValue));
- j++;
- }
+ relParams.put(params.get(searchRelationshipKey), params.get(searchRelationshipValue));
+ j++;
+ }
AAIRequest rlRequest = AAIRequest.createRequest(relatedTo, relParams);
for(Map.Entry<String,String> entry : relParams.entrySet()) {
rlRequest.addRequestProperty(entry.getKey(), entry.getValue());
String path = rlRequest.updatePathDataValues(null);
relationship.setRelatedLink(path);
}
+ {
+ int k = 0;
+ // process related to properties
+ Map<String, String> relParams = new HashMap<String, String>();
+
+ while(true) {
+ String searchRelatedToKey = "relationship-list.relationship[" + i + "].related-to-property[" + k + "].property-key";
+ String searchRelatedToValue = "relationship-list.relationship[" + i + "].related-to-property[" + k + "].property-value";
+ if(!params.containsKey(searchRelatedToKey))
+ break;
+
+ RelatedToProperty relDatum = new RelatedToProperty();
+ relDatum.setPropertyKey(params.get(searchRelatedToKey));
+ relDatum.setPropertyValue(params.get(searchRelatedToValue));
+ relationship.getRelatedToProperty().add(relDatum);
+
+ relParams.put(params.get(searchRelatedToKey), params.get(searchRelatedToValue));
+ k++;
+ }
+ }
i++;
}
}
Method getVLansMethod = resourceClass.getMethod("getVlans");
if(getVLansMethod != null){
try {
- getVLansMethod.setAccessible(true);
obj = getVLansMethod.invoke(instance);
} catch (InvocationTargetException x) {
Throwable cause = x.getCause();
Method setVlansMethod = resourceClass.getMethod("setVlans", Vlans.class);
if(setVlansMethod != null){
try {
- setVlansMethod.setAccessible(true);
Object arglist[] = new Object[1];
arglist[0] = vlanList;
Method getMetadataMethod = resourceClass.getMethod("getMetadata");
if(getMetadataMethod != null){
try {
- getMetadataMethod.setAccessible(true);
obj = getMetadataMethod.invoke(instance);
} catch (InvocationTargetException x) {
Throwable cause = x.getCause();
Method setMetadataMethod = resourceClass.getMethod("setMetadata", Metadata.class);
if(setMetadataMethod != null){
try {
- setMetadataMethod.setAccessible(true);
Object arglist[] = new Object[1];
arglist[0] = metadataList;
}
}
- if(metadataList.getMetadatum() == null) {
-// metadataList.setMetadatum(new ArrayList<Metadatum>());
- }
-
// process data
int i = 0;
while(true){
}
if(getRelationshipListMethod != null){
try {
- getRelationshipListMethod.setAccessible(true);
obj = getRelationshipListMethod.invoke(instance);
} catch (InvocationTargetException x) {
Throwable cause = x.getCause();
Method setRelationshipListMethod = resourceClass.getMethod("setRelationshipList", RelationshipList.class);
if(setRelationshipListMethod != null){
try {
- setRelationshipListMethod.setAccessible(true);
Object arglist[] = new Object[1];
arglist[0] = relationshipList;
if(!params.containsKey(searchKey))
break;
- int j = 0;
String relatedTo = params.get(searchKey);
String relatedLinkKey = "relationship-list.relationship[" + i + "].related-link";
String relatedLink = null;
}
Relationship relationship = new Relationship();
- relationships.add(relationship);
- relationship.setRelatedTo(relatedTo);
- if(relatedLink != null) {
- relationship.setRelatedLink(relatedLink);
- } else {
+ relationships.add(relationship);
+ relationship.setRelatedTo(relatedTo);
+
+ String relationshipLabel = "relationship-list.relationship[" + i + "].relationship-label";
+ if(params.containsKey(searchKey)) {
+ relationship.setRelationshipLabel(params.get(relationshipLabel));
+ }
+
+ if (relatedLink != null) {
+ if(relatedLink.contains("v$"))
+ relatedLink = relatedLink.replace("v$", "v13");
+ relationship.setRelatedLink(relatedLink);
+ } else {
Map<String, String> relParams = new HashMap<>();
+ int j = 0;
- 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;
+ 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));
+ relationship.getRelationshipData().add(relDatum);
relParams.put(params.get(searchRelationshipKey), params.get(searchRelationshipValue));
- j++;
- }
+ j++;
+ }
AAIRequest rlRequest = AAIRequest.createRequest(relatedTo, relParams);
- for(Map.Entry<String,String> entry : relParams.entrySet()) {
+ for (Map.Entry<String, String> entry : relParams.entrySet()) {
rlRequest.addRequestProperty(entry.getKey(), entry.getValue());
}
String path = rlRequest.updatePathDataValues(null);
relationship.setRelatedLink(path);
}
+ {
+ int k = 0;
+ // process related to properties
+ Map<String, String> relParams = new HashMap<String, String>();
+
+ while(true) {
+ String searchRelatedToKey = "relationship-list.relationship[" + i + "].related-to-property[" + k + "].property-key";
+ String searchRelatedToValue = "relationship-list.relationship[" + i + "].related-to-property[" + k + "].property-value";
+ if(!params.containsKey(searchRelatedToKey))
+ break;
+
+ RelatedToProperty relDatum = new RelatedToProperty();
+ relDatum.setPropertyKey(params.get(searchRelatedToKey));
+ relDatum.setPropertyValue(params.get(searchRelatedToValue));
+ relationship.getRelatedToProperty().add(relDatum);
+
+ relParams.put(params.get(searchRelatedToKey), params.get(searchRelatedToValue));
+ k++;
+ }
+ }
i++;
}
Method getMetadataMethod = resourceClass.getMethod("getMetadata");
if(getMetadataMethod != null){
try {
- getMetadataMethod.setAccessible(true);
obj = getMetadataMethod.invoke(instance);
} catch (InvocationTargetException x) {
Throwable cause = x.getCause();
Method setMetadataMethod = resourceClass.getMethod("setMetadata", Metadata.class);
if(setMetadataMethod != null){
try {
- setMetadataMethod.setAccessible(true);
setMetadataMethod.invoke(instance, metadata);
} catch (InvocationTargetException x) {
}
try {
retval = newModelBackupRequest(resource, params, "tmpRestore", ctx);
if(retval == QueryStatus.SUCCESS) {
- String current_json = ctx.getAttribute("tmpRestore");
- ctx. setAttribute("tmpRestore", null);
-
- String snapshot_json = ctx.getAttribute(prefix);
+ ctx.setAttribute("tmpRestore", null);
}
} catch (Exception exc) {
getLogger().warn("Failed restore - returning FAILURE", exc);
Method getResourceVersionMethod = resourceClass.getMethod("getResourceVersion");
if(getResourceVersionMethod != null){
try {
- getResourceVersionMethod.setAccessible(true);
Object object = getResourceVersionMethod.invoke(instance);
if(object != null)
resourceVersion = object.toString();
- } catch (InvocationTargetException x) {
- Throwable cause = x.getCause();
+ } catch (InvocationTargetException exc) {
+ getLogger().warn("Retrieving resource version", exc);
}
}
}
if(getRelationshipListMethod != null){
try {
- getRelationshipListMethod.setAccessible(true);
obj = getRelationshipListMethod.invoke(instance);
} catch (InvocationTargetException x) {
Throwable cause = x.getCause();
request.processRequestPathValues(nameValues);
URL url = request.getRequestUrl("GET", null);
- Class resourceClass = request.getModelClass();
+ Class<?> resourceClass = request.getModelClass();
Object instance = getResource(url.toString(), resourceClass);
// get resource version
Method getResourceVersionMethod = resourceClass.getMethod("getResourceVersion");
if(getResourceVersionMethod != null){
try {
- getResourceVersionMethod.setAccessible(true);
resourceVersion = (String) getResourceVersionMethod.invoke(instance);
} catch (InvocationTargetException x) {
}
Method getMetadataMethod = resourceClass.getMethod("getMetadata");
if(getMetadataMethod != null){
try {
- getMetadataMethod.setAccessible(true);
obj = getMetadataMethod.invoke(instance);
} catch (InvocationTargetException x) {
Throwable cause = x.getCause();
Map<String, String> prefixMap = new HashMap<>();
Pattern p = Pattern.compile(".*\\[\\d\\]");
- SortedSet<String> keys = new TreeSet(tmpPrefixMap.keySet () );
+ SortedSet<String> keys = new TreeSet<String>(tmpPrefixMap.keySet () );
for(String key : keys) {
Matcher m = p.matcher(key);
if(m.matches()) {