Search in sources :

Example 1 with ConfigUpdateCheckFailedException

use of com.thoughtworks.go.config.update.ConfigUpdateCheckFailedException in project gocd by gocd.

the class GoConfigDao method updateConfig.

public ConfigSaveState updateConfig(UpdateConfigCommand command) {
    ConfigSaveState configSaveState = null;
    LOGGER.info("Config update request by {} is in queue - {}", UserHelper.getUserName().getUsername(), command);
    synchronized (GoConfigWriteLock.class) {
        try {
            LOGGER.info("Config update request {} by {} is being processed", command, UserHelper.getUserName().getUsername());
            if (command instanceof CheckedUpdateCommand) {
                CheckedUpdateCommand checkedCommand = (CheckedUpdateCommand) command;
                if (!checkedCommand.canContinue(cachedConfigService.currentConfig())) {
                    throw new ConfigUpdateCheckFailedException();
                }
            }
            configSaveState = cachedConfigService.writeWithLock(command);
        } finally {
            if (command instanceof ConfigAwareUpdate) {
                ((ConfigAwareUpdate) command).afterUpdate(clonedConfig());
            }
            LOGGER.info("Config update request by {} is completed", UserHelper.getUserName().getUsername());
        }
    }
    return configSaveState;
}
Also used : ConfigUpdateCheckFailedException(com.thoughtworks.go.config.update.ConfigUpdateCheckFailedException) CheckedUpdateCommand(com.thoughtworks.go.config.commands.CheckedUpdateCommand)

Example 2 with ConfigUpdateCheckFailedException

use of com.thoughtworks.go.config.update.ConfigUpdateCheckFailedException in project gocd by gocd.

the class GoConfigDaoTestBase method shouldNotUpdatePipelineConfigIfUserDoesNotHaveRequiredPermissionsToDoSo.

@Test
public void shouldNotUpdatePipelineConfigIfUserDoesNotHaveRequiredPermissionsToDoSo() {
    CachedGoConfig cachedConfigService = mock(CachedGoConfig.class);
    CruiseConfig cruiseConfig = mock(CruiseConfig.class);
    when(cachedConfigService.currentConfig()).thenReturn(cruiseConfig);
    goConfigDao = new GoConfigDao(cachedConfigService);
    EntityConfigUpdateCommand command = mock(EntityConfigUpdateCommand.class);
    when(command.canContinue(cruiseConfig)).thenReturn(false);
    try {
        goConfigDao.updateConfig(command, new Username(new CaseInsensitiveString("user")));
        fail("Expected to throw exception of type:" + ConfigUpdateCheckFailedException.class.getName());
    } catch (Exception e) {
        assertTrue(e instanceof ConfigUpdateCheckFailedException);
    }
    verify(cachedConfigService).currentConfig();
    verifyNoMoreInteractions(cachedConfigService);
}
Also used : Username(com.thoughtworks.go.server.domain.Username) ConfigUpdateCheckFailedException(com.thoughtworks.go.config.update.ConfigUpdateCheckFailedException) EntityConfigUpdateCommand(com.thoughtworks.go.config.commands.EntityConfigUpdateCommand) ConfigFileHasChangedException(com.thoughtworks.go.config.exceptions.ConfigFileHasChangedException) ConfigUpdateCheckFailedException(com.thoughtworks.go.config.update.ConfigUpdateCheckFailedException) Test(org.junit.Test)

Aggregations

ConfigUpdateCheckFailedException (com.thoughtworks.go.config.update.ConfigUpdateCheckFailedException)2 CheckedUpdateCommand (com.thoughtworks.go.config.commands.CheckedUpdateCommand)1 EntityConfigUpdateCommand (com.thoughtworks.go.config.commands.EntityConfigUpdateCommand)1 ConfigFileHasChangedException (com.thoughtworks.go.config.exceptions.ConfigFileHasChangedException)1 Username (com.thoughtworks.go.server.domain.Username)1 Test (org.junit.Test)1