Java源码示例:org.apache.nifi.properties.NiFiPropertiesLoader
示例1
/**
* Demonstrates reading values from nifi.properties
* @throws Exception
*/
@Test
public void testPropertiesJavascript() throws Exception {
final TestRunner runner = TestRunners.newTestRunner(new ExecuteScript());
System.setProperty(NiFiProperties.PROPERTIES_FILE_PATH, "src/test/resources/executescript/properties/nifi.properties");
NiFiPropertiesLoader nifiPropertiesLoader = new NiFiPropertiesLoader();
NiFiProperties nifiProperties = nifiPropertiesLoader.get();
runner.setValidateExpressionUsage(false);
runner.setProperty(SCRIPT_ENGINE, "ECMAScript");
runner.setProperty(ScriptingComponentUtils.SCRIPT_FILE, "src/test/resources/executescript/properties/properties.js");
runner.setProperty(ScriptingComponentUtils.MODULES, "src/test/resources/executescript");
runner.assertValid();
final Map<String, String> attributes = new HashMap<>();
attributes.put("property-name", "nifi.version");
runner.enqueue("sample text".getBytes(StandardCharsets.UTF_8), attributes);
runner.run();
runner.assertAllFlowFilesTransferred("success", 1);
final List<MockFlowFile> successFlowFiles = runner.getFlowFilesForRelationship("success");
MockFlowFile result = successFlowFiles.get(0);
result.assertAttributeEquals("property-value", nifiProperties.getProperty("nifi.version"));
}
示例2
/**
* Demonstrates reading values from nifi.properties
* @throws Exception
*/
@Test
public void testPropertiesPython() throws Exception {
final TestRunner runner = TestRunners.newTestRunner(new ExecuteScript());
System.setProperty(NiFiProperties.PROPERTIES_FILE_PATH, "src/test/resources/executescript/properties/nifi.properties");
NiFiPropertiesLoader nifiPropertiesLoader = new NiFiPropertiesLoader();
NiFiProperties nifiProperties = nifiPropertiesLoader.get();
runner.setValidateExpressionUsage(false);
runner.setProperty(SCRIPT_ENGINE, "python");
runner.setProperty(ScriptingComponentUtils.SCRIPT_FILE, "src/test/resources/executescript/properties/properties.py");
runner.setProperty(ScriptingComponentUtils.MODULES, "src/test/resources/executescript");
runner.assertValid();
final Map<String, String> attributes = new HashMap<>();
attributes.put("property-name", "nifi.version");
runner.enqueue("sample text".getBytes(StandardCharsets.UTF_8), attributes);
runner.run();
runner.assertAllFlowFilesTransferred("success", 1);
final List<MockFlowFile> successFlowFiles = runner.getFlowFilesForRelationship("success");
MockFlowFile result = successFlowFiles.get(0);
result.assertAttributeEquals("property-value", nifiProperties.getProperty("nifi.version"));
}
示例3
private static boolean isEncryptionAvailable() {
if (encryptionPropertiesRead) {
return isEncryptionAvailable;
} else {
try {
NiFiProperties niFiProperties = NiFiPropertiesLoader.loadDefaultWithKeyFromBootstrap();
isEncryptionAvailable = RepositoryEncryptorUtils.isRepositoryEncryptionConfigured(niFiProperties, RepositoryType.PROVENANCE);
encryptionPropertiesRead = true;
} catch (IOException e) {
logger.error("Encountered an error checking the provenance repository encryption configuration: ", e);
isEncryptionAvailable = false;
}
return isEncryptionAvailable;
}
}
示例4
private static SecretKey getMasterKey() throws KeyManagementException {
try {
// Get the master encryption key from bootstrap.conf
String masterKeyHex = NiFiPropertiesLoader.extractKeyFromBootstrapFile();
return new SecretKeySpec(Hex.decodeHex(masterKeyHex.toCharArray()), "AES");
} catch (IOException | DecoderException e) {
logger.error("Encountered an error: ", e);
throw new KeyManagementException(e);
}
}
示例5
private static String getMasterKey() throws IOException {
return NiFiPropertiesLoader.extractKeyFromBootstrapFile();
}
示例6
private static String getMasterKey() throws IOException {
return NiFiPropertiesLoader.extractKeyFromBootstrapFile();
}
示例7
private static String getMasterKey() throws IOException {
return NiFiPropertiesLoader.extractKeyFromBootstrapFile();
}