Search in sources :

Example 6 with NotificationFeedInfo

use of co.cask.cdap.proto.notification.NotificationFeedInfo in project cdap by caskdata.

the class NotificationFeedHttpHandlerTest method testCreateDuplicate.

@Test
public void testCreateDuplicate() throws Exception {
    try {
        // prepare - create feed
        HttpResponse response = createFeed(FEED_VALID);
        assertResponseCode(200, response);
        response = getFeed(NAMESPACE, CATEGORY, NAME);
        NotificationFeedInfo feed = readGetResponse(response);
        Assert.assertEquals(FEED_VALID, feed);
        // create again with the same name
        response = createFeed(FEED_EMPTY_DESCRIPTION);
        assertResponseCode(200, response);
        // check that no updates happened
        response = getFeed(NAMESPACE, CATEGORY, NAME);
        feed = readGetResponse(response);
        Assert.assertEquals(FEED_EMPTY_DESCRIPTION, feed);
    } finally {
        // cleanup
        HttpResponse response = deleteFeed(NAMESPACE, CATEGORY, NAME);
        assertResponseCode(200, response);
    }
}
Also used : HttpResponse(org.apache.http.HttpResponse) NotificationFeedInfo(co.cask.cdap.proto.notification.NotificationFeedInfo) Test(org.junit.Test)

Example 7 with NotificationFeedInfo

use of co.cask.cdap.proto.notification.NotificationFeedInfo in project cdap by caskdata.

the class NotificationFeedHttpHandlerTest method testCreateMissingOrEmptyDescription.

@Test
public void testCreateMissingOrEmptyDescription() throws Exception {
    // create with missing description
    HttpResponse response = createFeed(FEED_MISSING_DESCRIPTION);
    assertResponseCode(200, response);
    try {
        // verify
        response = getFeed(NAMESPACE, CATEGORY, NAME);
        NotificationFeedInfo feed = readGetResponse(response);
        Assert.assertEquals(FEED_MISSING_DESCRIPTION, feed);
        // cleanup
        response = deleteFeed(NAMESPACE, CATEGORY, NAME);
        assertResponseCode(200, response);
        // create with empty description
        response = createFeed(FEED_EMPTY_DESCRIPTION);
        assertResponseCode(200, response);
        // verify
        response = getFeed(NAMESPACE, CATEGORY, NAME);
        feed = readGetResponse(response);
        Assert.assertEquals(FEED_EMPTY_DESCRIPTION, feed);
    } finally {
        // cleanup
        response = deleteFeed(NAMESPACE, CATEGORY, NAME);
        assertResponseCode(200, response);
    }
    response = createFeed(NAMESPACE, CATEGORY, NAME, "");
    assertResponseCode(200, response);
}
Also used : HttpResponse(org.apache.http.HttpResponse) NotificationFeedInfo(co.cask.cdap.proto.notification.NotificationFeedInfo) Test(org.junit.Test)

Example 8 with NotificationFeedInfo

use of co.cask.cdap.proto.notification.NotificationFeedInfo in project cdap by caskdata.

the class DistributedStreamService method createHeartbeatsFeed.

/**
   * Create Notification feed for stream's heartbeats, if it does not already exist.
   */
private void createHeartbeatsFeed() throws NotificationFeedException {
    NotificationFeedInfo streamHeartbeatsFeed = new NotificationFeedInfo(NamespaceId.SYSTEM.getEntityName(), Constants.Notification.Stream.STREAM_INTERNAL_FEED_CATEGORY, Constants.Notification.Stream.STREAM_HEARTBEAT_FEED_NAME, "Stream heartbeats feed.");
    LOG.debug("Ensuring Stream HeartbeatsFeed exists.");
    boolean isRetry = false;
    while (true) {
        try {
            feedManager.getFeed(streamHeartbeatsFeed);
            LOG.debug("Stream HeartbeatsFeed exists.");
            return;
        } catch (NotificationFeedNotFoundException notFoundException) {
            if (!isRetry) {
                LOG.debug("Creating Stream HeartbeatsFeed.");
            }
            feedManager.createFeed(streamHeartbeatsFeed);
            LOG.info("Stream HeartbeatsFeed created.");
            return;
        } catch (NotificationFeedException | RetryableException e) {
            if (!isRetry) {
                LOG.warn("Could not ensure existence of HeartbeatsFeed. Will retry until successful. " + "Retry failures will be logged at debug level.", e);
            } else {
                LOG.debug("Could not ensure existence of HeartbeatsFeed. Will retry until successful.", e);
            }
            isRetry = true;
            waitBeforeRetryHeartbeatsFeedOperation();
        }
    }
}
Also used : NotificationFeedException(co.cask.cdap.notifications.feeds.NotificationFeedException) RetryableException(co.cask.cdap.api.retry.RetryableException) NotificationFeedNotFoundException(co.cask.cdap.notifications.feeds.NotificationFeedNotFoundException) NotificationFeedInfo(co.cask.cdap.proto.notification.NotificationFeedInfo)

Example 9 with NotificationFeedInfo

use of co.cask.cdap.proto.notification.NotificationFeedInfo 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 10 with NotificationFeedInfo

use of co.cask.cdap.proto.notification.NotificationFeedInfo in project cdap by caskdata.

the class NotificationFeedInfoDeserializerTest method testDeserialization.

@Test
public void testDeserialization() {
    Gson gson = new GsonBuilder().registerTypeAdapter(NotificationFeedInfo.class, new NotificationFeedInfoDeserializer()).create();
    NotificationFeedInfo newFeed = new NotificationFeedInfo("ns1", "category", "feed1", "desc");
    LegacyNotificationFeedInfo legacyFeed = new LegacyNotificationFeedInfo(newFeed);
    Assert.assertEquals(newFeed, gson.fromJson(gson.toJson(legacyFeed), NotificationFeedInfo.class));
}
Also used : GsonBuilder(com.google.gson.GsonBuilder) Gson(com.google.gson.Gson) NotificationFeedInfo(co.cask.cdap.proto.notification.NotificationFeedInfo) Test(org.junit.Test)

Aggregations

NotificationFeedInfo (co.cask.cdap.proto.notification.NotificationFeedInfo)13 NotificationFeedException (co.cask.cdap.notifications.feeds.NotificationFeedException)6 Test (org.junit.Test)4 NotificationFeedNotFoundException (co.cask.cdap.notifications.feeds.NotificationFeedNotFoundException)3 HttpResponse (org.apache.http.HttpResponse)3 NotificationFeedId (co.cask.cdap.proto.id.NotificationFeedId)2 HttpResponse (co.cask.common.http.HttpResponse)2 Path (javax.ws.rs.Path)2 RetryableException (co.cask.cdap.api.retry.RetryableException)1 AuditPolicy (co.cask.cdap.common.security.AuditPolicy)1 NotificationContext (co.cask.cdap.notifications.service.NotificationContext)1 NamespaceId (co.cask.cdap.proto.id.NamespaceId)1 TypeToken (com.google.common.reflect.TypeToken)1 Gson (com.google.gson.Gson)1 GsonBuilder (com.google.gson.GsonBuilder)1 JsonElement (com.google.gson.JsonElement)1 JsonObject (com.google.gson.JsonObject)1 JsonSyntaxException (com.google.gson.JsonSyntaxException)1 IOException (java.io.IOException)1 Type (java.lang.reflect.Type)1