add demo-java code to maven-install dir.
This commit is contained in:
parent
044b1057b0
commit
7bc615df5b
|
@ -0,0 +1,29 @@
|
|||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you 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 hmodule.demojava;
|
||||
|
||||
public class DemoJavaMain {
|
||||
public static void main(String[] args) {
|
||||
System.out.println("Demo Java Main");
|
||||
|
||||
System.out.println("# Arguments: " + args.length);
|
||||
for (int i = 0; i < args.length; i++) {
|
||||
System.out.println("Argument[" + i + "]: " + args[i]);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,69 @@
|
|||
package hmodule.demojava;
|
||||
|
||||
import haflow.module.Module;
|
||||
import haflow.module.ModuleConfiguration;
|
||||
import haflow.module.ModuleMetadata;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.StringReader;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
|
||||
import org.w3c.dom.Document;
|
||||
import org.xml.sax.InputSource;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
@Module(id = "ada600a8-aa63-968a-ca46-9085e0e0bd2e", name = "Java", category = "General")
|
||||
@ModuleConfiguration(configurationKeys = { "eee" }, configurationDisplayNames = { "fff" })
|
||||
public class JavaModule implements ModuleMetadata {
|
||||
|
||||
public Document generate(Map<String, String> configurations) {
|
||||
String name = configurations.get("name");
|
||||
String eee = configurations.get("eee");
|
||||
String ok = configurations.get("ok");
|
||||
|
||||
Class<?> moduleClass = this.getClass();
|
||||
assert (moduleClass.isAnnotationPresent(haflow.module.Module.class));
|
||||
// String moduleName = moduleClass.getAnnotation(haflow.module.Module.class).name();
|
||||
|
||||
String actionXML =
|
||||
"<action name=\"" + name + "\">" + "\n" +
|
||||
"<java>" + "\n" +
|
||||
"<job-tracker>${jobTracker}</job-tracker>" + "\n" +
|
||||
"<name-node>${nameNode}</name-node>" + "\n" +
|
||||
"<configuration>" + "\n" +
|
||||
"<property>" + "\n" +
|
||||
"<name>mapred.job.queue.name</name>" + "\n" +
|
||||
"<value>${queueName}</value>" + "\n" +
|
||||
"</property>" + "\n" +
|
||||
"</configuration>" + "\n" +
|
||||
"<main-class>" + DemoJavaMain.class.getName() + "</main-class>" + "\n" +//TODO
|
||||
"<arg>" + "-eee " + eee + "</arg>" + "\n" +
|
||||
"</java>" + "\n" +
|
||||
"<ok to=\"" + ok + "\"/>" + "\n" +
|
||||
"<error to=\"fail\"/>" + "\n" +
|
||||
"</action>";
|
||||
|
||||
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
|
||||
|
||||
try {
|
||||
DocumentBuilder db = dbf.newDocumentBuilder();
|
||||
StringReader sr = new StringReader(actionXML);
|
||||
InputSource is = new InputSource(sr);
|
||||
Document doc = db.parse(is);
|
||||
return doc;
|
||||
} catch (SAXException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch (ParserConfigurationException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue