It seems that this was not reaching nutch-user so here's it again in
case someone else is also interested.
---
hello,
here's an adhoc addition to search server to support shutdown command.
client calls server like this:
"bin/nutch 'org.apache.nutch.searcher.DistributedSearch$Client'
-shutdown 127.0.0.1 9999"
--
Sami Siren
Alvaro Cabrerizo wrote:
2006/9/27, Sami Siren <[EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]>>:
Alvaro Cabrerizo wrote:
> How could I stop an index server (started with "bin/nutch server
<port>
> <index>") knowing the port?
>
> Thanks in advance.
>
It does not support such a feature. Can you describe a little bit more
what are you trying to accomplish something similar to tomcats SHUTDOWN?
Sure,
That's right. If this feature doesn't exist, I'm looking for a clue to
develop a SHUTDOWN and a RESTART command, using NUTCH/HADOOP api. The
idea is to have a group of JAVA classes that lets people execute a
command like: "SERVER_RESTART <port>" or more advanced "SERVER_RESTART
<port> <ip_address>".
Anyway I can execute "ps aux | grep 44444" in a shell and find out
proccess number in order to kill it or I can make a "^C" to stop it, but
this is not the solution I'm looking for.
Thanks, in advance.
--
Sami Siren
Index: src/java/org/apache/nutch/searcher/NutchBean.java
===================================================================
--- src/java/org/apache/nutch/searcher/NutchBean.java (revision 447940)
+++ src/java/org/apache/nutch/searcher/NutchBean.java (working copy)
@@ -25,10 +25,12 @@
import org.apache.hadoop.fs.*;
import org.apache.hadoop.io.Closeable;
+import org.apache.hadoop.ipc.RPC.Server;
import org.apache.hadoop.conf.*;
import org.apache.nutch.parse.*;
import org.apache.nutch.indexer.*;
import org.apache.nutch.crawl.Inlinks;
+import org.apache.nutch.searcher.DistributedSearch.Protocol;
import org.apache.nutch.util.NutchConfiguration;
/**
@@ -36,8 +38,8 @@
* @version $Id: NutchBean.java,v 1.19 2005/02/07 19:10:08 cutting Exp $
*/
public class NutchBean
- implements Searcher, HitDetailer, HitSummarizer, HitContent, HitInlinks,
- DistributedSearch.Protocol, Closeable {
+ implements Protocol, Searcher, HitDetailer, HitSummarizer, HitContent, HitInlinks,
+ Closeable {
public static final Log LOG = LogFactory.getLog(NutchBean.class);
@@ -400,12 +402,29 @@
public long getProtocolVersion(String className, long arg1) throws IOException {
if(DistributedSearch.Protocol.class.getName().equals(className)){
- return 1;
+ return DistributedSearch.Client.versionID;
} else {
throw new IOException("Unknown Protocol classname:" + className);
}
}
-
-
+ public void shutdown() {
+ try {
+ LOG.info("Closing NutchBean instance " + this);
+ this.close();
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ final Server server=(Server)conf.getObject(DistributedSearch.DISTRIBITED_SERVER_INSTANCE);
+
+ new Thread(){
+ public void run(){
+
+ LOG.info("Shutting down server instance:" + server);
+ server.stop();
+ }
+ }.start();
+
+ }
}
Index: src/java/org/apache/nutch/searcher/DistributedSearch.java
===================================================================
--- src/java/org/apache/nutch/searcher/DistributedSearch.java (revision 447940)
+++ src/java/org/apache/nutch/searcher/DistributedSearch.java (working copy)
@@ -38,6 +38,8 @@
/** Implements the search API over IPC connnections. */
public class DistributedSearch {
+
+ public static final String DISTRIBITED_SERVER_INSTANCE = "DistribitedServerInstance";
public static final Log LOG = LogFactory.getLog(DistributedSearch.class);
private DistributedSearch() {} // no public ctor
@@ -48,11 +50,17 @@
/** The name of the segments searched by this node. */
String[] getSegmentNames();
+
+
+ /** Ask server to shutdown itself
+ * @throws IOException */
+ void shutdown();
}
/** The search server. */
public static class Server {
+
private Server() {}
/** Runs a search server. */
@@ -70,6 +78,7 @@
Configuration conf = NutchConfiguration.create();
org.apache.hadoop.ipc.Server server = getServer(conf, directory, port);
+ conf.setObject(DISTRIBITED_SERVER_INSTANCE, server);
server.start();
server.join();
}
@@ -83,7 +92,7 @@
/** The search client. */
public static class Client extends Thread
- implements Searcher, HitDetailer, HitSummarizer, HitContent, HitInlinks,
+ implements Protocol, Searcher, HitDetailer, HitSummarizer, HitContent, HitInlinks,
Runnable {
private InetSocketAddress[] defaultAddresses;
@@ -143,6 +152,8 @@
private static final Method SEARCH;
private static final Method DETAILS;
private static final Method SUMMARY;
+ private static final Method SHUTDOWN;
+
static {
try {
GET_SEGMENTS = Protocol.class.getMethod
@@ -154,12 +165,13 @@
("getDetails", new Class[] { Hit.class});
SUMMARY = Protocol.class.getMethod
("getSummary", new Class[] { HitDetails.class, Query.class});
+ SHUTDOWN = Protocol.class.getMethod
+ ("shutdown", new Class[] {});
} catch (NoSuchMethodException e) {
throw new RuntimeException(e);
}
}
-
/** Updates segment names.
*
* @throws IOException
@@ -318,7 +330,7 @@
public Summary getSummary(HitDetails hit, Query query) throws IOException {
return getRemote(hit).getSummary(hit, query);
}
-
+
public Summary[] getSummary(HitDetails[] hits, Query query)
throws IOException {
InetSocketAddress[] addrs = new InetSocketAddress[hits.length];
@@ -358,15 +370,13 @@
}
public static void main(String[] args) throws Exception {
- String usage = "DistributedSearch$Client query <host> <port> ...";
+ String usage = "DistributedSearch$Client [query <host> <port>] [-shutdown <host> <port>] ...";
if (args.length == 0) {
System.err.println(usage);
System.exit(-1);
}
- Query query = Query.parse(args[0], NutchConfiguration.create());
-
InetSocketAddress[] addresses = new InetSocketAddress[(args.length-1)/2];
for (int i = 0; i < (args.length-1)/2; i++) {
addresses[i] =
@@ -374,14 +384,22 @@
}
Client client = new Client(addresses, NutchConfiguration.create());
- //client.setTimeout(Integer.MAX_VALUE);
- Hits hits = client.search(query, 10, null, null, false);
- System.out.println("Total hits: " + hits.getTotal());
- for (int i = 0; i < hits.getLength(); i++) {
- System.out.println(" "+i+" "+ client.getDetails(hits.getHit(i)));
+
+ if("-shutdown".equals(args[0])){
+ client.shutdown();
+ } else {
+ Query query = Query.parse(args[0], NutchConfiguration.create());
+ Hits hits = client.search(query, 10, null, null, false);
+ System.out.println("Total hits: " + hits.getTotal());
+ for (int i = 0; i < hits.getLength(); i++) {
+ System.out.println(" "+i+" "+ client.getDetails(hits.getHit(i)));
+ }
}
+
+
+
}
public void run() {
@@ -412,5 +430,24 @@
running = false;
interrupt();
}
+
+ /**
+ * Ask server to shutdown itself
+ * @param port
+ * @throws IOException
+ */
+ public void shutdown() {
+ try{
+ Object[][] params = new Object[defaultAddresses.length][0];
+ RPC.call(SHUTDOWN, params, defaultAddresses, this.conf);
+ } catch (Exception e){
+ LOG.info("Cannot initiate shutdown:" + e);
+ }
+ }
+
+ public long getProtocolVersion(String protocol, long clientVersion) throws IOException {
+ // TODO Auto-generated method stub
+ return 0;
+ }
}
}
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Nutch-general mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/nutch-general