Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 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
20 changes: 13 additions & 7 deletions batch/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -133,16 +133,22 @@
<plugin>
<groupId>net.revelc.code.formatter</groupId>
<artifactId>formatter-maven-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
<executions>
<execution>
<goals>
<goal>format</goal>
</goals>
<configuration>
<configFile>../buildtools/src/main/resources/eclipse/formatter.xml</configFile>
</configuration>
<id>default</id>
<phase>none</phase>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>ca.bc.gov.nrs.vdyp</groupId>
<artifactId>vdyp-buildtools</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</plugin>

<plugin>
Expand Down Expand Up @@ -224,4 +230,4 @@
</plugin>
</plugins>
</build>
</project>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.event.EventListener;
import org.springframework.aot.hint.annotation.RegisterReflectionForBinding;
import ca.bc.gov.nrs.vdyp.batch.model.BatchRecord;
import ca.bc.gov.nrs.vdyp.batch.controller.BatchJobRequest;
Expand All @@ -15,17 +17,46 @@ public class VdypBatchApplication {
private static final Logger logger = LoggerFactory.getLogger(VdypBatchApplication.class);

public static void main(String[] args) {
// Override VDYP properties before any VdypComponent initialization
// This ensures VdypComponent uses correct values regardless of classpath order
overrideVdypProperties();

SpringApplication.run(VdypBatchApplication.class, args);
}

/**
* This method is called once when the application is fully started and ready.
* Using ApplicationReadyEvent ensures
* the startup message is shown only once, not on every batch job execution.
*/
@EventListener(ApplicationReadyEvent.class)
public void onApplicationReady() {
String separator = "============================================================";
logger.info(separator);
logger.info("VDYP Batch Processing Service Started!");
logger.info("API Endpoints:");
logger.info(" POST /api/batch/start - Start batch job");
logger.info(" GET /api/batch/status/{id} - Check job status");
logger.info(" GET /api/batch/status/{{id}} - Check job status");
logger.info(" GET /api/batch/jobs - List recent jobs");
logger.info(" GET /api/batch/metrics/{id} - Get detailed job metrics");
logger.info(" GET /api/batch/statistics - Get batch statistics");
logger.info(" GET /api/batch/metrics/{{id}} - Get detailed job metrics");
logger.info(" GET /api/batch/health - Health check");
logger.info(separator);
}

private static void overrideVdypProperties() {
// Create a ClassLoader that prioritizes the application.properties
Thread.currentThread().setContextClassLoader(new ClassLoader(Thread.currentThread().getContextClassLoader()) {
@Override
public java.io.InputStream getResourceAsStream(String name) {
if ("application.properties".equals(name)) {
// Return the batch module's application.properties first
java.io.InputStream stream = VdypBatchApplication.class.getClassLoader().getResourceAsStream(name);
if (stream != null) {
return stream;
}
}
return super.getResourceAsStream(name);
}
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import org.springframework.stereotype.Component;

/**
* Configuration properties for VDYP batch processing. This class handles all custom batch.* properties to eliminate
* unknown property warnings.
* Configuration properties for VDYP batch processing. This class handles all
* custom batch.* properties to eliminate unknown property warnings.
*/
@Component
@ConfigurationProperties(prefix = "batch")
Expand All @@ -17,9 +17,9 @@ public class BatchProperties {
private Partitioning partitioning = new Partitioning();
private ThreadPool threadPool = new ThreadPool();
private Validation validation = new Validation();
private Error error = new Error();
private Retry retry = new Retry();
private Skip skip = new Skip();
private Reader reader = new Reader();

public static class Job {
private boolean autoCreate = true;
Expand All @@ -34,21 +34,7 @@ public void setAutoCreate(boolean autoCreate) {
}

public static class Input {
private String filePath;

public String getFilePath() {
return filePath;
}

public void setFilePath(String filePath) {
this.filePath = filePath;
}
}

public static class Output {
private Directory directory = new Directory();
private String filePrefix;
private String csvHeader;

public static class Directory {
private String defaultPath;
Expand All @@ -70,35 +56,34 @@ public void setDirectory(Directory directory) {
this.directory = directory;
}

public String getFilePrefix() {
return filePrefix;
}
}

public static class Output {
private Directory directory = new Directory();

public static class Directory {
private String defaultPath;

public String getDefaultPath() {
return defaultPath;
}

public void setFilePrefix(String filePrefix) {
this.filePrefix = filePrefix;
public void setDefaultPath(String defaultPath) {
this.defaultPath = defaultPath;
}
}

public String getCsvHeader() {
return csvHeader;
public Directory getDirectory() {
return directory;
}

public void setCsvHeader(String csvHeader) {
this.csvHeader = csvHeader;
public void setDirectory(Directory directory) {
this.directory = directory;
}
}

public static class Partitioning {
private boolean enabled = true;
private int gridSize;
private int chunkSize;

public boolean isEnabled() {
return enabled;
}

public void setEnabled(boolean enabled) {
this.enabled = enabled;
}

public int getGridSize() {
return gridSize;
Expand All @@ -107,14 +92,6 @@ public int getGridSize() {
public void setGridSize(int gridSize) {
this.gridSize = gridSize;
}

public int getChunkSize() {
return chunkSize;
}

public void setChunkSize(int chunkSize) {
this.chunkSize = chunkSize;
}
}

public static class Retry {
Expand Down Expand Up @@ -198,27 +175,6 @@ public void setMaxPolygonIdLength(int maxPolygonIdLength) {
}
}

public static class Error {
private String transientPatterns;
private int maxConsecutiveFailures;

public String getTransientPatterns() {
return transientPatterns;
}

public void setTransientPatterns(String transientPatterns) {
this.transientPatterns = transientPatterns;
}

public int getMaxConsecutiveFailures() {
return maxConsecutiveFailures;
}

public void setMaxConsecutiveFailures(int maxConsecutiveFailures) {
this.maxConsecutiveFailures = maxConsecutiveFailures;
}
}

public static class Skip {
private int maxCount;

Expand All @@ -231,6 +187,18 @@ public void setMaxCount(int maxCount) {
}
}

public static class Reader {
private int chunkSize = 10;

public int getChunkSize() {
return chunkSize;
}

public void setChunkSize(int chunkSize) {
this.chunkSize = chunkSize;
}
}

public Job getJob() {
return job;
}
Expand Down Expand Up @@ -287,19 +255,20 @@ public void setValidation(Validation validation) {
this.validation = validation;
}

public Error getError() {
return error;
}

public void setError(Error error) {
this.error = error;
}

public Skip getSkip() {
return skip;
}

public void setSkip(Skip skip) {
this.skip = skip;
}
}

public Reader getReader() {
return reader;
}

public void setReader(Reader reader) {
this.reader = reader;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -215,9 +215,9 @@ private BatchRecord extractRecord(Throwable t) {
return cachedRecord;
}

// Fallback: create a basic record with the extracted ID for tracking
// Fallback: create a basic record with the extracted recordId as featureId for tracking
BatchRecord batchRecord = new BatchRecord();
batchRecord.setId(recordId);
batchRecord.setFeatureId(String.valueOf(recordId));
return batchRecord;
}
return null;
Expand Down
Loading
Loading