Search in sources :

Example 1 with ConfigRepository

use of com.thoughtworks.go.service.ConfigRepository in project gocd by gocd.

the class GoConfigFileHelper method createTestingDao.

/**
 * Creates config dao that has custom remote configuration parts provided by partialConfig argument
 */
public static GoConfigDao createTestingDao(GoPartialConfig partialConfig) {
    SystemEnvironment systemEnvironment = new SystemEnvironment();
    try {
        ServerHealthService serverHealthService = new ServerHealthService();
        ConfigRepository configRepository = new ConfigRepository(systemEnvironment);
        configRepository.initialize();
        FullConfigSaveNormalFlow normalFlow = new FullConfigSaveNormalFlow(new ConfigCache(), com.thoughtworks.go.util.ConfigElementImplementationRegistryMother.withNoPlugins(), systemEnvironment, new ServerVersion(), new TimeProvider(), configRepository, new CachedGoPartials(serverHealthService));
        GoFileConfigDataSource dataSource = new GoFileConfigDataSource(new DoNotUpgrade(), configRepository, systemEnvironment, new TimeProvider(), new ConfigCache(), new ServerVersion(), com.thoughtworks.go.util.ConfigElementImplementationRegistryMother.withNoPlugins(), serverHealthService, new CachedGoPartials(serverHealthService), null, normalFlow);
        dataSource.upgradeIfNecessary();
        CachedGoPartials cachedGoPartials = new CachedGoPartials(serverHealthService);
        CachedGoConfig cachedConfigService = new CachedGoConfig(serverHealthService, dataSource, cachedGoPartials, null, null);
        cachedConfigService.loadConfigIfNull();
        return new GoConfigDao(cachedConfigService);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
Also used : ServerVersion(com.thoughtworks.go.server.util.ServerVersion) ConfigRepository(com.thoughtworks.go.service.ConfigRepository) IOException(java.io.IOException) ServerHealthService(com.thoughtworks.go.serverhealth.ServerHealthService)

Example 2 with ConfigRepository

use of com.thoughtworks.go.service.ConfigRepository in project gocd by gocd.

the class GoConfigMigrationIntegrationTest method setUp.

@Before
public void setUp() throws Exception {
    File file = temporaryFolder.newFolder();
    configFile = new File(file, "cruise-config.xml");
    new SystemEnvironment().setProperty(SystemEnvironment.CONFIG_FILE_PROPERTY, configFile.getAbsolutePath());
    GoConfigFileHelper.clearConfigVersions();
    configRepository = new ConfigRepository(systemEnvironment);
    configRepository.initialize();
    serverHealthService.removeAllLogs();
    currentGoServerVersion = serverVersion.version();
    loader = new MagicalGoConfigXmlLoader(new ConfigCache(), ConfigElementImplementationRegistryMother.withNoPlugins());
    password = UUID.randomUUID().toString();
    encryptedPassword = new GoCipher().encrypt(password);
}
Also used : GoCipher(com.thoughtworks.go.security.GoCipher) ConfigRepository(com.thoughtworks.go.service.ConfigRepository) File(java.io.File) Before(org.junit.Before)

Example 3 with ConfigRepository

use of com.thoughtworks.go.service.ConfigRepository in project gocd by gocd.

the class BackupServiceIntegrationTest method shouldReturnIfBackupIsInProgress.

@Test
public void shouldReturnIfBackupIsInProgress() throws InterruptedException {
    final Semaphore waitForBackupToBegin = new Semaphore(1);
    final Semaphore waitForAssertion_whichHasToHappen_whileBackupIsRunning = new Semaphore(1);
    Database databaseStrategyMock = mock(Database.class);
    doAnswer((Answer<Object>) invocationOnMock -> {
        waitForBackupToBegin.release();
        waitForAssertion_whichHasToHappen_whileBackupIsRunning.acquire();
        return null;
    }).when(databaseStrategyMock).backup(any(File.class));
    final BackupService backupService = new BackupService(artifactsDirHolder, goConfigService, new TimeProvider(), backupInfoRepository, systemEnvSpy, configRepository, databaseStrategyMock, null);
    waitForBackupToBegin.acquire();
    Thread thd = new Thread(() -> backupService.startBackup(admin));
    thd.start();
    waitForAssertion_whichHasToHappen_whileBackupIsRunning.acquire();
    waitForBackupToBegin.acquire();
    assertThat(backupService.isBackingUp(), is(true));
    waitForAssertion_whichHasToHappen_whileBackupIsRunning.release();
    thd.join();
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) BackupProgressStatus(com.thoughtworks.go.server.domain.BackupProgressStatus) Autowired(org.springframework.beans.factory.annotation.Autowired) ServerBackup(com.thoughtworks.go.server.domain.ServerBackup) GitMaterial(com.thoughtworks.go.config.materials.git.GitMaterial) Database(com.thoughtworks.go.server.database.Database) StringRevision(com.thoughtworks.go.domain.materials.mercurial.StringRevision) ConfigRepository(com.thoughtworks.go.service.ConfigRepository) DESCipherProvider(com.thoughtworks.go.security.DESCipherProvider) Username(com.thoughtworks.go.server.domain.Username) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) AESCipherProvider(com.thoughtworks.go.security.AESCipherProvider) ServerBackupRepository(com.thoughtworks.go.server.persistence.ServerBackupRepository) Modification(com.thoughtworks.go.domain.materials.Modification) TrueFileFilter(org.apache.commons.io.filefilter.TrueFileFilter) Path(java.nio.file.Path) ZipEntry(java.util.zip.ZipEntry) ISODateTimeFormat(org.joda.time.format.ISODateTimeFormat) InMemoryStreamConsumer(com.thoughtworks.go.util.command.InMemoryStreamConsumer) DatabaseAccessHelper(com.thoughtworks.go.server.dao.DatabaseAccessHelper) Test(org.junit.jupiter.api.Test) IOUtils(org.apache.commons.io.IOUtils) List(java.util.List) Hex.encodeHexString(org.apache.commons.codec.binary.Hex.encodeHexString) ServerBackupQueue(com.thoughtworks.go.server.messaging.ServerBackupQueue) TempDir(org.junit.jupiter.api.io.TempDir) Optional(java.util.Optional) Matchers.greaterThan(org.hamcrest.Matchers.greaterThan) Matchers.is(org.hamcrest.Matchers.is) FilenameUtils(org.apache.commons.io.FilenameUtils) ZipInputStream(java.util.zip.ZipInputStream) RevisionContext(com.thoughtworks.go.domain.materials.RevisionContext) SubprocessExecutionContext(com.thoughtworks.go.config.materials.SubprocessExecutionContext) ArrayList(java.util.ArrayList) Answer(org.mockito.stubbing.Answer) NameFileFilter(org.apache.commons.io.filefilter.NameFileFilter) CurrentGoCDVersion(com.thoughtworks.go.CurrentGoCDVersion) DataSource(javax.sql.DataSource) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) DateTimeFormatter(org.joda.time.format.DateTimeFormatter) SpringExtension(org.springframework.test.context.junit.jupiter.SpringExtension) Semaphore(java.util.concurrent.Semaphore) UTF_8(java.nio.charset.StandardCharsets.UTF_8) DateTime(org.joda.time.DateTime) FileUtils(org.apache.commons.io.FileUtils) com.thoughtworks.go.config(com.thoughtworks.go.config) Mockito(org.mockito.Mockito) com.thoughtworks.go.util(com.thoughtworks.go.util) AfterEach(org.junit.jupiter.api.AfterEach) java.io(java.io) SendEmailMessage(com.thoughtworks.go.server.messaging.SendEmailMessage) ContextConfiguration(org.springframework.test.context.ContextConfiguration) BackupUpdateListener(com.thoughtworks.go.server.service.backup.BackupUpdateListener) Database(com.thoughtworks.go.server.database.Database) Semaphore(java.util.concurrent.Semaphore) Test(org.junit.jupiter.api.Test)

