tillrohrmann commented on a change in pull request #16265:
URL: https://github.com/apache/flink/pull/16265#discussion_r660540058



##########
File path: 
flink-runtime/src/main/java/org/apache/flink/runtime/rpc/akka/AkkaRpcSystem.java
##########
@@ -0,0 +1,68 @@
+/*
+ * 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.runtime.rpc.akka;
+
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.runtime.akka.AkkaUtils;
+import org.apache.flink.runtime.rpc.AddressResolution;
+import org.apache.flink.runtime.rpc.RpcSystem;
+
+import javax.annotation.Nullable;
+
+import java.net.InetSocketAddress;
+import java.net.UnknownHostException;
+
+/** {@link RpcSystem} implementation based on Akka. */
+public class AkkaRpcSystem implements RpcSystem {
+
+    @Override
+    public RpcServiceBuilder localServiceBuilder(Configuration configuration) {
+        return AkkaRpcServiceUtils.localServiceBuilder(configuration);
+    }
+
+    @Override
+    public RpcServiceBuilder remoteServiceBuilder(
+            Configuration configuration,
+            @Nullable String externalAddress,
+            String externalPortRange) {
+        return AkkaRpcServiceUtils.remoteServiceBuilder(
+                configuration, externalAddress, externalPortRange);
+    }
+
+    @Override
+    public InetSocketAddress getInetSocketAddressFromRpcUrl(String url) throws 
Exception {
+        return AkkaUtils.getInetSocketAddressFromAkkaURL(url);

Review comment:
       Should we unify `AkkaUtils` and `AkkaRpcServiceUtils`?

##########
File path: 
flink-runtime/src/main/java/org/apache/flink/runtime/rpc/RpcSystemUtils.java
##########
@@ -0,0 +1,55 @@
+/*
+ * 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.runtime.rpc;
+
+import org.apache.flink.configuration.Configuration;
+
+import javax.annotation.Nullable;
+
+import java.util.Optional;
+
+/** Utils related to the {@link RpcSystem}. */
+public final class RpcSystemUtils {
+
+    /**
+     * Convenient shortcut for constructing a remote RPC Service that takes 
care of checking for
+     * null and empty optionals.
+     *
+     * @see RpcSystem#remoteServiceBuilder(Configuration, String, String)
+     */
+    public static RpcService createRemoteRpcService(

Review comment:
       Does it make sense to move this method into the `RpcUtils` class? The 
downside of introducing a new `RpcSystemUtils` class is that helper methods are 
harder to find.

##########
File path: 
flink-metrics/flink-metrics-prometheus/src/test/java/org/apache/flink/metrics/prometheus/PrometheusReporterTest.java
##########
@@ -85,7 +85,7 @@
     public void setupReporter() {
         registry =
                 new MetricRegistryImpl(
-                        
MetricRegistryConfiguration.defaultMetricRegistryConfiguration(),
+                        
MetricRegistryTestUtils.defaultMetricRegistryConfiguration(),

Review comment:
       Alternatively, this might indicate that the reporters are not super easy 
to test since we require the registry.

##########
File path: 
flink-runtime/src/main/java/org/apache/flink/runtime/rpc/RpcSystem.java
##########
@@ -0,0 +1,185 @@
+/*
+ * 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.runtime.rpc;
+
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.runtime.rpc.akka.AkkaRpcSystem;
+
+import javax.annotation.Nullable;
+
+import java.net.InetSocketAddress;
+import java.net.UnknownHostException;
+
+/**
+ * This interface serves as a factory interface for RPC services, with some 
additional utilities
+ * that are reliant on implementation details of the RPC service.
+ */
+public interface RpcSystem {
+
+    /**
+     * Returns a builder for an {@link RpcService} that is only reachable from 
the local machine.
+     *
+     * @param configuration Flink configuration
+     * @return rpc service builder
+     */
+    RpcServiceBuilder localServiceBuilder(Configuration configuration);
+
+    /**
+     * Returns a builder for an {@link RpcService} that is reachable from 
other machines.
+     *
+     * @param configuration Flink configuration
+     * @param externalAddress optional address under which the RpcService 
should be reachable
+     * @param externalPortRange port range from which 1 port will be chosen 
under which the
+     *     RpcService should be reachable
+     * @return rpc service builder
+     */
+    RpcServiceBuilder remoteServiceBuilder(
+            Configuration configuration,
+            @Nullable String externalAddress,
+            String externalPortRange);
+
+    /**
+     * Constructs an RPC URL for the given parameters, that can be used to 
connect to the targeted
+     * RpcService.
+     *
+     * @param hostname The hostname or address where the target RPC service is 
listening.
+     * @param port The port where the target RPC service is listening.
+     * @param endpointName The name of the RPC endpoint.
+     * @param addressResolution Whether to try address resolution of the given 
hostname or not. This
+     *     allows to fail fast in case that the hostname cannot be resolved.
+     * @param config The configuration from which to deduce further settings.
+     * @return The RPC URL of the specified RPC endpoint.
+     */
+    String getRpcUrl(
+            String hostname,
+            int port,
+            String endpointName,
+            AddressResolution addressResolution,
+            Configuration config)
+            throws UnknownHostException;
+
+    /**
+     * Returns an {@link InetSocketAddress} corresponding to the given RPC url.
+     *
+     * @see #getRpcUrl
+     * @param url RPC url
+     * @return inet socket address
+     * @throws Exception if the URL is invalid
+     */
+    InetSocketAddress getInetSocketAddressFromRpcUrl(String url) throws 
Exception;
+
+    /**
+     * Returns the maximum number of bytes that an RPC message may carry 
according to the given
+     * configuration. If no limit exists then {@link Long#MAX_VALUE} should be 
returned.
+     *
+     * @param config Flink configuration
+     * @return maximum number of bytes that an RPC message may carry
+     */
+    long getMaximumMessageSizeInBytes(Configuration config);

Review comment:
       We might think about creating a separate `RpcSystemUtils` interface for 
these methods which the `RpcSystem` extends. That way, we have a better 
interface segregation. Especially, for all the methods which don't need the 
builders.

##########
File path: 
flink-metrics/flink-metrics-prometheus/src/test/java/org/apache/flink/metrics/prometheus/PrometheusReporterTest.java
##########
@@ -85,7 +85,7 @@
     public void setupReporter() {
         registry =
                 new MetricRegistryImpl(
-                        
MetricRegistryConfiguration.defaultMetricRegistryConfiguration(),
+                        
MetricRegistryTestUtils.defaultMetricRegistryConfiguration(),

Review comment:
       This is a bit unrelated to this change. But it looks to me that this 
test is more of an integration test which could go into `flink-tests` because 
we use things from `flink-runtime`.




-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to