Skip to content

Commit

Permalink
Adjustments for native code
Browse files Browse the repository at this point in the history
  • Loading branch information
mjunkin committed Nov 28, 2024
1 parent c330185 commit d5b0ad5
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 54 deletions.
13 changes: 6 additions & 7 deletions backend/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,12 @@
<artifactId>jersey-common</artifactId>
<version>2.26</version>
</dependency>
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-annotations</artifactId>
<version>${io.swagger.annotations.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<dependency>
<groupId>org.codehaus.janino</groupId>
<artifactId>janino</artifactId>
<version>3.1.12</version>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-flyway</artifactId>
<exclusions>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import ca.bc.gov.nrs.vdyp.backend.v1.api.projection.IProjectionRunner;
import ca.bc.gov.nrs.vdyp.backend.v1.api.projection.ProjectionRunner;
import ca.bc.gov.nrs.vdyp.backend.v1.api.projection.StubProjectionRunner;
import ca.bc.gov.nrs.vdyp.backend.v1.gen.api.ParameterNames;
import ca.bc.gov.nrs.vdyp.backend.v1.gen.model.Parameters;
import ca.bc.gov.nrs.vdyp.backend.v1.utils.FileHelper;
import jakarta.enterprise.context.ApplicationScoped;
Expand All @@ -50,9 +51,7 @@ public Response projectionHcsvPost(
FileUpload layersFileStream, //
SecurityContext securityContext
) {
if (trialRun == null) {
trialRun = false;
}
Response response;

Map<String, InputStream> inputStreams = new HashMap<>();

Expand All @@ -62,27 +61,37 @@ public Response projectionHcsvPost(

if (trialRun) {
if (polyStream.available() == 0) {
polyStream.close();
polyStream = FileHelper.getStubResourceFile("VDYP7_INPUT_POLY.csv");
}

if (layersStream.available() == 0) {
layersStream.close();
layersStream = FileHelper.getStubResourceFile("VDYP7_INPUT_LAYER.csv");
}
}

inputStreams.put("polygon", polyStream);
inputStreams.put("layers", layersStream);
response = runProjection("hcsv", inputStreams, trialRun, parameters, securityContext);

inputStreams.put(ParameterNames.POLYGON_INPUT_DATA, polyStream);
inputStreams.put(ParameterNames.LAYERS_INPUT_DATA, layersStream);
} catch (IOException e) {
String message = Exceptions.getMessage(e, "Projection, when opening input files,");

logger.error(message);

return Response.serverError().status(500).entity(message).build();
response = Response.serverError().status(500).entity(message).build();
} finally {
logger.info(FINALIZE_SESSION_MARKER, ">projectionHcsvPost");
for (var entry : inputStreams.entrySet()) {
try {
entry.getValue().close();
} catch (IOException e) {
logger.warn("Unable to close {}; reason: {}", entry.getKey(), e.getMessage());
}
}
}

return runProjection("hcsv", inputStreams, trialRun, parameters, securityContext);
return response;
}

public Response projectionDcsvPost(
Expand All @@ -103,52 +112,53 @@ private Response runProjection(
String projectionType, Map<String, InputStream> inputStreams, Boolean trialRun, Parameters params,
SecurityContext securityContext
) {
if (trialRun == null) {
trialRun = false;
}

String projectionId = ProjectionService.buildId(projectionType);

logger.info("<runProjection {} {}", projectionType, projectionId);

boolean debugLoggingEnabled = params.getSelectedExecutionOptions()
.contains(Parameters.SelectedExecutionOptionsEnum.DO_ENABLE_DEBUG_LOGGING);
if (debugLoggingEnabled) {
MDC.put("projectionId", projectionId);
}

IProjectionRunner runner;

logger.info("<projectionHcsvPost {}", projectionId);

if (trialRun) {
runner = new StubProjectionRunner(projectionId, params);
} else {
runner = new ProjectionRunner(projectionId, params);
}

runner.run(inputStreams);

/* this is known from logback.xml */
Path debugLogPath = Path.of("logs", projectionId + ".log");

InputStream debugLogStream;
Response response = Response.serverError().status(500).build();

try {
if (debugLoggingEnabled) {
debugLogStream = FileHelper.get(debugLogPath);
IProjectionRunner runner;

logger.info("Running {} projection {}", projectionType, projectionId);

if (trialRun) {
runner = new StubProjectionRunner(projectionId, params);
} else {
debugLogStream = new ByteArrayInputStream(new byte[0]);
runner = new ProjectionRunner(projectionId, params);
}
} catch (IOException e) {
String message = Exceptions.getMessage(e, "Projection, when opening input files,");

logger.error(message);
runner.run(inputStreams);

return Response.serverError().status(500).entity(message).build();
}
InputStream debugLogStream = new ByteArrayInputStream(new byte[0]);
try {
if (debugLoggingEnabled) {
debugLogStream = FileHelper.get(debugLogPath);
}
} catch (IOException e) {
String message = Exceptions.getMessage(e, "Projection, when opening input files,");
logger.warn(message);
}

Response response = buildOutputZipFile(runner, debugLogStream);
response = buildOutputZipFile(runner, debugLogStream);

if (debugLoggingEnabled) {
FileHelper.delete(debugLogPath);
} finally {
logger.info(FINALIZE_SESSION_MARKER, ">runProjection {} {}", projectionType, projectionId);

if (debugLoggingEnabled) {
MDC.remove("projectionId");
// FileHelper.delete(debugLogPath);
}
}

return response;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
import org.jboss.resteasy.reactive.multipart.FileUpload;

import ca.bc.gov.nrs.vdyp.backend.v1.api.ProjectionService;
import ca.bc.gov.nrs.vdyp.backend.v1.gen.model.MessagesInner;
import ca.bc.gov.nrs.vdyp.backend.v1.gen.model.Parameters;
import ca.bc.gov.nrs.vdyp.backend.v1.gen.responses.ProjectionResource;
import io.quarkus.runtime.annotations.RegisterForReflection;
import jakarta.inject.Inject;
import jakarta.ws.rs.Consumes;
Expand Down
2 changes: 1 addition & 1 deletion backend/src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@

mp.openapi.scan.disable=false
mp.openapi.extensions.smallrye.operationIdStrategy=METHOD
quarkus.native.additional-build-args=--initialize-at-run-time=org.glassfish.jersey.server.internal.process.RequestProcessingContext,-H:+UnlockExperimentalVMOptions,-H:Log=registerResource:3
quarkus.native.additional-build-args=--initialize-at-run-time=org.glassfish.jersey.server.internal.process.RequestProcessingContext\\,io.netty.resolver.dns.DnsServerAddressStreamProviders,-H:+UnlockExperimentalVMOptions,-H:Log=registerResource:3
quarkus.native.resources.includes=VDYP7Console-sample-files/**
10 changes: 2 additions & 8 deletions backend/src/main/resources/logback.xml
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
<configuration>

<turboFilter class="ch.qos.logback.classic.turbo.MDCFilter">
<MDCKey>projectionId</MDCKey>
<Value>not-request-specific</Value>
<OnMatch>DENY</OnMatch>
</turboFilter>

<appender name="sifter" class="ch.qos.logback.classic.sift.SiftingAppender">
<!-- in the absence of the class attribute, it is assumed that the
desired discriminator type is
Expand All @@ -20,7 +14,7 @@
<immediateFlush>true</immediateFlush>
<append>false</append>
<layout class="ch.qos.logback.classic.PatternLayout">
<pattern>%d [%thread] %level %mdc %logger{35} -%kvp -%msg%n</pattern>
<pattern>%d [%thread] %-5level %logger{35}: %msg%n</pattern>
</layout>
</appender>
</sift>
Expand All @@ -30,7 +24,7 @@
<!-- encoders are assigned the type
ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
<encoder>
<pattern>%-4relative [%thread] %-5level %logger{35} -%kvp- %msg %n</pattern>
<pattern>%-4relative [%thread] %-5level %logger{35}: %msg%n</pattern>
</encoder>
</appender>

Expand Down

0 comments on commit d5b0ad5

Please sign in to comment.