junit test fixes Change-Id: I9bebb592c3e1f5705c2c2d4a18fa6037409f65d3
Project: http://git-wip-us.apache.org/repos/asf/oozie/repo Commit: http://git-wip-us.apache.org/repos/asf/oozie/commit/40ee3200 Tree: http://git-wip-us.apache.org/repos/asf/oozie/tree/40ee3200 Diff: http://git-wip-us.apache.org/repos/asf/oozie/diff/40ee3200 Branch: refs/heads/oya Commit: 40ee3200f6d86c93141d54f1de6ddd228ae66d81 Parents: 2f99ad1 Author: Gezapeti Cseh <gezap...@gmail.com> Authored: Wed May 10 14:03:20 2017 -0700 Committer: Gezapeti Cseh <gezap...@gmail.com> Committed: Wed May 10 14:04:00 2017 -0700 ---------------------------------------------------------------------- .../hadoop/CredentialsProviderFactory.java | 19 ++++++++++++---- .../oozie/action/hadoop/JavaActionExecutor.java | 8 +++---- .../action/hadoop/TestJavaActionExecutor.java | 2 ++ .../oozie/action/hadoop/LauncherMain.java | 23 +++++++++++--------- 4 files changed, 34 insertions(+), 18 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/oozie/blob/40ee3200/core/src/main/java/org/apache/oozie/action/hadoop/CredentialsProviderFactory.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/oozie/action/hadoop/CredentialsProviderFactory.java b/core/src/main/java/org/apache/oozie/action/hadoop/CredentialsProviderFactory.java index fc8c065..ddffc79 100644 --- a/core/src/main/java/org/apache/oozie/action/hadoop/CredentialsProviderFactory.java +++ b/core/src/main/java/org/apache/oozie/action/hadoop/CredentialsProviderFactory.java @@ -22,6 +22,7 @@ import java.io.IOException; import java.util.HashMap; import java.util.Map; +import com.google.common.annotations.VisibleForTesting; import org.apache.hadoop.security.UserGroupInformation; import org.apache.oozie.service.ConfigurationService; import org.apache.oozie.util.XLog; @@ -29,17 +30,23 @@ import org.apache.oozie.util.XLog; public class CredentialsProviderFactory { public static final String CRED_KEY = "oozie.credentials.credentialclasses"; private static final XLog LOG = XLog.getLog(CredentialsProviderFactory.class); - private static final Map<String, Class<CredentialsProvider>> providerCache = new HashMap<>(); private static CredentialsProviderFactory instance; + private final Map<String, Class<CredentialsProvider>> providerCache; - public static CredentialsProviderFactory getInstance() throws ClassNotFoundException { + @VisibleForTesting + static void destroy() { + instance = null; + } + + public static CredentialsProviderFactory getInstance() throws Exception { if(instance == null) { instance = new CredentialsProviderFactory(); } return instance; } - private CredentialsProviderFactory() throws ClassNotFoundException { + private CredentialsProviderFactory() throws Exception { + providerCache = new HashMap<>(); for (String function : ConfigurationService.getStrings(CRED_KEY)) { function = trim(function); LOG.debug("Creating Credential class for : " + function); @@ -72,7 +79,11 @@ public class CredentialsProviderFactory { * @throws Exception */ public CredentialsProvider createCredentialsProvider(String type) throws Exception { - return providerCache.get(type).newInstance(); + Class<CredentialsProvider> providerClass = providerCache.get(type); + if(providerClass == null){ + return null; + } + return providerClass.newInstance(); } /** http://git-wip-us.apache.org/repos/asf/oozie/blob/40ee3200/core/src/main/java/org/apache/oozie/action/hadoop/JavaActionExecutor.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/oozie/action/hadoop/JavaActionExecutor.java b/core/src/main/java/org/apache/oozie/action/hadoop/JavaActionExecutor.java index 1e686c0..f3e5e32 100644 --- a/core/src/main/java/org/apache/oozie/action/hadoop/JavaActionExecutor.java +++ b/core/src/main/java/org/apache/oozie/action/hadoop/JavaActionExecutor.java @@ -1500,14 +1500,14 @@ public class JavaActionExecutor extends ActionExecutor { final Configuration jobConf = createBaseHadoopConf(context, actionXml); String launcherTag = LauncherHelper.getActionYarnTag(jobConf, context.getWorkflow().getParentId(), action); jobConf.set(LauncherMain.CHILD_MAPREDUCE_JOB_TAGS, LauncherHelper.getTag(launcherTag)); - jobConf.set(LauncherMain.OOZIE_JOB_LAUNCH_TIME, Long.toString(action.getStartTime().getTime())); yarnClient = createYarnClient(context, jobConf); - for(ApplicationId id : LauncherMain.getChildYarnJobs(jobConf, ApplicationsRequestScope.ALL)){ - yarnClient.killApplication(id); - } if(action.getExternalId() != null) { yarnClient.killApplication(ConverterUtils.toApplicationId(action.getExternalId())); } + for(ApplicationId id : LauncherMain.getChildYarnJobs(jobConf, ApplicationsRequestScope.ALL, + action.getStartTime().getTime())){ + yarnClient.killApplication(id); + } context.setExternalStatus(KILLED); context.setExecutionData(KILLED, null); http://git-wip-us.apache.org/repos/asf/oozie/blob/40ee3200/core/src/test/java/org/apache/oozie/action/hadoop/TestJavaActionExecutor.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/oozie/action/hadoop/TestJavaActionExecutor.java b/core/src/test/java/org/apache/oozie/action/hadoop/TestJavaActionExecutor.java index c3ff968..972cc1c 100644 --- a/core/src/test/java/org/apache/oozie/action/hadoop/TestJavaActionExecutor.java +++ b/core/src/test/java/org/apache/oozie/action/hadoop/TestJavaActionExecutor.java @@ -876,6 +876,7 @@ public class TestJavaActionExecutor extends ActionExecutorTestCase { assertEquals("val3", prop.getProperties().get("prop3")); // Try to load the token without it being defined in oozie-site; should get an exception + CredentialsProviderFactory.destroy(); JobConf credentialsConf = new JobConf(); Credentials credentials = new Credentials(); Configuration launcherConf = ae.createBaseHadoopConf(context, actionXmlconf); @@ -889,6 +890,7 @@ public class TestJavaActionExecutor extends ActionExecutorTestCase { assertTrue(aee.getMessage().contains("type [abc]")); assertTrue(aee.getMessage().contains("name [abcname]")); } + CredentialsProviderFactory.destroy(); // Define 'abc' token type in oozie-site ConfigurationService.set("oozie.credentials.credentialclasses", "abc=org.apache.oozie.action.hadoop.InsertTestToken"); http://git-wip-us.apache.org/repos/asf/oozie/blob/40ee3200/sharelib/oozie/src/main/java/org/apache/oozie/action/hadoop/LauncherMain.java ---------------------------------------------------------------------- diff --git a/sharelib/oozie/src/main/java/org/apache/oozie/action/hadoop/LauncherMain.java b/sharelib/oozie/src/main/java/org/apache/oozie/action/hadoop/LauncherMain.java index 5ec509c..0f14ec0 100644 --- a/sharelib/oozie/src/main/java/org/apache/oozie/action/hadoop/LauncherMain.java +++ b/sharelib/oozie/src/main/java/org/apache/oozie/action/hadoop/LauncherMain.java @@ -189,8 +189,8 @@ public abstract class LauncherMain { return getChildYarnJobs(actionConf, ApplicationsRequestScope.OWN); } - public static Set<ApplicationId> getChildYarnJobs(Configuration actionConf, ApplicationsRequestScope scope) { - System.out.println("Fetching child yarn jobs"); + public static Set<ApplicationId> getChildYarnJobs(Configuration actionConf, ApplicationsRequestScope scope, + long startTime) { Set<ApplicationId> childYarnJobs = new HashSet<ApplicationId>(); String tag = actionConf.get(CHILD_MAPREDUCE_JOB_TAGS); if (tag == null) { @@ -198,17 +198,9 @@ public abstract class LauncherMain { return childYarnJobs; } System.out.println("tag id : " + tag); - long startTime = 0L; - try { - startTime = Long.parseLong(System.getProperty(OOZIE_JOB_LAUNCH_TIME)); - } catch(NumberFormatException nfe) { - throw new RuntimeException("Could not find Oozie job launch time", nfe); - } - GetApplicationsRequest gar = GetApplicationsRequest.newInstance(); gar.setScope(scope); gar.setApplicationTags(Collections.singleton(tag)); - long endTime = System.currentTimeMillis(); if (startTime > endTime) { System.out.println("WARNING: Clock skew between the Oozie server host and this host detected. Please fix this. " + @@ -236,6 +228,17 @@ public abstract class LauncherMain { System.out.println("Child yarn jobs are found - " + StringUtils.join(childYarnJobs, ",")); return childYarnJobs; } + public static Set<ApplicationId> getChildYarnJobs(Configuration actionConf, ApplicationsRequestScope scope) { + System.out.println("Fetching child yarn jobs"); + + long startTime = 0L; + try { + startTime = Long.parseLong(System.getProperty(OOZIE_JOB_LAUNCH_TIME)); + } catch(NumberFormatException nfe) { + throw new RuntimeException("Could not find Oozie job launch time", nfe); + } + return getChildYarnJobs(actionConf, scope, startTime); + } public static void killChildYarnJobs(Configuration actionConf) { try {