This is an automated email from the ASF dual-hosted git repository.

mhubail pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/asterixdb.git


The following commit(s) were added to refs/heads/master by this push:
     new 0ae8aeb  [NO ISSUE][STO] Use actual server address in RequestReference
0ae8aeb is described below

commit 0ae8aeb10d50cf8041d9287afd82f2a098f68082
Author: Murtadha Hubail <[email protected]>
AuthorDate: Fri Sep 4 14:22:15 2020 +0300

    [NO ISSUE][STO] Use actual server address in RequestReference
    
    - user model changes: no
    - storage format changes: no
    - interface changes: yes
    
    Details:
    
    - Add server local address to IServletRequest.
    - Use actual server address in IRequestReference rather
      than fixed node name.
    
    Change-Id: I8ff2f4e83ffe1a75753b89e68cae2a9264bdf20b
    Reviewed-on: https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/7823
    Integration-Tests: Jenkins <[email protected]>
    Tested-by: Jenkins <[email protected]>
    Reviewed-by: Murtadha Hubail <[email protected]>
    Reviewed-by: Ali Alsuliman <[email protected]>
---
 .../java/org/apache/asterix/translator/Receptionist.java     | 11 ++++-------
 .../org/apache/asterix/hyracks/bootstrap/CCApplication.java  |  4 ++--
 .../org/apache/asterix/hyracks/bootstrap/NCApplication.java  |  2 +-
 .../java/org/apache/hyracks/http/api/IServletRequest.java    |  7 +++++++
 .../java/org/apache/hyracks/http/server/BaseRequest.java     | 12 ++++++++++--
 .../apache/hyracks/http/server/FormUrlEncodedRequest.java    |  9 +++++----
 6 files changed, 29 insertions(+), 16 deletions(-)

diff --git 
a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/Receptionist.java
 
b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/Receptionist.java
index ec4fb6f..84bee6a 100644
--- 
a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/Receptionist.java
+++ 
b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/Receptionist.java
@@ -18,6 +18,7 @@
  */
 package org.apache.asterix.translator;
 
+import java.net.InetSocketAddress;
 import java.util.UUID;
 
 import org.apache.asterix.common.api.IClientRequest;
