Added: 
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/StandbyCommand.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/StandbyCommand.java?rev=1727599&view=auto
==============================================================================
--- 
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/StandbyCommand.java
 (added)
+++ 
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/StandbyCommand.java
 Fri Jan 29 15:17:44 2016
@@ -0,0 +1,109 @@
+/*
+ * 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.jackrabbit.oak.run;
+
+import static java.util.Arrays.asList;
+import static 
org.apache.jackrabbit.oak.plugins.segment.FileStoreHelper.openFileStore;
+
+import java.util.List;
+import java.util.concurrent.TimeUnit;
+
+import com.google.common.util.concurrent.AbstractScheduledService;
+import joptsimple.OptionParser;
+import joptsimple.OptionSet;
+import joptsimple.OptionSpec;
+import org.apache.jackrabbit.oak.plugins.segment.file.FileStore;
+import org.apache.jackrabbit.oak.plugins.segment.standby.client.StandbyClient;
+
+class StandbyCommand implements Command {
+
+    @Override
+    public void execute(String... args) throws Exception {
+        final String defaultHost = "127.0.0.1";
+        final int defaultPort = 8023;
+
+        final OptionParser parser = new OptionParser();
+        final OptionSpec<String> host = parser.accepts("host", "master 
host").withRequiredArg().ofType(String.class).defaultsTo(defaultHost);
+        final OptionSpec<Integer> port = parser.accepts("port", "master 
port").withRequiredArg().ofType(Integer.class).defaultsTo(defaultPort);
+        final OptionSpec<Integer> interval = parser.accepts("interval", 
"interval between successive 
executions").withRequiredArg().ofType(Integer.class);
+        final OptionSpec<Boolean> secure = parser.accepts("secure", "use 
secure connections").withRequiredArg().ofType(Boolean.class);
+        final OptionSpec<?> help = parser.acceptsAll(asList("h", "?", "help"), 
"show help").forHelp();
+        final OptionSpec<String> nonOption = parser.nonOptions("<path to 
repository>");
+
+        final OptionSet options = parser.parse(args);
+        final List<String> nonOptions = nonOption.values(options);
+
+        if (options.has(help)) {
+            parser.printHelpOn(System.out);
+            System.exit(0);
+        }
+
+        if (nonOptions.isEmpty()) {
+            parser.printHelpOn(System.err);
+            System.exit(1);
+        }
+
+        FileStore store = null;
+        StandbyClient failoverClient = null;
+        try {
+            store = openFileStore(nonOptions.get(0));
+            failoverClient = new StandbyClient(
+                    options.has(host)? options.valueOf(host) : defaultHost,
+                    options.has(port)? options.valueOf(port) : defaultPort,
+                    store,
+                    options.has(secure) && options.valueOf(secure), 10000);
+            if (!options.has(interval)) {
+                failoverClient.run();
+            } else {
+                ScheduledSyncService syncService = new 
ScheduledSyncService(failoverClient, options.valueOf(interval));
+                syncService.startAsync();
+                syncService.awaitTerminated();
+            }
+        } finally {
+            if (store != null) {
+                store.close();
+            }
+            if (failoverClient != null) {
+                failoverClient.close();
+            }
+        }
+    }
+
+    //TODO react to state changes of FailoverClient (triggered via JMX), once 
the state model of FailoverClient is complete.
+    private static class ScheduledSyncService extends AbstractScheduledService 
{
+
+        private final StandbyClient failoverClient;
+        private final int interval;
+
+        public ScheduledSyncService(StandbyClient failoverClient, int 
interval) {
+            this.failoverClient = failoverClient;
+            this.interval = interval;
+        }
+
+        @Override
+        public void runOneIteration() throws Exception {
+            failoverClient.run();
+        }
+
+        @Override
+        protected Scheduler scheduler() {
+            return Scheduler.newFixedDelaySchedule(0, interval, 
TimeUnit.SECONDS);
+        }
+    }
+
+}

Propchange: 
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/StandbyCommand.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/TikaCommand.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/TikaCommand.java?rev=1727599&view=auto
==============================================================================
--- 
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/TikaCommand.java
 (added)
+++ 
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/TikaCommand.java
 Fri Jan 29 15:17:44 2016
@@ -0,0 +1,29 @@
+/*
+ * 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.jackrabbit.oak.run;
+
+import org.apache.jackrabbit.oak.plugins.tika.TextExtractorMain;
+
+class TikaCommand implements Command {
+
+    @Override
+    public void execute(String... args) throws Exception {
+        TextExtractorMain.main(args);
+    }
+
+}

Propchange: 
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/TikaCommand.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/UpgradeCommand.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/UpgradeCommand.java?rev=1727599&view=auto
==============================================================================
--- 
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/UpgradeCommand.java
 (added)
+++ 
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/UpgradeCommand.java
 Fri Jan 29 15:17:44 2016
@@ -0,0 +1,27 @@
+/*
+ * 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.jackrabbit.oak.run;
+
+class UpgradeCommand implements Command {
+
+    @Override
+    public void execute(String... args) throws Exception {
+        System.out.println("This command was moved to the oak-upgrade module");
+    }
+
+}

Propchange: 
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/UpgradeCommand.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/Utils.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/Utils.java?rev=1727599&view=auto
==============================================================================
--- 
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/Utils.java
 (added)
+++ 
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/Utils.java
 Fri Jan 29 15:17:44 2016
@@ -0,0 +1,118 @@
+/*
+ * 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.jackrabbit.oak.run;
+
+import static java.util.Arrays.asList;
+import static 
org.apache.jackrabbit.oak.plugins.segment.FileStoreHelper.openFileStore;
+
+import java.io.Closeable;
+import java.io.IOException;
+import java.util.List;
+
+import com.google.common.io.Closer;
+import com.mongodb.MongoClientURI;
+import com.mongodb.MongoURI;
+import joptsimple.OptionParser;
+import joptsimple.OptionSet;
+import joptsimple.OptionSpec;
+import org.apache.jackrabbit.oak.plugins.document.DocumentMK;
+import org.apache.jackrabbit.oak.plugins.document.DocumentNodeStore;
+import org.apache.jackrabbit.oak.plugins.document.util.MongoConnection;
+import org.apache.jackrabbit.oak.plugins.segment.SegmentNodeStore;
+import org.apache.jackrabbit.oak.plugins.segment.file.FileStore;
+import org.apache.jackrabbit.oak.spi.state.NodeStore;
+
+class Utils {
+
+    public static NodeStore bootstrapNodeStore(String[] args, Closer closer, 
String h) throws IOException {
+        //TODO add support for other NodeStore flags
+        OptionParser parser = new OptionParser();
+        OptionSpec<Integer> clusterId = parser
+                .accepts("clusterId", "MongoMK clusterId").withRequiredArg()
+                .ofType(Integer.class).defaultsTo(0);
+        OptionSpec<?> help = parser.acceptsAll(asList("h", "?", "help"),
+                "show help").forHelp();
+        OptionSpec<String> nonOption = parser
+                .nonOptions(h);
+
+        OptionSet options = parser.parse(args);
+        List<String> nonOptions = nonOption.values(options);
+
+        if (options.has(help)) {
+            parser.printHelpOn(System.out);
+            System.exit(0);
+        }
+
+        if (nonOptions.isEmpty()) {
+            parser.printHelpOn(System.err);
+            System.exit(1);
+        }
+
+        String src = nonOptions.get(0);
+        if (src.startsWith(MongoURI.MONGODB_PREFIX)) {
+            MongoClientURI uri = new MongoClientURI(src);
+            if (uri.getDatabase() == null) {
+                System.err.println("Database missing in MongoDB URI: "
+                        + uri.getURI());
+                System.exit(1);
+            }
+            MongoConnection mongo = new MongoConnection(uri.getURI());
+            closer.register(asCloseable(mongo));
+            DocumentNodeStore store = new DocumentMK.Builder()
+                    .setMongoDB(mongo.getDB())
+                    .setLeaseCheck(false)
+                    .setClusterId(clusterId.value(options)).getNodeStore();
+            closer.register(asCloseable(store));
+            return store;
+        }
+
+        FileStore fs = openFileStore(src);
+        closer.register(asCloseable(fs));
+        return SegmentNodeStore.newSegmentNodeStore(fs).create();
+    }
+
+    static Closeable asCloseable(final FileStore fs) {
+        return new Closeable() {
+
+            @Override
+            public void close() throws IOException {
+                fs.close();
+            }
+        };
+    }
+
+    static Closeable asCloseable(final DocumentNodeStore dns) {
+        return new Closeable() {
+
+            @Override
+            public void close() throws IOException {
+                dns.dispose();
+            }
+        };
+    }
+
+    private static Closeable asCloseable(final MongoConnection con) {
+        return new Closeable() {
+
+            @Override
+            public void close() throws IOException {
+                con.close();
+            }
+        };
+    }
+}

Propchange: 
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/Utils.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: 
jackrabbit/oak/trunk/oak-run/src/test/java/org/apache/jackrabbit/oak/run/BasicServerTest.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-run/src/test/java/org/apache/jackrabbit/oak/run/BasicServerTest.java?rev=1727599&r1=1727598&r2=1727599&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-run/src/test/java/org/apache/jackrabbit/oak/run/BasicServerTest.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-run/src/test/java/org/apache/jackrabbit/oak/run/BasicServerTest.java
 Fri Jan 29 15:17:44 2016
@@ -18,6 +18,8 @@
  */
 package org.apache.jackrabbit.oak.run;
 
