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));
}
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");
}
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);
}
});
}
}
};
}
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());
}
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));
}
Aggregations