From afb92745b997e09a6983da09a985668fe6c39ead Mon Sep 17 00:00:00 2001 From: zm330 Date: Thu, 17 Sep 2020 00:29:43 +0800 Subject: Update template analysis process Issue-ID: SO-2963 Signed-off-by: zm330 Change-Id: I2a1190191e18b8a580e421847a5143ef45a7877d --- .../org/onap/so/asdc/client/ASDCController.java | 18 ++-- .../installer/heat/ToscaResourceInstaller.java | 97 +++++++++++++++------- 2 files changed, 79 insertions(+), 36 deletions(-) (limited to 'asdc-controller') diff --git a/asdc-controller/src/main/java/org/onap/so/asdc/client/ASDCController.java b/asdc-controller/src/main/java/org/onap/so/asdc/client/ASDCController.java index 61c0cdbf2e..44ea2a25a2 100644 --- a/asdc-controller/src/main/java/org/onap/so/asdc/client/ASDCController.java +++ b/asdc-controller/src/main/java/org/onap/so/asdc/client/ASDCController.java @@ -971,8 +971,10 @@ public class ASDCController { private void processNsstNotification(INotificationData iNotif, ToscaResourceStructure toscaResourceStructure) { Metadata serviceMetadata = toscaResourceStructure.getServiceMetadata(); try { - if (serviceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_CATEGORY).equalsIgnoreCase("NSST")) { - + String category = serviceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_CATEGORY); + boolean isNeedInital = (category.contains("NSST") || category.equalsIgnoreCase("TN Network Requirement")) + && iNotif.getResources().isEmpty(); + if (isNeedInital) { String artifactContent = null; List serviceArtifacts = iNotif.getServiceArtifacts(); Optional artifactOpt = serviceArtifacts.stream() @@ -986,14 +988,18 @@ public class ASDCController { artifactContent = zipParserInstance.parseJsonForZip(filePath); logger.debug( "serviceArtifact parsing success! serviceArtifactUUID: " + artifactInfo.getArtifactUUID()); + + ResourceStructure resourceStructure = new VfResourceStructure(iNotif, new ResourceInstance()); + resourceStructure.setResourceType(ResourceType.OTHER); + toscaInstaller.installNsstService(toscaResourceStructure, (VfResourceStructure) resourceStructure, + artifactContent); } else { logger.debug("serviceArtifact is null"); + toscaInstaller.installNsstService(toscaResourceStructure, null, null); } - ResourceStructure resourceStructure = new VfResourceStructure(iNotif, new ResourceInstance()); - resourceStructure.setResourceType(ResourceType.OTHER); - toscaInstaller.installTheNsstService(toscaResourceStructure, (VfResourceStructure) resourceStructure, - artifactContent); + } + } catch (IOException e) { logger.error("serviceArtifact parse failure for service uuid: " + serviceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_CATEGORY)); diff --git a/asdc-controller/src/main/java/org/onap/so/asdc/installer/heat/ToscaResourceInstaller.java b/asdc-controller/src/main/java/org/onap/so/asdc/installer/heat/ToscaResourceInstaller.java index d023df3b79..49fef1d3f0 100644 --- a/asdc-controller/src/main/java/org/onap/so/asdc/installer/heat/ToscaResourceInstaller.java +++ b/asdc-controller/src/main/java/org/onap/so/asdc/installer/heat/ToscaResourceInstaller.java @@ -2870,7 +2870,15 @@ public class ToscaResourceInstaller { List serviceInputs = sdcCsarHelper.getServiceInputs(); if (!serviceInputs.isEmpty()) { serviceInputList = new ArrayList<>(); - serviceInputs.forEach(input -> { + List filterList; + filterList = serviceInputs.stream() + .filter(input -> !SKIP_POST_INST_CONF.equals(input.getName()) + && !CDS_MODEL_NAME.equalsIgnoreCase(input.getName()) + && !CDS_MODEL_VERSION.equalsIgnoreCase(input.getName()) + && !CONTROLLER_ACTOR.equalsIgnoreCase(input.getName())) + .collect(Collectors.toList()); + + filterList.forEach(input -> { Map serviceInputMap = new HashMap<>(); serviceInputMap.put("name", input.getName()); serviceInputMap.put("type", input.getType()); @@ -2894,7 +2902,7 @@ public class ToscaResourceInstaller { } @Transactional(rollbackFor = {ArtifactInstallerException.class}) - public void installTheNsstService(ToscaResourceStructure toscaResourceStruct, VfResourceStructure vfResourceStruct, + public void installNsstService(ToscaResourceStructure toscaResourceStruct, VfResourceStructure vfResourceStruct, String artifactContent) { createToscaCsar(toscaResourceStruct); createService(toscaResourceStruct, vfResourceStruct); @@ -2925,6 +2933,10 @@ public class ToscaResourceInstaller { } private void createServiceInfo(ToscaResourceStructure toscaResourceStruct, Service service) { + if (!service.getServiceInfos().isEmpty()) { + return; + } + List serviceInfos = new ArrayList<>(); ServiceInfo serviceInfo = new ServiceInfo(); @@ -2945,42 +2957,67 @@ public class ToscaResourceInstaller { ISdcCsarHelper helper = toscaResourceStruct.getSdcCsarHelper(); String typeName = helper.getServiceSubstitutionMappingsTypeName(); Optional nodeTemplate = helper.getServiceNodeTemplates().stream().findAny(); - List serviceProperties = new ArrayList<>(); - Map servicePropertiesMap; + if (nodeTemplate.isPresent()) { + String serviceUUID = nodeTemplate.get().getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID); LinkedHashMap customDef = nodeTemplate.get().getCustomDef(); - Optional machKey = - customDef.keySet().stream().filter(key -> key.equalsIgnoreCase(typeName)).findFirst(); - if (machKey.isPresent()) { - Object obj = customDef.get(machKey.get()); - try { - if (obj instanceof Map) { - Object properties = ((HashMap) obj).get("properties"); - if (null != properties) { - for (Object propertyName : ((Map) properties).keySet()) { - servicePropertiesMap = new HashMap<>(); - servicePropertiesMap.put("name", propertyName); - Object object = ((Map) properties).get(propertyName); - for (Object entry : ((Map) object).entrySet()) { - servicePropertiesMap.put((String) ((Map.Entry) entry).getKey(), - ((Map.Entry) entry).getValue()); - } - servicePropertiesMap.remove("description"); - serviceProperties.add(servicePropertiesMap); + List serviceProperties = getPropertiesFromCustomDef(customDef, typeName); + + try { + propertiesJson = objectMapper.writeValueAsString(serviceProperties); + propertiesJson = propertiesJson.replace("\"", "\\\""); + } catch (JsonProcessingException e) { + logger.error("serviceProperties could not be deserialized for service uuid: " + serviceUUID); + } catch (Exception ex) { + logger.error("service properties parsing failed. service uuid:" + serviceUUID); + } + + } else { + logger.debug("ServiceNodeTemplates is null"); + } + return propertiesJson; + } + + private static List getPropertiesFromCustomDef(LinkedHashMap customDef, + final String typeName) { + Optional machKey = + customDef.keySet().stream().filter(key -> key.equalsIgnoreCase(typeName)).findFirst(); + Map servicePropertiesMap; + List serviceProperties = new ArrayList<>(); + + if (machKey.isPresent()) { + Object obj = customDef.get(machKey.get()); + if (obj instanceof Map) { + Object properties = ((HashMap) obj).get("properties"); + if (null != properties) { + for (Object propertyName : ((Map) properties).keySet()) { + if (propertyName.toString().split("_").length >= 2) { + continue; + } + + servicePropertiesMap = new HashMap<>(); + servicePropertiesMap.put("name", propertyName); + Object object = ((Map) properties).get(propertyName); + for (Object entry : ((Map) object).entrySet()) { + servicePropertiesMap.put((String) ((Map.Entry) entry).getKey(), + ((Map.Entry) entry).getValue()); + } + + String type = servicePropertiesMap.get("type").toString(); + if (type.split("\\.").length >= 2) { + List subProperties = getPropertiesFromCustomDef(customDef, type); + if (subProperties.size() > 0) { + serviceProperties.addAll(subProperties); } - propertiesJson = objectMapper.writeValueAsString(serviceProperties); - propertiesJson = propertiesJson.replace("\"", "\\\""); + continue; } + servicePropertiesMap.remove("description"); + serviceProperties.add(servicePropertiesMap); } - } catch (JsonProcessingException e) { - logger.error("serviceProperties could not be deserialized for service uuid: " - + nodeTemplate.get().getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID)); } } - } else { - logger.debug("ServiceNodeTemplates is null"); } - return propertiesJson; + return serviceProperties; } } -- cgit 1.2.3-korg