diff options
author | Jorge Hernandez <jh1730@att.com> | 2017-09-13 13:59:58 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2017-09-13 13:59:58 +0000 |
commit | bc4267d043427c080b1cc1fe42ea0860bed9fa97 (patch) | |
tree | 7579c0e66a53bbb1cde15f1eef38bbb0e8227751 /controlloop/common/actors/actor.appclcm | |
parent | dbf8cdaec4b7fc8378b317fdb169eab45fcfadc8 (diff) | |
parent | c226d61d3c1266f592fc3d785164aedb34a25ef6 (diff) |
Merge "Fix A&AI Named Query for vFW"
Diffstat (limited to 'controlloop/common/actors/actor.appclcm')
-rw-r--r-- | controlloop/common/actors/actor.appclcm/src/main/java/org/onap/policy/controlloop/actor/appclcm/AppcLcmActorServiceProvider.java | 64 |
1 files changed, 50 insertions, 14 deletions
diff --git a/controlloop/common/actors/actor.appclcm/src/main/java/org/onap/policy/controlloop/actor/appclcm/AppcLcmActorServiceProvider.java b/controlloop/common/actors/actor.appclcm/src/main/java/org/onap/policy/controlloop/actor/appclcm/AppcLcmActorServiceProvider.java index c52a7f08e..4ffbf6941 100644 --- a/controlloop/common/actors/actor.appclcm/src/main/java/org/onap/policy/controlloop/actor/appclcm/AppcLcmActorServiceProvider.java +++ b/controlloop/common/actors/actor.appclcm/src/main/java/org/onap/policy/controlloop/actor/appclcm/AppcLcmActorServiceProvider.java @@ -31,8 +31,11 @@ import java.util.List; import java.util.Map; import java.util.UUID; +import org.onap.policy.aai.AAINQF199.AAINQF199InstanceFilters; import org.onap.policy.aai.AAINQF199.AAINQF199InventoryResponseItem; import org.onap.policy.aai.AAINQF199.AAINQF199Manager; +import org.onap.policy.aai.AAINQF199.AAINQF199NamedQuery; +import org.onap.policy.aai.AAINQF199.AAINQF199QueryParameters; import org.onap.policy.aai.AAINQF199.AAINQF199Request; import org.onap.policy.aai.AAINQF199.AAINQF199Response; import org.onap.policy.appclcm.LCMCommonHeader; @@ -91,6 +94,37 @@ public class AppcLcmActorServiceProvider implements Actor { public List<String> recipePayloads(String recipe) { return ImmutableList.copyOf(payloads.getOrDefault(recipe, Collections.emptyList())); } + + /** + * This method recursively traverses the A&AI named query response + * to find the generic-vnf object that contains a model-invariant-id + * that matches the resourceId of the policy. Once this match is found + * the generic-vnf object's vnf-id is returned. + * + * @param items + * the list of items related to the vnf returned by A&AI + * @param resourceId + * the id of the target from the sdc catalog + * + * @return the vnf-id of the target vnf to act upon or null if not found + */ + private static String parseAAIResponse(List<AAINQF199InventoryResponseItem> items, String resourceId) { + String vnfId = null; + for (AAINQF199InventoryResponseItem item: items) { + if ((item.genericVNF != null) + && (item.genericVNF.modelInvariantId != null) + && (resourceId.equals(item.genericVNF.modelInvariantId))) { + vnfId = item.genericVNF.vnfID; + break; + } + else { + if((item.items != null) && (item.items.inventoryResponseItems != null)) { + vnfId = parseAAIResponse(item.items.inventoryResponseItems, resourceId); + } + } + } + return vnfId; + } /** * Constructs an A&AI Named Query using a source vnf-id to determine @@ -105,30 +139,32 @@ public class AppcLcmActorServiceProvider implements Actor { * @return the target entities vnf id to act upon */ public static String vnfNamedQuery(String resourceId, String sourceVnfId) { - String targetVnfId = ""; - AAINQF199Request aaiRequest = new AAINQF199Request(); - UUID requestId = UUID.randomUUID(); + //TODO: This request id should not be hard coded in future releases + UUID requestId = UUID.fromString("a93ac487-409c-4e8c-9e5f-334ae8f99087"); + + AAINQF199Request aaiRequest = new AAINQF199Request(); + aaiRequest.queryParameters = new AAINQF199QueryParameters(); + aaiRequest.queryParameters.namedQuery = new AAINQF199NamedQuery(); aaiRequest.queryParameters.namedQuery.namedQueryUUID = requestId; - Map<String, Map<String, String>> filter = new HashMap<String, Map<String, String>>(); + Map<String, Map<String, String>> filter = new HashMap<>(); + Map<String, String> filterItem = new HashMap<>(); - Map<String, String> filterItem = new HashMap<String, String>(); filterItem.put("vnf-id", sourceVnfId); - filter.put("generic-vnf", filterItem); + aaiRequest.instanceFilters = new AAINQF199InstanceFilters(); aaiRequest.instanceFilters.instanceFilter.add(filter); - //TODO: What is the url to use? - AAINQF199Response aaiResponse = AAINQF199Manager.postQuery("http://localhost:6666", "policy", "policy", aaiRequest, requestId); - + //TODO: URL should not be hard coded for future releases + AAINQF199Response aaiResponse = AAINQF199Manager.postQuery( + "http://localhost:6666", + "policy", "policy", + aaiRequest, requestId); + //TODO: What if the resourceId never matches? - for (AAINQF199InventoryResponseItem item: aaiResponse.inventoryResponseItems) { - if (item.genericVNF.modelInvariantId.equals(resourceId)) { - targetVnfId = item.genericVNF.vnfID; - } - } + String targetVnfId = parseAAIResponse(aaiResponse.inventoryResponseItems, resourceId); return targetVnfId; } |