use of org.apache.rya.indexing.pcj.fluo.api.DeletePeriodicQuery in project incubator-rya by apache.
the class CreateDeletePeriodicPCJ method runTest.
private void runTest(String query, Collection<Statement> statements, int expectedEntries) throws Exception {
try (FluoClient fluoClient = FluoFactory.newClient(super.getFluoConfiguration())) {
String topic = "notification_topic";
PeriodicQueryResultStorage storage = new AccumuloPeriodicQueryResultStorage(super.getAccumuloConnector(), RYA_INSTANCE_NAME);
PeriodicNotificationClient notificationClient = new KafkaNotificationRegistrationClient(topic, getNotificationProducer("localhost:9092"));
CreatePeriodicQuery periodicPCJ = new CreatePeriodicQuery(fluoClient, storage);
String id = periodicPCJ.createPeriodicQuery(query, notificationClient).getQueryId();
loadData(statements);
// Ensure the data was loaded.
final List<Bytes> rows = getFluoTableEntries(fluoClient);
assertEquals(expectedEntries, rows.size());
DeletePeriodicQuery deletePeriodic = new DeletePeriodicQuery(fluoClient, storage);
deletePeriodic.deletePeriodicQuery(FluoQueryUtils.convertFluoQueryIdToPcjId(id), notificationClient);
getMiniFluo().waitForObservers();
// Ensure all data related to the query has been removed.
final List<Bytes> empty_rows = getFluoTableEntries(fluoClient);
assertEquals(1, empty_rows.size());
// Ensure that Periodic Service notified to add and delete PeriodicNotification
Set<CommandNotification> notifications;
try (KafkaConsumer<String, CommandNotification> consumer = makeNotificationConsumer(topic)) {
notifications = getKafkaNotifications(topic, 7000, consumer);
}
assertEquals(2, notifications.size());
String notificationId = "";
boolean addCalled = false;
boolean deleteCalled = false;
for (CommandNotification notification : notifications) {
if (notificationId.length() == 0) {
notificationId = notification.getId();
} else {
assertEquals(notificationId, notification.getId());
}
if (notification.getCommand() == Command.ADD) {
addCalled = true;
}
if (notification.getCommand() == Command.DELETE) {
deleteCalled = true;
}
}
assertEquals(true, addCalled);
assertEquals(true, deleteCalled);
}
}
use of org.apache.rya.indexing.pcj.fluo.api.DeletePeriodicQuery in project incubator-rya by apache.
the class AccumuloDeletePeriodicPCJ method stopUpdatingPCJ.
private void stopUpdatingPCJ(final String ryaInstance, final String fluoAppName, final String pcjId, final String topic, final String brokers) throws UnsupportedQueryException, MalformedQueryException, QueryDeletionException {
requireNonNull(fluoAppName);
requireNonNull(pcjId);
// Connect to the Fluo application that is updating this instance's PCJs.
final AccumuloConnectionDetails cd = super.getAccumuloConnectionDetails();
try (final FluoClient fluoClient = new FluoClientFactory().connect(cd.getUsername(), new String(cd.getUserPass()), cd.getInstanceName(), cd.getZookeepers(), fluoAppName)) {
// Delete the PCJ from the Fluo App.
PeriodicQueryResultStorage periodic = new AccumuloPeriodicQueryResultStorage(getConnector(), ryaInstance);
DeletePeriodicQuery deletePeriodic = new DeletePeriodicQuery(fluoClient, periodic);
deletePeriodic.deletePeriodicQuery(pcjId, getPeriodicNotificationClient(topic, brokers));
}
}
Aggregations