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);
}
}
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);
}
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();
}
}
}
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);
}
}
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));
}
Aggregations