001: /**
002: * JOnAS: Java(TM) Open Application Server
003: * Copyright (C) 2005-2006 Bull S.A.S.
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: * Initial developer: Benoit Pelletier
022: * --------------------------------------------------------------------------
023: * $Id: WebContainerCluster.java 9523 2006-09-05 15:55:34Z pelletib $
024: * --------------------------------------------------------------------------
025: */package org.objectweb.jonas.ant.cluster;
026:
027: import java.io.File;
028: import java.util.Iterator;
029:
030: import org.objectweb.jonas.ant.jonasbase.BaseTaskItf;
031: import org.objectweb.jonas.ant.jonasbase.WebContainer;
032: import org.objectweb.jonas.ant.jonasbase.web.Ajp;
033: import org.objectweb.jonas.ant.jonasbase.web.Cluster;
034: import org.objectweb.jonas.ant.jonasbase.web.Http;
035: import org.objectweb.jonas.ant.jonasbase.web.Tomcat;
036:
037: /**
038: * Define WebContainerCluster task
039: * @author Benoit Pelletier
040: */
041: public class WebContainerCluster extends ClusterTasks {
042:
043: /**
044: * Info for the logger
045: */
046: private static final String INFO = "[WebContainerCluster] ";
047:
048: /**
049: * Name of the container web : tomcat/jetty
050: */
051: private String name = null;
052:
053: /**
054: * HTTP ports range
055: */
056: private String[] httpPortRange = null;
057:
058: /**
059: * AJP ports range
060: */
061: private String[] ajpPortRange = null;
062:
063: /**
064: * Sticky Session : true/false
065: */
066: private boolean stickySession = false;
067:
068: /**
069: * mod_jk enabled : true/false
070: */
071: private boolean modjkEnabled = false;
072:
073: /**
074: * mod_jk LB factor ports range
075: */
076: private String[] modJkLbFactorRange = null;
077:
078: /**
079: * director enabled : true/false
080: */
081: private boolean directorEnabled = false;
082:
083: /**
084: * Director ports range
085: */
086: private String[] directorPortRange = null;
087:
088: /**
089: * director LB factor ports range
090: */
091: private String[] directorLbFactorRange = null;
092:
093: /**
094: * multicast addr
095: */
096: private String clusterMcastAddr = null;
097:
098: /**
099: * multicast port
100: */
101: private String clusterMcastPort = null;
102:
103: /**
104: * Cluster Listen Port Range
105: */
106: private String[] clusterListenPortRange = null;
107:
108: /**
109: * Cluster name
110: */
111: private String clusterName = null;
112:
113: /**
114: * mod_jk directory
115: */
116: private String modjkDir = null;
117:
118: /**
119: * mod_jk root directory
120: */
121: private String modjkRootDir = null;
122:
123: /**
124: * director directory
125: */
126: private String directorDir = null;
127:
128: /**
129: * Default constructor
130: */
131: public WebContainerCluster() {
132: super ();
133: }
134:
135: /**
136: * Set director directory
137: * @param directorDir directory
138: */
139: public void setDirectorDir(String directorDir) {
140: this .directorDir = directorDir;
141: }
142:
143: /**
144: * Set mod_jk enabled
145: * @param enabled true/false
146: */
147: public void setModjkEnabled(boolean enabled) {
148: this .modjkEnabled = enabled;
149: }
150:
151: /**
152: * Set director enabled
153: * @param enabled true/false
154: */
155: public void setDirectorEnabled(boolean enabled) {
156: this .directorEnabled = enabled;
157: }
158:
159: /**
160: * Set mod_jk directory
161: * @param modjkDir directory
162: */
163: public void setModjkDir(String modjkDir) {
164: this .modjkDir = modjkDir;
165: }
166:
167: /**
168: * Set mod_jk root directory
169: * @param modjkRootDir directory
170: */
171: public void setModjkRootDir(String modjkRootDir) {
172: this .modjkRootDir = modjkRootDir;
173: }
174:
175: /**
176: * Set clusterMcastAddr
177: * @param clusterMcastAddr multicast address to set
178: */
179: public void setClusterMcastAddr(String clusterMcastAddr) {
180: this .clusterMcastAddr = clusterMcastAddr;
181: }
182:
183: /**
184: * Set clusterMcastPort
185: * @param clusterMcastPort multicast port to set
186: */
187: public void setClusterMcastPort(String clusterMcastPort) {
188: this .clusterMcastPort = clusterMcastPort;
189: }
190:
191: /**
192: * Set Cluster listen ports range
193: * @param clusterListenPortRange Cluster Listen ports range
194: */
195: public void setClusterListenPortRange(String clusterListenPortRange) {
196: this .clusterListenPortRange = clusterListenPortRange.split(",");
197:
198: }
199:
200: /**
201: * Set Cluster name
202: * @param clusterName cluster name
203: */
204: public void setClusterName(String clusterName) {
205: this .clusterName = clusterName;
206:
207: }
208:
209: /**
210: * Set HTTP ports range
211: * @param httpPortRange HTTP ports range
212: */
213: public void setHttpPortRange(String httpPortRange) {
214: this .httpPortRange = httpPortRange.split(",");
215:
216: }
217:
218: /**
219: * Set AJP ports range
220: * @param ajpPortRange AJP ports range
221: */
222: public void setAjpPortRange(String ajpPortRange) {
223: this .ajpPortRange = ajpPortRange.split(",");
224:
225: }
226:
227: /**
228: * Set mod_jk lb factor range
229: * @param modJkLbFactorRange load balancing factor range
230: */
231: public void setModJkLbFactorRange(String modJkLbFactorRange) {
232: this .modJkLbFactorRange = modJkLbFactorRange.split(",");
233:
234: }
235:
236: /**
237: * Set Director ports range
238: * @param directorPortRange Director ports range
239: */
240: public void setDirectorPortRange(String directorPortRange) {
241: this .directorPortRange = directorPortRange.split(",");
242:
243: }
244:
245: /**
246: * Set director lb factor range
247: * @param directorLbFactorRange load balancing factor range
248: */
249: public void setDirectorLbFactorRange(String directorLbFactorRange) {
250: this .directorLbFactorRange = directorLbFactorRange.split(",");
251:
252: }
253:
254: /**
255: * Set the name of the web container : jetty or tomcat
256: * @param containerName jetty or tomcat
257: */
258: public void setName(String containerName) {
259:
260: this .name = containerName;
261: }
262:
263: /**
264: * Set the sticky session
265: * @param stickySession true/false
266: */
267: public void setStickySession(boolean stickySession) {
268:
269: this .stickySession = stickySession;
270: }
271:
272: /**
273: * Generates the carol tasks for each JOnAS's instances
274: */
275: public void generatesTasks() {
276:
277: int portInd = 0;
278:
279: ModJk modJk = new ModJk();
280: Director director = new Director();
281:
282: // creation of the mod_jk file
283: modJk.setRootDir(modjkRootDir);
284: modJk.setDir(modjkDir);
285: modJk.createFiles();
286: modJk.setStickySession(stickySession);
287:
288: // creation of the Director file
289: director.createFile(directorDir);
290:
291: for (int i = getDestDirSuffixIndFirst(); i <= getDestDirSuffixIndLast(); i++) {
292:
293: String destDir = getDestDir(getDestDirPrefix(), i);
294:
295: log(INFO + "tasks generation for " + destDir);
296:
297: // creation of the WebContainer tasks
298: WebContainer webContainer = new WebContainer();
299:
300: // FIXME still needed as we expect Tomcat only usage ?
301: webContainer.setName(name);
302:
303: Tomcat tomcat = new Tomcat();
304: Http http = new Http();
305: http.setPort(httpPortRange[portInd]);
306: tomcat.addConfiguredHttp(http);
307:
308: if (directorEnabled) {
309: org.objectweb.jonas.ant.jonasbase.web.Director d = new org.objectweb.jonas.ant.jonasbase.web.Director();
310: d.setPort(directorPortRange[portInd]);
311: tomcat.addConfiguredDirector(d);
312: }
313: if (modjkEnabled) {
314: Ajp ajp = new Ajp();
315: ajp.setPort(ajpPortRange[portInd]);
316: tomcat.addConfiguredAjp(ajp);
317: }
318:
319: Cluster cluster = new Cluster();
320: cluster.setListenPort(clusterListenPortRange[portInd]);
321: cluster.setMcastAddr(clusterMcastAddr);
322: cluster.setMcastPort(clusterMcastPort);
323: cluster.setName(clusterName);
324: tomcat.addConfiguredCluster(cluster);
325:
326: // mod_jk
327: if (modjkEnabled) {
328: String workerName = modJk.addWorker(
329: ajpPortRange[portInd],
330: modJkLbFactorRange[portInd]);
331: tomcat.addConfiguredJvmRoute(workerName);
332: }
333:
334: webContainer.addConfiguredTomcat(tomcat);
335:
336: // director
337: if (directorEnabled) {
338: director.addAppServer(directorPortRange[portInd],
339: directorLbFactorRange[portInd]);
340: }
341:
342: // set destDir for each webContainer task
343: for (Iterator it = webContainer.getTasks().iterator(); it
344: .hasNext();) {
345: BaseTaskItf task = (BaseTaskItf) it.next();
346: task.setDestDir(new File(destDir));
347: }
348:
349: addTasks(webContainer);
350:
351: portInd++;
352:
353: }
354:
355: if (modjkEnabled) {
356: modJk.flushFiles();
357: addTasks(modJk);
358: }
359:
360: if (directorEnabled) {
361: director.flushFile();
362: addTasks(director);
363: }
364: }
365: }
|