[cig-commits] r7800 - in cs/cigtg/trunk/cigtg-dev/CigPortal/cigportal/src/org: . cig cig/portal cig/portal/beans cig/portal/grid cig/portal/grid/data cig/portal/grid/job cig/portal/grid/security cig/portal/portlets cig/portal/util

wei at geodynamics.org wei at geodynamics.org
Fri Aug 10 12:36:50 PDT 2007


Author: wei
Date: 2007-08-10 12:36:49 -0700 (Fri, 10 Aug 2007)
New Revision: 7800

Added:
   cs/cigtg/trunk/cigtg-dev/CigPortal/cigportal/src/org/cig/
   cs/cigtg/trunk/cigtg-dev/CigPortal/cigportal/src/org/cig/portal/
   cs/cigtg/trunk/cigtg-dev/CigPortal/cigportal/src/org/cig/portal/TG07.java
   cs/cigtg/trunk/cigtg-dev/CigPortal/cigportal/src/org/cig/portal/TG07GT4.java
   cs/cigtg/trunk/cigtg-dev/CigPortal/cigportal/src/org/cig/portal/TGHWGT4.java
   cs/cigtg/trunk/cigtg-dev/CigPortal/cigportal/src/org/cig/portal/beans/
   cs/cigtg/trunk/cigtg-dev/CigPortal/cigportal/src/org/cig/portal/beans/MagjobBean.java
   cs/cigtg/trunk/cigtg-dev/CigPortal/cigportal/src/org/cig/portal/beans/UserBean.java
   cs/cigtg/trunk/cigtg-dev/CigPortal/cigportal/src/org/cig/portal/grid/
   cs/cigtg/trunk/cigtg-dev/CigPortal/cigportal/src/org/cig/portal/grid/data/
   cs/cigtg/trunk/cigtg-dev/CigPortal/cigportal/src/org/cig/portal/grid/data/SimpleTransfer.java
   cs/cigtg/trunk/cigtg-dev/CigPortal/cigportal/src/org/cig/portal/grid/data/SimpleTransferThread.java
   cs/cigtg/trunk/cigtg-dev/CigPortal/cigportal/src/org/cig/portal/grid/job/
   cs/cigtg/trunk/cigtg-dev/CigPortal/cigportal/src/org/cig/portal/grid/job/SimpleRSL.java
   cs/cigtg/trunk/cigtg-dev/CigPortal/cigportal/src/org/cig/portal/grid/job/SimpleRunGT2.java
   cs/cigtg/trunk/cigtg-dev/CigPortal/cigportal/src/org/cig/portal/grid/job/SimpleRunGT4.java
   cs/cigtg/trunk/cigtg-dev/CigPortal/cigportal/src/org/cig/portal/grid/security/
   cs/cigtg/trunk/cigtg-dev/CigPortal/cigportal/src/org/cig/portal/grid/security/SimpleCred.java
   cs/cigtg/trunk/cigtg-dev/CigPortal/cigportal/src/org/cig/portal/portlets/
   cs/cigtg/trunk/cigtg-dev/CigPortal/cigportal/src/org/cig/portal/portlets/CigMagPortlet.java
   cs/cigtg/trunk/cigtg-dev/CigPortal/cigportal/src/org/cig/portal/portlets/UserPortlet.java
   cs/cigtg/trunk/cigtg-dev/CigPortal/cigportal/src/org/cig/portal/util/
   cs/cigtg/trunk/cigtg-dev/CigPortal/cigportal/src/org/cig/portal/util/Config.java
   cs/cigtg/trunk/cigtg-dev/CigPortal/cigportal/src/org/cig/portal/util/MAGPortletConfig.java
   cs/cigtg/trunk/cigtg-dev/CigPortal/cigportal/src/org/cig/portal/util/SimpleGridConstants.java
Log:
Add portlet for MAG, this set of code needs more tweak and testing. File sturcture will be set on teragrid sites(ncsa only for now) for MAG job.

Added: cs/cigtg/trunk/cigtg-dev/CigPortal/cigportal/src/org/cig/portal/TG07.java
===================================================================
--- cs/cigtg/trunk/cigtg-dev/CigPortal/cigportal/src/org/cig/portal/TG07.java	2007-08-10 02:13:13 UTC (rev 7799)
+++ cs/cigtg/trunk/cigtg-dev/CigPortal/cigportal/src/org/cig/portal/TG07.java	2007-08-10 19:36:49 UTC (rev 7800)
@@ -0,0 +1,92 @@
+/**
+ *  Copyright (c) 2007 Computational Infrastructure for Geodynamics (CIG),
+ *  , All Rights Reserved.
+ */
+
+package org.cig.portal;
+
+import org.gisolve.demo.app.*;
+import org.cig.portal.grid.data.*;
+import org.cig.portal.grid.job.*;
+import org.cig.portal.grid.security.*;
+import org.cig.portal.util.*;
+
+import java.io.*;
+import java.util.*;
+import org.ietf.jgss.GSSCredential;
+import org.globus.util.Util;
+
+public class TG07 {
+	/**
+	 * The SimpleGrid workflow process illustrated
+	 * @param args
+	 */
+	public static void main(String[] args) throws Exception {
+		String site = (args.length==0)?"NCSA":args[0];
+		TG07 test = new TG07();
+		String testhome = System.getenv("HOME")+"/cigtg"+"/CigPortal/test2";
+		String dataset = System.getenv("HOME")+"/cigtg"+"/CigPortal/cigportal/webapp/storage/samples/sample";
+		System.out.println("-----------------------------------------------------");
+		System.out.println("SimpleGrid java application workflow for DMS analysis");
+		System.out.println("-----------------------------------------------------");
+		System.out.println("Anytime, press Ctrol+C to stop the workflow\n");
+		// 0. load our configuration
+		System.out.println("\nStep 0: load our configuration");
+		String configPath = System.getenv("HOME")+"/cigtg"+"/CigPortal/cigportal/webapp/cigportal.properties";
+		org.cig.portal.util.Config myconfig= new org.cig.portal.util.Config(configPath);
+		System.out.println("Configuration is loaded from default config file "+configPath+". Please check:");
+		myconfig.print();
+
+		// 1. get a proxy
+		// 1.1 method 1: load a valid proxy file
+		System.out.println("\nStep 1: get a grid proxy");
+		System.out.println("myproxy server: "+myconfig.get("grid.myproxy.server")+":"+myconfig.get("grid.myproxy.port"));
+		System.out.println("username: "+myconfig.get("grid.myproxy.username"));
+		String password = Util.getPrivateInput("password: ");
+		SimpleCred mycred = new SimpleCred(myconfig.get("grid.myproxy.server"), Integer.parseInt(myconfig.get("grid.myproxy.port")), "", "", "");
+		mycred.logon(myconfig.get("grid.myproxy.username"), password);
+		GSSCredential proxy = mycred.get();
+		System.out.println(mycred.info());
+
+		// 2. transfer the sample dataset to one of the teragrid site
+		System.out.println("\nStep 2: transfer dataset to "+site);
+		System.out.println("dataset: " + dataset);
+		SimpleTransfer ft = new SimpleTransfer(proxy, myconfig.get("grid.gridftp."+site), 2811);
+		ft.local2remote(dataset, myconfig.get("grid.sites.dmsdir."+site)+"/datasets/sample2");
+
+		// 3. submit job : GT2 method
+		System.out.println("\nStep 3: submit job to "+site);
+		String rsl = SimpleRSL.getRSL_GT2(myconfig, site, 500, 20, "sample2", "result2");
+		System.out.println("RSL:\n"+rsl);
+		SimpleRunGT2 sr = new SimpleRunGT2(proxy);
+		String jobId = sr.execute(myconfig.get("grid.gram."+site), rsl);
+	    System.out.println("Job submitted. ID: " + jobId);
+	    String status;
+	    do {
+	          Thread.sleep(4000);
+	          status = sr.getStatus(jobId);
+	          System.out.println("Job Status: " + status);
+	    } while (!(status.equalsIgnoreCase("Error fetching status") || status.equalsIgnoreCase("DONE")));
+
+	    // 4. transfer results back
+	    System.out.println("\nStep 4: transfer result from "+site);
+	    String remotefile = myconfig.get("grid.sites.dmsdir."+site)+"/results/result2.20.dat";
+		System.out.println("result file: " + remotefile);
+	    ft.remote2local(remotefile, testhome+"/result2");
+
+		// 5. visualize results
+		String s1 = System.getenv("HOME")+"/cigtg"+"/CigPortal/cigportal/webapp/storage/bnd_poly.dat";
+		String s12 = System.getenv("HOME")+"/cigtg"+"/CigPortal/cigportal/webapp/storage/bnd_uspolygon.dat";
+		String s2 = testhome+"/result2";
+		String s3 = "";
+		String s4 = testhome+"/result2.jpg";
+		IDWViz viz = new IDWViz(s1, s12, s2, s3, s4);
+		viz.loadBoundary();
+		viz.loadUSPolygon();
+		//viz.createSample(500, 500, 0, 10000, true, true);
+		viz.loadDataset();
+		viz.plot();
+	}
+
+}
+

Added: cs/cigtg/trunk/cigtg-dev/CigPortal/cigportal/src/org/cig/portal/TG07GT4.java
===================================================================
--- cs/cigtg/trunk/cigtg-dev/CigPortal/cigportal/src/org/cig/portal/TG07GT4.java	2007-08-10 02:13:13 UTC (rev 7799)
+++ cs/cigtg/trunk/cigtg-dev/CigPortal/cigportal/src/org/cig/portal/TG07GT4.java	2007-08-10 19:36:49 UTC (rev 7800)
@@ -0,0 +1,91 @@
+/**
+ *  Copyright (c) 2007 Computational Infrastructure for Geodynamics (CIG),
+ *  California Institute of Technology, All Rights Reserved.
+ */
+
+package org.cig.portal;
+
+import org.gisolve.demo.app.*;
+import org.cig.portal.grid.data.*;
+import org.cig.portal.grid.job.*;
+import org.cig.portal.grid.security.*;
+import org.cig.portal.util.*;
+
+import java.io.*;
+import java.util.*;
+import org.ietf.jgss.GSSCredential;
+import org.globus.util.Util;
+
+public class TG07GT4 {
+	/**
+	 * The SimpleGrid workflow process illustrated
+	 * @param args
+	 */
+	public static void main(String[] args) throws Exception {
+		String site = (args.length==0)?"NCSA":args[0];
+		TG07GT4 test = new TG07GT4();
+		String testhome = System.getenv("HOME")+"/cigtg"+"/CigPortal/test2";
+		String dataset = System.getenv("HOME")+"/cigtg"+"/CigPortal/cigportal/webapp/storage/samples/sample";
+		System.out.println("-----------------------------------------------------");
+		System.out.println("SimpleGrid java application workflow for DMS analysis");
+		System.out.println("-----------------------------------------------------");
+		System.out.println("Anytime, press Ctrol+C to stop the workflow\n");
+		// 0. load our configuration
+		System.out.println("\nStep 0: load our configuration");
+		String configPath = System.getenv("HOME")+"/cigtg"+"/CigPortal/cigportal/webapp/cigportal.properties";
+		org.cig.portal.util.Config myconfig= new org.cig.portal.util.Config(configPath);
+		System.out.println("Configuration is loaded from default config file "+configPath+". Please check:");
+		myconfig.print();
+
+		// 1. get a proxy
+		// 1.1 method 1: load a valid proxy file
+		System.out.println("\nStep 1: get a grid proxy");
+		System.out.println("myproxy server: "+myconfig.get("grid.myproxy.server")+":"+myconfig.get("grid.myproxy.port"));
+		System.out.println("username: "+myconfig.get("grid.myproxy.username"));
+		String password = Util.getPrivateInput("password: ");
+		SimpleCred mycred = new SimpleCred(myconfig.get("grid.myproxy.server"), Integer.parseInt(myconfig.get("grid.myproxy.port")), "", "", "");
+		mycred.logon(myconfig.get("grid.myproxy.username"), password);
+		GSSCredential proxy = mycred.get();
+		System.out.println(mycred.info());
+
+		// 2. transfer the sample dataset to one of the teragrid site
+		System.out.println("\nStep 2: transfer dataset to "+site);
+		System.out.println("dataset: " + dataset);
+		SimpleTransfer ft = new SimpleTransfer(proxy, myconfig.get("grid.gridftp."+site), 2811);
+		ft.local2remote(dataset, myconfig.get("grid.sites.dmsdir."+site)+"/datasets/sample2");
+
+		// 3. submit job : GT4 method
+		System.out.println("\nStep 3: submit job to "+site);
+		String rsl = SimpleRSL.getRSL_GT4(myconfig, site, 500, 20, "sample2", "result2");
+		System.out.println("RSL:\n"+rsl);
+		SimpleRunGT4 sr = new SimpleRunGT4(proxy);
+		String jobId = sr.execute(myconfig.get("grid.wsgram."+site), rsl);
+	    System.out.println("Job submitted. ID: " + jobId);
+	    String status;
+	    do {
+	          Thread.sleep(4000);
+	          status = sr.getStatus(jobId);
+	          System.out.println("Job Status: " + status);
+	    } while (!(status.equalsIgnoreCase("Error fetching status") || status.equalsIgnoreCase("DONE")));
+
+	    // 4. transfer results back
+	    System.out.println("\nStep 4: transfer result from "+site);
+	    String remotefile = myconfig.get("grid.sites.dmsdir."+site)+"/results/result2.20.dat";
+		System.out.println("result file: " + remotefile);
+	    ft.remote2local(remotefile, testhome+"/result2");
+
+		// 5. visualize results
+		String s1 = System.getenv("HOME")+"/cigtg"+"/CigPortal/cigportal/webapp/storage/bnd_poly.dat";
+		String s12 = System.getenv("HOME")+"/cigtg"+"/CigPortal/cigportal/webapp/storage/bnd_uspolygon.dat";
+		String s2 = testhome+"/result2";
+		String s3 = "";
+		String s4 = testhome+"/result2.jpg";
+		IDWViz viz = new IDWViz(s1, s12, s2, s3, s4);
+		viz.loadBoundary();
+		viz.loadUSPolygon();
+		//viz.createSample(500, 500, 0, 10000, true, true);
+		viz.loadDataset();
+		viz.plot();
+	}
+
+}

