event.putParameters(parameters); event.putParameter(HIVE_METASTORE_TRANSACTION_ACTIVE, Boolean.toString(ms.isActiveTransaction()));
/** * Notify a list of listeners about a specific metastore event. Each listener notified might update * the (ListenerEvent) event by setting a parameter key/value pair. These updated parameters will * be returned to the caller. * * @param listeners List of MetaStoreEventListener listeners. * @param eventType Type of the notification event. * @param event The ListenerEvent with information about the event. * @return A list of key/value pair parameters that the listeners set. The returned object will return an empty * map if no parameters were updated or if no listeners were notified. * @throws MetaException If an error occurred while calling the listeners. */ public static Map<String, String> notifyEvent(List<? extends MetaStoreEventListener> listeners, EventType eventType, ListenerEvent event) throws MetaException { Preconditions.checkNotNull(listeners, "Listeners must not be null."); Preconditions.checkNotNull(event, "The event must not be null."); for (MetaStoreEventListener listener : listeners) { notificationEvents.get(eventType).notify(listener, event); } // Each listener called above might set a different parameter on the event. // This write permission is allowed on the listener side to avoid breaking compatibility if we change the API // method calls. return event.getParameters(); }
/** * Notify a list of listeners about a specific metastore event. Each listener notified might update * the (ListenerEvent) event by setting a parameter key/value pair. These updated parameters will * be returned to the caller. * * @param listeners List of MetaStoreEventListener listeners. * @param eventType Type of the notification event. * @param event The ListenerEvent with information about the event. * @param environmentContext An EnvironmentContext object with parameters sent by the HMS client. * @return A list of key/value pair parameters that the listeners set. The returned object will return an empty * map if no parameters were updated or if no listeners were notified. * @throws MetaException If an error occurred while calling the listeners. */ public static Map<String, String> notifyEvent(List<? extends MetaStoreEventListener> listeners, EventType eventType, ListenerEvent event, EnvironmentContext environmentContext) throws MetaException { Preconditions.checkNotNull(event, "The event must not be null."); event.setEnvironmentContext(environmentContext); return notifyEvent(listeners, eventType, event); }
/** * Put a new parameter to the listener event. * * Overridden parameters is not allowed, and an exception may be thrown to avoid a mis-configuration * between listeners setting the same parameters. * * @param name Name of the parameter. * @param value Value of the parameter. * @throws IllegalStateException if a parameter already exists. */ public void putParameter(String name, String value) { putParameterIfAbsent(name, value); updateUnmodifiableParameters(); }
listenerEvent.putParameter( MetaStoreEventListenerConstants.DB_NOTIFICATION_EVENT_ID_KEY_NAME, Long.toString(event.getEventId()));
public ListenerEvent(boolean status, IHMSHandler handler) { super(); this.status = status; this.handler = handler; this.parameters = new HashMap<>(PARAMETERS_INITIAL_CAPACITY); updateUnmodifiableParameters(); }
notifyList = DummyListener.notifyList; assertEquals(notifyList.size(), listSize); assertTrue(DummyListener.getLastEvent().getStatus()); notifyList = DummyListener.notifyList; assertEquals(notifyList.size(), listSize); assertTrue(DummyListener.getLastEvent().getStatus()); notifyList = DummyListener.notifyList; assertEquals(notifyList.size(), listSize); assertTrue(DummyListener.getLastEvent().getStatus()); notifyList = DummyListener.notifyList; assertEquals(notifyList.size(), listSize); assertFalse(DummyListener.getLastEvent().getStatus());
/** * Process this notification by adding it to metastore DB. * * @param event NotificationEvent is the object written to the metastore DB. * @param listenerEvent ListenerEvent (from which NotificationEvent was based) used only to set the * DB_NOTIFICATION_EVENT_ID_KEY_NAME for future reference by other listeners. */ private void process(NotificationEvent event, ListenerEvent listenerEvent) throws MetaException { event.setMessageFormat(msgEncoder.getMessageFormat()); LOG.debug("DbNotificationListener: Processing : {}:{}", event.getEventId(), event.getMessage()); HMSHandler.getMSForConf(conf).addNotificationEvent(event); // Set the DB_NOTIFICATION_EVENT_ID for future reference by other listeners. if (event.isSetEventId()) { listenerEvent.putParameter( MetaStoreEventListenerConstants.DB_NOTIFICATION_EVENT_ID_KEY_NAME, Long.toString(event.getEventId())); } }
/** * Put a new set the parameters to the listener event. * * Overridden parameters is not allowed, and an exception may be thrown to avoid a mis-configuration * between listeners setting the same parameters. * * @param parameters A Map object with the a set of parameters. * @throws IllegalStateException if a parameter already exists. */ public void putParameters(final Map<String, String> parameters) { if (parameters != null) { for (Map.Entry<String, String> entry : parameters.entrySet()) { putParameterIfAbsent(entry.getKey(), entry.getValue()); } updateUnmodifiableParameters(); } }
event.putParameters(parameters); event.putParameter(HIVE_METASTORE_TRANSACTION_ACTIVE, Boolean.toString(ms.isActiveTransaction()));
listenerEvent.putParameter( MetaStoreEventListenerConstants.DB_NOTIFICATION_EVENT_ID_KEY_NAME, Long.toString(event.getEventId()));
/** * Notify a list of listeners about a specific metastore event to be executed within a txn. Each listener notified * might update the (ListenerEvent) event by setting a parameter key/value pair. These updated parameters will * be returned to the caller. * * @param listeners List of MetaStoreEventListener listeners. * @param eventType Type of the notification event. * @param event The ListenerEvent with information about the event. * @param dbConn The JDBC connection to the remote meta store db. * @param sqlGenerator The helper class to generate db specific SQL string. * @return A list of key/value pair parameters that the listeners set. The returned object will return an empty * map if no parameters were updated or if no listeners were notified. * @throws MetaException If an error occurred while calling the listeners. */ public static Map<String, String> notifyEventWithDirectSql(List<? extends MetaStoreEventListener> listeners, EventType eventType, ListenerEvent event, Connection dbConn, SQLGenerator sqlGenerator) throws MetaException { Preconditions.checkNotNull(listeners, "Listeners must not be null."); Preconditions.checkNotNull(event, "The event must not be null."); for (MetaStoreEventListener listener : listeners) { txnNotificationEvents.get(eventType).notify(listener, event, dbConn, sqlGenerator); } // Each listener called above might set a different parameter on the event. // This write permission is allowed on the listener side to avoid breaking compatibility if we change the API // method calls. return event.getParameters(); }
/** * Notify a list of listeners about a specific metastore event. Each listener notified might update * the (ListenerEvent) event by setting a parameter key/value pair. These updated parameters will * be returned to the caller. * * @param listeners List of MetaStoreEventListener listeners. * @param eventType Type of the notification event. * @param event The ListenerEvent with information about the event. * @param environmentContext An EnvironmentContext object with parameters sent by the HMS client. * @return A list of key/value pair parameters that the listeners set. The returned object will return an empty * map if no parameters were updated or if no listeners were notified. * @throws MetaException If an error occurred while calling the listeners. */ public static Map<String, String> notifyEvent(List<? extends MetaStoreEventListener> listeners, EventType eventType, ListenerEvent event, EnvironmentContext environmentContext) throws MetaException { Preconditions.checkNotNull(event, "The event must not be null."); event.setEnvironmentContext(environmentContext); return notifyEvent(listeners, eventType, event); }
/** * Process this notification by adding it to metastore DB. * * @param event NotificationEvent is the object written to the metastore DB. * @param listenerEvent ListenerEvent (from which NotificationEvent was based) used only to set the * DB_NOTIFICATION_EVENT_ID_KEY_NAME for future reference by other listeners. */ private void process(NotificationEvent event, ListenerEvent listenerEvent) throws MetaException { event.setMessageFormat(msgFactory.getMessageFormat()); LOG.debug("DbNotificationListener: Processing : {}:{}", event.getEventId(), event.getMessage()); HMSHandler.getMSForConf(conf).addNotificationEvent(event); // Set the DB_NOTIFICATION_EVENT_ID for future reference by other listeners. if (event.isSetEventId()) { listenerEvent.putParameter( MetaStoreEventListenerConstants.DB_NOTIFICATION_EVENT_ID_KEY_NAME, Long.toString(event.getEventId())); } }
/** * Notify a list of listeners about a specific metastore event. Each listener notified might update * the (ListenerEvent) event by setting a parameter key/value pair. These updated parameters will * be returned to the caller. * * @param listeners List of MetaStoreEventListener listeners. * @param eventType Type of the notification event. * @param event The ListenerEvent with information about the event. * @return A list of key/value pair parameters that the listeners set. The returned object will return an empty * map if no parameters were updated or if no listeners were notified. * @throws MetaException If an error occurred while calling the listeners. */ public static Map<String, String> notifyEvent(List<? extends MetaStoreEventListener> listeners, EventType eventType, ListenerEvent event) throws MetaException { Preconditions.checkNotNull(listeners, "Listeners must not be null."); Preconditions.checkNotNull(event, "The event must not be null."); for (MetaStoreEventListener listener : listeners) { notificationEvents.get(eventType).notify(listener, event); } // Each listener called above might set a different parameter on the event. // This write permission is allowed on the listener side to avoid breaking compatibility if we change the API // method calls. return event.getParameters(); }
/** * Notify a list of listeners about a specific metastore event to be executed within a txn. Each listener notified * might update the (ListenerEvent) event by setting a parameter key/value pair. These updated parameters will * be returned to the caller. * * @param listeners List of MetaStoreEventListener listeners. * @param eventType Type of the notification event. * @param event The ListenerEvent with information about the event. * @param dbConn The JDBC connection to the remote meta store db. * @param sqlGenerator The helper class to generate db specific SQL string. * @return A list of key/value pair parameters that the listeners set. The returned object will return an empty * map if no parameters were updated or if no listeners were notified. * @throws MetaException If an error occurred while calling the listeners. */ public static Map<String, String> notifyEventWithDirectSql(List<? extends MetaStoreEventListener> listeners, EventType eventType, ListenerEvent event, Connection dbConn, SQLGenerator sqlGenerator) throws MetaException { Preconditions.checkNotNull(listeners, "Listeners must not be null."); Preconditions.checkNotNull(event, "The event must not be null."); for (MetaStoreEventListener listener : listeners) { txnNotificationEvents.get(eventType).notify(listener, event, dbConn, sqlGenerator); } // Each listener called above might set a different parameter on the event. // This write permission is allowed on the listener side to avoid breaking compatibility if we change the API // method calls. return event.getParameters(); }