1 23 24 package com.sun.enterprise.tools.common.deploy; 25 26 31 32 import java.beans.*; 33 import java.util.*; 34 import java.io.File ; 35 import javax.swing.JOptionPane ; 36 import java.net.InetAddress ; 37 import java.net.Socket ; 38 import com.sun.enterprise.tools.common.LoginFailureException; 39 import com.sun.enterprise.tools.common.ui.UIMessenger; 40 41 import com.sun.enterprise.admin.servermodel.beans.*; 42 import com.sun.enterprise.admin.servermodel.ServerInstanceManager; 43 import com.sun.enterprise.admin.servermodel.ServerInstanceManagerFactory; 44 import com.sun.enterprise.admin.servermodel.AppServerInstance; 45 import com.sun.enterprise.admin.common.constant.DeploymentConstants; 46 import com.sun.enterprise.admin.common.constant.ConfigAttributeName; 47 import com.sun.enterprise.admin.common.exception.*; 48 import com.sun.enterprise.admin.util.HostAndPort; 49 import com.sun.enterprise.tools.common.util.diagnostics.Reporter; 50 import com.sun.enterprise.tools.common.deploy.NameValuePair; 51 52 57 public class ServerInstance extends Object implements java.io.Serializable { 58 59 60 private String host; 61 private String ad_host; 62 transient private PropertyChangeSupport propertySupport; 63 64 65 private String name; 66 67 private String dispName; 68 69 70 private String password; 71 72 73 private int port; 74 private int ad_port; 75 76 private String userName; 77 78 public static String pw_editor; 79 80 transient boolean checkAlreadyDone = false; 81 transient boolean IAS_Running ; 82 transient boolean checkDone = false; 83 transient boolean KJS_Running ; 84 transient boolean instRunning; 85 transient boolean isEnabled; 86 87 transient private ServerInstanceManager manager; 88 transient private AppServerInstance instance; 89 90 String depName = null; 91 92 static final ResourceBundle bundle = ResourceBundle.getBundle("com.sun.enterprise.tools.common.deploy.Bundle"); 94 95 public ServerInstance(String SOM_name, String serv_name, int serv_port, String username, String passwd) { 96 propertySupport = new PropertyChangeSupport ( this ); 97 userName = username; 98 password = passwd; 99 dispName = SOM_name; 100 name = serv_name; 101 port = serv_port; 102 ad_host = serv_name.substring(serv_name.indexOf("(")+1, serv_name.indexOf(":")); ad_port = Integer.parseInt( serv_name.substring(serv_name.indexOf(":")+1, serv_name.indexOf(")")) ); } 105 106 public ServerInstance(String SOM_name, String serv_name, int serv_port) { 107 this(SOM_name,serv_name,serv_port,"admin","admin123"); } 109 110 public ServerInstance(String SOM_name, String serv_name) { 111 this(SOM_name,serv_name,-1); 112 } 113 114 public static HostAndPort configurInstance(String host_name, int port_no){ 115 HostAndPort hp = new HostAndPort(host_name, port_no); 116 return hp; 117 } 118 119 public String getHost() { 120 return host; 121 } 122 123 public void setHost(String value) { 124 String oldValue = host; 125 host = value; 126 initPropertyChangeSupport(); 127 propertySupport.firePropertyChange ("host", oldValue, host); } 129 130 private void initPropertyChangeSupport(){ 131 if(propertySupport==null) 132 propertySupport = new PropertyChangeSupport ( this ); 133 134 } 135 public void addPropertyChangeListener (PropertyChangeListener listener) { 136 initPropertyChangeSupport(); 137 138 propertySupport.addPropertyChangeListener (listener); 139 } 140 141 public void removePropertyChangeListener (PropertyChangeListener listener) { 142 initPropertyChangeSupport(); 143 propertySupport.removePropertyChangeListener (listener); 144 } 145 146 149 public String getName() { 150 return name; 151 } 152 153 156 public void setName(String value) { 157 String oldValue = name; 158 name = value; 159 initPropertyChangeSupport(); 160 propertySupport.firePropertyChange ("name", oldValue, name); } 163 164 public String getDisplayName() { 165 return dispName; 166 } 167 168 171 public void setDisplayName(String value) { 172 String oldValue = dispName; 173 dispName = value; 174 initPropertyChangeSupport(); 175 propertySupport.firePropertyChange ("displayname", oldValue, dispName); } 178 179 182 public String getPrivatePassword() { 183 String pw = getPassword(); 184 String passw = ""; for(int i=0; i<pw.length(); i++) 186 passw = passw + "*"; return passw; 188 } 189 192 public String getPassword() { 193 pw_editor = password; 194 return password; 195 } 196 197 200 public void setPassword(String value) { 201 String oldValue = host; 202 password = value; 203 initPropertyChangeSupport(); 204 propertySupport.firePropertyChange ("password", oldValue, password); } 206 207 210 public int getPort() { 211 return port; 212 } 213 214 217 public void setPort(int value) { 218 Reporter.info("Setting Server Port to " + value); String oldValue = host; 220 port = value; 221 initPropertyChangeSupport(); 222 propertySupport.firePropertyChange ("port", null, null); } 224 225 228 public String getUserName() { 229 return userName; 230 } 231 232 235 public void setUserName(String value) { 236 String oldValue = host; 237 userName = value; 238 initPropertyChangeSupport(); 239 propertySupport.firePropertyChange ("userName", oldValue, userName); } 241 242 public String getAdminHost() { 243 return ad_host; 244 } 245 246 public void setAdminHost(String value) { 247 String oldValue = ad_host; 248 ad_host = value; 249 initPropertyChangeSupport(); 250 propertySupport.firePropertyChange ("ad_host", oldValue, ad_host); } 252 253 public int getAdminPort() { 254 return ad_port; 255 } 256 257 public void setAdminPort(int value) { 258 int oldValue = ad_port; 259 ad_port = value; 260 initPropertyChangeSupport(); 261 propertySupport.firePropertyChange ("ad_port", oldValue, ad_port); } 263 264 public String getConnectorUrl(){ 265 276 return "http://"+this.getName().substring(this.getName().indexOf("(")+1, this.getName().indexOf(":")+1)+ 277 getPort(); } 279 280 private synchronized AppServerInstance getSelectedInstance() throws DeploymentException,AFTargetNotFoundException { 281 if(instance == null){ 282 Reporter.info("Initializing instance"); String host = this.getName().substring(this.getName().indexOf("(")+1, this.getName().indexOf(":")); int port = Integer.parseInt( this.getName().substring(this.getName().indexOf(":")+1, this.getName().indexOf(")")) ); HostAndPort hostPort = new HostAndPort(host, port); 286 Reporter.info("getSelectedInstance " + this.getName().substring(0, this.getName().indexOf("("))); Reporter.info(hostPort); 288 manager = ServerInstanceManagerFactory.getFactory().getServerInstanceManager(hostPort,userName,password); 289 Reporter.assertIt(manager); 290 instance = manager.getServerInstance(this.getName().substring(0, this.getName().indexOf("("))); Reporter.assertIt(instance); 292 } 293 return instance; 294 } 295 296 public void createResource(String fname) throws AFException,AFResourceException,AFTargetNotFoundException, DeploymentException{ 297 getSelectedInstance().createResource(fname); 298 getSelectedInstance().applyChanges(); 299 } 301 302 383 384 public boolean deployEarFile( String earPath, UIMessenger messenger) throws DeploymentException { 385 final String path = earPath; 386 Reporter.info(earPath); 387 Iterator it = null; 388 InetAddress IP = null; 389 boolean deploySuccess = true; 390 try{ 391 IP = InetAddress.getByName(this.getAdminHost()); 392 Socket s = new Socket (IP, this.getAdminPort()); 393 s.close (); 394 try{ 395 Reporter.info("Getting App Name"); String appName = path.substring(path.lastIndexOf(File.separator)+1, path.lastIndexOf(".")); boolean exists = false; 398 Reporter.info(appName); 399 try{ 400 it = getSelectedInstance().getDeployedApplications(); 401 }catch( AFException e){ 402 throw new DeploymentException(e.getLocalizedMessage()); 403 }catch(AFRuntimeStoreException afre){ 405 throw new AFRuntimeStoreException(afre.getLocalizedMessage()); 406 } 407 messenger.setProgressMessage(bundle.getString("ExsistingAppCheck")); messenger.setProgressLevel(30); 409 while (it.hasNext()) 410 { 411 depName = it.next().toString(); 412 if(depName.equalsIgnoreCase(appName)){ 414 exists = true; 415 break; 416 } 417 } 418 Reporter.info(getSelectedInstance().getDeployedApplication(appName)); 419 if(exists){ 420 Reporter.info("Calling Redeploy"); messenger.setProgressMessage( bundle.getString("RedeployMessage")); messenger.setProgressLevel(55); 423 deploySuccess = getSelectedInstance().redeployApplication(path,appName); 424 }else{ 425 Reporter.info("Calling Deploy"); messenger.setProgressMessage( bundle.getString("DeployMessage")); messenger.setProgressLevel(55); 428 deploySuccess = getSelectedInstance().deployApplication(path, appName, true, null, true, false, false); 429 } 430 441 messenger.setProgressLevel(90); 442 447 messenger.setProgressLevel(100); 448 }catch(AFTargetNotFoundException te){ 449 throw new DeploymentException(te.getLocalizedMessage()); 450 }catch(DeploymentException de){ 452 throw new DeploymentException(de.getLocalizedMessage()); 453 }catch(AFRuntimeStoreException afre){ 455 messenger.ConfigXmlChanged(this.getName()); 456 } 457 }catch(java.net.UnknownHostException e){ 458 throw new DeploymentException(e.getLocalizedMessage()); 459 }catch(java.io.IOException con){ 460 throw new DeploymentException(con.getLocalizedMessage()); 461 } 462 return deploySuccess; 463 } 464 465 public boolean deployWarFile(String warPath, String waName, String contextRoot, UIMessenger messenger) throws DeploymentException { 466 final String path = warPath; 467 Reporter.info("Context Root" + contextRoot + "War Path" + warPath); Iterator it = null; 469 InetAddress IP = null; 470 boolean deploySuccess = true; 471 try{ 472 IP = InetAddress.getByName(this.getAdminHost()); 473 Socket s = new Socket (IP, this.getAdminPort()); 474 s.close (); 475 try{ 476 String webAppName = waName; Reporter.info("webAppName is : " + webAppName); boolean exists = false; 479 try{ 480 it = getSelectedInstance().getDeployedWebModules(); 481 }catch( AFException e){ 482 throw new DeploymentException(e.getLocalizedMessage()); 483 }catch(AFRuntimeStoreException afre){ 485 throw new AFRuntimeStoreException(afre.getLocalizedMessage()); 486 } 487 messenger.setProgressMessage( bundle.getString("ExsistingModuleCheck")); messenger.setProgressLevel(30); 489 while (it.hasNext()) 490 { 491 depName = it.next().toString(); 492 if(depName.equalsIgnoreCase(webAppName)){ 493 exists = true; 494 break; 495 } 496 } 497 messenger.setProgressMessage( bundle.getString("DeployWar")); if(exists){ 499 Reporter.info("Calling Redeploy"); messenger.setProgressMessage( bundle.getString("RedeployModuleMessage")); messenger.setProgressLevel(55); 502 deploySuccess = getSelectedInstance().redeployWarModule(path, webAppName, contextRoot); 503 }else{ 504 Reporter.info("Calling Deploy"); messenger.setProgressMessage( bundle.getString("DeployModuleMessage")); messenger.setProgressLevel(55); 507 deploySuccess = getSelectedInstance().deployWarModule(path, webAppName, contextRoot, true, null, true, false, false); 508 } 509 messenger.setProgressLevel(90); 510 515 messenger.setProgressLevel(100); 516 }catch(AFTargetNotFoundException te){ 517 throw new DeploymentException(te.getLocalizedMessage()); 518 }catch(DeploymentException de){ 520 throw new DeploymentException(de.getLocalizedMessage()); 521 }catch(AFRuntimeStoreException afre){ 523 messenger.ConfigXmlChanged(this.getName()); 524 } 525 }catch(java.net.UnknownHostException e){ 526 throw new DeploymentException(e.getLocalizedMessage()); 527 }catch(java.io.IOException con){ 528 throw new DeploymentException(con.getLocalizedMessage()); 529 } 530 return deploySuccess; 531 } 532 533 public boolean deployEjbJarFile(String ejbJarName, String ejbjarfilePath, UIMessenger messenger) throws DeploymentException { 534 final String path = ejbjarfilePath; 535 Iterator it = null; 536 Reporter.info(ejbjarfilePath); 537 InetAddress IP = null; 538 boolean deploySuccess = true; 539 try{ 540 IP = InetAddress.getByName(this.getAdminHost()); 541 Socket s = new Socket (IP, this.getAdminPort()); 542 s.close (); 543 try{ 544 Reporter.info("EjbJar Name" + ejbJarName); boolean exists = false; 547 try{ 548 it = getSelectedInstance().getDeployedEJBModules(); 549 }catch( AFException e){ 550 throw new DeploymentException(e.getLocalizedMessage()); 551 }catch(AFRuntimeStoreException afre){ 553 throw new AFRuntimeStoreException(afre.getLocalizedMessage()); 554 } 555 messenger.setProgressMessage( bundle.getString("ExsistingModuleCheck")); messenger.setProgressLevel(30); 557 while (it.hasNext()) 558 { 559 depName = it.next().toString(); 560 if(depName.equalsIgnoreCase(ejbJarName)){ 562 exists = true; 563 break; 564 } 565 } 566 messenger.setProgressMessage( bundle.getString("DeployEjbJar")); if(exists){ 568 Reporter.info("Calling Redeploy"); messenger.setProgressMessage( bundle.getString("RedeployModuleMessage")); messenger.setProgressLevel(55); 571 deploySuccess = getSelectedInstance().redeployEJBJarModule(path, ejbJarName); 572 }else{ 573 Reporter.info("Calling Deploy"); messenger.setProgressMessage( bundle.getString("DeployModuleMessage")); messenger.setProgressLevel(55); 576 deploySuccess = getSelectedInstance().deployEJBJarModule(path, ejbJarName); 577 } 578 messenger.setProgressLevel(90); 579 584 messenger.setProgressLevel(100); 585 }catch(AFTargetNotFoundException te){ 586 throw new DeploymentException(te.getLocalizedMessage()); 587 }catch(DeploymentException de){ 589 throw new DeploymentException(de.getLocalizedMessage()); 590 }catch(AFRuntimeStoreException afre){ 592 messenger.ConfigXmlChanged(this.getName()); 593 } 594 }catch(java.net.UnknownHostException e){ 595 throw new DeploymentException(e.getLocalizedMessage()); 596 }catch(java.io.IOException con){ 597 throw new DeploymentException(con.getLocalizedMessage()); 598 } 599 return deploySuccess; 600 } 601 602 603 604 606 public boolean deployRARFile(String rarfilePath, UIMessenger messenger) throws DeploymentException { 607 final String path = rarfilePath; 608 Iterator it = null; 609 Reporter.info(rarfilePath); 610 InetAddress IP = null; 611 boolean deploySuccess = true; 612 try{ 613 IP = InetAddress.getByName(this.getAdminHost()); 614 Socket s = new Socket (IP, this.getAdminPort()); 615 s.close (); 616 try{ 617 String rarName = path.substring(path.lastIndexOf(File.separator)+1, path.lastIndexOf(".")); Reporter.info("rar Name" + rarName); boolean exists = false; 620 try{ 621 it = getSelectedInstance().getDeployedConnectors(); 622 }catch( AFException e){ 623 throw new DeploymentException(e.getLocalizedMessage()); 624 }catch(AFRuntimeStoreException afre){ 626 throw new AFRuntimeStoreException(afre.getLocalizedMessage()); 627 } 628 if(messenger != null) messenger.setProgressMessage( bundle.getString("ExsistingModuleCheck")); if(messenger != null) messenger.setProgressLevel(30); 630 while (it.hasNext()) 631 { 632 depName = it.next().toString(); 633 if(depName.equalsIgnoreCase(rarName)){ 635 exists = true; 636 break; 637 } 638 } 639 if(messenger != null) messenger.setProgressMessage( bundle.getString("DeployRar")); if(exists){ 641 Reporter.info("Calling Redeploy"); if(messenger != null) messenger.setProgressMessage( bundle.getString("RedeployModuleMessage")); deploySuccess = getSelectedInstance().redeployConnectorModule(path, rarName); 644 }else{ 645 Reporter.info("Calling Deploy"); if(messenger != null) messenger.setProgressMessage( bundle.getString("DeployModuleMessage")); deploySuccess = getSelectedInstance().deployConnectorModule(path, rarName); 648 } 649 if(messenger != null) messenger.setProgressLevel(90); 650 655 if(messenger != null) messenger.setProgressLevel(100); 656 }catch(AFTargetNotFoundException te){ 657 throw new DeploymentException(te.getLocalizedMessage()); 658 }catch(DeploymentException de){ 660 throw new DeploymentException(de.getLocalizedMessage()); 661 }catch(AFRuntimeStoreException afre){ 663 messenger.ConfigXmlChanged(this.getName()); 664 } 665 }catch(java.net.UnknownHostException e){ 666 throw new DeploymentException(e.getLocalizedMessage()); 667 }catch(java.io.IOException con){ 668 throw new DeploymentException(con.getLocalizedMessage()); 669 } 670 return deploySuccess; 671 } 672 673 public void registerDatasource (String xmlFile) throws DeploymentException { 674 } 677 678 private void initEngine() throws LoginFailureException { 679 683 } 685 public void removeEngineController(){ 686 } 691 692 697 public void stopInstance(final UIMessenger messenger){ 699 try{ 700 Reporter.info("---------------------stopInstance"); class StopThread extends Thread { 702 public void run () { 703 try{ 704 if(getSelectedInstance().isRunning()){ 705 getSelectedInstance().stop(); 706 } 707 Reporter.info("---------------------AFTER STOP-------------"); }catch(AFTargetNotFoundException te){ 709 messenger.setNotify(te.getLocalizedMessage()); 710 }catch(DeploymentException de){ 711 messenger.setNotify(de.getLocalizedMessage()); 712 }catch(InstanceNotRunningException inre){ 713 messenger.setNotify(inre.getLocalizedMessage()); 714 }catch(ControlException ce){ 715 messenger.setNotify(ce.getLocalizedMessage()); 716 }catch(AFException afe){ 717 messenger.setNotify(afe.getLocalizedMessage()); 718 } 719 720 } 721 } 722 StopThread stop_server = new StopThread(); 723 stop_server.start(); 724 Thread.sleep(500); 725 while(stop_server.isAlive()){ 726 Thread.sleep(1000); 727 } 728 Reporter.info("---------------------After stop server"); }catch(Exception e){ 730 e.printStackTrace(); 731 } 732 } 733 734 public boolean stopInstance() throws AFTargetNotFoundException, InstanceNotRunningException, 735 ControlException, AFException, DeploymentException{ 736 Reporter.info("---------------------STARTANYKJS"); boolean status = false; 738 if(getSelectedInstance().isRunning()) 739 status = getSelectedInstance().stop(); 740 Reporter.info("---------------------AFTER START-------------"); return status; 742 } 743 744 public void restart(){ 745 try{ 746 Reporter.info("---------------------RESTART"); class RestartThread extends Thread { 748 public void run () { 749 try{ 750 getSelectedInstance().restart(); 751 Reporter.info("---------------------AFTER RESTART-------------"); }catch(AFTargetNotFoundException te){ 753 te.printStackTrace(); 755 }catch(DeploymentException de){ 756 de.printStackTrace(); 758 }catch(ControlException ce){ 759 ce.printStackTrace(); 761 }catch(AFException afe){ 762 afe.printStackTrace(); 764 } 765 } 766 } 767 RestartThread restart = new RestartThread(); 768 restart.start(); 769 Reporter.info("---------------------Ready after restart"); }catch(Exception e){ 775 e.printStackTrace(); 776 } 777 778 } 779 780 public void startInstance(final UIMessenger messenger){ 781 try{ 782 Reporter.info("---------------------STARTANYKJS"); class StartThread extends Thread { 784 public void run () { 785 try{ 786 if(!getSelectedInstance().isRunning()){ 787 getSelectedInstance().start(); 788 } 789 Reporter.info("---------------------AFTER START-------------"); }catch(AFTargetNotFoundException te){ 791 messenger.setNotify(te.getLocalizedMessage()); 792 }catch(DeploymentException de){ 793 messenger.setNotify(de.getLocalizedMessage()); 794 }catch(InstanceAlreadyRunningException iare){ 795 messenger.setNotify(iare.getLocalizedMessage()); 796 }catch(ControlException ce){ 797 messenger.setNotify(ce.getLocalizedMessage()); 798 }catch(AFException afe){ 799 messenger.setNotify(afe.getLocalizedMessage()); 800 } 801 } 802 } 803 804 StartThread start_server = new StartThread(); 805 start_server.start(); 806 while(start_server.isAlive()){ 808 Thread.sleep(1000); 809 } 810 Reporter.info("---------------------Ready after start"); }catch(Exception e){ 812 e.printStackTrace(); 813 } 814 815 } 816 817 public boolean startInstance() throws AFTargetNotFoundException, InstanceAlreadyRunningException, 818 ControlException, AFException, DeploymentException{ 819 Reporter.info("---------------------STARTANYKJS"); boolean status = false; 821 if(!getSelectedInstance().isRunning()){ 822 status = getSelectedInstance().start(); 823 } 824 Reporter.info("---------------------AFTER START-------------"); return status; 826 } 828 829 public boolean isRunning() throws AFException, AFTargetNotFoundException, DeploymentException, AFRuntimeStoreException{ 830 instRunning = false; 831 instRunning = getSelectedInstance().isRunning(); 832 return instRunning; 833 } 834 835 public boolean isLocal() throws DeploymentException { 836 try{ 837 String host=InetAddress.getLocalHost().getHostName(); 838 return host.equals (getHost()); 839 } 840 catch(java.net.UnknownHostException e){ 841 throw new DeploymentException(e.getLocalizedMessage()); 842 } 844 } 845 public boolean isUp(){ 846 if (checkAlreadyDone==true) 847 return IAS_Running; 848 checkAlreadyDone = true; 850 Timer aTimer = new Timer(); 851 TimerTask task = new TimerTask(){ 852 public void run() { 853 synchronized (this) { 854 checkAlreadyDone = false; 855 } 856 } 857 858 }; 859 aTimer.schedule(task,2000); 860 return IAS_Running; 861 862 863 } 864 865 866 public static boolean ServName(String value, List serv, String nod_name, HostAndPort hostport,String uName,String passwd){ 867 boolean exists = false; 868 value = value + "(" + nod_name + ")"; for(int i=0; i<serv.size(); i++){ 870 IServerInstanceBean instance = (IServerInstanceBean) serv.get(i); 871 String inst = instance.getName(); 872 if(inst.equals(value)) 873 exists = true; 874 } Iterator it = ServerInstanceManagerFactory.getFactory().getServerInstanceManager(hostport,uName,passwd).getAllServerInstances(); 876 while (it.hasNext()){ 877 String inst1 = ((AppServerInstance)it.next()).toString(); 878 if(inst1.equals(value)) 879 exists = true; 880 } 881 882 return exists; 883 } 884 885 public void Undeploy(final String resName, final String resType, final UIMessenger messenger){ 886 final String server = this.getName(); 887 try{ 888 Reporter.info("---------------------Before Undeploy "); class UndeployThread extends Thread { 890 public void run () { 891 try{ 892 if(resType.trim().indexOf(".ear") != -1){ getSelectedInstance().undeployApplication(resName); 894 }else{ 895 if(resType.trim().indexOf(".war") != -1){ getSelectedInstance().undeployModule(resName, DeploymentConstants.WAR); 897 }else if(resType.trim().indexOf(".jar") != -1){ getSelectedInstance().undeployModule(resName, DeploymentConstants.EJB); 899 }else if(resType.trim().indexOf(".rar") != -1){ getSelectedInstance().undeployModule(resName, DeploymentConstants.RAR); 901 } 902 } getSelectedInstance().applyChanges(); 904 messenger.setStatusText(java.text.MessageFormat.format(bundle.getString("Msg_FinUndeploy"), new Object [] {server}) ); }catch(AFTargetNotFoundException te){ 906 messenger.setNotify(te.getLocalizedMessage()); 907 }catch(AFException afe){ 909 messenger.setNotify(afe.getLocalizedMessage()); 910 }catch(AFRuntimeStoreException afre){ 912 messenger.ConfigXmlChanged(server); 913 } 914 } } 916 UndeployThread undeploy = new UndeployThread(); 917 undeploy.start(); 918 Reporter.info("---------------------After Undeploy"); while(undeploy.isAlive()){ 920 Thread.sleep(500); 921 } 922 923 Reporter.info("---------------------Finished Undeploy"); }catch(Exception e){ 925 e.printStackTrace(); 926 } 927 } 929 public void Apply(final UIMessenger messenger){ 930 final String server = this.getName(); 931 try{ 932 Reporter.info("---------------------Applying changes to Server Instance"); class ApplyThread extends Thread { 934 public void run () { 935 try{ 936 getSelectedInstance().applyChanges(); 937 messenger.setStatusText(java.text.MessageFormat.format(bundle.getString("Msg_Applyed"), new Object [] {server}) ); }catch(AFTargetNotFoundException te){ 939 messenger.setNotify(te.getLocalizedMessage()); 940 }catch(AFException afe){ 942 messenger.setNotify(afe.getLocalizedMessage()); 943 }catch(AFRuntimeStoreException afre){ 945 messenger.ConfigXmlChanged(server); 946 } 947 } } 949 ApplyThread appl = new ApplyThread(); 950 appl.start(); 951 Reporter.info("---------------------After Applying changes to Server Instance"); while(appl.isAlive()){ 953 Thread.sleep(500); 954 } 955 Reporter.info("---------------------Finished Applying changes to Server Instance"); }catch(Exception e){ 957 e.printStackTrace(); 958 } 959 } 961 public void Enable(final String resName, final String resType, final UIMessenger messenger){ 962 final String server = this.getName(); 963 try{ 964 Reporter.info("---------------------Enabling Resource"); class EnableThread extends Thread { 966 public void run () { 967 try{ 968 if(resType.trim().indexOf(".ear") != -1){ DeployedApplicationComponentBean component = getSelectedInstance().getDeployedApplication(resName); 970 component.enable(); 971 }else{ 972 if(resType.trim().indexOf(".jar") != -1){ DeployedEJBModuleComponentBean component = getSelectedInstance().getDeployedEJBModule(resName); 974 component.enable(); 975 }else if(resType.trim().indexOf(".war") != -1){ DeployedWebModuleComponentBean component = getSelectedInstance().getDeployedWebModule(resName); 977 component.enable(); 978 }else{ 979 Reporter.info("####### UNKNOWN Archive Type"); } 981 } getSelectedInstance().applyChanges(); 983 messenger.setStatusText(java.text.MessageFormat.format(bundle.getString("Msg_FinEnable"), new Object [] {server}) ); }catch(AFTargetNotFoundException te){ 985 messenger.setNotify(te.getLocalizedMessage()); 986 }catch(AFException afe){ 988 messenger.setNotify(afe.getLocalizedMessage()); 989 }catch(AFRuntimeStoreException afre){ 991 messenger.ConfigXmlChanged(server); 992 } 993 } } 995 EnableThread enThread = new EnableThread(); 996 enThread.start(); 997 Reporter.info("---------------------After Enabling Resource"); while(enThread.isAlive()){ 999 Thread.sleep(500); 1000 } 1001 Reporter.info("---------------------Finished Enabling Resource"); }catch(Exception e){ 1003 e.printStackTrace(); 1004 } 1005 } 1007 public void Disable(final String resName, final String resType, final UIMessenger messenger){ 1008 final String server = this.getName(); 1009 try{ 1010 Reporter.info("---------------------Before Disabling Resource"); class DisableThread extends Thread { 1012 public void run () { 1013 try{ 1014 if(resType.trim().indexOf(".ear") != -1){ DeployedApplicationComponentBean component = getSelectedInstance().getDeployedApplication(resName); 1016 component.disable(); 1017 }else{ 1018 if(resType.trim().indexOf(".jar") != -1){ DeployedEJBModuleComponentBean component = getSelectedInstance().getDeployedEJBModule(resName); 1020 component.disable(); 1021 }else if(resType.trim().indexOf(".war") != -1){ DeployedWebModuleComponentBean component = getSelectedInstance().getDeployedWebModule(resName); 1023 component.disable(); 1024 }else{ 1025 Reporter.info("####### UNKNOWN Archive Type"); } 1027 } getSelectedInstance().applyChanges(); 1029 messenger.setStatusText(java.text.MessageFormat.format(bundle.getString("Msg_FinDisable"), new Object [] {server}) ); }catch(AFTargetNotFoundException te){ 1031 messenger.setNotify(te.getLocalizedMessage()); 1032 }catch(AFException afe){ 1034 messenger.setNotify(afe.getLocalizedMessage()); 1035 }catch(AFRuntimeStoreException afre){ 1037 messenger.ConfigXmlChanged(server); 1038 } 1039 } } 1041 DisableThread disThread = new DisableThread(); 1042 disThread.start(); 1043 Reporter.info("---------------------After Disabling Resource"); while(disThread.isAlive()){ 1045 Thread.sleep(500); 1046 } 1047 Reporter.info("---------------------Finished Disabling Resource"); }catch(Exception e){ 1049 e.printStackTrace(); 1050 } 1051 } 1053 1054 public boolean isEnabled(final String resName, final String resType, final UIMessenger messenger){ 1055 final String server = this.getName(); 1056 Reporter.info("---------------------Before checking if resource is enabled"); try{ 1058 if(resType.trim().indexOf(".ear") != -1){ DeployedApplicationComponentBean component = getSelectedInstance().getDeployedApplication(resName); 1060 isEnabled = component.isEnabled(); 1061 }else{ 1062 if(resType.trim().indexOf(".war") != -1){ DeployedWebModuleComponentBean component = getSelectedInstance().getDeployedWebModule(resName); 1064 isEnabled = component.isEnabled(); 1065 }else if(resType.trim().indexOf(".jar") != -1){ DeployedEJBModuleComponentBean component = getSelectedInstance().getDeployedEJBModule(resName); 1067 isEnabled = component.isEnabled(); 1068 } 1069 } }catch(AFTargetNotFoundException te){ 1072 messenger.setNotify(te.getLocalizedMessage()); 1073 }catch(AFException afe){ 1075 messenger.setNotify(afe.getLocalizedMessage()); 1076 }catch(AFRuntimeStoreException afre){ 1078 } 1080 1081 Reporter.info("---------------------Finished checking if resource is enabled"); return isEnabled; 1083 } 1085 1086 1087 public void deleteJdbc(final String resourceName, final UIMessenger messenger){ 1088 final String server = this.getName(); 1089 try{ 1090 Reporter.info("---------------------Before deleting Jdbc"); class deleteJdbcThread extends Thread { 1092 public void run () { 1093 try{ 1094 getSelectedInstance().deleteJDBCResource(resourceName); 1095 }catch(DeploymentException de){ 1096 messenger.setNotify(de.getLocalizedMessage()); 1097 }catch(AFTargetNotFoundException te){ 1099 messenger.setNotify(te.getLocalizedMessage()); 1100 }catch(AFException afe){ 1102 messenger.setNotify(afe.getLocalizedMessage()); 1103 }catch(AFRuntimeStoreException afre){ 1105 messenger.ConfigXmlChanged(server); 1106 } 1107 } 1108 } deleteJdbcThread delJdbc = new deleteJdbcThread(); 1110 delJdbc.start(); 1111 Reporter.info("---------------------After deleting Registered Jdbc "); while(delJdbc.isAlive()){ 1113 } 1115 getSelectedInstance().applyChanges(); 1116 Reporter.info("---------------------Finished deleting Registered Jdbc"); }catch(Exception e){ 1118 e.printStackTrace(); 1119 } 1120 } 1122 public void deleteResource(final String resourceName, final String resType, final UIMessenger messenger){ 1123 final String server = this.getName(); 1124 try{ 1125 Reporter.info("---------------------Before deleting resource"); class deleteResourceThread extends Thread { 1127 public void run () { 1128 try{ 1129 if (resType.equals("JDBC")) getSelectedInstance().deleteJDBCResource(resourceName); 1131 else if (resType.equals("CP")) getSelectedInstance().deleteJDBCConnectionPool(resourceName); 1133 else if (resType.equals("JMS")) getSelectedInstance().deleteJMSResource(resourceName); 1135 else if (resType.equals("PMF")) getSelectedInstance().deletePersistenceManagerFactoryResource(resourceName); 1137 else if (resType.equals("Mail")) getSelectedInstance().deleteJavaMailResource(resourceName); 1139 else 1140 Reporter.error(bundle.getString("Err_NoResource")); 1141 }catch(DeploymentException de){ 1142 messenger.setNotify(de.getLocalizedMessage()); 1143 }catch(AFTargetNotFoundException te){ 1145 messenger.setNotify(te.getLocalizedMessage()); 1146 }catch(AFException afe){ 1148 messenger.setNotify(afe.getLocalizedMessage()); 1149 }catch(AFRuntimeStoreException afre){ 1151 messenger.ConfigXmlChanged(server); 1152 } 1153 } 1154 } deleteResourceThread del = new deleteResourceThread(); 1156 del.start(); 1157 Reporter.info("---------------------After deleting registered resource"); while(del.isAlive()){ 1159 } 1161 getSelectedInstance().applyChanges(); 1162 Reporter.info("---------------------Finished deleting Registered Resource"); }catch(Exception e){ 1164 e.printStackTrace(); 1165 } 1166 } 1168 private int debugPort; 1169 public int startInDebugMode(final UIMessenger messenger){ 1170 debugPort = -1; 1171 try{ 1172 Reporter.info("---------------------STARTANYKJS"); class StartDebugThread extends Thread { 1174 public void run() { 1175 try{ 1176 if(!getSelectedInstance().isRunning()){ 1177 1178 debugPort = getSelectedInstance().startInDebugMode(); 1179 } 1180 Reporter.info("---------------------AFTER START-------------"); }catch(AFTargetNotFoundException te){ 1182 messenger.setNotify(te.getLocalizedMessage()); 1183 }catch(DeploymentException de){ 1184 messenger.setNotify(de.getLocalizedMessage()); 1185 }catch(InstanceAlreadyRunningException iare){ 1186 messenger.setNotify(iare.getLocalizedMessage()); 1187 }catch(ControlException ce){ 1188 messenger.setNotify(ce.getLocalizedMessage()); 1189 }catch(AFException afe){ 1190 messenger.setNotify(afe.getLocalizedMessage()); 1191 } 1192 } 1193 } 1194 1195 StartDebugThread debug_server = new StartDebugThread(); 1196 debug_server.start(); 1197 Thread.sleep(500); 1198 1199 while(debug_server.isAlive()){ 1200 Thread.sleep(1000); 1201 } 1202 Reporter.info("---------------------Ready after start"); }catch(Exception e){ 1204 e.printStackTrace(); 1205 } 1206 return debugPort; 1207 } 1208 1209 public int startInDebugMode() throws AFTargetNotFoundException, DeploymentException, ControlException, 1210 InstanceAlreadyRunningException, AFException{ 1211 debugPort = -1; 1212 Reporter.info("---------------------STARTANYKJS"); if(!getSelectedInstance().isRunning()){ 1214 debugPort = getSelectedInstance().startInDebugMode(); 1215 } 1216 Reporter.info("---------------------AFTER START-------------"); return debugPort; 1218 } 1219 1220 public void OverwriteConfig() throws AFException{ 1221 getSelectedInstance().overwriteChanges(); 1222 } 1223 1224 public void useManualConfig() throws AFException{ 1225 getSelectedInstance().useManualChanges(); 1226 } 1227 1228 public int getORBPort() throws AttributeNotFoundException, AccessViolationException,AFTargetNotFoundException, DeploymentException, AFException { 1229 Integer portObj = (Integer ) getSelectedInstance().getORBComponent().getIiopListener("orb-listener-1").getAttribute("port"); int port = portObj.intValue(); 1231 Reporter.verbose("getORBPort() returns " + port); return port; 1233 } 1234 1235 1237 public int getJPDAPortNumber() throws AFException { 1238 int p = getSelectedInstance().getServerStatus().getDebugPort(); 1239 Reporter.verbose("getJPDAPortNumber() returns " + p); return p; 1241 } 1242} 1243 | Popular Tags |