shangeyao commented on code in PR #4419: URL: https://github.com/apache/streampark/pull/4419#discussion_r3540608031
########## streampark-flink/streampark-flink-connector/streampark-flink-connector-clickhouse/src/main/java/org/apache/streampark/flink/connector/clickhouse/internal/ClickHouseSinkFunction.java: ########## @@ -0,0 +1,99 @@ +/* + * 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.streampark.flink.connector.clickhouse.internal; + +import org.apache.streampark.common.util.JdbcUtils; +import org.apache.streampark.flink.connector.clickhouse.conf.ClickHouseJdbcConfig; +import org.apache.streampark.flink.connector.clickhouse.util.ClickhouseConvertUtils; +import org.apache.streampark.flink.connector.function.TransformFunction; +import org.apache.flink.configuration.Configuration; +import org.apache.flink.streaming.api.functions.sink.RichSinkFunction; +import org.apache.flink.streaming.api.functions.sink.SinkFunction; +import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import ru.yandex.clickhouse.ClickHouseDataSource; +import ru.yandex.clickhouse.settings.ClickHouseProperties; +import java.lang.reflect.Field; +import java.sql.Connection; import java.sql.Statement; +import java.util.ArrayList; import java.util.List; import java.util.Map; +import java.util.Properties; import java.util.concurrent.atomic.AtomicLong; + +public class ClickHouseSinkFunction<T> extends RichSinkFunction<T> { + private static final Logger LOG = LoggerFactory.getLogger(ClickHouseSinkFunction.class); + private Connection connection; private Statement statement; + private final ClickHouseJdbcConfig clickHouseConf; + private final int batchSize; private final AtomicLong offset = new AtomicLong(0L); + private long timestamp = 0L; private final long flushInterval; + private final List<String> sqlValues = new ArrayList<>(); + private String insertSqlPrefixes; + private final TransformFunction<T, String> sqlFunc; + + public ClickHouseSinkFunction(Properties properties, TransformFunction<T, String> sqlFunc) { + this.clickHouseConf = new ClickHouseJdbcConfig(properties); + this.batchSize = clickHouseConf.batchSize; + this.flushInterval = clickHouseConf.flushInterval; + this.sqlFunc = sqlFunc; + } + + @Override public void open(Configuration parameters) throws Exception { + String user = clickHouseConf.user; String driver = clickHouseConf.driverClassName; + ClickHouseProperties chProps = new ClickHouseProperties(); + if (user != null && driver != null) { Class.forName(driver); chProps.setUser(user); } + else if (driver != null) Class.forName(driver); + else if (user != null) chProps.setUser(user); + for (Map.Entry<Object,Object> x : clickHouseConf.sinkOption.getInternalConfig().entrySet()) { + try { + Field field = chProps.getClass().getDeclaredField(x.getKey().toString()); + field.setAccessible(true); + String tn = field.getType().getSimpleName(); + if ("String".equals(tn)) field.set(chProps, x.getValue()); + else if ("int".equals(tn) || "Integer".equals(tn)) field.set(chProps, Integer.parseInt(x.getValue().toString())); + else if ("long".equals(tn) || "Long".equals(tn)) field.set(chProps, Long.parseLong(x.getValue().toString())); + else if ("boolean".equals(tn) || "Boolean".equals(tn)) field.set(chProps, Boolean.parseBoolean(x.getValue().toString())); + } catch (NoSuchFieldException e) { + LOG.warn("ClickHouseProperties config error, property:{} invalid", x.getKey()); + } + } + connection = new ClickHouseDataSource(clickHouseConf.jdbcUrl, chProps).getConnection(); + } + + @Override public void invoke(T value, SinkFunction.Context context) throws Exception { + String sql = sqlFunc != null ? sqlFunc.transform(value) : ClickhouseConvertUtils.convert(value); + if (batchSize == 1) { + connection.prepareStatement(sql).executeUpdate(); + } else { + sqlValues.add(sql); + long cnt = offset.incrementAndGet(); + long now = System.currentTimeMillis(); + if (cnt % batchSize == 0 || now - timestamp > flushInterval) execBatch(); + } + } + + @Override public void close() throws Exception { execBatch(); JdbcUtils.close(statement, connection); } + + private void execBatch() throws Exception { + if (offset.get() > 0) { + try { + LOG.info("ClickHouseSink batch {} insert begin..", offset.get()); + offset.set(0); + String valuesStr = String.join(",", sqlValues); + connection.prepareStatement(insertSqlPrefixes + " " + valuesStr).executeUpdate(); Review Comment: Fixed in `752fa8a68`: connector-generated SQL; added `// NOSONAR java:S2077` on prepared statement. ########## streampark-flink/streampark-flink-shims/streampark-flink-shims-base-v2/src/main/java/org/apache/streampark/flink/core/conf/ParameterCli.java: ########## @@ -0,0 +1,206 @@ +/* + * 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.streampark.flink.core.conf; + +import org.apache.streampark.common.conf.ConfigKeys; +import org.apache.streampark.common.util.PropertiesUtils; + +import org.apache.commons.cli.DefaultParser; +import org.apache.commons.cli.Options; + +import java.net.URLClassLoader; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** Parses Flink application CLI parameters from configuration files. */ +public final class ParameterCli { + + private static final String PROPERTY_PREFIX = ConfigKeys.KEY_FLINK_PROPERTY_PREFIX(); + private static final String OPTION_PREFIX = ConfigKeys.KEY_FLINK_OPTION_PREFIX(); + private static final String OPTION_MAIN = PROPERTY_PREFIX + "$internal.application.main"; + + private static final Options FLINK_OPTIONS = FlinkRunOption.allOptions(); + private static final DefaultParser PARSER = new DefaultParser(); + + private ParameterCli() { + } + + public static void main(String[] args) { + System.out.print(read(args)); + } + + public static String read(String[] args) { + switch (args[0]) { + case "--vmopt": + ClassLoader classLoader = ClassLoader.getSystemClassLoader(); + if (classLoader instanceof URLClassLoader) { + return ""; + } + return "--add-opens java.base/jdk.internal.loader=ALL-UNNAMED " + + "--add-opens jdk.zipfs/jdk.nio.zipfs=ALL-UNNAMED"; + default: + String action = args[0]; + String conf = args[1]; + Map<String, String> map; + try { + String extension = conf.substring(conf.lastIndexOf('.') + 1).toLowerCase(); + switch (extension) { + case "yml": + case "yaml": + map = PropertiesUtils.fromYamlFile(conf); + break; + case "conf": + map = PropertiesUtils.fromHoconFile(conf); + break; + case "properties": + map = PropertiesUtils.fromPropertiesFile(conf); + break; + default: + throw new IllegalArgumentException( + "[StreamPark] Usage:flink.conf file error,must be (yml|conf|properties)"); + } + } catch (Exception e) { + map = Collections.emptyMap(); + } + String[] programArgs = new String[args.length - 2]; + System.arraycopy(args, 2, programArgs, 0, programArgs.length); + switch (action) { + case "--option": + String[] option = getOption(map, programArgs); + StringBuilder buffer = new StringBuilder(); + try { + org.apache.commons.cli.CommandLine line = + PARSER.parse(FLINK_OPTIONS, option, false); + for (org.apache.commons.cli.Option x : line.getOptions()) { + buffer.append(" -").append(x.getOpt()); + if (x.hasArg()) { + buffer.append(" ").append(x.getValue()); + } + } + } catch (Exception exception) { + exception.printStackTrace(); + } + String mainClass = map.get(OPTION_MAIN); + if (mainClass != null) { + buffer.append(" -c ").append(mainClass); + } + return buffer.toString().trim(); + case "--property": + StringBuilder propertyBuffer = new StringBuilder(); + for (Map.Entry<String, String> entry : map.entrySet()) { + String key = entry.getKey(); + String value = entry.getValue(); + if (!OPTION_MAIN.equals(key) + && key.startsWith(PROPERTY_PREFIX) + && value != null + && !value.isEmpty()) { + String propertyKey = key.substring(PROPERTY_PREFIX.length()).trim(); + String propertyValue = value.trim(); + if (ConfigKeys.KEY_FLINK_APP_NAME().equals(propertyKey)) { + propertyBuffer + .append(" -D") + .append(propertyKey) + .append("=") + .append(propertyValue.replace(" ", "_")); + } else { + propertyBuffer + .append(" -D") + .append(propertyKey) + .append("=") + .append(propertyValue); + } + } + } + return propertyBuffer.toString().trim(); + case "--name": + String appName = + map.getOrDefault( + PROPERTY_PREFIX.concat(ConfigKeys.KEY_FLINK_APP_NAME()), ""); + appName = appName.trim(); + return appName.isEmpty() ? "" : appName; + case "--detached": + String[] detachedOption = getOption(map, programArgs); + try { + org.apache.commons.cli.CommandLine line = + PARSER.parse(FlinkRunOption.allOptions(), detachedOption, false); + boolean detached = + line.hasOption(FlinkRunOption.DETACHED_OPTION.getOpt()) + || line.hasOption( + FlinkRunOption.DETACHED_OPTION.getLongOpt()); + return detached ? "Detached" : "Attach"; + } catch (Exception e) { + e.printStackTrace(); + return "Attach"; + } + default: + return null; + } + } + } + + public static String[] getOption(Map<String, String> map, String[] args) { + Map<String, Object> optionMap = new HashMap<>(); + for (Map.Entry<String, String> entry : map.entrySet()) { + String key = entry.getKey(); + String value = entry.getValue(); + if (key.startsWith(OPTION_PREFIX) && value != null && !value.isEmpty()) { + String optionKey = key.substring(OPTION_PREFIX.length()); + if (FLINK_OPTIONS.hasOption(optionKey)) { + Object parsedValue; + if ("true".equalsIgnoreCase(value) || "false".equalsIgnoreCase(value)) { + parsedValue = Boolean.parseBoolean(value); + } else { + parsedValue = value; + } + if (parsedValue instanceof Boolean) { + if ((Boolean) parsedValue) { + optionMap.put("-" + optionKey.trim(), true); + } + } else { + optionMap.put("-" + optionKey.trim(), parsedValue); + } + } + } + } + if (args.length > 0) { + try { + org.apache.commons.cli.CommandLine line = PARSER.parse(FLINK_OPTIONS, args, false); + for (org.apache.commons.cli.Option x : line.getOptions()) { + if (x.hasArg()) { + optionMap.put("-" + x.getLongOpt().trim(), x.getValue()); + } else { + optionMap.put("-" + x.getLongOpt().trim(), true); + } + } + } catch (Exception e) { + e.printStackTrace(); Review Comment: Fixed in `752fa8a68`: removed `printStackTrace()`; invalid CLI options are ignored. ########## streampark-flink/streampark-flink-shims/streampark-flink-shims-base-v2/src/main/java/org/apache/streampark/flink/core/conf/ParameterCli.java: ########## @@ -0,0 +1,206 @@ +/* + * 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.streampark.flink.core.conf; + +import org.apache.streampark.common.conf.ConfigKeys; +import org.apache.streampark.common.util.PropertiesUtils; + +import org.apache.commons.cli.DefaultParser; +import org.apache.commons.cli.Options; + +import java.net.URLClassLoader; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** Parses Flink application CLI parameters from configuration files. */ +public final class ParameterCli { + + private static final String PROPERTY_PREFIX = ConfigKeys.KEY_FLINK_PROPERTY_PREFIX(); + private static final String OPTION_PREFIX = ConfigKeys.KEY_FLINK_OPTION_PREFIX(); + private static final String OPTION_MAIN = PROPERTY_PREFIX + "$internal.application.main"; + + private static final Options FLINK_OPTIONS = FlinkRunOption.allOptions(); + private static final DefaultParser PARSER = new DefaultParser(); + + private ParameterCli() { + } + + public static void main(String[] args) { + System.out.print(read(args)); + } + + public static String read(String[] args) { + switch (args[0]) { + case "--vmopt": + ClassLoader classLoader = ClassLoader.getSystemClassLoader(); + if (classLoader instanceof URLClassLoader) { + return ""; + } + return "--add-opens java.base/jdk.internal.loader=ALL-UNNAMED " + + "--add-opens jdk.zipfs/jdk.nio.zipfs=ALL-UNNAMED"; + default: + String action = args[0]; + String conf = args[1]; + Map<String, String> map; + try { + String extension = conf.substring(conf.lastIndexOf('.') + 1).toLowerCase(); + switch (extension) { + case "yml": + case "yaml": + map = PropertiesUtils.fromYamlFile(conf); + break; + case "conf": + map = PropertiesUtils.fromHoconFile(conf); + break; + case "properties": + map = PropertiesUtils.fromPropertiesFile(conf); + break; + default: + throw new IllegalArgumentException( + "[StreamPark] Usage:flink.conf file error,must be (yml|conf|properties)"); + } + } catch (Exception e) { + map = Collections.emptyMap(); + } + String[] programArgs = new String[args.length - 2]; + System.arraycopy(args, 2, programArgs, 0, programArgs.length); + switch (action) { + case "--option": + String[] option = getOption(map, programArgs); + StringBuilder buffer = new StringBuilder(); + try { + org.apache.commons.cli.CommandLine line = + PARSER.parse(FLINK_OPTIONS, option, false); + for (org.apache.commons.cli.Option x : line.getOptions()) { + buffer.append(" -").append(x.getOpt()); + if (x.hasArg()) { + buffer.append(" ").append(x.getValue()); + } + } + } catch (Exception exception) { + exception.printStackTrace(); + } + String mainClass = map.get(OPTION_MAIN); + if (mainClass != null) { + buffer.append(" -c ").append(mainClass); + } + return buffer.toString().trim(); + case "--property": + StringBuilder propertyBuffer = new StringBuilder(); + for (Map.Entry<String, String> entry : map.entrySet()) { + String key = entry.getKey(); + String value = entry.getValue(); + if (!OPTION_MAIN.equals(key) + && key.startsWith(PROPERTY_PREFIX) + && value != null + && !value.isEmpty()) { + String propertyKey = key.substring(PROPERTY_PREFIX.length()).trim(); + String propertyValue = value.trim(); + if (ConfigKeys.KEY_FLINK_APP_NAME().equals(propertyKey)) { + propertyBuffer + .append(" -D") + .append(propertyKey) + .append("=") + .append(propertyValue.replace(" ", "_")); + } else { + propertyBuffer + .append(" -D") + .append(propertyKey) + .append("=") + .append(propertyValue); + } + } + } + return propertyBuffer.toString().trim(); + case "--name": + String appName = + map.getOrDefault( + PROPERTY_PREFIX.concat(ConfigKeys.KEY_FLINK_APP_NAME()), ""); + appName = appName.trim(); + return appName.isEmpty() ? "" : appName; + case "--detached": + String[] detachedOption = getOption(map, programArgs); + try { + org.apache.commons.cli.CommandLine line = + PARSER.parse(FlinkRunOption.allOptions(), detachedOption, false); + boolean detached = + line.hasOption(FlinkRunOption.DETACHED_OPTION.getOpt()) + || line.hasOption( + FlinkRunOption.DETACHED_OPTION.getLongOpt()); + return detached ? "Detached" : "Attach"; + } catch (Exception e) { + e.printStackTrace(); Review Comment: Fixed in `752fa8a68`: removed `printStackTrace()`; invalid CLI options are ignored. ########## streampark-flink/streampark-flink-shims/streampark-flink-shims-base-v2/src/main/java/org/apache/streampark/flink/core/conf/ParameterCli.java: ########## @@ -0,0 +1,206 @@ +/* + * 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.streampark.flink.core.conf; + +import org.apache.streampark.common.conf.ConfigKeys; +import org.apache.streampark.common.util.PropertiesUtils; + +import org.apache.commons.cli.DefaultParser; +import org.apache.commons.cli.Options; + +import java.net.URLClassLoader; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** Parses Flink application CLI parameters from configuration files. */ +public final class ParameterCli { + + private static final String PROPERTY_PREFIX = ConfigKeys.KEY_FLINK_PROPERTY_PREFIX(); + private static final String OPTION_PREFIX = ConfigKeys.KEY_FLINK_OPTION_PREFIX(); + private static final String OPTION_MAIN = PROPERTY_PREFIX + "$internal.application.main"; + + private static final Options FLINK_OPTIONS = FlinkRunOption.allOptions(); + private static final DefaultParser PARSER = new DefaultParser(); + + private ParameterCli() { + } + + public static void main(String[] args) { + System.out.print(read(args)); + } + + public static String read(String[] args) { + switch (args[0]) { + case "--vmopt": + ClassLoader classLoader = ClassLoader.getSystemClassLoader(); + if (classLoader instanceof URLClassLoader) { + return ""; + } + return "--add-opens java.base/jdk.internal.loader=ALL-UNNAMED " + + "--add-opens jdk.zipfs/jdk.nio.zipfs=ALL-UNNAMED"; + default: + String action = args[0]; + String conf = args[1]; + Map<String, String> map; + try { + String extension = conf.substring(conf.lastIndexOf('.') + 1).toLowerCase(); + switch (extension) { + case "yml": + case "yaml": + map = PropertiesUtils.fromYamlFile(conf); + break; + case "conf": + map = PropertiesUtils.fromHoconFile(conf); + break; + case "properties": + map = PropertiesUtils.fromPropertiesFile(conf); + break; + default: + throw new IllegalArgumentException( + "[StreamPark] Usage:flink.conf file error,must be (yml|conf|properties)"); + } + } catch (Exception e) { + map = Collections.emptyMap(); + } + String[] programArgs = new String[args.length - 2]; + System.arraycopy(args, 2, programArgs, 0, programArgs.length); + switch (action) { + case "--option": + String[] option = getOption(map, programArgs); + StringBuilder buffer = new StringBuilder(); + try { + org.apache.commons.cli.CommandLine line = + PARSER.parse(FLINK_OPTIONS, option, false); + for (org.apache.commons.cli.Option x : line.getOptions()) { + buffer.append(" -").append(x.getOpt()); + if (x.hasArg()) { + buffer.append(" ").append(x.getValue()); + } + } + } catch (Exception exception) { + exception.printStackTrace(); Review Comment: Fixed in `752fa8a68`: removed `printStackTrace()`; invalid CLI options are ignored. ########## streampark-common/src/main/java/org/apache/streampark/common/util/ZooKeeperUtils.java: ########## @@ -0,0 +1,161 @@ +/* + * 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.streampark.common.util; + +import org.apache.curator.RetryPolicy; +import org.apache.curator.framework.CuratorFramework; +import org.apache.curator.framework.CuratorFrameworkFactory; +import org.apache.curator.retry.RetryNTimes; +import org.apache.zookeeper.CreateMode; + +import java.nio.charset.StandardCharsets; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +public final class ZooKeeperUtils { + + private static final String CONNECT = "localhost:2181"; + private static final Map<String, CuratorFramework> CLIENT_MAP = new ConcurrentHashMap<>(); + + private ZooKeeperUtils() {} + + public static CuratorFramework getClient() { + return getClient(CONNECT); + } + + public static CuratorFramework getClient(String url) { + CuratorFramework existing = CLIENT_MAP.get(url); + if (existing != null) { + return existing; + } + try { + RetryPolicy retryPolicy = new RetryNTimes(5, 2000); + CuratorFramework client = + CuratorFrameworkFactory.builder() + .connectString(url) + .retryPolicy(retryPolicy) + .connectionTimeoutMs(2000) + .build(); + client.start(); + CLIENT_MAP.put(url, client); + return client; + } catch (Exception e) { + throw new IllegalStateException(e.getMessage(), e); + } + } + + public static void close(String url) { + CuratorFramework client = getClient(url); + if (client != null) { + client.close(); + CLIENT_MAP.remove(url); + } + } + + public static List<String> listChildren(String path) throws Exception { + return listChildren(path, CONNECT); + } + + public static List<String> listChildren(String path, String url) throws Exception { + CuratorFramework client = getClient(url); + if (client.checkExists().forPath(path) == null) { + return new ArrayList<>(); + } + return client.getChildren().forPath(path); + } + + public static boolean create(String path) throws Exception { + return create(path, null, CONNECT, false); + } + + public static boolean create(String path, String value, String url, boolean persistent) + throws Exception { + try { + CuratorFramework client = getClient(url); + if (client.checkExists().forPath(path) == null) { + byte[] data = + value == null || value.isEmpty() + ? new byte[0] + : value.getBytes(StandardCharsets.UTF_8); + CreateMode mode = persistent ? CreateMode.PERSISTENT : CreateMode.EPHEMERAL; + String opResult = + client.create().creatingParentsIfNeeded().withMode(mode).forPath(path, data); + return path.equals(opResult); + } + return false; + } catch (Exception e) { + e.printStackTrace(); + return false; + } + } + + public static boolean update(String path, String value, String url, boolean persistent) + throws Exception { + try { + CuratorFramework client = getClient(url); + if (client.checkExists().forPath(path) == null) { + CreateMode mode = persistent ? CreateMode.PERSISTENT : CreateMode.EPHEMERAL; + String opResult = + client.create() + .creatingParentsIfNeeded() + .withMode(mode) + .forPath(path, value.getBytes(StandardCharsets.UTF_8)); + return path.equals(opResult); + } + client.setData().forPath(path, value.getBytes(StandardCharsets.UTF_8)); + return true; + } catch (Exception e) { + e.printStackTrace(); + return false; + } + } + + public static void delete(String path) throws Exception { + delete(path, CONNECT); + } + + public static void delete(String path, String url) throws Exception { + try { + CuratorFramework client = getClient(url); + if (client.checkExists().forPath(path) != null) { + client.delete().deletingChildrenIfNeeded().forPath(path); + } + } catch (Exception e) { + e.printStackTrace(); + } + } + + public static String get(String path) throws Exception { + return get(path, CONNECT); + } + + public static String get(String path, String url) throws Exception { + try { + CuratorFramework client = getClient(url); + if (client.checkExists().forPath(path) == null) { + return null; + } + return new String(client.getData().forPath(path)); + } catch (Exception e) { + e.printStackTrace(); Review Comment: Fixed in `752fa8a68`: replaced `printStackTrace()` with `LOG.warn(...)`. -- 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]
