using cyberaide javascript to develop ajax based grid apps – a tutorial for...

Download Using  Cyberaide  JavaScript to develop Ajax based Grid Apps – A Tutorial for Grid App Developers

Post on 23-Feb-2016

43 views

Category:

Documents

0 download

Embed Size (px)

DESCRIPTION

Using Cyberaide JavaScript to develop Ajax based Grid Apps – A Tutorial for Grid App Developers. Gregor von Laszewski Fugang Wang Jun 22, 2009. Agenda. Prerequisite to use the framework for your development How to use the JavaScript API to interact with Grid - PowerPoint PPT Presentation

TRANSCRIPT

Slide 1

Using Cyberaide JavaScript to develop Ajax based Grid Apps A Tutorial for Grid App DevelopersGregor von LaszewskiFugang WangJun 22, 2009

Agenda Prerequisite to use the framework for your development How to use the JavaScript API to interact with Grid Authentication; job/workflow submission and status monitor; file transfer, etc. Mashup with other useful resources Expand the mediator functionality while reusing the architecture

Prerequisite to use the framework for your development How to use the JavaScript API to interact with Grid Authentication; job/workflow submission and status monitor; file transfer, etc. Mashup with other useful resources Expand the mediator functionality while reusing the architecture

Please setup the three-tier cyberaide JavaScript framework first. A full instruction can be found at:

http://cyberaide.googlecode.com/svn/trunk/project/javascript/README.txt The framework has Mediator service, Agent, and a web client[1]. Your app will be a web client while based on the Cyberaide JavaScript API.

[1] von Laszewski, G., Wang, F., Younge, A., He, X., Guo, Z., & Pierce, M. (2008). Cyberaide JavaScript: A JavaScript Commodity Grid Kit. Paper presented at the GCE08 at SC08, Austin, TX

Agenda Prerequisite to use the framework for your development How to use the JavaScript API to interact with Grid Authentication; job/workflow submission and status monitor; file transfer, etc. Mashup with other useful resources Expand the mediator functionality while reusing the architecture

The usage of the Cyberaide JavaScript toolkit is shown through code snipes. The code itself is not runnable. Please setup the three-tier cyberaide JavaScript framework first as mentioned previously, and put the code snipes into your code where you want to fulfill the functionality.

An Ajax Teragrid portal example developed based on the architecture and JavaScript API

// construct authenticator object for authentication using myproxy// make sure to use the attributes keys specified here.var auth = org.cyberaide.js.jsAuthenticator(url);auth.setAttribute("host", "myproxy.teragrid.org");auth.setAttribute("port", 7512);auth.setAttribute("user", YOURTGUSERNAME');auth.setAttribute("password", YOURPASSWORD');// currently only 'myproxy' is supportedauth.setProvider("myproxy"); How to authenticate through the Cyberaidejs?

// construct cyberaidejs object by pointing to the Agent service's url// Your call through the JavaScript API will be conducted to this Web service// Refer to the installation instruction for the url.

var url = "../axis2/services/AgentService; //If you followed each step, the url should be like this

var cyberaidejs = new org.cyberaide.js.jsUtil(url);

// authenticationcyberaidejs.authenticate(auth, authResponse);

// authResponse is the callback function handler

