Service:
"*":
- VF
+ - VFC
- CR
- CP
- PNF
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());
}
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());
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();
.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))
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);
.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))
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);
* @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;
}
}
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.
}
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);
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);
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));
}
}