Skip to content

Commit f4405f9

Browse files
committed
SSCS-10722 Specify loggers, use set for cases.
1 parent baa51ab commit f4405f9

File tree

2 files changed

+23
-20
lines changed

2 files changed

+23
-20
lines changed

modules/processor/src/main/java/uk/gov/hmcts/reform/migration/CaseMigrationProcessor.java

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
package uk.gov.hmcts.reform.migration;
22

33
import java.time.LocalDate;
4-
import java.util.ArrayList;
4+
import java.util.HashSet;
55
import java.util.List;
66
import java.util.Map;
7+
import java.util.Set;
78
import java.util.concurrent.ExecutorService;
89
import java.util.concurrent.Executors;
910
import java.util.concurrent.TimeUnit;
1011
import java.util.stream.Collectors;
1112

1213
import lombok.Getter;
1314
import lombok.RequiredArgsConstructor;
14-
import lombok.extern.slf4j.Slf4j;
1515
import org.apache.commons.lang3.time.StopWatch;
16-
import org.springframework.beans.factory.annotation.Value;
16+
import org.slf4j.Logger;
17+
import org.slf4j.LoggerFactory;
1718
import org.springframework.stereotype.Component;
1819
import uk.gov.hmcts.reform.ccd.client.model.CaseDetails;
1920
import uk.gov.hmcts.reform.ccd.client.model.SearchResult;
@@ -22,11 +23,14 @@
2223

2324
import static uk.gov.hmcts.reform.migration.queries.CcdElasticSearchQueries.fetchAllUnsetCaseAccessManagementFieldsCasesQuery;
2425

25-
@Slf4j
2626
@Component
2727
@RequiredArgsConstructor
2828
public class CaseMigrationProcessor {
2929

30+
private final Logger errorLogger = LoggerFactory.getLogger("ccd-migration-error");
31+
32+
private final Logger infoLogger = LoggerFactory.getLogger("ccd-migration-info");
33+
3034
private static final String EVENT_ID = "migrateCase";
3135
private static final String EVENT_SUMMARY = "Migrate Case";
3236
private static final String EVENT_DESCRIPTION = "Migrate Case";
@@ -37,10 +41,10 @@ public class CaseMigrationProcessor {
3741
private final DataMigrationService<?> dataMigrationService;
3842

3943
@Getter
40-
private final List<Long> migratedCases = new ArrayList<>();
44+
private final Set<Long> migratedCases = new HashSet<>();
4145

4246
@Getter
43-
private final List<Long> failedCases = new ArrayList<>();
47+
private final Set<Long> failedCases = new HashSet<>();
4448

4549
@Getter
4650
private Long totalCases = 0L;
@@ -50,13 +54,13 @@ public void processSingleCase(String userToken, String caseId, boolean dryRun) {
5054
try {
5155
caseDetails = coreCaseDataService.fetchOne(userToken, caseId);
5256
} catch (Exception ex) {
53-
log.error("Case {} not found due to: {}", caseId, ex.getMessage());
57+
errorLogger.error("Case {} not found due to: {}", caseId, ex.getMessage());
5458
return;
5559
}
5660
if (dataMigrationService.accepts().test(caseDetails)) {
5761
updateCase(userToken, caseDetails.getId(), caseDetails.getData(), dryRun);
5862
} else {
59-
log.info("Case {} already migrated", caseDetails.getId());
63+
infoLogger.info("Case {} already migrated", caseDetails.getId());
6064
}
6165
}
6266

@@ -89,10 +93,10 @@ private int resolveTotalCasesToProcess(SearchResult initialSearch, int maxCasesT
8993
int totalCasesToProcess = 0;
9094

9195
if (maxCasesToProcess > 0) {
92-
log.info("Manual case override in use, limiting to {} cases", maxCasesToProcess);
96+
infoLogger.info("Manual case override in use, limiting to {} cases", maxCasesToProcess);
9397
totalCasesToProcess = maxCasesToProcess;
9498
} else {
95-
log.info("No manual case override in use, fetching all: {} cases", initialSearch.getTotal());
99+
infoLogger.info("No manual case override in use, fetching all: {} cases", initialSearch.getTotal());
96100
totalCasesToProcess = initialSearch.getTotal();
97101
}
98102

@@ -120,11 +124,11 @@ private void fetchAndSubmitTasks(String userToken, boolean dryRun, int totalCase
120124
.forEach(caseDetail ->
121125
updateCase(userToken, caseDetail.getId(), caseDetail.getData(), dryRun)));
122126

123-
log.info("New task submitted");
127+
infoLogger.info("New task submitted");
124128

125129
casesFetched += caseDetails.size();
126130

127-
log.info("{} cases fetched out of {}", casesFetched, totalCasesToProcess);
131+
infoLogger.info("{} cases fetched out of {}", casesFetched, totalCasesToProcess);
128132
}
129133
}
130134

@@ -137,7 +141,7 @@ private int resolvePageSize(int totalCasesToProcess, int casesFetched, int numCa
137141
}
138142

139143
private Long handleFirstCase(String userToken, boolean dryRun, SearchResult initialSearch) {
140-
log.info("Processing first case...");
144+
infoLogger.info("Processing first case...");
141145
CaseDetails firstCase = initialSearch.getCases().get(0);
142146
updateCase(userToken, firstCase.getId(), firstCase.getData(), dryRun);
143147
return firstCase.getId();
@@ -169,17 +173,17 @@ private void updateCase(String authorisation, Long id, Map<String, Object> data,
169173
EVENT_SUMMARY,
170174
EVENT_DESCRIPTION,
171175
migratedData);
172-
log.info("Case {} successfully updated", id);
176+
infoLogger.info("Case {} successfully updated", id);
173177
}
174178
migratedCases.add(id);
175179

176180
} catch (Exception e) {
177-
log.error("Case {} update failed due to: {}", id, e.getMessage());
181+
errorLogger.error("Case {} update failed due to: {}", id, e.getMessage());
178182
failedCases.add(id);
179183
}
180184

