aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-be/src/main/java
diff options
context:
space:
mode:
authorandre.schmid <andre.schmid@est.tech>2020-03-04 16:28:05 +0000
committerJulien Bertozzi <julien.bertozzi@intl.att.com>2020-07-29 11:39:50 +0000
commit5e8464585f07210ad4b20ddfee2c23b1cf2d8b2a (patch)
treed0e9b828f0b374f504115443814537deb35d49c1 /catalog-be/src/main/java
parent18a43d537bc91d752377159fb0d5b3e9f5bdd6e5 (diff)
Config. allowed instances in component composition
During the creation of Resource and Services components, the allowed types to add in its composition are hard-coded. This change allows those types to be configurable using the configuration.yaml backend file. Change-Id: If48849b57fe5124468db3d55f2f06391348935fb Issue-ID: SDC-3177 Signed-off-by: andre.schmid <andre.schmid@est.tech>
Diffstat (limited to 'catalog-be/src/main/java')
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogic.java107
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/utils/ContainerInstanceTypesData.java62
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ComponentInstanceServlet.java26
3 files changed, 68 insertions, 127 deletions
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 e9fc6a04cc..b0c9b308ab 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
@@ -61,7 +61,7 @@ import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus;
import org.openecomp.sdc.be.dao.jsongraph.types.JsonParseFlagEnum;
import org.openecomp.sdc.be.dao.neo4j.GraphPropertiesDictionary;
-import org.openecomp.sdc.be.datamodel.utils.ContainerInstanceTypesData;
+import org.openecomp.sdc.be.model.jsonjanusgraph.config.ContainerInstanceTypesData;
import org.openecomp.sdc.be.datatypes.elements.CINodeFilterDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.CapabilityDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.ForwardingPathDataDefinition;
@@ -184,7 +184,7 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic {
private ContainerInstanceTypesData containerInstanceTypesData;
public ComponentInstance createComponentInstance(String containerComponentParam, String containerComponentId, String userId, ComponentInstance resourceInstance) {
- return createComponentInstance(containerComponentParam, containerComponentId, userId, resourceInstance, false, true);
+ return createComponentInstance(containerComponentParam, containerComponentId, userId, resourceInstance, true);
}
public List<ComponentInstanceProperty> getComponentInstancePropertiesByInputId(org.openecomp.sdc.be.model.Component component, String inputId){
@@ -324,55 +324,54 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic {
}
}
- public ComponentInstance createComponentInstance(String containerComponentParam, String containerComponentId, String userId, ComponentInstance resourceInstance, boolean inTransaction, boolean needLock) {
-
- Component origComponent = null;
- User user;
- org.openecomp.sdc.be.model.Component containerComponent = null;
- ComponentTypeEnum containerComponentType;
- try {
- user = validateUserExists(userId);
- validateUserNotEmpty(user, "Create component instance");
- validateJsonBody(resourceInstance, ComponentInstance.class);
- containerComponentType = validateComponentType(containerComponentParam);
- containerComponent = validateComponentExists(containerComponentId, containerComponentType, null);
+ public ComponentInstance createComponentInstance(final String containerComponentParam,
+ final String containerComponentId, final String userId,
+ final ComponentInstance resourceInstance, final boolean needLock) {
+ final User user = validateUserExists(userId);
+ validateUserNotEmpty(user, "Create component instance");
+ validateJsonBody(resourceInstance, ComponentInstance.class);
+ final ComponentTypeEnum containerComponentType = validateComponentType(containerComponentParam);
+ final org.openecomp.sdc.be.model.Component containerComponent =
+ validateComponentExists(containerComponentId, containerComponentType, null);
- if (ModelConverter.isAtomicComponent(containerComponent)) {
+ if (ModelConverter.isAtomicComponent(containerComponent)) {
+ if (log.isDebugEnabled()) {
log.debug("Cannot attach resource instances to container resource of type {}", containerComponent.assetType());
- throw new ByActionStatusComponentException(ActionStatus.RESOURCE_CANNOT_CONTAIN_RESOURCE_INSTANCES, containerComponent.assetType());
}
+ throw new ByActionStatusComponentException(ActionStatus.RESOURCE_CANNOT_CONTAIN_RESOURCE_INSTANCES, containerComponent.assetType());
+ }
- validateCanWorkOnComponent(containerComponent, userId);
-
- if (resourceInstance != null && containerComponentType != null) {
- OriginTypeEnum originType = resourceInstance.getOriginType();
- validateInstanceName(resourceInstance);
- if (originType == OriginTypeEnum.ServiceProxy) {
-
- Either<Component, StorageOperationStatus> serviceProxyOrigin = toscaOperationFacade.getLatestByName("serviceProxy");
- if (isServiceProxyOrigin(serviceProxyOrigin)) {
- throw new ByActionStatusComponentException(componentsUtils.convertFromStorageResponse(serviceProxyOrigin.right().value()));
- }
- origComponent = serviceProxyOrigin.left().value();
+ validateCanWorkOnComponent(containerComponent, userId);
- StorageOperationStatus fillProxyRes = fillProxyInstanceData(resourceInstance, origComponent);
- if (isFillProxyRes(fillProxyRes)) {
- throw new ByActionStatusComponentException(componentsUtils.convertFromStorageResponse(fillProxyRes));
- }
+ Component origComponent = null;
+ if (resourceInstance != null && containerComponentType != null) {
+ final OriginTypeEnum originType = resourceInstance.getOriginType();
+ validateInstanceName(resourceInstance);
+ if (originType == OriginTypeEnum.ServiceProxy) {
+
+ final Either<Component, StorageOperationStatus> serviceProxyOrigin =
+ toscaOperationFacade.getLatestByName("serviceProxy");
+ if (isServiceProxyOrigin(serviceProxyOrigin)) {
+ throw new ByActionStatusComponentException(
+ componentsUtils.convertFromStorageResponse(serviceProxyOrigin.right().value()));
}
- else {
- origComponent = getAndValidateOriginComponentOfComponentInstance(containerComponent, resourceInstance);
+ origComponent = serviceProxyOrigin.left().value();
+
+ final StorageOperationStatus fillProxyRes = fillProxyInstanceData(resourceInstance, origComponent);
+ if (isFillProxyRes(fillProxyRes)) {
+ throw new ByActionStatusComponentException(
+ componentsUtils.convertFromStorageResponse(fillProxyRes));
}
- validateOriginAndResourceInstanceTypes(containerComponent, origComponent, originType);
- validateResourceInstanceState(containerComponent, origComponent);
- overrideFields(origComponent, resourceInstance);
- compositionBusinessLogic.validateAndSetDefaultCoordinates(resourceInstance);
+ } else {
+ origComponent = getAndValidateOriginComponentOfComponentInstance(containerComponent,
+ resourceInstance);
}
- return createComponent(needLock, containerComponent,origComponent, resourceInstance, user);
-
- }catch (ComponentException e){
- throw e;
+ validateOriginAndResourceInstanceTypes(containerComponent, origComponent, originType);
+ validateResourceInstanceState(containerComponent, origComponent);
+ overrideFields(origComponent, resourceInstance);
+ compositionBusinessLogic.validateAndSetDefaultCoordinates(resourceInstance);
}
+ return createComponent(needLock, containerComponent, origComponent, resourceInstance, user);
}
private ComponentInstance createComponent(boolean needLock, Component containerComponent, Component origComponent, ComponentInstance resourceInstance, User user) {
@@ -426,10 +425,10 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic {
}
}
- private void validateOriginAndResourceInstanceTypes(Component containerComponent, Component origComponent, OriginTypeEnum originType) {
- ResourceTypeEnum resourceType = null;
- ResourceTypeEnum convertedOriginType;
- resourceType = getResourceTypeEnumFromOriginComponent(origComponent, resourceType);
+ private void validateOriginAndResourceInstanceTypes(final Component containerComponent,
+ final Component origComponent,
+ final OriginTypeEnum originType) {
+ final ResourceTypeEnum resourceType = getResourceTypeEnumFromOriginComponent(origComponent);
validateOriginType(originType, resourceType);
validateOriginComponentIsValidForContainer(containerComponent, resourceType);
}
@@ -437,13 +436,14 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic {
private void validateOriginComponentIsValidForContainer(Component containerComponent, ResourceTypeEnum resourceType) {
switch (containerComponent.getComponentType()) {
case SERVICE:
- if (!containerInstanceTypesData.getServiceContainerList().contains((resourceType))) {
+ if (!containerInstanceTypesData.isAllowedForServiceComponent(resourceType)) {
throw new ByActionStatusComponentException(ActionStatus.CONTAINER_CANNOT_CONTAIN_INSTANCE,
containerComponent.getComponentType().toString(), resourceType.name());
}
break;
case RESOURCE:
- if (!containerInstanceTypesData.getValidInstanceTypesInResourceContainer().get(((Resource) containerComponent).getResourceType()).contains(resourceType)) {
+ final ResourceTypeEnum componentResourceType = ((Resource) containerComponent).getResourceType();
+ if (!containerInstanceTypesData.isAllowedForResourceComponent(componentResourceType, resourceType)) {
throw new ByActionStatusComponentException(ActionStatus.CONTAINER_CANNOT_CONTAIN_INSTANCE,
containerComponent.getComponentType().toString(), resourceType.name());
}
@@ -465,18 +465,15 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic {
if (resourceType != convertedOriginType) throw new ByActionStatusComponentException(ActionStatus.INVALID_CONTENT);
}
- private ResourceTypeEnum getResourceTypeEnumFromOriginComponent(Component origComponent, ResourceTypeEnum resourceType) {
+ private ResourceTypeEnum getResourceTypeEnumFromOriginComponent(final Component origComponent) {
switch (origComponent.getComponentType()) {
case SERVICE:
- resourceType = ResourceTypeEnum.ServiceProxy;
- break;
+ return ResourceTypeEnum.ServiceProxy;
case RESOURCE:
- resourceType = ((Resource) origComponent).getResourceType();
- break;
+ return ((Resource) origComponent).getResourceType();
default:
throw new ByActionStatusComponentException(ActionStatus.INVALID_CONTENT);
}
- return resourceType;
}
private ComponentInstance isNeedLock(boolean needLock, Component containerComponent) {
@@ -2730,7 +2727,7 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic {
try {
actionResponse = createComponentInstance(
- "services", containerComponentId, userId, inputComponentInstance, true, false);
+ "services", containerComponentId, userId, inputComponentInstance, false);
} catch (ComponentException e) {
failed = true;
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/utils/ContainerInstanceTypesData.java b/catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/utils/ContainerInstanceTypesData.java
deleted file mode 100644
index 3ee9645cd9..0000000000
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/utils/ContainerInstanceTypesData.java
+++ /dev/null
@@ -1,62 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.openecomp.sdc.be.datamodel.utils;
-
-import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
-import org.springframework.stereotype.Component;
-
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-@Component
-public class ContainerInstanceTypesData {
-
- private List<ResourceTypeEnum> validInstanceTypesInServiceContainer = Arrays.asList(ResourceTypeEnum.PNF,
- ResourceTypeEnum.VF, ResourceTypeEnum.CP,
- ResourceTypeEnum.VL, ResourceTypeEnum.CR,
- ResourceTypeEnum.ServiceProxy,ResourceTypeEnum.Configuration);
- private Map<ResourceTypeEnum,List<ResourceTypeEnum>> validInstanceTypesInResourceContainer = new HashMap<>();
-
- private ContainerInstanceTypesData() {
- List<ResourceTypeEnum> vfContainerInstances = Arrays.asList(ResourceTypeEnum.CP,
- ResourceTypeEnum.VL, ResourceTypeEnum.Configuration,
- ResourceTypeEnum.VFC);
- List<ResourceTypeEnum> crContainerInstances = Arrays.asList(ResourceTypeEnum.CP,
- ResourceTypeEnum.VL, ResourceTypeEnum.Configuration,
- ResourceTypeEnum.VFC);
- List<ResourceTypeEnum> pnfContainerInstances = Arrays.asList(ResourceTypeEnum.CP,
- ResourceTypeEnum.VL, ResourceTypeEnum.Configuration,
- ResourceTypeEnum.VFC);
- validInstanceTypesInResourceContainer.put(ResourceTypeEnum.VF, vfContainerInstances);
- validInstanceTypesInResourceContainer.put(ResourceTypeEnum.CR, crContainerInstances);
- validInstanceTypesInResourceContainer.put(ResourceTypeEnum.PNF, pnfContainerInstances);
- }
-
- public List<ResourceTypeEnum> getServiceContainerList() {
- return validInstanceTypesInServiceContainer;
- }
-
- public Map<ResourceTypeEnum, List<ResourceTypeEnum>> getValidInstanceTypesInResourceContainer() {
- return validInstanceTypesInResourceContainer;
- }
-}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ComponentInstanceServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ComponentInstanceServlet.java
index 34b261b106..4f3120aba2 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ComponentInstanceServlet.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ComponentInstanceServlet.java
@@ -166,24 +166,30 @@ public class ComponentInstanceServlet extends AbstractValidationsServlet {
@Context final HttpServletRequest request) {
validateNotEmptyBody(data);
- ComponentInstance componentInstance = null;
+ final ComponentInstance componentInstance;
try {
componentInstance = RepresentationUtils.fromRepresentation(data, ComponentInstance.class);
componentInstance.setInvariantName(null);
componentInstance.setCreatedFrom(CreatedFrom.UI);
- } catch (Exception e) {
+ } catch (final Exception e) {
BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Create Component Instance");
log.debug("create component instance failed with exception", e);
throw new ByActionStatusComponentException(ActionStatus.INVALID_CONTENT);
}
- loggerSupportability.log(LoggerSupportabilityActions.CREATE_INSTANCE, StatusCode.STARTED,"Starting to create component instance by {}",userId);
- if (componentInstanceBusinessLogic == null) {
- log.debug(UNSUPPORTED_COMPONENT_TYPE, containerComponentType);
- return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.UNSUPPORTED_ERROR, containerComponentType));
- }
- ComponentInstance actionResponse = componentInstanceBusinessLogic.createComponentInstance(containerComponentType, containerComponentId, userId, componentInstance);
- loggerSupportability.log(LoggerSupportabilityActions.CREATE_INSTANCE,actionResponse.getComponentMetadataForSupportLog(),StatusCode.COMPLETE,"Ending to create component instance by user {}",userId);
- return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.CREATED), actionResponse);
+
+ loggerSupportability.log(LoggerSupportabilityActions.CREATE_INSTANCE, StatusCode.STARTED,
+ "Starting to create component instance by {}", userId);
+ if (componentInstanceBusinessLogic == null) {
+ log.debug(UNSUPPORTED_COMPONENT_TYPE, containerComponentType);
+ return buildErrorResponse(
+ getComponentsUtils().getResponseFormat(ActionStatus.UNSUPPORTED_ERROR, containerComponentType));
+ }
+ final ComponentInstance actionResponse = componentInstanceBusinessLogic.
+ createComponentInstance(containerComponentType, containerComponentId, userId, componentInstance);
+ loggerSupportability
+ .log(LoggerSupportabilityActions.CREATE_INSTANCE, actionResponse.getComponentMetadataForSupportLog(),
+ StatusCode.COMPLETE, "Ending to create component instance by user {}", userId);
+ return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.CREATED), actionResponse);
}