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 +++++++++++++++------- .../bpmn/common/scripts/DoHandleOofRequest.groovy | 2 +- .../scripts/CreateSliceService.groovy | 2 +- .../resources/subprocess/DoHandleOofRequest.bpmn | 8 +- .../onap/so/db/catalog/beans/AllottedResource.java | 3 + 6 files changed, 87 insertions(+), 43 deletions(-) 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; } } diff --git a/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/DoHandleOofRequest.groovy b/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/DoHandleOofRequest.groovy index ebc5f4ac58..644cf5e387 100644 --- a/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/DoHandleOofRequest.groovy +++ b/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/DoHandleOofRequest.groovy @@ -79,7 +79,7 @@ class DoHandleOofRequest extends AbstractServiceTaskProcessor { oofRequestPayload.setApiPath(apiPath) oofRequestPayload.setRequestDetails(requestDetails) ObjectMapper objectMapper = new ObjectMapper() - String requestJson = objectMapper.writeValueAsString(oofRequestPayload) + String requestJson = objectMapper.writeValueAsString(oofRequestPayload) execution.setVariable("oofRequestPayload", requestJson) } diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/CreateSliceService.groovy b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/CreateSliceService.groovy index 389f0a089c..dcbaf746ea 100644 --- a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/CreateSliceService.groovy +++ b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/CreateSliceService.groovy @@ -181,7 +181,7 @@ public class CreateSliceService extends AbstractServiceTaskProcessor { public void prepareSelectNSTRequest(DelegateExecution execution) { logger.debug("Start prepareSelectNSTRequest") String requestId = execution.getVariable("msoRequestId") - String messageType = "NSTSelectionResponse" + String messageType = "NSTSelectionResponse" Map serviceProfile = execution.getVariable("serviceProfile") execution.setVariable("nstSelectionUrl", "/api/oof/v1/selection/nst") execution.setVariable("nstSelection_messageType",messageType) diff --git a/bpmn/so-bpmn-infrastructure-flows/src/main/resources/subprocess/DoHandleOofRequest.bpmn b/bpmn/so-bpmn-infrastructure-flows/src/main/resources/subprocess/DoHandleOofRequest.bpmn index 7ca1a62312..d6b251649f 100644 --- a/bpmn/so-bpmn-infrastructure-flows/src/main/resources/subprocess/DoHandleOofRequest.bpmn +++ b/bpmn/so-bpmn-infrastructure-flows/src/main/resources/subprocess/DoHandleOofRequest.bpmn @@ -1,5 +1,5 @@ - + Flow_1jorico @@ -10,8 +10,7 @@ Flow_013jfci import org.onap.so.bpmn.common.scripts.* def oofHandler = new DoHandleOofRequest() -oofHandler .callOofAdapter(execution) - +oofHandler.callOofAdapter(execution) @@ -19,8 +18,7 @@ oofHandler .callOofAdapter(execution) Flow_1fbzzqg import org.onap.so.bpmn.common.scripts.* def oofHandler = new DoHandleOofRequest() -oofHandler .preProcessRequest(execution) - +oofHandler .preProcessRequest(execution) diff --git a/mso-catalog-db/src/main/java/org/onap/so/db/catalog/beans/AllottedResource.java b/mso-catalog-db/src/main/java/org/onap/so/db/catalog/beans/AllottedResource.java index 19e875f8bc..3827c0e19f 100644 --- a/mso-catalog-db/src/main/java/org/onap/so/db/catalog/beans/AllottedResource.java +++ b/mso-catalog-db/src/main/java/org/onap/so/db/catalog/beans/AllottedResource.java @@ -38,6 +38,8 @@ import org.apache.commons.lang3.builder.EqualsBuilder; import org.apache.commons.lang3.builder.HashCodeBuilder; import org.apache.commons.lang3.builder.ToStringBuilder; import com.openpojo.business.annotation.BusinessKey; +import org.hibernate.annotations.NotFound; +import org.hibernate.annotations.NotFoundAction; import uk.co.blackpepper.bowman.annotation.LinkedResource; import uk.co.blackpepper.bowman.annotation.RemoteResource; @@ -76,6 +78,7 @@ public class AllottedResource implements Serializable { private Date created; @OneToMany(cascade = CascadeType.ALL, mappedBy = "allottedResource") + @NotFound(action = NotFoundAction.IGNORE) private Set allotedResourceCustomization; @Override -- cgit 1.2.3-korg