AdministrationAgent implements InitializingBean { protected void shutdownHost(long hostId) { try { checkIfHostIsUpAndEnabled(hostId); List<VMInstanceVO> vms = hostService.listAllVmsFromHost(hostId); if (CollectionUtils.isNotEmpty(vms)) { logger.debug(String.format("Could not shut dow host [id=%d], there are %d VMs running in this host.", hostId, vms.size())); return; } putHostInMaintenance(hostId); hypervisorManager.shutdownHost(hostService.findHostById(hostId)); } catch (Exception e) { logger.info(String.format("Error while shutting down host [id=%d]", hostId), e); } }  void receiveClusterToBeManaged(Long clusterId); Long searchClusterToBeManaged(); List<ClusterResourcesUp> createAllClustersResourcesUp(); @Override void afterPropertiesSet();  }
@Test public void shutdownHostTestHostWithoutVms() { setupShutdownHostTest(new ArrayList<VMInstanceVO>()); administrationAgent.shutdownHost(0l); verifyShutdownHostCalledMethods(1, 1, 1); }
@Test public void shutdownHostTestExceptionThrownByShutdownHost() { setupShutdownHostTest(new ArrayList<VMInstanceVO>()); Mockito.doThrow(CloudRuntimeException.class).when(hypervisorManager).shutdownHost(Mockito.any(HostVO.class)); administrationAgent.shutdownHost(0l); verifyShutdownHostCalledMethods(1, 1, 1); }
@Test public void shutdownHostTestHostWithVms() { setupShutdownHostTest(createVms()); administrationAgent.shutdownHost(0l); verifyShutdownHostCalledMethods(1, 0, 0); }