From 517d06a213dd00f919c17d023718ed2d85d424bc Mon Sep 17 00:00:00 2001 From: priyanshu Date: Thu, 2 Aug 2018 17:11:25 +0300 Subject: Interface operations on VF Interface operations on VF Fixed the broken code after merge Change-Id: I08381c0e69fbe85e1df26fb7ecbf93af43f906b2 Issue-ID: SDC-1586 Signed-off-by: priyanshu --- .../be/components/impl/ResourceBusinessLogic.java | 80 ++++++++++++++++++++++ 1 file changed, 80 insertions(+) (limited to 'catalog-be/src/main') diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogic.java index 5678a628c5..492f5bf850 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogic.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogic.java @@ -63,6 +63,8 @@ import org.openecomp.sdc.be.model.*; import org.openecomp.sdc.be.model.cache.ApplicationDataTypeCache; import org.openecomp.sdc.be.model.category.CategoryDefinition; import org.openecomp.sdc.be.model.category.SubCategoryDefinition; +import org.openecomp.sdc.be.model.jsontitan.operations.InterfaceOperation; +import org.openecomp.sdc.be.model.jsontitan.utils.InterfaceUtils; import org.openecomp.sdc.be.model.jsontitan.utils.ModelConverter; import org.openecomp.sdc.be.model.operations.StorageException; import org.openecomp.sdc.be.model.operations.api.*; @@ -169,6 +171,13 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { @Autowired private CsarBusinessLogic csarBusinessLogic; + @Autowired + private InterfaceOperation interfaceOperation; + + public void setInterfaceOperation(InterfaceOperation interfaceOperation) { + this.interfaceOperation = interfaceOperation; + } + public LifecycleBusinessLogic getLifecycleBusinessLogic() { return lifecycleBusinessLogic; } @@ -217,6 +226,10 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { this.applicationDataTypeCache = applicationDataTypeCache; } + public void setInterfaceTypeOperation(IInterfaceLifecycleOperation interfaceTypeOperation) { + this.interfaceTypeOperation = interfaceTypeOperation; + } + /** * the method returns a list of all the resources that are certified, the * returned resources are only abstract or only none abstract according to @@ -3974,6 +3987,13 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { newResource.setDerivedFrom(null); } + Either validateAndUpdateInterfacesEither = validateAndUpdateInterfaces(resourceIdToUpdate, newResource); + if (validateAndUpdateInterfacesEither.isRight()) { + log.error("failed to validate and update Interfaces"); + rollbackNeeded = true; + throw new ComponentException(validateAndUpdateInterfacesEither.right().value()); + } + Either dataModelResponse = updateResourceMetadata(resourceIdToUpdate, newResource, user, currentResource, false, true); if (dataModelResponse.isRight()) { @@ -5153,4 +5173,64 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { } } + private Either validateAndUpdateInterfaces(String resourceId, Resource resourceUpdate) { + Either resourceStorageOperationStatusEither = + toscaOperationFacade.getToscaElement(resourceId); + if (resourceStorageOperationStatusEither.isRight()) { + StorageOperationStatus errorStatus = resourceStorageOperationStatusEither.right().value(); + log.error("Failed to fetch resource information by resource id {}, error {}", resourceId, errorStatus); + return Either.right(componentsUtils + .getResponseFormat(componentsUtils.convertFromStorageResponse(errorStatus))); + } + + Resource storedResource = resourceStorageOperationStatusEither.left().value(); + Map storedResourceInterfaces = storedResource.getInterfaces(); + + if(!storedResource.getName().equals(resourceUpdate.getName()) ) { + Collection interfaceDefinitionListFromToscaName = InterfaceUtils + .getInterfaceDefinitionListFromToscaName(storedResource.getInterfaces().values(), + storedResource.getName()); + + for (InterfaceDefinition interfaceDefinition : storedResourceInterfaces.values()) { + Either updateInterfaceDefinitionEither = updateInterfaceDefinition(resourceUpdate, + interfaceDefinition, + interfaceDefinitionListFromToscaName); + if(updateInterfaceDefinitionEither.isRight()) { + return Either.right(updateInterfaceDefinitionEither.right().value()); + } + } + } + + return Either.left(Boolean.TRUE); + } + + private Either updateInterfaceDefinition(Resource resourceUpdate, + InterfaceDefinition interfaceDefinition, + Collection interfaceDefinitionListFromToscaName) { + interfaceDefinitionListFromToscaName.forEach(interfaceDefinitionFromList -> { + if(interfaceDefinitionFromList.getToscaResourceName().equals(interfaceDefinition.getToscaResourceName())) { + log.info("Going to Update interface definition toscaResourceName {} to {}", + interfaceDefinitionFromList.getToscaResourceName(), + InterfaceUtils.createInterfaceToscaResourceName(resourceUpdate.getName())); + interfaceDefinition.setToscaResourceName(InterfaceUtils + .createInterfaceToscaResourceName(resourceUpdate.getName())); + } + } ); + try { + Either interfaceUpdate = interfaceOperation + .updateInterface(resourceUpdate.getUniqueId(), interfaceDefinition); + if (interfaceUpdate.isRight()) { + log.error("Failed to Update interface {}. Response is {}. ", resourceUpdate.getName(), interfaceUpdate.right().value()); + titanDao.rollback(); + return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(interfaceUpdate.right().value(), ComponentTypeEnum.RESOURCE))); + } + } catch (Exception e) { + log.error("Exception occurred during update interface toscaResourceName : {}", e); + titanDao.rollback(); + return Either.right(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR)); + } + + return Either.left( interfaceDefinition); + } + } \ No newline at end of file -- cgit 1.2.3-korg