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