Search in sources :

Example 11 with NotificationFeedException

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

the class NotificationFeedHttpHandler method createFeed.

@PUT
@Path("/feeds/categories/{feed-category}/names/{feed-name}")
@AuditPolicy(AuditDetail.REQUEST_BODY)
public void createFeed(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId, @PathParam("feed-category") String category, @PathParam("feed-name") String name) {
    try {
        NotificationFeedInfo feedInfo;
        try {
            Map<String, String> body = parseBody(request, MAP_TYPE);
            String description = body == null ? null : body.get("description");
            feedInfo = new NotificationFeedInfo(namespaceId, category, name, description);
        } catch (IllegalArgumentException e) {
            responder.sendString(HttpResponseStatus.BAD_REQUEST, String.format("Could not create Notification Feed. %s", e.getMessage()));
            return;
        }
        if (feedManager.createFeed(feedInfo)) {
            responder.sendString(HttpResponseStatus.OK, "Notification Feed created successfully");
        } else {
            LOG.trace("Notification Feed already exists.");
            responder.sendString(HttpResponseStatus.OK, "Notification Feed already exists.");
        }
    } catch (NotificationFeedException e) {
        LOG.error("Could not create notification feed.", e);
        responder.sendString(HttpResponseStatus.INTERNAL_SERVER_ERROR, e.getMessage());
    } catch (JsonSyntaxException e) {
        responder.sendString(HttpResponseStatus.BAD_REQUEST, "Invalid json object provided in request body.");
    } catch (IOException e) {
        LOG.error("Failed to read Notification feed request body.", e);
        responder.sendString(HttpResponseStatus.INTERNAL_SERVER_ERROR, e.getMessage());
    } catch (Throwable t) {
        LOG.debug("Error in creating notification feed.", t);
        responder.sendString(HttpResponseStatus.INTERNAL_SERVER_ERROR, t.getMessage());
    }
}
Also used : NotificationFeedException(co.cask.cdap.notifications.feeds.NotificationFeedException) JsonSyntaxException(com.google.gson.JsonSyntaxException) NotificationFeedInfo(co.cask.cdap.proto.notification.NotificationFeedInfo) IOException(java.io.IOException) Path(javax.ws.rs.Path) AuditPolicy(co.cask.cdap.common.security.AuditPolicy) PUT(javax.ws.rs.PUT)

Example 12 with NotificationFeedException

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

the class NotificationFeedHttpHandler method listFeeds.

@GET
@Path("/feeds")
public void listFeeds(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId) {
    try {
        List<NotificationFeedInfo> feeds = feedManager.listFeeds(new NamespaceId(namespaceId));
        responder.sendJson(HttpResponseStatus.OK, feeds);
    } 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 listing notification feeds.", t);
        responder.sendString(HttpResponseStatus.INTERNAL_SERVER_ERROR, t.getMessage());
    }
}
Also used : NotificationFeedException(co.cask.cdap.notifications.feeds.NotificationFeedException) NotificationFeedInfo(co.cask.cdap.proto.notification.NotificationFeedInfo) NamespaceId(co.cask.cdap.proto.id.NamespaceId) 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