diff --git a/redis/redis-console/src/main/java/com/ctrip/xpipe/redis/console/reporter/DefaultMigrationProcessReporter.java b/redis/redis-console/src/main/java/com/ctrip/xpipe/redis/console/reporter/DefaultMigrationProcessReporter.java index 55ee9ee961..5b9a9e552d 100644 --- a/redis/redis-console/src/main/java/com/ctrip/xpipe/redis/console/reporter/DefaultMigrationProcessReporter.java +++ b/redis/redis-console/src/main/java/com/ctrip/xpipe/redis/console/reporter/DefaultMigrationProcessReporter.java @@ -15,6 +15,7 @@ import org.springframework.stereotype.Component; import java.util.List; +import java.util.Set; @Component @Profile(AbstractProfile.PROFILE_NAME_PRODUCTION) @@ -43,13 +44,25 @@ public class DefaultMigrationProcessReporter extends AbstractSiteLeaderIntervalA private long totalClusters = 0; + private Set lastBreakDownDc; + @Override protected void doAction() { EventMonitor.DEFAULT.logEvent(REPORT_EVENT, "begin"); MigrationProcessReportModel model = new MigrationProcessReportModel(); + if (lastBreakDownDc == null) { + lastBreakDownDc = migrationReporterConfig.getBreakDownDc(); + } + if (lastBreakDownDc != null && !lastBreakDownDc.equals(migrationReporterConfig.getBreakDownDc()) ) { + lastBreakDownDc = migrationReporterConfig.getBreakDownDc(); + totalClusters = 0; + } - // TODO AzGroup need to be considered after hetero cluster type online - Long nonMigrateClustersNum = clusterService.getCountByActiveDcAndClusterType(dcService.find(migrationReporterConfig.getBreakDownDc()).getId(), ClusterType.ONE_WAY.name()); + Long nonMigrateClustersNum = 0L; + for (String breakDownDc : migrationReporterConfig.getBreakDownDc()) { + nonMigrateClustersNum += clusterService.getCountByActiveDcAndClusterType(dcService.find(breakDownDc).getId(), ClusterType.ONE_WAY.name()); + nonMigrateClustersNum += clusterService.getCountByActiveDcAndClusterType(dcService.find(breakDownDc).getId(), ClusterType.HETERO.name()); + } if (totalClusters == 0 || nonMigrateClustersNum > totalClusters) { totalClusters = nonMigrateClustersNum; } diff --git a/redis/redis-console/src/main/java/com/ctrip/xpipe/redis/console/reporter/MigrationReporterConfig.java b/redis/redis-console/src/main/java/com/ctrip/xpipe/redis/console/reporter/MigrationReporterConfig.java index 6bcc565c65..5376ce5275 100644 --- a/redis/redis-console/src/main/java/com/ctrip/xpipe/redis/console/reporter/MigrationReporterConfig.java +++ b/redis/redis-console/src/main/java/com/ctrip/xpipe/redis/console/reporter/MigrationReporterConfig.java @@ -7,6 +7,10 @@ import com.ctrip.xpipe.utils.StringUtil; import org.springframework.context.annotation.Configuration; +import java.util.Arrays; +import java.util.HashSet; +import java.util.Set; + import static com.ctrip.xpipe.api.config.ConfigProvider.COMMON_CONFIG; @Configuration @@ -66,8 +70,8 @@ public long getMigrationProcessReportIntervalMill() { return getLongProperty(KEY_MIGRATION_PROCESS_REPORT_INTERVAL_MILLI, 10000L); } - public String getBreakDownDc() { - return getProperty(KEY_MIGRATION_BREAK_DOWN_DC, "jq"); + public Set getBreakDownDc() { + return getSplitStringSet(getProperty(KEY_MIGRATION_BREAK_DOWN_DC, "jq")); } diff --git a/redis/redis-console/src/test/java/com/ctrip/xpipe/redis/console/reporter/DefaultMigrationProcessReporterTest.java b/redis/redis-console/src/test/java/com/ctrip/xpipe/redis/console/reporter/DefaultMigrationProcessReporterTest.java index 69b93d3242..093af6b95b 100644 --- a/redis/redis-console/src/test/java/com/ctrip/xpipe/redis/console/reporter/DefaultMigrationProcessReporterTest.java +++ b/redis/redis-console/src/test/java/com/ctrip/xpipe/redis/console/reporter/DefaultMigrationProcessReporterTest.java @@ -15,6 +15,9 @@ import org.springframework.http.ResponseEntity; import org.springframework.web.client.RestOperations; +import java.util.Collections; +import java.util.HashSet; + @RunWith(MockitoJUnitRunner.class) public class DefaultMigrationProcessReporterTest { @@ -53,7 +56,7 @@ public class DefaultMigrationProcessReporterTest { @Before public void before() { Mockito.when(migrationReporterConfig.getKeyMigrationProcessReportUrl()).thenReturn("127.0.0.1:8080"); - Mockito.when(migrationReporterConfig.getBreakDownDc()).thenReturn("jq"); + Mockito.when(migrationReporterConfig.getBreakDownDc()).thenReturn(new HashSet<>(Collections.singleton("jq"))); Mockito.when(httpService.getRestTemplate()).thenReturn(restTemplate); Mockito.when(restTemplate.postForEntity(Mockito.anyString(), migrationProcessReportModelArgumentCaptor.capture(), Mockito.eq(NocReportResponseModel.class))) @@ -70,7 +73,7 @@ public void testReportSuccess() { migrationProcessReportModelArgumentCaptor.capture(), Mockito.eq(NocReportResponseModel.class)); MigrationProcessReportModel value = migrationProcessReportModelArgumentCaptor.getValue(); Assert.assertEquals(0, value.getProcess()); - Assert.assertEquals(1000, value.getObjectCount()); + Assert.assertEquals(2000, value.getObjectCount()); Assert.assertEquals("redis", value.getService()); Mockito.when(clusterService.getCountByActiveDcAndClusterType(Mockito.anyLong(), Mockito.anyString())).thenReturn(1001L); @@ -80,7 +83,7 @@ public void testReportSuccess() { migrationProcessReportModelArgumentCaptor.capture(), Mockito.eq(NocReportResponseModel.class)); value = migrationProcessReportModelArgumentCaptor.getValue(); Assert.assertEquals(0, value.getProcess()); - Assert.assertEquals(1001, value.getObjectCount()); + Assert.assertEquals(2002, value.getObjectCount()); Mockito.when(clusterService.getCountByActiveDcAndClusterType(Mockito.anyLong(), Mockito.anyString())).thenReturn(400L); migrationReporter.doAction(); @@ -89,6 +92,6 @@ public void testReportSuccess() { migrationProcessReportModelArgumentCaptor.capture(), Mockito.eq(NocReportResponseModel.class)); value = migrationProcessReportModelArgumentCaptor.getValue(); Assert.assertEquals(60, value.getProcess()); - Assert.assertEquals(1001, value.getObjectCount()); + Assert.assertEquals(2002, value.getObjectCount()); } } \ No newline at end of file