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