public boolean isAnyPluginInterestedIn(String notificationName) { return !getPluginsInterestedIn(notificationName).isEmpty(); }
private boolean isAnyPluginInterestedInAgentStatus() { return notificationPluginRegistry.isAnyPluginInterestedIn(NotificationExtension.AGENT_STATUS_CHANGE_NOTIFICATION); } }
@Before public void setUp() { notificationPluginRegistry = new NotificationPluginRegistry(); notificationPluginRegistry.registerPluginInterests(PLUGIN_ID_1, asList(PIPELINE_STATUS, STAGE_STATUS, JOB_STATUS)); notificationPluginRegistry.registerPluginInterests(PLUGIN_ID_2, asList(PIPELINE_STATUS)); notificationPluginRegistry.registerPluginInterests(PLUGIN_ID_3, asList(STAGE_STATUS)); }
@Test public void shouldNotListDeRegisteredPlugins() { notificationPluginRegistry.registerPlugin("plugin_id_1"); notificationPluginRegistry.deregisterPlugin("plugin_id_1"); assertTrue(notificationPluginRegistry.getNotificationPlugins().isEmpty()); } }
@Test public void should_removePluginInterests_Correctly() { notificationPluginRegistry.removePluginInterests(PLUGIN_ID_1); assertThat(notificationPluginRegistry.getPluginsInterestedIn(PIPELINE_STATUS), containsInAnyOrder(PLUGIN_ID_2)); assertThat(notificationPluginRegistry.getPluginsInterestedIn(STAGE_STATUS), containsInAnyOrder(PLUGIN_ID_3)); assertThat(notificationPluginRegistry.getPluginsInterestedIn(JOB_STATUS), containsInAnyOrder()); assertThat(notificationPluginRegistry.getPluginsInterestedIn(UNKNOWN_NOTIFICATION), containsInAnyOrder()); }
@Override public void pluginUnLoaded(GoPluginDescriptor pluginDescriptor) { if (notificationExtension.canHandlePlugin(pluginDescriptor.id())) { notificationPluginRegistry.deregisterPlugin(pluginDescriptor.id()); notificationPluginRegistry.removePluginInterests(pluginDescriptor.id()); } } }
@Override public void pluginLoaded(GoPluginDescriptor pluginDescriptor) { if (notificationExtension.canHandlePlugin(pluginDescriptor.id())) { try { notificationPluginRegistry.registerPlugin(pluginDescriptor.id()); List<String> notificationsInterestedIn = notificationExtension.getNotificationsOfInterestFor(pluginDescriptor.id()); if (notificationsInterestedIn != null && !notificationsInterestedIn.isEmpty()) { checkNotificationTypes(pluginDescriptor, notificationsInterestedIn); notificationPluginRegistry.registerPluginInterests(pluginDescriptor.id(), notificationsInterestedIn); } } catch (Exception e) { LOGGER.warn("Error occurred during plugin notification interest registration.", e); } } }
@Test public void shouldNotRegisterDuplicatePlugins() { notificationPluginRegistry.registerPlugin("plugin_id_1"); notificationPluginRegistry.registerPlugin("plugin_id_1"); assertThat(notificationPluginRegistry.getNotificationPlugins().size(), is(1)); assertTrue(notificationPluginRegistry.getNotificationPlugins().contains("plugin_id_1")); }
@Test public void shouldRegisterPluginInterestsOnPluginLoad() { NotificationPluginRegistrar notificationPluginRegistrar = new NotificationPluginRegistrar(pluginManager, notificationExtension, notificationPluginRegistry); notificationPluginRegistrar.pluginLoaded(new GoPluginDescriptor(PLUGIN_ID_1, null, null, null, null, true)); verify(notificationPluginRegistry).registerPluginInterests(PLUGIN_ID_1, asList(PIPELINE_STATUS, STAGE_STATUS, JOB_STATUS)); notificationPluginRegistrar.pluginLoaded(new GoPluginDescriptor(PLUGIN_ID_2, null, null, null, null, true)); verify(notificationPluginRegistry).registerPluginInterests(PLUGIN_ID_2, asList(PIPELINE_STATUS)); notificationPluginRegistrar.pluginLoaded(new GoPluginDescriptor(PLUGIN_ID_3, null, null, null, null, true)); verify(notificationPluginRegistry).registerPluginInterests(PLUGIN_ID_3, asList(STAGE_STATUS)); }
@Test public void shouldNotUnregisterPluginInterestsOnPluginUnLoadIfPluginIsNotOfNotificationType() { NotificationPluginRegistrar notificationPluginRegistrar = new NotificationPluginRegistrar(pluginManager, notificationExtension, notificationPluginRegistry); notificationPluginRegistrar.pluginUnLoaded(new GoPluginDescriptor(PLUGIN_ID_4, null, null, null, null, true)); verify(notificationPluginRegistry, never()).removePluginInterests(PLUGIN_ID_4); }
@Test public void shouldRegisterPluginOnPluginLoad() { NotificationPluginRegistrar notificationPluginRegistrar = new NotificationPluginRegistrar(pluginManager, notificationExtension, notificationPluginRegistry); notificationPluginRegistrar.pluginLoaded(new GoPluginDescriptor(PLUGIN_ID_1, null, null, null, null, true)); verify(notificationPluginRegistry).registerPlugin(PLUGIN_ID_1); }
@Test public void shouldUnregisterPluginOnPluginUnLoad() { NotificationPluginRegistrar notificationPluginRegistrar = new NotificationPluginRegistrar(pluginManager, notificationExtension, notificationPluginRegistry); notificationPluginRegistrar.pluginUnLoaded(new GoPluginDescriptor(PLUGIN_ID_1, null, null, null, null, true)); verify(notificationPluginRegistry).deregisterPlugin(PLUGIN_ID_1); } }
public void registerPluginInterests(String pluginId, List<String> notificationNames) { if (notificationNames != null && !notificationNames.isEmpty()) { for (String notificationName : notificationNames) { addToMap(notificationName, pluginId); } } }
@After public void tearDown() { notificationPluginRegistry.clear(); }
@Test public void shouldListRegisteredPlugins() { notificationPluginRegistry.registerPlugin("plugin_id_1"); notificationPluginRegistry.registerPlugin("plugin_id_2"); assertThat(notificationPluginRegistry.getNotificationPlugins().size(), is(2)); assertTrue(notificationPluginRegistry.getNotificationPlugins().contains("plugin_id_1")); assertTrue(notificationPluginRegistry.getNotificationPlugins().contains("plugin_id_2")); }
@Test public void shouldNotRegisterPluginInterestsOnPluginLoadIfPluginIfPluginIsNotOfNotificationType() { NotificationPluginRegistrar notificationPluginRegistrar = new NotificationPluginRegistrar(pluginManager, notificationExtension, notificationPluginRegistry); notificationPluginRegistrar.pluginLoaded(new GoPluginDescriptor(PLUGIN_ID_4, null, null, null, null, true)); verify(notificationPluginRegistry, never()).registerPluginInterests(anyString(), anyList()); }
@Test public void shouldUnregisterPluginInterestsOnPluginUnLoad() { NotificationPluginRegistrar notificationPluginRegistrar = new NotificationPluginRegistrar(pluginManager, notificationExtension, notificationPluginRegistry); notificationPluginRegistrar.pluginUnLoaded(new GoPluginDescriptor(PLUGIN_ID_1, null, null, null, null, true)); verify(notificationPluginRegistry).removePluginInterests(PLUGIN_ID_1); }
private <T> void notify(String requestName, T instance) { Set<String> interestedPlugins = notificationPluginRegistry.getPluginsInterestedIn(requestName); Long timeToLive = systemEnvironment.get(NOTIFICATION_PLUGIN_MESSAGES_TTL); for (String pluginId : interestedPlugins) { PluginNotificationMessage message = new PluginNotificationMessage<>(pluginId, requestName, map.get(requestName).notificationDataFor(instance)); pluginNotificationsQueueHandler.post(message, timeToLive); } }
private boolean isAnyPluginInterestedInStageStatus() { return notificationPluginRegistry.isAnyPluginInterestedIn(NotificationExtension.STAGE_STATUS_CHANGE_NOTIFICATION); }
@Test public void should_getPluginsInterestedIn_Correctly() { assertThat(notificationPluginRegistry.getPluginsInterestedIn(PIPELINE_STATUS), containsInAnyOrder(PLUGIN_ID_1, PLUGIN_ID_2)); assertThat(notificationPluginRegistry.getPluginsInterestedIn(STAGE_STATUS), containsInAnyOrder(PLUGIN_ID_1, PLUGIN_ID_3)); assertThat(notificationPluginRegistry.getPluginsInterestedIn(JOB_STATUS), containsInAnyOrder(PLUGIN_ID_1)); assertThat(notificationPluginRegistry.getPluginsInterestedIn(UNKNOWN_NOTIFICATION), containsInAnyOrder()); }