Search in sources :

Example 61 with ConfigRepoConfig

use of com.thoughtworks.go.config.remote.ConfigRepoConfig in project gocd by gocd.

the class ConfigMaterialUpdaterIntegrationTest method setup.

@Before
public void setup() throws Exception {
    diskSpaceSimulator = new DiskSpaceSimulator();
    hgRepo = new HgTestRepo("testHgRepo", temporaryFolder);
    dbHelper.onSetUp();
    configHelper.onSetUp();
    configHelper.usingCruiseConfigDao(goConfigDao).initializeConfigFile();
    materialConfig = new HgMaterialConfig(hgRepo.projectRepositoryUrl(), null);
    configHelper.addConfigRepo(new ConfigRepoConfig(materialConfig, "gocd-xml"));
    logger = mock(MDUPerformanceLogger.class);
    TestingEmailSender emailSender = new TestingEmailSender();
    SystemDiskSpaceChecker mockDiskSpaceChecker = Mockito.mock(SystemDiskSpaceChecker.class);
    StageService stageService = mock(StageService.class);
    ConfigDbStateRepository configDbStateRepository = mock(ConfigDbStateRepository.class);
    GoDiskSpaceMonitor goDiskSpaceMonitor = new GoDiskSpaceMonitor(goConfigService, systemEnvironment, serverHealthService, emailSender, mockDiskSpaceChecker, mock(ArtifactsService.class), stageService, configDbStateRepository);
    goDiskSpaceMonitor.initialize();
    worker = new MaterialUpdateListener(configTopic, materialDatabaseUpdater, logger, goDiskSpaceMonitor);
    xmlWriter = new MagicalGoConfigXmlWriter(configCache, ConfigElementImplementationRegistryMother.withNoPlugins());
    configTestRepo = new ConfigTestRepo(hgRepo, xmlWriter);
    this.material = configTestRepo.getMaterial();
}
Also used : MDUPerformanceLogger(com.thoughtworks.go.server.perf.MDUPerformanceLogger) ConfigRepoConfig(com.thoughtworks.go.config.remote.ConfigRepoConfig) HgMaterialConfig(com.thoughtworks.go.config.materials.mercurial.HgMaterialConfig) GoDiskSpaceMonitor(com.thoughtworks.go.server.cronjob.GoDiskSpaceMonitor) HgTestRepo(com.thoughtworks.go.helper.HgTestRepo) ConfigTestRepo(com.thoughtworks.go.helper.ConfigTestRepo)

Example 62 with ConfigRepoConfig

use of com.thoughtworks.go.config.remote.ConfigRepoConfig in project gocd by gocd.

the class PipelineConfigServiceIntegrationTest method setup.

@Before
public void setup() throws Exception {
    cachedGoPartials.clear();
    configHelper = new GoConfigFileHelper();
    dbHelper.onSetUp();
    configHelper.usingCruiseConfigDao(goConfigDao).initializeConfigFile();
    configHelper.onSetUp();
    goConfigService.forceNotifyListeners();
    user = new Username(new CaseInsensitiveString("current"));
    pipelineConfig = GoConfigMother.createPipelineConfigWithMaterialConfig(UUID.randomUUID().toString(), new GitMaterialConfig("FOO"));
    goConfigService.addPipeline(pipelineConfig, groupName);
    repoConfig1 = new ConfigRepoConfig(MaterialConfigsMother.gitMaterialConfig("url"), XmlPartialConfigProvider.providerName);
    repoConfig2 = new ConfigRepoConfig(MaterialConfigsMother.gitMaterialConfig("url2"), XmlPartialConfigProvider.providerName);
    goConfigService.updateConfig(new UpdateConfigCommand() {

        @Override
        public CruiseConfig update(CruiseConfig cruiseConfig) throws Exception {
            cruiseConfig.getConfigRepos().add(repoConfig1);
            cruiseConfig.getConfigRepos().add(repoConfig2);
            return cruiseConfig;
        }
    });
    GoCipher goCipher = new GoCipher();
    goConfigService.updateServerConfig(new MailHost(goCipher), false, goConfigService.configFileMd5(), "artifacts", null, null, "0", null, null, "foo");
    UpdateConfigCommand command = goConfigService.modifyAdminPrivilegesCommand(asList(user.getUsername().toString()), new TriStateSelection(Admin.GO_SYSTEM_ADMIN, TriStateSelection.Action.add));
    goConfigService.updateConfig(command);
    remoteDownstreamPipelineName = "remote-downstream";
    partialConfig = PartialConfigMother.pipelineWithDependencyMaterial(remoteDownstreamPipelineName, pipelineConfig, new RepoConfigOrigin(repoConfig1, "repo1_r1"));
    goPartialConfig.onSuccessPartialConfig(repoConfig1, partialConfig);
    PartialConfig partialConfigFromRepo2 = PartialConfigMother.withPipeline("independent-pipeline", new RepoConfigOrigin(repoConfig2, "repo2_r1"));
    goPartialConfig.onSuccessPartialConfig(repoConfig2, partialConfigFromRepo2);
    result = new HttpLocalizedOperationResult();
    headCommitBeforeUpdate = configRepository.getCurrentRevCommit().name();
    goConfigService.security().securityAuthConfigs().add(new SecurityAuthConfig("file", "cd.go.authentication.passwordfile"));
}
Also used : GoCipher(com.thoughtworks.go.security.GoCipher) ConfigRepoConfig(com.thoughtworks.go.config.remote.ConfigRepoConfig) TriStateSelection(com.thoughtworks.go.presentation.TriStateSelection) PartialConfig(com.thoughtworks.go.config.remote.PartialConfig) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) ExpectedException(org.junit.rules.ExpectedException) HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) Username(com.thoughtworks.go.server.domain.Username) GitMaterialConfig(com.thoughtworks.go.config.materials.git.GitMaterialConfig) RepoConfigOrigin(com.thoughtworks.go.config.remote.RepoConfigOrigin) GoConfigFileHelper(com.thoughtworks.go.util.GoConfigFileHelper) Before(org.junit.Before)

