Search in sources :

Example 66 with SystemEnvironment

use of com.thoughtworks.go.util.SystemEnvironment in project gocd by gocd.

the class BuildCauseProducerServiceIntegrationTest method setup.

@Before
public void setup() throws Exception {
    diskSpaceSimulator = new DiskSpaceSimulator();
    new HgTestRepo("testHgRepo", temporaryFolder);
    svnRepository = new SvnTestRepo(temporaryFolder);
    dbHelper.onSetUp();
    configHelper.onSetUp();
    configHelper.usingCruiseConfigDao(goConfigDao).initializeConfigFile();
    repository = new SvnCommand(null, svnRepository.projectRepositoryUrl());
    PipelineConfig goParentPipelineConfig = configHelper.addPipeline(GO_PIPELINE_UPSTREAM, STAGE_NAME, new MaterialConfigs(new GitMaterialConfig("foo-bar")), "unit");
    goPipelineConfig = configHelper.addPipeline(GO_PIPELINE_NAME, STAGE_NAME, repository, "unit");
    svnMaterialRevs = new MaterialRevisions();
    svnMaterial = SvnMaterial.createSvnMaterialWithMock(repository);
    svnMaterialRevs.addRevision(svnMaterial, svnMaterial.latestModification(null, new ServerSubprocessExecutionContext(goConfigService, new SystemEnvironment())));
    final MaterialRevisions materialRevisions = new MaterialRevisions();
    SvnMaterial anotherSvnMaterial = SvnMaterial.createSvnMaterialWithMock(repository);
    materialRevisions.addRevision(anotherSvnMaterial, anotherSvnMaterial.latestModification(null, subprocessExecutionContext));
    transactionTemplate.execute(new TransactionCallbackWithoutResult() {

        @Override
        protected void doInTransactionWithoutResult(TransactionStatus status) {
            materialRepository.save(svnMaterialRevs);
        }
    });
    BuildCause buildCause = BuildCause.createWithModifications(svnMaterialRevs, "");
    mingleConfig = configHelper.addPipeline(MINGLE_PIPELINE_NAME, STAGE_NAME, repository, new Filter(new IgnoredFiles("**/*.doc")), "unit", "functional");
    latestPipeline = PipelineMother.schedule(this.mingleConfig, buildCause);
    latestPipeline = pipelineDao.saveWithStages(latestPipeline);
    dbHelper.passStage(latestPipeline.getStages().first());
    pipelineScheduleQueue.clear();
    result = new HttpOperationResult();
    scheduleOptions = new ScheduleOptions();
    u = new ScheduleTestUtil(transactionTemplate, materialRepository, dbHelper, configHelper);
    materialForManualTriggerPipeline = u.wf(new SvnMaterial("svn", "username", "password", false), "folder1");
    u.checkinInOrder(materialForManualTriggerPipeline, u.d(1), "s1");
    manualTriggerPipeline = configHelper.addPipeline(UUID.randomUUID().toString(), STAGE_NAME, materialForManualTriggerPipeline.config(), "build");
    username = Username.ANONYMOUS;
}
Also used : MaterialConfigs(com.thoughtworks.go.config.materials.MaterialConfigs) HttpOperationResult(com.thoughtworks.go.server.service.result.HttpOperationResult) PipelineConfig(com.thoughtworks.go.config.PipelineConfig) MaterialRevisions(com.thoughtworks.go.domain.MaterialRevisions) SvnMaterial(com.thoughtworks.go.config.materials.svn.SvnMaterial) TransactionStatus(org.springframework.transaction.TransactionStatus) BuildCause(com.thoughtworks.go.domain.buildcause.BuildCause) SystemEnvironment(com.thoughtworks.go.util.SystemEnvironment) ScheduleOptions(com.thoughtworks.go.server.scheduling.ScheduleOptions) GitMaterialConfig(com.thoughtworks.go.config.materials.git.GitMaterialConfig) Filter(com.thoughtworks.go.config.materials.Filter) IgnoredFiles(com.thoughtworks.go.config.materials.IgnoredFiles) SvnCommand(com.thoughtworks.go.domain.materials.svn.SvnCommand) TransactionCallbackWithoutResult(org.springframework.transaction.support.TransactionCallbackWithoutResult) Before(org.junit.Before)

Example 67 with SystemEnvironment

use of com.thoughtworks.go.util.SystemEnvironment in project gocd by gocd.

the class AgentConfigServiceIntegrationTest method shouldEnableMultipleAgents.

