Skip to content

Commit

Permalink
migrate repoter: add HTTERO and milty break down dc
Browse files Browse the repository at this point in the history
  • Loading branch information
yifuzhou committed Nov 7, 2024
1 parent 841869b commit f6224bf
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Set;

@Component
@Profile(AbstractProfile.PROFILE_NAME_PRODUCTION)
Expand Down Expand Up @@ -43,13 +44,25 @@ public class DefaultMigrationProcessReporter extends AbstractSiteLeaderIntervalA

private long totalClusters = 0;

private Set<String> 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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<String> getBreakDownDc() {
return new HashSet<>(Arrays.asList(getProperty(KEY_MIGRATION_BREAK_DOWN_DC, "jq").split(",")));
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)))
Expand All @@ -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);
Expand All @@ -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();
Expand All @@ -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());
}
}

0 comments on commit f6224bf

Please sign in to comment.