Search in sources :

Example 36 with TimeProvider

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

the class BuildWork method initialize.

private void initialize(AgentWorkContext agentWorkContext) {
    JobIdentifier jobIdentifier = assignment.getJobIdentifier();
    this.timeProvider = new TimeProvider();
    agentWorkContext.getAgentRuntimeInfo().busy(new AgentBuildingInfo(jobIdentifier.buildLocatorForDisplay(), jobIdentifier.buildLocator()));
    this.workingDirectory = assignment.getWorkingDirectory();
    this.materialRevisions = assignment.materialRevisions();
    this.goPublisher = new DefaultGoPublisher(agentWorkContext.getArtifactsManipulator(), jobIdentifier, agentWorkContext.getRepositoryRemote(), agentWorkContext.getAgentRuntimeInfo(), consoleLogCharset);
    this.artifactsPublisher = new ArtifactsPublisher(goPublisher, agentWorkContext.getArtifactExtension(), assignment.getArtifactStores(), agentWorkContext.getPluginRequestProcessorRegistry(), workingDirectory);
    this.builders = new Builders(assignment.getBuilders(), goPublisher, agentWorkContext.getTaskExtension(), agentWorkContext.getArtifactExtension(), agentWorkContext.getPluginRequestProcessorRegistry());
}
Also used : AgentBuildingInfo(com.thoughtworks.go.server.service.AgentBuildingInfo) TimeProvider(com.thoughtworks.go.util.TimeProvider) DefaultGoPublisher(com.thoughtworks.go.work.DefaultGoPublisher) ArtifactsPublisher(com.thoughtworks.go.remote.work.artifact.ArtifactsPublisher)

Example 37 with TimeProvider

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

the class InstanceFactoryTest method shouldNotRerun_WhenJobRunConfigIsChanged_ForRunMultipleInstance.

@Test
public void shouldNotRerun_WhenJobRunConfigIsChanged_ForRunMultipleInstance() {
    Date old = new DateTime().minusDays(2).toDate();
    StageConfig stageConfig = StageConfigMother.custom("dev", "rails", "java");
    JobConfig railsConfig = stageConfig.getJobs().getJob(new CaseInsensitiveString("rails"));
    railsConfig.setRunInstanceCount(3);
    DefaultSchedulingContext schedulingContext = new DefaultSchedulingContext("loser", new Agents());
    RunMultipleInstance.CounterBasedJobNameGenerator jobNameGenerator = new RunMultipleInstance.CounterBasedJobNameGenerator(CaseInsensitiveString.str(railsConfig.name()));
    JobInstances jobs = instanceFactory.createJobInstance(new CaseInsensitiveString("dev"), railsConfig, schedulingContext, new TimeProvider(), jobNameGenerator);
    Stage stage = createStageInstance(old, jobs);
    Stage newStage = null;
    railsConfig.setRunOnAllAgents(true);
    railsConfig.setRunInstanceCount(0);
    CannotRerunJobException exception = null;
    try {
        newStage = instanceFactory.createStageForRerunOfJobs(stage, a("rails-runInstance-1"), schedulingContext, stageConfig, new TimeProvider(), "md5");
        fail("should not schedule since job config changed to run multiple instance");
    } catch (CannotRerunJobException e) {
        exception = e;
    }
    assertThat(exception.getJobName(), is("rails"));
    assertThat(exception.getInformation(), is("Run configuration for job has been changed to 'run on all agents'."));
    assertThat(newStage, is(nullValue()));
    railsConfig.setRunOnAllAgents(false);
    try {
        newStage = instanceFactory.createStageForRerunOfJobs(stage, a("rails-runInstance-1"), schedulingContext, stageConfig, new TimeProvider(), "md5");
        fail("should not schedule since job config changed to run multiple instance");
    } catch (CannotRerunJobException e) {
        exception = e;
    }
    assertThat(exception.getJobName(), is("rails"));
    assertThat(exception.getInformation(), is("Run configuration for job has been changed to 'simple'."));
    assertThat(newStage, is(nullValue()));
}
Also used : TimeProvider(com.thoughtworks.go.util.TimeProvider) Date(java.util.Date) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 38 with TimeProvider

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

the class InstanceFactoryTest method shouldNotRerun_WhenJobConfigIsChangedToRunMultipleInstance_ForRunOnAllAgentsJobInstance.

