public ConfigUpdateResponse updateConfigFromUI( final UpdateConfigFromUI command, final String md5, Username username, final LocalizedOperationResult result) { UiBasedConfigUpdateCommand updateCommand = new UiBasedConfigUpdateCommand(md5, command, result, cachedGoPartials); UpdatedNodeSubjectResolver updatedConfigResolver = new UpdatedNodeSubjectResolver(); try { ConfigSaveState configSaveState = updateConfig(updateCommand); return latestUpdateResponse( command, updateCommand, updatedConfigResolver, clonedConfigForEdit(), configSaveState); } catch (ConfigFileHasChangedException e) { CruiseConfig updatedConfig = handleMergeException(md5, updateCommand); result.conflict(LocalizedMessage.string("SAVE_FAILED_WITH_REASON", e.getMessage())); return latestUpdateResponse( command, updateCommand, new OldNodeSubjectResolver(), updatedConfig, null); } catch (ConfigUpdateCheckFailedException e) { // result is already set } catch (Exception e) { ConfigMergeException mergeException = ExceptionUtils.getCause(e, ConfigMergeException.class); ConfigMergePostValidationException mergePostValidationException = ExceptionUtils.getCause(e, ConfigMergePostValidationException.class); if (mergeException != null || mergePostValidationException != null) { CruiseConfig updatedConfig = handleMergeException(md5, updateCommand); result.conflict(LocalizedMessage.string("SAVE_FAILED_WITH_REASON", e.getMessage())); return latestUpdateResponse( command, updateCommand, new OldNodeSubjectResolver(), updatedConfig, null); } GoConfigInvalidException ex = ExceptionUtils.getCause(e, GoConfigInvalidException.class); if (ex != null) { CruiseConfig badConfig = ex.getCruiseConfig(); setMD5(md5, badConfig); Validatable node = updatedConfigResolver.getNode(command, updateCommand.cruiseConfig()); BasicCruiseConfig.copyErrors(command.updatedNode(badConfig), node); result.badRequest(LocalizedMessage.string("SAVE_FAILED")); return new ConfigUpdateResponse( badConfig, node, subjectFromNode(command, updatedConfigResolver, node), updateCommand, null); } else { result.badRequest(LocalizedMessage.string("SAVE_FAILED_WITH_REASON", e.getMessage())); } } CruiseConfig newConfigSinceNoOtherConfigExists = clonedConfigForEdit(); setMD5(md5, newConfigSinceNoOtherConfigExists); return latestUpdateResponse( command, updateCommand, new OldNodeSubjectResolver(), newConfigSinceNoOtherConfigExists, null); }
@Override public boolean isValid(CruiseConfig preprocessedConfig) { preprocessedPipelineConfig = preprocessedConfig.getPipelineConfigByName(pipelineConfig.name()); boolean isValid = preprocessedPipelineConfig.validateTree( PipelineConfigSaveValidationContext.forChain( true, groupName, preprocessedConfig, preprocessedPipelineConfig)); if (!isValid) BasicCruiseConfig.copyErrors(preprocessedPipelineConfig, pipelineConfig); return isValid; }
@Override public boolean isValid(CruiseConfig preprocessedConfig) { PackageRepositories repositories = preprocessedConfig.getPackageRepositories(); this.preprocessedRepository = repositories.find(this.repository.getRepoId()); preprocessedRepository.validate(null); repositories.validate(null); boolean isValidConfiguration = packageRepositoryService.validatePluginId(preprocessedRepository) && packageRepositoryService.validateRepositoryConfiguration(preprocessedRepository); BasicCruiseConfig.copyErrors(preprocessedRepository, this.repository); return getAllErrors(this.repository).isEmpty() && isValidConfiguration && result.isSuccessful(); }