ksprojects / zkcopy

ZooKeeper copy utililty
Apache License 2.0
237 stars 94 forks source link

CLI improvement #3

Closed kshchepanovskyi closed 8 years ago

kshchepanovskyi commented 9 years ago

Use commons-cli for working with command-line arguments.

hekaldama commented 8 years ago

@kshchepanovskyi does it actually work for you at all? I can't figure out what I am doing wrong, but it won't work at all per README.

Apache Maven 3.0.5 java version "1.7.0_79"

I just keep getting usage examples passing in:

java -jar target/zkcopy-*-jar-with-dependencies.jar \
  -Dsource="somehost:2181/dir/active" \
  -Ddestination="somehost:2181/dir/backup" \
  -Dthreads=10 \
  -DremoveDeprecatedNodes=false

Thanks in advance.

hekaldama commented 8 years ago

I had to put the -jar *jar after all the -D and it worked. Yay.

kshchepanovskyi commented 8 years ago

Interesting, it worked for me in the original form. I can check it again later.

Raboo commented 8 years ago

Same problem here, @hekaldama workaround worked for me.

kshchepanovskyi commented 8 years ago

It is related to parameter order for JVM, system properties should go before -jar. In any case, I'm going to change it from system properties to CLI arguments. Wait few hours :)

kshchepanovskyi commented 8 years ago

Guys, please review: https://github.com/kshchepanovskyi/zkcopy/pull/6

Konstantin@ks-laptop MINGW64 ~/IdeaProjects/zkcopy (cli-improvement)
$ java -jar target/zkcopy.jar
usage: zkcopy
 -c,--copyOnly <true|false>       (optional) set this flag if you do not
                                  want to remove nodes that are removed on
                                  source
 -h,--help                        print this message
 -s,--source <server:port/path>   location of a source tree to copy
 -t,--target <server:port/path>   target location
 -w,--workers <N>                 (optional) number of concurrent workers
                                  to copy data

Also, improved error handling - there was a bug, if source is not available it could wipe out target.

Now we just stop everything if there is problem with reading data:

Konstantin@ks-laptop MINGW64 ~/IdeaProjects/zkcopy (cli-improvement)
$ java -jar target/zkcopy.jar -s localhost:1234/hello/world -t localhost:4321/hello/world
2016-06-14 21:35:42,548 [main] INFO  com.github.ksprojects.ZkCopy - using 10 concurrent workers to copy data
2016-06-14 21:35:42,549 [main] INFO  com.github.ksprojects.zkcopy.reader.Reader - Reading /hello/world from localhost:1234
2016-06-14 21:35:43,660 [main] INFO  com.github.ksprojects.zkcopy.reader.Reader - Processing, total=1, processed=0
2016-06-14 21:35:43,667 [main-SendThread(0:0:0:0:0:0:0:1:1234)] WARN  org.apache.zookeeper.ClientCnxn - Session 0x0 for server null, unexpected error, closing socket connection and attempting reconnect
java.net.ConnectException: Connection refused: no further information
        at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
        at sun.nio.ch.SocketChannelImpl.finishConnect(Unknown Source)
        at org.apache.zookeeper.ClientCnxnSocketNIO.doTransport(ClientCnxnSocketNIO.java:361)
        at org.apache.zookeeper.ClientCnxn$SendThread.run(ClientCnxn.java:1081)
2016-06-14 21:35:43,792 [Thread-0] ERROR com.github.ksprojects.zkcopy.reader.NodeReader - Could not read from remote server
org.apache.zookeeper.KeeperException$ConnectionLossException: KeeperErrorCode = ConnectionLoss for /hello/world
        at org.apache.zookeeper.KeeperException.create(KeeperException.java:99)
        at org.apache.zookeeper.KeeperException.create(KeeperException.java:51)
        at org.apache.zookeeper.ZooKeeper.getData(ZooKeeper.java:1155)
        at org.apache.zookeeper.ZooKeeper.getData(ZooKeeper.java:1184)
        at com.github.ksprojects.zkcopy.reader.NodeReader.run(NodeReader.java:45)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
        at java.lang.Thread.run(Unknown Source)
2016-06-14 21:35:44,661 [main] INFO  com.github.ksprojects.zkcopy.reader.Reader - Processing, total=1, processed=1
2016-06-14 21:35:44,661 [main] INFO  com.github.ksprojects.zkcopy.reader.Reader - Completed.
2016-06-14 21:35:44,662 [main] ERROR com.github.ksprojects.ZkCopy - FAILED
kshchepanovskyi commented 8 years ago

UPD: Just now realized how badly I want to make a refactoring of the code that I wrote 4 years ago :)