Skip to content

Commit

Permalink
Revert "NIFI-7592: Allow NiFi to be started without a GUI/REST interf…
Browse files Browse the repository at this point in the history
…ace"

This reverts commit 1b91a6c.
  • Loading branch information
mattyb149 authored and markap14 committed Aug 7, 2020
1 parent b8a1a4c commit 55adb11
Show file tree
Hide file tree
Showing 45 changed files with 73 additions and 2,819 deletions.
33 changes: 0 additions & 33 deletions nifi-assembly/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,6 @@ language governing permissions and limitations under the License. -->
<artifactId>nifi-framework-api</artifactId>
<version>1.12.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.nifi</groupId>
<artifactId>nifi-server-api</artifactId>
<version>1.12.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.nifi</groupId>
<artifactId>nifi-runtime</artifactId>
Expand Down Expand Up @@ -138,12 +133,6 @@ language governing permissions and limitations under the License. -->
<version>1.12.0-SNAPSHOT</version>
<type>nar</type>
</dependency>
<dependency>
<groupId>org.apache.nifi</groupId>
<artifactId>nifi-server-nar</artifactId>
<version>1.12.0-SNAPSHOT</version>
<type>nar</type>
</dependency>
<dependency>
<groupId>org.apache.nifi</groupId>
<artifactId>nifi-provenance-repository-nar</artifactId>
Expand Down Expand Up @@ -957,28 +946,6 @@ language governing permissions and limitations under the License. -->
</dependency>
</dependencies>
</profile>
<profile>
<id>headless</id>
<!-- This profile handles the inclusion of nifi-server artifacts, such as the Web/UI NAR(s). -->
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<dependencies>
<dependency>
<groupId>org.apache.nifi</groupId>
<artifactId>nifi-server-nar</artifactId>
<version>1.12.0-SNAPSHOT</version>
<type>nar</type>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.nifi</groupId>
<artifactId>nifi-headless-server-nar</artifactId>
<version>1.12.0-SNAPSHOT</version>
<type>nar</type>
</dependency>
</dependencies>
</profile>
<profile>
<id>include-accumulo</id>
<!-- This profile handles the inclusion of nifi-accumulo artifacts. -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@
<source.skip>true</source.skip>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.nifi</groupId>
<artifactId>nifi-jetty</artifactId>
</dependency>
<dependency>
<groupId>org.apache.nifi</groupId>
<artifactId>nifi-file-authorizer</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@
<groupId>org.apache.nifi</groupId>
<artifactId>nifi-framework-api</artifactId>
</dependency>
<dependency>
<groupId>org.apache.nifi</groupId>
<artifactId>nifi-server-api</artifactId>
</dependency>
<dependency>
<groupId>org.apache.nifi</groupId>
<artifactId>nifi-properties</artifactId>
Expand Down

This file was deleted.

Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -17,34 +17,24 @@
package org.apache.nifi.authorization;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardOpenOption;
import java.util.ArrayList;
import java.util.List;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;
import javax.xml.XMLConstants;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.Result;
import javax.xml.transform.Source;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import javax.xml.validation.Schema;
import javax.xml.validation.SchemaFactory;
import org.apache.commons.io.IOUtils;
import org.apache.nifi.controller.serialization.FlowFromDOMFactory;
import org.apache.nifi.security.xml.XmlUtils;
import org.apache.nifi.util.LoggingXmlParserErrorHandler;
import org.apache.nifi.util.file.FileUtils;
import org.apache.nifi.web.api.dto.PortDTO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -64,9 +54,10 @@ public class FlowParser {
private static final String FLOW_XSD = "/FlowConfiguration.xsd";

private final Schema flowSchema;
private final SchemaFactory schemaFactory;

public FlowParser() throws SAXException {
SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
flowSchema = schemaFactory.newSchema(FlowParser.class.getResource(FLOW_XSD));
}

Expand Down Expand Up @@ -139,48 +130,6 @@ public FlowInfo parse(final File flowConfigurationFile) {
}
}

/**
* Generates a {@link Document} from the flow configuration file provided
*/
public Document parseDocument(final File flowConfigurationFile) {
if (flowConfigurationFile == null) {
logger.debug("Flow Configuration file was null");
return null;
}

// if the flow doesn't exist or is 0 bytes, then return null
final Path flowPath = flowConfigurationFile.toPath();
try {
if (!Files.exists(flowPath) || Files.size(flowPath) == 0) {
logger.warn("Flow Configuration does not exist or was empty");
return null;
}
} catch (IOException e) {
logger.error("An error occurred determining the size of the Flow Configuration file");
return null;
}

// otherwise create the appropriate input streams to read the file
try (final InputStream in = Files.newInputStream(flowPath, StandardOpenOption.READ);
final InputStream gzipIn = new GZIPInputStream(in)) {

final byte[] flowBytes = IOUtils.toByteArray(gzipIn);
if (flowBytes == null || flowBytes.length == 0) {
logger.warn("Could not extract root group id because Flow Configuration File was empty");
return null;
}

// create validating document builder
final DocumentBuilder docBuilder = XmlUtils.createSafeDocumentBuilder(flowSchema);
docBuilder.setErrorHandler(new LoggingXmlParserErrorHandler("Flow Configuration", logger));
return docBuilder.parse(new ByteArrayInputStream(flowBytes));

} catch (final SAXException | ParserConfigurationException | IOException ex) {
logger.error("Unable to parse flow {} due to {}", new Object[]{flowPath.toAbsolutePath(), ex});
return null;
}
}

