Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 19CAE200CFD for ; Wed, 6 Sep 2017 11:25:14 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 188D0161198; Wed, 6 Sep 2017 09:25:14 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 5F638160CD8 for ; Wed, 6 Sep 2017 11:25:13 +0200 (CEST) Received: (qmail 45192 invoked by uid 500); 6 Sep 2017 09:25:12 -0000 Mailing-List: contact issues-help@flink.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@flink.apache.org Delivered-To: mailing list issues@flink.apache.org Received: (qmail 45183 invoked by uid 99); 6 Sep 2017 09:25:12 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd1-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 06 Sep 2017 09:25:12 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd1-us-west.apache.org (ASF Mail Server at spamd1-us-west.apache.org) with ESMTP id E643DCC260 for ; Wed, 6 Sep 2017 09:25:11 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd1-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -4.021 X-Spam-Level: X-Spam-Status: No, score=-4.021 tagged_above=-999 required=6.31 tests=[KAM_LAZY_DOMAIN_SECURITY=1, RCVD_IN_DNSWL_HI=-5, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, RP_MATCHES_RCVD=-0.001] autolearn=disabled Received: from mx1-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd1-us-west.apache.org [10.40.0.7]) (amavisd-new, port 10024) with ESMTP id pK6-OSVj6tfZ for ; Wed, 6 Sep 2017 09:25:11 +0000 (UTC) Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx1-lw-eu.apache.org (ASF Mail Server at mx1-lw-eu.apache.org) with SMTP id 135C95FE5F for ; Wed, 6 Sep 2017 09:25:09 +0000 (UTC) Received: (qmail 45166 invoked by uid 99); 6 Sep 2017 09:25:09 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 06 Sep 2017 09:25:09 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 31450F32EA; Wed, 6 Sep 2017 09:25:09 +0000 (UTC) From: aljoscha To: issues@flink.incubator.apache.org Reply-To: issues@flink.incubator.apache.org References: In-Reply-To: Subject: [GitHub] flink pull request #4636: [FLINK-2268] Allow Flink binary release without Ha... Content-Type: text/plain Message-Id: <20170906092509.31450F32EA@git1-us-west.apache.org> Date: Wed, 6 Sep 2017 09:25:09 +0000 (UTC) archived-at: Wed, 06 Sep 2017 09:25:14 -0000 Github user aljoscha commented on a diff in the pull request: https://github.com/apache/flink/pull/4636#discussion_r137215719 --- Diff: flink-runtime/src/main/java/org/apache/flink/runtime/util/HadoopUtils.java --- @@ -0,0 +1,114 @@ +/* + * 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.runtime.util; + +import org.apache.flink.configuration.ConfigConstants; + +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.io.Text; +import org.apache.hadoop.security.UserGroupInformation; +import org.apache.hadoop.security.token.Token; +import org.apache.hadoop.security.token.TokenIdentifier; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.File; +import java.util.Collection; + +/** + * Utility class for working with Hadoop-related classes. This should only be used if Hadoop + * is on the classpath. + */ +public class HadoopUtils { + + private static final Logger LOG = LoggerFactory.getLogger(HadoopUtils.class); + + private static final Text HDFS_DELEGATION_TOKEN_KIND = new Text("HDFS_DELEGATION_TOKEN"); + + public static Configuration getHadoopConfiguration(org.apache.flink.configuration.Configuration flinkConfiguration) { + + Configuration retConf = new Configuration(); + + // We need to load both core-site.xml and hdfs-site.xml to determine the default fs path and + // the hdfs configuration + // Try to load HDFS configuration from Hadoop's own configuration files + // 1. approach: Flink configuration + final String hdfsDefaultPath = flinkConfiguration.getString(ConfigConstants + .HDFS_DEFAULT_CONFIG, null); + if (hdfsDefaultPath != null) { + retConf.addResource(new org.apache.hadoop.fs.Path(hdfsDefaultPath)); + } else { + LOG.debug("Cannot find hdfs-default configuration file"); + } + + final String hdfsSitePath = flinkConfiguration.getString(ConfigConstants.HDFS_SITE_CONFIG, null); + if (hdfsSitePath != null) { + retConf.addResource(new org.apache.hadoop.fs.Path(hdfsSitePath)); + } else { + LOG.debug("Cannot find hdfs-site configuration file"); + } + + // 2. Approach environment variables + String[] possibleHadoopConfPaths = new String[4]; + possibleHadoopConfPaths[0] = flinkConfiguration.getString(ConfigConstants.PATH_HADOOP_CONFIG, null); + possibleHadoopConfPaths[1] = System.getenv("HADOOP_CONF_DIR"); + + if (System.getenv("HADOOP_HOME") != null) { + possibleHadoopConfPaths[2] = System.getenv("HADOOP_HOME") + "/conf"; + possibleHadoopConfPaths[3] = System.getenv("HADOOP_HOME") + "/etc/hadoop"; // hadoop 2.2 + } + + for (String possibleHadoopConfPath : possibleHadoopConfPaths) { + if (possibleHadoopConfPath != null) { + if (new File(possibleHadoopConfPath).exists()) { + if (new File(possibleHadoopConfPath + "/core-site.xml").exists()) { + retConf.addResource(new org.apache.hadoop.fs.Path(possibleHadoopConfPath + "/core-site.xml")); + + if (LOG.isDebugEnabled()) { + LOG.debug("Adding " + possibleHadoopConfPath + "/core-site.xml to hadoop configuration"); + } + } + if (new File(possibleHadoopConfPath + "/hdfs-site.xml").exists()) { + retConf.addResource(new org.apache.hadoop.fs.Path(possibleHadoopConfPath + "/hdfs-site.xml")); + + if (LOG.isDebugEnabled()) { + LOG.debug("Adding " + possibleHadoopConfPath + "/hdfs-site.xml to hadoop configuration"); + } + } + } + } + } + return retConf; --- End diff -- done ---