presto热加载catalog配置

presto热加载catalog配置,第1张

presto热加载catalog配置 presto启动从远程获取catalog配置做加载 启动类Server的代码变更
        try {
            Injector injector = app.strictConfig().initialize();

            logLocation(log, "Working directory", Paths.get("."));
            logLocation(log, "Etc directory", Paths.get("etc"));

            injector.getInstance(PluginManager.class).loadPlugins();
            // 变更代码 presto原生加载catalog
            // injector.getInstance(StaticCatalogStore.class).loadCatalogs();
            // 变更代码 动态加载catalog
            injector.getInstance(CatalogStore.class).loadCatalogs();

            // 
            // 变更代码  去掉在Server类加载ConnectorIds信息,统一在热加载模版更新
//            updateConnectorIds(injector.getInstance(Announcer.class), injector.getInstance(CatalogManager.class));

            injector.getInstance(SessionPropertyDefaults.class).loadConfigurationManager();
            injector.getInstance(ResourceGroupManager.class).loadConfigurationManager();
            injector.getInstance(AccessControlManager.class).loadSystemAccessControl();
            injector.getInstance(PasswordAuthenticatorManager.class).loadPasswordAuthenticator();
            injector.getInstance(EventListenerManager.class).loadEventListeners();
            injector.getInstance(GroupProviderManager.class).loadConfiguredGroupProvider();
            injector.getInstance(CertificateAuthenticatorManager.class).loadCertificateAuthenticator();

            injector.getInstance(Announcer.class).start();

            injector.getInstance(ServerInfoResource.class).startupComplete();

            log.info("======== SERVER STARTED ========");
        }
        catch (Throwable e) {
            log.error(e);
            System.exit(1);
        }
远程加载流程

presto监听远程catalog配置变化做热加载

配置类,配置写在config.properties
public class DynamicCatalogStoreConfig {
    private boolean dynamic;
    private String restUrl;
    private long timerPeriod= 5L;
    private String secretKey;

    @Config("catalog.dynamic")
    public DynamicCatalogStoreConfig setDynamic(boolean dynamic) {
        this.dynamic = dynamic;
        return this;
    }

    @Config("catalog.dynamic.rest-url")
    public DynamicCatalogStoreConfig setRestUrl(String restUrl) {
        this.restUrl = restUrl;
        return this;
    }

    @Config("catalog.dynamic.timer-period-minutes")
    public DynamicCatalogStoreConfig setTimerPeriod(long timerPeriod) {
        this.timerPeriod = timerPeriod * 60 * 1000;
        return this;
    }

    @Config("catalog.dynamic.secret-key")
    public DynamicCatalogStoreConfig setSecretKey(String secretKey) {
        this.secretKey = secretKey;
        return this;
    }

    public boolean isDynamic() {
        return dynamic;
    }

    public String getRestUrl() {
        return restUrl;
    }

    public long getTimerPeriod() {
        return timerPeriod;
    }

    public String getSecretKey() {
        return secretKey;
    }
}
key描述默认值catalog.dynamic是否动态热加载数据源falsecatalog.dynamic.rest-url获取远程catalog数据源信息的接口空catalog.dynamic.secret-key解密从远程获取的catalog信息空catalog.dynamic.timer-period-minutes定时从远程获取catalog数据源并刷新本地内存catalog频率,单位分5

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5682776.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-17
下一篇 2022-12-17

发表评论

登录后才能评论

评论列表(0条)

保存