├── README.md ├── .mvn ├── jvm.config ├── wrapper │ ├── maven-wrapper.jar │ └── maven-wrapper.properties └── maven.config ├── spring-cloud-starter-stream-sink-gpfdist ├── src │ ├── main │ │ ├── resources │ │ │ └── META-INF │ │ │ │ ├── spring.provides │ │ │ │ └── spring-configuration-metadata-whitelist.properties │ │ └── java │ │ │ └── org │ │ │ └── springframework │ │ │ └── cloud │ │ │ └── stream │ │ │ └── app │ │ │ └── gpfdist │ │ │ └── sink │ │ │ ├── support │ │ │ ├── Format.java │ │ │ ├── Mode.java │ │ │ ├── GreenplumLoad.java │ │ │ ├── LoadService.java │ │ │ ├── NetworkUtils.java │ │ │ ├── SegmentRejectType.java │ │ │ ├── DefaultGreenplumLoad.java │ │ │ ├── RuntimeContext.java │ │ │ ├── ReadableTable.java │ │ │ ├── DefaultLoadService.java │ │ │ ├── LoadFactoryBean.java │ │ │ ├── LoadConfiguration.java │ │ │ ├── GreenplumDataSourceFactoryBean.java │ │ │ ├── AbstractExternalTable.java │ │ │ ├── ControlFile.java │ │ │ ├── JdbcCommands.java │ │ │ ├── LoadConfigurationFactoryBean.java │ │ │ ├── ControlFileFactoryBean.java │ │ │ ├── ReadableTableFactoryBean.java │ │ │ └── SqlUtils.java │ │ │ ├── GpfdistSinkApplication.java │ │ │ ├── GpfdistCodec.java │ │ │ ├── HostInfoDiscoveryProperties.java │ │ │ ├── AbstractGpfdistMessageHandler.java │ │ │ ├── GpfdistServer.java │ │ │ ├── GpfdistSinkConfiguration.java │ │ │ ├── GpfdistMessageHandler.java │ │ │ └── GpfdistSinkProperties.java │ └── test │ │ ├── resources │ │ ├── test.yml │ │ └── LoadConfigurationFactoryBeanTests1.xml │ │ └── java │ │ └── org │ │ └── springframework │ │ └── cloud │ │ └── stream │ │ └── app │ │ └── gpfdist │ │ └── sink │ │ ├── support │ │ ├── LoadConfigurationFactoryBeanTests.java │ │ ├── ControlFileTests.java │ │ └── LoadConfigurationIT.java │ │ ├── TestListenAddress.java │ │ ├── AbstractDbTests.java │ │ ├── TestUtils.java │ │ ├── GpfdistSinkPropertiesTests.java │ │ ├── AbstractLoadTests.java │ │ ├── HostInfoDiscoveryPropertiesTests.java │ │ └── LoadIT.java ├── pom.xml └── README.adoc ├── README.adoc ├── .gitignore ├── CODE_OF_CONDUCT.adoc ├── pom.xml ├── mvnw.cmd ├── gpfdist-app-dependencies └── pom.xml ├── mvnw └── LICENSE /README.md: -------------------------------------------------------------------------------- 1 | # gpfdist is no longer actively maintained by VMware, Inc. 2 | 3 | -------------------------------------------------------------------------------- /.mvn/jvm.config: -------------------------------------------------------------------------------- 1 | -Xmx1024m -XX:CICompilerCount=1 -XX:TieredStopAtLevel=1 -Djava.security.egd=file:/dev/./urandom -------------------------------------------------------------------------------- /.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spring-attic/gpfdist/main/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /.mvn/maven.config: -------------------------------------------------------------------------------- 1 | -DaltSnapshotDeploymentRepository=repo.spring.io::default::https://repo.spring.io/libs-snapshot-local -P spring 2 | -------------------------------------------------------------------------------- /spring-cloud-starter-stream-sink-gpfdist/src/main/resources/META-INF/spring.provides: -------------------------------------------------------------------------------- 1 | provides: spring-cloud-starter-stream-sink-gpfdist -------------------------------------------------------------------------------- /.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.3.3/apache-maven-3.3.3-bin.zip -------------------------------------------------------------------------------- /README.adoc: -------------------------------------------------------------------------------- 1 | # Gpfdist Sink 2 | 3 | To learn more about this application and the supported properties, please review the following link. 4 | 5 | include::spring-cloud-starter-stream-sink-gpfdist/README.adoc[] 6 | -------------------------------------------------------------------------------- /spring-cloud-starter-stream-sink-gpfdist/src/main/resources/META-INF/spring-configuration-metadata-whitelist.properties: -------------------------------------------------------------------------------- 1 | configuration-properties.classes=org.springframework.cloud.stream.app.gpfdist.sink.GpfdistSinkProperties, \ 2 | org.springframework.cloud.stream.app.gpfdist.sink.HostInfoDiscoveryProperties 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | apps/ 2 | /application.yml 3 | /application.properties 4 | asciidoctor.css 5 | *~ 6 | .#* 7 | *# 8 | target/ 9 | build/ 10 | bin/ 11 | _site/ 12 | .classpath 13 | .project 14 | .settings 15 | .springBeans 16 | .DS_Store 17 | *.sw* 18 | *.iml 19 | *.ipr 20 | *.iws 21 | .idea/ 22 | .factorypath 23 | spring-xd-samples/*/xd 24 | dump.rdb 25 | coverage-error.log 26 | .apt_generated 27 | aws.credentials.properties 28 | -------------------------------------------------------------------------------- /spring-cloud-starter-stream-sink-gpfdist/src/main/java/org/springframework/cloud/stream/app/gpfdist/sink/support/Format.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.cloud.stream.app.gpfdist.sink.support; 17 | 18 | public enum Format { 19 | 20 | TEXT, CSV 21 | 22 | } 23 | -------------------------------------------------------------------------------- /spring-cloud-starter-stream-sink-gpfdist/src/main/java/org/springframework/cloud/stream/app/gpfdist/sink/support/Mode.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.springframework.cloud.stream.app.gpfdist.sink.support; 18 | 19 | public enum Mode { 20 | 21 | INSERT, UPDATE 22 | 23 | } 24 | -------------------------------------------------------------------------------- /spring-cloud-starter-stream-sink-gpfdist/src/test/resources/test.yml: -------------------------------------------------------------------------------- 1 | VERSION: 1.0.0.1 2 | DATABASE: gpadmin 3 | USER: gpadmin 4 | HOST: mdw.example.org 5 | PORT: 5432 6 | GPLOAD: 7 | INPUT: 8 | - SOURCE: 9 | PORT: 8100 10 | FILE: [ /home/gpadmin/test/data/* ] 11 | - COLUMNS: 12 | - "id": 13 | - "name": 14 | - FORMAT: text 15 | - DELIMITER: ',' 16 | - ENCODING: 'UTF8' 17 | - NULL_AS: '' 18 | - ERROR_LIMIT: 100000 19 | - ERROR_TABLE: test_err 20 | OUTPUT: 21 | - TABLE: test 22 | - MODE: UPDATE 23 | - MATCH_COLUMNS: 24 | - col11 25 | - col12 26 | - UPDATE_COLUMNS: 27 | - col21 28 | - col22 29 | - UPDATE_CONDITION: 'condition' 30 | SQL: 31 | - BEFORE: "select 1 as before" 32 | - BEFORE: "select 2 as before" 33 | - AFTER: "select 1 as after" 34 | - AFTER: "select 2 as after" -------------------------------------------------------------------------------- /spring-cloud-starter-stream-sink-gpfdist/src/main/java/org/springframework/cloud/stream/app/gpfdist/sink/support/GreenplumLoad.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.cloud.stream.app.gpfdist.sink.support; 17 | 18 | public interface GreenplumLoad { 19 | 20 | public void load(); 21 | 22 | public void load(RuntimeContext context); 23 | 24 | } 25 | -------------------------------------------------------------------------------- /spring-cloud-starter-stream-sink-gpfdist/src/test/resources/LoadConfigurationFactoryBeanTests1.xml: -------------------------------------------------------------------------------- 1 | 2 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /spring-cloud-starter-stream-sink-gpfdist/src/main/java/org/springframework/cloud/stream/app/gpfdist/sink/support/LoadService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.cloud.stream.app.gpfdist.sink.support; 17 | 18 | public interface LoadService { 19 | 20 | public void load(LoadConfiguration loadConfiguration); 21 | 22 | public void load(LoadConfiguration loadConfiguration, RuntimeContext context); 23 | 24 | } 25 | -------------------------------------------------------------------------------- /spring-cloud-starter-stream-sink-gpfdist/src/main/java/org/springframework/cloud/stream/app/gpfdist/sink/support/NetworkUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.cloud.stream.app.gpfdist.sink.support; 17 | 18 | /** 19 | * Various network utilities. 20 | * 21 | * @author Janne Valkealahti 22 | * 23 | */ 24 | public class NetworkUtils { 25 | 26 | public static String getGPFDistUri(String address, int port) { 27 | return "gpfdist://" + address + ":" + port + "/data"; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /spring-cloud-starter-stream-sink-gpfdist/src/main/java/org/springframework/cloud/stream/app/gpfdist/sink/support/SegmentRejectType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.cloud.stream.app.gpfdist.sink.support; 17 | 18 | /** 19 | * Enumeration of a possible values in a clause section 20 | * `SEGMENT REJECT LIMIT count [ROWS | PERCENT]` 21 | * 22 | * @author Janne Valkealahti 23 | */ 24 | public enum SegmentRejectType { 25 | 26 | /** Rows reject type */ 27 | ROWS, 28 | 29 | /** Percent reject type */ 30 | PERCENT 31 | } 32 | -------------------------------------------------------------------------------- /spring-cloud-starter-stream-sink-gpfdist/src/main/java/org/springframework/cloud/stream/app/gpfdist/sink/GpfdistSinkApplication.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.springframework.cloud.stream.app.gpfdist.sink; 18 | 19 | import org.springframework.boot.SpringApplication; 20 | import org.springframework.boot.autoconfigure.SpringBootApplication; 21 | import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; 22 | 23 | /** 24 | * Spring Boot app running gpfdist sink application. 25 | * 26 | * @author Janne Valkealahti 27 | */ 28 | @SpringBootApplication(exclude = DataSourceAutoConfiguration.class) 29 | public class GpfdistSinkApplication { 30 | // explicitly exclude DataSourceAutoConfiguration as it is 31 | // interfering too much with data source config for gpdb. 32 | 33 | public static void main(String[] args) throws InterruptedException { 34 | SpringApplication.run(GpfdistSinkApplication.class, args); 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /spring-cloud-starter-stream-sink-gpfdist/src/main/java/org/springframework/cloud/stream/app/gpfdist/sink/GpfdistCodec.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.springframework.cloud.stream.app.gpfdist.sink; 18 | 19 | import reactor.fn.Consumer; 20 | import reactor.fn.Function; 21 | import reactor.io.buffer.Buffer; 22 | import reactor.io.codec.Codec; 23 | 24 | import java.nio.ByteBuffer; 25 | import java.nio.charset.Charset; 26 | 27 | /** 28 | * Gpfdist related reactor {@link Codec}. 29 | * 30 | * @author Janne Valkealahti 31 | */ 32 | public class GpfdistCodec extends Codec { 33 | 34 | final byte[] h1 = Character.toString('D').getBytes(Charset.forName("UTF-8")); 35 | 36 | @SuppressWarnings("resource") 37 | @Override 38 | public Buffer apply(Buffer t) { 39 | byte[] h2 = ByteBuffer.allocate(4).putInt(t.flip().remaining()).array(); 40 | return new Buffer().append(h1).append(h2).append(t).flip(); 41 | } 42 | 43 | @Override 44 | public Function decoder(Consumer next) { 45 | return null; 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /spring-cloud-starter-stream-sink-gpfdist/src/test/java/org/springframework/cloud/stream/app/gpfdist/sink/support/LoadConfigurationFactoryBeanTests.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.springframework.cloud.stream.app.gpfdist.sink.support; 18 | 19 | import org.junit.Test; 20 | import org.springframework.context.support.ClassPathXmlApplicationContext; 21 | 22 | import static org.hamcrest.Matchers.is; 23 | import static org.junit.Assert.assertThat; 24 | 25 | /** 26 | * Tests for {@link LoadConfigurationFactoryBean}. 27 | * 28 | * @author Janne Valkealahti 29 | */ 30 | public class LoadConfigurationFactoryBeanTests { 31 | 32 | @Test 33 | public void testListValuesToColumns() { 34 | ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( 35 | "LoadConfigurationFactoryBeanTests1.xml"); 36 | LoadConfigurationFactoryBean factoryBean = context.getBean("&greenplumLoadConfiguration", 37 | LoadConfigurationFactoryBean.class); 38 | assertThat(factoryBean.getUpdateColumns().size(), is(2)); 39 | assertThat(factoryBean.getMatchColumns().size(), is(2)); 40 | context.close(); 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /spring-cloud-starter-stream-sink-gpfdist/src/main/java/org/springframework/cloud/stream/app/gpfdist/sink/support/DefaultGreenplumLoad.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.cloud.stream.app.gpfdist.sink.support; 17 | 18 | import org.apache.commons.logging.Log; 19 | import org.apache.commons.logging.LogFactory; 20 | import org.springframework.util.Assert; 21 | 22 | public class DefaultGreenplumLoad implements GreenplumLoad { 23 | 24 | private final static Log log = LogFactory.getLog(DefaultGreenplumLoad.class); 25 | 26 | private final LoadService loadService; 27 | 28 | private final LoadConfiguration loadConfiguration; 29 | 30 | public DefaultGreenplumLoad(LoadConfiguration loadConfiguration, LoadService loadService) { 31 | this.loadConfiguration = loadConfiguration; 32 | this.loadService = loadService; 33 | Assert.notNull(loadConfiguration, "Load configuration must be set"); 34 | Assert.notNull(loadService, "Load service must be set"); 35 | } 36 | 37 | @Override 38 | public void load() { 39 | load(null); 40 | } 41 | 42 | @Override 43 | public void load(RuntimeContext context) { 44 | log.debug("Doing greenplum load"); 45 | loadService.load(loadConfiguration, context); 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /spring-cloud-starter-stream-sink-gpfdist/src/main/java/org/springframework/cloud/stream/app/gpfdist/sink/support/RuntimeContext.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.cloud.stream.app.gpfdist.sink.support; 17 | 18 | import java.util.ArrayList; 19 | import java.util.List; 20 | 21 | /** 22 | * Runtime context for load operations. 23 | * 24 | * @author Janne Valkealahti 25 | */ 26 | public class RuntimeContext { 27 | 28 | private final List locations; 29 | 30 | /** 31 | * Instantiates a new runtime context. 32 | */ 33 | public RuntimeContext() { 34 | this.locations = new ArrayList<>(); 35 | } 36 | 37 | /** 38 | * Instantiates a new runtime context. 39 | * 40 | * @param location the location 41 | */ 42 | public RuntimeContext(String location) { 43 | this.locations = new ArrayList<>(); 44 | addLocation(location); 45 | } 46 | 47 | /** 48 | * Gets the locations. 49 | * 50 | * @return the locations 51 | */ 52 | public List getLocations() { 53 | return locations; 54 | } 55 | 56 | /** 57 | * Sets the locations. 58 | * 59 | * @param locations the new locations 60 | */ 61 | public void setLocations(List locations) { 62 | this.locations.clear(); 63 | this.locations.addAll(locations); 64 | } 65 | 66 | /** 67 | * Adds the location. 68 | * 69 | * @param location the location 70 | */ 71 | public void addLocation(String location) { 72 | this.locations.add(location); 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /spring-cloud-starter-stream-sink-gpfdist/src/test/java/org/springframework/cloud/stream/app/gpfdist/sink/TestListenAddress.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.springframework.cloud.stream.app.gpfdist.sink; 18 | 19 | import org.junit.Test; 20 | import reactor.Environment; 21 | import reactor.fn.Function; 22 | import reactor.io.buffer.Buffer; 23 | import reactor.io.net.NetStreams; 24 | import reactor.io.net.Spec.HttpServerSpec; 25 | import reactor.io.net.http.HttpServer; 26 | 27 | import java.net.InetSocketAddress; 28 | 29 | import static org.hamcrest.Matchers.not; 30 | import static org.hamcrest.Matchers.notNullValue; 31 | import static org.junit.Assert.assertThat; 32 | 33 | public class TestListenAddress { 34 | 35 | @Test 36 | public void testBindZero() throws Exception { 37 | Environment.initializeIfEmpty().assignErrorJournal(); 38 | 39 | HttpServer httpServer = NetStreams 40 | .httpServer(new Function, HttpServerSpec>() { 41 | 42 | @Override 43 | public HttpServerSpec apply(HttpServerSpec server) { 44 | return server 45 | .codec(new GpfdistCodec()) 46 | .listen(0); 47 | } 48 | }); 49 | httpServer.start().awaitSuccess(); 50 | InetSocketAddress address = httpServer.getListenAddress(); 51 | assertThat(address, notNullValue()); 52 | assertThat(address.getPort(), not(0)); 53 | httpServer.shutdown(); 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /spring-cloud-starter-stream-sink-gpfdist/src/main/java/org/springframework/cloud/stream/app/gpfdist/sink/support/ReadableTable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.cloud.stream.app.gpfdist.sink.support; 17 | 18 | /** 19 | * Settings for readable external table. 20 | * 21 | * @author Janne Valkealahti 22 | */ 23 | public class ReadableTable extends AbstractExternalTable { 24 | 25 | // [LOG ERRORS] 26 | private boolean logErrors; 27 | 28 | // SEGMENT REJECT LIMIT count 29 | private Integer segmentRejectLimit; 30 | 31 | // [ROWS | PERCENT] 32 | private SegmentRejectType segmentRejectType; 33 | 34 | // FORMAT 'TEXT|CVS' [( [HEADER] 35 | private boolean formatHeader; 36 | 37 | public boolean isFormatHeader() { 38 | return formatHeader; 39 | } 40 | 41 | public void setFormatHeader(boolean formatHeader) { 42 | this.formatHeader = formatHeader; 43 | } 44 | 45 | public boolean isLogErrors() { 46 | return logErrors; 47 | } 48 | 49 | public void setLogErrors(boolean logErrors) { 50 | this.logErrors = logErrors; 51 | } 52 | 53 | public Integer getSegmentRejectLimit() { 54 | return segmentRejectLimit; 55 | } 56 | 57 | public void setSegmentRejectLimit(Integer segmentRejectLimit) { 58 | this.segmentRejectLimit = segmentRejectLimit; 59 | } 60 | 61 | public SegmentRejectType getSegmentRejectType() { 62 | return segmentRejectType; 63 | } 64 | 65 | public void setSegmentRejectType(SegmentRejectType segmentRejectType) { 66 | this.segmentRejectType = segmentRejectType; 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /spring-cloud-starter-stream-sink-gpfdist/src/test/java/org/springframework/cloud/stream/app/gpfdist/sink/AbstractDbTests.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.cloud.stream.app.gpfdist.sink; 17 | 18 | import org.apache.commons.dbcp.BasicDataSource; 19 | import org.junit.After; 20 | import org.junit.Before; 21 | import org.springframework.context.annotation.AnnotationConfigApplicationContext; 22 | import org.springframework.context.annotation.Bean; 23 | import org.springframework.context.annotation.Configuration; 24 | import org.springframework.jdbc.core.JdbcTemplate; 25 | 26 | public abstract class AbstractDbTests { 27 | 28 | protected AnnotationConfigApplicationContext context; 29 | 30 | @Before 31 | public void setup() { 32 | context = buildContext(); 33 | } 34 | 35 | @After 36 | public void clean() { 37 | if (context != null) { 38 | context.close(); 39 | } 40 | } 41 | 42 | protected AnnotationConfigApplicationContext buildContext() { 43 | return null; 44 | } 45 | 46 | @Configuration 47 | protected static class TestDatasourceConfig { 48 | 49 | @Bean 50 | public JdbcTemplate jdbcTemplate() { 51 | return new JdbcTemplate(dataSource()); 52 | } 53 | 54 | @Bean 55 | public BasicDataSource dataSource() { 56 | BasicDataSource dataSource = new BasicDataSource(); 57 | dataSource.setDriverClassName("org.postgresql.Driver"); 58 | dataSource.setUrl("jdbc:postgresql://mdw/gpadmin"); 59 | dataSource.setUsername("gpadmin"); 60 | dataSource.setPassword("gpadmin"); 61 | return dataSource; 62 | } 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /spring-cloud-starter-stream-sink-gpfdist/src/main/java/org/springframework/cloud/stream/app/gpfdist/sink/support/DefaultLoadService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.springframework.cloud.stream.app.gpfdist.sink.support; 18 | 19 | import org.springframework.jdbc.core.JdbcTemplate; 20 | import org.springframework.util.Assert; 21 | 22 | import java.util.UUID; 23 | 24 | public class DefaultLoadService implements LoadService { 25 | 26 | private final JdbcTemplate jdbcTemplate; 27 | 28 | public DefaultLoadService(JdbcTemplate jdbcTemplate) { 29 | this.jdbcTemplate = jdbcTemplate; 30 | Assert.notNull(jdbcTemplate, "JdbcTemplate must be set"); 31 | } 32 | 33 | @Override 34 | public void load(LoadConfiguration loadConfiguration) { 35 | load(loadConfiguration, null); 36 | } 37 | 38 | @Override 39 | public void load(LoadConfiguration loadConfiguration, RuntimeContext context) { 40 | String prefix = UUID.randomUUID().toString().replaceAll("-", "_"); 41 | 42 | // setup jdbc operations 43 | JdbcCommands operations = new JdbcCommands(jdbcTemplate); 44 | 45 | String sqlCreateTable = SqlUtils.createExternalReadableTable(loadConfiguration, prefix, 46 | context != null ? context.getLocations() : null); 47 | String sqlDropTable = SqlUtils.dropExternalReadableTable(loadConfiguration, prefix); 48 | String sqlInsert = SqlUtils.load(loadConfiguration, prefix); 49 | 50 | operations.setPrepareSql(sqlCreateTable); 51 | operations.setCleanSql(sqlDropTable); 52 | operations.setRunSql(sqlInsert); 53 | 54 | operations.setBeforeSqls(loadConfiguration.getSqlBefore()); 55 | operations.setAfterSqls(loadConfiguration.getSqlAfter()); 56 | 57 | if (!operations.execute() && operations.getLastException() != null) { 58 | throw operations.getLastException(); 59 | } 60 | } 61 | 62 | } 63 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.adoc: -------------------------------------------------------------------------------- 1 | = Contributor Code of Conduct 2 | 3 | As contributors and maintainers of this project, and in the interest of fostering an open 4 | and welcoming community, we pledge to respect all people who contribute through reporting 5 | issues, posting feature requests, updating documentation, submitting pull requests or 6 | patches, and other activities. 7 | 8 | We are committed to making participation in this project a harassment-free experience for 9 | everyone, regardless of level of experience, gender, gender identity and expression, 10 | sexual orientation, disability, personal appearance, body size, race, ethnicity, age, 11 | religion, or nationality. 12 | 13 | Examples of unacceptable behavior by participants include: 14 | 15 | * The use of sexualized language or imagery 16 | * Personal attacks 17 | * Trolling or insulting/derogatory comments 18 | * Public or private harassment 19 | * Publishing other's private information, such as physical or electronic addresses, 20 | without explicit permission 21 | * Other unethical or unprofessional conduct 22 | 23 | Project maintainers have the right and responsibility to remove, edit, or reject comments, 24 | commits, code, wiki edits, issues, and other contributions that are not aligned to this 25 | Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors 26 | that they deem inappropriate, threatening, offensive, or harmful. 27 | 28 | By adopting this Code of Conduct, project maintainers commit themselves to fairly and 29 | consistently applying these principles to every aspect of managing this project. Project 30 | maintainers who do not follow or enforce the Code of Conduct may be permanently removed 31 | from the project team. 32 | 33 | This Code of Conduct applies both within project spaces and in public spaces when an 34 | individual is representing the project or its community. 35 | 36 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by 37 | contacting a project maintainer at spring-code-of-conduct@pivotal.io . All complaints will 38 | be reviewed and investigated and will result in a response that is deemed necessary and 39 | appropriate to the circumstances. Maintainers are obligated to maintain confidentiality 40 | with regard to the reporter of an incident. 41 | 42 | This Code of Conduct is adapted from the 43 | https://contributor-covenant.org[Contributor Covenant], version 1.3.0, available at 44 | https://contributor-covenant.org/version/1/3/0/[contributor-covenant.org/version/1/3/0/] 45 | -------------------------------------------------------------------------------- /spring-cloud-starter-stream-sink-gpfdist/src/main/java/org/springframework/cloud/stream/app/gpfdist/sink/support/LoadFactoryBean.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.springframework.cloud.stream.app.gpfdist.sink.support; 18 | 19 | import org.springframework.beans.factory.DisposableBean; 20 | import org.springframework.beans.factory.FactoryBean; 21 | import org.springframework.beans.factory.InitializingBean; 22 | import org.springframework.jdbc.core.JdbcTemplate; 23 | import org.springframework.util.Assert; 24 | 25 | import javax.sql.DataSource; 26 | import java.io.IOException; 27 | 28 | /** 29 | * FactoryBean for easy creation and configuration of {@link GreenplumLoad} 30 | * instances. 31 | * 32 | * @author Janne Valkealahti 33 | * 34 | */ 35 | public class LoadFactoryBean implements FactoryBean, InitializingBean, DisposableBean { 36 | 37 | private DataSource dataSource; 38 | 39 | private LoadConfiguration loadConfiguration; 40 | 41 | private JdbcTemplate jdbcTemplate; 42 | 43 | @Override 44 | public GreenplumLoad getObject() throws Exception { 45 | return new DefaultGreenplumLoad(loadConfiguration, new DefaultLoadService(jdbcTemplate)); 46 | } 47 | 48 | @Override 49 | public Class getObjectType() { 50 | return GreenplumLoad.class; 51 | } 52 | 53 | @Override 54 | public boolean isSingleton() { 55 | return true; 56 | } 57 | 58 | @Override 59 | public void afterPropertiesSet() throws IOException { 60 | Assert.notNull(dataSource, "DataSource must not be null."); 61 | Assert.notNull(loadConfiguration, "Load configuration must not be null."); 62 | jdbcTemplate = new JdbcTemplate(dataSource); 63 | } 64 | 65 | @Override 66 | public void destroy() { 67 | } 68 | 69 | public void setDataSource(DataSource dataSource) { 70 | this.dataSource = dataSource; 71 | } 72 | 73 | public void setLoadConfiguration(LoadConfiguration LoadConfiguration) { 74 | this.loadConfiguration = LoadConfiguration; 75 | } 76 | 77 | } 78 | -------------------------------------------------------------------------------- /spring-cloud-starter-stream-sink-gpfdist/src/main/java/org/springframework/cloud/stream/app/gpfdist/sink/HostInfoDiscoveryProperties.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.cloud.stream.app.gpfdist.sink; 17 | 18 | import org.springframework.boot.context.properties.ConfigurationProperties; 19 | 20 | import java.util.List; 21 | 22 | /** 23 | * Shared boot configuration properties for "spring.net.hostdiscovery". 24 | * 25 | * @author Janne Valkealahti 26 | * @author Sabby Anandan 27 | * 28 | */ 29 | @ConfigurationProperties(value = "spring.net.hostdiscovery") 30 | public class HostInfoDiscoveryProperties { 31 | 32 | /** 33 | * Used to match ip address from a network using a cidr notation 34 | */ 35 | private String matchIpv4; 36 | 37 | /** 38 | * The new match interface regex pattern. Default value is is empty 39 | */ 40 | private String matchInterface; 41 | 42 | /** 43 | * The new preferred interface list 44 | */ 45 | private List preferInterface; 46 | 47 | /** 48 | * The new point to point flag. Default value is FALSE 49 | */ 50 | private boolean pointToPoint = false; 51 | 52 | /** 53 | * The new loopback flag. Default value is FALSE 54 | */ 55 | private boolean loopback = false; 56 | 57 | public String getMatchIpv4() { 58 | return matchIpv4; 59 | } 60 | 61 | public void setMatchIpv4(String matchIpv4) { 62 | this.matchIpv4 = matchIpv4; 63 | } 64 | 65 | public String getMatchInterface() { 66 | return matchInterface; 67 | } 68 | 69 | public void setMatchInterface(String matchInterface) { 70 | this.matchInterface = matchInterface; 71 | } 72 | 73 | public List getPreferInterface() { 74 | return preferInterface; 75 | } 76 | 77 | public void setPreferInterface(List preferInterface) { 78 | this.preferInterface = preferInterface; 79 | } 80 | 81 | public boolean isPointToPoint() { 82 | return pointToPoint; 83 | } 84 | 85 | public void setPointToPoint(boolean pointToPoint) { 86 | this.pointToPoint = pointToPoint; 87 | } 88 | 89 | public boolean isLoopback() { 90 | return loopback; 91 | } 92 | 93 | public void setLoopback(boolean loopback) { 94 | this.loopback = loopback; 95 | } 96 | } -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4.0.0 4 | gpfdist-app-starters-build 5 | 2.0.0.BUILD-SNAPSHOT 6 | pom 7 | 8 | 9 | org.springframework.cloud.stream.app 10 | app-starters-build 11 | 2.1.6.BUILD-SNAPSHOT 12 | 13 | 14 | 15 | 16 | true 17 | 18 | 19 | 20 | spring-cloud-starter-stream-sink-gpfdist 21 | gpfdist-app-dependencies 22 | 23 | 24 | 25 | 26 | 27 | org.springframework.cloud.stream.app 28 | gpfdist-app-dependencies 29 | 2.0.0.BUILD-SNAPSHOT 30 | pom 31 | import 32 | 33 | 34 | 35 | 36 | 37 | spring 38 | 39 | 40 | spring-snapshots 41 | Spring Snapshots 42 | https://repo.spring.io/libs-snapshot-local 43 | 44 | true 45 | 46 | 47 | 48 | spring-milestones 49 | Spring Milestones 50 | https://repo.spring.io/libs-milestone-local 51 | 52 | false 53 | 54 | 55 | 56 | spring-releases 57 | Spring Releases 58 | https://repo.spring.io/release 59 | 60 | false 61 | 62 | 63 | 64 | spring-libs-release 65 | Spring Libs Release 66 | https://repo.spring.io/libs-release 67 | 68 | false 69 | 70 | 71 | 72 | 73 | false 74 | 75 | spring-milestone-release 76 | Spring Milestone Release 77 | https://repo.spring.io/libs-milestone 78 | 79 | 80 | 81 | 82 | spring-snapshots 83 | Spring Snapshots 84 | https://repo.spring.io/libs-snapshot-local 85 | 86 | true 87 | 88 | 89 | 90 | spring-milestones 91 | Spring Milestones 92 | https://repo.spring.io/libs-milestone-local 93 | 94 | false 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | -------------------------------------------------------------------------------- /spring-cloud-starter-stream-sink-gpfdist/src/test/java/org/springframework/cloud/stream/app/gpfdist/sink/support/ControlFileTests.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.springframework.cloud.stream.app.gpfdist.sink.support; 18 | 19 | import org.junit.After; 20 | import org.junit.Test; 21 | import org.springframework.cloud.stream.app.gpfdist.sink.support.ControlFile.OutputMode; 22 | import org.springframework.context.annotation.AnnotationConfigApplicationContext; 23 | import org.springframework.context.annotation.Bean; 24 | import org.springframework.core.io.ClassPathResource; 25 | 26 | import static org.hamcrest.Matchers.*; 27 | import static org.junit.Assert.assertThat; 28 | 29 | public class ControlFileTests { 30 | 31 | private AnnotationConfigApplicationContext context; 32 | 33 | @Test 34 | public void testLoadFromFactory() { 35 | context = new AnnotationConfigApplicationContext(); 36 | context.register(Config1.class); 37 | context.refresh(); 38 | 39 | ControlFile cf = context.getBean(ControlFile.class); 40 | assertThat(cf.getGploadOutputTable(), is("test")); 41 | assertThat(cf.getGploadInputDelimiter(), is(',')); 42 | assertThat(cf.getDatabase(), is("gpadmin")); 43 | assertThat(cf.getUser(), is("gpadmin")); 44 | assertThat(cf.getHost(), is("mdw.example.org")); 45 | assertThat(cf.getPort(), is(5432)); 46 | assertThat(cf.getPassword(), nullValue()); 47 | 48 | assertThat(cf.getGploadOutputMode(), is(OutputMode.UPDATE)); 49 | 50 | assertThat(cf.getGploadOutputMatchColumns(), notNullValue()); 51 | assertThat(cf.getGploadOutputMatchColumns().size(), is(2)); 52 | assertThat(cf.getGploadOutputMatchColumns().get(0), is("col11")); 53 | assertThat(cf.getGploadOutputMatchColumns().get(1), is("col12")); 54 | 55 | assertThat(cf.getGploadOutputUpdateColumns(), notNullValue()); 56 | assertThat(cf.getGploadOutputUpdateColumns().size(), is(2)); 57 | assertThat(cf.getGploadOutputUpdateColumns().get(0), is("col21")); 58 | assertThat(cf.getGploadOutputUpdateColumns().get(1), is("col22")); 59 | assertThat(cf.getGploadOutputUpdateCondition(), is("condition")); 60 | 61 | assertThat(cf.getGploadSqlBefore().get(0), is("select 1 as before")); 62 | assertThat(cf.getGploadSqlBefore().get(1), is("select 2 as before")); 63 | assertThat(cf.getGploadSqlAfter().get(0), is("select 1 as after")); 64 | assertThat(cf.getGploadSqlAfter().get(1), is("select 2 as after")); 65 | } 66 | 67 | static class Config1 { 68 | 69 | @Bean 70 | public ControlFileFactoryBean controlFile() { 71 | ControlFileFactoryBean f = new ControlFileFactoryBean(); 72 | f.setControlFileResource(new ClassPathResource("test.yml")); 73 | return f; 74 | } 75 | 76 | } 77 | 78 | @After 79 | public void clean() { 80 | context.close(); 81 | context = null; 82 | } 83 | 84 | } 85 | -------------------------------------------------------------------------------- /spring-cloud-starter-stream-sink-gpfdist/src/test/java/org/springframework/cloud/stream/app/gpfdist/sink/TestUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.springframework.cloud.stream.app.gpfdist.sink; 18 | 19 | import org.springframework.util.ReflectionUtils; 20 | 21 | import java.lang.reflect.Field; 22 | import java.lang.reflect.Method; 23 | 24 | /** 25 | * Utils for tests. 26 | * 27 | * @author Janne Valkealahti 28 | * 29 | */ 30 | public class TestUtils { 31 | 32 | @SuppressWarnings("unchecked") 33 | public static T readField(String name, Object target) throws Exception { 34 | Field field = null; 35 | Class clazz = target.getClass(); 36 | do { 37 | try { 38 | field = clazz.getDeclaredField(name); 39 | } catch (Exception ex) { 40 | } 41 | 42 | clazz = clazz.getSuperclass(); 43 | } while (field == null && !clazz.equals(Object.class)); 44 | 45 | if (field == null) 46 | throw new IllegalArgumentException("Cannot find field '" + name + "' in the class hierarchy of " 47 | + target.getClass()); 48 | field.setAccessible(true); 49 | return (T) field.get(target); 50 | } 51 | 52 | @SuppressWarnings("unchecked") 53 | public static T callMethod(String name, Object target) throws Exception { 54 | Class clazz = target.getClass(); 55 | Method method = ReflectionUtils.findMethod(clazz, name); 56 | 57 | if (method == null) 58 | throw new IllegalArgumentException("Cannot find method '" + method + "' in the class hierarchy of " 59 | + target.getClass()); 60 | method.setAccessible(true); 61 | return (T) ReflectionUtils.invokeMethod(method, target); 62 | } 63 | 64 | public static void setField(String name, Object target, Object value) throws Exception { 65 | Field field = null; 66 | Class clazz = target.getClass(); 67 | do { 68 | try { 69 | field = clazz.getDeclaredField(name); 70 | } catch (Exception ex) { 71 | } 72 | 73 | clazz = clazz.getSuperclass(); 74 | } while (field == null && !clazz.equals(Object.class)); 75 | 76 | if (field == null) 77 | throw new IllegalArgumentException("Cannot find field '" + name + "' in the class hierarchy of " 78 | + target.getClass()); 79 | field.setAccessible(true); 80 | field.set(target, value); 81 | } 82 | 83 | @SuppressWarnings("unchecked") 84 | public static T callMethod(String name, Object target, Object[] args, Class[] argsTypes) throws Exception { 85 | Class clazz = target.getClass(); 86 | Method method = ReflectionUtils.findMethod(clazz, name, argsTypes); 87 | 88 | if (method == null) 89 | throw new IllegalArgumentException("Cannot find method '" + method + "' in the class hierarchy of " 90 | + target.getClass()); 91 | method.setAccessible(true); 92 | return (T) ReflectionUtils.invokeMethod(method, target, args); 93 | } 94 | 95 | } 96 | -------------------------------------------------------------------------------- /spring-cloud-starter-stream-sink-gpfdist/src/main/java/org/springframework/cloud/stream/app/gpfdist/sink/support/LoadConfiguration.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.springframework.cloud.stream.app.gpfdist.sink.support; 18 | 19 | import java.util.List; 20 | 21 | public class LoadConfiguration { 22 | 23 | private String table; 24 | 25 | private String columns; 26 | 27 | private ReadableTable externalTable; 28 | 29 | private Mode mode; 30 | 31 | private List matchColumns; 32 | 33 | private List updateColumns; 34 | 35 | private String updateCondition; 36 | 37 | private List sqlBefore; 38 | 39 | private List sqlAfter; 40 | 41 | public LoadConfiguration() { 42 | super(); 43 | } 44 | 45 | public LoadConfiguration(String table, String columns, ReadableTable externalTable, Mode mode, 46 | List matchColumns, List updateColumns, String updateCondition) { 47 | this.table = table; 48 | this.columns = columns; 49 | this.externalTable = externalTable; 50 | this.mode = mode; 51 | this.matchColumns = matchColumns; 52 | this.updateColumns = updateColumns; 53 | this.updateCondition = updateCondition; 54 | } 55 | 56 | public String getTable() { 57 | return table; 58 | } 59 | 60 | public void setTable(String table) { 61 | this.table = table; 62 | } 63 | 64 | public String getColumns() { 65 | return columns; 66 | } 67 | 68 | public void setColumns(String columns) { 69 | this.columns = columns; 70 | } 71 | 72 | public ReadableTable getExternalTable() { 73 | return externalTable; 74 | } 75 | 76 | public void setExternalTable(ReadableTable externalTable) { 77 | this.externalTable = externalTable; 78 | } 79 | 80 | public Mode getMode() { 81 | return mode; 82 | } 83 | 84 | public void setMode(Mode mode) { 85 | this.mode = mode; 86 | } 87 | 88 | public List getMatchColumns() { 89 | return matchColumns; 90 | } 91 | 92 | public void setMatchColumns(List matchColumns) { 93 | this.matchColumns = matchColumns; 94 | } 95 | 96 | public List getUpdateColumns() { 97 | return updateColumns; 98 | } 99 | 100 | public void setUpdateColumns(List updateColumns) { 101 | this.updateColumns = updateColumns; 102 | } 103 | 104 | public String getUpdateCondition() { 105 | return updateCondition; 106 | } 107 | 108 | public void setUpdateCondition(String updateCondition) { 109 | this.updateCondition = updateCondition; 110 | } 111 | 112 | public List getSqlBefore() { 113 | return sqlBefore; 114 | } 115 | 116 | public void setSqlBefore(List sqlBefore) { 117 | this.sqlBefore = sqlBefore; 118 | } 119 | 120 | public List getSqlAfter() { 121 | return sqlAfter; 122 | } 123 | 124 | public void setSqlAfter(List sqlAfter) { 125 | this.sqlAfter = sqlAfter; 126 | } 127 | 128 | } 129 | -------------------------------------------------------------------------------- /spring-cloud-starter-stream-sink-gpfdist/src/test/java/org/springframework/cloud/stream/app/gpfdist/sink/GpfdistSinkPropertiesTests.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.cloud.stream.app.gpfdist.sink; 17 | 18 | import static org.hamcrest.CoreMatchers.notNullValue; 19 | import static org.hamcrest.Matchers.is; 20 | import static org.junit.Assert.assertThat; 21 | 22 | import org.junit.Test; 23 | 24 | import org.springframework.boot.SpringApplication; 25 | import org.springframework.boot.context.properties.EnableConfigurationProperties; 26 | import org.springframework.cloud.stream.app.gpfdist.sink.support.SegmentRejectType; 27 | import org.springframework.context.ConfigurableApplicationContext; 28 | import org.springframework.context.annotation.Configuration; 29 | 30 | public class GpfdistSinkPropertiesTests { 31 | 32 | @Test 33 | public void testErrorTable1() { 34 | SpringApplication app = new SpringApplication(TestConfiguration.class); 35 | app.setWebEnvironment(false); 36 | ConfigurableApplicationContext context = app 37 | .run(new String[] { "--gpfdist.logErrors=true", 38 | "--gpfdist.segmentRejectLimit=1", 39 | "--gpfdist.segmentRejectType=ROWS" }); 40 | 41 | GpfdistSinkProperties properties = context.getBean(GpfdistSinkProperties.class); 42 | assertThat(properties, notNullValue()); 43 | assertThat(properties.isLogErrors(), is(true)); 44 | assertThat(properties.getSegmentRejectLimit(), is("1")); 45 | assertThat(properties.getSegmentRejectType(), is(SegmentRejectType.ROWS)); 46 | context.close(); 47 | } 48 | 49 | @Test 50 | public void testErrorTable2() { 51 | SpringApplication app = new SpringApplication(TestConfiguration.class); 52 | app.setWebEnvironment(false); 53 | ConfigurableApplicationContext context = app 54 | .run(new String[] { "--gpfdist.logErrors=true", 55 | "--gpfdist.segmentRejectLimit=1", 56 | "--gpfdist.segmentRejectType=percent" }); 57 | 58 | GpfdistSinkProperties properties = context.getBean(GpfdistSinkProperties.class); 59 | assertThat(properties, notNullValue()); 60 | assertThat(properties.isLogErrors(), is(true)); 61 | assertThat(properties.getSegmentRejectLimit(), is("1")); 62 | assertThat(properties.getSegmentRejectType(), is(SegmentRejectType.PERCENT)); 63 | context.close(); 64 | } 65 | 66 | @Test 67 | public void testNullString() { 68 | SpringApplication app = new SpringApplication(TestConfiguration.class); 69 | app.setWebEnvironment(false); 70 | ConfigurableApplicationContext context = app 71 | .run(new String[] { "--gpfdist.nullString=mynullstring" }); 72 | 73 | GpfdistSinkProperties properties = context.getBean(GpfdistSinkProperties.class); 74 | assertThat(properties, notNullValue()); 75 | assertThat(properties.getNullString(), is("mynullstring")); 76 | context.close(); 77 | } 78 | 79 | @Configuration 80 | @EnableConfigurationProperties({ GpfdistSinkProperties.class }) 81 | protected static class TestConfiguration { 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /spring-cloud-starter-stream-sink-gpfdist/src/main/java/org/springframework/cloud/stream/app/gpfdist/sink/support/GreenplumDataSourceFactoryBean.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.springframework.cloud.stream.app.gpfdist.sink.support; 18 | 19 | import org.apache.commons.dbcp.BasicDataSource; 20 | import org.springframework.beans.factory.config.AbstractFactoryBean; 21 | import org.springframework.util.StringUtils; 22 | 23 | import javax.sql.DataSource; 24 | 25 | /** 26 | * Factory bean for configuring a {@link DataSource}. Needed to use 27 | * both command-line props and a control file. 28 | * 29 | * @author Janne Valkealahti 30 | */ 31 | public class GreenplumDataSourceFactoryBean extends AbstractFactoryBean { 32 | 33 | private ControlFile controlFile; 34 | 35 | private String dbHost = "localhost"; 36 | 37 | private String dbName = "gpadmin"; 38 | 39 | private String dbUser = "gpadmin"; 40 | 41 | private String dbPassword = "gpadmin"; 42 | 43 | private int dbPort = 5432; 44 | 45 | @Override 46 | public Class getObjectType() { 47 | return DataSource.class; 48 | } 49 | 50 | @Override 51 | protected BasicDataSource createInstance() throws Exception { 52 | BasicDataSource ds = new BasicDataSource(); 53 | ds.setDriverClassName("org.postgresql.Driver"); 54 | if (StringUtils.hasText(dbUser)) { 55 | ds.setUsername(dbUser); 56 | } 57 | if (StringUtils.hasText(dbPassword)) { 58 | ds.setPassword(dbPassword); 59 | } 60 | ds.setUrl("jdbc:postgresql://" + dbHost + ":" + dbPort + "/" + dbName); 61 | return ds; 62 | } 63 | 64 | @Override 65 | public void afterPropertiesSet() throws Exception { 66 | if (controlFile != null) { 67 | if (StringUtils.hasText(controlFile.getHost())) { 68 | dbHost = controlFile.getHost(); 69 | } 70 | if (StringUtils.hasText(controlFile.getDatabase())) { 71 | dbName = controlFile.getDatabase(); 72 | } 73 | if (StringUtils.hasText(controlFile.getUser())) { 74 | dbUser = controlFile.getUser(); 75 | } 76 | if (StringUtils.hasText(controlFile.getPassword())) { 77 | dbPassword = controlFile.getPassword(); 78 | } 79 | if (controlFile.getPort() != null) { 80 | dbPort = controlFile.getPort(); 81 | } 82 | } 83 | super.afterPropertiesSet(); 84 | } 85 | 86 | @Override 87 | protected void destroyInstance(BasicDataSource instance) throws Exception { 88 | instance.close(); 89 | } 90 | 91 | public void setControlFile(ControlFile controlFile) { 92 | this.controlFile = controlFile; 93 | } 94 | 95 | public void setDbHost(String dbHost) { 96 | this.dbHost = dbHost; 97 | } 98 | 99 | 100 | public void setDbName(String dbName) { 101 | this.dbName = dbName; 102 | } 103 | 104 | 105 | public void setDbUser(String dbUser) { 106 | this.dbUser = dbUser; 107 | } 108 | 109 | 110 | public void setDbPassword(String dbPassword) { 111 | this.dbPassword = dbPassword; 112 | } 113 | 114 | 115 | public void setDbPort(int dbPort) { 116 | this.dbPort = dbPort; 117 | } 118 | 119 | } 120 | -------------------------------------------------------------------------------- /spring-cloud-starter-stream-sink-gpfdist/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4.0.0 4 | 5 | 6 | org.springframework.cloud.stream.app 7 | gpfdist-app-starters-build 8 | 2.0.0.BUILD-SNAPSHOT 9 | 10 | 11 | spring-cloud-starter-stream-sink-gpfdist 12 | 2.0.0.BUILD-SNAPSHOT 13 | 14 | 15 | 16 | 17 | org.springframework.cloud.stream.app 18 | gpfdist-app-dependencies 19 | 2.0.0.BUILD-SNAPSHOT 20 | pom 21 | import 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | io.projectreactor 30 | reactor-core 31 | 32 | 33 | io.projectreactor 34 | reactor-net 35 | 36 | 37 | com.codahale.metrics 38 | metrics-core 39 | 40 | 41 | commons-dbcp 42 | commons-dbcp 43 | 44 | 45 | org.springframework 46 | spring-jdbc 47 | 48 | 49 | io.netty 50 | netty-all 51 | 52 | 53 | org.postgresql 54 | postgresql 55 | 56 | 57 | org.springframework.data 58 | spring-data-hadoop-util 59 | 60 | 61 | org.springframework.cloud.stream.app 62 | app-starters-test-support 63 | 64 | 65 | 66 | 67 | 68 | 69 | maven-failsafe-plugin 70 | 71 | ${skipITs} 72 | 73 | 74 | 75 | package 76 | 77 | integration-test 78 | verify 79 | 80 | 81 | 82 | 83 | 84 | org.springframework.cloud 85 | spring-cloud-app-starter-doc-maven-plugin 86 | 87 | 88 | org.springframework.cloud.stream.app.plugin 89 | spring-cloud-stream-app-maven-plugin 90 | 91 | ${session.executionRootDirectory}/apps 92 | ${project.version} 93 | 94 | scs-bom 95 | org.springframework.cloud.stream.app 96 | gpfdist-app-dependencies 97 | ${project.version} 98 | 99 | 100 | 101 | true 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | -------------------------------------------------------------------------------- /spring-cloud-starter-stream-sink-gpfdist/src/test/java/org/springframework/cloud/stream/app/gpfdist/sink/AbstractLoadTests.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.springframework.cloud.stream.app.gpfdist.sink; 18 | 19 | import org.apache.commons.dbcp.BasicDataSource; 20 | import org.junit.After; 21 | import org.junit.Before; 22 | import org.reactivestreams.Processor; 23 | import org.springframework.cloud.stream.app.gpfdist.sink.support.*; 24 | import org.springframework.context.annotation.AnnotationConfigApplicationContext; 25 | import org.springframework.context.annotation.Bean; 26 | import org.springframework.data.hadoop.util.net.DefaultHostInfoDiscovery; 27 | import org.springframework.jdbc.core.JdbcTemplate; 28 | import reactor.Environment; 29 | import reactor.core.processor.RingBufferProcessor; 30 | import reactor.io.buffer.Buffer; 31 | 32 | import java.util.Arrays; 33 | import java.util.List; 34 | 35 | /** 36 | * Base integration support for using local protocol listener. 37 | * 38 | * @author Janne Valkealahti 39 | * 40 | */ 41 | public abstract class AbstractLoadTests { 42 | 43 | protected AnnotationConfigApplicationContext context; 44 | 45 | protected Processor processor; 46 | 47 | private GpfdistServer server; 48 | 49 | static class CommonConfig { 50 | 51 | @Bean 52 | public LoadFactoryBean greenplumLoad(LoadConfiguration loadConfiguration) { 53 | LoadFactoryBean factory = new LoadFactoryBean(); 54 | factory.setLoadConfiguration(loadConfiguration); 55 | factory.setDataSource(dataSource()); 56 | return factory; 57 | } 58 | 59 | @Bean 60 | public ReadableTableFactoryBean greenplumReadableTable() { 61 | ReadableTableFactoryBean factory = new ReadableTableFactoryBean(); 62 | DefaultHostInfoDiscovery discovery = new DefaultHostInfoDiscovery(); 63 | factory.setLocations(Arrays.asList(NetworkUtils.getGPFDistUri(discovery.getHostInfo().getAddress(), 8080))); 64 | factory.setFormat(Format.TEXT); 65 | return factory; 66 | } 67 | 68 | @Bean 69 | public JdbcTemplate jdbcTemplate() { 70 | return new JdbcTemplate(dataSource()); 71 | } 72 | 73 | @Bean 74 | public BasicDataSource dataSource() { 75 | BasicDataSource dataSource = new BasicDataSource(); 76 | dataSource.setDriverClassName("org.postgresql.Driver"); 77 | dataSource.setUrl("jdbc:postgresql://mdw/gpadmin"); 78 | dataSource.setUsername("gpadmin"); 79 | dataSource.setPassword("gpadmin"); 80 | return dataSource; 81 | } 82 | 83 | } 84 | 85 | protected void broadcastData(List data) { 86 | for (String d : data) { 87 | processor.onNext(Buffer.wrap(d)); 88 | } 89 | } 90 | 91 | @Before 92 | public void setup() throws Exception { 93 | Environment.initializeIfEmpty().assignErrorJournal(); 94 | processor = RingBufferProcessor.create(false); 95 | server = new GpfdistServer(processor, 8080, 1, 1, 1, 10); 96 | server.start(); 97 | context = new AnnotationConfigApplicationContext(); 98 | } 99 | 100 | @After 101 | public void clean() throws Exception { 102 | server.stop(); 103 | context.close(); 104 | context = null; 105 | server = null; 106 | } 107 | 108 | } 109 | -------------------------------------------------------------------------------- /spring-cloud-starter-stream-sink-gpfdist/src/test/java/org/springframework/cloud/stream/app/gpfdist/sink/HostInfoDiscoveryPropertiesTests.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.cloud.stream.app.gpfdist.sink; 17 | 18 | import org.junit.Test; 19 | import org.springframework.boot.SpringApplication; 20 | import org.springframework.boot.context.properties.EnableConfigurationProperties; 21 | import org.springframework.context.ConfigurableApplicationContext; 22 | import org.springframework.context.annotation.Configuration; 23 | 24 | import static org.hamcrest.CoreMatchers.notNullValue; 25 | import static org.hamcrest.Matchers.containsInAnyOrder; 26 | import static org.hamcrest.Matchers.is; 27 | import static org.junit.Assert.assertThat; 28 | 29 | public class HostInfoDiscoveryPropertiesTests { 30 | 31 | @Test 32 | public void testAllSet() { 33 | SpringApplication app = new SpringApplication(TestConfiguration.class); 34 | app.setWebEnvironment(false); 35 | ConfigurableApplicationContext context = app 36 | .run(new String[] { "--spring.net.hostdiscovery.pointToPoint=true", 37 | "--spring.net.hostdiscovery.loopback=true", 38 | "--spring.net.hostdiscovery.preferInterface=lxcbr", 39 | "--spring.net.hostdiscovery.matchIpv4=192.168.0.0/24", 40 | "--spring.net.hostdiscovery.matchInterface=eth0" }); 41 | 42 | HostInfoDiscoveryProperties properties = context.getBean(HostInfoDiscoveryProperties.class); 43 | assertThat(properties, notNullValue()); 44 | assertThat(properties.isPointToPoint(), is(true)); 45 | assertThat(properties.isLoopback(), is(true)); 46 | assertThat(properties.getPreferInterface(), notNullValue()); 47 | assertThat(properties.getPreferInterface().size(), is(1)); 48 | assertThat(properties.getMatchIpv4(), is("192.168.0.0/24")); 49 | assertThat(properties.getMatchInterface(), is("eth0")); 50 | context.close(); 51 | } 52 | 53 | @Test 54 | public void testPreferOne() { 55 | SpringApplication app = new SpringApplication(TestConfiguration.class); 56 | app.setWebEnvironment(false); 57 | ConfigurableApplicationContext context = app 58 | .run(new String[] { "--spring.net.hostdiscovery.preferInterface=lxcbr" }); 59 | 60 | HostInfoDiscoveryProperties properties = context.getBean(HostInfoDiscoveryProperties.class); 61 | assertThat(properties, notNullValue()); 62 | assertThat(properties.getPreferInterface(), notNullValue()); 63 | assertThat(properties.getPreferInterface().size(), is(1)); 64 | context.close(); 65 | } 66 | 67 | @Test 68 | public void testPreferTwo() { 69 | SpringApplication app = new SpringApplication(TestConfiguration.class); 70 | app.setWebEnvironment(false); 71 | ConfigurableApplicationContext context = app 72 | .run(new String[] { "--spring.net.hostdiscovery.preferInterface=lxcbr,foo" }); 73 | 74 | HostInfoDiscoveryProperties properties = context.getBean(HostInfoDiscoveryProperties.class); 75 | assertThat(properties, notNullValue()); 76 | assertThat(properties.getPreferInterface(), notNullValue()); 77 | assertThat(properties.getPreferInterface().size(), is(2)); 78 | assertThat(properties.getPreferInterface(), containsInAnyOrder("lxcbr", "foo")); 79 | context.close(); 80 | } 81 | 82 | @Configuration 83 | @EnableConfigurationProperties({ HostInfoDiscoveryProperties.class }) 84 | protected static class TestConfiguration { 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /spring-cloud-starter-stream-sink-gpfdist/src/main/java/org/springframework/cloud/stream/app/gpfdist/sink/support/AbstractExternalTable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.springframework.cloud.stream.app.gpfdist.sink.support; 18 | 19 | import java.util.ArrayList; 20 | import java.util.Arrays; 21 | import java.util.List; 22 | 23 | /** 24 | * Base settings for all external tables; 25 | * 26 | * @author Janne Valkealahti 27 | * @author Gary Russell 28 | */ 29 | public abstract class AbstractExternalTable { 30 | 31 | // LOCATION 32 | private List locations; 33 | 34 | // FORMAT 'TEXT'|'CVS' 35 | private Format format; 36 | 37 | // [DELIMITER [AS] 'delimiter' | 'OFF'] 38 | private Character delimiter; 39 | 40 | // [NULL [AS] 'null string'] 41 | private String nullString; 42 | 43 | // [ESCAPE [AS] 'escape' | 'OFF'] 44 | private Character escape; 45 | 46 | // [QUOTE [AS] 'quote'] 47 | private Character formatQuote; 48 | 49 | // [FORCE NOT NULL column [, ...]] 50 | private String[] formatForceQuote; 51 | 52 | // [ ENCODING 'encoding' ] 53 | private String encoding; 54 | 55 | private String like; 56 | 57 | private String columns; 58 | 59 | public List getLocations() { 60 | return locations; 61 | } 62 | 63 | public void setLocations(List locations) { 64 | this.locations = new ArrayList(locations); 65 | } 66 | 67 | public void setTextFormat() { 68 | this.format = Format.TEXT; 69 | } 70 | 71 | public void setTextFormat(Character delimiter, String nullString, Character escape) { 72 | this.format = Format.TEXT; 73 | this.delimiter = delimiter; 74 | this.nullString = nullString; 75 | this.escape = escape; 76 | } 77 | 78 | public void setCsvFormat() { 79 | this.format = Format.CSV; 80 | } 81 | 82 | public void setCsvFormat(Character quote, Character delimiter, String nullString, String[] forceQuote, 83 | Character escape) { 84 | this.format = Format.CSV; 85 | this.formatQuote = quote; 86 | this.delimiter = delimiter; 87 | this.nullString = nullString; 88 | this.escape = escape; 89 | this.formatForceQuote = Arrays.copyOf(forceQuote, forceQuote.length); 90 | } 91 | 92 | public Format getFormat() { 93 | return format; 94 | } 95 | 96 | public Character getDelimiter() { 97 | return delimiter; 98 | } 99 | 100 | public void setDelimiter(Character delimiter) { 101 | this.delimiter = delimiter; 102 | } 103 | 104 | public String getNullString() { 105 | return nullString; 106 | } 107 | 108 | public void setNullString(String nullString) { 109 | this.nullString = nullString; 110 | } 111 | 112 | public Character getEscape() { 113 | return escape; 114 | } 115 | 116 | public void setEscape(Character escape) { 117 | this.escape = escape; 118 | } 119 | 120 | public Character getQuote() { 121 | return formatQuote; 122 | } 123 | 124 | public void setQuote(Character quote) { 125 | this.formatQuote = quote; 126 | } 127 | 128 | public String[] getForceQuote() { 129 | return formatForceQuote; 130 | } 131 | 132 | public void setForceQuote(String[] forceQuote) { 133 | this.formatForceQuote = Arrays.copyOf(forceQuote, forceQuote.length); 134 | } 135 | 136 | public String getEncoding() { 137 | return encoding; 138 | } 139 | 140 | public void setEncoding(String encoding) { 141 | this.encoding = encoding; 142 | } 143 | 144 | public String getLike() { 145 | return like; 146 | } 147 | 148 | public void setLike(String like) { 149 | this.like = like; 150 | } 151 | 152 | public String getColumns() { 153 | return columns; 154 | } 155 | 156 | public void setColumns(String columns) { 157 | this.columns = columns; 158 | } 159 | } 160 | -------------------------------------------------------------------------------- /spring-cloud-starter-stream-sink-gpfdist/src/main/java/org/springframework/cloud/stream/app/gpfdist/sink/support/ControlFile.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.springframework.cloud.stream.app.gpfdist.sink.support; 18 | 19 | import java.util.ArrayList; 20 | import java.util.List; 21 | 22 | public class ControlFile { 23 | 24 | private Character gploadInputDelimiter; 25 | 26 | private String gploadOutputTable; 27 | 28 | private List gploadOutputMatchColumns; 29 | 30 | private List gploadOutputUpdateColumns; 31 | 32 | private String gploadOutputUpdateCondition; 33 | 34 | private OutputMode gploadOutputMode; 35 | 36 | private String database; 37 | 38 | private String user; 39 | 40 | private String password; 41 | 42 | private String host; 43 | 44 | private Integer port; 45 | 46 | private final List gploadSqlBefore = new ArrayList(); 47 | 48 | private final List gploadSqlAfter = new ArrayList(); 49 | 50 | public Character getGploadInputDelimiter() { 51 | return gploadInputDelimiter; 52 | } 53 | 54 | public void setGploadInputDelimiter(Character gploadInputDelimiter) { 55 | this.gploadInputDelimiter = gploadInputDelimiter; 56 | } 57 | 58 | public String getGploadOutputTable() { 59 | return gploadOutputTable; 60 | } 61 | 62 | public void setGploadOutputTable(String gploadOutputTable) { 63 | this.gploadOutputTable = gploadOutputTable; 64 | } 65 | 66 | public List getGploadOutputMatchColumns() { 67 | return gploadOutputMatchColumns; 68 | } 69 | 70 | public void setGploadOutputMatchColumns(List gploadOutputMatchColumns) { 71 | this.gploadOutputMatchColumns = gploadOutputMatchColumns; 72 | } 73 | 74 | public List getGploadOutputUpdateColumns() { 75 | return gploadOutputUpdateColumns; 76 | } 77 | 78 | public void setGploadOutputUpdateColumns(List gploadOutputUpdateColumns) { 79 | this.gploadOutputUpdateColumns = gploadOutputUpdateColumns; 80 | } 81 | 82 | public String getGploadOutputUpdateCondition() { 83 | return gploadOutputUpdateCondition; 84 | } 85 | 86 | public void setGploadOutputUpdateCondition(String gploadOutputUpdateCondition) { 87 | this.gploadOutputUpdateCondition = gploadOutputUpdateCondition; 88 | } 89 | 90 | public OutputMode getGploadOutputMode() { 91 | return gploadOutputMode; 92 | } 93 | 94 | public void setGploadOutputMode(OutputMode gploadOutputMode) { 95 | this.gploadOutputMode = gploadOutputMode; 96 | } 97 | 98 | public String getDatabase() { 99 | return database; 100 | } 101 | 102 | public void setDatabase(String database) { 103 | this.database = database; 104 | } 105 | 106 | public String getUser() { 107 | return user; 108 | } 109 | 110 | public void setUser(String user) { 111 | this.user = user; 112 | } 113 | 114 | public String getPassword() { 115 | return password; 116 | } 117 | 118 | public void setPassword(String password) { 119 | this.password = password; 120 | } 121 | 122 | public String getHost() { 123 | return host; 124 | } 125 | 126 | public void setHost(String host) { 127 | this.host = host; 128 | } 129 | 130 | public Integer getPort() { 131 | return port; 132 | } 133 | 134 | public void setPort(Integer port) { 135 | this.port = port; 136 | } 137 | 138 | public List getGploadSqlBefore() { 139 | return gploadSqlBefore; 140 | } 141 | 142 | public void addGploadSqlBefore(String gploadSqlBefore) { 143 | this.gploadSqlBefore.add(gploadSqlBefore); 144 | } 145 | 146 | public List getGploadSqlAfter() { 147 | return gploadSqlAfter; 148 | } 149 | 150 | public void addGploadSqlAfter(String gploadSqlAfter) { 151 | this.gploadSqlAfter.add(gploadSqlAfter); 152 | } 153 | 154 | public enum OutputMode { 155 | INSERT, UPDATE, MERGE 156 | } 157 | 158 | } 159 | -------------------------------------------------------------------------------- /spring-cloud-starter-stream-sink-gpfdist/src/main/java/org/springframework/cloud/stream/app/gpfdist/sink/AbstractGpfdistMessageHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.springframework.cloud.stream.app.gpfdist.sink; 18 | 19 | import org.apache.commons.logging.Log; 20 | import org.apache.commons.logging.LogFactory; 21 | import org.springframework.context.SmartLifecycle; 22 | import org.springframework.integration.handler.AbstractMessageHandler; 23 | import org.springframework.messaging.Message; 24 | import org.springframework.messaging.MessageHandlingException; 25 | 26 | import java.util.concurrent.locks.ReentrantLock; 27 | 28 | /** 29 | * Base implementation of Spring Integration {@code MessageHandler} handling {@code Message}. 30 | * 31 | * @author Janne Valkealahti 32 | */ 33 | public abstract class AbstractGpfdistMessageHandler extends AbstractMessageHandler implements SmartLifecycle { 34 | 35 | private static final Log logger = LogFactory.getLog(AbstractGpfdistMessageHandler.class); 36 | 37 | private volatile boolean autoStartup = true; 38 | 39 | private volatile int phase = 0; 40 | 41 | private volatile boolean running; 42 | 43 | private final ReentrantLock lifecycleLock = new ReentrantLock(); 44 | 45 | @Override 46 | public final boolean isAutoStartup() { 47 | return this.autoStartup; 48 | } 49 | 50 | @Override 51 | public final int getPhase() { 52 | return this.phase; 53 | } 54 | 55 | @Override 56 | public final boolean isRunning() { 57 | this.lifecycleLock.lock(); 58 | try { 59 | return this.running; 60 | } 61 | finally { 62 | this.lifecycleLock.unlock(); 63 | } 64 | } 65 | 66 | @Override 67 | public final void start() { 68 | this.lifecycleLock.lock(); 69 | try { 70 | if (!this.running) { 71 | this.doStart(); 72 | this.running = true; 73 | if (logger.isInfoEnabled()) { 74 | logger.info("started " + this); 75 | } 76 | else { 77 | if (logger.isDebugEnabled()) { 78 | logger.debug("already started " + this); 79 | } 80 | } 81 | } 82 | } 83 | finally { 84 | this.lifecycleLock.unlock(); 85 | } 86 | } 87 | 88 | @Override 89 | public final void stop() { 90 | this.lifecycleLock.lock(); 91 | try { 92 | if (this.running) { 93 | this.doStop(); 94 | this.running = false; 95 | if (logger.isInfoEnabled()) { 96 | logger.info("stopped " + this); 97 | } 98 | } 99 | else { 100 | if (logger.isDebugEnabled()) { 101 | logger.debug("already stopped " + this); 102 | } 103 | } 104 | } 105 | finally { 106 | this.lifecycleLock.unlock(); 107 | } 108 | } 109 | 110 | @Override 111 | public final void stop(Runnable callback) { 112 | this.lifecycleLock.lock(); 113 | try { 114 | this.stop(); 115 | callback.run(); 116 | } 117 | finally { 118 | this.lifecycleLock.unlock(); 119 | } 120 | } 121 | 122 | @Override 123 | protected final void handleMessageInternal(Message message) throws Exception { 124 | try { 125 | doWrite(message); 126 | } 127 | catch (Exception e) { 128 | throw new MessageHandlingException(message, 129 | "failed to write Message payload to GPDB/HAWQ", e); 130 | } 131 | } 132 | 133 | /** 134 | * Sets the auto startup. 135 | * 136 | * @param autoStartup the new auto startup 137 | * @see SmartLifecycle 138 | */ 139 | public void setAutoStartup(boolean autoStartup) { 140 | this.autoStartup = autoStartup; 141 | } 142 | 143 | /** 144 | * Sets the phase. 145 | * 146 | * @param phase the new phase 147 | * @see SmartLifecycle 148 | */ 149 | public void setPhase(int phase) { 150 | this.phase = phase; 151 | } 152 | 153 | /** 154 | * Subclasses may override this method with the start behaviour. This method will be invoked while holding the 155 | * {@link #lifecycleLock}. 156 | */ 157 | protected void doStart() { 158 | }; 159 | 160 | /** 161 | * Subclasses may override this method with the stop behaviour. This method will be invoked while holding the 162 | * {@link #lifecycleLock}. 163 | */ 164 | protected void doStop() { 165 | }; 166 | 167 | /** 168 | * Subclasses need to implement this method to handle {@link Message} in its writer. 169 | * 170 | * @param message the message to write 171 | */ 172 | protected abstract void doWrite(Message message) throws Exception; 173 | 174 | } 175 | -------------------------------------------------------------------------------- /spring-cloud-starter-stream-sink-gpfdist/src/main/java/org/springframework/cloud/stream/app/gpfdist/sink/support/JdbcCommands.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.springframework.cloud.stream.app.gpfdist.sink.support; 18 | 19 | import org.apache.commons.logging.Log; 20 | import org.apache.commons.logging.LogFactory; 21 | import org.springframework.dao.DataAccessException; 22 | import org.springframework.jdbc.core.JdbcTemplate; 23 | import org.springframework.util.StringUtils; 24 | 25 | import java.util.List; 26 | 27 | /** 28 | * Utility class helping to execute jdbc operations within a load session. 29 | * Provides a way to prepare, run and clean a main load command. Additionally 30 | * it can use a list of before and after commands which are execute before and after 31 | * of a main command. Clean command is executed last even if some of the other 32 | * commands fail. 33 | * 34 | * @author Janne Valkealahti 35 | * 36 | */ 37 | public class JdbcCommands { 38 | 39 | private static final Log log = LogFactory.getLog(JdbcCommands.class); 40 | 41 | private JdbcTemplate jdbcTemplate; 42 | 43 | private List beforeSqls; 44 | 45 | private List afterSqls; 46 | 47 | private String prepareSql; 48 | 49 | private String runSql; 50 | 51 | private String cleanSql; 52 | 53 | private DataAccessException lastException; 54 | 55 | public JdbcCommands(JdbcTemplate jdbcTemplate) { 56 | this.jdbcTemplate = jdbcTemplate; 57 | } 58 | 59 | public void setJdbcTemplate(JdbcTemplate jdbcTemplate) { 60 | this.jdbcTemplate = jdbcTemplate; 61 | } 62 | 63 | public void setPrepareSql(String sql) { 64 | this.prepareSql = sql; 65 | } 66 | 67 | public void setRunSql(String sql) { 68 | this.runSql = sql; 69 | } 70 | 71 | public void setCleanSql(String sql) { 72 | this.cleanSql = sql; 73 | } 74 | 75 | public void setBeforeSqls(List beforeSqls) { 76 | this.beforeSqls = beforeSqls; 77 | } 78 | 79 | public void setAfterSqls(List afterSqls) { 80 | this.afterSqls = afterSqls; 81 | } 82 | 83 | public boolean execute() { 84 | boolean succeed = true; 85 | 86 | try { 87 | succeed = prepare(); 88 | if (succeed) { 89 | succeed = before(); 90 | } 91 | if (succeed) { 92 | succeed = run(); 93 | } 94 | if (succeed) { 95 | succeed = after(); 96 | } 97 | } 98 | catch (Exception e) { 99 | } 100 | finally { 101 | try { 102 | clean(); 103 | } 104 | catch (Exception e2) { 105 | } 106 | } 107 | return succeed; 108 | } 109 | 110 | public DataAccessException getLastException() { 111 | return lastException; 112 | } 113 | 114 | private boolean prepare() { 115 | try { 116 | if (log.isDebugEnabled()) { 117 | log.debug("Executing prepare: " + prepareSql); 118 | } 119 | jdbcTemplate.execute(prepareSql); 120 | } 121 | catch (DataAccessException e) { 122 | log.error("Error during prepare sql", e); 123 | lastException = e; 124 | return false; 125 | } 126 | return true; 127 | } 128 | 129 | private boolean run() { 130 | try { 131 | if (log.isDebugEnabled()) { 132 | log.debug("Executing run: " + runSql); 133 | } 134 | jdbcTemplate.execute(runSql); 135 | } 136 | catch (DataAccessException e) { 137 | log.error("Error during run sql", e); 138 | lastException = e; 139 | return false; 140 | } 141 | return true; 142 | } 143 | 144 | private boolean clean() { 145 | try { 146 | if (log.isDebugEnabled()) { 147 | log.debug("Executing clean: " + cleanSql); 148 | } 149 | jdbcTemplate.execute(cleanSql); 150 | } 151 | catch (DataAccessException e) { 152 | log.error("Error during clean sql", e); 153 | lastException = e; 154 | return false; 155 | } 156 | return true; 157 | } 158 | 159 | private boolean before() { 160 | if (beforeSqls != null) { 161 | for (String sql : beforeSqls) { 162 | if (!StringUtils.hasText(sql)) { 163 | continue; 164 | } 165 | if (log.isDebugEnabled()) { 166 | log.debug("Executing before: " + sql); 167 | } 168 | try { 169 | jdbcTemplate.execute(sql); 170 | } 171 | catch (DataAccessException e) { 172 | lastException = e; 173 | return false; 174 | } 175 | } 176 | } 177 | return true; 178 | } 179 | 180 | private boolean after() { 181 | if (afterSqls != null) { 182 | for (String sql : afterSqls) { 183 | if (!StringUtils.hasText(sql)) { 184 | continue; 185 | } 186 | if (log.isDebugEnabled()) { 187 | log.debug("Executing after: " + sql); 188 | } 189 | try { 190 | jdbcTemplate.execute(sql); 191 | } 192 | catch (DataAccessException e) { 193 | lastException = e; 194 | return false; 195 | } 196 | } 197 | } 198 | return true; 199 | } 200 | 201 | } 202 | -------------------------------------------------------------------------------- /spring-cloud-starter-stream-sink-gpfdist/src/main/java/org/springframework/cloud/stream/app/gpfdist/sink/support/LoadConfigurationFactoryBean.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.springframework.cloud.stream.app.gpfdist.sink.support; 18 | 19 | import org.springframework.beans.factory.FactoryBean; 20 | import org.springframework.beans.factory.InitializingBean; 21 | import org.springframework.cloud.stream.app.gpfdist.sink.support.ControlFile.OutputMode; 22 | import org.springframework.util.StringUtils; 23 | 24 | import java.util.Arrays; 25 | import java.util.List; 26 | 27 | /** 28 | * {@link FactoryBean} creating instances of a {@link LoadConfiguration}. 29 | * 30 | * @author Janne Valkealahti 31 | */ 32 | public class LoadConfigurationFactoryBean implements FactoryBean, InitializingBean { 33 | 34 | private ControlFile controlFile; 35 | 36 | private String table; 37 | 38 | private String columns; 39 | 40 | private ReadableTable externalTable; 41 | 42 | private Mode mode = Mode.INSERT; 43 | 44 | private List matchColumns; 45 | 46 | private List updateColumns; 47 | 48 | private String updateCondition; 49 | 50 | private List sqlBefore; 51 | 52 | private List sqlAfter; 53 | 54 | @Override 55 | public void afterPropertiesSet() throws Exception { 56 | if (controlFile != null) { 57 | if (controlFile.getGploadOutputMode() != null) { 58 | if (controlFile.getGploadOutputMode() == OutputMode.INSERT) { 59 | mode = Mode.INSERT; 60 | } 61 | else if (controlFile.getGploadOutputMode() == OutputMode.UPDATE) { 62 | mode = Mode.UPDATE; 63 | } 64 | } 65 | if (StringUtils.hasText(controlFile.getGploadOutputTable())) { 66 | table = controlFile.getGploadOutputTable(); 67 | } 68 | if (controlFile.getGploadOutputMatchColumns() != null) { 69 | matchColumns = controlFile.getGploadOutputMatchColumns(); 70 | } 71 | if (controlFile.getGploadOutputUpdateColumns() != null) { 72 | updateColumns = controlFile.getGploadOutputUpdateColumns(); 73 | } 74 | if (StringUtils.hasText(controlFile.getGploadOutputUpdateCondition())) { 75 | updateCondition = controlFile.getGploadOutputUpdateCondition(); 76 | } 77 | if (!controlFile.getGploadSqlBefore().isEmpty()) { 78 | sqlBefore = controlFile.getGploadSqlBefore(); 79 | } 80 | if (!controlFile.getGploadSqlAfter().isEmpty()) { 81 | sqlAfter = controlFile.getGploadSqlAfter(); 82 | } 83 | } 84 | } 85 | 86 | @Override 87 | public LoadConfiguration getObject() throws Exception { 88 | LoadConfiguration loadConfiguration = new LoadConfiguration(table, columns, externalTable, mode, matchColumns, 89 | updateColumns, updateCondition); 90 | loadConfiguration.setSqlBefore(sqlBefore); 91 | loadConfiguration.setSqlAfter(sqlAfter); 92 | return loadConfiguration; 93 | } 94 | 95 | @Override 96 | public Class getObjectType() { 97 | return LoadConfiguration.class; 98 | } 99 | 100 | @Override 101 | public boolean isSingleton() { 102 | return false; 103 | } 104 | 105 | public void setControlFile(ControlFile controlFile) { 106 | this.controlFile = controlFile; 107 | } 108 | 109 | public String getTable() { 110 | return table; 111 | } 112 | 113 | public void setTable(String table) { 114 | this.table = table; 115 | } 116 | 117 | public String getColumns() { 118 | return columns; 119 | } 120 | 121 | public void setColumns(String columns) { 122 | this.columns = columns; 123 | } 124 | 125 | public ReadableTable getExternalTable() { 126 | return externalTable; 127 | } 128 | 129 | public void setExternalTable(ReadableTable externalTable) { 130 | this.externalTable = externalTable; 131 | } 132 | 133 | public Mode getMode() { 134 | return mode; 135 | } 136 | 137 | public void setMode(Mode mode) { 138 | this.mode = mode; 139 | } 140 | 141 | public List getMatchColumns() { 142 | return matchColumns; 143 | } 144 | 145 | public void setMatchColumns(String[] matchColumns) { 146 | this.matchColumns = Arrays.asList(matchColumns); 147 | } 148 | 149 | public List getUpdateColumns() { 150 | return updateColumns; 151 | } 152 | 153 | public void setUpdateColumns(String[] updateColumns) { 154 | this.updateColumns = Arrays.asList(updateColumns); 155 | } 156 | 157 | public String getUpdateCondition() { 158 | return updateCondition; 159 | } 160 | 161 | public void setUpdateCondition(String updateCondition) { 162 | this.updateCondition = updateCondition; 163 | } 164 | 165 | public List getSqlBefore() { 166 | return sqlBefore; 167 | } 168 | 169 | public void setSqlBefore(List sqlBefore) { 170 | this.sqlBefore = sqlBefore; 171 | } 172 | 173 | public List getSqlAfter() { 174 | return sqlAfter; 175 | } 176 | 177 | public void setSqlAfter(List sqlAfter) { 178 | this.sqlAfter = sqlAfter; 179 | } 180 | 181 | } 182 | -------------------------------------------------------------------------------- /mvnw.cmd: -------------------------------------------------------------------------------- 1 | @REM ---------------------------------------------------------------------------- 2 | @REM Licensed to the Apache Software Foundation (ASF) under one 3 | @REM or more contributor license agreements. See the NOTICE file 4 | @REM distributed with this work for additional information 5 | @REM regarding copyright ownership. The ASF licenses this file 6 | @REM to you under the Apache License, Version 2.0 (the 7 | @REM "License"); you may not use this file except in compliance 8 | @REM with the License. You may obtain a copy of the License at 9 | @REM 10 | @REM https://www.apache.org/licenses/LICENSE-2.0 11 | @REM 12 | @REM Unless required by applicable law or agreed to in writing, 13 | @REM software distributed under the License is distributed on an 14 | @REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | @REM KIND, either express or implied. See the License for the 16 | @REM specific language governing permissions and limitations 17 | @REM under the License. 18 | @REM ---------------------------------------------------------------------------- 19 | 20 | @REM ---------------------------------------------------------------------------- 21 | @REM Maven2 Start Up Batch script 22 | @REM 23 | @REM Required ENV vars: 24 | @REM JAVA_HOME - location of a JDK home dir 25 | @REM 26 | @REM Optional ENV vars 27 | @REM M2_HOME - location of maven2's installed home dir 28 | @REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands 29 | @REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending 30 | @REM MAVEN_OPTS - parameters passed to the Java VM when running Maven 31 | @REM e.g. to debug Maven itself, use 32 | @REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 33 | @REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files 34 | @REM ---------------------------------------------------------------------------- 35 | 36 | @REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' 37 | @echo off 38 | @REM enable echoing my setting MAVEN_BATCH_ECHO to 'on' 39 | @if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% 40 | 41 | @REM set %HOME% to equivalent of $HOME 42 | if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") 43 | 44 | @REM Execute a user defined script before this one 45 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre 46 | @REM check for pre script, once with legacy .bat ending and once with .cmd ending 47 | if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" 48 | if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" 49 | :skipRcPre 50 | 51 | @setlocal 52 | 53 | set ERROR_CODE=0 54 | 55 | @REM To isolate internal variables from possible post scripts, we use another setlocal 56 | @setlocal 57 | 58 | @REM ==== START VALIDATION ==== 59 | if not "%JAVA_HOME%" == "" goto OkJHome 60 | 61 | echo. 62 | echo Error: JAVA_HOME not found in your environment. >&2 63 | echo Please set the JAVA_HOME variable in your environment to match the >&2 64 | echo location of your Java installation. >&2 65 | echo. 66 | goto error 67 | 68 | :OkJHome 69 | if exist "%JAVA_HOME%\bin\java.exe" goto init 70 | 71 | echo. 72 | echo Error: JAVA_HOME is set to an invalid directory. >&2 73 | echo JAVA_HOME = "%JAVA_HOME%" >&2 74 | echo Please set the JAVA_HOME variable in your environment to match the >&2 75 | echo location of your Java installation. >&2 76 | echo. 77 | goto error 78 | 79 | @REM ==== END VALIDATION ==== 80 | 81 | :init 82 | 83 | set MAVEN_CMD_LINE_ARGS=%* 84 | 85 | @REM Find the project base dir, i.e. the directory that contains the folder ".mvn". 86 | @REM Fallback to current working directory if not found. 87 | 88 | set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% 89 | IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir 90 | 91 | set EXEC_DIR=%CD% 92 | set WDIR=%EXEC_DIR% 93 | :findBaseDir 94 | IF EXIST "%WDIR%"\.mvn goto baseDirFound 95 | cd .. 96 | IF "%WDIR%"=="%CD%" goto baseDirNotFound 97 | set WDIR=%CD% 98 | goto findBaseDir 99 | 100 | :baseDirFound 101 | set MAVEN_PROJECTBASEDIR=%WDIR% 102 | cd "%EXEC_DIR%" 103 | goto endDetectBaseDir 104 | 105 | :baseDirNotFound 106 | set MAVEN_PROJECTBASEDIR=%EXEC_DIR% 107 | cd "%EXEC_DIR%" 108 | 109 | :endDetectBaseDir 110 | 111 | IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig 112 | 113 | @setlocal EnableExtensions EnableDelayedExpansion 114 | for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a 115 | @endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% 116 | 117 | :endReadAdditionalConfig 118 | 119 | SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" 120 | 121 | set WRAPPER_JAR="".\.mvn\wrapper\maven-wrapper.jar"" 122 | set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 123 | 124 | %MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CMD_LINE_ARGS% 125 | if ERRORLEVEL 1 goto error 126 | goto end 127 | 128 | :error 129 | set ERROR_CODE=1 130 | 131 | :end 132 | @endlocal & set ERROR_CODE=%ERROR_CODE% 133 | 134 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost 135 | @REM check for post script, once with legacy .bat ending and once with .cmd ending 136 | if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" 137 | if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" 138 | :skipRcPost 139 | 140 | @REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' 141 | if "%MAVEN_BATCH_PAUSE%" == "on" pause 142 | 143 | if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% 144 | 145 | exit /B %ERROR_CODE% 146 | -------------------------------------------------------------------------------- /spring-cloud-starter-stream-sink-gpfdist/src/main/java/org/springframework/cloud/stream/app/gpfdist/sink/GpfdistServer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.springframework.cloud.stream.app.gpfdist.sink; 18 | 19 | import org.apache.commons.logging.Log; 20 | import org.apache.commons.logging.LogFactory; 21 | import org.reactivestreams.Processor; 22 | import org.reactivestreams.Publisher; 23 | import reactor.core.processor.RingBufferWorkProcessor; 24 | import reactor.fn.BiFunction; 25 | import reactor.fn.Function; 26 | import reactor.io.buffer.Buffer; 27 | import reactor.io.net.NetStreams; 28 | import reactor.io.net.ReactorChannelHandler; 29 | import reactor.io.net.Spec.HttpServerSpec; 30 | import reactor.io.net.http.HttpChannel; 31 | import reactor.io.net.http.HttpServer; 32 | import reactor.rx.Stream; 33 | import reactor.rx.Streams; 34 | 35 | import java.util.concurrent.TimeUnit; 36 | 37 | /** 38 | * Server implementation around reactor and netty providing endpoint 39 | * where data can be sent using a gpfdist protocol. 40 | * 41 | * @author Janne Valkealahti 42 | */ 43 | public class GpfdistServer { 44 | 45 | private final static Log log = LogFactory.getLog(GpfdistServer.class); 46 | 47 | private final Processor processor; 48 | private final int port; 49 | private final int flushCount; 50 | private final int flushTime; 51 | private final int batchTimeout; 52 | private final int batchCount; 53 | private HttpServer server; 54 | private int localPort = -1; 55 | 56 | /** 57 | * Instantiates a new gpfdist server. 58 | * 59 | * @param processor the processor 60 | * @param port the port 61 | * @param flushCount the flush count 62 | * @param flushTime the flush time 63 | * @param batchTimeout the batch timeout 64 | * @param batchCount the batch count 65 | */ 66 | public GpfdistServer(Processor processor, int port, int flushCount, int flushTime, 67 | int batchTimeout, int batchCount) { 68 | this.processor = processor; 69 | this.port = port; 70 | this.flushCount = flushCount; 71 | this.flushTime = flushTime; 72 | this.batchTimeout = batchTimeout; 73 | this.batchCount = batchCount; 74 | } 75 | 76 | /** 77 | * Start a server. 78 | * 79 | * @return the http server 80 | * @throws Exception the exception 81 | */ 82 | public synchronized HttpServer start() throws Exception { 83 | if (server == null) { 84 | server = createProtocolListener(); 85 | } 86 | return server; 87 | } 88 | 89 | /** 90 | * Stop a server. 91 | * 92 | * @throws Exception the exception 93 | */ 94 | public synchronized void stop() throws Exception { 95 | if (server != null) { 96 | server.shutdown().awaitSuccess(); 97 | } 98 | server = null; 99 | } 100 | 101 | /** 102 | * Gets the local port. 103 | * 104 | * @return the local port 105 | */ 106 | public int getLocalPort() { 107 | return localPort; 108 | } 109 | 110 | private HttpServer createProtocolListener() 111 | throws Exception { 112 | 113 | final Stream stream = Streams 114 | .wrap(processor) 115 | .window(flushCount, flushTime, TimeUnit.SECONDS) 116 | .flatMap(new Function, Publisher>() { 117 | 118 | @Override 119 | public Publisher apply(Stream t) { 120 | 121 | return t.reduce(new Buffer(), new BiFunction() { 122 | 123 | @Override 124 | public Buffer apply(Buffer prev, Buffer next) { 125 | return prev.append(next); 126 | } 127 | }); 128 | } 129 | }) 130 | .process(RingBufferWorkProcessor.create("gpfdist-sink-worker", 8192, false)); 131 | 132 | HttpServer httpServer = NetStreams 133 | .httpServer(new Function, HttpServerSpec>() { 134 | 135 | @Override 136 | public HttpServerSpec apply(HttpServerSpec server) { 137 | return server 138 | .codec(new GpfdistCodec()) 139 | .listen(port); 140 | } 141 | }); 142 | 143 | httpServer.get("/data", new ReactorChannelHandler>() { 144 | 145 | @Override 146 | public Publisher apply(HttpChannel request) { 147 | request.responseHeaders().removeTransferEncodingChunked(); 148 | request.addResponseHeader("Content-type", "text/plain"); 149 | request.addResponseHeader("Expires", "0"); 150 | request.addResponseHeader("X-GPFDIST-VERSION", "Spring Dataflow"); 151 | request.addResponseHeader("X-GP-PROTO", "1"); 152 | request.addResponseHeader("Cache-Control", "no-cache"); 153 | request.addResponseHeader("Connection", "close"); 154 | 155 | return request.writeWith(stream 156 | .take(batchCount) 157 | .timeout(batchTimeout, TimeUnit.SECONDS, Streams.empty()) 158 | .concatWith(Streams.just(Buffer.wrap(new byte[0])))) 159 | .capacity(1l); 160 | } 161 | }); 162 | 163 | httpServer.start().awaitSuccess(); 164 | log.info("Server running using address=[" + httpServer.getListenAddress() + "]"); 165 | localPort = httpServer.getListenAddress().getPort(); 166 | return httpServer; 167 | } 168 | } 169 | -------------------------------------------------------------------------------- /gpfdist-app-dependencies/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4.0.0 4 | org.springframework.cloud.stream.app 5 | gpfdist-app-dependencies 6 | 2.0.0.BUILD-SNAPSHOT 7 | pom 8 | gpfdist-app-dependencies 9 | Spring Cloud Stream Gpfdist App Dependencies 10 | 11 | 12 | spring-cloud-dependencies-parent 13 | org.springframework.cloud 14 | 2.0.0.BUILD-SNAPSHOT 15 | 16 | 17 | 18 | 19 | 2.0.8.RELEASE 20 | 3.0.2 21 | 4.0.27.Final 22 | 9.4-1201-jdbc41 23 | 1.4 24 | 4.3.5.RELEASE 25 | 2.4.0.RELEASE 26 | 27 | 28 | 29 | 30 | 31 | org.springframework.cloud.stream.app 32 | spring-cloud-starter-stream-sink-gpfdist 33 | 2.0.0.BUILD-SNAPSHOT 34 | 35 | 36 | io.projectreactor 37 | reactor-core 38 | ${reactor.version} 39 | 40 | 41 | io.projectreactor 42 | reactor-net 43 | ${reactor.version} 44 | 45 | 46 | com.codahale.metrics 47 | metrics-core 48 | ${codahale.version} 49 | 50 | 51 | commons-dbcp 52 | commons-dbcp 53 | ${commons-dbcp.version} 54 | 55 | 56 | org.springframework 57 | spring-jdbc 58 | ${spring-jdbc.version} 59 | 60 | 61 | io.netty 62 | netty-all 63 | ${netty.version} 64 | runtime 65 | 66 | 67 | org.postgresql 68 | postgresql 69 | ${postgresql.version} 70 | runtime 71 | 72 | 73 | org.springframework.data 74 | spring-data-hadoop-util 75 | ${spring-data-hadoop.version} 76 | 77 | 78 | org.apache.hadoop 79 | * 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | spring 88 | 89 | 90 | spring-snapshots 91 | Spring Snapshots 92 | https://repo.spring.io/libs-snapshot-local 93 | 94 | true 95 | 96 | 97 | 98 | spring-milestones 99 | Spring Milestones 100 | https://repo.spring.io/libs-milestone-local 101 | 102 | false 103 | 104 | 105 | 106 | spring-releases 107 | Spring Releases 108 | https://repo.spring.io/release 109 | 110 | false 111 | 112 | 113 | 114 | spring-libs-release 115 | Spring Libs Release 116 | https://repo.spring.io/libs-release 117 | 118 | false 119 | 120 | 121 | 122 | 123 | false 124 | 125 | spring-milestone-release 126 | Spring Milestone Release 127 | https://repo.spring.io/libs-milestone 128 | 129 | 130 | 131 | 132 | spring-snapshots 133 | Spring Snapshots 134 | https://repo.spring.io/libs-snapshot-local 135 | 136 | true 137 | 138 | 139 | 140 | spring-milestones 141 | Spring Milestones 142 | https://repo.spring.io/libs-milestone-local 143 | 144 | false 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | -------------------------------------------------------------------------------- /spring-cloud-starter-stream-sink-gpfdist/src/test/java/org/springframework/cloud/stream/app/gpfdist/sink/LoadIT.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.springframework.cloud.stream.app.gpfdist.sink; 18 | 19 | import org.junit.Test; 20 | import org.springframework.cloud.stream.app.gpfdist.sink.support.GreenplumLoad; 21 | import org.springframework.cloud.stream.app.gpfdist.sink.support.LoadConfigurationFactoryBean; 22 | import org.springframework.cloud.stream.app.gpfdist.sink.support.Mode; 23 | import org.springframework.cloud.stream.app.gpfdist.sink.support.ReadableTable; 24 | import org.springframework.context.annotation.Bean; 25 | import org.springframework.jdbc.core.JdbcTemplate; 26 | 27 | import java.util.ArrayList; 28 | import java.util.List; 29 | import java.util.Map; 30 | 31 | import static org.hamcrest.Matchers.*; 32 | import static org.junit.Assert.assertThat; 33 | 34 | public class LoadIT extends AbstractLoadTests { 35 | 36 | @Test 37 | public void testInsert() { 38 | context.register(Config1.class, CommonConfig.class); 39 | context.refresh(); 40 | JdbcTemplate template = context.getBean(JdbcTemplate.class); 41 | String drop = "DROP TABLE IF EXISTS AbstractLoadTests;"; 42 | String create = "CREATE TABLE AbstractLoadTests (data text);"; 43 | template.execute(drop); 44 | template.execute(create); 45 | 46 | List data = new ArrayList(); 47 | for (int i = 0; i < 10; i++) { 48 | data.add("DATA" + i + "\n"); 49 | } 50 | 51 | broadcastData(data); 52 | 53 | GreenplumLoad greenplumLoad = context.getBean(GreenplumLoad.class); 54 | greenplumLoad.load(); 55 | 56 | List> queryForList = template.queryForList("SELECT * from AbstractLoadTests;"); 57 | assertThat(queryForList, notNullValue()); 58 | assertThat(queryForList.size(), is(10)); 59 | List queryData = new ArrayList(); 60 | for (int i = 0; i < 10; i++) { 61 | queryData.add((String) queryForList.get(i).get("data")); 62 | } 63 | assertThat( 64 | queryData, 65 | containsInAnyOrder("DATA0", "DATA1", "DATA2", "DATA3", "DATA4", "DATA5", "DATA6", "DATA7", "DATA8", 66 | "DATA9")); 67 | } 68 | 69 | @Test 70 | public void testUpdate() { 71 | context.register(Config2.class, CommonConfig.class); 72 | context.refresh(); 73 | JdbcTemplate template = context.getBean(JdbcTemplate.class); 74 | String drop = "DROP TABLE IF EXISTS AbstractLoadTests;"; 75 | String create = "CREATE TABLE AbstractLoadTests (col1 text, col2 text);"; 76 | template.execute(drop); 77 | template.execute(create); 78 | 79 | List data = new ArrayList(); 80 | for (int i = 0; i < 10; i++) { 81 | template.execute("insert into AbstractLoadTests values('DATA" + i + "', 'DATA');"); 82 | data.add("DATA" + i + "\tDATA" + i + "\n"); 83 | } 84 | 85 | broadcastData(data); 86 | 87 | GreenplumLoad greenplumLoad = context.getBean(GreenplumLoad.class); 88 | greenplumLoad.load(); 89 | 90 | List> queryForList = template.queryForList("SELECT * from AbstractLoadTests;"); 91 | assertThat(queryForList, notNullValue()); 92 | assertThat(queryForList.size(), is(10)); 93 | for (int i = 0; i < 10; i++) { 94 | assertThat(queryForList.get(i).get("col2"), is(queryForList.get(i).get("col1"))); 95 | } 96 | } 97 | 98 | @Test 99 | public void testUpdateMultiColumns() { 100 | context.register(Config3.class, CommonConfig.class); 101 | context.refresh(); 102 | JdbcTemplate template = context.getBean(JdbcTemplate.class); 103 | String drop = "DROP TABLE IF EXISTS AbstractLoadTests;"; 104 | String create = "CREATE TABLE AbstractLoadTests (col1 text, col2 text, col3 text);"; 105 | template.execute(drop); 106 | template.execute(create); 107 | 108 | List data = new ArrayList(); 109 | for (int i = 0; i < 10; i++) { 110 | template.execute("insert into AbstractLoadTests values('DATA" + i + "', 'DATA', 'DATA');"); 111 | data.add("DATA" + i + "\tDATA" + i + "\tDATA" + i + "\n"); 112 | } 113 | 114 | broadcastData(data); 115 | 116 | GreenplumLoad greenplumLoad = context.getBean(GreenplumLoad.class); 117 | greenplumLoad.load(); 118 | 119 | List> queryForList = template.queryForList("SELECT * from AbstractLoadTests;"); 120 | assertThat(queryForList, notNullValue()); 121 | assertThat(queryForList.size(), is(10)); 122 | for (int i = 0; i < 10; i++) { 123 | assertThat(queryForList.get(i).get("col2"), is(queryForList.get(i).get("col1"))); 124 | assertThat(queryForList.get(i).get("col3"), is(queryForList.get(i).get("col1"))); 125 | } 126 | } 127 | 128 | static class Config1 { 129 | 130 | @Bean 131 | public LoadConfigurationFactoryBean greenplumLoadConfiguration(ReadableTable externalTable) { 132 | LoadConfigurationFactoryBean factory = new LoadConfigurationFactoryBean(); 133 | factory.setTable("AbstractLoadTests"); 134 | factory.setExternalTable(externalTable); 135 | factory.setMode(Mode.INSERT); 136 | return factory; 137 | } 138 | 139 | } 140 | 141 | static class Config2 { 142 | 143 | @Bean 144 | public LoadConfigurationFactoryBean greenplumLoadConfiguration(ReadableTable externalTable) { 145 | LoadConfigurationFactoryBean factory = new LoadConfigurationFactoryBean(); 146 | factory.setTable("AbstractLoadTests"); 147 | factory.setExternalTable(externalTable); 148 | factory.setMode(Mode.UPDATE); 149 | factory.setUpdateColumns(new String[] { "col2" }); 150 | factory.setMatchColumns(new String[] { "col1" }); 151 | return factory; 152 | } 153 | 154 | } 155 | 156 | static class Config3 { 157 | 158 | @Bean 159 | public LoadConfigurationFactoryBean greenplumLoadConfiguration(ReadableTable externalTable) { 160 | LoadConfigurationFactoryBean factory = new LoadConfigurationFactoryBean(); 161 | factory.setTable("AbstractLoadTests"); 162 | factory.setExternalTable(externalTable); 163 | factory.setMode(Mode.UPDATE); 164 | factory.setUpdateColumns(new String[] { "col2", "col3" }); 165 | factory.setMatchColumns(new String[] { "col1" }); 166 | return factory; 167 | } 168 | 169 | } 170 | 171 | } 172 | -------------------------------------------------------------------------------- /spring-cloud-starter-stream-sink-gpfdist/src/main/java/org/springframework/cloud/stream/app/gpfdist/sink/GpfdistSinkConfiguration.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.springframework.cloud.stream.app.gpfdist.sink; 18 | 19 | import org.springframework.beans.factory.annotation.Autowired; 20 | import org.springframework.boot.context.properties.EnableConfigurationProperties; 21 | import org.springframework.cloud.stream.annotation.EnableBinding; 22 | import org.springframework.cloud.stream.app.gpfdist.sink.support.*; 23 | import org.springframework.cloud.stream.messaging.Sink; 24 | import org.springframework.context.annotation.Bean; 25 | import org.springframework.context.annotation.Configuration; 26 | import org.springframework.data.hadoop.util.net.DefaultHostInfoDiscovery; 27 | import org.springframework.data.hadoop.util.net.HostInfoDiscovery; 28 | import org.springframework.data.hadoop.util.net.HostInfoDiscovery.HostInfo; 29 | import org.springframework.integration.annotation.ServiceActivator; 30 | import org.springframework.scheduling.TaskScheduler; 31 | import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; 32 | import org.springframework.util.StringUtils; 33 | 34 | import javax.sql.DataSource; 35 | import java.util.ArrayList; 36 | import java.util.Arrays; 37 | 38 | /** 39 | * Configuration for all beans needed for gpfdist sink. 40 | * 41 | * @author Janne Valkealahti 42 | */ 43 | @Configuration 44 | @EnableConfigurationProperties({ GpfdistSinkProperties.class, HostInfoDiscoveryProperties.class }) 45 | @EnableBinding(Sink.class) 46 | public class GpfdistSinkConfiguration { 47 | 48 | @Autowired 49 | private GpfdistSinkProperties properties; 50 | 51 | @Autowired 52 | private HostInfoDiscoveryProperties discoveryProperties; 53 | 54 | @Bean 55 | public HostInfoDiscovery hostInfoDiscovery() { 56 | DefaultHostInfoDiscovery discovery = new DefaultHostInfoDiscovery(); 57 | if (StringUtils.hasText(discoveryProperties.getMatchIpv4())) { 58 | discovery.setMatchIpv4(discoveryProperties.getMatchIpv4()); 59 | } 60 | if (StringUtils.hasText(discoveryProperties.getMatchInterface())) { 61 | discovery.setMatchInterface(discoveryProperties.getMatchInterface()); 62 | } 63 | if (discoveryProperties.getPreferInterface() != null) { 64 | discovery.setPreferInterface(discoveryProperties.getPreferInterface()); 65 | } 66 | discovery.setLoopback(discoveryProperties.isLoopback()); 67 | discovery.setPointToPoint(discoveryProperties.isPointToPoint()); 68 | return discovery; 69 | } 70 | 71 | @Bean 72 | public TaskScheduler sqlTaskScheduler() { 73 | ThreadPoolTaskScheduler taskScheduler = new ThreadPoolTaskScheduler(); 74 | taskScheduler.setWaitForTasksToCompleteOnShutdown(true); 75 | taskScheduler.setAwaitTerminationSeconds(properties.getBatchTimeout()); 76 | return taskScheduler; 77 | } 78 | 79 | @Bean 80 | public ControlFileFactoryBean greenplumControlFile() { 81 | ControlFileFactoryBean factoryBean = new ControlFileFactoryBean(); 82 | factoryBean.setControlFileResource(properties.getControlFile()); 83 | return factoryBean; 84 | } 85 | 86 | @Bean 87 | public GreenplumDataSourceFactoryBean dataSource(ControlFile controlFile) { 88 | GreenplumDataSourceFactoryBean factoryBean = new GreenplumDataSourceFactoryBean(); 89 | factoryBean.setControlFile(controlFile); 90 | factoryBean.setDbHost(properties.getDbHost()); 91 | factoryBean.setDbName(properties.getDbName()); 92 | factoryBean.setDbUser(properties.getDbUser()); 93 | factoryBean.setDbPassword(properties.getDbPassword()); 94 | factoryBean.setDbPort(properties.getDbPort()); 95 | return factoryBean; 96 | } 97 | 98 | @Bean 99 | public ReadableTableFactoryBean greenplumReadableTable(ControlFile controlFile, HostInfoDiscovery hostInfoDiscovery) { 100 | ReadableTableFactoryBean factoryBean = new ReadableTableFactoryBean(); 101 | factoryBean.setControlFile(controlFile); 102 | factoryBean.setDelimiter(properties.getColumnDelimiter()); 103 | factoryBean.setLogErrors(properties.isLogErrors()); 104 | factoryBean.setSegmentReject(properties.getSegmentRejectLimit()); 105 | factoryBean.setSegmentRejectType(properties.getSegmentRejectType()); 106 | factoryBean.setNullString(properties.getNullString()); 107 | HostInfo hostInfo = hostInfoDiscovery.getHostInfo(); 108 | factoryBean.setLocations(Arrays.asList(NetworkUtils.getGPFDistUri(hostInfo.getAddress(), properties.getGpfdistPort()))); 109 | return factoryBean; 110 | } 111 | 112 | @Bean 113 | public LoadConfigurationFactoryBean greenplumLoadConfiguration(ReadableTable externalTable, ControlFile controlFile) { 114 | LoadConfigurationFactoryBean factoryBean = new LoadConfigurationFactoryBean(); 115 | factoryBean.setExternalTable(externalTable); 116 | factoryBean.setControlFile(controlFile); 117 | factoryBean.setMode(StringUtils.hasText(properties.getMode()) ? Mode.valueOf(properties.getMode().toUpperCase()) : Mode.INSERT); 118 | factoryBean.setUpdateColumns(StringUtils.commaDelimitedListToStringArray(properties.getUpdateColumns())); 119 | factoryBean.setMatchColumns(StringUtils.commaDelimitedListToStringArray(properties.getMatchColumns())); 120 | factoryBean.setTable(properties.getTable()); 121 | factoryBean.setSqlBefore(StringUtils.hasText(properties.getSqlBefore()) ? Arrays.asList(properties.getSqlBefore()) : new ArrayList()); 122 | factoryBean.setSqlAfter(StringUtils.hasText(properties.getSqlAfter()) ? Arrays.asList(properties.getSqlAfter()) : new ArrayList()); 123 | return factoryBean; 124 | } 125 | 126 | @Bean 127 | public LoadFactoryBean greenplumLoad(LoadConfiguration loadConfiguration, DataSource dataSource) { 128 | LoadFactoryBean factoryBean = new LoadFactoryBean(); 129 | factoryBean.setLoadConfiguration(loadConfiguration); 130 | factoryBean.setDataSource(dataSource); 131 | return factoryBean; 132 | } 133 | 134 | @Bean 135 | @ServiceActivator(inputChannel= Sink.INPUT) 136 | public GpfdistMessageHandler gpfdist(GreenplumLoad greenplumLoad, TaskScheduler sqlTaskScheduler, HostInfoDiscovery hostInfoDiscovery) { 137 | GpfdistMessageHandler handler = new GpfdistMessageHandler(properties.getGpfdistPort(), properties.getFlushCount(), 138 | properties.getFlushTime(), properties.getBatchTimeout(), properties.getBatchCount(), properties.getBatchPeriod(), 139 | properties.getDelimiter(), hostInfoDiscovery); 140 | handler.setRateInterval(properties.getRateInterval()); 141 | handler.setGreenplumLoad(greenplumLoad); 142 | handler.setSqlTaskScheduler(sqlTaskScheduler); 143 | return handler; 144 | } 145 | } 146 | -------------------------------------------------------------------------------- /spring-cloud-starter-stream-sink-gpfdist/src/main/java/org/springframework/cloud/stream/app/gpfdist/sink/support/ControlFileFactoryBean.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.springframework.cloud.stream.app.gpfdist.sink.support; 18 | 19 | import org.springframework.beans.factory.FactoryBean; 20 | import org.springframework.beans.factory.InitializingBean; 21 | import org.springframework.beans.factory.config.YamlMapFactoryBean; 22 | import org.springframework.cloud.stream.app.gpfdist.sink.support.ControlFile.OutputMode; 23 | import org.springframework.core.io.Resource; 24 | 25 | import java.util.List; 26 | import java.util.Map; 27 | import java.util.Map.Entry; 28 | 29 | public class ControlFileFactoryBean implements FactoryBean, InitializingBean { 30 | 31 | private ControlFile controlFile; 32 | 33 | private Resource controlFileResource; 34 | 35 | @Override 36 | public void afterPropertiesSet() throws Exception { 37 | if (controlFileResource != null) { 38 | controlFile = parseYaml(); 39 | } 40 | else { 41 | controlFile = new ControlFile(); 42 | } 43 | } 44 | 45 | @Override 46 | public ControlFile getObject() throws Exception { 47 | return controlFile; 48 | } 49 | 50 | @Override 51 | public Class getObjectType() { 52 | return ControlFile.class; 53 | } 54 | 55 | @Override 56 | public boolean isSingleton() { 57 | return true; 58 | } 59 | 60 | public void setControlFileResource(Resource controlFileResource) { 61 | this.controlFileResource = controlFileResource; 62 | } 63 | 64 | @SuppressWarnings({ "unchecked" }) 65 | private ControlFile parseYaml() { 66 | ControlFile cf = new ControlFile(); 67 | YamlMapFactoryBean factory = new YamlMapFactoryBean(); 68 | factory.setResources(controlFileResource); 69 | Map yaml = factory.getObject(); 70 | 71 | // main map 72 | for (Entry e0 : yaml.entrySet()) { 73 | if (e0.getKey().toLowerCase().equals("gpload")) { 74 | if (e0.getValue() instanceof Map) { 75 | Map gploadMap = (Map) e0.getValue(); 76 | 77 | // GPLOAD map 78 | for (Entry e1 : gploadMap.entrySet()) { 79 | if (e1.getKey().toLowerCase().equals("output")) { 80 | 81 | // GPLOAD.OUTPUT list 82 | if (e1.getValue() instanceof List) { 83 | for (Object v : (List) e1.getValue()) { 84 | if (v instanceof Map) { 85 | Map tableMap = (Map) v; 86 | for (Entry e2 : tableMap.entrySet()) { 87 | if (e2.getKey().toLowerCase().equals("table")) { 88 | if (e2.getValue() instanceof String) { 89 | cf.setGploadOutputTable((String) e2.getValue()); 90 | } 91 | } 92 | else if (e2.getKey().toLowerCase().equals("mode")) { 93 | if (e2.getValue() instanceof String) { 94 | cf.setGploadOutputMode(OutputMode.valueOf(((String) e2.getValue()).toUpperCase())); 95 | } 96 | } 97 | else if (e2.getKey().toLowerCase().equals("match_columns")) { 98 | if (e2.getValue() instanceof List) { 99 | cf.setGploadOutputMatchColumns(((List) e2.getValue())); 100 | } 101 | } 102 | else if (e2.getKey().toLowerCase().equals("update_columns")) { 103 | if (e2.getValue() instanceof List) { 104 | cf.setGploadOutputUpdateColumns(((List) e2.getValue())); 105 | } 106 | } 107 | else if (e2.getKey().toLowerCase().equals("update_condition")) { 108 | if (e2.getValue() instanceof String) { 109 | cf.setGploadOutputUpdateCondition((String) e2.getValue()); 110 | } 111 | } 112 | } 113 | 114 | } 115 | } 116 | } 117 | } 118 | else if (e1.getKey().toLowerCase().equals("input")) { 119 | if (e1.getValue() instanceof List) { 120 | for (Object v : (List) e1.getValue()) { 121 | if (v instanceof Map) { 122 | Map tableMap = (Map) v; 123 | for (Entry e2 : tableMap.entrySet()) { 124 | if (e2.getKey().toLowerCase().equals("delimiter")) { 125 | if (e2.getValue() instanceof Character) { 126 | cf.setGploadInputDelimiter((Character) e2.getValue()); 127 | } 128 | else if (e2.getValue() instanceof String) { 129 | if (((String) e2.getValue()).length() == 1) { 130 | cf.setGploadInputDelimiter(((String) e2.getValue()).charAt(0)); 131 | } 132 | } 133 | } 134 | } 135 | } 136 | } 137 | } 138 | } 139 | else if (e1.getKey().toLowerCase().equals("sql")) { 140 | if (e1.getValue() instanceof List) { 141 | for (Object v : (List) e1.getValue()) { 142 | if (v instanceof Map) { 143 | Map sqlMap = (Map) v; 144 | for (Entry e2 : sqlMap.entrySet()) { 145 | if (e2.getKey().toLowerCase().equals("before")) { 146 | if (e2.getValue() instanceof String) { 147 | cf.addGploadSqlBefore((String) e2.getValue()); 148 | } 149 | } 150 | else if (e2.getKey().toLowerCase().equals("after")) { 151 | if (e2.getValue() instanceof String) { 152 | cf.addGploadSqlAfter((String) e2.getValue()); 153 | } 154 | } 155 | } 156 | } 157 | } 158 | } 159 | } 160 | } 161 | } 162 | } 163 | else if (e0.getKey().toLowerCase().equals("database")) { 164 | if (e0.getValue() instanceof String) { 165 | cf.setDatabase((String) e0.getValue()); 166 | } 167 | } 168 | else if (e0.getKey().toLowerCase().equals("user")) { 169 | if (e0.getValue() instanceof String) { 170 | cf.setUser((String) e0.getValue()); 171 | } 172 | } 173 | else if (e0.getKey().toLowerCase().equals("password")) { 174 | if (e0.getValue() instanceof String) { 175 | cf.setPassword((String) e0.getValue()); 176 | } 177 | } 178 | else if (e0.getKey().toLowerCase().equals("host")) { 179 | if (e0.getValue() instanceof String) { 180 | cf.setHost((String) e0.getValue()); 181 | } 182 | } 183 | else if (e0.getKey().toLowerCase().equals("port")) { 184 | if (e0.getValue() instanceof Integer) { 185 | cf.setPort((Integer) e0.getValue()); 186 | } 187 | } 188 | } 189 | return cf; 190 | } 191 | 192 | } 193 | -------------------------------------------------------------------------------- /spring-cloud-starter-stream-sink-gpfdist/src/main/java/org/springframework/cloud/stream/app/gpfdist/sink/support/ReadableTableFactoryBean.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.springframework.cloud.stream.app.gpfdist.sink.support; 18 | 19 | import org.springframework.beans.factory.FactoryBean; 20 | import org.springframework.beans.factory.InitializingBean; 21 | import org.springframework.util.StringUtils; 22 | 23 | import java.util.Arrays; 24 | import java.util.List; 25 | 26 | /** 27 | * {@link FactoryBean} creating instances of a {@link ReadableTable}. 28 | * 29 | * @author Janne Valkealahti 30 | * @author Gary Russell 31 | */ 32 | public class ReadableTableFactoryBean implements FactoryBean, InitializingBean { 33 | 34 | private ControlFile controlFile; 35 | private List locations; 36 | private String columns; 37 | private String like; 38 | private boolean keeptable; 39 | private Format format = Format.TEXT; 40 | private Character delimiter; 41 | private String nullString; 42 | private Character escape; 43 | private Character quote; 44 | private String[] forceQuote; 45 | private boolean logErrors; 46 | private Integer segmentRejectLimit; 47 | private SegmentRejectType segmentRejectType; 48 | 49 | @Override 50 | public void afterPropertiesSet() throws Exception { 51 | if (controlFile != null) { 52 | if (controlFile.getGploadInputDelimiter() != null) { 53 | this.delimiter = controlFile.getGploadInputDelimiter(); 54 | } 55 | } 56 | } 57 | 58 | @Override 59 | public ReadableTable getObject() throws Exception { 60 | ReadableTable w = new ReadableTable(); 61 | w.setLocations(locations); 62 | w.setColumns(columns); 63 | w.setLike(like); 64 | w.setLogErrors(logErrors); 65 | 66 | if (segmentRejectLimit != null && segmentRejectLimit > 0) { 67 | w.setSegmentRejectLimit(segmentRejectLimit); 68 | } 69 | w.setSegmentRejectType(segmentRejectType); 70 | 71 | if (format == Format.TEXT) { 72 | Character delim = delimiter != null ? delimiter : Character.valueOf('\t'); 73 | w.setTextFormat(delim, nullString, escape); 74 | } 75 | else if (format == Format.CSV) { 76 | Character delim = delimiter != null ? delimiter : Character.valueOf(','); 77 | w.setCsvFormat(quote, delim, nullString, forceQuote, escape); 78 | } 79 | 80 | return w; 81 | } 82 | 83 | @Override 84 | public Class getObjectType() { 85 | return ReadableTable.class; 86 | } 87 | 88 | @Override 89 | public boolean isSingleton() { 90 | return true; 91 | } 92 | 93 | public void setControlFile(ControlFile controlFile) { 94 | this.controlFile = controlFile; 95 | } 96 | 97 | /** 98 | * Gets the segment reject limit. 99 | * 100 | * @return the segment reject limit 101 | */ 102 | public Integer getSegmentRejectLimit() { 103 | return segmentRejectLimit; 104 | } 105 | 106 | /** 107 | * Sets the segment reject limit. 108 | * 109 | * @param segmentRejectLimit the new segment reject limit 110 | */ 111 | public void setSegmentRejectLimit(Integer segmentRejectLimit) { 112 | this.segmentRejectLimit = segmentRejectLimit; 113 | } 114 | 115 | /** 116 | * Gets the segment reject type. 117 | * 118 | * @return the segment reject type 119 | */ 120 | public SegmentRejectType getSegmentRejectType() { 121 | return segmentRejectType; 122 | } 123 | 124 | /** 125 | * Sets the segment reject as a string. This method is for convenience 126 | * to be able to set percent reject type just by calling with '3%' and 127 | * otherwise it uses rows. All this assuming that parsing finds '%' characher 128 | * and is able to parse a raw reject number. 129 | * 130 | * @param reject the new segment reject 131 | */ 132 | public void setSegmentReject(String reject) { 133 | if (!StringUtils.hasText(reject)) { 134 | return; 135 | } 136 | Integer parsedLimit = null; 137 | try { 138 | parsedLimit = Integer.parseInt(reject); 139 | segmentRejectType = SegmentRejectType.ROWS; 140 | } catch (NumberFormatException e) { 141 | } 142 | if (parsedLimit == null && reject.contains("%")) { 143 | try { 144 | parsedLimit = Integer.parseInt(reject.replace("%", "").trim()); 145 | segmentRejectType = SegmentRejectType.PERCENT; 146 | } catch (NumberFormatException e) { 147 | } 148 | } 149 | segmentRejectLimit = parsedLimit; 150 | } 151 | 152 | /** 153 | * Sets the segment reject type. 154 | * 155 | * @param segmentRejectType the new segment reject type 156 | */ 157 | public void setSegmentRejectType(SegmentRejectType segmentRejectType) { 158 | if (segmentRejectType != null) { 159 | this.segmentRejectType = segmentRejectType; 160 | } 161 | } 162 | 163 | /** 164 | * Gets if the errors are logged 165 | * 166 | * @return the if log errors is enabled 167 | */ 168 | public boolean isLogErrors() { 169 | return logErrors; 170 | } 171 | 172 | /** 173 | * Sets the if the errors should be logged. 174 | * 175 | * @param logErrors if true the errors are logged in internal tables 176 | */ 177 | public void setLogErrors(boolean logErrors) { 178 | this.logErrors = logErrors; 179 | } 180 | 181 | public Character getQuote() { 182 | return quote; 183 | } 184 | 185 | public void setQuote(Character quote) { 186 | this.quote = quote; 187 | } 188 | 189 | public String[] getForceQuote() { 190 | return forceQuote; 191 | } 192 | 193 | public void setForceQuote(String[] forceQuote) { 194 | this.forceQuote = Arrays.copyOf(forceQuote, forceQuote.length); 195 | } 196 | 197 | public Character getDelimiter() { 198 | return delimiter; 199 | } 200 | 201 | public void setDelimiter(Character delimiter) { 202 | this.delimiter = delimiter; 203 | } 204 | 205 | public String getNullString() { 206 | return nullString; 207 | } 208 | 209 | public void setNullString(String nullString) { 210 | this.nullString = nullString; 211 | } 212 | 213 | public Character getEscape() { 214 | return escape; 215 | } 216 | 217 | public void setEscape(Character escape) { 218 | this.escape = escape; 219 | } 220 | 221 | public List getLocations() { 222 | return locations; 223 | } 224 | 225 | public void setLocations(List locations) { 226 | this.locations = locations; 227 | } 228 | 229 | public String getColumns() { 230 | return columns; 231 | } 232 | 233 | public void setColumns(String columns) { 234 | this.columns = columns; 235 | } 236 | 237 | public String getLike() { 238 | return like; 239 | } 240 | 241 | public void setLike(String like) { 242 | this.like = like; 243 | } 244 | 245 | public boolean isKeeptable() { 246 | return keeptable; 247 | } 248 | 249 | public void setKeeptable(boolean keeptable) { 250 | this.keeptable = keeptable; 251 | } 252 | 253 | public Format getFormat() { 254 | return format; 255 | } 256 | 257 | public void setFormat(Format format) { 258 | this.format = format; 259 | } 260 | } 261 | -------------------------------------------------------------------------------- /spring-cloud-starter-stream-sink-gpfdist/src/main/java/org/springframework/cloud/stream/app/gpfdist/sink/GpfdistMessageHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.springframework.cloud.stream.app.gpfdist.sink; 18 | 19 | import com.codahale.metrics.Meter; 20 | import org.apache.commons.logging.Log; 21 | import org.apache.commons.logging.LogFactory; 22 | import org.reactivestreams.Processor; 23 | import org.springframework.cloud.stream.app.gpfdist.sink.support.GreenplumLoad; 24 | import org.springframework.cloud.stream.app.gpfdist.sink.support.NetworkUtils; 25 | import org.springframework.cloud.stream.app.gpfdist.sink.support.RuntimeContext; 26 | import org.springframework.data.hadoop.util.net.HostInfoDiscovery; 27 | import org.springframework.messaging.Message; 28 | import org.springframework.messaging.MessageHandlingException; 29 | import org.springframework.scheduling.TaskScheduler; 30 | import org.springframework.util.StringUtils; 31 | import org.springframework.util.concurrent.SettableListenableFuture; 32 | import reactor.Environment; 33 | import reactor.core.processor.RingBufferProcessor; 34 | import reactor.io.buffer.Buffer; 35 | 36 | import java.util.Date; 37 | import java.util.concurrent.FutureTask; 38 | import java.util.concurrent.TimeUnit; 39 | 40 | /** 41 | * Gpfdist related {@code MessageHandler}. 42 | * 43 | * @author Janne Valkealahti 44 | */ 45 | public class GpfdistMessageHandler extends AbstractGpfdistMessageHandler { 46 | 47 | private final Log log = LogFactory.getLog(GpfdistMessageHandler.class); 48 | 49 | private final int port; 50 | private final int flushCount; 51 | private final int flushTime; 52 | private final int batchTimeout; 53 | private final int batchCount; 54 | private final int batchPeriod; 55 | private final String delimiter; 56 | private GreenplumLoad greenplumLoad; 57 | private Processor processor; 58 | private GpfdistServer gpfdistServer; 59 | private TaskScheduler sqlTaskScheduler; 60 | private final TaskFuture taskFuture = new TaskFuture(); 61 | private int rateInterval = 0; 62 | private Meter meter = null; 63 | private int meterCount = 0; 64 | private final HostInfoDiscovery hostInfoDiscovery; 65 | 66 | /** 67 | * Instantiates a new gpfdist message handler. 68 | * 69 | * @param port the port 70 | * @param flushCount the flush count 71 | * @param flushTime the flush time 72 | * @param batchTimeout the batch timeout 73 | * @param batchCount the batch count 74 | * @param batchPeriod the batch period 75 | * @param delimiter the delimiter 76 | * @param hostInfoDiscovery the host info discovery 77 | */ 78 | public GpfdistMessageHandler(int port, int flushCount, int flushTime, int batchTimeout, int batchCount, 79 | int batchPeriod, String delimiter, HostInfoDiscovery hostInfoDiscovery) { 80 | super(); 81 | this.port = port; 82 | this.flushCount = flushCount; 83 | this.flushTime = flushTime; 84 | this.batchTimeout = batchTimeout; 85 | this.batchCount = batchCount; 86 | this.batchPeriod = batchPeriod; 87 | this.delimiter = StringUtils.hasLength(delimiter) ? delimiter : null; 88 | this.hostInfoDiscovery = hostInfoDiscovery; 89 | } 90 | 91 | @Override 92 | protected void doWrite(Message message) throws Exception { 93 | Object payload = message.getPayload(); 94 | if (payload instanceof String) { 95 | String data = (String)payload; 96 | if (delimiter != null) { 97 | processor.onNext(Buffer.wrap(data+delimiter)); 98 | } else { 99 | processor.onNext(Buffer.wrap(data)); 100 | } 101 | if (meter != null) { 102 | if ((meterCount++ % rateInterval) == 0) { 103 | meter.mark(rateInterval); 104 | log.info("METER: 1 minute rate = " + meter.getOneMinuteRate() + " mean rate = " + meter.getMeanRate()); 105 | } 106 | } 107 | } else { 108 | throw new MessageHandlingException(message, "message not a String"); 109 | } 110 | } 111 | 112 | @Override 113 | protected void onInit() throws Exception { 114 | super.onInit(); 115 | Environment.initializeIfEmpty().assignErrorJournal(); 116 | processor = RingBufferProcessor.create(false); 117 | } 118 | 119 | @Override 120 | protected void doStart() { 121 | try { 122 | log.info("Creating gpfdist protocol listener on port=" + port); 123 | gpfdistServer = new GpfdistServer(processor, port, flushCount, flushTime, batchTimeout, batchCount); 124 | gpfdistServer.start(); 125 | log.info("gpfdist protocol listener running on port=" + gpfdistServer.getLocalPort()); 126 | } catch (Exception e) { 127 | throw new RuntimeException("Error starting protocol listener", e); 128 | } 129 | 130 | if (greenplumLoad != null) { 131 | log.info("Scheduling gpload task with batchPeriod=" + batchPeriod); 132 | 133 | final RuntimeContext context = new RuntimeContext( 134 | NetworkUtils.getGPFDistUri(hostInfoDiscovery.getHostInfo().getAddress(), gpfdistServer.getLocalPort())); 135 | 136 | sqlTaskScheduler.schedule((new FutureTask(new Runnable() { 137 | @Override 138 | public void run() { 139 | boolean taskValue = true; 140 | try { 141 | while(!taskFuture.interrupted) { 142 | try { 143 | greenplumLoad.load(context); 144 | } catch (Exception e) { 145 | log.error("Error in load", e); 146 | } 147 | Thread.sleep(batchPeriod*1000); 148 | } 149 | } catch (Exception e) { 150 | taskValue = false; 151 | } 152 | taskFuture.set(taskValue); 153 | } 154 | }, null)), new Date()); 155 | 156 | } else { 157 | log.info("Skipping gpload tasks because greenplumLoad is not set"); 158 | } 159 | } 160 | 161 | @Override 162 | protected void doStop() { 163 | if (greenplumLoad != null) { 164 | taskFuture.interruptTask(); 165 | try { 166 | long now = System.currentTimeMillis(); 167 | // wait a bit more than batch period 168 | Boolean value = taskFuture.get(batchTimeout + batchPeriod + 2, TimeUnit.SECONDS); 169 | log.info("Stopping, got future value " + value + " from task which took " 170 | + (System.currentTimeMillis() - now) + "ms"); 171 | } catch (Exception e) { 172 | log.warn("Got error from task wait value which may indicate trouble", e); 173 | } 174 | } 175 | 176 | try { 177 | processor.onComplete(); 178 | gpfdistServer.stop(); 179 | } catch (Exception e) { 180 | log.warn("Error shutting down protocol listener", e); 181 | } 182 | } 183 | 184 | /** 185 | * Sets the sql task scheduler. 186 | * 187 | * @param sqlTaskScheduler the new sql task scheduler 188 | */ 189 | public void setSqlTaskScheduler(TaskScheduler sqlTaskScheduler) { 190 | this.sqlTaskScheduler = sqlTaskScheduler; 191 | } 192 | 193 | /** 194 | * Sets the greenplum load. 195 | * 196 | * @param greenplumLoad the new greenplum load 197 | */ 198 | public void setGreenplumLoad(GreenplumLoad greenplumLoad) { 199 | this.greenplumLoad = greenplumLoad; 200 | } 201 | 202 | /** 203 | * Sets the rate interval. 204 | * 205 | * @param rateInterval the new rate interval 206 | */ 207 | public void setRateInterval(int rateInterval) { 208 | this.rateInterval = rateInterval; 209 | if (rateInterval > 0) { 210 | meter = new Meter(); 211 | } 212 | } 213 | 214 | private static class TaskFuture extends SettableListenableFuture { 215 | 216 | boolean interrupted = false; 217 | 218 | @Override 219 | protected void interruptTask() { 220 | interrupted = true; 221 | } 222 | } 223 | } 224 | -------------------------------------------------------------------------------- /spring-cloud-starter-stream-sink-gpfdist/src/main/java/org/springframework/cloud/stream/app/gpfdist/sink/support/SqlUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.springframework.cloud.stream.app.gpfdist.sink.support; 18 | 19 | import org.springframework.util.StringUtils; 20 | 21 | import java.util.List; 22 | 23 | /** 24 | * Utilities creating various types of sql clauses 25 | * needed with gpfdist. 26 | * 27 | * @author Janne Valkealahti 28 | */ 29 | public abstract class SqlUtils { 30 | 31 | public static String createExternalReadableTable(LoadConfiguration config, String prefix, 32 | List overrideLocations) { 33 | 34 | // TODO: this function needs a cleanup 35 | StringBuilder buf = new StringBuilder(); 36 | 37 | // unique table name 38 | String name = config.getTable() + "_ext_" + prefix; 39 | buf.append("CREATE READABLE EXTERNAL TABLE "); 40 | buf.append(name); 41 | buf.append(" ( "); 42 | 43 | // column types or like 44 | ReadableTable externalTable = config.getExternalTable(); 45 | if (externalTable.getLike() != null) { 46 | buf.append("LIKE "); 47 | buf.append(config.getTable()); 48 | } 49 | else if (StringUtils.hasText(externalTable.getColumns())) { 50 | buf.append(externalTable.getColumns()); 51 | } 52 | else { 53 | buf.append("LIKE "); 54 | buf.append(config.getTable()); 55 | } 56 | buf.append(" ) "); 57 | 58 | // locations 59 | buf.append("LOCATION("); 60 | if (overrideLocations != null && !overrideLocations.isEmpty()) { 61 | buf.append(createLocationString(overrideLocations.toArray(new String[0]))); 62 | } 63 | else { 64 | buf.append(createLocationString(externalTable.getLocations().toArray(new String[0]))); 65 | } 66 | buf.append(") "); 67 | 68 | // format type 69 | if (externalTable.getFormat() == Format.TEXT) { 70 | buf.append("FORMAT 'TEXT'"); 71 | } 72 | else { 73 | buf.append("FORMAT 'CSV'"); 74 | } 75 | 76 | // format parameters 77 | buf.append(" ( "); 78 | buf.append("DELIMITER '"); 79 | if (externalTable.getDelimiter() != null) { 80 | buf.append(unicodeEscaped(externalTable.getDelimiter().charValue())); 81 | } 82 | else { 83 | buf.append("|"); 84 | } 85 | buf.append("'"); 86 | 87 | if (externalTable.getNullString() != null) { 88 | buf.append(" NULL '"); 89 | buf.append(externalTable.getNullString()); 90 | buf.append("'"); 91 | } 92 | 93 | if (externalTable.getEscape() != null) { 94 | buf.append(" ESCAPE '"); 95 | buf.append(externalTable.getEscape()); 96 | buf.append("'"); 97 | } 98 | 99 | if (externalTable.getQuote() != null) { 100 | buf.append(" QUOTE '"); 101 | buf.append(externalTable.getQuote()); 102 | buf.append("'"); 103 | } 104 | 105 | if (externalTable.getForceQuote() != null) { 106 | buf.append(" FORCE QUOTE "); 107 | buf.append(StringUtils.arrayToCommaDelimitedString(externalTable.getForceQuote())); 108 | } 109 | 110 | buf.append(" )"); 111 | 112 | if (externalTable.getEncoding() != null) { 113 | buf.append(" ENCODING '"); 114 | buf.append(externalTable.getEncoding()); 115 | buf.append("'"); 116 | } 117 | 118 | if (externalTable.getSegmentRejectLimit() != null && externalTable.getSegmentRejectType() != null) { 119 | if (externalTable.isLogErrors()) { 120 | buf.append(" LOG ERRORS"); 121 | } 122 | buf.append(" SEGMENT REJECT LIMIT "); 123 | buf.append(externalTable.getSegmentRejectLimit()); 124 | buf.append(" "); 125 | buf.append(externalTable.getSegmentRejectType()); 126 | } 127 | 128 | return buf.toString(); 129 | } 130 | 131 | /** 132 | * 133 | * @param config the load configuration 134 | * @param prefix the prefix 135 | * @return the drop DDL 136 | */ 137 | public static String dropExternalReadableTable(LoadConfiguration config, String prefix) { 138 | StringBuilder b = new StringBuilder(); 139 | 140 | // unique table name 141 | String name = config.getTable() + "_ext_" + prefix; 142 | 143 | b.append("DROP EXTERNAL TABLE "); 144 | b.append(name); 145 | 146 | return b.toString(); 147 | 148 | } 149 | 150 | /** 151 | * Builds sql clause to load data into a database. 152 | * 153 | * @param config Load configuration. 154 | * @param prefix Prefix for temporary resources. 155 | * @return the load DDL 156 | */ 157 | public static String load(LoadConfiguration config, String prefix) { 158 | if (config.getMode() == Mode.INSERT) { 159 | return loadInsert(config, prefix); 160 | } 161 | else if (config.getMode() == Mode.UPDATE) { 162 | return loadUpdate(config, prefix); 163 | } 164 | throw new IllegalArgumentException("Unsupported mode " + config.getMode()); 165 | } 166 | 167 | private static String loadInsert(LoadConfiguration config, String prefix) { 168 | StringBuilder b = new StringBuilder(); 169 | 170 | String name = config.getTable() + "_ext_" + prefix; 171 | 172 | b.append("INSERT INTO "); 173 | b.append(config.getTable()); 174 | b.append(" SELECT "); 175 | if (StringUtils.hasText(config.getColumns())) { 176 | b.append(config.getColumns()); 177 | } 178 | else { 179 | b.append("*"); 180 | } 181 | b.append(" FROM "); 182 | b.append(name); 183 | 184 | return b.toString(); 185 | } 186 | 187 | private static String loadUpdate(LoadConfiguration config, String prefix) { 188 | StringBuilder b = new StringBuilder(); 189 | String name = config.getTable() + "_ext_" + prefix; 190 | b.append("UPDATE "); 191 | b.append(config.getTable()); 192 | b.append(" into_table set "); 193 | 194 | for (int i = 0; i < config.getUpdateColumns().size(); i++) { 195 | b.append(config.getUpdateColumns().get(i) + "=from_table." + config.getUpdateColumns().get(i)); 196 | if (i + 1 < config.getUpdateColumns().size()) { 197 | b.append(", "); 198 | } 199 | } 200 | 201 | b.append(" FROM "); 202 | b.append(name); 203 | b.append(" from_table where "); 204 | 205 | for (int i = 0; i < config.getMatchColumns().size(); i++) { 206 | b.append("into_table." + config.getMatchColumns().get(i) + "=from_table." + config.getMatchColumns().get(i)); 207 | if (i + 1 < config.getMatchColumns().size()) { 208 | b.append(" and "); 209 | } 210 | } 211 | 212 | if (StringUtils.hasText(config.getUpdateCondition())) { 213 | b.append(" and " + config.getUpdateCondition()); 214 | } 215 | 216 | return b.toString(); 217 | } 218 | 219 | /** 220 | * Converts string array to greenplum friendly string. From new 221 | * String[]{"foo","jee"} we get "'foo',jee'". 222 | * 223 | * @param strings 224 | * String array to explode 225 | * @return Comma delimited string with values encapsulated with 226 | * apostropheres. ‘' 227 | */ 228 | public static String createLocationString(String[] strings) { 229 | StringBuilder locString = new StringBuilder(); 230 | for (int i = 0; i < strings.length; i++) { 231 | String string = strings[i]; 232 | locString.append("'"); 233 | locString.append(string); 234 | locString.append("'"); 235 | if (i < strings.length - 1) { 236 | locString.append(","); 237 | } 238 | } 239 | return locString.toString(); 240 | } 241 | 242 | private static String unicodeEscaped(char ch) { 243 | if (ch < 0x10) { 244 | return "\\u000" + Integer.toHexString(ch); 245 | } 246 | else if (ch < 0x100) { 247 | return "\\u00" + Integer.toHexString(ch); 248 | } 249 | else if (ch < 0x1000) { 250 | return "\\u0" + Integer.toHexString(ch); 251 | } 252 | return "\\u" + Integer.toHexString(ch); 253 | } 254 | 255 | } 256 | -------------------------------------------------------------------------------- /spring-cloud-starter-stream-sink-gpfdist/src/test/java/org/springframework/cloud/stream/app/gpfdist/sink/support/LoadConfigurationIT.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.cloud.stream.app.gpfdist.sink.support; 17 | 18 | import org.junit.After; 19 | import org.junit.Test; 20 | import org.springframework.cloud.stream.app.gpfdist.sink.AbstractDbTests; 21 | import org.springframework.context.annotation.AnnotationConfigApplicationContext; 22 | import org.springframework.jdbc.core.JdbcTemplate; 23 | 24 | import java.util.Arrays; 25 | 26 | import static org.hamcrest.CoreMatchers.containsString; 27 | import static org.junit.Assert.assertThat; 28 | 29 | public class LoadConfigurationIT extends AbstractDbTests { 30 | 31 | public final String TEST_TABLE = "LoadConfigurationIT"; 32 | 33 | @Test 34 | public void testErrorTableSql() throws Exception { 35 | context.register(TestDatasourceConfig.class); 36 | context.refresh(); 37 | dropTestTable(); 38 | createTestTable(); 39 | 40 | ReadableTableFactoryBean factory1 = new ReadableTableFactoryBean(); 41 | factory1.setLocations(Arrays.asList(NetworkUtils.getGPFDistUri("localhost", 1234))); 42 | factory1.setLogErrors(true); 43 | factory1.setSegmentRejectLimit(2); 44 | factory1.setSegmentRejectType(SegmentRejectType.ROWS); 45 | factory1.afterPropertiesSet(); 46 | 47 | LoadConfigurationFactoryBean factory2 = new LoadConfigurationFactoryBean(); 48 | factory2.setExternalTable(factory1.getObject()); 49 | factory2.setTable("LoadConfigurationIT"); 50 | factory2.afterPropertiesSet(); 51 | LoadConfiguration loadConfiguration = factory2.getObject(); 52 | 53 | String sql = SqlUtils.createExternalReadableTable(loadConfiguration, "xxx", null); 54 | assertThat(sql, containsString("LOG ERRORS SEGMENT REJECT LIMIT 2 ROWS")); 55 | assertSql(sql); 56 | } 57 | 58 | @Test 59 | public void testErrorSegmentRejectPercent1() throws Exception { 60 | context.register(TestDatasourceConfig.class); 61 | context.refresh(); 62 | dropTestTable(); 63 | createTestTable(); 64 | 65 | ReadableTableFactoryBean factory1 = new ReadableTableFactoryBean(); 66 | factory1.setLocations(Arrays.asList(NetworkUtils.getGPFDistUri("localhost", 1234))); 67 | factory1.setLogErrors(true); 68 | factory1.setSegmentRejectLimit(2); 69 | factory1.setSegmentRejectType(SegmentRejectType.PERCENT); 70 | factory1.afterPropertiesSet(); 71 | 72 | LoadConfigurationFactoryBean factory2 = new LoadConfigurationFactoryBean(); 73 | factory2.setExternalTable(factory1.getObject()); 74 | factory2.setTable("LoadConfigurationIT"); 75 | factory2.afterPropertiesSet(); 76 | LoadConfiguration loadConfiguration = factory2.getObject(); 77 | 78 | String sql = SqlUtils.createExternalReadableTable(loadConfiguration, "xxx", null); 79 | assertThat(sql, containsString("LOG ERRORS SEGMENT REJECT LIMIT 2 PERCENT")); 80 | assertSql(sql); 81 | } 82 | 83 | @Test 84 | public void testErrorSegmentRejectPercent2() throws Exception { 85 | context.register(TestDatasourceConfig.class); 86 | context.refresh(); 87 | dropTestTable(); 88 | createTestTable(); 89 | 90 | ReadableTableFactoryBean factory1 = new ReadableTableFactoryBean(); 91 | factory1.setLocations(Arrays.asList(NetworkUtils.getGPFDistUri("localhost", 1234))); 92 | factory1.setLogErrors(true); 93 | factory1.setSegmentReject("3%"); 94 | factory1.afterPropertiesSet(); 95 | 96 | LoadConfigurationFactoryBean factory2 = new LoadConfigurationFactoryBean(); 97 | factory2.setExternalTable(factory1.getObject()); 98 | factory2.setTable("LoadConfigurationIT"); 99 | factory2.afterPropertiesSet(); 100 | LoadConfiguration loadConfiguration = factory2.getObject(); 101 | 102 | String sql = SqlUtils.createExternalReadableTable(loadConfiguration, "xxx", null); 103 | assertThat(sql, containsString("LOG ERRORS SEGMENT REJECT LIMIT 3 PERCENT")); 104 | assertSql(sql); 105 | } 106 | 107 | @Test 108 | public void testErrorSegmentRejectPercent3() throws Exception { 109 | context.register(TestDatasourceConfig.class); 110 | context.refresh(); 111 | dropTestTable(); 112 | createTestTable(); 113 | 114 | ReadableTableFactoryBean factory1 = new ReadableTableFactoryBean(); 115 | factory1.setLocations(Arrays.asList(NetworkUtils.getGPFDistUri("localhost", 1234))); 116 | factory1.setLogErrors(true); 117 | factory1.setSegmentRejectLimit(2); 118 | factory1.setSegmentRejectType(SegmentRejectType.ROWS); 119 | // 3% overrides manually set 2 and ROWS 120 | factory1.setSegmentReject("3%"); 121 | factory1.afterPropertiesSet(); 122 | 123 | LoadConfigurationFactoryBean factory2 = new LoadConfigurationFactoryBean(); 124 | factory2.setExternalTable(factory1.getObject()); 125 | factory2.setTable("LoadConfigurationIT"); 126 | factory2.afterPropertiesSet(); 127 | LoadConfiguration loadConfiguration = factory2.getObject(); 128 | 129 | String sql = SqlUtils.createExternalReadableTable(loadConfiguration, "xxx", null); 130 | assertThat(sql, containsString("LOG ERRORS SEGMENT REJECT LIMIT 3 PERCENT")); 131 | assertSql(sql); 132 | } 133 | 134 | @Test 135 | public void testNullString1() throws Exception { 136 | context.register(TestDatasourceConfig.class); 137 | context.refresh(); 138 | dropTestTable(); 139 | createTestTable(); 140 | 141 | ReadableTableFactoryBean factory1 = new ReadableTableFactoryBean(); 142 | factory1.setLocations(Arrays.asList(NetworkUtils.getGPFDistUri("localhost", 1234))); 143 | factory1.setNullString("nullstring"); 144 | factory1.afterPropertiesSet(); 145 | 146 | LoadConfigurationFactoryBean factory2 = new LoadConfigurationFactoryBean(); 147 | factory2.setExternalTable(factory1.getObject()); 148 | factory2.setTable("LoadConfigurationIT"); 149 | factory2.afterPropertiesSet(); 150 | LoadConfiguration loadConfiguration = factory2.getObject(); 151 | 152 | String sql = SqlUtils.createExternalReadableTable(loadConfiguration, "xxx", null); 153 | assertThat(sql, containsString("NULL 'nullstring'")); 154 | assertSql(sql); 155 | } 156 | 157 | @Test 158 | public void testNullString2() throws Exception { 159 | context.register(TestDatasourceConfig.class); 160 | context.refresh(); 161 | dropTestTable(); 162 | createTestTable(); 163 | 164 | ReadableTableFactoryBean factory1 = new ReadableTableFactoryBean(); 165 | factory1.setLocations(Arrays.asList(NetworkUtils.getGPFDistUri("localhost", 1234))); 166 | factory1.setNullString("\\'\\'"); 167 | factory1.afterPropertiesSet(); 168 | 169 | LoadConfigurationFactoryBean factory2 = new LoadConfigurationFactoryBean(); 170 | factory2.setExternalTable(factory1.getObject()); 171 | factory2.setTable("LoadConfigurationIT"); 172 | factory2.afterPropertiesSet(); 173 | LoadConfiguration loadConfiguration = factory2.getObject(); 174 | 175 | String sql = SqlUtils.createExternalReadableTable(loadConfiguration, "xxx", null); 176 | assertThat(sql, containsString("NULL '\\'\\''")); 177 | assertSql(sql); 178 | } 179 | 180 | private void assertSql(String sql) { 181 | JdbcTemplate template = context.getBean(JdbcTemplate.class); 182 | template.execute(sql); 183 | } 184 | 185 | private void createTestTable() { 186 | JdbcTemplate template = context.getBean(JdbcTemplate.class); 187 | template.execute("create table " + TEST_TABLE + " (data text)"); 188 | } 189 | 190 | private void dropTestTable() { 191 | JdbcTemplate template = context.getBean(JdbcTemplate.class); 192 | template.execute("drop table if exists " + TEST_TABLE); 193 | template.execute("drop external table if exists " + TEST_TABLE + "_ext_xxx"); 194 | } 195 | 196 | @After 197 | public void clean() { 198 | dropTestTable(); 199 | super.clean(); 200 | } 201 | 202 | @Override 203 | protected AnnotationConfigApplicationContext buildContext() { 204 | return new AnnotationConfigApplicationContext(); 205 | } 206 | } 207 | -------------------------------------------------------------------------------- /mvnw: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # ---------------------------------------------------------------------------- 3 | # Licensed to the Apache Software Foundation (ASF) under one 4 | # or more contributor license agreements. See the NOTICE file 5 | # distributed with this work for additional information 6 | # regarding copyright ownership. The ASF licenses this file 7 | # to you under the Apache License, Version 2.0 (the 8 | # "License"); you may not use this file except in compliance 9 | # with the License. You may obtain a copy of the License at 10 | # 11 | # https://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, 14 | # software distributed under the License is distributed on an 15 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | # KIND, either express or implied. See the License for the 17 | # specific language governing permissions and limitations 18 | # under the License. 19 | # ---------------------------------------------------------------------------- 20 | 21 | # ---------------------------------------------------------------------------- 22 | # Maven2 Start Up Batch script 23 | # 24 | # Required ENV vars: 25 | # ------------------ 26 | # JAVA_HOME - location of a JDK home dir 27 | # 28 | # Optional ENV vars 29 | # ----------------- 30 | # M2_HOME - location of maven2's installed home dir 31 | # MAVEN_OPTS - parameters passed to the Java VM when running Maven 32 | # e.g. to debug Maven itself, use 33 | # set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 34 | # MAVEN_SKIP_RC - flag to disable loading of mavenrc files 35 | # ---------------------------------------------------------------------------- 36 | 37 | if [ -z "$MAVEN_SKIP_RC" ] ; then 38 | 39 | if [ -f /etc/mavenrc ] ; then 40 | . /etc/mavenrc 41 | fi 42 | 43 | if [ -f "$HOME/.mavenrc" ] ; then 44 | . "$HOME/.mavenrc" 45 | fi 46 | 47 | fi 48 | 49 | # OS specific support. $var _must_ be set to either true or false. 50 | cygwin=false; 51 | darwin=false; 52 | mingw=false 53 | case "`uname`" in 54 | CYGWIN*) cygwin=true ;; 55 | MINGW*) mingw=true;; 56 | Darwin*) darwin=true 57 | # 58 | # Look for the Apple JDKs first to preserve the existing behaviour, and then look 59 | # for the new JDKs provided by Oracle. 60 | # 61 | if [ -z "$JAVA_HOME" ] && [ -L /System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK ] ; then 62 | # 63 | # Apple JDKs 64 | # 65 | export JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Home 66 | fi 67 | 68 | if [ -z "$JAVA_HOME" ] && [ -L /System/Library/Java/JavaVirtualMachines/CurrentJDK ] ; then 69 | # 70 | # Apple JDKs 71 | # 72 | export JAVA_HOME=/System/Library/Java/JavaVirtualMachines/CurrentJDK/Contents/Home 73 | fi 74 | 75 | if [ -z "$JAVA_HOME" ] && [ -L "/Library/Java/JavaVirtualMachines/CurrentJDK" ] ; then 76 | # 77 | # Oracle JDKs 78 | # 79 | export JAVA_HOME=/Library/Java/JavaVirtualMachines/CurrentJDK/Contents/Home 80 | fi 81 | 82 | if [ -z "$JAVA_HOME" ] && [ -x "/usr/libexec/java_home" ]; then 83 | # 84 | # Apple JDKs 85 | # 86 | export JAVA_HOME=`/usr/libexec/java_home` 87 | fi 88 | ;; 89 | esac 90 | 91 | if [ -z "$JAVA_HOME" ] ; then 92 | if [ -r /etc/gentoo-release ] ; then 93 | JAVA_HOME=`java-config --jre-home` 94 | fi 95 | fi 96 | 97 | if [ -z "$M2_HOME" ] ; then 98 | ## resolve links - $0 may be a link to maven's home 99 | PRG="$0" 100 | 101 | # need this for relative symlinks 102 | while [ -h "$PRG" ] ; do 103 | ls=`ls -ld "$PRG"` 104 | link=`expr "$ls" : '.*-> \(.*\)$'` 105 | if expr "$link" : '/.*' > /dev/null; then 106 | PRG="$link" 107 | else 108 | PRG="`dirname "$PRG"`/$link" 109 | fi 110 | done 111 | 112 | saveddir=`pwd` 113 | 114 | M2_HOME=`dirname "$PRG"`/.. 115 | 116 | # make it fully qualified 117 | M2_HOME=`cd "$M2_HOME" && pwd` 118 | 119 | cd "$saveddir" 120 | # echo Using m2 at $M2_HOME 121 | fi 122 | 123 | # For Cygwin, ensure paths are in UNIX format before anything is touched 124 | if $cygwin ; then 125 | [ -n "$M2_HOME" ] && 126 | M2_HOME=`cygpath --unix "$M2_HOME"` 127 | [ -n "$JAVA_HOME" ] && 128 | JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 129 | [ -n "$CLASSPATH" ] && 130 | CLASSPATH=`cygpath --path --unix "$CLASSPATH"` 131 | fi 132 | 133 | # For Migwn, ensure paths are in UNIX format before anything is touched 134 | if $mingw ; then 135 | [ -n "$M2_HOME" ] && 136 | M2_HOME="`(cd "$M2_HOME"; pwd)`" 137 | [ -n "$JAVA_HOME" ] && 138 | JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" 139 | # TODO classpath? 140 | fi 141 | 142 | if [ -z "$JAVA_HOME" ]; then 143 | javaExecutable="`which javac`" 144 | if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then 145 | # readlink(1) is not available as standard on Solaris 10. 146 | readLink=`which readlink` 147 | if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then 148 | if $darwin ; then 149 | javaHome="`dirname \"$javaExecutable\"`" 150 | javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" 151 | else 152 | javaExecutable="`readlink -f \"$javaExecutable\"`" 153 | fi 154 | javaHome="`dirname \"$javaExecutable\"`" 155 | javaHome=`expr "$javaHome" : '\(.*\)/bin'` 156 | JAVA_HOME="$javaHome" 157 | export JAVA_HOME 158 | fi 159 | fi 160 | fi 161 | 162 | if [ -z "$JAVACMD" ] ; then 163 | if [ -n "$JAVA_HOME" ] ; then 164 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 165 | # IBM's JDK on AIX uses strange locations for the executables 166 | JAVACMD="$JAVA_HOME/jre/sh/java" 167 | else 168 | JAVACMD="$JAVA_HOME/bin/java" 169 | fi 170 | else 171 | JAVACMD="`which java`" 172 | fi 173 | fi 174 | 175 | if [ ! -x "$JAVACMD" ] ; then 176 | echo "Error: JAVA_HOME is not defined correctly." >&2 177 | echo " We cannot execute $JAVACMD" >&2 178 | exit 1 179 | fi 180 | 181 | if [ -z "$JAVA_HOME" ] ; then 182 | echo "Warning: JAVA_HOME environment variable is not set." 183 | fi 184 | 185 | CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher 186 | 187 | # For Cygwin, switch paths to Windows format before running java 188 | if $cygwin; then 189 | [ -n "$M2_HOME" ] && 190 | M2_HOME=`cygpath --path --windows "$M2_HOME"` 191 | [ -n "$JAVA_HOME" ] && 192 | JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` 193 | [ -n "$CLASSPATH" ] && 194 | CLASSPATH=`cygpath --path --windows "$CLASSPATH"` 195 | fi 196 | 197 | # traverses directory structure from process work directory to filesystem root 198 | # first directory with .mvn subdirectory is considered project base directory 199 | find_maven_basedir() { 200 | local basedir=$(pwd) 201 | local wdir=$(pwd) 202 | while [ "$wdir" != '/' ] ; do 203 | if [ -d "$wdir"/.mvn ] ; then 204 | basedir=$wdir 205 | break 206 | fi 207 | wdir=$(cd "$wdir/.."; pwd) 208 | done 209 | echo "${basedir}" 210 | } 211 | 212 | # concatenates all lines of a file 213 | concat_lines() { 214 | if [ -f "$1" ]; then 215 | echo "$(tr -s '\n' ' ' < "$1")" 216 | fi 217 | } 218 | 219 | export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-$(find_maven_basedir)} 220 | MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" 221 | 222 | # Provide a "standardized" way to retrieve the CLI args that will 223 | # work with both Windows and non-Windows executions. 224 | MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@" 225 | export MAVEN_CMD_LINE_ARGS 226 | 227 | WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 228 | 229 | echo "Running version check" 230 | VERSION=$( sed '\!//' -e 's!.*$!!' ) 231 | echo "The found version is [${VERSION}]" 232 | 233 | if echo $VERSION | egrep -q 'M|RC'; then 234 | echo Activating \"milestone\" profile for version=\"$VERSION\" 235 | echo $MAVEN_ARGS | grep -q milestone || MAVEN_ARGS="$MAVEN_ARGS -Pmilestone" 236 | else 237 | echo Deactivating \"milestone\" profile for version=\"$VERSION\" 238 | echo $MAVEN_ARGS | grep -q milestone && MAVEN_ARGS=$(echo $MAVEN_ARGS | sed -e 's/-Pmilestone//') 239 | fi 240 | 241 | exec "$JAVACMD" \ 242 | $MAVEN_OPTS \ 243 | -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ 244 | "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ 245 | ${WRAPPER_LAUNCHER} ${MAVEN_ARGS} "$@" 246 | -------------------------------------------------------------------------------- /spring-cloud-starter-stream-sink-gpfdist/src/main/java/org/springframework/cloud/stream/app/gpfdist/sink/GpfdistSinkProperties.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.springframework.cloud.stream.app.gpfdist.sink; 18 | 19 | import org.springframework.boot.context.properties.ConfigurationProperties; 20 | import org.springframework.cloud.stream.app.gpfdist.sink.support.SegmentRejectType; 21 | import org.springframework.core.io.Resource; 22 | 23 | /** 24 | * Config options for gpfdist sink. 25 | * 26 | * @author Janne Valkealahti 27 | * @author Sabby Anandan 28 | */ 29 | @ConfigurationProperties("gpfdist") 30 | public class GpfdistSinkProperties { 31 | 32 | /** 33 | * Port of gpfdist server. Default port `0` indicates that a random port is chosen. (Integer, default: 0) 34 | */ 35 | private int gpfdistPort = 0; 36 | 37 | /** 38 | * Flush item count (int, default: 100) 39 | */ 40 | private int flushCount = 100; 41 | 42 | /** 43 | * Flush item time (int, default: 2) 44 | */ 45 | private int flushTime = 2; 46 | 47 | /** 48 | * Timeout in seconds for segment inactivity. (Integer, default: 4) 49 | */ 50 | private int batchTimeout = 4; 51 | 52 | /** 53 | * Number of windowed batch each segment takest (int, default: 100) 54 | */ 55 | private int batchCount = 100; 56 | 57 | /** 58 | * Time in seconds for each load operation to sleep in between operations (int, default: 10) 59 | */ 60 | private int batchPeriod = 10; 61 | 62 | /** 63 | * Database name (String, default: gpadmin) 64 | */ 65 | private String dbName = "gpadmin"; 66 | 67 | /** 68 | * Database user (String, default: gpadmin) 69 | */ 70 | private String dbUser = "gpadmin"; 71 | 72 | /** 73 | * Database password (String, default: gpadmin) 74 | */ 75 | private String dbPassword = "gpadmin"; 76 | 77 | /** 78 | * Database host (String, default: localhost) 79 | */ 80 | private String dbHost = "localhost"; 81 | 82 | /** 83 | * Database port (int, default: 5432) 84 | */ 85 | private int dbPort = 5432; 86 | 87 | /** 88 | * Path to yaml control file (String, no default) 89 | */ 90 | private Resource controlFile; 91 | 92 | /** 93 | * Data line delimiter (String, default: newline character) 94 | */ 95 | private String delimiter = "\n"; 96 | 97 | /** 98 | * Data record column delimiter. *(Character, default: no default) 99 | */ 100 | private Character columnDelimiter; 101 | 102 | /** 103 | * Mode, either insert or update (String, no default) 104 | */ 105 | private String mode; 106 | 107 | /** 108 | * Match columns with update (String, no default) 109 | */ 110 | private String matchColumns; 111 | 112 | /** 113 | * Update columns with update (String, no default) 114 | */ 115 | private String updateColumns; 116 | 117 | /** 118 | * Target database table (String, no default) 119 | */ 120 | private String table; 121 | 122 | /** 123 | * Enable transfer rate interval (int, default: 0) 124 | */ 125 | private int rateInterval = 0; 126 | 127 | /** 128 | * Sql to run before load (String, no default) 129 | */ 130 | private String sqlBefore; 131 | 132 | /** 133 | * Sql to run after load (String, no default) 134 | */ 135 | private String sqlAfter; 136 | 137 | /** 138 | * Enable log errors. (Boolean, default: false) 139 | */ 140 | private boolean logErrors; 141 | 142 | /** 143 | * Error reject limit. (String, default: ``) 144 | */ 145 | private String segmentRejectLimit; 146 | 147 | /** 148 | * Error reject type, either `rows` or `percent`. (String, default: `rows`) 149 | */ 150 | private SegmentRejectType segmentRejectType = SegmentRejectType.ROWS; 151 | 152 | /** 153 | * Null string definition. (String, default: ``) 154 | */ 155 | private String nullString; 156 | 157 | public int getGpfdistPort() { 158 | return gpfdistPort; 159 | } 160 | 161 | public void setGpfdistPort(int gpfdistPort) { 162 | this.gpfdistPort = gpfdistPort; 163 | } 164 | 165 | public int getFlushCount() { 166 | return flushCount; 167 | } 168 | 169 | public void setFlushCount(int flushCount) { 170 | this.flushCount = flushCount; 171 | } 172 | 173 | public int getFlushTime() { 174 | return flushTime; 175 | } 176 | 177 | public void setFlushTime(int flushTime) { 178 | this.flushTime = flushTime; 179 | } 180 | 181 | public int getBatchTimeout() { 182 | return batchTimeout; 183 | } 184 | 185 | public void setBatchTimeout(int batchTimeout) { 186 | this.batchTimeout = batchTimeout; 187 | } 188 | 189 | public int getBatchPeriod() { 190 | return batchPeriod; 191 | } 192 | 193 | public void setBatchPeriod(int batchPeriod) { 194 | this.batchPeriod = batchPeriod; 195 | } 196 | 197 | public int getBatchCount() { 198 | return batchCount; 199 | } 200 | 201 | public void setBatchCount(int batchCount) { 202 | this.batchCount = batchCount; 203 | } 204 | 205 | public String getDbName() { 206 | return dbName; 207 | } 208 | 209 | public void setDbName(String dbName) { 210 | this.dbName = dbName; 211 | } 212 | 213 | public String getDbUser() { 214 | return dbUser; 215 | } 216 | 217 | public void setDbUser(String dbUser) { 218 | this.dbUser = dbUser; 219 | } 220 | 221 | public String getDbPassword() { 222 | return dbPassword; 223 | } 224 | 225 | public void setDbPassword(String dbPassword) { 226 | this.dbPassword = dbPassword; 227 | } 228 | 229 | public String getDbHost() { 230 | return dbHost; 231 | } 232 | 233 | public void setDbHost(String dbHost) { 234 | this.dbHost = dbHost; 235 | } 236 | 237 | public int getDbPort() { 238 | return dbPort; 239 | } 240 | 241 | public void setDbPort(int dbPort) { 242 | this.dbPort = dbPort; 243 | } 244 | 245 | public Resource getControlFile() { 246 | return controlFile; 247 | } 248 | 249 | public void setControlFile(Resource controlFile) { 250 | this.controlFile = controlFile; 251 | } 252 | 253 | public String getDelimiter() { 254 | return delimiter; 255 | } 256 | 257 | public void setDelimiter(String delimiter) { 258 | this.delimiter = delimiter; 259 | } 260 | 261 | public Character getColumnDelimiter() { 262 | return columnDelimiter; 263 | } 264 | 265 | public void setColumnDelimiter(Character columnDelimiter) { 266 | this.columnDelimiter = columnDelimiter; 267 | } 268 | 269 | public String getMode() { 270 | return mode; 271 | } 272 | 273 | public void setMode(String mode) { 274 | this.mode = mode; 275 | } 276 | 277 | public String getUpdateColumns() { 278 | return updateColumns; 279 | } 280 | 281 | public void setUpdateColumns(String updateColumns) { 282 | this.updateColumns = updateColumns; 283 | } 284 | 285 | public String getMatchColumns() { 286 | return matchColumns; 287 | } 288 | 289 | public void setMatchColumns(String matchColumns) { 290 | this.matchColumns = matchColumns; 291 | } 292 | 293 | public String getTable() { 294 | return table; 295 | } 296 | 297 | public void setTable(String table) { 298 | this.table = table; 299 | } 300 | 301 | public int getRateInterval() { 302 | return rateInterval; 303 | } 304 | 305 | public void setRateInterval(int rateInterval) { 306 | this.rateInterval = rateInterval; 307 | } 308 | 309 | public String getSqlBefore() { 310 | return sqlBefore; 311 | } 312 | 313 | public void setSqlBefore(String sqlBefore) { 314 | this.sqlBefore = sqlBefore; 315 | } 316 | 317 | public String getSqlAfter() { 318 | return sqlAfter; 319 | } 320 | 321 | public void setSqlAfter(String sqlAfter) { 322 | this.sqlAfter = sqlAfter; 323 | } 324 | 325 | public boolean isLogErrors() { 326 | return logErrors; 327 | } 328 | 329 | public void setLogErrors(boolean logErrors) { 330 | this.logErrors = logErrors; 331 | } 332 | 333 | public String getSegmentRejectLimit() { 334 | return segmentRejectLimit; 335 | } 336 | 337 | public void setSegmentRejectLimit(String segmentRejectLimit) { 338 | this.segmentRejectLimit = segmentRejectLimit; 339 | } 340 | 341 | public SegmentRejectType getSegmentRejectType() { 342 | return segmentRejectType; 343 | } 344 | 345 | public void setSegmentRejectType(SegmentRejectType segmentRejectType) { 346 | this.segmentRejectType = segmentRejectType; 347 | } 348 | 349 | public String getNullString() { 350 | return nullString; 351 | } 352 | 353 | public void setNullString(String nullString) { 354 | this.nullString = nullString; 355 | } 356 | } 357 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | https://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | https://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /spring-cloud-starter-stream-sink-gpfdist/README.adoc: -------------------------------------------------------------------------------- 1 | //tag::ref-doc[] 2 | = Gpfdist Sink 3 | 4 | A sink module that route messages into `GPDB/HAWQ` segments via 5 | _gpfdist_ protocol. Internally, this sink creates a custom http listener that supports 6 | the `gpfdist` protcol and schedules a task that orchestrates a `gploadd` session in the 7 | same way it is done natively in Greenplum. 8 | 9 | No data is written into temporary files and all data is kept in stream buffers waiting 10 | to get inserted into Greenplum DB or HAWQ. If there are no existing load sessions from Greenplum, 11 | the sink will block until such sessions are established. 12 | 13 | == Input 14 | 15 | ==== Headers: 16 | 17 | * `Content-Type: text/plain` 18 | 19 | ==== Payload: 20 | 21 | * `String` 22 | 23 | == Output 24 | 25 | N/A 26 | 27 | == Options 28 | 29 | The **$$gpfdist$$** $$sink$$ has the following options: 30 | 31 | //tag::configuration-properties[] 32 | $$gpfdist.batch-count$$:: $$Number of windowed batch each segment takest (int, default: 100)$$ *($$Integer$$, default: `$$100$$`)* 33 | $$gpfdist.batch-period$$:: $$Time in seconds for each load operation to sleep in between operations (int, default: 10)$$ *($$Integer$$, default: `$$10$$`)* 34 | $$gpfdist.batch-timeout$$:: $$Timeout in seconds for segment inactivity. (Integer, default: 4)$$ *($$Integer$$, default: `$$4$$`)* 35 | $$gpfdist.column-delimiter$$:: $$Data record column delimiter. *(Character, default: no default)$$ *($$Character$$, default: `$$$$`)* 36 | $$gpfdist.control-file$$:: $$Path to yaml control file (String, no default)$$ *($$Resource$$, default: `$$$$`)* 37 | $$gpfdist.db-host$$:: $$Database host (String, default: localhost)$$ *($$String$$, default: `$$localhost$$`)* 38 | $$gpfdist.db-name$$:: $$Database name (String, default: gpadmin)$$ *($$String$$, default: `$$gpadmin$$`)* 39 | $$gpfdist.db-password$$:: $$Database password (String, default: gpadmin)$$ *($$String$$, default: `$$gpadmin$$`)* 40 | $$gpfdist.db-port$$:: $$Database port (int, default: 5432)$$ *($$Integer$$, default: `$$5432$$`)* 41 | $$gpfdist.db-user$$:: $$Database user (String, default: gpadmin)$$ *($$String$$, default: `$$gpadmin$$`)* 42 | $$gpfdist.delimiter$$:: $$Data line delimiter (String, default: newline character)$$ *($$String$$, default: `$$ 43 | $$`)* 44 | $$gpfdist.flush-count$$:: $$Flush item count (int, default: 100)$$ *($$Integer$$, default: `$$100$$`)* 45 | $$gpfdist.flush-time$$:: $$Flush item time (int, default: 2)$$ *($$Integer$$, default: `$$2$$`)* 46 | $$gpfdist.gpfdist-port$$:: $$Port of gpfdist server. Default port `0` indicates that a random port is chosen. (Integer, default: 0)$$ *($$Integer$$, default: `$$0$$`)* 47 | $$gpfdist.log-errors$$:: $$Enable log errors. (Boolean, default: false)$$ *($$Boolean$$, default: `$$false$$`)* 48 | $$gpfdist.match-columns$$:: $$Match columns with update (String, no default)$$ *($$String$$, default: `$$$$`)* 49 | $$gpfdist.mode$$:: $$Mode, either insert or update (String, no default)$$ *($$String$$, default: `$$$$`)* 50 | $$gpfdist.null-string$$:: $$Null string definition. (String, default: ``)$$ *($$String$$, default: `$$$$`)* 51 | $$gpfdist.rate-interval$$:: $$Enable transfer rate interval (int, default: 0)$$ *($$Integer$$, default: `$$0$$`)* 52 | $$gpfdist.segment-reject-limit$$:: $$Error reject limit. (String, default: ``)$$ *($$String$$, default: `$$$$`)* 53 | $$gpfdist.segment-reject-type$$:: $$Error reject type, either `rows` or `percent`. (String, default: `rows`)$$ *($$SegmentRejectType$$, default: `$$$$`, possible values: `ROWS`,`PERCENT`)* 54 | $$gpfdist.sql-after$$:: $$Sql to run after load (String, no default)$$ *($$String$$, default: `$$$$`)* 55 | $$gpfdist.sql-before$$:: $$Sql to run before load (String, no default)$$ *($$String$$, default: `$$$$`)* 56 | $$gpfdist.table$$:: $$Target database table (String, no default)$$ *($$String$$, default: `$$$$`)* 57 | $$gpfdist.update-columns$$:: $$Update columns with update (String, no default)$$ *($$String$$, default: `$$$$`)* 58 | $$spring.net.hostdiscovery.loopback$$:: $$The new loopback flag. Default value is FALSE$$ *($$Boolean$$, default: `$$false$$`)* 59 | $$spring.net.hostdiscovery.match-interface$$:: $$The new match interface regex pattern. Default value is is empty$$ *($$String$$, default: `$$$$`)* 60 | $$spring.net.hostdiscovery.match-ipv4$$:: $$Used to match ip address from a network using a cidr notation$$ *($$String$$, default: `$$$$`)* 61 | $$spring.net.hostdiscovery.point-to-point$$:: $$The new point to point flag. Default value is FALSE$$ *($$Boolean$$, default: `$$false$$`)* 62 | $$spring.net.hostdiscovery.prefer-interface$$:: $$The new preferred interface list$$ *($$List$$, default: `$$$$`)* 63 | //end::configuration-properties[] 64 | 65 | == Implementation Notes 66 | 67 | Within a `gpfdist` sink we have a Reactor based stream where data is published from the incoming SI channel. 68 | This channel receives data from the Message Bus. The Reactor stream is then connected to `Netty` based 69 | http channel adapters so that when a new http connection is established, the Reactor stream is flushed and balanced among 70 | existing http clients. When `Greenplum` does a load from an external table, each segment will initiate 71 | a http connection and start loading data. The net effect is that incoming data is automatically spread 72 | among the Greenplum segments. 73 | 74 | 75 | == Detailed Option Descriptions 76 | 77 | The **$$gpfdist$$** $$sink$$ supports the following configuration properties: 78 | 79 | $$table$$:: 80 | $$Database table to work with.$$ *($$String$$, default: ``, required)* 81 | + 82 | This option denotes a table where data will be inserted or updated. 83 | Also external table structure will be derived from structure of this 84 | table. 85 | + 86 | Currently `table` is only way to define a structure of an external 87 | table. Effectively it will replace `other_table` in below clause 88 | segment. 89 | + 90 | ``` 91 | CREATE READABLE EXTERNAL TABLE table_name LIKE other_table 92 | ``` 93 | $$mode$$:: 94 | $$Gpfdist mode, either `insert` or `update`.$$ *($$String$$, default: `insert`)* 95 | + 96 | Currently only `insert` and `update` gpfdist mode is supported. Mode 97 | `merge` familiar from a native gpfdist loader is not yet supported. 98 | + 99 | For mode `update` options `matchColumns` and `updateColumns` are 100 | required. 101 | $$columnDelimiter$$:: $$Data record column delimiter.$$ *($$Character$$, default: ``)* 102 | + 103 | Defines used `delimiter` character in below clause segment which would 104 | be part of a `FORMAT 'TEXT'` or `FORMAT 'CSV'` sections. 105 | + 106 | ``` 107 | [DELIMITER AS 'delimiter'] 108 | ``` 109 | $$segmentRejectLimit$$:: 110 | $$Error reject limit.$$ *($$String$$, default: ``)* 111 | + 112 | Defines a `count` value in a below clause segment. 113 | + 114 | ``` 115 | [ [LOG ERRORS] SEGMENT REJECT LIMIT count 116 | [ROWS | PERCENT] ] 117 | ``` 118 | + 119 | As a conveniance this reject limit also recognizes a percentage format 120 | `2%` and if used, `segmentRejectType` is automatically set to 121 | `percent`. 122 | $$segmentRejectType$$:: 123 | $$Error reject type, either `rows` or `percent`.$$ *($$String$$, default: ``)* 124 | + 125 | Defines `ROWS` or `PERCENT` in below clause segment. 126 | + 127 | ``` 128 | [ [LOG ERRORS] SEGMENT REJECT LIMIT count 129 | [ROWS | PERCENT] ] 130 | ``` 131 | $$logErrors$$:: 132 | $$Enable or disable log errors.$$ *($$Boolean$$, default: `false`)* 133 | + 134 | As error logging is optional with `SEGMENT REJECT LIMIT`, it's only used 135 | if both `segmentRejectLimit` and `segmentRejectType` are set. Enables 136 | the error log in below clause segment. 137 | + 138 | ``` 139 | [ [LOG ERRORS] SEGMENT REJECT LIMIT count 140 | [ROWS | PERCENT] ] 141 | ``` 142 | $$nullString$$:: 143 | $$Null string definition.$$ *($$String$$, default: ``)* 144 | + 145 | Defines used `null string` in below clause segment which would 146 | be part of a `FORMAT 'TEXT'` or `FORMAT 'CSV'` sections. 147 | + 148 | ``` 149 | [NULL AS 'null string'] 150 | ``` 151 | $$delimiter$$:: 152 | $$Data record delimiter for incoming messages.$$ *($$String$$, default: `\n`)* 153 | + 154 | On default a delimiter in this option will be added as a postfix to 155 | every message sent into this sink. Currently _NEWLINE_ is not a 156 | supported config option and line termination for data is coming from a 157 | default functionality. 158 | + 159 | [quote, External Table Docs] 160 | ____________________________________________________________________ 161 | If not specified, a Greenplum Database segment will detect the 162 | newline type by looking at the first row of data it receives and 163 | using the first newline type encountered. 164 | ____________________________________________________________________ 165 | $$matchColumns$$:: 166 | $$Comma delimited list of columns to match.$$ *($$String$$, default: ``)* 167 | + 168 | [NOTE] 169 | ===== 170 | See more from examples below. 171 | ===== 172 | $$updateColumns$$:: 173 | $$Comma delimited list of columns to update.$$ *($$String$$, default: ``)* 174 | + 175 | [NOTE] 176 | ===== 177 | See more from examples below. 178 | ===== 179 | $$sqlBefore$$:: 180 | $$Sql clause to run before each load operation.$$ *($$String$$, default: ``)* 181 | $$sqlAfter$$:: 182 | $$Sql clause to run after each load operation.$$ *($$String$$, default: ``)* 183 | $$rateInterval$$:: 184 | $$Debug rate of data transfer.$$ *($$Integer$$, default: `0`)* 185 | + 186 | If set to non zero, sink will log a rate of messages passing throught 187 | a sink after number of messages denoted by this setting has been 188 | processed. Value `0` means that this rate calculation and logging is 189 | disabled. 190 | $$flushCount$$:: 191 | $$Max collected size per windowed data.$$ *($$Integer$$, default: `100`)* 192 | + 193 | [NOTE] 194 | ===== 195 | For more info on flush and batch settings, see above. 196 | ===== 197 | 198 | == How Data Is Sent Into Segments 199 | There are few important concepts involving how data passes into a 200 | sink, through it and finally lands into a database. 201 | 202 | * Sink has its normal message handler for incoming data from a source 203 | module, gpfdist protocol listener based on netty where segments 204 | connect to and in between those two a reactor based streams 205 | controlling load balancing into different segment connections. 206 | * Incoming data is first sent into a reactor which first constructs a 207 | windows. This window is then released into a downstream when it gets 208 | full(`flushTime`) or timeouts(`flushTime`) if window doesn't get full. 209 | One window is then ready to get send into a segment. 210 | * Segments which connects to this stream are now able to see a stream 211 | of window data, not stream of individual messages. We can also call 212 | this as a stream of batches. 213 | * When segment makes a connection to a protocol listener it subscribes 214 | itself into this stream and takes count of batches denoted by 215 | `batchCount` and completes a stream if it got enough batches or if 216 | `batchTimeout` occurred due to inactivity. 217 | * It doesn't matter how many simultaneous connections there are from 218 | a database cluster at any given time as reactor will load balance 219 | batches with all subscribers. 220 | * Database cluster will initiate this loading session when select is 221 | done from an external table which will point to this sink. These 222 | loading operations are run in a background in a loop one after 223 | another. Option `batchPeriod` is then used as a sleep time in 224 | between these load sessions. 225 | 226 | Lets take a closer look how options `flushCount`, `flushTime`, 227 | `batchCount`, `batchTimeout` and `batchPeriod` work. 228 | 229 | As in a highest level where incoming data into a sink is windowed, 230 | `flushCount` and `flushTime` controls when a batch of messages are 231 | sent into a downstream. If there are a lot of simultaneous segment 232 | connections, flushing less will keep more segments inactive as there 233 | is more demand for batches than what flushing will produce. 234 | 235 | When existing segment connection is active and it has subscribed 236 | itself with a stream of batches, data will keep flowing until either 237 | `batchCount` is met or `batchTimeout` occurs due to inactivity of data 238 | from an upstream. Higher a `batchCount` is more data each segment 239 | will read. Higher a `batchTimeout` is more time segment will wait in 240 | case there is more data to come. 241 | 242 | As gpfdist load operations are done in a loop, `batchPeriod` simply 243 | controls not to run things in a buzy loop. Buzy loop would be ok if 244 | there is a constant stream of data coming in but if incoming data is 245 | more like bursts then buzy loop would be unnecessary. 246 | 247 | [NOTE] 248 | ===== 249 | Data loaded via gpfdist will not become visible in a database until 250 | whole distributed loading session have finished successfully. 251 | ===== 252 | 253 | Reactor is also handling backpressure meaning if existing load 254 | operations will not produce enought demand for data, eventually 255 | message passing into a sink will block. This happens when Reactor's 256 | internal ring buffer(size of 32 items) gets full. Flow of data through 257 | sink really happens when data is pulled from it by segments. 258 | 259 | == Example Usage 260 | 261 | In this first example we're just creating a simple stream which 262 | inserts data from a `time` source. Let's create a table with two 263 | _text_ columns. 264 | ``` 265 | gpadmin=# create table ticktock (date text, time text); 266 | ``` 267 | 268 | Create a simple stream `gpstream`. 269 | ``` 270 | dataflow:>stream create --name gpstream1 --definition "time | gpfdist 271 | --dbHost=mdw --table=ticktock --batchTime=1 --batchPeriod=1 272 | --flushCount=2 --flushTime=2 --columnDelimiter=' '" --deploy 273 | ``` 274 | 275 | Let it run and see results from a database. 276 | ``` 277 | gpadmin=# select count(*) from ticktock; 278 | count 279 | ------- 280 | 14 281 | (1 row) 282 | ``` 283 | 284 | In previous example we did a simple inserts into a table. Let’s see 285 | how we can update data in a table. Create a simple table _httpdata_ with 286 | three text columns and insert some data. 287 | ``` 288 | gpadmin=# create table httpdata (col1 text, col2 text, col3 text); 289 | gpadmin=# insert into httpdata values ('DATA1', 'DATA', 'DATA'); 290 | gpadmin=# insert into httpdata values ('DATA2', 'DATA', 'DATA'); 291 | gpadmin=# insert into httpdata values ('DATA3', 'DATA', 'DATA'); 292 | ``` 293 | 294 | Now table looks like this. 295 | ``` 296 | gpadmin=# select * from httpdata; 297 | col1 | col2 | col3 298 | -------+------+------ 299 | DATA3 | DATA | DATA 300 | DATA2 | DATA | DATA 301 | DATA1 | DATA | DATA 302 | (3 rows) 303 | ``` 304 | 305 | Let’s create a stream which will update table _httpdata_ by matching a 306 | column _col1_ and updates columns _col2_ and _col3_. 307 | ``` 308 | dataflow:>stream create --name gpfdiststream2 --definition "http 309 | --server.port=8081|gpfdist --mode=update --table=httpdata 310 | --dbHost=mdw --columnDelimiter=',' --matchColumns=col1 311 | --updateColumns=col2,col3" --deploy 312 | ``` 313 | 314 | Post some data into a stream which will be passed into a _gpfdist_ sink 315 | via _http_ source. 316 | ``` 317 | curl --data "DATA1,DATA1,DATA1" -H "Content-Type:text/plain" http://localhost:8081/ 318 | ``` 319 | 320 | If you query table again, you’ll see that row for _DATA1_ has been 321 | updated. 322 | ``` 323 | gpadmin=# select * from httpdata; 324 | col1 | col2 | col3 325 | -------+-------+------- 326 | DATA3 | DATA | DATA 327 | DATA2 | DATA | DATA 328 | DATA1 | DATA1 | DATA1 329 | (3 rows) 330 | ``` 331 | 332 | 333 | == Tuning Transfer Rate 334 | Default values for options `flushCount`, `flushTime`, `batchCount`, 335 | `batchTimeout` and `batchPeriod` are relatively conservative and needs 336 | to be _tuned_ for every use case for optimal performance. Order to make 337 | a decision on how to tune sink behaviour to suit your needs few things 338 | needs to be considered. 339 | 340 | * What is an average size of messages ingested by a sink. 341 | * How fast you want data to become visible in a database. 342 | * Is incoming data a constant flow or a bursts of data. 343 | 344 | Everything what flows throught a sink is kept in-memory and because 345 | sink is handling backpressure, memory consumption is relatively low. 346 | However because sink cannot predict what is an average size of 347 | an incoming data and this data is anyway windowed later in a 348 | downstream you should not allow window size to become too large if 349 | average data size is large as every batch of data is kept in memory. 350 | 351 | Generally speaking if you have a lot of segments in a load operation, 352 | it's adviced to keep flushed window size relatively small which allows 353 | more segments to stay active. This however also depends on how much 354 | data is flowing in into a sink itself. 355 | 356 | Longer a load session for each segment is active higher the overall 357 | transfer rate is going to be. Option `batchCount` naturally controls 358 | this. However option `batchTimeout` then really controls how fast each 359 | segment will complete a stream due to inactivity from upstream and to 360 | step away from a loading session to allow distributes session to 361 | finish and data become visible in a database. 362 | 363 | == Build 364 | 365 | ``` 366 | $ ./mvnw clean install -PgenerateApps 367 | $ cd apps 368 | ``` 369 | You can find the corresponding binder based projects here. You can then cd into one one of the folders and 370 | build it: 371 | ``` 372 | $ ./mvnw clean package 373 | ``` 374 | 375 | == Examples 376 | 377 | See above. 378 | 379 | //end::ref-doc[] 380 | --------------------------------------------------------------------------------