Example 63 with ConfigRepoConfig

use of com.thoughtworks.go.config.remote.ConfigRepoConfig in project gocd by gocd.

the class GoFileConfigDataSourceIntegrationTest method setUp.

@Before
public void setUp() throws Exception {
    File configDir = temporaryFolder.newFolder();
    String absolutePath = new File(configDir, "cruise-config.xml").getAbsolutePath();
    systemEnvironment.setProperty(SystemEnvironment.CONFIG_FILE_PROPERTY, absolutePath);
    configHelper = new GoConfigFileHelper(DEFAULT_XML_WITH_2_AGENTS);
    configHelper.usingCruiseConfigDao(goConfigDao).initializeConfigFile();
    configHelper.onSetUp();
    configHelper.addConfigRepo(new ConfigRepoConfig(MaterialConfigsMother.gitMaterialConfig("url"), XmlPartialConfigProvider.providerName));
    configHelper.addPipeline("upstream", "upstream_stage_original");
    goConfigService.forceNotifyListeners();
    cachedGoPartials.clear();
    configRepo = configWatchList.getCurrentConfigRepos().get(0);
    upstreamPipeline = goConfigService.pipelineConfigNamed(new CaseInsensitiveString("upstream"));
    partialConfig = PartialConfigMother.pipelineWithDependencyMaterial(remoteDownstream, upstreamPipeline, new RepoConfigOrigin(configRepo, "r1"));
    goPartialConfig.onSuccessPartialConfig(configRepo, partialConfig);
}
Also used : ConfigRepoConfig(com.thoughtworks.go.config.remote.ConfigRepoConfig) RepoConfigOrigin(com.thoughtworks.go.config.remote.RepoConfigOrigin) File(java.io.File) Before(org.junit.Before)

Example 64 with ConfigRepoConfig

use of com.thoughtworks.go.config.remote.ConfigRepoConfig in project gocd by gocd.

the class CachedGoConfigIntegrationTest method shouldRemoveCorrespondingRemotePipelinesFromCachedGoConfigIfTheConfigRepoIsDeleted.

