/*
 * 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.accumulo.server.util;

import java.io.IOException;

import org.apache.accumulo.core.Constants;
import org.apache.accumulo.core.zookeeper.ZooUtil.NodeMissingPolicy;
import org.apache.accumulo.server.client.HdfsZooInstance;
import org.apache.accumulo.server.zookeeper.ZooReaderWriter;
import org.apache.log4j.Logger;
import org.apache.zookeeper.KeeperException;

public class CleanZookeeper {
  
  private static final Logger log = Logger.getLogger(CleanZookeeper.class);
  
  /**
   * @param args
   *          should contain one element: the address of a zookeeper node
   * @throws IOException
   *           error connecting to accumulo or zookeeper
   */
  public static void main(String[] args) throws IOException {
    if (args.length < 1) {
      System.err.println("Usage: " + CleanZookeeper.class.getName() + " hostname[:port]");
      System.exit(1);
    }
    String root = Constants.ZROOT;
    ZooReaderWriter zk = ZooReaderWriter.getInstance();
    try {
      for (String child : zk.getChildren(root)) {
        if (Constants.ZINSTANCES.equals("/" + child)) {
          for (String instanceName : zk.getChildren(root + Constants.ZINSTANCES)) {
            String instanceNamePath = root + Constants.ZINSTANCES + "/" + instanceName;
            byte[] id = zk.getData(instanceNamePath, null);
            if (id != null && !new String(id).equals(HdfsZooInstance.getInstance().getInstanceID())) {
              try {
                zk.recursiveDelete(instanceNamePath, NodeMissingPolicy.SKIP);
              } catch (KeeperException.NoAuthException ex) {
                log.warn("Unable to delete " + instanceNamePath);
              }
            }
          }
        } else if (!child.equals(HdfsZooInstance.getInstance().getInstanceID())) {
          String path = root + "/" + child;
          try {
            zk.recursiveDelete(path, NodeMissingPolicy.SKIP);
          } catch (KeeperException.NoAuthException ex) {
            log.warn("Unable to delete " + path);
          }
        }
      }
    } catch (Exception ex) {
      System.out.println("Error Occurred: " + ex);
    }
  }
  
}

@@ -1328,14 +1328,12 @@
     
-should
+must
  con
@@ -1382,16 +1382,93 @@
 er node%0A
+   *          a second parameter provides an additional authentication value%0A
    * @th
@@ -1723,16 +1723,23 @@
 e%5B:port%5D
+ %5Bauth%5D
 %22);%0A    
@@ -1853,16 +1853,122 @@
 ance();%0A
+    if (args.length == 2) %7B%0A      zk.getZooKeeper().addAuthInfo(%22digest%22, args%5B1%5D.getBytes());%0A    %7D%0A    %0A
     try 

allow users to provide additional digest auth to clean up old entries in zookeeper