You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pinot.apache.org by ma...@apache.org on 2021/09/21 16:13:59 UTC
[pinot] branch master updated: fix manifest scan which drives
/version endpoint (#7456)
This is an automated email from the ASF dual-hosted git repository.
mayanks pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/pinot.git
The following commit(s) were added to refs/heads/master by this push:
new 0f42295 fix manifest scan which drives /version endpoint (#7456)
0f42295 is described below
commit 0f42295d2b03f999bb659071eb23de1bce77f7c3
Author: Richard Startin <ri...@startree.ai>
AuthorDate: Tue Sep 21 17:13:46 2021 +0100
fix manifest scan which drives /version endpoint (#7456)
---
.../main/java/org/apache/pinot/common/Utils.java | 39 +++++++++-------------
1 file changed, 15 insertions(+), 24 deletions(-)
diff --git a/pinot-common/src/main/java/org/apache/pinot/common/Utils.java b/pinot-common/src/main/java/org/apache/pinot/common/Utils.java
index da4c1d6..d9d58e0 100644
--- a/pinot-common/src/main/java/org/apache/pinot/common/Utils.java
+++ b/pinot-common/src/main/java/org/apache/pinot/common/Utils.java
@@ -19,14 +19,14 @@
package org.apache.pinot.common;
import java.io.IOException;
-import java.net.JarURLConnection;
+import java.io.InputStream;
import java.net.URL;
-import java.net.URLClassLoader;
-import java.net.URLConnection;
+import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.atomic.AtomicLong;
import java.util.jar.Attributes;
+import java.util.jar.Manifest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -118,37 +118,28 @@ public class Utils {
public static Map<String, String> getComponentVersions() {
Map<String, String> componentVersions = new HashMap<>();
- // Find the first URLClassLoader, walking up the chain of parent classloaders if necessary
+ // unless Utils was somehow loaded on the bootclasspath, this will not be null
+ // and will find all manifests
ClassLoader classLoader = Utils.class.getClassLoader();
- while (classLoader != null && !(classLoader instanceof URLClassLoader)) {
- classLoader = classLoader.getParent();
- }
-
if (classLoader != null) {
- URLClassLoader urlClassLoader = (URLClassLoader) classLoader;
- URL[] urls = urlClassLoader.getURLs();
- for (URL url : urls) {
- try {
- // Convert the URL to the JAR into a JAR URL: eg. jar:http://www.foo.com/bar/baz.jar!/ in order to load it
- URL jarUrl = new URL("jar", "", url + "!/");
- URLConnection connection = jarUrl.openConnection();
- if (connection instanceof JarURLConnection) {
- JarURLConnection jarURLConnection = (JarURLConnection) connection;
-
- // Read JAR attributes and log the Implementation-Title and Implementation-Version manifestvalues for pinot
- // components
- Attributes attributes = jarURLConnection.getMainAttributes();
+ try {
+ Enumeration<URL> manifests = classLoader.getResources("META-INF/MANIFEST.MF");
+ while (manifests.hasMoreElements()) {
+ URL url = manifests.nextElement();
+ try (InputStream stream = url.openStream()) {
+ Manifest manifest = new Manifest(stream);
+ Attributes attributes = manifest.getMainAttributes();
if (attributes != null) {
String implementationTitle = attributes.getValue(Attributes.Name.IMPLEMENTATION_TITLE);
- String implementationVersion = attributes.getValue(Attributes.Name.IMPLEMENTATION_VERSION);
if (implementationTitle != null && implementationTitle.contains("pinot")) {
+ String implementationVersion = attributes.getValue(Attributes.Name.IMPLEMENTATION_VERSION);
componentVersions.put(implementationTitle, implementationVersion);
}
}
}
- } catch (IOException e) {
- // Ignored
}
+ } catch (IOException e) {
+ // ignore
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org