Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* 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 java.io.PrintStream;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.TimeZone;
import org.apache.jackrabbit.oak.plugins.document.ClusterNodeInfoDocument;
import org.apache.jackrabbit.oak.plugins.document.DocumentNodeStoreBuilder;
import org.apache.jackrabbit.oak.plugins.document.DocumentStore;
import org.apache.jackrabbit.oak.plugins.document.rdb.RDBJSONSupport;
import org.apache.jackrabbit.oak.run.commons.Command;
import com.google.common.io.Closer;
import joptsimple.OptionSpec;
class ClusterNodesCommand implements Command {
@Override
public void execute(String... args) throws Exception {
Closer closer = Utils.createCloserWithShutdownHook();
try {
String h = "clusternodes mongodb://host:port/database|jdbc:...";
ClusterNodesOptions options = new ClusterNodesOptions(h).parse(args);
if (options.isHelp()) {
options.printHelpOn(System.out);
System.exit(0);
}
DocumentNodeStoreBuilder> builder = Utils.createDocumentMKBuilder(options, closer);
if (builder == null) {
System.err
.println("Clusternodes command only available for DocumentNodeStore backed by MongoDB or RDB persistence");
System.exit(1);
}
builder.setReadOnlyMode();
DocumentStore ds = builder.getDocumentStore();
try {
List all = new ArrayList<>(ClusterNodeInfoDocument.all(ds));
Collections.sort(all, new Comparator() {
@Override
public int compare(ClusterNodeInfoDocument one, ClusterNodeInfoDocument two) {
return Integer.compare(one.getClusterId(), two.getClusterId());
}
});
if (options.isRaw()) {
printRaw(all);
} else {
print(all, options.isVerbose());
}
} catch (Throwable e) {
e.printStackTrace(System.err);
}
} catch (Throwable e) {
throw closer.rethrow(e);
} finally {
closer.close();
}
}
private static void print(List docs, boolean verbose) {
String sId = "Id";
String sState = "State";
String sStarted = "Started";
String sLeaseEnd = "LeaseEnd";
String sRecoveryBy = "RecoveryBy";
String sLeft = "Left";
String sLastRootRev = "LastRootRev";
String sOakVersion = "OakVersion";
long now = System.currentTimeMillis();
List header = new ArrayList<>();
header.addAll(Arrays.asList(new String[] { sId, sState, sStarted, sLeaseEnd, sLeft, sRecoveryBy }));
if (verbose) {
header.add(sLastRootRev);
header.add(sOakVersion);
}
SimpleDateFormat df = new SimpleDateFormat("yyyyMMdd'T'HHmmss'Z'");
df.setTimeZone(TimeZone.getTimeZone("UTC"));
List