Added: cs/cigtg/trunk/cigtg-dev/CigPortal/cigportal/src/org/cig/portal/TGHWGT4.java
===================================================================
--- cs/cigtg/trunk/cigtg-dev/CigPortal/cigportal/src/org/cig/portal/TGHWGT4.java	2007-08-10 02:13:13 UTC (rev 7799)
+++ cs/cigtg/trunk/cigtg-dev/CigPortal/cigportal/src/org/cig/portal/TGHWGT4.java	2007-08-10 19:36:49 UTC (rev 7800)
@@ -0,0 +1,92 @@
+/**
+ *  Copyright (c) 2007 Computational Infrastructure for Geodynamics (CIG),
+ *  California Institute of Technology, All Rights Reserved.
+ */
+
+package org.cig.portal;
+
+import org.gisolve.demo.app.*;
+import org.cig.portal.grid.data.*;
+import org.cig.portal.grid.job.*;
+import org.cig.portal.grid.security.*;
+import org.cig.portal.util.*;
+
+import java.io.*;
+import java.util.*;
+import org.ietf.jgss.GSSCredential;
+import org.globus.util.Util;
+
+public class TGHWGT4 {
+	/**
+	 * The SimpleGrid workflow process illustrated
+	 * @param args
+	 */
+	public static void main(String[] args) throws Exception {
+		String site = (args.length==0)?"NCSA":args[0];
+		TGHWGT4 test = new TGHWGT4();
+		String cigportalhome = System.getenv("HOME")+"/cigtg"+"/CigPortal-svn/";
+		String testhome = cigportalhome+"/test2";
+		String dataset =  cigportalhome+"/cigportal/webapp/storage/samples/helloworld";
+		System.out.println("-----------------------------------------------------");
+		System.out.println("SimpleGrid java application workflow for HelloWorld analysis");
+		System.out.println("-----------------------------------------------------");
+		System.out.println("Anytime, press Ctrol+C to stop the workflow\n");
+		// 0. load our configuration
+		System.out.println("\nStep 0: load our configuration");
+		String configPath = cigportalhome+"/cigportal/webapp/cigportal.properties";
+		org.cig.portal.util.Config myconfig= new org.cig.portal.util.Config(configPath);
+		System.out.println("Configuration is loaded from default config file "+configPath+". Please check:");
+		myconfig.print();
+
+		// 1. get a proxy
+		// 1.1 method 1: load a valid proxy file
+		System.out.println("\nStep 1: get a grid proxy");
+		System.out.println("myproxy server: "+myconfig.get("grid.myproxy.server")+":"+myconfig.get("grid.myproxy.port"));
+		System.out.println("username: "+myconfig.get("grid.myproxy.username"));
+		String password = Util.getPrivateInput("password: ");
+		SimpleCred mycred = new SimpleCred(myconfig.get("grid.myproxy.server"), Integer.parseInt(myconfig.get("grid.myproxy.port")), "", "", "");
+		mycred.logon(myconfig.get("grid.myproxy.username"), password);
+		GSSCredential proxy = mycred.get();
+		System.out.println(mycred.info());
+
+		// 2. transfer the sample dataset to one of the teragrid site
+		System.out.println("\nStep 2: transfer dataset to "+site);
+		System.out.println("dataset: " + dataset);
+		SimpleTransfer ft = new SimpleTransfer(proxy, myconfig.get("grid.gridftp."+site), 2811);
+		ft.local2remote(dataset, myconfig.get("grid.sites.dmsdir."+site)+"/datasets/sample2");
+
+		// 3. submit job : GT4 method
+		System.out.println("\nStep 3: submit job to "+site);
+		String rsl = SimpleRSL.getRSL_GT4(myconfig, site, 500, 20, "sample2", "result2");
+		System.out.println("RSL:\n"+rsl);
+		SimpleRunGT4 sr = new SimpleRunGT4(proxy);
+		String jobId = sr.execute(myconfig.get("grid.wsgram."+site), rsl);
+	    System.out.println("Job submitted. ID: " + jobId);
+	    String status;
+	    do {
+	          Thread.sleep(4000);
+	          status = sr.getStatus(jobId);
+	          System.out.println("Job Status: " + status);
+	    } while (!(status.equalsIgnoreCase("Error fetching status") || status.equalsIgnoreCase("DONE")));
+
+	    // 4. transfer results back
+	    System.out.println("\nStep 4: transfer result from "+site);
+	    String remotefile = myconfig.get("grid.sites.dmsdir."+site)+"/results/result2.20.dat";
+		System.out.println("result file: " + remotefile);
+	    ft.remote2local(remotefile, testhome+"/result2");
+
+		// 5. visualize results
+		String s1 = cigportalhome+"/cigportal/webapp/storage/bnd_poly.dat";
+		String s12 = cigportalhome+"/cigportal/webapp/storage/bnd_uspolygon.dat";
+		String s2 = testhome+"/result2";
+		String s3 = "";
+		String s4 = testhome+"/result2.jpg";
+		IDWViz viz = new IDWViz(s1, s12, s2, s3, s4);
+		viz.loadBoundary();
+		viz.loadUSPolygon();
+		//viz.createSample(500, 500, 0, 10000, true, true);
+		viz.loadDataset();
+		viz.plot();
+	}
+
+}

Added: cs/cigtg/trunk/cigtg-dev/CigPortal/cigportal/src/org/cig/portal/beans/MagjobBean.java
===================================================================
--- cs/cigtg/trunk/cigtg-dev/CigPortal/cigportal/src/org/cig/portal/beans/MagjobBean.java	2007-08-10 02:13:13 UTC (rev 7799)
+++ cs/cigtg/trunk/cigtg-dev/CigPortal/cigportal/src/org/cig/portal/beans/MagjobBean.java	2007-08-10 19:36:49 UTC (rev 7800)
@@ -0,0 +1,100 @@
+/**
+ *  Copyright (c) 2007 Computational Infrastructure for Geodynamics (CIG),
+ *  California Institute of Technology, All Rights Reserved.
+ */
+
+package org.cig.portal.beans;
+
+public class MagjobBean {
+	String id;
+	int[] K;
+	int N;
+	String dataset;
+	String status;
+	String site; // index of this site
+	String jobhandle[];
+	String gtVersion;
+	
+	public MagjobBean() {
+		id = null;
+		K = null;
+		N = 0;
+		dataset = "";
+		status = "New";
+		site = "";
+		jobhandle = null;
+		gtVersion = "GT2";
+	}
+	public MagjobBean(String pid) {
+		id = pid;
+		K = null;
+		N = 0;
+		dataset = "";
+		status = "New";
+		site = "";
+		jobhandle = null;
+		gtVersion = "GT2";
+	}
+	public void setId(String pid) {
+		id = pid;
+	}
+	public String getId() {
+		return id;
+	}
+	public void setKList(int[] pk) {
+		K = pk;
+		jobhandle = new String[pk.length];
+	}
+	public int[] getKList() {
+		return K;
+	}
+	public int getK(int i) {
+		return K[i];
+	}
+	public int getKnum() {
+		return K.length;
+	}
+	public void setN(int pn) {
+		N = pn;
+	}
+	public int getN() {
+		return N;
+	}
+	public void setDataset(String s) {
+		dataset = s;
+	}
+	public String getDataset() {
+		return dataset;
+	}
+	public void setSite(String s) {
+		site = s;
+	}
+	public String getSite() {
+		return site;
+	}
+	public void setStatus(String s) {
+		status = s;
+	}
+	public String getStatus() {
+		return status;
+	}	
+	public void setHandleList(String[] s) {
+		jobhandle = s;
+	}
+	public void setHandle(int i, String s) {
+		jobhandle[i] = s;
+	}
+	public String[] getHandleList() {
+		return jobhandle;
+	}
+	public String getHandle(int i) {
+		return jobhandle[i];
+	}
+	public void setGtVersion(String s) {
+		gtVersion = s;
+	}
+	public String getGtVersion() {
+		return gtVersion;
+	}	
+}
+

Added: cs/cigtg/trunk/cigtg-dev/CigPortal/cigportal/src/org/cig/portal/beans/UserBean.java
===================================================================
--- cs/cigtg/trunk/cigtg-dev/CigPortal/cigportal/src/org/cig/portal/beans/UserBean.java	2007-08-10 02:13:13 UTC (rev 7799)
+++ cs/cigtg/trunk/cigtg-dev/CigPortal/cigportal/src/org/cig/portal/beans/UserBean.java	2007-08-10 19:36:49 UTC (rev 7800)
@@ -0,0 +1,60 @@
+/**
+ *  Copyright (c) 2007 Computational Infrastructure for Geodynamics (CIG),
+ *  California Institute of Technology, All Rights Reserved.
+ */
+
+package org.cig.portal.beans;
+
+import java.util.Date;
+import java.text.DateFormat;
+
+public class UserBean {
+	String firstName;
+	String lastName;
+	String emailAddress;
+	String organization;
+	int numLogins;
+	String lastLoginTime;
+	
+	public UserBean() {
+		
+	}
+	
+	public String getFirstName() {
+		return this.firstName;
+	}
+	public void setFirstName(String s) {
+		this.firstName = s;
+	}	
+	public String getLastName() {
+		return this.lastName;
+	}
+	public void setLastName(String s) {
+		this.lastName = s;
+	}
+	public String getEmailAddress() {
+		return this.emailAddress;
+	}
+	public void setEmailAddress(String s) {
+		this.emailAddress = s;
+	}
+	public String getOrganization() {
+		return this.organization;
+	}
+	public void setOrganization(String s) {
+		this.organization = s;
+	}
+	public String getLastLoginTime() {
+		return this.lastLoginTime;
+	}
+	public void setLastLoginTime(String s) {
+		this.lastLoginTime = s;
+	}
+	public int getNumLogins() {
+		return this.numLogins;
+	}
+	public void setNumLogins(int i) {
+		this.numLogins = i;
+	}
+}
+

Added: cs/cigtg/trunk/cigtg-dev/CigPortal/cigportal/src/org/cig/portal/grid/data/SimpleTransfer.java
===================================================================
--- cs/cigtg/trunk/cigtg-dev/CigPortal/cigportal/src/org/cig/portal/grid/data/SimpleTransfer.java	2007-08-10 02:13:13 UTC (rev 7799)
+++ cs/cigtg/trunk/cigtg-dev/CigPortal/cigportal/src/org/cig/portal/grid/data/SimpleTransfer.java	2007-08-10 19:36:49 UTC (rev 7800)
@@ -0,0 +1,138 @@
+/**
+ *  Copyright (c) 2007 Computational Infrastructure for Geodynamics (CIG),
+ *  California Institute of Technology, All Rights Reserved.
+ */
+
+package org.cig.portal.grid.data;
+
+//ftp
+import org.globus.ftp.GridFTPClient;
+import org.globus.ftp.DataChannelAuthentication;
+import org.globus.ftp.GridFTPSession;
+import org.globus.ftp.HostPort;
+import org.globus.ftp.HostPortList;
+import org.globus.ftp.exception.*;
+// security
+import org.ietf.jgss.GSSCredential;
+import org.ietf.jgss.GSSException;
+import org.cig.portal.grid.security.*;
+
+import java.io.*;
+
+/**
+ * A simple gridftp utility class
+ * @author liuyan 
+ * @author wei modified
+ */
+public class SimpleTransfer {
+        String host1;
+        String host2;
+        int port1;
+        int port2;
+        GSSCredential proxy;
+        /**
+         * Constructor for 3rd party transfer
+         * @param proxyp a valid proxy
+         * @param s source host
+         * @param sport source port
+         * @param d dest host
+         * @param dport dest port
+         */
+        public SimpleTransfer(GSSCredential proxyp, String s, int sport, String d, int dport) {
+                host1 = s;
+                port1 = sport;
+                host2 = d;
+                port2 = dport;
+                proxy = proxyp;
+        }
+        /**
+         * Constructor for local-remote transfer
+         * @param proxyp a valid proxy
+         * @param d remote host
+         * @param dport remote port
+         */
+        public SimpleTransfer(GSSCredential proxyp, String d, int dport) {
+                host1 = "localhost";
+                host2 = d;
+                port2 = dport;
+                proxy = proxyp;
+        }
+        /**
+         * Transfer a remote file to local
+         * @param remote remote file as source
+         * @param local local file as destination
+         * @throws GSSException
+         * @throws ServerException
+         * @throws IOException
+         * @throws ClientException
+         */
+        public void remote2local(String remote, String local) throws GSSException, ServerException, IOException, ClientException {
+        	if (proxy.getRemainingLifetime() < SimpleCred.DEFAULT_MIN) {
+                throw new GSSException(GSSException.CREDENTIALS_EXPIRED);
+        	}
+
+	        GridFTPClient host = new GridFTPClient(host2, port2);
+	
+	        host.authenticate(proxy);
+	
+	        //set up the parameter of the client part
+	        //host.setProtectionBufferSize(16384);    //unit
+	        //host.setDataChannelAuthentication(DataChannelAuthentication.SELF);
+	        //host.setDataChannelProtection(GridFTPSession.PROTECTION_SAFE);
+	        host.setPassive();
+	        host.setLocalActive();
+	        //get local file from remote file
+	        File localF = new File(local);
+	        host.get(remote, localF);
+        }
+        /**
+         * Transfer a local file to remote
+         * @param local local file as source
+         * @param remote remote file as destination
+         * @throws GSSException
+         * @throws ServerException
+         * @throws IOException
+         * @throws ClientException
+         */
+        public void local2remote(String local, String remote) throws GSSException, ServerException, IOException, ClientException {
+        	if (proxy.getRemainingLifetime() < SimpleCred.DEFAULT_MIN) {
+        		throw new GSSException(GSSException.CREDENTIALS_EXPIRED);
+        	}
+	        GridFTPClient host = new GridFTPClient(host2, port2);
+	
+	        host.authenticate(proxy);
+	
+	        //set up the parameter of the client part
+	        //host.setProtectionBufferSize(16384);    //unit 
+	        //host.setDataChannelAuthentication(DataChannelAuthentication.SELF);
+	        //host.setDataChannelProtection(GridFTPSession.PROTECTION_SAFE);
+	
+	        //put local file to remote file, don't append
+	        File localF = new File(local);
+	        host.put(localF, remote, false);
+	    }
+
+        public static void main(String[] args) throws Exception {
+        	org.cig.portal.util.Config myconfig=null;
+    		SimpleCred mycred=null;
+    		GSSCredential proxy = null;
+    		try {
+    			//String password = Util.getPrivateInput("Input password for user " + args[0]);
+    			myconfig = new org.cig.portal.util.Config();
+    			mycred = new SimpleCred(myconfig.get("grid.myproxy.server"), Integer.parseInt(myconfig.get("grid.myproxy.port")), myconfig.get("grid.myproxy.username"), "", myconfig.get("grid.myproxy.proxyfile"));
+    			// assume proxy file specified is valid
+    			proxy = mycred.get();
+    			System.out.println(mycred.info());
+    		} catch (Exception e) {
+    			e.printStackTrace();
+    		}
+            SimpleTransfer ft = new SimpleTransfer(proxy, "tg-gridftp.uc.teragrid.org", 2811);
+              
+            ft.local2remote("/home/wei/cigtg/test/sample", "/home/ac/cigportl/sample.ncsa");
+            ft.remote2local("/home/ac/cigportl/sample.ncsa", "/home/wei/cigtg/test/sample.loopback");
+            ft.local2remote("/home/wei/cigtg/test/sample2", "/home/ac/cigportl/sample.ncsa2");
+            ft.remote2local("/home/ac/cigportl/sample.ncsa2", "/home/wei/cigtg/test/sample.loopback2");
+           
+        }
+}
+

