@Override public void copyErrorsTo(CruiseConfig to) { copyErrors(this, to); }
protected boolean isValidForCreateOrUpdate(CruiseConfig preprocessedConfig) { preprocessedProfile = findExistingProfile(preprocessedConfig); preprocessedProfile.validateTree(null); if (preprocessedProfile.getAllErrors().isEmpty()) { getPluginProfiles(preprocessedConfig).validate(null); BasicCruiseConfig.copyErrors(preprocessedProfile, profile); return preprocessedProfile.getAllErrors().isEmpty(); } BasicCruiseConfig.copyErrors(preprocessedProfile, profile); return false; }
protected boolean isValid(CruiseConfig preprocessedConfig, boolean isTemplateBeingCreated) { TemplatesConfig templatesConfig = preprocessedConfig.getTemplates(); preprocessedTemplateConfig = findAddedTemplate(preprocessedConfig); preprocessedTemplateConfig.validateTree(ConfigSaveValidationContext.forChain(preprocessedConfig, templatesConfig), preprocessedConfig, isTemplateBeingCreated); if(preprocessedTemplateConfig.getAllErrors().isEmpty()) { templatesConfig.validate(null); BasicCruiseConfig.copyErrors(preprocessedTemplateConfig, templateConfig); return preprocessedTemplateConfig.getAllErrors().isEmpty() && templatesConfig.errors().isEmpty(); } BasicCruiseConfig.copyErrors(preprocessedTemplateConfig, templateConfig); return false; }
@Override public boolean isValid(CruiseConfig preprocessedConfig) { preprocessedPipelineConfigs = findPipelineConfigs(preprocessedConfig, group); authorization.validateTree(new DelegatingValidationContext(ConfigSaveValidationContext.forChain(preprocessedConfig, preprocessedPipelineConfigs)) { @Override public boolean shouldNotCheckRole() { return false; } }); if (!authorization.getAllErrors().isEmpty()) { BasicCruiseConfig.copyErrors(authorization, preprocessedPipelineConfigs.getAuthorization()); return false; } return true; }
@Override public boolean isValid(CruiseConfig preprocessedConfig) { SCMs scms = preprocessedConfig.getSCMs(); preprocessedGlobalScmConfig = scms.find(globalScmConfig.getSCMId()); preprocessedGlobalScmConfig.validate(null); if (preprocessedGlobalScmConfig.getAllErrors().isEmpty()) { scms.validate(null); boolean isValid = pluggableScmService.isValid(preprocessedGlobalScmConfig); BasicCruiseConfig.copyErrors(preprocessedGlobalScmConfig, globalScmConfig); return preprocessedGlobalScmConfig.getAllErrors().isEmpty() && scms.errors().isEmpty() && isValid; } BasicCruiseConfig.copyErrors(preprocessedGlobalScmConfig, globalScmConfig); return false; }
@Override public boolean isValid(CruiseConfig preprocessedConfig) { preprocessedRole = preprocessedConfig.server().security().getRoles().findByNameAndType(role.getName(), role.getClass()); if (!preprocessedRole.validateTree(RolesConfigUpdateValidator.validationContextWithSecurityConfig(preprocessedConfig))) { BasicCruiseConfig.copyErrors(preprocessedRole, role); return false; } return true; }
public boolean isValid(CruiseConfig preprocessedConfig, String repositoryId) { PackageRepositories packageRepositories = preprocessedConfig.getPackageRepositories(); PackageRepository repository = packageRepositories.find(repositoryId); Packages packages = repository.getPackages(); preprocessedPackageDefinition = packages.find(this.packageDefinition.getId()); preprocessedPackageDefinition.validate(null); if (preprocessedPackageDefinition.getAllErrors().isEmpty()) { packageRepositories.validate(null); packages.validate(null); packageDefinitionService.validatePackageConfiguration(preprocessedPackageDefinition); BasicCruiseConfig.copyErrors(preprocessedPackageDefinition, packageDefinition); return preprocessedPackageDefinition.getAllErrors().isEmpty() && result.isSuccessful(); } BasicCruiseConfig.copyErrors(preprocessedPackageDefinition, packageDefinition); return false; }
@Override public boolean isValid(CruiseConfig preprocessedConfig) { preprocessedAdmin = preprocessedConfig.server().security().adminsConfig(); if (!preprocessedAdmin.validateTree(ConfigSaveValidationContext.forChain(preprocessedConfig))) { BasicCruiseConfig.copyErrors(preprocessedAdmin, admin); return false; } return true; }
@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(); }
@Override public boolean isValid(CruiseConfig preprocessedConfig) { TemplatesConfig templates = preprocessedConfig.getTemplates(); preprocessedTemplateConfig = findAddedTemplate(preprocessedConfig); preprocessedTemplateConfig.getAuthorization().validateTree(new DelegatingValidationContext(ConfigSaveValidationContext.forChain(preprocessedConfig, templates)) { @Override public boolean shouldNotCheckRole() { return false; } }); if (!preprocessedTemplateConfig.getAuthorization().getAllErrors().isEmpty()) { BasicCruiseConfig.copyErrors(preprocessedTemplateConfig.getAuthorization(), authorization); return false; } return true; } }
@Override public boolean isValid(CruiseConfig preprocessedConfig) { validateConfigRepoId(this.configRepo); validateConfigRepoPluginId(this.configRepo); if (!this.configRepo.errors().isEmpty()) { return false; } preprocessedConfigRepo = preprocessedConfig.getConfigRepos().getConfigRepo(this.configRepo.getId()); if (!preprocessedConfigRepo.validateTree(new ConfigSaveValidationContext(preprocessedConfig))) { BasicCruiseConfig.copyErrors(preprocessedConfigRepo, configRepo); return false; } return true; }
@Test public void shouldNotTryAndCopyErrorsFromAnObjectWithANullField() throws Exception { AValidatableObjectWithAField badObjectWithNullField = new AValidatableObjectWithAField(null); badObjectWithNullField.addError("blah", "Bad"); AValidatableObjectWithAField goodObjectWithNonNullField = new AValidatableObjectWithAField(new SomeOtherObject("1")); BasicCruiseConfig.copyErrors(badObjectWithNullField, goodObjectWithNonNullField); assertThat(goodObjectWithNonNullField.errors().getAll().size(), is(1)); assertThat(goodObjectWithNonNullField.errors().firstError(), is("Bad")); }
@Test public void shouldCopyErrorsToCorrectObjectBasedOnEqualityRatherThanIndex() { AValidatableObjectWithAList badObjectWith2ObjectsInList = new AValidatableObjectWithAList(); SomeOtherObject soo1 = new SomeOtherObject("1"); soo1.addError("a", "b"); badObjectWith2ObjectsInList.add(soo1); SomeOtherObject soo2 = new SomeOtherObject("2"); soo2.addError("x", "y"); badObjectWith2ObjectsInList.add(soo2); AValidatableObjectWithAList goodObjectWith2ObjectsInList = new AValidatableObjectWithAList(); goodObjectWith2ObjectsInList.add(new SomeOtherObject("2")); BasicCruiseConfig.copyErrors(badObjectWith2ObjectsInList, goodObjectWith2ObjectsInList); assertThat(goodObjectWith2ObjectsInList.getSomeOtherObjectList().size(), is(1)); assertThat(goodObjectWith2ObjectsInList.getSomeOtherObjectList().get(0).errors().getAll().size(), is(1)); assertThat(goodObjectWith2ObjectsInList.getSomeOtherObjectList().get(0).errors().firstError(), is("y")); }
@Test public void shouldCopyErrorsForFieldsOnPipelineConfig(){ PipelineConfig pipelineConfig = PipelineConfigMother.pipelineConfig("pipeline", MaterialConfigsMother.defaultMaterialConfigs(), new JobConfigs(JobConfigMother.createJobConfigWithJobNameAndEmptyResources())); pipelineConfig.setVariables(new EnvironmentVariablesConfig(asList(new EnvironmentVariableConfig("name", "value")))); PipelineConfig pipelineWithErrors = new Cloner().deepClone(pipelineConfig); pipelineWithErrors.getVariables().get(0).addError("name", "error on environment variable"); pipelineWithErrors.first().addError("name", "error on stage"); pipelineWithErrors.first().getJobs().first().addError("name", "error on job"); BasicCruiseConfig.copyErrors(pipelineWithErrors, pipelineConfig); assertThat(pipelineConfig.getVariables().get(0).errors().on("name"), is("error on environment variable")); assertThat(pipelineConfig.first().errors().on("name"), is("error on stage")); assertThat(pipelineConfig.first().getJobs().first().errors().on("name"), is("error on job")); }
setMD5(md5, badConfig); Validatable node = updatedConfigResolver.getNode(command, updateCommand.cruiseConfig()); BasicCruiseConfig.copyErrors(command.updatedNode(badConfig), node); result.badRequest("Save failed, see errors below"); return new ConfigUpdateResponse(badConfig, node, subjectFromNode(command, updatedConfigResolver, node), updateCommand, null);