bbende commented on a change in pull request #4509:
URL: https://github.com/apache/nifi/pull/4509#discussion_r496085387



##########
File path: 
nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-nar-utils/src/main/java/org/apache/nifi/nar/NarClassLoaders.java
##########
@@ -224,7 +228,7 @@ private InitContext load(final ClassLoader rootClassloader,
                     // see if this class loader is eligible for loading
                     ClassLoader narClassLoader = null;
                     if (narDependencyCoordinate == null) {
-                        narClassLoader = 
createNarClassLoader(narDetail.getWorkingDirectory(), jettyClassLoader);
+                        narClassLoader = 
createNarClassLoader(narDetail.getWorkingDirectory(), rootClassloader);

Review comment:
       I think we should make this line consistent with the logic below around 
line 390...
   
   In this case we are saying, if no dependency then the parent is always the 
root class loader.
   
   In the other case we are saying, if no dependency and if jetty bundle exists 
(which currently it always does), then make jetty bundle the parent, otherwise 
the parent is null.
   
   I think both cases should probably make the parent be the jetty class loader 
if the jetty bundle exists, otherwise the root class loader.

##########
File path: 
nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-headless-server/src/main/java/org/apache/nifi/headless/HeadlessNiFiServer.java
##########
@@ -0,0 +1,199 @@
+/*
+ * 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.headless;
+
+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.FlowParser;
+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 HeadlessNiFiServer implements NiFiServer {
+
+    private static final Logger logger = 
LoggerFactory.getLogger(HeadlessNiFiServer.class);
+    private NiFiProperties props;
+    private Bundle systemBundle;
+    private Set<Bundle> bundles;
+    private FlowService flowService;
+
+    private static final String DEFAULT_SENSITIVE_PROPS_KEY = "nififtw!";
+
+    /**
+     * Default constructor
+     */
+    public HeadlessNiFiServer() {
+    }
+
+    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();
+            StandardFlowRegistryClient flowRegistryClient = new 
StandardFlowRegistryClient();
+            flowRegistryClient.setProperties(props);
+
+            FlowController flowController = 
FlowController.createStandaloneInstance(
+                    flowFileEventRepository,
+                    props,
+                    authorizer,
+                    auditService,
+                    encryptor,
+                    bulletinRepository,
+                    variableRegistry,
+                    flowRegistryClient,
+                    extensionManager
+                    );
+
+            flowService = StandardFlowService.createStandaloneInstance(
+                    flowController,
+                    props,
+                    encryptor,
+                    null, // revision manager
+                    authorizer);
+
+            // start and load the flow
+            flowService.start();
+            flowService.load(null);
+            flowController.onFlowInitialized(true);
+            FlowManager flowManager = flowController.getFlowManager();
+            
flowManager.getGroup(flowManager.getRootGroupId()).startProcessing();
+
+            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));
+        }
+    }
+
+    private void startUpFailure(Throwable t) {
+        System.err.println("Failed to start flow service: " + t.getMessage());
+        System.err.println("Shutting down...");
+        logger.warn("Failed to start headless server... shutting down.", t);
+        System.exit(1);
+    }
+
+    @Override
+    public void initialize(NiFiProperties properties, Bundle systemBundle, 
Set<Bundle> bundles, ExtensionMapping extensionMapping) {
+        this.props = properties;
+        this.systemBundle = systemBundle;
+        this.bundles = bundles;
+    }
+
+    public DiagnosticsFactory getDiagnosticsFactory() {
+        return null;
+    }
+
+    public DiagnosticsFactory getThreadDumpFactory() {
+        return null;
+    }

Review comment:
       I don't really know what is involved in providing these, but just wanted 
to double check that we really want them to be null since then I think you 
can't call the nifi.sh diagnostics command without them.




----------------------------------------------------------------
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:
[email protected]


Reply via email to