@Test public void testCheckHostAndClusterVersions() throws Exception { StateRecoveryManager stateRecoveryManager = injector.getInstance(StateRecoveryManager.class); final Capture<RepositoryVersionState> installFailedHostVersionCapture = EasyMock.newCapture(); final Capture<RepositoryVersionState> installingHostVersionCapture = EasyMock.newCapture(); final Capture<RepositoryVersionState> installedHostVersionCapture = EasyMock.newCapture(); final Capture<RepositoryVersionState> outOfSyncHostVersionCapture = EasyMock.newCapture(); final Capture<RepositoryVersionState> upgradeFailedHostVersionCapture = EasyMock.newCapture(); final Capture<RepositoryVersionState> upgradingHostVersionCapture = EasyMock.newCapture(); final Capture<RepositoryVersionState> upgradedHostVersionCapture = EasyMock.newCapture(); final Capture<RepositoryVersionState> currentHostVersionCapture = EasyMock.newCapture(); expect(hostVersionDAOMock.findAll()).andReturn(new ArrayList<HostVersionEntity>() {{ add(getHostVersionMock("install_failed_version", RepositoryVersionState.INSTALL_FAILED, installFailedHostVersionCapture)); add(getHostVersionMock("installing_version", RepositoryVersionState.INSTALLING, installingHostVersionCapture)); add(getHostVersionMock("installed_version", RepositoryVersionState.INSTALLED, installedHostVersionCapture)); add(getHostVersionMock("out_of_sync_version", RepositoryVersionState.OUT_OF_SYNC, outOfSyncHostVersionCapture)); add(getHostVersionMock("current_version", RepositoryVersionState.CURRENT, currentHostVersionCapture)); }}); final Capture<RepositoryVersionState> installFailedClusterVersionCapture = EasyMock.newCapture(); final Capture<RepositoryVersionState> installingClusterVersionCapture = EasyMock.newCapture(); final Capture<RepositoryVersionState> installedClusterVersionCapture = EasyMock.newCapture(); final Capture<RepositoryVersionState> outOfSyncClusterVersionCapture = EasyMock.newCapture(); final Capture<RepositoryVersionState> upgradeFailedClusterVersionCapture = EasyMock.newCapture(); final Capture<RepositoryVersionState> upgradingClusterVersionCapture = EasyMock.newCapture(); final Capture<RepositoryVersionState> upgradedClusterVersionCapture = EasyMock.newCapture(); final Capture<RepositoryVersionState> currentClusterVersionCapture = EasyMock.newCapture(); expect(clusterVersionDAOMock.findAll()).andReturn(new ArrayList<ClusterVersionEntity>() {{ add(getClusterVersionMock("install_failed_version", RepositoryVersionState.INSTALL_FAILED, installFailedClusterVersionCapture)); add(getClusterVersionMock("installing_version", RepositoryVersionState.INSTALLING, installingClusterVersionCapture)); add(getClusterVersionMock("installed_version", RepositoryVersionState.INSTALLED, installedClusterVersionCapture)); add(getClusterVersionMock("out_of_sync_version", RepositoryVersionState.OUT_OF_SYNC, outOfSyncClusterVersionCapture)); add(getClusterVersionMock("current_version", RepositoryVersionState.CURRENT, currentClusterVersionCapture)); }}); replay(hostVersionDAOMock, clusterVersionDAOMock); stateRecoveryManager.checkHostAndClusterVersions(); assertFalse(installFailedHostVersionCapture.hasCaptured()); assertEquals(installingHostVersionCapture.getValue(), RepositoryVersionState.INSTALL_FAILED); assertFalse(installedHostVersionCapture.hasCaptured()); assertFalse(outOfSyncHostVersionCapture.hasCaptured()); assertFalse(upgradeFailedHostVersionCapture.hasCaptured()); assertFalse(upgradingHostVersionCapture.hasCaptured()); assertFalse(upgradedHostVersionCapture.hasCaptured()); assertFalse(currentHostVersionCapture.hasCaptured()); assertFalse(installFailedClusterVersionCapture.hasCaptured()); assertEquals(installingClusterVersionCapture.getValue(), RepositoryVersionState.INSTALL_FAILED); assertFalse(installedClusterVersionCapture.hasCaptured()); assertFalse(outOfSyncClusterVersionCapture.hasCaptured()); assertFalse(upgradeFailedClusterVersionCapture.hasCaptured()); assertFalse(upgradingClusterVersionCapture.hasCaptured()); assertFalse(upgradedClusterVersionCapture.hasCaptured()); assertFalse(currentClusterVersionCapture.hasCaptured()); }
void checkHostAndClusterVersions() { List<HostVersionEntity> hostVersions = hostVersionDAO.findAll(); for (HostVersionEntity hostVersion : hostVersions) { if (hostVersion.getState().equals(RepositoryVersionState.INSTALLING)) { hostVersion.setState(RepositoryVersionState.INSTALL_FAILED); String msg = String.format( "Recovered state of host version %s on host %s from %s to %s", hostVersion.getRepositoryVersion().getDisplayName(), hostVersion.getHostName(), RepositoryVersionState.INSTALLING, RepositoryVersionState.INSTALL_FAILED); LOG.warn(msg); hostVersionDAO.merge(hostVersion); } } List<ClusterVersionEntity> clusterVersions = clusterVersionDAO.findAll(); for (ClusterVersionEntity clusterVersion : clusterVersions) { if (clusterVersion.getState().equals(RepositoryVersionState.INSTALLING)) { clusterVersion.setState(RepositoryVersionState.INSTALL_FAILED); String msg = String.format( "Recovered state of cluster version %s for cluster %s from %s to %s", clusterVersion.getRepositoryVersion().getDisplayName(), clusterVersion.getClusterEntity().getClusterName(), RepositoryVersionState.INSTALLING, RepositoryVersionState.INSTALL_FAILED); LOG.warn(msg); clusterVersionDAO.merge(clusterVersion); } } }
StateRecoveryManager { void checkHostAndClusterVersions() { List<HostVersionEntity> hostVersions = hostVersionDAO.findAll(); for (HostVersionEntity hostVersion : hostVersions) { if (hostVersion.getState().equals(RepositoryVersionState.INSTALLING)) { hostVersion.setState(RepositoryVersionState.INSTALL_FAILED); String msg = String.format( "Recovered state of host version %s on host %s from %s to %s", hostVersion.getRepositoryVersion().getDisplayName(), hostVersion.getHostName(), RepositoryVersionState.INSTALLING, RepositoryVersionState.INSTALL_FAILED); LOG.warn(msg); hostVersionDAO.merge(hostVersion); } } List<ClusterVersionEntity> clusterVersions = clusterVersionDAO.findAll(); for (ClusterVersionEntity clusterVersion : clusterVersions) { if (clusterVersion.getState().equals(RepositoryVersionState.INSTALLING)) { clusterVersion.setState(RepositoryVersionState.INSTALL_FAILED); String msg = String.format( "Recovered state of cluster version %s for cluster %s from %s to %s", clusterVersion.getRepositoryVersion().getDisplayName(), clusterVersion.getClusterEntity().getClusterName(), RepositoryVersionState.INSTALLING, RepositoryVersionState.INSTALL_FAILED); LOG.warn(msg); clusterVersionDAO.merge(clusterVersion); } } } }
StateRecoveryManager { void checkHostAndClusterVersions() { List<HostVersionEntity> hostVersions = hostVersionDAO.findAll(); for (HostVersionEntity hostVersion : hostVersions) { if (hostVersion.getState().equals(RepositoryVersionState.INSTALLING)) { hostVersion.setState(RepositoryVersionState.INSTALL_FAILED); String msg = String.format( "Recovered state of host version %s on host %s from %s to %s", hostVersion.getRepositoryVersion().getDisplayName(), hostVersion.getHostName(), RepositoryVersionState.INSTALLING, RepositoryVersionState.INSTALL_FAILED); LOG.warn(msg); hostVersionDAO.merge(hostVersion); } } List<ClusterVersionEntity> clusterVersions = clusterVersionDAO.findAll(); for (ClusterVersionEntity clusterVersion : clusterVersions) { if (clusterVersion.getState().equals(RepositoryVersionState.INSTALLING)) { clusterVersion.setState(RepositoryVersionState.INSTALL_FAILED); String msg = String.format( "Recovered state of cluster version %s for cluster %s from %s to %s", clusterVersion.getRepositoryVersion().getDisplayName(), clusterVersion.getClusterEntity().getClusterName(), RepositoryVersionState.INSTALLING, RepositoryVersionState.INSTALL_FAILED); LOG.warn(msg); clusterVersionDAO.merge(clusterVersion); } } }  }
StateRecoveryManager { void checkHostAndClusterVersions() { List<HostVersionEntity> hostVersions = hostVersionDAO.findAll(); for (HostVersionEntity hostVersion : hostVersions) { if (hostVersion.getState().equals(RepositoryVersionState.INSTALLING)) { hostVersion.setState(RepositoryVersionState.INSTALL_FAILED); String msg = String.format( "Recovered state of host version %s on host %s from %s to %s", hostVersion.getRepositoryVersion().getDisplayName(), hostVersion.getHostName(), RepositoryVersionState.INSTALLING, RepositoryVersionState.INSTALL_FAILED); LOG.warn(msg); hostVersionDAO.merge(hostVersion); } } List<ClusterVersionEntity> clusterVersions = clusterVersionDAO.findAll(); for (ClusterVersionEntity clusterVersion : clusterVersions) { if (clusterVersion.getState().equals(RepositoryVersionState.INSTALLING)) { clusterVersion.setState(RepositoryVersionState.INSTALL_FAILED); String msg = String.format( "Recovered state of cluster version %s for cluster %s from %s to %s", clusterVersion.getRepositoryVersion().getDisplayName(), clusterVersion.getClusterEntity().getClusterName(), RepositoryVersionState.INSTALLING, RepositoryVersionState.INSTALL_FAILED); LOG.warn(msg); clusterVersionDAO.merge(clusterVersion); } } }  void doWork(); }
StateRecoveryManager { void checkHostAndClusterVersions() { List<HostVersionEntity> hostVersions = hostVersionDAO.findAll(); for (HostVersionEntity hostVersion : hostVersions) { if (hostVersion.getState().equals(RepositoryVersionState.INSTALLING)) { hostVersion.setState(RepositoryVersionState.INSTALL_FAILED); String msg = String.format( "Recovered state of host version %s on host %s from %s to %s", hostVersion.getRepositoryVersion().getDisplayName(), hostVersion.getHostName(), RepositoryVersionState.INSTALLING, RepositoryVersionState.INSTALL_FAILED); LOG.warn(msg); hostVersionDAO.merge(hostVersion); } } List<ClusterVersionEntity> clusterVersions = clusterVersionDAO.findAll(); for (ClusterVersionEntity clusterVersion : clusterVersions) { if (clusterVersion.getState().equals(RepositoryVersionState.INSTALLING)) { clusterVersion.setState(RepositoryVersionState.INSTALL_FAILED); String msg = String.format( "Recovered state of cluster version %s for cluster %s from %s to %s", clusterVersion.getRepositoryVersion().getDisplayName(), clusterVersion.getClusterEntity().getClusterName(), RepositoryVersionState.INSTALLING, RepositoryVersionState.INSTALL_FAILED); LOG.warn(msg); clusterVersionDAO.merge(clusterVersion); } } }  void doWork();  }