/* * the authenticate callback function */function authResponse(ret) { if(ret){ //authenticated successfully! //put your code here } else{ //authentication failed //put your code here }}

// define the job object//make sure to use the attributes keys specified here.var execObj = new org.cyberaide.js.jsExecutable();execObj.setAttribute("cmd", "/bin/ls");execObj.setAttribute("arg", "-l");execObj.setAttribute("rHost", 'REMOTEHOST');execObj.setAttribute("stdout", "lsoutput");execObj.setAttribute("provider", "GT4");// construct cyberaidejs object by pointing to the agent service's urlvar cyberaidejs = new org.cyberaide.js.jsUtil(url); How to submit a job to remote machine to execute?

// construct a remote job through the executable objectvar strProj = cyberaidejs.constructRemoteJob(execObj);

// submit the job by specifying constructed job specification, callback function.// you must be in authenticated status and in a valid session.cyberaidejs.submit(strProj, submitResponse);

// submitResponse is the callback function handler

/* * callback function of submission */function submitResponse(ret) { if(ret > 0){ //job submitted and job id returned. //your job id is 'ret', in Number format //do something here.

} else { //job submission failed. //do something here. }}

// Construct your Karajan workflow// var strProj = ...;// assign the Karajan workflow to this string and submit it.// you must be in authenticated status and in a valid session.cyberaidejs.submit(strProj, submitResponse, null);// Construct cyberaidejs object by pointing to the agent service's urlvar cyberaidejs = new org.cyberaide.js.jsUtil(url);// callback function could be the same as in job submission How to submit a workflow (in Karajan format)?

// construct cyberaidejs object by pointing to the agent service's urlvar cyberaidejs = new org.cyberaide.js.jsUtil(url);

// Invoke the list function//do this only after you have been authenticated and in a valid session.cyberaidejs.list(listResponse);

// listResponse is the callback function handler How to query job/workflow list that user submitted?

/* * call back for submitted jobs listing */function listResponse(jsonRet){ if(jsonRet != null){ var jsonRetObj = eval("(" + jsonRet + ")"); var wfids = jsonRetObj.wfids; var numIds = wfids.length; //now you got the jobs list with 'numIds' items in an array wfids //do something here. }}

// the jsonRet is in JSON format {"wfids": String[]}

// construct cyberaidejs object by pointing to the agent service's urlvar cyberaidejs = new org.cyberaide.js.jsUtil(url);

// and then query the status with its id// do this only after you have submitted some job/workflow cyberaidejs.statusQuery(wfid, statusQueryResponse);

// statusQueryResponse is the callback function handler How to query job/workflow execution status?

/* * callback function of status query, to display the status info */function statusQueryResponse(jsonRet){ if(jsonRet != null){ var jsonRetObj = eval("(" + jsonRet + ")") var wfid = jsonRetObj.wfid; var status = jsonRetObj.status; //now you get the workflowid and its current status, in a 'Number' format, //representing jobs finished so far in the workflow. //do something here. }}

// the jsonRet is in JSON format {"wfid":String,"status":String}

// construct cyberaidejs object by pointing to the agent service's urlvar cyberaidejs = new org.cyberaide.js.jsUtil(url);

// call the queryOutput function// do this only after you have been authenticated and in a valid session.cyberaidejs.queryOutput(wfid, queryOutputResponse);

// statusQueryResponse is the callback function handler How to query output fileNAME of a job/workflow?

/* * display the returned output file names appropriately and add content retrieve links */function queryOutputResponse(jsonRet){ if(jsonRet != null){ var jsonRetObj = eval("(" + jsonRet + ")"); var wfid = jsonRetObj.wfid; var resultFiles = jsonRetObj.resultFiles; //the result output file names for job/workflow with id 'wfid' have been stored //into array 'resultFiles' //you can display the filenames or get the REAL output through getOutput() method. } return false;}

// the jsonRet is in JSON format {"wfid":String,"outputFiles":String[]}

// construct cyberaidejs object by pointing to the agent service's urlvar cyberaidejs = new org.cyberaide.js.jsUtil(url);

// call the getOutput function// do this only after you have been authenticated and in a valid session.// wfid and filename specified job/workflow id and (one of) its output filename obtained through queryOutputcyberaidejs.getOutput(wfid, filename, getOutputResponse);

// getOutputResponse is the callback function handler How to get a specific output from a job/workflow execution?

/* * processing the returned output */function getOutputResponse(jsonRet){ if(jsonRet != null){ var jsonRetObj = eval("(" + jsonRet + ")"); var wfid = jsonRetObj.wfid; var filename = jsonRetObj.filename; var content = jsonRetObj.content; //now you have got the output content of an output file for the job 'wfid' //your code for further processing goes herer.. }}

// the jsonRet is in JSON format {"wfid":String,"outputfilename":String,"output":String}

How to do file transfer through cyberaidejs?// construct cyberaidejs object if not done yetvar cyberaidejs = new org.cyberaide.js.jsUtil(url);

// Invoke transfer function// source and dest are all URI per gridftp supported format, like file://PATH, gsiftp://HOST:PORT/PATH/TO/FILE// when using file:///~, it represents the user's remote home directory at where the mediator service resides,// using gsiftp://HOST:PORT/PATH/TO/FILE to point to the location at other remote resources like those from Teragrid// do this only after you have been successfully authenticated and is in valid sessioncyberaidejs.transfer(source, dest, transferResponse);

/* * the transfer callback function */function transferResponse(ret, updateloc) { if(!ret){ //Transfered successfully! //Your code goes here

} else{ //Transfer failed! //Your code goes here }}

Prerequisite to use the framework for your development How to use the JavaScript API to interact with Grid Authentication; job/workflow submission and status monitor; file transfer, etc. Mashup with other useful resources Expand the mediator functionality while reusing the architecture

You can develop sophisticated Grid app/portal/scientific gateway in Ajax style based on the JavaScript API. But you also can reuse the architecture and mashup useful resources in either server side or client side. Mas