use of org.apache.curator.framework.recipes.cache.ChildData in project elastic-job by dangdangdotcom.
the class JobOperationListenerManagerTest method assertJobPausedStatusJobListenerWhenIsJobPausedPathAndRemove.
@Test
public void assertJobPausedStatusJobListenerWhenIsJobPausedPathAndRemove() {
JobRegistry.getInstance().addJobScheduleController("test_job", jobScheduleController);
jobOperationListenerManager.new JobPausedStatusJobListener().dataChanged(null, new TreeCacheEvent(TreeCacheEvent.Type.NODE_REMOVED, new ChildData("/test_job/servers/" + ip + "/paused", null, "".getBytes())), "/test_job/servers/" + ip + "/paused");
verify(jobScheduleController, times(0)).pauseJob();
verify(jobScheduleController).resumeJob();
verify(serverService).clearJobPausedStatus();
}
use of org.apache.curator.framework.recipes.cache.ChildData in project elastic-job by dangdangdotcom.
the class JobOperationListenerManagerTest method assertJobPausedStatusJobListenerWhenIsJobPausedPathButJobIsNotExisted.
@Test
public void assertJobPausedStatusJobListenerWhenIsJobPausedPathButJobIsNotExisted() {
jobOperationListenerManager.new JobPausedStatusJobListener().dataChanged(null, new TreeCacheEvent(TreeCacheEvent.Type.NODE_ADDED, new ChildData("/test_job/servers/" + ip + "/paused", null, "".getBytes())), "/test_job/servers/" + ip + "/paused");
verify(jobScheduleController, times(0)).pauseJob();
verify(jobScheduleController, times(0)).resumeJob();
}
use of org.apache.curator.framework.recipes.cache.ChildData in project elastic-job by dangdangdotcom.
the class ZookeeperRegistryCenter method get.
@Override
public String get(final String key) {
TreeCache cache = findTreeCache(key);
if (null == cache) {
return getDirectly(key);
}
ChildData resultInCache = cache.getCurrentData(key);
if (null != resultInCache) {
return null == resultInCache.getData() ? null : new String(resultInCache.getData(), Charsets.UTF_8);
}
return getDirectly(key);
}
use of org.apache.curator.framework.recipes.cache.ChildData in project flink by apache.
the class ZooKeeperLeaderElectionService method nodeChanged.
@Override
public void nodeChanged() throws Exception {
try {
// leaderSessionID is null if the leader contender has not yet confirmed the session ID
if (leaderLatch.hasLeadership()) {
synchronized (lock) {
if (LOG.isDebugEnabled()) {
LOG.debug("Leader node changed while {} is the leader with session ID {}.", leaderContender.getAddress(), confirmedLeaderSessionID);
}
if (confirmedLeaderSessionID != null) {
ChildData childData = cache.getCurrentData();
if (childData == null) {
if (LOG.isDebugEnabled()) {
LOG.debug("Writing leader information into empty node by {}.", leaderContender.getAddress());
}
writeLeaderInformation(confirmedLeaderSessionID);
} else {
byte[] data = childData.getData();
if (data == null || data.length == 0) {
// the data field seems to be empty, rewrite information
if (LOG.isDebugEnabled()) {
LOG.debug("Writing leader information into node with empty data field by {}.", leaderContender.getAddress());
}
writeLeaderInformation(confirmedLeaderSessionID);
} else {
ByteArrayInputStream bais = new ByteArrayInputStream(data);
ObjectInputStream ois = new ObjectInputStream(bais);
String leaderAddress = ois.readUTF();
UUID leaderSessionID = (UUID) ois.readObject();
if (!leaderAddress.equals(this.leaderContender.getAddress()) || (leaderSessionID == null || !leaderSessionID.equals(confirmedLeaderSessionID))) {
// the data field does not correspond to the expected leader information
if (LOG.isDebugEnabled()) {
LOG.debug("Correcting leader information by {}.", leaderContender.getAddress());
}
writeLeaderInformation(confirmedLeaderSessionID);
}
}
}
}
}
}
} catch (Exception e) {
leaderContender.handleError(new Exception("Could not handle node changed event.", e));
throw e;
}
}
use of org.apache.curator.framework.recipes.cache.ChildData in project hadoop by apache.
the class ZKDelegationTokenSecretManager method loadFromZKCache.
/**
* Load the PathChildrenCache into the in-memory map. Possible caches to be
* loaded are keyCache and tokenCache.
*
* @param isTokenCache true if loading tokenCache, false if loading keyCache.
*/
private void loadFromZKCache(final boolean isTokenCache) {
final String cacheName = isTokenCache ? "token" : "key";
LOG.info("Starting to load {} cache.", cacheName);
final List<ChildData> children;
if (isTokenCache) {
children = tokenCache.getCurrentData();
} else {
children = keyCache.getCurrentData();
}
int count = 0;
for (ChildData child : children) {
try {
if (isTokenCache) {
processTokenAddOrUpdate(child);
} else {
processKeyAddOrUpdate(child.getData());
}
} catch (Exception e) {
LOG.info("Ignoring node {} because it failed to load.", child.getPath());
LOG.debug("Failure exception:", e);
++count;
}
}
if (count > 0) {
LOG.warn("Ignored {} nodes while loading {} cache.", count, cacheName);
}
LOG.info("Loaded {} cache.", cacheName);
}
Aggregations