use of io.pravega.controller.eventProcessor.EventProcessorGroup in project pravega by pravega.
the class ControllerEventProcessors method handleOrphanedReaders.
private CompletableFuture<Void> handleOrphanedReaders(final EventProcessorGroup<? extends ControllerEvent> group, final Supplier<Set<String>> processes) {
return withRetriesAsync(() -> CompletableFuture.supplyAsync(() -> {
try {
return group.getProcesses();
} catch (CheckpointStoreException e) {
if (e.getType().equals(CheckpointStoreException.Type.NoNode)) {
return Collections.<String>emptySet();
}
throw new CompletionException(e);
}
}, executor), RETRYABLE_PREDICATE, Integer.MAX_VALUE, executor).thenComposeAsync(groupProcesses -> withRetriesAsync(() -> CompletableFuture.supplyAsync(() -> {
try {
return new ImmutablePair<>(processes.get(), groupProcesses);
} catch (Exception e) {
log.error(String.format("Error fetching current processes%s", group.toString()), e);
throw new CompletionException(e);
}
}, executor), RETRYABLE_PREDICATE, Integer.MAX_VALUE, executor)).thenComposeAsync(pair -> {
Set<String> activeProcesses = pair.getLeft();
Set<String> registeredProcesses = pair.getRight();
if (registeredProcesses == null || registeredProcesses.isEmpty()) {
return CompletableFuture.completedFuture(null);
}
if (activeProcesses != null) {
registeredProcesses.removeAll(activeProcesses);
}
List<CompletableFuture<Void>> futureList = new ArrayList<>();
for (String process : registeredProcesses) {
futureList.add(withRetriesAsync(() -> CompletableFuture.runAsync(() -> {
try {
group.notifyProcessFailure(process);
} catch (CheckpointStoreException e) {
log.error(String.format("Error notifying failure of process=%s in event processor group %s", process, group.toString()), e);
throw new CompletionException(e);
}
}, executor), RETRYABLE_PREDICATE, Integer.MAX_VALUE, executor));
}
return Futures.allOf(futureList);
});
}
use of io.pravega.controller.eventProcessor.EventProcessorGroup in project pravega by pravega.
the class ControllerEventProcessorsTest method testHandleOrphaned.
@Test(timeout = 10000)
public void testHandleOrphaned() {
Controller localController = mock(Controller.class);
CheckpointStore checkpointStore = mock(CheckpointStore.class);
StreamMetadataStore streamStore = mock(StreamMetadataStore.class);
HostControllerStore hostStore = mock(HostControllerStore.class);
ConnectionFactory connectionFactory = mock(ConnectionFactory.class);
StreamMetadataTasks streamMetadataTasks = mock(StreamMetadataTasks.class);
StreamTransactionMetadataTasks streamTransactionMetadataTasks = mock(StreamTransactionMetadataTasks.class);
executor = Executors.newSingleThreadScheduledExecutor();
ControllerEventProcessorConfig config = ControllerEventProcessorConfigImpl.withDefault();
EventProcessorSystem system = mock(EventProcessorSystem.class);
EventProcessorGroup<ControllerEvent> processor = new EventProcessorGroup<ControllerEvent>() {
@Override
public void notifyProcessFailure(String process) throws CheckpointStoreException {
}
@Override
public EventStreamWriter<ControllerEvent> getWriter() {
return null;
}
@Override
public Set<String> getProcesses() throws CheckpointStoreException {
return Sets.newHashSet("host1", "host2");
}
@Override
public Service startAsync() {
return null;
}
@Override
public boolean isRunning() {
return false;
}
@Override
public State state() {
return null;
}
@Override
public Service stopAsync() {
return null;
}
@Override
public void awaitRunning() {
}
@Override
public void awaitRunning(long timeout, TimeUnit unit) throws TimeoutException {
}
@Override
public void awaitTerminated() {
}
@Override
public void awaitTerminated(long timeout, TimeUnit unit) throws TimeoutException {
}
@Override
public Throwable failureCause() {
return null;
}
@Override
public void addListener(Listener listener, Executor executor) {
}
@Override
public void close() throws Exception {
}
};
try {
when(system.createEventProcessorGroup(any(), any())).thenReturn(processor);
} catch (CheckpointStoreException e) {
e.printStackTrace();
}
ControllerEventProcessors processors = new ControllerEventProcessors("host1", config, localController, checkpointStore, streamStore, hostStore, SegmentHelperMock.getSegmentHelperMock(), connectionFactory, streamMetadataTasks, system, executor);
processors.startAsync();
processors.awaitRunning();
assertTrue(Futures.await(processors.sweepFailedProcesses(() -> Sets.newHashSet("host1"))));
assertTrue(Futures.await(processors.handleFailedProcess("host1")));
processors.shutDown();
}
Aggregations