Added: cs/cigtg/trunk/cigtg-dev/CigPortal/cigportal/src/org/cig/portal/grid/data/SimpleTransferThread.java
===================================================================
--- cs/cigtg/trunk/cigtg-dev/CigPortal/cigportal/src/org/cig/portal/grid/data/SimpleTransferThread.java	2007-08-10 02:13:13 UTC (rev 7799)
+++ cs/cigtg/trunk/cigtg-dev/CigPortal/cigportal/src/org/cig/portal/grid/data/SimpleTransferThread.java	2007-08-10 19:36:49 UTC (rev 7800)
@@ -0,0 +1,51 @@
+/**
+ *  Copyright (c) 2007 Computational Infrastructure for Geodynamics (CIG),
+ *  California Institute of Technology, All Rights Reserved.
+ */
+
+package org.cig.portal.grid.data;
+
+import org.cig.portal.grid.data.SimpleTransfer;
+import org.ietf.jgss.GSSCredential;
+
+public class SimpleTransferThread extends Thread {
+	public static final int LOCALTOREMOTE = 0;
+	public static final int REMOTETOLOCAL = 1;
+	String local[]; 
+	String remote[];
+	String status, ownerid; // id is used to identify the owner of this thread
+	int mode;
+	SimpleTransfer myxfer;
+	public SimpleTransferThread(int mmode, GSSCredential pproxy, String remoteHost, String localFile[], String remoteFile[], String jid) {
+		status = "";
+		mode = mmode;
+		remote = remoteFile;
+		local = localFile;
+		myxfer = new SimpleTransfer(pproxy, remoteHost, 2811);
+		ownerid = jid;
+	}
+	public String getStatus() {
+		return status;
+	}
+	public String getOwnerId() {
+		return ownerid;
+	}
+	public void run() {
+		try {
+			for (int i=0; i<local.length; i++) {
+		
+				if (mode == SimpleTransferThread.LOCALTOREMOTE) {
+					myxfer.local2remote(local[i], remote[i]);
+				} else {
+					myxfer.remote2local(remote[i], local[i]);
+				}
+			}
+			status = "SUCCESS";
+		} catch (Exception e) {
+			// just stop
+			status = "error: "+e.toString();
+			e.printStackTrace();
+		}
+	}
+}
+

Added: cs/cigtg/trunk/cigtg-dev/CigPortal/cigportal/src/org/cig/portal/grid/job/SimpleRSL.java
===================================================================
--- cs/cigtg/trunk/cigtg-dev/CigPortal/cigportal/src/org/cig/portal/grid/job/SimpleRSL.java	2007-08-10 02:13:13 UTC (rev 7799)
+++ cs/cigtg/trunk/cigtg-dev/CigPortal/cigportal/src/org/cig/portal/grid/job/SimpleRSL.java	2007-08-10 19:36:49 UTC (rev 7800)
@@ -0,0 +1,81 @@
+/**
+ *  Copyright (c) 2007 Computational Infrastructure for Geodynamics (CIG),
+ *  California Institute of Technology, All Rights Reserved.
+ */
+
+package org.cig.portal.grid.job;
+
+import org.cig.portal.util.Config;
+import java.io.File;
+
+/**
+ * A simple globus RSL composer for the tutorial application
+ * @author liuyan
+ * @author wei modified for CIG portal
+ */
+public class SimpleRSL {
+	public static String getRSL_GT2(Config myconfig, String site, int resolution, int k, String dataset, String jobid) {
+		String project = myconfig.get("grid.projectname");
+		String appdir = myconfig.get("grid.sites.dmsdir."+site);
+		
+		// GT2 rsl doesn't need to include resource manager element
+		//return "& (resourceManagerContact=\"tg-login1.sdsc.teragrid.org:2120/jobmanager-pbs\")" + "\n"
+        return "&  (jobType=single)" + "\n"
+        + "        (count=1)" + "\n"
+        + "        (host_count=\"1"+(site.equals("UC")?":ia64-compute":"")+"\")" + "\n"
+        + (project==null?"":"        (project=\""+project+"\")" + "\n")
+        + "        (executable=\""+appdir+"/release/process.pl"+"\")" + "\n"
+        + "        (arguments=\""+resolution+"\" \""+resolution+"\" \""+k+"\" \""
+        			+appdir+"/datasets/"+dataset+"\" \""
+        			+appdir+"/results/"+jobid+"."+k+".dat\""+")" + "\n"
+        + "        (directory=\""+appdir+"/release"+"\")" + "\n"
+        + "        (stdout=\""+appdir+"/results/stdout."+jobid+"."+k+"\")" + "\n"
+        + "        (stderr=\""+appdir+"/results/stderr."+jobid+"."+k+"\")" + "\n"
+        + "" + "\n";
+	}
+	public static String getRSL_GT4(Config myconfig, String site, int resolution, int k, String dataset, String output) {
+		return SimpleRSL.getRSL_GT4(true, myconfig, site, resolution, k, dataset, output);
+	}
+	public static String getRSL_GT4(boolean header, Config myconfig, String site, int resolution, int k, String dataset, String jobid) {
+		String project = myconfig.get("grid.projectname");
+		String appdir = myconfig.get("grid.sites.dmsdir."+site);
+		String remoteurl = myconfig.get("grid.wsgram."+site);
+		String remotescheduler = myconfig.get("grid.wsgram.rm."+site);
+		return "<job>" + "\n"
+		+	(header?(
+		  "    <factoryEndpoint" + "\n"
+        + "          xmlns:gram=\"http://www.globus.org/namespaces/2004/10/gram/job\"" + "\n"
+        + "          xmlns:wsa=\"http://schemas.xmlsoap.org/ws/2004/03/addressing\">" + "\n"
+        + "        <wsa:Address>"+remoteurl+"</wsa:Address>" + "\n"
+        + "        <wsa:ReferenceProperties>" + "\n"
+        + "            <gram:ResourceID>"+remotescheduler+"</gram:ResourceID>" + "\n"
+        + "        </wsa:ReferenceProperties>" + "\n"
+        + "    </factoryEndpoint>" + "\n"
+        	):"")
+/* optional        	
+        + "    <jobType>single</jobType>" + "\n"
+        + "    <count>1</count>" + "\n"
+        + "    <hostCount>1</hostCount>" + "\n"
+*/
+        + (project==null?"":"    <project>"+project+"</project>" + "\n")
+        + "    <executable>"+appdir+"/release/process.pl"+"</executable>" + "\n"
+        + "    <directory>"+appdir+"/release"+"</directory>" + "\n"
+        + "    <argument>"+resolution+"</argument>" + "\n"
+        + "    <argument>"+resolution+"</argument>" + "\n"
+        + "    <argument>"+k+"</argument>" + "\n"
+        + "    <argument>"+appdir+"/datasets/"+dataset+"</argument>" + "\n"
+        + "    <argument>"+appdir+"/results/"+jobid+"."+k+".dat</argument>" + "\n"
+        + "    <stdout>"+appdir+"/results/stdout."+jobid+"."+k+"</stdout>" + "\n"
+        + "    <stderr>"+appdir+"/results/stderr."+jobid+"."+k+"</stderr>" + "\n"
+        + "</job>" + "\n";
+	}
+	public static void main(String[] args) throws Exception {
+		org.cig.portal.util.Config myconfig=new org.cig.portal.util.Config();
+		SimpleRSL myrsl = new SimpleRSL();
+		String rsl = myrsl.getRSL_GT2(myconfig, "UC", 500, 20, "mydataset", "myoutput");
+		String rsl2 = myrsl.getRSL_GT2(myconfig, "SDSC", 500, 20, "mydataset", "myoutput");
+		String rsl3 = myrsl.getRSL_GT4(myconfig, "SDSC", 500, 20, "mydataset", "myoutput");
+	}
+
+}
+

Added: cs/cigtg/trunk/cigtg-dev/CigPortal/cigportal/src/org/cig/portal/grid/job/SimpleRunGT2.java
===================================================================
--- cs/cigtg/trunk/cigtg-dev/CigPortal/cigportal/src/org/cig/portal/grid/job/SimpleRunGT2.java	2007-08-10 02:13:13 UTC (rev 7799)
+++ cs/cigtg/trunk/cigtg-dev/CigPortal/cigportal/src/org/cig/portal/grid/job/SimpleRunGT2.java	2007-08-10 19:36:49 UTC (rev 7800)
@@ -0,0 +1,121 @@
+/**
+ *  Copyright (c) 2007 Computational Infrastructure for Geodynamics (CIG),
+ *  California Institute of Technology, All Rights Reserved.
+ */
+
+package org.cig.portal.grid.job;
+//Grid security
+import org.ietf.jgss.GSSException;
+import org.ietf.jgss.GSSCredential;
+
+import org.gridforum.jgss.ExtendedGSSManager;
+import org.gridforum.jgss.ExtendedGSSCredential;
+
+import org.globus.gsi.gssapi.GlobusGSSCredentialImpl;
+import org.globus.gsi.gssapi.GlobusGSSManagerImpl;
+import org.globus.gsi.gssapi.GlobusGSSException;
+import org.globus.gsi.GlobusCredential;
+import org.globus.gsi.GlobusCredentialException;
+
+// Gram
+import org.globus.gram.Gram;
+import org.globus.gram.GramJob;
+import org.globus.gram.GramException;
+
+import org.cig.portal.grid.security.*;
+
+import java.io.*;
+//import java.util.Properties;
+
+public class SimpleRunGT2 {
+	protected GSSCredential proxy;
+
+	public SimpleRunGT2(GSSCredential cred) {
+		proxy = cred;
+	}
+	// ping remote Gram server
+	private boolean ping(String contact) {
+		try {
+			Gram.ping(proxy, contact);
+		} catch(Exception e) {
+			System.err.println("Error - SimpleRunGT2::ping():");
+			e.printStackTrace();
+			return false;
+		}
+		return true;
+	}
+	// run job
+	// Note: Gram.request doens't recognize DUROC rsl, so single job is rsl required
+	public String execute(String contact, String rsl) {
+		GramJob job = null;
+		String id;
+		try {
+			if (proxy.getRemainingLifetime() < SimpleCred.DEFAULT_MIN)
+				return null;
+			// ping remote Gram server
+			boolean b = ping(contact);
+			if (!b) return null;
+			// submit job
+			job = new GramJob(proxy, rsl);
+			//System.out.println(test_pbs);
+			Gram.request(contact, job, true);
+			id = job.getIDAsString();
+		} catch (GramException e) {
+			System.err.println("GramException - SimpleRunGT2::execute():\n"+e.toString());
+			return null;
+		} catch (GSSException e) {
+			System.err.println("GSSException - SimpleRunGT2::execute():\n"+e.toString());
+			return null;
+		}
+		System.out.println("globus-job-run: SUCCESS, ghandle: "+id);
+		return id;
+	}
+
+	// get job status
+	private GramJob probeJob(String jobId) {
+		GramJob job = null;
+		try {
+			job = new GramJob("probe rsl");
+			job.setCredentials(proxy);
+			job.setID(jobId);
+			Gram.jobStatus(job);
+		} catch (Exception e) {
+			return null;
+		}
+		return job;
+	}
+	public String getStatus(String jobId) {
+		GramJob rJob = this.probeJob(jobId);
+		// Note: if status is "Error fetching status", it means job is dequed,
+		//       either finished or failed
+		return (rJob==null)?"Error fetching status":GramJob.getStatusAsString(rJob.getStatus());
+	}
+
+	// test main
+  public static void main(String[] args) {
+    try {
+    	org.cig.portal.util.Config myconfig=new org.cig.portal.util.Config();
+    	String rsl = SimpleRSL.getRSL_GT2(myconfig, "UC", 500, 20, "mydataset", "myoutput");
+		SimpleCred mycred=null;
+		GSSCredential proxy = null;
+		myconfig = new org.cig.portal.util.Config();
+		mycred = new SimpleCred(myconfig.get("grid.myproxy.server"), Integer.parseInt(myconfig.get("grid.myproxy.port")), myconfig.get("grid.myproxy.username"), "", myconfig.get("grid.myproxy.proxyfile"));
+		// assume proxy file specified is valid
+		proxy = mycred.get();
+
+	  SimpleRunGT2 sr = new SimpleRunGT2(proxy);
+      String jobId = sr.execute(myconfig.get("grid.gram."+"UC"), rsl);
+      System.out.println("Job submitted. ID: " + jobId);
+      String status;
+      do {
+          Thread.sleep(4000);
+          status = sr.getStatus(jobId);
+          System.out.println("Job Status: " + status);
+      } while (!status.equalsIgnoreCase("Error fetching status"));
+    } catch (Exception e) {
+      e.printStackTrace();
+    }
+
+  }
+}
+

