@Test public void getPowerButtonReturnsHostsWhenThereAreLessBackupsThanNeeded() { assertEquals(1, nBackupHostsStrategy.getPowerButtonsToPress( getClusterStateWithLessBackupsThanNeeded()).size()); }
@Override public List<Host> getPowerButtonsToPress(ClusterState clusterState) { if (currentNumberOfBackUpHosts(clusterState) > desiredBackupHosts) { return hostSelector.selectHostsToBeTurnedOff( clusterState.getHostsWithoutVmsAndSwitchedOn(), currentNumberOfBackUpHosts(clusterState) - desiredBackupHosts); } return hostSelector.selectHostsToBeTurnedOn( clusterState.getTurnedOffHosts(), desiredBackupHosts - currentNumberOfBackUpHosts(clusterState)); }
NBackupHostsStrategy implements PowerButtonStrategy { @Override public List<Host> getPowerButtonsToPress(ClusterState clusterState) { if (currentNumberOfBackUpHosts(clusterState) > desiredBackupHosts) { return hostSelector.selectHostsToBeTurnedOff( clusterState.getHostsWithoutVmsAndSwitchedOn(), currentNumberOfBackUpHosts(clusterState) - desiredBackupHosts); } return hostSelector.selectHostsToBeTurnedOn( clusterState.getTurnedOffHosts(), desiredBackupHosts - currentNumberOfBackUpHosts(clusterState)); } }
NBackupHostsStrategy implements PowerButtonStrategy { @Override public List<Host> getPowerButtonsToPress(ClusterState clusterState) { if (currentNumberOfBackUpHosts(clusterState) > desiredBackupHosts) { return hostSelector.selectHostsToBeTurnedOff( clusterState.getHostsWithoutVmsAndSwitchedOn(), currentNumberOfBackUpHosts(clusterState) - desiredBackupHosts); } return hostSelector.selectHostsToBeTurnedOn( clusterState.getTurnedOffHosts(), desiredBackupHosts - currentNumberOfBackUpHosts(clusterState)); } NBackupHostsStrategy(int desiredBackupHosts, HostSelector hostSelector); }
NBackupHostsStrategy implements PowerButtonStrategy { @Override public List<Host> getPowerButtonsToPress(ClusterState clusterState) { if (currentNumberOfBackUpHosts(clusterState) > desiredBackupHosts) { return hostSelector.selectHostsToBeTurnedOff( clusterState.getHostsWithoutVmsAndSwitchedOn(), currentNumberOfBackUpHosts(clusterState) - desiredBackupHosts); } return hostSelector.selectHostsToBeTurnedOn( clusterState.getTurnedOffHosts(), desiredBackupHosts - currentNumberOfBackUpHosts(clusterState)); } NBackupHostsStrategy(int desiredBackupHosts, HostSelector hostSelector); @Override List<Host> getPowerButtonsToPress(ClusterState clusterState); }
NBackupHostsStrategy implements PowerButtonStrategy { @Override public List<Host> getPowerButtonsToPress(ClusterState clusterState) { if (currentNumberOfBackUpHosts(clusterState) > desiredBackupHosts) { return hostSelector.selectHostsToBeTurnedOff( clusterState.getHostsWithoutVmsAndSwitchedOn(), currentNumberOfBackUpHosts(clusterState) - desiredBackupHosts); } return hostSelector.selectHostsToBeTurnedOn( clusterState.getTurnedOffHosts(), desiredBackupHosts - currentNumberOfBackUpHosts(clusterState)); } NBackupHostsStrategy(int desiredBackupHosts, HostSelector hostSelector); @Override List<Host> getPowerButtonsToPress(ClusterState clusterState);  }