@Test public void testInitPrimary() throws Exception { haStateDbManager.init(DhcpServerConfiguration.HaRole.PRIMARY); }
public HaState init(DhcpServerConfiguration.HaRole haRole) throws Exception { boolean isBackup = haRole.equals(DhcpServerConfiguration.HaRole.BACKUP); HaState myLastSavedHaState = null; log.info("Initializing HA state DB: " + stateDbFile); haStateDb = new HaStateDb(); haStateDb.haRole = haRole; haStateDb.haStates = new ArrayList<HaState>(); if (!stateDbFile.exists()) { File haDbDir = stateDbFile.getParentFile(); if (!haDbDir.exists()) { haDbDir.mkdirs(); } stateDbFile.createNewFile(); } else { JsonReader jsonReader = null; try { jsonReader = new JsonReader(new FileReader(stateDbFile)); if (stateDbFile.length() > 0) { HaState haState = null; jsonReader.beginArray(); while (jsonReader.hasNext()) { haState = gson.fromJson(jsonReader, HaState.class); log.debug("Read HA state: " + haState); if (haState != null) { haStateDb.haStates.add(haState); if (!isBackup && isPrimaryState(haState.state)) { myLastSavedHaState = haState; } else if (isBackup && isBackupState(haState.state)) { myLastSavedHaState = haState; } } } jsonReader.endArray(); jsonReader.close(); } } finally { try { if (jsonReader != null) { jsonReader.close(); } } catch (IOException ex) { log.error("Failed to close jsonReader: " + ex); } } } if (myLastSavedHaState == null) { log.info("No saved HA states"); if (!isBackup) { currentHaState = updatePrimaryState(HaPrimaryFSM.State.PRIMARY_INIT); } else { currentHaState = updateBackupState(HaBackupFSM.State.BACKUP_INIT); } } else { log.info("Last saved HA state: " + myLastSavedHaState); currentHaState = myLastSavedHaState; } return currentHaState; }
HaStateDbManager { public HaState init(DhcpServerConfiguration.HaRole haRole) throws Exception { boolean isBackup = haRole.equals(DhcpServerConfiguration.HaRole.BACKUP); HaState myLastSavedHaState = null; log.info("Initializing HA state DB: " + stateDbFile); haStateDb = new HaStateDb(); haStateDb.haRole = haRole; haStateDb.haStates = new ArrayList<HaState>(); if (!stateDbFile.exists()) { File haDbDir = stateDbFile.getParentFile(); if (!haDbDir.exists()) { haDbDir.mkdirs(); } stateDbFile.createNewFile(); } else { JsonReader jsonReader = null; try { jsonReader = new JsonReader(new FileReader(stateDbFile)); if (stateDbFile.length() > 0) { HaState haState = null; jsonReader.beginArray(); while (jsonReader.hasNext()) { haState = gson.fromJson(jsonReader, HaState.class); log.debug("Read HA state: " + haState); if (haState != null) { haStateDb.haStates.add(haState); if (!isBackup && isPrimaryState(haState.state)) { myLastSavedHaState = haState; } else if (isBackup && isBackupState(haState.state)) { myLastSavedHaState = haState; } } } jsonReader.endArray(); jsonReader.close(); } } finally { try { if (jsonReader != null) { jsonReader.close(); } } catch (IOException ex) { log.error("Failed to close jsonReader: " + ex); } } } if (myLastSavedHaState == null) { log.info("No saved HA states"); if (!isBackup) { currentHaState = updatePrimaryState(HaPrimaryFSM.State.PRIMARY_INIT); } else { currentHaState = updateBackupState(HaBackupFSM.State.BACKUP_INIT); } } else { log.info("Last saved HA state: " + myLastSavedHaState); currentHaState = myLastSavedHaState; } return currentHaState; } }
HaStateDbManager { public HaState init(DhcpServerConfiguration.HaRole haRole) throws Exception { boolean isBackup = haRole.equals(DhcpServerConfiguration.HaRole.BACKUP); HaState myLastSavedHaState = null; log.info("Initializing HA state DB: " + stateDbFile); haStateDb = new HaStateDb(); haStateDb.haRole = haRole; haStateDb.haStates = new ArrayList<HaState>(); if (!stateDbFile.exists()) { File haDbDir = stateDbFile.getParentFile(); if (!haDbDir.exists()) { haDbDir.mkdirs(); } stateDbFile.createNewFile(); } else { JsonReader jsonReader = null; try { jsonReader = new JsonReader(new FileReader(stateDbFile)); if (stateDbFile.length() > 0) { HaState haState = null; jsonReader.beginArray(); while (jsonReader.hasNext()) { haState = gson.fromJson(jsonReader, HaState.class); log.debug("Read HA state: " + haState); if (haState != null) { haStateDb.haStates.add(haState); if (!isBackup && isPrimaryState(haState.state)) { myLastSavedHaState = haState; } else if (isBackup && isBackupState(haState.state)) { myLastSavedHaState = haState; } } } jsonReader.endArray(); jsonReader.close(); } } finally { try { if (jsonReader != null) { jsonReader.close(); } } catch (IOException ex) { log.error("Failed to close jsonReader: " + ex); } } } if (myLastSavedHaState == null) { log.info("No saved HA states"); if (!isBackup) { currentHaState = updatePrimaryState(HaPrimaryFSM.State.PRIMARY_INIT); } else { currentHaState = updateBackupState(HaBackupFSM.State.BACKUP_INIT); } } else { log.info("Last saved HA state: " + myLastSavedHaState); currentHaState = myLastSavedHaState; } return currentHaState; } HaStateDbManager(); }
HaStateDbManager { public HaState init(DhcpServerConfiguration.HaRole haRole) throws Exception { boolean isBackup = haRole.equals(DhcpServerConfiguration.HaRole.BACKUP); HaState myLastSavedHaState = null; log.info("Initializing HA state DB: " + stateDbFile); haStateDb = new HaStateDb(); haStateDb.haRole = haRole; haStateDb.haStates = new ArrayList<HaState>(); if (!stateDbFile.exists()) { File haDbDir = stateDbFile.getParentFile(); if (!haDbDir.exists()) { haDbDir.mkdirs(); } stateDbFile.createNewFile(); } else { JsonReader jsonReader = null; try { jsonReader = new JsonReader(new FileReader(stateDbFile)); if (stateDbFile.length() > 0) { HaState haState = null; jsonReader.beginArray(); while (jsonReader.hasNext()) { haState = gson.fromJson(jsonReader, HaState.class); log.debug("Read HA state: " + haState); if (haState != null) { haStateDb.haStates.add(haState); if (!isBackup && isPrimaryState(haState.state)) { myLastSavedHaState = haState; } else if (isBackup && isBackupState(haState.state)) { myLastSavedHaState = haState; } } } jsonReader.endArray(); jsonReader.close(); } } finally { try { if (jsonReader != null) { jsonReader.close(); } } catch (IOException ex) { log.error("Failed to close jsonReader: " + ex); } } } if (myLastSavedHaState == null) { log.info("No saved HA states"); if (!isBackup) { currentHaState = updatePrimaryState(HaPrimaryFSM.State.PRIMARY_INIT); } else { currentHaState = updateBackupState(HaBackupFSM.State.BACKUP_INIT); } } else { log.info("Last saved HA state: " + myLastSavedHaState); currentHaState = myLastSavedHaState; } return currentHaState; } HaStateDbManager(); void deleteStateDbFile(); HaState init(DhcpServerConfiguration.HaRole haRole); boolean isPrimaryState(String state); boolean isBackupState(String state); HaState updatePrimaryState(HaPrimaryFSM.State primaryState); HaState updateBackupState(HaBackupFSM.State backupState); }
HaStateDbManager { public HaState init(DhcpServerConfiguration.HaRole haRole) throws Exception { boolean isBackup = haRole.equals(DhcpServerConfiguration.HaRole.BACKUP); HaState myLastSavedHaState = null; log.info("Initializing HA state DB: " + stateDbFile); haStateDb = new HaStateDb(); haStateDb.haRole = haRole; haStateDb.haStates = new ArrayList<HaState>(); if (!stateDbFile.exists()) { File haDbDir = stateDbFile.getParentFile(); if (!haDbDir.exists()) { haDbDir.mkdirs(); } stateDbFile.createNewFile(); } else { JsonReader jsonReader = null; try { jsonReader = new JsonReader(new FileReader(stateDbFile)); if (stateDbFile.length() > 0) { HaState haState = null; jsonReader.beginArray(); while (jsonReader.hasNext()) { haState = gson.fromJson(jsonReader, HaState.class); log.debug("Read HA state: " + haState); if (haState != null) { haStateDb.haStates.add(haState); if (!isBackup && isPrimaryState(haState.state)) { myLastSavedHaState = haState; } else if (isBackup && isBackupState(haState.state)) { myLastSavedHaState = haState; } } } jsonReader.endArray(); jsonReader.close(); } } finally { try { if (jsonReader != null) { jsonReader.close(); } } catch (IOException ex) { log.error("Failed to close jsonReader: " + ex); } } } if (myLastSavedHaState == null) { log.info("No saved HA states"); if (!isBackup) { currentHaState = updatePrimaryState(HaPrimaryFSM.State.PRIMARY_INIT); } else { currentHaState = updateBackupState(HaBackupFSM.State.BACKUP_INIT); } } else { log.info("Last saved HA state: " + myLastSavedHaState); currentHaState = myLastSavedHaState; } return currentHaState; } HaStateDbManager(); void deleteStateDbFile(); HaState init(DhcpServerConfiguration.HaRole haRole); boolean isPrimaryState(String state); boolean isBackupState(String state); HaState updatePrimaryState(HaPrimaryFSM.State primaryState); HaState updateBackupState(HaBackupFSM.State backupState);  }