diff options
Diffstat (limited to 'src')
12 files changed, 306 insertions, 442 deletions
diff --git a/src/main/java/org/onap/pomba/contextbuilder/sdnc/SdncConfiguration.java b/src/main/java/org/onap/pomba/contextbuilder/sdnc/SdncConfiguration.java index ebf308c..7e77659 100644 --- a/src/main/java/org/onap/pomba/contextbuilder/sdnc/SdncConfiguration.java +++ b/src/main/java/org/onap/pomba/contextbuilder/sdnc/SdncConfiguration.java @@ -100,97 +100,85 @@ public class SdncConfiguration { @Value("${aai.http.password}") private String aaiHttpPassword; - @Value("${aai.searchNodeQuery}") - private String aaiSearchNodeQuery; + @Value("${aai.serviceInstanceQuery}") + private String aaiServiceInstanceQuery; - @Value("${aai.customerQuery}") - private String aaiCustomerQuery; + private static final String BASIC = "Basic "; - @Value("${aai.serviceInstancePath}") - private String serviceInstancePath; - - private final static String BASIC = "Basic "; - - @Bean(name="sdncBaseUrl") - public String getURL() { + @Bean(name = "sdncBaseUrl") + public String getUrl() { return httpProtocol + "://" + serviceName + ":" + servicePort; } - @Bean(name="sdncGenericResourcePath") + @Bean(name = "sdncGenericResourcePath") public String getGenericResourcePath() { return genericResourcePath; } - @Bean(name="sdncPortMirrorResourcePath") + @Bean(name = "sdncPortMirrorResourcePath") public String getPortMirrorResourcePath() { return portMirrorResourcePath; } - @Bean(name="sdncVnfPath") + @Bean(name = "sdncVnfPath") public String getVnfPath() { return vnfPath; } @Bean(name = "sdncBasicAuthorization") public String getSdncBasicAuth() { - String auth = this.user + ":"+ Password.deobfuscate(this.password); + String auth = this.user + ":" + Password.deobfuscate(this.password); return (BASIC + Base64.getEncoder().encodeToString(auth.getBytes())); } - - @Bean(name="aaiHttpBasicAuthorization") + @Bean(name = "aaiHttpBasicAuthorization") public String getHttpBasicAuth() { - String auth = new String(this.aaiHttpUserId + ":" + Password.deobfuscate(this.aaiHttpPassword)); - String encodedAuth = Base64.getEncoder().encodeToString(auth.getBytes()); + String auth = this.aaiHttpUserId + ":" + Password.deobfuscate(this.aaiHttpPassword); + String encodedAuth = Base64.getEncoder().encodeToString(auth.getBytes()); return (BASIC + encodedAuth); } - @Bean(name="aaiBasicAuthorization") - public String getAAIBasicAuth() { - String auth = new String(this.aaiUsername + ":" + Password.deobfuscate(this.aaiPassword)); - String encodedAuth = Base64.getEncoder().encodeToString(auth.getBytes()); + @Bean(name = "aaiBasicAuthorization") + public String getAaiBasicAuth() { + String auth = this.aaiUsername + ":" + Password.deobfuscate(this.aaiPassword); + String encodedAuth = Base64.getEncoder().encodeToString(auth.getBytes()); return (BASIC + encodedAuth); } @Conditional(AAIBasicAuthCondition.class) - @Bean(name="aaiClient") + @Bean(name = "aaiClient") public RestClient restClientWithBasicAuth() { RestClient restClient = new RestClient(); - restClient.validateServerHostname(false).validateServerCertChain(false).connectTimeoutMs(aaiConnectionTimeout).readTimeoutMs(aaiReadTimeout); + restClient.validateServerHostname(false).validateServerCertChain(false).connectTimeoutMs(aaiConnectionTimeout) + .readTimeoutMs(aaiReadTimeout); restClient.basicAuthUsername(aaiUsername); restClient.basicAuthPassword(Password.deobfuscate(aaiPassword)); return restClient; } @Conditional(AAIClientCertCondition.class) - @Bean(name="aaiClient") + @Bean(name = "aaiClient") public RestClient restClientWithClientCert() { RestClient restClient = new RestClient(); - if ("https".equals(aaiHttpProtocol)) - restClient.validateServerHostname(false).validateServerCertChain(false).trustStore(trustStorePath).clientCertFile(keyStorePath).clientCertPassword(keyStorePassword).connectTimeoutMs(connectionTimeout).readTimeoutMs(readTimeout); - else - restClient.validateServerHostname(false).validateServerCertChain(false).connectTimeoutMs(connectionTimeout).readTimeoutMs(readTimeout); + if ("https".equals(aaiHttpProtocol)) { + restClient.validateServerHostname(false).validateServerCertChain(false).trustStore(trustStorePath) + .clientCertFile(keyStorePath).clientCertPassword(keyStorePassword) + .connectTimeoutMs(connectionTimeout).readTimeoutMs(readTimeout); + } else { + restClient.validateServerHostname(false).validateServerCertChain(false).connectTimeoutMs(connectionTimeout) + .readTimeoutMs(readTimeout); + } return restClient; } - @Bean(name="aaiBaseUrl") - public String getAaiURL() { + @Bean(name = "aaiBaseUrl") + public String getAaiUrl() { return aaiHttpProtocol + "://" + aaiHost + ":" + aaiPort; } - @Bean(name="aaiPathToSearchNodeQuery") - public String getAaiPathToSearchNodeQuery() { - return aaiSearchNodeQuery.trim(); - } - - @Bean(name="aaiPathToCustomerQuery") - public String getAaiPathToCustomerQuery() { - return aaiCustomerQuery.trim(); - } - - @Bean(name="aaiServiceInstancePath") - public String getserviceInstancePathL() { - return serviceInstancePath; + @Bean(name = "aaiPathToServiceInstanceQuery") + public String getAaiPathToServiceInstanceQuery() { + return aaiServiceInstanceQuery.trim(); } } diff --git a/src/main/java/org/onap/pomba/contextbuilder/sdnc/handlers/VnfApiHandler.java b/src/main/java/org/onap/pomba/contextbuilder/sdnc/handlers/VnfApiHandler.java index 7cb9214..cb83517 100644 --- a/src/main/java/org/onap/pomba/contextbuilder/sdnc/handlers/VnfApiHandler.java +++ b/src/main/java/org/onap/pomba/contextbuilder/sdnc/handlers/VnfApiHandler.java @@ -52,7 +52,7 @@ public class VnfApiHandler { @Autowired private String aaiBaseUrl; @Autowired - private String aaiServiceInstancePath; + private String aaiPathToServiceInstanceQuery; @Autowired private Client jerseyClient; @Autowired @@ -73,20 +73,23 @@ public class VnfApiHandler { log.info("in VNF-API HANDLER: "); Service service = new Service(); - ServiceEntity serviceEntity = (ServiceEntity)exchange.getIn().getBody(); + ServiceEntity serviceEntity = (ServiceEntity) exchange.getIn().getBody(); service.setUuid(serviceEntity.getServiceInstanceId()); // GET the list of VNF related-to links from AAI - String url= aaiBaseUrl+generateServiceInstanceURL(aaiServiceInstancePath, serviceEntity.getCustomerId(), serviceEntity.getServiceType(), serviceEntity.getServiceInstanceId()); - String serviceInstancePayload = RestUtil.getAaiResource(aaiClient, url, aaiBasicAuthorization, serviceEntity.getTransactionId()); + String url = aaiBaseUrl + + generateServiceInstanceUrl(aaiPathToServiceInstanceQuery, serviceEntity.getServiceInstanceId()); + String serviceInstancePayload = RestUtil.getAaiResource(aaiClient, url, aaiBasicAuthorization, + serviceEntity.getTransactionId()); + List<String> genericVnfLinks = extractGenericVnfRelatedLink(serviceInstancePayload); // GET the VNF list (module-id) from AAI - List <VnfInstance> vnfList = retrieveAaiVnfList(aaiClient, aaiBaseUrl, aaiBasicAuthorization, serviceEntity.getTransactionId(), genericVnfLinks); - + List<VnfInstance> vnfList = retrieveAaiVnfList(aaiClient, aaiBaseUrl, aaiBasicAuthorization, + serviceEntity.getTransactionId(), genericVnfLinks); // GET the module-id from SDNC using VNF-API - Map<String,List<Vnf>> sdncVnfMap = RestUtil.getSdncVnfList(jerseyClient, sdncBaseUrl, sdncVnfPath, + Map<String, List<Vnf>> sdncVnfMap = RestUtil.getSdncVnfList(jerseyClient, sdncBaseUrl, sdncVnfPath, sdncBasicAuthorization, vnfList); // Transform the AAI and SDNC models to the audit common model @@ -97,12 +100,12 @@ public class VnfApiHandler { return context; } - private static String generateServiceInstanceURL(String siPath, String customerId, String serviceType, String serviceInstanceId) { - return MessageFormat.format(siPath, customerId, serviceType, serviceInstanceId); + private static String generateServiceInstanceUrl(String siPath, String serviceInstanceId) { + return MessageFormat.format(siPath, serviceInstanceId); } private static List<String> extractGenericVnfRelatedLink(String serviceInstancePayload) throws AuditException { - List<String> genericVnfLinks = new ArrayList<>();; + List<String> genericVnfLinks = new ArrayList<>(); try { JSONObject relationshipList = new JSONObject(serviceInstancePayload).getJSONObject(JSON_RELATIONSHIP_LIST); @@ -110,7 +113,8 @@ public class VnfApiHandler { if (relationship != null) { for (int i = 0; i < relationship.length(); i++) { JSONObject relationshipInstance = relationship.optJSONObject(i); - if (relationshipInstance.has(JSON_RELATED_TO) && (relationshipInstance.getString(JSON_RELATED_TO).equals(JSON_GENERIC_VNF))) { + if (relationshipInstance.has(JSON_RELATED_TO) + && (relationshipInstance.getString(JSON_RELATED_TO).equals(JSON_GENERIC_VNF))) { genericVnfLinks.add(relationshipInstance.getString(JSON_RELATED_LINK)); } } @@ -122,20 +126,22 @@ public class VnfApiHandler { return genericVnfLinks; } - private static List<VnfInstance> retrieveAaiVnfList(RestClient aaiClient, String aaiBaseUrl, String aaiBasicAuthorization, String transactionId, List <String>genericVnfLinks) throws AuditException { + private static List<VnfInstance> retrieveAaiVnfList(RestClient aaiClient, String aaiBaseUrl, + String aaiBasicAuthorization, String transactionId, List<String> genericVnfLinks) throws AuditException { List<VnfInstance> vnfList = new ArrayList<>(); for (String genericVnfLink : genericVnfLinks) { - String genericVnfUrl = RestUtil.generateAaiUrl(aaiBaseUrl, genericVnfLink, "?depth=all"); - String genericVnfPayload = RestUtil.getAaiResource(aaiClient, genericVnfUrl, aaiBasicAuthorization, transactionId); + String genericVnfUrl = aaiBaseUrl + genericVnfLink + "?depth=all"; + String genericVnfPayload = RestUtil.getAaiResource(aaiClient, genericVnfUrl, aaiBasicAuthorization, + transactionId); if (genericVnfPayload.equals(EMPTY_JSON_STRING)) { - log.info("retrieveAaiVnfList "+ genericVnfPayload +" is not found, " + "return empty Json "); + log.info("retrieveAaiVnfList {} is not found, return empty Json ", genericVnfPayload); } else { // Create the AAI VnfInstance from the AAI generic-vnf json VnfInstance vnfInstance = VnfInstance.fromJson(genericVnfPayload); vnfList.add(vnfInstance); } } - log.debug("The size of vnfList:"+ vnfList.size()); + log.debug("The size of vnfList: {}", vnfList.size()); return vnfList; } } diff --git a/src/main/java/org/onap/pomba/contextbuilder/sdnc/service/SpringServiceImpl.java b/src/main/java/org/onap/pomba/contextbuilder/sdnc/service/SpringServiceImpl.java index 52ee416..538a84b 100644 --- a/src/main/java/org/onap/pomba/contextbuilder/sdnc/service/SpringServiceImpl.java +++ b/src/main/java/org/onap/pomba/contextbuilder/sdnc/service/SpringServiceImpl.java @@ -55,9 +55,7 @@ public class SpringServiceImpl implements SpringService { @Autowired private String aaiBaseUrl; @Autowired - private String aaiPathToSearchNodeQuery; - @Autowired - private String aaiPathToCustomerQuery; + private String aaiPathToServiceInstanceQuery; public static final String APP_NAME = "SdncContextBuilder"; public static final String MDC_REQUEST_ID = "RequestId"; @@ -92,14 +90,14 @@ public class SpringServiceImpl implements SpringService { ModelContext context = null; // Call AAI system to populate ServiceData - ServiceEntity serviceEntity = RestUtil.getServiceEntity(aaiClient, aaiBaseUrl, aaiBasicAuthorization, aaiPathToSearchNodeQuery, aaiPathToCustomerQuery, serviceInstanceId, transactionId); + ServiceEntity serviceEntity = RestUtil.getServiceEntity(aaiClient, aaiBaseUrl, aaiBasicAuthorization, aaiPathToServiceInstanceQuery, serviceInstanceId, transactionId); if (null == serviceEntity) { return context; } processApiMappingRules(serviceEntity); - log.info("SDN-C determined API: " + serviceEntity.getApiName()); + log.info("SDN-C determined API: {}", serviceEntity.getApiName()); context = producerTemplate.requestBody("direct:startRoutingProcess", serviceEntity, ModelContext.class); @@ -126,10 +124,10 @@ public class SpringServiceImpl implements SpringService { } } - private void processApiMappingRules(ServiceEntity serviceData){ + private void processApiMappingRules(ServiceEntity serviceData) { KieSession kieSession = kieContainer.newKieSession(); - log.info ("KIE Session is created"); + log.info("KIE Session is created"); kieSession.insert(serviceData); kieSession.fireAllRules(); log.info("Rules are fired"); diff --git a/src/main/java/org/onap/pomba/contextbuilder/sdnc/service/rs/RestServiceImpl.java b/src/main/java/org/onap/pomba/contextbuilder/sdnc/service/rs/RestServiceImpl.java index b3d21bf..3822a58 100644 --- a/src/main/java/org/onap/pomba/contextbuilder/sdnc/service/rs/RestServiceImpl.java +++ b/src/main/java/org/onap/pomba/contextbuilder/sdnc/service/rs/RestServiceImpl.java @@ -39,19 +39,15 @@ public class RestServiceImpl implements RestService { @Autowired private SpringService service; - - public RestServiceImpl() { - } - @Override public Response getContext(HttpServletRequest request, HttpHeaders headers, String serviceInstanceId) { Response response = null; - ModelContext sdncContext= null; + ModelContext sdncContext = null; Gson gson = new GsonBuilder().create(); try { // Validate URL parameters - RestUtil.validateURL(serviceInstanceId); + RestUtil.validateUrl(serviceInstanceId); // Validate Headers and extract Partner Name String partnerName = RestUtil.validateHeader(headers, service.getSdncAuthoriztion()); @@ -61,17 +57,18 @@ public class RestServiceImpl implements RestService { sdncContext = service.getContext(request, serviceInstanceId, transactionId, partnerName); - if (sdncContext==null) { + if (sdncContext == null) { // Return empty JSON response = Response.ok().entity(EMPTY_JSON_STRING).build(); - }else { + } else { response = Response.ok().entity(gson.toJson(sdncContext)).build(); } } catch (AuditException ce) { - if (ce.getHttpStatus() !=null) { + if (ce.getHttpStatus() != null) { response = Response.status(ce.getHttpStatus()).entity(ce.getMessage()).build(); - }else { - // No response received, could be the cases of network issue: i.e. unreachable host + } else { + // No response received, could be the cases of network issue: i.e. unreachable + // host response = Response.status(Status.INTERNAL_SERVER_ERROR).entity(ce.getMessage()).build(); } } catch (Exception e) { diff --git a/src/main/java/org/onap/pomba/contextbuilder/sdnc/util/RestUtil.java b/src/main/java/org/onap/pomba/contextbuilder/sdnc/util/RestUtil.java index bd073c7..51623e5 100644 --- a/src/main/java/org/onap/pomba/contextbuilder/sdnc/util/RestUtil.java +++ b/src/main/java/org/onap/pomba/contextbuilder/sdnc/util/RestUtil.java @@ -41,7 +41,6 @@ import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MultivaluedMap; import javax.ws.rs.core.Response; import javax.ws.rs.core.Response.Status; -import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import org.onap.aai.restclient.client.OperationResult; @@ -83,23 +82,14 @@ public class RestUtil { // AAI related private static final String APP_NAME = "sdncCtxBuilder"; private static final String EMPTY_JSON_STRING = "{}"; - private static final String JSON_RESOURCE_TYPE = "resource-type"; - private static final String JSON_RESOURCE_LINK = "resource-link"; - private static final String JSON_GLOBAL_CUSTOMER_ID = "global-customer-id"; - private static final String JSON_SUBSCRIBER_TYPE = "subscriber-type"; - private static final String JSON_SUBSCRIBER_NAME = "subscriber-name"; - private static final String RESULT_DATA = "result-data"; - private static final String CATALOG_SERVICE_INSTANCE = "service-instance"; - private static final String CUSTOMER_ID_STRING = "/customers/customer/"; - private static final String SERVICE_TYPE_STRING = "/service-subscriptions/service-subscription/"; - - private static final String FORWARD_SLASH = "/"; + private static final String JSON_SERVICE_TYPE = "service-type"; + // SDNC vnf Json Path private static final String GENERIC_API_SPEC_PATH = "config/sdncgenericresource.spec"; private static final String PROVIDED_CONFIGURATIONS_SPEC_PATH = "config/providedConfigurations.spec"; private static final String PORT_MIRROR_CONFIGURATIONS_SPEC_PATH = "config/portMirrorConfigurations.spec"; - // Parameters for Query SDNC Model Data REST API URL + // Parameters for Query SDNC Model Data REST API URL private static final String SERVICE_INSTANCE_ID = "serviceInstanceId"; private RestUtil() { @@ -107,55 +97,60 @@ public class RestUtil { /** * Validates the URL parameter. - * @throws AuditException if there is missing parameter + * + * @throws AuditException + * if there is missing parameter */ - public static void validateURL(String serviceInstanceId) throws AuditException { + public static void validateUrl(String serviceInstanceId) throws AuditException { - if (serviceInstanceId == null || serviceInstanceId.isEmpty()) - throw new AuditException("Invalid request URL, missing parameter: "+ SERVICE_INSTANCE_ID, Status.BAD_REQUEST); + if (serviceInstanceId == null || serviceInstanceId.isEmpty()) { + throw new AuditException("Invalid request URL, missing parameter: " + SERVICE_INSTANCE_ID, + Status.BAD_REQUEST); + } } - - public static String validateHeader(HttpHeaders headers, String sdncCtxBuilderBasicAuthorization) throws AuditException { + public static String validateHeader(HttpHeaders headers, String sdncCtxBuilderBasicAuthorization) + throws AuditException { /* * Validate that the headers are there and return the FROM_APP_ID */ String fromAppId = headers.getRequestHeaders().getFirst(FROM_APP_ID); - if((fromAppId == null) || fromAppId.trim().isEmpty()) { - throw new AuditException("Missing header parameter: "+ FROM_APP_ID, Status.BAD_REQUEST); + if ((fromAppId == null) || fromAppId.trim().isEmpty()) { + throw new AuditException("Missing header parameter: " + FROM_APP_ID, Status.BAD_REQUEST); } String headerAuthorization = headers.getRequestHeaders().getFirst(AUTHORIZATION); - if((headerAuthorization == null) || headerAuthorization.trim().isEmpty()) { - throw new AuditException("Missing header parameter: "+ AUTHORIZATION, Status.BAD_REQUEST); + if ((headerAuthorization == null) || headerAuthorization.trim().isEmpty()) { + throw new AuditException("Missing header parameter: " + AUTHORIZATION, Status.BAD_REQUEST); } - if((!headerAuthorization.contentEquals(sdncCtxBuilderBasicAuthorization))) { - throw new AuditException("Failed Basic "+ AUTHORIZATION, Status.UNAUTHORIZED); + if ((!headerAuthorization.contentEquals(sdncCtxBuilderBasicAuthorization))) { + throw new AuditException("Failed Basic " + AUTHORIZATION, Status.UNAUTHORIZED); } return fromAppId; } - /* - * The purpose is to keep same transaction Id from north bound interface to south bound interface + * The purpose is to keep same transaction Id from north bound interface to + * south bound interface */ - public static String extractTranactionIdHeader(HttpHeaders headers) { + public static String extractTranactionIdHeader(HttpHeaders headers) { String transactionId = null; transactionId = headers.getRequestHeaders().getFirst(TRANSACTION_ID); - if((transactionId == null) || transactionId.trim().isEmpty()) { + if ((transactionId == null) || transactionId.trim().isEmpty()) { transactionId = UUID.randomUUID().toString(); - log.info("Header ", TRANSACTION_ID, " not present in request, generating new value: ", transactionId); + log.info("Header {} not present in request, generating new value: {}", TRANSACTION_ID, transactionId); } return transactionId; } - /** - * For each AAI VnfInstance, use the AAI VfModuleId to make a rest call to SDNC VNF-API to create a list of all SDNC Vnfs. - * The URL for VNF-API is https://<SDN-C_HOST_NAME>:8543/restconf/config/VNF-API:vnfs/vnf-list/<vnf-id> + * For each AAI VnfInstance, use the AAI VfModuleId to make a rest call to SDNC + * VNF-API to create a list of all SDNC Vnfs. The URL for VNF-API is + * https://<SDN-C_HOST_NAME>:8543/restconf/config/VNF-API:vnfs/vnf-list/<vnf-id> + * * @param sdncClient * @param sdncBaseUrl * @param authorization @@ -164,16 +159,19 @@ public class RestUtil { * @return * @throws AuditException */ - public static String getSdncGenericResource(Client sdncClient, String sdncBaseUrl, String authorization, String sdncGenericResourcePath, - String serviceInstaceId) throws AuditException { - String genericResourceSdncURL = sdncBaseUrl+generateSdncInstanceURL(sdncGenericResourcePath, serviceInstaceId); + public static String getSdncGenericResource(Client sdncClient, String sdncBaseUrl, String authorization, + String sdncGenericResourcePath, String serviceInstaceId) throws AuditException { + String genericResourceSdncUrl = sdncBaseUrl + + generateSdncInstanceUrl(sdncGenericResourcePath, serviceInstaceId); // send rest request to SDNC GENERIC-RESOURCE-API - return getSdncResource(sdncClient, genericResourceSdncURL, authorization); + return getSdncResource(sdncClient, genericResourceSdncUrl, authorization); } /** - * For each AAI VnfInstance, use the AAI Vf_module_id to make a rest call to SDNC VNF-API to create a list of all SDNC Vnfs. - * The URL for VNF-API is https://<SDN-C_HOST_NAME>:8543/restconf/config/VNF-API:vnfs/vnf-list/<vnf-id> + * For each AAI VnfInstance, use the AAI Vf_module_id to make a rest call to + * SDNC VNF-API to create a list of all SDNC Vnfs. The URL for VNF-API is + * https://<SDN-C_HOST_NAME>:8543/restconf/config/VNF-API:vnfs/vnf-list/<vnf-id> + * * @param sdncClient * @param sdncBaseUrl * @param sdncVnfInstancePath @@ -183,36 +181,37 @@ public class RestUtil { * @return * @throws AuditException */ - public static Map<String,List<Vnf>> getSdncVnfList(Client sdncClient, String sdncBaseUrl, String sdncVnfInstancePath, - String authorization, List<VnfInstance> vnfList) throws AuditException { + public static Map<String, List<Vnf>> getSdncVnfList(Client sdncClient, String sdncBaseUrl, + String sdncVnfInstancePath, String authorization, List<VnfInstance> vnfList) throws AuditException { - // define map [key: vnf-id, value: list of SDNC vnfs, which in fact are vf_modules] - Map<String,List<Vnf>> sdncVnfMap = new HashMap<>(); - for (VnfInstance vnfInstance: vnfList) { + // define map [key: vnf-id, value: list of SDNC vnfs, which in fact are + // vf_modules] + Map<String, List<Vnf>> sdncVnfMap = new HashMap<>(); + for (VnfInstance vnfInstance : vnfList) { if (vnfInstance.getVfModules() != null) { List<Vnf> sdncVnfList = new ArrayList<>(); List<VfModule> vfModuleList = vnfInstance.getVfModules().getVfModule(); if (vfModuleList != null && !vfModuleList.isEmpty()) { for (VfModule vfModuleInstance : vfModuleList) { // create SDNC VNF-API url using AAI VnfInstance VfModule Vf_module_id - String vnfSdncURL = sdncBaseUrl+generateSdncInstanceURL(sdncVnfInstancePath, vfModuleInstance.getVfModuleId()); + String vnfSdncUrl = sdncBaseUrl + + generateSdncInstanceUrl(sdncVnfInstancePath, vfModuleInstance.getVfModuleId()); // send rest request to SDNC VNF-API - String sndcVNFPayload = getSdncResource(sdncClient, vnfSdncURL, authorization); - if (isEmptyJson(sndcVNFPayload)) { + String sndcVnfPayload = getSdncResource(sdncClient, vnfSdncUrl, authorization); + if (isEmptyJson(sndcVnfPayload)) { log.info("VNF with vf-module-id is not found from SDNC"); } else { - List<Vnf> vnfsList = extractVnfList(sndcVNFPayload); + List<Vnf> vnfsList = extractVnfList(sndcVnfPayload); sdncVnfList.addAll(vnfsList); } } } - sdncVnfMap.put(vnfInstance.getVnfId(),sdncVnfList); + sdncVnfMap.put(vnfInstance.getVnfId(), sdncVnfList); } } return sdncVnfMap; } - public static ModelContext transformGenericResource(String sdncResponse) { List<Object> jsonSpec = JsonUtils.filepathToList(GENERIC_API_SPEC_PATH); Object jsonInput = JsonUtils.jsonToObject(sdncResponse); @@ -226,7 +225,8 @@ public class RestUtil { } - public static List<PNF> getPnfFromSdncResonse(Client sdncClient, String sdncBaseUrl, String authorization, String sdncPortMirrorResourcePath, String sdncResponse) throws AuditException { + public static List<PNF> getPnfFromSdncResonse(Client sdncClient, String sdncBaseUrl, String authorization, + String sdncPortMirrorResourcePath, String sdncResponse) throws AuditException { List<PNF> pnfList = new ArrayList<>(); List<Object> providedConfigurationsSpec = JsonUtils.filepathToList(PROVIDED_CONFIGURATIONS_SPEC_PATH); Object providedConfigurationsInput = JsonUtils.jsonToObject(sdncResponse); @@ -239,31 +239,33 @@ public class RestUtil { JsonElement jsonElement = gson.toJsonTree(providedConfigurationsObject); JsonObject jsonObject = (JsonObject) jsonElement; JsonArray jsonArray = jsonObject.getAsJsonArray("configuration-id"); - for (JsonElement configurationId : jsonArray) { + for (JsonElement configurationId : jsonArray) { String pnfId = configurationId.getAsString(); - String portMirrorResponse = getSdncGenericResource(sdncClient, sdncBaseUrl, authorization, sdncPortMirrorResourcePath, pnfId); + String portMirrorResponse = getSdncGenericResource(sdncClient, sdncBaseUrl, authorization, + sdncPortMirrorResourcePath, pnfId); List<Object> portMirrorSpec = JsonUtils.filepathToList(PORT_MIRROR_CONFIGURATIONS_SPEC_PATH); Object portMirrorInput = JsonUtils.jsonToObject(portMirrorResponse); Chainr portMirror = Chainr.fromSpec(portMirrorSpec); Object portMirrorObject = portMirror.transform(portMirrorInput); - for (PNF pnf :gson.fromJson(JsonUtils.toPrettyJsonString(portMirrorObject), ModelContext.class).getPnfs()) { + for (PNF pnf : gson.fromJson(JsonUtils.toPrettyJsonString(portMirrorObject), ModelContext.class) + .getPnfs()) { if (null != pnf) { pnfList.add(pnf); } - }; + } } return pnfList; } /** * Transform the AAI and SDNC models to the audit common model + * * @param aaiVnfLst * @param sdncVnfMap * @return * @throws AuditException */ - public static ModelContext transformVnfList(List<VnfInstance> aaiVnfLst, Map<String,List<Vnf>> sdncVnfMap) { - ModelContext context = new ModelContext(); + public static ModelContext transformVnfList(List<VnfInstance> aaiVnfLst, Map<String, List<Vnf>> sdncVnfMap) { Service service = new Service(); List<VNF> vnfList = new ArrayList<>(); @@ -272,8 +274,8 @@ public class RestUtil { service.setUuid("null"); service.setName("null"); - for(VnfInstance aaiVnfInstance : aaiVnfLst) { - VNF vnf = new VNF(); + for (VnfInstance aaiVnfInstance : aaiVnfLst) { + VNF vnf = new VNF(); // Initialize common model members to null vnf.setName("null"); vnf.setType("null"); @@ -283,14 +285,15 @@ public class RestUtil { try { // Set the common model VNF name and type from the SDNC topology info if (sdncVnfList != null && !sdncVnfList.isEmpty()) { - for(Vnf sdncVnf : sdncVnfList) { + for (Vnf sdncVnf : sdncVnfList) { if (null == sdncVnf.getServiceData()) { break; } if (null == sdncVnf.getServiceData().getVnfTopologyInformation()) { break; } - VnfTopologyIdentifier vnfTopologyId = sdncVnf.getServiceData().getVnfTopologyInformation().getVnfTopologyIdentifier(); + VnfTopologyIdentifier vnfTopologyId = sdncVnf.getServiceData().getVnfTopologyInformation() + .getVnfTopologyIdentifier(); if (null != vnfTopologyId) { if (vnf.getName().contentEquals("null")) { vnf.setName(vnfTopologyId.getGenericVnfName()); @@ -299,8 +302,8 @@ public class RestUtil { vnf.setType(vnfTopologyId.getGenericVnfType()); } if (vnf.getAttributes().isEmpty()) { - if ((null != vnfTopologyId.getInMaint()) && !(vnfTopologyId.getInMaint().isEmpty())) { - Attribute lockedBoolean = new Attribute(); + if ((null != vnfTopologyId.getInMaint()) && !(vnfTopologyId.getInMaint().isEmpty())) { + Attribute lockedBoolean = new Attribute(); lockedBoolean.setName(Name.lockedBoolean); if (vnfTopologyId.getInMaint().equalsIgnoreCase("yes")) { lockedBoolean.setValue("true"); @@ -310,15 +313,17 @@ public class RestUtil { } vnf.addAttribute(lockedBoolean); } - if ((null != vnfTopologyId.getProvStatus()) && !(vnfTopologyId.getProvStatus().isEmpty())) { + if ((null != vnfTopologyId.getProvStatus()) + && !(vnfTopologyId.getProvStatus().isEmpty())) { Attribute provStatus = new Attribute(); provStatus.setName(Name.provStatus); provStatus.setValue(vnfTopologyId.getProvStatus()); vnf.addAttribute(provStatus); } if (null != vnfTopologyId.getPserver()) { - if ((null != vnfTopologyId.getPserver().getHostname()) && !(vnfTopologyId.getPserver().getHostname().isEmpty())) { - Attribute hostname = new Attribute(); + if ((null != vnfTopologyId.getPserver().getHostname()) + && !(vnfTopologyId.getPserver().getHostname().isEmpty())) { + Attribute hostname = new Attribute(); hostname.setName(Name.hostName); hostname.setValue(vnfTopologyId.getPserver().getHostname()); vnf.addAttribute(hostname); @@ -326,8 +331,9 @@ public class RestUtil { } } if (null != vnfTopologyId.getImage()) { - if ((null != vnfTopologyId.getImage().getImageName()) && !(vnfTopologyId.getImage().getImageName().isEmpty())) { - Attribute imageName = new Attribute(); + if ((null != vnfTopologyId.getImage().getImageName()) + && !(vnfTopologyId.getImage().getImageName().isEmpty())) { + Attribute imageName = new Attribute(); imageName.setName(Name.imageId); imageName.setValue(vnfTopologyId.getImage().getImageName()); vnf.addAttribute(imageName); @@ -351,23 +357,23 @@ public class RestUtil { vnfList.add(vnf); } + ModelContext context = new ModelContext(); context.setService(service); context.setVnfs(vnfList); return context; } - public static String getSdncResource(Client sdncClient, String url, String authorization) throws AuditException { + public static String getSdncResource(Client sdncClient, String url, String authorization) throws AuditException { - log.info("SDNC GET request at url = " + url); - Response response = sdncClient.target(url).request() - .header("Accept", "application/json") + log.info("SDNC GET request at url = {}", url); + Response response = sdncClient.target(url).request().header("Accept", "application/json") .header(AUTHORIZATION, authorization).get(); - if (response.getStatus() == 200) { + if (response.getStatus() == 200) { return response.readEntity(String.class); } else if (response.getStatus() == 404) { - //Resource not found, generate empty JSON format - log.info("Return empty Json. Resource not found: ", url); + // Resource not found, generate empty JSON format + log.info("Return empty Json. Resource not found: {}", url); return new JSONObject().toString(); } else { @@ -375,58 +381,40 @@ public class RestUtil { } } - - private static String generateSdncInstanceURL(String siPath, String vfModuleLink) { + private static String generateSdncInstanceUrl(String siPath, String vfModuleLink) { return MessageFormat.format(siPath, vfModuleLink); } /** - * Get customer info from multiple AAI api + * Get Service Entity from AAI api + * * @param aaiClient * @param aaiBaseUrl * @param aaiBasicAuthorization - * @param aaiPathToSearchNodeQuery - * @param aaiPathToCustomerQuery - * @param serviceInstaceId + * @param aaiPathToServiceInstanceQuery + * @param serviceInstanceId * @param transactionId - * @return + * @return ServiceEntity * @throws AuditException */ - public static ServiceEntity getServiceEntity(RestClient aaiClient, - String aaiBaseUrl, - String aaiBasicAuthorization, - String aaiPathToSearchNodeQuery, - String aaiPathToCustomerQuery, - String serviceInstanceId, - String transactionId) throws AuditException { + public static ServiceEntity getServiceEntity(RestClient aaiClient, String aaiBaseUrl, String aaiBasicAuthorization, + String aaiPathToServiceInstanceQuery, String serviceInstanceId, String transactionId) + throws AuditException { - String getResourceLinkUrl = generateAaiUrl(aaiBaseUrl, aaiPathToSearchNodeQuery, serviceInstanceId); - String aaiResourceData = getAaiResource(aaiClient, getResourceLinkUrl, aaiBasicAuthorization, transactionId); + String getResourceLinkUrl = generateAaiUrl(aaiBaseUrl, aaiPathToServiceInstanceQuery, serviceInstanceId); + String aaiResourceData = getAaiResource(aaiClient, getResourceLinkUrl, aaiBasicAuthorization, transactionId); // Handle the case if the service instance is not found in AAI if (isEmptyJson(aaiResourceData)) { - log.info(" Service Instance {} is not found from AAI", serviceInstanceId); + log.info("Service Instance {} is not found from AAI", serviceInstanceId); // Only return the empty Json on the root level. i.e service instance return null; } - String resourceLink = extractResourceLink(aaiResourceData, CATALOG_SERVICE_INSTANCE); - - ServiceEntity serviceEntityObj = createServiceEntityObj (resourceLink); //customerId and serviceType are updated here. + ServiceEntity serviceEntityObj = createServiceEntityObj(aaiResourceData); if (serviceEntityObj != null) { serviceEntityObj.setTransactionId(transactionId); serviceEntityObj.setServiceInstanceId(serviceInstanceId); - String customerId = serviceEntityObj.getCustomerId(); - // Obtain customerType and customerName - String getCustomerUrl = generateAaiUrl (aaiBaseUrl, aaiPathToCustomerQuery, customerId); - String aaiCustomerData = getAaiResource(aaiClient, getCustomerUrl, aaiBasicAuthorization, transactionId); - if (isEmptyJson(aaiCustomerData)) { - log.info(" Customer name {} is not found from AAI", customerId); - // Only return the empty Json on the root level. i.e service instance - throw new AuditException(AuditError.INTERNAL_SERVER_ERROR + ": Customer ID cannot be found from AAI :" + customerId); - } - // Update customerType and customerName to the existing serviceEntityObj - updateServiceEntityObj ( aaiCustomerData , serviceEntityObj); } return serviceEntityObj; @@ -436,8 +424,8 @@ public class RestUtil { return (serviceInstancePayload.equals(EMPTY_JSON_STRING)); } - public static String generateAaiUrl (String aaiBaseURL, String aaiPathToCustomerQuery, String parameter) { - return aaiBaseURL + aaiPathToCustomerQuery + (parameter != null ? parameter : ""); + public static String generateAaiUrl(String aaiBaseUrl, String aaiPathToServiceInstanceQuery, String parameter) { + return aaiBaseUrl + MessageFormat.format(aaiPathToServiceInstanceQuery, parameter != null ? parameter : ""); } private static Map<String, List<String>> buildHeaders(String aaiBasicAuthorization, String transactionId) { @@ -448,9 +436,10 @@ public class RestUtil { return headers; } - public static String getAaiResource(RestClient client, String url, String aaiBasicAuthorization, String transactionId) - throws AuditException { - OperationResult result = client.get(url, buildHeaders(aaiBasicAuthorization, transactionId), MediaType.valueOf(MediaType.APPLICATION_JSON)); + public static String getAaiResource(RestClient client, String url, String aaiBasicAuthorization, + String transactionId) throws AuditException { + OperationResult result = client.get(url, buildHeaders(aaiBasicAuthorization, transactionId), + MediaType.valueOf(MediaType.APPLICATION_JSON)); if (result.getResultCode() == 200) { return result.getResult(); @@ -464,106 +453,29 @@ public class RestUtil { } } - - /* - * Extract the resource-Link from Json payload. For example - * { - * "result-data": [ - * { - * "resource-type": "service-instance", - * "resource-link": "/aai/v11/business/customers/customer/DemoCust_651800ed-2a3c-45f5-b920-85c1ed155fc2/service-subscriptions/service-subscription/vFW/service-instances/service-instance/adc3cc2a-c73e-414f-8ddb-367de81300cb" - * } - * ] - * } - */ - private static String extractResourceLink(String payload, String catalog) throws AuditException { - String resourceLink = null; - log.info("Fetching the resource-link based on resource-type=" + catalog); - - try { - JSONArray resultDataList = new JSONObject(payload).getJSONArray(RESULT_DATA); - if (resultDataList != null) { - for (int i = 0; i < resultDataList.length(); i++) { - JSONObject obj = resultDataList.optJSONObject(i); - if (obj.has(JSON_RESOURCE_TYPE) && (obj.getString(JSON_RESOURCE_TYPE).equals(catalog) )) { - resourceLink = obj.getString(JSON_RESOURCE_LINK); - log.info(resourceLink); - return resourceLink; - } - } - } - } catch (JSONException e) { - log.error(e.getMessage()); - throw new AuditException(AuditError.JSON_PARSE_ERROR + e.getMessage()); + private static ServiceEntity createServiceEntityObj(String aaiServiceInstance) throws AuditException { + if ((aaiServiceInstance == null) || aaiServiceInstance.isEmpty()) { + return null; } - log.warn("resource-link CANNOT be found: ", payload ); - - return resourceLink; - } - - /* - * Extract the "subscriber-name" and "subscriber-type" from Json payload. For example - * { - * "global-customer-id": "OttoonMorph36", - * "subscriber-name": "OttoonMorph36", - * "subscriber-type": "CUST", - * "resource-version": "1526324315029" - * } - */ - private static void updateServiceEntityObj(String payload, ServiceEntity serviceEntityObj) throws AuditException { - if (serviceEntityObj == null ) { - throw new AuditException("null pointer serviceEntityObj"); - } - String customerId = serviceEntityObj.getCustomerId(); - log.info("Fetching the subscriber type based on customer-id = " + customerId); + ServiceEntity serviceEntity = new ServiceEntity(); try { - JSONObject obj = new JSONObject (payload); - if (obj.has(JSON_GLOBAL_CUSTOMER_ID) && (obj.getString(JSON_GLOBAL_CUSTOMER_ID).equals(customerId) )) { - serviceEntityObj.setCustomerType(obj.getString(JSON_SUBSCRIBER_TYPE)); - serviceEntityObj.setCustomerName(obj.getString(JSON_SUBSCRIBER_NAME)); - return; + JSONObject obj = new JSONObject(aaiServiceInstance); + if (obj.has(JSON_SERVICE_TYPE)) { + serviceEntity.setServiceType(obj.getString(JSON_SERVICE_TYPE)); } } catch (JSONException e) { log.error(e.getMessage()); throw new AuditException("Json Reader Parse Error " + e.getMessage()); } - - log.warn("subscriberType (" + customerId + ") CANNOT be found: ", payload ); - - return; - } - - /* Look for "/customers/customer/" and "/service-subscriptions/service-subscription/" in resourceLink - * and find the customer id and service type. - * For example, - * "/aai/v11/business/customers/customer/DemoCust_651800ed-2a3c-45f5-b920-85c1ed155fc2/service-subscriptions/service-subscription/vFW/service-instances/service-instance/adc3cc2a-c73e-414f-8ddb-367de81300cb" - * customerId = DemoCust_651800ed-2a3c-45f5-b920-85c1ed155fc2 - * serviceType = vFW - * */ - private static ServiceEntity createServiceEntityObj (String resourceLink) { - if ((null == resourceLink) || resourceLink.isEmpty()) { - return null; - } - int customerIdIdx = resourceLink.indexOf(CUSTOMER_ID_STRING); - int serviceTypeIdx = resourceLink.indexOf(SERVICE_TYPE_STRING); - - if (( customerIdIdx < 0 ) || ( serviceTypeIdx < 0 )) { - return null; - } - - ServiceEntity serviceEntity = new ServiceEntity (); - serviceEntity.setCustomerId(abstractStrInfo(resourceLink, CUSTOMER_ID_STRING)); - serviceEntity.setServiceType(abstractStrInfo(resourceLink, SERVICE_TYPE_STRING)); return serviceEntity; } - /* * Extract the vnf-list from the Json payload. */ - private static List<Vnf> extractVnfList(String payload) throws AuditException { + private static List<Vnf> extractVnfList(String payload) throws AuditException { VnfList vnfList = VnfList.fromJson(payload); if (null != vnfList) { return vnfList.getVnfList(); @@ -572,14 +484,10 @@ public class RestUtil { } - private static String abstractStrInfo (String origStr, String matchStr) { - String after = origStr.substring( origStr.indexOf(matchStr) + matchStr.length()); - - return after.substring(0, after.indexOf(FORWARD_SLASH)); - } - /** - * Get the common model list of AAI exist in SDNC per each (AAI GenericVNF > vf-modules > vf-module > model-version-id ) + * Get the common model list of AAI exist in SDNC per each (AAI GenericVNF > + * vf-modules > vf-module > model-version-id ) + * * @param aaiVnf * @param sdncVnfList * @return @@ -587,16 +495,18 @@ public class RestUtil { */ private static List<VFModule> getVfModuleList(VnfInstance aaiVnf, List<Vnf> sdncVnfList) { List<VFModule> vfmoduleLst = new ArrayList<>(); - if (aaiVnf.getVfModules() != null && aaiVnf.getVfModules().getVfModule() != null ) { - ConcurrentMap<String, AtomicInteger> vnfModulemap = buildMaxInstanceMap(aaiVnf.getVfModules().getVfModule()) ; + if (aaiVnf.getVfModules() != null && aaiVnf.getVfModules().getVfModule() != null) { + ConcurrentMap<String, AtomicInteger> vnfModulemap = buildMaxInstanceMap( + aaiVnf.getVfModules().getVfModule()); for (Map.Entry<String, AtomicInteger> entry : vnfModulemap.entrySet()) { String modelVersionId = entry.getKey(); for (Vnf sdncVnf : sdncVnfList) { - if ( sdncVnf.getVnfId().equals(modelVersionId)) { + if (sdncVnf.getVnfId().equals(modelVersionId)) { VFModule vfModule = new VFModule(); vfModule.setUuid(modelVersionId); vfModule.setMaxInstances(entry.getValue().intValue()); - VnfAssignments vnfAssignments = sdncVnf.getServiceData().getVnfTopologyInformation().getVnfAssignments(); + VnfAssignments vnfAssignments = sdncVnf.getServiceData().getVnfTopologyInformation() + .getVnfAssignments(); if (null != vnfAssignments) { List<Network> networks = new ArrayList<>(); for (VnfNetwork vnfNetwork : vnfAssignments.getVnfNetworks()) { @@ -604,7 +514,7 @@ public class RestUtil { network.setName(vnfNetwork.getNetworkName()); network.setUuid(vnfNetwork.getNetworkId()); if (null != vnfNetwork.getNetworkRole()) { - Attribute networkRole = new Attribute(); + Attribute networkRole = new Attribute(); networkRole.setName(Name.networkRole); networkRole.setValue(vnfNetwork.getNetworkRole()); } @@ -617,20 +527,23 @@ public class RestUtil { } } } - log.debug("The size of vfmoduleLst:"+ vfmoduleLst.size()); + log.debug("The size of vfmoduleLst: {}", vfmoduleLst.size()); return vfmoduleLst; } /* - * Build the map with key (model_version_id) and with the max occurrences of the value in the map + * Build the map with key (model_version_id) and with the max occurrences of the + * value in the map + * * @param vf_module_List + * * @return */ private static ConcurrentMap<String, AtomicInteger> buildMaxInstanceMap(List<VfModule> vfModuleList) { ConcurrentMap<String, AtomicInteger> map = new ConcurrentHashMap<>(); - for (VfModule vfModule: vfModuleList) { + for (VfModule vfModule : vfModuleList) { String vfModuleId = vfModule.getVfModuleId(); map.putIfAbsent(vfModuleId, new AtomicInteger(0)); map.get(vfModuleId).incrementAndGet(); @@ -640,7 +553,9 @@ public class RestUtil { /* * Get the common model list of VNFC from the SDNC Vnfs + * * @param sdncVnfMap + * * @return */ private static List<VNFC> getVnfcList(List<Vnf> sdncVnfList) { @@ -648,7 +563,8 @@ public class RestUtil { if (sdncVnfList != null && !sdncVnfList.isEmpty()) { for (Vnf sdncVnf : sdncVnfList) { try { - List<VnfVm> sdncVnfVmLst = sdncVnf.getServiceData().getVnfTopologyInformation().getVnfAssignments().getVnfVms(); + List<VnfVm> sdncVnfVmLst = sdncVnf.getServiceData().getVnfTopologyInformation().getVnfAssignments() + .getVnfVms(); if (sdncVnfVmLst != null && !sdncVnfVmLst.isEmpty()) { for (VnfVm sdncVnfVm : sdncVnfVmLst) { List<VmName> sdncVmNameLst = sdncVnfVm.getVmNames(); @@ -669,10 +585,8 @@ public class RestUtil { } } } - log.debug("The size of vnfcList:"+ vnfcList.size()); + log.debug("The size of vnfcList: {}", vnfcList.size()); return vnfcList; } - - } diff --git a/src/test/java/org/onap/pomba/contextbuilder/sdnc/unittest/service/SdncContextBuilderTest.java b/src/test/java/org/onap/pomba/contextbuilder/sdnc/unittest/service/SdncContextBuilderTest.java index f0c0210..b7fbd33 100644 --- a/src/test/java/org/onap/pomba/contextbuilder/sdnc/unittest/service/SdncContextBuilderTest.java +++ b/src/test/java/org/onap/pomba/contextbuilder/sdnc/unittest/service/SdncContextBuilderTest.java @@ -30,8 +30,8 @@ import com.github.jknack.handlebars.internal.Files; import com.github.tomakehurst.wiremock.junit.WireMockRule; import java.io.File; import java.io.IOException; +import java.text.MessageFormat; import java.util.Collections; -import java.util.UUID; import javax.servlet.http.HttpServletRequest; import javax.ws.rs.core.HttpHeaders; import javax.ws.rs.core.MultivaluedHashMap; @@ -43,9 +43,7 @@ import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; -import org.onap.aai.restclient.client.RestClient; import org.onap.pomba.contextbuilder.sdnc.Application; -import org.onap.pomba.contextbuilder.sdnc.model.ServiceEntity; import org.onap.pomba.contextbuilder.sdnc.service.rs.RestService; import org.onap.pomba.contextbuilder.sdnc.util.RestUtil; import org.springframework.beans.factory.annotation.Autowired; @@ -70,15 +68,12 @@ import org.springframework.test.context.web.WebAppConfiguration; public class SdncContextBuilderTest { private String testRestHeaders = "testRestHeaders"; - private String servicePath = "/service-subscriptions/service-subscription/vFW/service-instances/service-instance/"; - private String genericVnfPath = "/aai/v11/network/generic-vnfs/generic-vnf/"; + private String aaiGenericVnfPath = "/aai/v11/network/generic-vnfs/generic-vnf/"; private String genericResourcePath = "/restconf/config/GENERIC-RESOURCE-API:services/service/"; private String portMirrorConfigurationsResourcePath = "/restconf/config/GENERIC-RESOURCE-API:port-mirror-configurations/port-mirror-configuration/3c368d8d-efda-49d4-bbb5-a6465330a230/configuration-data/configuration-operation-information/port-mirror-configuration-request-input"; private String vnfPath = "/restconf/config/VNF-API:vnfs/vnf-list/"; private String serviceInstanceIdVfw = "7d518257-49bd-40ac-8d17-017a726ec12a"; // customerData.json private String serviceInstanceIdVcpe = "68352304-7bba-4609-8551-0d0b819376c3"; // queryNodeDataVcpe.json - private String customerIdVfw = "DemoCust_651800ed-2a3c-45f5-b920-85c1ed155fc2"; // customerData.json - private String customerIdVcpe = "SDN-ETHERNET-INTERNET"; private String genericVnfId = "d94daff6-7d5b-4d2e-bc99-c9af0754b59d"; private String moduleId = "2c3f8902-f278-4ee3-93cf-9d2364cbafca"; @@ -90,15 +85,7 @@ public class SdncContextBuilderTest { private String sdncCtxBuilderBasicAuthorization; //AAI related @Autowired - private String aaiBasicAuthorization; - @Autowired - private RestClient aaiClient; - @Autowired - private String aaiBaseUrl; - @Autowired - private String aaiPathToSearchNodeQuery; - @Autowired - private String aaiPathToCustomerQuery; + private String aaiPathToServiceInstanceQuery; @Rule public WireMockRule aaiEnricherRule = new WireMockRule(wireMockConfig().port(9808)); @@ -115,7 +102,7 @@ public class SdncContextBuilderTest { @Test public void testRestHeaders() throws Exception { - HttpHeaders mockHttpHeaders = mock( HttpHeaders.class); + HttpHeaders mockHttpHeaders = mock(HttpHeaders.class); // Test with No Partner Name final MultivaluedMap<String, String> multivaluedMapImpl = buildHeaders( @@ -144,7 +131,7 @@ public class SdncContextBuilderTest { @Test public void testRestParameterServiceInstanceId() throws Exception { - HttpHeaders mockHttpHeaders = mock( HttpHeaders.class); + HttpHeaders mockHttpHeaders = mock(HttpHeaders.class); final MultivaluedMap<String, String> multivaluedMapImpl = buildHeaders( "testRestParameterServiceInstanceId", "test1", sdncCtxBuilderBasicAuthorization); @@ -157,126 +144,70 @@ public class SdncContextBuilderTest { } @Test - public void testVerifySdncContextBuilder() throws Exception { - + public void testVerifySdncContextBuilderVnfApi() throws Exception { - HttpHeaders mockHttpHeaders = mock( HttpHeaders.class); + HttpHeaders mockHttpHeaders = mock(HttpHeaders.class); final MultivaluedMap<String, String> multivaluedMapImpl = buildHeaders( "testVerifyServiceDecomposition", "test1", sdncCtxBuilderBasicAuthorization); when(mockHttpHeaders.getRequestHeaders()).thenReturn(multivaluedMapImpl); - // First try a vFW service instance - - String queryNodeVfwUrl = aaiPathToSearchNodeQuery + serviceInstanceIdVfw; - addResponse(queryNodeVfwUrl, "junit/queryNodeDataVfw.json", aaiEnricherRule); - - String customerVfwUrl = aaiPathToCustomerQuery + customerIdVfw; - addResponse(customerVfwUrl, "junit/customerData.json", aaiEnricherRule); - - String serviceInstanceUrl = aaiPathToCustomerQuery - + customerIdVfw - + servicePath - + serviceInstanceIdVfw; - addResponse(serviceInstanceUrl, "junit/serviceInstance.json", aaiEnricherRule); + String serviceInstanceUrl = MessageFormat.format(aaiPathToServiceInstanceQuery, serviceInstanceIdVfw); + addResponse(serviceInstanceUrl, "junit/serviceInstancevfw.json", aaiEnricherRule); String vnfApiUrl = vnfPath + moduleId; addResponse(vnfApiUrl, "junit/vnfApiResponse.json", sdncRule); - String genericVnfUrl = genericVnfPath + genericVnfId + "?depth=all"; + String genericVnfUrl = aaiGenericVnfPath + genericVnfId + "?depth=all"; addResponse(genericVnfUrl, "junit/genericVnf.json", aaiEnricherRule); + Response response = this.service.getContext(httpServletRequest, mockHttpHeaders, serviceInstanceIdVfw); assertEquals(Status.OK.getStatusCode(), response.getStatus()); + } - // Now try a vCPE service instance - - String queryNodeUrlVcpe = aaiPathToSearchNodeQuery + serviceInstanceIdVcpe; - addResponse(queryNodeUrlVcpe, "junit/queryNodeDataVcpe.json", aaiEnricherRule); - - String customerVcpeUrl = aaiPathToCustomerQuery + customerIdVcpe; - addResponse(customerVcpeUrl, "junit/customerData.json", aaiEnricherRule); + @Test + public void testVerifySdncContextBuilderGenericVnf() throws Exception { + HttpHeaders mockHttpHeaders = mock(HttpHeaders.class); + final MultivaluedMap<String, String> multivaluedMapImpl = buildHeaders( + "testVerifyServiceDecomposition", "test1", sdncCtxBuilderBasicAuthorization); + when(mockHttpHeaders.getRequestHeaders()).thenReturn(multivaluedMapImpl); + + String serviceInstanceUrl = MessageFormat.format(aaiPathToServiceInstanceQuery, serviceInstanceIdVcpe); + addResponse(serviceInstanceUrl, "junit/serviceInstance.json", aaiEnricherRule); + String genericVnfUrl = aaiGenericVnfPath + genericVnfId + "?depth=all"; + addResponse(genericVnfUrl, "junit/genericVnf.json", aaiEnricherRule); + String urlStr = genericResourcePath + serviceInstanceIdVcpe; addResponse(urlStr, "junit/sdncGenericResponse.json", sdncRule); addResponse(portMirrorConfigurationsResourcePath, "junit/portMirrorConfigurationsResponse.json", sdncRule); - response = this.service.getContext(httpServletRequest, mockHttpHeaders, serviceInstanceIdVcpe); - assertEquals(Status.OK.getStatusCode(), response.getStatus()); - - // Try again with no transcactionId - final MultivaluedMap<String, String> multivaluedMapImpl1 = buildHeaders( - "testVerifyServiceDecomposition", null, sdncCtxBuilderBasicAuthorization); - when(mockHttpHeaders.getRequestHeaders()).thenReturn(multivaluedMapImpl1); - response = this.service.getContext(httpServletRequest, mockHttpHeaders, serviceInstanceIdVcpe); + Response response = this.service.getContext(httpServletRequest, mockHttpHeaders, serviceInstanceIdVcpe); assertEquals(Status.OK.getStatusCode(), response.getStatus()); } + @Test + public void testVerifySdncContextBuilderNoTransactionId() throws Exception { - //AAI related + HttpHeaders mockHttpHeaders = mock(HttpHeaders.class); + final MultivaluedMap<String, String> multivaluedMapImpl = buildHeaders( + "testVerifyServiceDecomposition", null, sdncCtxBuilderBasicAuthorization); + when(mockHttpHeaders.getRequestHeaders()).thenReturn(multivaluedMapImpl); + + String serviceInstanceUrl = MessageFormat.format(aaiPathToServiceInstanceQuery, serviceInstanceIdVcpe); + addResponse(serviceInstanceUrl, "junit/serviceInstance.json", aaiEnricherRule); - @Test - public void testObtainResouceLinkBasedOnServiceInstanceFromAai() throws Exception { - String transactionId = UUID.randomUUID().toString(); - String queryNodeUrl = aaiPathToSearchNodeQuery + serviceInstanceIdVfw; - addResponse(queryNodeUrl, "junit/queryNodeDataVfw.json", aaiEnricherRule); - String customerUrl = aaiPathToCustomerQuery + customerIdVfw; - addResponse(customerUrl, "junit/customerData.json", aaiEnricherRule); - - ServiceEntity serviceEntity = RestUtil.getServiceEntity(aaiClient, - aaiBaseUrl, - aaiBasicAuthorization, - aaiPathToSearchNodeQuery, - aaiPathToCustomerQuery, - serviceInstanceIdVfw, - transactionId); - - assertEquals(serviceInstanceIdVfw, serviceEntity.getServiceInstanceId()); - assertEquals("vFW", serviceEntity.getServiceType()); // customerData.json - assertEquals(customerIdVfw, serviceEntity.getCustomerId()); // queryNodeData-1.json - assertEquals("DemoCust_651800ed-2a3c-45f5-b920-85c1ed155fc2", - serviceEntity.getCustomerName()); // customerData.json - assertEquals("CUST", serviceEntity.getCustomerType()); // customerData.json - } + String genericVnfUrl = aaiGenericVnfPath + genericVnfId + "?depth=all"; + addResponse(genericVnfUrl, "junit/genericVnf.json", aaiEnricherRule); + + String urlStr = genericResourcePath + serviceInstanceIdVcpe; + addResponse(urlStr, "junit/sdncGenericResponse.json", sdncRule); - @Test - public void testObtainResouceLinkBasedOnServiceInstanceFromAaiNullResourceLink() throws Exception { - String transactionId = UUID.randomUUID().toString(); - String queryNodeUrl = aaiPathToSearchNodeQuery + serviceInstanceIdVfw; - addResponse(queryNodeUrl, "junit/queryNodeDataNullResourceLink.json", aaiEnricherRule); - - try { - RestUtil.getServiceEntity(aaiClient, - aaiBaseUrl, - aaiBasicAuthorization, - aaiPathToSearchNodeQuery, - aaiPathToCustomerQuery, - serviceInstanceIdVfw, - transactionId); - } catch (Exception e) { - assertTrue(e.getMessage().contains("JSONObject[\"resource-link\"] not found")); - } - } + addResponse(portMirrorConfigurationsResourcePath, "junit/portMirrorConfigurationsResponse.json", sdncRule); - @Test - public void testObtainResouceLinkBasedOnServiceInstanceFromAaiNullCustomerType() throws Exception { - String transactionId = UUID.randomUUID().toString(); - String queryNodeUrl = aaiPathToSearchNodeQuery + serviceInstanceIdVfw; - addResponse(queryNodeUrl, "junit/queryNodeDataVfw.json", aaiEnricherRule); - String customerUrl = aaiPathToCustomerQuery + customerIdVfw; - addResponse(customerUrl, "junit/customerDataCustomerIdNotFound.json", aaiEnricherRule); - - try { - RestUtil.getServiceEntity(aaiClient, - aaiBaseUrl, - aaiBasicAuthorization, - aaiPathToSearchNodeQuery, - aaiPathToCustomerQuery, - serviceInstanceIdVfw, - transactionId); - } catch (Exception e) { - assertTrue(e.getMessage().contains("Customer ID cannot be found from AAI")); - } + Response response = this.service.getContext(httpServletRequest, mockHttpHeaders, serviceInstanceIdVcpe); + assertEquals(Status.OK.getStatusCode(), response.getStatus()); } private void addResponse(String url, String responseFile, WireMockRule thisMock) throws IOException { diff --git a/src/test/resources/junit/customerData.json b/src/test/resources/junit/customerData.json deleted file mode 100644 index 31e6baa..0000000 --- a/src/test/resources/junit/customerData.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "global-customer-id": "DemoCust_651800ed-2a3c-45f5-b920-85c1ed155fc2", - "subscriber-name": "DemoCust_651800ed-2a3c-45f5-b920-85c1ed155fc2", - "subscriber-type": "CUST", - "resource-version": "1526324315029" -}
\ No newline at end of file diff --git a/src/test/resources/junit/customerDataCustomerIdNotFound.json b/src/test/resources/junit/customerDataCustomerIdNotFound.json deleted file mode 100644 index e2f71c6..0000000 --- a/src/test/resources/junit/customerDataCustomerIdNotFound.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "global-customer-id": "dummy", - "subscriber-name": "dummy", - "subscriber-type": "CUST", - "resource-version": "1526324315029" -}
\ No newline at end of file diff --git a/src/test/resources/junit/queryNodeDataNullResourceLink.json b/src/test/resources/junit/queryNodeDataNullResourceLink.json deleted file mode 100644 index 36eb667..0000000 --- a/src/test/resources/junit/queryNodeDataNullResourceLink.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "result-data": [ - { - "resource-type": "service-instance", - "related-link": "/aai/v11/network/vnfcs/vnfc/zrdm5aepdg01vmg003" - } - ] -} diff --git a/src/test/resources/junit/queryNodeDataVcpe.json b/src/test/resources/junit/queryNodeDataVcpe.json deleted file mode 100644 index 593ba09..0000000 --- a/src/test/resources/junit/queryNodeDataVcpe.json +++ /dev/null @@ -1,9 +0,0 @@ -{
- "result-data": [
- {
- "resource-type": "service-instance",
- "resource-link": "/aai/v11/business/customers/customer/SDN-ETHERNET-INTERNET/service-subscriptions/service-subscription/vCPE/service-instances/service-instance/68352304-7bba-4609-8551-0d0b819376c3"
- }
- ]
-}
-
diff --git a/src/test/resources/junit/queryNodeDataVfw.json b/src/test/resources/junit/queryNodeDataVfw.json deleted file mode 100644 index e827391..0000000 --- a/src/test/resources/junit/queryNodeDataVfw.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "result-data": [ - { - "resource-type": "service-instance", - "resource-link": "/aai/v11/business/customers/customer/DemoCust_651800ed-2a3c-45f5-b920-85c1ed155fc2/service-subscriptions/service-subscription/vFW/service-instances/service-instance/7d518257-49bd-40ac-8d17-017a726ec12a" - } - ] -}
\ No newline at end of file diff --git a/src/test/resources/junit/serviceInstancevfw.json b/src/test/resources/junit/serviceInstancevfw.json new file mode 100644 index 0000000..85afe08 --- /dev/null +++ b/src/test/resources/junit/serviceInstancevfw.json @@ -0,0 +1,67 @@ +{
+ "service-instance-id": "68352304-7bba-4609-8551-0d0b819376c3",
+ "service-instance-name": "vcpe_svc_vcpesvc_vgmux_201809061919",
+ "service-type": "vFW",
+ "environment-context": "General_Revenue-Bearing",
+ "workload-context": "Production",
+ "model-invariant-id": "58f20afd-6ed1-4451-a19d-4fbee4aefa08",
+ "model-version-id": "7b4beec3-04a6-4513-8341-959589d2bd01",
+ "resource-version": "1536261835931",
+ "orchestration-status": "Active",
+ "relationship-list": {
+ "relationship": [
+ {
+ "related-to": "project",
+ "related-link": "/aai/v11/business/projects/project/Project-Demonstration",
+ "relationship-data": [
+ {
+ "relationship-key": "project.project-name",
+ "relationship-value": "Project-Demonstration"
+ }
+ ]
+ },
+ {
+ "related-to": "generic-vnf",
+ "related-link": "/aai/v11/network/generic-vnfs/generic-vnf/d94daff6-7d5b-4d2e-bc99-c9af0754b59d",
+ "relationship-data": [
+ {
+ "relationship-key": "generic-vnf.vnf-id",
+ "relationship-value": "d94daff6-7d5b-4d2e-bc99-c9af0754b59d"
+ }
+ ],
+ "related-to-property": [
+ {
+ "property-key": "generic-vnf.vnf-name",
+ "property-value": "vcpe_vnf_vcpevsp_vgmux_0830_201809061919"
+ }
+ ]
+ },
+ {
+ "related-to": "l3-network",
+ "related-link": "/aai/v11/network/l3-networks/l3-network/ca6f5cdc-cf66-4d03-b5c0-3604da0709a6",
+ "relationship-data": [
+ {
+ "relationship-key": "l3-network.network-id",
+ "relationship-value": "ca6f5cdc-cf66-4d03-b5c0-3604da0709a6"
+ }
+ ],
+ "related-to-property": [
+ {
+ "property-key": "l3-network.network-name",
+ "property-value": "vcpe_net_mux_gw_201809061919"
+ }
+ ]
+ },
+ {
+ "related-to": "owning-entity",
+ "related-link": "/aai/v11/business/owning-entities/owning-entity/520cc603-a3c4-4ec2-9ef4-ca70facd79c0",
+ "relationship-data": [
+ {
+ "relationship-key": "owning-entity.owning-entity-id",
+ "relationship-value": "520cc603-a3c4-4ec2-9ef4-ca70facd79c0"
+ }
+ ]
+ }
+ ]
+ }
+}
|