This is an automated email from the ASF dual-hosted git repository.

lizhimins pushed a commit to branch rocketmq-studio
in repository https://gitbox.apache.org/repos/asf/rocketmq-dashboard.git


The following commit(s) were added to refs/heads/rocketmq-studio by this push:
     new e37adf846 fix(instance): grade cloud import audits by the import 
outcome (#4660)
e37adf846 is described below

commit e37adf84638c603d29e452ae50380f3ca63ddfc1
Author: 烤化の初雪 <[email protected]>
AuthorDate: Thu Oct 1 18:30:30 2026 +0800

    fix(instance): grade cloud import audits by the import outcome (#4660)
    
    Every cloud instance import was audited as SUCCESS: the private recordAudit
    helper hardcoded the result, so an import whose catalog lookup failed or in
    which every region failed still produced a successful audit row while the
    API response correctly reported failedCount. The audit timeline and summary
    therefore trusted an operation that never imported anything.
    
    Grade the audit with the shared vocabulary — SUCCESS when nothing failed,
    PARTIAL when some instances imported and some failures occurred, FAILED when
    failures occurred and nothing was imported — mirroring the DLQ resend
    outcome classification. The other instance audits pass their existing
    SUCCESS result explicitly.
    
    Fixes #4656.
    
    Co-authored-by: unbridled-41 
<[email protected]>
---
 .../rocketmq/studio/instance/InstanceService.java  | 25 ++++++++++++++++------
 .../studio/instance/InstanceServiceTest.java       | 19 +++++++++++++++-
 2 files changed, 37 insertions(+), 7 deletions(-)

diff --git 
a/server/src/main/java/org/apache/rocketmq/studio/instance/InstanceService.java 
b/server/src/main/java/org/apache/rocketmq/studio/instance/InstanceService.java
index 54e56e980..713a07ebd 100644
--- 
a/server/src/main/java/org/apache/rocketmq/studio/instance/InstanceService.java
+++ 
b/server/src/main/java/org/apache/rocketmq/studio/instance/InstanceService.java
@@ -240,7 +240,7 @@ public class InstanceService {
             throw exception;
         }
         recordAudit("CREATE_INSTANCE", "INSTANCE", 
String.valueOf(saved.getId()), null,
-                instanceAuditDetail(saved));
+                instanceAuditDetail(saved), "SUCCESS");
         return saved;
     }
 
@@ -363,10 +363,23 @@ public class InstanceService {
                 vendor, credentialId, result.discovered, result.imported, 
result.skipped, result.failedCount);
         recordAudit("IMPORT_CLOUD_INSTANCES", "INSTANCE", 
String.valueOf(credentialId), null,
                 "vendor=" + vendor + ", imported=" + result.imported + ", 
skipped=" + result.skipped
-                        + ", failed=" + result.failedCount);
+                        + ", failed=" + result.failedCount,
+                cloudImportAuditResult(result.imported, result.failedCount));
         return result.toValue();
     }
 
+    /**
+     * Grade the import outcome with the shared audit vocabulary: a clean 
import is SUCCESS,
+     * a fully failed one is FAILED, and anything in between (some instances 
imported, some
+     * regions or rows failed) is PARTIAL — matching the DLQ resend 
classification.
+     */
+    private static String cloudImportAuditResult(int imported, int 
failedCount) {
+        if (failedCount <= 0) {
+            return "SUCCESS";
+        }
+        return imported > 0 ? "PARTIAL" : "FAILED";
+    }
+
     private String normalizeCloudImportValue(String value) {
         return StringUtils.hasText(value) ? value.trim() : null;
     }
@@ -657,7 +670,7 @@ public class InstanceService {
             releaseApacheClientIfChanged(existing, saved);
         }
         recordAudit("UPDATE_INSTANCE", "INSTANCE", 
String.valueOf(saved.getId()), null,
-                instanceAuditDetail(saved));
+                instanceAuditDetail(saved), "SUCCESS");
         return saved;
     }
 
@@ -692,7 +705,7 @@ public class InstanceService {
         }
         removeDataSourceBindings(existing.getName());
         recordAudit("DELETE_INSTANCE", "INSTANCE", String.valueOf(id), null,
-                instanceAuditDetail(existing));
+                instanceAuditDetail(existing), "SUCCESS");
         completeInstanceDeletionAfterCommit(existing);
     }
 
@@ -884,9 +897,9 @@ public class InstanceService {
     }
 
     private void recordAudit(String operation, String resourceType, String 
resourceName,
-                             String clusterId, String detail) {
+                             String clusterId, String detail, String result) {
         try {
-            operationAuditService.record(operation, resourceType, 
resourceName, clusterId, detail, "SUCCESS", null);
+            operationAuditService.record(operation, resourceType, 
resourceName, clusterId, detail, result, null);
         } catch (Exception auditFailure) {
             log.warn("Failed to record audit operation={} resource={}: {}", 
operation, resourceName,
                     auditFailure.getMessage());
diff --git 
a/server/src/test/java/org/apache/rocketmq/studio/instance/InstanceServiceTest.java
 
b/server/src/test/java/org/apache/rocketmq/studio/instance/InstanceServiceTest.java
index 0de5d3fd1..31cd7eaa9 100644
--- 
a/server/src/test/java/org/apache/rocketmq/studio/instance/InstanceServiceTest.java
+++ 
b/server/src/test/java/org/apache/rocketmq/studio/instance/InstanceServiceTest.java
@@ -1639,11 +1639,28 @@ class InstanceServiceTest {
         assertThat(result.getFailedCount()).isEqualTo(1);
         assertThat(result.isFailureDetailsTruncated()).isFalse();
         assertThat(result.getFailed()).containsExactly("cn-broken: regional 
outage");
+        verify(catalog).listCloudInstances(1L, "cn-broken", null);
         verify(catalog).listCloudInstances(1L, "cn-working", null);
         verify(catalog).getCloudInstance(1L, "cn-working", "rmq-working");
         verify(operationAuditService).record(eq("IMPORT_CLOUD_INSTANCES"), 
eq("INSTANCE"), eq("1"), eq(null),
                 argThat(detail -> detail.contains("imported=1") && 
detail.contains("failed=1")),
-                eq("SUCCESS"), eq(null));
+                eq("PARTIAL"), eq(null));
+    }
+
+    @Test
+    void importCloudInstancesShouldAuditAFullyFailedImportAsFailedTest() {
+        CloudCatalogProvider catalog = prepareAliyunCatalog();
+        when(catalog.listRegions(1L)).thenThrow(new BusinessException(502, 
"invalid credential"));
+
+        CloudImportResultVO result = 
instanceService.importCloudInstances(InstanceVendor.ALIYUN, 1L);
+
+        assertThat(result.getImported()).isZero();
+        assertThat(result.getFailedCount()).isEqualTo(1);
+        assertThat(result.getFailed()).containsExactly("regions: invalid 
credential");
+
+        verify(operationAuditService).record(eq("IMPORT_CLOUD_INSTANCES"), 
eq("INSTANCE"), eq("1"), eq(null),
+                argThat(detail -> detail.contains("imported=0") && 
detail.contains("failed=1")),
+                eq("FAILED"), eq(null));
     }
 
     @Test

Reply via email to