Service import issues
[sdc.git] / catalog-be / src / main / java / org / openecomp / sdc / be / components / impl / ServiceImportBusinessLogic.java
index 82add98..fff1ac5 100644 (file)
@@ -13,6 +13,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+
 package org.openecomp.sdc.be.components.impl;
 
 import static java.util.stream.Collectors.joining;
@@ -43,6 +44,7 @@ import java.util.Map.Entry;
 import java.util.Optional;
 import java.util.Set;
 import java.util.TreeSet;
+import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.concurrent.atomic.AtomicReference;
 import java.util.regex.Pattern;
 import java.util.stream.Collectors;
@@ -74,7 +76,6 @@ import org.openecomp.sdc.be.dao.api.ActionStatus;
 import org.openecomp.sdc.be.dao.janusgraph.JanusGraphDao;
 import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus;
 import org.openecomp.sdc.be.datamodel.utils.ArtifactUtils;
-import org.openecomp.sdc.be.datatypes.elements.ComponentInstanceDataDefinition;
 import org.openecomp.sdc.be.datatypes.elements.CustomYamlFunction;
 import org.openecomp.sdc.be.datatypes.elements.GetInputValueDataDefinition;
 import org.openecomp.sdc.be.datatypes.elements.ListCapabilityDataDefinition;
@@ -86,6 +87,7 @@ import org.openecomp.sdc.be.datatypes.elements.PolicyDataDefinition;
 import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
 import org.openecomp.sdc.be.datatypes.elements.SubPropertyToscaFunction;
 import org.openecomp.sdc.be.datatypes.elements.SubstitutionFilterPropertyDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.ToscaGetFunctionDataDefinition;
 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
 import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
 import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