@Test
public void shouldEnableMultipleAgents() {
    AgentConfig agentConfig1 = new AgentConfig(UUID.randomUUID().toString(), "remote-host1", "50.40.30.21");
    AgentConfig agentConfig2 = new AgentConfig(UUID.randomUUID().toString(), "remote-host2", "50.40.30.22");
    agentConfig1.disable();
    agentConfig2.disable();
    AgentInstance fromConfigFile1 = AgentInstance.createFromConfig(agentConfig1, new SystemEnvironment(), getAgentStatusChangeListener());
    AgentInstance fromConfigFile2 = AgentInstance.createFromConfig(agentConfig2, new SystemEnvironment(), getAgentStatusChangeListener());
    agentConfigService.addAgent(agentConfig1, Username.ANONYMOUS);
    agentConfigService.addAgent(agentConfig2, Username.ANONYMOUS);
    CruiseConfig cruiseConfig = goConfigDao.load();
    assertThat(cruiseConfig.agents().getAgentByUuid(agentConfig1.getUuid()).isDisabled(), is(true));
    assertThat(cruiseConfig.agents().getAgentByUuid(agentConfig1.getUuid()).isDisabled(), is(true));
    agentConfigService.enableAgents(Username.ANONYMOUS, fromConfigFile1, fromConfigFile2);
    cruiseConfig = goConfigDao.load();
    assertThat(cruiseConfig.agents().getAgentByUuid(agentConfig1.getUuid()).isDisabled(), is(false));
    assertThat(cruiseConfig.agents().getAgentByUuid(agentConfig2.getUuid()).isDisabled(), is(false));
}
Also used : AgentInstance(com.thoughtworks.go.domain.AgentInstance) SystemEnvironment(com.thoughtworks.go.util.SystemEnvironment) Test(org.junit.Test)

Example 68 with SystemEnvironment

use of com.thoughtworks.go.util.SystemEnvironment in project gocd by gocd.

the class AgentConfigServiceIntegrationTest method shouldAddResourcestoTheSpecifiedAgents.

@Test
public void shouldAddResourcestoTheSpecifiedAgents() throws Exception {
    AgentConfig agentConfig1 = new AgentConfig(UUID.randomUUID().toString(), "remote-host1", "50.40.30.21");
    AgentConfig agentConfig2 = new AgentConfig(UUID.randomUUID().toString(), "remote-host2", "50.40.30.22");
    AgentInstance agentInstance1 = AgentInstance.createFromConfig(agentConfig1, new SystemEnvironment(), getAgentStatusChangeListener());
    AgentInstance agentInstance2 = AgentInstance.createFromConfig(agentConfig2, new SystemEnvironment(), getAgentStatusChangeListener());
    agentInstances.add(agentInstance1);
    agentInstances.add(agentInstance2);
    agentConfigService.addAgent(agentConfig1, Username.ANONYMOUS);
    agentConfigService.addAgent(agentConfig2, Username.ANONYMOUS);
    CruiseConfig cruiseConfig = goConfigDao.load();
    assertThat(cruiseConfig.agents().getAgentByUuid(agentConfig1.getUuid()).getResourceConfigs().size(), is(0));
    assertThat(cruiseConfig.agents().getAgentByUuid(agentConfig2.getUuid()).getResourceConfigs().size(), is(0));
    HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
    ArrayList<String> uuids = new ArrayList<>();
    uuids.add(agentConfig1.getUuid());
    uuids.add(agentConfig2.getUuid());
    ArrayList<String> resources = new ArrayList<>();
    resources.add("resource1");
    resources.add("resource2");
    agentConfigService.bulkUpdateAgentAttributes(agentInstances, Username.ANONYMOUS, result, uuids, resources, new ArrayList<>(), new ArrayList<>(), new ArrayList<>(), TriState.FALSE);
    cruiseConfig = goConfigDao.load();
    assertTrue(result.isSuccessful());
    assertThat(result.toString(), containsString("BULK_AGENT_UPDATE_SUCESSFUL"));
    assertThat(cruiseConfig.agents().getAgentByUuid(agentConfig1.getUuid()).getResourceConfigs().size(), is(2));
    assertThat(cruiseConfig.agents().getAgentByUuid(agentConfig1.getUuid()).getResourceConfigs(), containsInAnyOrder(new ResourceConfig("resource1"), new ResourceConfig("resource2")));
}
Also used : AgentInstance(com.thoughtworks.go.domain.AgentInstance) SystemEnvironment(com.thoughtworks.go.util.SystemEnvironment) HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 69 with SystemEnvironment

use of com.thoughtworks.go.util.SystemEnvironment in project gocd by gocd.

the class AgentConfigServiceIntegrationTest method shouldAddProvidedAgentsToTheSpecifiedEnvironments.

