Repository: oozie Updated Branches: refs/heads/master dd053ebf0 -> 9dc474e83
OOZIE-2588 Support getting credentials for same cluster hcat when credentials config is empty (satishsaley via rohini) Project: http://git-wip-us.apache.org/repos/asf/oozie/repo Commit: http://git-wip-us.apache.org/repos/asf/oozie/commit/9dc474e8 Tree: http://git-wip-us.apache.org/repos/asf/oozie/tree/9dc474e8 Diff: http://git-wip-us.apache.org/repos/asf/oozie/diff/9dc474e8 Branch: refs/heads/master Commit: 9dc474e8313638680bd674ff9d0e81f760ab82a4 Parents: dd053eb Author: Rohini Palaniswamy <roh...@apache.org> Authored: Mon Sep 19 09:49:46 2016 -0700 Committer: Rohini Palaniswamy <roh...@apache.org> Committed: Mon Sep 19 09:49:46 2016 -0700 ---------------------------------------------------------------------- core/pom.xml | 18 +++++++ .../oozie/action/hadoop/HCatCredentials.java | 49 +++++++++++++++++--- pom.xml | 23 ++++++++- release-log.txt | 1 + 4 files changed, 84 insertions(+), 7 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/oozie/blob/9dc474e8/core/pom.xml ---------------------------------------------------------------------- diff --git a/core/pom.xml b/core/pom.xml index 62ace06..4c63cca 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -321,6 +321,24 @@ </dependency> <dependency> + <groupId>org.powermock</groupId> + <artifactId>powermock-core</artifactId> + <scope>test</scope> + </dependency> + + <dependency> + <groupId>org.powermock</groupId> + <artifactId>powermock-api-mockito</artifactId> + <scope>test</scope> + </dependency> + + <dependency> + <groupId>org.powermock</groupId> + <artifactId>powermock-module-junit4</artifactId> + <scope>test</scope> + </dependency> + + <dependency> <groupId>org.apache.activemq</groupId> <artifactId>activemq-broker</artifactId> <scope>test</scope> http://git-wip-us.apache.org/repos/asf/oozie/blob/9dc474e8/core/src/main/java/org/apache/oozie/action/hadoop/HCatCredentials.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/oozie/action/hadoop/HCatCredentials.java b/core/src/main/java/org/apache/oozie/action/hadoop/HCatCredentials.java index 330e6e3..d7689a9 100644 --- a/core/src/main/java/org/apache/oozie/action/hadoop/HCatCredentials.java +++ b/core/src/main/java/org/apache/oozie/action/hadoop/HCatCredentials.java @@ -18,11 +18,19 @@ package org.apache.oozie.action.hadoop; +import java.util.HashMap; + +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.hive.conf.HiveConf; import org.apache.hadoop.mapred.JobConf; import org.apache.oozie.ErrorCode; import org.apache.oozie.action.ActionExecutor.Context; +import org.apache.oozie.service.HCatAccessorService; +import org.apache.oozie.service.Services; import org.apache.oozie.util.XLog; +import com.google.common.annotations.VisibleForTesting; + /** * Credentials implementation to store in jobConf, HCat-specific properties such as Principal and Uri * User specifies these credential properties along with the action configuration @@ -37,6 +45,10 @@ public class HCatCredentials extends Credentials { private static final String HCAT_METASTORE_URI = "hcat.metastore.uri"; private static final String HIVE_METASTORE_PRINCIPAL = "hive.metastore.kerberos.principal"; private static final String HIVE_METASTORE_URI = "hive.metastore.uris"; + private final static Configuration hiveConf = new Configuration(false); + static { + hiveConf.addResource("hive-site.xml"); + } /* (non-Javadoc) * @see org.apache.oozie.action.hadoop.Credentials#addtoJobConf(org.apache.hadoop.mapred.JobConf, org.apache.oozie.action.hadoop.CredentialsProperties, org.apache.oozie.action.ActionExecutor.Context) @@ -44,15 +56,14 @@ public class HCatCredentials extends Credentials { @Override public void addtoJobConf(JobConf jobconf, CredentialsProperties props, Context context) throws Exception { try { - String principal = props.getProperties().get(HCAT_METASTORE_PRINCIPAL) == null - ? props.getProperties().get(HIVE_METASTORE_PRINCIPAL) - : props.getProperties().get(HCAT_METASTORE_PRINCIPAL); + + String principal = getProperty(props.getProperties(), HCAT_METASTORE_PRINCIPAL, HIVE_METASTORE_PRINCIPAL); if (principal == null || principal.isEmpty()) { throw new CredentialException(ErrorCode.E0510, HCAT_METASTORE_PRINCIPAL + " is required to get hcat credential"); } - String server = props.getProperties().get(HCAT_METASTORE_URI) == null - ? props.getProperties().get(HIVE_METASTORE_URI) : props.getProperties().get(HCAT_METASTORE_URI); + + String server = getProperty(props.getProperties(), HCAT_METASTORE_URI, HIVE_METASTORE_URI); if (server == null || server.isEmpty()) { throw new CredentialException(ErrorCode.E0510, HCAT_METASTORE_URI + " is required to get hcat credential"); @@ -65,4 +76,30 @@ public class HCatCredentials extends Credentials { throw e; } } -} + + /** + * Returns the value for the oozieConfName if its present in prop map else + * value of hiveConfName. It will also check HCatAccessorService and + * HiveConf for hiveConfName. + * + * @param prop + * @param oozieConfName + * @param hiveConfName + * @return value for the oozieConfName if its present else value of + * hiveConfName. If both are absent then returns null. + */ + private String getProperty(HashMap<String, String> prop, String oozieConfName, String hiveConfName) { + String value = prop.get(oozieConfName) == null ? prop.get(hiveConfName) : prop.get(oozieConfName); + if (value == null || value.isEmpty()) { + HCatAccessorService hCatService = Services.get().get(HCatAccessorService.class); + Configuration hCatConf = hCatService.getHCatConf(); + if (hCatConf != null) { + value = hCatConf.get(hiveConfName); + } + } + if (value == null || value.isEmpty()) { + value = hiveConf.get(hiveConfName); + } + return value; + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/oozie/blob/9dc474e8/pom.xml ---------------------------------------------------------------------- diff --git a/pom.xml b/pom.xml index 0712d4c..5a8e5f5 100644 --- a/pom.xml +++ b/pom.xml @@ -1332,7 +1332,28 @@ <dependency> <groupId>org.mockito</groupId> <artifactId>mockito-all</artifactId> - <version>1.8.5</version> + <version>1.10.19</version> + </dependency> + + <dependency> + <groupId>org.powermock</groupId> + <artifactId>powermock-core</artifactId> + <version>1.6.4</version> + <scope>test</scope> + </dependency> + + <dependency> + <groupId>org.powermock</groupId> + <artifactId>powermock-api-mockito</artifactId> + <version>1.6.4</version> + <scope>test</scope> + </dependency> + + <dependency> + <groupId>org.powermock</groupId> + <artifactId>powermock-module-junit4</artifactId> + <version>1.6.4</version> + <scope>test</scope> </dependency> <dependency> http://git-wip-us.apache.org/repos/asf/oozie/blob/9dc474e8/release-log.txt ---------------------------------------------------------------------- diff --git a/release-log.txt b/release-log.txt index 247886c..d1e36be 100644 --- a/release-log.txt +++ b/release-log.txt @@ -1,5 +1,6 @@ -- Oozie 4.3.0 release (trunk - unreleased) +OOZIE-2588 Support getting credentials for same cluster hcat when credentials config is empty (satishsaley via rohini) OOZIE-2538 Update HttpClient versions to close security vulnerabilities (abhishekbafna via rkanter) OOZIE-2037 Add TLSv1.1,TLSv1.2 (rkanter) OOZIE-2500 -DtestJarSimple option mentioned in minioozie doc does not work (abhishekbafna via rkanter)