Search in sources :

Example 1 with JobIdentifier

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

the class ReportTest method encodeAndDecodeAsMessageData.

@Test
public void encodeAndDecodeAsMessageData() throws Exception {
    AgentRuntimeInfo info = new AgentRuntimeInfo(new AgentIdentifier("HostName", "ipAddress", "uuid"), AgentRuntimeStatus.Idle, null, null, true);
    JobIdentifier jobIdentifier = new JobIdentifier("pipeline", 1, "pipelinelabel", "stagename", "1", "job", 1L);
    Report report = new Report(info, jobIdentifier, JobResult.Passed);
    assertThat(MessageEncoding.decodeData(MessageEncoding.encodeData(report), Report.class), is(report));
}
Also used : AgentRuntimeInfo(com.thoughtworks.go.server.service.AgentRuntimeInfo) AgentIdentifier(com.thoughtworks.go.remote.AgentIdentifier) JobIdentifier(com.thoughtworks.go.domain.JobIdentifier) Test(org.junit.Test)

Example 2 with JobIdentifier

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

the class URLServiceTest method setUp.

@Before
public void setUp() {
    urlService = new URLService();
    jobIdentifier = new JobIdentifier("pipelineName", -2, "LATEST", "stageName", "LATEST", "buildName", 123L);
}
Also used : JobIdentifier(com.thoughtworks.go.domain.JobIdentifier) Before(org.junit.Before)

Example 3 with JobIdentifier

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

the class ArtifactsController method getArtifact.

ModelAndView getArtifact(String filePath, ArtifactFolderViewFactory folderViewFactory, String pipelineName, String counterOrLabel, String stageName, String stageCounter, String buildName, String sha, String serverAlias) throws Exception {
    LOGGER.info(String.format("[Artifact Download] Trying to resolve '%s' for '%s/%s/%s/%s/%s'", filePath, pipelineName, counterOrLabel, stageName, stageCounter, buildName));
    long before = System.currentTimeMillis();
    ArtifactsView view;
    //Work out the job that we are trying to retrieve
    JobIdentifier translatedId;
    try {
        translatedId = restfulService.findJob(pipelineName, counterOrLabel, stageName, stageCounter, buildName);
    } catch (Exception e) {
        return buildNotFound(pipelineName, counterOrLabel, stageName, stageCounter, buildName);
    }
    if (filePath.contains("..")) {
        return FileModelAndView.forbiddenUrl(filePath);
    }
    view = new LocalArtifactsView(folderViewFactory, artifactsService, translatedId, consoleService);
    ModelAndView createdView = view.createView(filePath, sha);
    LOGGER.info(String.format("[Artifact Download] Successfully resolved '%s' for '%s/%s/%s/%s/%s'. It took: %sms", filePath, pipelineName, counterOrLabel, stageName, stageCounter, buildName, System.currentTimeMillis() - before));
    return createdView;
}
Also used : FileModelAndView(com.thoughtworks.go.server.web.FileModelAndView) ModelAndView(org.springframework.web.servlet.ModelAndView) LocalArtifactsView(com.thoughtworks.go.server.view.artifacts.LocalArtifactsView) ArtifactsView(com.thoughtworks.go.server.view.artifacts.ArtifactsView) LocalArtifactsView(com.thoughtworks.go.server.view.artifacts.LocalArtifactsView) JobIdentifier(com.thoughtworks.go.domain.JobIdentifier) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) IllegalArtifactLocationException(com.thoughtworks.go.domain.exception.IllegalArtifactLocationException)

Example 4 with JobIdentifier

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

the class ArtifactsController method postArtifact.

@RequestMapping("/repository/restful/artifact/POST/*")
public ModelAndView postArtifact(@RequestParam("pipelineName") String pipelineName, @RequestParam("pipelineLabel") String counterOrLabel, @RequestParam("stageName") String stageName, @RequestParam(value = "stageCounter", required = false) String stageCounter, @RequestParam("buildName") String buildName, @RequestParam(value = "buildId", required = false) Long buildId, @RequestParam("filePath") String filePath, @RequestParam(value = "attempt", required = false) Integer attempt, MultipartHttpServletRequest request) throws Exception {
    JobIdentifier jobIdentifier;
    if (!headerConstraint.isSatisfied(request)) {
        return ResponseCodeView.create(HttpServletResponse.SC_BAD_REQUEST, "Missing required header 'Confirm'");
    }
    try {
        jobIdentifier = restfulService.findJob(pipelineName, counterOrLabel, stageName, stageCounter, buildName, buildId);
    } catch (Exception e) {
        return buildNotFound(pipelineName, counterOrLabel, stageName, stageCounter, buildName);
    }
    int convertedAttempt = attempt == null ? 1 : attempt;
    try {
        File artifact = artifactsService.findArtifact(jobIdentifier, filePath);
        if (artifact.exists() && artifact.isFile()) {
            return FileModelAndView.fileAlreadyExists(filePath);
        }
        MultipartFile multipartFile = multipartFile(request);
        if (multipartFile == null) {
            return FileModelAndView.invalidUploadRequest();
        }
        boolean success = saveFile(convertedAttempt, artifact, multipartFile, shouldUnzipStream(multipartFile));
        if (!success) {
            return FileModelAndView.errorSavingFile(filePath);
        }
        success = updateChecksumFile(request, jobIdentifier, filePath);
        if (!success) {
            return FileModelAndView.errorSavingChecksumFile(filePath);
        }
        return FileModelAndView.fileCreated(filePath);
    } catch (IllegalArtifactLocationException e) {
        return FileModelAndView.forbiddenUrl(filePath);
    }
}
Also used : MultipartFile(org.springframework.web.multipart.MultipartFile) IllegalArtifactLocationException(com.thoughtworks.go.domain.exception.IllegalArtifactLocationException) JobIdentifier(com.thoughtworks.go.domain.JobIdentifier) File(java.io.File) MultipartFile(org.springframework.web.multipart.MultipartFile) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) IllegalArtifactLocationException(com.thoughtworks.go.domain.exception.IllegalArtifactLocationException) HeaderConstraint(com.thoughtworks.go.server.security.HeaderConstraint) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 5 with JobIdentifier

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

the class RestfulServiceTest method canSupportQueryingUsingPipelineNameWithDifferentCase.

@Test
public void canSupportQueryingUsingPipelineNameWithDifferentCase() throws Exception {
    Pipeline pipeline = fixture.createdPipelineWithAllStagesPassed();
    JobIdentifier jobIdentifier = restfulService.findJob(pipeline.getName().toUpperCase(), JobIdentifier.LATEST, fixture.devStage, "", PipelineWithTwoStages.JOB_FOR_DEV_STAGE);
    assertThat(jobIdentifier.getPipelineName(), is(pipeline.getName()));
}
Also used : JobIdentifier(com.thoughtworks.go.domain.JobIdentifier) Pipeline(com.thoughtworks.go.domain.Pipeline) Test(org.junit.Test)

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