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

}
相关推荐
数字化顾问4 分钟前
(138页PPT)流程体系的建设优化与运营(附下载方式)
大数据·运维·人工智能
织码weavecodes30 分钟前
培训平台部署备份与容灾:从三服务交付到可恢复运行
大数据·学习·开源软件
天涯明月19931 小时前
世界模型:原理、范式与工程实践
大数据·人工智能·大模型·具身智能·世界模型
梦想画家3 小时前
SQLMesh Python 模型入门(三):前后置语句、蓝图建模与避坑指南
大数据·python·sqlmesh
和裕3 小时前
年度框架直供 vs 零散按需采购:定制纸箱采购成本、交付与服务核心区别全对比
大数据·运维·网络·人工智能·算法
具身AGI4 小时前
ARR还是交付量,物理AI 国产 的三种收入口径
大数据·人工智能
计算机源码社4 小时前
基于大数据技术的城市空气质量时序趋势与站点特征分析系统 面向监测站点的城市空气污染时空异质性分析与可视化系统
大数据·机器学习·数据挖掘·数据分析·毕业设计·课程设计·数据可视化
AC赳赳老秦5 小时前
OpenClaw 数据引用规范自动生成:为公开数据构建可信来源标注与标准引用体系
大数据·开发语言·汇编·数据库·人工智能·deepseek·openclaw
乐迪信息5 小时前
AI防爆摄像机,监测港口船舶航行偏航隐患
大数据·人工智能·深度学习·算法·计算机视觉
西索斯coding5 小时前
grok-4.7 调用一直 429 怎么办?不是额度用完——是 RPM 和 TPM 双桶限流,附响应头读取代码和退避策略
大数据·人工智能·机器学习·ai