Changeset 4722
- Timestamp:
- Jan 9, 2009, 1:18:06 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2.9-stable/src/plugins/core/net/sf/basedb/plugins/Base1PluginExecuter.java
r4716 r4722 563 563 File stdout = null; 564 564 Transformation trans = null; 565 566 565 Directory workingDirectory = null; 567 568 //Export 566 boolean leaveStdin = Boolean.TRUE.equals(configuration.getValue("leaveStdin")); 567 boolean leaveStdout = Boolean.TRUE.equals(configuration.getValue("leaveStdout")); 568 569 569 try 570 570 { 571 dc = sc.newDbControl(); 572 String workingPath = (String) job.getValue("pluginDirectory") + "/" + job.getId(); 573 workingDirectory = getPluginDirectory(dc, workingPath); 574 progress.display(0, "Exporting data to be used by plugin."); 575 stdin = exportData(dc, workingDirectory); 576 checkInterrupted(); 577 dc.commit(); 578 } 579 catch(Exception e) 580 { 581 response.setError("Error during export: " + e.getMessage(), Arrays.asList(e)); 582 return; 571 //Export 572 try 573 { 574 dc = sc.newDbControl(); 575 String workingPath = (String) job.getValue("pluginDirectory") + "/" + job.getId(); 576 workingDirectory = getPluginDirectory(dc, workingPath); 577 progress.display(0, "Exporting data to be used by plugin."); 578 stdin = exportData(dc, workingDirectory); 579 checkInterrupted(); 580 dc.commit(); 581 } 582 catch(Exception e) 583 { 584 response.setError("Error during export: " + e.getMessage(), Arrays.asList(e)); 585 return; 586 } 587 finally 588 { 589 if (dc != null) dc.close(); 590 } 591 592 //Execution 593 Process externalProcess = null; 594 try 595 { 596 checkInterrupted(); 597 copy(stdin, getExecDirectory()); 598 progress.display(10, "Running on remote computation server."); 599 externalProcess = Runtime.getRuntime().exec(getExecLine(), null, getExecDirectory()); 600 601 ByteArrayOutputStream err = new ByteArrayOutputStream(); 602 StreamHandler errorStream = new StreamHandler( 603 new BufferedInputStream(externalProcess.getErrorStream()), 604 new BufferedOutputStream(err)); 605 606 FileOutputStream out = 607 new FileOutputStream(new java.io.File(getExecDirectory(), "stdout.txt")); 608 StreamHandler inputStream = new StreamHandler( 609 new BufferedInputStream(externalProcess.getInputStream()), 610 new BufferedOutputStream(out)); 611 612 FileInputStream in = 613 new FileInputStream(new java.io.File(getExecDirectory(), "stdin.txt")); 614 StreamHandler outputStream = new StreamHandler( 615 new BufferedInputStream(in), 616 new BufferedOutputStream(externalProcess.getOutputStream())); 617 618 inputStream.start(); 619 errorStream.start(); 620 outputStream.start(); 621 int exitValue = 0; 622 try 623 { 624 exitValue = externalProcess.waitFor(); 625 } 626 catch (InterruptedException ex) 627 { 628 // Aborted by user 629 externalProcess.destroy(); 630 throw new SignalException("Aborted by user", ex); 631 } 632 633 progress.display(50, "Reading from error stream."); 634 for(int i = 0; errorStream.isAlive(); ++i) 635 { 636 Thread.sleep(1000); 637 if (i > 300) throw new BaseException("Waited 5 minutes for the errormessage. I give up."); 638 } 639 640 err.flush(); 641 msg = err.toString(); 642 out.flush(); 643 644 if (exitValue != 0) 645 { 646 response.setError(msg, null); 647 return; 648 } 649 } 650 catch (Exception e) 651 { 652 response.setError("Error during execution: " + e.getMessage(), Arrays.asList(e)); 653 return; 654 } 655 656 // Import analysis files created by the BASE1 plug-in 657 try 658 { 659 //Copy files 660 dc = sc.newDbControl(); 661 progress.display(60, "Copying files to server."); 662 importTempFiles(dc, getExecDirectory().listFiles(), workingDirectory); 663 dc.commit(); 664 if (!deleteDir(getExecDirectory())) 665 { 666 response.setError("Could not remove execution directory: "+getExecDirectory().getAbsolutePath(), null); 667 return; 668 } 669 } 670 finally 671 { 672 if (dc != null) dc.close(); 673 } 674 675 //Import 676 try 677 { 678 dc = sc.newDbControl(); 679 checkInterrupted(); 680 progress.display(70, "Importing data from plugin."); 681 BioAssaySet parentBas = getSourceBioAssaySet(dc); 682 trans = parentBas.newTransformation(Job.getById(dc, job.getId())); 683 trans.setName(PluginConfiguration.getById(dc, configuration.getId()).getName()); 684 dc.saveItem(trans); 685 stdout = File.getFile(dc, workingDirectory, "stdout.txt", true); 686 associateFiles(dc, trans, workingDirectory); 687 importData(dc, stdout, trans); 688 dc.commit(); 689 } 690 catch (Exception ex) 691 { 692 response.setError(ex.getMessage(), Arrays.asList(ex)); 693 return; 694 } 695 finally 696 { 697 if (dc != null) dc.close(); 698 } 583 699 } 584 700 finally 585 701 { 586 if (dc != null) dc.close(); 587 } 588 589 //Execution 590 Process externalProcess = null; 591 try 592 { 593 checkInterrupted(); 594 copy(stdin, getExecDirectory()); 595 progress.display(10, "Running on remote computation server."); 596 externalProcess = Runtime.getRuntime().exec(getExecLine(), null, getExecDirectory()); 597 598 ByteArrayOutputStream err = new ByteArrayOutputStream(); 599 StreamHandler errorStream = new StreamHandler( 600 new BufferedInputStream(externalProcess.getErrorStream()), 601 new BufferedOutputStream(err)); 602 603 FileOutputStream out = 604 new FileOutputStream(new java.io.File(getExecDirectory(), "stdout.txt")); 605 StreamHandler inputStream = new StreamHandler( 606 new BufferedInputStream(externalProcess.getInputStream()), 607 new BufferedOutputStream(out)); 608 609 FileInputStream in = 610 new FileInputStream(new java.io.File(getExecDirectory(), "stdin.txt")); 611 StreamHandler outputStream = new StreamHandler( 612 new BufferedInputStream(in), 613 new BufferedOutputStream(externalProcess.getOutputStream())); 614 615 inputStream.start(); 616 errorStream.start(); 617 outputStream.start(); 618 int exitValue = 0; 619 try 620 { 621 exitValue = externalProcess.waitFor(); 622 } 623 catch (InterruptedException ex) 624 { 625 // Aborted by user 626 externalProcess.destroy(); 627 throw new SignalException("Aborted by user", ex); 628 } 629 630 progress.display(50, "Reading from error stream."); 631 for(int i = 0; errorStream.isAlive(); ++i) 632 { 633 Thread.sleep(1000); 634 if (i > 300) throw new BaseException("Waited 5 minutes for the errormessage. I give up."); 635 } 636 637 err.flush(); 638 msg = err.toString(); 639 out.flush(); 640 641 if (exitValue != 0) 642 { 643 response.setError(msg, null); 644 return; 645 } 646 } 647 catch (Exception e) 648 { 649 response.setError("Error during execution: " + e.getMessage(), Arrays.asList(e)); 650 return; 651 } 652 653 // Import analysis files created by the BASE1 plug-in 654 try 655 { 656 //Copy files 657 dc = sc.newDbControl(); 658 progress.display(60, "Copying files to server."); 659 importTempFiles(dc, getExecDirectory().listFiles(), workingDirectory); 660 dc.commit(); 661 if (!deleteDir(getExecDirectory())) 662 { 663 response.setError("Could not remove execution directory: "+getExecDirectory().getAbsolutePath(), null); 664 } 665 } 666 finally 667 { 668 if (dc != null) dc.close(); 669 } 670 671 //Import data and clean up 672 try 673 { 674 dc = sc.newDbControl(); 675 checkInterrupted(); 676 progress.display(70, "Importing data from plugin."); 677 BioAssaySet parentBas = getSourceBioAssaySet(dc); 678 trans = parentBas.newTransformation(Job.getById(dc, job.getId())); 679 trans.setName(PluginConfiguration.getById(dc, configuration.getId()).getName()); 680 dc.saveItem(trans); 681 stdout = File.getFile(dc, workingDirectory, "stdout.txt", true); 682 associateFiles(dc, trans, workingDirectory); 683 importData(dc, stdout, trans); 684 685 if (!Values.getBoolean(String.valueOf(configuration.getValue("leaveStdin")))) 686 { 687 if (stdin != null) 688 { 689 stdin = File.getById(dc, stdin.getId()); 690 if (trans != null) 702 // Cleanup stdin and stdout 703 if (workingDirectory != null) 704 { 705 try 706 { 707 dc = sc.newDbControl(); 708 if (!leaveStdin && File.exists(dc, workingDirectory, "stdin.txt")) 691 709 { 692 trans = Transformation.getById(dc, trans.getId()); 693 AnyToAny ata = AnyToAny.getByName(dc, trans, stdin.getPath().toString()); 694 dc.deleteItem(ata); 710 stdin = File.getFile(dc, workingDirectory, "stdin.txt", false); 711 dc.deleteItem(stdin); 695 712 } 696 dc.deleteItem(stdin); 697 } 698 } 699 if (!Values.getBoolean(String.valueOf(configuration.getValue("leaveStdout")))) 700 { 701 if (stdout != null) 702 { 703 stdout = File.getById(dc, stdout.getId()); 704 if (trans != null) 713 if (!leaveStdout && File.exists(dc, workingDirectory, "stdout.txt")) 705 714 { 706 trans = Transformation.getById(dc, trans.getId()); 707 AnyToAny ata = AnyToAny.getByName(dc, trans, stdout.getPath().toString()); 708 dc.deleteItem(ata); 715 stdout = File.getFile(dc, workingDirectory, "stdout.txt", false); 716 dc.deleteItem(stdout); 709 717 } 710 dc.deleteItem(stdout); 711 } 712 } 713 714 dc.commit(); 715 } 716 catch (Exception ex) 717 { 718 response.setError(ex.getMessage(), Arrays.asList(ex)); 719 return; 720 } 721 finally 722 { 723 if (dc != null) dc.close(); 718 dc.commit(); 719 } 720 catch (Exception ex) 721 { 722 response.setError("Plug-in completed successfully, but stdin and/or stdout could not be removed: " + 723 ex.getMessage(), Arrays.asList(ex)); 724 return; 725 } 726 finally 727 { 728 if (dc != null) dc.close(); 729 } 730 } 724 731 } 725 732 response.setDone(msg);
Note: See TracChangeset
for help on using the changeset viewer.