@Ignore @Test(expected = AmbariException.class) public void testCheckDBVersionInvalid() throws Exception { MetainfoDAO metainfoDAO = createMock(MetainfoDAO.class); MetainfoEntity metainfoEntity = new MetainfoEntity(); metainfoEntity.setMetainfoName(Configuration.SERVER_VERSION_KEY); metainfoEntity.setMetainfoValue("0.0.0"); expect(metainfoDAO.findByKey(Configuration.SERVER_VERSION_KEY)). andReturn(metainfoEntity); replay(metainfoDAO); DatabaseChecker.metainfoDAO = metainfoDAO; DatabaseChecker.ambariMetaInfo = ambariMetaInfo; DatabaseChecker.checkDBVersion(); }
public static void checkDBVersion() throws AmbariException { LOG.info("Checking DB store version"); if (metainfoDAO == null) { metainfoDAO = injector.getInstance(MetainfoDAO.class); } MetainfoEntity schemaVersionEntity = metainfoDAO.findByKey(Configuration.SERVER_VERSION_KEY); String schemaVersion = null; if (schemaVersionEntity != null) { schemaVersion = schemaVersionEntity.getMetainfoValue(); } Configuration conf = injector.getInstance(Configuration.class); File versionFile = new File(conf.getServerVersionFilePath()); if (!versionFile.exists()) { throw new AmbariException("Server version file does not exist."); } String serverVersion = null; try (Scanner scanner = new Scanner(versionFile)) { serverVersion = scanner.useDelimiter("\\Z").next(); } catch (IOException ioe) { throw new AmbariException("Unable to read server version file."); } if (schemaVersionEntity==null || VersionUtils.compareVersions(schemaVersion, serverVersion, 3) != 0) { String error = "Current database store version is not compatible with " + "current server version" + ", serverVersion=" + serverVersion + ", schemaVersion=" + schemaVersion; LOG.warn(error); throw new AmbariException(error); } LOG.info("DB store version is compatible"); }
DatabaseChecker { public static void checkDBVersion() throws AmbariException { LOG.info("Checking DB store version"); if (metainfoDAO == null) { metainfoDAO = injector.getInstance(MetainfoDAO.class); } MetainfoEntity schemaVersionEntity = metainfoDAO.findByKey(Configuration.SERVER_VERSION_KEY); String schemaVersion = null; if (schemaVersionEntity != null) { schemaVersion = schemaVersionEntity.getMetainfoValue(); } Configuration conf = injector.getInstance(Configuration.class); File versionFile = new File(conf.getServerVersionFilePath()); if (!versionFile.exists()) { throw new AmbariException("Server version file does not exist."); } String serverVersion = null; try (Scanner scanner = new Scanner(versionFile)) { serverVersion = scanner.useDelimiter("\\Z").next(); } catch (IOException ioe) { throw new AmbariException("Unable to read server version file."); } if (schemaVersionEntity==null || VersionUtils.compareVersions(schemaVersion, serverVersion, 3) != 0) { String error = "Current database store version is not compatible with " + "current server version" + ", serverVersion=" + serverVersion + ", schemaVersion=" + schemaVersion; LOG.warn(error); throw new AmbariException(error); } LOG.info("DB store version is compatible"); } }
DatabaseChecker { public static void checkDBVersion() throws AmbariException { LOG.info("Checking DB store version"); if (metainfoDAO == null) { metainfoDAO = injector.getInstance(MetainfoDAO.class); } MetainfoEntity schemaVersionEntity = metainfoDAO.findByKey(Configuration.SERVER_VERSION_KEY); String schemaVersion = null; if (schemaVersionEntity != null) { schemaVersion = schemaVersionEntity.getMetainfoValue(); } Configuration conf = injector.getInstance(Configuration.class); File versionFile = new File(conf.getServerVersionFilePath()); if (!versionFile.exists()) { throw new AmbariException("Server version file does not exist."); } String serverVersion = null; try (Scanner scanner = new Scanner(versionFile)) { serverVersion = scanner.useDelimiter("\\Z").next(); } catch (IOException ioe) { throw new AmbariException("Unable to read server version file."); } if (schemaVersionEntity==null || VersionUtils.compareVersions(schemaVersion, serverVersion, 3) != 0) { String error = "Current database store version is not compatible with " + "current server version" + ", serverVersion=" + serverVersion + ", schemaVersion=" + schemaVersion; LOG.warn(error); throw new AmbariException(error); } LOG.info("DB store version is compatible"); }  }
DatabaseChecker { public static void checkDBVersion() throws AmbariException { LOG.info("Checking DB store version"); if (metainfoDAO == null) { metainfoDAO = injector.getInstance(MetainfoDAO.class); } MetainfoEntity schemaVersionEntity = metainfoDAO.findByKey(Configuration.SERVER_VERSION_KEY); String schemaVersion = null; if (schemaVersionEntity != null) { schemaVersion = schemaVersionEntity.getMetainfoValue(); } Configuration conf = injector.getInstance(Configuration.class); File versionFile = new File(conf.getServerVersionFilePath()); if (!versionFile.exists()) { throw new AmbariException("Server version file does not exist."); } String serverVersion = null; try (Scanner scanner = new Scanner(versionFile)) { serverVersion = scanner.useDelimiter("\\Z").next(); } catch (IOException ioe) { throw new AmbariException("Unable to read server version file."); } if (schemaVersionEntity==null || VersionUtils.compareVersions(schemaVersion, serverVersion, 3) != 0) { String error = "Current database store version is not compatible with " + "current server version" + ", serverVersion=" + serverVersion + ", schemaVersion=" + schemaVersion; LOG.warn(error); throw new AmbariException(error); } LOG.info("DB store version is compatible"); }  static void checkDBConsistency(); static void checkDBConfigsConsistency(); static void checkDBVersion(); }
DatabaseChecker { public static void checkDBVersion() throws AmbariException { LOG.info("Checking DB store version"); if (metainfoDAO == null) { metainfoDAO = injector.getInstance(MetainfoDAO.class); } MetainfoEntity schemaVersionEntity = metainfoDAO.findByKey(Configuration.SERVER_VERSION_KEY); String schemaVersion = null; if (schemaVersionEntity != null) { schemaVersion = schemaVersionEntity.getMetainfoValue(); } Configuration conf = injector.getInstance(Configuration.class); File versionFile = new File(conf.getServerVersionFilePath()); if (!versionFile.exists()) { throw new AmbariException("Server version file does not exist."); } String serverVersion = null; try (Scanner scanner = new Scanner(versionFile)) { serverVersion = scanner.useDelimiter("\\Z").next(); } catch (IOException ioe) { throw new AmbariException("Unable to read server version file."); } if (schemaVersionEntity==null || VersionUtils.compareVersions(schemaVersion, serverVersion, 3) != 0) { String error = "Current database store version is not compatible with " + "current server version" + ", serverVersion=" + serverVersion + ", schemaVersion=" + schemaVersion; LOG.warn(error); throw new AmbariException(error); } LOG.info("DB store version is compatible"); }  static void checkDBConsistency(); static void checkDBConfigsConsistency(); static void checkDBVersion();  }