Skip to content
Browse files

remove service folder

  • Loading branch information...
1 parent 4970c7a commit ae52497624e87f418fe034226b0fca46f4f36ba8 @leejianwei leejianwei committed
Showing with 0 additions and 5,397 deletions.
  1. +0 −1 service/.gitignore
  2. +0 −52 service/build.gradle
  3. +0 −13 service/gradle.properties
  4. +0 −58 service/src/main/java/org/springframework/data/hadoop/admin/SpringHadoopAdminException.java
  5. +0 −57 service/src/main/java/org/springframework/data/hadoop/admin/SpringHadoopAdminWorkflowException.java
  6. +0 −278 service/src/main/java/org/springframework/data/hadoop/admin/service/BaseFileService.java
  7. +0 −81 service/src/main/java/org/springframework/data/hadoop/admin/service/FileInfo.java
  8. +0 −28 service/src/main/java/org/springframework/data/hadoop/admin/service/FileRemover.java
  9. +0 −28 service/src/main/java/org/springframework/data/hadoop/admin/service/FileSender.java
  10. +0 −46 service/src/main/java/org/springframework/data/hadoop/admin/service/FileService.java
  11. +0 −63 service/src/main/java/org/springframework/data/hadoop/admin/service/SimpleTemplateService.java
  12. +0 −149 service/src/main/java/org/springframework/data/hadoop/admin/service/SimpleWorkflowService.java
  13. +0 −72 service/src/main/java/org/springframework/data/hadoop/admin/service/TemplateInfo.java
  14. +0 −29 service/src/main/java/org/springframework/data/hadoop/admin/service/TemplateService.java
  15. +0 −106 service/src/main/java/org/springframework/data/hadoop/admin/service/WorkflowInfo.java
  16. +0 −31 service/src/main/java/org/springframework/data/hadoop/admin/service/WorkflowService.java
  17. +0 −34 service/src/main/java/org/springframework/data/hadoop/admin/util/Constant.java
  18. +0 −195 service/src/main/java/org/springframework/data/hadoop/admin/util/HadoopWorkflowDescriptorUtils.java
  19. +0 −447 service/src/main/java/org/springframework/data/hadoop/admin/util/HadoopWorkflowUtils.java
  20. +0 −162 service/src/main/java/org/springframework/data/hadoop/admin/web/TemplateController.java
  21. +0 −27 service/src/main/java/org/springframework/data/hadoop/admin/web/TemplateMenu.java
  22. +0 −168 service/src/main/java/org/springframework/data/hadoop/admin/web/WorkflowController.java
  23. +0 −27 service/src/main/java/org/springframework/data/hadoop/admin/web/WorkflowMenu.java
  24. +0 −43 service/src/main/java/org/springframework/data/hadoop/admin/workflow/HadoopWorkflowDirectory.java
  25. +0 −72 ...e/src/main/java/org/springframework/data/hadoop/admin/workflow/HadoopWorkflowDirectoryFilter.java
  26. +0 −72 .../main/java/org/springframework/data/hadoop/admin/workflow/HadoopWorkflowLaunchRequestAdapter.java
  27. +0 −93 .../main/java/org/springframework/data/hadoop/admin/workflow/HadoopWorkflowRemoveRequestAdapter.java
  28. +0 −65 service/src/main/java/org/springframework/data/hadoop/admin/workflow/SimpleSpringHadoopTasklet.java
  29. +0 −287 ...a/org/springframework/data/hadoop/admin/workflow/support/FileSystemApplicationContextFactory.java
  30. +0 −174 .../springframework/data/hadoop/admin/workflow/support/FileSystemApplicationContextsFactoryBean.java
  31. +0 −111 ...org/springframework/data/hadoop/admin/workflow/support/FileSystemWorkflowResourceFactoryBean.java
  32. +0 −71 service/src/main/java/org/springframework/data/hadoop/admin/workflow/support/WorkflowArtifacts.java
  33. +0 −31 ...ces/META-INF/spring/batch/bootstrap/spring-hadoop-admin/spring-hadoop-admin-execution-context.xml
  34. +0 −47 service/src/main/resources/META-INF/spring/batch/jobs/spring-hadoop-admin-workflow-context.xml
  35. +0 −53 ...rc/main/resources/META-INF/spring/batch/override/integration/spring-hadoop-admin-file-context.xml
  36. +0 −11 ...c/main/resources/META-INF/spring/batch/servlet/override/spring-hadoo-admin-controller-context.xml
  37. +0 −14 .../src/main/resources/META-INF/spring/batch/servlet/override/spring-hadoo-admin-message-context.xml
  38. +0 −60 ...src/main/resources/META-INF/spring/batch/servlet/override/spring-hadoop-admin-manager-context.xml
  39. 0 service/src/main/resources/batch-admin-dummy-business-schema.sql
  40. +0 −16 service/src/main/resources/batch-hsql.properties
  41. +0 −3 service/src/main/resources/core-site.xml
  42. +0 −7 service/src/main/resources/log4j.properties
  43. +0 −32 service/src/main/resources/ui-messages.properties
  44. +0 −51 service/src/main/webapp/WEB-INF/web.xml
  45. +0 −88 service/src/main/webapp/WEB-INF/web/manager/templates/html/templates.ftl
  46. +0 −17 service/src/main/webapp/WEB-INF/web/manager/templates/json/templates.ftl
  47. +0 −129 service/src/main/webapp/WEB-INF/web/manager/workflows/html/workflows.ftl
  48. +0 −27 service/src/main/webapp/WEB-INF/web/manager/workflows/json/workflows.ftl
  49. +0 −1 service/src/main/webapp/index.jsp
  50. +0 −130 ...e/src/test/java/org/springframework/data/hadoop/admin/util/HadoopWorkflowDescriptorUtilsTest.java
  51. +0 −293 service/src/test/java/org/springframework/data/hadoop/admin/util/HadoopWorkflowUtilsTest.java
  52. +0 −41 service/src/test/java/org/springframework/data/hadoop/admin/util/SimpleBean.java
  53. +0 −100 ...c/test/java/org/springframework/data/hadoop/admin/workflow/HadoopWorkflowDirectoryFilterTest.java
  54. +0 −67 ...ice/src/test/java/org/springframework/data/hadoop/admin/workflow/HadoopWorkflowDirectoryTest.java
  55. +0 −73 ...t/java/org/springframework/data/hadoop/admin/workflow/HadoopWorkflowLaunchRequestAdapterTest.java
  56. +0 −84 ...t/java/org/springframework/data/hadoop/admin/workflow/HadoopWorkflowRemoveRequestAdapterTest.java
  57. +0 −97 ...e/src/test/java/org/springframework/data/hadoop/admin/workflow/SimpleSpringHadoopTaskletTest.java
  58. +0 −136 ...g/springframework/data/hadoop/admin/workflow/support/FileSystemApplicationContextFactoryTest.java
  59. +0 −96 ...ingframework/data/hadoop/admin/workflow/support/FileSystemApplicationContextsFactoryBeanTest.java
  60. +0 −90 ...springframework/data/hadoop/admin/workflow/support/FileSystemWorkflowResourceFactoryBeanTest.java
  61. +0 −96 ...e/src/test/java/org/springframework/data/hadoop/admin/workflow/support/WorkflowArtifactsTest.java
  62. 0 service/src/test/resources/batch-admin-dummy-business-schema.sql
  63. +0 −16 service/src/test/resources/batch-hsql.properties
  64. +0 −11 service/src/test/resources/batch.properties
  65. +0 −17 service/src/test/resources/log4j.properties
  66. +0 −29 service/src/test/resources/org/springframework/data/hadoop/admin/data-source-context.xml
  67. +0 −20 service/src/test/resources/org/springframework/data/hadoop/admin/env-context.xml
  68. +0 −49 service/src/test/resources/org/springframework/data/hadoop/admin/execution-context.xml
  69. +0 −8 service/src/test/resources/org/springframework/data/hadoop/admin/util/context.xml
  70. BIN service/src/test/resources/org/springframework/data/hadoop/admin/util/hadoop-examples-1.0.0.jar
  71. +0 −2 service/src/test/resources/org/springframework/data/hadoop/admin/util/hadoop.properties
  72. +0 −10 service/src/test/resources/org/springframework/data/hadoop/admin/util/invalid-context.xml
  73. +0 −8 service/src/test/resources/org/springframework/data/hadoop/admin/util/test/context.xml
  74. BIN service/src/test/resources/org/springframework/data/hadoop/admin/util/test/hadoop-examples-1.0.0.jar
  75. +0 −2 service/src/test/resources/org/springframework/data/hadoop/admin/util/test/hadoop.properties
  76. +0 −24 service/src/test/resources/org/springframework/data/hadoop/admin/util/testSpringBatchJob/context.xml
  77. BIN ...resources/org/springframework/data/hadoop/admin/util/testSpringBatchJob/hadoop-examples-1.0.0.jar
  78. +0 −8 ...rc/test/resources/org/springframework/data/hadoop/admin/util/testSpringBatchJob/hadoop.properties
  79. BIN ...ources/org/springframework/data/hadoop/admin/util/testWithoutDescriptor/hadoop-examples-1.0.0.jar
  80. +0 −2 ...test/resources/org/springframework/data/hadoop/admin/util/testWithoutDescriptor/hadoop.properties
  81. +0 −8 ...e/src/test/resources/org/springframework/data/hadoop/admin/util/testWithoutProperties/context.xml
  82. BIN ...ources/org/springframework/data/hadoop/admin/util/testWithoutProperties/hadoop-examples-1.0.0.jar
  83. +0 −38 ...c/test/resources/org/springframework/data/hadoop/admin/util/testWithoutSpringBatchJob/context.xml
  84. BIN ...es/org/springframework/data/hadoop/admin/util/testWithoutSpringBatchJob/hadoop-examples-1.0.0.jar
  85. +0 −8 .../resources/org/springframework/data/hadoop/admin/util/testWithoutSpringBatchJob/hadoop.properties
  86. +0 −8 service/src/test/resources/org/springframework/data/hadoop/admin/util/withoutJars/context.xml
  87. +0 −2 service/src/test/resources/org/springframework/data/hadoop/admin/util/withoutJars/hadoop.properties
  88. +0 −23 service/src/test/resources/org/springframework/data/hadoop/admin/workflow/context.xml
  89. BIN service/src/test/resources/org/springframework/data/hadoop/admin/workflow/hadoop-examples-1.0.0.jar
  90. +0 −8 service/src/test/resources/org/springframework/data/hadoop/admin/workflow/hadoop.properties
  91. +0 −24 service/src/test/resources/org/springframework/data/hadoop/admin/workflow/support/context.xml
  92. +0 −23 service/src/test/resources/org/springframework/data/hadoop/admin/workflow/support/copy/context.xml
  93. BIN ...t/resources/org/springframework/data/hadoop/admin/workflow/support/copy/hadoop-examples-1.0.0.jar
  94. +0 −8 .../src/test/resources/org/springframework/data/hadoop/admin/workflow/support/copy/hadoop.properties
  95. BIN ...c/test/resources/org/springframework/data/hadoop/admin/workflow/support/hadoop-examples-1.0.0.jar
  96. +0 −8 service/src/test/resources/org/springframework/data/hadoop/admin/workflow/support/hadoop.properties
  97. +0 −3 settings.gradle