@@ -33,16 +34,12 @@ import org.apache.hyracks.util.NetworkUtil;
 
 public class Receptionist implements IReceptionist {
 
-    private final String node;
-
-    public Receptionist(String node) {
-        this.node = node;
-    }
-
     @Override
     public IRequestReference welcome(IServletRequest request) {
         final String uuid = UUID.randomUUID().toString();
-        final RequestReference ref = RequestReference.of(uuid, node, 
System.currentTimeMillis());
+        final InetSocketAddress localAddress = request.getLocalAddress();
+        final RequestReference ref =
+                RequestReference.of(uuid, 
NetworkUtil.toHostPort(localAddress), System.currentTimeMillis());
         ref.setUserAgent(request.getHeader(HttpHeaders.USER_AGENT));
         ref.setRemoteAddr(NetworkUtil.toHostPort(request.getRemoteAddress()));
         return ref;
diff --git 
a/asterixdb/asterix-app/src/main/java/org/apache/asterix/hyracks/bootstrap/CCApplication.java
 
b/asterixdb/asterix-app/src/main/java/org/apache/asterix/hyracks/bootstrap/CCApplication.java
index 17cf664..d06b8ab 100644
--- 
a/asterixdb/asterix-app/src/main/java/org/apache/asterix/hyracks/bootstrap/CCApplication.java
+++ 
b/asterixdb/asterix-app/src/main/java/org/apache/asterix/hyracks/bootstrap/CCApplication.java
@@ -161,8 +161,8 @@ public class CCApplication extends BaseCCApplication {
         componentProvider = new StorageComponentProvider();
         ccExtensionManager = new CCExtensionManager(new 
ArrayList<>(getExtensions()));
         IGlobalRecoveryManager globalRecoveryManager = 
createGlobalRecoveryManager();
-        appCtx = createApplicationContext(null, globalRecoveryManager, 
lifecycleCoordinator,
-                () -> new Receptionist("CC"), ConfigValidator::new, 
ccExtensionManager, new AdapterFactoryService());
+        appCtx = createApplicationContext(null, globalRecoveryManager, 
lifecycleCoordinator, Receptionist::new,
+                ConfigValidator::new, ccExtensionManager, new 
AdapterFactoryService());
         final CCConfig ccConfig = controllerService.getCCConfig();
         if (System.getProperty("java.rmi.server.hostname") == null) {
             System.setProperty("java.rmi.server.hostname", 
ccConfig.getClusterPublicAddress());
diff --git 
a/asterixdb/asterix-app/src/main/java/org/apache/asterix/hyracks/bootstrap/NCApplication.java
 
b/asterixdb/asterix-app/src/main/java/org/apache/asterix/hyracks/bootstrap/NCApplication.java
index 1036fb2..e90976e 100644
--- 
a/asterixdb/asterix-app/src/main/java/org/apache/asterix/hyracks/bootstrap/NCApplication.java
+++ 
b/asterixdb/asterix-app/src/main/java/org/apache/asterix/hyracks/bootstrap/NCApplication.java
@@ -175,7 +175,7 @@ public class NCApplication extends BaseNCApplication {
     }
 
     protected IReceptionistFactory getReceptionistFactory() {
-        return () -> new Receptionist(nodeId);
+        return Receptionist::new;
     }
 
     protected IConfigValidatorFactory getConfigValidatorFactory() {
diff --git 
a/hyracks-fullstack/hyracks/hyracks-http/src/main/java/org/apache/hyracks/http/api/IServletRequest.java
 
b/hyracks-fullstack/hyracks/hyracks-http/src/main/java/org/apache/hyracks/http/api/IServletRequest.java
index ce1734a..a8996e3 100644
--- 
a/hyracks-fullstack/hyracks/hyracks-http/src/main/java/org/apache/hyracks/http/api/IServletRequest.java
+++ 
b/hyracks-fullstack/hyracks/hyracks-http/src/main/java/org/apache/hyracks/http/api/IServletRequest.java
@@ -96,4 +96,11 @@ public interface IServletRequest {
      * Indicates which scheme the client used making this request
      */
     HttpScheme getScheme();
+
+    /**
+     * Gets the local address of this request
+     *
+     * @return the remote address
+     */
+    InetSocketAddress getLocalAddress();
 }
diff --git 
a/hyracks-fullstack/hyracks/hyracks-http/src/main/java/org/apache/hyracks/http/server/BaseRequest.java
 
b/hyracks-fullstack/hyracks/hyracks-http/src/main/java/org/apache/hyracks/http/server/BaseRequest.java
index bd56eb3..f5749b1 100644
--- 
a/hyracks-fullstack/hyracks/hyracks-http/src/main/java/org/apache/hyracks/http/server/BaseRequest.java
+++ 
b/hyracks-fullstack/hyracks/hyracks-http/src/main/java/org/apache/hyracks/http/server/BaseRequest.java
@@ -38,17 +38,20 @@ public class BaseRequest implements IServletRequest {
     protected final Map<String, List<String>> parameters;
     protected final InetSocketAddress remoteAddress;
     protected final HttpScheme scheme;
+    protected final InetSocketAddress localAddress;
 
     public static IServletRequest create(ChannelHandlerContext ctx, 
FullHttpRequest request, HttpScheme scheme) {
         QueryStringDecoder decoder = new QueryStringDecoder(request.uri());
         Map<String, List<String>> param = decoder.parameters();
         InetSocketAddress remoteAddress = (InetSocketAddress) 
ctx.channel().remoteAddress();
-        return new BaseRequest(request, remoteAddress, param, scheme);
+        InetSocketAddress localAddress = (InetSocketAddress) 
ctx.channel().localAddress();
+        return new BaseRequest(request, localAddress, remoteAddress, param, 
scheme);
     }
 
-    protected BaseRequest(FullHttpRequest request, InetSocketAddress 
remoteAddress,
+    protected BaseRequest(FullHttpRequest request, InetSocketAddress 
localAddress, InetSocketAddress remoteAddress,
             Map<String, List<String>> parameters, HttpScheme scheme) {
         this.request = request;
+        this.localAddress = localAddress;
         this.remoteAddress = remoteAddress;
         this.parameters = parameters;
         this.scheme = scheme;
@@ -99,4 +102,9 @@ public class BaseRequest implements IServletRequest {
     public HttpScheme getScheme() {
         return scheme;
     }
+
+    @Override
+    public InetSocketAddress getLocalAddress() {
+        return localAddress;
+    }
 }
diff --git 
a/hyracks-fullstack/hyracks/hyracks-http/src/main/java/org/apache/hyracks/http/server/FormUrlEncodedRequest.java
 
b/hyracks-fullstack/hyracks/hyracks-http/src/main/java/org/apache/hyracks/http/server/FormUrlEncodedRequest.java
index 0e57d8d..de6ed72 100644
--- 
a/hyracks-fullstack/hyracks/hyracks-http/src/main/java/org/apache/hyracks/http/server/FormUrlEncodedRequest.java
+++ 
b/hyracks-fullstack/hyracks/hyracks-http/src/main/java/org/apache/hyracks/http/server/FormUrlEncodedRequest.java
@@ -44,11 +44,12 @@ public class FormUrlEncodedRequest extends BaseRequest 
implements IServletReques
         new QueryStringDecoder(request.uri()).parameters()
                 .forEach((name, value) -> parameters.computeIfAbsent(name, a 
-> new ArrayList<>()).addAll(value));
         InetSocketAddress remoteAddress = (InetSocketAddress) 
ctx.channel().remoteAddress();
-        return new FormUrlEncodedRequest(request, remoteAddress, parameters, 
scheme);
+        InetSocketAddress localAddress = (InetSocketAddress) 
ctx.channel().localAddress();
+        return new FormUrlEncodedRequest(request, localAddress, remoteAddress, 
parameters, scheme);
     }
 
-    private FormUrlEncodedRequest(FullHttpRequest request, InetSocketAddress 
remoteAddress,
-            Map<String, List<String>> parameters, HttpScheme scheme) {
-        super(request, remoteAddress, parameters, scheme);
+    private FormUrlEncodedRequest(FullHttpRequest request, InetSocketAddress 
localAddress,
+            InetSocketAddress remoteAddress, Map<String, List<String>> 
parameters, HttpScheme scheme) {
+        super(request, localAddress, remoteAddress, parameters, scheme);
     }
 }

Reply via email to