MINIFI-554: Move OSUtils to nifi-bootstrap-utils for MiNiFi and NiFi

This closes #5062

Signed-off-by: David Handermann <exceptionfactory@apache.org>
This commit is contained in:
Matthew Burgess 2021-05-07 14:35:41 -04:00 committed by exceptionfactory
parent 1e75b7ef06
commit 284322feed
No known key found for this signature in database
GPG Key ID: 29B6A52D2AAE8DBA
19 changed files with 87 additions and 29 deletions

View File

@ -105,6 +105,10 @@ limitations under the License.
<scope>runtime</scope>
<type>zip</type>
</dependency>
<dependency>
<groupId>org.apache.nifi</groupId>
<artifactId>nifi-bootstrap-utils</artifactId>
</dependency>
<dependency>
<groupId>org.apache.nifi.minifi</groupId>
<artifactId>minifi-bootstrap</artifactId>

View File

@ -33,6 +33,7 @@
<fileMode>0660</fileMode>
<useTransitiveFiltering>true</useTransitiveFiltering>
<excludes>
<exclude>nifi-bootstrap-utils</exclude>
<exclude>minifi-bootstrap</exclude>
<exclude>minifi-resources</exclude>
<!-- Filter items introduced via transitive dependencies that are provided in associated NARs -->
@ -61,6 +62,7 @@
<fileMode>0660</fileMode>
<useTransitiveFiltering>true</useTransitiveFiltering>
<includes>
<include>nifi-bootstrap-utils</include>
<include>minifi-bootstrap</include>
<include>minifi-utils</include>
<include>nifi-utils</include>

View File

@ -33,6 +33,7 @@
<fileMode>0660</fileMode>
<useTransitiveFiltering>true</useTransitiveFiltering>
<excludes>
<exclude>nifi-bootstrap-utils</exclude>
<exclude>minifi-bootstrap</exclude>
<exclude>minifi-resources</exclude>
<!-- Filter items introduced via transitive dependencies that are provided in associated NARs -->
@ -61,6 +62,7 @@
<fileMode>0660</fileMode>
<useTransitiveFiltering>true</useTransitiveFiltering>
<includes>
<include>nifi-bootstrap-utils</include>
<include>minifi-bootstrap</include>
<include>minifi-utils</include>
<include>nifi-utils</include>

View File

@ -40,6 +40,10 @@ limitations under the License.
<artifactId>nifi-api</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.nifi</groupId>
<artifactId>nifi-bootstrap-utils</artifactId>
</dependency>
<dependency>
<groupId>org.apache.nifi</groupId>
<artifactId>nifi-processor-utils</artifactId>

View File

