AutonomiccsSystemVirtualMachinesTemplateRegister implements InitializingBean { @Scheduled(initialDelay = ONE_MINUTE_IN_MILLISECONDS, fixedDelay = ONE_MINUTE_IN_MILLISECONDS * NUMBER_OF_MINUTES_BETWEEN_REGISTRATION_OF_TEMPLATES) public void registerTemplatesIfNeeded() { if (autonomicManagementHeuristicService.getAdministrationAlgorithm().canHeuristicShutdownHosts() || hostService.isThereAnyHostOnCloudDeactivatedByOurManager()) { List<HypervisorType> allHypervisorsTypeInCloud = hostService.getAllHypervisorsTypeInCloud(); for (HypervisorType hypervisorType : allHypervisorsTypeInCloud) { if (!autonomiccsSystemVmTemplateService.isTemplateRegisteredForHypervisor(hypervisorType)) { RegisterTemplateCmd templateCommandForHypervisor = createRegisterTemplateCommandForHypervisor(hypervisorType); try { templateService.registerTemplate(templateCommandForHypervisor); } catch (Exception e) { logger.error("Error while registering a Autonomiccs system vm. ", e); } } } } }  @Scheduled(initialDelay = ONE_MINUTE_IN_MILLISECONDS, fixedDelay = ONE_MINUTE_IN_MILLISECONDS * NUMBER_OF_MINUTES_BETWEEN_REGISTRATION_OF_TEMPLATES) void registerTemplatesIfNeeded(); @Override void afterPropertiesSet();  }
@Test public void registerTemplatesIfNeededTestHeuristicCannotShutDownHost() throws Exception { configureWithOneHypervisorType(new ClusterManagementDummyAlgorithm(), true, false); spy.registerTemplatesIfNeeded(); verifyRegisterTemplatesIfNeededCalledMethods(1, 1, 1, 1); }
@Test public void registerTemplatesIfNeededTestHeuristicCannotShutDownHostAndNoDeactivatedHost() throws Exception { configureWithOneHypervisorType(new ClusterManagementDummyAlgorithm(), false, false); spy.registerTemplatesIfNeeded(); verifyRegisterTemplatesIfNeededCalledMethods(1, 0, 0, 0); }
@Test public void registerTemplatesIfNeededTestHeuristicCanShutDownHostAndNoDeactivatedHost() throws Exception { configureWithOneHypervisorType(new ConsolidationAlgorithmBase(), false, false); spy.registerTemplatesIfNeeded(); verifyRegisterTemplatesIfNeededCalledMethods(0, 1, 1, 1); }
@Test public void registerTemplatesIfNeededTestIsTemplateRegisteredForHypervisorTrue() throws Exception { configureWithOneHypervisorType(new ConsolidationAlgorithmBase(), false, true); spy.registerTemplatesIfNeeded(); verifyRegisterTemplatesIfNeededCalledMethods(0, 1, 1, 0); }
@Test public void registerTemplatesIfNeededTestIsTemplateRegisteredForHypervisorFalse() throws Exception { configureWithOneHypervisorType(new ConsolidationAlgorithmBase(), true, false); spy.registerTemplatesIfNeeded(); verifyRegisterTemplatesIfNeededCalledMethods(0, 1, 1, 1); }
@Test public void registerTemplatesIfNeededTestHeuristicCanShutDownHostEmptyHypervisorList() throws Exception { configureRegisterTemplatesIfNeededTest(new ConsolidationAlgorithmBase(), true, new ArrayList<HypervisorType>(), false); spy.registerTemplatesIfNeeded(); verifyRegisterTemplatesIfNeededCalledMethods(0, 1, 0, 0); }
@Test public void registerTemplatesIfNeededTestCatchException() throws Exception { configureWithOneHypervisorType(new ConsolidationAlgorithmBase(), true, false); Mockito.doThrow(Exception.class).when(templateService).registerTemplate(Mockito.any(RegisterTemplateCmd.class)); spy.logger = Mockito.mock(Logger.class); spy.registerTemplatesIfNeeded(); verifyRegisterTemplatesIfNeededCalledMethods(0, 1, 1, 1); String exceptionMessage = "Error while registering a Autonomiccs system vm. "; Mockito.verify(spy.logger).error(Mockito.eq(exceptionMessage), Mockito.any(Exception.class)); }