Added: cs/cigtg/trunk/cigtg-dev/CigPortal/cigportal/src/org/cig/portal/grid/job/SimpleRunGT4.java
===================================================================
--- cs/cigtg/trunk/cigtg-dev/CigPortal/cigportal/src/org/cig/portal/grid/job/SimpleRunGT4.java	2007-08-10 02:13:13 UTC (rev 7799)
+++ cs/cigtg/trunk/cigtg-dev/CigPortal/cigportal/src/org/cig/portal/grid/job/SimpleRunGT4.java	2007-08-10 19:36:49 UTC (rev 7800)
@@ -0,0 +1,221 @@
+/**
+ *  Copyright (c) 2007 Computational Infrastructure for Geodynamics (CIG),
+ *  California Institute of Technology, All Rights Reserved.
+ */
+
+package org.cig.portal.grid.job;
+
+// Grid security
+import org.ietf.jgss.GSSException;
+import org.ietf.jgss.GSSCredential;
+
+import org.cig.portal.grid.security.*;
+
+// required by WS GRAM client
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileReader;
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.net.URL;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Vector;
+import java.security.cert.X509Certificate;
+import javax.xml.rpc.Stub;
+import javax.xml.soap.SOAPElement;
+import org.apache.axis.components.uuid.UUIDGenFactory;
+import org.apache.axis.message.addressing.AttributedURI;
+import org.apache.axis.message.addressing.EndpointReferenceType;
+import org.globus.delegation.DelegationUtil;
+import org.globus.exec.generated.CreateManagedJobInputType;
+import org.globus.exec.generated.CreateManagedJobOutputType;
+import org.globus.exec.generated.JobDescriptionType;
+import org.globus.exec.generated.ManagedJobFactoryPortType;
+import org.globus.exec.generated.ManagedJobPortType;
+import org.globus.exec.generated.ReleaseInputType;
+import org.globus.exec.utils.ManagedJobConstants;
+import org.globus.exec.utils.ManagedJobFactoryConstants;
+import org.globus.exec.utils.client.ManagedJobClientHelper;
+import org.globus.exec.utils.client.ManagedJobFactoryClientHelper;
+import org.globus.exec.utils.rsl.RSLHelper;
+import org.globus.wsrf.NotificationConsumerManager;
+import org.globus.wsrf.WSNConstants;
+import org.globus.wsrf.encoding.ObjectDeserializer;
+import org.globus.wsrf.impl.security.authentication.Constants;
+import org.globus.wsrf.impl.security.authorization.Authorization;
+import org.globus.wsrf.impl.security.authorization.HostAuthorization;
+import org.globus.wsrf.impl.security.authorization.IdentityAuthorization;
+import org.globus.wsrf.impl.security.authorization.SelfAuthorization;
+import org.globus.wsrf.impl.security.descriptor.ClientSecurityDescriptor;
+import org.globus.wsrf.impl.security.descriptor.GSISecureMsgAuthMethod;
+import org.globus.wsrf.impl.security.descriptor.GSITransportAuthMethod;
+import org.globus.wsrf.impl.security.descriptor.ResourceSecurityDescriptor;
+
+import org.oasis.wsn.Subscribe;
+import org.oasis.wsn.SubscribeResponse;
+import org.oasis.wsn.SubscriptionManager;
+import org.oasis.wsn.TopicExpressionType;
+import org.oasis.wsn.WSBaseNotificationServiceAddressingLocator;
+import org.oasis.wsrf.lifetime.Destroy;
+import org.oasis.wsrf.properties.GetMultipleResourceProperties_Element;
+import org.oasis.wsrf.properties.GetMultipleResourcePropertiesResponse;
+import org.oasis.wsrf.properties.GetResourcePropertyResponse;
+
+/*
+import java.io.File;
+import java.io.FileInputStream;
+import java.net.URL;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Vector;
+import java.security.cert.X509Certificate;
+import javax.xml.rpc.Stub;
+import javax.xml.soap.SOAPElement;
+import org.apache.axis.components.uuid.UUIDGenFactory;
+import org.apache.axis.message.addressing.AttributedURI;
+import org.apache.axis.message.addressing.EndpointReferenceType;
+import org.globus.delegation.DelegationUtil;
+import org.globus.exec.generated.CreateManagedJobInputType;
+import org.globus.exec.generated.CreateManagedJobOutputType;
+import org.globus.exec.generated.JobDescriptionType;
+import org.globus.exec.generated.ManagedJobFactoryPortType;
+import org.globus.exec.generated.ManagedJobPortType;
+import org.globus.exec.generated.ReleaseInputType;
+import org.globus.exec.utils.ManagedJobConstants;
+import org.globus.exec.utils.ManagedJobFactoryConstants;
+import org.globus.exec.utils.client.ManagedJobClientHelper;
+import org.globus.exec.utils.client.ManagedJobFactoryClientHelper;
+import org.globus.exec.utils.rsl.RSLHelper;
+import org.globus.wsrf.NotificationConsumerManager;
+import org.globus.wsrf.WSNConstants;
+import org.globus.wsrf.encoding.ObjectDeserializer;
+import org.globus.wsrf.impl.security.authentication.Constants;
+import org.globus.wsrf.impl.security.authorization.Authorization;
+import org.globus.wsrf.impl.security.authorization.HostAuthorization;
+import org.globus.wsrf.impl.security.authorization.IdentityAuthorization;
+import org.globus.wsrf.impl.security.authorization.SelfAuthorization;
+import org.globus.wsrf.impl.security.descriptor.ClientSecurityDescriptor;
+import org.globus.wsrf.impl.security.descriptor.GSISecureMsgAuthMethod;
+import org.globus.wsrf.impl.security.descriptor.GSITransportAuthMethod;
+import org.globus.wsrf.impl.security.descriptor.ResourceSecurityDescriptor;
+import org.gridforum.jgss.ExtendedGSSManager;
+import org.oasis.wsn.Subscribe;
+import org.oasis.wsn.SubscribeResponse;
+import org.oasis.wsn.SubscriptionManager;
+import org.oasis.wsn.TopicExpressionType;
+import org.oasis.wsn.WSBaseNotificationServiceAddressingLocator;
+import org.oasis.wsrf.lifetime.Destroy;
+import org.oasis.wsrf.properties.GetMultipleResourceProperties_Element;
+import org.oasis.wsrf.properties.GetMultipleResourcePropertiesResponse;
+import org.oasis.wsrf.properties.GetResourcePropertyResponse;
+*/
+public class SimpleRunGT4 {
+	protected GSSCredential proxy;
+
+	public SimpleRunGT4(GSSCredential cred) {
+		proxy = cred;
+	}
+	// run single job
+	// TODO: support multijob submission --> support job delegation
+	// argument "contact" non-use, just comply with SimpleRun interface
+	public String execute(String contact, String rsl) {
+		org.globus.exec.client.GramJob job = null;
+		try {
+			//JobDescriptionType jobDescription = RSLHelper.readRSL(rsl);
+			//System.err.println("Job's endpoint: "+jobDescription.getFactoryEndpoint().toString());
+			if (proxy.getRemainingLifetime() < SimpleCred.DEFAULT_MIN)
+				throw new Exception("proxy doesn't have enough lifetime to submit job");
+            //System.out.println("remaining time: "+cred.getRemainingLifetime());
+			job = new org.globus.exec.client.GramJob(rsl);
+			job.setCredentials(proxy);
+			// Since Endpoint has been specified in RSL, we don't care the 1st argument here
+			job.submit(null, true); // batch mode
+			System.out.println("Job submitted. RSL:\n"+rsl);
+			if (job.isRequested()) {
+				return job.getHandle();
+			} else {
+				throw new Exception("job submission failed");
+			}
+		} catch (Exception e) {
+            System.err.println(" General exception - SimpleRunGT4::execute():\n"+e.toString());
+            System.err.println(rsl);
+            e.printStackTrace();
+            return null;
+        }
+	}
+	public String execute2(String contact, String rsl) {
+		org.globus.exec.client.GramJob job = null;
+		try {
+			//JobDescriptionType jobDescription = RSLHelper.readRSL(rsl);
+			//System.err.println("Job's endpoint: "+jobDescription.getFactoryEndpoint().toString());
+			URL factoryUrl = ManagedJobFactoryClientHelper.getServiceURL(
+				    contact).getURL();
+			String factoryType
+				    = ManagedJobFactoryConstants.FACTORY_TYPE.PBS;
+			EndpointReferenceType factoryEndpoint
+				    = ManagedJobFactoryClientHelper.getFactoryEndpoint(factoryUrl, factoryType);
+			ManagedJobFactoryPortType factoryPort
+				    = ManagedJobFactoryClientHelper.getPort(factoryEndpoint);
+			
+			
+			if (proxy.getRemainingLifetime() < SimpleCred.DEFAULT_MIN)
+				return null;
+            //System.out.println("remaining time: "+cred.getRemainingLifetime());
+			job = new org.globus.exec.client.GramJob(rsl);
+			job.setCredentials(proxy);
+			// Since Endpoint has been specified in RSL, we don't care the 1st argument here
+			job.submit(factoryEndpoint, true); // batch mode
+
+			if (job.isRequested()) {
+				return job.getHandle();
+			} else {
+				return null; 
+			}
+		} catch (Exception e) {
+            System.err.println(" General exception - SimpleRunGT4::execute():\n"+e.toString());
+            System.err.println(rsl);
+            e.printStackTrace();
+            return null;
+        }
+	}
+    public String getStatus(String handle) {
+     	org.globus.exec.client.GramJob job = null;
+        try {
+            job = new org.globus.exec.client.GramJob("<job><executable>probeJob</executable></job>");
+            job.setCredentials(proxy);
+            job.setHandle(handle);
+            job.refreshStatus();
+            return job.getState().getValue();
+        } catch (Exception e) {
+            return null;
+        }
+    }
+	// test main
+    public static void main(String[] args) {
+      try {
+      	org.cig.portal.util.Config myconfig=new org.cig.portal.util.Config();
+      	String rsl = SimpleRSL.getRSL_GT4(myconfig, "UC", 500, 20, "mydataset", "myoutput");
+  		SimpleCred mycred=null;
+  		GSSCredential proxy = null;
+  		myconfig = new org.cig.portal.util.Config();
+  		mycred = new SimpleCred(myconfig.get("grid.myproxy.server"), Integer.parseInt(myconfig.get("grid.myproxy.port")), myconfig.get("grid.myproxy.username"), "", myconfig.get("grid.myproxy.proxyfile"));
+  		// assume proxy file specified is valid
+  		proxy = mycred.get();
+
+  	  SimpleRunGT4 sr = new SimpleRunGT4(proxy);
+        String jobId = sr.execute2(myconfig.get("grid.wsgram."+"UC"), rsl);
+        System.out.println("Job submitted. ID: " + jobId);
+        String status;
+        do {
+            Thread.sleep(4000);
+            status = sr.getStatus(jobId);
+            System.out.println("Job Status: " + status);
+        } while (!status.equalsIgnoreCase("Error fetching status") && status.equalsIgnoreCase("Done"));
+      } catch (Exception e) {
+        e.printStackTrace();
+      }
+
+    }
+}
+

