Search in sources :

Example 1 with VariableRegistry

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"));
}
Also used : FlowFile(org.apache.nifi.flowfile.FlowFile) HashMap(java.util.HashMap) VariableRegistry(org.apache.nifi.registry.VariableRegistry) Test(org.junit.Test)

Example 2 with VariableRegistry

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());
    }
}
Also used : Funnel(org.apache.nifi.connectable.Funnel) RemoteProcessGroup(org.apache.nifi.groups.RemoteProcessGroup) Element(org.w3c.dom.Element) Port(org.apache.nifi.connectable.Port) RootGroupPort(org.apache.nifi.remote.RootGroupPort) RemoteGroupPort(org.apache.nifi.remote.RemoteGroupPort) Label(org.apache.nifi.controller.label.Label) Connection(org.apache.nifi.connectable.Connection) VariableRegistry(org.apache.nifi.registry.VariableRegistry) Document(org.w3c.dom.Document) VariableDescriptor(org.apache.nifi.registry.VariableDescriptor) Template(org.apache.nifi.controller.Template) ProcessorNode(org.apache.nifi.controller.ProcessorNode) VersionControlInformation(org.apache.nifi.registry.flow.VersionControlInformation) ControllerServiceNode(org.apache.nifi.controller.service.ControllerServiceNode) ProcessGroup(org.apache.nifi.groups.ProcessGroup) RemoteProcessGroup(org.apache.nifi.groups.RemoteProcessGroup) Map(java.util.Map)

Example 3 with VariableRegistry

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);
}
Also used : NiFiProperties(org.apache.nifi.util.NiFiProperties) BulletinRepository(org.apache.nifi.reporting.BulletinRepository) HashMap(java.util.HashMap) FileBasedVariableRegistry(org.apache.nifi.registry.variable.FileBasedVariableRegistry) VariableRegistry(org.apache.nifi.registry.VariableRegistry) AbstractPolicyBasedAuthorizer(org.apache.nifi.authorization.AbstractPolicyBasedAuthorizer) FlowFileEventRepository(org.apache.nifi.controller.repository.FlowFileEventRepository) MockProvenanceRepository(org.apache.nifi.provenance.MockProvenanceRepository) StringEncryptor(org.apache.nifi.encrypt.StringEncryptor) MockPolicyBasedAuthorizer(org.apache.nifi.authorization.MockPolicyBasedAuthorizer) AuditService(org.apache.nifi.admin.service.AuditService) FileBasedVariableRegistry(org.apache.nifi.registry.variable.FileBasedVariableRegistry) Before(org.junit.Before)

Example 4 with VariableRegistry

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"));
}
Also used : Path(java.nio.file.Path) VariableRegistry(org.apache.nifi.registry.VariableRegistry) FileBasedVariableRegistry(org.apache.nifi.registry.variable.FileBasedVariableRegistry) VariableDescriptor(org.apache.nifi.registry.VariableDescriptor) FileBasedVariableRegistry(org.apache.nifi.registry.variable.FileBasedVariableRegistry) Test(org.junit.Test)

Example 5 with VariableRegistry

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));
    }
}
Also used : VolatileBulletinRepository(org.apache.nifi.events.VolatileBulletinRepository) VolatileBulletinRepository(org.apache.nifi.events.VolatileBulletinRepository) BulletinRepository(org.apache.nifi.reporting.BulletinRepository) AuthorizationRequest(org.apache.nifi.authorization.AuthorizationRequest) FileBasedVariableRegistry(org.apache.nifi.util.FileBasedVariableRegistry) VariableRegistry(org.apache.nifi.registry.VariableRegistry) StatusRequestException(org.apache.nifi.minifi.status.StatusRequestException) AuthorizerCreationException(org.apache.nifi.authorization.exception.AuthorizerCreationException) AuthorizerDestructionException(org.apache.nifi.authorization.exception.AuthorizerDestructionException) AuthorizationAccessException(org.apache.nifi.authorization.exception.AuthorizationAccessException) RingBufferEventRepository(org.apache.nifi.controller.repository.metrics.RingBufferEventRepository) FlowFileEventRepository(org.apache.nifi.controller.repository.FlowFileEventRepository) Authorizer(org.apache.nifi.authorization.Authorizer) StringEncryptor(org.apache.nifi.encrypt.StringEncryptor) FlowController(org.apache.nifi.controller.FlowController) AuthorizerInitializationContext(org.apache.nifi.authorization.AuthorizerInitializationContext) StandardFlowRegistryClient(org.apache.nifi.registry.flow.StandardFlowRegistryClient) StandardAuditService(org.apache.nifi.admin.service.impl.StandardAuditService) AuditService(org.apache.nifi.admin.service.AuditService) StandardAuditService(org.apache.nifi.admin.service.impl.StandardAuditService) AuthorizerConfigurationContext(org.apache.nifi.authorization.AuthorizerConfigurationContext) FileBasedVariableRegistry(org.apache.nifi.util.FileBasedVariableRegistry)

Aggregations

VariableRegistry (org.apache.nifi.registry.VariableRegistry)5 HashMap (java.util.HashMap)2 AuditService (org.apache.nifi.admin.service.AuditService)2 FlowFileEventRepository (org.apache.nifi.controller.repository.FlowFileEventRepository)2 StringEncryptor (org.apache.nifi.encrypt.StringEncryptor)2 VariableDescriptor (org.apache.nifi.registry.VariableDescriptor)2 FileBasedVariableRegistry (org.apache.nifi.registry.variable.FileBasedVariableRegistry)2 BulletinRepository (org.apache.nifi.reporting.BulletinRepository)2 Path (java.nio.file.Path)1 Map (java.util.Map)1 StandardAuditService (org.apache.nifi.admin.service.impl.StandardAuditService)1 AbstractPolicyBasedAuthorizer (org.apache.nifi.authorization.AbstractPolicyBasedAuthorizer)1 AuthorizationRequest (org.apache.nifi.authorization.AuthorizationRequest)1 Authorizer (org.apache.nifi.authorization.Authorizer)1 AuthorizerConfigurationContext (org.apache.nifi.authorization.AuthorizerConfigurationContext)1 AuthorizerInitializationContext (org.apache.nifi.authorization.AuthorizerInitializationContext)1 MockPolicyBasedAuthorizer (org.apache.nifi.authorization.MockPolicyBasedAuthorizer)1 AuthorizationAccessException (org.apache.nifi.authorization.exception.AuthorizationAccessException)1 AuthorizerCreationException (org.apache.nifi.authorization.exception.AuthorizerCreationException)1 AuthorizerDestructionException (org.apache.nifi.authorization.exception.AuthorizerDestructionException)1