You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by GitBox <gi...@apache.org> on 2020/02/10 11:18:28 UTC

[GitHub] [flink-statefun] igalshilman opened a new pull request #19: [FLINK-15956] Add HTTP function protocol

igalshilman opened a new pull request #19: [FLINK-15956] Add HTTP function protocol
URL: https://github.com/apache/flink-statefun/pull/19
 
 
   ### Work in progress PR
   
   This PR introduces an `HttpFunction`,  an extension to stateful functions that allows invoking 
   remote functions exposed via an HTTP endpoint.
   
   As a reminder, users can specify an http function by providing an `module.yaml`
   with the following section:
   ```
   module:
     ..
     spec:
       functions:
         - function:
             meta:
               kind: http
               type: com.foobar/world
             spec:
               endpoint: foobar.com:5959/statefun
               states:
                - seen_count
     ...
   ```
   The definition above implies the following:
   - that there is a function running behind an HTTP server located at `foobar.com`, port `5959` under the path `/statefun`.
   - Parsing this module, would create a `StatefulFunction` of type `HttpFunction` that would act as a proxy for the function located at that url.
   -   Any messages sent to `Address(FunctionType("com.foobar", "world"), KEY)` would be directed to an instance of the `HttpFunction` responsible for `KEY` which is responsible for forwarding the message to the actual function at `foobar.com:5959/statefun`.
   
   The on the wire communication format is a set of Protocol Buffers messages defined at `http-function.proto`.
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [flink-statefun] StephanEwen commented on a change in pull request #19: [FLINK-15956] Add HTTP function protocol

Posted by GitBox <gi...@apache.org>.
StephanEwen commented on a change in pull request #19: [FLINK-15956] Add HTTP function protocol
URL: https://github.com/apache/flink-statefun/pull/19#discussion_r379549979
 
 

 ##########
 File path: statefun-flink/statefun-flink-core/src/main/java/org/apache/flink/statefun/flink/core/common/PolyglotUtil.java
 ##########
 @@ -0,0 +1,53 @@
+/*
+ * 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.statefun.flink.core.common;
+
+import com.google.protobuf.Message;
+import com.google.protobuf.Parser;
+import java.io.IOException;
+import java.io.InputStream;
+import javax.annotation.Nonnull;
+import org.apache.flink.statefun.flink.core.polyglot.generated.Address;
+import org.apache.flink.statefun.sdk.FunctionType;
+
+public final class PolyglotUtil {
+  private PolyglotUtil() {}
+
+  public static <M extends Message> M parseProtobufOrThrow(Parser<M> parser, InputStream input) {
+    try {
+      return parser.parseFrom(input);
+    } catch (IOException e) {
+      throw new IllegalStateException("Unable to parse a Protobuf message", e);
+    }
+  }
+
+  public static Address sdkAddressToPolyglotAddress(
+      @Nonnull org.apache.flink.statefun.sdk.Address sdkAddress) {
 
 Review comment:
   Nit: `@Nonnull` is not used in any other method, despite accepting only non-null values.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [flink-statefun] StephanEwen commented on issue #19: [FLINK-15956] Add HTTP function protocol

Posted by GitBox <gi...@apache.org>.
StephanEwen commented on issue #19: [FLINK-15956] Add HTTP function protocol
URL: https://github.com/apache/flink-statefun/pull/19#issuecomment-586388713
 
 
   Thanks! Merging this...

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [flink-statefun] StephanEwen merged pull request #19: [FLINK-15956] Add HTTP function protocol

Posted by GitBox <gi...@apache.org>.
StephanEwen merged pull request #19: [FLINK-15956] Add HTTP function protocol
URL: https://github.com/apache/flink-statefun/pull/19
 
 
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [flink-statefun] StephanEwen commented on a change in pull request #19: [FLINK-15956] Add HTTP function protocol

Posted by GitBox <gi...@apache.org>.
StephanEwen commented on a change in pull request #19: [FLINK-15956] Add HTTP function protocol
URL: https://github.com/apache/flink-statefun/pull/19#discussion_r379540884
 
 

 ##########
 File path: statefun-flink/statefun-flink-core/src/main/java/org/apache/flink/statefun/flink/core/backpressure/SystemNanoTimer.java
 ##########
 @@ -0,0 +1,50 @@
+/*
+ * 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.statefun.flink.core.backpressure;
+
+import static java.util.concurrent.TimeUnit.NANOSECONDS;
+
+/** A {@code Timer} backed by {@link System#nanoTime()}. */
+final class SystemNanoTimer implements Timer {
+  private static final SystemNanoTimer INSTANCE = new SystemNanoTimer();
+
+  public static SystemNanoTimer instance() {
+    return INSTANCE;
+  }
+
+  private SystemNanoTimer() {}
+
+  @Override
+  public long now() {
+    return System.nanoTime();
+  }
+
+  @Override
+  public void sleep(long sleepTimeNanos) {
+    try {
+      final long sleepTimeMs = NANOSECONDS.toMillis(sleepTimeNanos);
+      Thread.sleep(sleepTimeMs);
+    } catch (InterruptedException ex) {
+      if (Thread.interrupted()) {
 
 Review comment:
   I think this will always be false because the Thread's interruption flag is cleared when the InterruptedException is thrown.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services