From 3568f4098cc5294c3956b70db3d9d2ee6368fb36 Mon Sep 17 00:00:00 2001 From: Chris André Date: Tue, 5 May 2020 14:09:02 -0400 Subject: Add null test to ComponentInstanceBusinessLogic - Added test in `changeInstanceVersion` for null value Issue-ID: SDC-2908 Signed-off-by: Chris Andre Change-Id: I42a428c4b245a55b7229e2ec9b781e9af4403662 --- .../impl/ComponentInstanceBusinessLogic.java | 136 ++++++++++++--------- 1 file changed, 81 insertions(+), 55 deletions(-) (limited to 'catalog-be') 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 resourceInstanceStatus; @@ -2306,10 +2309,14 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic { } String resourceId = newComponentInstance.getComponentUid(); - Either componentExistsRes = toscaOperationFacade.validateComponentExists(resourceId); + Either 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 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 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 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 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); } } -- cgit 1.2.3-korg