Search in sources :

Example 1 with BootstrapDiscoveryConfig

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;
}
Also used : AtomixConfig(io.atomix.core.AtomixConfig) Address(io.atomix.utils.net.Address) MulticastDiscoveryConfig(io.atomix.cluster.discovery.MulticastDiscoveryConfig) BootstrapDiscoveryConfig(io.atomix.cluster.discovery.BootstrapDiscoveryConfig) File(java.io.File) NodeConfig(io.atomix.cluster.NodeConfig)

Aggregations

NodeConfig (io.atomix.cluster.NodeConfig)1 BootstrapDiscoveryConfig (io.atomix.cluster.discovery.BootstrapDiscoveryConfig)1 MulticastDiscoveryConfig (io.atomix.cluster.discovery.MulticastDiscoveryConfig)1 AtomixConfig (io.atomix.core.AtomixConfig)1 Address (io.atomix.utils.net.Address)1 File (java.io.File)1