Search in sources :

Example 1 with HelixException

use of org.apache.helix.HelixException in project databus by linkedin.

the class ClusterCheckpointPersistenceProvider method createCluster.

/**
     * Create a cluster if it doesn't exist Note: This method is not thread-safe
     * as HelixAdmin.addCluster appears to fail on concurrent execution within
     * threads
     * 
     * @return true if cluster was created false otherwise
     */
public static boolean createCluster(String zkAddr, String clusterName) {
    boolean created = false;
    ZkClient zkClient = null;
    try {
        zkClient = new ZkClient(zkAddr, ZkClient.DEFAULT_SESSION_TIMEOUT, ZkClient.DEFAULT_CONNECTION_TIMEOUT, new ZNRecordSerializer());
        ZKHelixAdmin admin = new ZKHelixAdmin(zkClient);
        admin.addCluster(clusterName, false);
        created = true;
    } catch (HelixException e) {
        LOG.warn("Warn! Cluster might already exist! " + clusterName);
        created = false;
    } finally {
        // close this connection
        if (zkClient != null) {
            zkClient.close();
        }
    }
    return created;
}
Also used : ZkClient(org.apache.helix.manager.zk.ZkClient) HelixException(org.apache.helix.HelixException) ZKHelixAdmin(org.apache.helix.manager.zk.ZKHelixAdmin) ZNRecordSerializer(org.apache.helix.manager.zk.ZNRecordSerializer)

Example 2 with HelixException

use of org.apache.helix.HelixException in project databus by linkedin.

the class DatabusCluster method addMember.

public DatabusClusterMember addMember(String id, DatabusClusterNotifier notifier) {
    try {
        if (_admin != null) {
            InstanceConfig config = null;
            try {
                config = _admin.getInstanceConfig(_clusterName, id);
            } catch (HelixException e) {
            // the instance doesn't exist , so adding a new config
            }
            if (config != null) {
                LOG.warn("Member id already exists! Overwriting instance for id=" + id);
                _admin.dropInstance(_clusterName, config);
                config = null;
            }
            config = new InstanceConfig(id);
            config.setHostName(InetAddress.getLocalHost().getCanonicalHostName());
            config.setInstanceEnabled(true);
            _admin.addInstance(_clusterName, config);
            return new DatabusClusterMember(id, notifier);
        }
    } catch (Exception e) {
        LOG.error("Error creating databus cluster member " + id + " exception:" + e);
    }
    return null;
}
Also used : HelixException(org.apache.helix.HelixException) InstanceConfig(org.apache.helix.model.InstanceConfig) HelixException(org.apache.helix.HelixException)

Aggregations

HelixException (org.apache.helix.HelixException)2 ZKHelixAdmin (org.apache.helix.manager.zk.ZKHelixAdmin)1 ZNRecordSerializer (org.apache.helix.manager.zk.ZNRecordSerializer)1 ZkClient (org.apache.helix.manager.zk.ZkClient)1 InstanceConfig (org.apache.helix.model.InstanceConfig)1