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: EditDomainAction.java 9680 2006-10-06 12:08:33Z danesa $
023: * --------------------------------------------------------------------------
024: */package org.objectweb.jonas.webapp.jonasadmin.domain;
025:
026: import java.io.IOException;
027: import java.util.ArrayList;
028: import java.util.Collections;
029: import java.util.Iterator;
030:
031: import javax.management.ObjectName;
032: import javax.servlet.ServletException;
033: import javax.servlet.http.HttpServletRequest;
034: import javax.servlet.http.HttpServletResponse;
035:
036: import org.apache.struts.action.ActionForm;
037: import org.apache.struts.action.ActionForward;
038: import org.apache.struts.action.ActionMapping;
039:
040: import org.objectweb.jonas.jmx.J2eeObjectName;
041: import org.objectweb.jonas.jmx.ManagementReprLoader;
042: import org.objectweb.jonas.management.cluster.BaseCluster;
043: import org.objectweb.jonas.management.j2eemanagement.J2EEDomain;
044: import org.objectweb.jonas.management.monitoring.ClusterDaemonProxy;
045: import org.objectweb.jonas.management.monitoring.DomainMonitor;
046: import org.objectweb.jonas.management.monitoring.ServerProxy;
047: import org.objectweb.jonas.webapp.jonasadmin.JonasBaseAction;
048: import org.objectweb.jonas.webapp.jonasadmin.common.BeanComparator;
049:
050: /**
051: * Display domain or cluster informations
052: * @author Adriana Danes
053: */
054: public class EditDomainAction extends JonasBaseAction {
055:
056: /**
057: * Compute info about this cluster or domain
058: * Populate the DomainForm
059: * Eventually call the domain.jsp for display
060: */
061: public ActionForward executeAction(ActionMapping p_Mapping,
062: ActionForm p_Form, HttpServletRequest p_Request,
063: HttpServletResponse p_Response) throws IOException,
064: ServletException {
065:
066: try {
067: DomainForm oForm = (DomainForm) p_Form;
068: String domainName = m_WhereAreYou.getCurrentDomainName();
069: boolean changeMap;
070: Boolean changeMapObj = ((Boolean) m_Session
071: .getAttribute("mapChanged"));
072: if (changeMapObj == null) {
073: changeMap = false;
074: } else {
075: changeMap = changeMapObj.booleanValue();
076: }
077: String selected = p_Request.getParameter("select");
078: if (selected == null) {
079: // By default we edit the domain page
080: // -- this is necessary for example when creating a cluster in the
081: // domain, at the end of the ApplyClusterAction we comme back
082: // into EdirDomainAction
083: // -- maybe this should be treated otherwise ?
084: selected = domainName;
085: }
086: // domain or cluster name
087: String name = selected;
088: m_Session.setAttribute("currentCluster", name);
089:
090: // Support mgmt context switch from a slave to the master
091: // (to the administrator server)
092: String adminServerName = m_WhereAreYou
093: .getAdminJonasServerName();
094: boolean changeManagement = false;
095: if (!adminServerName.equals(m_WhereAreYou
096: .getCurrentJonasServerName())) {
097: // change management conext from a managed server in the domain
098: // to the JonasAdmin server
099: ManagementReprLoader.loadServerRepr(adminServerName);
100: m_WhereAreYou
101: .refreshServers(p_Request, adminServerName);
102: // onCurrentServer = m_WhereAreYou.getCurrentJonasServer();
103: changeManagement = true;
104: }
105:
106: // Force the node selected in tree
107: m_WhereAreYou.selectNameNode("domain", true);
108:
109: if (changeManagement) {
110: refreshServerTree(p_Request);
111: }
112: if (changeMap) {
113: //refreshDomainMonitoringTree(p_Request);
114: refreshServerTree(p_Request);
115:
116: m_WhereAreYou.setTreeToRefresh(true);
117: m_Session
118: .setAttribute("mapChanged", new Boolean(false));
119: }
120: // domain or cluster
121: boolean inCluster = false;
122: if (domainName.equals(selected)) {
123: // this is a domain
124: oForm.setType("Domain");
125: } else {
126: inCluster = true;
127: oForm.setType("Cluster");
128: }
129:
130: // set general properties
131: oForm.setName(name);
132: oForm.setDomainName(domainName);
133: //oForm.setDescription(getStringAttribute(onDomain, "description"));
134: oForm.setCluster(inCluster);
135: oForm.setMasterName(adminServerName);
136: oForm.setMasterON(J2eeObjectName.J2EEServer(domainName,
137: adminServerName).toString());
138: oForm.setMaster(getBooleanAttribute(m_WhereAreYou
139: .getCurrentDomain(), "master"));
140:
141: // Get access to the DomainMonitor and domain/cluster management data
142: BaseCluster baseCluster = null;
143: DomainMonitor dm = J2EEDomain.getInstance()
144: .getDomainMonitor();
145: if (dm != null) {
146: baseCluster = dm.findCluster(name);
147: if (baseCluster == null) {
148: throw new RuntimeException("Cannot find cluster "
149: + name);
150: }
151: ObjectName clOn = ObjectName.getInstance(baseCluster
152: .getObjectName());
153: oForm.setClusterType(clOn.getKeyProperty("type"));
154: // Get servers running in this domain (or cluster)
155: ArrayList al = new ArrayList();
156: for (Iterator it = baseCluster.getServerProxyList()
157: .iterator(); it.hasNext();) {
158: ServerProxy proxy = (ServerProxy) it.next();
159: ObjectName on = ObjectName.getInstance(proxy
160: .getJ2eeObjectName());
161: al.add(new ServerItem(on, proxy.getState(), proxy
162: .getClusterDaemonName()));
163: }
164: Collections.sort(al, new BeanComparator(
165: new String[] { "name" }));
166: p_Request.setAttribute("listServers", al);
167:
168: if (!inCluster) {
169: // Get clusters in this domain
170: ArrayList clustAl = new ArrayList();
171: for (Iterator it = dm.getTotalClusterList()
172: .iterator(); it.hasNext();) {
173: BaseCluster cl = (BaseCluster) it.next();
174: String clusterName = cl.getName();
175: if (!domainName.equals(clusterName)) {
176: ObjectName on = new ObjectName(cl
177: .getObjectName());
178: ServerItem item = new ServerItem(on, cl
179: .getState(), null);
180: item.setName(clusterName);
181: clustAl.add(item);
182: }
183: }
184: Collections.sort(clustAl, new BeanComparator(
185: new String[] { "name" }));
186: p_Request.setAttribute("listClusters", clustAl);
187:
188: // Get cluster daemons
189: ArrayList clustDaemonAl = new ArrayList();
190: for (Iterator it = dm.getClusterDaemonList()
191: .iterator(); it.hasNext();) {
192: ClusterDaemonProxy cdp = (ClusterDaemonProxy) it
193: .next();
194: String cdpName = cdp.getName();
195: ObjectName on = new ObjectName(cdp
196: .getObjectName());
197: ServerItem item = new ServerItem(on, cdp
198: .getState(), null);
199: item.setName(cdpName);
200: clustDaemonAl.add(item);
201: }
202: Collections.sort(clustDaemonAl, new BeanComparator(
203: new String[] { "name" }));
204: p_Request.setAttribute("listCdps", clustDaemonAl);
205: // Re-check server states for a more accurate display
206: dm.refreshStates();
207: } else {
208: p_Request.setAttribute("listClusters",
209: new ArrayList());
210: p_Request.setAttribute("listCdps", new ArrayList());
211: }
212: }
213: } catch (Throwable t) {
214: addGlobalError(t);
215: saveErrors(p_Request, m_Errors);
216: return (p_Mapping.findForward("Global Error"));
217: }
218: // Forward to the jsp.
219: return (p_Mapping.findForward("Domain"));
220:
221: }
222:
223: }
|