Hisoka-X commented on code in PR #9688: URL: https://github.com/apache/seatunnel/pull/9688#discussion_r2365911821
########## seatunnel-api/src/main/java/org/apache/seatunnel/api/metalake/MetalakeConfigUtils.java: ########## @@ -0,0 +1,97 @@ +/* + * 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.seatunnel.api.metalake; + +import org.apache.seatunnel.shade.com.fasterxml.jackson.databind.JsonNode; +import org.apache.seatunnel.shade.com.typesafe.config.Config; +import org.apache.seatunnel.shade.com.typesafe.config.ConfigList; +import org.apache.seatunnel.shade.com.typesafe.config.ConfigObject; +import org.apache.seatunnel.shade.com.typesafe.config.ConfigValue; +import org.apache.seatunnel.shade.com.typesafe.config.ConfigValueFactory; +import org.apache.seatunnel.shade.com.typesafe.config.ConfigValueType; + +import org.apache.seatunnel.common.utils.PlaceholderUtils; + +import lombok.extern.slf4j.Slf4j; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +@Slf4j +public class MetalakeConfigUtils { + + public static Config getMetalakeConfig(Config jobConfigTmp) { + Config envConfig = jobConfigTmp.getConfig("env"); + boolean metalakeEnabled = + envConfig.hasPath("metalake_enabled") + ? envConfig.getBoolean("metalake_enabled") + : Boolean.parseBoolean( + System.getenv().getOrDefault("METALAKE_ENABLED", "false")); + if (!metalakeEnabled) return jobConfigTmp; + + Config update = jobConfigTmp; + update = replaceConfigList(update, "source"); + update = replaceConfigList(update, "sink"); + update = replaceConfigList(update, "transform"); + return update; + } + + private static Config replaceConfigList(Config updateConfig, String key) { + Config envConfig = updateConfig.getConfig("env"); + String metalakeType = + envConfig.hasPath("metalake_type") + ? envConfig.getString("metalake_type") + : System.getenv("METALAKE_TYPE"); + String metalakeUrl = + envConfig.hasPath("metalake_url") + ? envConfig.getString("metalake_url") + : System.getenv("METALAKE_URL"); + MetalakeClient metalakeClient = MetalakeClientFactory.create(metalakeType, metalakeUrl); Review Comment: we should move this part outer `replaceConfigList`. The metalakeClient should only created once. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
