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

来源:互联网 发布:机器人路径 d算法 编辑:程序博客网 时间:2024/06/05 17:48

实例研究

网格计算为我们提供了超级的计算能力,但是到底什么样的应用将需要用到网格的能力呢?就目前来说e-Science应用是一个十分合适的候选者。在文章的这一部分,我将引入这样一个实例(分布式肾脏分析模型系统)来说明网格的实际应用领域。该系统的需求不算复杂,医学科研人员需要通过该系统对人体肾脏进行分析,他们可以提供不同的边界条件和实例参数,也可以选择不同的分析模型。当他们决定好参数之后,所有的分析将在远程计算机上的模型上展开直到所有的结果返回给客户端程序并以3D虚拟模型的形式展现在这些科学家的计算机上。系统将为用户提供完善的基于Web的界面,并且一旦用户登陆他将可以使用所有的分析模型来进行分析。回顾这些需求,我们发现后台分析过程是可以发挥网格优势的地方,另外不同的模型可能位于世界各地不同的服务器上,它们可能有不同的访问和管理政策,这些又必须完全对用户透明,所以网格的Single Sign-On安全机制将极大的方便用户权限的管理。

1:系统体系结构图

在系统体系结构图中,用户通过系统提供的门户与系统交互,VOVirtual Organization)将管理用户凭证和Single Sign On, Gridbus Broker将用于用户任务的管理和不同分析模型的通讯,Visualization软件包将把文本分析结果以3D模型的形式展现给用户。 这种体系结构是大多数e-Science应用都采用的基本架构,不管只局限于本系统。VO服务实际上就是用户和组织管理服务,GT-4的安全基础服务将为我们提供这些基本的安全机制。所以我们首先需要做的是将各种分析模型整合在一起并能够将其发布为一个网格服务供Gridbus Broker(参见文章第一部分)来调用。由于医学模型分析都是一些数值分析程序,很多都是用Fortune等语言来编程的,我们的第一步就是要使用Java来创建这些遗留程序的包装程序,然后再利用GT-4WSRF来开发网格服务。

整合遗留程序

首先我们来看看如何整合遗留程序,因为我们的第一个分析模型KSim来自法国,它使用的是Fortune语言,该分析程序是一个可执行文件,它接受一个文本文件parfile.txt作为输入,用户可以在该文件中提供所有的程序所需要的参数然后运行此程序。程序的输出是一个XML文档,包含了所有的分析结果。在我们将它发布成GT-4网格服务之前,我们需要使用Java将该程序包装成Java程序,然后我们可以使用GT-4Java 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);

              }

       }

       /**

        * execute the fortune program for the Ksim

        *

        * @return

        */

       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;

              }

       }

       /**

        * <code> createParfile </code> reads in the parameters from KSimResource and creates

        * the parfile.txt for the ksim simulator

        */

       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);

              }

       }

       /**

        * <code> parseFactor </code> parses the factor and convert to correct format for ksim

        *

        * @param factor

        * @return

        * @throws Exception

        */

       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: xchu@csse.unimelb.edu.au
work: +61 3 8344 1335

原创粉丝点击