/**
* Gets the ports that are direct children of the given element.
*
Expand All @@ -202,35 +151,14 @@ private List<PortDTO> getPorts(final Element element, final String type) {
return ports;
}

/**
* Writes a given XML Flow out to the specified path.
*
* @param flowDocument flowDocument of the associated XML content to write to disk
* @param flowXmlPath path on disk to write the flow
* @throws IOException if there are issues in accessing the target destination for the flow
* @throws TransformerException if there are issues in the xml transformation process
*/
public void writeFlow(final Document flowDocument, final Path flowXmlPath) throws IOException, TransformerException {
final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
final Source xmlSource = new DOMSource(flowDocument);
final Result outputTarget = new StreamResult(outputStream);
TransformerFactory.newInstance().newTransformer().transform(xmlSource, outputTarget);
final InputStream is = new ByteArrayInputStream(outputStream.toByteArray());

try (final OutputStream output = Files.newOutputStream(flowXmlPath, StandardOpenOption.WRITE, StandardOpenOption.CREATE);
final OutputStream gzipOut = new GZIPOutputStream(output)) {
FileUtils.copy(is, gzipOut);
}
}

/**
* Finds child elements with the given tagName.
*
* @param element the parent element
* @param tagName the child element name to find
* @return a list of matching child elements
*/
public static List<Element> getChildrenByTagName(final Element element, final String tagName) {
private static List<Element> getChildrenByTagName(final Element element, final String tagName) {
final List<Element> matches = new ArrayList<>();
final NodeList nodeList = element.getChildNodes();
for (int i = 0; i < nodeList.getLength(); i++) {
Expand All @@ -244,6 +172,8 @@ public static List<Element> getChildrenByTagName(final Element element, final St
matches.add(child);
}
}

return matches;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,6 @@
<groupId>org.apache.nifi</groupId>
<artifactId>nifi-framework-api</artifactId>
</dependency>
<dependency>
<groupId>org.apache.nifi</groupId>
<artifactId>nifi-server-api</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,7 @@ public synchronized NarLoadResult load(final Collection<File> narFiles) {
}

LOGGER.debug("Loading custom UIs for extensions...");
if(extensionUiLoader != null) {
extensionUiLoader.loadExtensionUis(loadedBundles);
}
extensionUiLoader.loadExtensionUis(loadedBundles);
}

LOGGER.info("Finished NAR loading process!");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ public void setup() throws IOException, ClassNotFoundException {

extensionManager = new StandardExtensionDiscoveringManager();

// Should have Framework, Jetty, and NiFiServer NARs loaded here
assertEquals(3, narClassLoaders.getBundles().size());
// Should have Framework and Jetty NARs loaded here
assertEquals(2, narClassLoaders.getBundles().size());

// No extensions should be loaded yet
assertEquals(0, extensionManager.getExtensions(Processor.class).size());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public void testNarLoaderWhenAllAvailable() throws IOException {
assertEquals(3, narLoadResult.getLoadedBundles().size());
assertEquals(0, narLoadResult.getSkippedBundles().size());

assertEquals(6, narClassLoaders.getBundles().size());
assertEquals(5, narClassLoaders.getBundles().size());
assertEquals(1, extensionManager.getExtensions(Processor.class).size());
assertEquals(1, extensionManager.getExtensions(ControllerService.class).size());
assertEquals(0, extensionManager.getExtensions(ReportingTask.class).size());
Expand Down Expand Up @@ -111,7 +111,7 @@ public void testNarLoaderWhenDependentNarsAreMissing() throws IOException {
assertEquals(3, narLoadResult3.getLoadedBundles().size());
assertEquals(0, narLoadResult3.getSkippedBundles().size());

assertEquals(6, narClassLoaders.getBundles().size());
assertEquals(5, narClassLoaders.getBundles().size());
assertEquals(1, extensionManager.getExtensions(Processor.class).size());
assertEquals(1, extensionManager.getExtensions(ControllerService.class).size());
assertEquals(0, extensionManager.getExtensions(ReportingTask.class).size());
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,5 @@
<groupId>org.apache.nifi</groupId>
<artifactId>nifi-framework-api</artifactId>
</dependency>
<dependency>
<groupId>org.apache.nifi</groupId>
<artifactId>nifi-server-api</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ Class<?>[] getExecutionStack() {
public static <T> T createInstance(final ExtensionManager extensionManager, final String implementationClassName, final Class<T> typeDefinition, final NiFiProperties nifiProperties)
throws InstantiationException, IllegalAccessException, ClassNotFoundException {
final ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(NarThreadContextClassLoader.getInstance());
try {
final List<Bundle> bundles = extensionManager.getBundles(implementationClassName);
if (bundles.size() == 0) {
Expand Down
Loading

0 comments on commit 55adb11

Please sign in to comment.