• Flink on yarn 加载失败plugins失效问题解决


    Flink on yarn 加载失败plugins失效问题解决

    flink版本:1.13.6

    1. 问题

    flink 任务运行在yarn集群,plugins加载失效,导致通过扩展资源获取任务参数失效

    2. 问题定位

    1. yarn容器的jar包及插件信息,jar包是正常上传
      在这里插入图片描述

    2. 源码定位
      加载plugins入口,TaskManagerRunner.class
      PluginUtils.createPluginManagerFromRootFolder
      在这里插入图片描述
      源码加载扩展资源参数入口TaskManagerRunner.class
      ExternalResourceUtils.createStaticExternalResourceInfoProviderFromConfig
      在这里插入图片描述
      日志信息
      在这里插入图片描述
      定位PluginConfig源码
      在这里插入图片描述

    3. 方案

    重写覆盖集群的PluginConfig.java,优先从configurtaion获取

    /*
     * 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.core.plugin;
    
    import com.alibaba.fastjson.JSON;
    import org.apache.commons.lang3.StringUtils;
    import org.apache.flink.configuration.*;
    
    import org.slf4j.Logger;
    import org.slf4j.LoggerFactory;
    
    import java.io.File;
    import java.nio.file.Path;
    import java.util.Arrays;
    import java.util.Objects;
    import java.util.Optional;
    
    /** Stores the configuration for plugins mechanism. */
    @SuppressWarnings("OptionalUsedAsFieldOrParameterType")
    public class PluginConfig {
        private static final Logger LOG = LoggerFactory.getLogger(PluginConfig.class);
    
        private static final String PUPU_FLINK_PLUGINS_DIR = "flink_plugins_dir";
    
        private final Optional<Path> pluginsPath;
    
        private final String[] alwaysParentFirstPatterns;
    
        private PluginConfig(Optional<Path> pluginsPath, String[] alwaysParentFirstPatterns) {
            pluginsPath.ifPresent(path -> LOG.info("pluginsPath: {}", path));
            LOG.info("alwaysParentFirstPatterns: {}", Arrays.stream(alwaysParentFirstPatterns).toArray());
            this.pluginsPath = pluginsPath;
            this.alwaysParentFirstPatterns = alwaysParentFirstPatterns;
        }
    
        public Optional<Path> getPluginsPath() {
            return pluginsPath;
        }
    
        public String[] getAlwaysParentFirstPatterns() {
            return alwaysParentFirstPatterns;
        }
    
        public static PluginConfig fromConfiguration(Configuration configuration) {
            return new PluginConfig(
                    getPluginsDir(configuration).map(File::toPath),
                    CoreOptions.getPluginParentFirstLoaderPatterns(configuration));
        }
    
        public static Optional<File> getPluginsDir(Configuration configuration) {
            String pluginsDir = configuration.get(ConfigOptions.key(PUPU_FLINK_PLUGINS_DIR).stringType().defaultValue(null));
            if (StringUtils.isBlank(pluginsDir)) {
                pluginsDir =
                        System.getenv()
                                .getOrDefault(
                                        ConfigConstants.ENV_FLINK_PLUGINS_DIR,
                                        ConfigConstants.DEFAULT_FLINK_PLUGINS_DIRS);
            }
            File pluginsDirFile = new File(pluginsDir);
            if (!pluginsDirFile.isDirectory()) {
                LOG.warn("The plugins directory [{}] does not exist.", pluginsDirFile);
                return Optional.empty();
            }
            return Optional.of(pluginsDirFile);
        }
    
    }
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
  • 相关阅读:
    【STM32】SD卡
    mycat
    Pytorch导出onnx模型,C++转化为TensorRT并实现推理过程
    java毕业设计网上商城购物系统mybatis+源码+调试部署+系统+数据库+lw
    Python之作业(三)
    Go-Excelize API源码阅读(四十)——SetCellRichText
    安果计算器-您的全能计算伴侣
    DMNet复现(一)之数据准备篇:Density map guided object detection in aerial image
    算法拾遗十七之二叉树的基本算法+二叉树的递归套路
    Python数据可视化------下载数据
  • 原文地址:https://blog.csdn.net/qq_27242695/article/details/134056372