ProcessEntityParser extends EntityParser<Process> { @Override public void validate(Process process) throws IvoryException { if(process.getTimezone() == null) process.setTimezone(TimeZone.getTimeZone("UTC")); Set<String> clusters = new HashSet<String>(); for (org.apache.ivory.entity.v0.process.Cluster cluster : process.getClusters().getClusters()) { String clusterName = cluster.getName(); if (!clusters.add(cluster.getName())) { throw new ValidationException("Cluster: " + cluster.getName() + " is defined more than once for process: "+process.getName()); } validateEntityExists(EntityType.CLUSTER, clusterName); validateProcessValidity(cluster.getValidity().getStart(), cluster.getValidity().getEnd()); validateHDFSpaths(process, clusterName); if (process.getInputs() != null) { for (Input input : process.getInputs().getInputs()) { validateEntityExists(EntityType.FEED, input.getFeed()); Feed feed = (Feed) ConfigurationStore.get().get(EntityType.FEED, input.getFeed()); CrossEntityValidations.validateFeedDefinedForCluster(feed, clusterName); CrossEntityValidations.validateFeedRetentionPeriod(input.getStart(), feed, clusterName); CrossEntityValidations.validateInstanceRange(process, input, feed); if (input.getPartition() != null) { CrossEntityValidations.validateInputPartition(input, feed); } } } if (process.getOutputs() != null) { for (Output output : process.getOutputs().getOutputs()) { validateEntityExists(EntityType.FEED, output.getFeed()); Feed feed = (Feed) ConfigurationStore.get().get(EntityType.FEED, output.getFeed()); CrossEntityValidations.validateFeedDefinedForCluster(feed, clusterName); CrossEntityValidations.validateInstance(process, output, feed); } } } validateDatasetName(process.getInputs(), process.getOutputs()); validateLateInputs(process); } ProcessEntityParser(); @Override void validate(Process process);  }
@Test public void testELExpressions() throws Exception { Process process = parser.parseAndValidate(getClass().getResourceAsStream(PROCESS_XML)); process.getInputs().getInputs().get(0).setStart("lastMonth(0,0,0)"); try { parser.validate(process); throw new AssertionError("Expected ValidationException!"); } catch (ValidationException e) { } process.getInputs().getInputs().get(0).setStart("today(0,0)"); process.getInputs().getInputs().get(0).setEnd("lastMonth(0,0,0)"); try { parser.validate(process); throw new AssertionError("Expected ValidationException!"); } catch (ValidationException e) { } process.getInputs().getInputs().get(0).setStart("today(2,0)"); process.getInputs().getInputs().get(0).setEnd("today(0,0)"); try { parser.validate(process); throw new AssertionError("Expected ValidationException!"); } catch (ValidationException e) { } }
@Test(expectedExceptions = ValidationException.class) public void applyValidationInvalidProcess() throws Exception { Process process = (Process) parser.parseAndValidate(getClass().getResourceAsStream(PROCESS_XML)); process.getClusters().getClusters().get(0).setName("invalid cluster"); parser.validate(process); }
@Test(expectedExceptions = IvoryException.class) public void testValidate() throws IvoryException { parser.parseAndValidate("<process></process>"); }
@Test(expectedExceptions = ValidationException.class) public void testInvalidProcessValidity() throws Exception { Process process = parser .parseAndValidate((ProcessEntityParserTest.class .getResourceAsStream(PROCESS_XML))); process.getClusters().getClusters().get(0).getValidity().setStart(SchemaHelper.parseDateUTC("2011-12-31T00:00Z")); parser.validate(process); }
@Test(expectedExceptions = ValidationException.class) public void testInvalidDependentFeedsRetentionLimit() throws Exception { Process process = parser .parseAndValidate((ProcessEntityParserTest.class .getResourceAsStream(PROCESS_XML))); process.getInputs().getInputs().get(0).setStart("today(-48,0)"); parser.validate(process); }
@Test(expectedExceptions = ValidationException.class) public void testDuplicateInputOutputNames() throws IvoryException { Process process = parser .parseAndValidate((ProcessEntityParserTest.class .getResourceAsStream(PROCESS_XML))); process.getInputs().getInputs().get(0).setName("duplicateName"); process.getOutputs().getOutputs().get(0).setName("duplicateName"); parser.validate(process); }
@Test(expectedExceptions=ValidationException.class) public void testDuplicateClusterName() throws Exception { Process process = parser .parse((ProcessEntityParserTest.class .getResourceAsStream(PROCESS_XML))); process.getClusters().getClusters().add(1, process.getClusters().getClusters().get(0)); parser.validate(process); }