Search in sources :

Example 16 with JobIdentifier

use of com.thoughtworks.go.domain.JobIdentifier in project gocd by gocd.

the class JobStatusJsonPresentationModelTest method shouldIncludeBuildLocatorForDisplay.

@Test
public void shouldIncludeBuildLocatorForDisplay() throws Exception {
    JobInstance instance = JobInstanceMother.completed("job-%", JobResult.Passed);
    instance.setIdentifier(new JobIdentifier("cruise-%", 1, "label-1", "dev-%", "1", "job-%", -1L));
    JobStatusJsonPresentationModel presenter = new JobStatusJsonPresentationModel(instance, null);
    Map json = presenter.toJsonHash();
    assertThat(JsonUtils.from(json).getString("buildLocatorForDisplay"), is("cruise-%/label-1/dev-%/1/job-%"));
}
Also used : JobInstance(com.thoughtworks.go.domain.JobInstance) JobIdentifier(com.thoughtworks.go.domain.JobIdentifier) Map(java.util.Map) Test(org.junit.Test)

Example 17 with JobIdentifier

use of com.thoughtworks.go.domain.JobIdentifier in project gocd by gocd.

the class JobStatusJsonPresentationModelTest method shouldEncodeBuildLocator.

@Test
public void shouldEncodeBuildLocator() throws Exception {
    JobInstance instance = JobInstanceMother.completed("job-%", JobResult.Passed);
    instance.setIdentifier(new JobIdentifier("cruise-%", 1, "label-1", "dev-%", "1", "job-%", -1L));
    JobStatusJsonPresentationModel presenter = new JobStatusJsonPresentationModel(instance, null);
    Map json = presenter.toJsonHash();
    assertThat(JsonUtils.from(json).getString("buildLocator"), is("cruise-%25/1/dev-%25/1/job-%25"));
}
Also used : JobInstance(com.thoughtworks.go.domain.JobInstance) JobIdentifier(com.thoughtworks.go.domain.JobIdentifier) Map(java.util.Map) Test(org.junit.Test)

Example 18 with JobIdentifier

use of com.thoughtworks.go.domain.JobIdentifier in project gocd by gocd.

the class ArtifactDirectoryChooserTest method shouldReturnASameLocationForConsoleFilesWithSimilarJobIdentifiers.

@Test
public void shouldReturnASameLocationForConsoleFilesWithSimilarJobIdentifiers() throws Exception {
    JobIdentifier jobIdentifier = JobIdentifierMother.jobIdentifier("come", 1, "together", "1", "right");
    JobIdentifier anotherJobIdentifier = JobIdentifierMother.jobIdentifier("come", 1, "together", "1", "right");
    assertThat(chooser.temporaryConsoleFile(jobIdentifier).getPath(), equalToIgnoringCase(chooser.temporaryConsoleFile(anotherJobIdentifier).getPath()));
}
Also used : JobIdentifier(com.thoughtworks.go.domain.JobIdentifier) Test(org.junit.Test)

Example 19 with JobIdentifier

use of com.thoughtworks.go.domain.JobIdentifier in project gocd by gocd.

the class PathBasedArtifactsLocatorTest method shouldUsePipelineLabelForArtifactDirectory.

@Test
public void shouldUsePipelineLabelForArtifactDirectory() {
    PathBasedArtifactsLocator locator = new PathBasedArtifactsLocator(new File("root"));
    File directory = locator.directoryFor(new JobIdentifier("cruise", -2, "1.1", "dev", "2", "linux-firefox", null));
    assertThat(directory, is(new File("root/pipelines/cruise/1.1/dev/2/linux-firefox")));
}
Also used : JobIdentifier(com.thoughtworks.go.domain.JobIdentifier) File(java.io.File) Test(org.junit.Test)

Example 20 with JobIdentifier

use of com.thoughtworks.go.domain.JobIdentifier in project gocd by gocd.

the class FetchTaskBuilder method resolveTargetJob.

