Search in sources :

Example 6 with EntityConfigChangedListener

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

the class PipelineConfigServiceIntegrationTest method shouldNotifyListenersWithPreprocessedConfigUponSuccessfulUpdate.

@Test
public void shouldNotifyListenersWithPreprocessedConfigUponSuccessfulUpdate() {
    final String pipelineName = UUID.randomUUID().toString();
    final String templateName = UUID.randomUUID().toString();
    final boolean[] listenerInvoked = { false };
    setupPipelineWithTemplate(pipelineName, templateName);
    PipelineConfig pipelineConfig1 = goConfigService.pipelineConfigNamed(new CaseInsensitiveString(pipelineName));
    String xml = new MagicalGoConfigXmlWriter(configCache, registry).toXmlPartial(pipelineConfig1);
    String md5 = CachedDigestUtils.md5Hex(xml);
    EntityConfigChangedListener<PipelineConfig> pipelineConfigChangedListener = new EntityConfigChangedListener<PipelineConfig>() {

        @Override
        public void onConfigChange(CruiseConfig newCruiseConfig) {
        }

        @Override
        public void onEntityConfigChange(PipelineConfig pipelineConfig) {
            listenerInvoked[0] = true;
            assertThat(pipelineConfig.first(), is(goConfigService.cruiseConfig().getTemplateByName(new CaseInsensitiveString(templateName)).first()));
        }
    };
    goConfigService.register(pipelineConfigChangedListener);
    PipelineConfig pipeline = PipelineConfigMother.pipelineConfigWithTemplate(pipelineName, templateName);
    pipeline.setVariables(new EnvironmentVariablesConfig());
    pipelineConfigService.updatePipelineConfig(user, pipeline, md5, new DefaultLocalizedOperationResult());
    assertThat(listenerInvoked[0], is(true));
}
Also used : DefaultLocalizedOperationResult(com.thoughtworks.go.server.service.result.DefaultLocalizedOperationResult) EntityConfigChangedListener(com.thoughtworks.go.listener.EntityConfigChangedListener) Test(org.junit.Test)

Example 7 with EntityConfigChangedListener

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

the class CcTrayActivityListenerTest method shouldInvokeConfigChangeHandlerWhenPipelineConfigChanges.

@Test
public void shouldInvokeConfigChangeHandlerWhenPipelineConfigChanges() throws InterruptedException {
    PipelineConfig pipelineConfig = mock(PipelineConfig.class);
    CaseInsensitiveString p1 = new CaseInsensitiveString("p1");
    when(pipelineConfig.name()).thenReturn(p1);
    CcTrayConfigChangeHandler ccTrayConfigChangeHandler = mock(CcTrayConfigChangeHandler.class);
    ArgumentCaptor<ConfigChangedListener> captor = ArgumentCaptor.forClass(ConfigChangedListener.class);
    doNothing().when(goConfigService).register(captor.capture());
    when(goConfigService.findGroupNameByPipeline(p1)).thenReturn("group1");
    CcTrayActivityListener listener = new CcTrayActivityListener(goConfigService, mock(CcTrayJobStatusChangeHandler.class), mock(CcTrayStageStatusChangeHandler.class), ccTrayConfigChangeHandler);
    listener.initialize();
    List<ConfigChangedListener> listeners = captor.getAllValues();
    assertThat(listeners.get(1) instanceof EntityConfigChangedListener, is(true));
    EntityConfigChangedListener<PipelineConfig> pipelineConfigChangeListener = (EntityConfigChangedListener<PipelineConfig>) listeners.get(1);
    pipelineConfigChangeListener.onEntityConfigChange(pipelineConfig);
    waitForProcessingToHappen();
    verify(ccTrayConfigChangeHandler).call(pipelineConfig, "group1");
}
Also used : EntityConfigChangedListener(com.thoughtworks.go.listener.EntityConfigChangedListener) ConfigChangedListener(com.thoughtworks.go.listener.ConfigChangedListener) PipelineConfig(com.thoughtworks.go.config.PipelineConfig) EntityConfigChangedListener(com.thoughtworks.go.listener.EntityConfigChangedListener) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) Test(org.junit.Test)

Example 8 with EntityConfigChangedListener

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

the class BuildAssignmentService method pipelineConfigChangedListener.

