saintstack commented on a change in pull request #11: HBASE-21322 Add a 
scheduleServerCrashProcedure() API to HbckService
URL: 
https://github.com/apache/hbase-operator-tools/pull/11#discussion_r304721905
 
 

 ##########
 File path: hbase-hbck2/src/main/java/org/apache/hbase/Version.java
 ##########
 @@ -0,0 +1,115 @@
+/*
+ * 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.hbase;
+
+import org.apache.commons.lang3.StringUtils;
+
+/**
+ * Check versions.
+ */
+public final class Version {
+  // Copied from hbase VersionInfo.
+  private static final int VERY_LARGE_NUMBER = 100000;
+  private static final int MAJOR = 0;
+  private static final int MINOR = 1;
+  private static final int PATCH = 2;
+
+  private Version() {}
+
+  /**
+   * @param thresholdVersions List of versions from oldest to newest.
+   * @return true if <code>version</code> is less-than or equal to 
thresholdVersions.
+   *   For example, if passed threshold list is <code>{"2.0.2", "2.1.3", 
"2.2.1"}</code>
+   *   and the version is 2.1.2 then the result should be false since 2.1.2
+   *   is less than the matching passed-in 2.1.3 but if version is 2.1.5 then 
we return true.
+   */
+  static boolean check(final String version, String ... thresholdVersions) {
+    if (thresholdVersions == null) {
+      return true;
+    }
+    boolean supported = false;
+    // Components of the server version string.
+    String [] versionComponents = getVersionComponents(version);
+    boolean excessiveMajor = false;
+    boolean excessiveMinor = false;
+    for (String thresholdVersion: thresholdVersions) {
+      // Get components of current threshold version.
+      String[] thresholdVersionComponents = 
getVersionComponents(thresholdVersion);
+      int serverMajor = Integer.parseInt(versionComponents[MAJOR]);
+      int thresholdMajor = Integer.parseInt(thresholdVersionComponents[MAJOR]);
+      if (serverMajor > thresholdMajor) {
+        excessiveMajor = true;
+        continue;
+      }
+      excessiveMajor = false;
+      if (serverMajor < thresholdMajor) {
+        continue;
+      }
+      int serverMinor = Integer.parseInt(versionComponents[MINOR]);
+      int thresholdMinor = Integer.parseInt(thresholdVersionComponents[MINOR]);
+      if (serverMinor > thresholdMinor) {
+        excessiveMinor = true;
+        continue;
+      }
+      excessiveMinor = false;
+      if (serverMinor < thresholdMinor) {
+        continue;
+      }
+      if (Integer.parseInt(versionComponents[PATCH]) >=
+          Integer.parseInt(thresholdVersionComponents[PATCH])) {
+        supported = true;
+      }
+      break;
+    }
+    return supported || excessiveMajor || excessiveMinor;
+  }
+
+  /**
+   * Copied from hbase VersionInfo.
 
 Review comment:
   The getComponents in private in VersionInfo so have to copy it.
   
   VI doesn't have the check we do here.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to