You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@solr.apache.org by kr...@apache.org on 2023/01/05 15:43:09 UTC

[solr] branch branch_9x updated: SOLR-16612: Workaround IBM Java check in Hadoop (#1271)

This is an automated email from the ASF dual-hosted git repository.

krisden pushed a commit to branch branch_9x
in repository https://gitbox.apache.org/repos/asf/solr.git


The following commit(s) were added to refs/heads/branch_9x by this push:
     new 0d6cba9a7e9 SOLR-16612: Workaround IBM Java check in Hadoop (#1271)
0d6cba9a7e9 is described below

commit 0d6cba9a7e993f70c85eec62537515caa2abddfd
Author: Kevin Risden <ri...@users.noreply.github.com>
AuthorDate: Thu Jan 5 10:40:47 2023 -0500

    SOLR-16612: Workaround IBM Java check in Hadoop (#1271)
---
 .../solr/security/hadoop/KerberosTestServices.java |  3 +-
 .../test/org/apache/hadoop/util/PlatformName.java  | 54 ++++++++++++++++++++++
 .../apache/solr/client/solrj/util/Constants.java   | 22 +++++++++
 3 files changed, 78 insertions(+), 1 deletion(-)

diff --git a/solr/modules/hadoop-auth/src/test/org/apache/solr/security/hadoop/KerberosTestServices.java b/solr/modules/hadoop-auth/src/test/org/apache/solr/security/hadoop/KerberosTestServices.java
index fb89828f694..7f65706600f 100644
--- a/solr/modules/hadoop-auth/src/test/org/apache/solr/security/hadoop/KerberosTestServices.java
+++ b/solr/modules/hadoop-auth/src/test/org/apache/solr/security/hadoop/KerberosTestServices.java
@@ -30,6 +30,7 @@ import javax.security.auth.login.Configuration;
 import org.apache.commons.io.file.PathUtils;
 import org.apache.hadoop.minikdc.MiniKdc;
 import org.apache.solr.client.solrj.impl.Krb5HttpClientBuilder;
+import org.apache.solr.client.solrj.util.Constants;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -189,7 +190,7 @@ public class KerberosTestServices {
   }
 
   public static final String krb5LoginModuleName =
-      System.getProperty("java.vendor").contains("IBM")
+      Constants.IS_IBM_JAVA
           ? "com.ibm.security.auth.module.Krb5LoginModule"
           : "com.sun.security.auth.module.Krb5LoginModule";
 
diff --git a/solr/modules/hdfs/src/test/org/apache/hadoop/util/PlatformName.java b/solr/modules/hdfs/src/test/org/apache/hadoop/util/PlatformName.java
new file mode 100644
index 00000000000..945a3e53c0e
--- /dev/null
+++ b/solr/modules/hdfs/src/test/org/apache/hadoop/util/PlatformName.java
@@ -0,0 +1,54 @@
+/*
+ * 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.hadoop.util;
+
+import org.apache.hadoop.classification.InterfaceAudience;
+import org.apache.hadoop.classification.InterfaceStability;
+import org.apache.solr.client.solrj.util.Constants;
+
+/**
+ * A helper class for getting build-info of the java-vm.
+ *
+ */
+@InterfaceAudience.LimitedPrivate({"HBase"})
+@InterfaceStability.Unstable
+public class PlatformName {
+  /**
+   * The complete platform 'name' to identify the platform as
+   * per the java-vm.
+   */
+  public static final String PLATFORM_NAME =
+      (System.getProperty("os.name").startsWith("Windows")
+          ? System.getenv("os") : System.getProperty("os.name"))
+          + "-" + System.getProperty("os.arch")
+          + "-" + System.getProperty("sun.arch.data.model");
+
+  /**
+   * The java vendor name used in this platform.
+   */
+  public static final String JAVA_VENDOR_NAME = System.getProperty("java.vendor");
+
+  /**
+   * A public static variable to indicate the current java vendor is
+   * IBM java or not.
+   */
+  public static final boolean IBM_JAVA = Constants.IS_IBM_JAVA;
+
+  public static void main(String[] args) {
+    System.out.println(PLATFORM_NAME);
+  }
+}
diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/util/Constants.java b/solr/solrj/src/java/org/apache/solr/client/solrj/util/Constants.java
index 3ad41799b59..5136a95d63b 100644
--- a/solr/solrj/src/java/org/apache/solr/client/solrj/util/Constants.java
+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/util/Constants.java
@@ -17,12 +17,34 @@
 
 package org.apache.solr.client.solrj.util;
 
+import java.lang.invoke.MethodHandles;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
 // Clone of org.apache.lucene.util.Constants, so SolrJ can use it
 public class Constants {
+  private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
+
   public static final String JVM_SPEC_VERSION = System.getProperty("java.specification.version");
 
   public static final boolean JRE_IS_MINIMUM_JAVA9 = true;
   public static final boolean JRE_IS_MINIMUM_JAVA11 = true;
   // Future, enable if needed...
   // public static final boolean JRE_IS_MINIMUM_JAVA17 = Runtime.version().feature() >= 17;
+
+  public static final boolean IS_IBM_JAVA = isIBMJava();
+
+  private static boolean isIBMJava() {
+    try {
+      Class.forName(
+          "com.ibm.security.auth.module.Krb5LoginModule", false, Constants.class.getClassLoader());
+      return true;
+    } catch (SecurityException se) {
+      log.warn(
+          "Unable to determine if IBM Java due to SecurityException. Assuming not IBM Java.", se);
+      return false;
+    } catch (ClassNotFoundException ignore) {
+      return false;
+    }
+  }
 }