public static boolean isVersionInStack(StackId stackId, String version) {
    if (null != version && !StringUtils.isBlank(version)) {
      String stackName = stackId.getStackName();
      if (version.startsWith(stackName + "-")) {
        version = version.substring(stackName.length() + 1);
      }

      String leading = stackId.getStackVersion();  // E.g, 2.3
      // In some cases during unit tests, the leading can contain 3 digits, so only the major number (first two parts) are needed.
      String[] leadingParts = leading.split("\\.");
      if (leadingParts.length > 2) {
        leading = leadingParts[0] + "." + leadingParts[1];
      }
      return version.startsWith(leading);
    }
    return false;
  }
Determine if the version belongs to the stack.
@param stackId Stack, such as HDP-2.3
@param version Version number, such as 2.3.0.0, or 2.3.0.0-1234
@return Return true if the version starts with the digits of the stack.
ambari-server/src/main/java/org/apache/ambari/server/orm/entities/RepositoryVersionEntity.java