@Test
public void shouldAddProvidedAgentsToTheSpecifiedEnvironments() throws Exception {
    AgentConfig agentConfig1 = new AgentConfig(UUID.randomUUID().toString(), "remote-host1", "50.40.30.21");
    AgentConfig agentConfig2 = new AgentConfig(UUID.randomUUID().toString(), "remote-host2", "50.40.30.22");
    AgentInstance agentInstance1 = AgentInstance.createFromConfig(agentConfig1, new SystemEnvironment(), getAgentStatusChangeListener());
    AgentInstance agentInstance2 = AgentInstance.createFromConfig(agentConfig2, new SystemEnvironment(), getAgentStatusChangeListener());
    agentInstances.add(agentInstance1);
    agentInstances.add(agentInstance2);
    agentConfigService.addAgent(agentConfig1, Username.ANONYMOUS);
    agentConfigService.addAgent(agentConfig2, Username.ANONYMOUS);
    BasicEnvironmentConfig environment = new BasicEnvironmentConfig(new CaseInsensitiveString("Dev"));
    goConfigDao.addEnvironment(environment);
    assertFalse(environment.hasAgent(agentConfig1.getUuid()));
    assertFalse(environment.hasAgent(agentConfig2.getUuid()));
    HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
    ArrayList<String> uuids = new ArrayList<>();
    uuids.add(agentConfig1.getUuid());
    uuids.add(agentConfig2.getUuid());
    ArrayList<String> environmentsToAdd = new ArrayList<>();
    environmentsToAdd.add("Dev");
    agentConfigService.bulkUpdateAgentAttributes(agentInstances, Username.ANONYMOUS, result, uuids, new ArrayList<>(), new ArrayList<>(), environmentsToAdd, new ArrayList<>(), TriState.TRUE);
    assertTrue(result.isSuccessful());
    assertThat(result.toString(), containsString("BULK_AGENT_UPDATE_SUCESSFUL"));
    assertThat(goConfigDao.load().getEnvironments().find(new CaseInsensitiveString("Dev")).getAgents().getUuids(), containsInAnyOrder(agentConfig1.getUuid(), agentConfig2.getUuid()));
}
Also used : AgentInstance(com.thoughtworks.go.domain.AgentInstance) SystemEnvironment(com.thoughtworks.go.util.SystemEnvironment) HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 70 with SystemEnvironment

use of com.thoughtworks.go.util.SystemEnvironment in project gocd by gocd.

the class AgentConfigServiceIntegrationTest method shouldDisableTheProvidedAgents.

@Test
public void shouldDisableTheProvidedAgents() throws Exception {
    AgentConfig agentConfig1 = new AgentConfig(UUID.randomUUID().toString(), "remote-host1", "50.40.30.21");
    AgentConfig agentConfig2 = new AgentConfig(UUID.randomUUID().toString(), "remote-host2", "50.40.30.22");
    AgentInstance agentInstance1 = AgentInstance.createFromConfig(agentConfig1, new SystemEnvironment(), getAgentStatusChangeListener());
    AgentInstance agentInstance2 = AgentInstance.createFromConfig(agentConfig2, new SystemEnvironment(), getAgentStatusChangeListener());
    agentInstances.add(agentInstance1);
    agentInstances.add(agentInstance2);
    agentConfigService.addAgent(agentConfig1, Username.ANONYMOUS);
    agentConfigService.addAgent(agentConfig2, Username.ANONYMOUS);
    CruiseConfig cruiseConfig = goConfigDao.load();
    assertThat(cruiseConfig.agents().getAgentByUuid(agentConfig1.getUuid()).isDisabled(), is(false));
    assertThat(cruiseConfig.agents().getAgentByUuid(agentConfig2.getUuid()).isDisabled(), is(false));
    HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
    ArrayList<String> uuids = new ArrayList<>();
    uuids.add(agentConfig1.getUuid());
    uuids.add(agentConfig2.getUuid());
    agentConfigService.bulkUpdateAgentAttributes(agentInstances, Username.ANONYMOUS, result, uuids, new ArrayList<>(), new ArrayList<>(), new ArrayList<>(), new ArrayList<>(), TriState.FALSE);
    cruiseConfig = goConfigDao.load();
    assertTrue(result.isSuccessful());
    assertTrue(result.toString(), result.toString().contains("BULK_AGENT_UPDATE_SUCESSFUL"));
    assertTrue(cruiseConfig.agents().getAgentByUuid(agentConfig1.getUuid()).isDisabled());
    assertTrue(cruiseConfig.agents().getAgentByUuid(agentConfig2.getUuid()).isDisabled());
}
Also used : AgentInstance(com.thoughtworks.go.domain.AgentInstance) SystemEnvironment(com.thoughtworks.go.util.SystemEnvironment) HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Aggregations

SystemEnvironment (com.thoughtworks.go.util.SystemEnvironment)174 Test (org.junit.Test)93 Before (org.junit.Before)38 File (java.io.File)37 AgentInstance (com.thoughtworks.go.domain.AgentInstance)27 MaterialRevisions (com.thoughtworks.go.domain.MaterialRevisions)15 HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)14 ArrayList (java.util.ArrayList)14 AgentRuntimeInfo (com.thoughtworks.go.server.service.AgentRuntimeInfo)11 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)10 BuildCause (com.thoughtworks.go.domain.buildcause.BuildCause)10 AgentStatusChangeListener (com.thoughtworks.go.listener.AgentStatusChangeListener)10 AgentIdentifier (com.thoughtworks.go.remote.AgentIdentifier)9 AgentConfig (com.thoughtworks.go.config.AgentConfig)8 MaterialRevision (com.thoughtworks.go.domain.MaterialRevision)8 PipelineConfigDependencyGraph (com.thoughtworks.go.server.domain.PipelineConfigDependencyGraph)8 SvnMaterial (com.thoughtworks.go.config.materials.svn.SvnMaterial)7 EnvironmentVariableContext (com.thoughtworks.go.util.command.EnvironmentVariableContext)7 Date (java.util.Date)7 CruiseConfig (com.thoughtworks.go.config.CruiseConfig)6