diff options
author | 2019-05-13 17:08:25 +0530 | |
---|---|---|
committer | 2019-05-13 17:09:02 +0530 | |
commit | 0cf08bff1f9b50d227d7047b5fdd7776c667ca25 (patch) | |
tree | 2b3700b5fd02cbedb2f53acddcee96c8249fe04a /catalog-model/src/main | |
parent | 81f5b9422af04f3287f7c1e0babf355b5251dada (diff) |
Support Capability Properties
This change includes following changes
1. Get capability properties from global types- BE
2. Show capability properties in cap/req screen
3. Support Capability Properties in assingment, operation and consumption screens
Change-Id: I7e21691beedfa8831ecf78c01ed501804f81ec78
Issue-ID: SDC-2295
Signed-off-by: Mojahidul Islam <mojahidul.islam@amdocs.com>
Diffstat (limited to 'catalog-model/src/main')
6 files changed, 293 insertions, 52 deletions
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/ComponentParametersView.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/ComponentParametersView.java index 05d9a572a3..a405f6ee07 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/ComponentParametersView.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/ComponentParametersView.java @@ -46,7 +46,7 @@ public class ComponentParametersView { private boolean ignoreComponentInstancesAttributesFrom = false; private boolean ignoreInputs = false; private boolean ignoreComponentInstancesInputs = false; - private boolean ignoreCapabiltyProperties = true; + private boolean ignoreCapabiltyProperties = false; private boolean ignoreServicePath = true; private boolean ignorePolicies = false; private boolean ignoreNodeFilterRequirements = false; @@ -94,6 +94,7 @@ public class ComponentParametersView { this.setIgnoreCapabilities(false); this.setIgnoreRequirements(false); this.setIgnoreNodeFilter(false); + this.setIgnoreCapabiltyProperties(false); break; case COMPONENT_INSTANCES_PROPERTIES: this.setIgnoreComponentInstances(false); //we need this in order to get the calculate capabilities requirements @@ -102,6 +103,7 @@ public class ComponentParametersView { case CAPABILITIES: this.setIgnoreComponentInstances(false);//we need this in order to get the calculate capabilities requirements this.setIgnoreCapabilities(false); + this.setIgnoreCapabiltyProperties(false); break; case REQUIREMENTS: this.setIgnoreComponentInstances(false); diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/BaseOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/BaseOperation.java index 6dfd1fcffb..d44865c399 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/BaseOperation.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/BaseOperation.java @@ -1485,7 +1485,7 @@ public abstract class BaseOperation { return titanOperationStatus; } - private GraphVertex throwStorageException(TitanOperationStatus status) { + protected GraphVertex throwStorageException(TitanOperationStatus status) { throw new StorageException(status); } diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/CapabilitiesOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/CapabilitiesOperation.java index a8337b6c4f..9d7f64c24a 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/CapabilitiesOperation.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/CapabilitiesOperation.java @@ -17,13 +17,23 @@ package org.openecomp.sdc.be.model.jsontitan.operations; import fj.data.Either; +import org.apache.commons.collections.MapUtils; +import org.openecomp.sdc.be.dao.jsongraph.GraphVertex; import org.openecomp.sdc.be.dao.jsongraph.types.EdgeLabelEnum; +import org.openecomp.sdc.be.dao.jsongraph.types.JsonParseFlagEnum; import org.openecomp.sdc.be.dao.jsongraph.types.VertexTypeEnum; import org.openecomp.sdc.be.datatypes.elements.CapabilityDataDefinition; import org.openecomp.sdc.be.datatypes.elements.ListCapabilityDataDefinition; +import org.openecomp.sdc.be.datatypes.elements.MapPropertiesDataDefinition; +import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition; import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields; +import org.openecomp.sdc.be.datatypes.tosca.ToscaDataDefinition; import org.openecomp.sdc.be.model.CapabilityDefinition; import org.openecomp.sdc.be.model.Component; +import org.openecomp.sdc.be.model.ComponentParametersView; +import org.openecomp.sdc.be.model.jsontitan.datamodel.TopologyTemplate; +import org.openecomp.sdc.be.model.jsontitan.datamodel.ToscaElement; +import org.openecomp.sdc.be.model.operations.StorageException; import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -31,20 +41,19 @@ import org.slf4j.LoggerFactory; import java.util.ArrayList; import java.util.Collections; import java.util.List; +import java.util.Map; @org.springframework.stereotype.Component("capabilities-operation") public class CapabilitiesOperation extends BaseOperation { private static final Logger LOGGER = LoggerFactory.getLogger(CapabilitiesOperation.class); - public Either<List<CapabilityDefinition>, StorageOperationStatus> addCapabilities( - String componentId, - List<CapabilityDefinition> capabilityDefinitions) { + public Either<List<CapabilityDefinition>, StorageOperationStatus> addCapabilities(String componentId, + List<CapabilityDefinition> capabilityDefinitions) { return addOrUpdateCapabilities(componentId, capabilityDefinitions, false); } - public Either<List<CapabilityDefinition>, StorageOperationStatus> updateCapabilities( - String componentId, - List<CapabilityDefinition> capabilityDefinitions) { + public Either<List<CapabilityDefinition>, StorageOperationStatus> updateCapabilities(String componentId, + List<CapabilityDefinition> capabilityDefinitions) { return addOrUpdateCapabilities(componentId, capabilityDefinitions, true); } @@ -52,33 +61,31 @@ public class CapabilitiesOperation extends BaseOperation { List<CapabilityDefinition> capabilityDefinitions, boolean isUpdateAction) { StorageOperationStatus statusRes = performUpdateToscaAction(isUpdateAction, - componentId, Collections - .singletonList(convertToListCapabilityDataDefinition(capabilityDefinitions))); + componentId, Collections.singletonList(convertToListCapabilityDataDefinition(capabilityDefinitions))); if (!statusRes.equals(StorageOperationStatus.OK)) { - titanDao.rollback(); - LOGGER.error("Failed to find the parent capability of capability type {}." - + " status is {}", componentId, statusRes); + LOGGER.error("Failed to find the parent capability of capability type {}." + " status is {}", componentId, + statusRes); return Either.right(statusRes); } - titanDao.commit(); return Either.left(capabilityDefinitions); } - public StorageOperationStatus deleteCapabilities(Component component, - String capabilityIdToDelete) { - return deleteToscaDataElements(component.getUniqueId(), - EdgeLabelEnum.CAPABILITIES, + public StorageOperationStatus deleteCapabilities(Component component, String capabilityIdToDelete) { + return deleteToscaDataElements(component.getUniqueId(), EdgeLabelEnum.CAPABILITIES, Collections.singletonList(capabilityIdToDelete)); } - private static ListCapabilityDataDefinition convertToListCapabilityDataDefinition( - List<CapabilityDefinition> capabilities) { + public StorageOperationStatus deleteCapabilityProperties(Component component, String capabilityPropIdToDelete) { + return deleteToscaDataElements(component.getUniqueId(), EdgeLabelEnum.CAPABILITIES_PROPERTIES, + Collections.singletonList(capabilityPropIdToDelete)); + } + + private static ListCapabilityDataDefinition convertToListCapabilityDataDefinition(List<CapabilityDefinition> capabilities) { List<CapabilityDataDefinition> capabilityDefinitions = new ArrayList<>(capabilities); return new ListCapabilityDataDefinition(capabilityDefinitions); } - private StorageOperationStatus performUpdateToscaAction(boolean isUpdate, - String componentId, + private StorageOperationStatus performUpdateToscaAction(boolean isUpdate, String componentId, List<ListCapabilityDataDefinition> toscaDataList) { if (isUpdate) { return updateToscaDataOfToscaElement(componentId, EdgeLabelEnum.CAPABILITIES, @@ -88,4 +95,61 @@ public class CapabilitiesOperation extends BaseOperation { VertexTypeEnum.CAPABILITIES, toscaDataList, JsonPresentationFields.TYPE); } } + + private StorageOperationStatus createOrUpdateCapabilityProperties(String componentId, TopologyTemplate toscaElement, + Map<String, MapPropertiesDataDefinition> propertiesMap) { + GraphVertex toscaElementV = titanDao.getVertexById(componentId, JsonParseFlagEnum.NoParse) + .left().on(this::throwStorageException); + Map<String, MapPropertiesDataDefinition> capabilitiesProperties = toscaElement.getCapabilitiesProperties(); + if(MapUtils.isNotEmpty(capabilitiesProperties)) { + + capabilitiesProperties.forEach((key, val) -> { + Map<String, PropertyDataDefinition> mapToscaDataDefinition = val.getMapToscaDataDefinition(); + mapToscaDataDefinition.forEach((key1, val1) -> { + + propertiesMap.forEach((propKey, propVal) -> { + Map<String, PropertyDataDefinition> propValMapToscaDataDefinition = propVal.getMapToscaDataDefinition(); + propValMapToscaDataDefinition.forEach((propKey1, propVal1) -> { + if(propKey1.equals(key1) && val1.getUniqueId().equals(propVal1.getUniqueId())) { + ToscaDataDefinition.mergeDataMaps(mapToscaDataDefinition, propValMapToscaDataDefinition); + } + }); + }); + }); + }); + + ToscaDataDefinition.mergeDataMaps(propertiesMap, capabilitiesProperties); + } + + return topologyTemplateOperation.updateFullToscaData(toscaElementV, + EdgeLabelEnum.CAPABILITIES_PROPERTIES, VertexTypeEnum.CAPABILITIES_PROPERTIES, propertiesMap); + } + + public StorageOperationStatus createOrUpdateCapabilityProperties(String componentId, + Map<String, MapPropertiesDataDefinition> propertiesMap) { + StorageOperationStatus propertiesStatusRes = null; + if(MapUtils.isNotEmpty(propertiesMap)) { + propertiesStatusRes = createOrUpdateCapabilityProperties(componentId, getTopologyTemplate(componentId), + propertiesMap); + } + + return propertiesStatusRes; + } + + private TopologyTemplate getTopologyTemplate(String componentId) { + return (TopologyTemplate)topologyTemplateOperation + .getToscaElement(componentId, getFilterComponentWithCapProperties()) + .left() + .on(this::throwStorageException); + } + private ComponentParametersView getFilterComponentWithCapProperties() { + ComponentParametersView filter = new ComponentParametersView(); + filter.setIgnoreCapabiltyProperties(false); + return filter; + } + + private ToscaElement throwStorageException(StorageOperationStatus status) { + throw new StorageException(status); + } + } diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/TopologyTemplateOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/TopologyTemplateOperation.java index 417577320c..f0a5e2b7d6 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/TopologyTemplateOperation.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/TopologyTemplateOperation.java @@ -251,11 +251,24 @@ public class TopologyTemplateOperation extends ToscaElementOperation { } private StorageOperationStatus associateCapPropertiesToResource(GraphVertex topologyTemplateVertex, TopologyTemplate topologyTemplate) { - Map<String, MapCapabilityProperty> calculatedCapProperties = topologyTemplate.getCalculatedCapabilitiesProperties(); - if (calculatedCapProperties != null && !calculatedCapProperties.isEmpty()) { - Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(topologyTemplateVertex, VertexTypeEnum.CALCULATED_CAP_PROPERTIES, EdgeLabelEnum.CALCULATED_CAP_PROPERTIES, calculatedCapProperties); - if (assosiateElementToData.isRight()) { - return assosiateElementToData.right().value(); + Map<String, MapCapabilityProperty> calculatedCapProperties = topologyTemplate + .getCalculatedCapabilitiesProperties(); + if (MapUtils.isNotEmpty(calculatedCapProperties)) { + Either<GraphVertex, StorageOperationStatus> associateElementToData = associateElementToData + (topologyTemplateVertex, VertexTypeEnum.CALCULATED_CAP_PROPERTIES, + EdgeLabelEnum.CALCULATED_CAP_PROPERTIES, calculatedCapProperties); + if (associateElementToData.isRight()) { + return associateElementToData.right().value(); + } + } + + Map<String, MapPropertiesDataDefinition> capabilitiesProperties = topologyTemplate.getCapabilitiesProperties(); + if (MapUtils.isNotEmpty(capabilitiesProperties)) { + Either<GraphVertex, StorageOperationStatus> associateElementToData = + associateElementToData(topologyTemplateVertex, VertexTypeEnum.CAPABILITIES_PROPERTIES, + EdgeLabelEnum.CAPABILITIES_PROPERTIES, capabilitiesProperties); + if (associateElementToData.isRight()) { + return associateElementToData.right().value(); } } return StorageOperationStatus.OK; @@ -866,6 +879,16 @@ public class TopologyTemplateOperation extends ToscaElementOperation { return result.right().value(); } } + Either<Map<String, MapPropertiesDataDefinition>, TitanOperationStatus> capPropResult = + getDataFromGraph(componentV, EdgeLabelEnum.CAPABILITIES_PROPERTIES); + if (capPropResult.isLeft()) { + topologyTemplate.setCapabilitiesProperties(capPropResult.left().value()); + } else { + if (capPropResult.right().value() != TitanOperationStatus.NOT_FOUND) { + return capPropResult.right().value(); + } + } + return TitanOperationStatus.OK; } @@ -1151,6 +1174,11 @@ public class TopologyTemplateOperation extends ToscaElementOperation { log.debug("Failed to disassociate instance inputs for {} error {}", toscaElementVertex.getUniqueId(), status); return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status)); } + status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.CAPABILITIES_PROPERTIES); + if (status != TitanOperationStatus.OK) { + log.debug("Failed to disassociate capabilities properties for {} error {}", toscaElementVertex.getUniqueId(), status); + Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status)); + } status = titanDao.disassociateAndDeleteLast(toscaElementVertex, Direction.OUT, EdgeLabelEnum.CALCULATED_CAPABILITIES); if (status != TitanOperationStatus.OK) { log.debug("Failed to disassociate calculated capabiliites for {} error {}", toscaElementVertex.getUniqueId(), status); @@ -1499,10 +1527,6 @@ public class TopologyTemplateOperation extends ToscaElementOperation { } } - private GraphVertex throwStorageException(TitanOperationStatus status) { - throw new StorageException(status); - } - private ToscaElement getOriginToscaElement(ComponentInstanceDataDefinition instance) { log.debug("#getOriginToscaElement - origin name: {}", instance.getComponentName()); ToscaElementTypeEnum elementType = detectToscaType(instance.getOriginType()); @@ -1536,11 +1560,12 @@ public class TopologyTemplateOperation extends ToscaElementOperation { filter.setIgnoreRequirements(false); return filter; } - public void updateCapReqOwnerId(String componentId, TopologyTemplate toscaElement) { + public void updateCapReqPropertiesOwnerId(String componentId, TopologyTemplate toscaElement) { GraphVertex toscaElementV = titanDao.getVertexById(componentId, JsonParseFlagEnum.NoParse) .left().on(this::throwStorageException); updateCapOwnerId(toscaElement, componentId); updateReqOwnerId(toscaElement, componentId); + updatePropertiesOwnerId(toscaElement, componentId); topologyTemplateOperation .updateFullToscaData(toscaElementV, EdgeLabelEnum.CAPABILITIES, @@ -1548,6 +1573,9 @@ public class TopologyTemplateOperation extends ToscaElementOperation { topologyTemplateOperation .updateFullToscaData(toscaElementV, EdgeLabelEnum.REQUIREMENTS, VertexTypeEnum.REQUIREMENTS, toscaElement.getRequirements()); + topologyTemplateOperation + .updateFullToscaData(toscaElementV, EdgeLabelEnum.PROPERTIES, + VertexTypeEnum.PROPERTIES, toscaElement.getProperties()); } private void updateCapOwnerId(ToscaElement toscaElement, String ownerId) { @@ -1564,4 +1592,11 @@ public class TopologyTemplateOperation extends ToscaElementOperation { } } + private void updatePropertiesOwnerId(ToscaElement toscaElement, String ownerId) { + Map<String, PropertyDataDefinition> properties = toscaElement.getProperties(); + if(MapUtils.isNotEmpty(properties)) { + properties.values().forEach(propertyDataDefinition -> propertyDataDefinition.setParentUniqueId(ownerId)); + } + } + } diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/ToscaOperationFacade.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/ToscaOperationFacade.java index 10dd919fc7..228faeb798 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/ToscaOperationFacade.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/ToscaOperationFacade.java @@ -1166,23 +1166,28 @@ public class ToscaOperationFacade { public Either<Map<String, List<ComponentInstanceProperty>>, StorageOperationStatus> addComponentInstancePropertiesToComponent(Component containerComponent, Map<String, List<ComponentInstanceProperty>> instProperties) { requireNonNull(instProperties); - StorageOperationStatus status; + StorageOperationStatus status = null; for (Entry<String, List<ComponentInstanceProperty>> entry : instProperties.entrySet()) { List<ComponentInstanceProperty> props = entry.getValue(); String componentInstanceId = entry.getKey(); - List<ComponentInstanceProperty> instanceProperties = containerComponent.getComponentInstancesProperties().get(componentInstanceId); + + Map<String, List<CapabilityDefinition>> containerComponentCapabilities = containerComponent.getCapabilities(); + if (!isEmpty(props)) { for (ComponentInstanceProperty property : props) { - Optional<ComponentInstanceProperty> instanceProperty = instanceProperties.stream() - .filter(p -> p.getUniqueId().equals(property.getUniqueId())) - .findAny(); - if (instanceProperty.isPresent()) { - status = updateComponentInstanceProperty(containerComponent, componentInstanceId, property); - } else { - status = addComponentInstanceProperty(containerComponent, componentInstanceId, property); + String propertyParentUniqueId = property.getParentUniqueId(); + Optional<CapabilityDefinition> + capPropDefinition = getPropertyCapability(propertyParentUniqueId, containerComponent); + if(capPropDefinition.isPresent() && MapUtils.isNotEmpty(containerComponentCapabilities)) { + status = populateAndUpdateInstanceCapProperty(containerComponent, componentInstanceId, + containerComponentCapabilities, property, capPropDefinition.get()); } - if (status != StorageOperationStatus.OK) { - log.debug("Failed to update instance property {} for instance {} error {} ", property, componentInstanceId, status); + if(status == null) { + List<ComponentInstanceProperty> instanceProperties = containerComponent + .getComponentInstancesProperties().get(componentInstanceId); + status = updateInstanceProperty(containerComponent, componentInstanceId, instanceProperties, property); + } + if(status != StorageOperationStatus.OK) { return Either.right(status); } } @@ -1191,6 +1196,104 @@ public class ToscaOperationFacade { return Either.left(instProperties); } + private StorageOperationStatus populateAndUpdateInstanceCapProperty(Component containerComponent, String componentInstanceId, + Map<String, List<CapabilityDefinition>> containerComponentCapabilities, + ComponentInstanceProperty property, + CapabilityDefinition capabilityDefinition) { + List<CapabilityDefinition> capabilityDefinitions = containerComponentCapabilities.get(capabilityDefinition.getType()); + if(CollectionUtils.isEmpty(capabilityDefinitions)) { + return null; + } + Optional<CapabilityDefinition> capDefToGetProp = capabilityDefinitions.stream() + .filter(cap -> cap.getUniqueId().equals(capabilityDefinition.getUniqueId()) && cap.getPath().size() == 1).findAny(); + if(capDefToGetProp.isPresent()) { + return updateInstanceCapabilityProperty(containerComponent, componentInstanceId, property, capDefToGetProp.get()); + } + return null; + } + + private static Optional<CapabilityDefinition> getPropertyCapability(String propertyParentUniqueId, + Component containerComponent) { + + Map<String, List<CapabilityDefinition>> componentCapabilities = containerComponent.getCapabilities(); + if(MapUtils.isEmpty(componentCapabilities)){ + return Optional.empty(); + } + List<CapabilityDefinition> capabilityDefinitionList = componentCapabilities.values() + .stream().flatMap(Collection::stream).collect(Collectors.toList()); + if(CollectionUtils.isEmpty(capabilityDefinitionList)){ + return Optional.empty(); + } + return capabilityDefinitionList.stream() + .filter(capabilityDefinition -> capabilityDefinition.getUniqueId().equals(propertyParentUniqueId)) + .findAny(); + } + + private StorageOperationStatus updateInstanceProperty(Component containerComponent, String componentInstanceId, + List<ComponentInstanceProperty> instanceProperties, + ComponentInstanceProperty property) { + StorageOperationStatus status; + Optional<ComponentInstanceProperty> instanceProperty = instanceProperties.stream() + .filter(p -> p.getUniqueId().equals(property.getUniqueId())) + .findAny(); + if (instanceProperty.isPresent()) { + status = updateComponentInstanceProperty(containerComponent, componentInstanceId, property); + } else { + status = addComponentInstanceProperty(containerComponent, componentInstanceId, property); + } + if (status != StorageOperationStatus.OK) { + log.debug("Failed to update instance property {} for instance {} error {} ", property, componentInstanceId, status); + return status; + } + return StorageOperationStatus.OK; + } + + public StorageOperationStatus updateInstanceCapabilityProperty(Component containerComponent, String componentInstanceId, + ComponentInstanceProperty property, + CapabilityDefinition capabilityDefinition) { + Optional<ComponentInstance> fetchedCIOptional = containerComponent.getComponentInstanceById(componentInstanceId); + if(!fetchedCIOptional.isPresent()) { + return StorageOperationStatus.GENERAL_ERROR; + } + Either<Component, StorageOperationStatus> getComponentRes = + getToscaFullElement(fetchedCIOptional.get().getComponentUid()); + if(getComponentRes.isRight()) { + return StorageOperationStatus.GENERAL_ERROR; + } + Optional<Component> componentOptional = isNodeServiceProxy(getComponentRes.left().value()); + String propOwner; + if(!componentOptional.isPresent()) { + propOwner = componentInstanceId; + } else { + propOwner = fetchedCIOptional.get().getSourceModelUid(); + } + StorageOperationStatus status; + StringBuffer sb = new StringBuffer(componentInstanceId); + sb.append(ModelConverter.CAP_PROP_DELIM).append(propOwner).append(ModelConverter.CAP_PROP_DELIM) + .append(capabilityDefinition.getType()).append(ModelConverter.CAP_PROP_DELIM).append(capabilityDefinition.getName()); + String capKey = sb.toString(); + status = updateComponentInstanceCapabiltyProperty(containerComponent, componentInstanceId, capKey, property); + if (status != StorageOperationStatus.OK) { + log.debug("Failed to update instance capability property {} for instance {} error {} ", property, + componentInstanceId, status); + return status; + } + return StorageOperationStatus.OK; + } + + private Optional<Component> isNodeServiceProxy(Component component) { + if (component.getComponentType().equals(ComponentTypeEnum.SERVICE)) { + return Optional.empty(); + } + Resource resource = (Resource) component; + ResourceTypeEnum resType = resource.getResourceType(); + if(resType.equals(ResourceTypeEnum.ServiceProxy)) { + return Optional.of(component); + } + return Optional.empty(); + } + + public StorageOperationStatus associateDeploymentArtifactsToInstances(Map<String, Map<String, ArtifactDefinition>> instDeploymentArtifacts, String componentId, User user) { Either<GraphVertex, TitanOperationStatus> getVertexEither = titanDao.getVertexById(componentId, JsonParseFlagEnum.NoParse); @@ -2554,8 +2657,8 @@ public class ToscaOperationFacade { } return Either.left(parentComponents); } - public void updateCapReqOwnerId(String componentId) { + public void updateCapReqPropertiesOwnerId(String componentId) { topologyTemplateOperation - .updateCapReqOwnerId(componentId, getTopologyTemplate(componentId)); + .updateCapReqPropertiesOwnerId(componentId, getTopologyTemplate(componentId)); } } diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/utils/ModelConverter.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/utils/ModelConverter.java index 808fdbd4f6..95147313f8 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/utils/ModelConverter.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/utils/ModelConverter.java @@ -459,7 +459,9 @@ public class ModelConverter { if (CollectionUtils.isNotEmpty(capPrps)) { MapPropertiesDataDefinition dataToCreate = new MapPropertiesDataDefinition(); for (ComponentInstanceProperty cip : capPrps) { - dataToCreate.put(cip.getName(), new PropertyDataDefinition(cip)); + PropertyDataDefinition propertyDataDefinition = new PropertyDataDefinition(cip); + propertyDataDefinition.setParentUniqueId(cap.getUniqueId()); + dataToCreate.put(cip.getName(), propertyDataDefinition); } toscaCapPropMap.put(s + CAP_PROP_DELIM + cap.getName(), dataToCreate); } @@ -1358,16 +1360,51 @@ public class ModelConverter { private static void setCapabilitiesToComponent(TopologyTemplate topologyTemplate, Component component) { Map<String, ListCapabilityDataDefinition> capabilities = topologyTemplate.getCapabilities(); - Map<String, List<CapabilityDefinition>> componentCapabilities = component.getCapabilities(); + Map<String, MapPropertiesDataDefinition> capabilitiesProperties = topologyTemplate.getCapabilitiesProperties(); + Map<String, List<CapabilityDefinition>> allCapabilities = new HashMap<>(); + if(MapUtils.isNotEmpty(capabilities)) { - if(componentCapabilities == null) { - componentCapabilities = new HashMap<>(); - } - componentCapabilities.putAll(groupCapabilityByType(capabilities)); - component.setCapabilities(componentCapabilities); + allCapabilities.putAll(groupCapabilityByType(capabilities)); + } + + if(MapUtils.isNotEmpty(capabilitiesProperties)) { + capabilitiesProperties.forEach((s, capProp)-> { + String[] result = s.split(CAP_PROP_DELIM); + if (capProp != null) { + Map<String, PropertyDataDefinition> capMap = capProp.getMapToscaDataDefinition(); + + if (MapUtils.isNotEmpty(capMap)) { + List<ComponentInstanceProperty> capPropsList = capMap.values().stream() + .map(ComponentInstanceProperty::new).collect(Collectors.toList()); + + List<CapabilityDefinition> cap = allCapabilities.get(result[0]); + if (cap !=null) { + Optional<CapabilityDefinition> op = cap.stream().filter(c -> c.getName() + .equals(result[1])).findFirst(); + op.ifPresent(capabilityDefinition -> capabilityDefinition.setProperties(capPropsList)); + } + } + } + } + ); + } + Map<String, List<CapabilityDefinition>> componentCapabilities = component.getCapabilities(); + if(MapUtils.isNotEmpty(componentCapabilities)) { + mergeCapabilityMap(allCapabilities, componentCapabilities); } + component.setCapabilities(allCapabilities); + } + private static void mergeCapabilityMap(Map<String, List<CapabilityDefinition>> map1, + Map<String, List<CapabilityDefinition>> map2) { + map1.forEach((key1, val1) -> map2.forEach((key2, val2) -> { + if(key1.equals(key2)) { + val2.addAll(val1); + } + })); + map1.putAll(map2); } + private static Map<String, List<CapabilityDefinition>> groupCapabilityByType(Map<String, ListCapabilityDataDefinition> capabilities) { Map<String, List<CapabilityDefinition>> groupedCapabilities = new HashMap<>(); |