Skip to content

Commit d072606

Browse files
Merge pull request #245 from bcgov/feature/VDYP-714
VDYP-714: VDYP Batch - Execution
2 parents 2791e01 + 9badaa5 commit d072606

File tree

46 files changed

+4512
-3623
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+4512
-3623
lines changed

batch/pom.xml

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -133,16 +133,22 @@
133133
<plugin>
134134
<groupId>net.revelc.code.formatter</groupId>
135135
<artifactId>formatter-maven-plugin</artifactId>
136+
<configuration>
137+
<skip>true</skip>
138+
</configuration>
136139
<executions>
137140
<execution>
138-
<goals>
139-
<goal>format</goal>
140-
</goals>
141-
<configuration>
142-
<configFile>../buildtools/src/main/resources/eclipse/formatter.xml</configFile>
143-
</configuration>
141+
<id>default</id>
142+
<phase>none</phase>
144143
</execution>
145144
</executions>
145+
<dependencies>
146+
<dependency>
147+
<groupId>ca.bc.gov.nrs.vdyp</groupId>
148+
<artifactId>vdyp-buildtools</artifactId>
149+
<version>${project.version}</version>
150+
</dependency>
151+
</dependencies>
146152
</plugin>
147153

148154
<plugin>
@@ -224,4 +230,4 @@
224230
</plugin>
225231
</plugins>
226232
</build>
227-
</project>
233+
</project>

batch/src/main/java/ca/bc/gov/nrs/vdyp/batch/VdypBatchApplication.java

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import org.slf4j.LoggerFactory;
55
import org.springframework.boot.SpringApplication;
66
import org.springframework.boot.autoconfigure.SpringBootApplication;
7+
import org.springframework.boot.context.event.ApplicationReadyEvent;
8+
import org.springframework.context.event.EventListener;
79
import org.springframework.aot.hint.annotation.RegisterReflectionForBinding;
810
import ca.bc.gov.nrs.vdyp.batch.model.BatchRecord;
911
import ca.bc.gov.nrs.vdyp.batch.controller.BatchJobRequest;
@@ -15,17 +17,46 @@ public class VdypBatchApplication {
1517
private static final Logger logger = LoggerFactory.getLogger(VdypBatchApplication.class);
1618

1719
public static void main(String[] args) {
20+
// Override VDYP properties before any VdypComponent initialization
21+
// This ensures VdypComponent uses correct values regardless of classpath order
22+
overrideVdypProperties();
23+
1824
SpringApplication.run(VdypBatchApplication.class, args);
25+
}
26+
27+
/**
28+
* This method is called once when the application is fully started and ready.
29+
* Using ApplicationReadyEvent ensures
30+
* the startup message is shown only once, not on every batch job execution.
31+
*/
32+
@EventListener(ApplicationReadyEvent.class)
33+
public void onApplicationReady() {
1934
String separator = "============================================================";
2035
logger.info(separator);
2136
logger.info("VDYP Batch Processing Service Started!");
2237
logger.info("API Endpoints:");
2338
logger.info(" POST /api/batch/start - Start batch job");
24-
logger.info(" GET /api/batch/status/{id} - Check job status");
39+
logger.info(" GET /api/batch/status/{{id}} - Check job status");
2540
logger.info(" GET /api/batch/jobs - List recent jobs");
26-
logger.info(" GET /api/batch/metrics/{id} - Get detailed job metrics");
27-
logger.info(" GET /api/batch/statistics - Get batch statistics");
41+
logger.info(" GET /api/batch/metrics/{{id}} - Get detailed job metrics");
2842
logger.info(" GET /api/batch/health - Health check");
2943
logger.info(separator);
3044
}
45+
46+
private static void overrideVdypProperties() {
47+
// Create a ClassLoader that prioritizes the application.properties
48+
Thread.currentThread().setContextClassLoader(new ClassLoader(Thread.currentThread().getContextClassLoader()) {
49+
@Override
50+
public java.io.InputStream getResourceAsStream(String name) {
51+
if ("application.properties".equals(name)) {
52+
// Return the batch module's application.properties first
53+
java.io.InputStream stream = VdypBatchApplication.class.getClassLoader().getResourceAsStream(name);
54+
if (stream != null) {
55+
return stream;
56+
}
57+
}
58+
return super.getResourceAsStream(name);
59+
}
60+
});
61+
}
3162
}

batch/src/main/java/ca/bc/gov/nrs/vdyp/batch/configuration/BatchProperties.java

Lines changed: 43 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
import org.springframework.stereotype.Component;
55

