Search in sources :

Example 6 with CommandNotification

use of org.apache.rya.periodic.notification.notification.CommandNotification in project incubator-rya by apache.

the class CreateDeletePeriodicPCJ method makeNotificationConsumer.

private KafkaConsumer<String, CommandNotification> makeNotificationConsumer(final String topic) {
    // setup consumer
    final Properties consumerProps = new Properties();
    consumerProps.setProperty(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, "localhost:9092");
    consumerProps.setProperty(ConsumerConfig.GROUP_ID_CONFIG, "group0");
    consumerProps.setProperty(ConsumerConfig.CLIENT_ID_CONFIG, "consumer0");
    consumerProps.setProperty(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class.getName());
    consumerProps.setProperty(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, CommandNotificationSerializer.class.getName());
    // to make sure the consumer starts from the beginning of the topic
    consumerProps.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest");
    final KafkaConsumer<String, CommandNotification> consumer = new KafkaConsumer<>(consumerProps);
    consumer.subscribe(Arrays.asList(topic));
    return consumer;
}
Also used : StringDeserializer(org.apache.kafka.common.serialization.StringDeserializer) KafkaConsumer(org.apache.kafka.clients.consumer.KafkaConsumer) Properties(java.util.Properties) CommandNotification(org.apache.rya.periodic.notification.notification.CommandNotification) CommandNotificationSerializer(org.apache.rya.periodic.notification.serialization.CommandNotificationSerializer)

Example 7 with CommandNotification

use of org.apache.rya.periodic.notification.notification.CommandNotification in project incubator-rya by apache.

the class PeriodicNotificationProvider method getCommandNotifications.

private Collection<CommandNotification> getCommandNotifications(Snapshot sx, Collection<PeriodicQueryMetadata> metadata) {
    Set<CommandNotification> notifications = new HashSet<>();
    int i = 1;
    for (PeriodicQueryMetadata meta : metadata) {
        // offset initial wait to avoid overloading system
        PeriodicNotification periodic = new PeriodicNotification(getQueryId(meta.getNodeId(), sx), meta.getPeriod(), TimeUnit.MILLISECONDS, i * 5000);
        notifications.add(new CommandNotification(Command.ADD, periodic));
        i++;
    }
    return notifications;
}
Also used : PeriodicQueryMetadata(org.apache.rya.indexing.pcj.fluo.app.query.PeriodicQueryMetadata) PeriodicNotification(org.apache.rya.periodic.notification.notification.PeriodicNotification) CommandNotification(org.apache.rya.periodic.notification.notification.CommandNotification) HashSet(java.util.HashSet)

Example 8 with CommandNotification

use of org.apache.rya.periodic.notification.notification.CommandNotification in project incubator-rya by apache.

the class CommandNotificationTypeAdapter method deserialize.

@Override
public CommandNotification deserialize(JsonElement arg0, Type arg1, JsonDeserializationContext arg2) throws JsonParseException {
    JsonObject json = arg0.getAsJsonObject();
    Command command = Command.valueOf(json.get("command").getAsString());
    String type = json.get("type").getAsString();
    Notification notification = null;
    if (type.equals(PeriodicNotification.class.getSimpleName())) {
        notification = (new PeriodicNotificationTypeAdapter()).deserialize(json.get("notification"), PeriodicNotification.class, arg2);
    } else if (type.equals(BasicNotification.class.getSimpleName())) {
        notification = (new BasicNotificationTypeAdapter()).deserialize(json.get("notification"), BasicNotification.class, arg2);
    } else {
        throw new JsonParseException("Cannot deserialize Json");
    }
    return new CommandNotification(command, notification);
}
Also used : Command(org.apache.rya.periodic.notification.notification.CommandNotification.Command) JsonObject(com.google.gson.JsonObject) PeriodicNotification(org.apache.rya.periodic.notification.notification.PeriodicNotification) JsonParseException(com.google.gson.JsonParseException) CommandNotification(org.apache.rya.periodic.notification.notification.CommandNotification) Notification(org.apache.rya.periodic.notification.api.Notification) PeriodicNotification(org.apache.rya.periodic.notification.notification.PeriodicNotification) CommandNotification(org.apache.rya.periodic.notification.notification.CommandNotification) BasicNotification(org.apache.rya.periodic.notification.notification.BasicNotification)

