use of com.thoughtworks.go.config.CruiseConfig in project gocd by gocd.
the class MaterialUpdateService method notifyMaterialsForUpdate.
public void notifyMaterialsForUpdate(Username username, Object params, HttpLocalizedOperationResult result) {
if (!goConfigService.isUserAdmin(username)) {
result.unauthorized(LocalizedMessage.string("API_ACCESS_UNAUTHORIZED"), HealthStateType.unauthorised());
return;
}
final Map attributes = (Map) params;
if (attributes.containsKey(MaterialUpdateService.TYPE)) {
PostCommitHookMaterialType materialType = postCommitHookMaterialType.toType((String) attributes.get(MaterialUpdateService.TYPE));
if (!materialType.isKnown()) {
result.badRequest(LocalizedMessage.string("API_BAD_REQUEST"));
return;
}
final PostCommitHookImplementer materialTypeImplementer = materialType.getImplementer();
final CruiseConfig cruiseConfig = goConfigService.currentCruiseConfig();
Set<Material> allUniquePostCommitSchedulableMaterials = materialConfigConverter.toMaterials(cruiseConfig.getAllUniquePostCommitSchedulableMaterials());
final Set<Material> prunedMaterialList = materialTypeImplementer.prune(allUniquePostCommitSchedulableMaterials, attributes);
if (prunedMaterialList.isEmpty()) {
result.notFound(LocalizedMessage.string("MATERIAL_SUITABLE_FOR_NOTIFICATION_NOT_FOUND"), HealthStateType.general(HealthStateScope.GLOBAL));
return;
}
for (Material material : prunedMaterialList) {
updateMaterial(material);
}
result.accepted(LocalizedMessage.string("MATERIAL_SCHEDULE_NOTIFICATION_ACCEPTED"));
} else {
result.badRequest(LocalizedMessage.string("API_BAD_REQUEST"));
}
}
use of com.thoughtworks.go.config.CruiseConfig in project gocd by gocd.
the class EmailNotificationListener method onMessage.
public void onMessage(SendEmailMessage message) {
CruiseConfig cruiseConfig = goConfigService.currentCruiseConfig();
if (!cruiseConfig.isMailHostConfigured()) {
return;
}
GoMailSender mailSender = factory.createSender();
ValidationBean validationBean = mailSender.send(message.getSubject(), message.getBody(), message.getTo());
if (!validationBean.isValid()) {
LOGGER.error(validationBean.getError());
}
}
use of com.thoughtworks.go.config.CruiseConfig in project gocd by gocd.
the class MaterialsTest method shouldFailIfMultipleMaterialsHaveSameFolderNameSet_CaseInSensitive.
@Test
@RunIf(value = EnhancedOSChecker.class, arguments = { DO_NOT_RUN_ON, WINDOWS })
public void shouldFailIfMultipleMaterialsHaveSameFolderNameSet_CaseInSensitive() {
HgMaterialConfig materialOne = new HgMaterialConfig("http://url1", null);
materialOne.setConfigAttributes(Collections.singletonMap(ScmMaterialConfig.FOLDER, "folder"));
HgMaterialConfig materialTwo = new HgMaterialConfig("http://url2", null);
materialTwo.setConfigAttributes(Collections.singletonMap(ScmMaterialConfig.FOLDER, "foLder"));
CruiseConfig config = GoConfigMother.configWithPipelines("one");
PipelineConfig pipelineOne = config.pipelineConfigByName(new CaseInsensitiveString("one"));
pipelineOne.setMaterialConfigs(new MaterialConfigs(materialOne, materialTwo));
MaterialConfigs materials = pipelineOne.materialConfigs();
materials.validate(ConfigSaveValidationContext.forChain(config));
assertThat(materials.get(0).errors().isEmpty(), is(false));
assertThat(materials.get(1).errors().isEmpty(), is(false));
assertThat(materials.get(0).errors().on(ScmMaterialConfig.FOLDER), is("The destination directory must be unique across materials."));
assertThat(materials.get(1).errors().on(ScmMaterialConfig.FOLDER), is("The destination directory must be unique across materials."));
}
use of com.thoughtworks.go.config.CruiseConfig in project gocd by gocd.
the class UpdateAgentStatusTest method shouldUpdateAgentIPAddressWhenItChanges_asAgent.
@Test
public void shouldUpdateAgentIPAddressWhenItChanges_asAgent() throws Exception {
CruiseConfig oldConfig = goConfigDao.load();
String oldIp = oldConfig.agents().getAgentByUuid("uuid").getIpAddress();
assertThat(oldIp, is("10.81.2.1"));
AgentIdentifier agentIdentifier1 = new AgentIdentifier("localhost", "10.18.3.95", "uuid");
AgentRuntimeInfo agentRuntimeInfo1 = new AgentRuntimeInfo(agentIdentifier1, AgentRuntimeStatus.Idle, currentWorkingDirectory(), "cookie", false);
agentRuntimeInfo1.busy(new AgentBuildingInfo("building", "buildLocator"));
agentService.updateRuntimeInfo(agentRuntimeInfo1);
CruiseConfig newConfig = goConfigDao.load();
String newIp = newConfig.agents().getAgentByUuid("uuid").getIpAddress();
assertThat(newIp, is("10.18.3.95"));
GoConfigRevision rev = configRepo.getRevision(newConfig.getMd5());
assertThat(rev.getUsername(), is("agent_uuid_10.18.3.95_CCEDev01"));
}
use of com.thoughtworks.go.config.CruiseConfig in project gocd by gocd.
the class PipelinePauseServiceIntegrationTest method shouldUnpauseAPausedPipeline.
@Test
public void shouldUnpauseAPausedPipeline() throws Exception {
String name = "pipeline-name";
CruiseConfig cruiseConfig = GoConfigMother.configWithPipelines(name);
configHelper.writeConfigFile(cruiseConfig);
cachedGoConfig.forceReload();
Username userName = new Username(new CaseInsensitiveString("UserFoo"));
pipelinePauseService.pause(name, "pause for testing", userName);
assertThat(pipelinePauseService.pipelinePauseInfo(name).getPauseCause(), is("pause for testing"));
assertThat(pipelinePauseService.pipelinePauseInfo(name).isPaused(), is(true));
pipelinePauseService.unpause(name);
assertThat(pipelinePauseService.pipelinePauseInfo(name).isPaused(), is(false));
}
Aggregations