Search in sources :

Example 66 with CruiseConfig

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"));
    }
}
Also used : Material(com.thoughtworks.go.domain.materials.Material) DependencyMaterial(com.thoughtworks.go.config.materials.dependency.DependencyMaterial) GitMaterial(com.thoughtworks.go.config.materials.git.GitMaterial) ConcurrentMap(java.util.concurrent.ConcurrentMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) PostCommitHookImplementer(com.thoughtworks.go.server.materials.postcommit.PostCommitHookImplementer) PostCommitHookMaterialType(com.thoughtworks.go.server.materials.postcommit.PostCommitHookMaterialType) CruiseConfig(com.thoughtworks.go.config.CruiseConfig)

Example 67 with CruiseConfig

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());
    }
}
Also used : GoMailSender(com.thoughtworks.go.config.GoMailSender) ValidationBean(com.thoughtworks.go.domain.materials.ValidationBean) CruiseConfig(com.thoughtworks.go.config.CruiseConfig)

Example 68 with CruiseConfig

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."));
}
Also used : PipelineConfig(com.thoughtworks.go.config.PipelineConfig) HgMaterialConfig(com.thoughtworks.go.config.materials.mercurial.HgMaterialConfig) CruiseConfig(com.thoughtworks.go.config.CruiseConfig) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) RunIf(com.googlecode.junit.ext.RunIf) Test(org.junit.Test)

Example 69 with CruiseConfig

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"));
}
Also used : AgentIdentifier(com.thoughtworks.go.remote.AgentIdentifier) StringContains.containsString(org.hamcrest.core.StringContains.containsString) GoConfigRevision(com.thoughtworks.go.domain.GoConfigRevision) CruiseConfig(com.thoughtworks.go.config.CruiseConfig) Test(org.junit.Test)

Example 70 with CruiseConfig

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));
}
Also used : Username(com.thoughtworks.go.server.domain.Username) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) CruiseConfig(com.thoughtworks.go.config.CruiseConfig) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) Test(org.junit.Test)

Aggregations

CruiseConfig (com.thoughtworks.go.config.CruiseConfig)95 Test (org.junit.Test)77 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)54 GitMaterial (com.thoughtworks.go.config.materials.git.GitMaterial)35 MaterialRevisions (com.thoughtworks.go.domain.MaterialRevisions)33 BasicCruiseConfig (com.thoughtworks.go.config.BasicCruiseConfig)32 ServerConfig (com.thoughtworks.go.config.ServerConfig)11 PipelineConfig (com.thoughtworks.go.config.PipelineConfig)7 ServerHealthStateOperationResult (com.thoughtworks.go.server.service.result.ServerHealthStateOperationResult)5 SystemEnvironment (com.thoughtworks.go.util.SystemEnvironment)5 MaterialConfigs (com.thoughtworks.go.config.materials.MaterialConfigs)4 DependencyMaterial (com.thoughtworks.go.config.materials.dependency.DependencyMaterial)4 SvnMaterial (com.thoughtworks.go.config.materials.svn.SvnMaterial)4 ServerSiteUrlConfig (com.thoughtworks.go.domain.ServerSiteUrlConfig)4 File (java.io.File)4 ConfigCache (com.thoughtworks.go.config.ConfigCache)3 GoConfigDao (com.thoughtworks.go.config.GoConfigDao)3 MagicalGoConfigXmlLoader (com.thoughtworks.go.config.MagicalGoConfigXmlLoader)3 SecurityConfig (com.thoughtworks.go.config.SecurityConfig)3 HgMaterialConfig (com.thoughtworks.go.config.materials.mercurial.HgMaterialConfig)3