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



##########
File path: 
nifi-nar-bundles/nifi-framework-bundle/nifi-stateless-bundle/nifi-stateless-bootstrap/src/main/java/org/apache/nifi/stateless/bootstrap/StatelessBootstrap.java
##########
@@ -0,0 +1,149 @@
+/*
+ * 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.stateless.bootstrap;
+
+import org.apache.nifi.bundle.Bundle;
+import org.apache.nifi.bundle.BundleCoordinate;
+import org.apache.nifi.nar.NarUnpacker;
+import org.apache.nifi.nar.SystemBundle;
+import org.apache.nifi.stateless.config.ParameterOverride;
+import org.apache.nifi.stateless.config.StatelessConfigurationException;
+import org.apache.nifi.stateless.engine.StatelessEngineConfiguration;
+import org.apache.nifi.stateless.flow.DataflowDefinition;
+import org.apache.nifi.stateless.flow.DataflowDefinitionParser;
+import org.apache.nifi.stateless.flow.StatelessDataflow;
+import org.apache.nifi.stateless.flow.StatelessDataflowFactory;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.nio.file.Path;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.ServiceLoader;
+import java.util.function.Predicate;
+import java.util.regex.Pattern;
+
+public class StatelessBootstrap {
+    private static final Logger logger = 
LoggerFactory.getLogger(StatelessBootstrap.class);
+    private static final Pattern STATELESS_NAR_PATTERN = 
Pattern.compile("nifi-stateless-nar-.*\\.nar-unpacked");
+    private final ClassLoader statelessClassLoader;
+    private final StatelessEngineConfiguration engineConfiguration;
+
+    private StatelessBootstrap(final ClassLoader statelessClassLoader, final 
StatelessEngineConfiguration engineConfiguration) {
+        this.statelessClassLoader = statelessClassLoader;
+        this.engineConfiguration = engineConfiguration;
+    }
+
+    public <T> StatelessDataflow createDataflow(final DataflowDefinition<T> 
dataflowDefinition, final List<ParameterOverride> parameterOverrides)
+                throws IOException, StatelessConfigurationException {
+        final StatelessDataflowFactory<T> dataflowFactory = 
getSingleInstance(statelessClassLoader, StatelessDataflowFactory.class);
+        final StatelessDataflow dataflow = 
dataflowFactory.createDataflow(engineConfiguration, dataflowDefinition, 
parameterOverrides);
+        return dataflow;
+    }
+
+    public DataflowDefinition<?> parseDataflowDefinition(final File 
flowDefinitionFile) throws StatelessConfigurationException, IOException {
+        final DataflowDefinitionParser dataflowDefinitionParser = 
getSingleInstance(statelessClassLoader, DataflowDefinitionParser.class);
+        final DataflowDefinition<?> dataflowDefinition = 
dataflowDefinitionParser.parseFlowDefinition(flowDefinitionFile, 
engineConfiguration);
+        return dataflowDefinition;
+    }
+
+    public static StatelessBootstrap bootstrap(final 
StatelessEngineConfiguration engineConfiguration) throws IOException {
+        final File narDirectory = engineConfiguration.getNarDirectory();
+        final File workingDirectory = 
engineConfiguration.getWorkingDirectory();
+
+        final Bundle systemBundle = 
SystemBundle.create(narDirectory.getAbsolutePath(), 
ClassLoader.getSystemClassLoader());
+        final File frameworkWorkingDir = new File(workingDirectory, 
"nifi-framework");
+        final File extensionsWorkingDir = new File(workingDirectory, 
"extensions");
+        final File docsWorkingDir = new File(workingDirectory, 
"documentation");
+        final List<Path> narDirectories = 
Collections.singletonList(narDirectory.toPath());
+
+        // Unpack NARs
+        final long unpackStart = System.currentTimeMillis();
+        final Predicate<BundleCoordinate> narFilter = coordinate -> true;
+        NarUnpacker.unpackNars(systemBundle, frameworkWorkingDir, 
extensionsWorkingDir, docsWorkingDir, narDirectories, false, false, narFilter);
+        final long unpackMillis = System.currentTimeMillis() - unpackStart;
+        logger.info("Unpacked NAR's in {} millis", unpackMillis);

Review comment:
       Fair enough.




----------------------------------------------------------------
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