Added: cs/cigtg/trunk/cigtg-dev/CigPortal/cigportal/src/org/cig/portal/grid/security/SimpleCred.java
===================================================================
--- cs/cigtg/trunk/cigtg-dev/CigPortal/cigportal/src/org/cig/portal/grid/security/SimpleCred.java	2007-08-10 02:13:13 UTC (rev 7799)
+++ cs/cigtg/trunk/cigtg-dev/CigPortal/cigportal/src/org/cig/portal/grid/security/SimpleCred.java	2007-08-10 19:36:49 UTC (rev 7800)
@@ -0,0 +1,309 @@
+/**
+ *  Copyright (c) 2007 Computational Infrastructure for Geodynamics (CIG),
+ *  California Institute of Technology, All Rights Reserved.
+ */
+
+package org.cig.portal.grid.security;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.FileInputStream;
+import java.io.OutputStream;
+import java.io.IOException;
+import java.security.PrivateKey;
+import java.security.GeneralSecurityException;
+import java.security.cert.X509Certificate;
+
+import org.globus.gsi.CertUtil;
+import org.globus.gsi.GSIConstants;
+import org.globus.gsi.GlobusCredential;
+import org.globus.gsi.GlobusCredentialException;
+import org.globus.gsi.OpenSSLKey;
+import org.globus.gsi.bc.BouncyCastleOpenSSLKey;
+import org.globus.gsi.bc.BouncyCastleCertProcessingFactory;
+import org.globus.gsi.gssapi.auth.IdentityAuthorization;
+import org.globus.gsi.gssapi.GlobusGSSCredentialImpl;
+import org.globus.util.Util;
+import org.globus.common.CoGProperties;
+import org.globus.common.Version;
+import org.globus.myproxy.CredentialInfo;
+import org.globus.myproxy.ChangePasswordParams;
+import org.globus.myproxy.DestroyParams;
+import org.globus.myproxy.InitParams;
+import org.globus.myproxy.GetParams;
+import org.globus.myproxy.InfoParams;
+import org.globus.myproxy.StoreParams;
+import org.globus.myproxy.MyProxyException;
+
+import org.gridforum.jgss.ExtendedGSSManager;
+import org.gridforum.jgss.ExtendedGSSCredential;
+
+import org.ietf.jgss.GSSCredential;
+import org.ietf.jgss.GSSManager;
+import org.ietf.jgss.GSSException;
+
+/**
+ * A simple grid proxy credential manager
+ * - Use anonymous init
+ * - return proxy
+ * - automatic renewal at new request (not for existing jobs)
+ * @author liuyan
+ * @author wei modified for CIG portal
+ */
+public class SimpleCred {
+	public static final int DEFAULT_LIFETIME = 12 * 3600;
+	public static final int DEFAULT_MIN = 3 * 3600;
+	String proxy_file; // this is a valid proxy file that exists already
+	String host;
+	int port;
+	int requested_lifetime;
+	String username;
+	String password;
+	GSSCredential proxy;
+	org.globus.myproxy.MyProxy myproxy;
+
+	/**
+	 * Constructor
+	 * @param server
+	 * @param p
+	 * @param user
+	 * @param passwd
+	 * @param fname
+	 * @throws Exception
+	 */
+	public SimpleCred(String server, int p, String user, String passwd, String fname) throws Exception {
+		host = server;
+		port = p;
+		proxy = null;
+		myproxy = null; 
+		username = user;
+		password = passwd;
+		proxy_file = fname;
+		requested_lifetime = SimpleCred.DEFAULT_LIFETIME;
+	}
+	/**
+	 * Load proxy from a valid proxy file
+	 * @param proxyFile
+	 */
+	public void load(String certFile) {
+		proxy = null;
+		try{
+			// not recommended by cog manual. listed here for illustration purpose
+			//GlobusCredential cred = new GlobusCredential(proxyFile);	        
+        	//GSSCredential gssCred = new GlobusGSSCredentialImpl(cred, GSSCredential.INITIATE_AND_ACCEPT);
+			//proxy = gssCred;
+        //} catch (GlobusCredentialException e1){
+       	// 	e1.printStackTrace();
+			File proxyFile = new File(certFile);
+			byte [] credData = new byte[(int)proxyFile.length()];
+			FileInputStream in = new FileInputStream(proxyFile);
+			in.read(credData);
+			in.close();
+			// create credential by loading from proxy file
+			ExtendedGSSManager manager = (ExtendedGSSManager)ExtendedGSSManager.getInstance();
+			proxy = manager.createCredential(credData,
+	  		                         ExtendedGSSCredential.IMPEXP_OPAQUE,
+	                                 GSSCredential.DEFAULT_LIFETIME,
+	                                 null, // use default mechanism - GSI
+	                                 GSSCredential.INITIATE_AND_ACCEPT);
+        } catch (GSSException e2) {
+        	e2.printStackTrace();           
+        } catch (IOException ioe) {
+        	ioe.printStackTrace();
+        }
+        if (!this.isValid())
+        	proxy = null;
+	}
+	/**
+	 * MyProxy logon with default lifetime request
+	 * @param user
+	 * @param passwd
+	 * @throws GSSException
+	 */
+	public void logon(String user, String passwd) throws GSSException {
+		this.logon(user, passwd, this.requested_lifetime);
+	}
+	/**
+	 * MyProxy logon
+	 * @param user user name on myproxy server
+	 * @param passwd password
+	 * @param lthours lifetime to request in seconds
+	 * @throws GSSException
+	 */
+	public void logon(String user, String passwd, int ltseconds) throws GSSException {
+		CertUtil.init();
+		username = user;
+		password = passwd;
+		requested_lifetime = ltseconds;
+		GetParams getRequest = new GetParams();
+		getRequest.setUserName(user);
+		getRequest.setPassphrase(passwd);
+		getRequest.setCredentialName(null); // anonymous logon
+		getRequest.setLifetime(requested_lifetime);
+		    
+		try {
+			if (myproxy == null) {
+				myproxy = new org.globus.myproxy.MyProxy(this.host, this.port);
+			}
+		    proxy = myproxy.get(null, getRequest);
+		    if (!this.isValid()) 
+		    	proxy = null;
+			System.out.println(this.info());
+		} catch(MyProxyException e) {
+		    proxy = null;
+		    e.printStackTrace();
+		}
+	}
+	/**
+	 * Save proxy into a proxy file
+	 * @param proxy_location
+	 * @return success or failure
+	 */
+	public boolean export(String proxy_location) {
+		try {
+			if (proxy_location != null) {
+			    // create a file
+			    File f = new File(proxy_location);
+			    if (!f.exists() || f.canWrite()) {
+				    OutputStream out = new FileOutputStream(proxy_location);
+					// set read only permissions
+					Util.setOwnerAccessOnly(proxy_location);
+					// write the contents
+					byte [] data = ((ExtendedGSSCredential)proxy).export(ExtendedGSSCredential.IMPEXP_OPAQUE);
+					out.write(data);
+				    out.close();
+			    }
+			}
+			return true;
+		} catch (IOException ioe) {
+			ioe.printStackTrace();
+			return false;
+		} catch(GSSException e) {
+		    e.printStackTrace();
+		    return false;
+		}
+	}
+	/**
+	 * Get a proxy
+	 * Load proxy file first; if not avail, use myproxy logon
+	 * @return a valid grid proxy or null
+	 */
+	public GSSCredential get() {
+		return this.get(false);
+	}
+	public GSSCredential get(boolean forceRetrieve) {
+		// destry current credential first
+		if (forceRetrieve && proxy != null) {
+			try {
+				proxy.dispose();
+			} catch (Exception e) {
+				e.printStackTrace();
+			}
+			proxy = null;
+		}
+		if (this.isValid())
+			return proxy;
+		try {
+			this.load(proxy_file);
+			if (proxy != null)
+				return proxy;
+			this.logon(username, password);
+			if (proxy != null)
+				return proxy;
+		} catch (Exception e) {
+			e.printStackTrace();
+		}
+		return null;
+	}
+	/**
+	 * Print grid proxy information
+	 * @return proxy information as a String
+	 */
+	public String info() {
+		if (!this.isValid())
+			return "";
+		String s = "";
+		s += "Subject: " + this.getDN() + "\n";
+		int t = this.getRemainingTime();
+		s += "Remaining lifetime: " + (t / 3600) + ":" + ((t % 3600) / 60) + ":" + (t % 60) + " ("+ t + " seconds)\n";
+		s += "MyProxy server: " + this.host + ":" + this.port + "\n";
+		s += "MyProxy user: " +this.username +"\n";
+		
+		return s;
+	}
+	/**
+	 * Get subject information of a proxy
+	 * @return Subject of the proxy as a String
+	 */
+	public String getDN() {
+		try {
+			return (this.isValid()?(proxy.getName().toString()):"");
+		} catch (GSSException e) {
+			return "";
+		}
+	}
+	/**
+	 * Test if current proxy is valid
+	 * @return true or false
+	 */
+	public boolean isValid() {
+		if (proxy == null) return false;
+		try {
+			// the min requirement for a globus job submission
+			return proxy.getRemainingLifetime() > SimpleCred.DEFAULT_MIN;
+		} catch (Exception e) {
+			return false;
+		}
+	}
+	/**
+	 * Get remaining time in seconds
+	 * @return
+	 */
+	public int getRemainingTime() {
+		if (proxy == null) return 0;
+		try {
+			return proxy.getRemainingLifetime();
+		} catch (GSSException e) {
+			return 0;
+		}
+	}
+	//TODO
+	public void destroy() {
+		
+	}
+
+	// bean set/get methods
+	public String getUsername() { return this.username; }
+	public String getPassword() { return this.password; }
+	public String getHost() { return this.host; }
+	public int getPort() { return this.port; }
+	public String getProxyFile() { return this.proxy_file; }
+	public void setUsername(String uname) { this.username = uname; }
+	public void setPassword(String pass) { this.password = pass; }
+	public void setHost(String h) { this.host = h; }
+	public void setPort(int p) { this.port = p; }
+	public void setProxyFile(String pf) { this.proxy_file = pf; }
+	public void setRemainingTime(int ltseconds) { this.requested_lifetime = ltseconds; }
+	
+	public static void main(String[] args) {
+		org.gisolve.demo.util.Config myconfig=null;
+		SimpleCred mycred=null;
+		try {
+			//String password = Util.getPrivateInput("Input password for user " + args[0]);
+			myconfig = new org.gisolve.demo.util.Config();
+			mycred = new SimpleCred(myconfig.get("grid.myproxy.server"), Integer.parseInt(myconfig.get("grid.myproxy.port")), myconfig.get("grid.myproxy.username"), "", myconfig.get("grid.myproxy.proxyfile"));
+		
+			GSSCredential proxy = mycred.get();
+			System.out.println(mycred.info());
+		} catch (Exception e) {
+			e.printStackTrace();
+		}
+		try {
+			mycred.logon("cigportl", ""); // feed correct password
+			System.out.println(mycred.info());
+		} catch (Exception e) {
+			e.printStackTrace();
+		}
+	}
+}
+

