Search in sources :

Example 6 with NotificationFeedException

use of co.cask.cdap.notifications.feeds.NotificationFeedException in project cdap by caskdata.

the class DistributedStreamService method subscribeToHeartbeatsFeed.

/**
   * Subscribe to the streams heartbeat notification feed. One heartbeat contains data for all existing streams,
   * we filter that to only take into account the streams that this {@link DistributedStreamService} is a leader
   * of.
   *
   * @return a {@link Cancellable} to cancel the subscription
   * @throws NotificationFeedNotFoundException if the heartbeat feed does not exist
   */
private Cancellable subscribeToHeartbeatsFeed() throws NotificationFeedNotFoundException {
    LOG.debug("Subscribing to stream heartbeats notification feed");
    NotificationFeedId heartbeatsFeed = new NotificationFeedId(NamespaceId.SYSTEM.getNamespace(), Constants.Notification.Stream.STREAM_INTERNAL_FEED_CATEGORY, Constants.Notification.Stream.STREAM_HEARTBEAT_FEED_NAME);
    boolean isRetry = false;
    while (true) {
        try {
            return notificationService.subscribe(heartbeatsFeed, new NotificationHandler<StreamWriterHeartbeat>() {

                @Override
                public Type getNotificationType() {
                    return StreamWriterHeartbeat.class;
                }

                @Override
                public void received(StreamWriterHeartbeat heartbeat, NotificationContext notificationContext) {
                    LOG.trace("Received heartbeat {}", heartbeat);
                    for (Map.Entry<StreamId, Long> entry : heartbeat.getStreamsSizes().entrySet()) {
                        StreamSizeAggregator streamSizeAggregator = aggregators.get(entry.getKey());
                        if (streamSizeAggregator == null) {
                            LOG.trace("Aggregator for stream {} is null", entry.getKey());
                            continue;
                        }
                        streamSizeAggregator.bytesReceived(heartbeat.getInstanceId(), entry.getValue());
                    }
                }
            }, heartbeatsSubscriptionExecutor);
        } catch (NotificationFeedException e) {
            if (!isRetry) {
                LOG.warn("Unable to subscribe to HeartbeatsFeed. Will retry until successfully subscribed. " + "Retry failures will be logged at debug level.", e);
            } else {
                LOG.debug("Unable to subscribe to HeartbeatsFeed. Will retry until successfully subscribed. ", e);
            }
            isRetry = true;
            waitBeforeRetryHeartbeatsFeedOperation();
        }
    }
}
Also used : NotificationContext(co.cask.cdap.notifications.service.NotificationContext) NotificationFeedException(co.cask.cdap.notifications.feeds.NotificationFeedException) Type(java.lang.reflect.Type) NotificationFeedId(co.cask.cdap.proto.id.NotificationFeedId) StreamWriterHeartbeat(co.cask.cdap.data.stream.service.heartbeat.StreamWriterHeartbeat)

Example 7 with NotificationFeedException

use of co.cask.cdap.notifications.feeds.NotificationFeedException in project cdap by caskdata.

the class NotificationFeedHttpHandler method deleteFeed.

@DELETE
@Path("/feeds/categories/{feed-category}/names/{feed-name}")
public void deleteFeed(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId, @PathParam("feed-category") String category, @PathParam("feed-name") String name) {
    try {
        NotificationFeedId feed;
        try {
            feed = new NotificationFeedId(namespaceId, category, name);
        } catch (IllegalArgumentException e) {
            responder.sendString(HttpResponseStatus.BAD_REQUEST, e.getMessage());
            return;
        }
        feedManager.deleteFeed(feed);
        responder.sendStatus(HttpResponseStatus.OK);
    } catch (NotificationFeedNotFoundException e) {
        responder.sendStatus(HttpResponseStatus.NOT_FOUND);
    } catch (NotificationFeedException e) {
        responder.sendString(HttpResponseStatus.INTERNAL_SERVER_ERROR, String.format("Could not delete Notification Feed. %s", e.getMessage()));
    } catch (Throwable t) {
        LOG.debug("Error in deleting notification feed.", t);
        responder.sendString(HttpResponseStatus.INTERNAL_SERVER_ERROR, t.getMessage());
    }
}
Also used : NotificationFeedException(co.cask.cdap.notifications.feeds.NotificationFeedException) NotificationFeedId(co.cask.cdap.proto.id.NotificationFeedId) NotificationFeedNotFoundException(co.cask.cdap.notifications.feeds.NotificationFeedNotFoundException) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE)

Example 8 with NotificationFeedException

use of co.cask.cdap.notifications.feeds.NotificationFeedException in project cdap by caskdata.

the class FileStreamAdmin method createStreamFeeds.

/**
   * Create the public {@link NotificationFeedId}s that concerns the stream with configuration {@code config}.
   *
   * @param config config of the stream to create feeds for
   */
