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获取

bash 复制代码
/*
 * 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);
    }

}
相关推荐
小淮AI40 分钟前
国际教育课程的本土化探索:以枫叶教育三十年为观察样本
大数据·人工智能
龙兵AI增长破局圈.赵老师讲成交1 小时前
只有把过程管好,结果才会出来。
大数据·人工智能·ai·创业创新
qq407855602 小时前
面向智能补货需求的进销存系统盘点
大数据·人工智能·低代码·制造
CHENGQUAN_kenan2 小时前
佛山亚马逊卖家出口退税合规指南|9610免税、一般贸易退税、无票采购、申报误区全覆盖
大数据·经验分享·笔记·百度
Web3_Daisy3 小时前
从流动性到执行:如何降低 MEV 对 Web3 市场
大数据·人工智能·web3·区块链
日常通勤穿搭3 小时前
电商 AI 作图用哪个最方便?新手商家 AI 出图工具对比
大数据·人工智能
小淮AI3 小时前
一个国际家庭在武汉的择校笔记:两份外籍人员子女学校的课程方案比较
大数据·人工智能
一只鹿鹿鹿4 小时前
大数据中心安全系统解决方案(Word文件)
大数据·运维·物联网·安全·政务
qq_33776320194 小时前
仿博易大师内外盘国际期货软件源码全套开发:期货交易系统架构设计与核心技术解析
大数据·区块链
盛世宏博智慧档案5 小时前
POE温湿度传感器常见故障排查与优化解决原理
大数据