BaseDeployAction.java

00001 
00026 package org.objectweb.jonas.webapp.jonasadmin.deploy;
00027 
00028 import java.util.ArrayList;
00029 import java.util.Properties;
00030 
00031 import javax.management.ObjectName;
00032 import javax.servlet.http.HttpServletRequest;
00033 
00034 import org.objectweb.jonas.jmx.J2eeObjectName;
00035 import org.objectweb.jonas.jmx.JonasManagementRepr;
00036 import org.objectweb.jonas.jmx.JonasObjectName;
00037 import org.objectweb.jonas.webapp.jonasadmin.JonasAdminJmx;
00038 import org.objectweb.jonas.webapp.jonasadmin.JonasBaseAction;
00039 import org.objectweb.jonas.webapp.jonasadmin.JonasTreeBuilder;
00040 import org.objectweb.jonas.webapp.jonasadmin.MBeanTreeBuilder;
00041 import org.objectweb.jonas.webapp.jonasadmin.WhereAreYou;
00042 import org.objectweb.jonas.webapp.taglib.TreeControl;
00043 import org.objectweb.jonas.webapp.taglib.TreeControlNode;
00044 
00049 abstract public class BaseDeployAction extends JonasBaseAction {
00050 
00051 // --------------------------------------------------------- Protected Methods
00052 
00053     protected int getCurrentJonasDeployment()
00054         throws Exception {
00055         int iRet = 0;
00056         iRet = m_WhereAreYou.getCurrentJonasDeploymentType();
00057         return iRet;
00058     }
00059 
00060     protected void setCurrentJonasDeployment(HttpServletRequest p_Request)
00061         throws Exception {
00062         int iDeployment = 0;
00063         String sDeployment = p_Request.getParameter("type");
00064         if (sDeployment != null) {
00065             // Dispatch
00066             if (sDeployment.equals(WhereAreYou.DEPLOYMENT_STRING_EAR) == true) {
00067                 iDeployment = WhereAreYou.DEPLOYMENT_EAR;
00068             }
00069             else if (sDeployment.equals(WhereAreYou.DEPLOYMENT_STRING_JAR) == true) {
00070                 iDeployment = WhereAreYou.DEPLOYMENT_JAR;
00071             }
00072             else if (sDeployment.equals(WhereAreYou.DEPLOYMENT_STRING_WAR) == true) {
00073                 iDeployment = WhereAreYou.DEPLOYMENT_WAR;
00074             }
00075             else if (sDeployment.equals(WhereAreYou.DEPLOYMENT_STRING_RAR) == true) {
00076                 iDeployment = WhereAreYou.DEPLOYMENT_RAR;
00077             }
00078             else if (sDeployment.equals(WhereAreYou.DEPLOYMENT_STRING_DATASOURCE) == true) {
00079                 iDeployment = WhereAreYou.DEPLOYMENT_DATASOURCE;
00080             }
00081             else if (sDeployment.equals(WhereAreYou.DEPLOYMENT_STRING_MAILFACTORY) == true) {
00082                 iDeployment = WhereAreYou.DEPLOYMENT_MAIL;
00083             }
00084             else {
00085                 throw new Exception("Unknown type deployment");
00086             }
00087             // Storing
00088             m_WhereAreYou.setCurrentJonasDeploymentType(iDeployment);
00089         }
00090     }
00091 
00097     protected String getForwardEdit() {
00098         String sForward = null;
00099         try {
00100             switch (getCurrentJonasDeployment()) {
00101                 case WhereAreYou.DEPLOYMENT_EAR:
00102                 case WhereAreYou.DEPLOYMENT_JAR:
00103                 case WhereAreYou.DEPLOYMENT_WAR:
00104                 case WhereAreYou.DEPLOYMENT_RAR:
00105                     sForward = "Deploy";
00106                     break;
00107                 case WhereAreYou.DEPLOYMENT_DATASOURCE:
00108                     sForward = "Deploy Datasource";
00109                     break;
00110                 case WhereAreYou.DEPLOYMENT_MAIL:
00111                     sForward = "Deploy Mail Factory";
00112                     break;
00113             }
00114         }
00115         catch (Exception e) {
00116             // none
00117         }
00118         return sForward;
00119     }
00120 
00128     protected ArrayList getListDeployableFiles()
00129         throws Exception {
00130         ArrayList al = null;
00131         switch (getCurrentJonasDeployment()) {
00132             case WhereAreYou.DEPLOYMENT_EAR:
00133                 al = JonasAdminJmx.getEarFilesDeployable();
00134                 break;
00135             case WhereAreYou.DEPLOYMENT_JAR:
00136                 al = JonasAdminJmx.getJarFilesDeployable();
00137                 break;
00138             case WhereAreYou.DEPLOYMENT_WAR:
00139                 al = JonasAdminJmx.getWarFilesDeployable();
00140                 break;
00141             case WhereAreYou.DEPLOYMENT_RAR:
00142                 al = JonasAdminJmx.getRarFilesDeployable();
00143                 break;
00144             case WhereAreYou.DEPLOYMENT_DATASOURCE:
00145                 al = JonasAdminJmx.getDatasourceFilesDeployable();
00146                 break;
00147             case WhereAreYou.DEPLOYMENT_MAIL:
00148                 al = JonasAdminJmx.getMailFilesDeployable();
00149                 break;
00150         }
00151         return al;
00152     }
00153 
00161     protected ArrayList getListDeployedFiles()
00162         throws Exception {
00163         ArrayList al = null;
00164         switch (getCurrentJonasDeployment()) {
00165             case WhereAreYou.DEPLOYMENT_EAR:
00166                 al = JonasAdminJmx.getEarFilesDeployed();
00167                 break;
00168             case WhereAreYou.DEPLOYMENT_JAR:
00169                 al = JonasAdminJmx.getJarFilesDeployed();
00170                 break;
00171             case WhereAreYou.DEPLOYMENT_RAR:
00172                 al = JonasAdminJmx.getRarFilesDeployed();
00173                 break;
00174             case WhereAreYou.DEPLOYMENT_WAR:
00175                 al = JonasAdminJmx.getWarFilesDeployed();
00176                 break;
00177             case WhereAreYou.DEPLOYMENT_DATASOURCE:
00178                 String domainName = m_WhereAreYou.getCurrentDomainName();
00179                 String serverName = m_WhereAreYou.getCurrentJonasServerName();
00180                 al = JonasAdminJmx.getDatasourceFilesDeployed(domainName, serverName);
00181                 break;
00182             case WhereAreYou.DEPLOYMENT_MAIL:
00183                 al = JonasAdminJmx.getMailFilesDeployed(m_WhereAreYou);
00184                 break;
00185         }
00186         return al;
00187     }
00188 
00196     protected void undeploy(String p_Filename)
00197         throws Exception {
00198         String[] asParam = new String[1];
00199         asParam[0] = p_Filename;
00200         String[] asSignature = new String[1];
00201         asSignature[0] = "java.lang.String";
00202 
00203         switch (getCurrentJonasDeployment()) {
00204             case WhereAreYou.DEPLOYMENT_EAR:
00205                 JonasManagementRepr.invoke(JonasObjectName.earService(), "unDeployEarMBean"
00206                     , asParam, asSignature);
00207                 break;
00208             case WhereAreYou.DEPLOYMENT_JAR:
00209                 JonasManagementRepr.invoke(JonasObjectName.ejbService(), "removeContainerMBean", asParam
00210                     , asSignature);
00211                 break;
00212             case WhereAreYou.DEPLOYMENT_RAR:
00213                 JonasManagementRepr.invoke(JonasObjectName.resourceService(), "unDeployRarMBean"
00214                     , asParam, asSignature);
00215                 break;
00216             case WhereAreYou.DEPLOYMENT_WAR:
00217                 JonasManagementRepr.invoke(JonasObjectName.webContainerService()
00218                     , "unRegisterWarMBean", asParam, asSignature);
00219                 break;
00220             case WhereAreYou.DEPLOYMENT_DATASOURCE:
00221                 undeployDataSource(p_Filename);
00222                 break;
00223             case WhereAreYou.DEPLOYMENT_MAIL:
00224                 undeployMailFactory(p_Filename);
00225                 break;
00226         }
00227     }
00228 
00235     protected void undeployDataSource(String p_Filename)
00236         throws Exception {
00237         ArrayList al = JonasAdminJmx.getDatasourceDependences(p_Filename
00238                 , m_WhereAreYou.getCurrentDomainName()
00239                 , m_WhereAreYou.getCurrentJonasServerName());
00240         if (al.size() == 0) {
00241             String[] asParam = new String[1];
00242             asParam[0] = p_Filename;
00243             String[] asSignature = new String[1];
00244             asSignature[0] = "java.lang.String";
00245             JonasManagementRepr.invoke(JonasObjectName.databaseService(), "unloadDataSource"
00246                 , asParam, asSignature);
00247         }
00248         else {
00249             throw new Exception(m_Resources.getMessage("error.undeploy.datasource.dependences"
00250                 , al.toString()));
00251         }
00252     }
00253 
00260     protected void undeployMailFactory(String p_Filename)
00261         throws Exception {
00262         ArrayList al = JonasAdminJmx.getMailFactoryDependences(p_Filename, m_WhereAreYou);
00263         if (al.size() == 0) {
00264             String[] asParam = new String[1];
00265             asParam[0] = p_Filename;
00266             String[] asSignature = new String[1];
00267             asSignature[0] = "java.lang.String";
00268             JonasManagementRepr.invoke(JonasObjectName.mailService(), "unbindMailFactoryMBean"
00269                 , asParam, asSignature);
00270         }
00271         else {
00272             throw new Exception(m_Resources.getMessage("error.undeploy.mailfactory.dependences"
00273                 , al.toString()));
00274         }
00275     }
00276 
00284     protected void deploy(String p_Filename)
00285         throws Exception {
00286         String[] asParam = new String[1];
00287         asParam[0] = p_Filename;
00288         String[] asSignature = new String[1];
00289         asSignature[0] = "java.lang.String";
00290 
00291         switch (getCurrentJonasDeployment()) {
00292             case WhereAreYou.DEPLOYMENT_EAR:
00293                 JonasManagementRepr.invoke(JonasObjectName.earService(), "deployEarMBean", asParam
00294                     , asSignature);
00295                 break;
00296             case WhereAreYou.DEPLOYMENT_JAR:
00297                 JonasManagementRepr.invoke(JonasObjectName.ejbService(), "createContainerMBean", asParam
00298                     , asSignature);
00299                 break;
00300             case WhereAreYou.DEPLOYMENT_RAR:
00301                 JonasManagementRepr.invoke(JonasObjectName.resourceService(), "deployRarMBean"
00302                     , asParam, asSignature);
00303                 break;
00304             case WhereAreYou.DEPLOYMENT_WAR:
00305                 JonasManagementRepr.invoke(JonasObjectName.webContainerService()
00306                     , "registerWarMBean", asParam, asSignature);
00307                 break;
00308             case WhereAreYou.DEPLOYMENT_DATASOURCE:
00309                 deployDataSource(p_Filename);
00310                 break;
00311             case WhereAreYou.DEPLOYMENT_MAIL:
00312                 deployMailFactory(p_Filename);
00313                 break;
00314         }
00315     }
00316 
00323     protected void deployDataSource(String p_Filename)
00324         throws Exception {
00325 
00326         String[] asParam = new String[1];
00327         String[] asSignature = new String[1];
00328         asParam[0] = p_Filename;
00329         asSignature[0] = "java.lang.String";
00330 
00331         ObjectName onDb = JonasObjectName.databaseService();
00332         // Verify if datasource already loaded
00333         Boolean oLoaded = (Boolean) JonasManagementRepr.invoke(onDb, "isLoadedDataSource", asParam
00334             , asSignature);
00335         if (oLoaded.booleanValue() == false) {
00336             // Get Datasource properties file
00337             Properties oProps = (Properties) JonasManagementRepr.invoke(onDb
00338                 , "getDataSourcePropertiesFile", asParam, asSignature);
00339             // Load Datasource
00340             Object[] aoParam = {
00341                 p_Filename, oProps, new Boolean(true)};
00342             String[] asSign_3 = {
00343                 "java.lang.String", "java.util.Properties", "java.lang.Boolean"};
00344             JonasManagementRepr.invoke(onDb, "loadDataSource", aoParam, asSign_3);
00345         }
00346         else {
00347             throw new Exception(m_Resources.getMessage("error.deploy.datasource.isloaded"));
00348         }
00349     }
00350 
00357     protected void deployMailFactory(String p_Filename)
00358         throws Exception {
00359 
00360         String[] asParam = new String[1];
00361         String[] asSignature = new String[1];
00362         asParam[0] = p_Filename;
00363         asSignature[0] = "java.lang.String";
00364 
00365         ObjectName onMail = JonasObjectName.mailService();
00366         // Get mail factory properties file
00367         Properties oProps = (Properties) JonasManagementRepr.invoke(onMail
00368             , "getMailFactoryPropertiesFile", asParam, asSignature);
00369         // Load mail factory
00370         Object[] aoParam = {
00371             p_Filename, oProps, new Boolean(true)};
00372         String[] asSign_3 = {
00373             "java.lang.String", "java.util.Properties", "java.lang.Boolean"};
00374         JonasManagementRepr.invoke(onMail, "createMailFactoryMBean", aoParam, asSign_3);
00375     }
00376 
00382     protected void runGC()
00383         throws Exception {
00384         ObjectName oObjectName = J2eeObjectName.J2EEServer(m_WhereAreYou.getCurrentDomainName()
00385             , m_WhereAreYou.getCurrentJonasServerName());
00386         JonasManagementRepr.invoke(oObjectName, "runGC", null, null);
00387     }
00388 
00395     protected void refreshTree(HttpServletRequest p_Request) throws Exception {
00396         // Refresh Service Tree
00397         switch (getCurrentJonasDeployment()) {
00398             case WhereAreYou.DEPLOYMENT_EAR:
00399                 refreshServiceTree(WhereAreYou.DEPLOYMENT_EAR, p_Request);
00400                 if (JonasAdminJmx.hasMBeanName(JonasObjectName.ejbService()) == true) {
00401                     refreshServiceTree(WhereAreYou.DEPLOYMENT_JAR, p_Request);
00402                 }
00403                 if (JonasAdminJmx.hasMBeanName(JonasObjectName.webContainerService()) == true) {
00404                     refreshServiceTree(WhereAreYou.DEPLOYMENT_WAR, p_Request);
00405                 }
00406                 if (JonasAdminJmx.hasMBeanName(JonasObjectName.resourceService()) == true) {
00407                     refreshServiceTree(WhereAreYou.DEPLOYMENT_RAR, p_Request);
00408                 }
00409                 break;
00410             case WhereAreYou.DEPLOYMENT_JAR:
00411                 refreshServiceTree(WhereAreYou.DEPLOYMENT_JAR, p_Request);
00412                 break;
00413             case WhereAreYou.DEPLOYMENT_WAR:
00414                 refreshServiceTree(WhereAreYou.DEPLOYMENT_WAR, p_Request);
00415                 break;
00416             case WhereAreYou.DEPLOYMENT_RAR:
00417                 refreshServiceTree(WhereAreYou.DEPLOYMENT_RAR, p_Request);
00418                 refreshJoramTree();
00419                 break;
00420             case WhereAreYou.DEPLOYMENT_DATASOURCE:
00421                 refreshServiceTree(WhereAreYou.DEPLOYMENT_DATASOURCE, p_Request);
00422                 break;
00423             case WhereAreYou.DEPLOYMENT_MAIL:
00424                 refreshServiceTree(WhereAreYou.DEPLOYMENT_MAIL, p_Request);
00425                 break;
00426         }
00427         // Refresh MBeans Tree
00428         refreshMBeansTree();
00429         // Force display to refresh
00430         m_WhereAreYou.setTreeToRefresh(true);
00431     }
00432 
00440     protected void refreshServiceTree(int p_Deployment, HttpServletRequest p_Request)
00441         throws Exception {
00442         // Get the domain and server name
00443         String sDomainName = m_WhereAreYou.getCurrentDomainName();
00444         String sServerName = m_WhereAreYou.getCurrentJonasServerName();
00445         // Get the service name
00446         String sCurrentNodeNameServiceItem = null;
00447         switch (p_Deployment) {
00448             case WhereAreYou.DEPLOYMENT_EAR:
00449                 sCurrentNodeNameServiceItem = sDomainName + WhereAreYou.NODE_SEPARATOR
00450                     + sServerName + WhereAreYou.NODE_SEPARATOR + "services"
00451                     + WhereAreYou.NODE_SEPARATOR + "ear";
00452                 break;
00453             case WhereAreYou.DEPLOYMENT_JAR:
00454                 sCurrentNodeNameServiceItem = sDomainName + WhereAreYou.NODE_SEPARATOR
00455                     + sServerName + WhereAreYou.NODE_SEPARATOR + "services"
00456                     + WhereAreYou.NODE_SEPARATOR + "ejbContainers";
00457                 break;
00458             case WhereAreYou.DEPLOYMENT_RAR:
00459                 sCurrentNodeNameServiceItem = sDomainName + WhereAreYou.NODE_SEPARATOR
00460                     + sServerName + WhereAreYou.NODE_SEPARATOR + "services"
00461                     + WhereAreYou.NODE_SEPARATOR + "resourceAdapter";
00462                 break;
00463             case WhereAreYou.DEPLOYMENT_WAR:
00464                 sCurrentNodeNameServiceItem = sDomainName + WhereAreYou.NODE_SEPARATOR
00465                     + sServerName + WhereAreYou.NODE_SEPARATOR + "services"
00466                     + WhereAreYou.NODE_SEPARATOR + "web";
00467                 break;
00468             case WhereAreYou.DEPLOYMENT_DATASOURCE:
00469                 sCurrentNodeNameServiceItem = sDomainName + WhereAreYou.NODE_SEPARATOR
00470                     + sServerName + WhereAreYou.NODE_SEPARATOR + "services"
00471                     + WhereAreYou.NODE_SEPARATOR + "database";
00472                 break;
00473             case WhereAreYou.DEPLOYMENT_MAIL:
00474                 sCurrentNodeNameServiceItem = sDomainName + WhereAreYou.NODE_SEPARATOR
00475                     + sServerName + WhereAreYou.NODE_SEPARATOR + "services"
00476                     + WhereAreYou.NODE_SEPARATOR + "mail";
00477                 break;
00478             case WhereAreYou.DEPLOYMENT_JMS:
00479                 sCurrentNodeNameServiceItem = sDomainName + WhereAreYou.NODE_SEPARATOR
00480                     + sServerName + WhereAreYou.NODE_SEPARATOR + "services"
00481                     + WhereAreYou.NODE_SEPARATOR + "jms";
00482                 break;
00483         }
00484         // Get current tree
00485         TreeControl oControl = m_WhereAreYou.getTreeControl();
00486         // Get service node
00487         TreeControlNode oServiceNode = oControl.findNode(sCurrentNodeNameServiceItem);
00488         // Enable auto-refresh mode
00489         oControl.enableAutoRefresh();
00490         // Remove old children
00491         TreeControlNode[] aoNodes = oServiceNode.findChildren();
00492         for (int i = 0; i < aoNodes.length; i++) {
00493             aoNodes[i].remove();
00494         }
00495         // Build node for the Service
00496         JonasTreeBuilder oBuilder = new JonasTreeBuilder();
00497         switch (p_Deployment) {
00498             case WhereAreYou.DEPLOYMENT_EAR:
00499                 oBuilder.getAppContainers(oServiceNode, m_Resources, sDomainName, sServerName);
00500                 break;
00501             case WhereAreYou.DEPLOYMENT_JAR:
00502                 oBuilder.getContainers(oServiceNode, m_Resources, sDomainName, sServerName);
00503                 break;
00504             case WhereAreYou.DEPLOYMENT_RAR:
00505                 oBuilder.getResourcesAdapters(oServiceNode, m_Resources);
00506                 break;
00507             case WhereAreYou.DEPLOYMENT_WAR:
00508                 oBuilder.getWebContainers(oServiceNode, m_Resources, p_Request);
00509                 break;
00510             case WhereAreYou.DEPLOYMENT_DATASOURCE:
00511                 oBuilder.getDatasources(oServiceNode, m_Resources, sDomainName, sServerName);
00512                 break;
00513             case WhereAreYou.DEPLOYMENT_JMS:
00514                 oBuilder.getJmsResources(oServiceNode, m_Resources);
00515                 break;
00516             case WhereAreYou.DEPLOYMENT_MAIL:
00517                 oBuilder.getAllSessionMailFactories(oServiceNode, m_Resources, p_Request);
00518                 oBuilder.getAllMimePartDSMailFactories(oServiceNode, m_Resources, p_Request);
00519                 break;
00520         }
00521         // Disable auto-refresh mode
00522         oControl.disableAutoRefresh();
00523     }
00524 
00530     protected void refreshMBeansTree() throws Exception {
00531         // Get current tree
00532         TreeControl oControl = m_WhereAreYou.getTreeControl();
00533         // MBeans node present ?
00534         TreeControlNode oMBeansNode = oControl.findNode("mbeans");
00535         if (oMBeansNode != null) {
00536             // Enable auto-refresh mode
00537             oControl.enableAutoRefresh();
00538             // Remove node
00539             oMBeansNode.remove();
00540             // Build node and his children
00541             MBeanTreeBuilder oBuilder = new MBeanTreeBuilder();
00542             oBuilder.getMBeans(oControl.getRoot(), m_Resources);
00543             // Disable auto-refresh mode
00544             oControl.disableAutoRefresh();
00545         }
00546     }
00547 
00553     protected void refreshJoramTree() throws Exception {
00554         // Get current tree
00555         TreeControl oControl = m_WhereAreYou.getTreeControl();
00556         // Joram node present ?
00557         String sNodeName = m_WhereAreYou.getCurrentDomainName() + WhereAreYou.NODE_SEPARATOR + "joramplatform";
00558         TreeControlNode oJoramNode = oControl.findNode(sNodeName);
00559         if (oJoramNode != null) {
00560             TreeControlNode parentNode = oJoramNode.getParent();
00561             // Enable auto-refresh mode
00562             oControl.enableAutoRefresh();
00563             // Remove node
00564             oJoramNode.remove();
00565             // Build node and his children
00566             JonasTreeBuilder oBuilder = new JonasTreeBuilder();
00567             oBuilder.getJoramPlatform(parentNode, m_Resources);
00568             // Disable auto-refresh mode
00569             oControl.disableAutoRefresh();
00570         } else {
00571             // Construct tree if necessary
00572             String sDomainName = m_WhereAreYou.getCurrentDomainName();
00573             TreeControlNode oDomainNode = oControl.findNode(sDomainName);
00574             // Enable auto-refresh mode
00575             oControl.enableAutoRefresh();
00576             // Build node and his children
00577             JonasTreeBuilder oBuilder = new JonasTreeBuilder();
00578             oBuilder.getJoramPlatform(oDomainNode, m_Resources);
00579             // Disable auto-refresh mode
00580             oControl.disableAutoRefresh();
00581         }
00582     }
00583 }

Generated on Tue Feb 15 15:05:26 2005 for JOnAS by  doxygen 1.3.9.1