You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by miguel0afd <gi...@git.apache.org> on 2015/03/14 23:58:00 UTC

[GitHub] flink pull request: [FLINK-1688] Socket client sink added

GitHub user miguel0afd opened a pull request:

    https://github.com/apache/flink/pull/484

    [FLINK-1688] Socket client sink added

    

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/miguel0afd/flink feature/FLINK-1688

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/flink/pull/484.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #484
    
----
commit 0fa39a939456c6f28c71f70210509c9423c9c3af
Author: miguel0afd <ma...@stratio.com>
Date:   2015-03-14T22:54:38Z

    [FLINK-1688] Socket client sink added

----


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] flink pull request: [FLINK-1688] Socket client sink added

Posted by miguel0afd <gi...@git.apache.org>.
Github user miguel0afd commented on the pull request:

    https://github.com/apache/flink/pull/484#issuecomment-84141928
  
    Sorry for the mess, I made a mistake with a undesired merge... Anyway, I can create a new branch in my fork repository and create a new pull request if that helps.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] flink pull request: [FLINK-1688] Socket client sink added

Posted by mbalassi <gi...@git.apache.org>.
Github user mbalassi commented on the pull request:

    https://github.com/apache/flink/pull/484#issuecomment-84087404
  
    @hsaputra thanks for the heads up - I am cherry-picking and squashing the relevant commits.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] flink pull request: [FLINK-1688] Socket client sink added

Posted by mxm <gi...@git.apache.org>.
Github user mxm commented on the pull request:

    https://github.com/apache/flink/pull/484#issuecomment-81665515
  
    Thanks for the pull request. Could you add some javadoc to the class and add an entry in the Flink website docs [1]?
    
    [1] http://ci.apache.org/projects/flink/flink-docs-master/programming_guide.html#data-sinks


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] flink pull request: [FLINK-1688] Socket client sink added

Posted by mbalassi <gi...@git.apache.org>.
Github user mbalassi commented on the pull request:

    https://github.com/apache/flink/pull/484#issuecomment-84575241
  
    No problem, thanks for the contribution. Cherry-picked and squashed your commits. I've decided to make three changes:
    
    1. The output was not necessarily flushed upon closure, fixed that.
    2. Some lines where indented with spaces.
    3. I moved the function into streaming-core - as the socket source is considered a core functionality I found this solution more consistent.
    
    Merging as soon as travis comes in green.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] flink pull request: [FLINK-1688] Socket client sink added

Posted by mxm <gi...@git.apache.org>.
Github user mxm commented on a diff in the pull request:

    https://github.com/apache/flink/pull/484#discussion_r26483484
  
    --- Diff: flink-staging/flink-streaming/flink-streaming-connectors/src/main/java/org/apache/flink/streaming/connectors/socket/SocketClientSink.java ---
    @@ -0,0 +1,107 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements.  See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You under the Apache License, Version 2.0
    + * (the "License"); you may not use this file except in compliance with
    + * the License.  You may obtain a copy of the License at
    + *
    + *	http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +
    +package org.apache.flink.streaming.connectors.socket;
    +
    +import java.io.DataOutputStream;
    +import java.io.IOException;
    +import java.io.OutputStream;
    +import java.net.Socket;
    +
    +import org.apache.flink.configuration.Configuration;
    +import org.apache.flink.streaming.api.function.sink.RichSinkFunction;
    +import org.apache.flink.streaming.connectors.util.SerializationSchema;
    +import org.slf4j.Logger;
    +import org.slf4j.LoggerFactory;
    +
    +public class SocketClientSink<IN> extends RichSinkFunction<IN> {
    --- End diff --
    
    Can you add a docstring for the class to explain its purpose?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] flink pull request: [FLINK-1688] Socket client sink added

Posted by mbalassi <gi...@git.apache.org>.
Github user mbalassi commented on the pull request:

    https://github.com/apache/flink/pull/484#issuecomment-84060511
  
    Thanks, LGTM. Merging it tomorrow.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] flink pull request: [FLINK-1688] Socket client sink added

Posted by hsaputra <gi...@git.apache.org>.
Github user hsaputra commented on the pull request:

    https://github.com/apache/flink/pull/484#issuecomment-84086653
  
    @mbalassi, @miguel0afd seemed like the PR contains more commits than the one targeted for the patch.
    
    Be careful when merging it bc it could murky the history.
    
    I would suggest create clean branch and do rebase instead of merge to keep history clean.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] flink pull request: [FLINK-1688] Socket client sink added

Posted by miguel0afd <gi...@git.apache.org>.
Github user miguel0afd commented on the pull request:

    https://github.com/apache/flink/pull/484#issuecomment-83221889
  
    Documentation patch sent: https://issues.apache.org/jira/browse/FLINK-1688


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] flink pull request: [FLINK-1688] Socket client sink added

Posted by miguel0afd <gi...@git.apache.org>.
Github user miguel0afd commented on the pull request:

    https://github.com/apache/flink/pull/484#issuecomment-84057923
  
    New suggestions added to the code


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] flink pull request: [FLINK-1688] Socket client sink added

