001: /*
002: * Copyright 2001 Sun Microsystems, Inc. All rights reserved.
003: * PROPRIETARY/CONFIDENTIAL. Use of this product is subject to license terms.
004: */
005:
006: package com.sun.portal.search.admin.model;
007:
008: import java.lang.*;
009: import java.util.*;
010: import java.util.logging.Logger;
011: import java.util.logging.Level;
012: import java.io.*;
013:
014: import javax.servlet.http.HttpServletRequest;
015:
016: import com.iplanet.jato.view.*;
017: import com.iplanet.jato.model.*;
018: import com.iplanet.jato.util.*;
019:
020: import com.sun.portal.search.rdmserver.*;
021: import com.sun.portal.search.rdmgr.*;
022: import com.sun.portal.search.util.SearchConfig;
023: import com.sun.portal.search.admin.CSConfig;
024: import com.sun.portal.log.common.PortalLogger;
025:
026: public class ReindexModel extends DefaultModel {
027: String serverRoot = null;
028: String output = "";
029: public String purgeSecString = "Purging the old category index...";
030: public String reindexSecString = "Indexing the categories...";
031:
032: // Create a Logger for this class
033: private static Logger debugLogger = PortalLogger
034: .getLogger(ReindexModel.class);
035:
036: public ReindexModel() {
037: serverRoot = CSConfig.getServerRoot();
038: }
039:
040: public ReindexModel(String name) {
041: serverRoot = CSConfig.getServerRoot();
042: }
043:
044: /*
045: * Load the SearchConfig file
046: */
047: public void initSearchConfig() {
048: String csidfn = serverRoot + File.separator
049: + SearchConfig.CONFDIR + File.separator
050: + SearchConfig.SEARCH_CONF;
051: debugLogger.log(Level.FINER, "PSSH_CSPSAM0038", csidfn);
052:
053: try {
054: SearchConfig.init(csidfn);
055: } catch (Exception e) {
056: debugLogger.log(Level.INFO, "PSSH_CSPSAM0039", serverRoot);
057: }
058: }
059:
060: // Used for purging the entire database. entire compass db directory,compass db = nova db + bdb
061: public synchronized boolean purgeDatabase() {
062: boolean res = false;
063: String cmd;
064: if (System.getProperty("os.name").startsWith("win")
065: || System.getProperty("os.name").startsWith("Win")
066: || System.getProperty("os.name").startsWith("WIN")) {
067: cmd = CSConfig.getServerRoot() + File.separator
068: + "run-cs-cli.bat rdmgr -p stdout -X -y "
069: + SearchConfig.getValue(SearchConfig.DBNAME);
070: } else {
071: cmd = CSConfig.getServerRoot() + File.separator
072: + "run-cs-cli rdmgr -p stdout -X -y "
073: + SearchConfig.getValue(SearchConfig.DBNAME);
074: }
075:
076: Runtime rt = Runtime.getRuntime();
077: debugLogger.log(Level.FINER, "PSSH_CSPSAM0033", cmd);
078: try {
079: Process process = rt.exec(cmd);
080: BufferedReader buf = new BufferedReader(
081: new InputStreamReader(process.getInputStream()));
082: String outLine = null;
083: while ((outLine = buf.readLine()) != null) {
084: debugLogger
085: .log(Level.FINER, "PSSH_CSPSAM0034", outLine);
086: output = output + " <BR> " + outLine;
087: }
088: res = process.waitFor() == 0;
089: } catch (Exception e) {
090: // XXX Not logging exceptions? XXX
091: debugLogger.log(Level.INFO, "PSSH_CSPSAM0012", e
092: .getMessage());
093: }
094: return res;
095: }
096:
097: /*
098: * index the categories
099: * run rdmgr -TV -p stdout csid https-nick/config/taxonomy.rdm
100: * executes a purge followed by a reindex of the taxonomy
101: */
102: public boolean indexCategories() {
103: try {
104: return indexCategories(null);
105: } catch (IOException e) {
106: return true;
107: }
108:
109: }
110:
111: public boolean indexCategories(Writer out) throws IOException {
112: boolean res = false;
113: String cmd[] = {
114: CSConfig.getServerRoot() + File.separator
115: + "run-cs-cli rdmgr -p stdout -T -X",
116: CSConfig.getServerRoot() + File.separator
117: + "run-cs-cli rdmgr -TV -p stdout "
118: + SearchConfig.getValue(SearchConfig.TAX) };
119:
120: if (System.getProperty("os.name").startsWith("win")
121: || System.getProperty("os.name").startsWith("Win")
122: || System.getProperty("os.name").startsWith("WIN")) {
123: for (int i = 0; i < cmd.length; i++) {
124: cmd[i].replaceAll("run-cs-cli", "run-cs-cli.bat");
125: }
126: }
127:
128: for (int i = 0; i < 2; i++) {
129: Runtime rt = Runtime.getRuntime();
130: if (i == 0) {
131: if (out != null) {
132: out.write("<B>" + purgeSecString + "</B><BR>\n");
133: out.flush();
134: }
135: } else {
136: if (out != null) {
137: out.write("<BR><B>" + reindexSecString
138: + "</B><BR>\n");
139: out.flush();
140: }
141: }
142: debugLogger.log(Level.FINER, "PSSH_CSPSAM0033", cmd[i]);
143: try {
144: Process process = rt.exec(cmd[i]);
145: BufferedReader buf = new BufferedReader(
146: new InputStreamReader(process.getInputStream()));
147: String outLine = null;
148: while ((outLine = buf.readLine()) != null) {
149: if (out != null) {
150: out.write(outLine + "<BR>");
151: out.flush();
152: }
153: debugLogger.log(Level.FINER, "PSSH_CSPSAM0034",
154: outLine);
155: output = output + " <BR> " + outLine;
156: }
157: res = process.waitFor() == 0;
158: } catch (Exception e) {
159: // XXX Not logging exceptions? XXX
160: debugLogger.log(Level.INFO, "PSSH_CSPSAM0012", e
161: .getMessage());
162: }
163: }
164:
165: return res;
166: }
167:
168: /*
169: * index the categories
170: * run rdmgr -TV -p stdout csid https-nick/config/taxonomy.rdm
171: */
172: public synchronized boolean reindexDatabase() {
173: boolean res = false;
174: String cmd[] = {
175: CSConfig.getServerRoot() + File.separator
176: + "run-cs-cli rdmgr -p stdout -X -V",
177: CSConfig.getServerRoot() + File.separator
178: + "run-cs-cli rdmgr -I -p stdout -y "
179: + SearchConfig.getValue(SearchConfig.DBNAME) };
180:
181: if (System.getProperty("os.name").startsWith("win")
182: || System.getProperty("os.name").startsWith("Win")
183: || System.getProperty("os.name").startsWith("WIN")) {
184: for (int i = 0; i < cmd.length; i++) {
185: cmd[i].replaceAll("run-cs-cli", "run-cs-cli.bat");
186: }
187: }
188:
189: for (int i = 0; i < 2; i++) {
190: Runtime rt = Runtime.getRuntime();
191: debugLogger.log(Level.FINER, "PSSH_CSPSAM0033", cmd[i]);
192:
193: try {
194: Process process = rt.exec(cmd[i]);
195: String outLine = null;
196: BufferedReader buf = new BufferedReader(
197: new InputStreamReader(process.getInputStream()));
198: while ((outLine = buf.readLine()) != null) {
199: debugLogger.log(Level.FINER, "PSSH_CSPSAM0034",
200: outLine);
201: output = output + " <BR> " + outLine;
202: }
203: res = process.waitFor() == 0;
204: } catch (Exception e) {
205: debugLogger.log(Level.INFO, "PSSH_CSPSAM0012", e
206: .getMessage());
207: }
208: }
209: return res;
210: }
211:
212: public String getOutput() {
213: return output;
214: }
215: }
|