PropertyValidator implements Validator { @Override public ValidationResult validateProperty(String property, ViewInstanceDefinition viewInstanceDefinition, ValidationContext validationContext) { if (property.equals(HIVE_SESSION_PARAMS)) { String auth = viewInstanceDefinition.getPropertyMap().get(HIVE_SESSION_PARAMS); if (auth != null && !auth.isEmpty()) { for(String param : auth.split(";")) { String[] keyvalue = param.split("="); if (keyvalue.length != 2) { return new InvalidPropertyValidationResult(false, "Can not parse session param " + param + " in " + auth); } } } } if (property.equals(USE_HIVE_INTERACTIVE_MODE)) { String value = viewInstanceDefinition.getPropertyMap().get(USE_HIVE_INTERACTIVE_MODE); if (!("true".equalsIgnoreCase(value) || "false".equalsIgnoreCase(value))) { return new InvalidPropertyValidationResult(false, "Must be 'true' or 'false'"); } } ClusterType clusterType = viewInstanceDefinition.getClusterType(); if (clusterType == ClusterType.LOCAL_AMBARI || clusterType == ClusterType.REMOTE_AMBARI) { return ValidationResult.SUCCESS; } if (property.equals(WEBHDFS_URL)) { String webhdfsUrl = viewInstanceDefinition.getPropertyMap().get(WEBHDFS_URL); if (!ValidatorUtils.validateHdfsURL(webhdfsUrl)) { return new InvalidPropertyValidationResult(false, "Must be valid URL"); } } if (property.equals(YARN_ATS_URL)) { String atsUrl = viewInstanceDefinition.getPropertyMap().get(YARN_ATS_URL); if (!ValidatorUtils.validateHttpURL(atsUrl)) { return new InvalidPropertyValidationResult(false, "Must be valid URL"); } } return ValidationResult.SUCCESS; }  @Override ValidationResult validateInstance(ViewInstanceDefinition viewInstanceDefinition, ValidationContext validationContext); @Override ValidationResult validateProperty(String property, ViewInstanceDefinition viewInstanceDefinition, ValidationContext validationContext); static final String WEBHDFS_URL; static final String HIVE_PORT; static final String YARN_ATS_URL; static final String HIVE_SESSION_PARAMS; static final String USE_HIVE_INTERACTIVE_MODE; }
@Test public void testValidatePropertyWebHDFSCom() throws Exception { PropertyValidator validator = new PropertyValidator(); ViewInstanceDefinition definition = getViewInstanceDefinition(); definition.getPropertyMap().put(PropertyValidator.WEBHDFS_URL, "hdfs: assertTrue(validator.validateProperty(PropertyValidator.WEBHDFS_URL, definition, Validator.ValidationContext.PRE_CREATE).isValid()); definition.getPropertyMap().put(PropertyValidator.WEBHDFS_URL, "webhdfs: assertTrue(validator.validateProperty(PropertyValidator.WEBHDFS_URL, definition, Validator.ValidationContext.PRE_CREATE).isValid()); definition.getPropertyMap().put(PropertyValidator.WEBHDFS_URL, "http: assertFalse(validator.validateProperty(PropertyValidator.WEBHDFS_URL, definition, Validator.ValidationContext.PRE_CREATE).isValid()); }
@Test public void testValidatePropertyWebHDFSInternal() throws Exception { PropertyValidator validator = new PropertyValidator(); ViewInstanceDefinition definition = getViewInstanceDefinition(); definition.getPropertyMap().put(PropertyValidator.WEBHDFS_URL, "hdfs: assertTrue(validator.validateProperty(PropertyValidator.WEBHDFS_URL, definition, Validator.ValidationContext.PRE_CREATE).isValid()); definition.getPropertyMap().put(PropertyValidator.WEBHDFS_URL, "webhdfs: assertTrue(validator.validateProperty(PropertyValidator.WEBHDFS_URL, definition, Validator.ValidationContext.PRE_CREATE).isValid()); definition.getPropertyMap().put(PropertyValidator.WEBHDFS_URL, "swebhdfs: assertTrue(validator.validateProperty(PropertyValidator.WEBHDFS_URL, definition, Validator.ValidationContext.PRE_CREATE).isValid()); definition.getPropertyMap().put(PropertyValidator.WEBHDFS_URL, "http: assertFalse(validator.validateProperty(PropertyValidator.WEBHDFS_URL, definition, Validator.ValidationContext.PRE_CREATE).isValid()); }
@Test public void testValidatePropertyATSCom() throws Exception { PropertyValidator validator = new PropertyValidator(); ViewInstanceDefinition definition = getViewInstanceDefinition(); definition.getPropertyMap().put(PropertyValidator.YARN_ATS_URL, "http: assertTrue(validator.validateProperty(PropertyValidator.YARN_ATS_URL, definition, Validator.ValidationContext.PRE_CREATE).isValid()); }
@Test public void testValidatePropertyATSInternal() throws Exception { PropertyValidator validator = new PropertyValidator(); ViewInstanceDefinition definition = getViewInstanceDefinition(); definition.getPropertyMap().put(PropertyValidator.YARN_ATS_URL, "http: assertTrue(validator.validateProperty(PropertyValidator.YARN_ATS_URL, definition, Validator.ValidationContext.PRE_CREATE).isValid()); }