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

migrate repoter: add HTTERO and milty break down dc #909

Merged
merged 1 commit into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 getSplitStringSet(getProperty(KEY_MIGRATION_BREAK_DOWN_DC, "jq"));
}


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());
}
}
Loading