markap14 commented on a change in pull request #4376:
URL: https://github.com/apache/nifi/pull/4376#discussion_r459715604



##########
File path: 
nifi-nar-bundles/nifi-framework-bundle/nifi-framework/minifi-server/src/main/java/org/apache/nifi/minifi/MiNiFiServer.java
##########
@@ -0,0 +1,211 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.minifi;
+
+import org.apache.nifi.NiFiServer;
+import org.apache.nifi.admin.service.AuditService;
+import org.apache.nifi.admin.service.impl.StandardAuditService;
+import org.apache.nifi.authorization.AuthorizationRequest;
+import org.apache.nifi.authorization.AuthorizationResult;
+import org.apache.nifi.authorization.Authorizer;
+import org.apache.nifi.authorization.AuthorizerConfigurationContext;
+import org.apache.nifi.authorization.AuthorizerInitializationContext;
+import org.apache.nifi.authorization.exception.AuthorizationAccessException;
+import org.apache.nifi.authorization.exception.AuthorizerCreationException;
+import org.apache.nifi.authorization.exception.AuthorizerDestructionException;
+import org.apache.nifi.bundle.Bundle;
+import org.apache.nifi.controller.FlowController;
+import org.apache.nifi.controller.StandardFlowService;
+import org.apache.nifi.controller.flow.FlowManager;
+import org.apache.nifi.controller.repository.FlowFileEventRepository;
+import org.apache.nifi.controller.repository.metrics.RingBufferEventRepository;
+import org.apache.nifi.diagnostics.DiagnosticsFactory;
+import org.apache.nifi.encrypt.StringEncryptor;
+import org.apache.nifi.events.VolatileBulletinRepository;
+import org.apache.nifi.nar.ExtensionDiscoveringManager;
+import org.apache.nifi.nar.ExtensionManagerHolder;
+import org.apache.nifi.nar.ExtensionMapping;
+import org.apache.nifi.nar.StandardExtensionDiscoveringManager;
+import org.apache.nifi.registry.VariableRegistry;
+import org.apache.nifi.registry.flow.StandardFlowRegistryClient;
+import org.apache.nifi.registry.variable.FileBasedVariableRegistry;
+import org.apache.nifi.reporting.BulletinRepository;
+import org.apache.nifi.services.FlowService;
+import org.apache.nifi.util.NiFiProperties;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.List;
+import java.util.Set;
+
+/**
+ */
+public class MiNiFiServer implements NiFiServer {
+
+    private static final Logger logger = 
LoggerFactory.getLogger(MiNiFiServer.class);
+    private NiFiProperties props;
+    private Bundle systemBundle;
+    private Set<Bundle> bundles;
+    private ExtensionMapping extensionMapping;
+    private FlowService flowService;
+
+    private static final String DEFAULT_SENSITIVE_PROPS_KEY = "nififtw!";
+
+    /**
+     * Default constructor
+     */
+    public MiNiFiServer() {
+    }
+
+    public void start() {
+        try {
+
+            // Create a standard extension manager and discover extensions
+            final ExtensionDiscoveringManager extensionManager = new 
StandardExtensionDiscoveringManager();
+            extensionManager.discoverExtensions(systemBundle, bundles);
+            extensionManager.logClassLoaderMapping();
+
+            // Set the extension manager into the holder which makes it 
available to the Spring context via a factory bean
+            ExtensionManagerHolder.init(extensionManager);
+
+            // Enrich the flow xml using the Extension Manager mapping
+            final FlowParser flowParser = new FlowParser();
+            final FlowEnricher flowEnricher = new FlowEnricher(this, 
flowParser, props);
+            flowEnricher.enrichFlowWithBundleInformation();
+            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(),

Review comment:
       The StandardFlowRegistryClient needs the nifi properties to be provided. 
So I think this needs to be pulled into a local variable and have 
`setNifiProperties` called before passing to the FlowController.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to