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;
}
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;
}
Aggregations