diff --git a/platform-services/data-flow-server/docker/Dockerfile b/platform-services/data-flow-server/docker/Dockerfile new file mode 100644 index 0000000..1e89b2c --- /dev/null +++ b/platform-services/data-flow-server/docker/Dockerfile @@ -0,0 +1,5 @@ +FROM anapsix/alpine-java:8 +VOLUME /tmp +ADD data-flow-server-1.0-SNAPSHOT.jar app.jar +RUN bash -c 'touch /app.jar' +ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"] \ No newline at end of file diff --git a/platform-services/data-flow-server/pom.xml b/platform-services/data-flow-server/pom.xml new file mode 100644 index 0000000..2f909dc --- /dev/null +++ b/platform-services/data-flow-server/pom.xml @@ -0,0 +1,83 @@ + + + 4.0.0 + data-flow-server + jar + + + org.kbastani + platform-services + 1.0-SNAPSHOT + ../ + + + + UTF-8 + UTF-8 + 1.8 + + + + + org.springframework.cloud + spring-cloud-starter-dataflow-server-local + + + org.springframework.cloud + spring-cloud-dataflow-rest-client + + + + org.json + json + + + + + + + org.springframework.cloud + spring-cloud-dataflow-dependencies + 1.1.0.RELEASE + pom + import + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + com.spotify + docker-maven-plugin + 0.4.13 + + ${project.artifactId} + ${project.basedir}/docker + + + / + ${project.build.directory} + ${project.build.finalName}.jar + + + + + + build-image + package + + build + + + + + + + + diff --git a/platform-services/data-flow-server/src/main/java/com/example/DataFlowApplication.java b/platform-services/data-flow-server/src/main/java/com/example/DataFlowApplication.java new file mode 100644 index 0000000..8661d16 --- /dev/null +++ b/platform-services/data-flow-server/src/main/java/com/example/DataFlowApplication.java @@ -0,0 +1,14 @@ +package com.example; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.dataflow.server.EnableDataFlowServer; + +@EnableDataFlowServer +@SpringBootApplication +public class DataFlowApplication { + + public static void main(String[] args) { + SpringApplication.run(DataFlowApplication.class, args); + } +} diff --git a/platform-services/data-flow-server/src/main/java/com/example/ImportResources.java b/platform-services/data-flow-server/src/main/java/com/example/ImportResources.java new file mode 100644 index 0000000..691437b --- /dev/null +++ b/platform-services/data-flow-server/src/main/java/com/example/ImportResources.java @@ -0,0 +1,79 @@ +package com.example; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.context.event.ApplicationReadyEvent; +import org.springframework.cloud.dataflow.rest.client.DataFlowTemplate; +import org.springframework.context.ApplicationListener; +import org.springframework.stereotype.Component; + +import java.net.MalformedURLException; +import java.net.URI; +import java.net.URL; +import java.util.Arrays; +import java.util.List; + +@Component +public class ImportResources implements ApplicationListener { + + @Value("${server.port}") + private String port; + + @Override + public void onApplicationEvent(ApplicationReadyEvent event) { + URI baseUri = URI.create("http://localhost:" + port); + DataFlowTemplate dataFlowTemplate = new DataFlowTemplate(baseUri); + try { + // Import event stream apps + dataFlowTemplate.appRegistryOperations() + .importFromResource(new URL(baseUri.toURL(), "app.properties").toString(), false); + + // Import RabbitMQ stream apps + dataFlowTemplate.appRegistryOperations() + .importFromResource("http://bit.ly/stream-applications-rabbit-maven", false); + + // Deploy a set of event stream definitions + List streams = Arrays.asList( + new StreamApp("account-stream", + "account-web: account-web | account-worker: account-worker"), + new StreamApp("order-stream", + "order-web: order-web | order-worker: order-worker"), + new StreamApp("payment-stream", + "payment-web: payment-web | payment-worker: payment-worker"), + new StreamApp("warehouse-stream", + "warehouse-web: warehouse-web | warehouse-worker: warehouse-worker")); + + // Deploy the streams in parallel + streams.parallelStream() + .forEach(stream -> dataFlowTemplate.streamOperations() + .createStream(stream.getName(), stream.getDefinition(), true)); + } catch (MalformedURLException e) { + e.printStackTrace(); + } + } + + static class StreamApp { + private String name; + private String definition; + + public StreamApp(String name, String definition) { + this.name = name; + this.definition = definition; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getDefinition() { + return definition; + } + + public void setDefinition(String definition) { + this.definition = definition; + } + } +} diff --git a/platform-services/data-flow-server/src/main/resources/application.yml b/platform-services/data-flow-server/src/main/resources/application.yml new file mode 100644 index 0000000..c059f22 --- /dev/null +++ b/platform-services/data-flow-server/src/main/resources/application.yml @@ -0,0 +1,5 @@ +server: + port: ${PORT:9393} +spring: + application: + name: data-flow-server \ No newline at end of file diff --git a/platform-services/data-flow-server/src/main/resources/static/app.properties b/platform-services/data-flow-server/src/main/resources/static/app.properties new file mode 100644 index 0000000..12c6a11 --- /dev/null +++ b/platform-services/data-flow-server/src/main/resources/static/app.properties @@ -0,0 +1,8 @@ +source.account-web=maven://org.kbastani:account-web:0.0.1-SNAPSHOT +sink.account-worker=maven://org.kbastani:account-worker:0.0.1-SNAPSHOT +source.order-web=maven://org.kbastani:order-web:0.0.1-SNAPSHOT +sink.order-worker=maven://org.kbastani:order-worker:0.0.1-SNAPSHOT +source.payment-web=maven://org.kbastani:payment-web:0.0.1-SNAPSHOT +sink.payment-worker=maven://org.kbastani:payment-worker:0.0.1-SNAPSHOT +source.warehouse-web=maven://org.kbastani:warehouse-web:0.0.1-SNAPSHOT +sink.warehouse-worker=maven://org.kbastani:warehouse-worker:0.0.1-SNAPSHOT \ No newline at end of file diff --git a/platform-services/pom.xml b/platform-services/pom.xml index 8db4837..8f75f2b 100644 --- a/platform-services/pom.xml +++ b/platform-services/pom.xml @@ -25,5 +25,6 @@ discovery + data-flow-server \ No newline at end of file