summaryrefslogtreecommitdiffstats
path: root/catalog-be/src/main
diff options
context:
space:
mode:
authorpriyanshu <pagarwal@amdocs.com>2018-08-02 17:11:25 +0300
committerpriyanshu <pagarwal@amdocs.com>2018-08-03 12:09:28 +0530
commit517d06a213dd00f919c17d023718ed2d85d424bc (patch)
treeb4b08cf8cc5d00297296fde96e684716a7c60b04 /catalog-be/src/main
parentef4b94ef2e02b2b43234eaf47f3e50be63ddb1ee (diff)
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 <pagarwal@amdocs.com>
Diffstat (limited to 'catalog-be/src/main')
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogic.java80
1 files changed, 80 insertions, 0 deletions
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<Boolean, ResponseFormat> validateAndUpdateInterfacesEither = validateAndUpdateInterfaces(resourceIdToUpdate, newResource);
+ if (validateAndUpdateInterfacesEither.isRight()) {
+ log.error("failed to validate and update Interfaces");
+ rollbackNeeded = true;
+ throw new ComponentException(validateAndUpdateInterfacesEither.right().value());
+ }
+
Either<Resource, ResponseFormat> dataModelResponse = updateResourceMetadata(resourceIdToUpdate, newResource,
user, currentResource, false, true);
if (dataModelResponse.isRight()) {
@@ -5153,4 +5173,64 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
}
}
+ private Either<Boolean, ResponseFormat> validateAndUpdateInterfaces(String resourceId, Resource resourceUpdate) {
+ Either<Resource, StorageOperationStatus> 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<String, InterfaceDefinition> storedResourceInterfaces = storedResource.getInterfaces();
+
+ if(!storedResource.getName().equals(resourceUpdate.getName()) ) {
+ Collection<InterfaceDefinition> interfaceDefinitionListFromToscaName = InterfaceUtils
+ .getInterfaceDefinitionListFromToscaName(storedResource.getInterfaces().values(),
+ storedResource.getName());
+
+ for (InterfaceDefinition interfaceDefinition : storedResourceInterfaces.values()) {
+ Either<InterfaceDefinition, ResponseFormat> updateInterfaceDefinitionEither = updateInterfaceDefinition(resourceUpdate,
+ interfaceDefinition,
+ interfaceDefinitionListFromToscaName);
+ if(updateInterfaceDefinitionEither.isRight()) {
+ return Either.right(updateInterfaceDefinitionEither.right().value());
+ }
+ }
+ }
+
+ return Either.left(Boolean.TRUE);
+ }
+
+ private Either<InterfaceDefinition, ResponseFormat > updateInterfaceDefinition(Resource resourceUpdate,
+ InterfaceDefinition interfaceDefinition,
+ Collection<InterfaceDefinition> 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<InterfaceDefinition, StorageOperationStatus> 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