天天看點

Grid Application Development: e-Science Application using GT-4 and Web Services (2)

執行個體研究

網格計算為我們提供了超級的計算能力,但是到底什麼樣的應用将需要用到網格的能力呢?就目前來說e-Science應用是一個十分合适的候選者。在文章的這一部分,我将引入這樣一個執行個體(分布式腎髒分析模型系統)來說明網格的實際應用領域。該系統的需求不算複雜,醫學科研人員需要通過該系統對人體腎髒進行分析,他們可以提供不同的邊界條件和執行個體參數,也可以選擇不同的分析模型。當他們決定好參數之後,所有的分析将在遠端計算機上的模型上展開直到所有的結果傳回給用戶端程式并以3D虛拟模型的形式展現在這些科學家的計算機上。系統将為使用者提供完善的基于Web的界面,并且一旦使用者登陸他将可以使用所有的分析模型來進行分析。回顧這些需求,我們發現背景分析過程是可以發揮網格優勢的地方,另外不同的模型可能位于世界各地不同的伺服器上,它們可能有不同的通路和管理政策,這些又必須完全對使用者透明,是以網格的Single Sign-On安全機制将極大的友善使用者權限的管理。

Grid Application Development: e-Science Application using GT-4 and Web Services (2)

圖1:系統體系結構圖

在系統體系結構圖中,使用者通過系統提供的門戶與系統互動,VO(Virtual Organization)将管理使用者憑證和Single Sign On, Gridbus Broker将用于使用者任務的管理和不同分析模型的通訊,Visualization軟體包将把文本分析結果以3D模型的形式展現給使用者。 這種體系結構是大多數e-Science應用都采用的基本架構,不管隻局限于本系統。VO服務實際上就是使用者群組織管理服務,GT-4的安全基礎服務将為我們提供這些基本的安全機制。是以我們首先需要做的是将各種分析模型整合在一起并能夠将其釋出為一個網格服務供Gridbus Broker(參見文章第一部分)來調用。由于醫學模型分析都是一些數值分析程式,很多都是用Fortune等語言來程式設計的,我們的第一步就是要使用Java來建立這些遺留程式的包裝程式,然後再利用GT-4和WSRF來開發網格服務。

整合遺留程式

首先我們來看看如何整合遺留程式,因為我們的第一個分析模型KSim來自法國,它使用的是Fortune語言,該分析程式是一個可執行檔案,它接受一個文本檔案parfile.txt作為輸入,使用者可以在該檔案中提供所有的程式所需要的參數然後運作此程式。程式的輸出是一個XML文檔,包含了所有的分析結果。在我們将它釋出成GT-4網格服務之前,我們需要使用Java将該程式包裝成Java程式,然後我們可以使用GT-4的Java WS Core來進行網格的開發。

public final class KSimExecutor implements Runnable{

       private KSimResource resource = null;

       private String executor = null;

       public KSimExecutor(KSimResource resource) throws Exception{

              this(resource, System.getenv().get("KSIM_EXECUTOR"));

       }    

       public KSimExecutor(KSimResource resource, String executor) throws Exception{

              this.resource = resource;

              this.executor = executor;

              prepare();

       }

       public void run(){

              int procCode = execute();

              if(procCode == 0){

                     resource.setStatus(KSimConstant.Status.SUCCESS);

              }else{

                     resource.setStatus(KSimConstant.Status.FAIL);

              }

       }

       private int execute(){

              try{

                     //create the process using the ksim executable program

                     Runtime runtime = Runtime.getRuntime();

                     Process proc = runtime.exec(executor);

                     //execute the process and return the outcome 0 stands for success

                     return proc.waitFor();

              }catch(Exception e){

                     return -1;

              }

       }

       private void prepare() throws Exception{

              FileWriter writer = null;

              try{

                     File parfile = new File("parfile.txt");

                     File saveDir = new File("save");

                     if(!saveDir.exists()){

                            if(!saveDir.mkdir()){

                                   throw new Exception("Failed to create save directory");

                            }

                     }

                     String output = resource.getOutput();

                     File outputFile = new File(output);

                     if(outputFile.exists()){

                            //clear the current file and create a new output file

                            outputFile.delete();

                            outputFile.createNewFile();

                     }

                     //construct the parfile.txt file

                     writer = new FileWriter(parfile);

                     writer.write(" "+resource.getInput()+"/n");

                     writer.write(" "+output+"/n");

                     writer.write(" "+resource.getSolute()+"/n");

                     writer.write(" "+resource.getTube()+"/n");

                     writer.write(" "+resource.getRegion()+"/n");

                     writer.write(" "+parseFactor(resource.getFactor())+"/n");

                     writer.flush();

                     writer.close();

              }catch(IOException e){

                     if(writer != null){

                            try{

                                   writer.close();

                            }catch(Exception uE){}

                     }

                     throw new Exception("Failed to create the required parfile.txt”,e);

              }

       }

       private String parseFactor(int factor) throws Exception{

              if(factor < -100 || factor > 100 ){

                     throw new Exception("Factor exceeds the acceptance range.");

              }

              String suffix = null;

              String prefix = null;

              if(factor < 0){

                     suffix = "e0";

                     prefix = new Float(1 - (float)factor / 100).toString();

              }else{

                     suffix = "d0";

                     prefix = new Float(1+ (float)factor / 100).toString();

              }

              return prefix+suffix;

       }    

}

KSimExecutor包裝程式實作了Runnable接口目的是可以讓它在獨立的線程中運作,因為分析程式需要運作一段時間,我們不想浪費資源等待它的執行。我們的包裝程式首先将分析輸入的資料KSimResource, 将所有所需的參數動态建立parfile.txt檔案和save目錄。在execute方法中,我們将建立一個Runtime類,它将利用系統環境變量中讀取KSim可執行檔案的絕對路徑建立一個系統程序,并執行該程序。run方法簡單的調用execute方法并記錄其結果。通過這個包裝程式,我們就可以在其他Java程式中使用我們的KSim分析模型了。我們可以開始進入GT-4網格服務的開發階段。

總結

文章的這一部分我們簡單的讨論了我們将要實作的系統的需求和體系結構,該體系結構可以作為對e-Science應用一個通用的解決方案。另外我們還使用Java對我們的第一個Fortune語言編寫的分析模型KSim進行了包裝,以便其他的Java程式使用。文章的下一部分,我們将開始GT-4網格服務的開發。

Copyright Reserved by Xingchen Chu,Research Programmer,GRIDS laboratory,Department of Computer Science and Software Engineering,The University of Melbourne.

email: [email protected]

work: +61 3 8344 1335

繼續閱讀