Example 4 with ConfigRepository

use of com.thoughtworks.go.service.ConfigRepository in project gocd by gocd.

the class ConfigGitRepoFilter method init.

@Override
public void init(FilterConfig config) throws ServletException {
    ConfigRepository configRepository = ContextLoader.getCurrentWebApplicationContext().getBean(ConfigRepository.class);
    FileResolver<HttpServletRequest> resolver = new FileResolver<>();
    resolver.exportRepository("api/config-repository.git", configRepository.getGitRepo());
    setRepositoryResolver(resolver);
    setReceivePackFactory(null);
    super.init(config);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ConfigRepository(com.thoughtworks.go.service.ConfigRepository) FileResolver(org.eclipse.jgit.transport.resolver.FileResolver)

Example 5 with ConfigRepository

use of com.thoughtworks.go.service.ConfigRepository in project gocd by gocd.

the class GoConfigFileHelper method createTestingDao.

/**
 * Creates config dao that accesses single file
 */
public static GoConfigDao createTestingDao() {
    SystemEnvironment systemEnvironment = new SystemEnvironment();
    try {
        MaintenanceModeService maintenanceModeService = new MaintenanceModeService(new TimeProvider(), systemEnvironment);
        ServerHealthService serverHealthService = new ServerHealthService();
        ConfigRepository configRepository = new ConfigRepository(systemEnvironment);
        configRepository.initialize();
        ConfigCache configCache = new ConfigCache();
        ConfigElementImplementationRegistry configElementImplementationRegistry = ConfigElementImplementationRegistryMother.withNoPlugins();
        CachedGoPartials cachedGoPartials = new CachedGoPartials(serverHealthService);
        FullConfigSaveNormalFlow normalFlow = new FullConfigSaveNormalFlow(configCache, configElementImplementationRegistry, systemEnvironment, new TimeProvider(), configRepository, cachedGoPartials);
        GoFileConfigDataSource dataSource = new GoFileConfigDataSource(new DoNotUpgrade(), configRepository, systemEnvironment, new TimeProvider(), configCache, configElementImplementationRegistry, cachedGoPartials, null, normalFlow, mock(PartialConfigHelper.class));
        GoConfigMigration goConfigMigration = new GoConfigMigration(new TimeProvider(), configElementImplementationRegistry);
        GoConfigMigrator goConfigMigrator = new GoConfigMigrator(goConfigMigration, new SystemEnvironment(), configCache, configElementImplementationRegistry, normalFlow, configRepository, serverHealthService);
        FileUtils.writeStringToFile(dataSource.fileLocation(), ConfigFileFixture.configWithSecurity(""), UTF_8);
        goConfigMigrator.migrate();
        CachedGoConfig cachedConfigService = new CachedGoConfig(serverHealthService, dataSource, cachedGoPartials, null, maintenanceModeService);
        cachedConfigService.loadConfigIfNull();
        return new GoConfigDao(cachedConfigService);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
Also used : ConfigRepository(com.thoughtworks.go.service.ConfigRepository) IOException(java.io.IOException) MaintenanceModeService(com.thoughtworks.go.server.service.MaintenanceModeService) ConfigElementImplementationRegistry(com.thoughtworks.go.config.registry.ConfigElementImplementationRegistry) ServerHealthService(com.thoughtworks.go.serverhealth.ServerHealthService)

Aggregations

ConfigRepository (com.thoughtworks.go.service.ConfigRepository)14 File (java.io.File)5 BeforeEach (org.junit.jupiter.api.BeforeEach)5 ConfigElementImplementationRegistry (com.thoughtworks.go.config.registry.ConfigElementImplementationRegistry)4 IOException (java.io.IOException)4 ServerHealthService (com.thoughtworks.go.serverhealth.ServerHealthService)3 SystemEnvironment (com.thoughtworks.go.util.SystemEnvironment)3 FullConfigUpdateCommand (com.thoughtworks.go.config.update.FullConfigUpdateCommand)2 ServerVersion (com.thoughtworks.go.server.util.ServerVersion)2 GoConfigFileHelper (com.thoughtworks.go.util.GoConfigFileHelper)2 TimeProvider (com.thoughtworks.go.util.TimeProvider)2 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)2 Document (org.jdom2.Document)2 Before (org.junit.Before)2 Test (org.junit.jupiter.api.Test)2 CurrentGoCDVersion (com.thoughtworks.go.CurrentGoCDVersion)1 com.thoughtworks.go.config (com.thoughtworks.go.config)1 ConfigFileHasChangedException (com.thoughtworks.go.config.exceptions.ConfigFileHasChangedException)1 ConfigMergeException (com.thoughtworks.go.config.exceptions.ConfigMergeException)1 GoConfigInvalidException (com.thoughtworks.go.config.exceptions.GoConfigInvalidException)1