Skip to content

Commit

Permalink
Merge pull request #44971 from mcruzdev/config-amz-lambda-common
Browse files Browse the repository at this point in the history
Convert Lambda Common to use @ConfigMapping
  • Loading branch information
gsmet authored Dec 7, 2024
2 parents 73b62a5 + 8989e17 commit c3710d4
Show file tree
Hide file tree
Showing 10 changed files with 29 additions and 38 deletions.
3 changes: 0 additions & 3 deletions extensions/amazon-lambda/common-deployment/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,6 @@
<version>${project.version}</version>
</path>
</annotationProcessorPaths>
<compilerArgs>
<arg>-AlegacyConfigRoot=true</arg>
</compilerArgs>
</configuration>
</execution>
</executions>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public void startEventServer(LaunchModeBuildItem launchMode,
return;
if (legacyTestingEnabled())
return;
if (!config.mockEventServer.enabled) {
if (!config.mockEventServer().enabled()) {
return;
}
if (server != null) {
Expand All @@ -77,8 +77,8 @@ public void startEventServer(LaunchModeBuildItem launchMode,
}

server = supplier.get();
int port = launchMode.getLaunchMode() == LaunchMode.TEST ? config.mockEventServer.testPort
: config.mockEventServer.devPort;
int port = launchMode.getLaunchMode() == LaunchMode.TEST ? config.mockEventServer().testPort()
: config.mockEventServer().devPort();
startMode = launchMode.getLaunchMode();
server.start(port);
int actualPort = server.getPort();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@

import io.quarkus.runtime.annotations.ConfigPhase;
import io.quarkus.runtime.annotations.ConfigRoot;
import io.smallrye.config.ConfigMapping;

@ConfigRoot(phase = ConfigPhase.BUILD_TIME)
public class LambdaConfig {
@ConfigMapping(prefix = "quarkus.lambda")
public interface LambdaConfig {

/**
* Configuration for the mock event server that is run
* in dev mode and test mode
*/
MockEventServerConfig mockEventServer;
MockEventServerConfig mockEventServer();
}
Original file line number Diff line number Diff line change
@@ -1,29 +1,27 @@
package io.quarkus.amazon.lambda.deployment;

import io.quarkus.runtime.annotations.ConfigGroup;
import io.quarkus.runtime.annotations.ConfigItem;
import io.smallrye.config.WithDefault;

/**
* Configuration for the mock event server that is run
* in dev mode and test mode
*/
@ConfigGroup
public class MockEventServerConfig {
public interface MockEventServerConfig {
/**
* Setting to true will start event server even if quarkus.devservices.enabled=false
*/
@ConfigItem(defaultValue = "true")
public boolean enabled;
@WithDefault("true")
boolean enabled();

/**
* Port to access mock event server in dev mode
*/
@ConfigItem(defaultValue = "8080")
public int devPort;
@WithDefault("8080")
int devPort();

/**
* Port to access mock event server in dev mode
*/
@ConfigItem(defaultValue = "8081")
public int testPort;
@WithDefault("8081")
int testPort();
}
3 changes: 0 additions & 3 deletions extensions/amazon-lambda/common-runtime/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,6 @@
<version>${project.version}</version>
</path>
</annotationProcessorPaths>
<compilerArgs>
<arg>-AlegacyConfigRoot=true</arg>
</compilerArgs>
</configuration>
</execution>
</executions>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ void startPoolLoopDevOrTest(AmazonLambdaRecorder recorder,
void recordExpectedExceptions(LambdaBuildTimeConfig config,
BuildProducer<ReflectiveClassBuildItem> registerForReflection,
AmazonLambdaStaticRecorder recorder) {
Set<Class<?>> classes = config.expectedExceptions.map(Set::copyOf).orElseGet(Set::of);
Set<Class<?>> classes = config.expectedExceptions().map(Set::copyOf).orElseGet(Set::of);
classes.stream()
.map(clazz -> ReflectiveClassBuildItem.builder(clazz).constructors(false)
.reason(getClass().getName() + " expectedExceptions")
Expand Down
3 changes: 0 additions & 3 deletions extensions/amazon-lambda/runtime/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,6 @@
<version>${project.version}</version>
</path>
</annotationProcessorPaths>
<compilerArgs>
<arg>-AlegacyConfigRoot=true</arg>
</compilerArgs>
</configuration>
</execution>
</executions>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,12 @@ public void chooseHandlerClass(List<Class<? extends RequestHandler<?, ?>>> unnam

Class<? extends RequestHandler<?, ?>> handlerClass = null;
Class<? extends RequestStreamHandler> handlerStreamClass = null;
if (config.handler.isPresent()) {
handlerClass = namedHandlerClasses.get(config.handler.get());
handlerStreamClass = namedStreamHandlerClasses.get(config.handler.get());
if (config.handler().isPresent()) {
handlerClass = namedHandlerClasses.get(config.handler().get());
handlerStreamClass = namedStreamHandlerClasses.get(config.handler().get());

if (handlerClass == null && handlerStreamClass == null) {
String errorMessage = "Unable to find handler class with name " + config.handler.get()
String errorMessage = "Unable to find handler class with name " + config.handler().get()
+ " make sure there is a handler class in the deployment with the correct @Named annotation";
throw new RuntimeException(errorMessage);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
import java.util.List;
import java.util.Optional;

import io.quarkus.runtime.annotations.ConfigItem;
import io.quarkus.runtime.annotations.ConfigPhase;
import io.quarkus.runtime.annotations.ConfigRoot;
import io.smallrye.config.ConfigMapping;

@ConfigRoot(name = "lambda", phase = ConfigPhase.BUILD_AND_RUN_TIME_FIXED)
public class LambdaBuildTimeConfig {
@ConfigRoot(phase = ConfigPhase.BUILD_AND_RUN_TIME_FIXED)
@ConfigMapping(prefix = "quarkus.lambda")
public interface LambdaBuildTimeConfig {

/**
* The exception classes expected to be thrown by the handler.
Expand All @@ -17,6 +18,5 @@ public class LambdaBuildTimeConfig {
* but will otherwise be handled normally by the lambda runtime. This is useful for avoiding unnecessary
* stack traces while preserving the ability to log unexpected exceptions.
*/
@ConfigItem
public Optional<List<Class<?>>> expectedExceptions;
Optional<List<Class<?>>> expectedExceptions();
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

import java.util.Optional;

import io.quarkus.runtime.annotations.ConfigItem;
import io.quarkus.runtime.annotations.ConfigPhase;
import io.quarkus.runtime.annotations.ConfigRoot;
import io.smallrye.config.ConfigMapping;

@ConfigRoot(phase = ConfigPhase.RUN_TIME)
public class LambdaConfig {
@ConfigMapping(prefix = "quarkus.lambda")
public interface LambdaConfig {

/**
* The handler name. Handler names are specified on handler classes using the {@link @jakarta.inject.Named} annotation.
Expand All @@ -18,6 +19,5 @@ public class LambdaConfig {
* then the named handler will be used.
*
*/
@ConfigItem
public Optional<String> handler;
Optional<String> handler();
}

0 comments on commit c3710d4

Please sign in to comment.