Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[APIM-4.2.0] Cannot publish a new API revision due to partially created API revisions #2987

Closed
Hashini-Deshappriya opened this issue Jul 5, 2024 · 1 comment · Fixed by wso2/carbon-apimgt#12487

Comments

@Hashini-Deshappriya
Copy link

Hashini-Deshappriya commented Jul 5, 2024

Problem

  • If any DB related Exception occurs when creating a new revision, the DB transaction will be rolled back.But the registry related transactions are not rolled back. This is causing the partially created APIs in the registry side.

Solution

  • We could add some improvements to the add revision method.
  • We could try adding a logic to delete the created revision if there is a rollback happened when apiMgtDAO.addAPIRevision(apiRevision) is called.

Sample Code

@@ -5614,7 +5614,20 @@ class APIProviderImpl extends AbstractAPIManager implements APIProvider {
                     ExceptionCodes.from(ExceptionCodes.API_REVISION_UUID_NOT_FOUND));
         }
         apiRevision.setRevisionUUID(revisionUUID);
-        apiMgtDAO.addAPIRevision(apiRevision);
+        try {
+            apiMgtDAO.addAPIRevision(apiRevision);
+        } catch (APIManagementException e) {
+            try {
+                apiPersistenceInstance.deleteAPIRevision(new Organization(organization), apiId.getUUID(), revisionUUID,
+                        revisionId);
+            } catch (APIPersistenceException e1) {
+                String errorMessage = "Failed to removing revision registry artifacts";
+                throw new APIManagementException(errorMessage, ExceptionCodes.from(ExceptionCodes.
+                        ERROR_DELETING_API_REVISION, apiRevision.getApiUUID()));
+            }
+            throw new APIManagementException("Failed to add API Revision entry of API UUID "
+                    + apiRevision.getApiUUID(), e);
+        }
         if (importExportAPI != null) {
             try {
                 File artifact = importExportAPI

Product : wso2am-4.2.0
Update level : -
WSO2 case id : FISGLOBALSUB-1166
Case number : CS0282684

@BLasan
Copy link

BLasan commented Jul 8, 2024

Issue will be closed once the PR is received

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants