Search in sources :

Example 11 with ConfigChangedListener

use of com.thoughtworks.go.listener.ConfigChangedListener in project gocd by gocd.

the class CachedGoConfig method saveValidConfigToCacheAndNotifyEntityConfigChangeListeners.

private <T> void saveValidConfigToCacheAndNotifyEntityConfigChangeListeners(EntityConfigSaveResult<T> saveResult) {
    saveValidConfigToCache(saveResult.getConfigHolder());
    LOGGER.info("About to notify {} config listeners", saveResult.getEntityConfig().getClass().getName());
    for (ConfigChangedListener listener : listeners) {
        if (listener instanceof EntityConfigChangedListener<?> && ((EntityConfigChangedListener) listener).shouldCareAbout(saveResult.getEntityConfig())) {
            try {
                long startTime = System.currentTimeMillis();
                EntityConfigChangedListener<T> entityConfigChangedListener = (EntityConfigChangedListener<T>) listener;
                entityConfigChangedListener.onEntityConfigChange(saveResult.getEntityConfig());
                LOGGER.debug("Notifying {} took (in ms): {}", listener.getClass(), (System.currentTimeMillis() - startTime));
            } catch (Exception e) {
                LOGGER.error("failed to fire config changed event for listener: {}", listener, e);
            }
        }
    }
    LOGGER.info("Finished notifying {} config listeners", saveResult.getEntityConfig().getClass().getName());
}
Also used : EntityConfigChangedListener(com.thoughtworks.go.listener.EntityConfigChangedListener) ConfigChangedListener(com.thoughtworks.go.listener.ConfigChangedListener) EntityConfigChangedListener(com.thoughtworks.go.listener.EntityConfigChangedListener)

Example 12 with ConfigChangedListener

use of com.thoughtworks.go.listener.ConfigChangedListener in project gocd by gocd.

the class CachedGoConfig method notifyListeners.

private synchronized void notifyListeners(CruiseConfig newCruiseConfig) {
    LOGGER.info("About to notify config listeners");
    for (ConfigChangedListener listener : listeners) {
        try {
            listener.onConfigChange(newCruiseConfig);
        } catch (Exception e) {
            LOGGER.error("Failed to fire config changed event for listener: {}", listener, e);
        }
    }
    LOGGER.info("Finished notifying all listeners");
}
Also used : EntityConfigChangedListener(com.thoughtworks.go.listener.EntityConfigChangedListener) ConfigChangedListener(com.thoughtworks.go.listener.ConfigChangedListener)

Example 13 with ConfigChangedListener

use of com.thoughtworks.go.listener.ConfigChangedListener in project gocd by gocd.

the class CachedGoConfigTest method shouldNotNotifyWhenConfigIsNullDuringRegistration.

@Test
public void shouldNotNotifyWhenConfigIsNullDuringRegistration() throws Exception {
    final ConfigChangedListener listener = mock(ConfigChangedListener.class);
    cachedGoConfig.registerListener(listener);
    verifyNoMoreInteractions(listener);
}
Also used : EntityConfigChangedListener(com.thoughtworks.go.listener.EntityConfigChangedListener) ConfigChangedListener(com.thoughtworks.go.listener.ConfigChangedListener) Test(org.junit.jupiter.api.Test)

Example 14 with ConfigChangedListener

use of com.thoughtworks.go.listener.ConfigChangedListener in project gocd by gocd.

the class CcTrayActivityListenerTest method shouldInvokeConfigChangeHandlerWhenSecurityConfigChanges.

@Test
public void shouldInvokeConfigChangeHandlerWhenSecurityConfigChanges() throws InterruptedException {
    CcTrayConfigChangeHandler ccTrayConfigChangeHandler = mock(CcTrayConfigChangeHandler.class);
    CruiseConfig cruiseConfig = mock(CruiseConfig.class);
    ArgumentCaptor<ConfigChangedListener> captor = ArgumentCaptor.forClass(ConfigChangedListener.class);
    doNothing().when(goConfigService).register(captor.capture());
    when(goConfigService.currentCruiseConfig()).thenReturn(cruiseConfig);
    CcTrayActivityListener listener = new CcTrayActivityListener(goConfigService, mock(CcTrayJobStatusChangeHandler.class), mock(CcTrayStageStatusChangeHandler.class), ccTrayConfigChangeHandler);
    listener.initialize();
    listener.startDaemon();
    List<ConfigChangedListener> listeners = captor.getAllValues();
    assertThat(listeners.get(2) instanceof SecurityConfigChangeListener, is(true));
    SecurityConfigChangeListener securityConfigChangeListener = (SecurityConfigChangeListener) listeners.get(2);
    securityConfigChangeListener.onEntityConfigChange(new PluginRoleConfig());
    waitForProcessingToHappen();
    verify(ccTrayConfigChangeHandler).call(cruiseConfig);
}
Also used : EntityConfigChangedListener(com.thoughtworks.go.listener.EntityConfigChangedListener) ConfigChangedListener(com.thoughtworks.go.listener.ConfigChangedListener) SecurityConfigChangeListener(com.thoughtworks.go.listener.SecurityConfigChangeListener) PluginRoleConfig(com.thoughtworks.go.config.PluginRoleConfig) CruiseConfig(com.thoughtworks.go.config.CruiseConfig) Test(org.junit.jupiter.api.Test)

Aggregations

ConfigChangedListener (com.thoughtworks.go.listener.ConfigChangedListener)14 EntityConfigChangedListener (com.thoughtworks.go.listener.EntityConfigChangedListener)12 Test (org.junit.jupiter.api.Test)11 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)5 PipelineConfig (com.thoughtworks.go.config.PipelineConfig)5 GoConfigService (com.thoughtworks.go.server.service.GoConfigService)2 BasicCruiseConfig (com.thoughtworks.go.config.BasicCruiseConfig)1 ConfigRepoReparseListener (com.thoughtworks.go.config.ConfigReposMaterialParseResultManager.ConfigRepoReparseListener)1 CruiseConfig (com.thoughtworks.go.config.CruiseConfig)1 PluginRoleConfig (com.thoughtworks.go.config.PluginRoleConfig)1 TimerConfig (com.thoughtworks.go.config.TimerConfig)1 ConfigRepoConfig (com.thoughtworks.go.config.remote.ConfigRepoConfig)1 ConfigReposConfig (com.thoughtworks.go.config.remote.ConfigReposConfig)1 PartialConfig (com.thoughtworks.go.config.remote.PartialConfig)1 RepoConfigOrigin (com.thoughtworks.go.config.remote.RepoConfigOrigin)1 SecurityConfigChangeListener (com.thoughtworks.go.listener.SecurityConfigChangeListener)1 HealthStateScope (com.thoughtworks.go.serverhealth.HealthStateScope)1 ServerHealthService (com.thoughtworks.go.serverhealth.ServerHealthService)1 Date (java.util.Date)1 Test (org.junit.Test)1