@Test
public void shouldNotRerun_WhenJobConfigIsChangedToRunMultipleInstance_ForRunOnAllAgentsJobInstance() {
    Date old = new DateTime().minusDays(2).toDate();
    StageConfig stageConfig = StageConfigMother.custom("dev", "rails", "java");
    JobConfig railsConfig = stageConfig.getJobs().getJob(new CaseInsensitiveString("rails"));
    railsConfig.setRunOnAllAgents(true);
    railsConfig.addResourceConfig("foobar");
    AgentConfig agent1 = new AgentConfig("abcd1234", "host", "127.0.0.2", new ResourceConfigs(new ResourceConfig("foobar")));
    AgentConfig agent2 = new AgentConfig("1234abcd", "ghost", "192.168.1.2", new ResourceConfigs(new ResourceConfig("baz"), new ResourceConfig("foobar")));
    AgentConfig agent3 = new AgentConfig("7890abdc", "lost", "10.4.3.55", new ResourceConfigs(new ResourceConfig("crapyagent")));
    DefaultSchedulingContext schedulingContext = new DefaultSchedulingContext("loser", new Agents(agent1, agent2, agent3));
    RunOnAllAgents.CounterBasedJobNameGenerator jobNameGenerator = new RunOnAllAgents.CounterBasedJobNameGenerator(CaseInsensitiveString.str(railsConfig.name()));
    JobInstances jobs = instanceFactory.createJobInstance(new CaseInsensitiveString("dev"), railsConfig, schedulingContext, new TimeProvider(), jobNameGenerator);
    Stage stage = createStageInstance(old, jobs);
    Stage newStage = null;
    railsConfig.setRunOnAllAgents(false);
    railsConfig.setRunInstanceCount(10);
    CannotRerunJobException exception = null;
    try {
        newStage = instanceFactory.createStageForRerunOfJobs(stage, a("rails-runOnAll-1"), schedulingContext, stageConfig, new TimeProvider(), "md5");
        fail("should not schedule since job config changed to run multiple instance");
    } catch (CannotRerunJobException e) {
        exception = e;
    }
    assertThat(exception.getJobName(), is("rails"));
    assertThat(exception.getInformation(), is("Run configuration for job has been changed to 'run multiple instance'."));
    assertThat(newStage, is(nullValue()));
}
Also used : TimeProvider(com.thoughtworks.go.util.TimeProvider) Date(java.util.Date) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 39 with TimeProvider

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

the class InstanceFactoryTest method shouldSchedulePipelineWithFirstStage.

@Test
public void shouldSchedulePipelineWithFirstStage() {
    StageConfig stageOneConfig = StageConfigMother.stageConfig("dev", BuildPlanMother.withBuildPlans("functional", "unit"));
    StageConfig stageTwoConfig = StageConfigMother.stageConfig("qa", BuildPlanMother.withBuildPlans("suiteOne", "suiteTwo"));
    MaterialConfigs materialConfigs = MaterialConfigsMother.defaultMaterialConfigs();
    PipelineConfig pipelineConfig = new PipelineConfig(new CaseInsensitiveString("mingle"), materialConfigs, stageOneConfig, stageTwoConfig);
    BuildCause buildCause = BuildCause.createManualForced(modifyOneFile(pipelineConfig), Username.ANONYMOUS);
    Pipeline pipeline = instanceFactory.createPipelineInstance(pipelineConfig, buildCause, new DefaultSchedulingContext("test"), "some-md5", new TimeProvider());
    assertThat(pipeline.getName(), is("mingle"));
    assertThat(pipeline.getStages().size(), is(1));
    assertThat(pipeline.getStages().get(0).getName(), is("dev"));
    assertThat(pipeline.getStages().get(0).getJobInstances().get(0).getName(), is("functional"));
}
Also used : MaterialConfigs(com.thoughtworks.go.config.materials.MaterialConfigs) TimeProvider(com.thoughtworks.go.util.TimeProvider) BuildCause(com.thoughtworks.go.domain.buildcause.BuildCause) Test(org.junit.Test)

Example 40 with TimeProvider

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

the class InstanceFactoryTest method shouldCreateJobInstancesCorrectly_RunMultipleInstance_Rerun.