Added: cs/cigtg/trunk/cigtg-dev/CigPortal/cigportal/src/org/cig/portal/portlets/CigMagPortlet.java
===================================================================
--- cs/cigtg/trunk/cigtg-dev/CigPortal/cigportal/src/org/cig/portal/portlets/CigMagPortlet.java	2007-08-10 02:13:13 UTC (rev 7799)
+++ cs/cigtg/trunk/cigtg-dev/CigPortal/cigportal/src/org/cig/portal/portlets/CigMagPortlet.java	2007-08-10 19:36:49 UTC (rev 7800)
@@ -0,0 +1,585 @@
+/**
+ *  Copyright (c) 2007 Computational Infrastructure for Geodynamics (CIG),
+ *  California Institute of Technology, All Rights Reserved.
+ */
+
+package org.cig.portal.portlets;
+
+//JSR-168
+import javax.portlet.*;
+
+// GridSphere
+import org.gridsphere.services.core.user.User;
+import org.gridsphere.portlet.impl.SportletProperties;
+// velocity
+import org.apache.velocity.context.Context;
+//import org.apache.velocity.VelocityContext;
+import org.ogce.portlets.VelocityPortlet;
+
+import java.util.*;
+import java.io.*;
+import java.text.DateFormat;
+import org.ietf.jgss.GSSCredential;
+
+import org.cig.portal.beans.MagjobBean;
+import org.cig.portal.util.Config;
+import org.cig.portal.util.SimpleGridConstants;
+import org.cig.portal.util.MAGPortletConfig;
+import org.cig.portal.grid.data.SimpleTransferThread;
+import org.cig.portal.grid.job.*;
+import org.cig.portal.grid.security.*;
+import org.gisolve.demo.app.IDWVizThread;
+
+public class CigMagPortlet extends VelocityPortlet {
+    /* This method is called whenever porlet is loaded */
+    public void buildViewContext( RenderRequest req, RenderResponse res, Context aContext ) {
+    	try {
+        	this.fillTemplate(aContext, req, res, "");
+        	// debug
+    		this.getPortletContext().log("CigPortal: magAction::buildViewContext() called");
+    	} catch (Exception e) {
+    		this.getPortletContext().log("CigPortal: magAction::buildViewContext()\n" + e.toString());
+    	}
+    }
+	/* This method is called when user click "customizer" action */
+    public void buildEditContext( RenderRequest req, RenderResponse res, Context aContext ) {
+		buildViewContext(req, res, aContext);    	
+    }
+    /* This method is called when user click "help" action */
+    public void buildHelpContext( RenderRequest req, RenderResponse res, Context aContext ) {
+    	buildViewContext(req, res, aContext);    
+    }	
+    public void fillTemplate(Context aContext, PortletRequest req, PortletResponse res, String actionError) {
+		PortletSession mysession = req.getPortletSession(true);
+		User user = (User) req.getAttribute(SportletProperties.PORTLET_USER);
+		String uid = user.getUserID();
+		String error = "";
+    	try {
+    		// get config info about grid security
+			Config myconfig = (Config)mysession.getAttribute(SimpleGridConstants.SESSION_ATTR_CONFIG + uid, PortletSession.APPLICATION_SCOPE);
+			String mywebappname = myconfig.get("portal.webappname");
+			if (!isValidWebapp(mywebappname))
+				throw new PortletException("CigPortalMAGPortlet.fillTemplate(): "+mywebappname+" is not a valid name. Check your config file first.");
+			//TODO: object persistence
+			ArrayList joblist = (ArrayList)mysession.getAttribute(SimpleGridConstants.magJobList + uid, PortletSession.APPLICATION_SCOPE);
+			// workflow 
+			String cursid = (String)mysession.getAttribute(SimpleGridConstants.magJobSid + uid, PortletSession.APPLICATION_SCOPE);
+			String curPage = (String)mysession.getAttribute(SimpleGridConstants.magPage + uid, PortletSession.APPLICATION_SCOPE);
+			if (curPage.equals("Viz")) {
+				MagjobBean item = null;
+				int i;
+				int numviz = 0, numReady = 0;
+				for (i=0; i<joblist.size(); i++) {
+					item = (MagjobBean)joblist.get(i);
+					if (item.getId().equals(cursid)) {
+						numviz = item.getKnum();
+						for (int v=0; v<numviz; v++) {
+							// this job exists, check if result is there
+							String rfile = this.getPortletContext().getRealPath("storage/"+uid+"/Mag/images/" + cursid+"."+item.getK(v) + ".jpg");
+							File rF = new File(rfile);
+							if (rF.isFile()) 
+								numReady++;
+						}
+						if (numReady < numviz) {
+							error += "Visualization file not ready yet. Please wait for a while or click \"Next\" to refresh status\n";
+						}
+						break;
+					}
+				}
+				if (i<joblist.size() && numviz>0 && numReady==numviz) {
+					// set links
+					ArrayList<String> resultlink = new ArrayList<String>(numviz);
+					ArrayList<String> imagelink = new ArrayList<String>(numviz);
+					ArrayList<String> vizklist = new ArrayList<String>(numviz);
+					for (int v=0; v<numviz; v++) {
+						resultlink.add("/"+mywebappname+"/storage/"+uid+"/Mag/results/" + cursid+"."+item.getK(v) + ".dat");
+						imagelink.add("/"+mywebappname+"/storage/"+uid+"/Mag/images/" + cursid+"."+item.getK(v) + ".jpg");
+						vizklist.add(Integer.toString(item.getK(v)));
+					}
+					String rfile = this.getPortletContext().getRealPath("storage/"+uid+"/Mag/results/" + cursid+"."+item.getK(0) + ".dat");
+					String str_zrange = this.getZRange(rfile);
+					String[] minmax = str_zrange.split(",");
+					int zmax=0, zmin=0;
+					if (minmax.length == 2) {
+						zmin=Integer.parseInt(minmax[0]);
+						zmax=Integer.parseInt(minmax[1]);
+					}
+					String legendlink = "/"+mywebappname+"/images/vizlegend.jpg";
+					aContext.put("cigportal_mag_viz_zmax", zmax);
+					aContext.put("cigportal_mag_viz_zmin", zmin);
+					aContext.put("cigportal_mag_viz_legendlink", legendlink);
+					aContext.put("cigportal_mag_viz_resultlink", resultlink);
+					aContext.put("cigportal_mag_viz_imagelink", imagelink);
+					aContext.put("cigportal_mag_viz_klist", vizklist);
+					aContext.put("cigportal_mag_viz_dataset", item.getDataset());
+					aContext.put("cigportal_mag_viz_jobid", item.getId());
+					
+					aContext.put(SimpleGridConstants.errorInfo, actionError + error);
+					setTemplate(req, "Mag-1.vm");
+					return;
+				}
+			} 
+			aContext.put(SimpleGridConstants.MagJobList, joblist);
+			aContext.put(SimpleGridConstants.MagJobSid, cursid);
+			String statusinfo = (String)mysession.getAttribute("cigportal_mag_status_info" + uid, PortletSession.APPLICATION_SCOPE);
+			aContext.put("cigportal_mag_status_info", statusinfo);
+			ArrayList sites = this.getSiteList(myconfig);
+			aContext.put("cigportal_mag_site_list", sites);
+			String udir = this.getPortletContext().getRealPath("storage/"+uid+"/Mag/datasets");
+			File userMagDir = new File(udir);
+			if (!userMagDir.isDirectory()) throw new PortletException(udir+": Mag portlet: user Mag dataset dir is not a directory.");
+			String[] flist = userMagDir.list();
+			ArrayList<String> filelist = new ArrayList<String>(flist.length);
+			for (int i=0; i<flist.length; i++) {
+				filelist.add(flist[i]);
+			}
+			aContext.put("cigportal_mag_parm_datalist", filelist);
+			// render dataset view
+			String viewdataset = (String)mysession.getAttribute("cigportal_mag_viz_vieworig" + uid, PortletSession.APPLICATION_SCOPE);
+			if (viewdataset != null) {
+				aContext.put("cigportal_mag_viz_vieworig", viewdataset);
+				aContext.put("cigportal_mag_viz_datasetlink", "/"+mywebappname+"/storage/"+uid+"/Mag/datasets/"+viewdataset);
+				aContext.put("cigportal_mag_viz_datasetimagelink", "/"+mywebappname+"/storage/"+uid+"/Mag/images/"+viewdataset+".jpg");
+				mysession.setAttribute("cigportal_mag_viz_vieworig" + uid, null, PortletSession.APPLICATION_SCOPE); // reset
+			} else {
+				aContext.put("cigportal_mag_viz_vieworig", null);
+			}
+			setTemplate(req, "Mag-0.vm");
+		} catch (Exception e) {
+			error += "User portlet::fillTemplate() error\n"+e.toString()+"\n";
+			setTemplate(req, "Mag-0.vm");
+		}
+		// fille error info
+		aContext.put(SimpleGridConstants.errorInfo, actionError + error);
+	}
+    private boolean isValidWebapp(String mywebappname) {
+    	if (mywebappname == null)
+    		return false;
+    	return this.getPortletContext().getRealPath("thisshouldnotexist").indexOf(mywebappname+"/thisshouldnotexist") >= 0;
+    }
+    private ArrayList getSiteList(Config myconfig) {
+    	String str_sites = myconfig.get("grid.sites");
+		String[] sitelist = null;
+		if (str_sites != null) { 
+			sitelist = str_sites.split("\\s*,\\s*");
+			ArrayList<String> sitearray = new ArrayList<String>(sitelist.length);
+			for (int i=0; i<sitelist.length; i++)
+				sitearray.add(sitelist[i]);
+			return sitearray;
+		}
+		return null;
+    }
+    public void doMag_create( ActionRequest req, ActionResponse res, Context aContext ) throws Exception 
+    {
+        //clear error info
+    	String error = "";
+    	try {  		
+    		PortletSession mysession = req.getPortletSession(true);
+			User user = (User) req.getAttribute(SportletProperties.PORTLET_USER);
+			String uid = user.getUserID();
+			String str_klist = req.getParameter("cigportal_mag_parm_k");
+			if (str_klist == null || str_klist.equals(""))
+				throw new Exception("Please specify K-value");
+			String[] klist = str_klist.split("\\s*,\\s*");
+			int[] int_klist = new int[klist.length];
+			long timestamp = Calendar.getInstance().getTimeInMillis();
+			if (klist.length>11 || klist.length<=0)
+				throw new Exception ("Too many K values or K-value is not set");
+			else {
+				for (int i=0; i<klist.length; i++) 
+					int_klist[i] = Integer.parseInt(klist[i]);
+			}
+			// create a Mag job
+			ArrayList joblist = (ArrayList)mysession.getAttribute(SimpleGridConstants.MagJobList + uid, PortletSession.APPLICATION_SCOPE);
+			String jid = uid +".job."+ timestamp;
+			MagjobBean job = new MagjobBean(jid);
+			job.setDataset(req.getParameter("cigportal_mag_parm_dataset"));
+			job.setN(Integer.parseInt(req.getParameter("cigportal_mag_parm_r")));
+			job.setKList(int_klist);
+			job.setSite(req.getParameter("cigportal_mag_parm_site"));
+			job.setStatus("cigportal:New");
+			job.setGtVersion(req.getParameter("cigportal_mag_parm_globus"));
+			//job.setGtVersion("GT2");
+			joblist.add(job);
+
+			mysession.setAttribute(SimpleGridConstants.MagJobList + uid, joblist, PortletSession.APPLICATION_SCOPE);
+			mysession.setAttribute(SimpleGridConstants.MagJobSid + uid, jid, PortletSession.APPLICATION_SCOPE);
+			mysession.setAttribute(SimpleGridConstants.MagPage + uid, "Main", PortletSession.APPLICATION_SCOPE);
+			mysession.setAttribute("cigportal_mag_status_info" + uid, job.getDataset() + "(jobId="+job.getId()+"): Job is created. Clieck \"Next\" to transfer dataset to remote site", PortletSession.APPLICATION_SCOPE);
+    	}catch (Exception e) {
+			error += "GISolveMagAction::doMag_create: error\n"+e.toString()+"\nBe sure to select required parameters\n";
+		}
+    	this.fillTemplate(aContext, req, res, error);
+    }
+    public void doMag_return ( ActionRequest req, ActionResponse res, Context aContext ) throws Exception 
+    {
+        //clear error info
+    	String error = "";
+    	try {  		
+    		PortletSession mysession = req.getPortletSession(true);
+			User user = (User) req.getAttribute(SportletProperties.PORTLET_USER);
+			String uid = user.getUserID();
+			mysession.setAttribute(SimpleGridConstants.MagPage + uid, "Main", PortletSession.APPLICATION_SCOPE);
+    	}catch (Exception e) {
+			error += "GISolveMagAction::doMag_return: error\n"+e.toString()+"\n";
+		}
+    	this.fillTemplate(aContext, req, res, error);
+    }
+    public void doMag_view_dataset ( ActionRequest req, ActionResponse res, Context aContext ) throws Exception 
+    {
+        //clear error info
+    	String error = "";
+    	try {  		
+    		PortletSession mysession = req.getPortletSession(true);
+			User user = (User) req.getAttribute(SportletProperties.PORTLET_USER);
+			String uid = user.getUserID();
+			String viewdataset = req.getParameter("cigportal_mag_parm_dataset");
+			if (viewdataset.equals(""))	viewdataset = null;
+			mysession.setAttribute("cigportal_mag_viz_vieworig" + uid, viewdataset, PortletSession.APPLICATION_SCOPE);
+    	}catch (Exception e) {
+			error += "GISolveMagAction::doMag_view_dataset: error\n"+e.toString() + "\n";
+		}
+    	this.fillTemplate(aContext, req, res, error);
+    }
+    public void doMag_delete ( ActionRequest req, ActionResponse res, Context aContext ) throws PortletException {
+//    	clear error info
+    	String error = "";
+    	MagjobBean job = null;
+    	try {  		
+    		PortletSession mysession = req.getPortletSession(true);
+			User user = (User) req.getAttribute(SportletProperties.PORTLET_USER);
+			String uid = user.getUserID();
+			// get job id
+			String selectedjobid = req.getParameter("cigportal_mag_id");
+			if (selectedjobid != null) {
+				// find the job
+				ArrayList joblist = (ArrayList)mysession.getAttribute(SimpleGridConstants.MagJobList + uid, PortletSession.APPLICATION_SCOPE);
+				
+				int i; int size = joblist.size();
+				for (i=0; i<size; i++) {
+					job = (MagjobBean)joblist.get(i);
+					if (job.getId().equals(selectedjobid)) {
+						// this job exists, just delete it
+						String nextId = "";
+						if (size>1) {
+							nextId = ((MagjobBean)joblist.get((i+1) % size)).getId();
+						}
+						mysession.setAttribute(SimpleGridConstants.MagJobSid + uid, nextId, PortletSession.APPLICATION_SCOPE);
+						// delete
+						joblist.remove(i);
+						mysession.setAttribute("cigportal_mag_status_info" + uid, "", PortletSession.APPLICATION_SCOPE);
+						break;
+					}
+				}
+			}
+    	} catch (Exception e) {
+			error += "GISolveMagAction::doMag_delete: error\n"+e.toString() + "\n";
+			if (job != null) job.setStatus("Error");
+			//req.getPortletSession().setAttribute("cigportal_mag_status_info", e.toString(), PortletSession.APPLICATION_SCOPE);
+		}
+    	this.fillTemplate(aContext, req, res, error);
+    }
+    public void doMag_submit ( ActionRequest req, ActionResponse res, Context aContext ) throws PortletException {
+        //clear error info
+    	String error = "";
+    	MagjobBean job = null;
+    	try {  		
+    		PortletSession mysession = req.getPortletSession(true);
+			User user = (User) req.getAttribute(SportletProperties.PORTLET_USER);
+			String uid = user.getUserID();
+			// get job id
+			String selectedjobid = req.getParameter("cigportal_mag_id");
+			if (selectedjobid != null) {
+				// find the job
+				ArrayList joblist = (ArrayList)mysession.getAttribute(SimpleGridConstants.MagJobList + uid, PortletSession.APPLICATION_SCOPE);
+				
+				int i;
+				for (i=0; i<joblist.size(); i++) {
+					job = (MagjobBean)joblist.get(i);
+					if (job.getId().equals(selectedjobid)) {
+						// this job exists, check if result is there
+						break;
+					}
+				}
+				if (i < joblist.size()) {
+					mysession.setAttribute(SimpleGridConstants.MagJobSid + uid, job.getId(), PortletSession.APPLICATION_SCOPE);
+					String opstatus = "";
+					String sprefix = job.getDataset() + "(jobId="+job.getId()+"): ";
+					if (job.getStatus().equals("cigportal:New")) {
+						opstatus = this.goTransferDataset(mysession, uid, joblist, job);
+					} else if (job.getStatus().equals("cigportal:Dataset Transferred")) {
+						opstatus = goSubmit(mysession, uid, joblist, job);
+					} else if (job.getStatus().equals("cigportal:Job Submitted")) {
+						opstatus = goRefresh(mysession, uid, joblist, job);
+					} else if (job.getStatus().equals("cigportal:Job Done")) {
+						opstatus = goTransferResult(mysession, uid, joblist, job);
+					} else if (job.getStatus().equals("cigportal:Result Transferred")) { 
+						opstatus = goViz(mysession, uid, joblist, job);
+					} else if (job.getStatus().equals("cigportal:Image Created")) {
+						opstatus = goShowViz(mysession, uid, joblist, job);
+					}
+					mysession.setAttribute("cigportal_mag_status_info" + uid, sprefix+opstatus, PortletSession.APPLICATION_SCOPE);
+					//else throw new PortletException("Unknown job status for job " + selectedjobid + ": " +job.getStatus());
+				} else  throw new PortletException("Couldn't find this job: " + selectedjobid);
+			}
+    	}catch (Exception e) {
+			error += "GISolveMagAction::doMag_submit: error\n"+e.toString() + "\n";
+			if (job != null) job.setStatus("Error");
+			//req.getPortletSession().setAttribute("cigportal_mag_status_info", e.toString(), PortletSession.APPLICATION_SCOPE);
+		}
+    	this.fillTemplate(aContext, req, res, error);
+    }
+    public String goTransferDataset(PortletSession mysession, String uid, ArrayList joblist, MagjobBean job) throws Exception {
+		// get selected site
+		String selectedsite = job.getSite();
+		Config myconfig = (Config)mysession.getAttribute(SimpleGridConstants.SESSION_ATTR_CONFIG + uid, PortletSession.APPLICATION_SCOPE);
+		ArrayList sitelist = this.getSiteList(myconfig);
+		int j;
+		for (j=0; j<sitelist.size(); j++) {
+			if (sitelist.get(j).equals(selectedsite)) break;
+		}
+		if (j<sitelist.size()) {
+			SimpleTransferThread mytransfer = (SimpleTransferThread)mysession.getAttribute("cigportal_mag_ft_thread" + uid, PortletSession.APPLICATION_SCOPE);
+			if (mytransfer == null) {
+				// transfer dataset to remote site
+				String[] srcdataset = new String[1];
+				String[] dstdataset = new String[1];
+				srcdataset[0] = this.getPortletContext().getRealPath("storage/"+uid+"/Mag/datasets/" + job.getDataset());
+				dstdataset[0] =  myconfig.get("grid.sites.Magdir."+selectedsite) +"/datasets/"+ job.getDataset();
+				String host = myconfig.get("grid.gridftp."+selectedsite);
+				SimpleCred mycred = (SimpleCred)mysession.getAttribute(SimpleGridConstants.SESSION_ATTR_CRED + uid, PortletSession.APPLICATION_SCOPE);
+				GSSCredential proxy = mycred.get();
+				if (proxy == null) {
+					return "Grid proxy could not be loaded. Please go to home portlet to get a valid proxy";
+				}
+				mytransfer = new SimpleTransferThread(SimpleTransferThread.LOCALTOREMOTE, proxy, host, srcdataset, dstdataset, job.getId());
+				mytransfer.start();
+				mysession.setAttribute("cigportal_mag_ft_thread" + uid, mytransfer, PortletSession.APPLICATION_SCOPE);
+				//job.setStatus("cigportal:Dataset Transferring");
+				mysession.setAttribute(SimpleGridConstants.MagJobList + uid, joblist, PortletSession.APPLICATION_SCOPE);
+				return "Dataset is being transferred to remote site. Click \"Next\" to refresh the transfer status";
+			} else {
+				String curid = mytransfer.getOwnerId();
+				if (!curid.equals(job.getId())) {
+					return "Transfer thread is busy serving another your job:"+curid;
+				}
+				String mystatus = mytransfer.getStatus();
+				if (mystatus.equals("SUCCESS")) {
+					mysession.removeAttribute("cigportal_mag_ft_thread" + uid, PortletSession.APPLICATION_SCOPE);
+					job.setStatus("cigportal:Dataset Transferred");
+					mysession.setAttribute(SimpleGridConstants.MagJobList + uid, joblist, PortletSession.APPLICATION_SCOPE);
+					return "Dataset transferred. Click \"Next\" to submit the globus job. Note: click ONLY ONCE!";
+				} else if (mystatus.startsWith("error")) {
+					mysession.removeAttribute("cigportal_mag_ft_thread" + uid, PortletSession.APPLICATION_SCOPE);
+					throw new PortletException("Error in dataset transfer for job " + job.getId()+": "+ mystatus);
+				}
+				return "Dataset is being transferred to remote site. Click \"Next\" to refresh the transfer status";
+			}
+		} else throw new PortletException("The site index is not on the list for job: " + job.getId());
+    }
+    public String goSubmit(PortletSession mysession, String uid, ArrayList joblist, MagjobBean job) throws Exception {
+		// get selected site
+		String selectedsite = job.getSite();
+		Config myconfig = (Config)mysession.getAttribute(SimpleGridConstants.SESSION_ATTR_CONFIG + uid, PortletSession.APPLICATION_SCOPE);
+		ArrayList sitelist = this.getSiteList(myconfig);
+		int j;
+		for (j=0; j<sitelist.size(); j++) {
+			if (sitelist.get(j).equals(selectedsite)) break;
+		}
+		if (j<sitelist.size()) {
+			// compose a rsl
+			int numjob = job.getKnum();
+			for (int i=0; i<numjob; i++) {
+				String rsl = null;
+				if (job.getGtVersion().equals("GT4")) {
+					rsl = SimpleRSL.getRSL_GT4(myconfig, selectedsite, job.getN(), job.getK(i), job.getDataset(), job.getId());
+				} else {
+					rsl = SimpleRSL.getRSL_GT2(myconfig, selectedsite, job.getN(), job.getK(i), job.getDataset(), job.getId());
+				}
+				 
+				if (rsl != null) {
+					// job submission
+					SimpleCred mycred = (SimpleCred)mysession.getAttribute(SimpleGridConstants.SESSION_ATTR_CRED + uid, PortletSession.APPLICATION_SCOPE);
+					GSSCredential proxy = mycred.get();
+					String jhandle = null;
+					if (job.getGtVersion().equals("GT4")) {
+						SimpleRunGT4 myrun = new SimpleRunGT4(proxy);
+						jhandle = myrun.execute(myconfig.get("grid.wsgram."+selectedsite), rsl);
+					} else {
+						SimpleRunGT2 myrun = new SimpleRunGT2(proxy);
+						jhandle = myrun.execute(myconfig.get("grid.gram."+selectedsite), rsl);
+					}
+					if (jhandle != null) {
+						job.setHandle(i, jhandle);
+					} else throw new PortletException("Job submission failed for subjob "+i+". rsl: " + rsl);
+					System.out.println("Job submission:"+job.getGtVersion()+":"+i+":["+jhandle+"]");
+					System.out.println(rsl);
+				} else throw new PortletException("Failed to create a RSL in subjob: "+i+" for job " + job.getId());
+			}
+			job.setStatus("cigportal:Job Submitted");
+			//joblist.set(i, job);
+			mysession.setAttribute(SimpleGridConstants.MagJobList + uid, joblist, PortletSession.APPLICATION_SCOPE);
+		} else throw new PortletException("The site index is not on the list for job: " + job.getId());
+		return "Job has been submitted. Click \"Next\" to refresh job exection status";
+    }  
+    public String goRefresh ( PortletSession mysession, String uid, ArrayList joblist, MagjobBean job ) throws Exception {
+    	SimpleCred mycred = (SimpleCred)mysession.getAttribute(SimpleGridConstants.SESSION_ATTR_CRED + uid, PortletSession.APPLICATION_SCOPE);
+		GSSCredential proxy = mycred.get();
+		String[] handles = job.getHandleList();
+    	String allstatus = "";
+    	int numdone = 0;
+    	for (int i=0; i<handles.length; i++) {
+    		String status = "";
+    		if (job.getGtVersion().equals("GT4")) {
+    			SimpleRunGT4 myrun = new SimpleRunGT4(proxy);
+    			status = myrun.getStatus(handles[i]);
+    		} else {
+    			SimpleRunGT2 myrun = new SimpleRunGT2(proxy);
+    			status = myrun.getStatus(handles[i]);
+    		}
+    		if (status.equalsIgnoreCase("Error fetching status") || status.equalsIgnoreCase("DONE"))
+    			status = "DONE";
+    		allstatus += (i+1)+":"+status+" ";
+    		if (status.equals("DONE")) {
+    			numdone ++;
+    		}
+    	}
+		if (numdone == handles.length) {
+			job.setStatus("cigportal:Job Done");
+		}
+		mysession.setAttribute(SimpleGridConstants.MagJobList + uid, joblist, PortletSession.APPLICATION_SCOPE);
+		return "job status is: "+allstatus +(numdone == handles.length?"Click \"Next\" to transfer results back":"");
+    }
+    public String goTransferResult ( PortletSession mysession, String uid, ArrayList joblist, MagjobBean job ) throws Exception 
+    {
+    	// get selected site
+		String selectedsite = job.getSite();
+		Config myconfig = (Config)mysession.getAttribute(SimpleGridConstants.SESSION_ATTR_CONFIG + uid, PortletSession.APPLICATION_SCOPE);
+		ArrayList sitelist = this.getSiteList(myconfig);
+		int j;
+		for (j=0; j<sitelist.size(); j++) {
+			if (sitelist.get(j).equals(selectedsite)) break;
+		}
+		if (j<sitelist.size()) {
+			SimpleTransferThread mytransfer = (SimpleTransferThread)mysession.getAttribute("cigportal_mag_ft_thread" + uid, PortletSession.APPLICATION_SCOPE);
+			if (mytransfer == null) {
+				// transfer results to local
+				String[] localFileList = new String[job.getKnum()];
+				String[] remoteFileList = new String[job.getKnum()];
+				for (int i=0; i<job.getKnum(); i++) {
+					localFileList[i] = this.getPortletContext().getRealPath("storage/"+uid+"/Mag/results/" + job.getId()+"."+job.getK(i) + ".dat");
+					remoteFileList[i] =  myconfig.get("grid.sites.Magdir."+selectedsite) +"/results/"+ job.getId()+"."+job.getK(i) + ".dat";
+				}
+				String host = myconfig.get("grid.gridftp."+selectedsite);
+				SimpleCred mycred = (SimpleCred)mysession.getAttribute(SimpleGridConstants.SESSION_ATTR_CRED + uid, PortletSession.APPLICATION_SCOPE);
+				GSSCredential proxy = mycred.get();
+				if (proxy == null) {
+					return "Grid proxy could not be loaded. Please go to home portlet to get a valid proxy";
+				}
+				mytransfer = new SimpleTransferThread(SimpleTransferThread.REMOTETOLOCAL, proxy, host, localFileList, remoteFileList, job.getId());
+				mytransfer.start();
+				mysession.setAttribute("cigportal_mag_ft_thread" + uid, mytransfer, PortletSession.APPLICATION_SCOPE);
+				//job.setStatus("cigportal:Result Transferring");
+				//mysession.setAttribute(SimpleGridConstants.MagJobList + uid, joblist, PortletSession.APPLICATION_SCOPE);
+				//mysession.setAttribute(SimpleGridConstants.MagJobSid + uid, job.getId(), PortletSession.APPLICATION_SCOPE);
+				return "Results are being transferred from remote site. Click \"Next\" to refresh the transfer status";
+			} else {
+				String curid = mytransfer.getOwnerId();
+				if (!curid.equals(job.getId())) {
+					return "Transfer thread is busy serving another your job:"+curid;
+				}
+				String mystatus = mytransfer.getStatus();
+				if (mystatus.equals("SUCCESS")) {
+					mysession.removeAttribute("cigportal_mag_ft_thread" + uid, PortletSession.APPLICATION_SCOPE);
+					job.setStatus("cigportal:Result Transferred");
+					mysession.setAttribute(SimpleGridConstants.MagJobList + uid, joblist, PortletSession.APPLICATION_SCOPE);
+					return "Results transferred. Click \"Next\" to create visualization iamge";
+				} else if (mystatus.startsWith("error")) {
+					mysession.removeAttribute("cigportal_mag_ft_thread" + uid, PortletSession.APPLICATION_SCOPE);
+					throw new PortletException("Error in dataset transfer for job " + job.getId()+": "+mystatus);
+				}
+				return "results are being transferred from remote site. Click \"Next\" to refresh the transfer status";
+			}
+		} else throw new PortletException("Could not find selected site from site list for job "+job.getId());
+		
+    }
+    public String goViz( PortletSession mysession, String uid, ArrayList joblist, MagjobBean job ) throws Exception 
+    {
+    	IDWVizThread viz = (IDWVizThread)mysession.getAttribute("cigportal_mag_viz_thread" + uid, PortletSession.APPLICATION_SCOPE);
+    	if (viz == null) {
+    		int numviz = job.getKnum();
+    		String s1 =  this.getPortletContext().getRealPath("storage/bnd_poly.dat");
+    		String s2 =  this.getPortletContext().getRealPath("storage/bnd_uspolygon.dat");
+    		String[] s3 = new String[numviz];
+    		String[] s4 = new String[numviz];
+    		String[] s5 = new String[numviz];
+    		for (int i=0; i<numviz; i++) {
+	    		// set parameters
+	    		s3[i] =  this.getPortletContext().getRealPath("storage/"+uid+"/Mag/results/" + job.getId()+"."+job.getK(i) + ".dat");
+	    		s4[i] =  this.getPortletContext().getRealPath("storage/"+uid+"/Mag/results/" + job.getId()+"."+job.getK(i) + "_viz.dat");
+	    		s5[i] =  this.getPortletContext().getRealPath("storage/"+uid+"/Mag/images/" + job.getId()+"."+job.getK(i) + ".jpg");
+    		}
+    		viz = new IDWVizThread(s1, s2, s3, s4, s5, job.getId());
+    		viz.start();
+    		mysession.setAttribute("cigportal_mag_viz_thread" + uid, viz, PortletSession.APPLICATION_SCOPE);
+    		return "visualization image is being created. Click \"Next\" to refresh the status of visualization";
+    	} else {
+    		String curid = viz.getOwnerId();
+    		if (!curid.equals(job.getId())) {
+				return "Visualization thread is busy serving another your job:"+curid;
+			}
+			String mystatus = viz.getStatus();
+			if (mystatus.equals("SUCCESS")) {
+				mysession.removeAttribute("cigportal_mag_viz_thread" + uid, PortletSession.APPLICATION_SCOPE);
+				job.setStatus("cigportal:Image Created");
+				mysession.setAttribute(SimpleGridConstants.MagJobList + uid, joblist, PortletSession.APPLICATION_SCOPE);
+				return "visualization image has been created. Click \"Next\" to go to visualization page";
+			} else if (mystatus.startsWith("error")) {
+				mysession.removeAttribute("cigportal_mag_viz_thread" + uid, PortletSession.APPLICATION_SCOPE);
+				throw new PortletException("Error in visualization for job " + job.getId()+": "+mystatus);
+			}
+			return "visualization image is being created. Click \"Next\" to refresh the status of visualization";
+		}
+    }
+    public String goShowViz( PortletSession mysession, String uid, ArrayList joblist, MagjobBean job ) throws Exception 
+    {
+    	mysession.setAttribute(SimpleGridConstants.MagPage + uid, "Viz", PortletSession.APPLICATION_SCOPE);
+    	return "";
+    }
+    private String getZRange(String inFile) throws IOException {
+	    File inf = new File(inFile);
+	    int zmin=0, zmax=0;
+	    if (inf.isFile() && inf.canRead()) {
+	    	java.io.BufferedReader fr = new java.io.BufferedReader(new java.io.FileReader(inFile));
+	    	String aline;
+	    	while ((aline = fr.readLine()) != null) {
+    			if (aline.startsWith("HEADER=")) {
+    				String[] h_params = aline.substring(7).split("\\s+");
+    				zmin = (int)(Double.parseDouble(h_params[6]));
+    				zmax = (int)(Double.parseDouble(h_params[7]));
+    				break;
+	    		}
+	    	}
+	    	fr.close();
+	    	return new String(zmin+","+zmax);
+	    }		
+	    return "";
+    }
+    /**
+     * This is where we initialize in-memory storage for cigportal
+     */
+    public void doView(RenderRequest req, RenderResponse res) throws PortletException, java.io.IOException {
+    	//if (!GISolveConfig.isSetup(request)) GISolveConfig.init(request, response);
+    	PortletSession mysession = req.getPortletSession(true);
+    	User user = (User) req.getAttribute(SportletProperties.PORTLET_USER);
+		String uid = user.getUserID();
+		String storedSid = (String)mysession.getAttribute(SimpleGridConstants.SESSION_ATTR_ID + uid, PortletSession.APPLICATION_SCOPE);
+		if (storedSid == null || !storedSid.equals(mysession.getId())) {
+			storedSid = mysession.getId();
+			MagPortletConfig.init(req, this);
+			mysession.setAttribute(SimpleGridConstants.SESSION_ATTR_ID + uid, storedSid, PortletSession.APPLICATION_SCOPE);
+		}
+    	super.doView(req, res);
+    }
+}
+

