@Test public void testHandleRemoveFile() { ApplicationContext context = new ClassPathXmlApplicationContext(new String[] { "classpath:org/springframework/data/hadoop/admin/env-context.xml", "classpath:org/springframework/data/hadoop/admin/data-source-context.xml", "classpath:org/springframework/data/hadoop/admin/execution-context.xml", }); launchRequest.setApplicationContext(context); File descriptor = new File("src/test/resources/org/springframework/data/hadoop/admin/workflow/context.xml"); launchRequest.handleUploadedFile(descriptor); JobRegistry jobRegistry = context.getBean("jobRegistry", JobRegistry.class); Collection<String> jobNames = jobRegistry.getJobNames(); Assert.assertEquals(1, jobNames.size()); Assert.assertTrue(jobNames.contains("wordcount-withscript-job")); removeRequest.setApplicationContext(context); removeRequest.handleRemoveFile(descriptor); jobNames = jobRegistry.getJobNames(); Assert.assertEquals(0, jobNames.size()); }
@ServiceActivator public void handleRemoveFile(File file) { logger.info("remove file:" + file.getAbsolutePath()); if (file == null || !file.exists()) { return; } try { WorkflowArtifacts artifacts = HadoopWorkflowUtils.getWorkflowArtifacts(file.getParentFile()); if (artifacts != null) { FileSystemApplicationContextFactory factory = new FileSystemApplicationContextFactory(); factory.setApplicationContext(context); factory.setBeanClassLoader(artifacts.getWorkflowClassLoader()); factory.setResource(artifacts.getWorkflowDescriptor()); ConfigurableApplicationContext appContext = factory.createApplicationContext(); Map<String, Job> springBatchJobs = appContext.getBeansOfType(Job.class); if (springBatchJobs.size() > 0) { for (String jobName : springBatchJobs.keySet()) { HadoopWorkflowUtils.unregisterSpringBatchJob(context, jobName); } } else { String jobName = HadoopWorkflowUtils.generateSpringBatchJobName(artifacts); HadoopWorkflowUtils.unregisterSpringBatchJob(context, jobName); } } } catch (Exception e) { logger.error("handle removed file failed", e); } }
HadoopWorkflowRemoveRequestAdapter implements ApplicationContextAware { @ServiceActivator public void handleRemoveFile(File file) { logger.info("remove file:" + file.getAbsolutePath()); if (file == null || !file.exists()) { return; } try { WorkflowArtifacts artifacts = HadoopWorkflowUtils.getWorkflowArtifacts(file.getParentFile()); if (artifacts != null) { FileSystemApplicationContextFactory factory = new FileSystemApplicationContextFactory(); factory.setApplicationContext(context); factory.setBeanClassLoader(artifacts.getWorkflowClassLoader()); factory.setResource(artifacts.getWorkflowDescriptor()); ConfigurableApplicationContext appContext = factory.createApplicationContext(); Map<String, Job> springBatchJobs = appContext.getBeansOfType(Job.class); if (springBatchJobs.size() > 0) { for (String jobName : springBatchJobs.keySet()) { HadoopWorkflowUtils.unregisterSpringBatchJob(context, jobName); } } else { String jobName = HadoopWorkflowUtils.generateSpringBatchJobName(artifacts); HadoopWorkflowUtils.unregisterSpringBatchJob(context, jobName); } } } catch (Exception e) { logger.error("handle removed file failed", e); } } }
HadoopWorkflowRemoveRequestAdapter implements ApplicationContextAware { @ServiceActivator public void handleRemoveFile(File file) { logger.info("remove file:" + file.getAbsolutePath()); if (file == null || !file.exists()) { return; } try { WorkflowArtifacts artifacts = HadoopWorkflowUtils.getWorkflowArtifacts(file.getParentFile()); if (artifacts != null) { FileSystemApplicationContextFactory factory = new FileSystemApplicationContextFactory(); factory.setApplicationContext(context); factory.setBeanClassLoader(artifacts.getWorkflowClassLoader()); factory.setResource(artifacts.getWorkflowDescriptor()); ConfigurableApplicationContext appContext = factory.createApplicationContext(); Map<String, Job> springBatchJobs = appContext.getBeansOfType(Job.class); if (springBatchJobs.size() > 0) { for (String jobName : springBatchJobs.keySet()) { HadoopWorkflowUtils.unregisterSpringBatchJob(context, jobName); } } else { String jobName = HadoopWorkflowUtils.generateSpringBatchJobName(artifacts); HadoopWorkflowUtils.unregisterSpringBatchJob(context, jobName); } } } catch (Exception e) { logger.error("handle removed file failed", e); } }  }
HadoopWorkflowRemoveRequestAdapter implements ApplicationContextAware { @ServiceActivator public void handleRemoveFile(File file) { logger.info("remove file:" + file.getAbsolutePath()); if (file == null || !file.exists()) { return; } try { WorkflowArtifacts artifacts = HadoopWorkflowUtils.getWorkflowArtifacts(file.getParentFile()); if (artifacts != null) { FileSystemApplicationContextFactory factory = new FileSystemApplicationContextFactory(); factory.setApplicationContext(context); factory.setBeanClassLoader(artifacts.getWorkflowClassLoader()); factory.setResource(artifacts.getWorkflowDescriptor()); ConfigurableApplicationContext appContext = factory.createApplicationContext(); Map<String, Job> springBatchJobs = appContext.getBeansOfType(Job.class); if (springBatchJobs.size() > 0) { for (String jobName : springBatchJobs.keySet()) { HadoopWorkflowUtils.unregisterSpringBatchJob(context, jobName); } } else { String jobName = HadoopWorkflowUtils.generateSpringBatchJobName(artifacts); HadoopWorkflowUtils.unregisterSpringBatchJob(context, jobName); } } } catch (Exception e) { logger.error("handle removed file failed", e); } }  @ServiceActivator void handleRemoveFile(File file); @Override void setApplicationContext(ApplicationContext applicationContext); }
HadoopWorkflowRemoveRequestAdapter implements ApplicationContextAware { @ServiceActivator public void handleRemoveFile(File file) { logger.info("remove file:" + file.getAbsolutePath()); if (file == null || !file.exists()) { return; } try { WorkflowArtifacts artifacts = HadoopWorkflowUtils.getWorkflowArtifacts(file.getParentFile()); if (artifacts != null) { FileSystemApplicationContextFactory factory = new FileSystemApplicationContextFactory(); factory.setApplicationContext(context); factory.setBeanClassLoader(artifacts.getWorkflowClassLoader()); factory.setResource(artifacts.getWorkflowDescriptor()); ConfigurableApplicationContext appContext = factory.createApplicationContext(); Map<String, Job> springBatchJobs = appContext.getBeansOfType(Job.class); if (springBatchJobs.size() > 0) { for (String jobName : springBatchJobs.keySet()) { HadoopWorkflowUtils.unregisterSpringBatchJob(context, jobName); } } else { String jobName = HadoopWorkflowUtils.generateSpringBatchJobName(artifacts); HadoopWorkflowUtils.unregisterSpringBatchJob(context, jobName); } } } catch (Exception e) { logger.error("handle removed file failed", e); } }  @ServiceActivator void handleRemoveFile(File file); @Override void setApplicationContext(ApplicationContext applicationContext);  }