summaryrefslogtreecommitdiffstats
path: root/catalog-be
diff options
context:
space:
mode:
authorChris André <chris.andre@yoppworks.com>2020-05-05 14:09:02 -0400
committerOfir Sonsino <ofir.sonsino@intl.att.com>2020-05-19 08:19:31 +0000
commit3568f4098cc5294c3956b70db3d9d2ee6368fb36 (patch)
tree3ad79ffa1174569d345d86cbd92006bc50d7cf8a /catalog-be
parent9279f7e71679fb16c7ae74ef7c1b7948e381af01 (diff)
Add null test to ComponentInstanceBusinessLogic
- Added test in `changeInstanceVersion` for null value Issue-ID: SDC-2908 Signed-off-by: Chris Andre <chris.andre@yoppworks.com> Change-Id: I42a428c4b245a55b7229e2ec9b781e9af4403662
Diffstat (limited to 'catalog-be')
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogic.java136
1 files changed, 81 insertions, 55 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 da9e0f9444..e943af8519 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
@@ -2292,8 +2292,11 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic {
return changeInstanceVersion(containerComponent, currentResourceInstance, newComponentInstance, user, containerComponentType );
}
- public ComponentInstance changeInstanceVersion(org.openecomp.sdc.be.model.Component containerComponent, ComponentInstance currentResourceInstance,
- ComponentInstance newComponentInstance, User user, final ComponentTypeEnum containerComponentType ) {
+ public ComponentInstance changeInstanceVersion(org.openecomp.sdc.be.model.Component containerComponent,
+ ComponentInstance currentResourceInstance,
+ ComponentInstance newComponentInstance,
+ User user,
+ final ComponentTypeEnum containerComponentType) {
boolean failed = false;
Either<ComponentInstance, StorageOperationStatus> resourceInstanceStatus;
@@ -2306,10 +2309,14 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic {
}
String resourceId = newComponentInstance.getComponentUid();
- Either<Boolean, StorageOperationStatus> componentExistsRes = toscaOperationFacade.validateComponentExists(resourceId);
+ Either<Boolean, StorageOperationStatus> componentExistsRes = toscaOperationFacade
+ .validateComponentExists(resourceId);
if (componentExistsRes.isRight()) {
- log.debug("Failed to validate existing of the component {}. Status is {} ", resourceId, componentExistsRes.right().value());
- throw new ByActionStatusComponentException(componentsUtils.convertFromStorageResponse(componentExistsRes.right().value()), resourceId);
+ StorageOperationStatus errorStatus = componentExistsRes.right().value();
+
+ log.debug("Failed to validate existing of the component {}. Status is {} ", resourceId, errorStatus);
+ throw new ByActionStatusComponentException(
+ componentsUtils.convertFromStorageResponse(errorStatus), resourceId);
} else if (!componentExistsRes.left().value()) {
log.debug("The resource {} not found ", resourceId);
throw new ByActionStatusComponentException(ActionStatus.RESOURCE_NOT_FOUND, resourceId);
@@ -2317,60 +2324,79 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic {
Component eitherOriginComponent = getInstanceOriginNode(currentResourceInstance);
- DataForMergeHolder dataHolder = compInstMergeDataBL.saveAllDataBeforeDeleting(containerComponent, currentResourceInstance, eitherOriginComponent);
- ComponentInstance resResourceInfo = deleteComponentInstance(containerComponent, componentInstanceId, containerComponentType);
- Component origComponent = null;
- OriginTypeEnum originType = currentResourceInstance.getOriginType();
- 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();
-
- StorageOperationStatus fillProxyRes = fillProxyInstanceData(newComponentInstance, origComponent);
-
- if (isFillProxyRes(fillProxyRes))
- throw new ByActionStatusComponentException(componentsUtils.convertFromStorageResponse(fillProxyRes));
- newComponentInstance.setOriginType(originType);
- }else{
- origComponent = getOriginComponentFromComponentInstance(newComponentInstance);
- newComponentInstance.setName(resResourceInfo.getName());
- }
-
- newComponentInstance.setInvariantName(resResourceInfo.getInvariantName());
- newComponentInstance.setPosX(resResourceInfo.getPosX());
- newComponentInstance.setPosY(resResourceInfo.getPosY());
- newComponentInstance.setDescription(resResourceInfo.getDescription());
-
- ComponentInstance updatedComponentInstance = createComponentInstanceOnGraph(containerComponent, origComponent, newComponentInstance, user);
- dataHolder.setCurrInstanceNode(origComponent);
- Component mergeStatusEither = compInstMergeDataBL.mergeComponentUserOrigData(user, dataHolder, containerComponent, containerComponentId, newComponentInstance.getUniqueId());
-
- ActionStatus postChangeVersionResult = onChangeInstanceOperationOrchestrator.doPostChangeVersionOperations(containerComponent, currentResourceInstance, newComponentInstance);
- if (postChangeVersionResult != ActionStatus.OK) {
- throw new ByActionStatusComponentException(postChangeVersionResult);
- }
-
- ComponentParametersView filter = new ComponentParametersView(true);
- filter.setIgnoreComponentInstances(false);
- Either<Component, StorageOperationStatus> updatedComponentRes = toscaOperationFacade.getToscaElement(containerComponentId, filter);
- if (updatedComponentRes.isRight()) {
- StorageOperationStatus storageOperationStatus = updatedComponentRes.right().value();
- ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(storageOperationStatus, containerComponent.getComponentType());
- log.debug("Component with id {} was not found", containerComponentId);
- throw new ByActionStatusComponentException(actionStatus, Constants.EMPTY_STRING);
- }
- resourceInstanceStatus = getResourceInstanceById(updatedComponentRes.left().value(), updatedComponentInstance.getUniqueId());
- if (resourceInstanceStatus.isRight()) {
- throw new ByActionStatusComponentException(componentsUtils.convertFromStorageResponse
+ DataForMergeHolder dataHolder = compInstMergeDataBL
+ .saveAllDataBeforeDeleting(containerComponent, currentResourceInstance, eitherOriginComponent);
+ ComponentInstance resResourceInfo = deleteComponentInstance(containerComponent, componentInstanceId,
+ containerComponentType);
+
+ if (resResourceInfo == null) {
+ log.error("Calling `deleteComponentInstance` for the resource {} returned a null", resourceId);
+ throw new ByActionStatusComponentException(ActionStatus.RESOURCE_NOT_FOUND, resourceId);
+ } else {
+ Component origComponent = null;
+ OriginTypeEnum originType = currentResourceInstance.getOriginType();
+ 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();
+
+ StorageOperationStatus fillProxyRes = fillProxyInstanceData(newComponentInstance, origComponent);
+
+ if (isFillProxyRes(fillProxyRes)) {
+ throw new ByActionStatusComponentException(
+ componentsUtils.convertFromStorageResponse(fillProxyRes));
+ }
+ newComponentInstance.setOriginType(originType);
+ } else {
+ origComponent = getOriginComponentFromComponentInstance(newComponentInstance);
+ newComponentInstance.setName(resResourceInfo.getName());
+ }
+
+ newComponentInstance.setInvariantName(resResourceInfo.getInvariantName());
+ newComponentInstance.setPosX(resResourceInfo.getPosX());
+ newComponentInstance.setPosY(resResourceInfo.getPosY());
+ newComponentInstance.setDescription(resResourceInfo.getDescription());
+
+ ComponentInstance updatedComponentInstance = createComponentInstanceOnGraph(containerComponent,
+ origComponent, newComponentInstance, user);
+ dataHolder.setCurrInstanceNode(origComponent);
+ Component mergeStatusEither = compInstMergeDataBL
+ .mergeComponentUserOrigData(user, dataHolder, containerComponent, containerComponentId,
+ newComponentInstance.getUniqueId());
+
+ ActionStatus postChangeVersionResult = onChangeInstanceOperationOrchestrator
+ .doPostChangeVersionOperations(containerComponent, currentResourceInstance, newComponentInstance);
+ if (postChangeVersionResult != ActionStatus.OK) {
+ throw new ByActionStatusComponentException(postChangeVersionResult);
+ }
+
+ ComponentParametersView filter = new ComponentParametersView(true);
+ filter.setIgnoreComponentInstances(false);
+ Either<Component, StorageOperationStatus> updatedComponentRes = toscaOperationFacade
+ .getToscaElement(containerComponentId, filter);
+ if (updatedComponentRes.isRight()) {
+ StorageOperationStatus storageOperationStatus = updatedComponentRes.right().value();
+ ActionStatus actionStatus = componentsUtils
+ .convertFromStorageResponse(storageOperationStatus, containerComponent.getComponentType());
+ log.debug("Component with id {} was not found", containerComponentId);
+ throw new ByActionStatusComponentException(actionStatus, Constants.EMPTY_STRING);
+ }
+ resourceInstanceStatus = getResourceInstanceById(updatedComponentRes.left().value(),
+ updatedComponentInstance.getUniqueId());
+ if (resourceInstanceStatus.isRight()) {
+ throw new ByActionStatusComponentException(componentsUtils.convertFromStorageResponse
(resourceInstanceStatus.right().value()), updatedComponentInstance.getUniqueId());
+ }
+ return resourceInstanceStatus.left().value();
}
- return resourceInstanceStatus.left().value();
-
- }catch (ComponentException e){
+ } catch (ComponentException e) {
failed = true;
throw e;
- }finally {
+ } finally {
unlockComponent(failed, containerComponent);
}
}