From cfd416590d721319267b8b262322790464295802 Mon Sep 17 00:00:00 2001 From: markfisher Date: Wed, 11 Jan 2017 20:59:18 -0500 Subject: [PATCH] removing FileSystemFunctionRegistry --- ...ntextFunctionCatalogAutoConfiguration.java | 7 +- spring-cloud-function-core/pom.xml | 18 --- .../cloud/function/FunctionRegistrar.java | 48 ------ ...aultFunctionRegistryAutoConfiguration.java | 33 ----- .../registry/FileSystemFunctionRegistry.java | 139 ------------------ .../main/resources/META-INF/spring.factories | 2 - .../gateway/LocalFunctionGatewayTests.java | 4 +- .../FileSystemFunctionRegistryTests.java | 56 ------- .../FunctionExtractingAutoConfiguration.java | 3 - .../deployer/FunctionAppDeployerTests.java | 10 +- spring-cloud-function-web/pom.xml | 1 - 11 files changed, 9 insertions(+), 312 deletions(-) delete mode 100644 spring-cloud-function-core/src/main/java/org/springframework/cloud/function/FunctionRegistrar.java delete mode 100644 spring-cloud-function-core/src/main/java/org/springframework/cloud/function/registry/DefaultFunctionRegistryAutoConfiguration.java delete mode 100644 spring-cloud-function-core/src/main/java/org/springframework/cloud/function/registry/FileSystemFunctionRegistry.java delete mode 100644 spring-cloud-function-core/src/main/resources/META-INF/spring.factories delete mode 100644 spring-cloud-function-core/src/test/java/org/springframework/cloud/function/registry/FileSystemFunctionRegistryTests.java diff --git a/spring-cloud-function-context/src/main/java/org/springframework/cloud/function/context/ContextFunctionCatalogAutoConfiguration.java b/spring-cloud-function-context/src/main/java/org/springframework/cloud/function/context/ContextFunctionCatalogAutoConfiguration.java index fa0a50cc4..76fa74aa6 100644 --- a/spring-cloud-function-context/src/main/java/org/springframework/cloud/function/context/ContextFunctionCatalogAutoConfiguration.java +++ b/spring-cloud-function-context/src/main/java/org/springframework/cloud/function/context/ContextFunctionCatalogAutoConfiguration.java @@ -26,8 +26,6 @@ import java.util.function.Consumer; import java.util.function.Function; import java.util.function.Supplier; -import com.fasterxml.jackson.databind.ObjectMapper; - import org.springframework.beans.BeansException; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.config.BeanFactoryPostProcessor; @@ -35,10 +33,8 @@ import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; import org.springframework.beans.factory.support.BeanDefinitionRegistry; import org.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor; import org.springframework.beans.factory.support.RootBeanDefinition; -import org.springframework.boot.autoconfigure.AutoConfigureBefore; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; -import org.springframework.cloud.function.registry.DefaultFunctionRegistryAutoConfiguration; import org.springframework.cloud.function.registry.FunctionCatalog; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -47,12 +43,13 @@ import org.springframework.core.type.StandardMethodMetadata; import org.springframework.stereotype.Component; import org.springframework.util.ClassUtils; +import com.fasterxml.jackson.databind.ObjectMapper; + import reactor.core.publisher.Flux; @Configuration @ConditionalOnClass(ApplicationContextFunctionCatalog.class) @ConditionalOnMissingBean(FunctionCatalog.class) -@AutoConfigureBefore(DefaultFunctionRegistryAutoConfiguration.class) public class ContextFunctionCatalogAutoConfiguration { @Autowired(required = false) diff --git a/spring-cloud-function-core/pom.xml b/spring-cloud-function-core/pom.xml index cbf02fd29..dd2917fdc 100644 --- a/spring-cloud-function-core/pom.xml +++ b/spring-cloud-function-core/pom.xml @@ -42,22 +42,4 @@ - - - - org.springframework.boot - spring-boot-maven-plugin - - registrar - - - - org.springframework.boot.experimental - spring-boot-thin-launcher - ${wrapper.version} - - - - - diff --git a/spring-cloud-function-core/src/main/java/org/springframework/cloud/function/FunctionRegistrar.java b/spring-cloud-function-core/src/main/java/org/springframework/cloud/function/FunctionRegistrar.java deleted file mode 100644 index 4a6c29a88..000000000 --- a/spring-cloud-function-core/src/main/java/org/springframework/cloud/function/FunctionRegistrar.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright 2016 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 - * - * http://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; - -import org.springframework.cloud.function.registry.FileSystemFunctionRegistry; - -/** - * @author Mark Fisher - */ -public class FunctionRegistrar { - - public static void main(String[] args) { - String usage = "USAGE: java FunctionRegistrar [supplier|function|consumer] name lambda"; - if (args.length != 3) { - System.err.println(usage); - System.exit(1); - } - FileSystemFunctionRegistry registry = new FileSystemFunctionRegistry(); - String type = args[0]; - if ("supplier".equalsIgnoreCase(type)) { - registry.registerSupplier(args[1], args[2]); - } - else if ("function".equalsIgnoreCase(type)) { - registry.registerFunction(args[1], args[2]); - } - else if ("consumer".equalsIgnoreCase(type)) { - registry.registerConsumer(args[1], args[2]); - } - else { - System.err.println(usage); - System.exit(1); - } - } -} diff --git a/spring-cloud-function-core/src/main/java/org/springframework/cloud/function/registry/DefaultFunctionRegistryAutoConfiguration.java b/spring-cloud-function-core/src/main/java/org/springframework/cloud/function/registry/DefaultFunctionRegistryAutoConfiguration.java deleted file mode 100644 index 2ff70c9d9..000000000 --- a/spring-cloud-function-core/src/main/java/org/springframework/cloud/function/registry/DefaultFunctionRegistryAutoConfiguration.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright 2016 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 - * - * http://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.registry; - -import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; -import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -@Configuration -@ConditionalOnClass(FileSystemFunctionRegistry.class) -@ConditionalOnMissingBean(FunctionCatalog.class) -public class DefaultFunctionRegistryAutoConfiguration { - - @Bean - public FunctionRegistry functionRegistry() { - return new FileSystemFunctionRegistry(); - } - -} diff --git a/spring-cloud-function-core/src/main/java/org/springframework/cloud/function/registry/FileSystemFunctionRegistry.java b/spring-cloud-function-core/src/main/java/org/springframework/cloud/function/registry/FileSystemFunctionRegistry.java deleted file mode 100644 index 370cb1007..000000000 --- a/spring-cloud-function-core/src/main/java/org/springframework/cloud/function/registry/FileSystemFunctionRegistry.java +++ /dev/null @@ -1,139 +0,0 @@ -/* - * Copyright 2016 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 - * - * http://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.registry; - -import java.io.File; -import java.io.IOException; -import java.util.function.Consumer; -import java.util.function.Function; -import java.util.function.Supplier; - -import org.springframework.cloud.function.compiler.CompiledFunctionFactory; -import org.springframework.util.Assert; -import org.springframework.util.FileCopyUtils; - -/** - * @author Mark Fisher - */ -public class FileSystemFunctionRegistry extends AbstractFunctionRegistry { - - private static final String CONSUMER_DIRECTORY = "consumers"; - - private static final String FUNCTION_DIRECTORY = "functions"; - - private static final String SUPPLIER_DIRECTORY = "suppliers"; - - private final File consumerDirectory; - - private final File functionDirectory; - - private final File supplierDirectory; - - public FileSystemFunctionRegistry() { - this(new File("/tmp/function-registry")); - } - - public FileSystemFunctionRegistry(File directory) { - Assert.notNull(directory, "Directory must not be null"); - if (!directory.exists()) { - directory.mkdirs(); - } - else { - Assert.isTrue(directory.isDirectory(), - String.format("%s is not a directory.", directory.getAbsolutePath())); - } - this.consumerDirectory = new File(directory, CONSUMER_DIRECTORY); - this.functionDirectory = new File(directory, FUNCTION_DIRECTORY); - this.supplierDirectory = new File(directory, SUPPLIER_DIRECTORY); - this.consumerDirectory.mkdir(); - this.functionDirectory.mkdir(); - this.supplierDirectory.mkdir(); - } - - @Override - public Consumer doLookupConsumer(String name) { - try { - byte[] bytes = FileCopyUtils.copyToByteArray(new File(this.consumerDirectory, fileName(name))); - return this.deserializeConsumer(name, bytes); - } - catch (IOException e) { - throw new IllegalArgumentException(String.format("failed to lookup Consumer: %s", name), e); - } - } - - @Override - public Function doLookupFunction(String name) { - try { - byte[] bytes = FileCopyUtils.copyToByteArray(new File(this.functionDirectory, fileName(name))); - return this.deserializeFunction(name, bytes); - } - catch (IOException e) { - throw new IllegalArgumentException(String.format("failed to lookup Function: %s", name), e); - } - } - - @Override - public Supplier doLookupSupplier(String name) { - try { - byte[] bytes = FileCopyUtils.copyToByteArray(new File(this.supplierDirectory, fileName(name))); - return this.deserializeSupplier(name, bytes); - } - catch (IOException e) { - throw new IllegalArgumentException(String.format("failed to lookup Supplier: %s", name), e); - } - } - - @Override - public void registerConsumer(String name, String consumer) { - CompiledFunctionFactory factory = this.compileConsumer(name, consumer); - File file = new File(this.consumerDirectory, fileName(name)); - try { - FileCopyUtils.copy(factory.getGeneratedClassBytes(), file); - } - catch (IOException e) { - throw new IllegalArgumentException(String.format("failed to register Consumer: %s", name), e); - } - } - - @Override - public void registerFunction(String name, String function) { - CompiledFunctionFactory factory = this.compileFunction(name, function); - File file = new File(this.functionDirectory, fileName(name)); - try { - FileCopyUtils.copy(factory.getGeneratedClassBytes(), file); - } - catch (IOException e) { - throw new IllegalArgumentException(String.format("failed to register Function: %s", name), e); - } - } - - @Override - public void registerSupplier(String name, String supplier) { - CompiledFunctionFactory factory = this.compileSupplier(name, supplier); - File file = new File(this.supplierDirectory, fileName(name)); - try { - FileCopyUtils.copy(factory.getGeneratedClassBytes(), file); - } - catch (IOException e) { - throw new IllegalArgumentException(String.format("failed to register Supplier: %s", name), e); - } - } - - private static String fileName(String functionName) { - return String.format("%s.%s", functionName, "fun"); - } -} diff --git a/spring-cloud-function-core/src/main/resources/META-INF/spring.factories b/spring-cloud-function-core/src/main/resources/META-INF/spring.factories deleted file mode 100644 index 106bdaa49..000000000 --- a/spring-cloud-function-core/src/main/resources/META-INF/spring.factories +++ /dev/null @@ -1,2 +0,0 @@ -org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ -org.springframework.cloud.function.registry.DefaultFunctionRegistryAutoConfiguration \ No newline at end of file diff --git a/spring-cloud-function-core/src/test/java/org/springframework/cloud/function/gateway/LocalFunctionGatewayTests.java b/spring-cloud-function-core/src/test/java/org/springframework/cloud/function/gateway/LocalFunctionGatewayTests.java index 23a282bf7..63091a99e 100644 --- a/spring-cloud-function-core/src/test/java/org/springframework/cloud/function/gateway/LocalFunctionGatewayTests.java +++ b/spring-cloud-function-core/src/test/java/org/springframework/cloud/function/gateway/LocalFunctionGatewayTests.java @@ -23,8 +23,8 @@ import java.util.List; import org.junit.Before; import org.junit.Test; -import org.springframework.cloud.function.registry.FileSystemFunctionRegistry; import org.springframework.cloud.function.registry.FunctionRegistry; +import org.springframework.cloud.function.registry.InMemoryFunctionRegistry; import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; import reactor.core.publisher.Flux; @@ -34,7 +34,7 @@ import reactor.core.publisher.Flux; */ public class LocalFunctionGatewayTests { - private final FunctionRegistry registry = new FileSystemFunctionRegistry(); + private final FunctionRegistry registry = new InMemoryFunctionRegistry(); private final ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler(); diff --git a/spring-cloud-function-core/src/test/java/org/springframework/cloud/function/registry/FileSystemFunctionRegistryTests.java b/spring-cloud-function-core/src/test/java/org/springframework/cloud/function/registry/FileSystemFunctionRegistryTests.java deleted file mode 100644 index 659c5753a..000000000 --- a/spring-cloud-function-core/src/test/java/org/springframework/cloud/function/registry/FileSystemFunctionRegistryTests.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright 2016 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 - * - * http://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.registry; - -import java.io.File; -import java.io.IOException; -import java.util.List; -import java.util.function.Function; - -import org.junit.Before; -import org.junit.Test; - -import static org.junit.Assert.assertEquals; - -import reactor.core.publisher.Flux; - -/** - * @author Mark Fisher - */ -public class FileSystemFunctionRegistryTests { - - private File directory; - - @Before - public void init() throws IOException { - this.directory = new File("/tmp/file-system-function-registry-tests"); - this.directory.mkdirs(); - this.directory.deleteOnExit(); - } - - @Test - public void registerAndLookupFunction() throws IOException { - FileSystemFunctionRegistry registry = new FileSystemFunctionRegistry(this.directory); - registry.registerFunction("uppercase", "f->f.map(s->s.toString().toUpperCase())"); - Function, Flux> function = registry.lookupFunction("uppercase"); - Flux output = function.apply(Flux.just("foo", "bar")); - List results = output.collectList().block(); - assertEquals("FOO", results.get(0)); - assertEquals("BAR", results.get(1)); - } - -} diff --git a/spring-cloud-function-deployer/src/main/java/org/springframework/cloud/function/deployer/FunctionExtractingAutoConfiguration.java b/spring-cloud-function-deployer/src/main/java/org/springframework/cloud/function/deployer/FunctionExtractingAutoConfiguration.java index a6084daf3..b8efb4a2c 100644 --- a/spring-cloud-function-deployer/src/main/java/org/springframework/cloud/function/deployer/FunctionExtractingAutoConfiguration.java +++ b/spring-cloud-function-deployer/src/main/java/org/springframework/cloud/function/deployer/FunctionExtractingAutoConfiguration.java @@ -15,9 +15,7 @@ */ package org.springframework.cloud.function.deployer; -import org.springframework.boot.autoconfigure.AutoConfigureBefore; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; -import org.springframework.cloud.function.registry.DefaultFunctionRegistryAutoConfiguration; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -27,7 +25,6 @@ import org.springframework.context.annotation.Configuration; */ @Configuration @ConditionalOnClass(FunctionExtractingFunctionCatalog.class) -@AutoConfigureBefore(DefaultFunctionRegistryAutoConfiguration.class) public class FunctionExtractingAutoConfiguration { @Bean diff --git a/spring-cloud-function-deployer/src/test/java/org/springframework/cloud/function/deployer/FunctionAppDeployerTests.java b/spring-cloud-function-deployer/src/test/java/org/springframework/cloud/function/deployer/FunctionAppDeployerTests.java index 943306301..c92360b89 100644 --- a/spring-cloud-function-deployer/src/test/java/org/springframework/cloud/function/deployer/FunctionAppDeployerTests.java +++ b/spring-cloud-function-deployer/src/test/java/org/springframework/cloud/function/deployer/FunctionAppDeployerTests.java @@ -39,7 +39,7 @@ import static org.assertj.core.api.Assertions.assertThat; /** * @author Dave Syer - * + * @author Mark Fisher */ @RunWith(Parameterized.class) public class FunctionAppDeployerTests { @@ -54,7 +54,7 @@ public class FunctionAppDeployerTests { public static void skip() { try { ArchiveUtils.getArchiveRoot(ArchiveUtils.getArchive( - "maven://org.springframework.cloud:spring-cloud-function-web:1.0.0.BUILD-SNAPSHOT")); + "maven://com.example:function-sample:1.0.0.BUILD-SNAPSHOT")); } catch (Exception e) { Assume.assumeNoException( @@ -72,8 +72,8 @@ public class FunctionAppDeployerTests { @Test public void web() throws Exception { String first = deploy( - "maven://org.springframework.cloud:spring-cloud-function-web:1.0.0.BUILD-SNAPSHOT", - "--web.path=/words", "--function.name=uppercase"); + "maven://com.example:function-sample:1.0.0.BUILD-SNAPSHOT", + "--function.name=uppercase"); // Deployment is blocking so it either failed or succeeded. assertThat(deployer.status(first).getState()).isEqualTo(DeploymentState.deployed); deployer.undeploy(first); @@ -82,7 +82,7 @@ public class FunctionAppDeployerTests { @Test public void stream() throws Exception { String first = deploy( - "maven://org.springframework.cloud:spring-cloud-function-stream:1.0.0.BUILD-SNAPSHOT", + "maven://com.example:function-sample:1.0.0.BUILD-SNAPSHOT", "--spring.cloud.stream.bindings.input.destination=words", "--spring.cloud.stream.bindings.output.destination=uppercaseWords", "--function.name=uppercase"); diff --git a/spring-cloud-function-web/pom.xml b/spring-cloud-function-web/pom.xml index c68184059..28c9ec8fd 100644 --- a/spring-cloud-function-web/pom.xml +++ b/spring-cloud-function-web/pom.xml @@ -32,7 +32,6 @@ org.springframework.cloud spring-cloud-function-context ${project.version} - test org.springframework.boot