001: /**
002: * JOnAS: Java(TM) Open Application Server
003: * Copyright (C) 1999-2004 Bull S.A.
004: * Contact: jonas-team@objectweb.org
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
019: * USA
020: *
021: * --------------------------------------------------------------------------
022: * $Id: BaseDeployAction.java 9753 2006-10-17 12:52:55Z danesa $
023: * --------------------------------------------------------------------------
024: */package org.objectweb.jonas.webapp.jonasadmin.deploy;
025:
026: import java.util.ArrayList;
027: import java.util.Iterator;
028: import java.util.Properties;
029:
030: import javax.management.MBeanServerConnection;
031: import javax.management.ObjectName;
032: import javax.servlet.http.HttpServletRequest;
033:
034: import org.objectweb.jonas.jmx.J2eeObjectName;
035: import org.objectweb.jonas.jmx.JonasManagementRepr;
036: import org.objectweb.jonas.jmx.JonasObjectName;
037: import org.objectweb.jonas.jmx.JoramObjectName;
038: import org.objectweb.jonas.jmx.ManagementReprImplJSR160;
039: import org.objectweb.jonas.webapp.jonasadmin.JonasAdminJmx;
040: import org.objectweb.jonas.webapp.jonasadmin.JonasBaseAction;
041: import org.objectweb.jonas.webapp.jonasadmin.JonasTreeBuilder;
042: import org.objectweb.jonas.webapp.jonasadmin.WhereAreYou;
043: import org.objectweb.jonas.webapp.taglib.TreeControl;
044: import org.objectweb.jonas.webapp.taglib.TreeControlNode;
045:
046: /**
047: * @author Michel-Ange ANTON
048: */
049:
050: abstract public class BaseDeployAction extends JonasBaseAction {
051:
052: // --------------------------------------------------------- Protected Methods
053:
054: protected int getCurrentJonasDeployment() throws Exception {
055: int iRet = 0;
056: iRet = m_WhereAreYou.getCurrentJonasDeploymentType();
057: return iRet;
058: }
059:
060: protected void setCurrentJonasDeployment(
061: HttpServletRequest p_Request) throws Exception {
062: int iDeployment = 0;
063: String sDeployment = p_Request.getParameter("type");
064: if (sDeployment != null) {
065: // Dispatch
066: if (sDeployment.equals(WhereAreYou.DEPLOYMENT_STRING_EAR) == true) {
067: iDeployment = WhereAreYou.DEPLOYMENT_EAR;
068: } else if (sDeployment
069: .equals(WhereAreYou.DEPLOYMENT_STRING_JAR) == true) {
070: iDeployment = WhereAreYou.DEPLOYMENT_JAR;
071: } else if (sDeployment
072: .equals(WhereAreYou.DEPLOYMENT_STRING_WAR) == true) {
073: iDeployment = WhereAreYou.DEPLOYMENT_WAR;
074: } else if (sDeployment
075: .equals(WhereAreYou.DEPLOYMENT_STRING_RAR) == true) {
076: iDeployment = WhereAreYou.DEPLOYMENT_RAR;
077: } else if (sDeployment
078: .equals(WhereAreYou.DEPLOYMENT_STRING_DATASOURCE) == true) {
079: iDeployment = WhereAreYou.DEPLOYMENT_DATASOURCE;
080: } else if (sDeployment
081: .equals(WhereAreYou.DEPLOYMENT_STRING_MAILFACTORY) == true) {
082: iDeployment = WhereAreYou.DEPLOYMENT_MAIL;
083: } else if (sDeployment
084: .equals(WhereAreYou.DOMAIN_DEPLOYMENT_STRING_EAR) == true) {
085: iDeployment = WhereAreYou.DOMAIN_DEPLOYMENT_EAR;
086: } else if (sDeployment
087: .equals(WhereAreYou.DOMAIN_DEPLOYMENT_STRING_JAR) == true) {
088: iDeployment = WhereAreYou.DOMAIN_DEPLOYMENT_JAR;
089: } else if (sDeployment
090: .equals(WhereAreYou.DOMAIN_DEPLOYMENT_STRING_WAR) == true) {
091: iDeployment = WhereAreYou.DOMAIN_DEPLOYMENT_WAR;
092: } else if (sDeployment
093: .equals(WhereAreYou.DOMAIN_DEPLOYMENT_STRING_RAR) == true) {
094: iDeployment = WhereAreYou.DOMAIN_DEPLOYMENT_RAR;
095: } else {
096: throw new Exception("Unknown type deployment");
097: }
098: // Storing
099: m_WhereAreYou.setCurrentJonasDeploymentType(iDeployment);
100: }
101: }
102:
103: /**
104: * Return the edit forward string.
105: *
106: * @return The edit forward string
107: */
108: protected String getForwardEdit() {
109: String sForward = null;
110: try {
111: switch (getCurrentJonasDeployment()) {
112: case WhereAreYou.DEPLOYMENT_EAR:
113: case WhereAreYou.DEPLOYMENT_JAR:
114: case WhereAreYou.DEPLOYMENT_WAR:
115: case WhereAreYou.DEPLOYMENT_RAR:
116: sForward = "Deploy";
117: break;
118: case WhereAreYou.DOMAIN_DEPLOYMENT_EAR:
119: case WhereAreYou.DOMAIN_DEPLOYMENT_JAR:
120: case WhereAreYou.DOMAIN_DEPLOYMENT_WAR:
121: case WhereAreYou.DOMAIN_DEPLOYMENT_RAR:
122: sForward = "Domain Deploy";
123: break;
124: case WhereAreYou.DEPLOYMENT_DATASOURCE:
125: sForward = "Deploy Datasource";
126: break;
127: case WhereAreYou.DEPLOYMENT_MAIL:
128: sForward = "Deploy Mail Factory";
129: break;
130: }
131: } catch (Exception e) {
132: // none
133: }
134: return sForward;
135: }
136:
137: protected boolean isDomain() {
138: boolean result = false;
139: try {
140: switch (getCurrentJonasDeployment()) {
141: case WhereAreYou.DOMAIN_DEPLOYMENT_EAR:
142: case WhereAreYou.DOMAIN_DEPLOYMENT_JAR:
143: case WhereAreYou.DOMAIN_DEPLOYMENT_WAR:
144: case WhereAreYou.DOMAIN_DEPLOYMENT_RAR:
145: result = true;
146: break;
147: }
148: } catch (Exception e) {
149: // none
150: }
151: return result;
152: }
153:
154: protected boolean isConfigurable() {
155: boolean result = false;
156: try {
157: switch (getCurrentJonasDeployment()) {
158: case WhereAreYou.DOMAIN_DEPLOYMENT_RAR:
159: case WhereAreYou.DEPLOYMENT_RAR:
160: result = true;
161: break;
162: }
163: } catch (Exception e) {
164: // none
165: }
166: return result;
167: }
168:
169: protected boolean isModule() {
170: boolean result = false;
171: try {
172: switch (getCurrentJonasDeployment()) {
173: case WhereAreYou.DEPLOYMENT_JAR:
174: case WhereAreYou.DEPLOYMENT_WAR:
175: case WhereAreYou.DEPLOYMENT_EAR:
176: case WhereAreYou.DEPLOYMENT_RAR:
177: result = true;
178: break;
179: }
180: } catch (Exception e) {
181: // none
182: }
183: return result;
184: }
185:
186: protected String getDomainDeploymentMethodName() {
187: String result = "";
188: try {
189: switch (getCurrentJonasDeployment()) {
190: case WhereAreYou.DOMAIN_DEPLOYMENT_EAR:
191: result = "deployEar";
192: break;
193: case WhereAreYou.DOMAIN_DEPLOYMENT_JAR:
194: result = "deployJar";
195: break;
196: case WhereAreYou.DOMAIN_DEPLOYMENT_WAR:
197: result = "deployWar";
198: break;
199: case WhereAreYou.DOMAIN_DEPLOYMENT_RAR:
200: result = "deployRar";
201: break;
202: }
203: } catch (Exception e) {
204: // none
205: }
206: return result;
207: }
208:
209: protected String getDomainUploadDeployMethodName() {
210: String result = "";
211: try {
212: switch (getCurrentJonasDeployment()) {
213: case WhereAreYou.DOMAIN_DEPLOYMENT_EAR:
214: result = "uploadDeployEar";
215: break;
216: case WhereAreYou.DOMAIN_DEPLOYMENT_JAR:
217: result = "uploadDeployJar";
218: break;
219: case WhereAreYou.DOMAIN_DEPLOYMENT_WAR:
220: result = "uploadDeployWar";
221: break;
222: case WhereAreYou.DOMAIN_DEPLOYMENT_RAR:
223: result = "uploadDeployRar";
224: break;
225: }
226: } catch (Exception e) {
227: // none
228: }
229: return result;
230: }
231:
232: /**
233: * Return the list of deployable files in using the type of current
234: * deployment storing in WhereAreYou instance in session.
235: *
236: * @return The list of deployable files
237: * @throws Exception
238: */
239: protected ArrayList getListDeployableFiles() throws Exception {
240: ArrayList al = null;
241: String serverName = m_WhereAreYou.getCurrentJonasServerName();
242: switch (getCurrentJonasDeployment()) {
243: case WhereAreYou.DEPLOYMENT_EAR:
244: al = JonasAdminJmx.getEarFilesDeployable(serverName);
245: break;
246: case WhereAreYou.DEPLOYMENT_JAR:
247: al = JonasAdminJmx.getJarFilesDeployable(serverName);
248: break;
249: case WhereAreYou.DEPLOYMENT_WAR:
250: al = JonasAdminJmx.getWarFilesDeployable(serverName);
251: break;
252: case WhereAreYou.DEPLOYMENT_RAR:
253: al = JonasAdminJmx.getRarFilesDeployable(serverName);
254: break;
255: case WhereAreYou.DOMAIN_DEPLOYMENT_EAR:
256: al = JonasAdminJmx.getEarFilesDeployable(serverName);
257: al.addAll(JonasAdminJmx.getEarFilesDeployed(serverName));
258: break;
259: case WhereAreYou.DOMAIN_DEPLOYMENT_JAR:
260: al = JonasAdminJmx.getJarFilesDeployable(serverName);
261: al.addAll(JonasAdminJmx.getJarFilesDeployed(serverName));
262: break;
263: case WhereAreYou.DOMAIN_DEPLOYMENT_WAR:
264: al = JonasAdminJmx.getWarFilesDeployable(serverName);
265: al.addAll(JonasAdminJmx.getWarFilesDeployed(serverName));
266: break;
267: case WhereAreYou.DOMAIN_DEPLOYMENT_RAR:
268: al = JonasAdminJmx.getRarFilesDeployable(serverName);
269: al.addAll(JonasAdminJmx.getRarFilesDeployed(serverName));
270: break;
271: case WhereAreYou.DEPLOYMENT_DATASOURCE:
272: al = JonasAdminJmx.getDatasourceFilesDeployable(serverName);
273: break;
274: case WhereAreYou.DEPLOYMENT_MAIL:
275: al = JonasAdminJmx.getMailFilesDeployable(serverName);
276: break;
277: }
278: return al;
279: }
280:
281: /**
282: * Return the list of deployed files in using the type of current deployment
283: * storing in WhereAreYou instance in session.
284: *
285: * @return The list of deployed files
286: * @throws Exception
287: */
288: protected ArrayList getListDeployedFiles() throws Exception {
289: String serverName = m_WhereAreYou.getCurrentJonasServerName();
290: ArrayList al = null;
291: switch (getCurrentJonasDeployment()) {
292: case WhereAreYou.DEPLOYMENT_EAR:
293: al = JonasAdminJmx.getEarFilesDeployed(serverName);
294: break;
295: case WhereAreYou.DEPLOYMENT_JAR:
296: al = JonasAdminJmx.getJarFilesDeployed(serverName);
297: break;
298: case WhereAreYou.DEPLOYMENT_RAR:
299: al = JonasAdminJmx.getRarFilesDeployed(serverName);
300: break;
301: case WhereAreYou.DEPLOYMENT_WAR:
302: al = JonasAdminJmx.getWarFilesDeployed(serverName);
303: break;
304: case WhereAreYou.DEPLOYMENT_DATASOURCE:
305: String domainName = m_WhereAreYou.getCurrentDomainName();
306: al = JonasAdminJmx.getDatasourceFilesDeployed(domainName,
307: serverName);
308: break;
309: case WhereAreYou.DEPLOYMENT_MAIL:
310: al = JonasAdminJmx.getMailFilesDeployed(m_WhereAreYou);
311: break;
312: }
313: return al;
314: }
315:
316: /**
317: * Undeploy a file in using the type of current deployment
318: * storing in WhereAreYou instance in session.
319: *
320: * @param p_Filename Name of file to undeploy
321: * @throws Exception
322: */
323: protected void undeploy(String p_Filename) throws Exception {
324: String[] asParam = new String[1];
325: asParam[0] = p_Filename;
326: String[] asSignature = new String[1];
327: asSignature[0] = "java.lang.String";
328: String serverName = m_WhereAreYou.getCurrentJonasServerName();
329: switch (getCurrentJonasDeployment()) {
330: case WhereAreYou.DEPLOYMENT_EAR:
331: JonasManagementRepr.invoke(JonasObjectName.earService(),
332: "unDeployEarMBean", asParam, asSignature,
333: serverName);
334: break;
335: case WhereAreYou.DEPLOYMENT_JAR:
336: JonasManagementRepr.invoke(JonasObjectName.ejbService(),
337: "removeContainerMBean", asParam, asSignature,
338: serverName);
339: break;
340: case WhereAreYou.DEPLOYMENT_RAR:
341: JonasManagementRepr.invoke(JonasObjectName
342: .resourceService(), "unDeployRarMBean", asParam,
343: asSignature, serverName);
344: break;
345: case WhereAreYou.DEPLOYMENT_WAR:
346: JonasManagementRepr.invoke(JonasObjectName
347: .webContainerService(), "unRegisterWarMBean",
348: asParam, asSignature, serverName);
349: break;
350: case WhereAreYou.DEPLOYMENT_DATASOURCE:
351: undeployDataSource(p_Filename);
352: break;
353: case WhereAreYou.DEPLOYMENT_MAIL:
354: undeployMailFactory(p_Filename);
355: break;
356: }
357: }
358:
359: /**
360: * Undeploy a datasource file.
361: *
362: * @param p_Filename Name of file to undeploy
363: * @throws Exception
364: */
365: protected void undeployDataSource(String p_Filename)
366: throws Exception {
367: String serverName = m_WhereAreYou.getCurrentJonasServerName();
368: ArrayList al = JonasAdminJmx.getDatasourceDependences(
369: p_Filename, m_WhereAreYou.getCurrentDomainName(),
370: m_WhereAreYou.getCurrentJonasServerName());
371: if (al.size() == 0) {
372: String[] asParam = new String[1];
373: asParam[0] = p_Filename;
374: String[] asSignature = new String[1];
375: asSignature[0] = "java.lang.String";
376: JonasManagementRepr.invoke(JonasObjectName
377: .databaseService(), "unloadDataSource", asParam,
378: asSignature, serverName);
379: } else {
380: throw new Exception(m_Resources.getMessage(
381: "error.undeploy.datasource.dependences", al
382: .toString()));
383: }
384: }
385:
386: /**
387: * Undeploy a mail factory.
388: *
389: * @param p_Filename Name of the factory (same as the props file name configuring it)
390: * @throws Exception
391: */
392: protected void undeployMailFactory(String p_Filename)
393: throws Exception {
394: String serverName = m_WhereAreYou.getCurrentJonasServerName();
395: ArrayList al = JonasAdminJmx.getMailFactoryDependences(
396: p_Filename, m_WhereAreYou);
397: if (al.size() == 0) {
398: String[] asParam = new String[1];
399: asParam[0] = p_Filename;
400: String[] asSignature = new String[1];
401: asSignature[0] = "java.lang.String";
402: JonasManagementRepr.invoke(JonasObjectName.mailService(),
403: "unbindMailFactoryMBean", asParam, asSignature,
404: serverName);
405: } else {
406: throw new Exception(m_Resources.getMessage(
407: "error.undeploy.mailfactory.dependences", al
408: .toString()));
409: }
410: }
411:
412: /**
413: * Deploy a file in using the type of current deployment
414: * storing in WhereAreYou instance in session.
415: *
416: * @param p_Filename Name of file to deploy
417: * @throws Exception
418: */
419: protected void deploy(String p_Filename) throws Exception {
420: String[] asParam = new String[1];
421: asParam[0] = p_Filename;
422: String[] asSignature = new String[1];
423: asSignature[0] = "java.lang.String";
424:
425: String serverName = m_WhereAreYou.getCurrentJonasServerName();
426: switch (getCurrentJonasDeployment()) {
427: case WhereAreYou.DEPLOYMENT_EAR:
428: JonasManagementRepr.invoke(JonasObjectName.earService(),
429: "deployEarMBean", asParam, asSignature, serverName);
430: break;
431: case WhereAreYou.DEPLOYMENT_JAR:
432: JonasManagementRepr.invoke(JonasObjectName.ejbService(),
433: "createContainerMBean", asParam, asSignature,
434: serverName);
435: break;
436: case WhereAreYou.DEPLOYMENT_RAR:
437: JonasManagementRepr.invoke(JonasObjectName
438: .resourceService(), "deployRarMBean", asParam,
439: asSignature, serverName);
440: break;
441: case WhereAreYou.DEPLOYMENT_WAR:
442: JonasManagementRepr.invoke(JonasObjectName
443: .webContainerService(), "registerWarMBean",
444: asParam, asSignature, serverName);
445: break;
446: case WhereAreYou.DEPLOYMENT_DATASOURCE:
447: deployDataSource(p_Filename);
448: break;
449: case WhereAreYou.DEPLOYMENT_MAIL:
450: deployMailFactory(p_Filename);
451: break;
452: }
453: }
454:
455: /**
456: * Deploy a datasource file.
457: *
458: * @param p_Filename Name of file to deploy
459: * @throws Exception
460: */
461: protected void deployDataSource(String p_Filename) throws Exception {
462:
463: String serverName = m_WhereAreYou.getCurrentJonasServerName();
464: String[] asParam = new String[1];
465: String[] asSignature = new String[1];
466: asParam[0] = p_Filename;
467: asSignature[0] = "java.lang.String";
468:
469: ObjectName onDb = JonasObjectName.databaseService();
470: // Verify if datasource already loaded
471: Boolean oLoaded = (Boolean) JonasManagementRepr.invoke(onDb,
472: "isLoadedDataSource", asParam, asSignature, serverName);
473: if (oLoaded.booleanValue() == false) {
474: // Get Datasource properties file
475: Properties oProps = (Properties) JonasManagementRepr
476: .invoke(onDb, "getDataSourcePropertiesFile",
477: asParam, asSignature, serverName);
478: // Load Datasource
479: Object[] aoParam = { p_Filename, oProps, new Boolean(true) };
480: String[] asSign_3 = { "java.lang.String",
481: "java.util.Properties", "java.lang.Boolean" };
482: JonasManagementRepr.invoke(onDb, "loadDataSource", aoParam,
483: asSign_3, serverName);
484: } else {
485: throw new Exception(m_Resources
486: .getMessage("error.deploy.datasource.isloaded"));
487: }
488: }
489:
490: /**
491: * Deploy a mail factory.
492: *
493: * @param p_Filename Name of the mail factory whch is also the name of the file
494: * @throws Exception
495: */
496: protected void deployMailFactory(String p_Filename)
497: throws Exception {
498: String serverName = m_WhereAreYou.getCurrentJonasServerName();
499: String[] asParam = new String[1];
500: String[] asSignature = new String[1];
501: asParam[0] = p_Filename;
502: asSignature[0] = "java.lang.String";
503:
504: ObjectName onMail = JonasObjectName.mailService();
505: // Get mail factory properties file
506: Properties oProps = (Properties) JonasManagementRepr.invoke(
507: onMail, "getMailFactoryPropertiesFile", asParam,
508: asSignature, serverName);
509: // Load mail factory
510: Object[] aoParam = { p_Filename, oProps, new Boolean(true) };
511: String[] asSign_3 = { "java.lang.String",
512: "java.util.Properties", "java.lang.Boolean" };
513: JonasManagementRepr.invoke(onMail, "createMailFactoryMBean",
514: aoParam, asSign_3, serverName);
515: }
516:
517: /**
518: * Run garbage collector.
519: *
520: * @throws Exception
521: */
522: protected void runGC() throws Exception {
523: String serverName = m_WhereAreYou.getCurrentJonasServerName();
524: ObjectName oObjectName = J2eeObjectName.J2EEServer(
525: m_WhereAreYou.getCurrentDomainName(), m_WhereAreYou
526: .getCurrentJonasServerName());
527: JonasManagementRepr.invoke(oObjectName, "runGC", null, null,
528: m_WhereAreYou.getCurrentJonasServerName());
529: }
530:
531: /**
532: * Refresh the tree.
533: *
534: * @param p_Request The current HTTP Request
535: * @throws Exception
536: */
537: protected void refreshTree(HttpServletRequest p_Request)
538: throws Exception {
539: String serverName = m_WhereAreYou.getCurrentJonasServerName();
540: // Refresh Service Tree
541: switch (getCurrentJonasDeployment()) {
542: case WhereAreYou.DEPLOYMENT_EAR:
543: refreshServiceTree(WhereAreYou.DEPLOYMENT_EAR, p_Request);
544: if (JonasAdminJmx.hasMBeanName(
545: JonasObjectName.ejbService(), serverName) == true) {
546: refreshServiceTree(WhereAreYou.DEPLOYMENT_JAR,
547: p_Request);
548: String localJoramServerId = (String) p_Request
549: .getSession().getAttribute("localId");
550: refreshJoramTree(p_Request, localJoramServerId);
551: }
552: if (JonasAdminJmx.hasMBeanName(JonasObjectName
553: .webContainerService(), serverName) == true) {
554: refreshServiceTree(WhereAreYou.DEPLOYMENT_WAR,
555: p_Request);
556: }
557: if (JonasAdminJmx.hasMBeanName(JonasObjectName
558: .resourceService(), serverName) == true) {
559: refreshServiceTree(WhereAreYou.DEPLOYMENT_RAR,
560: p_Request);
561: }
562: break;
563: case WhereAreYou.DEPLOYMENT_JAR:
564: refreshServiceTree(WhereAreYou.DEPLOYMENT_JAR, p_Request);
565: String localJoramServerId = (String) p_Request.getSession()
566: .getAttribute("localId");
567: refreshJoramTree(p_Request, localJoramServerId);
568: break;
569: case WhereAreYou.DEPLOYMENT_WAR:
570: refreshServiceTree(WhereAreYou.DEPLOYMENT_WAR, p_Request);
571: break;
572: case WhereAreYou.DEPLOYMENT_RAR:
573: refreshServiceTree(WhereAreYou.DEPLOYMENT_RAR, p_Request);
574: refreshJoramTree(p_Request, null);
575: break;
576: case WhereAreYou.DEPLOYMENT_DATASOURCE:
577: refreshServiceTree(WhereAreYou.DEPLOYMENT_DATASOURCE,
578: p_Request);
579: break;
580: case WhereAreYou.DEPLOYMENT_MAIL:
581: refreshServiceTree(WhereAreYou.DEPLOYMENT_MAIL, p_Request);
582: break;
583: }
584: // Refresh MBeans Tree
585: refreshMBeansTree(p_Request);
586: // Force display to refresh
587: m_WhereAreYou.setTreeToRefresh(true);
588: }
589:
590: /**
591: * Refresh the service tree.
592: *
593: * @param p_Deployment The type of deployment
594: * @param p_Request The current HTTP Request
595: * @throws Exception
596: */
597: protected void refreshServiceTree(int p_Deployment,
598: HttpServletRequest p_Request) throws Exception {
599: // Get the domain and server name
600: String sDomainLabel = "domain";
601: String sServerName = m_WhereAreYou.getCurrentJonasServerName();
602: // Get the service name
603: String sCurrentNodeNameServiceItem = null;
604: switch (p_Deployment) {
605: case WhereAreYou.DEPLOYMENT_EAR:
606: sCurrentNodeNameServiceItem = sDomainLabel
607: + WhereAreYou.NODE_SEPARATOR + sServerName
608: + WhereAreYou.NODE_SEPARATOR + "services"
609: + WhereAreYou.NODE_SEPARATOR + "ear";
610: break;
611: case WhereAreYou.DEPLOYMENT_JAR:
612: sCurrentNodeNameServiceItem = sDomainLabel
613: + WhereAreYou.NODE_SEPARATOR + sServerName
614: + WhereAreYou.NODE_SEPARATOR + "services"
615: + WhereAreYou.NODE_SEPARATOR + "ejbContainers";
616: break;
617: case WhereAreYou.DEPLOYMENT_RAR:
618: sCurrentNodeNameServiceItem = sDomainLabel
619: + WhereAreYou.NODE_SEPARATOR + sServerName
620: + WhereAreYou.NODE_SEPARATOR + "services"
621: + WhereAreYou.NODE_SEPARATOR + "resourceAdapter";
622: break;
623: case WhereAreYou.DEPLOYMENT_WAR:
624: sCurrentNodeNameServiceItem = sDomainLabel
625: + WhereAreYou.NODE_SEPARATOR + sServerName
626: + WhereAreYou.NODE_SEPARATOR + "services"
627: + WhereAreYou.NODE_SEPARATOR + "web";
628: break;
629: case WhereAreYou.DEPLOYMENT_DATASOURCE:
630: sCurrentNodeNameServiceItem = sDomainLabel
631: + WhereAreYou.NODE_SEPARATOR + sServerName
632: + WhereAreYou.NODE_SEPARATOR + "services"
633: + WhereAreYou.NODE_SEPARATOR + "database";
634: break;
635: case WhereAreYou.DEPLOYMENT_MAIL:
636: sCurrentNodeNameServiceItem = sDomainLabel
637: + WhereAreYou.NODE_SEPARATOR + sServerName
638: + WhereAreYou.NODE_SEPARATOR + "services"
639: + WhereAreYou.NODE_SEPARATOR + "mail";
640: break;
641: case WhereAreYou.DEPLOYMENT_JMS:
642: sCurrentNodeNameServiceItem = sDomainLabel
643: + WhereAreYou.NODE_SEPARATOR + sServerName
644: + WhereAreYou.NODE_SEPARATOR + "services"
645: + WhereAreYou.NODE_SEPARATOR + "jms";
646: break;
647: }
648: // Get current tree
649: TreeControl oControl = m_WhereAreYou.getTreeControl();
650: // Get service node
651: TreeControlNode oServiceNode = oControl
652: .findNode(sCurrentNodeNameServiceItem);
653: // Enable auto-refresh mode
654: oControl.enableAutoRefresh();
655: // Remove old children
656: TreeControlNode[] aoNodes = oServiceNode.findChildren();
657: for (int i = 0; i < aoNodes.length; i++) {
658: aoNodes[i].remove();
659: }
660: // Build node for the Service
661: JonasTreeBuilder oBuilder = new JonasTreeBuilder();
662: String sDomainName = m_WhereAreYou.getCurrentDomainName();
663:
664: switch (p_Deployment) {
665: case WhereAreYou.DEPLOYMENT_EAR:
666: oBuilder.getAppContainers(oServiceNode, m_Resources,
667: sDomainName, sServerName);
668: refreshWebServiceTree(p_Request);
669: break;
670: case WhereAreYou.DEPLOYMENT_JAR:
671: oBuilder.getContainers(oServiceNode, m_Resources,
672: sDomainName, sServerName);
673: break;
674: case WhereAreYou.DEPLOYMENT_RAR:
675: oBuilder.getResourceAdapters(oServiceNode, m_Resources,
676: sDomainName, sServerName);
677: break;
678: case WhereAreYou.DEPLOYMENT_WAR:
679: oBuilder.getWebContainers(oServiceNode, m_Resources,
680: p_Request);
681: refreshWebServiceTree(p_Request);
682: break;
683: case WhereAreYou.DEPLOYMENT_DATASOURCE:
684: oBuilder.getDatasources(oServiceNode, m_Resources,
685: sDomainName, sServerName);
686: break;
687: case WhereAreYou.DEPLOYMENT_JMS:
688: oBuilder.getJmsResources(oServiceNode, m_Resources,
689: sServerName);
690: break;
691: case WhereAreYou.DEPLOYMENT_MAIL:
692: oBuilder.getAllSessionMailFactories(oServiceNode,
693: m_Resources, p_Request);
694: oBuilder.getAllMimePartDSMailFactories(oServiceNode,
695: m_Resources, p_Request);
696: break;
697: }
698: // Disable auto-refresh mode
699: oControl.disableAutoRefresh();
700: }
701:
702: protected void refreshWebServiceTree(HttpServletRequest p_Request)
703: throws Exception {
704: String sServerName = m_WhereAreYou.getCurrentJonasServerName();
705: String sDomainName = m_WhereAreYou.getCurrentDomainName();
706: // Get current tree
707: TreeControl oControl = m_WhereAreYou.getTreeControl();
708: // Build node and his children
709: JonasTreeBuilder oBuilder = new JonasTreeBuilder();
710:
711: // Since (un)deployment of ears and wars can add/remove webservices,
712: // this part of the tree needs to be recreated.
713: String sServicesNodeName = "domain"
714: + WhereAreYou.NODE_SEPARATOR + sServerName
715: + WhereAreYou.NODE_SEPARATOR + "services";
716: // The node representing services in the jonasAdmin tree.
717: TreeControlNode services = oControl.findNode(sServicesNodeName);
718: // If any web services are deployed and services node is present in tree.
719: if (JonasAdminJmx.hasMBeanName(JonasObjectName.wsService(),
720: sServerName)
721: && services != null) {
722: // Rebuild the webservices tree.
723: oBuilder.getServiceWebService(services, m_Resources,
724: p_Request, sDomainName, sServerName);
725: } else {
726: TreeControlNode ws = oControl.findNode(sServicesNodeName
727: + WhereAreYou.NODE_SEPARATOR + "WebService");
728: // If a web service node exists in tree already, remove it from there.
729: if (ws != null) {
730: ws.remove();
731: }
732: }
733: }
734:
735: /**
736: * Refresh the MBeans tree.
737: *
738: * @throws Exception
739: */
740: protected void refreshMBeansTree(HttpServletRequest p_Request)
741: throws Exception {
742: // Get current tree
743: TreeControl oControl = m_WhereAreYou.getTreeControl();
744: // MBeans node present ?
745: TreeControlNode oMBeansNode = oControl
746: .findNode("domain*mbeans");
747: TreeControlNode oDomainNode = oMBeansNode.getParent();
748: if (oMBeansNode != null) {
749: // Enable auto-refresh mode
750: oControl.enableAutoRefresh();
751: // Remove node
752: oMBeansNode.remove();
753: // Build node and his children
754: JonasTreeBuilder oBuilder = new JonasTreeBuilder();
755: oBuilder.getMBeans(oDomainNode, m_Resources, p_Request);
756: // Disable auto-refresh mode
757: oControl.disableAutoRefresh();
758: }
759: }
760:
761: /**
762: * Refresh the Joram tree after creating / removing a Joram destination
763: * or after deploying / undeploying the Joram RAR
764: * @param serverId Id of the Joram server which was updated
765: * @throws Exception
766: */
767: protected void refreshJoramTree(HttpServletRequest p_Request,
768: String serverId) throws Exception {
769: m_WhereAreYou.setTreeToRefresh(true);
770: String serverName = m_WhereAreYou.getCurrentJonasServerName();
771: // Get current tree
772: TreeControl oControl = m_WhereAreYou.getTreeControl();
773: // selected node
774: TreeControlNode selectedNode = oControl.getSelected();
775: // Joram node
776: String sJoramNodeName = "domain" + WhereAreYou.NODE_SEPARATOR
777: + "joramplatform";
778: TreeControlNode oJoramNode = oControl.findNode(sJoramNodeName);
779: // Root node
780: TreeControlNode oDomainNode = oControl.findNode("domain");
781: TreeControlNode oNode = null;
782: // check if this is a Joram tree update case
783: if (selectedNode.getName().indexOf(sJoramNodeName) < 0) {
784: // the selected node is not a Joram node, select the Joram node or a Joram server node
785: oNode = oJoramNode;
786: if (serverId != null) {
787: TreeControlNode[] aoNodes = oNode.findChildren();
788: for (int i = 0; i < aoNodes.length; i++) {
789: String serverNodeLabel = aoNodes[i].getLabel();
790: int indexBefore = serverNodeLabel.indexOf("(");// (
791: int indexAfter = serverNodeLabel.indexOf(")",
792: indexBefore + 1);// )
793: String id = serverNodeLabel.substring(
794: indexBefore + 1, indexAfter);
795: if (id.equals(serverId)) {
796: oNode = aoNodes[i];
797: break;
798: }
799: }
800: }
801: } else {
802: // refreshJoramTree was called after a Joram platform configuration operation
803: // which created or removed a Joram destination
804: oNode = selectedNode;
805: if (serverId == null) {
806: return;
807: }
808: }
809: // Enable auto-refresh mode
810: oControl.enableAutoRefresh();
811: if (oNode != null) {
812: // Remove old children
813: TreeControlNode[] aoNodes = oNode.findChildren();
814: for (int i = 0; i < aoNodes.length; i++) {
815: aoNodes[i].remove();
816: }
817:
818: if (JonasManagementRepr.queryNames(
819: JoramObjectName.joramAdapter(), serverName)
820: .isEmpty()) {
821: // Remove node
822: oNode.remove();
823: // Un-register joramClient MBeans
824: ObjectName joramClients = JoramObjectName
825: .joramClientMBeans();
826: Iterator it = JonasManagementRepr.queryNames(
827: joramClients, serverName).iterator();
828: ObjectName joramClient = null;
829: while (it.hasNext()) {
830: joramClient = (ObjectName) it.next();
831: MBeanServerConnection connection = ((ManagementReprImplJSR160) JonasManagementRepr
832: .getServerRepr(serverName))
833: .getMBeanServerConnection();
834: connection.unregisterMBean(joramClient);
835: }
836: // un-register AgentServer MBeans
837: /*
838: ObjectName agentServerMBeans = ObjectName.getInstance("AgentServer:*");
839: it = JonasManagementRepr.queryNames(agentServerMBeans).iterator();
840: ObjectName agentServerMBean = null;
841: while (it.hasNext()) {
842: agentServerMBeans = (ObjectName) it.next();
843: MBeanServerConnection connection = ((ManagementReprImplJSR160) JonasManagementRepr.getRepr()).getMBeanServerConnection();
844: connection.unregisterMBean(agentServerMBeans);
845: }
846: */
847: } else {
848: JonasTreeBuilder oBuilder = new JonasTreeBuilder();
849: if (serverId != null) {
850: oBuilder.getJoramResources(oNode, serverName,
851: serverId, m_Resources, p_Request);
852: } else {
853: oBuilder.getJoramServers(oJoramNode, serverName,
854: null, m_Resources, p_Request);
855: }
856: }
857: } else {
858: // Construct tree if necessary
859: // Build node and his children
860: JonasTreeBuilder oBuilder = new JonasTreeBuilder();
861: oBuilder.getJoramPlatform(oDomainNode, serverName,
862: m_Resources, p_Request);
863: }
864: // Disable auto-refresh mode
865: oControl.disableAutoRefresh();
866: }
867:
868: /**
869: * Remove a given file
870: * @param fileName Name of file to remove
871: * @return true if file has been removed
872: * @throws Exception if remove fails
873: */
874: protected boolean removeFile(String fileName) throws Exception {
875:
876: // J2EE server MBean
877: ObjectName j2eeServer = J2eeObjectName.J2EEServer(m_WhereAreYou
878: .getCurrentDomainName(), m_WhereAreYou
879: .getCurrentJonasServerName());
880: String serverName = m_WhereAreYou.getCurrentJonasServerName();
881: // invoke method on the MBean
882: Object[] param = new Object[] { fileName };
883: String[] signature = { "java.lang.String" };
884: return ((Boolean) JonasManagementRepr.invoke(j2eeServer,
885: "removeModuleFile", param, signature, serverName))
886: .booleanValue();
887: }
888:
889: }
|