use of org.apache.flink.shaded.curator5.org.apache.curator.framework.CuratorFramework in project elastic-job by dangdangdotcom.
the class JobNodeStorageTest method assertExecuteInTransactionFailure.
@Test(expected = RuntimeException.class)
public void assertExecuteInTransactionFailure() throws Exception {
CuratorFramework client = mock(CuratorFramework.class);
CuratorTransaction curatorTransaction = mock(CuratorTransaction.class);
TransactionCheckBuilder transactionCheckBuilder = mock(TransactionCheckBuilder.class);
CuratorTransactionBridge curatorTransactionBridge = mock(CuratorTransactionBridge.class);
CuratorTransactionFinal curatorTransactionFinal = mock(CuratorTransactionFinal.class);
when(regCenter.getRawClient()).thenReturn(client);
when(client.inTransaction()).thenReturn(curatorTransaction);
when(curatorTransaction.check()).thenReturn(transactionCheckBuilder);
when(transactionCheckBuilder.forPath("/")).thenReturn(curatorTransactionBridge);
when(curatorTransactionBridge.and()).thenReturn(curatorTransactionFinal);
TransactionCreateBuilder transactionCreateBuilder = mock(TransactionCreateBuilder.class);
when(curatorTransactionFinal.create()).thenReturn(transactionCreateBuilder);
when(transactionCreateBuilder.forPath("/test_transaction")).thenReturn(curatorTransactionBridge);
when(curatorTransactionBridge.and()).thenThrow(new RuntimeException());
jobNodeStorage.executeInTransaction(new TransactionExecutionCallback() {
@Override
public void execute(final CuratorTransactionFinal curatorTransactionFinal) throws Exception {
curatorTransactionFinal.create().forPath("/test_transaction").and();
}
});
verify(regCenter).getRawClient();
verify(client).inTransaction();
verify(curatorTransaction).check();
verify(transactionCheckBuilder).forPath("/");
verify(curatorTransactionBridge, times(2)).and();
verify(curatorTransactionFinal).create();
verify(transactionCreateBuilder).forPath("/test_transaction");
verify(curatorTransactionFinal, times(0)).commit();
}
use of org.apache.flink.shaded.curator5.org.apache.curator.framework.CuratorFramework in project druid by druid-io.
the class RemoteTaskRunner method start.
@Override
@LifecycleStart
public void start() {
try {
if (started) {
return;
}
final MutableInt waitingFor = new MutableInt(1);
final Object waitingForMonitor = new Object();
// Add listener for creation/deletion of workers
workerPathCache.getListenable().addListener(new PathChildrenCacheListener() {
@Override
public void childEvent(CuratorFramework client, final PathChildrenCacheEvent event) throws Exception {
final Worker worker;
switch(event.getType()) {
case CHILD_ADDED:
worker = jsonMapper.readValue(event.getData().getData(), Worker.class);
synchronized (waitingForMonitor) {
waitingFor.increment();
}
Futures.addCallback(addWorker(worker), new FutureCallback<ZkWorker>() {
@Override
public void onSuccess(ZkWorker zkWorker) {
synchronized (waitingForMonitor) {
waitingFor.decrement();
waitingForMonitor.notifyAll();
}
}
@Override
public void onFailure(Throwable throwable) {
synchronized (waitingForMonitor) {
waitingFor.decrement();
waitingForMonitor.notifyAll();
}
}
});
break;
case CHILD_UPDATED:
worker = jsonMapper.readValue(event.getData().getData(), Worker.class);
updateWorker(worker);
break;
case CHILD_REMOVED:
worker = jsonMapper.readValue(event.getData().getData(), Worker.class);
removeWorker(worker);
break;
case INITIALIZED:
// Schedule cleanup for task status of the workers that might have disconnected while overlord was not running
List<String> workers;
try {
workers = cf.getChildren().forPath(indexerZkConfig.getStatusPath());
} catch (KeeperException.NoNodeException e) {
// statusPath doesn't exist yet; can occur if no middleManagers have started.
workers = ImmutableList.of();
}
for (String workerId : workers) {
final String workerAnnouncePath = JOINER.join(indexerZkConfig.getAnnouncementsPath(), workerId);
final String workerStatusPath = JOINER.join(indexerZkConfig.getStatusPath(), workerId);
if (!zkWorkers.containsKey(workerId) && cf.checkExists().forPath(workerAnnouncePath) == null) {
try {
scheduleTasksCleanupForWorker(workerId, cf.getChildren().forPath(workerStatusPath));
} catch (Exception e) {
log.warn(e, "Could not schedule cleanup for worker[%s] during startup (maybe someone removed the status znode[%s]?). Skipping.", workerId, workerStatusPath);
}
}
}
synchronized (waitingForMonitor) {
waitingFor.decrement();
waitingForMonitor.notifyAll();
}
default:
break;
}
}
});
workerPathCache.start(PathChildrenCache.StartMode.POST_INITIALIZED_EVENT);
synchronized (waitingForMonitor) {
while (waitingFor.intValue() > 0) {
waitingForMonitor.wait();
}
}
scheduleBlackListedNodesCleanUp();
resourceManagement.startManagement(this);
started = true;
} catch (Exception e) {
throw Throwables.propagate(e);
}
}
use of org.apache.flink.shaded.curator5.org.apache.curator.framework.CuratorFramework in project elastic-job by dangdangdotcom.
the class ZookeeperRegistryCenterForAuthTest method assertInitWithDigestSuccess.
@Test
public void assertInitWithDigestSuccess() throws Exception {
CuratorFramework client = CuratorFrameworkFactory.builder().connectString(EmbedTestingServer.getConnectionString()).retryPolicy(new RetryOneTime(2000)).authorization("digest", "digest:password".getBytes()).build();
client.start();
client.blockUntilConnected();
assertThat(client.getData().forPath("/" + ZookeeperRegistryCenterForAuthTest.class.getName() + "/test/deep/nested"), is("deepNested".getBytes()));
}
use of org.apache.flink.shaded.curator5.org.apache.curator.framework.CuratorFramework in project elastic-job by dangdangdotcom.
the class ZookeeperRegistryCenterForAuthTest method assertInitWithDigestFailure.
@Test(expected = NoAuthException.class)
public void assertInitWithDigestFailure() throws Exception {
CuratorFramework client = CuratorFrameworkFactory.newClient(EmbedTestingServer.getConnectionString(), new RetryOneTime(2000));
client.start();
client.blockUntilConnected();
client.getData().forPath("/" + ZookeeperRegistryCenterForAuthTest.class.getName() + "/test/deep/nested");
}
use of org.apache.flink.shaded.curator5.org.apache.curator.framework.CuratorFramework in project elastic-job by dangdangdotcom.
the class ZookeeperRegistryCenterModifyTest method assertPersistEphemeral.
@Test
public void assertPersistEphemeral() throws Exception {
zkRegCenter.persist("/persist", "persist_value");
zkRegCenter.persistEphemeral("/ephemeral", "ephemeral_value");
assertThat(zkRegCenter.get("/persist"), is("persist_value"));
assertThat(zkRegCenter.get("/ephemeral"), is("ephemeral_value"));
zkRegCenter.close();
CuratorFramework client = CuratorFrameworkFactory.newClient(EmbedTestingServer.getConnectionString(), new RetryOneTime(2000));
client.start();
client.blockUntilConnected();
assertThat(client.getData().forPath("/" + ZookeeperRegistryCenterModifyTest.class.getName() + "/persist"), is("persist_value".getBytes()));
assertNull(client.checkExists().forPath("/" + ZookeeperRegistryCenterModifyTest.class.getName() + "/ephemeral"));
zkRegCenter.init();
}
Aggregations