Fix issues creating control loop model 14/126714/3
authorMichaelMorris <michael.morris@est.tech>
Fri, 21 Jan 2022 21:18:01 +0000 (21:18 +0000)
committerAndr� Schmid <andre.schmid@est.tech>
Mon, 24 Jan 2022 18:50:46 +0000 (18:50 +0000)
Change-Id: I38812f812fdf082aaadf13b79b8b05d26a481b15
Issue-ID: SDC-3856
Signed-off-by: MichaelMorris <michael.morris@est.tech>
catalog-be/src/main/docker/backend/chef-repo/cookbooks/sdc-catalog-be/templates/default/BE-configuration.yaml.erb
catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogic.java
catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java
catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogicTest.java
catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/config/ContainerInstanceTypesData.java
catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaOperationFacade.java
catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/config/ContainerInstanceTypesDataTest.java

index ebfb4c5..ca4002f 100644 (file)
@@ -637,7 +637,7 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic {
     private void validateOriginComponentIsValidForContainer(Component containerComponent, ResourceTypeEnum resourceType) {
         switch (containerComponent.getComponentType()) {
             case SERVICE:
-                if (!containerInstanceTypesData.isAllowedForServiceComponent(resourceType)) {
+                if (!containerInstanceTypesData.isAllowedForServiceComponent(resourceType, containerComponent.getModel())) {
                     throw new ByActionStatusComponentException(ActionStatus.CONTAINER_CANNOT_CONTAIN_INSTANCE,
                         containerComponent.getComponentType().toString(), resourceType.name());
                 }
index b6bd2a3..ef63a86 100644 (file)
@@ -765,13 +765,15 @@ public class ToscaExportHandler {
         ToscaNodeType toscaNodeType = createNodeType(component);
         Either<Map<String, InterfaceDefinition>, StorageOperationStatus> lifecycleTypeEither = interfaceLifecycleOperation
             .getAllInterfaceLifecycleTypes(component.getModel());
-        if (lifecycleTypeEither.isRight()) {
+        if (lifecycleTypeEither.isRight() && !StorageOperationStatus.NOT_FOUND.equals(lifecycleTypeEither.right().value())) {
             log.debug("Failed to fetch all interface types :", lifecycleTypeEither.right().value());
             return Either.right(ToscaError.GENERAL_ERROR);
         }
-        List<String> allGlobalInterfaceTypes = lifecycleTypeEither.left().value().values().stream().map(InterfaceDataDefinition::getType)
-            .collect(Collectors.toList());
-        toscaNode.setInterface_types(addInterfaceTypeElement(component, allGlobalInterfaceTypes));
+        if (lifecycleTypeEither.isLeft()) {
+            List<String> allGlobalInterfaceTypes = lifecycleTypeEither.left().value().values().stream().map(InterfaceDataDefinition::getType)
+                .collect(Collectors.toList());
+            toscaNode.setInterface_types(addInterfaceTypeElement(component, allGlobalInterfaceTypes));
+        }
         Either<Map<String, DataTypeDefinition>, JanusGraphOperationStatus> dataTypesEither = applicationDataTypeCache.getAll(component.getModel());
         if (dataTypesEither.isRight()) {
             log.debug("Failed to fetch all data types :", dataTypesEither.right().value());
index 99034f7..8499dad 100644 (file)
@@ -1726,14 +1726,14 @@ class ComponentInstanceBusinessLogicTest {
         when(toscaOperationFacade.getToscaFullElement(eq(ORIGIN_COMPONENT_ID)))
             .thenReturn(Either.left(originComponent));
         // Assume services cannot contain VF resource
-        when(containerInstanceTypeData.isAllowedForServiceComponent(eq(ResourceTypeEnum.VF)))
+        when(containerInstanceTypeData.isAllowedForServiceComponent(eq(ResourceTypeEnum.VF), eq(null)))
             .thenReturn(false);
 
         ByActionStatusComponentException actualException = assertThrows(ByActionStatusComponentException.class, () -> {
             componentInstanceBusinessLogic.createComponentInstance(ComponentTypeEnum.SERVICE_PARAM_NAME, COMPONENT_ID, USER_ID, ci);
         });
         assertThat(actualException.getActionStatus()).isEqualTo(ActionStatus.CONTAINER_CANNOT_CONTAIN_INSTANCE);
-        verify(containerInstanceTypeData, times(1)).isAllowedForServiceComponent(eq(ResourceTypeEnum.VF));
+        verify(containerInstanceTypeData, times(1)).isAllowedForServiceComponent(eq(ResourceTypeEnum.VF), eq(null));
 
         //given
         final Resource resource = createResource();
@@ -1765,7 +1765,7 @@ class ComponentInstanceBusinessLogicTest {
             .thenReturn(Either.left(service));
         when(toscaOperationFacade.getToscaFullElement(eq(ORIGIN_COMPONENT_ID)))
             .thenReturn(Either.left(originComponent));
-        when(containerInstanceTypeData.isAllowedForServiceComponent(eq(ResourceTypeEnum.VF)))
+        when(containerInstanceTypeData.isAllowedForServiceComponent(eq(ResourceTypeEnum.VF), eq(null)))
             .thenReturn(true);
         Mockito.doNothing().when(compositionBusinessLogic).validateAndSetDefaultCoordinates(ci);
         when(graphLockOperation.lockComponent(COMPONENT_ID, NodeTypeEnum.Service))
@@ -1784,7 +1784,7 @@ class ComponentInstanceBusinessLogicTest {
             componentInstanceBusinessLogic.createComponentInstance(ComponentTypeEnum.SERVICE_PARAM_NAME, COMPONENT_ID, USER_ID, ci);
         });
         verify(containerInstanceTypeData, times(1))
-            .isAllowedForServiceComponent(eq(ResourceTypeEnum.VF));
+            .isAllowedForServiceComponent(eq(ResourceTypeEnum.VF), eq(null));
         verify(compositionBusinessLogic, times(1)).validateAndSetDefaultCoordinates(ci);
         verify(toscaOperationFacade, times(1))
             .addComponentInstanceToTopologyTemplate(service, originComponent, ci, false, user);
@@ -1807,7 +1807,7 @@ class ComponentInstanceBusinessLogicTest {
             .thenReturn(Either.left(service));
         when(toscaOperationFacade.getToscaFullElement(eq(ORIGIN_COMPONENT_ID)))
             .thenReturn(Either.left(originComponent));
-        when(containerInstanceTypeData.isAllowedForServiceComponent(eq(ResourceTypeEnum.VF)))
+        when(containerInstanceTypeData.isAllowedForServiceComponent(eq(ResourceTypeEnum.VF), eq(null)))
             .thenReturn(true);
         Mockito.doNothing().when(compositionBusinessLogic).validateAndSetDefaultCoordinates(instanceToBeCreated);
         when(graphLockOperation.lockComponent(COMPONENT_ID, NodeTypeEnum.Service))
@@ -1830,7 +1830,7 @@ class ComponentInstanceBusinessLogicTest {
         assertThat(instanceToBeCreated.getComponentVersion()).isEqualTo(originComponent.getVersion());
         assertThat(instanceToBeCreated.getIcon()).isEqualTo(originComponent.getIcon());
         verify(containerInstanceTypeData, times(1))
-            .isAllowedForServiceComponent(eq(ResourceTypeEnum.VF));
+            .isAllowedForServiceComponent(eq(ResourceTypeEnum.VF), eq(null));
         verify(compositionBusinessLogic, times(1)).validateAndSetDefaultCoordinates(instanceToBeCreated);
         verify(toscaOperationFacade, times(1))
             .addComponentInstanceToTopologyTemplate(service, originComponent, instanceToBeCreated, false, user);
index 341d522..a355aa9 100644 (file)
@@ -47,8 +47,8 @@ public class ContainerInstanceTypesData {
      * @param resourceTypeToCheck the resource instance type that will be added to the container component
      * @return {@code true} if the resource instance is allowed, {@code false} otherwise
      */
-    public boolean isAllowedForServiceComponent(final ResourceTypeEnum resourceTypeToCheck) {
-        final List<String> allowedResourceInstanceTypeList = getComponentAllowedList(ComponentTypeEnum.SERVICE, null);
+    public boolean isAllowedForServiceComponent(final ResourceTypeEnum resourceTypeToCheck, final String modelName) {
+        final List<String> allowedResourceInstanceTypeList = getServiceAllowedList(modelName);
         if (CollectionUtils.isEmpty(allowedResourceInstanceTypeList)) {
             return false;
         }
@@ -69,6 +69,20 @@ public class ContainerInstanceTypesData {
         }
         return allowedResourceInstanceTypeList.contains(resourceToCheck.getValue());
     }
+    
+    /**
+     * Gets the list of allowed component instances for a service of the given model.
+     *
+     * @param model the model 
+     * @return the list of allowed component instances
+     */
+    public List<String> getServiceAllowedList(final String modelName) {
+        List<String> allowedInstanceResourceType = getComponentAllowedList(ComponentTypeEnum.SERVICE, null);
+        if (modelName == null || modelName.isEmpty() || modelName.equals("SDC AID")){
+            allowedInstanceResourceType.remove("VFC");
+        }
+        return allowedInstanceResourceType;
+    }
 
     /**
      * Gets the list of allowed component instances for a component type.
index 2dcc436..d477b8c 100644 (file)
@@ -2150,11 +2150,11 @@ public class ToscaOperationFacade {
     }
 
     private void fillNodeTypePropsMap(final Map<GraphPropertyEnum, Object> hasProps, final Map<GraphPropertyEnum, Object> hasNotProps,
-                                      final String internalComponentType) {
+                                      final String internalComponentType, String modelName) {
         final Configuration configuration = ConfigurationManager.getConfigurationManager().getConfiguration();
         final List<String> allowedTypes;
         if (ComponentTypeEnum.SERVICE.getValue().equalsIgnoreCase(internalComponentType)) {
-            allowedTypes = containerInstanceTypesData.getComponentAllowedList(ComponentTypeEnum.SERVICE, null);
+            allowedTypes = containerInstanceTypesData.getServiceAllowedList(modelName);
         } else {
             final ResourceTypeEnum resourceType = ResourceTypeEnum.getTypeIgnoreCase(internalComponentType);
             allowedTypes = containerInstanceTypesData.getComponentAllowedList(ComponentTypeEnum.RESOURCE, resourceType);
@@ -2197,7 +2197,7 @@ public class ToscaOperationFacade {
         if (VertexTypeEnum.NODE_TYPE == internalVertexType) {
             hasProps.put(GraphPropertyEnum.IS_ABSTRACT, isAbstract);
             if (internalComponentType != null) {
-                fillNodeTypePropsMap(hasProps, hasNotProps, internalComponentType);
+                fillNodeTypePropsMap(hasProps, hasNotProps, internalComponentType, modelName);
             }
         } else {
             fillTopologyTemplatePropsMap(hasProps, hasNotProps, componentTypeEnum);
index 5df7914..8a038c8 100644 (file)
@@ -124,7 +124,7 @@ public class ContainerInstanceTypesDataTest {
     public void isAllowedForServiceComponent() {
         for (final ResourceTypeEnum allowedType : serviceAllowedTypes) {
             assertThat(String.format("%s should be allowed", allowedType.getValue()),
-                containerInstanceTypesData.isAllowedForServiceComponent(allowedType), is(true));
+                containerInstanceTypesData.isAllowedForServiceComponent(allowedType, ""), is(true));
         }
     }