ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject ambari git commit: AMBARI-21359 Add JavaVersionCheck check (dili)
Date Wed, 28 Jun 2017 18:24:42 GMT
Repository: ambari
Updated Branches:
  refs/heads/branch-feature-AMBARI-21348 77099797a -> bb18f7fe0


AMBARI-21359 Add JavaVersionCheck check (dili)


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/bb18f7fe
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/bb18f7fe
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/bb18f7fe

Branch: refs/heads/branch-feature-AMBARI-21348
Commit: bb18f7fe0b2624e7f3022de4236983c695619bc2
Parents: 7709979
Author: Di Li <dili@apache.org>
Authored: Wed Jun 28 14:24:21 2017 -0400
Committer: Di Li <dili@apache.org>
Committed: Wed Jun 28 14:24:21 2017 -0400

----------------------------------------------------------------------
 .../ambari/server/checks/CheckDescription.java  |   8 ++
 .../ambari/server/checks/JavaVersionCheck.java  | 102 +++++++++++++++++++
 2 files changed, 110 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/bb18f7fe/ambari-server/src/main/java/org/apache/ambari/server/checks/CheckDescription.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/checks/CheckDescription.java
b/ambari-server/src/main/java/org/apache/ambari/server/checks/CheckDescription.java
index 71c5857..2be42fc 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/checks/CheckDescription.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/checks/CheckDescription.java
@@ -329,6 +329,14 @@ public class CheckDescription {
               "As Ranger is SSL enabled, Ranger SSL configurations will need to be changed
from default value of /etc/ranger/*/conf folder to /etc/ranger/security. " +
               "Since the certificates/keystores/truststores in this path may affect the upgrade/downgrade
process, it is recommended to manually move the certificates/keystores/truststores out of
the conf folders and change the appropriate config values before proceeding.").build());
 
+  public static CheckDescription JAVA_VERSION = new CheckDescription("JAVA_VERSION",
+      PrereqCheckType.CLUSTER,
+      "Verify Java version requirement",
+      new ImmutableMap.Builder<String, String>()
+        .put(AbstractCheckDescriptor.DEFAULT, "Ambari requires JDK with minimum version %s.
Reconfigure Ambari with a JDK that meets the version requirement.")
+        .build()
+    );
+
   private String m_name;
   private PrereqCheckType m_type;
   private String m_description;

http://git-wip-us.apache.org/repos/asf/ambari/blob/bb18f7fe/ambari-server/src/main/java/org/apache/ambari/server/checks/JavaVersionCheck.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/checks/JavaVersionCheck.java
b/ambari-server/src/main/java/org/apache/ambari/server/checks/JavaVersionCheck.java
new file mode 100644
index 0000000..882749f
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/checks/JavaVersionCheck.java
@@ -0,0 +1,102 @@
+/*
+ * 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.ambari.server.checks;
+
+import java.util.Map;
+
+import org.apache.ambari.server.AmbariException;
+import org.apache.ambari.server.configuration.Configuration;
+import org.apache.ambari.server.controller.PrereqCheckRequest;
+import org.apache.ambari.server.state.stack.PrereqCheckStatus;
+import org.apache.ambari.server.state.stack.PrerequisiteCheck;
+import org.apache.ambari.server.state.stack.UpgradePack.PrerequisiteCheckConfig;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.inject.Singleton;
+
+/**
+ * The {@link JavaVersionCheck} checks that JDK version used by Ambari meets the minimal
version requirement
+ */
+@Singleton
+@UpgradeCheck(group = UpgradeCheckGroup.DEFAULT)
+public class JavaVersionCheck extends AbstractCheckDescriptor {
+
+  private static final Logger LOG = LoggerFactory.getLogger(JavaVersionCheck.class);
+  static final String JAVA_VERSION_PROPERTY_NAME = "java-version";
+
+  /**
+   * Constructor.
+   */
+  public JavaVersionCheck() {
+    super(CheckDescription.JAVA_VERSION);
+  }
+
+  /**
+   * {@inheritDoc}
+   */
+  @Override
+  public void perform(PrerequisiteCheck prerequisiteCheck, PrereqCheckRequest request) throws
AmbariException {
+
+    PrerequisiteCheckConfig prerequisiteCheckConfig = request.getPrerequisiteCheckConfig();
+    Map<String, String> checkProperties = null;
+    if(prerequisiteCheckConfig != null) {
+      checkProperties = prerequisiteCheckConfig.getCheckProperties(this.getClass().getName());
+    }
+    String javaVersion = null;
+    if(checkProperties != null && checkProperties.containsKey(JAVA_VERSION_PROPERTY_NAME))
{
+      javaVersion = checkProperties.get(JAVA_VERSION_PROPERTY_NAME);
+      LOG.debug(String.format("JDK version defined in the upgrade pack: %s ", javaVersion));
+    }
+
+    if(null == javaVersion){
+      LOG.debug(String.format("No JDK version provided in the upgrade pack. Use default version
%.1f", Configuration.JDK_MIN_VERSION));
+      javaVersion = String.valueOf(Configuration.JDK_MIN_VERSION);
+    }
+
+    int version = parseJavaVersion(javaVersion);
+    boolean meetVersion = meetJavaVersion(version);
+
+    if(!meetVersion){
+      prerequisiteCheck.getFailedOn().add("Java");
+      prerequisiteCheck.setStatus(PrereqCheckStatus.FAIL);
+      String reason = getFailReason(prerequisiteCheck, request);
+      reason = String.format(reason, javaVersion);
+      prerequisiteCheck.setFailReason(reason);
+      return;
+    }
+  }
+
+  private boolean meetJavaVersion(int expectedVersion){
+    String version = System.getProperty("java.version");
+    int currentJavaVersion = parseJavaVersion(version);
+    return (currentJavaVersion >= expectedVersion) && (currentJavaVersion != -1);
+  }
+
+  private int parseJavaVersion(String javaVersion) {
+    if (javaVersion.startsWith("1.6")) {
+      return 6;
+    } else if (javaVersion.startsWith("1.7")) {
+      return 7;
+    } else if (javaVersion.startsWith("1.8")) {
+      return 8;
+    } else { // Some unsupported java version
+      return -1;
+    }
+  }
+}


Mime
View raw message