Search in sources :

Example 16 with IInstanceConfig

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);
}
Also used : InstanceConfig(org.apache.cassandra.distributed.impl.InstanceConfig) IInstanceConfig(org.apache.cassandra.distributed.api.IInstanceConfig)

Example 17 with IInstanceConfig

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);
}
Also used : IInstanceConfig(org.apache.cassandra.distributed.api.IInstanceConfig)

Example 18 with IInstanceConfig

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");
}
Also used : IInvokableInstance(org.apache.cassandra.distributed.api.IInvokableInstance) IInstanceConfig(org.apache.cassandra.distributed.api.IInstanceConfig)

Aggregations

IInstanceConfig (org.apache.cassandra.distributed.api.IInstanceConfig)18 Cluster (org.apache.cassandra.distributed.Cluster)8 TokenSupplier (org.apache.cassandra.distributed.api.TokenSupplier)7 NetworkTopology (org.apache.cassandra.distributed.shared.NetworkTopology)7 Test (org.junit.Test)7 GOSSIP (org.apache.cassandra.distributed.api.Feature.GOSSIP)6 NETWORK (org.apache.cassandra.distributed.api.Feature.NETWORK)6 IInvokableInstance (org.apache.cassandra.distributed.api.IInvokableInstance)6 Map (java.util.Map)5 File (org.apache.cassandra.io.util.File)4 Assert (org.junit.Assert)4 InetAddress (java.net.InetAddress)3 InetSocketAddress (java.net.InetSocketAddress)3 UUID (java.util.UUID)3 GossipHelper.bootstrap (org.apache.cassandra.distributed.action.GossipHelper.bootstrap)3 GossipHelper.statusToBootstrap (org.apache.cassandra.distributed.action.GossipHelper.statusToBootstrap)3 GossipHelper.withProperty (org.apache.cassandra.distributed.action.GossipHelper.withProperty)3 ConsistencyLevel (org.apache.cassandra.distributed.api.ConsistencyLevel)3 TestBaseImpl (org.apache.cassandra.distributed.test.TestBaseImpl)3 Arrays.asList (java.util.Arrays.asList)2