@Test
public void shouldRemoveCorrespondingRemotePipelinesFromCachedGoConfigIfTheConfigRepoIsDeleted() {
    final ConfigRepoConfig repoConfig1 = new ConfigRepoConfig(MaterialConfigsMother.gitMaterialConfig("url1"), XmlPartialConfigProvider.providerName);
    final ConfigRepoConfig repoConfig2 = new ConfigRepoConfig(MaterialConfigsMother.gitMaterialConfig("url2"), XmlPartialConfigProvider.providerName);
    goConfigService.updateConfig(new UpdateConfigCommand() {

        @Override
        public CruiseConfig update(CruiseConfig cruiseConfig) throws Exception {
            cruiseConfig.getConfigRepos().add(repoConfig1);
            cruiseConfig.getConfigRepos().add(repoConfig2);
            return cruiseConfig;
        }
    });
    PartialConfig partialConfigInRepo1 = PartialConfigMother.withPipeline("pipeline_in_repo1", new RepoConfigOrigin(repoConfig1, "repo1_r1"));
    PartialConfig partialConfigInRepo2 = PartialConfigMother.withPipeline("pipeline_in_repo2", new RepoConfigOrigin(repoConfig2, "repo2_r1"));
    goPartialConfig.onSuccessPartialConfig(repoConfig1, partialConfigInRepo1);
    goPartialConfig.onSuccessPartialConfig(repoConfig2, partialConfigInRepo2);
    // introduce an invalid change in repo1 so that there is a server health message corresponding to it
    PartialConfig invalidPartialInRepo1Revision2 = PartialConfigMother.invalidPartial("pipeline_in_repo1", new RepoConfigOrigin(repoConfig1, "repo1_r2"));
    goPartialConfig.onSuccessPartialConfig(repoConfig1, invalidPartialInRepo1Revision2);
    assertThat(serverHealthService.filterByScope(HealthStateScope.forPartialConfigRepo(repoConfig1)).size(), is(1));
    assertThat(serverHealthService.filterByScope(HealthStateScope.forPartialConfigRepo(repoConfig1)).get(0).getMessage(), is("Invalid Merged Configuration"));
    assertThat(serverHealthService.filterByScope(HealthStateScope.forPartialConfigRepo(repoConfig1)).get(0).getDescription(), is("1+ errors :: Invalid stage name ''. This must be alphanumeric and can contain underscores and periods (however, it cannot start with a period). The maximum allowed length is 255 characters.;;  -  Config-Repo: url1 at repo1_r2"));
    assertThat(serverHealthService.filterByScope(HealthStateScope.forPartialConfigRepo(repoConfig2)).isEmpty(), is(true));
    int countBeforeDeletion = cachedGoConfig.currentConfig().getConfigRepos().size();
    ConfigSaveState configSaveState = cachedGoConfig.writeWithLock(new UpdateConfigCommand() {

        @Override
        public CruiseConfig update(CruiseConfig cruiseConfig) throws Exception {
            cruiseConfig.getConfigRepos().remove(repoConfig1);
            return cruiseConfig;
        }
    });
    assertThat(configSaveState, is(ConfigSaveState.UPDATED));
    assertThat(cachedGoConfig.currentConfig().getConfigRepos().size(), is(countBeforeDeletion - 1));
    assertThat(cachedGoConfig.currentConfig().getConfigRepos().contains(repoConfig2), is(true));
    assertThat(cachedGoConfig.currentConfig().getAllPipelineNames().contains(new CaseInsensitiveString("pipeline_in_repo1")), is(false));
    assertThat(cachedGoConfig.currentConfig().getAllPipelineNames().contains(new CaseInsensitiveString("pipeline_in_repo2")), is(true));
    assertThat(cachedGoPartials.lastKnownPartials().size(), is(1));
    assertThat(((RepoConfigOrigin) cachedGoPartials.lastKnownPartials().get(0).getOrigin()).getMaterial().getFingerprint().equals(repoConfig2.getMaterialConfig().getFingerprint()), is(true));
    assertThat(cachedGoPartials.lastKnownPartials().stream().filter(new Predicate<PartialConfig>() {

        @Override
        public boolean test(PartialConfig item) {
            return ((RepoConfigOrigin) item.getOrigin()).getMaterial().getFingerprint().equals(repoConfig1.getMaterialConfig().getFingerprint());
        }
    }).findFirst().orElse(null), is(nullValue()));
    assertThat(cachedGoPartials.lastValidPartials().size(), is(1));
    assertThat(((RepoConfigOrigin) cachedGoPartials.lastValidPartials().get(0).getOrigin()).getMaterial().getFingerprint().equals(repoConfig2.getMaterialConfig().getFingerprint()), is(true));
    assertThat(cachedGoPartials.lastValidPartials().stream().filter(new Predicate<PartialConfig>() {

        @Override
        public boolean test(PartialConfig item) {
            return ((RepoConfigOrigin) item.getOrigin()).getMaterial().getFingerprint().equals(repoConfig1.getMaterialConfig().getFingerprint());
        }
    }).findFirst().orElse(null), is(nullValue()));
    assertThat(serverHealthService.filterByScope(HealthStateScope.forPartialConfigRepo(repoConfig1)).isEmpty(), is(true));
    assertThat(serverHealthService.filterByScope(HealthStateScope.forPartialConfigRepo(repoConfig2)).isEmpty(), is(true));
}
Also used : ConfigRepoConfig(com.thoughtworks.go.config.remote.ConfigRepoConfig) PartialConfig(com.thoughtworks.go.config.remote.PartialConfig) RepoConfigOrigin(com.thoughtworks.go.config.remote.RepoConfigOrigin) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) ExpectedException(org.junit.rules.ExpectedException) IOException(java.io.IOException) Predicate(java.util.function.Predicate)

Example 65 with ConfigRepoConfig

use of com.thoughtworks.go.config.remote.ConfigRepoConfig in project gocd by gocd.

the class CachedGoConfigIntegrationTest method shouldRecoverFromDeepConfigRepoReferencesBug1901When2Repos.