Posted by mxm <gi...@git.apache.org>.
Github user mxm commented on a diff in the pull request:

    https://github.com/apache/flink/pull/484#discussion_r26483479
  
    --- Diff: flink-staging/flink-streaming/flink-streaming-connectors/src/main/java/org/apache/flink/streaming/connectors/socket/SocketClientSink.java ---
    @@ -0,0 +1,107 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements.  See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You under the Apache License, Version 2.0
    + * (the "License"); you may not use this file except in compliance with
    + * the License.  You may obtain a copy of the License at
    + *
    + *	http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +
    +package org.apache.flink.streaming.connectors.socket;
    +
    +import java.io.DataOutputStream;
    +import java.io.IOException;
    +import java.io.OutputStream;
    +import java.net.Socket;
    +
    +import org.apache.flink.configuration.Configuration;
    +import org.apache.flink.streaming.api.function.sink.RichSinkFunction;
    +import org.apache.flink.streaming.connectors.util.SerializationSchema;
    +import org.slf4j.Logger;
    +import org.slf4j.LoggerFactory;
    +
    +public class SocketClientSink<IN> extends RichSinkFunction<IN> {
    +	private static final long serialVersionUID = 1L;
    +
    +	private static final Logger LOG = LoggerFactory.getLogger(SocketClientSink.class);
    +
    +	private final String hostName;
    +	private final int port;
    +	private final SerializationSchema<IN, byte[]> scheme;
    +	private transient Socket client;
    +	private transient DataOutputStream dataOutputStream;
    +
    +	public SocketClientSink(String hostName, int port, SerializationSchema<IN, byte[]> schema) {
    +		this.hostName = hostName;
    +		this.port = port;
    +		this.scheme = schema;
    +	}
    +
    +	/**
    +	 * Initializes the connection to Socket.
    +	 */
    +	public void initialize() {
    --- End diff --
    
    really? :) You could call this method `intializeConnection` like its counterpart `closeConnection`.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] flink pull request: [FLINK-1688] Socket client sink added

Posted by asfgit <gi...@git.apache.org>.
Github user asfgit closed the pull request at:

    https://github.com/apache/flink/pull/484


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] flink pull request: [FLINK-1688] Socket client sink added

Posted by mxm <gi...@git.apache.org>.
Github user mxm commented on a diff in the pull request:

    https://github.com/apache/flink/pull/484#discussion_r26483463
  
    --- Diff: flink-staging/flink-streaming/flink-streaming-connectors/src/main/java/org/apache/flink/streaming/connectors/socket/SocketClientSink.java ---
    @@ -0,0 +1,107 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements.  See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You under the Apache License, Version 2.0
    + * (the "License"); you may not use this file except in compliance with
    + * the License.  You may obtain a copy of the License at
    + *
    + *	http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +
    +package org.apache.flink.streaming.connectors.socket;
    +
    +import java.io.DataOutputStream;
    +import java.io.IOException;
    +import java.io.OutputStream;
    +import java.net.Socket;
    +
    +import org.apache.flink.configuration.Configuration;
    +import org.apache.flink.streaming.api.function.sink.RichSinkFunction;
    +import org.apache.flink.streaming.connectors.util.SerializationSchema;
    +import org.slf4j.Logger;
    +import org.slf4j.LoggerFactory;
    +
    +public class SocketClientSink<IN> extends RichSinkFunction<IN> {
    +	private static final long serialVersionUID = 1L;
    +
    +	private static final Logger LOG = LoggerFactory.getLogger(SocketClientSink.class);
    +
    +	private final String hostName;
    +	private final int port;
    +	private final SerializationSchema<IN, byte[]> scheme;
    +	private transient Socket client;
    +	private transient DataOutputStream dataOutputStream;
    +
    +	public SocketClientSink(String hostName, int port, SerializationSchema<IN, byte[]> schema) {
    +		this.hostName = hostName;
    +		this.port = port;
    +		this.scheme = schema;
    +	}
    +
    +	/**
    +	 * Initializes the connection to Socket.
    +	 */
    +	public void initialize() {
    +		OutputStream outputStream;
    +		try {
    +			client = new Socket(hostName, port);
    +			outputStream = client.getOutputStream();
    +		} catch (IOException e) {
    +			throw new RuntimeException(e);
    +		}
    +		dataOutputStream = new DataOutputStream(outputStream);
    +	}
    +
    +	/**
    +	 * Called when new data arrives to the sink, and forwards it to Socket.
    +	 *
    +	 * @param value
    +	 *			The incoming data
    +	 */
    +	@Override
    +	public void invoke(IN value) {
    +		byte[] msg = scheme.serialize(value);
    +		try {
    +			dataOutputStream.write(msg);
    +		} catch (IOException e) {
    +			if(LOG.isErrorEnabled()){
    +				LOG.error("Cannot send message to socket server at {}:{}", hostName, port);
    +			}
    +		}
    +	}
    +
    +	/**
    +	 * Closes the connection.
    +	 */
    +	private void closeConnection(){
    --- End diff --
    
    really? :)


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---