|
From: <das...@us...> - 2008-10-29 20:39:07
|
Revision: 1185
http://vlab.svn.sourceforge.net/vlab/?rev=1185&view=rev
Author: dasil014
Date: 2008-10-29 20:39:04 +0000 (Wed, 29 Oct 2008)
Log Message:
-----------
This class has the settings to dispatch the jobs to the Task Dispatcher web service. This class has methods that insert data into a object list based on directory structure of the execution packages, with different options distinct project types.
Added Paths:
-----------
trunk/vlab/services/project-executor/src/main/java/org/vlab/services/DispatcherSetting.java
Added: trunk/vlab/services/project-executor/src/main/java/org/vlab/services/DispatcherSetting.java
===================================================================
--- trunk/vlab/services/project-executor/src/main/java/org/vlab/services/DispatcherSetting.java (rev 0)
+++ trunk/vlab/services/project-executor/src/main/java/org/vlab/services/DispatcherSetting.java 2008-10-29 20:39:04 UTC (rev 1185)
@@ -0,0 +1,587 @@
+package org.vlab.services;
+
+import java.io.*;
+
+public class DispatcherSetting {
+
+ public static Receipt setDispSetting(Receipt projectReceipt, Receipt phaseReceipt, String projectType, Boolean phaseOption){
+
+ System.out.println("\n Here I just start the ProjectExecutor::setDispSetting \n");
+
+ String[] ListOfPackages = null;
+ String ActuallyPackage = null;
+ DispatchTask[] dispatch = null;
+
+ try{
+ ListOfPackages = ListPackages(projectType, phaseOption);
+ } catch (Exception ae){
+ System.err.println("[ProjectExecutor::setDispSetting()] Error getting the list of packages: "+ae.getMessage());
+ ae.printStackTrace();
+ //System.exit(-1);
+ }
+
+ //TotalJobs
+
+ try{
+ dispatch = new DispatchTask[ListOfPackages.length];
+
+ for(int i=0;i<ListOfPackages.length;i++){
+
+ //try{
+ ActuallyPackage = ListOfPackages[i];
+
+ dispatch[i] = new DispatchTask(i, "THREAD:"+i);
+ System.out.println("START: " + dispatch[i].getName());
+
+ dispatch[i].setProjectId(ProjectExecutor.projectId);
+
+ dispatch[i].setProjectName(ProjectExecutor.projectName);
+
+ dispatch[i].setProjectType(projectType);
+
+ dispatch[i].setFullPackageName(ProjectExecutor.ENV_PACKAGE_DIR + ProjectExecutor.dirEPName + ActuallyPackage);
+
+ dispatch[i].setZipFileName(ActuallyPackage);
+
+ dispatch[i].setTdUrl(ProjectExecutor.tdUrl);
+ dispatch[i].start();
+ dispatch[i].join();
+ //dispatch[i].sleep(2000);
+ }
+ } catch (Exception ae){
+ System.err.println("[ProjectExecutor::setDispSetting()] Error starting up the thread for submission: "+ae.getMessage());
+ ae.printStackTrace();
+ //System.exit(-1);
+ }
+
+
+ try{
+
+ dispatch[ListOfPackages.length-1].join();
+
+ for(int j=0;j<ListOfPackages.length;j++){
+ try{
+ if (dispatch[j].isAlive()){
+ System.out.println("Here I will do the join of: "+dispatch[j].getName());
+ dispatch[j].join();
+ }
+ }catch (Exception ae){
+ System.err.println("[ProjecExecutor::setDispSetting()] => Error catching up the task receipt: " + ae.getMessage());
+ ae.printStackTrace();
+ //System.exit(-1);
+ }
+ }
+
+
+ if (projectType.equals("1")) ReceiptManagement.setClosePhaseReceiptFastRefine("Dispatcher", projectReceipt, phaseReceipt);
+
+ if (projectType.equals("2") && phaseOption.booleanValue()==true) {
+ projectReceipt = ReceiptManagement.setClosePhaseReceiptFastRefine("Dispatcher", projectReceipt, phaseReceipt);
+ }
+
+ if (projectType.equals("2") && phaseOption.booleanValue()==false) {
+ projectReceipt = ReceiptManagement.setClosePhaseReceiptLongRefine("Dispatcher", projectReceipt, phaseReceipt, phaseOption);
+ }
+
+ projectReceipt = ReceiptManagement.setCloseProjectReceipt(projectReceipt);
+
+
+ } catch (Exception ae){
+ System.err.println("[ProjectExecutor::setDispSetting()] => Error finishing the start up of the Tasks");
+ ae.printStackTrace();
+ //System.exit(-1);
+ }
+
+ return projectReceipt;
+ }
+
+ public static Receipt setDispSettingCij(Receipt projectReceipt, Receipt phaseReceipt, String projectType, Boolean phaseOption){
+
+ System.out.println("\n Here I just start the ProjectExecutor::setDispSettingCij \n");
+
+ String[] ListOfPackages = null;
+
+ String[] ListOfEEPackages = null;
+
+ String ActuallyCCPackage = null;
+ String ActuallyEEPackage = null;
+ DispatchTask[][] dispatch = null;
+ int Index_i = 0;
+ int Index_j = 0;
+ int Index_EE[] = null;
+
+ try{
+ ListOfPackages = ListPackages(projectType, phaseOption);
+ if (ListOfPackages.length > 0){
+ ActuallyCCPackage = ListOfPackages[0];
+ ListOfEEPackages = ListEEPackages(ActuallyCCPackage, false);
+ }
+ Index_EE = new int[ListOfPackages.length];
+ } catch (Exception ae){
+ System.err.println("[ProjectExecutor::setDispSettingCij()] Error Taking the list of tasks for Cij: "+ae.getMessage());
+ ae.printStackTrace();
+ //System.exit(-1);
+ }
+
+ try{
+ dispatch = new DispatchTask[ListOfPackages.length][ListOfEEPackages.length];
+
+ for(Index_i=0;Index_i<ListOfPackages.length; Index_i++){
+
+ ActuallyCCPackage = ListOfPackages[Index_i];
+ System.out.println("ProjectExecutor::setDispSettingCij() => Actually package is: " + ActuallyCCPackage);
+ ListOfEEPackages = ListEEPackages(ActuallyCCPackage, true);
+
+ Index_EE[Index_i] = ListOfEEPackages.length;
+
+ for(Index_j=0; Index_j < ListOfEEPackages.length; Index_j++){
+
+ try{
+ ActuallyEEPackage = ListOfEEPackages[Index_j];
+
+ dispatch[Index_i][Index_j] = new DispatchTask(Index_i+Index_j, "THREAD:"+Index_i+":"+Index_j);
+
+ System.out.println("START: " + dispatch[Index_i][Index_j].getName());
+ dispatch[Index_i][Index_j].setProjectId(ProjectExecutor.projectId);
+
+ dispatch[Index_i][Index_j].setProjectName(ProjectExecutor.projectName);
+
+ dispatch[Index_i][Index_j].setProjectType(projectType);
+
+ dispatch[Index_i][Index_j].setFullPackageName(ProjectExecutor.ENV_PACKAGE_DIR + ProjectExecutor.dirEPName + "/" + ActuallyCCPackage.substring(0,ActuallyCCPackage.length()-4) + "/"+ActuallyEEPackage+".zip");
+
+ dispatch[Index_i][Index_j].setZipFileName(ActuallyEEPackage+".zip");
+
+ dispatch[Index_i][Index_j].setTdUrl(ProjectExecutor.tdUrl);
+ dispatch[Index_i][Index_j].start();
+ //dispatch[Index_i][Index_j].sleep(2000);
+ dispatch[Index_i][Index_j].join();
+
+ }catch (Exception ae){
+ System.err.println("[ProjecExecutor::setDispSettingCij()] => Error: " + ae.getMessage());
+ ae.printStackTrace();
+ //System.exit(-1);
+ }
+ }
+ }
+
+ dispatch[ListOfPackages.length-1][ListOfEEPackages.length-1].join();
+
+ System.out.println("THE SIZE OF INDEX_EE: "+Index_EE.length);
+
+ for(int i=0;i<Index_EE.length;i++){
+
+ System.out.println("Index_EE.length: "+Index_EE.length+" and inside the index: "+i+" I have: "+Index_EE[i]);
+
+ for(int j=0;j<Index_EE[i]; j++){
+
+ System.out.println("Thread: "+i+":"+j);
+
+ try{
+ if (dispatch[i][j].isAlive()) {
+ System.out.println("dispatch["+i+"]["+j+"]: " + dispatch[i][j].getName());
+ dispatch[i][j].join();
+ }
+ //else{
+ // System.out.println("Thread: "+i+":"+j+" died");
+ // if (projectType.equals("3")) setClosePhaseReceiptCij();
+ // setCloseProjectReceipt();
+ //}
+
+ }catch (Exception ae){
+ System.err.println("[ProjecExecutor::setDispSettingCij()] => Error trying to join the thread: " + ae.getMessage());
+ ae.printStackTrace();
+ //System.exit(-1);
+ }
+ }
+ }
+
+
+ if (projectType.equals("3")) {
+ projectReceipt = ReceiptManagement.setClosePhaseReceiptCij("Dispatcher", projectReceipt, phaseReceipt, phaseOption);
+ }
+
+ projectReceipt = ReceiptManagement.setCloseProjectReceipt(projectReceipt);
+
+ //setCloseProjectReceipt();
+ } catch(Exception ae){
+ System.err.println("[ProjectExecutor::setDispSettingCij()] Error Sending the Cij packages to Task Dispatcher: "+ae.getMessage());
+ ae.printStackTrace();
+ //System.exit(-1);
+ }
+ return projectReceipt;
+ }
+
+ public static Receipt setDispSettingHighTPThermo(Receipt projectReceipt, Receipt phaseReceipt, String projectType, Boolean phaseOption){
+
+ System.out.println("\n Here I just start the ProjectExecutor::setDispSettingHighTPThermo \n");
+ //List the packages of __CC5f_1
+ String[] ListOfPackages = null;
+
+ String[] ListOfPHPackages = null;
+
+ String ActuallyCCPackage = null;
+ String ActuallyPHPackage = null;
+ DispatchTask[][] dispatch = null;
+ int Index_i = 0;
+ int Index_j = 0;
+ int Index_PH[] = null;
+
+ int JobTotal = 0;
+
+ try{
+ ListOfPackages = ListPackages(projectType, phaseOption);
+ if (ListOfPackages.length > 0){
+ ActuallyCCPackage = ListOfPackages[0];
+ ListOfPHPackages = ListPHPackages(ActuallyCCPackage, false);
+ }
+ Index_PH = new int[ListOfPackages.length];
+ } catch(Exception ae){
+ System.err.println("[ProjectExecutor::setDispSettingHighTPThermo()] Error taking the list packages of HighTP thermo: "+ae.getMessage());
+ ae.printStackTrace();
+ //System.exit(-1);
+ }
+
+ try{
+ dispatch = new DispatchTask[ListOfPackages.length][ListOfPHPackages.length];
+
+ for(Index_i=0;Index_i<ListOfPackages.length; Index_i++){
+
+ ActuallyCCPackage = ListOfPackages[Index_i];
+ System.out.println("ProjectExecutor::setDispSettingHighTPThermo() => Actually package is: " + ActuallyCCPackage);
+ ListOfPHPackages = ListPHPackages(ActuallyCCPackage, true);
+
+ Index_PH[Index_i] = ListOfPHPackages.length;
+
+ for(Index_j=0; Index_j < ListOfPHPackages.length; Index_j++){
+
+ try{
+ ActuallyPHPackage = ListOfPHPackages[Index_j];
+
+ dispatch[Index_i][Index_j] = new DispatchTask(Index_i + Index_j, "THREAD:"+Index_i+":"+Index_j);
+
+ System.out.println("START: " + dispatch[Index_i][Index_j].getName() + " PCK: " + ListOfPHPackages[Index_j]);
+
+ dispatch[Index_i][Index_j].setProjectId(ProjectExecutor.projectId);
+
+ dispatch[Index_i][Index_j].setProjectName(ProjectExecutor.projectName);
+
+ dispatch[Index_i][Index_j].setFullPackageName(ProjectExecutor.ENV_PACKAGE_DIR + ProjectExecutor.dirEPName + "/" + ActuallyCCPackage.substring(0,ActuallyCCPackage.length()-4) + "/"+ActuallyPHPackage+".zip");
+
+ dispatch[Index_i][Index_j].setZipFileName(ActuallyPHPackage+".zip");
+
+ dispatch[Index_i][Index_j].setTdUrl(ProjectExecutor.tdUrl);
+
+ dispatch[Index_i][Index_j].setProjectType(projectType);
+
+ dispatch[Index_i][Index_j].start();
+ dispatch[Index_i][Index_j].join();
+
+ //dispatch[Index_i][Index_j].sleep(2000);
+ JobTotal++;
+
+ }catch (Exception ae){
+ System.err.println("[ProjecExecutor::setDispSettingHighTPThermo()] => Error: " + ae.getMessage());
+ ae.printStackTrace();
+ //System.exit(-1);
+ }
+ }
+ }
+
+ //dispatch[ListOfPackages.length-1][ListOfPHPackages.length-1].join();
+
+ System.out.println("THE SIZE OF INDEX_PH: "+Index_PH.length);
+
+ System.out.println("My Job Total is: " + JobTotal);
+
+ for(int i=0;i<Index_PH.length;i++){
+
+ System.out.println("Index_EE.length: "+Index_PH.length+" and inside the index: "+i+" I have: "+Index_PH[i]);
+
+ for(int j=0;j<Index_PH[i]; j++){
+
+ System.out.println("Thread: "+i+":"+j);
+
+ //if ( ((i/2)==0) && ((j/2)==0) ){
+ // if (projectType.equals("4")) setClosePhaseReceiptHighTPTHermo();
+ // setCloseProjectReceipt();
+ //}
+ try{
+ if (dispatch[i][j].isAlive()) {
+ System.out.println("dispatch["+i+"]["+j+"]: " + dispatch[i][j].getName());
+ dispatch[i][j].sleep(1000);
+ dispatch[i][j].join();
+ //setClosePhaseReceiptHighTPTHermo();
+ //setCloseProjectReceipt();
+ }
+ else{
+ System.out.println("Thread: "+i+":"+j+" died");
+ //if (projectType.equals("4")) ProjectExecutor.setClosePhaseReceiptHighTPTHermo("DispHigh Thermo inside the loop");
+ //ProjectExecutor.setCloseProjectReceipt();
+ }
+
+ }catch (Exception ae){
+ System.err.println("[ProjecExecutor::setDispSettingHighTPThermo()] => Error trying to join the thread: " + ae.getMessage());
+ ae.printStackTrace();
+ //System.exit(-1);
+ }
+ }
+ }
+
+ //if (ProjectExecutor.projectType.equals("4")) ProjectExecutor.setClosePhaseReceiptHighTPTHermo("DispHigh Thermo");
+
+ if (projectType.equals("4")) {
+ projectReceipt = ReceiptManagement.setClosePhaseReceiptHighTPTHermo("Dispatcher", projectReceipt, phaseReceipt, phaseOption);
+ }
+
+ projectReceipt = ReceiptManagement.setCloseProjectReceipt(projectReceipt);
+
+ //ProjectExecutor.setCloseProjectReceipt();
+ } catch (Exception ae){
+ System.err.println("[ProjectExecutor::setDispSettingHighTPThermo()] Error sending the HighTP pakcages to Task Dispatcher: "+ae.getMessage());
+ ae.printStackTrace();
+ //System.exit(-1);
+ }
+
+ return projectReceipt;
+ }
+
+ public static String[] ListPackages(String projectType, Boolean phaseOption){
+
+ System.out.println(" Here I start the ProjectExecutor::ListPackage() ");
+ File DirOfPackages = null;
+ String[] ListOfFiles = null;
+ FilenameFilter filter = null;
+
+ try{
+ DirOfPackages = new File(ProjectExecutor.ENV_PACKAGE_DIR + ProjectExecutor.dirEPName);
+
+ if (projectType.equals("1")){
+ filter = new FilenameFilter( ){
+ public boolean accept(File dir, String name){
+ return name.matches("SingleCalc.*.zip");
+ }
+ };
+ }
+
+ if (projectType.equals("2") && phaseOption.booleanValue()==false){
+ System.out.println("\n It means you choose LONG REFINE");
+ filter = new FilenameFilter(){
+ public boolean accept(File dir, String name){
+ return name.matches("__CC5f.*.zip");
+ }
+ };
+ }
+
+ if (projectType.equals("2") && phaseOption.booleanValue()==true){
+ System.out.println("\n It means you choose FAST REFINE");
+ filter = new FilenameFilter( ){
+ public boolean accept(File dir, String name){
+ return name.matches("__AA5f.*.zip");
+ }
+ };
+ }
+
+ if (projectType.equals("3") && phaseOption.booleanValue()==false){
+ System.out.println("\n It means you may chose Cij");
+ filter = new FilenameFilter(){
+ public boolean accept(File dir, String name){
+ return name.matches("__CC5f.*.zip");
+ }
+ };
+ }
+
+ if (projectType.equals("4")){
+ System.out.println("\n It means you may chose HiTP Thermo");
+ filter = new FilenameFilter(){
+ public boolean accept(File dir, String name){
+ return name.matches("__CC5f.*.zip");
+ }
+ };
+ }
+
+ ListOfFiles = DirOfPackages.list(filter);
+
+ System.out.println("I have the following packages: \n");
+ if (ListOfFiles != null) {
+ for (int i=0; i<ListOfFiles.length; i++) {
+ // Get filename of file or directory
+ String FileLabel = ListOfFiles[i];
+ System.out.println(FileLabel);
+ }
+ }
+
+ }catch(Exception ae){
+ System.err.println("[DispatcherSetting::ListPackage()] => Error: " + ae.getMessage());
+ ae.printStackTrace();
+ //System.exit(-1);
+ }
+ return ListOfFiles;
+ }
+
+ public static String[] ListEEPackages(String CCAtuallyPackage, boolean needszipfile){
+
+ System.out.println(" Here I start the ProjectExecutor::ListEEPackages() ");
+ File DirOfPackages = null;
+ String[] ListOfFiles = null;
+ FilenameFilter filter = null;
+
+
+ try{
+ DirOfPackages = new File(ProjectExecutor.ENV_PACKAGE_DIR + ProjectExecutor.dirEPName + CCAtuallyPackage.substring(0, CCAtuallyPackage.length()-4));
+
+ System.out.println("\n It means you choose LONG REFINE and package path is: " + DirOfPackages.getAbsolutePath());
+ filter = new FilenameFilter(){
+ public boolean accept(File dir, String name){
+ return name.startsWith("__EEf");
+ }
+ };
+
+ ListOfFiles = DirOfPackages.list(filter);
+
+ System.out.println("I have the following packages: \n");
+ if (ListOfFiles != null && needszipfile == true) {
+ for (int i=0; i<ListOfFiles.length; i++) {
+ // Get filename of file or directory
+ String FileLabel = ListOfFiles[i];
+ System.out.println(FileLabel);
+ setZipPackageEE(DirOfPackages.getAbsolutePath(), FileLabel);
+ }
+ }
+
+ }catch(Exception ae){
+ System.err.println("[ProjectExecutor::ListEEPackages()] => Error: " + ae.getMessage());
+ ae.printStackTrace();
+ //System.exit(-1);
+ }
+ return ListOfFiles;
+ }
+
+ public static String[] ListPHPackages(String CCAtuallyPackage, boolean needszipfile){
+
+ System.out.println(" Here I start the ProjectExecutor::ListPHPackages() ");
+ File DirOfPackages = null;
+ String[] ListOfFiles = null;
+ FilenameFilter filter = null;
+
+ try{
+ DirOfPackages = new File(ProjectExecutor.ENV_PACKAGE_DIR + ProjectExecutor.dirEPName + CCAtuallyPackage.substring(0, CCAtuallyPackage.length()-4));
+
+ System.out.println("\n It means you choose LONG REFINE and package path is: " + DirOfPackages.getAbsolutePath());
+ filter = new FilenameFilter(){
+ public boolean accept(File dir, String name){
+ return name.startsWith("__p");
+ }
+ };
+
+ ListOfFiles = DirOfPackages.list(filter);
+
+ System.out.println("I have the following packages: \n");
+ if (ListOfFiles != null && needszipfile == true) {
+ for (int i=0; i<ListOfFiles.length; i++) {
+ //Get filename of file or directory
+ String FileLabel = ListOfFiles[i];
+ System.out.println(FileLabel);
+ setZipPackagePH(DirOfPackages.getAbsolutePath(), FileLabel);
+ }
+ }
+
+ }catch(Exception ae){
+ System.err.println("[ProjectExecutor::ListEEPackages()] => Error: " + ae.getMessage());
+ ae.printStackTrace();
+ //System.exit(-1);
+ }
+ return ListOfFiles;
+ }
+
+
+
+ private static void setZipPackageEE(String workDir, String ActuallyPackageToZip){
+
+ System.out.println("\n Here I start the setZipPackageEE(String) I got the : " + ActuallyPackageToZip);
+
+ InputStream stderr = null;
+ InputStreamReader isr_err = null;
+ BufferedReader br_err = null;
+ InputStream stdin = null;
+ InputStreamReader isr_stdin = null;
+ BufferedReader br_stdin = null;
+ String returnMessage = null;
+ int exitValue = 0;
+
+
+
+ try{
+ File FileDir = new File(workDir);
+ String[] fullcommand = { ProjectExecutor.ENV_SCRIPT +"zipFile.sh",ActuallyPackageToZip};
+ Runtime Rt = Runtime.getRuntime();
+ Process procShell = Rt.exec(fullcommand, null , FileDir);
+
+ stderr = procShell.getErrorStream();
+ isr_err = new InputStreamReader(stderr);
+ br_err = new BufferedReader(isr_err);
+
+ stdin = procShell.getInputStream();
+ isr_stdin = new InputStreamReader(stdin);
+ br_stdin = new BufferedReader(isr_stdin);
+
+ for(int j=0;(returnMessage = br_stdin.readLine()) != null;j++){
+ System.out.println("Output >> " + returnMessage);
+ }
+ exitValue = procShell.waitFor();
+ System.out.println("Exit Status: "+exitValue);
+
+ } catch (Exception ae){
+
+ System.err.println("[ProjectExecutor:setZipPackageEE()] => Error: " + ae.getMessage());
+ ae.printStackTrace();
+ //System.exit(-1);
+ }
+ }
+
+ private static void setZipPackagePH(String workDir, String ActuallyPackageToZip){
+
+ System.out.println("\n Here I start the setZipPackagePH(String) I got the : " + ActuallyPackageToZip);
+
+ InputStream stderr = null;
+ InputStreamReader isr_err = null;
+ BufferedReader br_err = null;
+ InputStream stdin = null;
+ InputStreamReader isr_stdin = null;
+ BufferedReader br_stdin = null;
+ String returnMessage = null;
+ int exitValue = 0;
+
+ try{
+ File FileDir = new File(workDir);
+ String[] fullcommand = { ProjectExecutor.ENV_SCRIPT +"zipFile.sh",ActuallyPackageToZip};
+ Runtime Rt = Runtime.getRuntime();
+ Process procShell = Rt.exec(fullcommand, null , FileDir);
+
+ stderr = procShell.getErrorStream();
+ isr_err = new InputStreamReader(stderr);
+ br_err = new BufferedReader(isr_err);
+
+ stdin = procShell.getInputStream();
+ isr_stdin = new InputStreamReader(stdin);
+ br_stdin = new BufferedReader(isr_stdin);
+
+ for(int j=0;(returnMessage = br_stdin.readLine()) != null;j++){
+ System.out.println("Output >> " + returnMessage);
+ }
+ exitValue = procShell.waitFor();
+ System.out.println("Exit Status: "+exitValue);
+
+ } catch (Exception ae){
+
+ System.err.println("[ProjectExecutor:setZipPackagePH()] => Error: " + ae.getMessage());
+ ae.printStackTrace();
+ //System.exit(-1);
+ }
+ }
+
+
+
+
+
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|