Search in sources :

Example 1 with NotificationStore

use of com.hortonworks.streamline.streams.notification.store.NotificationStore in project streamline by hortonworks.

the class NotificationBolt method prepare.

@Override
public void prepare(Map stormConf, TopologyContext context, OutputCollector collector) {
    if (!stormConf.containsKey(CATALOG_ROOT_URL)) {
        throw new IllegalArgumentException("conf must contain " + CATALOG_ROOT_URL);
    }
    Map<String, Object> notificationConf = null;
    if (stormConf.get(NOTIFICATION_SERVICE_CONFIG_KEY) != null) {
        notificationConf = (Map<String, Object>) stormConf.get(NOTIFICATION_SERVICE_CONFIG_KEY);
    } else {
        notificationConf = Collections.emptyMap();
    }
    NotificationStore notificationStore = null;
    try {
        if (!StringUtils.isEmpty(notificationStoreClazz)) {
            Class<?> clazz = Class.forName(notificationStoreClazz);
            notificationStore = (NotificationStore) clazz.newInstance();
            Map<String, Object> config = (Map<String, Object>) stormConf.get(NOTIFICATION_STORE_CONFIG_KEY);
            if (config == null) {
                config = Collections.emptyMap();
            }
            notificationStore.init(config);
        }
    } catch (ClassNotFoundException | InstantiationException | IllegalAccessException ex) {
        throw new RuntimeException(ex);
    }
    notificationService = new NotificationServiceImpl(notificationConf, notificationStore);
    String jarPath = "";
    if (stormConf.containsKey(LOCAL_NOTIFIER_JAR_PATH)) {
        jarPath = String.format("%s%s%s", stormConf.get(LOCAL_NOTIFIER_JAR_PATH).toString(), File.separator, notificationSink.getNotifierJarFileName());
    }
    Properties props = new Properties();
    props.putAll(convertMapValuesToString(notificationSink.getNotifierProperties()));
    NotifierConfig notifierConfig = new NotifierConfigImpl(props, convertMapValuesToString(notificationSink.getNotifierFieldValues()), notificationSink.getNotifierClassName(), jarPath);
    notificationContext = new BoltNotificationContext(collector, notifierConfig);
    notificationService.register(notificationSink.getNotifierName(), notificationContext);
}
Also used : Properties(java.util.Properties) NotifierConfig(com.hortonworks.streamline.streams.notification.NotifierConfig) HashMap(java.util.HashMap) Map(java.util.Map) NotificationServiceImpl(com.hortonworks.streamline.streams.notification.service.NotificationServiceImpl) NotificationStore(com.hortonworks.streamline.streams.notification.store.NotificationStore) NotifierConfigImpl(com.hortonworks.streamline.streams.notification.common.NotifierConfigImpl)

Aggregations

NotifierConfig (com.hortonworks.streamline.streams.notification.NotifierConfig)1 NotifierConfigImpl (com.hortonworks.streamline.streams.notification.common.NotifierConfigImpl)1 NotificationServiceImpl (com.hortonworks.streamline.streams.notification.service.NotificationServiceImpl)1 NotificationStore (com.hortonworks.streamline.streams.notification.store.NotificationStore)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Properties (java.util.Properties)1