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

    https://github.com/apache/flink/pull/5509#discussion_r168922506
  
    --- Diff: 
flink-runtime-web/src/main/java/org/apache/flink/runtime/webmonitor/handlers/JarRunHandler.java
 ---
    @@ -0,0 +1,229 @@
    +/*
    + * 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.webmonitor.handlers;
    +
    +import org.apache.flink.annotation.VisibleForTesting;
    +import org.apache.flink.api.common.time.Time;
    +import org.apache.flink.client.cli.CliFrontend;
    +import org.apache.flink.client.program.PackagedProgram;
    +import org.apache.flink.client.program.ProgramInvocationException;
    +import org.apache.flink.client.program.rest.RestClusterClient;
    +import org.apache.flink.configuration.Configuration;
    +import org.apache.flink.runtime.dispatcher.DispatcherGateway;
    +import org.apache.flink.runtime.jobgraph.JobGraph;
    +import org.apache.flink.runtime.jobgraph.SavepointRestoreSettings;
    +import org.apache.flink.runtime.rest.handler.AbstractRestHandler;
    +import org.apache.flink.runtime.rest.handler.HandlerRequest;
    +import org.apache.flink.runtime.rest.handler.RestHandlerException;
    +import org.apache.flink.runtime.rest.messages.EmptyRequestBody;
    +import org.apache.flink.runtime.rest.messages.MessageHeaders;
    +import org.apache.flink.runtime.rest.messages.MessageQueryParameter;
    +import org.apache.flink.runtime.webmonitor.retriever.GatewayRetriever;
    +
    +import 
org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpResponseStatus;
    +
    +import javax.annotation.Nonnull;
    +import javax.annotation.Nullable;
    +
    +import java.nio.file.Files;
    +import java.nio.file.Path;
    +import java.util.ArrayList;
    +import java.util.Collections;
    +import java.util.List;
    +import java.util.Map;
    +import java.util.concurrent.CompletableFuture;
    +import java.util.concurrent.CompletionException;
    +import java.util.concurrent.Executor;
    +import java.util.regex.Matcher;
    +import java.util.regex.Pattern;
    +
    +import static java.util.Objects.requireNonNull;
    +import static 
org.apache.flink.shaded.guava18.com.google.common.base.Strings.emptyToNull;
    +
    +/**
    + * Handler to submit jobs uploaded via the Web UI.
    + */
    +public class JarRunHandler extends
    +           AbstractRestHandler<DispatcherGateway, EmptyRequestBody, 
JarRunResponseBody, JarRunMessageParameters> {
    +
    +   private static final Pattern ARGUMENTS_TOKENIZE_PATTERN = 
Pattern.compile("([^\"\']\\S*|\".+?\"|\'.+?\')\\s*");
    +
    +   private final Path jarDir;
    +
    +   private final Configuration configuration;
    +
    +   private final Executor executor;
    +
    +   private final RestClusterClient<String> restClusterClient;
    +
    +   public JarRunHandler(
    +                   final CompletableFuture<String> localRestAddress,
    +                   final GatewayRetriever<? extends DispatcherGateway> 
leaderRetriever,
    +                   final Time timeout,
    +                   final Map<String, String> responseHeaders,
    +                   final MessageHeaders<EmptyRequestBody, 
JarRunResponseBody, JarRunMessageParameters> messageHeaders,
    +                   final Path jarDir,
    +                   final Configuration configuration,
    +                   final Executor executor) {
    +           super(localRestAddress, leaderRetriever, timeout, 
responseHeaders, messageHeaders);
    +
    +           this.jarDir = requireNonNull(jarDir);
    +           this.configuration = requireNonNull(configuration);
    +           this.executor = requireNonNull(executor);
    +           try {
    +                   this.restClusterClient = new 
RestClusterClient<>(configuration, "");
    --- End diff --
    
    I think we should move the `RestClusterClient` creation out of the handler 
into the `DispatcherEndpoint`. That way we can also enforce a proper shut down 
of it.


---

Reply via email to