@Test
public void shouldCreateJobInstancesCorrectly_RunMultipleInstance_Rerun() {
    Date old = new DateTime().minusDays(2).toDate();
    StageConfig stageConfig = StageConfigMother.custom("dev", "rails", "java");
    JobConfig railsConfig = stageConfig.getJobs().getJob(new CaseInsensitiveString("rails"));
    railsConfig.setRunInstanceCount(3);
    DefaultSchedulingContext schedulingContext = new DefaultSchedulingContext("loser", new Agents());
    RunMultipleInstance.CounterBasedJobNameGenerator jobNameGenerator = new RunMultipleInstance.CounterBasedJobNameGenerator(CaseInsensitiveString.str(railsConfig.name()));
    JobInstances jobs = instanceFactory.createJobInstance(new CaseInsensitiveString("dev"), railsConfig, schedulingContext, new TimeProvider(), jobNameGenerator);
    assertThat(jobs.get(0).getName(), is("rails-runInstance-1"));
    assertEnvironmentVariable(jobs.get(0), 0, "GO_JOB_RUN_INDEX", "1");
    assertEnvironmentVariable(jobs.get(0), 1, "GO_JOB_RUN_COUNT", "3");
    assertThat(jobs.get(1).getName(), is("rails-runInstance-2"));
    assertEnvironmentVariable(jobs.get(1), 0, "GO_JOB_RUN_INDEX", "2");
    assertEnvironmentVariable(jobs.get(1), 1, "GO_JOB_RUN_COUNT", "3");
    assertThat(jobs.get(2).getName(), is("rails-runInstance-3"));
    assertEnvironmentVariable(jobs.get(2), 0, "GO_JOB_RUN_INDEX", "3");
    assertEnvironmentVariable(jobs.get(2), 1, "GO_JOB_RUN_COUNT", "3");
    Stage stage = createStageInstance(old, jobs);
    Stage stageForRerun = instanceFactory.createStageForRerunOfJobs(stage, a("rails-runInstance-1", "rails-runInstance-2"), schedulingContext, stageConfig, clock, "md5");
    JobInstances jobsForRerun = stageForRerun.getJobInstances();
    assertThat(jobsForRerun.get(0).getName(), is("rails-runInstance-3"));
    assertEnvironmentVariable(jobsForRerun.get(0), 0, "GO_JOB_RUN_INDEX", "3");
    assertEnvironmentVariable(jobsForRerun.get(0), 1, "GO_JOB_RUN_COUNT", "3");
    assertThat(jobsForRerun.get(2).getName(), is("rails-runInstance-1"));
    assertEnvironmentVariable(jobsForRerun.get(2), 0, "GO_JOB_RUN_INDEX", "1");
    assertEnvironmentVariable(jobsForRerun.get(2), 1, "GO_JOB_RUN_COUNT", "3");
    assertThat(jobsForRerun.get(3).getName(), is("rails-runInstance-2"));
    assertEnvironmentVariable(jobsForRerun.get(3), 0, "GO_JOB_RUN_INDEX", "2");
    assertEnvironmentVariable(jobsForRerun.get(3), 1, "GO_JOB_RUN_COUNT", "3");
    assertThat(jobsForRerun.size(), is(4));
    assertRunMultipleJobInstance(jobsForRerun.get(0), "rails-runInstance-3");
    assertThat(jobsForRerun.get(1).getName(), is("java"));
    assertReRunMultipleJobInstance(jobsForRerun.get(2), "rails-runInstance-1");
    assertReRunMultipleJobInstance(jobsForRerun.get(3), "rails-runInstance-2");
}
Also used : TimeProvider(com.thoughtworks.go.util.TimeProvider) Date(java.util.Date) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Aggregations

TimeProvider (com.thoughtworks.go.util.TimeProvider)177 Test (org.junit.Test)122 Date (java.util.Date)29 BuildCause (com.thoughtworks.go.domain.buildcause.BuildCause)28 MaterialConfigs (com.thoughtworks.go.config.materials.MaterialConfigs)25 DateTime (org.joda.time.DateTime)18 PipelineConfig (com.thoughtworks.go.config.PipelineConfig)16 GoConfigRevision (com.thoughtworks.go.domain.GoConfigRevision)13 Username (com.thoughtworks.go.server.domain.Username)13 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)13 Before (org.junit.Before)13 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)12 DependencyMaterial (com.thoughtworks.go.config.materials.dependency.DependencyMaterial)11 Materials (com.thoughtworks.go.config.materials.Materials)10 HgMaterial (com.thoughtworks.go.config.materials.mercurial.HgMaterial)10 HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)9 TransactionStatus (org.springframework.transaction.TransactionStatus)9 Material (com.thoughtworks.go.domain.materials.Material)7 Modification (com.thoughtworks.go.domain.materials.Modification)7 GitMaterial (com.thoughtworks.go.config.materials.git.GitMaterial)6