181185
if (totalCases % 1000 == 0) {
182-
log.info("----------{} cases migrated in {} minutes ({} seconds)----------", totalCases,
186+
infoLogger.info("----------{} cases migrated in {} minutes ({} seconds)----------", totalCases,
183187
totalTimer.getTime(TimeUnit.MINUTES), totalTimer.getTime(TimeUnit.SECONDS));
184188
}
185189
}

modules/processor/src/main/java/uk/gov/hmcts/reform/migration/CaseMigrationRunner.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,20 @@
22

33
import java.util.concurrent.TimeUnit;
44
import lombok.RequiredArgsConstructor;
5-
import lombok.extern.slf4j.Slf4j;
65
import org.apache.commons.lang3.time.StopWatch;
6+
import org.slf4j.Logger;
7+
import org.slf4j.LoggerFactory;
78
import org.springframework.beans.factory.annotation.Value;
89
import org.springframework.boot.CommandLineRunner;
910
import org.springframework.boot.SpringApplication;
1011
import org.springframework.boot.autoconfigure.SpringBootApplication;
1112
import uk.gov.hmcts.reform.idam.client.IdamClient;
1213

13-
@Slf4j
1414
@SpringBootApplication
1515
@RequiredArgsConstructor
1616
public class CaseMigrationRunner implements CommandLineRunner {
1717

18+
private final Logger log = LoggerFactory.getLogger("ccd-migration-info");
1819
@Value("${migration.idam.username}")
1920
private String idamUsername;
2021
@Value("${migration.idam.password}")
@@ -29,8 +30,6 @@ public class CaseMigrationRunner implements CommandLineRunner {
2930
private int maxCasesToProcess;
3031
@Value("${migration.numThreads}")
3132
private int numThreads;
32-
33-
3433
private final IdamClient idamClient;
3534
private final CaseMigrationProcessor caseMigrationProcessor;
3635

0 commit comments

Comments
 (0)