@@ -201,16 +203,14 @@ public class ServiceImportBusinessLogic {
     private final IGraphLockOperation graphLockOperation;
     private final ToscaFunctionService toscaFunctionService;
     private final DataTypeBusinessLogic dataTypeBusinessLogic;
-    private ApplicationDataTypeCache applicationDataTypeCache;
     private final ArtifactTypeOperation artifactTypeOperation;
-
     private final GroupTypeImportManager groupTypeImportManager;
     private final GroupTypeOperation groupTypeOperation;
-    private InterfaceLifecycleOperation interfaceLifecycleTypeOperation;
-    private InterfaceLifecycleTypeImportManager interfaceLifecycleTypeImportManager;
-
     private final CapabilityTypeImportManager capabilityTypeImportManager;
     private final CapabilityTypeOperation capabilityTypeOperation;
+    private ApplicationDataTypeCache applicationDataTypeCache;
+    private InterfaceLifecycleOperation interfaceLifecycleTypeOperation;
+    private InterfaceLifecycleTypeImportManager interfaceLifecycleTypeImportManager;
 
     public ServiceImportBusinessLogic(final GroupBusinessLogic groupBusinessLogic, final ArtifactsBusinessLogic artifactsBusinessLogic,
                                       final ComponentsUtils componentsUtils, final ToscaOperationFacade toscaOperationFacade,
@@ -291,49 +291,47 @@ public class ServiceImportBusinessLogic {
     protected Service createServiceFromCsar(Service service, User user, Map<String, byte[]> csarUIPayload, String csarUUID) {
         log.trace("************* created successfully from YAML, resource TOSCA ");
         try {
-            ServiceCsarInfo csarInfo = csarBusinessLogic.getCsarInfo(service, null, user, csarUIPayload, csarUUID);
-
-            final Map<String, Object> dataTypesToCreate = getDatatypesToCreate(service.getModel(), csarInfo);
+            final ServiceCsarInfo csarInfo = csarBusinessLogic.getCsarInfo(service, null, user, csarUIPayload, csarUUID);
+            final String serviceModel = service.getModel();
+            final Map<String, Object> dataTypesToCreate = getDatatypesToCreate(serviceModel, csarInfo);
             if (MapUtils.isNotEmpty(dataTypesToCreate)) {
-                dataTypeBusinessLogic.createDataTypeFromYaml(new Yaml().dump(dataTypesToCreate), service.getModel(), true);
-                dataTypesToCreate.entrySet().stream().forEach(createdOrUpdatedDataType -> {
-                    applicationDataTypeCache.reload(service.getModel(),
-                        UniqueIdBuilder.buildDataTypeUid(service.getModel(), createdOrUpdatedDataType.getKey()));
-                });
+                dataTypeBusinessLogic.createDataTypeFromYaml(new Yaml().dump(dataTypesToCreate), serviceModel, true);
+                dataTypesToCreate.keySet().forEach(key ->
+                    applicationDataTypeCache.reload(serviceModel, UniqueIdBuilder.buildDataTypeUid(serviceModel, key))
+                );
             }
 
-            final Map<String, Object> artifactTypesToCreate = getArtifactTypesToCreate(service.getModel(), csarInfo);
+            final Map<String, Object> artifactTypesToCreate = getArtifactTypesToCreate(serviceModel, csarInfo);
             if (MapUtils.isNotEmpty(artifactTypesToCreate)) {
-                artifactTypeImportManager.createArtifactTypes(new Yaml().dump(artifactTypesToCreate), service.getModel(), true);
+                artifactTypeImportManager.createArtifactTypes(new Yaml().dump(artifactTypesToCreate), serviceModel, true);
             }
 
-            final List<NodeTypeDefinition> nodeTypesToCreate = getNodeTypesToCreate(service.getModel(), csarInfo);
+            final List<NodeTypeDefinition> nodeTypesToCreate = getNodeTypesToCreate(serviceModel, csarInfo);
             if (CollectionUtils.isNotEmpty(nodeTypesToCreate)) {
-                createNodeTypes(nodeTypesToCreate, service.getModel(), csarInfo.getModifier());
+                createNodeTypes(nodeTypesToCreate, serviceModel, csarInfo.getModifier());
             }
 
-            final Map<String, Object> groupTypesToCreate = getGroupTypesToCreate(service.getModel(), csarInfo);
+            final Map<String, Object> groupTypesToCreate = getGroupTypesToCreate(serviceModel, csarInfo);
             if (MapUtils.isNotEmpty(groupTypesToCreate)) {
                 final Map<String, ToscaTypeMetadata> toscaTypeMetadata = fillToscaTypeMetadata(groupTypesToCreate);
                 final ToscaTypeImportData toscaTypeImportData = new ToscaTypeImportData(new Yaml().dump(groupTypesToCreate), toscaTypeMetadata);
-                groupTypeImportManager.createGroupTypes(toscaTypeImportData, service.getModel(), true);
+                groupTypeImportManager.createGroupTypes(toscaTypeImportData, serviceModel, true);
             }
 
-            final Map<String, Object> interfaceTypesToCreate = getInterfaceTypesToCreate(service.getModel(), csarInfo);
+            final Map<String, Object> interfaceTypesToCreate = getInterfaceTypesToCreate(serviceModel, csarInfo);
             if (MapUtils.isNotEmpty(interfaceTypesToCreate)) {
-                interfaceLifecycleTypeImportManager
-                    .createLifecycleTypes(new Yaml().dump(interfaceTypesToCreate), service.getModel(), true);
+                interfaceLifecycleTypeImportManager.createLifecycleTypes(new Yaml().dump(interfaceTypesToCreate), serviceModel, true);
             }
 
-            final Map<String, Object> capabilityTypesToCreate = getCapabilityTypesToCreate(service.getModel(), csarInfo);
+            final Map<String, Object> capabilityTypesToCreate = getCapabilityTypesToCreate(serviceModel, csarInfo);
 
             if (MapUtils.isNotEmpty(capabilityTypesToCreate)) {
-                capabilityTypeImportManager.createCapabilityTypes(new Yaml().dump(capabilityTypesToCreate), service.getModel(), true);
+                capabilityTypeImportManager.createCapabilityTypes(new Yaml().dump(capabilityTypesToCreate), serviceModel, true);
             }
 
             Map<String, NodeTypeInfo> nodeTypesInfo = csarInfo.extractTypesInfo();
-            Either<Map<String, EnumMap<ArtifactOperationEnum, List<ArtifactDefinition>>>, ResponseFormat> findNodeTypesArtifactsToHandleRes = serviceImportParseLogic
-                .findNodeTypesArtifactsToHandle(nodeTypesInfo, csarInfo, service);
+            Either<Map<String, EnumMap<ArtifactOperationEnum, List<ArtifactDefinition>>>, ResponseFormat> findNodeTypesArtifactsToHandleRes
+                = serviceImportParseLogic.findNodeTypesArtifactsToHandle(nodeTypesInfo, csarInfo, service);
             if (findNodeTypesArtifactsToHandleRes.isRight()) {
                 log.debug("failed to find node types for update with artifacts during import csar {}. ", csarInfo.getCsarUUID());
                 throw new ComponentException(findNodeTypesArtifactsToHandleRes.right().value());
@@ -465,7 +463,7 @@ public class ServiceImportBusinessLogic {
         NodeTypesMetadataList nodeTypesMetadataList = new NodeTypesMetadataList();
         List<NodeTypeMetadata> nodeTypeMetadataList = new ArrayList<>();
         final Map<String, Object> allTypesToCreate = new HashMap<>();
-        nodeTypesToCreate.stream().forEach(nodeType -> {
+        nodeTypesToCreate.forEach(nodeType -> {
             allTypesToCreate.put(nodeType.getMappedNodeType().getKey(), nodeType.getMappedNodeType().getValue());
             nodeTypeMetadataList.add(nodeType.getNodeTypeMetadata());
         });
@@ -489,6 +487,9 @@ public class ServiceImportBusinessLogic {
                 Map<String, Object> combinedMappedToscaTemplate =
                     getNewChangesToToscaTemplate(newMappedToscaTemplate, (Map<String, Object>) existingMappedToscaTemplate.getValue());
                 if (!combinedMappedToscaTemplate.equals(existingMappedToscaTemplate.getValue())) {
+                    if (latestResource.getComponentMetadataDefinition().getMetadataDataDefinition().isNormative()) {
+                        nodeTypeDefinition.getNodeTypeMetadata().setNormative(true);
+                    }
                     existingMappedToscaTemplate.setValue(combinedMappedToscaTemplate);
                     nodeTypeDefinition.setMappedNodeType(existingMappedToscaTemplate);
                     namesOfNodeTypesToCreate.add(nodeTypeDefinition);
@@ -690,7 +691,8 @@ public class ServiceImportBusinessLogic {
             Map<String, InputDefinition> inputs = parsedToscaYamlInfo.getInputs();
             service = serviceImportParseLogic.createInputsOnService(service, inputs);
             log.trace("************* Finished to add inputs from yaml {}", yamlName);
-            ListDataDefinition<SubstitutionFilterPropertyDataDefinition> substitutionFilterProperties = parsedToscaYamlInfo.getSubstitutionFilterProperties();
+            ListDataDefinition<SubstitutionFilterPropertyDataDefinition> substitutionFilterProperties =
+                parsedToscaYamlInfo.getSubstitutionFilterProperties();
             service = serviceImportParseLogic.createSubstitutionFilterOnService(service, substitutionFilterProperties);
             log.trace("************* Added Substitution filter from interface yaml {}", yamlName);
             Map<String, UploadComponentInstanceInfo> uploadComponentInstanceInfoMap = parsedToscaYamlInfo.getInstances();
@@ -738,7 +740,7 @@ public class ServiceImportBusinessLogic {
                 throw new ComponentException(createArtifactsEither.right().value());
             }
             service = serviceImportParseLogic.getServiceWithGroups(createArtifactsEither.left().value().getUniqueId());
-            service = updateInputs(service, userId);
+            service = updateInputs(service, userId, parsedToscaYamlInfo.getSubstitutionMappingProperties());
 
             ASDCKpiApi.countCreatedResourcesKPI();
             return service;
@@ -755,79 +757,82 @@ public class ServiceImportBusinessLogic {
                 }
             }
             if (shouldLock) {
-                graphLockOperation.unlockComponentByName(service.getSystemName(), service.getUniqueId(), NodeTypeEnum.Resource);
+                graphLockOperation.unlockComponentByName(service.getSystemName(), service.getUniqueId(), NodeTypeEnum.Service);
             }
         }
     }
 
-    private Service updateInputs(final Service component, final String userId) {
+    private Service updateInputs(final Service component, final String userId, final Map<String, List<String>> substitutionMappingProperties) {
         final List<InputDefinition> inputs = component.getInputs();
-        final List<ComponentInstance> componentInstances = component.getComponentInstances();
-        final String componentUniqueId = component.getUniqueId();
-        final Map<String, List<ComponentInstanceProperty>> componentInstancesProperties = component.getComponentInstancesProperties();
-        for (final InputDefinition input : inputs) {
-            if (isInputFromComponentInstanceProperty(input.getName(), componentInstances, componentInstancesProperties)) {
-                associateInputToComponentInstanceProperty(userId, input, componentInstances, componentInstancesProperties,
-                    componentUniqueId);
-            } else {
-                associateInputToServiceProperty(userId, input, component);
+        if (CollectionUtils.isNotEmpty(inputs)) {
+            final List<ComponentInstance> componentInstances = component.getComponentInstances();
+            final String componentUniqueId = component.getUniqueId();
+            for (final InputDefinition input : inputs) {
+                boolean isSubMapProp = false;
+                if (substitutionMappingProperties != null && !substitutionMappingProperties.isEmpty()) {
+                    isSubMapProp = substitutionMappingProperties.entrySet().stream()
+                        .anyMatch(stringEntry -> stringEntry.getValue().get(0).equals(input.getName()));
+                }
+                if (!isSubMapProp && isInputFromComponentInstanceProperty(input.getName(), componentInstances)) {
+                    associateInputToComponentInstanceProperty(userId, input, componentInstances, componentUniqueId);
+                } else {
+                    associateInputToServiceProperty(userId, input, component, substitutionMappingProperties);
+                }
+            }
+            Either<List<InputDefinition>, StorageOperationStatus> either = toscaOperationFacade.updateInputsToComponent(inputs, componentUniqueId);
+            if (either.isRight()) {
+                throw new ComponentException(ActionStatus.GENERAL_ERROR);
             }
-
-        }
-
-        final Either<List<InputDefinition>, StorageOperationStatus> either
-            = toscaOperationFacade.updateInputsToComponent(inputs, componentUniqueId);
-        if (either.isRight()) {
-            throw new ComponentException(ActionStatus.GENERAL_ERROR);
         }
 
         return component;
     }
 
-    private boolean isInputFromComponentInstanceProperty(final String inputName, final List<ComponentInstance> componentInstances,
-                                                         final Map<String, List<ComponentInstanceProperty>> componentInstancesProperties) {
+    private boolean isInputFromComponentInstanceProperty(final String inputName, final List<ComponentInstance> componentInstances) {
+
+        AtomicBoolean isInputFromCIProp = new AtomicBoolean(false);
         if (CollectionUtils.isNotEmpty(componentInstances)) {
-            // get instance's names
-            final List<String> componentInstancesNames = componentInstances.stream().map(ComponentInstanceDataDefinition::getNormalizedName)
-                .collect(toList());
-            final Optional<String> componentInstancesNameOptional = componentInstancesNames.stream()
-                .filter(cin -> inputName.startsWith(cin + "_")).findFirst();
-            if (componentInstancesNameOptional.isPresent() && MapUtils.isNotEmpty(componentInstancesProperties)) {
-                final Optional<String> componentInstanceIdOptional = componentInstancesProperties.keySet().stream()
-                    .filter(key -> key.endsWith("." + componentInstancesNameOptional.get())).findFirst();
-                if (componentInstanceIdOptional.isPresent()) {
-                    // get property's name
-                    final String propertyNameFromInput = extractPropertyNameFromInputName(inputName, componentInstancesNames);
-                    return componentInstancesProperties.get(componentInstanceIdOptional.get()).stream()
-                        .anyMatch(prop -> prop.getName().equals(propertyNameFromInput) && prop.getValue() != null
-                            && prop.getValue().contains(ToscaGetFunctionType.GET_INPUT.getFunctionName()));
+            outer:
+            for (ComponentInstance instance : componentInstances) {
+                for (PropertyDefinition instanceProperty : instance.getProperties()) {
+                    if (CollectionUtils.isNotEmpty(instanceProperty.getGetInputValues())) {
+                        for (GetInputValueDataDefinition getInputValueDataDefinition : instanceProperty.getGetInputValues()) {
+                            if (inputName.equals(getInputValueDataDefinition.getInputName())) {
+                                isInputFromCIProp.set(true);
+                                break outer;
+                            }
+                        }
+                    }
                 }
             }
         }
-        return false;
+        return isInputFromCIProp.get();
     }
 
     private void associateInputToComponentInstanceProperty(final String userId, final InputDefinition input,
                                                            final List<ComponentInstance> componentInstances,
-                                                           final Map<String, List<ComponentInstanceProperty>> componentInstancesProperties,
                                                            String componentUniqueId) {
-        // From Instance
-        final List<String> componentInstancesNames = componentInstances.stream().map(ComponentInstanceDataDefinition::getNormalizedName)
-            .collect(toList());
-        final String propertyNameFromInput = extractPropertyNameFromInputName(input.getName(), componentInstancesNames);
-
-        final Optional<String> componentInstancesNameOptional = componentInstancesNames.stream()
-            .filter(cin -> input.getName().startsWith(cin + "_")).findFirst();
 
-        final Optional<String> componentInstanceIdOptional = componentInstancesProperties.keySet().stream()
-            .filter(key -> key.endsWith("." + componentInstancesNameOptional.get())).findFirst();
-
-        final String componentInstanceId = componentInstanceIdOptional.get();
-        final List<ComponentInstanceProperty> componentInstanceProperties = componentInstancesProperties.get(componentInstanceId);
+        String componentInstanceId = null;
+        ComponentInstanceProperty componentInstanceProperty = new ComponentInstanceProperty();
+
+        outer:
+        for (ComponentInstance instance : componentInstances) {
+            for (PropertyDefinition instanceProperty : instance.getProperties()) {
+                if (CollectionUtils.isNotEmpty(instanceProperty.getGetInputValues())) {
+                    for (GetInputValueDataDefinition getInputValueDataDefinition : instanceProperty.getGetInputValues()) {
+                        if (input.getName().equals(getInputValueDataDefinition.getInputName())) {
+                            componentInstanceId = instance.getUniqueId();
+                            componentInstanceProperty = new ComponentInstanceProperty(instanceProperty);
+                            break outer;
+                        }
+                    }
+                }
+            }
+        }
 
-        final ComponentInstanceProperty componentInstanceProperty = componentInstanceProperties.stream()
-            .filter(prop -> prop.getName().equals(propertyNameFromInput) && prop.getValue() != null
-                && prop.getValue().contains(ToscaGetFunctionType.GET_INPUT.getFunctionName())).findFirst().get();
+        //unmapping instance property declared inputs from substitution mapping
+        input.setMappedToComponentProperty(false);
 
         // From Instance
         updateInput(input, componentInstanceProperty, userId, componentInstanceId);
@@ -841,12 +846,20 @@ public class ServiceImportBusinessLogic {
     }
 
     private void associateInputToServiceProperty(final String userId,
-                                                 final InputDefinition input, final Service component) {
+                                                 final InputDefinition input, final Service component,
+                                                 final Map<String, List<String>> substitutionMappingProperties) {
         final List<PropertyDefinition> properties = component.getProperties();
-        if (CollectionUtils.isNotEmpty(properties)) {
-            final String propertyNameFromInput = input.getName();
-            final Optional<PropertyDefinition> propDefOptional = properties.stream().filter(prop -> prop.getName().equals(propertyNameFromInput))
-                .findFirst();
+        if (CollectionUtils.isNotEmpty(properties) && MapUtils.isNotEmpty(substitutionMappingProperties)) {
+            AtomicReference<String> propertyNameFromInput = new AtomicReference<>(" ");
+            substitutionMappingProperties.entrySet().forEach(stringEntry -> {
+                if (stringEntry.getValue().get(0).equals(input.getName())) {
+                    propertyNameFromInput.set(stringEntry.getKey());
+                }
+            });
+
+            final Optional<PropertyDefinition> propDefOptional =
+                properties.stream().filter(prop -> prop.getName().equals(propertyNameFromInput.get()))
+                    .findFirst();
             if (propDefOptional.isPresent()) {
                 // From SELF
                 final String componentUniqueId = component.getUniqueId();
@@ -862,6 +875,8 @@ public class ServiceImportBusinessLogic {
                 if (either.isRight()) {
                     throw new ComponentException(ActionStatus.GENERAL_ERROR);
                 }
+            } else {
+                input.setMappedToComponentProperty(false);
             }
         }
     }
@@ -884,12 +899,6 @@ public class ServiceImportBusinessLogic {
         input.setParentPropertyType(propertyDefinition.getType());
     }
 
-    private String extractPropertyNameFromInputName(final String inputName, final List<String> componentInstancesNames) {
-        final AtomicReference<String> result = new AtomicReference<>(inputName);
-        componentInstancesNames.forEach(cin -> result.set(result.get().replace(cin + "_", "")));
-        return result.get();
-    }
-
     protected Either<Resource, ResponseFormat> createOrUpdateArtifacts(ArtifactsBusinessLogic.ArtifactOperationEnum operation,
                                                                        List<ArtifactDefinition> createdArtifacts, String yamlFileName,
                                                                        CsarInfo csarInfo, Resource preparedResource,
@@ -897,8 +906,9 @@ public class ServiceImportBusinessLogic {
                                                                        boolean inTransaction, boolean shouldLock) {
         String nodeName = nodeTypeInfoToUpdateArtifacts.getNodeName();
         Resource resource = preparedResource;
-        Map<String, EnumMap<ArtifactsBusinessLogic.ArtifactOperationEnum, List<ArtifactDefinition>>> nodeTypesArtifactsToHandle = nodeTypeInfoToUpdateArtifacts
-            .getNodeTypesArtifactsToHandle();
+        Map<String, EnumMap<ArtifactsBusinessLogic.ArtifactOperationEnum, List<ArtifactDefinition>>> nodeTypesArtifactsToHandle =
+            nodeTypeInfoToUpdateArtifacts
+                .getNodeTypesArtifactsToHandle();
         if (preparedResource.getResourceType() == ResourceTypeEnum.VF) {
             if (nodeName != null && nodeTypesArtifactsToHandle.get(nodeName) != null && !nodeTypesArtifactsToHandle.get(nodeName).isEmpty()) {
                 Either<List<ArtifactDefinition>, ResponseFormat> handleNodeTypeArtifactsRes = handleNodeTypeArtifacts(preparedResource,
@@ -1025,7 +1035,8 @@ public class ServiceImportBusinessLogic {
                 vfCsarArtifactsToHandle = new EnumMap<>(ArtifactsBusinessLogic.ArtifactOperationEnum.class);
                 vfCsarArtifactsToHandle.put(artifactOperation.getArtifactOperationEnum(), artifactPathAndNameList.left().value());
             } else {
-                Either<EnumMap<ArtifactsBusinessLogic.ArtifactOperationEnum, List<CsarUtils.NonMetaArtifactInfo>>, ResponseFormat> findVfCsarArtifactsToHandleRes = findVfCsarArtifactsToHandle(
+                Either<EnumMap<ArtifactsBusinessLogic.ArtifactOperationEnum, List<CsarUtils.NonMetaArtifactInfo>>, ResponseFormat>
+                    findVfCsarArtifactsToHandleRes = findVfCsarArtifactsToHandle(
                     component, artifactPathAndNameList.left().value(), csarInfo.getModifier());
                 if (findVfCsarArtifactsToHandleRes.isRight()) {
                     resStatus = Either.right(findVfCsarArtifactsToHandleRes.right().value());
@@ -1316,7 +1327,8 @@ public class ServiceImportBusinessLogic {
         EnumMap<ArtifactsBusinessLogic.ArtifactOperationEnum, List<CsarUtils.NonMetaArtifactInfo>> nodeTypeArtifactsToHandle = new EnumMap<>(
             ArtifactsBusinessLogic.ArtifactOperationEnum.class);
         Wrapper<ResponseFormat> responseWrapper = new Wrapper<>();
-        Either<EnumMap<ArtifactsBusinessLogic.ArtifactOperationEnum, List<CsarUtils.NonMetaArtifactInfo>>, ResponseFormat> nodeTypeArtifactsToHandleRes = Either
+        Either<EnumMap<ArtifactsBusinessLogic.ArtifactOperationEnum, List<CsarUtils.NonMetaArtifactInfo>>, ResponseFormat>
+            nodeTypeArtifactsToHandleRes = Either
             .left(nodeTypeArtifactsToHandle);
         try {
             List<CsarUtils.NonMetaArtifactInfo> artifactsToUpload = new ArrayList<>(artifactPathAndNameList);
@@ -1851,11 +1863,12 @@ public class ServiceImportBusinessLogic {
         log.debug("************* Going to create all nodes {}", yamlName);
         handleServiceNodeTypes(yamlName, service, topologyTemplateYaml, false, nodeTypesArtifactsToCreate, nodeTypesNewCreatedArtifacts,
             nodeTypesInfo, csarInfo, nodeName);
+        List<PropertyDefinition> serviceProperties = null != service ? service.getProperties() : Collections.emptyList();
         if (MapUtils.isNotEmpty(uploadComponentInstanceInfoMap)) {
             log.debug("************* Going to create all resource instances {}", yamlName);
             service = createServiceInstances(yamlName, service, uploadComponentInstanceInfoMap, csarInfo.getCreatedNodes());
             log.debug("************* Going to create all relations {}", yamlName);
-            service = createServiceInstancesRelations(csarInfo.getModifier(), yamlName, service, uploadComponentInstanceInfoMap);
+            service = createServiceInstancesRelations(csarInfo.getModifier(), yamlName, service, uploadComponentInstanceInfoMap, serviceProperties);
             log.debug("************* Going to create positions {}", yamlName);
             compositionBusinessLogic.setPositionsForComponentInstances(service, csarInfo.getModifier().getUserId());
             log.debug("************* Finished to set positions {}", yamlName);
@@ -1864,7 +1877,8 @@ public class ServiceImportBusinessLogic {
     }
 
     protected Service createServiceInstancesRelations(User user, String yamlName, Service service,
-                                                      Map<String, UploadComponentInstanceInfo> uploadResInstancesMap) {
+                                                      Map<String, UploadComponentInstanceInfo> uploadResInstancesMap,
+                                                      List<PropertyDefinition> serviceProperties) {
         log.debug("#createResourceInstancesRelations - Going to create relations ");
         List<ComponentInstance> componentInstancesList = service.getComponentInstances();
         if (MapUtils.isEmpty(uploadResInstancesMap) || CollectionUtils.isEmpty(componentInstancesList)) { // PNF can have no resource instances
@@ -1892,6 +1906,7 @@ public class ServiceImportBusinessLogic {
             final Map<String, DataTypeDefinition> allDataTypesMap =
                 componentsUtils.getAllDataTypes(applicationDataTypeCache, service.getModel());
             final Service service1 = service;
+            service1.setProperties(serviceProperties);
             uploadResInstancesMap.values().forEach(
                 i -> processComponentInstance(yamlName, service1, componentInstancesList,
                     allDataTypesMap, instProperties,
@@ -2293,6 +2308,17 @@ public class ServiceImportBusinessLogic {
                     //Inputs
                     ListDataDefinition<OperationInputDefinition> instanceInputs = instanceOperation.getInputs();
                     mergeOperationInputDefinitions(templateOperation.getInputs(), instanceInputs);
+                    if (null != instanceInputs) {
+                        component.getProperties()
+                            .forEach(property -> instanceInputs.getListToscaDataDefinition().stream()
+                                .filter(instanceInput ->
+                                    instanceInput.getToscaFunction() instanceof ToscaGetFunctionDataDefinition &&
+                                        property.getName().equals(instanceInput.getToscaFunction() != null ?
+                                            ((ToscaGetFunctionDataDefinition) instanceInput.getToscaFunction()).getPropertyName() :
+                                            null))
+                                .forEach(oldInput -> oldInput.setType(property.getType()))
+                            );
+                    }
                     templateOperation.setInputs(instanceInputs);
                     //Implementation
                     templateOperation.setImplementation(instanceOperation.getImplementation());
@@ -2675,7 +2701,8 @@ public class ServiceImportBusinessLogic {
             if (nodeNamespaceMap.containsKey(uploadComponentInstanceInfo.getType())) {
                 uploadComponentInstanceInfo.setType(nodeNamespaceMap.get(uploadComponentInstanceInfo.getType()).getToscaResourceName());
             }
-            Resource refResource = validateResourceInstanceBeforeCreate(yamlName, uploadComponentInstanceInfo, existingnodeTypeMap);
+            Resource refResource =
+                validateResourceInstanceBeforeCreate(yamlName, component.getModel(), uploadComponentInstanceInfo, existingnodeTypeMap);
             ComponentInstance componentInstance = new ComponentInstance();
             componentInstance.setComponentUid(refResource.getUniqueId());
             Collection<String> directives = uploadComponentInstanceInfo.getDirectives();
@@ -2706,27 +2733,32 @@ public class ServiceImportBusinessLogic {
             Resource origResource = existingnodeTypeMap.get(uploadComponentInstanceInfo.getType());
             componentInstance.setName(uploadComponentInstanceInfo.getName());
             componentInstance.setIcon(origResource.getIcon());
+            componentInstance.setMinOccurrences(uploadComponentInstanceInfo.getMinOccurrences());
+            componentInstance.setMaxOccurrences(uploadComponentInstanceInfo.getMaxOccurrences());
+            componentInstance.setInstanceCount(uploadComponentInstanceInfo.getInstanceCount());
             resourcesInstancesMap.put(componentInstance, origResource);
-        } catch (Exception e) {
+        } catch (final ComponentException e) {
+            throw e;
+        } catch (final Exception e) {
             throw new ComponentException(ActionStatus.GENERAL_ERROR, e.getMessage());
         }
     }
 
-    protected Resource validateResourceInstanceBeforeCreate(String yamlName, UploadComponentInstanceInfo uploadComponentInstanceInfo,
+    protected Resource validateResourceInstanceBeforeCreate(String yamlName, String model, UploadComponentInstanceInfo uploadComponentInstanceInfo,
                                                             Map<String, Resource> nodeNamespaceMap) {
         Resource refResource;
         try {
             if (nodeNamespaceMap.containsKey(uploadComponentInstanceInfo.getType())) {
                 refResource = nodeNamespaceMap.get(uploadComponentInstanceInfo.getType());
             } else {
-                Either<Resource, StorageOperationStatus> findResourceEither = toscaOperationFacade
-                    .getLatestResourceByToscaResourceName(uploadComponentInstanceInfo.getType());
-                if (findResourceEither.isRight()) {
+                final Either<Component, StorageOperationStatus> resourceEither =
+                    toscaOperationFacade.getLatestByToscaResourceName(uploadComponentInstanceInfo.getType(), model);
+                if (resourceEither.isRight()) {
                     ResponseFormat responseFormat = componentsUtils
-                        .getResponseFormat(componentsUtils.convertFromStorageResponse(findResourceEither.right().value()));
+                        .getResponseFormat(componentsUtils.convertFromStorageResponse(resourceEither.right().value()));
                     throw new ComponentException(responseFormat);
                 }
-                refResource = findResourceEither.left().value();
+                refResource = (Resource) resourceEither.left().value();
                 nodeNamespaceMap.put(refResource.getToscaResourceName(), refResource);
             }
             String componentState = refResource.getComponentMetadataDefinition().getMetadataDataDefinition().getState();
@@ -2744,7 +2776,9 @@ public class ServiceImportBusinessLogic {
                 throw new ComponentException(responseFormat);
             }
             return refResource;
-        } catch (Exception e) {
+        } catch (final ComponentException e) {
+            throw e;
+        } catch (final Exception e) {
             throw new ComponentException(ActionStatus.GENERAL_ERROR, e.getMessage());
         }
     }