+ public Either<CapabilityDefinition, ResponseFormat> updateInstanceCapability(final ComponentTypeEnum containerComponentType,
+ final String containerComponentId,
+ final String componentInstanceUniqueId,
+ final CapabilityDefinition capabilityDefinition,
+ final String userId) {
+ if (containerComponentType == null) {
+ BeEcompErrorManager.getInstance().logInvalidInputError("updateInstanceCapability", INVALID_COMPONENT_TYPE, ErrorSeverity.INFO);
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.NOT_ALLOWED));
+ }
+ validateUserExists(userId);
+ final Either<Component, StorageOperationStatus> getResourceResult = toscaOperationFacade.getToscaFullElement(containerComponentId);
+ if (getResourceResult.isRight()) {
+ log.debug(FAILED_TO_RETRIEVE_COMPONENT_COMPONENT_ID, containerComponentId);
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.COMPONENT_NOT_FOUND, containerComponentId));
+ }
+ final Component containerComponent = getResourceResult.left().value();
+ if (!ComponentValidationUtils.canWorkOnComponent(containerComponent, userId)) {
+ log.info(RESTRICTED_OPERATION_ON_COMPONENT, userId, containerComponentId);
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.RESTRICTED_OPERATION));
+ }
+ final Either<ComponentInstance, StorageOperationStatus> resourceInstanceStatus =
+ getResourceInstanceById(containerComponent, componentInstanceUniqueId);
+ if (resourceInstanceStatus.isRight()) {
+ return Either.right(componentsUtils
+ .getResponseFormat(ActionStatus.RESOURCE_INSTANCE_NOT_FOUND_ON_SERVICE, componentInstanceUniqueId, containerComponentId));
+ }
+ // lock resource
+ final StorageOperationStatus lockStatus = graphLockOperation.lockComponent(containerComponentId, containerComponentType.getNodeType());
+ if (lockStatus != StorageOperationStatus.OK) {
+ log.debug(FAILED_TO_LOCK_COMPONENT, containerComponentId);
+ return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(lockStatus)));
+ }
+ var success = false;
+ try {
+ final CapabilityDataDefinition updatedCapabilityDefinition = toscaOperationFacade
+ .updateComponentInstanceCapability(containerComponentId, componentInstanceUniqueId, capabilityDefinition);
+ final Either<Component, StorageOperationStatus> updateContainerEither = toscaOperationFacade
+ .updateComponentInstanceMetadataOfTopologyTemplate(containerComponent);
+ if (updateContainerEither.isRight()) {
+ var actionStatus = componentsUtils.convertFromStorageResponse(updateContainerEither.right().value(), containerComponentType);
+ return Either.right(componentsUtils.getResponseFormat(actionStatus));
+ }
+ success = true;
+ return Either.left(new CapabilityDefinition(updatedCapabilityDefinition));
+ } catch (final BusinessException e) {
+ log.error(EcompLoggerErrorCode.BUSINESS_PROCESS_ERROR, NodeTemplateOperation.class.getName(), (ErrorLogOptionalData) null,
+ FAILED_TO_UPDATE_COMPONENT_INSTANCE_CAPABILITY, componentInstanceUniqueId, containerComponentId);
+ throw e;
+ } catch (final Exception e) {
+ log.error(EcompLoggerErrorCode.BUSINESS_PROCESS_ERROR, NodeTemplateOperation.class.getName(), (ErrorLogOptionalData) null,
+ FAILED_TO_UPDATE_COMPONENT_INSTANCE_CAPABILITY, componentInstanceUniqueId, containerComponentId);
+ throw new ByResponseFormatComponentException(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));
+ } finally {
+ if (success) {
+ janusGraphDao.commit();
+ } else {
+ janusGraphDao.rollback();
+ }
+ // unlock resource
+ graphLockOperation.unlockComponent(containerComponentId, containerComponentType.getNodeType());
+ }
+ }