public void latestState(CruiseConfig config) { md5 = config.getMd5(); }
private boolean shouldMergeConfig(UpdateConfigCommand updatingCommand, GoConfigHolder configHolder) { LOGGER.debug("[Config Save] Checking whether config should be merged"); if (updatingCommand instanceof NoOverwriteUpdateConfigCommand) { NoOverwriteUpdateConfigCommand noOverwriteCommand = (NoOverwriteUpdateConfigCommand) updatingCommand; if (!configHolder.configForEdit.getMd5().equals(noOverwriteCommand.unmodifiedMd5())) { return true; } } return false; }
protected final CruiseConfig configForEditing() { CruiseConfig config = getConfigForEditing(); this.md5 = config.getMd5(); return config; }
public String md5OfConfigFile() { return cachedConfigService.currentConfig().getMd5(); }
protected void checkinToConfigRepo(String currentUser, CruiseConfig updatedConfig, String xmlString) throws Exception { LOGGER.debug("[Config Save] Checkin updated config to git: Starting."); configRepository.checkin(new GoConfigRevision(xmlString, updatedConfig.getMd5(), currentUser, CurrentGoCDVersion.getInstance().formatted(), timeProvider)); LOGGER.debug("[Config Save] Checkin updated config to git: Done."); }
private GoConfigHolder internalLoad(final String content, final ConfigModifyingUser configModifyingUser, final List<PartialConfig> partials) throws Exception { GoConfigHolder configHolder = magicalGoConfigXmlLoader.loadConfigHolder(content, cruiseConfig -> cruiseConfig.setPartials(partials)); CruiseConfig config = configHolder.config; checkinConfigToGitRepo(partials, config, content, configHolder.configForEdit.getMd5(), configModifyingUser.getUserName()); return configHolder; }
private GoConfigHolder trySavingConfig(UpdateConfigCommand updatingCommand, GoConfigHolder configHolder, List<PartialConfig> partials) throws Exception { String configAsXml; GoConfigHolder validatedConfigHolder; LOGGER.debug("[Config Save] ==-- Getting modified config"); if (shouldMergeConfig(updatingCommand, configHolder)) { if (!systemEnvironment.get(SystemEnvironment.ENABLE_CONFIG_MERGE_FEATURE)) { throw new ConfigMergeException(ConfigFileHasChangedException.CONFIG_CHANGED_PLEASE_REFRESH); } configAsXml = getMergedConfig((NoOverwriteUpdateConfigCommand) updatingCommand, configHolder.configForEdit.getMd5(), partials); try { validatedConfigHolder = internalLoad(configAsXml, getConfigUpdatingUser(updatingCommand), partials); } catch (Exception e) { LOGGER.info("[CONFIG_MERGE] Post merge validation failed, latest-md5: {}", configHolder.configForEdit.getMd5()); throw new ConfigMergePostValidationException(e.getMessage(), e); } } else { configAsXml = getUnmergedConfig(updatingCommand, configHolder, partials); validatedConfigHolder = internalLoad(configAsXml, getConfigUpdatingUser(updatingCommand), partials); } LOGGER.info("[Configuration Changed] Saving updated configuration."); writeToConfigXmlFile(configAsXml); return validatedConfigHolder; }
public Stage scheduleStage(String pipelineName, String stageName, SchedulingContext context) { PipelineConfig pipelineConfig = getCurrentConfig().pipelineConfigByName(new CaseInsensitiveString(pipelineName)); return instanceFactory.createStageInstance(pipelineConfig, new CaseInsensitiveString(stageName), context, getCurrentConfig().getMd5(), clock); }
public ConfigElementForEdit<EnvironmentConfig> getMergedEnvironmentforDisplay(String environmentName, HttpLocalizedOperationResult result) { ConfigElementForEdit<EnvironmentConfig> edit = null; try { CruiseConfig config = goConfigService.getMergedConfigForEditing(); EnvironmentConfig env = environments.named(new CaseInsensitiveString(environmentName)); edit = new ConfigElementForEdit<>(cloner.deepClone(env), config.getMd5()); } catch (NoSuchEnvironmentException e) { result.badRequest(resourceNotFound("Environment", environmentName)); } return edit; }
Stage resultStage = lockAndRerunStage(identifier.getPipelineName(), identifier.getPipelineCounter(), identifier.getStageName(), (pipelineName, stageName, context) -> { StageConfig stageConfig = goConfigService.stageConfigNamed(identifier.getPipelineName(), identifier.getStageName()); String latestMd5 = goConfigService.getCurrentConfig().getMd5(); try { return instanceFactory.createStageForRerunOfJobs(stage, jobNames, context, stageConfig, timeProvider, latestMd5);
Pipeline schedulePipeline(final CaseInsensitiveString pipelineName, final BuildCause buildCause) { try { PipelineConfig pipelineConfig = goConfigService.pipelineConfigNamed(pipelineName); if (canSchedule(pipelineConfig)) { final Pipeline pipelineInstance = pipelineScheduleQueue.createPipeline(buildCause, pipelineConfig, schedulingContext(buildCause.getApprover(), pipelineConfig, pipelineConfig.first()), goConfigService.getCurrentConfig().getMd5(), timeProvider); serverHealthService.update(stageSchedulingSuccessfulState(pipelineName.toString(), CaseInsensitiveString.str(pipelineConfig.get(0).name()))); return pipelineInstance; } } catch (PipelineNotFoundException e) { LOGGER.error("Could not find pipeline {}", pipelineName, e); pipelineScheduleQueue.clearPipeline(pipelineName); } catch (CannotScheduleException e) { pipelineScheduleQueue.clearPipeline(pipelineName); serverHealthService.update(stageSchedulingFailedState(pipelineName.toString(), e)); } catch (Exception e) { LOGGER.error("Error while scheduling pipeline {}", pipelineName, e); pipelineScheduleQueue.clearPipeline(pipelineName); } return null; }