diff --git a/pom.xml b/pom.xml index 27db9d0fb..bc9d699c9 100644 --- a/pom.xml +++ b/pom.xml @@ -60,7 +60,6 @@ spring-cloud-starter-function-webflux spring-cloud-function-samples spring-cloud-function-deployer - spring-cloud-function-deployer-new spring-cloud-function-adapters spring-cloud-function-kotlin docs diff --git a/spring-cloud-function-deployer-new/pom.xml b/spring-cloud-function-deployer-new/pom.xml deleted file mode 100644 index ad178f090..000000000 --- a/spring-cloud-function-deployer-new/pom.xml +++ /dev/null @@ -1,117 +0,0 @@ - - - 4.0.0 - spring-cloud-function-deployer-new - jar - spring-cloud-function-deployer-new - Spring Cloud Function Web Support - - - org.springframework.cloud - spring-cloud-function-parent - 3.0.0.BUILD-SNAPSHOT - - - - 1.8 - - - - - org.springframework.boot - spring-boot-loader - - - org.springframework.boot - spring-boot-starter - - - org.springframework.cloud - spring-cloud-function-context - - - org.springframework.boot - spring-boot-starter-test - test - - - org.springframework.boot - spring-boot-configuration-processor - true - - - - - - - - - - - - - - - - - - org.apache.maven.plugins - maven-invoker-plugin - 3.0.1 - - ${project.build.directory}/local-repo - - - - - prepare-test - test-compile - - run - - - ${project.build.directory}/it - - src/it/settings.xml - true - true - - - - - - - - - - spring-milestones - Spring Milestones - https://repo.spring.io/milestone - - - spring-snapshots - Spring Snapshots - https://repo.spring.io/snapshot - - true - - - - - - spring-milestones - Spring Milestones - https://repo.spring.io/milestone - - - spring-snapshots - Spring Snapshots - https://repo.spring.io/snapshot - - true - - - - - diff --git a/spring-cloud-function-deployer-new/src/main/java/org/springframework/cloud/function/deployer/FunctionDeployerConfiguration.java b/spring-cloud-function-deployer-new/src/main/java/org/springframework/cloud/function/deployer/FunctionDeployerConfiguration.java deleted file mode 100644 index 0741a5358..000000000 --- a/spring-cloud-function-deployer-new/src/main/java/org/springframework/cloud/function/deployer/FunctionDeployerConfiguration.java +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Copyright 2017-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. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.cloud.function.deployer; - -import java.io.File; -import java.io.IOException; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import org.springframework.boot.ApplicationArguments; -import org.springframework.boot.context.properties.EnableConfigurationProperties; -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; - -/** - * - * @author Oleg Zhurakousky - * - * @since 3.0 - * - */ -@Configuration(proxyBeanMethods = false) -@EnableConfigurationProperties(FunctionProperties.class) -public class FunctionDeployerConfiguration { - - private static Log logger = LogFactory.getLog(FunctionDeployerConfiguration.class); - - @Bean - SmartLifecycle functionArchiveDeployer(FunctionProperties functionProperties, - FunctionRegistry functionRegistry, ApplicationArguments arguments) { - - Archive archive = null; - try { - archive = new JarFileArchive(new File(functionProperties.getLocation())); - } - catch (IOException e) { - throw new IllegalStateException("Failed to create archive: " + functionProperties.getLocation(), e); - } - FunctionArchiveDeployer deployer = new FunctionArchiveDeployer(archive); - - return new SmartLifecycle() { - - private boolean running; - - @Override - public void stop() { - if (logger.isInfoEnabled()) { - logger.info("Undeploying archive: " + functionProperties.getLocation()); - } - deployer.undeploy(); - if (logger.isInfoEnabled()) { - logger.info("Successfully undeployed archive: " + functionProperties.getLocation()); - } - this.running = false; - } - - @Override - public void start() { - if (logger.isInfoEnabled()) { - logger.info("Deploying archive: " + functionProperties.getLocation()); - } - deployer.deploy(functionRegistry, functionProperties, arguments.getSourceArgs()); - this.running = true; - if (logger.isInfoEnabled()) { - logger.info("Successfully deployed archive: " + functionProperties.getLocation()); - } - } - - @Override - public boolean isRunning() { - return this.running; - } - }; - } - -} diff --git a/spring-cloud-function-deployer-new/src/main/java/org/springframework/cloud/function/deployer/FunctionProperties.java b/spring-cloud-function-deployer-new/src/main/java/org/springframework/cloud/function/deployer/FunctionProperties.java deleted file mode 100644 index c6c612dba..000000000 --- a/spring-cloud-function-deployer-new/src/main/java/org/springframework/cloud/function/deployer/FunctionProperties.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright 2017-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. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.cloud.function.deployer; - -import javax.annotation.PostConstruct; - -import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.util.Assert; -import org.springframework.util.StringUtils; - -/** - * Configuration properties for deciding how to locate the functional class to execute. - * - * @author Eric Bottard - */ -@ConfigurationProperties("spring.cloud.function") -public class FunctionProperties { - - /** - * Location of jar archive containing the supplier/function/consumer class or bean to run. - */ - private String location; - - /** - * The name of the function to be looked up from the FunctionCatalog (e.g., bean name). - */ - private String functionName; - - /** - * The name of the function class tyo be instantiated and loaded into FunctionCatalog. The name of the - * function will be decapitalized simple name of this class. - */ - private String functionClass; - - public void setFunctionClass(String functionClass) { - this.functionClass = functionClass; - } - - public String getFunctionClass() { - return this.functionClass; - } - - public void setFunctionName(String functionName) { - this.functionName = StringUtils.hasText(functionName) ? functionName : ""; - } - - public String getFunctionName() { - return this.functionName; - } - - public String getLocation() { - return this.location; - } - - public void setLocation(String location) { - this.location = location; - } - - @PostConstruct - public void init() { - Assert.notNull(this.location, "No archive location provided, please configure spring.cloud.function.location as a jar or directory."); - } - -} diff --git a/spring-cloud-function-deployer/.jdk8 b/spring-cloud-function-deployer-old/.jdk8 similarity index 100% rename from spring-cloud-function-deployer/.jdk8 rename to spring-cloud-function-deployer-old/.jdk8 diff --git a/spring-cloud-function-deployer/README.md b/spring-cloud-function-deployer-old/README.md similarity index 100% rename from spring-cloud-function-deployer/README.md rename to spring-cloud-function-deployer-old/README.md diff --git a/spring-cloud-function-deployer-old/pom.xml b/spring-cloud-function-deployer-old/pom.xml new file mode 100644 index 000000000..692c5bb01 --- /dev/null +++ b/spring-cloud-function-deployer-old/pom.xml @@ -0,0 +1,155 @@ + + + 4.0.0 + + spring-cloud-function-deployer-old + jar + spring-cloud-function-deployer + Spring Cloud Function Web Support + + + org.springframework.cloud + spring-cloud-function-parent + 3.0.0.BUILD-SNAPSHOT + + + + 1.0.10.RELEASE + 2.0.2.BUILD-SNAPSHOT + + + + + org.springframework.cloud + spring-cloud-function-context + + + org.springframework.boot + spring-boot-configuration-processor + true + + + org.springframework.boot + spring-boot-loader + + + org.springframework.cloud + spring-cloud-deployer-resource-maven + ${spring.cloud.deployer.version} + + + org.springframework.cloud + spring-cloud-deployer-resource-support + ${spring.cloud.deployer.version} + + + org.springframework.boot + spring-boot-starter-test + test + + + org.springframework.boot + spring-boot-starter-logging + test + + + + javax.annotation + javax.annotation-api + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + org.springframework.boot.experimental + spring-boot-thin-layout + ${wrapper.version} + + + + + org.apache.maven.plugins + maven-invoker-plugin + 3.0.1 + + ${project.build.directory}/local-repo + + + + + prepare-test + test-compile + + run + + + ${project.build.directory}/it + + src/it/settings.xml + true + true + + + + + + + + + + org.eclipse.m2e + lifecycle-mapping + 1.0.0 + + + + + + + org.apache.maven.plugins + + + maven-invoker-plugin + + + [1.10,) + + + run + + + + + + + + + + + + + + + + + invoke + + + target/it/flux/pom.xml + + + + false + + + + + diff --git a/spring-cloud-function-deployer/src/it/flux/pom.xml b/spring-cloud-function-deployer-old/src/it/flux/pom.xml similarity index 100% rename from spring-cloud-function-deployer/src/it/flux/pom.xml rename to spring-cloud-function-deployer-old/src/it/flux/pom.xml diff --git a/spring-cloud-function-deployer/src/it/flux/src/main/java/com/example/functions/FunctionApp.java b/spring-cloud-function-deployer-old/src/it/flux/src/main/java/com/example/functions/FunctionApp.java similarity index 100% rename from spring-cloud-function-deployer/src/it/flux/src/main/java/com/example/functions/FunctionApp.java rename to spring-cloud-function-deployer-old/src/it/flux/src/main/java/com/example/functions/FunctionApp.java diff --git a/spring-cloud-function-deployer-new/src/it/settings.xml b/spring-cloud-function-deployer-old/src/it/settings.xml similarity index 100% rename from spring-cloud-function-deployer-new/src/it/settings.xml rename to spring-cloud-function-deployer-old/src/it/settings.xml diff --git a/spring-cloud-function-deployer/src/it/support/pom.xml b/spring-cloud-function-deployer-old/src/it/support/pom.xml similarity index 100% rename from spring-cloud-function-deployer/src/it/support/pom.xml rename to spring-cloud-function-deployer-old/src/it/support/pom.xml diff --git a/spring-cloud-function-deployer/src/it/support/src/main/java/com/example/functions/DoubleLogger.java b/spring-cloud-function-deployer-old/src/it/support/src/main/java/com/example/functions/DoubleLogger.java similarity index 100% rename from spring-cloud-function-deployer/src/it/support/src/main/java/com/example/functions/DoubleLogger.java rename to spring-cloud-function-deployer-old/src/it/support/src/main/java/com/example/functions/DoubleLogger.java diff --git a/spring-cloud-function-deployer/src/it/support/src/main/java/com/example/functions/Emitter.java b/spring-cloud-function-deployer-old/src/it/support/src/main/java/com/example/functions/Emitter.java similarity index 100% rename from spring-cloud-function-deployer/src/it/support/src/main/java/com/example/functions/Emitter.java rename to spring-cloud-function-deployer-old/src/it/support/src/main/java/com/example/functions/Emitter.java diff --git a/spring-cloud-function-deployer/src/it/support/src/main/java/com/example/functions/FunctionApp.java b/spring-cloud-function-deployer-old/src/it/support/src/main/java/com/example/functions/FunctionApp.java similarity index 100% rename from spring-cloud-function-deployer/src/it/support/src/main/java/com/example/functions/FunctionApp.java rename to spring-cloud-function-deployer-old/src/it/support/src/main/java/com/example/functions/FunctionApp.java diff --git a/spring-cloud-function-deployer/src/it/support/src/main/java/com/example/functions/LengthCounter.java b/spring-cloud-function-deployer-old/src/it/support/src/main/java/com/example/functions/LengthCounter.java similarity index 100% rename from spring-cloud-function-deployer/src/it/support/src/main/java/com/example/functions/LengthCounter.java rename to spring-cloud-function-deployer-old/src/it/support/src/main/java/com/example/functions/LengthCounter.java diff --git a/spring-cloud-function-deployer/src/main/java/org/springframework/cloud/function/deployer/ApplicationBootstrap.java b/spring-cloud-function-deployer-old/src/main/java/org/springframework/cloud/function/deployer/ApplicationBootstrap.java similarity index 100% rename from spring-cloud-function-deployer/src/main/java/org/springframework/cloud/function/deployer/ApplicationBootstrap.java rename to spring-cloud-function-deployer-old/src/main/java/org/springframework/cloud/function/deployer/ApplicationBootstrap.java diff --git a/spring-cloud-function-deployer/src/main/java/org/springframework/cloud/function/deployer/ApplicationRunner.java b/spring-cloud-function-deployer-old/src/main/java/org/springframework/cloud/function/deployer/ApplicationRunner.java similarity index 100% rename from spring-cloud-function-deployer/src/main/java/org/springframework/cloud/function/deployer/ApplicationRunner.java rename to spring-cloud-function-deployer-old/src/main/java/org/springframework/cloud/function/deployer/ApplicationRunner.java diff --git a/spring-cloud-function-deployer/src/main/java/org/springframework/cloud/function/deployer/ContextRunner.java b/spring-cloud-function-deployer-old/src/main/java/org/springframework/cloud/function/deployer/ContextRunner.java similarity index 100% rename from spring-cloud-function-deployer/src/main/java/org/springframework/cloud/function/deployer/ContextRunner.java rename to spring-cloud-function-deployer-old/src/main/java/org/springframework/cloud/function/deployer/ContextRunner.java diff --git a/spring-cloud-function-deployer/src/main/java/org/springframework/cloud/function/deployer/EnableFunctionDeployer.java b/spring-cloud-function-deployer-old/src/main/java/org/springframework/cloud/function/deployer/EnableFunctionDeployer.java similarity index 100% rename from spring-cloud-function-deployer/src/main/java/org/springframework/cloud/function/deployer/EnableFunctionDeployer.java rename to spring-cloud-function-deployer-old/src/main/java/org/springframework/cloud/function/deployer/EnableFunctionDeployer.java diff --git a/spring-cloud-function-deployer/src/main/java/org/springframework/cloud/function/deployer/FunctionApplication.java b/spring-cloud-function-deployer-old/src/main/java/org/springframework/cloud/function/deployer/FunctionApplication.java similarity index 100% rename from spring-cloud-function-deployer/src/main/java/org/springframework/cloud/function/deployer/FunctionApplication.java rename to spring-cloud-function-deployer-old/src/main/java/org/springframework/cloud/function/deployer/FunctionApplication.java diff --git a/spring-cloud-function-deployer/src/main/java/org/springframework/cloud/function/deployer/FunctionCreatorConfiguration.java b/spring-cloud-function-deployer-old/src/main/java/org/springframework/cloud/function/deployer/FunctionCreatorConfiguration.java similarity index 100% rename from spring-cloud-function-deployer/src/main/java/org/springframework/cloud/function/deployer/FunctionCreatorConfiguration.java rename to spring-cloud-function-deployer-old/src/main/java/org/springframework/cloud/function/deployer/FunctionCreatorConfiguration.java diff --git a/spring-cloud-function-deployer-old/src/main/java/org/springframework/cloud/function/deployer/FunctionDeployerConfiguration.java b/spring-cloud-function-deployer-old/src/main/java/org/springframework/cloud/function/deployer/FunctionDeployerConfiguration.java new file mode 100644 index 000000000..e2712809b --- /dev/null +++ b/spring-cloud-function-deployer-old/src/main/java/org/springframework/cloud/function/deployer/FunctionDeployerConfiguration.java @@ -0,0 +1,66 @@ +/* + * Copyright 2012-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. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.function.deployer; + +import java.util.HashMap; +import java.util.Map; + +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.cloud.deployer.resource.maven.MavenProperties; +import org.springframework.cloud.deployer.resource.maven.MavenResource; +import org.springframework.cloud.deployer.resource.maven.MavenResourceLoader; +import org.springframework.cloud.deployer.resource.support.DelegatingResourceLoader; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Import; +import org.springframework.core.io.ResourceLoader; + +/** + * @author Dave Syer + * + */ +@Configuration +@ConditionalOnProperty(prefix = "function.deployer", name = "enabled", matchIfMissing = true) +@EnableConfigurationProperties +@Import(FunctionCreatorConfiguration.class) +public class FunctionDeployerConfiguration { + + @Bean + @ConfigurationProperties("maven") + public MavenProperties mavenProperties() { + return new MavenProperties(); + } + + @Bean + @ConfigurationProperties("function") + public FunctionProperties functionProperties() { + return new FunctionProperties(); + } + + @Bean + @ConditionalOnMissingBean(DelegatingResourceLoader.class) + public DelegatingResourceLoader delegatingResourceLoader( + MavenProperties mavenProperties) { + Map loaders = new HashMap<>(); + loaders.put(MavenResource.URI_SCHEME, new MavenResourceLoader(mavenProperties)); + return new DelegatingResourceLoader(loaders); + } + +} diff --git a/spring-cloud-function-deployer-old/src/main/java/org/springframework/cloud/function/deployer/FunctionProperties.java b/spring-cloud-function-deployer-old/src/main/java/org/springframework/cloud/function/deployer/FunctionProperties.java new file mode 100644 index 000000000..39b4e2fd3 --- /dev/null +++ b/spring-cloud-function-deployer-old/src/main/java/org/springframework/cloud/function/deployer/FunctionProperties.java @@ -0,0 +1,100 @@ +/* + * Copyright 2012-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. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.function.deployer; + +import java.util.ArrayList; +import java.util.List; + +import javax.annotation.PostConstruct; + +import org.springframework.util.StringUtils; + +/** + * Configuration properties for deciding how to locate the functional class to execute. + * + * @author Eric Bottard + */ +public class FunctionProperties { + + /** + * Location(s) of jar archives containing the supplier/function/consumer class to run. + */ + private String[] location = new String[0]; + + /** + * The bean name or fully qualified class name of the supplier/function/consumer to + * run. + */ + private String[] bean = new String[0]; + + /** + * Optional main class from which to build a Spring application context. + */ + private String main; + + public static String functionName(String name) { + if (!name.contains(",")) { + return "function0"; + } + List names = new ArrayList<>(); + for (int i = 0; i <= StringUtils.countOccurrencesOf(name, ","); i++) { + names.add("function" + i); + } + return StringUtils.collectionToDelimitedString(names, "|"); + } + + public static String functionName(int value) { + return "function" + value; + } + + public String getName() { + return functionName(StringUtils.arrayToDelimitedString(this.bean, ",")); + } + + public String[] getBean() { + return this.bean; + } + + public void setBean(String[] bean) { + this.bean = bean; + } + + public String[] getLocation() { + return this.location; + } + + public void setLocation(String[] location) { + this.location = location; + } + + public String getMain() { + return this.main; + } + + public void setMain(String main) { + this.main = main; + } + + @PostConstruct + public void init() { + if (this.location.length == 0) { + throw new IllegalStateException( + "No archive location provided, please configure function.location as a jar or directory."); + } + } + +} diff --git a/spring-cloud-function-deployer/src/main/java/org/springframework/cloud/function/deployer/SingleEntryFunctionRegistry.java b/spring-cloud-function-deployer-old/src/main/java/org/springframework/cloud/function/deployer/SingleEntryFunctionRegistry.java similarity index 100% rename from spring-cloud-function-deployer/src/main/java/org/springframework/cloud/function/deployer/SingleEntryFunctionRegistry.java rename to spring-cloud-function-deployer-old/src/main/java/org/springframework/cloud/function/deployer/SingleEntryFunctionRegistry.java diff --git a/spring-cloud-function-deployer/src/test/java/org/springframework/cloud/function/deployer/AdhocTestSuite.java b/spring-cloud-function-deployer-old/src/test/java/org/springframework/cloud/function/deployer/AdhocTestSuite.java similarity index 100% rename from spring-cloud-function-deployer/src/test/java/org/springframework/cloud/function/deployer/AdhocTestSuite.java rename to spring-cloud-function-deployer-old/src/test/java/org/springframework/cloud/function/deployer/AdhocTestSuite.java diff --git a/spring-cloud-function-deployer/src/test/java/org/springframework/cloud/function/deployer/ApplicationRunnerTests.java b/spring-cloud-function-deployer-old/src/test/java/org/springframework/cloud/function/deployer/ApplicationRunnerTests.java similarity index 100% rename from spring-cloud-function-deployer/src/test/java/org/springframework/cloud/function/deployer/ApplicationRunnerTests.java rename to spring-cloud-function-deployer-old/src/test/java/org/springframework/cloud/function/deployer/ApplicationRunnerTests.java diff --git a/spring-cloud-function-deployer/src/test/java/org/springframework/cloud/function/deployer/ContextRunnerTests.java b/spring-cloud-function-deployer-old/src/test/java/org/springframework/cloud/function/deployer/ContextRunnerTests.java similarity index 100% rename from spring-cloud-function-deployer/src/test/java/org/springframework/cloud/function/deployer/ContextRunnerTests.java rename to spring-cloud-function-deployer-old/src/test/java/org/springframework/cloud/function/deployer/ContextRunnerTests.java diff --git a/spring-cloud-function-deployer/src/test/java/org/springframework/cloud/function/deployer/FunctionCreatorConfigurationTests.java b/spring-cloud-function-deployer-old/src/test/java/org/springframework/cloud/function/deployer/FunctionCreatorConfigurationTests.java similarity index 100% rename from spring-cloud-function-deployer/src/test/java/org/springframework/cloud/function/deployer/FunctionCreatorConfigurationTests.java rename to spring-cloud-function-deployer-old/src/test/java/org/springframework/cloud/function/deployer/FunctionCreatorConfigurationTests.java diff --git a/spring-cloud-function-deployer/src/test/java/org/springframework/cloud/function/deployer/SingleEntryFunctionRegistryTests.java b/spring-cloud-function-deployer-old/src/test/java/org/springframework/cloud/function/deployer/SingleEntryFunctionRegistryTests.java similarity index 100% rename from spring-cloud-function-deployer/src/test/java/org/springframework/cloud/function/deployer/SingleEntryFunctionRegistryTests.java rename to spring-cloud-function-deployer-old/src/test/java/org/springframework/cloud/function/deployer/SingleEntryFunctionRegistryTests.java diff --git a/spring-cloud-function-deployer/src/test/java/org/springframework/cloud/function/deployer/SpringFunctionAppConfigurationTests.java b/spring-cloud-function-deployer-old/src/test/java/org/springframework/cloud/function/deployer/SpringFunctionAppConfigurationTests.java similarity index 100% rename from spring-cloud-function-deployer/src/test/java/org/springframework/cloud/function/deployer/SpringFunctionAppConfigurationTests.java rename to spring-cloud-function-deployer-old/src/test/java/org/springframework/cloud/function/deployer/SpringFunctionAppConfigurationTests.java diff --git a/spring-cloud-function-deployer/src/test/java/org/springframework/cloud/function/deployer/SpringFunctionAppExplodedConfigurationTests.java b/spring-cloud-function-deployer-old/src/test/java/org/springframework/cloud/function/deployer/SpringFunctionAppExplodedConfigurationTests.java similarity index 100% rename from spring-cloud-function-deployer/src/test/java/org/springframework/cloud/function/deployer/SpringFunctionAppExplodedConfigurationTests.java rename to spring-cloud-function-deployer-old/src/test/java/org/springframework/cloud/function/deployer/SpringFunctionAppExplodedConfigurationTests.java diff --git a/spring-cloud-function-deployer/src/test/java/org/springframework/cloud/function/deployer/SpringFunctionFluxConfigurationTests.java b/spring-cloud-function-deployer-old/src/test/java/org/springframework/cloud/function/deployer/SpringFunctionFluxConfigurationTests.java similarity index 100% rename from spring-cloud-function-deployer/src/test/java/org/springframework/cloud/function/deployer/SpringFunctionFluxConfigurationTests.java rename to spring-cloud-function-deployer-old/src/test/java/org/springframework/cloud/function/deployer/SpringFunctionFluxConfigurationTests.java diff --git a/spring-cloud-function-deployer/src/test/java/org/springframework/cloud/function/test/Doubler.java b/spring-cloud-function-deployer-old/src/test/java/org/springframework/cloud/function/test/Doubler.java similarity index 100% rename from spring-cloud-function-deployer/src/test/java/org/springframework/cloud/function/test/Doubler.java rename to spring-cloud-function-deployer-old/src/test/java/org/springframework/cloud/function/test/Doubler.java diff --git a/spring-cloud-function-deployer/src/test/java/org/springframework/cloud/function/test/Frenchizer.java b/spring-cloud-function-deployer-old/src/test/java/org/springframework/cloud/function/test/Frenchizer.java similarity index 100% rename from spring-cloud-function-deployer/src/test/java/org/springframework/cloud/function/test/Frenchizer.java rename to spring-cloud-function-deployer-old/src/test/java/org/springframework/cloud/function/test/Frenchizer.java diff --git a/spring-cloud-function-deployer/src/test/java/org/springframework/cloud/function/test/FunctionApp.java b/spring-cloud-function-deployer-old/src/test/java/org/springframework/cloud/function/test/FunctionApp.java similarity index 100% rename from spring-cloud-function-deployer/src/test/java/org/springframework/cloud/function/test/FunctionApp.java rename to spring-cloud-function-deployer-old/src/test/java/org/springframework/cloud/function/test/FunctionApp.java diff --git a/spring-cloud-function-deployer/src/test/java/org/springframework/cloud/function/test/FunctionInitializer.java b/spring-cloud-function-deployer-old/src/test/java/org/springframework/cloud/function/test/FunctionInitializer.java similarity index 100% rename from spring-cloud-function-deployer/src/test/java/org/springframework/cloud/function/test/FunctionInitializer.java rename to spring-cloud-function-deployer-old/src/test/java/org/springframework/cloud/function/test/FunctionInitializer.java diff --git a/spring-cloud-function-deployer/src/test/java/org/springframework/cloud/function/test/FunctionRegistrar.java b/spring-cloud-function-deployer-old/src/test/java/org/springframework/cloud/function/test/FunctionRegistrar.java similarity index 100% rename from spring-cloud-function-deployer/src/test/java/org/springframework/cloud/function/test/FunctionRegistrar.java rename to spring-cloud-function-deployer-old/src/test/java/org/springframework/cloud/function/test/FunctionRegistrar.java diff --git a/spring-cloud-function-deployer/src/test/java/org/springframework/cloud/function/test/NumberEmitter.java b/spring-cloud-function-deployer-old/src/test/java/org/springframework/cloud/function/test/NumberEmitter.java similarity index 100% rename from spring-cloud-function-deployer/src/test/java/org/springframework/cloud/function/test/NumberEmitter.java rename to spring-cloud-function-deployer-old/src/test/java/org/springframework/cloud/function/test/NumberEmitter.java diff --git a/spring-cloud-function-deployer/src/test/java/org/springframework/cloud/function/test/Printer.java b/spring-cloud-function-deployer-old/src/test/java/org/springframework/cloud/function/test/Printer.java similarity index 100% rename from spring-cloud-function-deployer/src/test/java/org/springframework/cloud/function/test/Printer.java rename to spring-cloud-function-deployer-old/src/test/java/org/springframework/cloud/function/test/Printer.java diff --git a/spring-cloud-function-deployer/src/test/java/org/springframework/cloud/function/test/SpringDoubler.java b/spring-cloud-function-deployer-old/src/test/java/org/springframework/cloud/function/test/SpringDoubler.java similarity index 100% rename from spring-cloud-function-deployer/src/test/java/org/springframework/cloud/function/test/SpringDoubler.java rename to spring-cloud-function-deployer-old/src/test/java/org/springframework/cloud/function/test/SpringDoubler.java diff --git a/spring-cloud-function-deployer/src/test/resources/app/META-INF/MANIFEST.MF b/spring-cloud-function-deployer-old/src/test/resources/app/META-INF/MANIFEST.MF similarity index 100% rename from spring-cloud-function-deployer/src/test/resources/app/META-INF/MANIFEST.MF rename to spring-cloud-function-deployer-old/src/test/resources/app/META-INF/MANIFEST.MF diff --git a/spring-cloud-function-deployer-new/.gitignore b/spring-cloud-function-deployer/.gitignore similarity index 100% rename from spring-cloud-function-deployer-new/.gitignore rename to spring-cloud-function-deployer/.gitignore diff --git a/spring-cloud-function-deployer-new/.mvn/wrapper/MavenWrapperDownloader.java b/spring-cloud-function-deployer/.mvn/wrapper/MavenWrapperDownloader.java similarity index 100% rename from spring-cloud-function-deployer-new/.mvn/wrapper/MavenWrapperDownloader.java rename to spring-cloud-function-deployer/.mvn/wrapper/MavenWrapperDownloader.java diff --git a/spring-cloud-function-deployer-new/.mvn/wrapper/maven-wrapper.jar b/spring-cloud-function-deployer/.mvn/wrapper/maven-wrapper.jar similarity index 100% rename from spring-cloud-function-deployer-new/.mvn/wrapper/maven-wrapper.jar rename to spring-cloud-function-deployer/.mvn/wrapper/maven-wrapper.jar diff --git a/spring-cloud-function-deployer-new/.mvn/wrapper/maven-wrapper.properties b/spring-cloud-function-deployer/.mvn/wrapper/maven-wrapper.properties similarity index 100% rename from spring-cloud-function-deployer-new/.mvn/wrapper/maven-wrapper.properties rename to spring-cloud-function-deployer/.mvn/wrapper/maven-wrapper.properties diff --git a/spring-cloud-function-deployer-new/mvnw b/spring-cloud-function-deployer/mvnw similarity index 100% rename from spring-cloud-function-deployer-new/mvnw rename to spring-cloud-function-deployer/mvnw diff --git a/spring-cloud-function-deployer-new/mvnw.cmd b/spring-cloud-function-deployer/mvnw.cmd similarity index 100% rename from spring-cloud-function-deployer-new/mvnw.cmd rename to spring-cloud-function-deployer/mvnw.cmd diff --git a/spring-cloud-function-deployer/pom.xml b/spring-cloud-function-deployer/pom.xml index 4b198a081..01d4cc7a6 100644 --- a/spring-cloud-function-deployer/pom.xml +++ b/spring-cloud-function-deployer/pom.xml @@ -1,48 +1,34 @@ - + 4.0.0 - spring-cloud-function-deployer - jar - spring-cloud-function-deployer - Spring Cloud Function Web Support + jar + spring-cloud-function-deployer-new + Spring Cloud Function Web Support - - org.springframework.cloud - spring-cloud-function-parent - 3.0.0.BUILD-SNAPSHOT - + + org.springframework.cloud + spring-cloud-function-parent + 3.0.0.BUILD-SNAPSHOT + - 1.0.10.RELEASE - 2.0.2.BUILD-SNAPSHOT + 1.8 - - org.springframework.cloud - spring-cloud-function-context - - - org.springframework.boot - spring-boot-configuration-processor - true - org.springframework.boot spring-boot-loader - org.springframework.cloud - spring-cloud-deployer-resource-maven - ${spring.cloud.deployer.version} + org.springframework.boot + spring-boot-starter org.springframework.cloud - spring-cloud-deployer-resource-support - ${spring.cloud.deployer.version} + spring-cloud-function-context org.springframework.boot @@ -51,29 +37,24 @@ org.springframework.boot - spring-boot-starter-logging - test - - - - javax.annotation - javax.annotation-api + spring-boot-configuration-processor + true - - org.springframework.boot - spring-boot-maven-plugin - - - org.springframework.boot.experimental - spring-boot-thin-layout - ${wrapper.version} - - - + + + + + + + + + + + org.apache.maven.plugins maven-invoker-plugin @@ -100,56 +81,37 @@ - - - - - org.eclipse.m2e - lifecycle-mapping - 1.0.0 - - - - - - - org.apache.maven.plugins - - - maven-invoker-plugin - - - [1.10,) - - - run - - - - - - - - - - - - - - - invoke - - - target/it/flux/pom.xml - - - - false - - - + + + spring-milestones + Spring Milestones + https://repo.spring.io/milestone + + + spring-snapshots + Spring Snapshots + https://repo.spring.io/snapshot + + true + + + + + + spring-milestones + Spring Milestones + https://repo.spring.io/milestone + + + spring-snapshots + Spring Snapshots + https://repo.spring.io/snapshot + + true + + + diff --git a/spring-cloud-function-deployer-new/src/it/bootapp-multi/pom.xml b/spring-cloud-function-deployer/src/it/bootapp-multi/pom.xml similarity index 100% rename from spring-cloud-function-deployer-new/src/it/bootapp-multi/pom.xml rename to spring-cloud-function-deployer/src/it/bootapp-multi/pom.xml diff --git a/spring-cloud-function-deployer-new/src/it/bootapp-multi/src/main/java/function/example/MyFn.java b/spring-cloud-function-deployer/src/it/bootapp-multi/src/main/java/function/example/MyFn.java similarity index 100% rename from spring-cloud-function-deployer-new/src/it/bootapp-multi/src/main/java/function/example/MyFn.java rename to spring-cloud-function-deployer/src/it/bootapp-multi/src/main/java/function/example/MyFn.java diff --git a/spring-cloud-function-deployer-new/src/it/bootapp-multi/src/main/java/function/example/RepeaterApplication.java b/spring-cloud-function-deployer/src/it/bootapp-multi/src/main/java/function/example/RepeaterApplication.java similarity index 100% rename from spring-cloud-function-deployer-new/src/it/bootapp-multi/src/main/java/function/example/RepeaterApplication.java rename to spring-cloud-function-deployer/src/it/bootapp-multi/src/main/java/function/example/RepeaterApplication.java diff --git a/spring-cloud-function-deployer-new/src/it/bootapp-with-javax/pom.xml b/spring-cloud-function-deployer/src/it/bootapp-with-javax/pom.xml similarity index 100% rename from spring-cloud-function-deployer-new/src/it/bootapp-with-javax/pom.xml rename to spring-cloud-function-deployer/src/it/bootapp-with-javax/pom.xml diff --git a/spring-cloud-function-deployer-new/src/it/bootapp-with-javax/src/main/java/function/example/SimpleFunctionAppApplication.java b/spring-cloud-function-deployer/src/it/bootapp-with-javax/src/main/java/function/example/SimpleFunctionAppApplication.java similarity index 100% rename from spring-cloud-function-deployer-new/src/it/bootapp-with-javax/src/main/java/function/example/SimpleFunctionAppApplication.java rename to spring-cloud-function-deployer/src/it/bootapp-with-javax/src/main/java/function/example/SimpleFunctionAppApplication.java diff --git a/spring-cloud-function-deployer-new/src/it/bootapp-with-javax/src/main/java/function/example/UpperCaseFunction.java b/spring-cloud-function-deployer/src/it/bootapp-with-javax/src/main/java/function/example/UpperCaseFunction.java similarity index 100% rename from spring-cloud-function-deployer-new/src/it/bootapp-with-javax/src/main/java/function/example/UpperCaseFunction.java rename to spring-cloud-function-deployer/src/it/bootapp-with-javax/src/main/java/function/example/UpperCaseFunction.java diff --git a/spring-cloud-function-deployer-new/src/it/bootapp-with-scf/pom.xml b/spring-cloud-function-deployer/src/it/bootapp-with-scf/pom.xml similarity index 100% rename from spring-cloud-function-deployer-new/src/it/bootapp-with-scf/pom.xml rename to spring-cloud-function-deployer/src/it/bootapp-with-scf/pom.xml diff --git a/spring-cloud-function-deployer-new/src/it/bootapp-with-scf/src/main/java/function/example/SimpleFunctionAppApplication.java b/spring-cloud-function-deployer/src/it/bootapp-with-scf/src/main/java/function/example/SimpleFunctionAppApplication.java similarity index 100% rename from spring-cloud-function-deployer-new/src/it/bootapp-with-scf/src/main/java/function/example/SimpleFunctionAppApplication.java rename to spring-cloud-function-deployer/src/it/bootapp-with-scf/src/main/java/function/example/SimpleFunctionAppApplication.java diff --git a/spring-cloud-function-deployer-new/src/it/bootapp-with-scf/src/main/java/function/example/UpperCaseFunction.java b/spring-cloud-function-deployer/src/it/bootapp-with-scf/src/main/java/function/example/UpperCaseFunction.java similarity index 100% rename from spring-cloud-function-deployer-new/src/it/bootapp-with-scf/src/main/java/function/example/UpperCaseFunction.java rename to spring-cloud-function-deployer/src/it/bootapp-with-scf/src/main/java/function/example/UpperCaseFunction.java diff --git a/spring-cloud-function-deployer-new/src/it/bootapp/pom.xml b/spring-cloud-function-deployer/src/it/bootapp/pom.xml similarity index 100% rename from spring-cloud-function-deployer-new/src/it/bootapp/pom.xml rename to spring-cloud-function-deployer/src/it/bootapp/pom.xml diff --git a/spring-cloud-function-deployer-new/src/it/bootapp/src/main/java/function/example/SimpleFunctionAppApplication.java b/spring-cloud-function-deployer/src/it/bootapp/src/main/java/function/example/SimpleFunctionAppApplication.java similarity index 100% rename from spring-cloud-function-deployer-new/src/it/bootapp/src/main/java/function/example/SimpleFunctionAppApplication.java rename to spring-cloud-function-deployer/src/it/bootapp/src/main/java/function/example/SimpleFunctionAppApplication.java diff --git a/spring-cloud-function-deployer-new/src/it/bootapp/src/main/java/function/example/UpperCaseFunction.java b/spring-cloud-function-deployer/src/it/bootapp/src/main/java/function/example/UpperCaseFunction.java similarity index 100% rename from spring-cloud-function-deployer-new/src/it/bootapp/src/main/java/function/example/UpperCaseFunction.java rename to spring-cloud-function-deployer/src/it/bootapp/src/main/java/function/example/UpperCaseFunction.java diff --git a/spring-cloud-function-deployer-new/src/it/bootjar-multi/pom.xml b/spring-cloud-function-deployer/src/it/bootjar-multi/pom.xml similarity index 100% rename from spring-cloud-function-deployer-new/src/it/bootjar-multi/pom.xml rename to spring-cloud-function-deployer/src/it/bootjar-multi/pom.xml diff --git a/spring-cloud-function-deployer-new/src/it/bootjar-multi/src/main/java/function/example/Repeater.java b/spring-cloud-function-deployer/src/it/bootjar-multi/src/main/java/function/example/Repeater.java similarity index 100% rename from spring-cloud-function-deployer-new/src/it/bootjar-multi/src/main/java/function/example/Repeater.java rename to spring-cloud-function-deployer/src/it/bootjar-multi/src/main/java/function/example/Repeater.java diff --git a/spring-cloud-function-deployer-new/src/it/bootjar/pom.xml b/spring-cloud-function-deployer/src/it/bootjar/pom.xml similarity index 100% rename from spring-cloud-function-deployer-new/src/it/bootjar/pom.xml rename to spring-cloud-function-deployer/src/it/bootjar/pom.xml diff --git a/spring-cloud-function-deployer-new/src/it/bootjar/src/main/java/function/example/SimpleFunctionAppApplication.java b/spring-cloud-function-deployer/src/it/bootjar/src/main/java/function/example/SimpleFunctionAppApplication.java similarity index 100% rename from spring-cloud-function-deployer-new/src/it/bootjar/src/main/java/function/example/SimpleFunctionAppApplication.java rename to spring-cloud-function-deployer/src/it/bootjar/src/main/java/function/example/SimpleFunctionAppApplication.java diff --git a/spring-cloud-function-deployer-new/src/it/bootjar/src/main/java/function/example/UpperCaseFunction.java b/spring-cloud-function-deployer/src/it/bootjar/src/main/java/function/example/UpperCaseFunction.java similarity index 100% rename from spring-cloud-function-deployer-new/src/it/bootjar/src/main/java/function/example/UpperCaseFunction.java rename to spring-cloud-function-deployer/src/it/bootjar/src/main/java/function/example/UpperCaseFunction.java diff --git a/spring-cloud-function-deployer-new/src/it/bootjarnostart/pom.xml b/spring-cloud-function-deployer/src/it/bootjarnostart/pom.xml similarity index 100% rename from spring-cloud-function-deployer-new/src/it/bootjarnostart/pom.xml rename to spring-cloud-function-deployer/src/it/bootjarnostart/pom.xml diff --git a/spring-cloud-function-deployer-new/src/it/bootjarnostart/src/main/java/function/example/UpperCaseFunction.java b/spring-cloud-function-deployer/src/it/bootjarnostart/src/main/java/function/example/UpperCaseFunction.java similarity index 100% rename from spring-cloud-function-deployer-new/src/it/bootjarnostart/src/main/java/function/example/UpperCaseFunction.java rename to spring-cloud-function-deployer/src/it/bootjarnostart/src/main/java/function/example/UpperCaseFunction.java diff --git a/spring-cloud-function-deployer-new/src/it/simplestjar/pom.xml b/spring-cloud-function-deployer/src/it/simplestjar/pom.xml similarity index 100% rename from spring-cloud-function-deployer-new/src/it/simplestjar/pom.xml rename to spring-cloud-function-deployer/src/it/simplestjar/pom.xml diff --git a/spring-cloud-function-deployer-new/src/it/simplestjar/src/main/java/function/example/UpperCaseFunction.java b/spring-cloud-function-deployer/src/it/simplestjar/src/main/java/function/example/UpperCaseFunction.java similarity index 100% rename from spring-cloud-function-deployer-new/src/it/simplestjar/src/main/java/function/example/UpperCaseFunction.java rename to spring-cloud-function-deployer/src/it/simplestjar/src/main/java/function/example/UpperCaseFunction.java diff --git a/spring-cloud-function-deployer-new/src/main/java/org/springframework/cloud/function/deployer/DeployerContextUtils.java b/spring-cloud-function-deployer/src/main/java/org/springframework/cloud/function/deployer/DeployerContextUtils.java similarity index 100% rename from spring-cloud-function-deployer-new/src/main/java/org/springframework/cloud/function/deployer/DeployerContextUtils.java rename to spring-cloud-function-deployer/src/main/java/org/springframework/cloud/function/deployer/DeployerContextUtils.java diff --git a/spring-cloud-function-deployer-new/src/main/java/org/springframework/cloud/function/deployer/FunctionArchiveDeployer.java b/spring-cloud-function-deployer/src/main/java/org/springframework/cloud/function/deployer/FunctionArchiveDeployer.java similarity index 100% rename from spring-cloud-function-deployer-new/src/main/java/org/springframework/cloud/function/deployer/FunctionArchiveDeployer.java rename to spring-cloud-function-deployer/src/main/java/org/springframework/cloud/function/deployer/FunctionArchiveDeployer.java diff --git a/spring-cloud-function-deployer/src/main/java/org/springframework/cloud/function/deployer/FunctionDeployerConfiguration.java b/spring-cloud-function-deployer/src/main/java/org/springframework/cloud/function/deployer/FunctionDeployerConfiguration.java index e2712809b..0741a5358 100644 --- a/spring-cloud-function-deployer/src/main/java/org/springframework/cloud/function/deployer/FunctionDeployerConfiguration.java +++ b/spring-cloud-function-deployer/src/main/java/org/springframework/cloud/function/deployer/FunctionDeployerConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2017-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. @@ -16,51 +16,80 @@ package org.springframework.cloud.function.deployer; -import java.util.HashMap; -import java.util.Map; +import java.io.File; +import java.io.IOException; -import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; -import org.springframework.boot.context.properties.ConfigurationProperties; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import org.springframework.boot.ApplicationArguments; import org.springframework.boot.context.properties.EnableConfigurationProperties; -import org.springframework.cloud.deployer.resource.maven.MavenProperties; -import org.springframework.cloud.deployer.resource.maven.MavenResource; -import org.springframework.cloud.deployer.resource.maven.MavenResourceLoader; -import org.springframework.cloud.deployer.resource.support.DelegatingResourceLoader; +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.context.annotation.Import; -import org.springframework.core.io.ResourceLoader; /** - * @author Dave Syer + * + * @author Oleg Zhurakousky + * + * @since 3.0 * */ -@Configuration -@ConditionalOnProperty(prefix = "function.deployer", name = "enabled", matchIfMissing = true) -@EnableConfigurationProperties -@Import(FunctionCreatorConfiguration.class) +@Configuration(proxyBeanMethods = false) +@EnableConfigurationProperties(FunctionProperties.class) public class FunctionDeployerConfiguration { - @Bean - @ConfigurationProperties("maven") - public MavenProperties mavenProperties() { - return new MavenProperties(); - } + private static Log logger = LogFactory.getLog(FunctionDeployerConfiguration.class); @Bean - @ConfigurationProperties("function") - public FunctionProperties functionProperties() { - return new FunctionProperties(); - } + SmartLifecycle functionArchiveDeployer(FunctionProperties functionProperties, + FunctionRegistry functionRegistry, ApplicationArguments arguments) { - @Bean - @ConditionalOnMissingBean(DelegatingResourceLoader.class) - public DelegatingResourceLoader delegatingResourceLoader( - MavenProperties mavenProperties) { - Map loaders = new HashMap<>(); - loaders.put(MavenResource.URI_SCHEME, new MavenResourceLoader(mavenProperties)); - return new DelegatingResourceLoader(loaders); + Archive archive = null; + try { + archive = new JarFileArchive(new File(functionProperties.getLocation())); + } + catch (IOException e) { + throw new IllegalStateException("Failed to create archive: " + functionProperties.getLocation(), e); + } + FunctionArchiveDeployer deployer = new FunctionArchiveDeployer(archive); + + return new SmartLifecycle() { + + private boolean running; + + @Override + public void stop() { + if (logger.isInfoEnabled()) { + logger.info("Undeploying archive: " + functionProperties.getLocation()); + } + deployer.undeploy(); + if (logger.isInfoEnabled()) { + logger.info("Successfully undeployed archive: " + functionProperties.getLocation()); + } + this.running = false; + } + + @Override + public void start() { + if (logger.isInfoEnabled()) { + logger.info("Deploying archive: " + functionProperties.getLocation()); + } + deployer.deploy(functionRegistry, functionProperties, arguments.getSourceArgs()); + this.running = true; + if (logger.isInfoEnabled()) { + logger.info("Successfully deployed archive: " + functionProperties.getLocation()); + } + } + + @Override + public boolean isRunning() { + return this.running; + } + }; } } diff --git a/spring-cloud-function-deployer/src/main/java/org/springframework/cloud/function/deployer/FunctionProperties.java b/spring-cloud-function-deployer/src/main/java/org/springframework/cloud/function/deployer/FunctionProperties.java index 39b4e2fd3..c6c612dba 100644 --- a/spring-cloud-function-deployer/src/main/java/org/springframework/cloud/function/deployer/FunctionProperties.java +++ b/spring-cloud-function-deployer/src/main/java/org/springframework/cloud/function/deployer/FunctionProperties.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2017-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. @@ -16,11 +16,10 @@ package org.springframework.cloud.function.deployer; -import java.util.ArrayList; -import java.util.List; - import javax.annotation.PostConstruct; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.util.Assert; import org.springframework.util.StringUtils; /** @@ -28,73 +27,52 @@ import org.springframework.util.StringUtils; * * @author Eric Bottard */ +@ConfigurationProperties("spring.cloud.function") public class FunctionProperties { /** - * Location(s) of jar archives containing the supplier/function/consumer class to run. + * Location of jar archive containing the supplier/function/consumer class or bean to run. */ - private String[] location = new String[0]; + private String location; /** - * The bean name or fully qualified class name of the supplier/function/consumer to - * run. + * The name of the function to be looked up from the FunctionCatalog (e.g., bean name). */ - private String[] bean = new String[0]; + private String functionName; /** - * Optional main class from which to build a Spring application context. + * The name of the function class tyo be instantiated and loaded into FunctionCatalog. The name of the + * function will be decapitalized simple name of this class. */ - private String main; + private String functionClass; - public static String functionName(String name) { - if (!name.contains(",")) { - return "function0"; - } - List names = new ArrayList<>(); - for (int i = 0; i <= StringUtils.countOccurrencesOf(name, ","); i++) { - names.add("function" + i); - } - return StringUtils.collectionToDelimitedString(names, "|"); + public void setFunctionClass(String functionClass) { + this.functionClass = functionClass; } - public static String functionName(int value) { - return "function" + value; + public String getFunctionClass() { + return this.functionClass; } - public String getName() { - return functionName(StringUtils.arrayToDelimitedString(this.bean, ",")); + public void setFunctionName(String functionName) { + this.functionName = StringUtils.hasText(functionName) ? functionName : ""; } - public String[] getBean() { - return this.bean; + public String getFunctionName() { + return this.functionName; } - public void setBean(String[] bean) { - this.bean = bean; - } - - public String[] getLocation() { + public String getLocation() { return this.location; } - public void setLocation(String[] location) { + public void setLocation(String location) { this.location = location; } - public String getMain() { - return this.main; - } - - public void setMain(String main) { - this.main = main; - } - @PostConstruct public void init() { - if (this.location.length == 0) { - throw new IllegalStateException( - "No archive location provided, please configure function.location as a jar or directory."); - } + Assert.notNull(this.location, "No archive location provided, please configure spring.cloud.function.location as a jar or directory."); } } diff --git a/spring-cloud-function-deployer-new/src/main/resources/META-INF/spring.factories b/spring-cloud-function-deployer/src/main/resources/META-INF/spring.factories similarity index 100% rename from spring-cloud-function-deployer-new/src/main/resources/META-INF/spring.factories rename to spring-cloud-function-deployer/src/main/resources/META-INF/spring.factories diff --git a/spring-cloud-function-deployer-new/src/test/java/org/springframework/cloud/function/deployer/FunctionDeployerTests.java b/spring-cloud-function-deployer/src/test/java/org/springframework/cloud/function/deployer/FunctionDeployerTests.java similarity index 100% rename from spring-cloud-function-deployer-new/src/test/java/org/springframework/cloud/function/deployer/FunctionDeployerTests.java rename to spring-cloud-function-deployer/src/test/java/org/springframework/cloud/function/deployer/FunctionDeployerTests.java