use of org.apache.cassandra.distributed.impl.InstanceConfig in project cassandra by apache.
the class ClusterUtils method updateAddress.
/**
* Changes the instance's address to the new address. This method should only be called while the instance is
* down, else has undefined behavior.
*
* @param conf to update address for
* @param address to set
*/
private static void updateAddress(IInstanceConfig conf, String address) {
InetSocketAddress previous = conf.broadcastAddress();
for (String key : Arrays.asList("broadcast_address", "listen_address", "broadcast_rpc_address", "rpc_address")) conf.set(key, address);
// InstanceConfig caches InetSocketAddress -> InetAddressAndPort
// this causes issues as startup now ignores config, so force reset it to pull from conf.
// TODO remove the need to null out the cache...
((InstanceConfig) conf).unsetBroadcastAddressAndPort();
// are a risk
if (!conf.broadcastAddress().equals(previous)) {
conf.networkTopology().put(conf.broadcastAddress(), NetworkTopology.dcAndRack(conf.localDatacenter(), conf.localRack()));
try {
Field field = NetworkTopology.class.getDeclaredField("map");
field.setAccessible(true);
Map<InetSocketAddress, NetworkTopology.DcAndRack> map = (Map<InetSocketAddress, NetworkTopology.DcAndRack>) field.get(conf.networkTopology());
map.remove(previous);
} catch (NoSuchFieldException | IllegalAccessException e) {
throw new AssertionError(e);
}
}
}
use of org.apache.cassandra.distributed.impl.InstanceConfig 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);
}
Aggregations