use of org.apache.cassandra.distributed.api.IInstanceConfig in project cassandra by apache.
the class ClusterUtils method addInstance.
/**
* Create a new instance and add it to the cluster, without starting it.
*
* @param cluster to add to
* @param dc the instance should be in
* @param rack the instance should be in
* @param fn function to add to the config before starting
* @param <I> instance type
* @return the instance added
*/
public static <I extends IInstance> I addInstance(AbstractCluster<I> cluster, String dc, String rack, Consumer<IInstanceConfig> fn) {
Objects.requireNonNull(dc, "dc");
Objects.requireNonNull(rack, "rack");
InstanceConfig config = cluster.newInstanceConfig();
// TODO adding new instances should be cleaner, currently requires you create the cluster with all
// instances known about (at least to NetworkTopology and TokenStategy)
// this is very hidden, so should be more explicit
config.networkTopology().put(config.broadcastAddress(), NetworkTopology.dcAndRack(dc, rack));
fn.accept(config);
return cluster.bootstrap(config);
}
use of org.apache.cassandra.distributed.api.IInstanceConfig in project cassandra by apache.
the class ClusterUtils method getTokens.
/**
* Get the tokens assigned to the instance via config. This method does not work if the instance has learned
* or generated its tokens.
*
* @param instance to get tokens from
* @return non-empty list of tokens
*/
public static List<String> getTokens(IInstance instance) {
IInstanceConfig conf = instance.config();
int numTokens = conf.getInt("num_tokens");
Assert.assertEquals("Only single token is supported", 1, numTokens);
String token = conf.getString("initial_token");
Assert.assertNotNull("initial_token was not found", token);
return Arrays.asList(token);
}
use of org.apache.cassandra.distributed.api.IInstanceConfig in project cassandra by apache.
the class BootstrapBinaryDisabledTest method bootstrap.
private static void bootstrap(Cluster cluster, Map<String, Object> config, boolean isWriteSurvey) throws TimeoutException {
IInstanceConfig nodeConfig = cluster.newInstanceConfig();
nodeConfig.set("auto_bootstrap", true);
config.forEach(nodeConfig::set);
// TODO can we make this more isolated?
System.setProperty("cassandra.ring_delay_ms", "5000");
if (isWriteSurvey)
System.setProperty("cassandra.write_survey", "true");
RewriteEnabled.enable();
cluster.bootstrap(nodeConfig).startup();
IInvokableInstance node = cluster.get(cluster.size());
assertLogHas(node, "Some data streaming failed");
assertLogHas(node, isWriteSurvey ? "Not starting client transports in write_survey mode as it's bootstrapping or auth is enabled" : "Node is not yet bootstrapped completely");
node.nodetoolResult("join").asserts().failure().errorContains("Cannot join the ring until bootstrap completes");
RewriteEnabled.disable();
node.nodetoolResult("bootstrap", "resume").asserts().success();
if (isWriteSurvey)
assertLogHas(node, "Not starting client transports in write_survey mode as it's bootstrapping or auth is enabled");
if (isWriteSurvey) {
node.nodetoolResult("join").asserts().success();
assertLogHas(node, "Leaving write survey mode and joining ring at operator request");
}
node.logs().watchFor("Starting listening for CQL clients");
assertBootstrapState(node, "COMPLETED");
}
Aggregations