@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2017-2019 the original author or authors.
|
||||
* Copyright 2019-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -23,16 +23,23 @@ import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.springframework.boot.ApplicationArguments;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.boot.env.EnvironmentPostProcessor;
|
||||
import org.springframework.boot.loader.archive.Archive;
|
||||
import org.springframework.boot.loader.archive.JarFileArchive;
|
||||
import org.springframework.cloud.function.context.FunctionRegistry;
|
||||
import org.springframework.context.SmartLifecycle;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.env.ConfigurableEnvironment;
|
||||
|
||||
/**
|
||||
*
|
||||
* Configuration class which creates an instance of {@link SmartLifecycle}
|
||||
* which deploys and un-deploys packages archives via it's {@link SmartLifecycle#start()}
|
||||
* and {@link SmartLifecycle#stop()} operations.
|
||||
* <br>
|
||||
* @author Oleg Zhurakousky
|
||||
*
|
||||
* @since 3.0
|
||||
@@ -97,4 +104,19 @@ public class FunctionDeployerConfiguration {
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Instance of {@link EnvironmentPostProcessor} which ensures that legacy
|
||||
* Function property names are still honored.
|
||||
*/
|
||||
static class LegacyPropertyEnvironmentPostProcessor implements EnvironmentPostProcessor {
|
||||
@Override
|
||||
public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) {
|
||||
if (environment.containsProperty("function.name")) {
|
||||
System.setProperty(FunctionProperties.PREFIX + ".function-name", environment.getProperty("function.name"));
|
||||
}
|
||||
if (environment.containsProperty("function.location")) {
|
||||
System.setProperty(FunctionProperties.PREFIX + ".location", environment.getProperty("function.location"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,10 +26,16 @@ import org.springframework.util.StringUtils;
|
||||
* Configuration properties for deciding how to locate the functional class to execute.
|
||||
*
|
||||
* @author Eric Bottard
|
||||
* @author Oleg Zhurakousky
|
||||
*/
|
||||
@ConfigurationProperties("spring.cloud.function")
|
||||
public class FunctionProperties {
|
||||
|
||||
/**
|
||||
* The name prefix for properties defined by this properties class.
|
||||
*/
|
||||
public final static String PREFIX = "spring.cloud.function";
|
||||
|
||||
/**
|
||||
* Location of jar archive containing the supplier/function/consumer class or bean to run.
|
||||
*/
|
||||
|
||||
@@ -1 +1,2 @@
|
||||
org.springframework.boot.autoconfigure.EnableAutoConfiguration=org.springframework.cloud.function.deployer.FunctionDeployerConfiguration
|
||||
org.springframework.boot.autoconfigure.EnableAutoConfiguration=org.springframework.cloud.function.deployer.FunctionDeployerConfiguration
|
||||
org.springframework.boot.env.EnvironmentPostProcessor=org.springframework.cloud.function.deployer.FunctionDeployerConfiguration$LegacyPropertyEnvironmentPostProcessor
|
||||
@@ -154,6 +154,20 @@ public class FunctionDeployerTests {
|
||||
assertThat(new String(result.getPayload(), StandardCharsets.UTF_8)).isEqualTo("\"BOB\"");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWithLegacyProperties() throws Exception {
|
||||
String[] args = new String[] {
|
||||
"--function.location=target/it/bootapp/target/bootapp-1.0.0.RELEASE-exec.jar",
|
||||
"--function.name=uppercase" };
|
||||
ApplicationContext context = SpringApplication.run(DeployerApplication.class, args);
|
||||
FunctionCatalog catalog = context.getBean(FunctionCatalog.class);
|
||||
Function<Message<byte[]>, Message<byte[]>> function = catalog.lookup("uppercase", "application/json");
|
||||
|
||||
Message<byte[]> result = function
|
||||
.apply(MessageBuilder.withPayload("\"bob\"".getBytes(StandardCharsets.UTF_8)).build());
|
||||
assertThat(new String(result.getPayload(), StandardCharsets.UTF_8)).isEqualTo("\"BOB\"");
|
||||
}
|
||||
|
||||
/*
|
||||
* Same as above but:
|
||||
* Given that Java 11 does not include 'javax' packages, this test simply validates that
|
||||
|
||||
Reference in New Issue
Block a user