public static ConfigSchema loadConfigSchemaFromYaml(Map<String, Object> yamlAsMap) throws SchemaLoaderException { return loadConvertableSchemaFromYaml(yamlAsMap).convert(); }
public static ConfigSchema loadConfigSchemaFromYaml(InputStream sourceStream) throws IOException, SchemaLoaderException { return loadConfigSchemaFromYaml(loadYamlAsMap(sourceStream)); }
public static ConvertableSchema<ConfigSchema> loadConvertableSchemaFromYaml(InputStream inputStream) throws SchemaLoaderException, IOException { return loadConvertableSchemaFromYaml(loadYamlAsMap(inputStream)); }
public ConfigSchema getConfigSchema(String urlString) throws IOException, SchemaLoaderException { HttpURLConnection urlConnection = openSuperUserUrlConnection(urlString); ConfigSchema configSchema; try (InputStream inputStream = urlConnection.getInputStream()) { configSchema = SchemaLoader.loadConfigSchemaFromYaml(inputStream); } finally { urlConnection.disconnect(); } return configSchema; }
protected ConfigSchema assertReturnCode(String query, SSLContext sslContext, int expectedReturnCode) throws Exception { HttpsURLConnection httpsURLConnection = openUrlConnection(C2_URL + query, sslContext); try { assertEquals(expectedReturnCode, httpsURLConnection.getResponseCode()); if (expectedReturnCode == 200) { return SchemaLoader.loadConfigSchemaFromYaml(httpsURLConnection.getInputStream()); } } finally { httpsURLConnection.disconnect(); } return null; }
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); }
ConvertableSchema<ConfigSchema> configSchema = SchemaLoader.loadConvertableSchemaFromYaml(new FileInputStream(configFile)); ConfigSchema currentSchema = configSchema.convert(); SecurityPropertiesSchema secProps = currentSchema.getSecurityProperties(); configSchema = SchemaLoader.loadConvertableSchemaFromYaml(new ByteBufferInputStream(bodyByteBuffer.duplicate())); ConfigSchema newSchema = configSchema.convert(); newSchema.setSecurityProperties(secProps);
public static void transformConfigFile(InputStream sourceStream, String destPath) throws Exception { ConvertableSchema<ConfigSchema> convertableSchema = throwIfInvalid(SchemaLoader.loadConvertableSchemaFromYaml(sourceStream)); ConfigSchema configSchema = throwIfInvalid(convertableSchema.convert()); // Create nifi.properties and flow.xml.gz in memory ByteArrayOutputStream nifiPropertiesOutputStream = new ByteArrayOutputStream(); writeNiFiProperties(configSchema, nifiPropertiesOutputStream); writeFlowXmlFile(configSchema, destPath); // Write nifi.properties and flow.xml.gz writeNiFiPropertiesFile(nifiPropertiesOutputStream, destPath); }