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: CreateJonasServerAction.java 9455 2006-08-24 12:34:22Z 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.Iterator;
029:
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.management.cluster.BaseCluster;
038: import org.objectweb.jonas.management.j2eemanagement.J2EEDomain;
039: import org.objectweb.jonas.management.monitoring.DomainMonitor;
040: import org.objectweb.jonas.management.monitoring.ServerProxy;
041: import org.objectweb.jonas.webapp.jonasadmin.JonasBaseAction;
042:
043: /**
044: * This action is called when adding a server to the domain (Add server button)
045: * @author Adriana Danes
046: */
047: public class CreateJonasServerAction extends JonasBaseAction {
048:
049: // --------------------------------------------------------- Public Methods
050: public ActionForward executeAction(ActionMapping p_Mapping,
051: ActionForm p_Form, HttpServletRequest p_Request,
052: HttpServletResponse p_Response) throws IOException,
053: ServletException {
054:
055: // Form used
056: NewServerForm oForm = new NewServerForm();
057: m_Session.setAttribute("newServerForm", oForm);
058: String clusterName = (String) m_Session
059: .getAttribute("currentCluster");
060: String domainName = m_WhereAreYou.getCurrentDomainName();
061: // Forward to the jsp.
062: if (domainName.equals(clusterName)) {
063: return (p_Mapping.findForward("AddServerToDomain"));
064: } else {
065: oForm.setCluster(true);
066: // Get access to the DomainMonitor and domain to the domain's
067: // and current cluster's server list
068: DomainMonitor dm = J2EEDomain.getInstance()
069: .getDomainMonitor();
070: if (dm != null) {
071: BaseCluster domainCluster = dm.findCluster(domainName);
072: if (domainCluster == null) {
073: throw new RuntimeException("Cannot find cluster "
074: + domainName);
075: }
076: BaseCluster currentCluster = dm
077: .findCluster(clusterName);
078: if (domainCluster == null) {
079: throw new RuntimeException("Cannot find cluster "
080: + clusterName);
081: }
082: // add all server names to the list
083: ArrayList serverNameList = new ArrayList();
084: for (Iterator it = domainCluster.getServerProxyList()
085: .iterator(); it.hasNext();) {
086: ServerProxy proxy = (ServerProxy) it.next();
087: serverNameList.add(proxy.getName());
088: }
089: // remove the names if servers already in the cluster
090: for (Iterator it = currentCluster.getServerProxyList()
091: .iterator(); it.hasNext();) {
092: ServerProxy proxy = (ServerProxy) it.next();
093: serverNameList.remove(proxy.getName());
094: }
095: String[] serverNames = new String[serverNameList.size()];
096: for (int i = 0; i < serverNameList.size(); i++) {
097: serverNames[i] = (String) serverNameList.get(i);
098: }
099: oForm.setServerNames(serverNames);
100: }
101: return (p_Mapping.findForward("AddServerToCluster"));
102: }
103: }
104: }
|