GH-394 Ensured deployer supports old Function properties

Resolves #394
This commit is contained in:
Oleg Zhurakousky
2019-08-13 21:07:34 +02:00
parent cc0dcaf6ed
commit e27f1e9d97
4 changed files with 45 additions and 2 deletions

View File

@@ -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"));
}
}
}
}

View File

@@ -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.
*/

View File

@@ -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