Added: cs/cigtg/trunk/cigtg-dev/CigPortal/cigportal/src/org/cig/portal/portlets/UserPortlet.java
===================================================================
--- cs/cigtg/trunk/cigtg-dev/CigPortal/cigportal/src/org/cig/portal/portlets/UserPortlet.java	2007-08-10 02:13:13 UTC (rev 7799)
+++ cs/cigtg/trunk/cigtg-dev/CigPortal/cigportal/src/org/cig/portal/portlets/UserPortlet.java	2007-08-10 19:36:49 UTC (rev 7800)
@@ -0,0 +1,141 @@
+/**
+ *  Copyright (c) 2007 Computational Infrastructure for Geodynamics (CIG),
+ *  California Institute of Technology, All Rights Reserved.
+ */
+
+package org.cig.portal.portlets;
+
+// GridSphere Visual UI
+import java.text.DateFormat;
+import java.util.Date;
+
+import org.gridsphere.provider.portletui.beans.CheckBoxBean;
+import org.gridsphere.provider.portletui.beans.TextFieldBean;
+import org.gridsphere.provider.portletui.beans.TextBean;
+import org.gridsphere.provider.event.jsr.RenderFormEvent;
+import org.gridsphere.provider.event.jsr.ActionFormEvent;
+import org.gridsphere.provider.portlet.jsr.ActionPortlet;
+// JSR-168
+import javax.portlet.PortletConfig;
+import javax.portlet.PortletException;
+import javax.portlet.PortletSession;
+import javax.portlet.PortletRequest;
+import javax.portlet.ActionRequest;
+import javax.portlet.ActionResponse;
+import javax.portlet.RenderRequest;
+import javax.portlet.RenderResponse;
+// applications
+import org.gridsphere.services.core.user.User;
+import org.gridsphere.portlet.impl.SportletProperties;
+import org.cig.portal.util.*;
+import org.cig.portal.grid.security.SimpleCred;
+import org.cig.portal.beans.*;
+
+//others
+
+public class UserPortlet extends ActionPortlet {
+	
+	public void init(PortletConfig config) throws PortletException {
+        super.init(config);
+        DEFAULT_VIEW_PAGE = "show";
+    }
+	
+    /**
+     * This is where we initialize in-memory storage for gisolve
+     */
+    public void doView(RenderRequest req, RenderResponse res) throws PortletException, java.io.IOException {
+    	//if (!GISolveConfig.isSetup(request)) GISolveConfig.init(request, response);
+    	PortletSession mysession = req.getPortletSession(true);
+    	User user = (User) req.getAttribute(SportletProperties.PORTLET_USER);
+		String uid = user.getUserID();
+		String storedSid = (String)mysession.getAttribute(SimpleGridConstants.SESSION_ATTR_ID + uid, PortletSession.APPLICATION_SCOPE);
+		if (storedSid == null || !storedSid.equals(mysession.getId())) {
+			storedSid = mysession.getId();
+			MAGPortletConfig.init(req, this);
+			mysession.setAttribute(SimpleGridConstants.SESSION_ATTR_ID + uid, storedSid, PortletSession.APPLICATION_SCOPE);
+		}
+    	super.doView(req, res);
+    }
+	/**
+	 * Rendering method
+	 * @param event
+	 * @throws PortletException
+	 */
+	public void show(RenderFormEvent event) throws PortletException {
+		PortletRequest req = event.getRenderRequest();
+		PortletSession mysession = req.getPortletSession(true);
+		User user = (User) req.getAttribute(SportletProperties.PORTLET_USER);
+		String uid = user.getUserID();
+		// render user information
+		UserBean userbean = new UserBean();
+		userbean.setLastLoginTime(DateFormat.getDateTimeInstance().format(new Date(user.getLastLoginTime())));
+		userbean.setFirstName(user.getFirstName());
+		userbean.setLastName(user.getLastName());
+		userbean.setEmailAddress(user.getEmailAddress());
+		userbean.setOrganization(user.getOrganization());
+		userbean.setNumLogins(user.getNumLogins());
+		req.setAttribute("user", userbean);
+		// initialize grid security context
+		SimpleCred mycred=(SimpleCred)mysession.getAttribute(SimpleGridConstants.SESSION_ATTR_CRED + uid, PortletSession.APPLICATION_SCOPE);
+		req.setAttribute("simplecred", mycred);
+		// render the page
+		this.setNextState(req, "simplegrid_user.jsp");
+	}
+	/**
+	 * Action method: save SimpleCred configuration
+	 * @param event
+	 * @throws PortletException
+	 */
+	public void configSimpleCred(ActionFormEvent event) throws PortletException {
+		ActionRequest req = event.getActionRequest();
+		ActionResponse res = event.getActionResponse();
+		// get user input
+		String host = event.getTextFieldBean("simplecred_host").getValue();
+		int port = Integer.parseInt(event.getTextFieldBean("simplecred_port").getValue());
+		String username = event.getTextFieldBean("simplecred_username").getValue();
+		String password = event.getTextFieldBean("simplecred_password").getValue();
+		int ltseconds = Integer.parseInt(event.getTextFieldBean("simplecred_lifetime").getValue()) * 3600;
+		String str_proxyfile = event.getTextFieldBean("simplecred_proxy_file").getValue();
+		String proxyfile;
+		if (!str_proxyfile.equals("") && str_proxyfile.startsWith("/")) {
+			proxyfile = str_proxyfile;
+		} else {
+			proxyfile = this.getPortletContext().getRealPath(str_proxyfile);
+		}
+		// save SimpleCred config
+		PortletSession mysession = req.getPortletSession(true);
+		User user = (User) req.getAttribute(SportletProperties.PORTLET_USER);
+		String uid = user.getUserID();
+		SimpleCred mycred = (SimpleCred)mysession.getAttribute(SimpleGridConstants.SESSION_ATTR_CRED + uid, PortletSession.APPLICATION_SCOPE);
+		try {
+			if (mycred == null) {
+				mycred = new SimpleCred(host, port, username, password, proxyfile);
+				mycred.setRemainingTime((ltseconds<SimpleCred.DEFAULT_MIN)?SimpleCred.DEFAULT_LIFETIME:ltseconds);
+			} else {
+				mycred.setHost(host);
+				mycred.setPort(port);
+				mycred.setUsername(username);
+				mycred.setPassword(password);
+				mycred.setProxyFile(proxyfile);
+				mycred.setRemainingTime((ltseconds<SimpleCred.DEFAULT_MIN)?SimpleCred.DEFAULT_LIFETIME:ltseconds);
+			}
+		} catch (Exception e) {
+			throw new PortletException("Error saving SimpleGrid grid credentials", e);
+		}
+		// get proxy if asked
+		boolean getNow = event.getCheckBoxBean("simplecred_getnow").isSelected();
+		//boolean getNow = Boolean.parseBoolean(str_getnow);
+		if (getNow) {
+			try {
+				mycred.get(true); // force to reload proxy
+			} catch (Exception e) {
+				throw new PortletException("Error getting grid credentials from "+host+" for "+username, e);
+			}
+		}
+		// save the change
+		mysession.setAttribute(SimpleGridConstants.SESSION_ATTR_CRED + uid, mycred, PortletSession.APPLICATION_SCOPE);
+		// go to rendering method
+		this.setNextState(req, DEFAULT_VIEW_PAGE);
+	}
+}
+

