JobTypeManager { public Job buildJobExecutor(final String jobId, Props jobProps, final Logger logger) throws JobTypeManagerException { final JobTypePluginSet pluginSet = getJobTypePluginSet(); Job job = null; try { final String jobType = jobProps.getString("type"); if (jobType == null || jobType.length() == 0) { throw new JobExecutionException(String.format( "The 'type' parameter for job[%s] is null or empty", jobProps)); } logger.info("Building " + jobType + " job executor. "); final Class<? extends Object> executorClass = pluginSet.getPluginClass(jobType); if (executorClass == null) { throw new JobExecutionException(String.format("Job type '" + jobType + "' is unrecognized. Could not construct job[%s] of type[%s].", jobProps, jobType)); } Props pluginJobProps = pluginSet.getPluginJobProps(jobType); if (pluginJobProps == null) { pluginJobProps = pluginSet.getCommonPluginJobProps(); } if (pluginJobProps != null) { for (final String k : pluginJobProps.getKeySet()) { if (!jobProps.containsKey(k)) { jobProps.put(k, pluginJobProps.get(k)); } } } jobProps = PropsUtils.resolveProps(jobProps); Props pluginLoadProps = pluginSet.getPluginLoaderProps(jobType); if (pluginLoadProps != null) { pluginLoadProps = PropsUtils.resolveProps(pluginLoadProps); } else { pluginLoadProps = pluginSet.getCommonPluginLoadProps(); if (pluginLoadProps == null) { pluginLoadProps = new Props(); } } try { job = (Job) Utils.callConstructor(executorClass, jobId, pluginLoadProps, jobProps, pluginSet.getPluginPrivateProps(jobType), logger); } catch (final Exception e) { logger.info("Failed with 5 inputs with exception e = " + e.getMessage()); job = (Job) Utils.callConstructor(executorClass, jobId, pluginLoadProps, jobProps, logger); } } catch (final Exception e) { logger.error("Failed to build job executor for job " + jobId + e.getMessage()); throw new JobTypeManagerException("Failed to build job executor for job " + jobId, e); } catch (final Throwable t) { logger.error( "Failed to build job executor for job " + jobId + t.getMessage(), t); throw new JobTypeManagerException("Failed to build job executor for job " + jobId, t); } return job; } JobTypeManager(final String jobtypePluginDir, final Props globalProperties,
      final ClassLoader parentClassLoader); void loadPlugins(); Job buildJobExecutor(final String jobId, Props jobProps, final Logger logger); synchronized JobTypePluginSet getJobTypePluginSet();  }
@Test public void testBuildClass() throws Exception { final Props jobProps = new Props(); jobProps.put("type", "anothertestjob"); jobProps.put("test", "test1"); jobProps.put("pluginprops3", "4"); final Job job = this.manager.buildJobExecutor("anothertestjob", jobProps, this.logger); assertTrue(job instanceof FakeJavaJob); final FakeJavaJob fjj = (FakeJavaJob) job; final Props props = fjj.getJobProps(); assertEquals("test1", props.get("test")); assertNull(props.get("pluginprops1")); assertEquals("4", props.get("pluginprops3")); assertEquals("commonprop1", props.get("commonprop1")); assertEquals("commonprop2", props.get("commonprop2")); assertEquals("commonprop3", props.get("commonprop3")); assertNull(props.get("commonprivate1")); }
@Test public void testBuildClass2() throws Exception { final Props jobProps = new Props(); jobProps.put("type", "testjob"); jobProps.put("test", "test1"); jobProps.put("pluginprops3", "4"); final Job job = this.manager.buildJobExecutor("testjob", jobProps, this.logger); assertTrue(job instanceof FakeJavaJob2); final FakeJavaJob2 fjj = (FakeJavaJob2) job; final Props props = fjj.getJobProps(); assertEquals("test1", props.get("test")); assertEquals("1", props.get("pluginprops1")); assertEquals("2", props.get("pluginprops2")); assertEquals("4", props.get("pluginprops3")); assertEquals("commonprop1", props.get("commonprop1")); assertEquals("commonprop2", props.get("commonprop2")); assertEquals("pluginprops", props.get("commonprop3")); assertNull(props.get("commonprivate1")); }