Search in sources :

Example 1 with RetryableException

use of co.cask.cdap.api.retry.RetryableException in project cdap by caskdata.

the class DatasetServiceStore method startUp.

@Override
protected void startUp() throws Exception {
    final DatasetId serviceStoreDatasetInstanceId = NamespaceId.SYSTEM.dataset(Constants.Service.SERVICE_INSTANCE_TABLE_NAME);
    table = Retries.supplyWithRetries(new Supplier<NoTxKeyValueTable>() {

        @Override
        public NoTxKeyValueTable get() {
            try {
                return DatasetsUtil.getOrCreateDataset(dsFramework, serviceStoreDatasetInstanceId, NoTxKeyValueTable.class.getName(), DatasetProperties.EMPTY, null);
            } catch (Exception e) {
                // Throwing RetryableException here is just to make it retry getting the dataset
                // an exception here usually means there is an hbase problem
                LOG.warn("Error getting service store dataset {}. Will retry after some time: {}", serviceStoreDatasetInstanceId, e.getMessage());
                throw new RetryableException(e);
            }
        }
    }, RetryStrategies.exponentialDelay(1, 30, TimeUnit.SECONDS));
}
Also used : RetryableException(co.cask.cdap.api.retry.RetryableException) NoTxKeyValueTable(co.cask.cdap.data2.dataset2.lib.kv.NoTxKeyValueTable) Supplier(com.google.common.base.Supplier) RetryableException(co.cask.cdap.api.retry.RetryableException) DatasetId(co.cask.cdap.proto.id.DatasetId)

Example 2 with RetryableException

use of co.cask.cdap.api.retry.RetryableException 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)

Aggregations

RetryableException (co.cask.cdap.api.retry.RetryableException)2 NoTxKeyValueTable (co.cask.cdap.data2.dataset2.lib.kv.NoTxKeyValueTable)1 NotificationFeedException (co.cask.cdap.notifications.feeds.NotificationFeedException)1 NotificationFeedNotFoundException (co.cask.cdap.notifications.feeds.NotificationFeedNotFoundException)1 DatasetId (co.cask.cdap.proto.id.DatasetId)1 NotificationFeedInfo (co.cask.cdap.proto.notification.NotificationFeedInfo)1 Supplier (com.google.common.base.Supplier)1