001: /**
002: * JOnAS: Java(TM) Open Application Server
003: * Copyright (C) 2003-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: ApplyJonasServersConfirmAction.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:
029: import javax.management.ObjectName;
030: import javax.servlet.ServletException;
031: import javax.servlet.http.HttpServletRequest;
032: import javax.servlet.http.HttpServletResponse;
033:
034: import org.apache.struts.action.ActionForm;
035: import org.apache.struts.action.ActionForward;
036: import org.apache.struts.action.ActionMapping;
037: import org.objectweb.jonas.jmx.JonasManagementRepr;
038: import org.objectweb.jonas.management.j2eemanagement.J2EEDomain;
039: import org.objectweb.jonas.management.monitoring.DomainMonitor;
040: import org.objectweb.jonas.webapp.jonasadmin.JonasBaseAction;
041:
042: /**
043: * @author Adriana Danes
044: */
045: public class ApplyJonasServersConfirmAction extends JonasBaseAction {
046:
047: // --------------------------------------------------------- Public Methods
048:
049: public ActionForward executeAction(ActionMapping p_Mapping,
050: ActionForm p_Form, HttpServletRequest p_Request,
051: HttpServletResponse p_Response) throws IOException,
052: ServletException {
053: // List of servers selected to be removed
054: ArrayList alSelected = (ArrayList) m_Session
055: .getAttribute("listServersSelected");
056: m_Session.setAttribute("listServersSelected", null);
057:
058: if (alSelected != null) {
059: // DomainName
060: String domainName = m_WhereAreYou.getCurrentDomainName();
061: // Current server nmae
062: String currentServerName = m_WhereAreYou
063: .getCurrentJonasServerName();
064: // Current cluster name
065: String clusterName = (String) m_Session
066: .getAttribute("currentCluster");
067: // Check if the selected cluster is the domain's one
068: boolean domainRemove = false;
069: if (clusterName.equals(domainName)) {
070: // In this case, the server have to be removed from all the clusters
071: domainRemove = true;
072: }
073: // Construct a list with the cluster ons for removing
074: ArrayList removeClOns = new ArrayList();
075: ObjectName domainClusterOn = null;
076: // Actions
077: try {
078: DomainMonitor dm = J2EEDomain.getInstance()
079: .getDomainMonitor();
080: if (dm != null) {
081: // All clusters Ons
082: String[] clOns = dm.getClusters();
083: for (int index = 0; index < clOns.length; index++) {
084: ObjectName clOn = ObjectName
085: .getInstance(clOns[index]);
086: String clType = clOn.getKeyProperty("type");
087: String clName = clOn.getKeyProperty("name");
088: if (!domainRemove) {
089: // put clOn in the list for removing if this the current cluster's on
090: if ("LogicalCluster".equals(clType)
091: && clusterName.equals(clName)) {
092: removeClOns.add(clOn);
093: break;
094: }
095: } else {
096: if ("LogicalCluster".equals(clType)
097: && domainName.equals(clName)) {
098: // keep the domain cluster On in domainClusterOn variable
099: domainClusterOn = clOn;
100: } else {
101: removeClOns.add(clOn);
102: }
103: }
104: }
105: if (domainRemove) {
106: // add domainClusterOn et the end in order to be the last treated one
107: removeClOns.add(domainClusterOn);
108: m_Session.setAttribute("mapChanged",
109: new Boolean(true));
110: }
111: // Remove all the servers from all the clusters in removeClOns
112: for (int j = 0; j < alSelected.size(); j++) {
113: String serverName = (String) alSelected.get(j);
114: for (int i = 0; i < removeClOns.size(); i++) {
115: ObjectName clOn = (ObjectName) removeClOns
116: .get(i);
117: String[] signature = { "java.lang.String" };
118: String[] params = { serverName };
119: JonasManagementRepr.invoke(clOn,
120: "removeServer", params, signature,
121: currentServerName);
122: }
123: }
124: }
125: } catch (Throwable t) {
126: addGlobalError(t);
127: saveErrors(p_Request, m_Errors);
128: return (p_Mapping.findForward("Global Error"));
129: }
130: }
131: // Forward to the domain page
132: return p_Mapping.findForward("ActionEditDomain");
133: }
134: }
|