001: /**
002: * JOnAS: Java(TM) Open Application Server
003: * Copyright (C) 1999 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: EditDomainDeployAction.java 9712 2006-10-10 13:42:20Z danesa $
023: * --------------------------------------------------------------------------
024: */package org.objectweb.jonas.webapp.jonasadmin.deploy;
025:
026: import java.io.IOException;
027: import java.util.ArrayList;
028:
029: import javax.management.MalformedObjectNameException;
030: import javax.management.ObjectName;
031: import javax.servlet.ServletException;
032: import javax.servlet.http.HttpServletRequest;
033: import javax.servlet.http.HttpServletResponse;
034:
035: import org.apache.struts.action.ActionForm;
036: import org.apache.struts.action.ActionForward;
037: import org.apache.struts.action.ActionMapping;
038: import org.objectweb.jonas.jmx.J2eeObjectName;
039: import org.objectweb.jonas.jmx.JonasManagementRepr;
040: import org.objectweb.jonas.webapp.jonasadmin.Jlists;
041: import org.objectweb.jonas.webapp.jonasadmin.JonasAdminJmx;
042:
043: /**
044: *
045: * @author Patrick Smith
046: * Greg Lapouchnian
047: * Adriana Danes
048: */
049:
050: public class EditDomainDeployAction extends BaseDeployAction {
051:
052: static final int indentUnit = 2;
053: static final char indentChar = '_';
054:
055: // --------------------------------------------------------- Public Methods
056:
057: public ActionForward executeAction(ActionMapping p_Mapping,
058: ActionForm p_Form, HttpServletRequest p_Request,
059: HttpServletResponse p_Response) throws IOException,
060: ServletException {
061:
062: String serverName = m_WhereAreYou.getCurrentJonasServerName();
063: // Form used
064: DomainDeployForm oForm = (DomainDeployForm) p_Form;
065: try {
066: // Store type deployment if exists
067: setCurrentJonasDeployment(p_Request);
068: // Domain ObjectName
069: ObjectName on = JonasAdminJmx
070: .getJ2eeDomainObjectName(serverName);
071:
072: // Get all targets in the domain: started servers and clusters
073: ArrayList alTargets = new ArrayList();
074: ArrayList alTargetNames = new ArrayList();
075: getTargetServerList(alTargetNames, alTargets, on,
076: serverName);
077: // Get deployable files (all files on the local server)
078: ArrayList alDeployable = getListDeployableFiles();
079:
080: // Deploy files
081: //ArrayList alDeploy = new ArrayList(alDeployable);
082:
083: // Set in form
084: oForm.setListDeployable(alDeployable);
085: oForm.setListTargets(alTargets);
086: oForm.setListTargetNames(alTargetNames);
087: //oForm.setListDeploy(alDeploy);
088: //oForm.setDeploy(Jlists.getString(alDeploy, Jlists.SEPARATOR));
089: oForm.setIsConfigurable(isConfigurable());
090:
091: } catch (Throwable t) {
092: addGlobalError(t);
093: saveErrors(p_Request, m_Errors);
094: return (p_Mapping.findForward("Global Error"));
095: }
096: // Forward to the jsp.
097: return (p_Mapping.findForward(getForwardEdit()));
098: }
099:
100: /**
101: *
102: * @param targetNames List of target names - output parameter
103: * @param targetONs List of target ONs - output parameter
104: * @param domainOn domain ObjectName
105: * @param serverName the currently managed server
106: * @return total number of target servers and clusters
107: * @throws MalformedObjectNameException Couldn't determine the target ObjectNames
108: */
109: int getTargetServerList(ArrayList targetNames, ArrayList targetONs,
110: ObjectName domainOn, String serverName)
111: throws MalformedObjectNameException {
112: String domainName = domainOn.getKeyProperty("name");
113: String[] startedServers = (String[]) JonasManagementRepr
114: .getAttribute(domainOn, "startedServers", serverName);
115:
116: for (int i = 0; i < startedServers.length; i++) {
117: String startedServer = ObjectName.getInstance(
118: startedServers[i]).getKeyProperty("name");
119: targetNames.add(startedServer);
120: targetONs.add(startedServers[i]);
121: }
122:
123: String[] clusters = (String[]) JonasManagementRepr
124: .getAttribute(domainOn, "clusters", serverName);
125: for (int i = 0; i < clusters.length; i++) {
126: ObjectName clOn = ObjectName.getInstance(clusters[i]);
127: String clusterName = clOn.getKeyProperty("name");
128: if (!clusterName.equals(domainName)) {
129: targetNames.add(clusterName);
130: targetONs.add(clusters[i]);
131: }
132: }
133:
134: return startedServers.length + clusters.length;
135: }
136: }
|