aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-be/src/main/java/org
diff options
context:
space:
mode:
authorDmitry Puzikov <dmitry.puzikov@tieto.com>2020-01-28 18:04:40 +0100
committerDmitry Puzikov <d.puzikov2@partner.samsung.com>2020-02-25 10:11:49 +0100
commitb4aaa6d004c4643e593fc789bbe9776a6226315d (patch)
tree9d0f93bb56dce0c7bea2f40efa838e00d08a24b6 /catalog-be/src/main/java/org
parent0c274e9356fc77c53340828b0ec18869dad71631 (diff)
Policies import when import VSP
Polices import implemented. Error type added for invalid policies. Import tests added. Fix test failures. Got rid of Either in the new code. Change-Id: I3e91cc6d24433c2b3862f407348e71e1e67c3b4e Issue-ID: SDC-2728 Signed-off-by: Dmitry Puzikov <d.puzikov2@partner.samsung.com>
Diffstat (limited to 'catalog-be/src/main/java/org')
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/YamlTemplateParsingHandler.java121
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/PolicyBusinessLogic.java89
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/PolicyTypeBusinessLogic.java17
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogic.java20
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/utils/PropertiesUtils.java9
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/GroupExportParserImpl.java11
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/PolicyExportParserImpl.java11
7 files changed, 269 insertions, 9 deletions
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/YamlTemplateParsingHandler.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/YamlTemplateParsingHandler.java
index b86348d3a7..41dc3a6db3 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/YamlTemplateParsingHandler.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/YamlTemplateParsingHandler.java
@@ -25,6 +25,9 @@ import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.gson.Gson;
import fj.data.Either;
+import java.util.Collections;
+import java.util.EnumMap;
+import java.util.Objects;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang.StringUtils;
@@ -32,12 +35,15 @@ import org.openecomp.sdc.be.components.impl.AnnotationBusinessLogic;
import org.openecomp.sdc.be.components.impl.GroupTypeBusinessLogic;
import org.openecomp.sdc.be.components.impl.ImportUtils;
import org.openecomp.sdc.be.components.impl.NodeFilterUploadCreator;
+import org.openecomp.sdc.be.components.impl.PolicyTypeBusinessLogic;
import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException;
+import org.openecomp.sdc.be.components.utils.PropertiesUtils;
import org.openecomp.sdc.be.config.BeEcompErrorManager;
import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.dao.jsongraph.JanusGraphDao;
import org.openecomp.sdc.be.datatypes.elements.CapabilityDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.GetInputValueDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.PolicyTargetType;
import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
import org.openecomp.sdc.be.model.CapabilityDefinition;
import org.openecomp.sdc.be.model.ComponentInstanceProperty;
@@ -46,6 +52,8 @@ import org.openecomp.sdc.be.model.GroupTypeDefinition;
import org.openecomp.sdc.be.model.InputDefinition;
import org.openecomp.sdc.be.model.NodeTypeInfo;
import org.openecomp.sdc.be.model.ParsedToscaYamlInfo;
+import org.openecomp.sdc.be.model.PolicyDefinition;
+import org.openecomp.sdc.be.model.PolicyTypeDefinition;
import org.openecomp.sdc.be.model.UploadArtifactInfo;
import org.openecomp.sdc.be.model.UploadCapInfo;
import org.openecomp.sdc.be.model.UploadComponentInstanceInfo;
@@ -85,9 +93,11 @@ import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.IS_PASSWORD
import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.MEMBERS;
import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.NODE;
import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.NODE_TEMPLATES;
+import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.POLICIES;
import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.PROPERTIES;
import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.REQUIREMENTS;
import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.SUBSTITUTION_MAPPINGS;
+import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.TARGETS;
import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.TOPOLOGY_TEMPLATE;
import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.TYPE;
import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.VALID_SOURCE_TYPES;
@@ -108,12 +118,14 @@ public class YamlTemplateParsingHandler {
private JanusGraphDao janusGraphDao;
private GroupTypeBusinessLogic groupTypeBusinessLogic;
private AnnotationBusinessLogic annotationBusinessLogic;
+ private PolicyTypeBusinessLogic policyTypeBusinessLogic;
- public YamlTemplateParsingHandler(JanusGraphDao janusGraphDao,
- GroupTypeBusinessLogic groupTypeBusinessLogic, AnnotationBusinessLogic annotationBusinessLogic) {
+ public YamlTemplateParsingHandler(JanusGraphDao janusGraphDao, GroupTypeBusinessLogic groupTypeBusinessLogic,
+ AnnotationBusinessLogic annotationBusinessLogic, PolicyTypeBusinessLogic policyTypeBusinessLogic) {
this.janusGraphDao = janusGraphDao;
this.groupTypeBusinessLogic = groupTypeBusinessLogic;
this.annotationBusinessLogic = annotationBusinessLogic;
+ this.policyTypeBusinessLogic = policyTypeBusinessLogic;
}
public ParsedToscaYamlInfo parseResourceInfoFromYAML(String fileName, String resourceYml, Map<String, String> createdNodesToscaResourceNames,
@@ -128,6 +140,7 @@ public class YamlTemplateParsingHandler {
parsedToscaYamlInfo.setInputs(getInputs(mappedToscaTemplate));
parsedToscaYamlInfo.setInstances(getInstances(fileName, mappedToscaTemplate, createdNodesToscaResourceNames));
parsedToscaYamlInfo.setGroups(getGroups(fileName, mappedToscaTemplate));
+ parsedToscaYamlInfo.setPolicies(getPolicies(fileName, mappedToscaTemplate));
log.debug("#parseResourceInfoFromYAML - The yaml {} has been parsed ", fileName);
return parsedToscaYamlInfo;
}
@@ -165,6 +178,110 @@ public class YamlTemplateParsingHandler {
return inputs;
}
+ private Map<String, PolicyDefinition> getPolicies(String fileName, Map<String, Object> toscaJson) {
+
+ Map<String, Object> foundPolicies = findFirstToscaMapElement(toscaJson, POLICIES)
+ .left()
+ .on(err -> logPoliciesNotFound(fileName));
+
+ if (MapUtils.isNotEmpty(foundPolicies)) {
+ return foundPolicies
+ .entrySet()
+ .stream()
+ .map(this::createPolicy)
+ .collect(Collectors.toMap(PolicyDefinition::getName, p -> p));
+ }
+ return Collections.emptyMap();
+ }
+
+ private PolicyDefinition createPolicy(Map.Entry<String, Object> policyNameValue) {
+ PolicyDefinition emptyPolicyDef = new PolicyDefinition();
+ String policyName = policyNameValue.getKey();
+ emptyPolicyDef.setName(policyName);
+ try {
+ if (policyNameValue.getValue() != null && policyNameValue.getValue() instanceof Map) {
+ Map<String, Object> policyTemplateJsonMap = (Map<String, Object>) policyNameValue.getValue();
+ validateAndFillPolicy(emptyPolicyDef, policyTemplateJsonMap);
+ } else {
+ rollbackWithException(ActionStatus.NOT_TOPOLOGY_TOSCA_TEMPLATE);
+ }
+ } catch (ClassCastException e) {
+ log.debug("#createPolicy - Failed to create the policy {}. The exception occurred", policyName, e);
+ rollbackWithException(ActionStatus.INVALID_YAML);
+ }
+ return emptyPolicyDef;
+ }
+
+ private Map<String, Object> logPoliciesNotFound(String fileName) {
+ log.debug("#logPoliciesNotFound - Policies were not found in the yaml template {}.", fileName);
+ return Collections.emptyMap();
+ }
+
+ private void validateAndFillPolicy(PolicyDefinition emptyPolicyDefinition, Map<String, Object> policyTemplateJsonMap) {
+ String policyTypeName = (String) policyTemplateJsonMap.get(TYPE.getElementName());
+ if(StringUtils.isEmpty(policyTypeName)){
+ log.debug("#validateAndFillPolicy - The 'type' member is not found under policy {}", emptyPolicyDefinition.getName());
+ rollbackWithException(ActionStatus.POLICY_MISSING_POLICY_TYPE, emptyPolicyDefinition.getName());
+ }
+ emptyPolicyDefinition.setType(policyTypeName);
+ // set policy targets
+ emptyPolicyDefinition.setTargets(validateFillPolicyTargets(policyTemplateJsonMap));
+ PolicyTypeDefinition policyTypeDefinition = validateGetPolicyTypeDefinition(policyTypeName);
+ // set policy properties
+ emptyPolicyDefinition.setProperties(validateFillPolicyProperties(policyTypeDefinition, policyTemplateJsonMap));
+ }
+
+ private PolicyTypeDefinition validateGetPolicyTypeDefinition(String policyType) {
+ PolicyTypeDefinition policyTypeDefinition = policyTypeBusinessLogic.getLatestPolicyTypeByType(policyType);
+ if (policyTypeDefinition == null) {
+ log.debug("#validateAndFillPolicy - The policy type {} not found", policyType);
+ rollbackWithException(ActionStatus.POLICY_TYPE_IS_INVALID, policyType);
+ }
+ return policyTypeDefinition;
+ }
+
+ private List<PropertyDataDefinition> validateFillPolicyProperties(PolicyTypeDefinition policyTypeDefinition,
+ Map<String, Object> policyTemplateJsonMap) {
+ if (MapUtils.isEmpty(policyTemplateJsonMap) || Objects.isNull(policyTypeDefinition)) {
+ return Collections.emptyList();
+ }
+ List<PropertyDataDefinition> propertyDataDefinitionList = new ArrayList<>();
+ Map<String, Object> propertiesMap =
+ (Map<String, Object>) policyTemplateJsonMap.get(PROPERTIES.getElementName());
+ if (MapUtils.isEmpty(propertiesMap)) {
+ return Collections.emptyList();
+ }
+ if (CollectionUtils.isNotEmpty(policyTypeDefinition.getProperties())) {
+ propertyDataDefinitionList = policyTypeDefinition
+ .getProperties()
+ .stream()
+ .map(propertyDefinition -> setPropertyValue(propertiesMap,
+ propertyDefinition))
+ .collect(Collectors.toList());
+ }
+ return propertyDataDefinitionList;
+ }
+
+ private PropertyDataDefinition setPropertyValue(Map<String, Object> propertiesMap, PropertyDataDefinition srcPropertyDataDefinition) {
+ PropertyDataDefinition newPropertyDef = new PropertyDataDefinition(srcPropertyDataDefinition);
+ String propertyName = newPropertyDef.getName();
+ if (Objects.nonNull(propertiesMap.get(propertyName))) {
+ Object propValue = propertiesMap.get(propertyName);
+ newPropertyDef.setValue(PropertiesUtils.trimQuotes(gson.toJson(propValue)));
+ }
+ return newPropertyDef;
+ }
+
+ private Map<PolicyTargetType, List<String>> validateFillPolicyTargets(Map<String, Object> policyTemplateJson) {
+ Map<PolicyTargetType, List<String>> targets = new EnumMap<>(PolicyTargetType.class);
+ if (policyTemplateJson.containsKey(TARGETS.getElementName())
+ && policyTemplateJson.get(TARGETS.getElementName()) instanceof List ) {
+ List<String> targetsElement = (List<String>) policyTemplateJson.get(TARGETS.getElementName());
+ targets.put(PolicyTargetType.COMPONENT_INSTANCES, targetsElement);
+ }
+ return targets;
+ }
+
private Map<String, UploadComponentInstanceInfo> getInstances(String yamlName, Map<String, Object> toscaJson, Map<String, String> createdNodesToscaResourceNames) {
Map<String, Object> nodeTemlates = findFirstToscaMapElement(toscaJson, NODE_TEMPLATES)
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/PolicyBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/PolicyBusinessLogic.java
index 2d0ee0dd66..f872074f26 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/PolicyBusinessLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/PolicyBusinessLogic.java
@@ -21,8 +21,12 @@
package org.openecomp.sdc.be.components.impl;
import fj.data.Either;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.EnumMap;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
+import org.apache.commons.lang.StringUtils;
import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException;
import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
import org.openecomp.sdc.be.components.property.PropertyDeclarationOrchestrator;
@@ -32,9 +36,11 @@ import org.openecomp.sdc.be.datatypes.elements.GetPolicyValueDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.PolicyTargetType;
import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
+import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
import org.openecomp.sdc.be.datatypes.enums.PromoteVersionEnum;
import org.openecomp.sdc.be.model.Component;
import org.openecomp.sdc.be.model.ComponentInstInputsMap;
+import org.openecomp.sdc.be.model.ComponentInstance;
import org.openecomp.sdc.be.model.ComponentInstanceProperty;
import org.openecomp.sdc.be.model.ComponentParametersView;
import org.openecomp.sdc.be.model.PolicyDefinition;
@@ -49,6 +55,9 @@ import org.openecomp.sdc.be.model.operations.api.IGroupTypeOperation;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
import org.openecomp.sdc.be.model.operations.impl.InterfaceLifecycleOperation;
import org.openecomp.sdc.common.datastructure.Wrapper;
+import org.openecomp.sdc.common.log.elements.LoggerSupportability;
+import org.openecomp.sdc.common.log.enums.LoggerSupportabilityActions;
+import org.openecomp.sdc.common.log.enums.StatusCode;
import org.openecomp.sdc.common.log.wrappers.Logger;
import org.openecomp.sdc.exception.ResponseFormat;
import org.springframework.beans.factory.annotation.Autowired;
@@ -76,6 +85,7 @@ public class PolicyBusinessLogic extends BaseBusinessLogic {
private static final String FAILED_TO_VALIDATE_COMPONENT = "#{} - failed to validate the component {} before policy processing. ";
private static final String DECLARE_PROPERTIES_TO_POLICIES = "declare properties to policies";
private static final Logger log = Logger.getLogger(PolicyBusinessLogic.class);
+ private static final LoggerSupportability loggerSupportability= LoggerSupportability.getLogger(PolicyBusinessLogic.class.getName());
private PropertyDeclarationOrchestrator propertyDeclarationOrchestrator;
@@ -123,6 +133,85 @@ public class PolicyBusinessLogic extends BaseBusinessLogic {
}
}
+ public Map<String, PolicyDefinition> createPoliciesFromParsedCsar(Component component,
+ final Map<String, PolicyDefinition> incomingPolicyDefinitions) {
+ if (MapUtils.isEmpty(incomingPolicyDefinitions)) {
+ return Collections.emptyMap();
+ }
+ Map<String, PolicyDefinition> createdPolicies = new HashMap<>();
+ for (Map.Entry<String, PolicyDefinition> policyEntry : incomingPolicyDefinitions.entrySet()) {
+ PolicyDefinition incomingPolicyDefinition = policyEntry.getValue();
+ String policyName = incomingPolicyDefinition.getName();
+ log.trace("Going to create policy {}", incomingPolicyDefinition);
+ loggerSupportability.log(LoggerSupportabilityActions.CREATE_GROUP_POLICY,component.getComponentMetadataForSupportLog(),
+ StatusCode.STARTED,"Start to create policy: {} for component {}", policyName, component.getName());
+ String policyType = incomingPolicyDefinition.getType();
+ if (StringUtils.isEmpty(policyType)) {
+ log.debug("Policy type '{}' for policy '{}' not found.", policyType, policyName);
+ throw new ByActionStatusComponentException(ActionStatus.POLICY_MISSING_POLICY_TYPE, policyName);
+ }
+ // create policyDefinition
+ String policyTypeName = incomingPolicyDefinition.getPolicyTypeName();
+ PolicyDefinition createdPolicyDefinition = createPolicy(policyTypeName, component);
+ // set isFromCsar
+ createdPolicyDefinition.setToscaPresentationValue(JsonPresentationFields.IS_FROM_CSAR, true);
+ // link policy to component
+ component.addPolicy(createdPolicyDefinition);
+ // process targets
+ Map<PolicyTargetType, List<String>> policyTargets = incomingPolicyDefinition.getTargets();
+ createdPolicyDefinition = setUpdatePolicyTargets(component, createdPolicyDefinition, policyTargets);
+ // process policy properties
+ List<PropertyDataDefinition> properties = incomingPolicyDefinition.getProperties();
+ createdPolicyDefinition = setUpdatePolicyProperties(component, createdPolicyDefinition, properties);
+ createdPolicies.put(policyName, createdPolicyDefinition);
+ loggerSupportability.log(LoggerSupportabilityActions.CREATE_POLICIES,component.getComponentMetadataForSupportLog(), StatusCode.COMPLETE,"policy {} has been created ", policyName);
+ }
+ return createdPolicies;
+ }
+
+ private PolicyDefinition setUpdatePolicyProperties(Component component, PolicyDefinition policyDefinition, List<PropertyDataDefinition> properties) {
+ if (CollectionUtils.isNotEmpty(properties)) {
+ PropertyDataDefinition[] propertiesArray = properties.toArray(new PropertyDataDefinition[properties.size()]);
+ List<PropertyDataDefinition> updatedPropertiesList = setComponentValidateUpdatePolicyProperties(
+ policyDefinition.getUniqueId(),
+ propertiesArray,
+ component
+ );
+ policyDefinition.setProperties(updatedPropertiesList);
+ }
+ return policyDefinition;
+ }
+
+ private PolicyDefinition setUpdatePolicyTargets(Component component, PolicyDefinition policyDefinition,
+ Map<PolicyTargetType, List<String>> targets) {
+ if (MapUtils.isEmpty(targets)) {
+ return policyDefinition;
+ }
+ List<String> targetsToUpdate = targets.get(PolicyTargetType.COMPONENT_INSTANCES);
+ if (CollectionUtils.isEmpty(targetsToUpdate)) {
+ return policyDefinition;
+ }
+ // update targets to uniqueIds of respective component instance
+ List<String> targetsUniqueIds = new ArrayList<>();
+ for (String targetName : targetsToUpdate) {
+ Optional<ComponentInstance> componentInstance = component.getComponentInstanceByName(targetName);
+ String componentUniqueId = componentInstance
+ .orElseThrow(
+ () -> new ByActionStatusComponentException(
+ ActionStatus.COMPONENT_INSTANCE_NOT_FOUND
+ )
+ )
+ .getUniqueId();
+ targetsUniqueIds.add(componentUniqueId);
+ }
+ EnumMap<PolicyTargetType, List<String>> updatedTargets = new EnumMap<>(PolicyTargetType.class);
+ updatedTargets.put(PolicyTargetType.COMPONENT_INSTANCES, targetsUniqueIds);
+ policyDefinition.setTargets(updatedTargets);
+ policyDefinition = validateAndUpdatePolicyTargets(component, policyDefinition.getUniqueId(),
+ policyDefinition.getTargets());
+ return policyDefinition;
+ }
+
/*public Either<PolicyDefinition, ResponseFormat> createPolicy(ComponentTypeEnum componentType, String componentId, String policyTypeName, String userId, boolean shouldLock) {
Either<PolicyDefinition, ResponseFormat> result = null;
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/PolicyTypeBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/PolicyTypeBusinessLogic.java
index 6154061056..c74520f825 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/PolicyTypeBusinessLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/PolicyTypeBusinessLogic.java
@@ -22,8 +22,10 @@ package org.openecomp.sdc.be.components.impl;
import fj.data.Either;
import org.apache.commons.lang.StringUtils;
+import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException;
import org.openecomp.sdc.be.components.validation.UserValidations;
import org.openecomp.sdc.be.config.ConfigurationManager;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.dao.jsongraph.JanusGraphDao;
import org.openecomp.sdc.be.impl.ComponentsUtils;
import org.openecomp.sdc.be.model.PolicyTypeDefinition;
@@ -63,6 +65,12 @@ public class PolicyTypeBusinessLogic {
return getPolicyTypes(excludedPolicyTypes);
}
+ public PolicyTypeDefinition getLatestPolicyTypeByType(String policyTypeName) {
+ return policyTypeOperation.getLatestPolicyTypeByType(policyTypeName)
+ .left()
+ .on(e -> failOnPolicyType(e, policyTypeName));
+ }
+
public Set<String> getExcludedPolicyTypes(String internalComponentType) {
if (StringUtils.isEmpty(internalComponentType)) {
return emptySet();
@@ -80,4 +88,13 @@ public class PolicyTypeBusinessLogic {
log.debug("error when trying to fetch policy types: {}", err);
return componentsUtils.convertToResponseFormatOrNotFoundErrorToEmptyList(err);
}
+
+ private PolicyTypeDefinition failOnPolicyType(StorageOperationStatus status, String policyType) {
+ janusGraphDao.rollback();
+ if (status == StorageOperationStatus.INVALID_ID) {
+ throw new ByActionStatusComponentException(ActionStatus.POLICY_TYPE_IS_INVALID, policyType);
+ } else {
+ throw new ByActionStatusComponentException(ActionStatus.GENERAL_ERROR);
+ }
+ }
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogic.java
index cd0f8a0f61..45f2434482 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogic.java
@@ -124,6 +124,7 @@ import org.openecomp.sdc.be.model.LifecycleStateEnum;
import org.openecomp.sdc.be.model.NodeTypeInfo;
import org.openecomp.sdc.be.model.Operation;
import org.openecomp.sdc.be.model.ParsedToscaYamlInfo;
+import org.openecomp.sdc.be.model.PolicyDefinition;
import org.openecomp.sdc.be.model.PropertyDefinition;
import org.openecomp.sdc.be.model.RelationshipImpl;
import org.openecomp.sdc.be.model.RelationshipInfo;
@@ -217,6 +218,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
private final UiComponentDataConverter uiComponentDataConverter;
private final CsarBusinessLogic csarBusinessLogic;
private final PropertyBusinessLogic propertyBusinessLogic;
+ private final PolicyBusinessLogic policyBusinessLogic;
@Autowired
public ResourceBusinessLogic(IElementOperation elementDao,
@@ -238,7 +240,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
ComponentValidator componentValidator,
ComponentIconValidator componentIconValidator,
ComponentProjectCodeValidator componentProjectCodeValidator,
- ComponentDescriptionValidator componentDescriptionValidator) {
+ ComponentDescriptionValidator componentDescriptionValidator, PolicyBusinessLogic policyBusinessLogic) {
super(elementDao, groupOperation, groupInstanceOperation, groupTypeOperation, groupBusinessLogic,
interfaceOperation, interfaceLifecycleTypeOperation, artifactsBusinessLogic, artifactToscaOperation,
componentContactIdValidator, componentNameValidator, componentTagsValidator, componentValidator,
@@ -253,6 +255,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
this.uiComponentDataConverter = uiComponentDataConverter;
this.csarBusinessLogic = csarBusinessLogic;
this.propertyBusinessLogic = propertyBusinessLogic;
+ this.policyBusinessLogic = policyBusinessLogic;
}
@Autowired
@@ -270,7 +273,6 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
@Autowired
private SoftwareInformationBusinessLogic softwareInformationBusinessLogic;
-
public LifecycleBusinessLogic getLifecycleBusinessLogic() {
return lifecycleBusinessLogic;
}
@@ -1690,8 +1692,15 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
resource.getComponentMetadataForSupportLog(),
StatusCode.STARTED,"Started to add artifacts from yaml: {}",yamlName);
+ log.trace("************* Starting to add policies from yaml {}", yamlName);
+ Map<String, PolicyDefinition> policies = parsedToscaYamlInfo.getPolicies();
+ if (MapUtils.isNotEmpty(policies)) {
+ resource = createPoliciesOnResource(resource, policies);
+ }
+ log.trace("************* Finished to add policies from yaml {}", yamlName);
+
final NodeTypeInfoToUpdateArtifacts nodeTypeInfoToUpdateArtifacts =
- new NodeTypeInfoToUpdateArtifacts(nodeName, nodeTypesArtifactsToCreate);
+ new NodeTypeInfoToUpdateArtifacts(nodeName, nodeTypesArtifactsToCreate);
final Either<Resource, ResponseFormat> createArtifactsEither = createOrUpdateArtifacts(
ArtifactOperationEnum.CREATE, createdArtifacts, yamlName, csarInfo, resource,
@@ -1789,6 +1798,11 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
}
}
+ private Resource createPoliciesOnResource(Resource resource, Map<String, PolicyDefinition> policies) {
+ policyBusinessLogic.createPoliciesFromParsedCsar(resource, policies);
+ return resource;
+ }
+
private void handleGetInputs(PropertyDataDefinition property, List<InputDefinition> inputs) {
if (isNotEmpty(property.getGetInputValues())) {
if (inputs == null || inputs.isEmpty()) {
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/utils/PropertiesUtils.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/utils/PropertiesUtils.java
index 22ba03ff27..351e2a343d 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/utils/PropertiesUtils.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/utils/PropertiesUtils.java
@@ -16,6 +16,7 @@
package org.openecomp.sdc.be.components.utils;
+import com.google.common.base.CharMatcher;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.collections4.ListUtils;
@@ -188,4 +189,12 @@ public class PropertiesUtils {
ResourceTypeEnum resType = resource.getResourceType();
return resType.equals(ResourceTypeEnum.ServiceProxy);
}
+
+ /**
+ * Trim " and ' quotes
+ * @return String
+ */
+ public static String trimQuotes(String incomingString) {
+ return CharMatcher.is('\"').or(CharMatcher.is('\'')).trimFrom(incomingString);
+ }
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/GroupExportParserImpl.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/GroupExportParserImpl.java
index 981c444197..bb4d363e43 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/GroupExportParserImpl.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/GroupExportParserImpl.java
@@ -43,7 +43,6 @@ import org.openecomp.sdc.be.tosca.model.VfModuleToscaMetadata;
import org.openecomp.sdc.common.api.Constants;
import org.openecomp.sdc.common.log.wrappers.Logger;
import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Service;
import java.util.Collection;
import java.util.HashMap;
@@ -52,6 +51,7 @@ import java.util.Map;
import java.util.Optional;
import java.util.function.Predicate;
import java.util.function.Supplier;
+import org.springframework.context.event.EventListener;
import static java.util.stream.Collectors.toList;
import static java.util.stream.Collectors.toMap;
@@ -62,7 +62,7 @@ import static org.apache.commons.collections.MapUtils.isNotEmpty;
import static org.apache.commons.lang.StringUtils.isNotEmpty;
import static org.openecomp.sdc.be.model.utils.ComponentUtilities.getComponentInstanceNameByInstanceId;
-@Service
+@org.springframework.stereotype.Component
public class GroupExportParserImpl implements GroupExportParser {
private static final Logger log = Logger.getLogger(GroupExportParserImpl.class);
@@ -87,6 +87,13 @@ public class GroupExportParserImpl implements GroupExportParser {
return dataTypesEither.left().value();
}
+
+ @EventListener
+ public void onDataTypesCacheChangedEvent(
+ ApplicationDataTypeCache.DataTypesCacheChangedEvent dataTypesCacheChangedEvent) {
+ dataTypes = dataTypesCacheChangedEvent.getNewData();
+ log.debug("Data types cache updated.");
+ }
@Override
public Map<String, ToscaGroupTemplate> getGroups(Component component) {
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/PolicyExportParserImpl.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/PolicyExportParserImpl.java
index ca4d40517a..598f73f9ee 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/PolicyExportParserImpl.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/PolicyExportParserImpl.java
@@ -37,7 +37,6 @@ import org.openecomp.sdc.be.tosca.model.ToscaMetadata;
import org.openecomp.sdc.be.tosca.model.ToscaPolicyTemplate;
import org.openecomp.sdc.common.log.wrappers.Logger;
import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.HashMap;
@@ -45,13 +44,14 @@ import java.util.List;
import java.util.Map;
import java.util.function.Supplier;
import java.util.stream.Collectors;
+import org.springframework.context.event.EventListener;
import static org.apache.commons.collections.CollectionUtils.isEmpty;
import static org.apache.commons.collections.CollectionUtils.isNotEmpty;
import static org.apache.commons.collections.MapUtils.isNotEmpty;
import static org.apache.commons.lang.StringUtils.isNotEmpty;
-@Service
+@org.springframework.stereotype.Component
public class PolicyExportParserImpl implements PolicyExportParser {
private static final Logger log = Logger.getLogger(PolicyExportParserImpl.class);
@@ -76,6 +76,13 @@ public class PolicyExportParserImpl implements PolicyExportParser {
return dataTypesEither.left().value();
}
+
+ @EventListener
+ public void onDataTypesCacheChangedEvent(
+ ApplicationDataTypeCache.DataTypesCacheChangedEvent dataTypesCacheChangedEvent) {
+ dataTypes = dataTypesCacheChangedEvent.getNewData();
+ log.debug("Data types cache updated.");
+ }
@Override
public Map<String, ToscaPolicyTemplate> getPolicies(Component component) {