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