use of org.apache.nifi.registry.VariableRegistry in project nifi by apache.
the class TestValueLookup method testCreateCustomVariableRegistry.
@Test
@SuppressWarnings("unchecked")
public void testCreateCustomVariableRegistry() {
final VariableRegistry variableRegistry = VariableRegistry.ENVIRONMENT_SYSTEM_REGISTRY;
final ValueLookup initialLookup = new ValueLookup(variableRegistry, null);
assertTrue(initialLookup.containsKey("PATH"));
assertFalse(initialLookup.containsKey("fake.property.3"));
assertFalse(initialLookup.containsKey("fake"));
final Map<String, String> otherAttrs = new HashMap<>();
otherAttrs.put("fake", "test");
otherAttrs.put("fake.property.3", "test me out 3, test me out 4");
final ValueLookup newLookup = new ValueLookup(variableRegistry, null, otherAttrs);
assertTrue(newLookup.containsKey("PATH"));
assertTrue(newLookup.containsKey("fake.property.3"));
assertEquals("test me out 3, test me out 4", newLookup.get("fake.property.3"));
assertEquals("test", newLookup.get("fake"));
assertFalse(newLookup.containsKey("filename"));
final FlowFile fakeFile = createFlowFile();
final ValueLookup ffLookup = new ValueLookup(variableRegistry, fakeFile, otherAttrs);
assertTrue(ffLookup.containsKey("filename"));
assertEquals("test", ffLookup.get("fake"));
assertEquals("1", ffLookup.get("flowFileId"));
assertEquals("50", ffLookup.get("fileSize"));
assertEquals("1000", ffLookup.get("entryDate"));
assertEquals("10000", ffLookup.get("lineageStartDate"));
assertEquals("fakefile.txt", ffLookup.get("filename"));
final Map<String, String> overrides = new HashMap<>();
overrides.put("fake", "the real deal");
final ValueLookup overriddenLookup = new ValueLookup(variableRegistry, fakeFile, overrides, otherAttrs);
assertTrue(overriddenLookup.containsKey("filename"));
assertEquals("the real deal", overriddenLookup.get("fake"));
assertEquals("1", overriddenLookup.get("flowFileId"));
assertEquals("50", overriddenLookup.get("fileSize"));
assertEquals("1000", overriddenLookup.get("entryDate"));
assertEquals("10000", overriddenLookup.get("lineageStartDate"));
assertEquals("fakefile.txt", overriddenLookup.get("filename"));
assertEquals("original", overriddenLookup.get("override me"));
final Map<String, String> newOverrides = new HashMap<>();
newOverrides.put("fake", "the real deal");
newOverrides.put("override me", "done you are now overridden");
final ValueLookup newOverriddenLookup = new ValueLookup(variableRegistry, fakeFile, newOverrides, otherAttrs);
assertTrue(newOverriddenLookup.containsKey("filename"));
assertEquals("the real deal", newOverriddenLookup.get("fake"));
assertEquals("1", newOverriddenLookup.get("flowFileId"));
assertEquals("50", newOverriddenLookup.get("fileSize"));
assertEquals("1000", newOverriddenLookup.get("entryDate"));
assertEquals("10000", newOverriddenLookup.get("lineageStartDate"));
assertEquals("fakefile.txt", newOverriddenLookup.get("filename"));
assertEquals("done you are now overridden", newOverriddenLookup.get("override me"));
}
use of org.apache.nifi.registry.VariableRegistry in project nifi by apache.
the class StandardFlowSerializer method addProcessGroup.
private void addProcessGroup(final Element parentElement, final ProcessGroup group, final String elementName, final ScheduledStateLookup scheduledStateLookup) {
final Document doc = parentElement.getOwnerDocument();
final Element element = doc.createElement(elementName);
parentElement.appendChild(element);
addTextElement(element, "id", group.getIdentifier());
addTextElement(element, "versionedComponentId", group.getVersionedComponentId());
addTextElement(element, "name", group.getName());
addPosition(element, group.getPosition());
addTextElement(element, "comment", group.getComments());
final VersionControlInformation versionControlInfo = group.getVersionControlInformation();
if (versionControlInfo != null) {
final Element versionControlInfoElement = doc.createElement("versionControlInformation");
addTextElement(versionControlInfoElement, "registryId", versionControlInfo.getRegistryIdentifier());
addTextElement(versionControlInfoElement, "bucketId", versionControlInfo.getBucketIdentifier());
addTextElement(versionControlInfoElement, "bucketName", versionControlInfo.getBucketName());
addTextElement(versionControlInfoElement, "flowId", versionControlInfo.getFlowIdentifier());
addTextElement(versionControlInfoElement, "flowName", versionControlInfo.getFlowName());
addTextElement(versionControlInfoElement, "flowDescription", versionControlInfo.getFlowDescription());
addTextElement(versionControlInfoElement, "version", versionControlInfo.getVersion());
element.appendChild(versionControlInfoElement);
}
for (final ProcessorNode processor : group.getProcessors()) {
addProcessor(element, processor, scheduledStateLookup);
}
if (group.isRootGroup()) {
for (final Port port : group.getInputPorts()) {
addRootGroupPort(element, (RootGroupPort) port, "inputPort", scheduledStateLookup);
}
for (final Port port : group.getOutputPorts()) {
addRootGroupPort(element, (RootGroupPort) port, "outputPort", scheduledStateLookup);
}
} else {
for (final Port port : group.getInputPorts()) {
addPort(element, port, "inputPort", scheduledStateLookup);
}
for (final Port port : group.getOutputPorts()) {
addPort(element, port, "outputPort", scheduledStateLookup);
}
}
for (final Label label : group.getLabels()) {
addLabel(element, label);
}
for (final Funnel funnel : group.getFunnels()) {
addFunnel(element, funnel);
}
for (final ProcessGroup childGroup : group.getProcessGroups()) {
addProcessGroup(element, childGroup, "processGroup", scheduledStateLookup);
}
for (final RemoteProcessGroup remoteRef : group.getRemoteProcessGroups()) {
addRemoteProcessGroup(element, remoteRef, scheduledStateLookup);
}
for (final Connection connection : group.getConnections()) {
addConnection(element, connection);
}
for (final ControllerServiceNode service : group.getControllerServices(false)) {
addControllerService(element, service);
}
for (final Template template : group.getTemplates()) {
addTemplate(element, template);
}
final VariableRegistry variableRegistry = group.getVariableRegistry();
for (final Map.Entry<VariableDescriptor, String> entry : variableRegistry.getVariableMap().entrySet()) {
addVariable(element, entry.getKey().getName(), entry.getValue());
}
}
use of org.apache.nifi.registry.VariableRegistry in project nifi by apache.
the class StandardFlowSerializerTest method setUp.
@Before
public void setUp() throws Exception {
final FlowFileEventRepository flowFileEventRepo = Mockito.mock(FlowFileEventRepository.class);
final AuditService auditService = Mockito.mock(AuditService.class);
final Map<String, String> otherProps = new HashMap<>();
otherProps.put(NiFiProperties.PROVENANCE_REPO_IMPLEMENTATION_CLASS, MockProvenanceRepository.class.getName());
otherProps.put("nifi.remote.input.socket.port", "");
otherProps.put("nifi.remote.input.secure", "");
final NiFiProperties nifiProperties = NiFiProperties.createBasicNiFiProperties(propsFile, otherProps);
final StringEncryptor encryptor = StringEncryptor.createEncryptor(nifiProperties);
// use the system bundle
systemBundle = SystemBundle.create(nifiProperties);
ExtensionManager.discoverExtensions(systemBundle, Collections.emptySet());
final AbstractPolicyBasedAuthorizer authorizer = new MockPolicyBasedAuthorizer();
final VariableRegistry variableRegistry = new FileBasedVariableRegistry(nifiProperties.getVariableRegistryPropertiesPaths());
final BulletinRepository bulletinRepo = Mockito.mock(BulletinRepository.class);
controller = FlowController.createStandaloneInstance(flowFileEventRepo, nifiProperties, authorizer, auditService, encryptor, bulletinRepo, variableRegistry, Mockito.mock(FlowRegistryClient.class));
serializer = new StandardFlowSerializer(encryptor);
}
use of org.apache.nifi.registry.VariableRegistry in project nifi by apache.
the class TestFileBasedVariableRegistry method testCreateCustomVariableRegistry.
@Test
public void testCreateCustomVariableRegistry() {
final Path fooPath = Paths.get("src/test/resources/TestVariableRegistry/foobar.properties");
final Path testPath = Paths.get("src/test/resources/TestVariableRegistry/test.properties");
Path[] paths = { fooPath, testPath };
final String vendorUrl = System.getProperty("java.vendor.url");
VariableRegistry variableRegistry = new FileBasedVariableRegistry(paths);
final Map<VariableDescriptor, String> variables = variableRegistry.getVariableMap();
assertTrue(variables.containsKey(new VariableDescriptor("fake.property.3")));
assertEquals(vendorUrl, variableRegistry.getVariableValue("java.vendor.url"));
assertEquals("test me out 3, test me out 4", variableRegistry.getVariableValue("fake.property.3"));
}
use of org.apache.nifi.registry.VariableRegistry in project nifi-minifi by apache.
the class MiNiFiServer method start.
public void start() {
try {
logger.info("Loading Flow...");
FlowFileEventRepository flowFileEventRepository = new RingBufferEventRepository(5);
AuditService auditService = new StandardAuditService();
Authorizer authorizer = new Authorizer() {
@Override
public AuthorizationResult authorize(AuthorizationRequest request) throws AuthorizationAccessException {
return AuthorizationResult.approved();
}
@Override
public void initialize(AuthorizerInitializationContext initializationContext) throws AuthorizerCreationException {
// do nothing
}
@Override
public void onConfigured(AuthorizerConfigurationContext configurationContext) throws AuthorizerCreationException {
// do nothing
}
@Override
public void preDestruction() throws AuthorizerDestructionException {
// do nothing
}
};
final String sensitivePropAlgorithmVal = props.getProperty(StringEncryptor.NF_SENSITIVE_PROPS_ALGORITHM);
final String sensitivePropProviderVal = props.getProperty(StringEncryptor.NF_SENSITIVE_PROPS_PROVIDER);
final String sensitivePropValueNifiPropVar = props.getProperty(StringEncryptor.NF_SENSITIVE_PROPS_KEY, DEFAULT_SENSITIVE_PROPS_KEY);
StringEncryptor encryptor = StringEncryptor.createEncryptor(sensitivePropAlgorithmVal, sensitivePropProviderVal, sensitivePropValueNifiPropVar);
VariableRegistry variableRegistry = new FileBasedVariableRegistry(props.getVariableRegistryPropertiesPaths());
BulletinRepository bulletinRepository = new VolatileBulletinRepository();
FlowController flowController = FlowController.createStandaloneInstance(flowFileEventRepository, props, authorizer, auditService, encryptor, bulletinRepository, variableRegistry, new StandardFlowRegistryClient());
flowService = StandardFlowService.createStandaloneInstance(flowController, props, encryptor, // revision manager
null, authorizer);
// start and load the flow
flowService.start();
flowService.load(null);
flowController.onFlowInitialized(true);
flowController.getGroup(flowController.getRootGroupId()).startProcessing();
this.flowController = flowController;
logger.info("Flow loaded successfully.");
} catch (Exception e) {
// ensure the flow service is terminated
if (flowService != null && flowService.isRunning()) {
flowService.stop(false);
}
startUpFailure(new Exception("Unable to load flow due to: " + e, e));
}
}
Aggregations