public <T> T loadAndPrintValidationErrors(InputStream inputStream, BiFunction<ConfigSchema, Boolean, T> resultHandler) throws IOException, SchemaLoaderException { ConvertableSchema<ConfigSchema> configSchema = SchemaLoader.loadConvertableSchemaFromYaml(inputStream); boolean valid = true; if (!configSchema.isValid()) { System.out.println("Found the following errors when parsing the configuration according to its version. (" + configSchema.getVersion() + ")"); configSchema.getValidationIssues().forEach(s -> System.out.println(s)); System.out.println(); valid = false; configSchema.clearValidationIssues(); } else { System.out.println("No errors found when parsing configuration according to its version. (" + configSchema.getVersion() + ")"); } ConfigSchema currentSchema = configSchema.convert(); if (!currentSchema.isValid()) { System.out.println("Found the following errors when converting configuration to latest version. (" + ConfigSchema.CONFIG_VERSION + ")"); currentSchema.getValidationIssues().forEach(s -> System.out.println(s)); System.out.println(); valid = false; } else if (configSchema.getVersion() == currentSchema.getVersion()) { System.out.println("Configuration was already latest version (" + ConfigSchema.CONFIG_VERSION + ") so no conversion was needed."); } else { System.out.println("No errors found when converting configuration to latest version. (" + ConfigSchema.CONFIG_VERSION + ")"); } return resultHandler.apply(currentSchema, valid); }
public <T> T loadAndPrintValidationErrors(InputStream inputStream, BiFunction<ConfigSchema, Boolean, T> resultHandler) throws IOException, SchemaLoaderException { ConvertableSchema<ConfigSchema> configSchema = SchemaLoader.loadConvertableSchemaFromYaml(inputStream); boolean valid = true; if (!configSchema.isValid()) { System.out.println("Found the following errors when parsing the configuration according to its version. (" + configSchema.getVersion() + ")"); configSchema.getValidationIssues().forEach(s -> System.out.println(s)); System.out.println(); valid = false; configSchema.clearValidationIssues(); } else { System.out.println("No errors found when parsing configuration according to its version. (" + configSchema.getVersion() + ")"); } ConfigSchema currentSchema = configSchema.convert(); if (!currentSchema.isValid()) { System.out.println("Found the following errors when converting configuration to latest version. (" + ConfigSchema.CONFIG_VERSION + ")"); currentSchema.getValidationIssues().forEach(s -> System.out.println(s)); System.out.println(); valid = false; } else if (configSchema.getVersion() == currentSchema.getVersion()) { System.out.println("Configuration was already latest version (" + ConfigSchema.CONFIG_VERSION + ") so no conversion was needed."); } else { System.out.println("No errors found when converting configuration to latest version. (" + ConfigSchema.CONFIG_VERSION + ")"); } return resultHandler.apply(currentSchema, valid); }
public Map<String, Object> toMap() { Map<String, Object> result = mapSupplier.get(); result.put(VERSION, getVersion()); putIfNotNull(result, FLOW_CONTROLLER_PROPS_KEY, flowControllerProperties); putIfNotNull(result, CORE_PROPS_KEY, coreProperties); putIfNotNull(result, FLOWFILE_REPO_KEY, flowfileRepositoryProperties); putIfNotNull(result, CONTENT_REPO_KEY, contentRepositoryProperties); putIfNotNull(result, PROVENANCE_REPO_KEY, provenanceRepositorySchema); putIfNotNull(result, COMPONENT_STATUS_REPO_KEY, componentStatusRepositoryProperties); putIfNotNull(result, SECURITY_PROPS_KEY, securityProperties); result.putAll(processGroupSchema.toMap()); putIfNotNull(result, PROVENANCE_REPORTING_KEY, provenanceReportingProperties); result.put(NIFI_PROPERTIES_OVERRIDES_KEY, nifiPropertiesOverrides); return result; }
@Test public void testCurrentVersion() throws IOException, SchemaLoaderException { ConfigSchema configSchema = getConfigSchema(c2Url + "?class=raspi3"); assertEquals(3, configSchema.getVersion()); assertEquals("raspi3.v2", configSchema.getFlowControllerProperties().getName()); }
@Test public void testVersion1() throws IOException, SchemaLoaderException { ConfigSchema configSchema = getConfigSchema(c2Url + "?class=raspi3&version=1"); assertEquals(3, configSchema.getVersion()); assertEquals("raspi3.v1", configSchema.getFlowControllerProperties().getName()); }
@Test public void testVersion2() throws IOException, SchemaLoaderException { ConfigSchema configSchema = getConfigSchema(c2Url + "?class=raspi3&version=2"); assertEquals(3, configSchema.getVersion()); assertEquals("raspi3.v2", configSchema.getFlowControllerProperties().getName()); }