flink-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "ASF GitHub Bot (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (FLINK-9599) Implement generic mechanism to receive files via rest
Date Thu, 21 Jun 2018 08:41:00 GMT

    [ https://issues.apache.org/jira/browse/FLINK-9599?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16519080#comment-16519080
] 

ASF GitHub Bot commented on FLINK-9599:
---------------------------------------

Github user zentol commented on a diff in the pull request:

    https://github.com/apache/flink/pull/6178#discussion_r197053400
  
    --- Diff: flink-runtime/src/test/java/org/apache/flink/runtime/rest/AbstractHandlerTest.java
---
    @@ -0,0 +1,190 @@
    +/*
    + * 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;
    +
    +import org.apache.flink.runtime.rest.handler.FileUploads;
    +import org.apache.flink.runtime.rest.handler.HandlerRequest;
    +import org.apache.flink.runtime.rest.handler.RestHandlerException;
    +import org.apache.flink.runtime.rest.handler.router.RouteResult;
    +import org.apache.flink.runtime.rest.handler.router.RoutedRequest;
    +import org.apache.flink.runtime.rest.messages.EmptyMessageParameters;
    +import org.apache.flink.runtime.rest.messages.EmptyRequestBody;
    +import org.apache.flink.runtime.rest.messages.UntypedResponseMessageHeaders;
    +import org.apache.flink.runtime.rpc.RpcUtils;
    +import org.apache.flink.runtime.webmonitor.RestfulGateway;
    +import org.apache.flink.runtime.webmonitor.TestingRestfulGateway;
    +import org.apache.flink.runtime.webmonitor.retriever.GatewayRetriever;
    +
    +import org.apache.flink.shaded.netty4.io.netty.buffer.Unpooled;
    +import org.apache.flink.shaded.netty4.io.netty.channel.Channel;
    +import org.apache.flink.shaded.netty4.io.netty.channel.ChannelHandlerContext;
    +import org.apache.flink.shaded.netty4.io.netty.handler.codec.http.DefaultFullHttpRequest;
    +import org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpMethod;
    +import org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpRequest;
    +import org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpVersion;
    +import org.apache.flink.shaded.netty4.io.netty.util.Attribute;
    +import org.apache.flink.shaded.netty4.io.netty.util.AttributeKey;
    +
    +import org.junit.Assert;
    +import org.junit.Rule;
    +import org.junit.Test;
    +import org.junit.rules.TemporaryFolder;
    +
    +import javax.annotation.Nonnull;
    +
    +import java.nio.file.Files;
    +import java.nio.file.Path;
    +import java.util.Collections;
    +import java.util.concurrent.CompletableFuture;
    +import java.util.concurrent.atomic.AtomicReference;
    +
    +import static org.mockito.Matchers.any;
    +import static org.mockito.Mockito.mock;
    +import static org.mockito.Mockito.when;
    +
    +/**
    + * Tests for {@link AbstractHandler}.
    + */
    +public class AbstractHandlerTest {
    +
    +	@Rule
    +	public final TemporaryFolder temporaryFolder = new TemporaryFolder();
    +
    +	@Test
    +	public void testFileCleanup() throws Exception {
    +		final Path file = temporaryFolder.newFile().toPath();
    +
    +		final String restAddress = "http://localhost:1234";
    +		RestfulGateway mockRestfulGateway = TestingRestfulGateway.newBuilder()
    +			.setRestAddress(restAddress)
    +			.build();
    +
    +		final GatewayRetriever<RestfulGateway> mockGatewayRetriever = () ->
    +			CompletableFuture.completedFuture(mockRestfulGateway);
    +
    +		TestHandler handler = new TestHandler(CompletableFuture.completedFuture(restAddress),
mockGatewayRetriever);
    +
    +		RouteResult<?> routeResult = new RouteResult<>("", "", Collections.emptyMap(),
Collections.emptyMap(), "");
    +		HttpRequest request = new DefaultFullHttpRequest(
    +			HttpVersion.HTTP_1_1,
    +			HttpMethod.GET,
    +			TestHandler.TestHeaders.INSTANCE.getTargetRestEndpointURL(),
    +			Unpooled.wrappedBuffer(new byte[0]));
    +		RoutedRequest<?> routerRequest = new RoutedRequest<>(routeResult, request);
    +
    +		Attribute<FileUploads> attribute = new SimpleAttribute();
    +		attribute.set(new FileUploads(Collections.emptyList(), Collections.singleton(file)));
    +		Channel channel = mock(Channel.class);
    +		when(channel.attr(any(AttributeKey.class))).thenReturn(attribute);
    +
    +		ChannelHandlerContext context = mock(ChannelHandlerContext.class);
    +		when(context.channel()).thenReturn(channel);
    --- End diff --
    
    Are you referring to the one in `AbstractTaskManagerFileHandlerTest`? If so, I don't really
see a difference between mocking 1 method and having an "implementation" that only really
implements a miniscule subset.
    
    I initially implemented both the `Channel` and `ChannelHandlerContext` with the same behavior
as the mocks, but all that was was add 50+ methods that are just noise.


> Implement generic mechanism to receive files via rest
> -----------------------------------------------------
>
>                 Key: FLINK-9599
>                 URL: https://issues.apache.org/jira/browse/FLINK-9599
>             Project: Flink
>          Issue Type: New Feature
>          Components: REST
>            Reporter: Chesnay Schepler
>            Assignee: Chesnay Schepler
>            Priority: Major
>              Labels: pull-request-available
>             Fix For: 1.6.0
>
>
> As a prerequisite for a cleaner implementation of FLINK-9280 we should
>  * extend the RestClient to allow the upload of Files
>  * extend FileUploadHandler to accept mixed multi-part requests (json + files)
>  * generalize mechanism for accessing uploaded files in {{AbstractHandler}}
> Uploaded files can be forwarded to subsequent handlers as an attribute, similar to the
existing special case for the {{JarUploadHandler}}. The JSON body can be forwarded by replacing
the incoming http requests with a simple {{DefaultFullHttpRequest}}.
> Uploaded files will be retrievable through the {{HandlerRequest}}.
> I'm not certain if/how we can document that a handler accepts files.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Mime
View raw message