001: /**
002: * Copyright 2005 Sun Microsystems, Inc. All
003: * rights reserved. Use of this product is subject
004: * to license terms. Federal Acquisitions:
005: * Commercial Software -- Government Users
006: * Subject to Standard License Terms and
007: * Conditions.
008: *
009: * Sun, Sun Microsystems, the Sun logo, and Sun ONE
010: * are trademarks or registered trademarks of Sun Microsystems,
011: * Inc. in the United States and other countries.
012: */package com.sun.portal.admin.console.search;
013:
014: import java.util.*;
015: import java.util.logging.Level;
016: import java.io.*;
017:
018: import javax.faces.context.FacesContext;
019: import javax.faces.application.FacesMessage;
020: import javax.faces.component.UIComponent;
021: import javax.faces.event.*;
022: import javax.faces.validator.*;
023: import javax.faces.el.ValueBinding;
024: import javax.servlet.http.HttpServletRequest;
025: import javax.management.*;
026:
027: import com.sun.web.ui.model.*;
028: import com.sun.web.ui.event.*;
029: import com.sun.web.ui.component.*;
030:
031: import com.sun.data.provider.*;
032: import com.sun.data.provider.impl.ObjectListDataProvider;
033:
034: import com.sun.cacao.agent.JmxClient;
035:
036: import com.sun.portal.admin.common.AttrOptionConstants;
037: import com.sun.portal.admin.common.util.*;
038: import com.sun.portal.admin.console.common.PSBaseBean;
039:
040: public class SchedulingRobotBean extends SchedulingBaseBean {
041:
042: private String host = null;
043:
044: private String startCommand = null;
045: private TableRowGroup tableRowGroup1 = null;
046: private TableSelectPhaseListener tspl1 = null;
047:
048: private String stopCommand = null;
049: private TableRowGroup tableRowGroup2 = null;
050: private TableSelectPhaseListener tspl2 = null;
051:
052: public SchedulingRobotBean() {
053: retrieveSearchServerHost();
054: retrieveCommands();
055:
056: ObjectListDataProvider startSchedules = (ObjectListDataProvider) getSessionAttribute("search.schedulingrobot.startschedules");
057: if (startSchedules == null) {
058: retrieveStartSchedules();
059: }
060:
061: ObjectListDataProvider stopSchedules = (ObjectListDataProvider) getSessionAttribute("search.schedulingrobot.stopschedules");
062: if (stopSchedules == null) {
063: retrieveStopSchedules();
064: }
065:
066: tspl1 = new TableSelectPhaseListener();
067: tspl2 = new TableSelectPhaseListener();
068: }
069:
070: public ObjectListDataProvider getStartSchedules() {
071: return (ObjectListDataProvider) getSessionAttribute("search.schedulingrobot.startschedules");
072: }
073:
074: public void setStartSchedules(ObjectListDataProvider startSchedules) {
075: setSessionAttribute("search.schedulingrobot.startschedules",
076: startSchedules);
077: }
078:
079: public ObjectListDataProvider getStopSchedules() {
080: return (ObjectListDataProvider) getSessionAttribute("search.schedulingrobot.stopschedules");
081: }
082:
083: public void setStopSchedules(ObjectListDataProvider stopSchedules) {
084: setSessionAttribute("search.schedulingrobot.stopschedules",
085: stopSchedules);
086: }
087:
088: public TableRowGroup getTableRowGroup1() {
089: return tableRowGroup1;
090: }
091:
092: public void setTableRowGroup1(TableRowGroup tableRowGroup) {
093: this .tableRowGroup1 = tableRowGroup;
094: }
095:
096: public TableRowGroup getTableRowGroup2() {
097: return tableRowGroup2;
098: }
099:
100: public void setTableRowGroup2(TableRowGroup tableRowGroup) {
101: this .tableRowGroup2 = tableRowGroup;
102: }
103:
104: public Object getSelected1() {
105: return tspl1.getSelected(getTableRow1());
106: }
107:
108: public void setSelected1(Object object) {
109: tspl1.setSelected(getTableRow1(), object);
110: }
111:
112: public Object getSelected2() {
113: return tspl2.getSelected(getTableRow2());
114: }
115:
116: public void setSelected2(Object object) {
117: tspl2.setSelected(getTableRow2(), object);
118: }
119:
120: public String createStart() {
121: ObjectListDataProvider startSchedules = (ObjectListDataProvider) getSessionAttribute("search.schedulingrobot.startschedules");
122: if (startSchedules == null) {
123: retrieveStartSchedules();
124: }
125:
126: if (startSchedules.canAppendRow()) {
127: startSchedules.appendRow();
128: startSchedules.commitChanges();
129: setSessionAttribute(
130: "search.schedulingrobot.startschedules",
131: startSchedules);
132: }
133:
134: return null;
135: }
136:
137: public String createStop() {
138: ObjectListDataProvider stopSchedules = (ObjectListDataProvider) getSessionAttribute("search.schedulingrobot.stopschedules");
139: if (stopSchedules == null) {
140: retrieveStopSchedules();
141: }
142:
143: if (stopSchedules.canAppendRow()) {
144: stopSchedules.appendRow();
145: stopSchedules.commitChanges();
146: setSessionAttribute("search.schedulingrobot.stopschedules",
147: stopSchedules);
148: }
149:
150: return null;
151: }
152:
153: public String deleteStart() {
154: ObjectListDataProvider startSchedules = (ObjectListDataProvider) getSessionAttribute("search.schedulingrobot.startschedules");
155: if (startSchedules == null) {
156: retrieveStartSchedules();
157: }
158:
159: RowKey[] rowKeys = tableRowGroup1.getRenderedRowKeys();
160: if (rowKeys != null) {
161: for (int index = 0; index < rowKeys.length; index++) {
162: RowKey rowKey = rowKeys[index];
163: if (tspl1.isSelected(rowKey)
164: && startSchedules.isRowAvailable(rowKey)
165: && startSchedules.canRemoveRow(rowKey)) {
166: startSchedules.removeRow(rowKey);
167: }
168: }
169: startSchedules.commitChanges();
170: setSessionAttribute(
171: "search.schedulingrobot.startschedules",
172: startSchedules);
173: tableRowGroup1.setFirst(0);
174: tspl1.clear();
175: }
176:
177: return null;
178: }
179:
180: public String deleteStop() {
181: ObjectListDataProvider stopSchedules = (ObjectListDataProvider) getSessionAttribute("search.schedulingrobot.stopschedules");
182: if (stopSchedules == null) {
183: retrieveStopSchedules();
184: }
185:
186: RowKey[] rowKeys = tableRowGroup2.getRenderedRowKeys();
187: if (rowKeys != null) {
188: for (int index = 0; index < rowKeys.length; index++) {
189: RowKey rowKey = rowKeys[index];
190: if (tspl2.isSelected(rowKey)
191: && stopSchedules.isRowAvailable(rowKey)
192: && stopSchedules.canRemoveRow(rowKey)) {
193: stopSchedules.removeRow(rowKey);
194: }
195: }
196: stopSchedules.commitChanges();
197: setSessionAttribute("search.schedulingrobot.stopschedules",
198: stopSchedules);
199: tableRowGroup2.setFirst(0);
200: tspl2.clear();
201: }
202:
203: return null;
204: }
205:
206: public String save() {
207: ArrayList originalStartSchedules = new ArrayList();
208: ArrayList originalStopSchedules = new ArrayList();
209: try {
210: LinkedList path = new LinkedList();
211: path.addFirst(AdminClientUtil.DEFAULT_DOMAIN);
212: path.addFirst("scheduler");
213: ObjectName on = AdminClientUtil.getResourceMBeanObjectName(
214: AdminClientUtil.SCHEDULER_MBEAN_TYPE, path);
215:
216: Object[] params1 = { host, startCommand };
217: String[] signatures1 = { "java.lang.String",
218: "java.lang.String" };
219: ArrayList data = (ArrayList) getMBeanServerConnection()
220: .invoke(on, "getSchedules", params1, signatures1);
221: for (int index = 0; index < data.size(); index++) {
222: String string = (String) data.get(index);
223: originalStartSchedules.add(string);
224: }
225:
226: Object[] params2 = { host, stopCommand };
227: String[] signatures2 = { "java.lang.String",
228: "java.lang.String" };
229: data = (ArrayList) getMBeanServerConnection().invoke(on,
230: "getSchedules", params2, signatures2);
231: for (int index = 0; index < data.size(); index++) {
232: String string = (String) data.get(index);
233: originalStopSchedules.add(string);
234: }
235: } catch (Exception e) {
236: log(Level.SEVERE,
237: "SchedulingRobotBean.save() : Exception ", e);
238: }
239:
240: ArrayList newStartSchedules = new ArrayList();
241: ObjectListDataProvider startSchedules = (ObjectListDataProvider) getSessionAttribute("search.schedulingrobot.startschedules");
242: if (startSchedules == null) {
243: retrieveStartSchedules();
244: }
245: startSchedules.commitChanges();
246: List l = startSchedules.getList();
247: for (int index = 0; index < l.size(); index++) {
248: ScheduleBean sb = (ScheduleBean) l.get(index);
249: if (sb.initialized()) {
250: newStartSchedules.add(sb.getSchedule(startCommand));
251: }
252: }
253:
254: ArrayList newStopSchedules = new ArrayList();
255: ObjectListDataProvider stopSchedules = (ObjectListDataProvider) getSessionAttribute("search.schedulingrobot.stopschedules");
256: if (stopSchedules == null) {
257: retrieveStopSchedules();
258: }
259: stopSchedules.commitChanges();
260: l = stopSchedules.getList();
261: for (int index = 0; index < l.size(); index++) {
262: ScheduleBean sb = (ScheduleBean) l.get(index);
263: if (sb.initialized()) {
264: newStopSchedules.add(sb.getSchedule(stopCommand));
265: }
266: }
267:
268: try {
269: LinkedList path = new LinkedList();
270: path.addFirst(AdminClientUtil.DEFAULT_DOMAIN);
271: path.addFirst("scheduler");
272: ObjectName on = AdminClientUtil.getResourceMBeanObjectName(
273: AdminClientUtil.SCHEDULER_MBEAN_TYPE, path);
274:
275: if (originalStartSchedules.size() > 0) {
276: Object[] params = { host, originalStartSchedules };
277: String[] signatures = { "java.lang.String",
278: "java.util.List" };
279: getMBeanServerConnection().invoke(on, "unschedule",
280: params, signatures);
281: }
282: if (newStartSchedules.size() > 0) {
283: Object[] params = { host, newStartSchedules };
284: String[] signatures = { "java.lang.String",
285: "java.util.List" };
286: getMBeanServerConnection().invoke(on, "schedule",
287: params, signatures);
288: }
289:
290: if (originalStopSchedules.size() > 0) {
291: Object[] params = { host, originalStopSchedules };
292: String[] signatures = { "java.lang.String",
293: "java.util.List" };
294: getMBeanServerConnection().invoke(on, "unschedule",
295: params, signatures);
296: }
297: if (newStopSchedules.size() > 0) {
298: Object[] params = { host, newStopSchedules };
299: String[] signatures = { "java.lang.String",
300: "java.util.List" };
301: getMBeanServerConnection().invoke(on, "schedule",
302: params, signatures);
303: }
304: } catch (Exception e) {
305: log(Level.SEVERE,
306: "SchedulingRobotBean.save() : Exception ", e);
307: }
308:
309: return null;
310: }
311:
312: public String reset() {
313: retrieveStartSchedules();
314: retrieveStopSchedules();
315: return null;
316: }
317:
318: private void retrieveSearchServerHost() {
319: try {
320: LinkedList path = new LinkedList();
321: path.addFirst(AdminClientUtil.DEFAULT_DOMAIN);
322: path
323: .addFirst((String) getSessionAttribute("search.server.selected"));
324: ObjectName on = AdminClientUtil.getResourceMBeanObjectName(
325: AdminClientUtil.SEARCHSERVER_MBEAN_TYPE, path);
326: host = (String) getMBeanServerConnection().getAttribute(on,
327: "Host");
328: } catch (Exception e) {
329: log(
330: Level.SEVERE,
331: "SchedulingRobotBean.retrieveSearchServerHost() : Exception ",
332: e);
333: }
334: }
335:
336: private void retrieveCommands() {
337: try {
338: LinkedList path = new LinkedList();
339: path.addFirst(AdminClientUtil.DEFAULT_DOMAIN);
340: path
341: .addFirst((String) getSessionAttribute("search.server.selected"));
342: ObjectName on = AdminClientUtil.getResourceMBeanObjectName(
343: AdminClientUtil.SEARCHSERVER_MBEAN_TYPE, path);
344: Object[] params = {};
345: String[] signatures = {};
346: startCommand = (String) getMBeanServerConnection()
347: .invoke(on, "retrieveStartRobotCommand", params,
348: signatures);
349: stopCommand = (String) getMBeanServerConnection().invoke(
350: on, "retrieveStopRobotCommand", params, signatures);
351: } catch (Exception e) {
352: log(
353: Level.SEVERE,
354: "SchedulingRobotBean.retrieveCommands() : Exception ",
355: e);
356: }
357: }
358:
359: private void retrieveStartSchedules() {
360: ArrayList al = new ArrayList();
361: try {
362: LinkedList path = new LinkedList();
363: path.addFirst(AdminClientUtil.DEFAULT_DOMAIN);
364: path.addFirst("scheduler");
365: ObjectName on = AdminClientUtil.getResourceMBeanObjectName(
366: AdminClientUtil.SCHEDULER_MBEAN_TYPE, path);
367:
368: Object[] params = { host, startCommand };
369: String[] signatures = { "java.lang.String",
370: "java.lang.String" };
371: ArrayList data = (ArrayList) getMBeanServerConnection()
372: .invoke(on, "getSchedules", params, signatures);
373: for (int index = 0; index < data.size(); index++) {
374: String string = (String) data.get(index);
375: String[] strings = string.split("\\|");
376:
377: ScheduleBean sb = new ScheduleBean();
378: sb.initialize(strings[1].trim());
379: al.add(sb);
380: }
381: } catch (Exception e) {
382: log(
383: Level.SEVERE,
384: "SchedulingRobotBean.retrieveStartSchedules() : Exception ",
385: e);
386: }
387: ObjectListDataProvider startSchedules = new ObjectListDataProvider(
388: al);
389: startSchedules.setObjectType(ScheduleBean.class);
390:
391: setSessionAttribute("search.schedulingrobot.startschedules",
392: startSchedules);
393: }
394:
395: private void retrieveStopSchedules() {
396: ArrayList al = new ArrayList();
397: try {
398: LinkedList path = new LinkedList();
399: path.addFirst(AdminClientUtil.DEFAULT_DOMAIN);
400: path.addFirst("scheduler");
401: ObjectName on = AdminClientUtil.getResourceMBeanObjectName(
402: AdminClientUtil.SCHEDULER_MBEAN_TYPE, path);
403:
404: Object[] params = { host, stopCommand };
405: String[] signatures = { "java.lang.String",
406: "java.lang.String" };
407: ArrayList data = (ArrayList) getMBeanServerConnection()
408: .invoke(on, "getSchedules", params, signatures);
409: for (int index = 0; index < data.size(); index++) {
410: String string = (String) data.get(index);
411: String[] strings = string.split("\\|");
412:
413: ScheduleBean sb = new ScheduleBean();
414: sb.initialize(strings[1].trim());
415: al.add(sb);
416: }
417: } catch (Exception e) {
418: log(
419: Level.SEVERE,
420: "SchedulingRobotBean.retrieveStopSchedules() : Exception ",
421: e);
422: }
423: ObjectListDataProvider stopSchedules = new ObjectListDataProvider(
424: al);
425: stopSchedules.setObjectType(ScheduleBean.class);
426:
427: setSessionAttribute("search.schedulingrobot.stopschedules",
428: stopSchedules);
429: }
430:
431: private RowKey getTableRow1() {
432: FacesContext fc = FacesContext.getCurrentInstance();
433: ValueBinding vb = fc.getApplication().createValueBinding(
434: "#{startSchedule.tableRow}");
435: return (RowKey) vb.getValue(fc);
436: }
437:
438: private RowKey getTableRow2() {
439: FacesContext fc = FacesContext.getCurrentInstance();
440: ValueBinding vb = fc.getApplication().createValueBinding(
441: "#{stopSchedule.tableRow}");
442: return (RowKey) vb.getValue(fc);
443: }
444:
445: }
|