NIFI-10219 Removed jna-platform from nifi-bootstrap-utils

- Removed OSUtils.getWindowsProcessId() which removes JNA-based retrieval of Process ID retrieval for Windows on Java 8
- Removing jna-platform from nifi-bootstrap-utils eliminates the library from lib/bootstrap and allows it as a dependency in lib/properties

This closes #6199

Signed-off-by: Joey Frazee <jfrazee@apache.org>
This commit is contained in:
exceptionfactory 2022-07-12 08:50:34 -05:00 committed by Joey Frazee
parent 51626d728b
commit 2a9139c57a
3 changed files with 4 additions and 40 deletions

View File

@ -24,12 +24,5 @@ language governing permissions and limitations under the License. -->
<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>5.10.0</version>
</dependency>
</dependencies>
</project>

View File

@ -17,9 +17,6 @@
package org.apache.nifi.bootstrap.util;
import com.sun.jna.Pointer;
import com.sun.jna.platform.win32.Kernel32;
import com.sun.jna.platform.win32.WinNT;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
@ -64,11 +61,8 @@ public final class OSUtils {
final String processClassName = process.getClass().getName();
if (processClassName.equals("java.lang.UNIXProcess")) {
pid = getUnixPid(process, logger);
} else if (processClassName.equals("java.lang.Win32Process")
|| processClassName.equals("java.lang.ProcessImpl")) {
pid = getWindowsProcessId(process, logger);
} else {
logger.debug("Failed to determine Process ID from [{}]: {}", processClassName, e.getMessage());
logger.info("Failed to determine Process ID from [{}]: {}", processClassName, e.getMessage());
}
}
@ -122,30 +116,4 @@ public final class OSUtils {
return null;
}
}
/**
* @param process NiFi Process Reference
* @param logger Logger Reference for Debug
* @return Returns pid or null in-case pid could not be determined
* This method takes {@link Process} and {@link Logger} and returns
* the platform specific Handle for Win32 Systems, a.k.a <b>pid</b>
* In-case it fails to determine the pid, it will return Null.
* Purpose for the Logger is to log any interaction for debugging.
*/
private static Long getWindowsProcessId(final Process process, final Logger logger) {
Long pid = null;
try {
final Field handleField = process.getClass().getDeclaredField("handle");
handleField.setAccessible(true);
long peer = handleField.getLong(process);
final Kernel32 kernel = Kernel32.INSTANCE;
final WinNT.HANDLE handle = new WinNT.HANDLE();
handle.setPointer(Pointer.createConstant(peer));
pid = Long.valueOf(kernel.GetProcessId(handle));
} catch (final IllegalAccessException | NoSuchFieldException e) {
logger.debug("Could not find Windows PID", e);
}
return pid;
}
}

View File

@ -17,6 +17,8 @@
package org.apache.nifi.bootstrap.util;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.DisabledOnOs;
import org.junit.jupiter.api.condition.OS;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -27,6 +29,7 @@ import static org.junit.jupiter.api.Assertions.assertNotNull;
public class OSUtilsTest {
@DisabledOnOs(OS.WINDOWS)
@Test
public void testGetPid() throws IOException {
final ProcessBuilder builder = new ProcessBuilder();