+import static org.junit.Assert.assertEquals;
+
 import java.net.HttpURLConnection;
 import java.net.URL;
 
@@ -25,26 +27,18 @@ import org.apache.jackrabbit.util.Base64
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
-import static org.junit.Assert.assertEquals;
 
 public class BasicServerTest {
 
-    private static final String SERVER_URL;
-
-    static {
-        String p = System.getProperty("jetty.http.port");
-        if (p != null) {
-            SERVER_URL = "http://localhost:"; + p + "/";
-        } else {
-            SERVER_URL = Main.URI;
-        }
+    private static int getPort() {
+        return Integer.getInteger("jetty.http.port", 8080);
     }
 
-    private Main.HttpServer server;
+    private HttpServer server;
 
     @Before
     public void startServer() throws Exception {
-        server = new Main.HttpServer(SERVER_URL);
+        server = new HttpServer(getPort());
     }
 
     @After
@@ -54,10 +48,10 @@ public class BasicServerTest {
 
     @Test
     public void testServerOk() throws Exception {
-        URL server = new URL(SERVER_URL);
+        URL server = new URL("http://localhost:"; + getPort());
         HttpURLConnection conn = (HttpURLConnection) server.openConnection();
-        conn.setRequestProperty(
-                "Authorization", "Basic " + Base64.encode("admin:admin"));
+        conn.setRequestProperty("Authorization", "Basic " + 
Base64.encode("admin:admin"));
         assertEquals(200, conn.getResponseCode());
     }
+
 }


Reply via email to