private void createStreamFeeds(StreamConfig config) {
    try {
        NotificationFeedInfo streamFeed = new NotificationFeedInfo(config.getStreamId().getNamespace(), Constants.Notification.Stream.STREAM_FEED_CATEGORY, String.format("%sSize", config.getStreamId().getEntityName()), String.format("Size updates feed for Stream %s every %dMB", config.getStreamId(), config.getNotificationThresholdMB()));
        notificationFeedManager.createFeed(streamFeed);
    } catch (NotificationFeedException e) {
        LOG.error("Cannot create feed for Stream {}", config.getStreamId(), e);
    }
}
Also used : NotificationFeedException(co.cask.cdap.notifications.feeds.NotificationFeedException) NotificationFeedInfo(co.cask.cdap.proto.notification.NotificationFeedInfo)

Example 9 with NotificationFeedException

use of co.cask.cdap.notifications.feeds.NotificationFeedException in project cdap by caskdata.

the class RemoteNotificationFeedManager method getFeed.

@Override
public NotificationFeedInfo getFeed(NotificationFeedId feed) throws NotificationFeedNotFoundException, NotificationFeedException {
    String path = String.format("namespaces/%s/feeds/categories/%s/names/%s", feed.getNamespace(), feed.getCategory(), feed.getFeed());
    HttpResponse response = execute(remoteClient.requestBuilder(HttpMethod.GET, path).build());
    if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) {
        throw new NotificationFeedNotFoundException(feed);
    } else if (response.getResponseCode() != HttpURLConnection.HTTP_OK) {
        throw new NotificationFeedException("Cannot get notification feed. Reason: " + response);
    }
    return ObjectResponse.fromJsonBody(response, NotificationFeedInfo.class).getResponseObject();
}
Also used : NotificationFeedException(co.cask.cdap.notifications.feeds.NotificationFeedException) NotificationFeedNotFoundException(co.cask.cdap.notifications.feeds.NotificationFeedNotFoundException) HttpResponse(co.cask.common.http.HttpResponse) NotificationFeedInfo(co.cask.cdap.proto.notification.NotificationFeedInfo)

Example 10 with NotificationFeedException

use of co.cask.cdap.notifications.feeds.NotificationFeedException in project cdap by caskdata.

the class NotificationFeedHttpHandler method getFeed.

@GET
@Path("/feeds/categories/{feed-category}/names/{feed-name}")
public void getFeed(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId, @PathParam("feed-category") String category, @PathParam("feed-name") String name) {
    try {
        NotificationFeedId feed;
        try {
            feed = new NotificationFeedId(namespaceId, category, name);
        } catch (IllegalArgumentException e) {
            responder.sendString(HttpResponseStatus.BAD_REQUEST, e.getMessage());
            return;
        }
        responder.sendJson(HttpResponseStatus.OK, feedManager.getFeed(feed));
    } catch (NotificationFeedNotFoundException e) {
        responder.sendStatus(HttpResponseStatus.NOT_FOUND);
    } catch (NotificationFeedException e) {
        responder.sendString(HttpResponseStatus.INTERNAL_SERVER_ERROR, String.format("Could not check subscribe permission for Notification Feed. %s", e.getMessage()));
    } catch (Throwable t) {
        LOG.debug("Error in getting notification feed.", t);
        responder.sendString(HttpResponseStatus.INTERNAL_SERVER_ERROR, t.getMessage());
    }
}
Also used : NotificationFeedException(co.cask.cdap.notifications.feeds.NotificationFeedException) NotificationFeedId(co.cask.cdap.proto.id.NotificationFeedId) NotificationFeedNotFoundException(co.cask.cdap.notifications.feeds.NotificationFeedNotFoundException) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Aggregations

NotificationFeedException (co.cask.cdap.notifications.feeds.NotificationFeedException)12 NotificationFeedNotFoundException (co.cask.cdap.notifications.feeds.NotificationFeedNotFoundException)6 NotificationFeedInfo (co.cask.cdap.proto.notification.NotificationFeedInfo)6 HttpResponse (co.cask.common.http.HttpResponse)4 Path (javax.ws.rs.Path)4 NotificationFeedId (co.cask.cdap.proto.id.NotificationFeedId)3 GET (javax.ws.rs.GET)2 CloseableIterator (co.cask.cdap.api.dataset.lib.CloseableIterator)1 RetryableException (co.cask.cdap.api.retry.RetryableException)1 AuditPolicy (co.cask.cdap.common.security.AuditPolicy)1 RetryStrategy (co.cask.cdap.common.service.RetryStrategy)1 StreamWriterHeartbeat (co.cask.cdap.data.stream.service.heartbeat.StreamWriterHeartbeat)1 MessageFetcher (co.cask.cdap.messaging.MessageFetcher)1 RawMessage (co.cask.cdap.messaging.data.RawMessage)1 NotificationContext (co.cask.cdap.notifications.service.NotificationContext)1 NotificationException (co.cask.cdap.notifications.service.NotificationException)1 NamespaceId (co.cask.cdap.proto.id.NamespaceId)1 HttpRequest (co.cask.common.http.HttpRequest)1 TypeToken (com.google.common.reflect.TypeToken)1 JsonSyntaxException (com.google.gson.JsonSyntaxException)1