Repository: incubator-blur Updated Branches: refs/heads/apache-blur-0.2 ef83c6021 -> a32457744
Adding new command to remove shard node from running cluster. Is meant to kill off a malfunctioning shard server by removing is from zookeeper and allowing the cluster to failover. Project: http://git-wip-us.apache.org/repos/asf/incubator-blur/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-blur/commit/a3245774 Tree: http://git-wip-us.apache.org/repos/asf/incubator-blur/tree/a3245774 Diff: http://git-wip-us.apache.org/repos/asf/incubator-blur/diff/a3245774 Branch: refs/heads/apache-blur-0.2 Commit: a324577447f0c4d0f2a212328693309eca12d6ec Parents: ef83c60 Author: Aaron McCurry <[email protected]> Authored: Thu Feb 27 17:29:31 2014 -0500 Committer: Aaron McCurry <[email protected]> Committed: Thu Feb 27 17:29:31 2014 -0500 ---------------------------------------------------------------------- .../main/java/org/apache/blur/shell/Main.java | 3 +- .../blur/shell/RemoveShardServerCommand.java | 119 +++++++++++++++++++ blur-shell/src/test/resources/log4j.xml | 48 ++++++++ 3 files changed, 169 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/a3245774/blur-shell/src/main/java/org/apache/blur/shell/Main.java ---------------------------------------------------------------------- diff --git a/blur-shell/src/main/java/org/apache/blur/shell/Main.java b/blur-shell/src/main/java/org/apache/blur/shell/Main.java index 6735689..f9df7ed 100644 --- a/blur-shell/src/main/java/org/apache/blur/shell/Main.java +++ b/blur-shell/src/main/java/org/apache/blur/shell/Main.java @@ -405,7 +405,7 @@ public class Main { public static String[] clusterCommands = { "controllers", "shards", "clusterlist", "cluster", "safemodewait", "top" }; public static String[] shellCommands = { "help", "debug", "timed", "quit", "reset", "user", "whoami", "trace", "trace-remove", "trace-list" }; - public static String[] serverCommands = { "logger", "logger-reset" }; + public static String[] serverCommands = { "logger", "logger-reset", "remove-shard" }; private static class HelpCommand extends Command { @Override @@ -694,6 +694,7 @@ public class Main { register(builder, new TraceRemove()); register(builder, new LogCommand()); register(builder, new LogResetCommand()); + register(builder, new RemoveShardServerCommand()); commands = builder.build(); } http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/a3245774/blur-shell/src/main/java/org/apache/blur/shell/RemoveShardServerCommand.java ---------------------------------------------------------------------- diff --git a/blur-shell/src/main/java/org/apache/blur/shell/RemoveShardServerCommand.java b/blur-shell/src/main/java/org/apache/blur/shell/RemoveShardServerCommand.java new file mode 100644 index 0000000..e1c3941 --- /dev/null +++ b/blur-shell/src/main/java/org/apache/blur/shell/RemoveShardServerCommand.java @@ -0,0 +1,119 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.blur.shell; + +import java.io.IOException; +import java.io.PrintWriter; + +import jline.console.ConsoleReader; + +import org.apache.blur.BlurConfiguration; +import org.apache.blur.thirdparty.thrift_0_9_0.TException; +import org.apache.blur.thrift.generated.Blur; +import org.apache.blur.thrift.generated.BlurException; +import org.apache.blur.utils.BlurConstants; +import org.apache.zookeeper.KeeperException; +import org.apache.zookeeper.WatchedEvent; +import org.apache.zookeeper.Watcher; +import org.apache.zookeeper.ZooKeeper; + +public class RemoveShardServerCommand extends Command { + @Override + public void doit(PrintWriter out, Blur.Iface client, String[] args) throws CommandException, TException, + BlurException { + if (args.length != 2) { + throw new CommandException("Invalid args: " + help()); + } + ZooKeeper zooKeeper = null; + try { + try { + BlurConfiguration configuration = new BlurConfiguration(); + String connectString = configuration.get(BlurConstants.BLUR_ZOOKEEPER_CONNECTION); + int sessionTimeout = configuration.getInt(BlurConstants.BLUR_ZOOKEEPER_TIMEOUT, 30000); + zooKeeper = new ZooKeeper(connectString, sessionTimeout, new Watcher() { + @Override + public void process(WatchedEvent event) { + + } + }); + } catch (IOException e) { + if (Main.debug) { + e.printStackTrace(); + } + throw new CommandException(e.getMessage()); + } + + String node = args[1]; + + out.println("Are you sure you want to remove the shard server [" + node + "]? [y/N]"); + out.flush(); + + ConsoleReader reader = getConsoleReader(); + try { + int readCharacter = reader.readCharacter(); + if (!(readCharacter == 'y' || readCharacter == 'Y')) { + return; + } + } catch (IOException e) { + if (Main.debug) { + e.printStackTrace(); + } + throw new CommandException(e.getMessage()); + } + + String path = "/blur/clusters/" + Main.getCluster(client) + "/online-nodes/" + node; + zooKeeper.delete(path, -1); + } catch (InterruptedException e) { + if (Main.debug) { + e.printStackTrace(); + } + throw new CommandException(e.getMessage()); + } catch (KeeperException e) { + if (Main.debug) { + e.printStackTrace(); + } + throw new CommandException(e.getMessage()); + } finally { + if (zooKeeper != null) { + try { + zooKeeper.close(); + } catch (InterruptedException e) { + if (Main.debug) { + e.printStackTrace(); + } + } + } + } + } + + @Override + public String description() { + return "Remove a node from ZooKeeper which will cause the cluster to consider it dead."; + } + + @Override + public String usage() { + return "<node:port>"; + } + + @Override + public String name() { + return "remove-shard"; + } +} http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/a3245774/blur-shell/src/test/resources/log4j.xml ---------------------------------------------------------------------- diff --git a/blur-shell/src/test/resources/log4j.xml b/blur-shell/src/test/resources/log4j.xml new file mode 100644 index 0000000..c08e4a2 --- /dev/null +++ b/blur-shell/src/test/resources/log4j.xml @@ -0,0 +1,48 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<!-- +Licensed to the Apache Software Foundation (ASF) under one +or more contributor license agreements. See the NOTICE file +distributed with this work for additional information +regarding copyright ownership. The ASF licenses this file +to you under the Apache License, Version 2.0 (the +"License"); you may not use this file except in compliance +with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, +software distributed under the License is distributed on an +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +KIND, either express or implied. See the License for the +specific language governing permissions and limitations +under the License. +--> +<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd"> + +<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/"> + <appender name="console" class="org.apache.log4j.ConsoleAppender"> + <param name="Target" value="System.out" /> + <layout class="org.apache.log4j.PatternLayout"> + <param name="ConversionPattern" value="%-5p %d{yyyyMMdd_HH:mm:ss:SSS_z} [%t] %c{2}: %m%n" /> + </layout> + </appender> + <logger name="org.apache.hadoop"> + <level value="ERROR" /> + <appender-ref ref="console"/> + </logger> + <logger name="REQUEST_LOG" additivity="false"> + <!-- Make value = "INFO"to enable --> + <level value="ERROR" /> + <appender-ref ref="console"/> + </logger> + + <logger name="RESPONSE_LOG" additivity="false"> + <!-- Make value = "INFO"to enable --> + <level value="ERROR" /> + <appender-ref ref="console"/> + </logger> + <root> + <priority value="ERROR" /> + <appender-ref ref="console" /> + </root> +</log4j:configuration> \ No newline at end of file
