Search in sources :

Example 6 with Notification

use of com.hortonworks.streamline.streams.notification.Notification in project streamline by hortonworks.

the class NotificationBolt method process.

@Override
protected void process(Tuple tuple) {
    Notification notification = new StreamlineEventAdapter((StreamlineEvent) tuple.getValueByField(StreamlineEvent.STREAMLINE_EVENT));
    notificationContext.track(notification.getId(), tuple);
    // send to notifier
    notificationService.notify(notificationSink.getNotifierName(), notification);
}
Also used : StreamlineEventAdapter(com.hortonworks.streamline.streams.runtime.notification.StreamlineEventAdapter) Notification(com.hortonworks.streamline.streams.notification.Notification)

Example 7 with Notification

use of com.hortonworks.streamline.streams.notification.Notification in project streamline by hortonworks.

the class NotificationsResource method updateNotificationStatus.

@PUT
@Path("/notifications/{id}/{status}")
@Timed
public Response updateNotificationStatus(@PathParam("id") String notificationId, @PathParam("status") Notification.Status status, @Context SecurityContext securityContext) {
    SecurityUtil.checkRole(authorizer, securityContext, Roles.ROLE_NOTIFICATION_USER);
    Notification updateNotification = notificationService.updateNotificationStatus(notificationId, status);
    return WSUtils.respondEntity(updateNotification, OK);
}
Also used : Notification(com.hortonworks.streamline.streams.notification.Notification) Path(javax.ws.rs.Path) Timed(com.codahale.metrics.annotation.Timed) PUT(javax.ws.rs.PUT)

Example 8 with Notification

use of com.hortonworks.streamline.streams.notification.Notification in project streamline by hortonworks.

the class NotificationsResource method getNotificationById.

@GET
@Path("/notifications/{id}")
@Timed
public Response getNotificationById(@PathParam("id") String id, @Context SecurityContext securityContext) {
    // We do a role based authorization since the notifications does not have object permissions right now.
    // It can be enhanced later if required.
    SecurityUtil.checkRole(authorizer, securityContext, Roles.ROLE_NOTIFICATION_USER);
    Notification result = notificationService.getNotification(id);
    if (result != null) {
        return WSUtils.respondEntity(result, OK);
    }
    throw EntityNotFoundException.byId(id);
}
Also used : Notification(com.hortonworks.streamline.streams.notification.Notification) Path(javax.ws.rs.Path) Timed(com.codahale.metrics.annotation.Timed) GET(javax.ws.rs.GET)

Example 9 with Notification

use of com.hortonworks.streamline.streams.notification.Notification in project streamline by hortonworks.

the class NotificationStatusIndexMapper method status.

@Override
public List<TableMutation> status(Notification notification, Notification.Status status) {
    // insert a new row
    Notification updated = new NotificationImpl.Builder(notification).status(status).build();
    List<TableMutation> tableMutations = tableMutations(updated);
    // delete existing
    for (byte[] rowKey : getRowKeys(notification)) {
        Delete delete = new Delete(rowKey);
        tableMutations.add(new TableMutationImpl(getTableName(), delete));
    }
    LOG.trace("TableMutations for status update {}", tableMutations);
    return tableMutations;
}
Also used : Delete(org.apache.hadoop.hbase.client.Delete) Notification(com.hortonworks.streamline.streams.notification.Notification)

Example 10 with Notification

use of com.hortonworks.streamline.streams.notification.Notification in project streamline by hortonworks.

the class AbstractNotificationMapper method entity.

@Override
public Notification entity(Result result) {
    String id = getNotificationId(result);
    Map<String, Object> fieldsAndValues = new HashMap<>();
    for (Map.Entry<byte[], byte[]> entry : result.getFamilyMap(CF_FIELDS).entrySet()) {
        fieldsAndValues.put(Bytes.toString(entry.getKey()), serializer.deserialize(entry.getValue()));
    }
    List<String> eventIds = new ArrayList<>();
    for (Map.Entry<byte[], byte[]> entry : result.getFamilyMap(CF_EVENTIDS).entrySet()) {
        eventIds.add(Bytes.toString(entry.getKey()));
    }
    List<String> dataSourceIds = new ArrayList<>();
    for (Map.Entry<byte[], byte[]> entry : result.getFamilyMap(CF_DATASOURCE_IDS).entrySet()) {
        dataSourceIds.add(Bytes.toString(entry.getKey()));
    }
    String ruleId = Bytes.toString(result.getFamilyMap(CF_RULEID).firstEntry().getKey());
    Notification.Status status = Notification.Status.valueOf(Bytes.toString(result.getValue(CF_STATUS, CQ_STATUS)));
    String notifierName = Bytes.toString(result.getFamilyMap(CF_NOTIFIER_NAME).firstEntry().getKey());
    long ts = Long.parseLong(Bytes.toString(result.getFamilyMap(CF_TIMESTAMP).firstEntry().getKey()));
    Notification notification = new NotificationImpl.Builder(fieldsAndValues).id(id).eventIds(eventIds).dataSourceIds(dataSourceIds).ruleId(ruleId).notifierName(notifierName).timestamp(ts).status(status).build();
    LOG.trace("Created Notification {} from Result {}", notification, result);
    return notification;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) HashMap(java.util.HashMap) Map(java.util.Map) Notification(com.hortonworks.streamline.streams.notification.Notification)

Aggregations

Notification (com.hortonworks.streamline.streams.notification.Notification)26 Test (org.junit.Test)18 Expectations (mockit.Expectations)9 HashMap (java.util.HashMap)7 Verifications (mockit.Verifications)6 HBaseIntegrationTest (com.hortonworks.streamline.common.test.HBaseIntegrationTest)5 Notifier (com.hortonworks.streamline.streams.notification.Notifier)5 CriteriaImpl (com.hortonworks.streamline.streams.notification.store.CriteriaImpl)5 ArrayList (java.util.ArrayList)5 StreamlineEvent (com.hortonworks.streamline.streams.StreamlineEvent)4 ConsoleNotifier (com.hortonworks.streamline.streams.notifiers.ConsoleNotifier)4 StreamlineEventAdapter (com.hortonworks.streamline.streams.runtime.notification.StreamlineEventAdapter)4 Map (java.util.Map)3 TreeMap (java.util.TreeMap)3 MockUp (mockit.MockUp)3 Bytes (org.apache.hadoop.hbase.util.Bytes)3 Timed (com.codahale.metrics.annotation.Timed)2 QueryParam (com.hortonworks.registries.common.QueryParam)2 NotificationSink (com.hortonworks.streamline.streams.layout.component.impl.NotificationSink)2 NotificationContext (com.hortonworks.streamline.streams.notification.NotificationContext)2