summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/YamlTemplateParsingHandler.java7
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/PolicyBusinessLogic.java25
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogic.java66
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/TopologyTemplateOperation.java10
4 files changed, 68 insertions, 40 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 3171277172..9734a0acdb 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
@@ -91,6 +91,7 @@ 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.janusgraph.JanusGraphDao;
@@ -367,11 +368,15 @@ public class YamlTemplateParsingHandler {
}
final UploadPropInfo uploadPropInfo = buildProperty(propertyJson.getKey(), propertyJson.getValue());
final PropertyDefinition propertyDefinition = new PropertyDefinition(originalProperty);
- propertyDefinition.setValue(gson.toJson(uploadPropInfo.getValue()));
propertyDefinition.setToscaFunction(uploadPropInfo.getToscaFunction());
propertyDefinition.setSubPropertyToscaFunctions(uploadPropInfo.getSubPropertyToscaFunctions());
propertyDefinition.setGetInputValues(uploadPropInfo.getGet_input());
propertyDefinition.setDescription(uploadPropInfo.getDescription());
+ String propertyValue = gson.toJson(uploadPropInfo.getValue());
+ if (!propertyDefinition.isToscaFunction()) {
+ propertyValue = PropertiesUtils.trimQuotes(propertyValue);
+ }
+ propertyDefinition.setValue(propertyValue);
return propertyDefinition;
})
.filter(Objects::nonNull)
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 08ac2c4c77..3d971663b1 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
@@ -147,7 +147,7 @@ public class PolicyBusinessLogic extends BaseBusinessLogic {
}
// create policyDefinition
final String policyTypeName = incomingPolicyDefinition.getPolicyTypeName();
- PolicyDefinition createdPolicyDefinition = createPolicy(policyTypeName, component);
+ PolicyDefinition createdPolicyDefinition = createPolicy(policyName, policyTypeName, component);
// set isFromCsar
createdPolicyDefinition.setToscaPresentationValue(JsonPresentationFields.IS_FROM_CSAR, true);
// link policy to component
@@ -560,15 +560,32 @@ public class PolicyBusinessLogic extends BaseBusinessLogic {
}
return policyById;
}
-
+
private PolicyDefinition createPolicy(String policyTypeName, Component component) {
PolicyTypeDefinition policyTypeDefinition = validatePolicyTypeOnCreatePolicy(policyTypeName, component);
return addPolicyToComponent(policyTypeDefinition, component);
}
-
+
+ private PolicyDefinition createPolicy(final String policyName, final String policyTypeName,
+ final Component component) {
+ PolicyTypeDefinition policyTypeDefinition = validatePolicyTypeOnCreatePolicy(policyTypeName, component);
+ return addPolicyToComponent(policyName, policyTypeDefinition, component);
+ }
+
private PolicyDefinition addPolicyToComponent(PolicyTypeDefinition policyType, Component component) {
Either<PolicyDefinition, StorageOperationStatus> associatePolicyToComponent = toscaOperationFacade
- .associatePolicyToComponent(component.getUniqueId(), new PolicyDefinition(policyType), getNextPolicyCounter(component.getPolicies()));
+ .associatePolicyToComponent(component.getUniqueId(), new PolicyDefinition(policyType), getNextPolicyCounter(component.getPolicies()));
+ if (associatePolicyToComponent.isRight()) {
+ throw new ByActionStatusComponentException(componentsUtils.convertFromStorageResponse(associatePolicyToComponent.right().value()));
+ }
+ return associatePolicyToComponent.left().value();
+ }
+
+ private PolicyDefinition addPolicyToComponent(final String policyName, final PolicyTypeDefinition policyType, final Component component) {
+ PolicyDefinition policyDefinition = new PolicyDefinition(policyType);
+ policyDefinition.setName(policyName);
+ Either<PolicyDefinition, StorageOperationStatus> associatePolicyToComponent = toscaOperationFacade
+ .associatePolicyToComponent(component.getUniqueId(), policyDefinition, getNextPolicyCounter(component.getPolicies()));
if (associatePolicyToComponent.isRight()) {
throw new ByActionStatusComponentException(componentsUtils.convertFromStorageResponse(associatePolicyToComponent.right().value()));
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogic.java
index b1d9d0a972..82add987f2 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogic.java
@@ -100,6 +100,7 @@ import org.openecomp.sdc.be.model.CapabilityRequirementRelationship;
import org.openecomp.sdc.be.model.CapabilityTypeDefinition;
import org.openecomp.sdc.be.model.Component;
import org.openecomp.sdc.be.model.ComponentInstance;
+import org.openecomp.sdc.be.model.ComponentInstanceAttribute;
import org.openecomp.sdc.be.model.ComponentInstanceInput;
import org.openecomp.sdc.be.model.ComponentInstanceProperty;
import org.openecomp.sdc.be.model.ComponentParametersView;
@@ -454,7 +455,8 @@ public class ServiceImportBusinessLogic {
return interfaceTypesToCreate;
}
- private boolean hasNewProperties(final Either<DataTypeDefinition, JanusGraphOperationStatus> result, final Map<String, Map<String, Object>> dataType) {
+ private boolean hasNewProperties(final Either<DataTypeDefinition, JanusGraphOperationStatus> result,
+ final Map<String, Map<String, Object>> dataType) {
return result.isLeft() && dataType.containsKey("properties") && result.left().value().getProperties() != null
&& result.left().value().getProperties().size() != dataType.get("properties").size();
}
@@ -509,19 +511,19 @@ public class ServiceImportBusinessLogic {
return eitherNodeTypes.left().value().entrySet().iterator().next();
}
- private Map<String, Object> getNewChangesToToscaTemplate(Map<String, Object> newMappedToscaTemplate,
+ private Map<String, Object> getNewChangesToToscaTemplate(Map<String, Object> newMappedToscaTemplate,
Map<String, Object> existingMappedToscaTemplate) {
Map<String, Object> combinedMappedToscaTemplate = new HashMap<>(existingMappedToscaTemplate);
combinePropertiesIntoToscaTemplate((Map<String, Object>) newMappedToscaTemplate.get("properties"),
- (Map<String, Object>) existingMappedToscaTemplate.get("properties"), combinedMappedToscaTemplate);
+ (Map<String, Object>) existingMappedToscaTemplate.get("properties"), combinedMappedToscaTemplate);
combineAttributesIntoToscaTemplate((Map<String, Object>) newMappedToscaTemplate.get("attributes"),
- (Map<String, Object>) existingMappedToscaTemplate.get("attributes"), combinedMappedToscaTemplate);
+ (Map<String, Object>) existingMappedToscaTemplate.get("attributes"), combinedMappedToscaTemplate);
combineRequirementsIntoToscaTemplate((List<Map<String, Object>>) newMappedToscaTemplate.get("requirements"),
- (List<Map<String, Object>>) existingMappedToscaTemplate.get("requirements"), combinedMappedToscaTemplate);
+ (List<Map<String, Object>>) existingMappedToscaTemplate.get("requirements"), combinedMappedToscaTemplate);
combineCapabilitiesIntoToscaTemplate((Map<String, Object>) newMappedToscaTemplate.get("capabilities"),
- (Map<String, Object>) existingMappedToscaTemplate.get("capabilities"), combinedMappedToscaTemplate);
+ (Map<String, Object>) existingMappedToscaTemplate.get("capabilities"), combinedMappedToscaTemplate);
combineInterfacesIntoToscaTemplate((Map<String, Map<String, Object>>) newMappedToscaTemplate.get("interfaces"),
- (Map<String, Map<String, Object>>) existingMappedToscaTemplate.get("interfaces"), combinedMappedToscaTemplate);
+ (Map<String, Map<String, Object>>) existingMappedToscaTemplate.get("interfaces"), combinedMappedToscaTemplate);
return combinedMappedToscaTemplate;
}
@@ -530,7 +532,7 @@ public class ServiceImportBusinessLogic {
Map<String, Object> combinedMappedToscaTemplate) {
Map<String, Map<String, Object>> combinedInterfaces = combineAdditionalInterfaces(existingInterfaces, newInterfaces);
if ((MapUtils.isEmpty(existingInterfaces) && MapUtils.isNotEmpty(combinedInterfaces))
- || (MapUtils.isNotEmpty(existingInterfaces) && !existingInterfaces.equals(combinedInterfaces))) {
+ || (MapUtils.isNotEmpty(existingInterfaces) && !existingInterfaces.equals(combinedInterfaces))) {
combinedMappedToscaTemplate.put("interfaces", combinedInterfaces);
}
}
@@ -539,7 +541,7 @@ public class ServiceImportBusinessLogic {
Map<String, Object> combinedMappedToscaTemplate) {
Map<String, Object> combinedCapabilities = combineEntries(newCapabilities, existingCapabilities);
if ((MapUtils.isEmpty(existingCapabilities) && MapUtils.isNotEmpty(combinedCapabilities)) ||
- ( MapUtils.isNotEmpty(existingCapabilities) && !combinedCapabilities.equals(existingCapabilities))) {
+ (MapUtils.isNotEmpty(existingCapabilities) && !combinedCapabilities.equals(existingCapabilities))) {
combinedMappedToscaTemplate.put("capabilities", combinedCapabilities);
}
}
@@ -548,7 +550,7 @@ public class ServiceImportBusinessLogic {
Map<String, Object> combinedMappedToscaTemplate) {
List<Map<String, Object>> combinedRequirements = combineAdditionalRequirements(newRequirements, existingRequirements);
if ((CollectionUtils.isEmpty(existingRequirements) && CollectionUtils.isNotEmpty(combinedRequirements))
- || (CollectionUtils.isNotEmpty(existingRequirements) && !combinedRequirements.equals(existingRequirements))) {
+ || (CollectionUtils.isNotEmpty(existingRequirements) && !combinedRequirements.equals(existingRequirements))) {
combinedMappedToscaTemplate.put("requirements", combinedRequirements);
}
}
@@ -557,7 +559,7 @@ public class ServiceImportBusinessLogic {
Map<String, Object> combinedMappedToscaTemplate) {
Map<String, Object> combinedAttributes = combineEntries(newAttributes, existingAttributes);
if ((MapUtils.isEmpty(existingAttributes) && MapUtils.isNotEmpty(combinedAttributes)) ||
- ( MapUtils.isNotEmpty(existingAttributes) && !combinedAttributes.equals(existingAttributes))) {
+ (MapUtils.isNotEmpty(existingAttributes) && !combinedAttributes.equals(existingAttributes))) {
combinedMappedToscaTemplate.put("attributes", combinedAttributes);
}
}
@@ -566,7 +568,7 @@ public class ServiceImportBusinessLogic {
Map<String, Object> combinedMappedToscaTemplate) {
Map<String, Object> combinedProperties = combineEntries(newProperties, existingProperties);
if ((MapUtils.isEmpty(existingProperties) && MapUtils.isNotEmpty(combinedProperties)) ||
- (MapUtils.isNotEmpty(existingProperties) && !combinedProperties.equals(existingProperties))) {
+ (MapUtils.isNotEmpty(existingProperties) && !combinedProperties.equals(existingProperties))) {
combinedMappedToscaTemplate.put("properties", combinedProperties);
}
}
@@ -580,20 +582,21 @@ public class ServiceImportBusinessLogic {
if (MapUtils.isEmpty(existingInterfaces)) {
return combinedEntries;
}
- existingInterfaces.entrySet().forEach(interfaceDef -> {
- combinedEntries.entrySet().stream().filter((interFace) -> interFace.getValue().get("type").equals(( interfaceDef.getValue()).get("type")))
- .findFirst().ifPresentOrElse((interFace) -> {
- interFace.getValue().putAll(interfaceDef.getValue());
- }, () -> {
- combinedEntries.put(interfaceDef.getKey(), interfaceDef.getValue());
- });
+ existingInterfaces.entrySet().forEach(interfaceDef -> {
+ combinedEntries.entrySet().stream().filter((interFace) -> interFace.getValue().get("type").equals((interfaceDef.getValue()).get("type")))
+ .findFirst().ifPresentOrElse((interFace) -> {
+ interFace.getValue().putAll(interfaceDef.getValue());
+ }, () -> {
+ combinedEntries.put(interfaceDef.getKey(), interfaceDef.getValue());
+ });
});
return combinedEntries;
}
- private List<Map<String, Object>> combineAdditionalRequirements(List<Map<String, Object>> newReqs, List<Map<String, Object>> existingResourceReqs) {
- if (CollectionUtils.isEmpty(newReqs)) {
- newReqs = new ArrayList<>();
+ private List<Map<String, Object>> combineAdditionalRequirements(List<Map<String, Object>> newReqs,
+ List<Map<String, Object>> existingResourceReqs) {
+ if (CollectionUtils.isEmpty(existingResourceReqs)) {
+ existingResourceReqs = new ArrayList<>();
}
Set<Map<String, Object>> combinedReqs = new TreeSet<>((map1, map2) ->
map1.keySet().equals(map2.keySet()) ? 0 : map1.keySet().iterator().next().compareTo(map2.keySet().iterator().next()));
@@ -1419,21 +1422,20 @@ public class ServiceImportBusinessLogic {
if (MapUtils.isEmpty(policies)) {
return Either.left(service);
}
- final Map<String, List<AttributeDefinition>> instanceAttributeMap =
- service.getComponentInstancesAttributes()
+ Map<String, List<ComponentInstanceAttribute>> componentInstancesAttributes = service.getComponentInstancesAttributes();
+ final Map<String, List<AttributeDefinition>> instanceAttributeMap = new HashMap<>();
+ if (MapUtils.isNotEmpty(componentInstancesAttributes)) {
+ instanceAttributeMap.putAll(componentInstancesAttributes
.entrySet().stream()
- .collect(
- toMap(Entry::getKey,
- entry -> entry.getValue().stream().map(AttributeDefinition.class::cast).collect(toList()))
- );
+ .collect(toMap(Entry::getKey, entry -> entry.getValue().stream().map(AttributeDefinition.class::cast).collect(toList()))));
+ }
policies.values().stream()
.map(PolicyDataDefinition::getProperties)
.flatMap(Collection::stream)
.filter(PropertyDataDefinition::isToscaFunction)
- .forEach(policyDefinition ->
- toscaFunctionService
- .updateFunctionWithDataFromSelfComponent(policyDefinition.getToscaFunction(), service, service.getComponentInstancesProperties(),
- instanceAttributeMap)
+ .forEach(policyDefinition -> toscaFunctionService
+ .updateFunctionWithDataFromSelfComponent(policyDefinition.getToscaFunction(), service, service.getComponentInstancesProperties(),
+ instanceAttributeMap)
);
policyBusinessLogic.createPolicies(service, policies);
return getServiceResponseFormatEither(service);
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/TopologyTemplateOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/TopologyTemplateOperation.java
index c450457855..790499c0da 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/TopologyTemplateOperation.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/TopologyTemplateOperation.java
@@ -31,6 +31,7 @@ import java.util.Map.Entry;
import java.util.Optional;
import java.util.stream.Collectors;
import org.apache.commons.collections.MapUtils;
+import org.apache.commons.lang3.StringUtils;
import org.apache.tinkerpop.gremlin.structure.Direction;
import org.apache.tinkerpop.gremlin.structure.Edge;
import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus;
@@ -1585,9 +1586,12 @@ public class TopologyTemplateOperation extends ToscaElementOperation {
}
private void fillPolicyDefinition(GraphVertex componentV, PolicyDefinition policyDefinition, int counter) {
- String policyName = buildSubComponentName((String) componentV.getJsonMetadataField(JsonPresentationFields.NAME),
- policyDefinition.getPolicyTypeName(), counter);
- policyDefinition.setName(policyName);
+ String policyName = policyDefinition.getName();
+ if (StringUtils.isBlank(policyName)) {
+ policyName = buildSubComponentName((String) componentV.getJsonMetadataField(JsonPresentationFields.NAME),
+ policyDefinition.getPolicyTypeName(), counter);
+ policyDefinition.setName(policyName);
+ }
policyDefinition.setInvariantName(policyName);
policyDefinition.setComponentName((String) componentV.getJsonMetadataField(JsonPresentationFields.NAME));
policyDefinition.setUniqueId(UniqueIdBuilder.buildPolicyUniqueId(componentV.getUniqueId(), policyName));