anuengineer commented on a change in pull request #861: HDDS-1596. Create service endpoint to download configuration from SCM URL: https://github.com/apache/hadoop/pull/861#discussion_r288732873
########## File path: hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/discovery/DiscoveryUtil.java ########## @@ -0,0 +1,90 @@ +/** + * 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 + * <p> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p> + * 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.hadoop.hdds.discovery; + +import java.io.File; +import java.io.FileOutputStream; +import java.net.URL; +import java.nio.channels.Channels; +import java.nio.channels.ReadableByteChannel; + +import org.apache.hadoop.hdds.conf.OzoneConfiguration; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Utility to download ozone configuration from SCM. + */ +public final class DiscoveryUtil { + + private static final Logger LOG = + LoggerFactory.getLogger(DiscoveryUtil.class); + + public static final String OZONE_GLOBAL_XML = "ozone-global.xml"; + + private DiscoveryUtil() { + } + + /** + * Download ozone-global.conf from SCM to the local HADOOP_CONF_DIR. + */ + public static boolean loadGlobalConfig(OzoneConfiguration conf) { + String hadoopConfDir = System.getenv("HADOOP_CONF_DIR"); + if (hadoopConfDir == null || hadoopConfDir.isEmpty()) { + LOG.warn( + "HADOOP_CONF_DIR is not set, can't download ozone-global.xml from " + + "SCM."); + return false; + } + if (conf.get("ozone.scm.names") == null) { + LOG.warn("ozone.scm.names is not set. Can't download config from scm."); + return false; + } + for (int i = 0; i < 60; i++) { Review comment: I am really conflicted about this line. One side: I think we should write the download code as a small function and then allow the user to pass max wait time. On the other hand, I like that simplicity for the user. It is get config, and wait until a reasonable time to get it. I am not really sure what is the best approach. Just leaving the comment here to consider the thought and do want you like. either one works. ---------------------------------------------------------------- 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. For queries about this service, please contact Infrastructure at: [email protected] With regards, Apache Git Services --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