View
1 service/.gitignore
@@ -1 +0,0 @@
-example.log
View
52 service/build.gradle
@@ -1,52 +0,0 @@
-description = 'Spring Hadoop Admin Service'
-
-apply plugin: 'war'
-apply plugin: 'jetty'
-apply plugin: 'eclipse-wtp'
-
-repositories {
- maven { url "http://www.datanucleus.org/downloads/maven2/" }
-}
-
-dependencies {
- compile "org.springframework.data:spring-data-hadoop:$springHadoopVersion"
-
-
- runtime "org.codehaus.jackson:jackson-core-asl:$jacksonVersion"
- runtime "org.codehaus.jackson:jackson-mapper-asl:$jacksonVersion"
- runtime "commons-lang:commons-lang:$commonsLangVersion"
- runtime "org.codehaus.groovy:groovy:$groovyVersion"
- runtime "hsqldb:hsqldb:$hsqldbVersion"
-
- //pig
- runtime "org.apache.pig:pig:$pigVersion"
- runtime "jline:jline:$jlineVersion"
- runtime "org.antlr:antlr:$antlrVersion"
-
- //hive
- runtime "javax.jdo:jdo2-api:$jdoVersion"
- runtime "org.apache.hive:hive-service:$hiveVersion"
- runtime "org.apache.hive:hive-metastore:$hiveVersion"
- runtime "org.apache.hive:hive-jdbc:$hiveVersion"
-
- //log
- runtime "org.slf4j:slf4j-api:$slf4jVersion"
- runtime "org.slf4j:slf4j-log4j12:$slf4jVersion"
- runtime "org.slf4j:jcl-over-slf4j:$slf4jVersion"
-
- testCompile "com.google.guava:guava:12.0"
-}
-
-war {
- baseName "spring-hadoop-admin"
-}
-
-eclipse {
- project {
- name = "spring-hadoop-admin-service"
- }
-}
-
-httpPort = 8081
-
-defaultTasks 'clean', 'build'
View
13 service/gradle.properties
@@ -1,13 +0,0 @@
-jacksonVersion = 1.9.6
-pigVersion = 0.9.2
-jlineVersion = 1.0
-antlrVersion = 3.1.1
-hiveVersion = 0.8.1
-jdoVersion = 2.3-ec
-groovyVersion = 1.8.5
-hsqldbVersion=1.8.0.7
-commonsLangVersion = 2.4
-springHadoopVersion = 1.0.0.BUILD-SNAPSHOT
-slf4jVersion = 1.6.1
-
-
View
58 service/src/main/java/org/springframework/data/hadoop/admin/SpringHadoopAdminException.java
@@ -1,58 +0,0 @@
-/*
- * Copyright 2011-2012 the original author or authors.
- *
- * Licensed 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.springframework.data.hadoop.admin;
-
-/**
- * Base class for Spring Hadoop Admin exception handling
- *
- * @author Jarred Li
- *
- */
-public class SpringHadoopAdminException extends Exception {
-
- /**
- *
- */
- private static final long serialVersionUID = -2954725715945849099L;
-
-
- /**
- * Default constructor
- *
- */
- public SpringHadoopAdminException() {
- super();
- }
-
- /**
- * constructor with message
- *
- * @param message The message for this exception
- */
- public SpringHadoopAdminException(String message) {
- super(message);
- }
-
- /**
- * constructor with message and throwable
- *
- * @param message The message for this exception
- * @param t
- */
- public SpringHadoopAdminException(String message, Throwable t) {
- super(message, t);
- }
-}
View
57 ...c/main/java/org/springframework/data/hadoop/admin/SpringHadoopAdminWorkflowException.java
@@ -1,57 +0,0 @@
-/*
- * Copyright 2011-2012 the original author or authors.
- *
- * Licensed 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.springframework.data.hadoop.admin;
-
-
-/**
- * Exception to handle abnormal workflow operations
- *
- * @author Jarred Li
- *
- */
-public class SpringHadoopAdminWorkflowException extends SpringHadoopAdminException {
-
- /**
- *
- */
- private static final long serialVersionUID = -7884675315021716510L;
-
- /**
- * default constructor
- */
- public SpringHadoopAdminWorkflowException() {
- super();
- }
-
- /**
- * Exception with message
- *
- * @param message
- */
- public SpringHadoopAdminWorkflowException(String message) {
- super(message);
- }
-
- /**
- * Exception with message and throwable
- *
- * @param message
- * @param t
- */
- public SpringHadoopAdminWorkflowException(String message, Throwable t) {
- super(message, t);
- }
-}
View
278 service/src/main/java/org/springframework/data/hadoop/admin/service/BaseFileService.java
@@ -1,278 +0,0 @@
-/*
- * Copyright 2009-2010 the original author or authors.
- *
- * Licensed 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.springframework.data.hadoop.admin.service;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.List;
-
-import org.apache.commons.io.FileUtils;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.springframework.beans.factory.InitializingBean;
-import org.springframework.context.ResourceLoaderAware;
-import org.springframework.core.io.ContextResource;
-import org.springframework.core.io.DefaultResourceLoader;
-import org.springframework.core.io.FileSystemResource;
-import org.springframework.core.io.Resource;
-import org.springframework.core.io.ResourceLoader;
-import org.springframework.core.io.support.ResourcePatternResolver;
-import org.springframework.core.io.support.ResourcePatternUtils;
-import org.springframework.data.hadoop.admin.util.Constant;
-import org.springframework.util.Assert;
-
-/**
- *
- * @author Dave Syer
- * @author Jarred Li
- *
- */
-public class BaseFileService implements FileService, InitializingBean, ResourceLoaderAware{
-
- private File outputDir = new File(System.getProperty("java.io.tmpdir", "/tmp"), Constant.ROOT_LOCATION);
-
- private static final Log logger = LogFactory.getLog(BaseFileService.class);
-
- private ResourceLoader resourceLoader = new DefaultResourceLoader();
-
- private FileSender fileSender;
-
- private FileRemover fileRemover;
-
-
-
- public void setFileRemover(FileRemover fileRemover) {
- this.fileRemover = fileRemover;
- }
-
- public void setResourceLoader(ResourceLoader resourceLoader) {
- this.resourceLoader = resourceLoader;
- }
-
- public void setFileSender(FileSender fileSender) {
- this.fileSender = fileSender;
- }
-
- /**
- * The output directory to store new files. Defaults to
- * <code>${java.io.tmpdir}/batch/files</code>.
- * @param outputDir the output directory to set
- */
- public void setOutputDir(File outputDir) {
- this.outputDir = outputDir;
- }
-
- public File getOutputDir(){
- return this.outputDir;
- }
-
- public void afterPropertiesSet() throws Exception {
- Assert.state(fileSender != null, "A WorkflowSender must be provided");
- Assert.state(fileRemover != null, "A WorkflowRemover must be provided");
- if (!outputDir.exists()) {
- Assert.state(outputDir.mkdirs(), "Cannot create output directory " + outputDir);
- }
- Assert.state(outputDir.exists(), "Output directory does not exist " + outputDir);
- Assert.state(outputDir.isDirectory(), "Output file is not a directory " + outputDir);
- }
-
- public FileInfo createFile(String path) throws IOException {
-
- path = sanitize(path);
-
- Assert.hasText(path, "The file path must not be empty");
-
- String name = path.substring(path.lastIndexOf("/") + 1);
- String parent = path.substring(0, path.lastIndexOf(name));
- if (parent.endsWith("/")) {
- parent = parent.substring(0, parent.length() - 1);
- }
-
- File directory = new File(outputDir, parent);
- directory.mkdirs();
- Assert.state(directory.exists() && directory.isDirectory(), "Could not create directory: " + directory);
-
- FileInfo result = new FileInfo(path);
- File dest = new File(outputDir, result.getFileName());
- dest.createNewFile();
-
- return result;
-
- }
-
- /**
- * @param target the target file
- * @return the path to the file from the base output directory
- */
- private String extractPath(File target) {
- String outputPath = outputDir.getAbsolutePath();
- return target.getAbsolutePath().substring(outputPath.length() + 1).replace("\\", "/");
- }
-
- public boolean publish(FileInfo dest) throws IOException {
- String path = dest.getPath();
- fileSender.send(getResource(path).getFile());
- return true;
- }
-
- public int countFiles() {
- ResourcePatternResolver resolver = ResourcePatternUtils.getResourcePatternResolver(resourceLoader);
- Resource[] resources;
- try {
- resources = resolver.getResources("file:///" + outputDir.getAbsolutePath() + "/**");
- } catch (IOException e) {
- throw new IllegalStateException("Unexpected problem resolving files", e);
- }
- return resources.length;
- }
-
- public List<FileInfo> getFiles(int startFile, int pageSize) throws IOException {
-
- List<FileInfo> files = getFiles("**");
-
- String path = "";
- int count = 0;
- for (FileInfo info : files) {
- FileInfo shortInfo = info.shortPath();
- if (!path.equals(shortInfo.getPath())) {
- files.set(count, shortInfo);
- path = shortInfo.getPath();
- }
- count++;
- }
-
- return new ArrayList<FileInfo>(files.subList(startFile, Math.min(startFile + pageSize, files.size())));
-
- }
-
- public List<FileInfo> getFiles(String pattern) {
- ResourcePatternResolver resolver = ResourcePatternUtils.getResourcePatternResolver(resourceLoader);
- List<Resource> resources = new ArrayList<Resource>();
-
- if (!pattern.startsWith("/")) {
- pattern = "/" + outputDir.getAbsolutePath() + "/" + pattern;
- }
- if (!pattern.startsWith("file:")) {
- pattern = "file:///" + pattern;
- }
-
- try {
- resources = Arrays.asList(resolver.getResources(pattern));
- } catch (IOException e) {
- logger.debug("Cannot locate files " + pattern, e);
- return new ArrayList<FileInfo>();
- }
-
- List<FileInfo> files = new ArrayList<FileInfo>();
- for (Resource resource : resources) {
- File file;
- try {
- file = resource.getFile();
- if (file.isFile()) {
- FileInfo info = new FileInfo(extractPath(file));
- files.add(info);
- }
- } catch (IOException e) {
- logger.debug("Cannot locate file " + resource, e);
- }
- }
-
- Collections.sort(files);
- return new ArrayList<FileInfo>(files);
-
- }
-
- public int delete(String pattern) throws IOException {
-
- ResourcePatternResolver resolver = ResourcePatternUtils.getResourcePatternResolver(resourceLoader);
- if (!pattern.startsWith("/")) {
- pattern = "/" + outputDir.getAbsolutePath() + "/" + pattern;
- }
- if (!pattern.startsWith("file:")) {
- pattern = "file:///" + pattern;
- }
-
- Resource[] resources = resolver.getResources(pattern);
-
- int count = 0;
- for (Resource resource : resources) {
- File file = resource.getFile();
- fileRemover.beforeRemove(file);
- if (file.isFile()) {
- count++;
- logger.info("removing file:" + file.getAbsolutePath());
- FileUtils.deleteQuietly(file);
- }
- }
-
- return count;
-
- }
-
- public Resource getResource(String path) {
-
- path = sanitize(path);
- FileInfo pattern = new FileInfo(path);
- List<FileInfo> files = getFiles(pattern.getPattern());
- FileInfo info = files.isEmpty() ? pattern : files.get(0);
- File file = new File(outputDir, info.getFileName());
- return new FileServiceResource(file, path);
-
- }
-
- public File getUploadDirectory() {
- return outputDir;
- }
-
- /**
- * Normalize file separators to "/" and strip leading prefix and separators
- * to create a simple relative path.
- *
- * @param path the raw path
- * @return a sanitized version
- */
- private String sanitize(String path) {
- path = path.replace("\\", "/");
- if (path.startsWith("files:")) {
- path = path.substring("files:".length());
- while (path.startsWith("/")) {
- path = path.substring(1);
- }
- }
- return path;
- }
-
- private static class FileServiceResource extends FileSystemResource implements ContextResource {
-
- private final String path;
-
- public FileServiceResource(File file, String path) {
- super(file);
- this.path = path;
- }
-
- public String getPathWithinContext() {
- return path;
- }
-
- }
-
-
-
-}
View
81 service/src/main/java/org/springframework/data/hadoop/admin/service/FileInfo.java
@@ -1,81 +0,0 @@
-/*
- * Copyright 2011-2012 the original author or authors.
- *
- * Licensed 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.springframework.data.hadoop.admin.service;
-
-
-import java.io.Serializable;
-
-/**
- *
- * @author Jarred Li
- *
- */
-@SuppressWarnings("serial")
-public class FileInfo implements Comparable<FileInfo>, Serializable {
- private final String path;
-
- private final String shortPath;
-
- private final boolean local;
-
- public FileInfo(String path) {
- this(path, true);
- }
-
- public FileInfo(String path, boolean local) {
- super();
- this.path = path.replace("\\", "/");
- this.shortPath = extractPath(path);
- this.local = local;
- }
-
- public FileInfo shortPath() {
- FileInfo info = new FileInfo(shortPath, local);
- return info;
- }
-
- public String getPattern() {
- return path;
- }
-
- private String extractPath(String path) {
- return path;
- }
- /**
- * @return the local
- */
- public boolean isLocal() {
- return local;
- }
-
-
- public String getPath() {
- return path;
- }
-
- public String getFileName() {
- return path;
- }
-
- public int compareTo(FileInfo o) {
- return shortPath.equals(o.shortPath) ? path.compareTo(o.path) : path.compareTo(o.path);
- }
-
- public String toString() {
- return "FileInfo [path=" + path + ", local=" + local + "]";
- }
-
-}
View
28 service/src/main/java/org/springframework/data/hadoop/admin/service/FileRemover.java
@@ -1,28 +0,0 @@
-/*
- * Copyright 2011-2012 the original author or authors.
- *
- * Licensed 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.springframework.data.hadoop.admin.service;
-
-import java.io.File;
-
-/**
- * @author Jarred Li
- *
- */
-public interface FileRemover {
-
- void beforeRemove(File file);
-
-}
View
28 service/src/main/java/org/springframework/data/hadoop/admin/service/FileSender.java
@@ -1,28 +0,0 @@
-/*
- * Copyright 2009-2010 the original author or authors.
- *
- * Licensed 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.springframework.data.hadoop.admin.service;
-
-import java.io.File;
-
-/**
- * @author Dave Syer
- *
- */
-public interface FileSender {
-
- void send(File file);
-
-}
View
46 service/src/main/java/org/springframework/data/hadoop/admin/service/FileService.java
@@ -1,46 +0,0 @@
-/*
- * Copyright 2009-2010 the original author or authors.
- *
- * Licensed 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.springframework.data.hadoop.admin.service;
-
-import java.io.IOException;
-import java.util.List;
-
-import org.springframework.core.io.Resource;
-
-/**
- * Encapsulation of file storage and creation hiding the actual location of the
- * files, but allowing their contents to be accessed by clients.
- *
- * @author Dave Syer
- * @author Jarred Li
- *
- */
-public interface FileService {
-
- FileInfo createFile(String path) throws IOException;
-
- boolean publish(FileInfo target) throws IOException;
-
- List<FileInfo> getFiles(int startFile, int pageSize) throws IOException;
-
- int countFiles();
-
- int delete(String pattern) throws IOException;
-
- Resource getResource(String path);
-
-}
View
63 ...ce/src/main/java/org/springframework/data/hadoop/admin/service/SimpleTemplateService.java
@@ -1,63 +0,0 @@
-/*
- * Copyright 2011-2012 the original author or authors.
- *
- * Licensed 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.springframework.data.hadoop.admin.service;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.springframework.data.hadoop.admin.util.Constant;
-
-/**
- * @author Jarred Li
- *
- */
-public class SimpleTemplateService extends BaseFileService implements TemplateService {
- {
- File outputDir = new File(System.getProperty("java.io.tmpdir", "/tmp"), Constant.TEMPLATE_LOCATION);
- setOutputDir(outputDir);
- }
-
- private static final Log logger = LogFactory.getLog(SimpleTemplateService.class);
-
- @Override
- public List<TemplateInfo> getTemplates(int start, int pageSize) throws IOException {
- List<TemplateInfo> templates = new ArrayList<TemplateInfo>();
- List<FileInfo> files = getFiles(start, pageSize);
- TemplateInfo ti;
- for (FileInfo file : files) {
- String fileName = file.getFileName();
- int index = fileName.lastIndexOf(".");
- fileName = fileName.substring(0,index);
- String[] elements = fileName.split("-");
- if (elements != null && elements.length == 3) {
- ti = new TemplateInfo();
- ti.setFileInfo(file);
- ti.setTemplateName(elements[0]);
- ti.setTemplateVersion(elements[2]);
- templates.add(ti);
- }
- else {
- logger.warn("invalid tempalte name");
- }
- }
- return new ArrayList<TemplateInfo>(templates.subList(start, Math.min(start + pageSize, templates.size())));
- }
-
-}
View
149 ...ce/src/main/java/org/springframework/data/hadoop/admin/service/SimpleWorkflowService.java
@@ -1,149 +0,0 @@
-/*
- * Copyright 2011-2012 the original author or authors.
- *
- * Licensed 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.springframework.data.hadoop.admin.service;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.springframework.batch.core.Job;
-import org.springframework.batch.core.configuration.JobRegistry;
-import org.springframework.batch.core.launch.NoSuchJobException;
-import org.springframework.beans.BeansException;
-import org.springframework.context.ApplicationContext;
-import org.springframework.context.ApplicationContextAware;
-import org.springframework.context.ConfigurableApplicationContext;
-import org.springframework.data.hadoop.admin.util.Constant;
-import org.springframework.data.hadoop.admin.util.HadoopWorkflowUtils;
-import org.springframework.data.hadoop.admin.workflow.support.FileSystemApplicationContextFactory;
-import org.springframework.data.hadoop.admin.workflow.support.WorkflowArtifacts;
-
-/**
- * @author Jarred Li
- *
- */
-public class SimpleWorkflowService extends BaseFileService implements WorkflowService, ApplicationContextAware {
-
- {
- File outputDir = new File(System.getProperty("java.io.tmpdir", "/tmp"), Constant.WORKFLOW_LOCATION);
- setOutputDir(outputDir);
- }
-
- private static final Log logger = LogFactory.getLog(SimpleWorkflowService.class);
-
- private ApplicationContext context;
-
- /* (non-Javadoc)
- * @see org.springframework.context.ApplicationContextAware#setApplicationContext(org.springframework.context.ApplicationContext)
- */
- @Override
- public void setApplicationContext(ApplicationContext arg0) throws BeansException {
- this.context = arg0;
- }
-
- /* (non-Javadoc)
- * @see org.springframework.data.hadoop.admin.service.WorkflowService#processAndRegister(java.lang.String)
- */
- @Override
- public void processAndRegister(String path) {
- File folder = new File("/" + getOutputDir().getAbsolutePath() + "/" + path);
- HadoopWorkflowUtils.processAndRegisterWorkflow(folder, context);
- }
-
-
-
- public List<WorkflowInfo> getWorkflows(int start, int pageSize) throws IOException {
- List<WorkflowInfo> wfInfoes = new ArrayList<WorkflowInfo>();
- if (getOutputDir().exists()) {
- logger.info("getWorkflows::workflow descriptor base directory:" + getOutputDir().getAbsolutePath());
- File[] wfArtifactsDirs = getOutputDir().listFiles();
- for (File f : wfArtifactsDirs) {
- if (f.isDirectory()) {
- List<FileInfo> files = getFiles(f.getName() + "/**");
- if (files.size() > 0) {
- WorkflowInfo wfInfo = new WorkflowInfo();
- wfInfo.setWorkflowName(f.getName());
- wfInfo.setFiles(files);
- boolean isValid = HadoopWorkflowUtils.isValidWorkflow(files);
- wfInfo.setValid(isValid);
- String jobName = getRegisteredJobName(f);
- boolean isRegistered = jobName != null;
- wfInfo.setRegistered(isRegistered);
- if (isRegistered) {
- wfInfo.setJobName(jobName);
- }
- wfInfoes.add(wfInfo);
- }
- }
- }
-
- }
- return new ArrayList<WorkflowInfo>(wfInfoes.subList(start, Math.min(start + pageSize, wfInfoes.size())));
- }
-
- private String getRegisteredJobName(File wfDirectory) {
- String result = null;
- WorkflowArtifacts artifacts = HadoopWorkflowUtils.getWorkflowArtifacts(wfDirectory);
- 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()) {
- if (isJobRegistered(jobName)) {
- result = jobName;
- break;
- }
- }
- }
- else {
- String jobName = HadoopWorkflowUtils.generateSpringBatchJobName(artifacts);
- if (isJobRegistered(jobName)) {
- result = jobName;
- }
- }
- }
- else {
- result = null;
- }
- return result;
- }
-
-
- private boolean isJobRegistered(String jobName) {
- boolean result = true;
- JobRegistry jobRegistry = context.getBean("jobRegistry", JobRegistry.class);
- try {
- Job job = jobRegistry.getJob(jobName);
- if (job == null) {
- result = false;
- }
- } catch (NoSuchJobException e) {
- result = false;
- }
- return result;
- }
-
-
-}
View
72 service/src/main/java/org/springframework/data/hadoop/admin/service/TemplateInfo.java
@@ -1,72 +0,0 @@
-/*
- * Copyright 2011-2012 the original author or authors.
- *
- * Licensed 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.springframework.data.hadoop.admin.service;
-
-/**
- * @author Jarred Li
- *
- */
-public class TemplateInfo{
-
- private String templateName;
-
- private String templateVersion;
-
- private FileInfo fileInfo;
-
- /**
- * @return the fileInfo
- */
- public FileInfo getFileInfo() {
- return fileInfo;
- }
-
- /**
- * @param fileInfo the fileInfo to set
- */
- public void setFileInfo(FileInfo fileInfo) {
- this.fileInfo = fileInfo;
- }
-
- /**
- * @return the templateName
- */
- public String getTemplateName() {
- return templateName;
- }
-
- /**
- * @param templateName the templateName to set
- */
- public void setTemplateName(String templateName) {
- this.templateName = templateName;
- }
-
- /**
- * @return the templateVersion
- */
- public String getTemplateVersion() {
- return templateVersion;
- }
-
- /**
- * @param templateVersion the templateVersion to set
- */
- public void setTemplateVersion(String templateVersion) {
- this.templateVersion = templateVersion;
- }
-
-}
View
29 service/src/main/java/org/springframework/data/hadoop/admin/service/TemplateService.java
@@ -1,29 +0,0 @@
-/*
- * Copyright 2011-2012 the original author or authors.
- *
- * Licensed 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.springframework.data.hadoop.admin.service;
-
-import java.io.IOException;
-import java.util.List;
-
-/**
- * @author Jarred Li
- *
- */
-public interface TemplateService extends FileService{
-
- List<TemplateInfo> getTemplates(int start, int pageSize) throws IOException;
-
-}
View
106 service/src/main/java/org/springframework/data/hadoop/admin/service/WorkflowInfo.java
@@ -1,106 +0,0 @@
-/*
- * Copyright 2011-2012 the original author or authors.
- *
- * Licensed 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.springframework.data.hadoop.admin.service;
-
-import java.util.List;
-
-/**
- * @author Jarred Li
- *
- */
-public class WorkflowInfo {
-
- private String workflowName;
-
- private String jobName = "NULL";
-
- private boolean valid;
-
- private boolean registered;
-
- private List<FileInfo> files;
-
- /**
- * @return the workflowName
- */
- public String getWorkflowName() {
- return workflowName;
- }
-
- /**
- * @param workflowName the workflowName to set
- */
- public void setWorkflowName(String workflowName) {
- this.workflowName = workflowName;
- }
-
- /**
- * @return the jobName
- */
- public String getJobName() {
- return jobName;
- }
-
- /**
- * @param jobName the jobName to set
- */
- public void setJobName(String jobName) {
- this.jobName = jobName;
- }
-
- /**
- * @return the valid
- */
- public boolean isValid() {
- return valid;
- }
-
- /**
- * @param valid the valid to set
- */
- public void setValid(boolean valid) {
- this.valid = valid;
- }
-
- /**
- * @return the registered
- */
- public boolean isRegistered() {
- return registered;
- }
-
- /**
- * @param egistered the registered to set
- */
- public void setRegistered(boolean registered) {
- this.registered = registered;
- }
-
- /**
- * @return the files
- */
- public List<FileInfo> getFiles() {
- return files;
- }
-
- /**
- * @param files the files to set
- */
- public void setFiles(List<FileInfo> files) {
- this.files = files;
- }
-
-}
View
31 service/src/main/java/org/springframework/data/hadoop/admin/service/WorkflowService.java
@@ -1,31 +0,0 @@
-/*
- * Copyright 2011-2012 the original author or authors.
- *
- * Licensed 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.springframework.data.hadoop.admin.service;
-
-import java.io.IOException;
-import java.util.List;
-
-/**
- * @author Jarred Li
- *
- */
-public interface WorkflowService extends FileService {
-
-
- List<WorkflowInfo> getWorkflows(int start, int pageSize) throws IOException;
-
- void processAndRegister(String path);
-}
View
34 service/src/main/java/org/springframework/data/hadoop/admin/util/Constant.java
@@ -1,34 +0,0 @@
-/*
- * Copyright 2011-2012 the original author or authors.
- *
- * Licensed 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.springframework.data.hadoop.admin.util;
-
-/**
- * @author Jarred Li
- *
- */
-public interface Constant {
-
- //String ONLY_TIMESTAMP_PATTERN = "\\.[0-9]{8}\\.[0-9]{6}";
-
- //String TIMESTAMP_PATTERN = ".*\\.[0-9]{8}\\.[0-9]{6}";
-
- String ROOT_LOCATION = "spring-hadoop-admin";
-
- String WORKFLOW_LOCATION = "spring-hadoop-admin/workflows";
-
- String TEMPLATE_LOCATION = "spring-hadoop-admin/templates";
-
-}
View
195 ...c/main/java/org/springframework/data/hadoop/admin/util/HadoopWorkflowDescriptorUtils.java
@@ -1,195 +0,0 @@
-/*
- * Copyright 2011-2012 the original author or authors.
- *
- * Licensed 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.springframework.data.hadoop.admin.util;
-
-import java.io.BufferedInputStream;
-import java.io.File;
-import java.io.FileInputStream;
-
-import javax.xml.transform.Transformer;
-import javax.xml.transform.TransformerFactory;
-import javax.xml.transform.dom.DOMSource;
-import javax.xml.transform.stream.StreamResult;
-
-import org.apache.commons.configuration.ConfigurationException;
-import org.apache.commons.configuration.PropertiesConfiguration;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.springframework.beans.factory.xml.DefaultDocumentLoader;
-import org.springframework.beans.factory.xml.DelegatingEntityResolver;
-import org.springframework.beans.factory.xml.DocumentLoader;
-import org.springframework.beans.factory.xml.ResourceEntityResolver;
-import org.springframework.core.io.ResourceLoader;
-import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
-import org.springframework.data.hadoop.admin.SpringHadoopAdminWorkflowException;
-import org.springframework.util.xml.SimpleSaxErrorHandler;
-import org.springframework.util.xml.XmlValidationModeDetector;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-import org.xml.sax.EntityResolver;
-import org.xml.sax.ErrorHandler;
-import org.xml.sax.InputSource;
-
-/**
- * Utility class for hadoop workflow descriptor
- *
- * @author Jarred Li
- *
- */
-public class HadoopWorkflowDescriptorUtils {
-
- private static final Log logger = LogFactory.getLog(HadoopWorkflowDescriptorUtils.class);
-
- private ClassLoader beanClassLoader = Thread.currentThread().getContextClassLoader();
-
- private ResourceLoader resourceLoader = new PathMatchingResourcePatternResolver();
-
- private static String springContextNameSpace = "http://www.springframework.org/schema/context";
-
- private static String placePlaceHolderTagName = "property-placeholder";
-
- private DocumentLoader documentLoader = new DefaultDocumentLoader();
-
- private EntityResolver entityResolver;
-
- private ErrorHandler errorHandler = new SimpleSaxErrorHandler(logger);
-
- private String replacePropertyPlaceHolderFaiure = "replace property place holder failed.";
-
- /**
- * replace the "property-placeholder" element in beans XML with absolute path
- * where the uploaded file exist in the server.
- *
- * @param workflowDescriptor spring's XML file
- * @param workflowProperty properties used in spring's XML file
- *
- * @return whether "property-placeholder" appears in the beans XML.
- * true - it appears
- * false - no
- *
- * @throws SpringHadoopAdminWorkflowException
- */
- public boolean replacePropertyPlaceHolder(File workflowDescriptor, File workflowProperty)
- throws SpringHadoopAdminWorkflowException {
- boolean result = false;
- String parentFolder = workflowDescriptor.getParentFile().getAbsolutePath();
- parentFolder = parentFolder + File.separator;
- try {
- BufferedInputStream bis = new BufferedInputStream(new FileInputStream(workflowDescriptor));
- InputSource inputSource = new InputSource(bis);
- Document doc = this.documentLoader.loadDocument(inputSource, getEntityResolver(), this.errorHandler,
- XmlValidationModeDetector.VALIDATION_NONE, true);
- NodeList nodes = doc.getElementsByTagNameNS(springContextNameSpace, placePlaceHolderTagName);
- logger.debug("number of nodes:" + nodes.getLength());
- for (int i = 0, j = nodes.getLength(); i < j; i++) {
- Node node = nodes.item(i);
- if (node instanceof Element) {
- Element e = (Element) node;
- String newValue = workflowProperty.getAbsolutePath().replace("\\", "/");
- newValue = HadoopWorkflowUtils.fileURLPrefix + newValue;
- e.setAttribute("location", newValue);
- result = true;
- logger.debug("new location after replaced:" + newValue);
- }
- }
- if (result) {
- TransformerFactory transformerFactory = TransformerFactory.newInstance();
- Transformer transformer = transformerFactory.newTransformer();
- DOMSource source = new DOMSource(doc);
- StreamResult out = new StreamResult(new File(workflowDescriptor.getAbsolutePath()));
- transformer.transform(source, out);
- }
- } catch (Exception e) {
- logger.warn(replacePropertyPlaceHolderFaiure);
- throw new SpringHadoopAdminWorkflowException(replacePropertyPlaceHolderFaiure, e);
- }
- return result;
- }
-
- /**
- * replace jar file name with full path where the uploaded jar in the server.
- *
- * @param workflowProperty workflow property file
- *
- * @throws ConfigurationException
- */
- public void replaceJarPath(File workflowProperty) throws ConfigurationException {
- PropertiesConfiguration config = new PropertiesConfiguration(workflowProperty);
- String workflowFolder = workflowProperty.getParent();
- workflowFolder.replace("\\", "/");
- workflowFolder = HadoopWorkflowUtils.fileURLPrefix + workflowFolder;
- config.setProperty("jar.path", workflowFolder);
- config.save();
- }
-
- /**
- * create new entity resolver <code>org.xml.sax.EntityResolver</code>
- *
- * @return
- */
- protected EntityResolver getEntityResolver() {
- if (this.entityResolver == null) {
- // Determine default EntityResolver to use.
- ResourceLoader resourceLoader = getResourceLoader();
- if (resourceLoader != null) {
- this.entityResolver = new ResourceEntityResolver(resourceLoader);
- }
- else {
- this.entityResolver = new DelegatingEntityResolver(getBeanClassLoader());
- }
- }
- return this.entityResolver;
- }
-
- /**
- * get ClassLoader which is used to load Spring Beans
- *
- * @return ClassLoader to load Beans
- */
- public ClassLoader getBeanClassLoader() {
- return this.beanClassLoader;
- }
-
- /**
- * set ClassLoader which is used to load Spring Beans
- *
- * @param beanClassLoader
- */
- public void setBeanClassLoader(ClassLoader beanClassLoader) {
- this.beanClassLoader = beanClassLoader;
- }
-
- /**
- * set ResourceLoader which is used to load resources
- *
- * @param resourceLoader
- */
- public void setResourceLoader(ResourceLoader resourceLoader) {
- this.resourceLoader = resourceLoader;
- }
-
- /**
- * get ResouseLoader which is used to load resource
- *
- * @return ResouseLoader which is used to load resource
- */
- public ResourceLoader getResourceLoader() {
- return this.resourceLoader;
- }
-
-}
View
447 service/src/main/java/org/springframework/data/hadoop/admin/util/HadoopWorkflowUtils.java
@@ -1,447 +0,0 @@
-/*
- * Copyright 2011-2012 the original author or authors.
- *
- * Licensed 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.springframework.data.hadoop.admin.util;
-
-import java.io.File;
-import java.io.FilenameFilter;
-import java.io.IOException;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.net.URLClassLoader;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.commons.configuration.ConfigurationException;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.springframework.batch.core.Job;
-import org.springframework.batch.core.configuration.JobFactory;
-import org.springframework.batch.core.configuration.JobRegistry;
-import org.springframework.batch.core.configuration.support.ApplicationContextFactory;
-import org.springframework.batch.core.configuration.support.AutomaticJobRegistrar;
-import org.springframework.batch.core.configuration.support.DefaultJobLoader;
-import org.springframework.batch.core.configuration.support.ReferenceJobFactory;
-import org.springframework.batch.core.job.SimpleJob;
-import org.springframework.batch.core.repository.JobRepository;
-import org.springframework.batch.core.step.tasklet.TaskletStep;
-import org.springframework.context.ApplicationContext;
-import org.springframework.context.ConfigurableApplicationContext;
-import org.springframework.context.support.FileSystemXmlApplicationContext;
-import org.springframework.core.io.FileSystemResource;
-import org.springframework.core.io.Resource;
-import org.springframework.data.hadoop.admin.SpringHadoopAdminWorkflowException;
-import org.springframework.data.hadoop.admin.service.FileInfo;
-import org.springframework.data.hadoop.admin.workflow.HadoopWorkflowLaunchRequestAdapter;
-import org.springframework.data.hadoop.admin.workflow.SimpleSpringHadoopTasklet;
-import org.springframework.data.hadoop.admin.workflow.support.FileSystemApplicationContextFactory;
-import org.springframework.data.hadoop.admin.workflow.support.FileSystemApplicationContextsFactoryBean;
-import org.springframework.data.hadoop.admin.workflow.support.WorkflowArtifacts;
-import org.springframework.jdbc.datasource.DataSourceTransactionManager;
-
-/**
- * Utility class for Spring Hadoop workflow
- *
- * @author Jarred Li
- *
- */
-public class HadoopWorkflowUtils {
-
- public static String fileURLPrefix = System.getProperty("os.name").toLowerCase().contains("windows") ? "file:///" : "file://";
-
- private static final Log logger = LogFactory.getLog(HadoopWorkflowUtils.class);
-
- public static String springHadoopJobPrefix = "spring-hadoop-job-";
-
- public static String springHadoopTaskName = "spring-hadoop-step";
-
-
- /**
- * get workflow artifacts aka, workflow descriptor and classloader from the specified folder
- *
- * @param workflowArtifactFolder folder contains artifacts
- * @return <code>WorkflowArtifacts</code>
- */
- public static WorkflowArtifacts getWorkflowArtifacts(File workflowArtifactFolder) {
- if (!workflowArtifactFolder.exists()) {
- return null;
- }
-
- WorkflowArtifacts result = null;
- String[] descriptor = getWorkflowDescriptor(workflowArtifactFolder);
- if (descriptor == null) {
- return null;
- }
- String workflowDescriptorFileName = descriptor[0];
- Resource resource = new FileSystemResource(new File(workflowDescriptorFileName));
-
- URL[] urls = HadoopWorkflowUtils.getWorkflowLibararies(workflowArtifactFolder);
- if (urls == null || urls.length == 0) {
- return null;
- }
- ClassLoader parentLoader = HadoopWorkflowUtils.class.getClassLoader();
- ClassLoader loader = new URLClassLoader(urls, parentLoader);
-
- result = new WorkflowArtifacts(resource, loader);
- return result;
- }
-
- /**
- * get the workflow descriptor file in XML.
- *
- * @param workflowArtifactFolder job artifacts folder.
- *
- * @return Spring Hadoop job descriptor file and property file.
- */
- public static String[] getWorkflowDescriptor(File workflowArtifactFolder) {
- String result[] = null;
- if (!workflowArtifactFolder.exists()) {
- return result;
- }
-
- File[] xmlFiles = workflowArtifactFolder.listFiles(new FilenameFilter() {
- @Override
- public boolean accept(File dir, String name) {
- return name.toLowerCase().endsWith(".xml");
- }
-
- });
-
- File[] propertiesFiles = workflowArtifactFolder.listFiles(new FilenameFilter() {
- @Override
- public boolean accept(File dir, String name) {
- return name.toLowerCase().endsWith(".properties");
- }
-
- });
-
- if (xmlFiles != null && xmlFiles.length == 1 && propertiesFiles != null && propertiesFiles.length == 1) {
- result = new String[2];
- result[0] = xmlFiles[0].getAbsolutePath();
- result[1] = propertiesFiles[0].getAbsolutePath();
- }
- else {
- logger.warn("uploaded workflow descriptor is incorrect");
- }
- return result;
- }
-
- public static boolean isValidWorkflow(List<FileInfo> files){
- if(files == null || files.size() < 3){
- return false;
- }
- boolean hasJar = false;
- boolean hasProperties = false;
- boolean hasXml = false;
- for(FileInfo fi : files){
- if(fi.getFileName().toLowerCase().endsWith(".jar")){
- hasJar = true;
- continue;
- }
- if(fi.getFileName().toLowerCase().endsWith(".properties")){
- hasProperties = true;
- continue;
- }
- if(fi.getFileName().toLowerCase().endsWith(".xml")){
- hasXml = true;
- continue;
- }
- if(hasJar && hasProperties && hasXml){
- break;
- }
- }
- return hasJar && hasProperties && hasXml;
- }
-
-
- /**
- * get jars as URL list.
- *
- * @param workflowArtifactFolder parent folder
- *
- * @return array of URL
- */
- public static URL[] getWorkflowLibararies(File workflowArtifactFolder) {
- if (!workflowArtifactFolder.exists()) {
- return null;
- }
- List<URL> result = new ArrayList<URL>();
-
- File[] jarFiles = workflowArtifactFolder.listFiles(new FilenameFilter() {
- @Override
- public boolean accept(File dir, String name) {
- return name.toLowerCase().endsWith(".jar");
- }
-
- });
- if (jarFiles != null && jarFiles.length > 0) {
- for (File jarFile : jarFiles) {
- try {
- result.add(new URL("jar:file:" + jarFile.getAbsolutePath() + "!/"));
- } catch (MalformedURLException e) {
- logger.warn("invalid uploaded jar");
- }
- }
- }
- logger.info("HadoopWorkflowUtils::getWorkflowLibararies, number of jar:" + result.size());
- return result.toArray(new URL[0]);
- }
-
- /**
- * get workflow class loader with all uploaded jar
- *
- * @param workflowArtifactFolder
- * @return workflow class loader
- */
- public static ClassLoader getWorkflowClassLoader(File workflowArtifactFolder) {
- ClassLoader parentLoader = HadoopWorkflowUtils.class.getClassLoader();
- if (!workflowArtifactFolder.exists()) {
- return parentLoader;
- }
- URL[] urls = getWorkflowLibararies(workflowArtifactFolder);
- if (urls != null && urls.length > 0) {
- ClassLoader loader = new URLClassLoader(urls, parentLoader);
- return loader;
- }
- else {
- return parentLoader;
- }
-
- }
-
- /**
- * To judge Whether the uploaded workflow descriptor is Spring Batch Job
- *
- * @param context Root ApplicationContext
- * @param artifacts workflow atifacts
- * @return true: if the workflow descritpor is Spring Batch Job
- * false: otherwise
- * @throws SpringHadoopAdminWorkflowException
- */
- public static boolean isSpringBatchJob(ApplicationContext context, WorkflowArtifacts artifacts)
- throws SpringHadoopAdminWorkflowException {
- if (context == null) {
- logger.warn("root applicaton context is null");
- throw new SpringHadoopAdminWorkflowException("root applicaton context is null");
- }
- if (artifacts == null) {
- logger.warn("workflow artifacts is null");
- throw new SpringHadoopAdminWorkflowException("workflow artifacts is null");
- }
-
- boolean result = true;
- 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);
- result = springBatchJobs.size() > 0;
- return result;
- }
-
- /**
- * create and register Spring Batch job
- *
- * @param context root application context
- * @param artifacts workflow artifacts which include workflow descriptor and class loader information.
- * @throws Exception
- */
- public static void createAndRegisterSpringBatchJob(ApplicationContext context, final WorkflowArtifacts artifacts)
- throws SpringHadoopAdminWorkflowException {
- if (context == null) {
- logger.warn("root applicaton context is null");
- throw new SpringHadoopAdminWorkflowException("root applicaton context is null");
- }
- String workflowDescriptor = getWorkflowDescriptor(artifacts);
- logger.info("create spring batch job:" + workflowDescriptor + ", classloader:"
- + artifacts.getWorkflowClassLoader());
-
- final FileSystemXmlApplicationContext ctx = new FileSystemXmlApplicationContext();
- ctx.setClassLoader(artifacts.getWorkflowClassLoader());
- ctx.setConfigLocation(HadoopWorkflowUtils.fileURLPrefix + workflowDescriptor);
-
- try {
- SimpleJob job = new SimpleJob(generateSpringBatchJobName(artifacts));
- TaskletStep step = new TaskletStep(springHadoopTaskName);
- SimpleSpringHadoopTasklet tasklet = new SimpleSpringHadoopTasklet();
- tasklet.setContext(ctx);
- step.setTasklet(tasklet);
- JobRepository jobRepository = context.getBean(JobRepository.class);
- DataSourceTransactionManager transactionManager = context.getBean("transactionManager",
- DataSourceTransactionManager.class);
- step.setTransactionManager(transactionManager);
- step.setJobRepository(jobRepository);
- step.afterPropertiesSet();
- job.addStep(step);
- JobRegistry jobRegistry = context.getBean("jobRegistry", JobRegistry.class);
- job.setJobRepository(jobRepository);
- job.afterPropertiesSet();
- JobFactory jobFactory = new ReferenceJobFactory(job);
- jobRegistry.register(jobFactory);
- } catch (Exception e) {
- logger.warn("create and register Spring Batch Job failed");
- throw new SpringHadoopAdminWorkflowException("create and register Spring Batch Job failed", e);
- }
- }
-
- /**
- * generate spring batch job name based on workflow descriptor name
- *
- * @param artifacts workflow artifact
- *
- * @return new generated job name
- */
- public static String generateSpringBatchJobName(final WorkflowArtifacts artifacts) {
- return springHadoopJobPrefix + artifacts.getWorkflowDescriptor().getFilename();
- }
-
- /**
- * unregister spring batch job.
- *
- * @param context root application context
- * @param springBatchJobName job name to be unregistered
- */
- public static void unregisterSpringBatchJob(ApplicationContext context, String springBatchJobName) {
- JobRegistry jobRegistry = context.getBean("jobRegistry", JobRegistry.class);
- jobRegistry.unregister(springBatchJobName);
- logger.info("unregister spring batch job:" + springBatchJobName);
- }
-
- /**
- * get workflow descriptor file name
- *
- * @param artifacts workflow artificats *
- * @return The workflow descriptor file name
- * @throws SpringHadoopAdminWorkflowException
- */
- public static String getWorkflowDescriptor(final WorkflowArtifacts artifacts)
- throws SpringHadoopAdminWorkflowException {
- if (artifacts == null) {
- logger.warn("workflow artifacts is null");
- throw new SpringHadoopAdminWorkflowException("workflow artifacts is null");
- }
-
- String workflowDescriptor = null;
-
- try {
- Resource resource = artifacts.getWorkflowDescriptor();
- if (resource == null) {
- throw new SpringHadoopAdminWorkflowException("workflow's descriptor is null");
- }
- File file = resource.getFile();
- if (file == null) {
- throw new SpringHadoopAdminWorkflowException("workflow's descriptor is null");
- }
- workflowDescriptor = file.getAbsolutePath();
- } catch (IOException e) {
- throw new SpringHadoopAdminWorkflowException("IO error when trying to get workflow's descriptor.");
- }
- return workflowDescriptor;
- }
-
-
-
- /**
- *
- * @param parentFolder
- * @param context
- */
- public static void processAndRegisterWorkflow(File parentFolder, ApplicationContext context) {
- try {
- WorkflowArtifacts artifacts = processUploadedFile(parentFolder);
- if (artifacts == null) {
- return;
- }
-
- boolean isSpringBatchJob = HadoopWorkflowUtils.isSpringBatchJob(context, artifacts);
- logger.info("uploaded workflow artifacts is spring batch job? " + isSpringBatchJob);
- if (isSpringBatchJob) {
- registerSpringBatchJob(artifacts, context);
- }
- else {
- HadoopWorkflowUtils.createAndRegisterSpringBatchJob(context, artifacts);
- }
- } catch (Exception e) {
- logger.error("handle uploaded file failed", e);
- }
- }
-
- /**
- * process the uploaded file. Replace context place holder locaton, update jar path.
- *
- * @param parentFolder parent folder of workflow files that are being uploaded
- * @return <code>WorkflowArtifacts<code> when all jar, descriptor, properties are uploaded
- * otherwise, null
- * @throws ConfigurationException
- * @throws SpringHadoopAdminWorkflowException
- */
- public static WorkflowArtifacts processUploadedFile(final File parentFolder) throws ConfigurationException,
- SpringHadoopAdminWorkflowException {
- String[] descriptor = HadoopWorkflowUtils.getWorkflowDescriptor(parentFolder);
- URL[] urls = HadoopWorkflowUtils.getWorkflowLibararies(parentFolder);
- if (descriptor == null || urls == null || urls.length == 0) {
- return null;
- }
-
- ClassLoader parentLoader = HadoopWorkflowLaunchRequestAdapter.class.getClassLoader();
- ClassLoader loader = new URLClassLoader(urls, parentLoader);
-
- String workflowDescriptorFileName = descriptor[0];
- String workflowPropertyFileName = descriptor[1];
- File workflowPropertyFile = new File(workflowPropertyFileName);
- File workflowDescriptorFile = new File(workflowDescriptorFileName);
- HadoopWorkflowDescriptorUtils util = new HadoopWorkflowDescriptorUtils();
- util.setBeanClassLoader(loader);
-
- util.replaceJarPath(workflowPropertyFile);
- boolean replaced = util.replacePropertyPlaceHolder(workflowDescriptorFile, workflowPropertyFile);
-
- if (!replaced) {
- throw new SpringHadoopAdminWorkflowException(
- "there is no property place holder in the workflow descriptor. MapReduce jar may not be found");
- }
-
- Resource resource = new FileSystemResource(new File(workflowDescriptorFileName));
- WorkflowArtifacts artifacts = new WorkflowArtifacts(resource, loader);
- return artifacts;
- }
-
- /**
- * register the new uploaded Spring Batch job
- *
- * @param artifacts workflow artifacts
- * @param context root Application Context
- *
- * @throws Exception
- */
- public static void registerSpringBatchJob(WorkflowArtifacts artifacts, ApplicationContext context) throws Exception {
- String workflowDescriptor = HadoopWorkflowUtils.getWorkflowDescriptor(artifacts);
- logger.info("create spring batch job:" + workflowDescriptor + ", classloader:"
- + artifacts.getWorkflowClassLoader());
- AutomaticJobRegistrar registarar = new AutomaticJobRegistrar();
- FileSystemApplicationContextsFactoryBean factoryBean = new FileSystemApplicationContextsFactoryBean();
- factoryBean.setApplicationContext(context);
- factoryBean.setWorkflowArtifacts(new WorkflowArtifacts[] { artifacts });
- registarar.setApplicationContextFactories((ApplicationContextFactory[]) factoryBean.getObject());
- DefaultJobLoader jobLoader = new DefaultJobLoader();
- JobRegistry jobRegistry = context.getBean("jobRegistry", JobRegistry.class);
- jobLoader.setJobRegistry(jobRegistry);
- registarar.setJobLoader(jobLoader);
- registarar.start();
- logger.info("successfully register spring batch job");
- }
-}
View
162 service/src/main/java/org/springframework/data/hadoop/admin/web/TemplateController.java
@@ -1,162 +0,0 @@
-/*
- * Copyright 2011-2012 the original author or authors.
- *
- * Licensed 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.springframework.data.hadoop.admin.web;
-
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
-
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.core.io.Resource;
-import org.springframework.data.hadoop.admin.service.FileInfo;
-import org.springframework.data.hadoop.admin.service.TemplateInfo;
-import org.springframework.data.hadoop.admin.service.TemplateService;
-import org.springframework.stereotype.Controller;
-import org.springframework.ui.ModelMap;
-import org.springframework.util.FileCopyUtils;
-import org.springframework.validation.Errors;
-import org.springframework.web.bind.annotation.ModelAttribute;
-import org.springframework.web.bind.annotation.PathVariable;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestMethod;
-import org.springframework.web.bind.annotation.RequestParam;
-import org.springframework.web.multipart.MultipartFile;
-import org.springframework.web.util.HtmlUtils;
-
-/**
- * @author Jarred Li
- *
- */
-@Controller
-public class TemplateController{
-
- private static Log logger = LogFactory.getLog(TemplateController.class);
-
- private TemplateService templateService;
-
- /**
- * The service used to manage template lists and uploads.
- *
- * @param templateService the {@link TemplateService} to set
- */
- @Autowired
- public void setTemplateService(TemplateService templateService) {
- this.templateService = templateService;
- }
-
-
- @RequestMapping(value = "/templates", method = RequestMethod.POST)
- public String uploadRequest(@RequestParam String path, @RequestParam MultipartFile file, ModelMap model, @RequestParam(defaultValue = "0") int startFile, @RequestParam(defaultValue = "20") int pageSize, @ModelAttribute("date") Date date, Errors errors)
- throws Exception {
- return upload(path, file, model, startFile, pageSize, date, errors);
- }
-
- @RequestMapping(value = "/templates/{path}", method = RequestMethod.POST)
- public String upload(@PathVariable String path, @RequestParam MultipartFile file, ModelMap model, @RequestParam(defaultValue = "0") int startFile, @RequestParam(defaultValue = "20") int pageSize, @ModelAttribute("date") Date date, Errors errors)
- throws Exception {
-
- String originalFilename = file.getOriginalFilename();
- if (file.isEmpty()) {
- errors.reject("file.upload.empty", new Object[] { originalFilename },
- "File upload was empty for filename=[" + HtmlUtils.htmlEscape(originalFilename) + "]");
- list(model, startFile, pageSize);
- return "workflows";
- }
-
- try {
- FileInfo dest = templateService.createFile(path + "/" + originalFilename);
- file.transferTo(templateService.getResource(dest.getPath()).getFile());
- templateService.publish(dest);
- model.put("uploaded", dest.getPath());
- } catch (IOException e) {
- errors.reject("file.upload.failed", new Object[] { originalFilename }, "File upload failed for "
- + HtmlUtils.htmlEscape(originalFilename));
- } catch (Exception e) {
- String message = "File upload failed downstream processing for " + HtmlUtils.htmlEscape(originalFilename);
- if (logger.isDebugEnabled()) {
- logger.debug(message, e);
- }
- else {
- logger.info(message);
- }
- errors.reject("file.upload.failed.downstream", new Object[] { originalFilename }, message);
- }
-
- if (errors.hasErrors()) {
- list(model, startFile, pageSize);
- return "templates";
- }
-
- return "redirect:templates";
-
- }
-
- @RequestMapping(value = "/templates", method = RequestMethod.GET)
- public void list(ModelMap model, @RequestParam(defaultValue = "0") int startFile, @RequestParam(defaultValue = "20") int pageSize)
- throws Exception {
- List<TemplateInfo> templates = templateService.getTemplates(startFile, pageSize);
- model.put("templates", templates);
-
- }
-
- @RequestMapping(value = "/templates/**", method = RequestMethod.GET)
- public String get(HttpServletRequest request, HttpServletResponse response, ModelMap model, @RequestParam(defaultValue = "0") int startFile, @RequestParam(defaultValue = "20") int pageSize, @ModelAttribute("date") Date date, Errors errors)
- throws Exception {
-
- list(model, startFile, pageSize);
-
- String path = request.getPathInfo().substring("/templates/".length());
- Resource file = templateService.getResource(path);
- if (file == null || !file.exists()) {
- errors.reject("file.download.missing", new Object[] { path },
- "File download failed for missing file at path=" + HtmlUtils.htmlEscape(path));
- return "templates";
- }
-
- response.setContentType("application/octet-stream");
- try {
- FileCopyUtils.copy(file.getInputStream(), response.getOutputStream());
- } catch (IOException e) {
- errors.reject("file.download.failed", new Object[] { path },
- "File download failed for path=" + HtmlUtils.htmlEscape(path));
- logger.info("File download failed for path=" + path, e);
- return "templates";
- }
-
- return null;
-
- }
-
- @RequestMapping(value = "/templates", method = RequestMethod.DELETE)
- public String delete(ModelMap model, @RequestParam(defaultValue = "**") String pattern) throws Exception {
-
- int deletedCount = templateService.delete(pattern);
-
- model.put("files", new ArrayList<String>());
- model.put("deletedCount", deletedCount);
-
- return "redirect:templates";
-
- }
-
-
-}
View
27 service/src/main/java/org/springframework/data/hadoop/admin/web/TemplateMenu.java
@@ -1,27 +0,0 @@
-/*
- * Copyright 2009-2010 the original author or authors.
- *
- * Licensed 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.springframework.data.hadoop.admin.web;
-
-import org.springframework.batch.admin.web.resources.BaseMenu;
-
-
-public class TemplateMenu extends BaseMenu {
-
- public TemplateMenu() {
- super("/templates", "Template", 1);
- }
-
-}
View
168 service/src/main/java/org/springframework/data/hadoop/admin/web/WorkflowController.java
@@ -1,168 +0,0 @@
-/*
- * Copyright 2011-2012 the original author or authors.
- *
- * Licensed 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.springframework.data.hadoop.admin.web;
-
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
-
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.core.io.Resource;
-import org.springframework.data.hadoop.admin.service.FileInfo;
-import org.springframework.data.hadoop.admin.service.WorkflowInfo;
-import org.springframework.data.hadoop.admin.service.WorkflowService;
-import org.springframework.stereotype.Controller;
-import org.springframework.ui.ModelMap;
-import org.springframework.util.FileCopyUtils;
-import org.springframework.validation.Errors;
-import org.springframework.web.bind.annotation.ModelAttribute;
-import org.springframework.web.bind.annotation.PathVariable;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestMethod;
-import org.springframework.web.bind.annotation.RequestParam;
-import org.springframework.web.multipart.MultipartFile;
-import org.springframework.web.util.HtmlUtils;
-
-/**
- * @author Jarred Li
- *
- */
-@Controller
-public class WorkflowController{
-
- private static Log logger = LogFactory.getLog(WorkflowController.class);
-
- private WorkflowService workflowService;
-
- /**
- * The service used to manage file lists and uploads.
- *
- * @param workflowService the {@link WorkflowService} to set
- */
- @Autowired
- public void setWorkflowService(WorkflowService workflowService) {
- this.workflowService = workflowService;
- }
-
- @RequestMapping(value = "/workflows", method = RequestMethod.POST)
- public String uploadRequest(@RequestParam String path, @RequestParam MultipartFile file, ModelMap model, @RequestParam(defaultValue = "0") int startFile, @RequestParam(defaultValue = "20") int pageSize, @ModelAttribute("date") Date date, Errors errors)
- throws Exception {
- return upload(path, file, model, startFile, pageSize, date, errors);
- }
-
- @RequestMapping(value = "/workflows/{path}", method = RequestMethod.POST)
- public String upload(@PathVariable String path, @RequestParam MultipartFile file, ModelMap model, @RequestParam(defaultValue = "0") int startFile, @RequestParam(defaultValue = "20") int pageSize, @ModelAttribute("date") Date date, Errors errors)
- throws Exception {
-
- String originalFilename = file.getOriginalFilename();
- if (file.isEmpty()) {
- errors.reject("file.upload.empty", new Object[] { originalFilename },
- "File upload was empty for filename=[" + HtmlUtils.htmlEscape(originalFilename) + "]");
- list(model, startFile, pageSize);
- return "workflows";
- }
-
- try {
- FileInfo dest = workflowService.createFile(path + "/" + originalFilename);
- file.transferTo(workflowService.getResource(dest.getPath()).getFile());
- workflowService.publish(dest);
- model.put("uploaded", dest.getPath());
- } catch (IOException e) {
- errors.reject("file.upload.failed", new Object[] { originalFilename }, "File upload failed for "
- + HtmlUtils.htmlEscape(originalFilename));
- } catch (Exception e) {
- String message = "File upload failed downstream processing for " + HtmlUtils.htmlEscape(originalFilename);
- if (logger.isDebugEnabled()) {
- logger.debug(message, e);
- }
- else {
- logger.info(message);
- }
- errors.reject("file.upload.failed.downstream", new Object[] { originalFilename }, message);
- }
-
- if (errors.hasErrors()) {
- list(model, startFile, pageSize);
- return "workflows";
- }
-
- return "redirect:workflows";
-
- }
-
- @RequestMapping(value = "/workflows/register", method = RequestMethod.POST)
- public String register(@RequestParam String path) throws Exception {
- workflowService.processAndRegister(path);
- return "redirect:workflows";
- }
-
- @RequestMapping(value = "/workflows", method = RequestMethod.GET)
- public void list(ModelMap model, @RequestParam(defaultValue = "0") int startFile, @RequestParam(defaultValue = "20") int pageSize)
- throws Exception {
- //List<FileInfo> files = workflowService.getFiles(startFile, pageSize);
- List<WorkflowInfo> workflows = workflowService.getWorkflows(startFile, Integer.MAX_VALUE);
- model.put("workflows", workflows);
-
- }
-
- @RequestMapping(value = "/workflows/**", method = RequestMethod.GET)
- public String get(HttpServletRequest request, HttpServletResponse response, ModelMap model, @RequestParam(defaultValue = "0") int startFile, @RequestParam(defaultValue = "20") int pageSize, @ModelAttribute("date") Date date, Errors errors)
- throws Exception {
-
- list(model, startFile, pageSize);
-
- String path = request.getPathInfo().substring("/workflows/".length());
- Resource file = workflowService.getResource(path);
- if (file == null || !file.exists()) {
- errors.reject("file.download.missing", new Object[] { path },
- "File download failed for missing file at path=" + HtmlUtils.htmlEscape(path));
- return "workflows";
- }
-
- response.setContentType("application/octet-stream");
- try {
- FileCopyUtils.copy(file.getInputStream(), response.getOutputStream());
- } catch (IOException e) {
- errors.reject("file.download.failed", new Object[] { path },
- "File download failed for path=" + HtmlUtils.htmlEscape(path));
- logger.info("File download failed for path=" + path, e);
- return "workflows";
- }
-
- return null;
-
- }
-
- @RequestMapping(value = "/workflows", method = RequestMethod.DELETE)
- public String delete(ModelMap model, @RequestParam(defaultValue = "**") String pattern) throws Exception {
-
- int deletedCount = workflowService.delete(pattern);
-
- model.put("files", new ArrayList<String>());
- model.put("deletedCount", deletedCount);
-
- return "redirect:workflows";
-
- }
-
-
-}
View
27 service/src/main/java/org/springframework/data/hadoop/admin/web/WorkflowMenu.java
@@ -1,27 +0,0 @@
-/*
- * Copyright 2009-2010 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.