diff options
author | MichaelMorris <michael.morris@est.tech> | 2022-01-21 21:18:01 +0000 |
---|---|---|
committer | Andr� Schmid <andre.schmid@est.tech> | 2022-01-24 18:50:46 +0000 |
commit | d77bdf472a4fb5b6cf8e17f2d0d8e8d2bababeaf (patch) | |
tree | aeedcacfeb7a7b6c4466aed6a9f55340591d8596 | |
parent | 03df024d4f9ace16307f380bdb5c131dd896f3db (diff) |
Fix issues creating control loop model
Change-Id: I38812f812fdf082aaadf13b79b8b05d26a481b15
Issue-ID: SDC-3856
Signed-off-by: MichaelMorris <michael.morris@est.tech>
7 files changed, 34 insertions, 17 deletions
diff --git a/catalog-be/src/main/docker/backend/chef-repo/cookbooks/sdc-catalog-be/templates/default/BE-configuration.yaml.erb b/catalog-be/src/main/docker/backend/chef-repo/cookbooks/sdc-catalog-be/templates/default/BE-configuration.yaml.erb index aa9d3f275b..974fc009ed 100644 --- a/catalog-be/src/main/docker/backend/chef-repo/cookbooks/sdc-catalog-be/templates/default/BE-configuration.yaml.erb +++ b/catalog-be/src/main/docker/backend/chef-repo/cookbooks/sdc-catalog-be/templates/default/BE-configuration.yaml.erb @@ -189,6 +189,7 @@ componentAllowedInstanceTypes: Service: "*": - VF + - VFC - CR - CP - PNF 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 ebfb4c5851..ca4002f26a 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 @@ -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()); } 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 b6bd2a3967..ef63a86d39 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 @@ -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()); diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogicTest.java index 99034f7785..8499dad5dc 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogicTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogicTest.java @@ -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); diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/config/ContainerInstanceTypesData.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/config/ContainerInstanceTypesData.java index 341d5222a1..a355aa9607 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/config/ContainerInstanceTypesData.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/config/ContainerInstanceTypesData.java @@ -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. diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaOperationFacade.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaOperationFacade.java index 2dcc4362d9..d477b8ce6a 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaOperationFacade.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaOperationFacade.java @@ -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); diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/config/ContainerInstanceTypesDataTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/config/ContainerInstanceTypesDataTest.java index 5df79146c4..8a038c8791 100644 --- a/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/config/ContainerInstanceTypesDataTest.java +++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/config/ContainerInstanceTypesDataTest.java @@ -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)); } } |