removing FileSystemFunctionRegistry
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -42,22 +42,4 @@
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
<configuration>
|
||||
<classifier>registrar</classifier>
|
||||
</configuration>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot.experimental</groupId>
|
||||
<artifactId>spring-boot-thin-launcher</artifactId>
|
||||
<version>${wrapper.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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 <T> Consumer<T> 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 <T, R> Function<T, R> 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 <T> Supplier<T> 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");
|
||||
}
|
||||
}
|
||||
@@ -1,2 +0,0 @@
|
||||
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
|
||||
org.springframework.cloud.function.registry.DefaultFunctionRegistryAutoConfiguration
|
||||
@@ -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();
|
||||
|
||||
|
||||
@@ -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<String>, Flux<String>> function = registry.lookupFunction("uppercase");
|
||||
Flux<String> output = function.apply(Flux.just("foo", "bar"));
|
||||
List<String> results = output.collectList().block();
|
||||
assertEquals("FOO", results.get(0));
|
||||
assertEquals("BAR", results.get(1));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -32,7 +32,6 @@
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-function-context</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
|
||||
Reference in New Issue
Block a user