@ -18,6 +18,7 @@ package org.apache.nifi.minifi.bootstrap;
import org.apache.commons.io.input.TeeInputStream;
import org.apache.commons.lang3.StringUtils;
import org.apache.nifi.bootstrap.util.OSUtils;
import org.apache.nifi.minifi.bootstrap.configuration.ConfigurationChangeCoordinator;
import org.apache.nifi.minifi.bootstrap.configuration.ConfigurationChangeException;
import org.apache.nifi.minifi.bootstrap.configuration.ConfigurationChangeListener;
@ -44,7 +45,6 @@ import java.io.InputStreamReader;
import java.io.ObjectInputStream;
import java.io.OutputStream;
import java.io.Reader;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.net.InetAddress;
import java.net.InetSocketAddress;
@ -1155,7 +1155,7 @@ public class RunMiNiFi implements QueryableStatusAggregator, ConfigurationFileHo
Process process = builder.start();
handleLogging(process);
Long pid = getPid(process, cmdLogger);
Long pid = OSUtils.getProcessId(process, cmdLogger);
if (pid != null) {
minifiPid = pid;
final Properties minifiProps = new Properties();
@ -1293,7 +1293,7 @@ public class RunMiNiFi implements QueryableStatusAggregator, ConfigurationFileHo
process = builder.start();
handleLogging(process);
Long pid = getPid(process, defaultLogger);
Long pid = OSUtils.getProcessId(process, defaultLogger);
if (pid != null) {
minifiPid = pid;
final Properties minifiProps = new Properties();
@ -1400,25 +1400,6 @@ public class RunMiNiFi implements QueryableStatusAggregator, ConfigurationFileHo
this.loggingFutures = futures;
}
private Long getPid(final Process process, final Logger logger) {
try {
final Class<?> procClass = process.getClass();
final Field pidField = procClass.getDeclaredField(PID_KEY);
pidField.setAccessible(true);
final Object pidObject = pidField.get(process);
logger.debug("PID Object = {}", pidObject);
if (pidObject instanceof Number) {
return ((Number) pidObject).longValue();
}
return null;
} catch (final IllegalAccessException | NoSuchFieldException nsfe) {
logger.debug("Could not find PID for child process due to {}", nsfe);
return null;
}
}
private boolean isWindows() {
final String osName = System.getProperty("os.name");
return osName != null && osName.toLowerCase().contains("win");

View File

@ -118,6 +118,11 @@ limitations under the License.
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.apache.nifi</groupId>
<artifactId>nifi-bootstrap-utils</artifactId>
<version>1.14.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.nifi.minifi</groupId>
<artifactId>minifi-bootstrap</artifactId>

View File

@ -116,6 +116,11 @@ language governing permissions and limitations under the License. -->
<artifactId>nifi-bootstrap</artifactId>
<version>1.14.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.nifi</groupId>
<artifactId>nifi-bootstrap-utils</artifactId>
<version>1.14.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.nifi</groupId>
<artifactId>nifi-resources</artifactId>
@ -1178,6 +1183,7 @@ language governing permissions and limitations under the License. -->
<exclude>javax.mail:mail</exclude>
<!-- must be in lib <exclude>org.apache.nifi:nifi-api</exclude> -->
<exclude>org.apache.nifi:nifi-bootstrap</exclude>
<exclude>org.apache.nifi:nifi-bootstrap-utils</exclude>
<exclude>org.apache.nifi:nifi-expression-language</exclude>
<exclude>org.apache.nifi:nifi-parameter</exclude>
<exclude>org.apache.nifi:nifi-processor-utils</exclude>
@ -1237,6 +1243,7 @@ language governing permissions and limitations under the License. -->
<include>javax.mail:mail</include>
<include>org.apache.nifi:nifi-api</include>
<include>org.apache.nifi:nifi-bootstrap</include>
<include>org.apache.nifi:nifi-bootstrap-utils</include>
<include>org.apache.nifi:nifi-expression-language</include>
<include>org.apache.nifi:nifi-parameter</include>
<include>org.apache.nifi:nifi-processor-utils</include>

View File

@ -24,6 +24,7 @@
<fileMode>0664</fileMode>
<useTransitiveFiltering>true</useTransitiveFiltering>
<includes>
<include>nifi-bootstrap-utils</include>
<include>nifi-bootstrap</include>
<include>slf4j-api</include>
<include>logback-classic</include>

View File

@ -32,6 +32,7 @@
<fileMode>0664</fileMode>
<useTransitiveFiltering>true</useTransitiveFiltering>
<excludes>
<exclude>nifi-bootstrap-utils</exclude>
<exclude>nifi-bootstrap</exclude>
<exclude>nifi-resources</exclude>
<exclude>nifi-docs</exclude>

View File

@ -37,6 +37,7 @@
<fileMode>0660</fileMode>
<useTransitiveFiltering>true</useTransitiveFiltering>
<excludes>
<exclude>nifi-bootstrap-utils</exclude>
<exclude>nifi-bootstrap</exclude>
<exclude>nifi-resources</exclude>
<exclude>nifi-docs</exclude>

View File

@ -30,6 +30,11 @@ language governing permissions and limitations under the License. -->
<version>1.14.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.nifi</groupId>
<artifactId>nifi-bootstrap-utils</artifactId>
<version>1.14.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.nifi</groupId>
<artifactId>nifi-utils</artifactId>
@ -74,11 +79,6 @@ language governing permissions and limitations under the License. -->
<artifactId>nifi-properties-loader</artifactId>
<version>1.14.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>net.java.dev.jna</groupId>
<artifactId>jna-platform</artifactId>
<version>4.4.0</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>

View File

@ -0,0 +1,41 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- 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. -->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.nifi</groupId>
<artifactId>nifi-commons</artifactId>
<version>1.14.0-SNAPSHOT</version>
</parent>
<artifactId>nifi-bootstrap-utils</artifactId>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<!-- This needs to be here because it is relied upon by the nifi-runtime which starts NiFi. It uses this bootstrap module
and the libs that get laid down in lib/bootstrap to create a child classloader with these bits in it -->
<dependency>
<groupId>net.java.dev.jna</groupId>
<artifactId>jna-platform</artifactId>
<version>4.4.0</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>

View File

@ -14,9 +14,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.nifi.bootstrap.http;
package org.apache.nifi.bootstrap.util;
import org.apache.nifi.bootstrap.util.OSUtils;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

View File

@ -24,6 +24,7 @@
<artifactId>nifi-commons</artifactId>
<packaging>pom</packaging>
<modules>
<module>nifi-bootstrap-utils</module>
<module>nifi-data-provenance-utils</module>
<module>nifi-expression-language</module>
<module>nifi-flowfile-packager</module>

View File

@ -28,6 +28,7 @@
<fileMode>0664</fileMode>
<useTransitiveFiltering>true</useTransitiveFiltering>
<excludes>
<exclude>nifi-bootstrap-utils</exclude>
<exclude>nifi-bootstrap</exclude>
<exclude>nifi-resources</exclude>
<exclude>nifi-docs</exclude>

View File

@ -28,6 +28,7 @@
<fileMode>0664</fileMode>
<useTransitiveFiltering>true</useTransitiveFiltering>
<excludes>
<exclude>nifi-bootstrap-utils</exclude>
<exclude>nifi-bootstrap</exclude>
<exclude>nifi-resources</exclude>
<exclude>nifi-docs</exclude>

View File

@ -150,6 +150,11 @@
<artifactId>nifi-runtime</artifactId>
<version>1.14.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.nifi</groupId>
<artifactId>nifi-bootstrap-utils</artifactId>
<version>1.14.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.nifi</groupId>
<artifactId>nifi-bootstrap</artifactId>

View File

@ -29,6 +29,7 @@
<fileMode>0664</fileMode>
<useTransitiveFiltering>true</useTransitiveFiltering>
<includes>
<include>nifi-bootstrap-utils</include>
<include>nifi-bootstrap</include>
<include>slf4j-api</include>
<include>nifi-api</include>
@ -62,6 +63,7 @@
<fileMode>0664</fileMode>
<useTransitiveFiltering>true</useTransitiveFiltering>
<excludes>
<exclude>nifi-bootstrap-utils</exclude>
<exclude>nifi-bootstrap</exclude>
<exclude>nifi-resources</exclude>
<exclude>nifi-docs</exclude>