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);
    }

}
相关推荐
AI推荐率6 小时前
想让AI在选购问题中推荐品牌,应该找什么类型的服务商?
大数据·人工智能·microsoft
浅思科技集6 小时前
工业生产运营软件如何选择?看端到端可见性、数据贯通与AI落地
大数据·人工智能
浅念-7 小时前
一文吃透Git:本地操作|冲突处理|远程协作|GitFlow工作流详解
大数据·git·elasticsearch·搜索引擎·gitflow
葫三生7 小时前
《论三生原理》神话学构想与“神话历史”理论、《古史中的神话》思路异同?
大数据·人工智能·科技·深度学习·算法
国科安芯7 小时前
星链供电架构中的高集成度电源管理方案研究——基于ASP4644四通道降压稳压器在低轨卫星星座中的应用分析
大数据·单片机·嵌入式硬件·架构·低轨卫星·星间链路
小王毕业啦7 小时前
2011-2024年 各地级市养老服务信息面板数据 xlsx
大数据·人工智能·数据挖掘·数据分析·社科数据·实证分析·经管数据
ailsa_hui8 小时前
对于医疗器械行业,鼎捷的ERP有成熟的行业解决方案和合规性支持吗?
大数据
资讯综合9 小时前
500亿招聘市场悖论:AI技术能否填平行业的信任深坑
大数据·人工智能
百胜软件@百胜软件10 小时前
胜券AI的Skills可插拔技能包,让零售AI从“泛”到“专”
大数据·人工智能·零售
汇智信科10 小时前
基于 Jmis 框架的制度与流程管控系统设计与应用|项目全生命周期管理
大数据·人工智能·微服务·云原生·汇智信科