66
/**
7-
* Configuration properties for VDYP batch processing. This class handles all custom batch.* properties to eliminate
8-
* unknown property warnings.
7+
* Configuration properties for VDYP batch processing. This class handles all
8+
* custom batch.* properties to eliminate unknown property warnings.
99
*/
1010
@Component
1111
@ConfigurationProperties(prefix = "batch")
@@ -17,9 +17,9 @@ public class BatchProperties {
1717
private Partitioning partitioning = new Partitioning();
1818
private ThreadPool threadPool = new ThreadPool();
1919
private Validation validation = new Validation();
20-
private Error error = new Error();
2120
private Retry retry = new Retry();
2221
private Skip skip = new Skip();
22+
private Reader reader = new Reader();
2323

2424
public static class Job {
2525
private boolean autoCreate = true;
@@ -34,21 +34,7 @@ public void setAutoCreate(boolean autoCreate) {
3434
}
3535

3636
public static class Input {
37-
private String filePath;
38-
39-
public String getFilePath() {
40-
return filePath;
41-
}
42-
43-
public void setFilePath(String filePath) {
44-
this.filePath = filePath;
45-
}
46-
}
47-
48-
public static class Output {
4937
private Directory directory = new Directory();
50-
private String filePrefix;
51-
private String csvHeader;
5238

5339
public static class Directory {
5440
private String defaultPath;
@@ -70,35 +56,34 @@ public void setDirectory(Directory directory) {
7056
this.directory = directory;
7157
}
7258

73-
public String getFilePrefix() {
74-
return filePrefix;
75-
}
59+
}
60+
61+
public static class Output {
62+
private Directory directory = new Directory();
63+
64+
public static class Directory {
65+
private String defaultPath;
66+
67+
public String getDefaultPath() {
68+
return defaultPath;
69+
}
7670

77-
public void setFilePrefix(String filePrefix) {
78-
this.filePrefix = filePrefix;
71+
public void setDefaultPath(String defaultPath) {
72+
this.defaultPath = defaultPath;
73+
}
7974
}
8075

81-
public String getCsvHeader() {
82-
return csvHeader;
76+
public Directory getDirectory() {
77+
return directory;
8378
}
8479

85-
public void setCsvHeader(String csvHeader) {
86-
this.csvHeader = csvHeader;
80+
public void setDirectory(Directory directory) {
81+
this.directory = directory;
8782
}
8883
}
8984

9085
public static class Partitioning {
91-
private boolean enabled = true;
9286
private int gridSize;
93-
private int chunkSize;
94-
95-
public boolean isEnabled() {
96-
return enabled;
97-
}
98-
99-
public void setEnabled(boolean enabled) {
100-
this.enabled = enabled;
101-
}
10287

10388
public int getGridSize() {
10489
return gridSize;
@@ -107,14 +92,6 @@ public int getGridSize() {
10792
public void setGridSize(int gridSize) {
10893
this.gridSize = gridSize;
10994
}
110-
111-
public int getChunkSize() {
112-
return chunkSize;
113-
}
114-
115-
public void setChunkSize(int chunkSize) {
116-
this.chunkSize = chunkSize;
117-
}
11895
}
11996

12097
public static class Retry {
@@ -198,27 +175,6 @@ public void setMaxPolygonIdLength(int maxPolygonIdLength) {
198175
}
199176
}
200177

201-
public static class Error {
202-
private String transientPatterns;
203-
private int maxConsecutiveFailures;
204-
205-
public String getTransientPatterns() {
206-
return transientPatterns;
207-
}
208-
209-
public void setTransientPatterns(String transientPatterns) {
210-
this.transientPatterns = transientPatterns;
211-
}
212-
213-
public int getMaxConsecutiveFailures() {
214-
return maxConsecutiveFailures;
215-
}
216-
217-
public void setMaxConsecutiveFailures(int maxConsecutiveFailures) {
218-
this.maxConsecutiveFailures = maxConsecutiveFailures;
219-
}
220-
}
221-
222178
public static class Skip {
223179
private int maxCount;
224180

@@ -231,6 +187,18 @@ public void setMaxCount(int maxCount) {
231187
}
232188
}
233189

190+
public static class Reader {
191+
private int chunkSize = 10;
192+
193+
public int getChunkSize() {
194+
return chunkSize;
195+
}
196+
197+
public void setChunkSize(int chunkSize) {
198+
this.chunkSize = chunkSize;
199+
}
200+
}
201+
234202
public Job getJob() {
235203
return job;
236204
}
@@ -287,19 +255,20 @@ public void setValidation(Validation validation) {
287255
this.validation = validation;
288256
}
289257

290-
public Error getError() {
291-
return error;
292-
}
293-
294-
public void setError(Error error) {
295-
this.error = error;
296-
}
297-
298258
public Skip getSkip() {
299259
return skip;
300260
}
301261

302262
public void setSkip(Skip skip) {
303263
this.skip = skip;
304264
}
305-
}
265+
266+
public Reader getReader() {
267+
return reader;
268+
}
269+
270+
public void setReader(Reader reader) {
271+
this.reader = reader;
272+
}
273+
274+
}

batch/src/main/java/ca/bc/gov/nrs/vdyp/batch/configuration/BatchSkipPolicy.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,9 +215,9 @@ private BatchRecord extractRecord(Throwable t) {
215215
return cachedRecord;
216216
}
217217

218-
// Fallback: create a basic record with the extracted ID for tracking
218+
// Fallback: create a basic record with the extracted recordId as featureId for tracking
219219
BatchRecord batchRecord = new BatchRecord();
220-
batchRecord.setId(recordId);
220+
batchRecord.setFeatureId(String.valueOf(recordId));
221221
return batchRecord;
222222
}
223223
return null;

0 commit comments

Comments
 (0)