Example 9 with CommandNotification

use of org.apache.rya.periodic.notification.notification.CommandNotification in project incubator-rya by apache.

the class PeriodicNotificationCoordinatorExecutor method processNotification.

private void processNotification(CommandNotification notification) {
    Command command = notification.getCommand();
    Notification periodic = notification.getNotification();
    switch(command) {
        case ADD:
            addNotification(periodic);
            break;
        case DELETE:
            deleteNotification(periodic);
            break;
    }
}
Also used : Command(org.apache.rya.periodic.notification.notification.CommandNotification.Command) Notification(org.apache.rya.periodic.notification.api.Notification) PeriodicNotification(org.apache.rya.periodic.notification.notification.PeriodicNotification) CommandNotification(org.apache.rya.periodic.notification.notification.CommandNotification) TimestampedNotification(org.apache.rya.periodic.notification.notification.TimestampedNotification)

Example 10 with CommandNotification

use of org.apache.rya.periodic.notification.notification.CommandNotification in project incubator-rya by apache.

the class CommandNotificationSerializerTest method basicSerializationTest.

@Test
public void basicSerializationTest() {
    PeriodicNotification notification = PeriodicNotification.builder().id(UUID.randomUUID().toString()).period(24).timeUnit(TimeUnit.DAYS).initialDelay(1).build();
    CommandNotification command = new CommandNotification(Command.ADD, notification);
    Assert.assertEquals(command, serializer.deserialize(topic, serializer.serialize(topic, command)));
    PeriodicNotification notification1 = PeriodicNotification.builder().id(UUID.randomUUID().toString()).period(32).timeUnit(TimeUnit.SECONDS).initialDelay(15).build();
    CommandNotification command1 = new CommandNotification(Command.ADD, notification1);
    Assert.assertEquals(command1, serializer.deserialize(topic, serializer.serialize(topic, command1)));
    PeriodicNotification notification2 = PeriodicNotification.builder().id(UUID.randomUUID().toString()).period(32).timeUnit(TimeUnit.SECONDS).initialDelay(15).build();
    CommandNotification command2 = new CommandNotification(Command.ADD, notification2);
    Assert.assertEquals(command2, serializer.deserialize(topic, serializer.serialize(topic, command2)));
    BasicNotification notification3 = new BasicNotification(UUID.randomUUID().toString());
    CommandNotification command3 = new CommandNotification(Command.ADD, notification3);
    Assert.assertEquals(command3, serializer.deserialize(topic, serializer.serialize(topic, command3)));
}
Also used : BasicNotification(org.apache.rya.periodic.notification.notification.BasicNotification) PeriodicNotification(org.apache.rya.periodic.notification.notification.PeriodicNotification) CommandNotification(org.apache.rya.periodic.notification.notification.CommandNotification) Test(org.junit.Test)

Aggregations

CommandNotification (org.apache.rya.periodic.notification.notification.CommandNotification)12 PeriodicNotification (org.apache.rya.periodic.notification.notification.PeriodicNotification)6 Notification (org.apache.rya.periodic.notification.api.Notification)4 BasicNotification (org.apache.rya.periodic.notification.notification.BasicNotification)4 Properties (java.util.Properties)3 StringDeserializer (org.apache.kafka.common.serialization.StringDeserializer)3 TimestampedNotification (org.apache.rya.periodic.notification.notification.TimestampedNotification)3 KafkaNotificationRegistrationClient (org.apache.rya.periodic.notification.registration.KafkaNotificationRegistrationClient)3 CommandNotificationSerializer (org.apache.rya.periodic.notification.serialization.CommandNotificationSerializer)3 Test (org.junit.Test)3 JsonObject (com.google.gson.JsonObject)2 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)2 KafkaProducer (org.apache.kafka.clients.producer.KafkaProducer)2 PeriodicNotificationCoordinatorExecutor (org.apache.rya.periodic.notification.coordinator.PeriodicNotificationCoordinatorExecutor)2 Command (org.apache.rya.periodic.notification.notification.CommandNotification.Command)2 JsonParseException (com.google.gson.JsonParseException)1 JsonPrimitive (com.google.gson.JsonPrimitive)1 HashSet (java.util.HashSet)1 FluoClient (org.apache.fluo.api.client.FluoClient)1 Bytes (org.apache.fluo.api.data.Bytes)1