From: Adrian OSullivan Date: Mon, 24 Aug 2020 14:28:05 +0000 (+0000) Subject: Merge "Implement E2EService activation/deactivation for NetworkSlicing" X-Git-Tag: 7.0.1~5 X-Git-Url: https://gerrit.onap.org/r/gitweb?a=commitdiff_plain;h=967b113a25e92e0b95ad4a1ac3b3966debd6d921;p=externalapi%2Fnbi.git Merge "Implement E2EService activation/deactivation for NetworkSlicing" --- 967b113a25e92e0b95ad4a1ac3b3966debd6d921 diff --cc src/main/java/org/onap/nbi/apis/serviceorder/workflow/PostSoProcessor.java index 17b72e4,9c673f9..4568b80 --- a/src/main/java/org/onap/nbi/apis/serviceorder/workflow/PostSoProcessor.java +++ b/src/main/java/org/onap/nbi/apis/serviceorder/workflow/PostSoProcessor.java @@@ -575,89 -578,5 +590,89 @@@ public class PostSoProcessor return userParams; } + + /** + * Build a list of InstanceParams for the SO Macro request by browsing a list of + * ServiceCharacteristics + */ + private HashMap retrieveInstanceParamsFromServiceCharacteristics( + List characteristics) { + + HashMap instanceParams = new HashMap<>(); + + if (!CollectionUtils.isEmpty(characteristics)) { + for (ServiceCharacteristic characteristic : characteristics) { + // Check is the characteristic is of type object, if proceed as before to allow + // for + // backwards compatibility. + if (characteristic.getValueType() != null && !characteristic.getValueType().isEmpty() + && characteristic.getValueType().equals("object")) { + ObjectMapper mapper = new ObjectMapper(); + JsonNode jsonNode = null; + try { + jsonNode = mapper.readTree(characteristic.getValue().getServiceCharacteristicValue()); + } catch (IOException e) { + LOGGER.error("Failed to read object json {} , exception is ", + characteristic.getValue().getServiceCharacteristicValue(), e.getMessage()); + } + ObjectNode objectNode = (ObjectNode) jsonNode; + Iterator> iter = objectNode.fields(); + while (iter.hasNext()) { + Map.Entry entry = iter.next(); + if (!entry.getValue().isArray()) { + instanceParams.put(entry.getKey(), entry.getValue().asText()); + } else { + ArrayNode arrayNode = (ArrayNode) entry.getValue(); + String arrayNodeValueString = arrayNode.toString(); + instanceParams.put(entry.getKey(), arrayNodeValueString); + } + } + } else { + instanceParams.put(characteristic.getName(), + characteristic.getValue().getServiceCharacteristicValue()); + } + } + } + + return instanceParams; + } + + /** + * Build and distinguish InstanceParams at VNF Level and Service level and overwrite values from ServiceOrder JSON Request. + * Can be used as buildAndDistinguishServiceAndVnfLevelParams.get("vnf"); or buildAndDistinguishServiceAndVnfLevelParams.get("cnf"); + */ + private Map buildAndDistinguishServiceAndVnfLevelParams( + Map instanceParamsFromServiceCharacteristic, Map existingVNFParams, + Map existingServiceParams) { + + //To be used by passing key as "vnf" or "service" for respective instanceParams + Map serviceAndVNFLevelInstanceParams = new HashMap<>(); + + Map resultVNFParams = new HashMap<>(); + Map resultServiceParams = new HashMap<>(); + + // First Filter VNF level Params From Service Characteristics and overwrite + // values + resultVNFParams = instanceParamsFromServiceCharacteristic.entrySet().stream() + .filter(entry -> existingVNFParams.containsKey(entry.getKey())) + .collect(Collectors.toMap(Entry::getKey, Entry::getValue)); + + //Add it as VNF level Params + serviceAndVNFLevelInstanceParams.put("vnf", resultVNFParams); + + // Filter VNF level Params From Service Level + existingServiceParams.entrySet().removeIf(e -> existingVNFParams.containsKey(e.getKey())); + + // Filter Service level Params From Service Characteristics and overwrite values + resultServiceParams = instanceParamsFromServiceCharacteristic.entrySet().stream() + .filter(entry -> existingServiceParams.containsKey(entry.getKey())) + .collect(Collectors.toMap(Entry::getKey, Entry::getValue)); + + //Add it as Service level params + serviceAndVNFLevelInstanceParams.put("service", resultServiceParams); + + return serviceAndVNFLevelInstanceParams; + + } - } + }