From 6044b053ae1f47896fee8d8df4d380129dd0c999 Mon Sep 17 00:00:00 2001 From: markfisher Date: Fri, 3 Mar 2017 16:35:30 -0500 Subject: [PATCH] renamed property keys --- scripts/stream.sh | 8 ++--- scripts/web.sh | 4 +-- .../FunctionProxyApplicationListener.java | 33 +++++++++++-------- .../com/example/SampleApplicationTests.java | 2 +- 4 files changed, 26 insertions(+), 21 deletions(-) diff --git a/scripts/stream.sh b/scripts/stream.sh index fa4dc2f97..e9bb2c429 100755 --- a/scripts/stream.sh +++ b/scripts/stream.sh @@ -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 diff --git a/scripts/web.sh b/scripts/web.sh index 5b12bebca..b1c72a14c 100755 --- a/scripts/web.sh +++ b/scripts/web.sh @@ -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 diff --git a/spring-cloud-function-compiler/src/main/java/org/springframework/cloud/function/compiler/config/FunctionProxyApplicationListener.java b/spring-cloud-function-compiler/src/main/java/org/springframework/cloud/function/compiler/config/FunctionProxyApplicationListener.java index 0b51f24d8..ee7478d1f 100644 --- a/spring-cloud-function-compiler/src/main/java/org/springframework/cloud/function/compiler/config/FunctionProxyApplicationListener.java +++ b/spring-cloud-function-compiler/src/main/java/org/springframework/cloud/function/compiler/config/FunctionProxyApplicationListener.java @@ -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 extracted = binder.extractAll("spring.cloud.function.proxy"); - for (Map.Entry entry : extracted.entrySet()) { + Map toCompile = binder.extractAll("spring.cloud.function.compile"); + for (Map.Entry entry : toCompile.entrySet()) { String name = entry.getKey(); @SuppressWarnings("unchecked") Map properties = (Map) 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 toImport = binder.extractAll("spring.cloud.function.import"); + for (Map.Entry entry : toImport.entrySet()) { + String name = entry.getKey(); + @SuppressWarnings("unchecked") + Map properties = (Map) 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); } } diff --git a/spring-cloud-function-samples/spring-cloud-function-sample-compiler/src/test/java/com/example/SampleApplicationTests.java b/spring-cloud-function-samples/spring-cloud-function-sample-compiler/src/test/java/com/example/SampleApplicationTests.java index 9466793c2..1bfd3d432 100644 --- a/spring-cloud-function-samples/spring-cloud-function-sample-compiler/src/test/java/com/example/SampleApplicationTests.java +++ b/spring-cloud-function-samples/spring-cloud-function-sample-compiler/src/test/java/com/example/SampleApplicationTests.java @@ -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