summaryrefslogtreecommitdiffstats
path: root/catalog-be/src/main/java/org
diff options
context:
space:
mode:
authorshrek2000 <orenkle@amdocs.com>2019-02-07 12:57:08 +0200
committershrek2000 <orenkle@amdocs.com>2019-02-07 16:21:31 +0200
commit1dd5db924b88f390f3301a0e3f229c0a81a91080 (patch)
treeac56d507ba986934477d0cabd4c98ed9d74c231d /catalog-be/src/main/java/org
parentb551a05893bcf6ac1ff3679d3354ba106fef24bb (diff)
Add dependent child service to service
Add dependent child service to service Issue-ID: SDC-1987 Change-Id: I5a650f57a27587c4ce6f33059719060ffa1f13de Signed-off-by: shrek2000 <orenkle@amdocs.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.java20
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogic.java139
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/NodeFilterUploadCreator.java117
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogic.java12
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/utils/DirectivesUtils.java62
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/utils/MapUtils.java84
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/utils/ProxyServicePropertiesUtils.java54
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/utils/UiComponentDataConverter.java8
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/impl/ServiceFilterUtils.java177
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ComponentInstanceServlet.java31
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java104
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaNodeTemplate.java40
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/utils/NodeFilterConverter.java6
13 files changed, 840 insertions, 14 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 9bc2d01c6d..48152ea166 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
@@ -10,6 +10,7 @@ import org.apache.commons.lang.StringUtils;
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.exceptions.ComponentException;
import org.openecomp.sdc.be.config.BeEcompErrorManager;
import org.openecomp.sdc.be.dao.api.ActionStatus;
@@ -19,6 +20,7 @@ import org.openecomp.sdc.be.datatypes.elements.GetInputValueDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
import org.openecomp.sdc.be.model.*;
import org.openecomp.sdc.be.model.tosca.ToscaPropertyType;
+import org.openecomp.sdc.be.utils.TypeUtils;
import org.openecomp.sdc.common.log.wrappers.Logger;
import org.springframework.stereotype.Component;
import org.yaml.snakeyaml.parser.ParserException;
@@ -449,6 +451,8 @@ public class YamlTemplateParsingHandler {
setRequirements(nodeTemplateInfo, nodeTemplateJsonMap);
setCapabilities(nodeTemplateInfo, nodeTemplateJsonMap);
updateProperties(nodeTemplateInfo, nodeTemplateJsonMap);
+ setDirectives(nodeTemplateInfo, nodeTemplateJsonMap);
+ setNodeFilter(nodeTemplateInfo, nodeTemplateJsonMap);
setSubstitutions(substitutionMappings, nodeTemplateInfo);
} else {
rollbackWithException(ActionStatus.NOT_TOPOLOGY_TOSCA_TEMPLATE);
@@ -514,6 +518,22 @@ public class YamlTemplateParsingHandler {
}
}
+ private void setDirectives(UploadComponentInstanceInfo nodeTemplateInfo,
+ Map<String, Object> nodeTemplateJsonMap) {
+ List<String> directives =
+ (List<String>) nodeTemplateJsonMap.get(TypeUtils.ToscaTagNamesEnum.DIRECTIVES.getElementName());
+ nodeTemplateInfo.setDirectives(directives);
+ }
+
+ private void setNodeFilter(UploadComponentInstanceInfo nodeTemplateInfo,
+ Map<String, Object> nodeTemplateJsonMap) {
+ if (nodeTemplateJsonMap.containsKey(TypeUtils.ToscaTagNamesEnum.NODE_FILTER.getElementName())) {
+ nodeTemplateInfo.setUploadNodeFilterInfo(
+ new NodeFilterUploadCreator().createNodeFilterData(nodeTemplateJsonMap.get(
+ TypeUtils.ToscaTagNamesEnum.NODE_FILTER.getElementName())));
+ }
+ }
+
@SuppressWarnings("unchecked")
private Map<String, List<UploadReqInfo>> createReqModuleFromYaml(Map<String, Object> nodeTemplateJsonMap) {
Map<String, List<UploadReqInfo>> moduleRequirements = new HashMap<>();
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogic.java
index 8c7c47391d..dd8cec347c 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogic.java
@@ -27,8 +27,10 @@ import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.openecomp.sdc.be.components.impl.instance.ComponentInstanceChangeOperationOrchestrator;
+import org.openecomp.sdc.be.components.impl.utils.DirectivesUtils;
import org.openecomp.sdc.be.components.merge.instance.ComponentInstanceMergeDataBusinessLogic;
import org.openecomp.sdc.be.components.merge.instance.DataForMergeHolder;
+import org.openecomp.sdc.be.components.utils.ProxyServicePropertiesUtils;
import org.openecomp.sdc.be.components.validation.ComponentValidations;
import org.openecomp.sdc.be.config.BeEcompErrorManager;
import org.openecomp.sdc.be.config.BeEcompErrorManager.ErrorSeverity;
@@ -36,6 +38,7 @@ import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.dao.jsongraph.types.JsonParseFlagEnum;
import org.openecomp.sdc.be.dao.neo4j.GraphPropertiesDictionary;
import org.openecomp.sdc.be.dao.titan.TitanOperationStatus;
+import org.openecomp.sdc.be.datatypes.elements.CINodeFilterDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.ForwardingPathDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.GetInputValueDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.GroupDataDefinition;
@@ -47,10 +50,12 @@ import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.OriginTypeEnum;
import org.openecomp.sdc.be.impl.ForwardingPathUtils;
+import org.openecomp.sdc.be.impl.ServiceFilterUtils;
import org.openecomp.sdc.be.info.CreateAndAssotiateInfo;
import org.openecomp.sdc.be.model.Component;
import org.openecomp.sdc.be.model.ComponentParametersView;
import org.openecomp.sdc.be.model.CapabilityDefinition;
+import org.openecomp.sdc.be.model.InterfaceDefinition;
import org.openecomp.sdc.be.model.RequirementDefinition;
import org.openecomp.sdc.be.model.Resource;
import org.openecomp.sdc.be.model.Service;
@@ -69,6 +74,7 @@ import org.openecomp.sdc.be.model.ComponentInstanceInput;
import org.openecomp.sdc.be.model.ComponentInstanceProperty;
import org.openecomp.sdc.be.model.PropertyDefinition.PropertyNames;
import org.openecomp.sdc.be.model.jsontitan.operations.ForwardingPathOperation;
+import org.openecomp.sdc.be.model.jsontitan.operations.NodeFilterOperation;
import org.openecomp.sdc.be.model.jsontitan.operations.ToscaOperationFacade;
import org.openecomp.sdc.be.model.jsontitan.utils.ModelConverter;
import org.openecomp.sdc.be.model.operations.api.IComponentInstanceOperation;
@@ -136,6 +142,9 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic {
@Autowired
private ForwardingPathOperation forwardingPathOperation;
+ @Autowired
+ private NodeFilterOperation serviceFilterOperation;
+
public ComponentInstanceBusinessLogic() {
}
@@ -301,7 +310,11 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic {
filter.setIgnoreCapabiltyProperties(false);
filter.setIgnoreComponentInstances(false);
filter.setIgnoreRequirements(false);
- Either<Component, StorageOperationStatus> serviceRes = toscaOperationFacade.getToscaElement(resourceInstance.getComponentUid(), filter);
+ filter.setIgnoreInterfaces(false);
+ filter.setIgnoreProperties(false);
+ filter.setIgnoreInputs(false);
+ Either<Component, StorageOperationStatus> serviceRes =
+ toscaOperationFacade.getToscaElement(resourceInstance.getComponentUid(), filter);
if (serviceRes.isRight()) {
return serviceRes.right().value();
}
@@ -311,6 +324,14 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic {
Map<String, List<RequirementDefinition>> req = service.getRequirements();
resourceInstance.setRequirements(req);
+ Map<String, InterfaceDefinition> serviceInterfaces = service.getInterfaces();
+ if(MapUtils.isNotEmpty(serviceInterfaces)) {
+ serviceInterfaces.forEach(resourceInstance::addInterface);
+ }
+
+
+ resourceInstance.setProperties(ProxyServicePropertiesUtils.getProperties(service));
+
String name = service.getNormalizedName() + ToscaOperationFacade.PROXY_SUFFIX;
String toscaResourceName = ((Resource) proxyTemplate).getToscaResourceName();
int lastIndexOf = toscaResourceName.lastIndexOf('.');
@@ -718,7 +739,6 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic {
resultOp = Either.right(componentsUtils.getResponseFormat(ActionStatus.COMPONENT_NAME_ALREADY_EXIST, containerComponentType.getValue(), origInst.getName()));
return resultOp;
}
-
listForUpdate.add(updatedCi);
} else
listForUpdate.add(origInst);
@@ -789,8 +809,22 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic {
CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Failed to update the name of the component instance {} to {}. A component instance with the same name already exists. ", oldComponentInstance.getName(), newInstanceName);
resultOp = Either.right(componentsUtils.getResponseFormat(ActionStatus.COMPONENT_NAME_ALREADY_EXIST, containerComponentType.getValue(), componentInstance.getName()));
}
+ if(!DirectivesUtils.isValid(componentInstance.getDirectives())) {
+ final String directivesStr =
+ componentInstance.getDirectives().stream().collect(Collectors.joining(" , ", " [ ", " ] "));
+ CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG,
+ "Failed to update the directives of the component instance {} to {}. Directives data {} is invalid. ",
+ oldComponentInstance.getName(), newInstanceName ,
+ directivesStr);
+ resultOp = Either.right(componentsUtils.getResponseFormat(ActionStatus.DIRECTIVES_INVALID_VALUE,
+ directivesStr));
+ }
}
+ String newInstanceName = componentInstance.getName();
+ String oldInstanceName = null;
if (resultOp == null) {
+ oldComponentInstance = componentInstanceOptional.get();
+ newInstanceName = componentInstance.getName();
updateRes = toscaOperationFacade.updateComponentInstanceMetadataOfTopologyTemplate(containerComponent, origComponent, updateComponentInstanceMetadata(oldComponentInstance, componentInstance));
if (updateRes.isRight()) {
CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Failed to update metadata of component instance {} belonging to container component {}. Status is {}. ", componentInstance.getName(), containerComponent.getName(),
@@ -802,6 +836,14 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic {
Either result = toscaOperationFacade.cleanAndAddGroupInstancesToComponentInstance(containerComponent, oldComponentInstance, componentInstanceId);
if (result.isRight())
CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Failed to rename group instances for container {}. error {} ", componentInstanceId, result.right().value());
+ if (containerComponent instanceof Service) {
+ Either<ComponentInstance, ResponseFormat> renameEither =
+ renameServiceFilter((Service) containerComponent, newInstanceName,
+ oldInstanceName);
+ if (renameEither.isRight()) {
+ return renameEither;
+ }
+ }
}
// endregion
}
@@ -824,6 +866,27 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic {
return resultOp;
}
+
+ public Either<ComponentInstance, ResponseFormat> renameServiceFilter(Service containerComponent,
+ String newInstanceName, String oldInstanceName) {
+
+ Map<String, CINodeFilterDataDefinition> renamedNodesFilter =
+ ServiceFilterUtils.getRenamedNodesFilter((Service) containerComponent,
+ oldInstanceName, newInstanceName);
+ for( Entry<String, CINodeFilterDataDefinition> entry : renamedNodesFilter.entrySet()){
+ Either<CINodeFilterDataDefinition, StorageOperationStatus>
+ renameEither = serviceFilterOperation.updateNodeFilter(
+ containerComponent.getUniqueId(),entry.getKey(),entry.getValue());
+ if (renameEither.isRight()){
+ return Either.right(componentsUtils.getResponseFormatForResourceInstance(
+ componentsUtils.convertFromStorageResponse(renameEither.right().value(), ComponentTypeEnum.SERVICE),
+ containerComponent.getName(), null));
+ }
+
+ }
+ return Either.left(null);
+ }
+
/**
* @param oldPrefix-
* The normalized old vf name
@@ -847,6 +910,7 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic {
oldComponentInstance.setName(newComponentInstance.getName());
oldComponentInstance.setModificationTime(System.currentTimeMillis());
oldComponentInstance.setCustomizationUUID(UUID.randomUUID().toString());
+ oldComponentInstance.setDirectives(newComponentInstance.getDirectives());
if (oldComponentInstance.getGroupInstances() != null)
oldComponentInstance.getGroupInstances().forEach(group -> group.setName(getNewGroupName(oldComponentInstance.getNormalizedName(), ValidationUtils.normalizeComponentInstanceName(newComponentInstance.getName()), group.getName())));
return oldComponentInstance;
@@ -879,6 +943,23 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic {
Either<ComponentInstance, ResponseFormat> resultOp = null;
try {
+ if (containerComponent instanceof Service) {
+ ComponentInstance componentInstance = containerComponent.getComponentInstanceById(componentInstanceId).get();
+ Either<String, StorageOperationStatus> deleteServiceFilterEither =
+ serviceFilterOperation.deleteNodeFilter((Service) containerComponent, componentInstanceId);
+ if (deleteServiceFilterEither.isRight()) {
+ ActionStatus status = componentsUtils.convertFromStorageResponse(deleteServiceFilterEither.right().value(),
+ containerComponentType);
+ titanDao.rollback();
+ return Either.right(componentsUtils.getResponseFormat(status, componentInstanceId));
+ }
+ resultOp = deleteServiceFiltersRelatedTobeDeletedComponentInstance((Service) containerComponent,
+ componentInstance, ComponentTypeEnum.SERVICE, userId);
+ if (resultOp.isRight()) {
+ titanDao.rollback();
+ return resultOp;
+ }
+ }
resultOp = deleteComponentInstance(containerComponent, componentInstanceId, containerComponentType);
if (resultOp.isRight()){
return resultOp;
@@ -895,6 +976,60 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic {
}
}
+ public Either<ComponentInstance, ResponseFormat> deleteServiceFiltersRelatedTobeDeletedComponentInstance(
+ Service service, ComponentInstance componentInstance, ComponentTypeEnum containerComponentType, String userId) {
+ if (containerComponentType.equals(ComponentTypeEnum.SERVICE)) {
+ Set<String> serviceFiltersIDsToBeDeleted =
+ getServiceFiltersRelatedToComponentInstance(service.getUniqueId(), componentInstance);
+ if (!serviceFiltersIDsToBeDeleted.isEmpty()) {
+ Set<String> ids = service.getComponentInstances().stream()
+ .filter(ci -> serviceFiltersIDsToBeDeleted
+ .contains(ci.getName()))
+ .map(ComponentInstance::getUniqueId)
+ .collect(Collectors.toSet());
+ Either<Set<String>, StorageOperationStatus> deleteServiceFiltersEither =
+ serviceFilterOperation.deleteNodeFilters(service, ids);
+ if (deleteServiceFiltersEither.isRight()) {
+ ActionStatus status = componentsUtils.convertFromStorageResponse(deleteServiceFiltersEither.right().value(),
+ containerComponentType);
+ return Either.right(componentsUtils.getResponseFormat(status, componentInstance.getName()));
+ }
+ for (String id : ids) {
+ final Optional<ComponentInstance> componentInstanceById = service.getComponentInstanceById(id);
+ if (!componentInstanceById.isPresent()){
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));
+ }
+ ComponentInstance ci = componentInstanceById.get();
+ List<String> directives = ci.getDirectives();
+ directives.remove(DirectivesUtils.SELECTABLE);
+ ci.setDirectives(directives);
+ final Either<ComponentInstance, ResponseFormat> componentInstanceResponseFormatEither =
+ updateComponentInstanceMetadata(ComponentTypeEnum.SERVICE_PARAM_NAME, service.getUniqueId(),
+ ci.getUniqueId(), userId, ci, true, false, false);
+ if (componentInstanceResponseFormatEither.isRight()) {
+ return componentInstanceResponseFormatEither;
+ }
+ }
+ }
+ }
+ return Either.left(componentInstance);
+ }
+
+
+
+ private Set<String> getServiceFiltersRelatedToComponentInstance(String containerComponentId,
+ ComponentInstance componentInstance) {
+ ComponentParametersView filter = new ComponentParametersView(true);
+ filter.setIgnoreComponentInstances(false);
+ Either<Service, StorageOperationStatus> serviceFilterOrigin =
+ toscaOperationFacade.getToscaElement(containerComponentId, filter);
+ final Service service = serviceFilterOrigin.left().value();
+ final Set<String> nodesFiltersToBeDeleted = ServiceFilterUtils.getNodesFiltersToBeDeleted(service,
+ componentInstance);
+ return nodesFiltersToBeDeleted;
+ }
+
+
public Either<ComponentInstance, ResponseFormat> deleteForwardingPathsRelatedTobeDeletedComponentInstance(String containerComponentId, ComponentTypeEnum containerComponentType,
Either<ComponentInstance, ResponseFormat> resultOp) {
if(containerComponentType.equals(ComponentTypeEnum.SERVICE) && resultOp.isLeft() ){
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/NodeFilterUploadCreator.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/NodeFilterUploadCreator.java
new file mode 100644
index 0000000000..444ac0b0cf
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/NodeFilterUploadCreator.java
@@ -0,0 +1,117 @@
+/*
+ * Copyright © 2016-2018 European Support Limited
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.openecomp.sdc.be.components.impl;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+import org.onap.sdc.tosca.services.YamlUtil;
+import org.openecomp.sdc.be.model.UploadNodeFilterCapabilitiesInfo;
+import org.openecomp.sdc.be.model.UploadNodeFilterInfo;
+import org.openecomp.sdc.be.model.UploadNodeFilterPropertyInfo;
+import org.openecomp.sdc.be.utils.TypeUtils;
+
+public class NodeFilterUploadCreator {
+
+
+ public UploadNodeFilterInfo createNodeFilterData(Object obj) {
+ if (!(obj instanceof Map)) {
+ return null;
+ }
+ Map<String, Object> nodeFilterMap = (Map<String, Object>) obj;
+
+ UploadNodeFilterInfo uploadNodeFilterInfo = new UploadNodeFilterInfo();
+ final String propertiesElementName = TypeUtils.ToscaTagNamesEnum.PROPERTIES.getElementName();
+ if (nodeFilterMap.containsKey(propertiesElementName)) {
+ uploadNodeFilterInfo.setProperties(createNodeFilterProperties(nodeFilterMap.get(propertiesElementName)));
+ }
+ final String capabilitiesElementName = TypeUtils.ToscaTagNamesEnum.CAPABILITIES.getElementName();
+ if (nodeFilterMap.containsKey(capabilitiesElementName)) {
+ uploadNodeFilterInfo
+ .setCapabilities(createNodeFilterCapabilities(nodeFilterMap.get(capabilitiesElementName)));
+ }
+ final String toscaId = TypeUtils.ToscaTagNamesEnum.TOSCA_ID.getElementName();
+ if (nodeFilterMap.containsKey(toscaId)) {
+ uploadNodeFilterInfo.setTosca_id(nodeFilterMap.get(toscaId));
+ }
+ return uploadNodeFilterInfo;
+ }
+
+ private List<UploadNodeFilterPropertyInfo> createNodeFilterProperties(Object o) {
+ if (!(o instanceof List)) {
+ return null;
+ }
+ List<UploadNodeFilterPropertyInfo> retVal = new ArrayList<>();
+ List<Map<String, Object>> propertiesList = (List<Map<String, Object>>) o;
+ for (Map<String, Object> map : propertiesList) {
+ final Map.Entry<String, Object> entry = map.entrySet().iterator().next();
+ final Object value = entry.getValue();
+ if (value instanceof Map) {
+ List<String> valueList = new ArrayList<>();
+ valueList.add(valueToProperty(entry.getValue()));
+ retVal.add(new UploadNodeFilterPropertyInfo(entry.getKey(), valueList));
+ } else if (value instanceof List) {
+ List<String> propertiesVals =
+ (List<String>) ((List) value).stream().map(this::valueToProperty).collect(Collectors.toList());
+ retVal.add(new UploadNodeFilterPropertyInfo(entry.getKey(), propertiesVals));
+ }
+ }
+ return retVal;
+ }
+
+ private String valueToProperty(Object o) {
+
+ if (o instanceof Map) {
+ return new YamlUtil().objectToYaml(o);
+ }
+ return null;
+ }
+
+ private Map<String, UploadNodeFilterCapabilitiesInfo> createNodeFilterCapabilities(Object o) {
+ if (!(o instanceof List)) {
+ return null;
+ }
+ Map<String, UploadNodeFilterCapabilitiesInfo> retVal = new HashMap<>();
+ List<Map<String, Object>> capabilitiesMap = (List<Map<String, Object>>) o;
+ for (Map<String, Object> map : capabilitiesMap) {
+ final Map.Entry<String, Object> entry = map.entrySet().iterator().next();
+ UploadNodeFilterCapabilitiesInfo uploadNodeFilterCapabilitiesInfo = new UploadNodeFilterCapabilitiesInfo();
+ uploadNodeFilterCapabilitiesInfo.setName(entry.getKey());
+ uploadNodeFilterCapabilitiesInfo.setProperties(createCapabilitiesProperties(entry.getValue()));
+ retVal.put(entry.getKey(), uploadNodeFilterCapabilitiesInfo);
+ }
+ return retVal;
+
+ }
+
+ private List<UploadNodeFilterPropertyInfo> createCapabilitiesProperties(Object o) {
+ if (!(o instanceof Map)) {
+ return null;
+ }
+ Map<String, Object> capabilitiesPropertiesMap = (Map<String, Object>) o;
+ final String capabilitiesPropertiesElementName = TypeUtils.ToscaTagNamesEnum.PROPERTIES.getElementName();
+ if (capabilitiesPropertiesMap.containsKey(capabilitiesPropertiesElementName)) {
+ final Object propertiesObject = capabilitiesPropertiesMap.get(capabilitiesPropertiesElementName);
+ return createNodeFilterProperties(propertiesObject);
+ }
+ return null;
+ }
+
+
+}
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 4e842928ef..d23fcfaa34 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
@@ -34,6 +34,7 @@ import org.openecomp.sdc.be.components.impl.ArtifactsBusinessLogic.ArtifactOpera
import org.openecomp.sdc.be.components.impl.ArtifactsBusinessLogic.ArtifactOperationInfo;
import org.openecomp.sdc.be.components.impl.ImportUtils.ResultStatusEnum;
import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
+import org.openecomp.sdc.be.components.impl.utils.CINodeFilterUtils;
import org.openecomp.sdc.be.components.lifecycle.LifecycleBusinessLogic;
import org.openecomp.sdc.be.components.lifecycle.LifecycleChangeInfoWithAction;
import org.openecomp.sdc.be.components.lifecycle.LifecycleChangeInfoWithAction.LifecycleChanceActionEnum;
@@ -3026,6 +3027,17 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
ComponentInstance componentInstance = new ComponentInstance();
componentInstance.setComponentUid(refResource.getUniqueId());
+
+ Collection<String> directives = uploadComponentInstanceInfo.getDirectives();
+ if(directives != null && !directives.isEmpty()) {
+ componentInstance.setDirectives(new ArrayList<>(directives));
+ }
+ UploadNodeFilterInfo uploadNodeFilterInfo = uploadComponentInstanceInfo.getUploadNodeFilterInfo();
+ if (uploadNodeFilterInfo != null){
+ componentInstance.setNodeFilter(new CINodeFilterUtils().getNodeFilterDataDefinition(uploadNodeFilterInfo,
+ componentInstance.getUniqueId()));
+ }
+
ComponentTypeEnum containerComponentType = resource.getComponentType();
NodeTypeEnum containerNodeType = containerComponentType.getNodeType();
if (containerNodeType.equals(NodeTypeEnum.Resource)
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/utils/DirectivesUtils.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/utils/DirectivesUtils.java
new file mode 100644
index 0000000000..b19f0592c1
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/utils/DirectivesUtils.java
@@ -0,0 +1,62 @@
+/*
+ * Copyright © 2016-2018 European Support Limited
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.openecomp.sdc.be.components.impl.utils;
+
+import com.google.common.collect.Sets;
+import java.util.List;
+import java.util.Optional;
+import org.apache.commons.collections.CollectionUtils;
+import org.apache.commons.lang.StringUtils;
+
+public class DirectivesUtils {
+
+ public static final String SUBSTITUTABLE = "substitutable";
+ public static final String SELECTABLE = "selectable";
+ public enum DIRECTIVE {
+
+ SUBSTITUTABLE(DirectivesUtils.SUBSTITUTABLE), SELECTABLE(DirectivesUtils.SELECTABLE);
+
+ private final String value;
+
+ DIRECTIVE(String value) {
+ this.value = value;
+ }
+
+ @Override
+ public String toString() {
+ return value;
+ }
+
+ }
+
+ public static Optional<DIRECTIVE> getDirective(String inDirective) {
+ if (StringUtils.isEmpty(inDirective)) {
+ return Optional.empty();
+ }
+
+ return Sets.newHashSet(DIRECTIVE.values()).stream()
+ .filter(directive -> directive.toString().equals(inDirective)).findAny();
+ }
+
+ public static boolean isValid(List<String> inDirectives){
+ if (CollectionUtils.isEmpty(inDirectives)){
+ return true;
+ }
+ return inDirectives.stream().allMatch(directive -> getDirective(directive).isPresent());
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/utils/MapUtils.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/utils/MapUtils.java
new file mode 100644
index 0000000000..30b905789c
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/utils/MapUtils.java
@@ -0,0 +1,84 @@
+package org.openecomp.sdc.be.components.utils;
+
+import java.util.List;
+import java.util.Map;
+
+public class MapUtils {
+ public static boolean compareMaps(Map<String, Object> source, Map<String, Object> target) {
+ if (source == null && target == null) {
+ return true;
+ }
+ if ((source == null && target != null) || source != null && target == null
+ || source.keySet().size() != target.keySet().size()) {
+ return false;
+ }
+
+ for (Map.Entry<String, Object> entry : source.entrySet()) {
+ Object sourceObj = entry.getValue();
+ Object targetObj = target.get(entry.getKey());
+ if ((sourceObj == null && targetObj != null) || (sourceObj != null && targetObj == null)) {
+ return false;
+ }
+ if (!handleSourceAndTargetObjects(sourceObj, targetObj)) {
+ return false;
+ }
+ }
+ return true;
+
+ }
+
+ public static boolean compareLists(List<Object> source, List<Object> target) {
+ if (source == null && target == null) {
+ return true;
+ }
+ if ((source == null && target != null) || source != null && target == null ||
+ source.size() != target.size()) {
+ return false;
+ }
+ for (int i = 0; i < source.size(); i++) {
+ Object sourceObj = source.get(i);
+ Object targetObj = target.get(i);
+ if ((sourceObj == null && targetObj != null) || sourceObj != null && targetObj == null) {
+ return false;
+ }
+ if (!handleSourceAndTargetObjects(sourceObj, targetObj)) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ public static boolean handleSourceAndTargetObjects(Object sourceObj, Object targetObj) {
+
+ if (sourceObj == null && targetObj == null) {
+ return true;
+ }
+
+ if (sourceObj == null && targetObj != null) {
+ return false;
+ }
+ if (sourceObj.getClass().equals(targetObj.getClass())) {
+ if (sourceObj instanceof Map) {
+ if (!compareMaps((Map<String, Object>) sourceObj, (Map<String, Object>) targetObj)) {
+ return false;
+ }
+ } else if (sourceObj instanceof List) {
+ if (!compareLists((List<Object>) sourceObj, (List<Object>) targetObj)) {
+ return false;
+ }
+ } else {
+
+ if(sourceObj.getClass() != targetObj.getClass()){
+ return false;
+ }
+
+ if (!sourceObj.equals(targetObj)) {
+ return false;
+ }
+ }
+ }
+ return true;
+ }
+
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/utils/ProxyServicePropertiesUtils.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/utils/ProxyServicePropertiesUtils.java
new file mode 100644
index 0000000000..b9b7ab690f
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/utils/ProxyServicePropertiesUtils.java
@@ -0,0 +1,54 @@
+/*
+ * Copyright © 2016-2018 European Support Limited
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.openecomp.sdc.be.components.utils;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+import java.util.function.Function;
+import java.util.function.Predicate;
+import java.util.stream.Collectors;
+import org.openecomp.sdc.be.model.Component;
+import org.openecomp.sdc.be.model.PropertyDefinition;
+
+public class ProxyServicePropertiesUtils {
+
+ private ProxyServicePropertiesUtils() {
+ }
+
+ public static List<PropertyDefinition> getProperties(Component service) {
+ List<PropertyDefinition> properties = service.getProperties();
+ if (properties == null) {
+ properties = new ArrayList<>();
+ }
+ Set<PropertyDefinition> serviceProperties = new HashSet<>(properties);
+ if (service.getInputs() != null) {
+ Set<PropertyDefinition> inputs = service.getInputs().stream().map(input -> new PropertyDefinition(input))
+ .collect(Collectors.toSet());
+ serviceProperties.addAll(inputs);
+ }
+ serviceProperties =
+ serviceProperties.stream().filter(distinctByKey(PropertyDefinition::getName)).collect(Collectors.toSet());
+ return new ArrayList<>(serviceProperties);
+ }
+
+ public static <T> Predicate<T> distinctByKey(Function<? super T, ?> keyExtractor) {
+ Set<Object> seen = new HashSet<>();
+ return t -> seen.add(keyExtractor.apply(t));
+ }
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/utils/UiComponentDataConverter.java b/catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/utils/UiComponentDataConverter.java
index 899a7b1cb8..b76664f968 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/utils/UiComponentDataConverter.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/utils/UiComponentDataConverter.java
@@ -28,6 +28,7 @@ import org.openecomp.sdc.be.datatypes.elements.CapabilityDataDefinition;
import org.openecomp.sdc.be.datatypes.enums.ComponentFieldsEnum;
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
import org.openecomp.sdc.be.model.*;
+import org.openecomp.sdc.be.tosca.utils.NodeFilterConverter;
import org.openecomp.sdc.be.ui.model.*;
import org.openecomp.sdc.common.log.wrappers.Logger;
@@ -101,6 +102,13 @@ public class UiComponentDataConverter {
case COMPONENT_INSTANCE_INPUTS:
setComponentInstanceInputs(dataTransfer, component);
break;
+ case NODE_FILTER:
+ if(component.getNodeFilterComponents() == null) {
+ dataTransfer.setNodeFilterData(null);
+ } else {
+ NodeFilterConverter nodeFilterConverter = new NodeFilterConverter();
+ dataTransfer.setNodeFilterData(nodeFilterConverter.convertDataMapToUI(component.getNodeFilterComponents()));
+ }
default:
break;
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/impl/ServiceFilterUtils.java b/catalog-be/src/main/java/org/openecomp/sdc/be/impl/ServiceFilterUtils.java
new file mode 100644
index 0000000000..7faf89cb89
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/impl/ServiceFilterUtils.java
@@ -0,0 +1,177 @@
+/*
+ * Copyright © 2016-2018 European Support Limited
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.openecomp.sdc.be.impl;
+
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+import org.javatuples.Pair;
+import org.openecomp.sdc.be.components.impl.utils.DirectivesUtils;
+import org.openecomp.sdc.be.datamodel.utils.ConstraintConvertor;
+import org.openecomp.sdc.be.datatypes.elements.CINodeFilterDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.RequirementNodeFilterPropertyDataDefinition;
+import org.openecomp.sdc.be.model.ComponentInstance;
+import org.openecomp.sdc.be.model.InputDefinition;
+import org.openecomp.sdc.be.model.Service;
+import org.openecomp.sdc.be.ui.model.UIConstraint;
+
+public class ServiceFilterUtils {
+
+
+ private ServiceFilterUtils() {
+ }
+
+
+ public static boolean isNodeFilterAffectedByPropertyRemoval(Service service, String ciName, String propertyName) {
+ return service.getComponentInstances().stream().filter(ci -> ci.getNodeFilter() != null)
+ .anyMatch(ci -> propertyIsUsedInCI(ci, ciName, propertyName));
+ }
+
+
+ private static boolean propertyIsUsedInCI(ComponentInstance ci, String ciName, String propertyName) {
+ final List<String> directives = ci.getDirectives();
+ if (!directives.contains(DirectivesUtils.SELECTABLE)) {
+ return false;
+ }
+ if (ci.getNodeFilter() == null || ci.getNodeFilter().getProperties() == null
+ || ci.getNodeFilter().getProperties().getListToscaDataDefinition() == null) {
+ return false;
+ }
+ return ci.getNodeFilter().getProperties().getListToscaDataDefinition().stream()
+ .flatMap(prop -> prop.getConstraints().stream()).map(String::new)
+ .filter(constraint -> new ConstraintConvertor().convert(constraint).getSourceType()
+ .equals(ConstraintConvertor.PROPERTY_CONSTRAINT))
+ .anyMatch(constraintStr -> {
+ UIConstraint uiConstraint = new ConstraintConvertor().convert(constraintStr);
+ return uiConstraint.getSourceName().equals(ciName) && uiConstraint.getValue().equals(propertyName);
+ });
+
+ }
+
+ public static Map<String, CINodeFilterDataDefinition> getRenamedNodesFilter(Service service, String oldName,
+ String newName) {
+ return service.getComponentInstances().stream().filter(ci -> isNodeFilterUsingChangedCi(ci, oldName))
+ .map(ci -> renameOldCiNames(ci, oldName, newName))
+ .collect(Collectors.toMap(Pair::getValue0, Pair::getValue1));
+ }
+
+ private static Pair<String, CINodeFilterDataDefinition> renameOldCiNames(ComponentInstance ci, String oldName,
+ String newName) {
+ ci.getNodeFilter().getProperties().getListToscaDataDefinition().stream()
+ .filter(property -> isPropertyConstraintChangedByCi(property, oldName))
+ .forEach(property -> renamePropertyCiNames(property, oldName, newName));
+
+ return new Pair<>(ci.getUniqueId(), ci.getNodeFilter());
+ }
+
+ private static void renamePropertyCiNames(RequirementNodeFilterPropertyDataDefinition property, String oldName,
+ String newName) {
+ final List<String> constraints = property.getConstraints().stream().map(getConstraintString(oldName, newName))
+ .collect(Collectors.toList());
+ property.setConstraints(constraints);
+ }
+
+ private static Function<String, String> getConstraintString(String oldName, String newName) {
+ return constraint -> {
+ final ConstraintConvertor constraintConvertor = new ConstraintConvertor();
+ UIConstraint uiConstraint = constraintConvertor.convert(constraint);
+ if (uiConstraint.getSourceName().equals(oldName)) {
+ uiConstraint.setSourceName(newName);
+ }
+ return constraintConvertor.convert(uiConstraint);
+ };
+ }
+
+
+ public static Set<String> getNodesFiltersToBeDeleted(Service service, String ciName) {
+ return service.getComponentInstances().stream().filter(ci -> isNodeFilterUsingChangedCi(ci, ciName))
+ .map(ComponentInstance::getName).collect(Collectors.toSet());
+ }
+
+
+
+ public static Set<String> getNodesFiltersToBeDeleted(Service service, ComponentInstance inCi) {
+ return getNodesFiltersToBeDeleted(service, inCi.getName());
+ }
+
+
+
+ private static boolean isNodeFilterUsingChangedCi(ComponentInstance ci, String name) {
+ final List<String> directives = ci.getDirectives();
+ if (!directives.contains(DirectivesUtils.SELECTABLE)) {
+ return false;
+ }
+ if (ci.getNodeFilter() == null || ci.getNodeFilter().getProperties() == null
+ || ci.getNodeFilter().getProperties().getListToscaDataDefinition() == null) {
+ return false;
+ }
+ return ci.getNodeFilter().getProperties().getListToscaDataDefinition().stream()
+ .anyMatch(property -> isPropertyConstraintChangedByCi(property, name));
+ }
+
+ private static boolean isPropertyConstraintChangedByCi(
+ RequirementNodeFilterPropertyDataDefinition requirementNodeFilterPropertyDataDefinition, String name) {
+ List<String> constraints = requirementNodeFilterPropertyDataDefinition.getConstraints();
+ if (constraints == null) {
+ return false;
+ }
+ return constraints.stream().anyMatch(constraint -> isConstraintChangedByCi(constraint, name));
+ }
+
+ private static boolean isConstraintChangedByCi(String constraint, String name) {
+ UIConstraint uiConstraint = new ConstraintConvertor().convert(constraint);
+ if (uiConstraint == null || uiConstraint.getSourceType() == null) {
+ return false;
+ }
+ if (!uiConstraint.getSourceType().equals(ConstraintConvertor.PROPERTY_CONSTRAINT)) {
+ return false;
+ }
+ return uiConstraint.getSourceName().equals(name);
+ }
+
+ public static Set<String> getNodesFiltersToBeDeleted(Service service, InputDefinition changedInput) {
+ return service.getComponentInstances().stream().filter(ci -> isNodeFilterUsingChangedInput(ci, changedInput))
+ .map(ComponentInstance::getName).collect(Collectors.toSet());
+ }
+
+ private static boolean isNodeFilterUsingChangedInput(ComponentInstance ci, InputDefinition changedInput) {
+ final List<String> directives = ci.getDirectives();
+ if (!directives.contains(DirectivesUtils.SELECTABLE)) {
+ return false;
+ }
+ return ci.getNodeFilter().getProperties().getListToscaDataDefinition().stream()
+ .anyMatch(property -> isPropertyConstraintChangedByInput(property, changedInput));
+ }
+
+ private static boolean isPropertyConstraintChangedByInput(
+ RequirementNodeFilterPropertyDataDefinition requirementNodeFilterPropertyDataDefinition,
+ InputDefinition changedInput) {
+ List<String> constraints = requirementNodeFilterPropertyDataDefinition.getConstraints();
+ return constraints.stream().anyMatch(constraint -> isConstraintChangedByInput(constraint, changedInput));
+ }
+
+ private static boolean isConstraintChangedByInput(String constraint, InputDefinition changedInput) {
+ UIConstraint uiConstraint = new ConstraintConvertor().convert(constraint);
+ if (!uiConstraint.getSourceType().equals(ConstraintConvertor.SERVICE_INPUT_CONSTRAINT)) {
+ return false;
+ }
+ return uiConstraint.getValue().equals(changedInput.getName());
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ComponentInstanceServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ComponentInstanceServlet.java
index b5e28148da..45d1c5f589 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ComponentInstanceServlet.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ComponentInstanceServlet.java
@@ -31,9 +31,12 @@ import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringUtils;
import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic;
import org.openecomp.sdc.be.components.impl.GroupBusinessLogic;
+import org.openecomp.sdc.be.components.impl.ServiceBusinessLogic;
+import org.openecomp.sdc.be.components.impl.utils.DirectivesUtils;
import org.openecomp.sdc.be.config.BeEcompErrorManager;
import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.datamodel.ForwardingPaths;
+import org.openecomp.sdc.be.datatypes.elements.CINodeFilterDataDefinition;
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
import org.openecomp.sdc.be.info.CreateAndAssotiateInfo;
@@ -171,6 +174,34 @@ public class ComponentInstanceServlet extends AbstractValidationsServlet {
if (actionResponse.isRight()) {
return buildErrorResponse(actionResponse.right().value());
}
+ ComponentInstance resultValue = actionResponse.left().value();
+ if (componentTypeEnum.equals(ComponentTypeEnum.SERVICE)){
+ boolean shouldCreateServiceFilter = resourceInstance.getDirectives() != null && resourceInstance.getDirectives().contains(
+ DirectivesUtils.SELECTABLE);
+ ServiceBusinessLogic
+ serviceBusinessLogic = (ServiceBusinessLogic) getComponentBL(componentTypeEnum, context);
+
+ if(shouldCreateServiceFilter) {
+ Either<CINodeFilterDataDefinition, ResponseFormat> either =
+ serviceBusinessLogic.createIfNotAlreadyExistServiceFilter(componentId, componentInstanceId, userId,
+ true);
+ if (either.isRight()){
+ BeEcompErrorManager.getInstance().logBeSystemError("Resource Instance - updateResourceInstance Failed to create service filter.");
+ log.debug("Failed to create service filter.");
+ return buildErrorResponse(convertResponse.right().value());
+ }
+ resultValue.setNodeFilter(either.left().value());
+ } else {
+ Either<String, ResponseFormat> either = serviceBusinessLogic.deleteIfNotAlreadyDeletedServiceFilter(componentId, componentInstanceId, userId,true);
+ if (either.isRight()){
+ BeEcompErrorManager.getInstance().logBeSystemError("Resource Instance - updateResourceInstance Failed to delete service filter.");
+ log.debug("Failed to delete service filter.");
+ return buildErrorResponse(convertResponse.right().value());
+ }
+ resultValue.setNodeFilter(null);
+ }
+ }
+
return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), actionResponse.left().value());
} catch (Exception e) {
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java
index 06cf2afe36..da0ec1c0ea 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java
@@ -29,11 +29,12 @@ import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.commons.lang3.tuple.ImmutableTriple;
import org.apache.commons.lang3.tuple.Triple;
+import org.onap.sdc.tosca.services.YamlUtil;
import org.openecomp.sdc.be.components.impl.exceptions.SdcResourceNotFoundException;
import org.openecomp.sdc.be.config.ConfigurationManager;
import org.openecomp.sdc.be.dao.titan.TitanOperationStatus;
import org.openecomp.sdc.be.datatypes.components.ResourceMetadataDataDefinition;
-import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.*;
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.OriginTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
@@ -116,6 +117,7 @@ public class ToscaExportHandler {
private static final String NOT_SUPPORTED_COMPONENT_TYPE = "Not supported component type {}";
private static final List<Map<String, Map<String, String>>> DEFAULT_IMPORTS = ConfigurationManager
.getConfigurationManager().getConfiguration().getDefaultImports();
+ private static YamlUtil yamlUtil = new YamlUtil();
public ToscaExportHandler(){}
@@ -587,7 +589,6 @@ public class ToscaExportHandler {
}
}
-
private Either<ToscaTemplate, ToscaError> convertReqCapAndTypeName(Map<String, Component> componentsCache, Component component, ToscaTemplate toscaNode,
Map<String, ToscaNodeType> nodeTypes, ToscaNodeType toscaNodeType,
Map<String, DataTypeDefinition> dataTypes) {
@@ -645,6 +646,8 @@ public class ToscaExportHandler {
for (ComponentInstance componentInstance : componentInstances) {
ToscaNodeTemplate nodeTemplate = new ToscaNodeTemplate();
nodeTemplate.setType(componentInstance.getToscaComponentName());
+ nodeTemplate.setDirectives(componentInstance.getDirectives());
+ nodeTemplate.setNode_filter(convertToNodeTemplateNodeFilterComponent(componentInstance.getNodeFilter()));
Either<Component, Boolean> originComponentRes = capabilityRequirementConverter
.getOriginComponent(componentCache, componentInstance);
@@ -809,7 +812,6 @@ public class ToscaExportHandler {
return interfaces;
}
- //M3[00001] - NODE TEMPLATE INTERFACES - END
private void addComponentInstanceInputs(Map<String, DataTypeDefinition> dataTypes,
Map<String, List<ComponentInstanceInput>> componentInstancesInputs,
@@ -1164,6 +1166,102 @@ public class ToscaExportHandler {
return Either.left(nodeType);
}
+
+ protected NodeFilter convertToNodeTemplateNodeFilterComponent(CINodeFilterDataDefinition inNodeFilter) {
+ if (inNodeFilter == null){
+ return null;
+ }
+ NodeFilter nodeFilter = new NodeFilter();
+
+ ListDataDefinition<RequirementNodeFilterCapabilityDataDefinition> origCapabilities =
+ inNodeFilter.getCapabilities();
+
+ ListDataDefinition<RequirementNodeFilterPropertyDataDefinition> origProperties = inNodeFilter.getProperties();
+
+ List<Map<String, CapabilityFilter>> capabilitiesCopy = new ArrayList<>();
+ List<Map<String, List<Object>>> propertiesCopy = new ArrayList<>();
+
+ copyNodeFilterCapabilitiesTemplate(origCapabilities, capabilitiesCopy);
+ copyNodeFilterProperties(origProperties, propertiesCopy);
+
+ if(CollectionUtils.isNotEmpty(capabilitiesCopy)) {
+ nodeFilter.setCapabilities(capabilitiesCopy);
+ }
+
+ if(CollectionUtils.isNotEmpty(propertiesCopy)) {
+ nodeFilter.setProperties(propertiesCopy);
+ }
+
+ nodeFilter.setTosca_id(cloneToscaId(inNodeFilter.getTosca_id()));
+
+
+ nodeFilter = (NodeFilter) cloneObjectFromYml(nodeFilter, NodeFilter.class);
+
+ return nodeFilter;
+ }
+
+ private Object cloneToscaId(Object toscaId) {
+ return Objects.isNull(toscaId) ? null
+ : cloneObjectFromYml(toscaId, toscaId.getClass());
+ }
+
+
+ private Object cloneObjectFromYml(Object objToClone, Class classOfObj) {
+ String objectAsYml = yamlUtil.objectToYaml(objToClone);
+ return yamlUtil.yamlToObject(objectAsYml, classOfObj);
+ }
+ private void copyNodeFilterCapabilitiesTemplate(
+ ListDataDefinition<RequirementNodeFilterCapabilityDataDefinition> origCapabilities,
+ List<Map<String, CapabilityFilter>> capabilitiesCopy) {
+ if(origCapabilities == null || origCapabilities.getListToscaDataDefinition() == null ||
+ origCapabilities.getListToscaDataDefinition().isEmpty() ) {
+ return;
+ }
+ for(RequirementNodeFilterCapabilityDataDefinition capability : origCapabilities.getListToscaDataDefinition()) {
+ Map<String, CapabilityFilter> capabilityFilterCopyMap = new HashMap<>();
+ CapabilityFilter capabilityFilter = new CapabilityFilter();
+ List<Map<String, List<Object>>> propertiesCopy = new ArrayList<>();
+ copyNodeFilterProperties(capability.getProperties(), propertiesCopy);
+ capabilityFilter.setProperties(propertiesCopy);
+ capabilityFilterCopyMap.put(capability.getName(), capabilityFilter);
+ capabilitiesCopy.add(capabilityFilterCopyMap);
+ }
+ }
+
+ private List<Object> copyNodeFilterProperty(List<Object> propertyList) {
+ String listAsString = yamlUtil.objectToYaml(propertyList);
+ return yamlUtil.yamlToObject(listAsString, List.class);
+ }
+
+
+ private void copyNodeFilterProperties(
+ ListDataDefinition<RequirementNodeFilterPropertyDataDefinition> origProperties,
+ List<Map<String, List<Object>>> propertiesCopy) {
+ if(origProperties == null || origProperties.getListToscaDataDefinition() == null ||
+ origProperties.isEmpty()) {
+ return;
+ }
+ for(RequirementNodeFilterPropertyDataDefinition propertyDataDefinition : origProperties.getListToscaDataDefinition()) {
+ Map<String, List<Object>> propertyMapCopy = new HashMap<>();
+ for(String propertyInfoEntry : propertyDataDefinition.getConstraints()) {
+ Map propertyValObj = new YamlUtil().yamlToObject(propertyInfoEntry, Map.class);
+ if (propertyMapCopy.containsKey(propertyDataDefinition.getName())){
+ propertyMapCopy.get(propertyDataDefinition.getName()).add(propertyValObj);
+ } else {
+ if (propertyDataDefinition.getName() != null) {
+ List propsList =new ArrayList();
+ propsList.add(propertyValObj);
+ propertyMapCopy.put(propertyDataDefinition.getName(), propsList);
+ } else {
+ propertyMapCopy.putAll(propertyValObj);
+ }
+ }
+ }
+ propertiesCopy.add(propertyMapCopy);
+ }
+
+ }
+
private static class CustomRepresenter extends Representer {
public CustomRepresenter() {
super();
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaNodeTemplate.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaNodeTemplate.java
index b67a2cf233..b17dc3a43f 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaNodeTemplate.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaNodeTemplate.java
@@ -7,9 +7,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -25,14 +25,18 @@ import org.apache.commons.collections.MapUtils;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import org.apache.commons.collections.CollectionUtils;
public class ToscaNodeTemplate {
+
private String type;
+ private List<String> directives;
private ToscaMetadata metadata;
private String description;
private Map<String, Object> properties;
private List<Map<String, ToscaTemplateRequirement>> requirements;
private Map<String, ToscaTemplateCapability> capabilities;
+ private NodeFilter node_filter;
private Map<String, Object> interfaces;
public String getType() {
@@ -75,13 +79,33 @@ public class ToscaNodeTemplate {
this.metadata = metadata;
}
- public String getDescription() {
- return description;
- }
+ public String getDescription() {
+ return description;
+ }
+
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+ public List<String> getDirectives() {
+ return directives;
+ }
+
+ public void setDirectives(List<String> directives) {
+ if (CollectionUtils.isEmpty(directives)) {
+ this.directives = null;
+ return;
+ }
+ this.directives = directives;
+ }
+
+ public NodeFilter getNode_filter() {
+ return node_filter;
+ }
- public void setDescription(String description) {
- this.description = description;
- }
+ public void setNode_filter(NodeFilter node_filter) {
+ this.node_filter = node_filter;
+ }
public void setInterfaces(
Map<String, Object> interfaces) {
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/utils/NodeFilterConverter.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/utils/NodeFilterConverter.java
index af0837fdcf..8470bd22a0 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/utils/NodeFilterConverter.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/utils/NodeFilterConverter.java
@@ -123,6 +123,10 @@ public class NodeFilterConverter {
}
}
+ public Map<String, UINodeFilter> convertDataMapToUI(Map<String, CINodeFilterDataDefinition> inMap) {
+ return inMap.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, o -> convertToUi(o.getValue())));
+ }
+
public UINodeFilter convertToUi(CINodeFilterDataDefinition inNodeFilter) {
UINodeFilter retVal = new UINodeFilter();
final ConstraintConvertor constraintConvertor = new ConstraintConvertor();
@@ -131,7 +135,7 @@ public class NodeFilterConverter {
}
List<UIConstraint> constraints = inNodeFilter.getProperties().getListToscaDataDefinition().stream()
.map(property -> property.getConstraints().iterator().next())
- .map(str -> constraintConvertor.convert(str))
+ .map(constraintConvertor::convert)
.collect(Collectors.toList());
retVal.setProperties(constraints);
return retVal;