|
From: <je...@us...> - 2007-12-07 05:39:58
|
Revision: 1852
http://cogkit.svn.sourceforge.net/cogkit/?rev=1852&view=rev
Author: jenvor
Date: 2007-12-06 21:39:56 -0800 (Thu, 06 Dec 2007)
Log Message:
-----------
add state service, modify executor implementation
Modified Paths:
--------------
trunk/cyberaide/src/axis2/axis2ws_client/SimpleHandlerClient.java
trunk/cyberaide/src/axis2/axis2ws_client/SimpleHandlerInterface.java
trunk/cyberaide/src/axis2/axis2ws_server/SimpleHandlerInterface.java
trunk/cyberaide/src/axis2/axis2ws_server/SimpleHandlerInterfaceSkeleton.java
Added Paths:
-----------
trunk/cyberaide/src/axis2/axis2ws_server/StatusServiceInterface.java
trunk/cyberaide/src/axis2/axis2ws_server/StatusServiceInterfaceSkeleton.java
Modified: trunk/cyberaide/src/axis2/axis2ws_client/SimpleHandlerClient.java
===================================================================
--- trunk/cyberaide/src/axis2/axis2ws_client/SimpleHandlerClient.java 2007-12-05 05:06:57 UTC (rev 1851)
+++ trunk/cyberaide/src/axis2/axis2ws_client/SimpleHandlerClient.java 2007-12-07 05:39:56 UTC (rev 1852)
@@ -14,30 +14,72 @@
import java.io.File;
import java.io.BufferedWriter;
+import java.io.BufferedReader;
import java.io.FileWriter;
+import java.io.FileReader;
+import java.io.FileOutputStream;
import java.io.FileInputStream;
+import java.io.StringWriter;
+
import java.util.Properties;
+import java.util.ArrayList;
+import java.util.HashMap;
import org.cogkit.cyberaide.axis2ws.SimpleHandlerInterfaceStub.Echo;
import org.cogkit.cyberaide.axis2ws.SimpleHandlerInterfaceStub.EchoResponse;
import org.cogkit.cyberaide.axis2ws.SimpleHandlerInterfaceStub.CmdCOGExecute;
import org.cogkit.cyberaide.axis2ws.SimpleHandlerInterfaceStub.CmdCOGExecuteResponse;
+import org.cogkit.cyberaide.axis2ws.SimpleHandlerInterfaceStub.CmdWFSubmit;
+import org.cogkit.cyberaide.axis2ws.SimpleHandlerInterfaceStub.CmdWFSubmitResponse;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
-public class SimpleHandlerClient{
- private String prefix = "(This is done by using Web servie)\n";
- private String propertiesFile = "webservice.properties";
- private String wsendpoint = "";
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.cogkit.cyberaide.axis2ws.StatusServiceInterfaceStub;
+import org.cogkit.cyberaide.axis2ws.StatusServiceInterfaceStub.AddWorkflowFromString;
+import org.cogkit.cyberaide.axis2ws.StatusServiceInterfaceStub.GetJSONStatusByUID;
+import org.cogkit.cyberaide.axis2ws.StatusServiceInterfaceStub.GetJSONStatusByUIDResponse;
+
+public class SimpleHandlerClient implements SimpleHandlerClientInterface{
+ private static String prefix = "(This is done by using Web service)\n";
+ //private static String propertiesFile = "/home/tomcat/apache-tomcat-6.0.14/webapps/webservice.properties";
+ private static String propertiesFile = "/home/tomcat/apache-tomcat-6.0.14/webapps/agent.properties";
+ private static String wsendpoint = "";
+ private static StatusServiceNotifier _notifier = new StatusServiceNotifier();
+ private static AgentWFDB _agentDb = null;
+ private static SimpleHandlerInterfaceStub stub = null;
+
public SimpleHandlerClient(){
try{
- Properties prop = new Properties();
- prop.load( new FileInputStream( propertiesFile ) );
- String endpoint = prop.getProperty( "serviceendpoint" );
- if( endpoint == null ){
- System.out.println( "you must specify 'serviceendpoint' property in file service.properties" );
- }else{
- wsendpoint = endpoint;
+ //open property file specified by propertiesFile
+ File propfile = new File(propertiesFile);
+ if( propfile.exists() == false ){
+ System.out.println("property file: "+propertiesFile+" does not exist!");
+ return ;
+ }
+
+ // get service end point
+ Properties prop = new Properties();
+ prop.load( new FileInputStream( propertiesFile ) );
+ String endpoint = prop.getProperty( "serviceendpoint" );
+ if( endpoint == null ){
+ System.out.println( "you must specify 'serviceendpoint' property in file service.properties" );
+ }else{
+ wsendpoint = endpoint;
+ stub = new SimpleHandlerInterfaceStub(wsendpoint);
+ }
+
+ if( _agentDb == null ){
+ String dbfile = prop.getProperty("agentdb");
+ _agentDb = new AgentWFDB(dbfile);
}
}catch( Exception e ){
System.out.println( e.toString() );
@@ -57,9 +99,6 @@
br.write( input );
br.close();
- //call the corresponding web service
- //SimpleHandlerInterfaceStub stub = new SimpleHandlerInterfaceStub("http://localhost:8080/axis2/services/SimpleHandler");
- SimpleHandlerInterfaceStub stub = new SimpleHandlerInterfaceStub(wsendpoint);
Echo req = new Echo();
req.setParam0( input );
EchoResponse resp = new EchoResponse();
@@ -72,27 +111,33 @@
}
/**
- * @param input workflow description which is represented by a string
+ * @param workflow workflow description which is represented by a string
* This invokes remote 'cmdCOGExecute' web service which will return a string.
* <b>Note</b>: the workflow description from user is logged in file <b>/tmp/workflow.xml</b>.
*/
public String cmdCOGExecute( String workflow ){
String output = "";
try {
+ String oldWF = workflow;
+ WorkflowTransformer transformer = new WorkflowTransformer();
+ transformer.LoadFromString(workflow);
+ workflow = transformer.getNewWF();
+
String filename = "/tmp/workflow.xml";
File recordfile = new File(filename);
BufferedWriter br = new BufferedWriter(new FileWriter(recordfile));
br.write(workflow);
br.close();
- //call the corresponding web service
- //SimpleHandlerInterfaceStub stub = new SimpleHandlerInterfaceStub("http://localhost:8080/axis2/services/SimpleHandler");
- SimpleHandlerInterfaceStub stub = new SimpleHandlerInterfaceStub(wsendpoint);
+ //send this workflow to status server
+ _notifier.addWorkFlowFromString("user1", "file1", oldWF);
+
CmdCOGExecute req = new CmdCOGExecute();
req.setParam0( workflow );
CmdCOGExecuteResponse resp = new CmdCOGExecuteResponse();
resp = stub.cmdCOGExecute( req );
output = resp.get_return();
+
} catch (IllegalThreadStateException e) {
return e.toString();
} catch (Exception e){
@@ -100,4 +145,482 @@
}
return prefix + output;
}
+ /**
+ */
+ public String WFSubmit(String username, String workflow){
+ String result = "", myprefix = "(This is done by using web service with status monitoring enabled)\n";
+ if( username.compareTo("")==0 ){
+ result = "You must specify your username!!";
+ return result;
+ }
+ System.out.println("this id received by WFSubmit method");
+ //TODO
+ //check whether the user exists in the system
+ //how to generate the wfid
+ String output = "", wfid = _agentDb.addWF( username );
+ try {
+ String oldWF = workflow;
+ WorkflowTransformer transformer = new WorkflowTransformer();
+ transformer.LoadFromString(workflow);
+ workflow = transformer.getNewWF();
+
+ //send this workflow to status server
+ _notifier.addWorkFlowFromString(username, wfid, oldWF);
+
+ CmdWFSubmit req = new CmdWFSubmit();
+ req.setParam0( username );
+ req.setParam1( wfid );
+ req.setParam2( workflow );
+ CmdWFSubmitResponse resp = stub.cmdWFSubmit( req );
+ output = resp.get_return();
+ } catch (IllegalThreadStateException e) {
+ return e.toString();
+ } catch (Exception e){
+ return e.toString();
+ }
+ return myprefix + output;
+ }
+
+ public String getStatusByUID(String struid){
+ return _notifier.getStatusByUID(struid);
+ }
}
+
+class WorkflowTransformer{
+ private String newWorkflow = "";
+ public String getNewWF(){
+ return newWorkflow;
+ }
+
+ public void LoadFromFile(String filename) {
+ try {
+ File karajanfile = new File(filename);
+ if (karajanfile.exists() == false) {
+ System.out.println("The karajan workflow file " + filename
+ + " does not exist!!");
+ return;
+ }
+ String content = "", line ="";
+ BufferedReader br = new BufferedReader(new FileReader(karajanfile));
+ boolean isFirstLine = true;
+ while( (line=br.readLine())!=null ){
+ if( isFirstLine ){
+ isFirstLine = false;
+ }else
+ content +="\n";
+ content += line;
+ }
+// buildTree(content);
+ LoadFromString(content);
+ } catch (Exception e) {
+ System.out.println(e);
+ }
+ }
+ public void LoadFromString(String strworkflow) {
+ String tempFilename = "_tempxx345";
+ File tempfile = new File(tempFilename);
+ BufferedWriter fw = null;
+ try {
+ fw = new BufferedWriter(new FileWriter(tempfile));
+ fw.write(strworkflow);
+ fw.close();
+ buildTree(tempFilename);
+ tempfile.delete();
+ } catch (Exception e) {
+ tempfile.delete();
+ System.out.println(e);
+ }
+ }
+ protected void buildTree(String workflowfilename){
+ try{
+ DocumentBuilderFactory domfactory = DocumentBuilderFactory.newInstance();
+ domfactory.setNamespaceAware(false);
+ DocumentBuilder builder = domfactory.newDocumentBuilder();
+
+ Document doc = builder.parse(new FileInputStream(workflowfilename));
+ Element root = doc.getDocumentElement();
+
+ //transformSubTree(root, doc);
+ transformSubTreeWithPath(root,doc,"");
+
+ /*
+ String newWF = "test.xml";
+ File newfile = new File(newWF);
+ if( newfile.exists() )
+ newfile.delete();
+ newfile.createNewFile();
+ */
+
+ DOMSource src = new DOMSource(doc);
+ TransformerFactory transformerfactory = TransformerFactory.newInstance();
+ Transformer transformer = transformerfactory.newTransformer();
+ //transformer.transform(src, new StreamResult(new FileWriter(newfile)));
+ StringWriter sw = new StringWriter();
+ transformer.transform(src, new StreamResult(sw));
+ newWorkflow = sw.toString();
+ } catch (Exception e) {
+ System.out.println(e);
+ }
+ }
+ protected void transformSubTree(Node root, Document doc){
+ if(root.getChildNodes().getLength()==0)
+ return;
+ Node parent = root;
+ Node node = root.getFirstChild();
+ boolean isfirstChild = true;
+ String previousNode ="";
+
+ do{
+ if( node.getNodeType() == Node.TEXT_NODE )
+ continue;
+ if( node.getNodeType() == Node.ELEMENT_NODE){
+ if( node.getNodeName().compareToIgnoreCase("include")==0)
+ continue;
+ String nodename = node.getNodeName();
+ if( nodename.trim().compareToIgnoreCase("execute")==0 ){
+ nodename = "job:"+nodename+"("+((Element)node).getAttribute("executable")+") ";
+ }else
+ nodename = "job:"+nodename;
+
+ if( isfirstChild ){
+ isfirstChild = false;
+ Element newChild = doc.createElement("echo");
+ newChild.setAttribute("message", nodename+" started");
+ parent.insertBefore(newChild, node);
+ Node newline = doc.createTextNode("\n");
+ parent.insertBefore(newline, node);
+ }else{
+ Element newChild = doc.createElement("echo");
+ newChild.setAttribute("message", previousNode+" completed");
+ parent.insertBefore(newChild, node);
+ Node newline = doc.createTextNode("\n");
+ parent.insertBefore(newline, node);
+ newChild = doc.createElement("echo");
+ newChild.setAttribute("message", nodename+" started");
+ parent.insertBefore(newChild, node);
+ newline = doc.createTextNode("\n");
+ parent.insertBefore(newline, node);
+ }
+ previousNode = nodename;
+ transformSubTree(node, doc);
+ }
+ }while( (node=node.getNextSibling())!=null);
+
+ Element newChild = doc.createElement("echo");
+ newChild.setAttribute("message", previousNode+" completed");
+ parent.appendChild(newChild);
+ }
+
+ protected void transformSubTreeWithPath(Node root, Document doc, String path){
+ if(root.getChildNodes().getLength()==0)
+ return;
+ Node parent = root;
+ Node node = root.getFirstChild();
+ boolean isfirstChild = true;
+ String previousNode ="", basepath = path, localpath="", oldpath="", oldEchoMsg="";
+ String echoMsg = "";
+ int childindex = 0;
+ do{
+ if( node.getNodeType() == Node.TEXT_NODE )
+ continue;
+ if( node.getNodeType() == Node.ELEMENT_NODE){
+ if( node.getNodeName().compareToIgnoreCase("include")==0){
+ childindex ++;
+ continue;
+ }
+ childindex ++;
+
+ String nodename = node.getNodeName();
+ if( nodename.trim().compareToIgnoreCase("execute")==0 )
+ nodename = nodename+"("+((Element)node).getAttribute("executable")+") ";
+
+ localpath = path+"/"+childindex;
+
+ if( isfirstChild ){
+ isfirstChild = false;
+ Element newChild = doc.createElement("echo");
+ echoMsg = localpath+"|job:"+nodename;
+ newChild.setAttribute("message", echoMsg+" started|1");
+ parent.insertBefore(newChild, node);
+ Node newline = doc.createTextNode("\n");
+ parent.insertBefore(newline, node);
+ }else{
+ Element newChild = doc.createElement("echo");
+ newChild.setAttribute("message", oldEchoMsg+" completed|2");
+ parent.insertBefore(newChild, node);
+
+ Node newline = doc.createTextNode("\n");
+ parent.insertBefore(newline, node);
+
+ echoMsg = localpath+"|job:"+nodename;
+ newChild = doc.createElement("echo");
+ newChild.setAttribute("message", echoMsg+" started|1");
+ parent.insertBefore(newChild, node);
+
+ newline = doc.createTextNode("\n");
+ parent.insertBefore(newline, node);
+ }
+ oldEchoMsg = echoMsg;
+ previousNode = nodename;
+ transformSubTreeWithPath(node, doc, localpath);
+ }
+ }while( (node=node.getNextSibling())!=null);
+
+ Element newChild = doc.createElement("echo");
+ newChild.setAttribute("message", oldEchoMsg+" completed|2");
+ parent.appendChild(newChild);
+ }
+}
+
+class StatusServiceNotifier{
+ private String _wsendpoint = "";
+ private StatusServiceInterfaceStub _stub = null;
+
+ public StatusServiceNotifier(){
+ try{
+ _wsendpoint = "http://156.56.104.196:8080/axis2/services/StatusServiceInterface";
+ _stub = new StatusServiceInterfaceStub(_wsendpoint);
+ } catch(Exception e){
+ System.out.println(e);
+ }
+ }
+
+ public String getStatusByUID(String struid){
+ try{
+ if( _stub == null ) return "_stub is null";
+ GetJSONStatusByUID req = new GetJSONStatusByUID();
+ req.setParam0( struid );
+ GetJSONStatusByUIDResponse resp = new GetJSONStatusByUIDResponse();
+ resp = _stub.getJSONStatusByUID(req);
+ return resp.get_return();
+ }catch(Exception e){
+ return e.toString();
+ }
+ }
+
+ public void addWorkFlowFromString(String userid, String wfid, String workflow){
+ try{
+ if( _stub == null ) return ;
+
+ String filename = "/tmp/statusservice_agent_client.test";
+ File file = new File(filename);
+ file.createNewFile();
+ BufferedWriter bw = new BufferedWriter(new FileWriter(file));
+
+ bw.write("add a new workflow\n");
+ //add a workflow
+ /*
+ File currentDir = new File(".");
+ if( true )
+ return currentDir.getAbsolutePath();
+ */
+
+ AddWorkflowFromString addWF1 = new AddWorkflowFromString();
+ addWF1.setParam0(userid);
+ addWF1.setParam1(wfid);
+ addWF1.setParam2(workflow);
+ _stub.addWorkflowFromString(addWF1);
+
+ bw.close();
+ }catch(Exception e){
+ System.out.println(e);
+ }
+ }
+}
+
+/**
+ * Format of the db file:
+ * username1 workflow1
+ * username2 workflow1
+ * username1 workflow2
+ * ... ...
+ */
+class AgentWFDB{
+ private ArrayList<Pair> _db = new ArrayList<Pair>();
+ private HashMap<String, Integer> _userwf = new HashMap<String,Integer>();
+
+ private String _dbfilename = "";//source file
+ private BufferedWriter _bw = null;
+ private boolean _load = false;
+
+ public AgentWFDB(String dbfilename){
+ _dbfilename = dbfilename;
+ File dbfile = new File(dbfilename);
+ if( dbfile.exists() )
+ _load = loadFromFile(dbfilename);
+ }
+ private void addPair(StringPair pair){
+ _db.add(pair);
+ }
+ private void addPair(String first, String second){
+ _db.add( new StringPair(first, second) );
+ }
+ /**
+ * This function first generates a unique workflow id for the user
+ * and add the entry to db.
+ * @param userid
+ * @return
+ */
+ public String addWF(String userid){
+ try{
+ File file = new File("/tmp/client.test");
+ file.createNewFile();
+ BufferedWriter bw = new BufferedWriter( new FileWriter( file ) );
+ bw.write( userid );
+ bw.close();
+ }catch(Exception e){
+ }
+ Integer cn = _userwf.get(userid);
+ int count;
+ if( cn == null ){
+ _userwf.put(userid, 1);
+ count = 1;
+ }else{
+ count = cn+1;
+ _userwf.put(userid, count);
+ }
+ String wfid = userid+"_"+count;
+ addPair(userid, wfid);
+ serialize2file();
+ return wfid;
+ }
+ public boolean contains(String username, String wfid){
+ StringPair pair = new StringPair(username, wfid);
+ return this.contains(pair);
+ }
+ public boolean contains(StringPair pair){
+ for( int i = 0 ; i < _db.size(); i++ ){
+ if( _db.get(i).isEqual(pair) )
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * get workflow list owned by a specified user.
+ * @param userid
+ * @return JSON string
+ */
+ public String getJSONByUserID(String userid){
+ String output = "{\"user\":\""+userid+"\", \"workflow\":[";
+ boolean isfirst = true;
+ for(int i = 0 ; i < _db.size(); i++){
+ if( ((String)_db.get(i).getFirst()).compareTo(userid)==0 ){
+ if( isfirst ){
+ isfirst = false;
+ }else
+ output += ",";
+ output += "\""+(String)_db.get(i).getSecond()+"\"";
+ }
+ }
+ output += "]}";
+ return output;
+ }
+
+ private boolean loadFromFile(String filename){
+ BufferedReader br = null;
+ String line = "";
+ try {
+ br = new BufferedReader(new FileReader(filename));
+ while( (line = br.readLine()) != null){
+ StringPair pair = new StringPair(line);
+ Integer cn = _userwf.get(pair.getFirst());
+ int count;
+ if( cn == null )
+ count = 1;
+ else
+ count = cn + 1;
+ _userwf.put(pair.getFirst(), count);
+ _db.add( pair );
+ }
+ br.close();
+ return true;
+ } catch (Exception e) {
+ return false;
+ }
+ }
+
+ public String serialize2string(){
+ String output = "";
+ for(int i=0; i<_db.size(); i++){
+ output += _db.get(i).serialize() +"\n";
+ }
+ return output;
+ }
+ public void serialize2file(){
+ try {
+ if( !_load ){
+ File file = new File(_dbfilename);
+ if( !file.exists() )
+ file.createNewFile();
+ if (_bw == null) {
+ _bw = new BufferedWriter(new FileWriter(_dbfilename));
+ }
+ _load = true;
+ }
+ String output = serialize2string();
+ if (_bw == null) {
+ _bw = new BufferedWriter(new FileWriter(_dbfilename));
+ }
+ _bw.write(output);
+ _bw.close();
+ _bw = null;
+ } catch (Exception e) {
+ System.out.println(e);
+ }
+ }
+}
+
+abstract class Pair{
+ abstract Object getFirst();
+ abstract Object getSecond();
+ abstract void setFirst(Object first);
+ abstract void setSecond(Object second);
+ abstract String serialize();
+ abstract void deserialize(String str);
+ abstract boolean isEqual(Pair pair);
+}
+
+class StringPair extends Pair{
+ private String _first = "";
+ private String _second = "";
+ public StringPair(String first, String second){
+ _first = first;
+ _second = second;
+ }
+ public StringPair(String str){
+ deserialize(str);
+ }
+ public void setFirst(Object first){
+ if( first instanceof String)
+ _first = (String)first;
+ }
+ public void setSecond(Object second){
+ if( second instanceof String)
+ _second = (String)second;
+ }
+ public String getFirst(){
+ return _first;
+ }
+ public String getSecond(){
+ return _second;
+ }
+ public String serialize(){
+ return _first+"\t"+_second;
+ }
+ public void deserialize(String str){
+ int index = str.indexOf('\t');
+ _first = str.substring( 0, index);
+ _second = str.substring(index+1);
+ }
+ public boolean isEqual( Pair p ){
+ if( p instanceof StringPair){
+ StringPair pair = (StringPair)p;
+ String first = pair.getFirst();
+ String second = pair.getSecond();
+ return (_first.compareTo(first)==0)&&(_second.compareTo(second)==0);
+ }else{
+ return false;
+ }
+ }
+}
Modified: trunk/cyberaide/src/axis2/axis2ws_client/SimpleHandlerInterface.java
===================================================================
--- trunk/cyberaide/src/axis2/axis2ws_client/SimpleHandlerInterface.java 2007-12-05 05:06:57 UTC (rev 1851)
+++ trunk/cyberaide/src/axis2/axis2ws_client/SimpleHandlerInterface.java 2007-12-07 05:39:56 UTC (rev 1852)
@@ -8,4 +8,11 @@
interface SimpleHandlerInterface{
String echo( String input );
String cmdCOGExecute( String workflow );
+ /**
+ * This method submits a workflow to CogKit.
+ * Notice: the user who submits the workflow is identified by <b><i>uid</i></b>
+ * the workflow is uniquely identified by wfid so that different workflows
+ * submitted by the same user can be distinguished.
+ */
+ String cmdWFSubmit(String uid, String wfid, String workflow);
}
Modified: trunk/cyberaide/src/axis2/axis2ws_server/SimpleHandlerInterface.java
===================================================================
--- trunk/cyberaide/src/axis2/axis2ws_server/SimpleHandlerInterface.java 2007-12-05 05:06:57 UTC (rev 1851)
+++ trunk/cyberaide/src/axis2/axis2ws_server/SimpleHandlerInterface.java 2007-12-07 05:39:56 UTC (rev 1852)
@@ -8,4 +8,11 @@
interface SimpleHandlerInterface{
String echo( String input );
String cmdCOGExecute( String workflow );
+ /**
+ * This method submits a workflow to CogKit.
+ * Notice: the user who submits the workflow is identified by <b><i>uid</i></b>
+ * the workflow is uniquely identified by wfid so that different workflows
+ * submitted by the same user can be distinguished.
+ */
+ String cmdWFSubmit(String uid, String wfid, String workflow);
}
Modified: trunk/cyberaide/src/axis2/axis2ws_server/SimpleHandlerInterfaceSkeleton.java
===================================================================
--- trunk/cyberaide/src/axis2/axis2ws_server/SimpleHandlerInterfaceSkeleton.java 2007-12-05 05:06:57 UTC (rev 1851)
+++ trunk/cyberaide/src/axis2/axis2ws_server/SimpleHandlerInterfaceSkeleton.java 2007-12-07 05:39:56 UTC (rev 1852)
@@ -32,11 +32,58 @@
import org.globus.common.CoGProperties;
import org.globus.util.Util;
+
+/* following imported packages are used by StatusService client */
+import org.cogkit.cyberaide.axis2ws.StatusServiceInterfaceStub;
+import org.cogkit.cyberaide.axis2ws.StatusServiceInterfaceStub.*;
+
/**
* SimpleHandlerInterfaceSkeleton java skeleton for the axisService
*/
-public class SimpleHandlerInterfaceSkeleton implements SimpleHandlerInterfaceSkeletonInterface {
+public class SimpleHandlerInterfaceSkeleton implements SimpleHandlerInterfaceSkeletonInterface {
+/* private String _uid = "user1";
+ private String _wfid = "file1";
+ private String _workflow ="";
+*/
+ private static String _statusFilename = "/tmp/status.txt";
+ private static String _statusserviceendpoint = "";
+ private static String _configFilename = "/home/tomcat/apache-tomcat-6.0.14/webapps/executor.properties";
+ private static StatusServiceClient _statusclient = null;
+
+ public SimpleHandlerInterfaceSkeleton(){
+ super();
+ try{
+ //open property file specified by propertiesFile
+ File propfile = new File(_configFilename);
+ if( propfile.exists() == false ){
+ System.out.println("property file: "+_configFilename+" does not exist!");
+ return ;
+ }
+
+ // get status service end point
+ Properties prop = new Properties();
+ prop.load( new FileInputStream( _configFilename ) );
+ String endpoint = prop.getProperty( "statusserviceendpoint" );
+ if( endpoint == null ){
+ System.out.println( "you must specify 'serviceendpoint' property in file service.properties" );
+ }else{
+ _statusserviceendpoint = endpoint;
+ if( _statusclient == null )
+ _statusclient = new StatusServiceClient(_statusserviceendpoint);
+ }
+ }catch(Exception e){
+ System.out.println(e);
+ }
+ }
+ /**
+ * Currently, the events generated by CoGKit during workflow execution is
+ * written into a file specified by variable _statusFilename. When end users
+ * check status, a routine reads this file and sends the content to clients.
+ * If the workflow is finished, another file is created to indicate it.
+ * I can not think of a better way now to tell status checker the completion
+ * of execution of workflow.
+ */
/**
* Auto generated method signature
* @param cmdCOGExecute0
@@ -44,20 +91,39 @@
public org.cogkit.cyberaide.axis2ws.CmdCOGExecuteResponse cmdCOGExecute(
org.cogkit.cyberaide.axis2ws.CmdCOGExecute cmdCOGExecute0) {
String workflow = cmdCOGExecute0.getParam0();
+ /* actually we invoke cmdWFSubmit !!! */
+ if( true ){
+ String result = "";
+ CmdWFSubmit req = new CmdWFSubmit();
+ req.setParam0("user1");
+ req.setParam1("file1");
+ req.setParam2(workflow);
+ CmdWFSubmitResponse resp = cmdWFSubmit( req );
+ CmdCOGExecuteResponse reply = new CmdCOGExecuteResponse();
+ reply.set_return( resp.get_return() );
+ return reply;
+ }
+
Process wfproc = null;
String output = "";
int exit = -1;
try {
- //First, get the proxy certificate from the myproxy server
- getCertFromMyproxy();//"gf1.ucs.indiana.edu", 7512, "gerald", "....", 60*60*24*10);
-
+ String tempEOFFilename = "/tmp/status_end";
+ File tempEOFFile = new File(tempEOFFilename);
+ tempEOFFile.delete();
+
//store the input(it is a workflow description actually) in a file
- String filename = "/tmp/workflow.xml";
+ String filename = "/tmp/workflow_ws.xml";
File recordfile = new File(filename);
- BufferedWriter br = new BufferedWriter(new FileWriter(recordfile));
- br.write(workflow);
- br.close();
+ BufferedWriter bw = new BufferedWriter(new FileWriter(recordfile));
+ bw.write(workflow);
+ bw.flush();
+ //First, get the proxy certificate from the myproxy server
+ getCertFromMyproxy();//"gf1.ucs.indiana.edu", 7512, "gerald", "....", 60*60*24*10);
+
+ bw.write("get proxy\n");
+
//filename = "\"" + filename +"\"";
//String cmd = "E:\\my_program\\cog-4_1_5\\bin\\cog-workflow.bat";// + filename;
// get value of environment variable COG_INSTALL_PATH
@@ -86,16 +152,41 @@
System.out.println("Execute a new command");
wfproc = Runtime.getRuntime().exec(cmdarray);
+ //open status file
+ int count = 0;
+ File statusFile = new File(_statusFilename);
+ BufferedWriter statusbw = new BufferedWriter( new FileWriter(statusFile) );
+
//get output from the executed tool
line = "";
input = new BufferedReader (new InputStreamReader(wfproc.getInputStream()));
+ boolean isfirstline = true;
while ((line = input.readLine()) != null) {
- output += line;
+ //create a new status file
+// File statusFile = new File(statusFilename+count);
+// BufferedWriter statusbw = new BufferedWriter( new FileWriter(statusFile) );
+
+ if( isfirstline ){
+ isfirstline = false;
+ output += "Firstline:"+line;
+ statusbw.write(line,0,line.length());
+ statusbw.flush();
+ }else{
+ output += "\nFollowing line:"+line;
+ String newline = "\n"+line;
+ statusbw.write(newline,0,newline.length());
+ statusbw.flush();
+ }
+ count ++;
+// statusbw.close();
}
input.close();
+
+ tempEOFFile.createNewFile();
+ statusbw.close();
//exit = wfproc.exitValue();
//output = Integer.toString( exit );
- output = "succeeds!"+output;
+ output = "succeeds!\n"+output;
wfproc.destroy();
} catch (IllegalThreadStateException e) {
wfproc.destroy();
@@ -127,7 +218,7 @@
*/
private void getCertFromMyproxy(){//String host, int port, String user, String pwd, int lifetime){
try{
- String propertiesFile = "myproxy.properties";
+ String propertiesFile = "/home/tomcat/apache-tomcat-6.0.14/webapps/myproxy.properties";
String host = "";
int port = -1;
String user = "";
@@ -192,4 +283,191 @@
}
}
+ /**
+ * Auto generated method signature
+ * This method will be used by agent to submit a workflow.
+ * @param cmdWFSubmit0
+ */
+ public org.cogkit.cyberaide.axis2ws.CmdWFSubmitResponse cmdWFSubmit(
+ org.cogkit.cyberaide.axis2ws.CmdWFSubmit cmdWFSubmit0) {
+ String uid = cmdWFSubmit0.getParam0();
+ String wfid = cmdWFSubmit0.getParam1();
+ String workflow = cmdWFSubmit0.getParam2();
+
+ /*
+ //internally, invoke cmdCogExecution
+ org.cogkit.cyberaide.axis2ws.CmdCOGExecute execution = new org.cogkit.cyberaide.axis2ws.CmdCOGExecute();
+ execution.setParam0(_workflow);
+ org.cogkit.cyberaide.axis2ws.CmdCOGExecuteResponse resp = new org.cogkit.cyberaide.axis2ws.CmdCOGExecuteResponse();
+ resp = cmdCOGExecute(execution);
+ org.cogkit.cyberaide.axis2ws.CmdWFSubmitResponse wfresp = new org.cogkit.cyberaide.axis2ws.CmdWFSubmitResponse();
+ wfresp.set_return(resp.get_return());
+ */
+
+ Process wfproc = null;
+ String output = "";
+ int exit = -1;
+ try {
+ //First, get the proxy certificate from the myproxy server
+ getCertFromMyproxy();//"gf1.ucs.indiana.edu", 7512, "gerald", "....", 60*60*24*10);
+
+ //store the input(it is a workflow description actually) in a file
+ String filename = "/tmp/workflow_WFSubmit.xml";
+ File recordfile = new File(filename);
+ BufferedWriter br = new BufferedWriter(new FileWriter(recordfile));
+ br.write(workflow);
+ br.close();
+
+ //filename = "\"" + filename +"\"";
+ //String cmd = "E:\\my_program\\cog-4_1_5\\bin\\cog-workflow.bat";// + filename;
+ // get value of environment variable COG_INSTALL_PATH
+ String cog_workflow = "";
+ String getEnvVar = "printenv COG_INSTALL_PATH";
+ String line = "";
+
+ wfproc = Runtime.getRuntime().exec(getEnvVar);
+ BufferedReader input...
[truncated message content] |
|
From: <je...@us...> - 2008-01-03 22:44:38
|
Revision: 1862
http://cogkit.svn.sourceforge.net/cogkit/?rev=1862&view=rev
Author: jenvor
Date: 2008-01-03 14:44:29 -0800 (Thu, 03 Jan 2008)
Log Message:
-----------
write a install script which can ease installation of the system
Added Paths:
-----------
trunk/cyberaide/src/axis2/INSTALL
trunk/cyberaide/src/axis2/scripts/install.sh
Added: trunk/cyberaide/src/axis2/INSTALL
===================================================================
--- trunk/cyberaide/src/axis2/INSTALL (rev 0)
+++ trunk/cyberaide/src/axis2/INSTALL 2008-01-03 22:44:29 UTC (rev 1862)
@@ -0,0 +1,63 @@
+How to install the whole CoGkit Javascript system
+
+Steps:
+(1) You should check out the install.sh which should be executed in bash.
+(2) Then run the script.
+After you run the script, three files should be generated:
+* SimpleHandlerInterface.aar
+* StatusServiceInterface.aar
+* SimpleHandlerInterface-test-client.jar
+
+SimpleHandlerInterface.aar
+ This is the package which provides executor service in our system.
+
+StatusServiceInterface.aar
+ This is the package which provides status service.
+
+SimpleHandlerInterface-test-client.jar
+ This is the package which provides agent service.
+
+Before further going on, you should have following requirements satisfied:
+(1) You should have a servlet/JSP container.
+ Currently, my system is only tested on Apache Tomcat.
+(2) Axis2 is deployed correctly in the container.
+(3) Apache Xmlrpc is correctly deployed in the container.
+
+Now, you are ready to deploy our system.
+(1) deploy SimpleHandlerInterface.arr into Axis2 at the machine which will
+ host executor service.
+
+ (1.1) You must create and edit the configuration file: executor.properties.
+ This file contains the address of the status service.
+ Typically, the content looks like this:
+ statusserviceendpoint=http://ip:port/axis2/services/StatusServiceInterface
+ (1.2) You must create and edit the configuration file: myproxy.properties.
+ This file contains the address and user account of a MyProxy server.
+ Typically, the content looks like this:
+ host=gf1.ucs.indiana.edu
+ port=7512
+ user=username
+ pwd=password
+
+(2) deploy StatusServiceInterface.aar into Axis2 at the machine which will
+ host status service.
+
+(3) Checkout all files and directories from:
+ http://cogkit.svn.sourceforge.net/svnroot/cogkit/trunk/cyberaide/src/js/securelogin
+ These files provide web-based interface for end users to submit workflows
+ and query status of workflows.
+ These files should be checked out into your Xmlrpc application directory at the
+ machine which will host the agent service.
+
+ Deploy SimpleHandlerInterface-test-client.jar. You should consult manual of Xmlrpc to see
+ exactly whether the .jar files should be positioned.
+ Xmlrpc must be configured correctly.
+
+ You must create and edit the configuration file: agent.properties.
+ This file contains address of executor service.
+ The content looks like this:
+ serviceendpoint=http://156.56.104.196:8080/axis2/services/SimpleHandlerInterface
+ agentdb=/tmp/agentdb.txt
+
+ Now address of the status service is hard-coded in the source code of agent service.
+ This will be modified later.
Added: trunk/cyberaide/src/axis2/scripts/install.sh
===================================================================
--- trunk/cyberaide/src/axis2/scripts/install.sh (rev 0)
+++ trunk/cyberaide/src/axis2/scripts/install.sh 2008-01-03 22:44:29 UTC (rev 1862)
@@ -0,0 +1,158 @@
+#!/bin/sh
+
+############################################################################
+# This script is used to install the Web-based CoGKit.
+############################################################################
+#First get the source code from svn repository
+svn checkout http://cogkit.svn.sourceforge.net/svnroot/cogkit/trunk/cyberaide/src/axis2 cyberaide/src/axis2 > /dev/null
+
+basedir='cyberaide/src/axis2'
+cwd=`pwd`
+
+#this dir should contain the agent server related files
+clientsrcdir=${basedir}/axis2ws_client
+#interface file
+agentServicei='SimpleHandlerClientInterface.java'
+#implementation
+agentService='SimpleHandlerClient.java'
+
+#this dir should contain executor and state server related files
+serversrcdir=${basedir}/axis2ws_server
+#status service interface
+statusservicei='StatusServiceInterface.java'
+#Status service implementation
+statusservice='StatusServiceInterfaceSkeleton.java'
+#executor service interface
+executorservicei='SimpleHandlerInterface.java'
+#executor implementation
+executorservice='SimpleHandlerInterfaceSkeleton.java'
+
+#temporary directory where the compilation and building work of status service is done.
+statusservicedir='statusservice'
+executorservicedir='executor'
+
+#name of the makefile which will be used to build various service.
+makefile='makefile'
+#directory which contains bash scripts needed by the makefile
+scriptdir=${cwd}/${basedir}/scripts
+
+#package name of all these files
+packagename='org.cogkit.cyberaide.axis2ws'
+packagepath=`echo ${packagename//.//}`
+
+
+if [ ! -d ${serversrcdir} ]; then
+ echo "Directory ${serversrcdir} can not be found"
+ exit 1
+fi
+
+oldpwd1=`pwd`
+
+############################################################
+#
+# Build state service
+#
+############################################################
+cd ${serversrcdir}
+#create a new directory which will contain statu service related files
+mkdir ${statusservicedir}
+
+oldpwd2=`pwd`
+#copy files StatusServiceInterface.java and makefile to the new created directory.
+cp ${statusservicei} ${statusservicedir}/
+cp ${scriptdir}/${makefile} ${statusservicedir}/
+
+#build client and server stub
+cd ${statusservicedir}
+make csfromjava scriptdir=${scriptdir} java=${statusservicei}
+cd ${oldpwd2}
+
+#copy the server side skeleton file "StatusServiceInterfaceSkeleton.java" to the
+#corresponding path
+path=${statusservicedir}/server/src/${packagepath}
+cp ${statusservice} ${path}/
+
+#build final package (a .arr file for server side and a .jar file for client side)
+cd ${statusservicedir}
+make serverbuild scriptdir=${scriptdir}
+cd ${oldpwd2}
+
+aar=`echo ${statusservicei//.java/.aar}`
+cp ${statusservicedir}/${aar} ${oldpwd1}/
+
+############################################################
+#
+# Build executor service
+#
+############################################################
+mkdir ${executorservicedir}
+
+cp ${executorservicei} ${executorservicedir}/
+cp ${scriptdir}/${makefile} ${executorservicedir}/
+
+cd ${executorservicedir}
+make csfromjava scriptdir=${scriptdir} java=${executorservicei}
+cd ${oldpwd2}
+
+#copy the server side skeleton file "SimpleHandlerInterfaceSkeleton.java" to the
+#corresponding path
+exeserverpath=${executorservicedir}/server/src/${packagepath}
+cp ${executorservice} ${exeserverpath}/
+
+#copy client side stub file of Status service to server side of executor service
+staclientpath=${statusservicedir}/client/src/${packagepath}
+clientstub=`echo ${statusservicei//.java/Stub.java}`
+clientstub=${staclientpath}/${clientstub}
+cp ${clientstub} ${exeserverpath}/
+
+#build final package (a .arr file for server side and a .jar file for client side)
+cd ${executorservicedir}
+make serverbuild scriptdir=${scriptdir}
+cd ${oldpwd2}
+
+aar=`echo ${executorservicei//.java/.aar}`
+cp ${executorservicedir}/${aar} ${oldpwd1}/
+
+
+############################################################
+#
+# Build agent server
+#
+############################################################
+#copy client side stub file of Status service, interface of agent service and implementation
+#of agent service to client side of executor service
+execlientpath=${executorservicedir}/client/src/${packagepath}
+cp ${clientstub} ${execlientpath}/
+cd ${oldpwd1}
+cp ${clientsrcdir}/${agentService} ${serversrcdir}/${execlientpath}/
+cp ${clientsrcdir}/${agentServicei} ${serversrcdir}/${execlientpath}/
+cd ${oldpwd2}
+
+#build final package (a .jar file for client side)
+cd ${executorservicedir}
+make clientbuild scriptdir=${scriptdir}
+cd ${oldpwd2}
+
+cp ${executorservicedir}/client/build/lib/*.jar ${oldpwd1}/
+
+############################################################
+#
+# Clear
+#
+############################################################
+#rm -rf ${statusservicedir}
+#rm -rf ${executorservicedir}
+
+cd ${oldpwd1}
+
+cat<<EOF
+Now, you have successfully built the agent server, executor service and state service.
+(*) The files corresponding to txecutor service and state service are .aar files and you should
+deploy these files to Axis2 which is typically run in Apache Tomcat. The typical path is
+"${TOMCAT_ROOT}/webapps/axis2/WEB_INF/services".
+(**) The file corresponding to the agent service is a .jar file and you can deploy it in Tomcat
+directly. But, Apache Xmlrpc is used and you should consult the manual of Apache Xmlrpc to
+deploy it correctly. The typical path is "${TOMCAT_ROOT}/webapps/your_service_dir/WEB_INF/classes/".
+EOF
+
+rm -rf cyberaide
Property changes on: trunk/cyberaide/src/axis2/scripts/install.sh
___________________________________________________________________
Name: svn:executable
+ *
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|