@Test public final void test_isValidConfigs_failures() { assertTrue(_validator.isValidConfigs(null, null, _failures)); assertTrue(_failures.isEmpty()); Object[][] config_def_data_bad = new Object[][] { { null, null, "" }, { 1L, "security", "blah" }, { 1L, "port", "int" }, { 2L, "security", "string" }, { 3L, "timeout", "enum", "units", null }, { 4L, "auth", "enum", "authentication-type", "dimple" }, }; List<RangerServiceConfigDef> configs = _utils.createServiceDefConfigs(config_def_data_bad); List<RangerEnumDef> enumDefs = _utils.createEnumDefs(enums_good); assertFalse(_validator.isValidConfigs(configs, enumDefs, _failures)); _utils.checkFailureForMissingValue(_failures, "config def name"); _utils.checkFailureForMissingValue(_failures, "config def itemId"); _utils.checkFailureForMissingValue(_failures, "config def type"); _utils.checkFailureForSemanticError(_failures, "config def name", "security"); _utils.checkFailureForSemanticError(_failures, "config def itemId", "1"); _utils.checkFailureForSemanticError(_failures, "config def type", "security"); _utils.checkFailureForSemanticError(_failures, "config def subtype", "timeout"); _utils.checkFailureForSemanticError(_failures, "config def default value", "auth"); }
boolean isValidConfigs(List<RangerServiceConfigDef> configs, List<RangerEnumDef> enumDefs, List<ValidationFailureDetails> failures) { if(LOG.isDebugEnabled()) { LOG.debug(String.format("==> RangerServiceDefValidator.isValidConfigs(%s, %s, %s)", configs, enumDefs, failures)); } boolean valid = true; if (CollectionUtils.isEmpty(configs)) { LOG.debug("Configs collection was null/empty! ok"); } else { Set<Long> ids = new HashSet<Long>(configs.size()); Set<String> names = new HashSet<String>(configs.size()); for (RangerServiceConfigDef aConfig : configs) { valid = isUnique(aConfig.getItemId(), ids, "config def itemId", "config defs", failures) && valid; String configName = aConfig.getName(); valid = isUnique(configName, names, "config def name", "config defs", failures) && valid; String type = aConfig.getType(); valid = isValidConfigType(type, configName, failures) && valid; if ("enum".equals(type)) { valid = isValidConfigOfEnumType(aConfig, enumDefs, failures) && valid; } } } if(LOG.isDebugEnabled()) { LOG.debug(String.format("<== RangerServiceDefValidator.isValidConfigs(%s, %s, %s): %s", configs, enumDefs, failures, valid)); } return valid; }
RangerServiceDefValidator extends RangerValidator { boolean isValidConfigs(List<RangerServiceConfigDef> configs, List<RangerEnumDef> enumDefs, List<ValidationFailureDetails> failures) { if(LOG.isDebugEnabled()) { LOG.debug(String.format("==> RangerServiceDefValidator.isValidConfigs(%s, %s, %s)", configs, enumDefs, failures)); } boolean valid = true; if (CollectionUtils.isEmpty(configs)) { LOG.debug("Configs collection was null/empty! ok"); } else { Set<Long> ids = new HashSet<Long>(configs.size()); Set<String> names = new HashSet<String>(configs.size()); for (RangerServiceConfigDef aConfig : configs) { valid = isUnique(aConfig.getItemId(), ids, "config def itemId", "config defs", failures) && valid; String configName = aConfig.getName(); valid = isUnique(configName, names, "config def name", "config defs", failures) && valid; String type = aConfig.getType(); valid = isValidConfigType(type, configName, failures) && valid; if ("enum".equals(type)) { valid = isValidConfigOfEnumType(aConfig, enumDefs, failures) && valid; } } } if(LOG.isDebugEnabled()) { LOG.debug(String.format("<== RangerServiceDefValidator.isValidConfigs(%s, %s, %s): %s", configs, enumDefs, failures, valid)); } return valid; } }
RangerServiceDefValidator extends RangerValidator { boolean isValidConfigs(List<RangerServiceConfigDef> configs, List<RangerEnumDef> enumDefs, List<ValidationFailureDetails> failures) { if(LOG.isDebugEnabled()) { LOG.debug(String.format("==> RangerServiceDefValidator.isValidConfigs(%s, %s, %s)", configs, enumDefs, failures)); } boolean valid = true; if (CollectionUtils.isEmpty(configs)) { LOG.debug("Configs collection was null/empty! ok"); } else { Set<Long> ids = new HashSet<Long>(configs.size()); Set<String> names = new HashSet<String>(configs.size()); for (RangerServiceConfigDef aConfig : configs) { valid = isUnique(aConfig.getItemId(), ids, "config def itemId", "config defs", failures) && valid; String configName = aConfig.getName(); valid = isUnique(configName, names, "config def name", "config defs", failures) && valid; String type = aConfig.getType(); valid = isValidConfigType(type, configName, failures) && valid; if ("enum".equals(type)) { valid = isValidConfigOfEnumType(aConfig, enumDefs, failures) && valid; } } } if(LOG.isDebugEnabled()) { LOG.debug(String.format("<== RangerServiceDefValidator.isValidConfigs(%s, %s, %s): %s", configs, enumDefs, failures, valid)); } return valid; } RangerServiceDefValidator(ServiceStore store); }
RangerServiceDefValidator extends RangerValidator { boolean isValidConfigs(List<RangerServiceConfigDef> configs, List<RangerEnumDef> enumDefs, List<ValidationFailureDetails> failures) { if(LOG.isDebugEnabled()) { LOG.debug(String.format("==> RangerServiceDefValidator.isValidConfigs(%s, %s, %s)", configs, enumDefs, failures)); } boolean valid = true; if (CollectionUtils.isEmpty(configs)) { LOG.debug("Configs collection was null/empty! ok"); } else { Set<Long> ids = new HashSet<Long>(configs.size()); Set<String> names = new HashSet<String>(configs.size()); for (RangerServiceConfigDef aConfig : configs) { valid = isUnique(aConfig.getItemId(), ids, "config def itemId", "config defs", failures) && valid; String configName = aConfig.getName(); valid = isUnique(configName, names, "config def name", "config defs", failures) && valid; String type = aConfig.getType(); valid = isValidConfigType(type, configName, failures) && valid; if ("enum".equals(type)) { valid = isValidConfigOfEnumType(aConfig, enumDefs, failures) && valid; } } } if(LOG.isDebugEnabled()) { LOG.debug(String.format("<== RangerServiceDefValidator.isValidConfigs(%s, %s, %s): %s", configs, enumDefs, failures, valid)); } return valid; } RangerServiceDefValidator(ServiceStore store); void validate(final RangerServiceDef serviceDef, final Action action); boolean isValidResources(RangerServiceDef serviceDef, List<ValidationFailureDetails> failures, final Action action); }
RangerServiceDefValidator extends RangerValidator { boolean isValidConfigs(List<RangerServiceConfigDef> configs, List<RangerEnumDef> enumDefs, List<ValidationFailureDetails> failures) { if(LOG.isDebugEnabled()) { LOG.debug(String.format("==> RangerServiceDefValidator.isValidConfigs(%s, %s, %s)", configs, enumDefs, failures)); } boolean valid = true; if (CollectionUtils.isEmpty(configs)) { LOG.debug("Configs collection was null/empty! ok"); } else { Set<Long> ids = new HashSet<Long>(configs.size()); Set<String> names = new HashSet<String>(configs.size()); for (RangerServiceConfigDef aConfig : configs) { valid = isUnique(aConfig.getItemId(), ids, "config def itemId", "config defs", failures) && valid; String configName = aConfig.getName(); valid = isUnique(configName, names, "config def name", "config defs", failures) && valid; String type = aConfig.getType(); valid = isValidConfigType(type, configName, failures) && valid; if ("enum".equals(type)) { valid = isValidConfigOfEnumType(aConfig, enumDefs, failures) && valid; } } } if(LOG.isDebugEnabled()) { LOG.debug(String.format("<== RangerServiceDefValidator.isValidConfigs(%s, %s, %s): %s", configs, enumDefs, failures, valid)); } return valid; } RangerServiceDefValidator(ServiceStore store); void validate(final RangerServiceDef serviceDef, final Action action); boolean isValidResources(RangerServiceDef serviceDef, List<ValidationFailureDetails> failures, final Action action);  }