Skip to content

Commit

Permalink
Merge pull request #45702 from mcruzdev/feature/config-funqy
Browse files Browse the repository at this point in the history
Convert funqy extensions to use @ConfigMapping
  • Loading branch information
gsmet authored Jan 19, 2025
2 parents f87ad4c + 187a356 commit 6488f90
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@ public void init(BeanContainer bc, FunqyAmazonBuildTimeConfig buildTimeConfig) {

public void chooseInvoker(FunqyConfig config, FunqyAmazonConfig amazonConfig) {
// this is done at Runtime so that we can change it with an environment variable.
if (config.export.isPresent()) {
invoker = FunctionRecorder.registry.matchInvoker(config.export.get());
if (config.export().isPresent()) {
invoker = FunctionRecorder.registry.matchInvoker(config.export().get());
if (invoker == null) {
throw new RuntimeException("quarkus.funqy.export does not match a function: " + config.export.get());
throw new RuntimeException("quarkus.funqy.export does not match a function: " + config.export().get());
}
} else if (FunctionRecorder.registry.invokers().size() == 0) {
throw new RuntimeException("There are no functions to process lambda");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ public void init(BeanContainer bc) {

public void chooseInvoker(FunqyConfig config) {
// this is done at Runtime so that we can change it with an environment variable.
if (config.export.isPresent()) {
invoker = FunctionRecorder.registry.matchInvoker(config.export.get());
if (config.export().isPresent()) {
invoker = FunctionRecorder.registry.matchInvoker(config.export().get());
if (invoker == null) {
throw new RuntimeException("quarkus.funqy.export does not match a function: " + config.export.get());
throw new RuntimeException("quarkus.funqy.export does not match a function: " + config.export().get());
}
} else if (FunctionRecorder.registry.invokers().size() == 0) {
throw new RuntimeException("There are no functions to process lambda");
Expand Down
3 changes: 0 additions & 3 deletions extensions/funqy/funqy-knative-events/deployment/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,6 @@
<version>${project.version}</version>
</path>
</annotationProcessorPaths>
<compilerArgs>
<arg>-AlegacyConfigRoot=true</arg>
</compilerArgs>
</configuration>
</execution>
</executions>
Expand Down
3 changes: 0 additions & 3 deletions extensions/funqy/funqy-knative-events/runtime/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,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 @@ -4,15 +4,16 @@
import java.util.Optional;

import io.quarkus.runtime.annotations.ConfigGroup;
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 = "funqy.knative-events", phase = ConfigPhase.RUN_TIME)
public class FunqyKnativeEventsConfig {
@ConfigRoot(phase = ConfigPhase.RUN_TIME)
@ConfigMapping(prefix = "quarkus.funqy.knative-events")
public interface FunqyKnativeEventsConfig {

@ConfigGroup
public static class FunctionMapping {
interface FunctionMapping {
/**
* Cloud Event type (ce-type) that triggers this function.
* Default value is function name.
Expand All @@ -23,28 +24,24 @@ public static class FunctionMapping {
* you to change the knative trigger binding without having to change the configuration
* of the quarkus deployment.
*/
@ConfigItem
public Optional<String> trigger;
Optional<String> trigger();

/**
* If function has response output, then what is the Cloud Event type (ce-type)?
* This will default to {function}.output
*/
@ConfigItem
public Optional<String> responseType;
Optional<String> responseType();

/**
* If function has response output, then what is the Cloud Event source (ce-source)?
* This will default to the function name
*/
@ConfigItem
public Optional<String> responseSource;
Optional<String> responseSource();
}

/**
* Cloud event to function mapping. Key to this map is a function name.
*/
@ConfigItem
public Map<String, FunctionMapping> mapping;
Map<String, FunctionMapping> mapping();

}
Original file line number Diff line number Diff line change
Expand Up @@ -187,24 +187,24 @@ public void run() {
// This needs to happen in start at RUNTIME so that
// mappings can be overridden by environment variables
FunctionInvoker defaultInvoker = null;
if (funqyConfig.export.isPresent()) {
defaultInvoker = FunctionRecorder.registry.matchInvoker(funqyConfig.export.get());
if (funqyConfig.export().isPresent()) {
defaultInvoker = FunctionRecorder.registry.matchInvoker(funqyConfig.export().get());
if (defaultInvoker == null) {
throw new RuntimeException("quarkus.funqy.export value does not map a function: " + funqyConfig.export.get());
throw new RuntimeException("quarkus.funqy.export value does not map a function: " + funqyConfig.export().get());
}

}

if (eventsConfig.mapping != null) {
for (Map.Entry<String, FunqyKnativeEventsConfig.FunctionMapping> entry : eventsConfig.mapping.entrySet()) {
if (eventsConfig.mapping() != null) {
for (Map.Entry<String, FunqyKnativeEventsConfig.FunctionMapping> entry : eventsConfig.mapping().entrySet()) {
String functionName = entry.getKey();
FunctionInvoker invoker = FunctionRecorder.registry.matchInvoker(functionName);
if (invoker == null) {
throw new RuntimeException("knative-events.function-mapping does not map to a function: " + functionName);
}
FunqyKnativeEventsConfig.FunctionMapping mapping = entry.getValue();
if (mapping.trigger.isPresent()) {
typeTriggers.compute(mapping.trigger.get(), (k, v) -> {
if (mapping.trigger().isPresent()) {
typeTriggers.compute(mapping.trigger().get(), (k, v) -> {
if (v == null) {
v = new ArrayList<>();
}
Expand All @@ -213,11 +213,11 @@ public void run() {
});
}
if (invoker.hasOutput()) {
if (mapping.responseSource.isPresent()) {
invoker.getBindingContext().put(RESPONSE_SOURCE, mapping.responseSource.get());
if (mapping.responseSource().isPresent()) {
invoker.getBindingContext().put(RESPONSE_SOURCE, mapping.responseSource().get());
}
if (mapping.responseType.isPresent()) {
invoker.getBindingContext().put(RESPONSE_TYPE, mapping.responseType.get());
if (mapping.responseType().isPresent()) {
invoker.getBindingContext().put(RESPONSE_TYPE, mapping.responseType().get());
}
}
}
Expand Down
3 changes: 0 additions & 3 deletions extensions/funqy/funqy-server-common/deployment/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,6 @@
<version>${project.version}</version>
</path>
</annotationProcessorPaths>
<compilerArgs>
<arg>-AlegacyConfigRoot=true</arg>
</compilerArgs>
</configuration>
</execution>
</executions>
Expand Down
3 changes: 0 additions & 3 deletions extensions/funqy/funqy-server-common/runtime/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,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 @@ -2,19 +2,19 @@

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 FunqyConfig {
@ConfigMapping(prefix = "quarkus.funqy")
public interface FunqyConfig {

/**
* The function to export. If there is more than one function
* defined for this deployment, then you must set this variable.
* If there is only a single function, you do not have to set this config item.
*
*/
@ConfigItem
public Optional<String> export;
Optional<String> export();
}

0 comments on commit 6488f90

Please sign in to comment.