renamed property keys
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
#!/bin/bash
|
||||
|
||||
PREFIX="--spring.cloud.function.proxy"
|
||||
PREFIX="--spring.cloud.function.import"
|
||||
DIR="file:///tmp/function-registry"
|
||||
|
||||
tokenize() {
|
||||
@@ -19,19 +19,19 @@ while getopts ":i:s:f:c:o:p:d:" opt; do
|
||||
s)
|
||||
FUNC=$OPTARG
|
||||
TYPE="$PREFIX.$FUNC.type=supplier"
|
||||
RESOURCE="$PREFIX.$FUNC.bytecode=$DIR/suppliers/$FUNC.fun"
|
||||
RESOURCE="$PREFIX.$FUNC.location=$DIR/suppliers/$FUNC.fun"
|
||||
;;
|
||||
f)
|
||||
FUNC=$OPTARG
|
||||
for i in `tokenize $OPTARG`; do
|
||||
RESOURCE="$RESOURCE $PREFIX.${i}.bytecode=$DIR/functions/${i}.fun"
|
||||
RESOURCE="$RESOURCE $PREFIX.${i}.location=$DIR/functions/${i}.fun"
|
||||
TYPE="$TYPE $PREFIX.${i}.type=function"
|
||||
done
|
||||
;;
|
||||
c)
|
||||
FUNC=$OPTARG
|
||||
TYPE="$PREFIX.$FUNC.type=consumer"
|
||||
RESOURCE="$PREFIX.$FUNC.bytecode=$DIR/consumers/$FUNC.fun"
|
||||
RESOURCE="$PREFIX.$FUNC.location=$DIR/consumers/$FUNC.fun"
|
||||
;;
|
||||
o)
|
||||
OUT=--spring.cloud.stream.bindings.output.destination=$OPTARG
|
||||
|
||||
@@ -21,7 +21,7 @@ while getopts ":s:f:c:p:" opt; do
|
||||
done
|
||||
|
||||
java -jar ../spring-cloud-function-samples/spring-cloud-function-sample-compiler/target/function-sample-compiler-1.0.0.BUILD-SNAPSHOT.jar\
|
||||
--spring.cloud.function.proxy.$FUNC.type=$TYPE\
|
||||
--spring.cloud.function.proxy.$FUNC.bytecode=file:///tmp/function-registry/$TYPE's'/$FUNC.fun\
|
||||
--spring.cloud.function.import.$FUNC.type=$TYPE\
|
||||
--spring.cloud.function.import.$FUNC.location=file:///tmp/function-registry/$TYPE's'/$FUNC.fun\
|
||||
--management.security.enabled=false\
|
||||
--server.port=$PORT
|
||||
|
||||
@@ -37,6 +37,7 @@ import org.springframework.context.ApplicationListener;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.core.io.ByteArrayResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
@@ -54,25 +55,29 @@ public class FunctionProxyApplicationListener implements ApplicationListener<App
|
||||
ConfigurableApplicationContext context = event.getApplicationContext();
|
||||
DefaultListableBeanFactory beanFactory = (DefaultListableBeanFactory) context.getBeanFactory();
|
||||
PropertySourcesBinder binder = new PropertySourcesBinder(context.getEnvironment());
|
||||
Map<String, Object> extracted = binder.extractAll("spring.cloud.function.proxy");
|
||||
for (Map.Entry<String, Object> entry : extracted.entrySet()) {
|
||||
Map<String, Object> toCompile = binder.extractAll("spring.cloud.function.compile");
|
||||
for (Map.Entry<String, Object> entry : toCompile.entrySet()) {
|
||||
String name = entry.getKey();
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, String> properties = (Map<String, String>) entry.getValue();
|
||||
String type = (properties.get("type") != null) ? properties.get("type") : "function";
|
||||
String bytecodeResource = properties.get("bytecode");
|
||||
String lambda = properties.get("lambda");
|
||||
if (!(null == bytecodeResource ^ null == lambda)) {
|
||||
throw new IllegalArgumentException("Exactly one of 'bytecode' or 'lambda' is required for a Function proxy");
|
||||
}
|
||||
if (bytecodeResource != null) {
|
||||
registerByteCodeLoadingProxy(name, type, context.getResource(bytecodeResource), beanFactory);
|
||||
}
|
||||
else {
|
||||
String inputType = properties.get("inputType");
|
||||
String outputType = properties.get("outputType");
|
||||
registerLambdaCompilingProxy(name, type, inputType, outputType, lambda, beanFactory);
|
||||
}
|
||||
Assert.notNull(lambda,
|
||||
String.format("The 'lambda' property is required for compiling Function: %s", name));
|
||||
String inputType = properties.get("inputType");
|
||||
String outputType = properties.get("outputType");
|
||||
registerLambdaCompilingProxy(name, type, inputType, outputType, lambda, beanFactory);
|
||||
}
|
||||
Map<String, Object> toImport = binder.extractAll("spring.cloud.function.import");
|
||||
for (Map.Entry<String, Object> entry : toImport.entrySet()) {
|
||||
String name = entry.getKey();
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, String> properties = (Map<String, String>) entry.getValue();
|
||||
String type = (properties.get("type") != null) ? properties.get("type") : "function";
|
||||
String location = properties.get("location");
|
||||
Assert.notNull(location,
|
||||
String.format("The 'location' property is required for importing Function: %s", name));
|
||||
registerByteCodeLoadingProxy(name, type, context.getResource(location), beanFactory);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT,
|
||||
properties = "spring.cloud.function.proxy.test.lambda=f->f.map(s->s+\"!!!\")")
|
||||
properties = "spring.cloud.function.compile.test.lambda=f->f.map(s->s+\"!!!\")")
|
||||
public class SampleApplicationTests {
|
||||
|
||||
@LocalServerPort
|
||||
|
||||
Reference in New Issue
Block a user