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

}
相关推荐
dunge202612 分钟前
# GPT 与 Codex:软件正在从“静态程序”演化为“持续推理系统”
大数据·gpt
ganbingfenxiang38 分钟前
太原干冰定制
大数据·python
跨境数据猎手1 小时前
反向海淘SaaS系统架构拆解与业务技术
大数据·爬虫·系统架构
CodeStats1 小时前
《源纹天书》第一百四十一章至第一百四十五章:etcd升级、2PC的阻塞困境、3PC的超时突破、TCC的补偿之道、Saga的最终选择!
java·大数据·数据库·etcd·源纹天书
2601_963016262 小时前
统一消息与事件调用:如何用微信接口把微信自动化做成稳健中台?
大数据·运维·人工智能·微信·自动化
ljs6482739512 小时前
VMware 中部署 HDFS 集群环境(Hadoop 3.4.3)完整指南
大数据·hadoop·hdfs
雪碧聊技术11 小时前
Badge 应用场景与落地实践指南
大数据·人工智能
望江东浪11 小时前
我的 Claude Code 效率工具全套配置分享
大数据·elasticsearch·搜索引擎
chaoyuanl12 小时前
现有游乐设施 XR 数字化升级改造方案
大数据·科技·3d·xr·娱乐
LL3344556713 小时前
创业自动化平台怎么选
大数据·人工智能