Added: cs/cigtg/trunk/cigtg-dev/CigPortal/cigportal/src/org/cig/portal/util/Config.java
===================================================================
--- cs/cigtg/trunk/cigtg-dev/CigPortal/cigportal/src/org/cig/portal/util/Config.java	2007-08-10 02:13:13 UTC (rev 7799)
+++ cs/cigtg/trunk/cigtg-dev/CigPortal/cigportal/src/org/cig/portal/util/Config.java	2007-08-10 19:36:49 UTC (rev 7800)
@@ -0,0 +1,66 @@
+/**
+ *  Copyright (c) 2007 Computational Infrastructure for Geodynamics (CIG),
+ *  California Institute of Technology, All Rights Reserved.
+ */
+
+/**
+ * Class: Config
+ * @author Yan Liu
+ * @version %I% %G%
+ */
+package org.cig.portal.util;
+
+import java.util.Properties;
+import java.io.File;
+
+public class Config {
+	private String conf_file;
+	private Properties conf;
+	public Config() throws java.io.IOException {
+		String home_dir = System.getenv("HOME"); 
+		conf_file = home_dir + File.separator + "cigportal.properties";
+		loadConfig();
+	}
+	public Config(String conf) throws java.io.IOException {
+		conf_file = conf;
+		loadConfig();
+	}
+	private void loadConfig() throws java.io.IOException {
+		File f = new File(conf_file);
+		conf = null;
+  		if (f.exists() && f.isFile() && f.canRead()) {
+			conf = new Properties();
+   			conf.load(new java.io.FileInputStream(conf_file));
+   		} else {
+   			throw new java.io.IOException("Error loading CigPortal configuration: " + conf_file);
+   		}
+	}
+	/**
+	 * This method reads a config item value
+	 * @param name the key of a config item
+	 * @return the value of a config item
+	 */
+	public String get(String name) {
+		return conf.getProperty(name, null);
+	}
+	/**
+	 * This method sets/overrides a config item
+	 * @param name the key of a config item
+	 * @param value the value of a config item
+	 */
+	public void set(String name, String value) {
+		conf.setProperty(name, value);
+	}
+	
+	public void print() {
+		conf.list(System.out);
+	}
+	/**
+	 * The main() for test purpose
+	 */
+	public static void main(String[] args) throws Exception {
+		Config myconfig = new Config();
+		myconfig.print();
+	}
+}
+

Added: cs/cigtg/trunk/cigtg-dev/CigPortal/cigportal/src/org/cig/portal/util/MAGPortletConfig.java
===================================================================
--- cs/cigtg/trunk/cigtg-dev/CigPortal/cigportal/src/org/cig/portal/util/MAGPortletConfig.java	2007-08-10 02:13:13 UTC (rev 7799)
+++ cs/cigtg/trunk/cigtg-dev/CigPortal/cigportal/src/org/cig/portal/util/MAGPortletConfig.java	2007-08-10 19:36:49 UTC (rev 7800)
@@ -0,0 +1,111 @@
+/**
+ *  Copyright (c) 2007 Computational Infrastructure for Geodynamics (CIG),
+ *  California Institute of Technology, All Rights Reserved.
+ */
+
+package org.cig.portal.util;
+//JSR-168
+import javax.portlet.PortletRequest;
+import javax.portlet.RenderRequest;
+import javax.portlet.RenderResponse;
+import javax.portlet.PortletException;
+import javax.portlet.PortletSession;
+import javax.portlet.GenericPortlet;
+// gridsphere
+import org.gridsphere.services.core.user.User;
+import org.gridsphere.portlet.impl.SportletProperties;
+//cigportal
+import org.cig.portal.util.Config;
+import org.cig.portal.util.SimpleGridConstants;
+import org.cig.portal.beans.MagjobBean;
+import org.cig.portal.grid.security.SimpleCred;
+
+import java.util.ArrayList;
+import java.io.*;
+
+public class MAGPortletConfig {
+	// use this variable to test if config has been done
+	static String websessionid = null;
+	public static void init(RenderRequest req, GenericPortlet portlet) throws PortletException {	
+		try {
+			websessionid = null;
+			PortletSession mysession = req.getPortletSession(true);
+			User user = (User) req.getAttribute(SportletProperties.PORTLET_USER);
+			String uid = user.getUserID();
+			//it is my responsibility to load portal configuration
+			Config config = (Config)mysession.getAttribute(SimpleGridConstants.SESSION_ATTR_CONFIG + uid, PortletSession.APPLICATION_SCOPE);
+			if (config == null) {
+				String configPath = "";
+				try {
+					configPath = portlet.getPortletContext().getRealPath("cigportal.properties");
+					config = new Config(configPath);
+					mysession.setAttribute(SimpleGridConstants.SESSION_ATTR_CONFIG + uid, config, PortletSession.APPLICATION_SCOPE);
+				} catch (java.io.IOException ioe) {
+					throw new PortletException("Error loading SimpleGrid configuration file "+configPath, ioe);
+				}
+			}
+			// initialize grid security context
+			SimpleCred mycred=(SimpleCred)mysession.getAttribute(SimpleGridConstants.SESSION_ATTR_CRED + uid, PortletSession.APPLICATION_SCOPE);
+			if (mycred == null) {
+				try {
+					String server = config.get("grid.myproxy.server");
+					int port = Integer.parseInt(config.get("grid.myproxy.port"));
+					String uname = config.get("grid.myproxy.username");
+					String proxyfile = config.get("grid.myproxy.proxyfile");
+					mycred = new SimpleCred(server, port, uname, "", proxyfile);
+					//this information is shared by all portlet in this portlet session and is user-specific
+					mysession.setAttribute(SimpleGridConstants.SESSION_ATTR_CRED + uid, mycred, PortletSession.APPLICATION_SCOPE);
+				} catch (Exception e) {
+					throw new PortletException("Error initializing SimpleGrid grid credentials", e);
+				}
+			}
+			// set initial error information
+			mysession.setAttribute(SimpleGridConstants.errorInfo + uid, "", PortletSession.APPLICATION_SCOPE);
+			// mag portlet: mag job list
+			ArrayList joblist = (ArrayList)mysession.getAttribute(SimpleGridConstants.magJobList + uid, PortletSession.APPLICATION_SCOPE);
+			if (joblist == null) {
+				joblist = new ArrayList<DmsjobBean>();
+				mysession.setAttribute(SimpleGridConstants.magJobList + uid, joblist, PortletSession.APPLICATION_SCOPE);
+			}
+			// mag portlet: current page name
+			String curPage = (String)mysession.getAttribute(SimpleGridConstants.magPage + uid, PortletSession.APPLICATION_SCOPE);
+			if (curPage == null) {
+				curPage = new String("Main");
+				mysession.setAttribute(SimpleGridConstants.magPage + uid, curPage, PortletSession.APPLICATION_SCOPE);
+			}
+			// create user directories
+			String dataRoot = mysession.getPortletContext().getRealPath("storage");
+			try {
+				File datasetDir = new File(dataRoot+File.separator+uid+File.separator+"mag"+File.separator+"datasets");
+				if (!datasetDir.exists()) datasetDir.mkdirs();
+				File resultsDir = new File(dataRoot+File.separator+uid+File.separator+"mag"+File.separator+"results");
+				if (!resultsDir.exists()) resultsDir.mkdirs();
+				File imagesDir = new File(dataRoot+File.separator+uid+File.separator+"mag"+File.separator+"images");
+				if (!imagesDir.exists()) imagesDir.mkdirs();
+			} catch (SecurityException ioe) {
+				System.out.println("MAGConfig::init(): error creating user directories for " + uid);
+				ioe.printStackTrace();
+			}
+			//generate a unique id for this session. it's used to indicate MAGConfig is done
+			websessionid = mysession.getId();
+			System.out.println("MAG application is initialized for user " + uid);
+		} catch (Exception e) {
+			websessionid = null;
+			throw new PortletException("MAGConfig::init(): Error:\n" + e.toString());
+		}
+	}
+	// Test if configuration is loaded for this session
+	public static boolean isSetup(PortletRequest req) {
+		try {
+			PortletSession mysession = req.getPortletSession();
+			if (websessionid != null && mysession.getId().equals(websessionid)) {
+				return true;
+			} else {
+				return false;
+			}
+		} catch (Exception e) {
+			return false;
+		}
+	}
+}
+

Added: cs/cigtg/trunk/cigtg-dev/CigPortal/cigportal/src/org/cig/portal/util/SimpleGridConstants.java
===================================================================
--- cs/cigtg/trunk/cigtg-dev/CigPortal/cigportal/src/org/cig/portal/util/SimpleGridConstants.java	2007-08-10 02:13:13 UTC (rev 7799)
+++ cs/cigtg/trunk/cigtg-dev/CigPortal/cigportal/src/org/cig/portal/util/SimpleGridConstants.java	2007-08-10 19:36:49 UTC (rev 7800)
@@ -0,0 +1,38 @@
+/**
+ *  Copyright (c) 2007 Computational Infrastructure for Geodynamics (CIG),
+ *  California Institute of Technology, All Rights Reserved.
+ */
+
+package org.cig.portal.util;
+
+public class SimpleGridConstants {
+	public final static String SESSION_ATTR_ID = "simplegrid_session_id";
+	public final static String SESSION_ATTR_CRED = "simplegrid_session_simplecred";
+	public final static String SESSION_ATTR_CONFIG = "simplegrid_session_config";
+	
+	public final static String errorInfo = "cig_portal_error_info";
+	
+	// mag portlet attributes
+	public final static String magJobList = "cig_mag_job_list";
+	public final static String magJobSid = "cig_mag_cur_sid";
+	public final static String magPage = "cig_mag_cur_page";
+	public final static String magResultLink = "cig_mag_viz_resultlink";
+	public final static String magImageLink = "cig_mag_viz_imagelink";
+	public final static String magDatasetLink = "cig_mag_viz_datasetlink";
+	public final static String magDatasetImageLink = "cig_mag_viz_datasetimagelink";
+	public final static String magStatusInfo = "cig_mag_status_info";
+	public final static String magSiteList = "cig_mag_site_list";
+	public final static String magParmDatasetList = "cig_mag_parm_datalist";
+	
+	// input parameters
+	public static final String magParamDataset = "cig_mag_parm_dataset";
+	public static final String magParamK = "cig_mag_parm_k";
+	public static final String magParamR = "cig_mag_parm_r";
+	public static final String magParamSite = "cig_mag_parm_site";
+	
+	public static final String magId = "cig_mag_id";
+	
+	// service instance names
+	public static final String gridFtpService = "cig_mag_ft_thread";
+	public static final String magVizService = "cig_mag_viz_thread";
+}



More information about the cig-commits mailing list