use of org.apache.helix.manager.zk.ZkClient in project helix by apache.
the class Consumer method main.
public static void main(String[] args) throws Exception {
if (args.length < 3) {
System.err.println("USAGE: java Consumer zookeeperAddress (e.g. localhost:2181) consumerId (0-2), rabbitmqServer (e.g. localhost)");
System.exit(1);
}
final String zkAddr = args[0];
final String clusterName = SetupConsumerCluster.DEFAULT_CLUSTER_NAME;
final String consumerId = args[1];
final String mqServer = args[2];
ZkClient zkclient = null;
try {
// add node to cluster if not already added
zkclient = new ZkClient(zkAddr, ZkClient.DEFAULT_SESSION_TIMEOUT, ZkClient.DEFAULT_CONNECTION_TIMEOUT, new ZNRecordSerializer());
ZKHelixAdmin admin = new ZKHelixAdmin(zkclient);
List<String> nodes = admin.getInstancesInCluster(clusterName);
if (!nodes.contains("consumer_" + consumerId)) {
InstanceConfig config = new InstanceConfig("consumer_" + consumerId);
config.setHostName("localhost");
config.setInstanceEnabled(true);
admin.addInstance(clusterName, config);
}
// start consumer
final Consumer consumer = new Consumer(zkAddr, clusterName, "consumer_" + consumerId, mqServer);
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
System.out.println("Shutting down consumer_" + consumerId);
consumer.disconnect();
}
});
consumer.connect();
} finally {
if (zkclient != null) {
zkclient.close();
}
}
}
use of org.apache.helix.manager.zk.ZkClient in project helix by apache.
the class SetupConsumerCluster method main.
public static void main(String[] args) {
if (args.length < 1) {
System.err.println("USAGE: java SetupConsumerCluster zookeeperAddress (e.g. localhost:2181)");
System.exit(1);
}
final String zkAddr = args[0];
final String clusterName = DEFAULT_CLUSTER_NAME;
ZkClient zkclient = null;
try {
zkclient = new ZkClient(zkAddr, ZkClient.DEFAULT_SESSION_TIMEOUT, ZkClient.DEFAULT_CONNECTION_TIMEOUT, new ZNRecordSerializer());
ZKHelixAdmin admin = new ZKHelixAdmin(zkclient);
// add cluster
admin.addCluster(clusterName, true);
// add state model definition
admin.addStateModelDef(clusterName, DEFAULT_STATE_MODEL, new StateModelDefinition(StateModelConfigGenerator.generateConfigForOnlineOffline()));
// add resource "topic" which has 6 partitions
String resourceName = DEFAULT_RESOURCE_NAME;
admin.addResource(clusterName, resourceName, DEFAULT_PARTITION_NUMBER, DEFAULT_STATE_MODEL, RebalanceMode.FULL_AUTO.toString());
admin.rebalance(clusterName, resourceName, 1);
} finally {
if (zkclient != null) {
zkclient.close();
}
}
}
use of org.apache.helix.manager.zk.ZkClient in project helix by apache.
the class FileStore method main.
public static void main(String[] args) throws Exception {
if (args.length < 2) {
System.err.println("USAGE: java FileStore zookeeperAddress(e.g. localhost:2181) serverId(host_port)");
System.exit(1);
}
final String zkAddr = args[0];
final String clusterName = SetupCluster.DEFAULT_CLUSTER_NAME;
final String serverId = args[1];
ZkClient zkclient = null;
try {
// start consumer
final FileStore store = new FileStore(zkAddr, clusterName, serverId);
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
System.out.println("Shutting down server:" + serverId);
store.disconnect();
}
});
store.connect();
} finally {
if (zkclient != null) {
zkclient.close();
}
}
}
use of org.apache.helix.manager.zk.ZkClient in project helix by apache.
the class ZkChildResource method delete.
@Override
public Representation delete() {
String zkPath = getZKPath();
try {
ZkClient zkClient = (ZkClient) getContext().getAttributes().get(RestAdminApplication.ZKCLIENT);
List<String> childNames = zkClient.getChildren(zkPath);
if (childNames != null) {
for (String childName : childNames) {
String childPath = zkPath.equals("/") ? "/" + childName : zkPath + "/" + childName;
zkClient.deleteRecursively(childPath);
}
}
getResponse().setStatus(Status.SUCCESS_OK);
} catch (Exception e) {
getResponse().setEntity(ClusterRepresentationUtil.getErrorAsJsonStringFromException(e), MediaType.APPLICATION_JSON);
getResponse().setStatus(Status.SUCCESS_OK);
LOG.error("Error in delete zkChild: " + zkPath, e);
}
return null;
}
use of org.apache.helix.manager.zk.ZkClient in project helix by apache.
the class ZkChildResource method get.
@Override
public Representation get() {
StringRepresentation presentation = null;
String zkPath = getZKPath();
try {
ZkClient zkClient = (ZkClient) getContext().getAttributes().get(RestAdminApplication.ZKCLIENT);
ZNRecord result = readZkChild(zkPath, zkClient);
presentation = new StringRepresentation(ClusterRepresentationUtil.ZNRecordToJson(result), MediaType.APPLICATION_JSON);
} catch (Exception e) {
String error = ClusterRepresentationUtil.getErrorAsJsonStringFromException(e);
presentation = new StringRepresentation(error, MediaType.APPLICATION_JSON);
LOG.error("Error in read zkPath: " + zkPath, e);
}
return presentation;
}
Aggregations