public StageIdentifier getStageIdentifier() { return new StageIdentifier(pipelineName, pipelineCounter, pipelineLabel, stageName, stageCounter); }
public JobIdentifier(StageIdentifier stage, String jobName, Long jobId) { this(stage.getPipelineName(), stage.getPipelineCounter(), stage.getPipelineLabel(), stage.getStageName(), stage.getStageCounter(), jobName, jobId); }
@Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } StageAsDMR asDMR = (StageAsDMR) o; if (completedDate != null ? !completedDate.equals(asDMR.completedDate) : asDMR.completedDate != null) { return false; } if (identifier != null ? !identifier.equals(asDMR.identifier) : asDMR.identifier != null) { return false; } return true; }
public String ccProjectName() { return String.format("%s :: %s", getPipelineName(), getStageName()); }
String cacheKeyForListOfStageIdentifiers(StageIdentifier stageIdentifier) { return cacheKeyGenerator.generate("stageRunIdentifier", stageIdentifier.getPipelineName(), stageIdentifier.getPipelineCounter(), stageIdentifier.getStageName()); }
@Override public StageNotificationDTO transformData() { String pipelineName = stage.getIdentifier().getPipelineName(); Integer pipelineCounter = stage.getIdentifier().getPipelineCounter(); String pipelineLabel = stage.getIdentifier().getPipelineLabel(); StageNotificationDTO.PipelineDTO pipeline = new StageNotificationDTO.PipelineDTO(pipelineName, pipelineCounter, pipelineLabel, pipelineGroup, createBuildCause(buildCause), createStageDTO()); return new StageNotificationDTO(pipeline); }
public void stageStatusChanged(Stage stage) { removeStageSpecificCache(stage); syncCachedActivePipelines(stage); updateCachedLatestSuccessfulStage(stage); String pipelineName = stage.getIdentifier().getPipelineName(); Integer pipelineCounter = stage.getIdentifier().getPipelineCounter(); clearPipelineHistoryCacheViaNameAndCounter(pipelineName, pipelineCounter); }
private StageIdentifier previousStage(Stage stage) { StageIdentifier previousStageIdentifier = null; StageIdentifier currentStageIdentifier = stage.getIdentifier(); String pipelineName = currentStageIdentifier.getPipelineName(); if (isStageAutomaticallyTriggered(stage) || (isManualStage(stage) && !isStageReRun(stage))) { StageConfig previousStage = goConfigService.previousStage(pipelineName, stage.getName()); int latestCounter = stageDao.findLatestStageCounter(stage.getIdentifier().pipelineIdentifier(), previousStage.name().toString()); previousStageIdentifier = new StageIdentifier(currentStageIdentifier.pipelineIdentifier(), previousStage.name().toString(), Integer.toString(latestCounter)); } return previousStageIdentifier; }
public Document toXml(XmlWriterContext writerContext) { DOMElement root = new DOMElement("stage"); root.addAttribute("name", stage.getName()).addAttribute("counter", String.valueOf(stage.getCounter())); Document document = new DOMDocument(root); root.addElement("link").addAttribute("rel", "self").addAttribute("href", httpUrl(writerContext.getBaseUrl())); StageIdentifier stageId = stage.getIdentifier(); root.addElement("id").addCDATA(stageId.asURN()); String pipelineName = stageId.getPipelineName(); root.addElement("pipeline").addAttribute("name", pipelineName) .addAttribute("counter", String.valueOf(stageId.getPipelineCounter())) .addAttribute("label", stageId.getPipelineLabel()) .addAttribute("href", writerContext.getBaseUrl() + "/api/pipelines/" + pipelineName + "/" + stage.getPipelineId() + ".xml"); root.addElement("updated").addText(DateUtils.formatISO8601(stage.latestTransitionDate())); root.addElement("result").addText(stage.getResult().toString()); root.addElement("state").addText(stage.status()); root.addElement("approvedBy").addCDATA(stage.getApprovedBy()); Element jobs = root.addElement("jobs"); for (JobInstance jobInstance : stage.getJobInstances()) { jobs.addElement("job").addAttribute("href", writerContext.getBaseUrl() + "/api/jobs/" + jobInstance.getId() + ".xml"); } return document; }
public List<Modification> getPassedStagesAfter(final String lastRevision, DependencyMaterial material, Pagination pagination) { StageIdentifier identifier = new StageIdentifier(lastRevision); List<StageAsDMR> passedStagesAfter = stageDao.getPassedStagesAfter(identifier, pagination.getPageSize(), pagination.getOffset()); List<Modification> mods = new ArrayList<>(); for (StageAsDMR stage : passedStagesAfter) { StageIdentifier stageIdentifier = stage.getIdentifier(); Modification modification = new Modification(stage.getCompletedDate(), stageIdentifier.stageLocator(), stageIdentifier.getPipelineLabel(), stage.getPipelineId()); mods.add(modification); } return mods; } }
@Test public void shouldContainCounterIfStageHasRerun() { StageIdentifier identifier = new StageIdentifier("cruise", null, "label", "dev", "2"); assertThat(identifier.ccTrayLastBuildLabel(), is("label :: 2")); }
public String getPipelineName() { return identifier.getPipelineName(); }
public StageDTO(String name, int counter, String approvalType, String approvedBy, StageIdentifier previousStage, StageState state, StageResult result, String createTime, String lastTransitionTime, List<JobDTO> jobs) { this.name = name; this.counter = new Integer(counter).toString(); this.approvalType = approvalType; this.approvedBy = approvedBy; this.state = state.toString(); this.result = result.toString(); this.createTime = createTime; this.lastTransitionTime = lastTransitionTime; this.jobs = jobs; if (previousStage != null) { this.previousStageName = previousStage.getStageName(); this.previousStageCounter = Integer.parseInt(previousStage.getStageCounter()); } } }
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; }
@Test public void shouldReturnURN() throws Exception { StageIdentifier id = new StageIdentifier("cruise", 1, "dev", "1"); assertThat(id.asURN(), is("urn:x-go.studios.thoughtworks.com:stage-id:cruise:1:dev:1")); } }
public String rerunSelectedJobs(Request req, Response res) throws IOException { HttpOperationResult result = new HttpOperationResult(); haltIfRequestBodyDoesNotContainPropertyJobs(req); JsonReader requestBody = GsonTransformer.getInstance().jsonReaderFrom(req.body()); List<String> requestedJobs = requestBody.readStringArrayIfPresent(JOB_NAMES_PROPERTY).get(); Optional<Stage> optionalStage = getStageFromRequestParam(req, result); optionalStage.ifPresent(stage -> { HealthStateType healthStateType = HealthStateType.general(HealthStateScope.forStage(stage.getIdentifier() .getPipelineName(), stage.getName())); Set<String> jobsInStage = stage.getJobInstances() .stream() .map(JobInstance::getName) .collect(Collectors.toSet()); List<String> unknownJobs = requestedJobs.stream() .filter(jobToRun -> !jobsInStage.contains(jobToRun)) .collect(Collectors.toList()); if (unknownJobs.isEmpty()) { scheduleService.rerunJobs(stage, requestedJobs, result); } else { String msg = String.format("Job(s) %s does not exist in stage '%s'.", unknownJobs, stage.getIdentifier().getStageLocator()); result.notFound(msg, "", healthStateType); } }); return renderHTTPOperationResult(result, req, res); }
@Override public int hashCode() { int result = identifier != null ? identifier.hashCode() : 0; result = 31 * result + (completedDate != null ? completedDate.hashCode() : 0); return result; }
final String pipelineName = pipeline.getName(); PipelineState fromCache = pipelineStateFor(pipelineName); if (fromCache != null && fromCache.isLocked() && !pipeline.getIdentifier().equals(fromCache.getLockedBy().pipelineIdentifier())) { throw new RuntimeException(String.format("Pipeline '%s' is already locked (counter = %s)", pipelineName, fromCache.getLockedBy().getPipelineCounter()));
public Integer getPipelineCounter() { return identifier.getPipelineCounter(); }
public String entityLocator() { return getStageLocator(); }