Repository: incubator-ranger Updated Branches: refs/heads/master 63030e280 -> 1283c9652
Ranger-225:Ranger-LookupResource and ValidateConfig implementation for all components in the new pluggable model - Hbase, Hive knox lookupresource issue fix and code improvement Project: http://git-wip-us.apache.org/repos/asf/incubator-ranger/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ranger/commit/1283c965 Tree: http://git-wip-us.apache.org/repos/asf/incubator-ranger/tree/1283c965 Diff: http://git-wip-us.apache.org/repos/asf/incubator-ranger/diff/1283c965 Branch: refs/heads/master Commit: 1283c965203472d562ef8dfe3fd03ac68fe0a407 Parents: 63030e2 Author: rmani <[email protected]> Authored: Wed Feb 18 00:19:37 2015 -0800 Committer: rmani <[email protected]> Committed: Wed Feb 18 00:19:37 2015 -0800 ---------------------------------------------------------------------- .../services/hbase/client/HBaseResourceMgr.java | 95 ++++++------- .../services/hive/client/HiveResourceMgr.java | 138 ++++++++++--------- .../services/knox/client/KnoxResourceMgr.java | 43 +++--- .../services/storm/client/StormResourceMgr.java | 19 +++ 4 files changed, 155 insertions(+), 140 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/1283c965/hbase-agent/src/main/java/org/apache/ranger/services/hbase/client/HBaseResourceMgr.java ---------------------------------------------------------------------- diff --git a/hbase-agent/src/main/java/org/apache/ranger/services/hbase/client/HBaseResourceMgr.java b/hbase-agent/src/main/java/org/apache/ranger/services/hbase/client/HBaseResourceMgr.java index f107bf0..ca3c715 100644 --- a/hbase-agent/src/main/java/org/apache/ranger/services/hbase/client/HBaseResourceMgr.java +++ b/hbase-agent/src/main/java/org/apache/ranger/services/hbase/client/HBaseResourceMgr.java @@ -71,36 +71,23 @@ public class HBaseResourceMgr { } if ( userInput != null && resource != null) { - if ( resourceMap != null && !resourceMap.isEmpty() && ( resourceMap.get(TABLE) != null || resourceMap.get(COLUMNFAMILY) != null) ) { - switch (resource.trim().toLowerCase()) { - case TABLE: - tableName = userInput; - tableList = resourceMap.get(TABLE); - break; - case COLUMNFAMILY: - columnFamilies = userInput; - columnFamilyList = resourceMap.get(COLUMNFAMILY); - break; - default: - break; - } + if ( resourceMap != null && !resourceMap.isEmpty() ) { + tableList = resourceMap.get(TABLE); + columnFamilyList = resourceMap.get(COLUMNFAMILY); + } + switch (resource.trim().toLowerCase()) { + case TABLE: + tableName = userInput; + break; + case COLUMNFAMILY: + columnFamilies = userInput; + break; + default: + break; } - else { - switch (resource.trim().toLowerCase()) { - case TABLE: - tableName = userInput; - break; - case COLUMNFAMILY: - columnFamilies = userInput; - break; - default: - break; - } - } } - - - if (serviceName != null && userInput != null && resource != null) { + + if (serviceName != null && userInput != null) { final List<String> finaltableList = tableList; final List<String> finalcolumnFamilyList = columnFamilyList; @@ -109,30 +96,12 @@ public class HBaseResourceMgr { LOG.debug("<== HBaseResourceMgr.getHBaseResource UserInput: \""+ userInput + "\" configs: " + configs + " context: " + context) ; } final HBaseClient hBaseClient = new HBaseConnectionMgr().getHBaseConnection(serviceName,configs); - final Callable<List<String>> callableObj; + Callable<List<String>> callableObj = null; - if (hBaseClient != null && tableName != null - && !tableName.isEmpty()) { - final String finalColFamilies; - final String finalTableName; - if (columnFamilies != null && !columnFamilies.isEmpty()) { - if (!columnFamilies.endsWith("*")) { - columnFamilies += "*"; - } - - columnFamilies = columnFamilies.replaceAll("\\*", - ".\\*"); - finalColFamilies = columnFamilies; - finalTableName = tableName; - - callableObj = new Callable<List<String>>() { - @Override - public List<String> call() { - return hBaseClient.getColumnFamilyList(finalColFamilies,finaltableList,finalcolumnFamilyList); - } - }; - - } else { + if ( hBaseClient != null) { + if ( tableName != null && !tableName.isEmpty()) { + final String finalTableName; + //get tableList if (!tableName.endsWith("*")) { tableName += "*"; } @@ -144,14 +113,32 @@ public class HBaseResourceMgr { @Override public List<String> call() { return hBaseClient.getTableList(finalTableName,finaltableList); - } - }; + } + }; + } else { + //get columfamilyList + final String finalColFamilies; + if (columnFamilies != null && !columnFamilies.isEmpty()) { + if (!columnFamilies.endsWith("*")) { + columnFamilies += "*"; + } + + columnFamilies = columnFamilies.replaceAll("\\*", + ".\\*"); + finalColFamilies = columnFamilies; + callableObj = new Callable<List<String>>() { + @Override + public List<String> call() { + return hBaseClient.getColumnFamilyList(finalColFamilies,finaltableList,finalcolumnFamilyList); + } + }; + } } resultList = TimedEventUtil.timedTask(callableObj, 5, TimeUnit.SECONDS); + } - } catch (Exception e) { LOG.error("Unable to get hbase resources.", e); throw e; http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/1283c965/hive-agent/src/main/java/org/apache/ranger/services/hive/client/HiveResourceMgr.java ---------------------------------------------------------------------- diff --git a/hive-agent/src/main/java/org/apache/ranger/services/hive/client/HiveResourceMgr.java b/hive-agent/src/main/java/org/apache/ranger/services/hive/client/HiveResourceMgr.java index b505924..a195627 100644 --- a/hive-agent/src/main/java/org/apache/ranger/services/hive/client/HiveResourceMgr.java +++ b/hive-agent/src/main/java/org/apache/ranger/services/hive/client/HiveResourceMgr.java @@ -1,3 +1,21 @@ +/* + * 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.ranger.services.hive.client; import java.util.HashMap; @@ -43,7 +61,6 @@ public class HiveResourceMgr { public static List<String> getHiveResources(String serviceName, Map<String, String> configs,ResourceLookupContext context) throws Exception { - String userInput = context.getUserInput(); String resource = context.getResourceName(); Map<String, List<String>> resourceMap = context.getResources(); @@ -56,36 +73,19 @@ public class HiveResourceMgr { String tableName = null; String udfName = null; String columnName = null; + if(LOG.isDebugEnabled()) { LOG.debug("<== HiveResourceMgr.getHiveResources() UserInput: \""+ userInput + "\" resource : " + resource + " resourceMap: " + resourceMap) ; } if ( userInput != null && resource != null) { - if ( resourceMap != null && !resourceMap.isEmpty() && - ( resourceMap.get(DATABASE) != null || resourceMap.get(TABLE) != null || - resourceMap.get(UDF) != null || resourceMap.get(COLUMN) != null ) ) { - switch (resource.trim().toLowerCase()) { - case DATABASE: - databaseName = userInput; - databaseList = resourceMap.get(DATABASE); - break; - case TABLE: - tableName = userInput; - tableList = resourceMap.get(TABLE); - break; - case UDF: - udfName = userInput; - udfList = resourceMap.get(UDF); - break; - case COLUMN: - columnName = userInput; - columnList = resourceMap.get(COLUMN); - break; - default: - break; - } - } else { + if ( resourceMap != null && !resourceMap.isEmpty() ) { + databaseList = resourceMap.get(DATABASE); + tableList = resourceMap.get(TABLE); + udfList = resourceMap.get(UDF); + columnList = resourceMap.get(COLUMN); + } switch (resource.trim().toLowerCase()) { case DATABASE: databaseName = userInput; @@ -97,19 +97,19 @@ public class HiveResourceMgr { udfName = userInput; break; case COLUMN: - columnName = userInput; + columnName = userInput; break; default: break; } - } } if (serviceName != null && userInput != null) { try { if(LOG.isDebugEnabled()) { - LOG.debug("<== HiveResourceMgr.getHiveResources() UserInput: "+ userInput + " configs: " + configs + " context: " + context) ; + LOG.debug("<== HiveResourceMgr.getHiveResources() UserInput: "+ userInput + " configs: " + configs + " databaseList: " + databaseList + " tableList: " + + tableList + " columnList: " + columnList ) ; } final HiveClient hiveClient = new HiveConnectionMgr().getHiveConnection(serviceName, configs); @@ -121,43 +121,14 @@ public class HiveResourceMgr { final List<String> finaldatabaseList = databaseList; final List<String> finaltableList = tableList; - final List<String> finaldfsList = udfList; + final List<String> finaludfList = udfList; final List<String> finalcolumnList = columnList; - if (hiveClient != null && databaseName != null - && !databaseName.isEmpty()) { - if (tableName != null && !tableName.isEmpty()) { - if (columnName != null && !columnName.isEmpty()) { - columnName += "*"; - finalColName = columnName; - finalDbName = databaseName; - finalTableName = tableName; - - callableObj = new Callable<List<String>>() { - @Override - public List<String> call() { - return hiveClient.getColumnList(finalColName, - finaldatabaseList, - finaltableList, - finalcolumnList); - } - }; - } else { - tableName += "*"; - finalTableName = tableName; - finalDbName = databaseName; - callableObj = new Callable<List<String>>() { - - @Override - public List<String> call() { - return hiveClient.getTableList(finalTableName, - finaldatabaseList, - finaltableList); - } - - }; - } - } else { + + if ( hiveClient != null) { + if ( databaseName != null + && !databaseName.isEmpty()){ + // get the DBList for given Input databaseName += "*"; finalDbName = databaseName; callableObj = new Callable<List<String>>() { @@ -165,11 +136,40 @@ public class HiveResourceMgr { public List<String> call() { return hiveClient.getDatabaseList(finalDbName, finaldatabaseList); - } - }; + } + }; + } else if ( tableName != null + && !tableName.isEmpty()) { + // get ColumnList for given Input + tableName += "*"; + finalTableName = tableName; + callableObj = new Callable<List<String>>() { - } - + @Override + public List<String> call() { + return hiveClient.getTableList(finalTableName, + finaldatabaseList, + finaltableList); + } + }; + } else if ( columnName != null + && !columnName.isEmpty()) { + // get ColumnList for given Input + columnName += "*"; + finalColName = columnName; + finalDbName = databaseName; + finalTableName = tableName; + + callableObj = new Callable<List<String>>() { + @Override + public List<String> call() { + return hiveClient.getColumnList(finalColName, + finaldatabaseList, + finaltableList, + finalcolumnList); + } + }; + } synchronized (hiveClient) { resultList = TimedEventUtil.timedTask(callableObj, 5, TimeUnit.SECONDS); @@ -181,7 +181,9 @@ public class HiveResourceMgr { } if(LOG.isDebugEnabled()) { - LOG.debug("<== HiveResourceMgr.getHiveResources() databaseName:" + databaseName + " tableName: " + tableName + " columnName: " + columnName + "Result :" + resultList) ; + LOG.debug("<== HiveResourceMgr.getHiveResources() UserInput: "+ userInput + " configs: " + configs + " databaseList: " + databaseList + " tableList: " + + tableList + " columnList: " + columnList + "Result :" + resultList ) ; + } return resultList; http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/1283c965/knox-agent/src/main/java/org/apache/ranger/services/knox/client/KnoxResourceMgr.java ---------------------------------------------------------------------- diff --git a/knox-agent/src/main/java/org/apache/ranger/services/knox/client/KnoxResourceMgr.java b/knox-agent/src/main/java/org/apache/ranger/services/knox/client/KnoxResourceMgr.java index 8aceb5f..e0206e7 100644 --- a/knox-agent/src/main/java/org/apache/ranger/services/knox/client/KnoxResourceMgr.java +++ b/knox-agent/src/main/java/org/apache/ranger/services/knox/client/KnoxResourceMgr.java @@ -1,3 +1,22 @@ +/* + * 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.ranger.services.knox.client; import java.util.HashMap; @@ -46,22 +65,11 @@ public class KnoxResourceMgr { String knoxServiceName = null; if ( userInput != null && resource != null) { - if ( resourceMap != null && !resourceMap.isEmpty() && - ( resourceMap.get(TOPOLOGY) != null || resourceMap.get(SERVICE) != null) ) { - switch (resource.trim().toLowerCase()) { - case TOPOLOGY: - knoxTopologyName = userInput; - knoxTopologyList = resourceMap.get(TOPOLOGY); - break; - case SERVICE: - knoxServiceName = userInput; - knoxServiceList = resourceMap.get(SERVICE); - break; - default: - break; - } - } else { - switch (resource.trim().toLowerCase()) { + if ( resourceMap != null && !resourceMap.isEmpty() ) { + knoxTopologyList = resourceMap.get(TOPOLOGY); + knoxServiceList = resourceMap.get(SERVICE); + } + switch (resource.trim().toLowerCase()) { case TOPOLOGY: knoxTopologyName = userInput; break; @@ -70,8 +78,7 @@ public class KnoxResourceMgr { break; default: break; - } - } + } } String knoxUrl = configs.get("knox.url"); http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/1283c965/storm-agent/src/main/java/org/apache/ranger/services/storm/client/StormResourceMgr.java ---------------------------------------------------------------------- diff --git a/storm-agent/src/main/java/org/apache/ranger/services/storm/client/StormResourceMgr.java b/storm-agent/src/main/java/org/apache/ranger/services/storm/client/StormResourceMgr.java index d232a54..3a9f1ac 100644 --- a/storm-agent/src/main/java/org/apache/ranger/services/storm/client/StormResourceMgr.java +++ b/storm-agent/src/main/java/org/apache/ranger/services/storm/client/StormResourceMgr.java @@ -1,3 +1,22 @@ +/* + * 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.ranger.services.storm.client; import java.util.HashMap;
