#!/usr/bin/python
# 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.
import xml.etree.ElementTree as ET
import os,errno,sys
from os import listdir
from os.path import isfile, join, dirname
try:
from urllib.parse import urlparse
except ImportError:
from urlparse import urlparse
debugLevel = 1
SUPPORTED_COMPONENTS = [ "hdfs", "hive", "hbase", "knox", "storm" ]
#
# xmlTemplateDirectory: directory where all of the xml templates are kept here
#
xmlTemplateDirectory = './install/conf.templates/enable'
def showUsage():
print("This script must be run with a <componentName> as parameter")
print("USAGE: upgrade-plugin.py <componentName>")
print(" <componentName> could be any one of the following: %s" % (SUPPORTED_COMPONENTS))
if (len(sys.argv) == 1):
showUsage()
sys.exit(1)
componentName = sys.argv[1]
if (componentName not in SUPPORTED_COMPONENTS):
print("Invalid componentName passed as parameter: %s" % (componentName))
showUsage()
sys.exit(1)
#
# For hdfs, the componentName is hadoop (for path calculation)
#
if (componentName == 'hdfs'):
configPath = 'hadoop'
else:
configPath = componentName
#
# configDirectory: where OLD (champlain) configuration exists and NEW (dal) configuration is written to
#
configDirectory = '/etc/' + configPath + '/conf'
def getXMLConfigKeys(xmlFileName):
ret = []
tree = ET.parse(xmlFileName)
root = tree.getroot()
for config in root.iter('property'):
name = config.find('name').text
ret.append(name)
return ret
def getXMLConfigMap(xmlFileName):
ret = {}
tree = ET.parse(xmlFileName)
root = tree.getroot()
for config in root.iter('property'):
name = config.find('name').text
val = config.find('value').text
ret[name] = val
return ret
def writeXMLUsingProperties(xmlTemplateFileName,prop,xmlOutputFileName):
tree = ET.parse(xmlTemplateFileName)
root = tree.getroot()
for config in root.iter('property'):
name = config.find('name').text
if (name in prop):
config.find('value').text = prop[name]
tree.write(xmlOutputFileName)
def rewriteConfig(props,newProps):
if (debugLevel > 0):
for k,v in props.items():
print("old config[%s] = [%s]" % (k,v))
#
# Derived fields
#
pmUrl = props['xasecure.' + componentName + '.policymgr.url']
url = urlparse(pmUrl)
restUrl = url[0] + "://" + url[1]
serviceName = url[2].split("/")[-1]
props['ranger.plugin.' + componentName + '.policy.rest.url'] = restUrl
props['ranger.plugin.' + componentName + '.service.name'] = serviceName
props['ranger.plugin.' + componentName + '.policy.pollIntervalMs'] = props['xasecure.' + componentName + '.policymgr.url.reloadIntervalInMillis']
#props['ranger.plugin.' + componentName + '.policy.rest.ssl.config.file'] = props['y']
fileLoc = props['xasecure.' + componentName + '.policymgr.url.laststoredfile']
props['ranger.plugin.' + componentName + '.policy.cache.dir'] = dirname(fileLoc)
if ( 'xasecure.policymgr.sslconfig.filename' in props ):
props['ranger.plugin.' + componentName + '.policy.rest.ssl.config.file'] = props['xasecure.policymgr.sslconfig.filename']
else:
sslConfigFileName = join(configDirectory,'ranger-policymgr-ssl.xml')
props['ranger.plugin.' + componentName + '.policy.rest.ssl.config.file'] = sslConfigFileName
#
# Fix for KNOX ssl (missing) configuration
#
if ('xasecure.policymgr.clientssl.keystore.credential.file' not in props):
props['xasecure.policymgr.clientssl.keystore.credential.file'] = 'jceks://file/tmp/keystore-' + serviceName + '-ssl.jceks'
if ( 'xasecure.policymgr.clientssl.truststore.credential.file' not in props):
props['xasecure.policymgr.clientssl.truststore.credential.file'] = 'jceks://file/tmp/keystore-' + serviceName + '-ssl.jceks'
for fn in listdir(xmlTemplateDirectory):
file = join(xmlTemplateDirectory,fn)
if isfile(file) and fn.startswith("ranger-") and fn.endswith(".xml") :
newConfigFile = join(configDirectory, fn)
writeXMLUsingProperties(file, props, newConfigFile)
def main():
props = {}
newProps = {}
foundFiles = []
for fn in listdir(configDirectory):
file = join(configDirectory,fn)
if isfile(file) and fn.startswith("xasecure-") and fn.endswith(".xml") :
foundFiles.append(file)
r = getXMLConfigMap(file)
props.update(r)
if (len(foundFiles) == 0):
print("INFO: Previous version of ranger is not enabled/configured for component [%s]" % (componentName))
sys.exit(0)
if (len(foundFiles) != 3):
print("ERROR: Expected to find three files matching xasecure-*.xml files under the folder (%s) - found %s" % (configDirectory,foundFiles))
sys.exit(1)
for fn in listdir(xmlTemplateDirectory):
file = join(xmlTemplateDirectory,fn)
if isfile(file) and fn.startswith("ranger-") and fn.endswith(".xml") :
r = getXMLConfigMap(file)
newProps.update(r)
newConfigFile = join(configDirectory,fn)
if isfile(newConfigFile):
print("ERROR: new config file [%s] already exists. Upgrade script can not overwrite an existing config file." % (newConfigFile))
sys.exit(1)
rewriteConfig(props,newProps)
main()
没有合适的资源?快使用搜索试试~ 我知道了~
资源详情
资源评论
资源推荐
收起资源包目录
ranger-2.1.0-hive-plugin.tar.gz (58个子文件)
ranger-2.1.0-hive-plugin
ranger_credential_helper.py 3KB
enable-hive-plugin.sh 24KB
install
lib
woodstox-core-5.0.3.jar 501KB
slf4j-api-1.7.25.jar 40KB
commons-cli-1.2.jar 40KB
commons-io-2.5.jar 204KB
credentialbuilder-2.1.0.jar 18KB
commons-lang-2.6.jar 278KB
guava-25.1-jre.jar 2.61MB
hadoop-common-3.1.1.jar 3.85MB
commons-logging-1.2.jar 60KB
ranger-plugins-installer-2.1.0.jar 16KB
commons-collections-3.2.2.jar 575KB
htrace-core4-4.1.0-incubating.jar 1.43MB
stax2-api-3.1.4.jar 158KB
hadoop-auth-3.1.1.jar 135KB
commons-configuration2-2.1.1.jar 602KB
conf.templates
disable
hiveserver2-site-changes.cfg 1KB
enable
ranger-hive-security.xml 3KB
ranger-policymgr-ssl-changes.cfg 1KB
ranger-hive-audit.xml 7KB
ranger-hive-audit-changes.cfg 8KB
hiveserver2-site-changes.cfg 2KB
ranger-policymgr-ssl.xml 2KB
ranger-hive-security-changes.cfg 2KB
default
configuration.xml 906B
upgrade-plugin.py 6KB
lib
ranger-hive-plugin-shim-2.1.0.jar 20KB
ranger-plugin-classloader-2.1.0.jar 17KB
ranger-hive-plugin-impl
rank-eval-client-7.6.0.jar 75KB
elasticsearch-7.6.0.jar 11.27MB
jna-5.2.0.jar 1.42MB
ranger-plugins-audit-2.1.0.jar 206KB
jna-platform-5.2.0.jar 2.41MB
httpclient-4.5.6.jar 749KB
ranger-plugins-common-2.1.0.jar 871KB
httpcore-4.4.6.jar 316KB
javax.persistence-2.1.0.jar 158KB
solr-solrj-7.7.1.jar 1.91MB
eclipselink-2.5.2.jar 8.23MB
elasticsearch-x-content-7.6.0.jar 129KB
gethostname4j-0.0.2.jar 4KB
elasticsearch-rest-client-7.6.0.jar 62KB
noggit-0.8.jar 27KB
httpcore-nio-4.4.6.jar 348KB
lucene-core-8.4.0.jar 3.15MB
elasticsearch-rest-high-level-client-7.6.0.jar 1.4MB
hppc-0.8.0.jar 1.14MB
elasticsearch-core-7.6.0.jar 44KB
httpasyncclient-4.1.3.jar 175KB
lang-mustache-client-7.6.0.jar 61KB
httpmime-4.5.6.jar 41KB
joda-time-2.10.6.jar 629KB
ranger-plugins-cred-2.1.0.jar 19KB
ranger-hive-plugin-2.1.0.jar 109KB
install.properties 6KB
disable-hive-plugin.sh 24KB
upgrade-hive-plugin.sh 1KB
共 58 条
- 1
诸葛余
- 粉丝: 14
- 资源: 24
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0