private JobIdentifier resolveTargetJob(FetchTask task, Pipeline currentPipeline, UpstreamPipelineResolver resolver) {
    PathFromAncestor pipelineNamePathFromAncestor = task.getPipelineNamePathFromAncestor();
    if (pipelineNamePathFromAncestor == null || CaseInsensitiveString.isBlank(pipelineNamePathFromAncestor.getPath()) || CaseInsensitiveString.areEqual(new CaseInsensitiveString(currentPipeline.getName()), pipelineNamePathFromAncestor.getPath())) {
        task.setPipelineName(new CaseInsensitiveString(currentPipeline.getName()));
        String stageCounter = JobIdentifier.LATEST;
        if (currentPipeline.hasStageBeenRun(CaseInsensitiveString.str(task.getStage()))) {
            stageCounter = String.valueOf(currentPipeline.findStage(CaseInsensitiveString.str(task.getStage())).getCounter());
        }
        return new JobIdentifier(new StageIdentifier(currentPipeline.getName(), currentPipeline.getCounter(), currentPipeline.getLabel(), CaseInsensitiveString.str(task.getStage()), stageCounter), CaseInsensitiveString.str(task.getJob()));
    } else {
        DependencyMaterialRevision revision = null;
        if (pipelineNamePathFromAncestor.isAncestor()) {
            BuildCause buildCause = currentPipeline.getBuildCause();
            for (CaseInsensitiveString parentPipelineName : pipelineNamePathFromAncestor.pathToAncestor()) {
                DependencyMaterialRevision dependencyMaterialRevision = dmrForPipeline(parentPipelineName, buildCause);
                if (dependencyMaterialRevision == null) {
                    throw bomb(String.format("Pipeline [%s] could not fetch artifact [%s]. Unable to resolve revision for [%s] from build cause", currentPipeline.getName(), task, parentPipelineName));
                }
                buildCause = resolver.buildCauseFor(dependencyMaterialRevision.getPipelineName(), dependencyMaterialRevision.getPipelineCounter());
            }
            revision = dmrForPipeline(pipelineNamePathFromAncestor.getAncestorName(), buildCause);
            if (revision == null) {
                throw bomb(String.format("Pipeline [%s] could not fetch artifact [%s]. Unable to resolve revision for [%s] from build cause", currentPipeline.getName(), task, pipelineNamePathFromAncestor.getAncestorName()));
            }
        } else {
            revision = dmrForPipeline(pipelineNamePathFromAncestor.getPath(), currentPipeline.getBuildCause());
            if (revision == null) {
                throw bomb(String.format("Pipeline [%s] tries to fetch artifact from job [%s/%s/%s] " + "which is not a dependency material", currentPipeline.getName(), pipelineNamePathFromAncestor, task.getStage(), task.getJob()));
            }
        }
        String stageCounter = JobIdentifier.LATEST;
        if (task.getStage().equals(new CaseInsensitiveString(revision.getStageName()))) {
            stageCounter = String.valueOf(revision.getStageCounter());
        }
        return new JobIdentifier(new StageIdentifier(CaseInsensitiveString.str(pipelineNamePathFromAncestor.getAncestorName()), revision.getPipelineCounter(), revision.getPipelineLabel(), CaseInsensitiveString.str(task.getStage()), stageCounter), CaseInsensitiveString.str(task.getJob()));
    }
}
Also used : StageIdentifier(com.thoughtworks.go.domain.StageIdentifier) PathFromAncestor(com.thoughtworks.go.config.PathFromAncestor) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) JobIdentifier(com.thoughtworks.go.domain.JobIdentifier) DependencyMaterialRevision(com.thoughtworks.go.domain.materials.dependency.DependencyMaterialRevision) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) BuildCause(com.thoughtworks.go.domain.buildcause.BuildCause)

Aggregations

JobIdentifier (com.thoughtworks.go.domain.JobIdentifier)100 Test (org.junit.Test)74 JobInstance (com.thoughtworks.go.domain.JobInstance)17 Pipeline (com.thoughtworks.go.domain.Pipeline)16 File (java.io.File)15 DateTime (org.joda.time.DateTime)12 Stage (com.thoughtworks.go.domain.Stage)9 Before (org.junit.Before)8 StageIdentifier (com.thoughtworks.go.domain.StageIdentifier)6 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)6 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)5 LogFile (com.thoughtworks.go.server.domain.LogFile)5 IllegalArtifactLocationException (com.thoughtworks.go.domain.exception.IllegalArtifactLocationException)4 Property (com.thoughtworks.go.domain.Property)3 Username (com.thoughtworks.go.server.domain.Username)3 IOException (java.io.IOException)3 Expectations (org.jmock.Expectations)3 RunIf (com.googlecode.junit.ext.RunIf)2 Tabs (com.thoughtworks.go.config.Tabs)2 Properties (com.thoughtworks.go.domain.Properties)2