@Test
public void shouldRecoverFromDeepConfigRepoReferencesBug1901When2Repos() throws Exception {
    // pipeline references are like this: pipe1 -> downstream
    File downstreamExternalConfigRepo = temporaryFolder.newFolder();
    /*here is a pipeline 'downstream' with material dependency on 'pipe1' in other repository*/
    String downstreamLatestCommit = setupExternalConfigRepo(downstreamExternalConfigRepo, "external_git_config_repo_referencing_first");
    configHelper.addConfigRepo(new ConfigRepoConfig(new GitMaterialConfig(downstreamExternalConfigRepo.getAbsolutePath()), "gocd-xml"));
    // TODO what if this is not called?
    goConfigService.forceNotifyListeners();
    ConfigRepoConfig downstreamConfigRepo = configWatchList.getCurrentConfigRepos().get(1);
    assertThat(configWatchList.getCurrentConfigRepos().size(), is(2));
    // And unluckily downstream gets parsed first
    repoConfigDataSource.onCheckoutComplete(downstreamConfigRepo.getMaterialConfig(), downstreamExternalConfigRepo, downstreamLatestCommit);
    // So parsing fails and proper message is shown:
    List<ServerHealthState> messageForInvalidMerge = serverHealthService.filterByScope(HealthStateScope.forPartialConfigRepo(downstreamConfigRepo));
    assertThat(messageForInvalidMerge.isEmpty(), is(false));
    assertThat(messageForInvalidMerge.get(0).getDescription(), containsString("tries to fetch artifact from pipeline &quot;pipe1&quot;"));
    // and current config is still old
    assertThat(goConfigService.hasPipelineNamed(new CaseInsensitiveString("downstream")), is(false));
    assertThat(cachedGoPartials.lastKnownPartials().size(), is(1));
    assertThat(cachedGoPartials.lastValidPartials().size(), is(0));
    // here downstream partial is waiting to be merged
    assertThat(cachedGoPartials.lastKnownPartials().get(0).getGroups().get(0).hasPipeline(new CaseInsensitiveString("downstream")), is(true));
    // Finally upstream config repository is parsed
    repoConfigDataSource.onCheckoutComplete(configRepo.getMaterialConfig(), externalConfigRepo, latestCommit);
    // now server should be healthy and contain all pipelines
    assertThat(serverHealthService.filterByScope(HealthStateScope.forPartialConfigRepo(configRepo)).isEmpty(), is(true));
    assertThat(serverHealthService.filterByScope(HealthStateScope.forPartialConfigRepo(downstreamConfigRepo)).isEmpty(), is(true));
    assertThat(cachedGoConfig.currentConfig().hasPipelineNamed(new CaseInsensitiveString("pipe1")), is(true));
    assertThat(cachedGoConfig.currentConfig().hasPipelineNamed(new CaseInsensitiveString("downstream")), is(true));
}
Also used : ConfigRepoConfig(com.thoughtworks.go.config.remote.ConfigRepoConfig) GitMaterialConfig(com.thoughtworks.go.config.materials.git.GitMaterialConfig) StringContains.containsString(org.hamcrest.core.StringContains.containsString) File(java.io.File)

Aggregations

ConfigRepoConfig (com.thoughtworks.go.config.remote.ConfigRepoConfig)66 Test (org.junit.Test)40 GitMaterialConfig (com.thoughtworks.go.config.materials.git.GitMaterialConfig)37 RepoConfigOrigin (com.thoughtworks.go.config.remote.RepoConfigOrigin)34 Before (org.junit.Before)13 PartialConfig (com.thoughtworks.go.config.remote.PartialConfig)11 HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)10 ConfigReposConfig (com.thoughtworks.go.config.remote.ConfigReposConfig)9 MaterialConfig (com.thoughtworks.go.domain.materials.MaterialConfig)9 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)8 DependencyMaterialConfig (com.thoughtworks.go.config.materials.dependency.DependencyMaterialConfig)6 SvnMaterialConfig (com.thoughtworks.go.config.materials.svn.SvnMaterialConfig)6 File (java.io.File)6 PipelineConfig (com.thoughtworks.go.config.PipelineConfig)5 HgMaterialConfig (com.thoughtworks.go.config.materials.mercurial.HgMaterialConfig)5 BuildCause (com.thoughtworks.go.domain.buildcause.BuildCause)5 IOException (java.io.IOException)5 AbstractMaterialConfig (com.thoughtworks.go.config.materials.AbstractMaterialConfig)4 PackageMaterialConfig (com.thoughtworks.go.config.materials.PackageMaterialConfig)4 PluggableSCMMaterialConfig (com.thoughtworks.go.config.materials.PluggableSCMMaterialConfig)4