diff options
author | 2018-08-17 13:40:21 -0400 | |
---|---|---|
committer | 2018-08-18 15:06:06 -0400 | |
commit | bd69aed3de015f670211ce425707b2e93a99d708 (patch) | |
tree | bfd4f809cb504b813760c40bbddea87e681da17f | |
parent | e3d9e2b6ed6a4958ded1ac0cbcac7c9cee2fe334 (diff) |
Make Resources in service-decomp configurable
Issue-ID: SDNC-317
Change-Id: I6dadf7b01d867564118a107364ddc97a6667daf8
Signed-off-by: Tait,Trevor(rt0435) <rtait@amdocs.com>
4 files changed, 57 insertions, 73 deletions
diff --git a/pomba/service-decomposition/config/application.properties b/pomba/service-decomposition/config/application.properties index cd118f0..3dfea70 100644 --- a/pomba/service-decomposition/config/application.properties +++ b/pomba/service-decomposition/config/application.properties @@ -30,6 +30,7 @@ aai.keyStoreType=PKCS12 aai.securityProtocol=TLS aai.connectionTimeout=5000 aai.readTimeout=1000 +aai.resourceList=vnfc,vserver,l3-network aai.serviceInstancePath=/aai/v13/nodes/service-instance/{0} diff --git a/pomba/service-decomposition/src/main/java/org/onap/sdnc/apps/pomba/servicedecomposition/AAIConfiguration.java b/pomba/service-decomposition/src/main/java/org/onap/sdnc/apps/pomba/servicedecomposition/AAIConfiguration.java index fedb64c..214c4d1 100644 --- a/pomba/service-decomposition/src/main/java/org/onap/sdnc/apps/pomba/servicedecomposition/AAIConfiguration.java +++ b/pomba/service-decomposition/src/main/java/org/onap/sdnc/apps/pomba/servicedecomposition/AAIConfiguration.java @@ -25,54 +25,45 @@ import org.springframework.stereotype.Component; @Component public class AAIConfiguration { - @Autowired @Value("${aai.host}") private String host; - @Autowired @Value("${aai.port}") private String port; - @Autowired @Value("${aai.httpProtocol}") private String httpProtocol; - @Autowired @Value("${aai.trustStorePath}") private String trustStorePath; - @Autowired @Value("${aai.keyStorePath}") private String keyStorePath; - @Autowired @Value("${aai.keyStorePassword}") private String keyStorePassword; - @Autowired @Value("${aai.keyManagerFactoryAlgorithm}") private String keyManagerFactoryAlgorithm; - @Autowired @Value("${aai.keyStoreType}") private String keyStoreType; - @Autowired @Value("${aai.securityProtocol}") private String securityProtocol; - @Autowired @Value("${aai.connectionTimeout}") private Integer connectionTimeout; - @Autowired @Value("${aai.readTimeout}") private Integer readTimeout; - @Autowired @Value("${aai.serviceInstancePath}") private String serviceInstancePath; + @Value("${aai.resourceList}") + private String resourceList; + @Bean(name="aaiClient") public RestClient restClient() { return new RestClient() @@ -92,4 +83,8 @@ public class AAIConfiguration { return this.serviceInstancePath; } + @Bean(name="aaiResourceList") + public String getResourceList() { + return this.resourceList; + } } diff --git a/pomba/service-decomposition/src/main/java/org/onap/sdnc/apps/pomba/servicedecomposition/service/SpringServiceImpl.java b/pomba/service-decomposition/src/main/java/org/onap/sdnc/apps/pomba/servicedecomposition/service/SpringServiceImpl.java index 4c61434..384115e 100644 --- a/pomba/service-decomposition/src/main/java/org/onap/sdnc/apps/pomba/servicedecomposition/service/SpringServiceImpl.java +++ b/pomba/service-decomposition/src/main/java/org/onap/sdnc/apps/pomba/servicedecomposition/service/SpringServiceImpl.java @@ -41,6 +41,9 @@ public class SpringServiceImpl implements SpringService { @Autowired private String aaiServiceInstancePath; + @Autowired + private String aaiResourceList; + @Override public String decomposeService(String fromAppId, String transactionId, @@ -49,7 +52,7 @@ public class SpringServiceImpl implements SpringService { log.info("Querying A&AI for service instance " + serviceInstanceId); - JSONObject serviceInstance = RestUtil.retrieveAAIModelData(aaiClient, aaiBaseUrl, aaiServiceInstancePath, + JSONObject serviceInstance = RestUtil.retrieveAAIModelData(aaiClient, aaiBaseUrl, aaiServiceInstancePath, aaiResourceList, transactionId, serviceInstanceId, adapter); return serviceInstance.toString(); } diff --git a/pomba/service-decomposition/src/main/java/org/onap/sdnc/apps/pomba/servicedecomposition/util/RestUtil.java b/pomba/service-decomposition/src/main/java/org/onap/sdnc/apps/pomba/servicedecomposition/util/RestUtil.java index 3043269..c9e2c50 100644 --- a/pomba/service-decomposition/src/main/java/org/onap/sdnc/apps/pomba/servicedecomposition/util/RestUtil.java +++ b/pomba/service-decomposition/src/main/java/org/onap/sdnc/apps/pomba/servicedecomposition/util/RestUtil.java @@ -24,18 +24,15 @@ import static org.onap.sdnc.apps.pomba.servicedecomposition.exception.DiscoveryE import static org.onap.sdnc.apps.pomba.servicedecomposition.exception.DiscoveryException.Error.SERVICE_RELATIONSHIP_PARSE_ERROR; import com.sun.jersey.core.util.MultivaluedMapImpl; - import java.text.MessageFormat; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; - import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MultivaluedMap; import javax.ws.rs.core.Response.Status; - import org.json.JSONArray; import org.json.JSONObject; import org.onap.aai.restclient.client.OperationResult; @@ -55,24 +52,25 @@ public class RestUtil { private static final String FROM_APP_ID = "X-FromAppId"; private static final String APP_NAME = "aaiCtxBuilder"; - // Service Catalog - public enum Catalog { - - VNF("generic-vnf"), VNFC("vnfc"), VSERVER("vserver"), L3NETWORK("l3-network"); + private static final Resource GENERIC_VNF = new Resource("generic-vnf"); - private final String resourceName; - private final String collectionName; + public static class Resource { + private String resourceName; + private String collectionName; - private Catalog(String objName) { - this.resourceName = objName; - this.collectionName = objName + "s"; // make plural + private Resource(String resource) { + this.resourceName = resource; + this.collectionName = resource + "s"; } - public String objName() { - return resourceName; + private String getResourceName() { + return this.resourceName; } - }; + private String getCollectionName() { + return this.collectionName; + } + } private static final String JSON_ATT_RELATED_TO = "related-to"; private static final String JSON_ATT_RELATED_LINK = "related-link"; @@ -114,7 +112,7 @@ public class RestUtil { * @return * @throws DiscoveryException */ - public static JSONObject retrieveAAIModelData(RestClient aaiClient, String baseURL, String aaiServiceInstancePath, + public static JSONObject retrieveAAIModelData(RestClient aaiClient, String baseURL, String aaiServiceInstancePath, String aaiResourceList, String transactionId, String serviceInstanceId, ONAPLogAdapter adapter) throws DiscoveryException { // Follow two variables for transform purpose @@ -133,7 +131,7 @@ public class RestUtil { logger.info("The number of the relationships for service instance id {} is: {}", serviceInstanceId, relationMap.size()); - JSONObject response = processVNFRelationMap(aaiClient, baseURL, transactionId, relationMap, serviceInstancePayload); + JSONObject response = processVNFRelationMap(aaiClient, aaiResourceList, baseURL, transactionId, relationMap, serviceInstancePayload); return response; } @@ -145,65 +143,43 @@ public class RestUtil { * @param relationMap * @throws DiscoveryException */ - private static JSONObject processVNFRelationMap(RestClient aaiClient, String baseURL, String transactionId, + private static JSONObject processVNFRelationMap(RestClient aaiClient, String aaiResourceList, String baseURL, String transactionId, HashMap<String, List<String>> relationMap, JSONObject serviceInstancePayload) throws DiscoveryException { List<JSONObject> vnfLst = new ArrayList<JSONObject>(); // List of the VNF JSON along with related resources JSONObject response = serviceInstancePayload; + List<Resource> resourceTypes = getResourceTypes(aaiResourceList); - if (relationMap.get(Catalog.VNF.resourceName) != null) { - List<JSONObject> vnfList = processResourceList(aaiClient, baseURL, transactionId, Catalog.VNF.resourceName, - relationMap.get(Catalog.VNF.resourceName)); + if (relationMap.get(GENERIC_VNF.getResourceName()) != null) { + List<JSONObject> vnfList = processResourceList(aaiClient, baseURL, transactionId, GENERIC_VNF.getResourceName(), + relationMap.get(GENERIC_VNF.getResourceName())); // Logic to Create the Generic VNF JSON and extract further relationships for (JSONObject vnfPayload : vnfList) { - List<String> vnfcLinkLst = extractRelatedLink(vnfPayload, Catalog.VNFC.resourceName); - if (vnfcLinkLst != null && !vnfcLinkLst.isEmpty()) { - logger.info("The number of the API call for vnfc is:" + vnfcLinkLst.size()); - List<JSONObject> vnfcList = processResourceList(aaiClient, baseURL, transactionId, - Catalog.VNFC.resourceName, vnfcLinkLst); - if (vnfcList != null) { - vnfPayload.put(Catalog.VNFC.collectionName, vnfcList); - } - } else { - logger.info("No vnfc found for vnf-id:" + vnfPayload.getString("vnf-id")); - } - - List<String> networkLinkLst = extractRelatedLink(vnfPayload, Catalog.L3NETWORK.resourceName); - if (networkLinkLst != null && !networkLinkLst.isEmpty()) { - logger.info("The number of the API call for l3-network is:" + networkLinkLst.size()); - List<JSONObject> networkList = processResourceList(aaiClient, baseURL, transactionId, - Catalog.L3NETWORK.resourceName, networkLinkLst); - if (networkList != null) { - vnfPayload.put(Catalog.L3NETWORK.collectionName, networkList); - } - } else { - logger.info("No l3-network found for vnf-id:" + vnfPayload.getString("vnf-id")); - } - List<String> vserverLinkLst = extractRelatedLink(vnfPayload, Catalog.VSERVER.resourceName); - if (vserverLinkLst != null && !vserverLinkLst.isEmpty()) { - logger.info("The number of the API call for vserver is:" + vserverLinkLst.size()); - List<JSONObject> vserverList = processResourceList(aaiClient, baseURL, transactionId, - Catalog.VSERVER.resourceName, vserverLinkLst); - if (vserverList != null) { - vnfPayload.put(Catalog.VSERVER.collectionName, vserverList); + for (Resource resourceType : resourceTypes) { + List<String> vnfcLinkLst = extractRelatedLink(vnfPayload, resourceType.getResourceName()); + if (vnfcLinkLst != null && !vnfcLinkLst.isEmpty()) { + logger.info("The number of the API call for vnfc is:" + vnfcLinkLst.size()); + List<JSONObject> vnfcList = processResourceList(aaiClient, baseURL, transactionId, + resourceType.getResourceName(), vnfcLinkLst); + if (vnfcList != null) { + vnfPayload.put(resourceType.getCollectionName(), vnfcList); + } + } else { + logger.info("No " + resourceType.getResourceName() + " found for vnf-id:" + vnfPayload.getString("vnf-id")); } - } else { - logger.info("No vserver found for vnf-id:" + vnfPayload.getString("vnf-id")); } - - // Add final vnf payload to list - vnfLst.add(vnfPayload); + // Add final vnf payload to list + vnfLst.add(vnfPayload); } } else { - logger.info("No generic vnf found for :" + serviceInstancePayload.getString("service-instance-id")); + logger.info("No " + GENERIC_VNF.getResourceName() + " found for :" + serviceInstancePayload.getString("service-instance-id")); } // Add generic vnf with related resource payload to response if (vnfLst != null && !vnfLst.isEmpty()) { - response.put(Catalog.VNF.collectionName, vnfLst); + response.put(GENERIC_VNF.getCollectionName(), vnfLst); } - return response; } @@ -225,7 +201,7 @@ public class RestUtil { String resourceURL = aaiBaseURL + resourceLink; // With latest AAI development, in order to retrieve the both generic VNF + vf_module, we can use // one API call but with depth=2 - if (resourceType.equals(Catalog.VNF.resourceName)) { + if (resourceType.equals(GENERIC_VNF.getResourceName())) { resourceURL += DEPTH; } @@ -371,4 +347,13 @@ public class RestUtil { return headers; } + private static List<Resource> getResourceTypes(String aaiResourceList) { + List<Resource> resources = new ArrayList<Resource>(); + String[] resourceList = aaiResourceList.split(","); + for (int i = 0; i < resourceList.length; i++) { + resources.add(new Resource(resourceList[i])); + } + return resources; + } + } |