[
https://issues.apache.org/jira/browse/FLINK-7527?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16171606#comment-16171606
]
ASF GitHub Bot commented on FLINK-7527:
---------------------------------------
Github user tillrohrmann commented on a diff in the pull request:
https://github.com/apache/flink/pull/4597#discussion_r139676205
--- Diff:
flink-runtime/src/main/java/org/apache/flink/runtime/rest/handler/RedirectHandler.java
---
@@ -0,0 +1,174 @@
+/*
+ * 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.rest.handler;
+
+import org.apache.flink.api.common.time.Time;
+import org.apache.flink.runtime.rest.handler.util.HandlerRedirectUtils;
+import org.apache.flink.runtime.rest.handler.util.HandlerUtils;
+import org.apache.flink.runtime.rest.messages.ErrorResponseBody;
+import org.apache.flink.runtime.webmonitor.RestfulGateway;
+import org.apache.flink.runtime.webmonitor.retriever.GatewayRetriever;
+import org.apache.flink.util.FlinkException;
+import org.apache.flink.util.OptionalConsumer;
+import org.apache.flink.util.Preconditions;
+
+import org.apache.flink.shaded.netty4.io.netty.channel.ChannelHandler;
+import
org.apache.flink.shaded.netty4.io.netty.channel.ChannelHandlerContext;
+import
org.apache.flink.shaded.netty4.io.netty.channel.SimpleChannelInboundHandler;
+import
org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpResponse;
+import
org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpResponseStatus;
+import
org.apache.flink.shaded.netty4.io.netty.handler.codec.http.router.KeepAliveWrite;
+import
org.apache.flink.shaded.netty4.io.netty.handler.codec.http.router.Routed;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.annotation.Nonnull;
+
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * {@link SimpleChannelInboundHandler} which encapsulates the redirection
logic for the
+ * REST endpoints.
+ *
+ * @param <T> type of the leader to retrieve
+ */
[email protected]
+public abstract class RedirectHandler<T extends RestfulGateway> extends
SimpleChannelInboundHandler<Routed> {
+
+ protected final Logger logger = LoggerFactory.getLogger(getClass());
+
+ private final CompletableFuture<String> localAddressFuture;
+
+ protected final GatewayRetriever<T> leaderRetriever;
+
+ protected final Time timeout;
+
+ /** Whether the web service has https enabled. */
+ protected final boolean httpsEnabled;
+
+ private String localAddress;
+
+ protected RedirectHandler(
+ @Nonnull CompletableFuture<String> localAddressFuture,
+ @Nonnull GatewayRetriever<T> leaderRetriever,
+ @Nonnull Time timeout,
+ boolean httpsEnabled) {
+ this.localAddressFuture =
Preconditions.checkNotNull(localAddressFuture);
+ this.leaderRetriever =
Preconditions.checkNotNull(leaderRetriever);
+ this.timeout = Preconditions.checkNotNull(timeout);
+ this.httpsEnabled = httpsEnabled;
+ localAddress = null;
+ }
+
+ @Override
+ protected void channelRead0(
+ ChannelHandlerContext channelHandlerContext,
+ Routed routed) throws Exception {
+
+ try {
+ if (localAddressFuture.isDone()) {
+ if (localAddress == null) {
+ try {
+ localAddress =
localAddressFuture.get(timeout.toMilliseconds(), TimeUnit.MILLISECONDS);
+ } catch (Exception e) {
+ logger.error("Could not obtain
local address.", e);
+
+ HandlerUtils.sendErrorResponse(
+ channelHandlerContext,
+ routed.request(),
+ new
ErrorResponseBody(new FlinkException("Could not obtain local address.", e)),
--- End diff --
Alright. Will remove them.
> Add redirection logic to AbstractRestHandler
> --------------------------------------------
>
> Key: FLINK-7527
> URL: https://issues.apache.org/jira/browse/FLINK-7527
> Project: Flink
> Issue Type: Improvement
> Components: REST
> Affects Versions: 1.4.0
> Reporter: Till Rohrmann
> Assignee: Till Rohrmann
> Labels: flip-6
>
> The {{AbstractRestHandler}} should extend the {{RedirectHandler}} introduced
> with FLINK-7459 in order to add redirection functionality to the
> {{AbstractRestHandler}}.
--
This message was sent by Atlassian JIRA
(v6.4.14#64029)