use of io.atomix.cluster.discovery.BootstrapDiscoveryConfig in project atomix by atomix.
the class AtomixAgent method createConfig.
/**
* Creates an Atomix configuration from the given namespace.
*
* @param namespace the namespace from which to create the configuration
* @return the Atomix configuration for the given namespace
*/
static AtomixConfig createConfig(Namespace namespace) {
final List<File> configFiles = namespace.getList("config");
final String memberId = namespace.getString("member");
final Address address = namespace.get("address");
final String host = namespace.getString("host");
final String rack = namespace.getString("rack");
final String zone = namespace.getString("zone");
final List<NodeConfig> bootstrap = namespace.getList("bootstrap");
final boolean multicastEnabled = namespace.getBoolean("multicast");
final String multicastGroup = namespace.get("multicast_group");
final Integer multicastPort = namespace.get("multicast_port");
System.setProperty("atomix.data", namespace.getString("data_dir"));
// If a configuration was provided, merge the configuration's member information with the provided command line arguments.
AtomixConfig config;
if (configFiles != null && !configFiles.isEmpty()) {
System.setProperty("atomix.config.resources", "");
config = Atomix.config(configFiles);
} else {
config = Atomix.config();
}
if (memberId != null) {
config.getClusterConfig().getNodeConfig().setId(memberId);
}
if (address != null) {
config.getClusterConfig().getNodeConfig().setAddress(address);
}
if (host != null) {
config.getClusterConfig().getNodeConfig().setHostId(host);
}
if (rack != null) {
config.getClusterConfig().getNodeConfig().setRackId(rack);
}
if (zone != null) {
config.getClusterConfig().getNodeConfig().setZoneId(zone);
}
if (bootstrap != null && !bootstrap.isEmpty()) {
config.getClusterConfig().setDiscoveryConfig(new BootstrapDiscoveryConfig().setNodes(bootstrap));
}
if (multicastEnabled) {
config.getClusterConfig().getMulticastConfig().setEnabled(true);
if (multicastGroup != null) {
config.getClusterConfig().getMulticastConfig().setGroup(multicastGroup);
}
if (multicastPort != null) {
config.getClusterConfig().getMulticastConfig().setPort(multicastPort);
}
if (bootstrap == null || bootstrap.isEmpty()) {
config.getClusterConfig().setDiscoveryConfig(new MulticastDiscoveryConfig());
}
}
return config;
}
Aggregations