protected EntityConfigChangedListener<PipelineConfig> pipelineConfigChangedListener() {
    return new EntityConfigChangedListener<PipelineConfig>() {

        @Override
        public void onEntityConfigChange(PipelineConfig pipelineConfig) {
            LOGGER.info("[Configuration Changed] Removing deleted jobs for pipeline {}.", pipelineConfig.name());
            synchronized (BuildAssignmentService.this) {
                List<JobPlan> jobsToRemove = new ArrayList<>();
                for (JobPlan jobPlan : jobPlans) {
                    if (pipelineConfig.name().equals(new CaseInsensitiveString(jobPlan.getPipelineName()))) {
                        StageConfig stageConfig = pipelineConfig.findBy(new CaseInsensitiveString(jobPlan.getStageName()));
                        if (stageConfig != null) {
                            JobConfig jobConfig = stageConfig.jobConfigByConfigName(new CaseInsensitiveString(jobPlan.getName()));
                            if (jobConfig == null) {
                                jobsToRemove.add(jobPlan);
                            }
                        } else {
                            jobsToRemove.add(jobPlan);
                        }
                    }
                }
                forAllDo(jobsToRemove, new Closure() {

                    @Override
                    public void execute(Object o) {
                        removeJob((JobPlan) o);
                    }
                });
            }
        }
    };
}
Also used : Closure(org.apache.commons.collections.Closure) EntityConfigChangedListener(com.thoughtworks.go.listener.EntityConfigChangedListener)

Example 9 with EntityConfigChangedListener

use of com.thoughtworks.go.listener.EntityConfigChangedListener 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();
                @SuppressWarnings("unchecked") 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 10 with EntityConfigChangedListener

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

the class PipelineConfigServiceIntegrationTest method shouldNotifyListenersWithPreprocessedConfigUponSuccessfulCreate.

@Test
public void shouldNotifyListenersWithPreprocessedConfigUponSuccessfulCreate() {
    final String pipelineName = UUID.randomUUID().toString();
    final String templateName = UUID.randomUUID().toString();
    final boolean[] listenerInvoked = { false };
    setupPipelineWithTemplate(pipelineName, templateName);
    EntityConfigChangedListener<PipelineConfig> pipelineConfigChangedListener = new EntityConfigChangedListener<PipelineConfig>() {

        @Override
        public void onConfigChange(CruiseConfig newCruiseConfig) {
        }

        @Override
        public void onEntityConfigChange(PipelineConfig pipelineConfig) {
            listenerInvoked[0] = true;
            assertThat(pipelineConfig.first(), is(goConfigService.cruiseConfig().getTemplateByName(new CaseInsensitiveString(templateName)).first()));
        }
    };
    goConfigService.register(pipelineConfigChangedListener);
    PipelineConfig pipeline = PipelineConfigMother.pipelineConfigWithTemplate(UUID.randomUUID().toString(), templateName);
    pipeline.setVariables(new EnvironmentVariablesConfig());
    pipelineConfigService.createPipelineConfig(user, pipeline, new DefaultLocalizedOperationResult(), "group1");
    assertThat(listenerInvoked[0], is(true));
}
Also used : DefaultLocalizedOperationResult(com.thoughtworks.go.server.service.result.DefaultLocalizedOperationResult) EntityConfigChangedListener(com.thoughtworks.go.listener.EntityConfigChangedListener) Test(org.junit.Test)

Aggregations

EntityConfigChangedListener (com.thoughtworks.go.listener.EntityConfigChangedListener)12 Test (org.junit.Test)10 ConfigChangedListener (com.thoughtworks.go.listener.ConfigChangedListener)6 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)4 PipelineConfig (com.thoughtworks.go.config.PipelineConfig)4 DefaultLocalizedOperationResult (com.thoughtworks.go.server.service.result.DefaultLocalizedOperationResult)2 TimerConfig (com.thoughtworks.go.config.TimerConfig)1 EntityConfigUpdateCommand (com.thoughtworks.go.config.commands.EntityConfigUpdateCommand)1 Username (com.thoughtworks.go.server.domain.Username)1 GoConfigService (com.thoughtworks.go.server.service.GoConfigService)1 HealthStateScope (com.thoughtworks.go.serverhealth.HealthStateScope)1 ServerHealthService (com.thoughtworks.go.serverhealth.ServerHealthService)1 Date (java.util.Date)1 Closure (org.apache.commons.collections.Closure)1