Search in sources :

Example 26 with StageIdentifier

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

the class PipelineWithTwoStages method latestPipelineWithIdentifiers.

private Pipeline latestPipelineWithIdentifiers() {
    Pipeline pipeline;
    pipeline = dbHelper.getPipelineDao().mostRecentPipeline(pipelineName);
    //TODO: #2318 - pipeline loaded from DB should contain identifiers
    for (Stage stage : pipeline.getStages()) {
        stage.setIdentifier(new StageIdentifier(pipeline, stage));
        for (JobInstance jobInstance : stage.getJobInstances()) {
            jobInstance.setIdentifier(new JobIdentifier(pipeline, stage, jobInstance));
        }
    }
    return pipeline;
}
Also used : StageIdentifier(com.thoughtworks.go.domain.StageIdentifier) JobInstance(com.thoughtworks.go.domain.JobInstance) Stage(com.thoughtworks.go.domain.Stage) JobIdentifier(com.thoughtworks.go.domain.JobIdentifier) Pipeline(com.thoughtworks.go.domain.Pipeline)

Example 27 with StageIdentifier

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

the class PipelineHistoryJsonPresentationModel method stageHistoryAsJson.

private List stageHistoryAsJson(PipelineInstanceModel pipelineInstanceModel, StageInstanceModels stageHistory) {
    List json = new ArrayList();
    for (StageInstanceModel stageHistoryItem : stageHistory) {
        Map<String, Object> jsonMap = new LinkedHashMap<>();
        jsonMap.put("stageName", stageHistoryItem.getName());
        jsonMap.put("stageId", stageHistoryItem.getId());
        jsonMap.put("stageStatus", stageHistoryItem.getState().toString());
        StageIdentifier stageIdentifier = new StageIdentifier(pipelineInstanceModel.getPipelineIdentifier(), stageHistoryItem.getName(), stageHistoryItem.getCounter());
        jsonMap.put("stageLocator", encodeInUtf8(stageIdentifier.stageLocator()));
        jsonMap.put("getCanRun", Boolean.toString(stageHistoryItem.getCanRun()));
        jsonMap.put("getCanCancel", Boolean.toString(stageHistoryItem.getCanCancel()));
        jsonMap.put("scheduled", Boolean.toString(stageHistoryItem.isScheduled()));
        jsonMap.put("stageCounter", stageHistoryItem.getCounter());
        handleApproval(stageHistoryItem, jsonMap);
        json.add(jsonMap);
    }
    return json;
}
Also used : StageIdentifier(com.thoughtworks.go.domain.StageIdentifier) StageInstanceModel(com.thoughtworks.go.presentation.pipelinehistory.StageInstanceModel)

Example 28 with StageIdentifier

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

the class FailureServiceTest method setUp.

@Before
public void setUp() {
    shineDao = mock(ShineDao.class);
    securityService = mock(SecurityService.class);
    stageFinder = mock(StageFinder.class);
    failureService = new FailureService(securityService, shineDao, stageFinder);
    username = new Username(new CaseInsensitiveString("foo"));
    jobIdentifier = new JobIdentifier(new StageIdentifier("pipeline", 10, "stage", "5"), "job");
    result = new HttpLocalizedOperationResult();
}
Also used : StageIdentifier(com.thoughtworks.go.domain.StageIdentifier) HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) ShineDao(com.thoughtworks.go.server.dao.sparql.ShineDao) Username(com.thoughtworks.go.server.domain.Username) JobIdentifier(com.thoughtworks.go.domain.JobIdentifier) StageFinder(com.thoughtworks.go.domain.StageFinder) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) Before(org.junit.Before)

Example 29 with StageIdentifier

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

the class StageStorage method save.

