2015-01-18 00:46:28 +00:00
|
|
|
package com.github.lookout.verspaetung.zk
|
|
|
|
|
2015-01-18 18:25:04 +00:00
|
|
|
import groovy.transform.TypeChecked
|
2015-01-19 21:08:01 +00:00
|
|
|
import groovy.transform.InheritConstructors
|
2015-01-18 00:46:28 +00:00
|
|
|
import org.apache.curator.framework.recipes.cache.ChildData
|
|
|
|
|
|
|
|
/**
|
|
|
|
* StandardTreeWatcher processes Zookeeper paths for standard high-level Kafka
|
|
|
|
* consumers
|
|
|
|
*/
|
2015-01-18 18:25:04 +00:00
|
|
|
@TypeChecked
|
2015-01-19 21:08:01 +00:00
|
|
|
@InheritConstructors
|
2015-01-28 10:01:53 +00:00
|
|
|
class StandardTreeWatcher extends AbstractConsumerTreeWatcher {
|
2015-01-28 09:44:53 +00:00
|
|
|
private static final String ZK_PATH = '/consumers'
|
|
|
|
|
2015-09-01 22:50:31 +00:00
|
|
|
String zookeeperPath() {
|
|
|
|
return ZK_PATH
|
|
|
|
}
|
2015-01-18 00:46:28 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Extract the necessary information from a standard (i.e. high-level Kafka
|
|
|
|
* consumer) tree of offsets
|
|
|
|
*/
|
2015-09-01 22:50:31 +00:00
|
|
|
@SuppressWarnings(['LineLength'])
|
2015-01-18 00:46:28 +00:00
|
|
|
ConsumerOffset processChildData(ChildData data) {
|
|
|
|
/*
|
|
|
|
ChildData{path='/consumers/offtopic-spock-test/offsets/topic/7', stat=8595174473,8595174478,1416808804928,1416808805262,1,0,0,0,1,0,8595174473, data=[48]}
|
|
|
|
*/
|
|
|
|
ConsumerOffset offset = new ConsumerOffset()
|
|
|
|
|
2015-01-18 18:25:04 +00:00
|
|
|
List<String> pathParts = data.path.split(/\//) as List<String>
|
2015-01-18 00:46:28 +00:00
|
|
|
|
2015-01-18 18:25:04 +00:00
|
|
|
if (pathParts.size() != 6) {
|
2015-01-18 00:46:28 +00:00
|
|
|
return null
|
|
|
|
}
|
|
|
|
|
|
|
|
offset.groupName = pathParts[2]
|
|
|
|
offset.topic = pathParts[4]
|
2015-01-26 12:06:27 +00:00
|
|
|
|
|
|
|
try {
|
|
|
|
offset.partition = new Integer(pathParts[5])
|
|
|
|
offset.offset = new Integer(new String(data.data))
|
|
|
|
}
|
|
|
|
catch (NumberFormatException ex) {
|
|
|
|
logger.error("Failed to parse an Integer: ${data}")
|
2015-09-01 22:50:31 +00:00
|
|
|
offset = null
|
2015-01-26 12:06:27 +00:00
|
|
|
}
|
2015-01-18 00:46:28 +00:00
|
|
|
|
|
|
|
return offset
|
|
|
|
}
|
2015-01-26 12:06:27 +00:00
|
|
|
|
|
|
|
Boolean isOffsetSubtree(String path) {
|
|
|
|
return (path =~ /\/consumers\/(.*)\/offsets\/(.*)/)
|
|
|
|
}
|
2015-01-18 00:46:28 +00:00
|
|
|
}
|