List of usage examples for org.apache.cassandra.tools NodeProbe NodeProbe
public NodeProbe(String host, int port) throws IOException
From source file:com.github.odiszapc.casskit.repair.ProbeRunner.java
License:Apache License
@Override public void execute() throws Exception { NodeProbe probe = new NodeProbe(opt(HOST), opt(JMX_PORT)); PrintStream devNull = new PrintStream(NULL_OUTPUT_STREAM); probe.forceRepairRangeAsync(devNull, opt(KEYSPACE), opt(SEQ), opt(LOCAL), opt(TOKEN_FROM), opt(TOKEN_TO), opt(COLUMN_FAMILY));//from ww w.ja v a 2 s.c o m }
From source file:com.spotify.cassandra.opstools.autobalance.Main.java
License:Apache License
private void run(CommandLine cmd) throws IOException, InterruptedException { boolean dryrun = cmd.hasOption("d"); boolean force = cmd.hasOption("f"); boolean noresolve = cmd.hasOption("r"); int port = cmd.hasOption("p") ? Integer.parseInt(cmd.getOptionValue("p")) : 7199; String nodehost = cmd.hasOption("h") ? cmd.getOptionValue("h") : "localhost"; System.out.println("Collecting information about the cluster..."); NodeProbe nodeProbe = new NodeProbe(nodehost, port); if (nodeProbe.getTokens().size() != 1) { System.err.println("Cluster is using vnodes and should already be automatically balanced!"); System.exit(1);//from www . j av a 2 s . c om } boolean hasData = false; if (!dryrun) { Map<String, String> loadMap = nodeProbe.getLoadMap(); for (String s : loadMap.values()) { if (s.contains("KB")) continue; if (s.contains("MB") || s.contains("GB") || s.contains("TB")) { hasData = true; continue; } throw new RuntimeException("Unknown suffix in load map; don't dare to continue"); } } String partitioner = nodeProbe.getPartitioner(); BigInteger minToken, maxToken; if (partitioner.equals(RandomPartitioner.class.getName())) { minToken = RandomPartitioner.ZERO; maxToken = RandomPartitioner.MAXIMUM; } else if (partitioner.equals(Murmur3Partitioner.class.getName())) { minToken = BigInteger.valueOf(Murmur3Partitioner.MINIMUM.token); maxToken = BigInteger.valueOf(Murmur3Partitioner.MAXIMUM); } else { throw new RuntimeException("Unsupported partitioner: " + partitioner); } // Get current mapping of all live nodes List<String> liveNodes = nodeProbe.getLiveNodes(); Map<String, BigInteger> hostTokenMap = new HashMap<String, BigInteger>(); Map<String, String> hostDcMap = new HashMap<String, String>(); for (String host : liveNodes) { String dc = nodeProbe.getEndpointSnitchInfoProxy().getDatacenter(host); String decoratedHost = host; if (!noresolve) { // Prefix host with canonical host name. // This makes things prettier and also causes tokens to be assigned in logical order. decoratedHost = InetAddress.getByName(host).getCanonicalHostName() + "/" + host; } else { decoratedHost = "/" + host; } hostDcMap.put(decoratedHost, dc); List<String> tokens = nodeProbe.getTokens(host); if (tokens.size() > 1) { throw new RuntimeException("vnodes not supported"); } if (tokens.size() == 0) { throw new RuntimeException("No token for " + host + "; aborting"); } hostTokenMap.put(decoratedHost, new BigInteger(tokens.get(0))); } Balancer balancer = new Balancer(hostTokenMap, hostDcMap, minToken, maxToken); Map<String, BigInteger> newMap = balancer.balance(); List<Operation> operations = new ArrayList<Operation>(); boolean movesNeeded = false; for (Map.Entry<String, BigInteger> entry : hostTokenMap.entrySet()) { String host = entry.getKey(); BigInteger oldToken = entry.getValue(); BigInteger newToken = newMap.get(host); if (!oldToken.equals(newToken)) { movesNeeded = true; } operations.add(new Operation(host, hostDcMap.get(host), oldToken, newToken)); } if (movesNeeded && hasData && !dryrun && !force) { dryrun = true; System.out.println( "The cluster is unbalanced but has data, so no operations will actually be carried out. Use --force if you want the cluster to balance anyway."); } Collections.sort(operations); boolean unbalanced = false, moved = false; for (Operation op : operations) { if (op.oldToken.equals(op.newToken)) { System.out.println(op.host + ": Stays on token " + op.oldToken); } else { System.out.println(op.host + ": Moving from token " + op.oldToken + " to token " + op.newToken); if (!dryrun) { String ip = op.host.substring(op.host.lastIndexOf("/") + 1); NodeProbe np = new NodeProbe(ip, 7199); np.move(op.newToken.toString()); moved = true; } else { unbalanced = true; } } } if (!unbalanced && moved) { System.out.println("The cluster is now balanced!"); } }
From source file:com.spotify.cassandra.opstools.TruncateHints.java
License:Apache License
public static void main(String[] args) throws IOException { if (args.length < 1) { System.out.println(String.format("Usage: %s [ALL | host [host ...]]", TruncateHints.class.getName())); System.exit(1);//from w ww. j av a2s . c o m } NodeProbe nodeProbe = new NodeProbe(InetAddress.getLocalHost().getCanonicalHostName(), 7199); for (String arg : args) { if (arg.equals("ALL")) { nodeProbe.truncateHints(); } else { nodeProbe.truncateHints(arg); } } System.out.println("Hints truncated!"); }
From source file:edu.tsinghua.software.cassandra.tools.ClusterConnection.java
License:Apache License
public void connect() throws IOException, InterruptedException, TTransportException { if (!connected) { // Updating the transport to Framed one as it has been depreciated with Cassandra 0.7.0 transport = new TFramedTransport(new TSocket(host, thriftPort)); protocol = new TBinaryProtocol(transport); client = new Client(protocol); setProbe(new NodeProbe(host, jmxPort)); transport.open();// ww w . j a va 2 s . co m connected = true; } }
From source file:edu.tsinghua.software.cassandra.tools.ClusterManager.java
License:Apache License
/** * Class Constructor/* w w w . j a v a 2 s . c o m*/ * @param probe * @throws InterruptedException * @throws IOException * @throws TTransportException * */ public ClusterManager(ClusterConnection clusterConnection, String host, int jmxPort) throws TTransportException, IOException, InterruptedException { if (!clusterConnection.isConnected()) { clusterConnection.connect(); } this.client = clusterConnection.getClient(); this.probe = new NodeProbe(host, jmxPort); }
From source file:Tools.ClusterConnection.java
License:Apache License
public void connect() throws IOException, InterruptedException, TTransportException { if (!connected) { // Updating the transport to Framed one as it has been depreciated with Cassandra 0.7.0 transport = new TFramedTransport(new TSocket(host, thriftPort)); protocol = new TBinaryProtocol(transport); client = new Client(protocol); setProbe(new NodeProbe(host, jmxPort)); transport.open();/*w w w . j a v a 2 s . co m*/ connected = true; } }
From source file:Tools.ClusterManager.java
License:Apache License
public ClusterManager(ClusterConnection clusterConnection, String host, int jmxPort) throws TTransportException, IOException, InterruptedException { if (!clusterConnection.isConnected()) { clusterConnection.connect();//from w w w . ja v a 2 s .c o m } this.client = clusterConnection.getClient(); this.probe = new NodeProbe(host, jmxPort); }