// File writes are not atomic in nature. There can be cases where the file is not completely written to disk.
// This is why we write to a tmp file and move it over to the actual file. File moves are atomic operations.
// If rename failed because target file already exists, we just ignore it because some other thread may have generated it.
public void save(Graph graph) {
    StageIdentifier identifier = extractStageIdentifier(graph);
    if (isStageStored(identifier)) {
        return;
    }
    synchronized (stageKey(identifier)) {
        if (isStageStored(identifier)) {
            return;
        }
        File file = new File(tmpStagePath(identifier));
        file.getParentFile().mkdirs();
        try {
            OutputStream os = new BufferedOutputStream(new GZIPOutputStream(new FileOutputStream(file)));
            graph.persistToTurtle(os);
            os.flush();
            os.close();
            file.renameTo(new File(stagePath(identifier)));
        } catch (IOException e) {
            throw new ShineRuntimeException(e);
        } finally {
            file.delete();
        }
    }
}
Also used : StageIdentifier(com.thoughtworks.go.domain.StageIdentifier) ShineRuntimeException(com.thoughtworks.studios.shine.ShineRuntimeException) GZIPOutputStream(java.util.zip.GZIPOutputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) BufferedOutputStream(java.io.BufferedOutputStream) GZIPOutputStream(java.util.zip.GZIPOutputStream) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) File(java.io.File) BufferedOutputStream(java.io.BufferedOutputStream)

Example 30 with StageIdentifier

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

the class StageStorage method extractStageIdentifier.

private StageIdentifier extractStageIdentifier(Graph graph) {
    String select = "" + "PREFIX cruise: <" + GoOntology.URI + "> " + "SELECT ?pipelineName ?pipelineCounter ?stageName ?stageCounter WHERE {" + "  ?pipeline a cruise:Pipeline ." + "  ?pipeline cruise:pipelineName ?pipelineName ." + "  ?pipeline cruise:pipelineCounter ?pipelineCounter ." + "  ?pipeline cruise:hasStage ?stage ." + "  ?stage cruise:stageName ?stageName ." + "  ?stage cruise:stageCounter ?stageCounter ." + "}";
    BoundVariables bv = graph.selectFirst(select);
    if (bv == null) {
        throw new ShineRuntimeException("Cannot save a stage graph without stage identification information!");
    }
    StageIdentifier stageIdentifier = new StageIdentifier(bv.getString("pipelineName"), bv.getInt("pipelineCounter"), bv.getString("stageName"), bv.getString("stageCounter"));
    return stageIdentifier;
}
Also used : StageIdentifier(com.thoughtworks.go.domain.StageIdentifier) BoundVariables(com.thoughtworks.studios.shine.semweb.BoundVariables) ShineRuntimeException(com.thoughtworks.studios.shine.ShineRuntimeException)

Aggregations

StageIdentifier (com.thoughtworks.go.domain.StageIdentifier)59 Test (org.junit.Test)31 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)12 Pipeline (com.thoughtworks.go.domain.Pipeline)12 Stage (com.thoughtworks.go.domain.Stage)12 JobIdentifier (com.thoughtworks.go.domain.JobIdentifier)6 StageTestRuns (com.thoughtworks.go.domain.testinfo.StageTestRuns)6 StageInstanceModel (com.thoughtworks.go.presentation.pipelinehistory.StageInstanceModel)6 ArrayList (java.util.ArrayList)6 Modification (com.thoughtworks.go.domain.materials.Modification)5 StageInstanceModels (com.thoughtworks.go.presentation.pipelinehistory.StageInstanceModels)5 Username (com.thoughtworks.go.server.domain.Username)4 MaterialConfigs (com.thoughtworks.go.config.materials.MaterialConfigs)3 JobInstance (com.thoughtworks.go.domain.JobInstance)3 PipelineDependencyGraphOld (com.thoughtworks.go.domain.PipelineDependencyGraphOld)3 DependencyMaterialRevision (com.thoughtworks.go.domain.materials.dependency.DependencyMaterialRevision)3 FailingTestsInPipeline (com.thoughtworks.go.domain.testinfo.FailingTestsInPipeline)3 PipelineInstanceModel (com.thoughtworks.go.presentation.pipelinehistory.PipelineInstanceModel)3 BoundVariables (com.thoughtworks.studios.shine.semweb.BoundVariables)3 Graph (com.thoughtworks.studios.shine.semweb.Graph)3