@Test public void runServiceTest() throws Exception { whenNew(SaltBootstrap.class).withAnyArguments().thenReturn(mock(SaltBootstrap.class)); whenNew(OrchestratorBootstrapRunner.class) .withArguments(any(OrchestratorBootstrap.class), any(ExitCriteria.class), any(ExitCriteriaModel.class), isNull(), anyInt(), anyInt(), anyInt()) .thenReturn(mock(OrchestratorBootstrapRunner.class)); PillarSave pillarSave = mock(PillarSave.class); whenNew(PillarSave.class).withAnyArguments().thenReturn(pillarSave); GrainAddRunner addRemoveGrainRunner = mock(GrainAddRunner.class); whenNew(GrainAddRunner.class).withAnyArguments().thenReturn(addRemoveGrainRunner); SaltCommandTracker roleCheckerSaltCommandTracker = mock(SaltCommandTracker.class); whenNew(SaltCommandTracker.class).withArguments(eq(saltConnector), eq(addRemoveGrainRunner)).thenReturn(roleCheckerSaltCommandTracker); SyncAllRunner syncAllRunner = mock(SyncAllRunner.class); whenNew(SyncAllRunner.class).withAnyArguments().thenReturn(syncAllRunner); SaltCommandTracker syncGrainsCheckerSaltCommandTracker = mock(SaltCommandTracker.class); whenNew(SaltCommandTracker.class).withArguments(eq(saltConnector), eq(syncAllRunner)).thenReturn(syncGrainsCheckerSaltCommandTracker); HighStateAllRunner highStateAllRunner = mock(HighStateAllRunner.class); whenNew(HighStateAllRunner.class).withAnyArguments().thenReturn(highStateAllRunner); SaltJobIdTracker saltJobIdTracker = mock(SaltJobIdTracker.class); whenNew(SaltJobIdTracker.class).withAnyArguments().thenReturn(saltJobIdTracker); MineUpdateRunner mineUpdateRunner = mock(MineUpdateRunner.class); whenNew(MineUpdateRunner.class).withAnyArguments().thenReturn(mineUpdateRunner); SaltCommandTracker mineUpdateRunnerSaltCommandTracker = mock(SaltCommandTracker.class); whenNew(SaltCommandTracker.class).withArguments(eq(saltConnector), eq(mineUpdateRunner)).thenReturn(mineUpdateRunnerSaltCommandTracker); PowerMockito.mockStatic(SaltStates.class); PowerMockito.when(SaltStates.getGrains(any(), any(), any())).thenReturn(new HashMap<>()); SaltConfig saltConfig = new SaltConfig(); saltOrchestrator.initServiceRun(Collections.singletonList(gatewayConfig), targets, saltConfig, exitCriteriaModel); saltOrchestrator.runService(Collections.singletonList(gatewayConfig), targets, saltConfig, exitCriteriaModel); Set<String> allNodes = targets.stream().map(Node::getHostname).collect(Collectors.toSet()); verifyNew(SyncAllRunner.class, times(1)).withArguments(eq(allNodes), eq(targets)); verifyNew(HighStateAllRunner.class, atLeastOnce()).withArguments(eq(allNodes), eq(targets)); verifyNew(SaltJobIdTracker.class, atLeastOnce()).withArguments(eq(saltConnector), eq(highStateAllRunner), eq(true)); verify(saltCommandRunner, times(4)).runSaltCommand(any(SaltConnector.class), any(BaseSaltJobRunner.class), any(ExitCriteriaModel.class), any(ExitCriteria.class)); verify(grainUploader, times(1)).uploadGrains(anySet(), anyList(), any(ExitCriteriaModel.class), any(SaltConnector.class), any(ExitCriteria.class)); }
@SuppressFBWarnings("REC_CATCH_EXCEPTION") @Override public void runService(List<GatewayConfig> allGateway, Set<Node> allNodes, SaltConfig saltConfig, ExitCriteriaModel exitModel) throws CloudbreakOrchestratorException { LOGGER.debug("Run Services on nodes: {}", allNodes); GatewayConfig primaryGateway = saltService.getPrimaryGatewayConfig(allGateway); try (SaltConnector sc = saltService.createSaltConnector(primaryGateway)) { retry.testWith2SecDelayMax5Times(() -> getRolesBeforeHighstateMagic(sc)); Set<String> allHostnames = allNodes.stream().map(Node::getHostname).collect(Collectors.toSet()); runNewService(sc, new HighStateAllRunner(allHostnames, allNodes), exitModel); } catch (ExecutionException e) { LOGGER.info("Error occurred during bootstrap", e); if (e.getCause() instanceof CloudbreakOrchestratorFailedException) { throw (CloudbreakOrchestratorFailedException) e.getCause(); } throw new CloudbreakOrchestratorFailedException(e); } catch (Exception e) { LOGGER.info("Error occurred during bootstrap", e); throw new CloudbreakOrchestratorFailedException(e); } LOGGER.debug("Run services on nodes finished: {}", allNodes); }
SaltOrchestrator implements HostOrchestrator { @SuppressFBWarnings("REC_CATCH_EXCEPTION") @Override public void runService(List<GatewayConfig> allGateway, Set<Node> allNodes, SaltConfig saltConfig, ExitCriteriaModel exitModel) throws CloudbreakOrchestratorException { LOGGER.debug("Run Services on nodes: {}", allNodes); GatewayConfig primaryGateway = saltService.getPrimaryGatewayConfig(allGateway); try (SaltConnector sc = saltService.createSaltConnector(primaryGateway)) { retry.testWith2SecDelayMax5Times(() -> getRolesBeforeHighstateMagic(sc)); Set<String> allHostnames = allNodes.stream().map(Node::getHostname).collect(Collectors.toSet()); runNewService(sc, new HighStateAllRunner(allHostnames, allNodes), exitModel); } catch (ExecutionException e) { LOGGER.info("Error occurred during bootstrap", e); if (e.getCause() instanceof CloudbreakOrchestratorFailedException) { throw (CloudbreakOrchestratorFailedException) e.getCause(); } throw new CloudbreakOrchestratorFailedException(e); } catch (Exception e) { LOGGER.info("Error occurred during bootstrap", e); throw new CloudbreakOrchestratorFailedException(e); } LOGGER.debug("Run services on nodes finished: {}", allNodes); } }
SaltOrchestrator implements HostOrchestrator { @SuppressFBWarnings("REC_CATCH_EXCEPTION") @Override public void runService(List<GatewayConfig> allGateway, Set<Node> allNodes, SaltConfig saltConfig, ExitCriteriaModel exitModel) throws CloudbreakOrchestratorException { LOGGER.debug("Run Services on nodes: {}", allNodes); GatewayConfig primaryGateway = saltService.getPrimaryGatewayConfig(allGateway); try (SaltConnector sc = saltService.createSaltConnector(primaryGateway)) { retry.testWith2SecDelayMax5Times(() -> getRolesBeforeHighstateMagic(sc)); Set<String> allHostnames = allNodes.stream().map(Node::getHostname).collect(Collectors.toSet()); runNewService(sc, new HighStateAllRunner(allHostnames, allNodes), exitModel); } catch (ExecutionException e) { LOGGER.info("Error occurred during bootstrap", e); if (e.getCause() instanceof CloudbreakOrchestratorFailedException) { throw (CloudbreakOrchestratorFailedException) e.getCause(); } throw new CloudbreakOrchestratorFailedException(e); } catch (Exception e) { LOGGER.info("Error occurred during bootstrap", e); throw new CloudbreakOrchestratorFailedException(e); } LOGGER.debug("Run services on nodes finished: {}", allNodes); }  }
SaltOrchestrator implements HostOrchestrator { @SuppressFBWarnings("REC_CATCH_EXCEPTION") @Override public void runService(List<GatewayConfig> allGateway, Set<Node> allNodes, SaltConfig saltConfig, ExitCriteriaModel exitModel) throws CloudbreakOrchestratorException { LOGGER.debug("Run Services on nodes: {}", allNodes); GatewayConfig primaryGateway = saltService.getPrimaryGatewayConfig(allGateway); try (SaltConnector sc = saltService.createSaltConnector(primaryGateway)) { retry.testWith2SecDelayMax5Times(() -> getRolesBeforeHighstateMagic(sc)); Set<String> allHostnames = allNodes.stream().map(Node::getHostname).collect(Collectors.toSet()); runNewService(sc, new HighStateAllRunner(allHostnames, allNodes), exitModel); } catch (ExecutionException e) { LOGGER.info("Error occurred during bootstrap", e); if (e.getCause() instanceof CloudbreakOrchestratorFailedException) { throw (CloudbreakOrchestratorFailedException) e.getCause(); } throw new CloudbreakOrchestratorFailedException(e); } catch (Exception e) { LOGGER.info("Error occurred during bootstrap", e); throw new CloudbreakOrchestratorFailedException(e); } LOGGER.debug("Run services on nodes finished: {}", allNodes); }  @Override void bootstrap(List<GatewayConfig> allGatewayConfigs, Set<Node> targets, BootstrapParams params,
            ExitCriteriaModel exitModel); @Override Map<String, Map<String, String>> formatAndMountDisksOnNodes(List<GatewayConfig> allGateway, Set<Node> nodes, Set<Node> allNodes,
            ExitCriteriaModel exitModel, String platformVariant); @Override void bootstrapNewNodes(List<GatewayConfig> allGatewayConfigs, Set<Node> targets, Set<Node> allNodes, byte[] stateConfigZip, BootstrapParams params,
            ExitCriteriaModel exitModel); @SuppressFBWarnings("REC_CATCH_EXCEPTION") @Override void initServiceRun(List<GatewayConfig> allGateway, Set<Node> allNodes, SaltConfig saltConfig, ExitCriteriaModel exitModel); @Override void initSaltConfig(List<GatewayConfig> allGateway, Set<Node> allNodes, SaltConfig saltConfig, ExitCriteriaModel exitModel); @SuppressFBWarnings("REC_CATCH_EXCEPTION") @Override void runService(List<GatewayConfig> allGateway, Set<Node> allNodes, SaltConfig saltConfig, ExitCriteriaModel exitModel); @SuppressFBWarnings("REC_CATCH_EXCEPTION") @Override void changePrimaryGateway(GatewayConfig formerGateway, GatewayConfig newPrimaryGateway, List<GatewayConfig> allGatewayConfigs, Set<Node> allNodes,
            ExitCriteriaModel exitCriteriaModel); @SuppressFBWarnings("REC_CATCH_EXCEPTION") @Override void installFreeIpa(GatewayConfig primaryGateway, List<GatewayConfig> allGatewayConfigs, Set<Node> allNodes,
            ExitCriteriaModel exitCriteriaModel); @Override Optional<String> getFreeIpaMasterHostname(GatewayConfig primaryGateway); @Override void resetClusterManager(GatewayConfig gatewayConfig, Set<String> target, Set<Node> allNodes, ExitCriteriaModel exitCriteriaModel); @Override void stopClusterManagerOnMaster(GatewayConfig gatewayConfig, Set<Node> allNodes, ExitCriteriaModel exitCriteriaModel); @Override void startClusterManagerOnMaster(GatewayConfig gatewayConfig, Set<Node> allNodes, ExitCriteriaModel exitCriteriaModel); @SuppressFBWarnings("REC_CATCH_EXCEPTION") @Override void upgradeClusterManager(GatewayConfig gatewayConfig, Set<String> target, Set<Node> allNodes, SaltConfig pillarConfig,
            ExitCriteriaModel exitCriteriaModel); @Override void tearDown(List<GatewayConfig> allGatewayConfigs, Map<String, String> removeNodePrivateIPsByFQDN,
            Set<Node> remainingNodes, ExitCriteriaModel exitModel); Map<String, Map<String, String>> getPackageVersionsFromAllHosts(GatewayConfig gateway, Map<String, Optional<String>> packages); Map<String, String> runCommandOnAllHosts(GatewayConfig gateway, String command); @Override Map<String, JsonNode> getGrainOnAllHosts(GatewayConfig gateway, String grain); @Override void uploadRecipes(List<GatewayConfig> allGatewayConfigs, Map<String, List<RecipeModel>> recipes, ExitCriteriaModel exitModel); @Override void uploadKeytabs(List<GatewayConfig> allGatewayConfigs, Set<KeytabModel> keytabModels, ExitCriteriaModel exitModel); @Override Map<String, Map<String, String>> formatAndMountDisksOnNodesLegacy(List<GatewayConfig> gatewayConfigs, Set<Node> nodes, Set<Node> allNodes,
            ExitCriteriaModel exitCriteriaModel, String platformVariant); @Override void applyDiagnosticsState(List<GatewayConfig> gatewayConfigs, String state, Map<String, Object> properties,
            ExitCriteriaModel exitCriteriaModel); @Override byte[] getStateConfigZip(); @Override void preClusterManagerStartRecipes(GatewayConfig gatewayConfig, Set<Node> allNodes, ExitCriteriaModel exitCriteriaModel); @Override void postClusterManagerStartRecipes(GatewayConfig gatewayConfig, Set<Node> allNodes, ExitCriteriaModel exitCriteriaModel); @Override void postInstallRecipes(GatewayConfig gatewayConfig, Set<Node> allNodes, ExitCriteriaModel exitCriteriaModel); @Override void preTerminationRecipes(GatewayConfig gatewayConfig, Set<Node> allNodes, ExitCriteriaModel exitCriteriaModel, boolean forced); @Override void stopClusterManagerAgent(GatewayConfig gatewayConfig, Set<Node> nodes, ExitCriteriaModel exitCriteriaModel, boolean adJoinable,
            boolean ipaJoinable, boolean forced); @Override void uploadGatewayPillar(List<GatewayConfig> allGatewayConfigs, Set<Node> allNodes, ExitCriteriaModel exitModel, SaltConfig saltConfig); void leaveDomain(GatewayConfig gatewayConfig, Set<Node> allNodes, String roleToRemove, String roleToAdd, ExitCriteriaModel exitCriteriaModel); @Override List<String> getMissingNodes(GatewayConfig gatewayConfig, Set<Node> nodes); @Override List<String> getAvailableNodes(GatewayConfig gatewayConfig, Set<Node> nodes); @Override boolean isBootstrapApiAvailable(GatewayConfig gatewayConfig); @Override String name(); @Override Map<String, String> getMembers(GatewayConfig gatewayConfig, List<String> privateIps); @Override void backupDatabase(GatewayConfig primaryGateway, Set<String> target, Set<Node> allNodes, SaltConfig saltConfig,
            ExitCriteriaModel exitModel); @Override void restoreDatabase(GatewayConfig primaryGateway, Set<String> target, Set<Node> allNodes, SaltConfig saltConfig,
                                ExitCriteriaModel exitModel); }
SaltOrchestrator implements HostOrchestrator { @SuppressFBWarnings("REC_CATCH_EXCEPTION") @Override public void runService(List<GatewayConfig> allGateway, Set<Node> allNodes, SaltConfig saltConfig, ExitCriteriaModel exitModel) throws CloudbreakOrchestratorException { LOGGER.debug("Run Services on nodes: {}", allNodes); GatewayConfig primaryGateway = saltService.getPrimaryGatewayConfig(allGateway); try (SaltConnector sc = saltService.createSaltConnector(primaryGateway)) { retry.testWith2SecDelayMax5Times(() -> getRolesBeforeHighstateMagic(sc)); Set<String> allHostnames = allNodes.stream().map(Node::getHostname).collect(Collectors.toSet()); runNewService(sc, new HighStateAllRunner(allHostnames, allNodes), exitModel); } catch (ExecutionException e) { LOGGER.info("Error occurred during bootstrap", e); if (e.getCause() instanceof CloudbreakOrchestratorFailedException) { throw (CloudbreakOrchestratorFailedException) e.getCause(); } throw new CloudbreakOrchestratorFailedException(e); } catch (Exception e) { LOGGER.info("Error occurred during bootstrap", e); throw new CloudbreakOrchestratorFailedException(e); } LOGGER.debug("Run services on nodes finished: {}", allNodes); }  @Override void bootstrap(List<GatewayConfig> allGatewayConfigs, Set<Node> targets, BootstrapParams params,
            ExitCriteriaModel exitModel); @Override Map<String, Map<String, String>> formatAndMountDisksOnNodes(List<GatewayConfig> allGateway, Set<Node> nodes, Set<Node> allNodes,
            ExitCriteriaModel exitModel, String platformVariant); @Override void bootstrapNewNodes(List<GatewayConfig> allGatewayConfigs, Set<Node> targets, Set<Node> allNodes, byte[] stateConfigZip, BootstrapParams params,
            ExitCriteriaModel exitModel); @SuppressFBWarnings("REC_CATCH_EXCEPTION") @Override void initServiceRun(List<GatewayConfig> allGateway, Set<Node> allNodes, SaltConfig saltConfig, ExitCriteriaModel exitModel); @Override void initSaltConfig(List<GatewayConfig> allGateway, Set<Node> allNodes, SaltConfig saltConfig, ExitCriteriaModel exitModel); @SuppressFBWarnings("REC_CATCH_EXCEPTION") @Override void runService(List<GatewayConfig> allGateway, Set<Node> allNodes, SaltConfig saltConfig, ExitCriteriaModel exitModel); @SuppressFBWarnings("REC_CATCH_EXCEPTION") @Override void changePrimaryGateway(GatewayConfig formerGateway, GatewayConfig newPrimaryGateway, List<GatewayConfig> allGatewayConfigs, Set<Node> allNodes,
            ExitCriteriaModel exitCriteriaModel); @SuppressFBWarnings("REC_CATCH_EXCEPTION") @Override void installFreeIpa(GatewayConfig primaryGateway, List<GatewayConfig> allGatewayConfigs, Set<Node> allNodes,
            ExitCriteriaModel exitCriteriaModel); @Override Optional<String> getFreeIpaMasterHostname(GatewayConfig primaryGateway); @Override void resetClusterManager(GatewayConfig gatewayConfig, Set<String> target, Set<Node> allNodes, ExitCriteriaModel exitCriteriaModel); @Override void stopClusterManagerOnMaster(GatewayConfig gatewayConfig, Set<Node> allNodes, ExitCriteriaModel exitCriteriaModel); @Override void startClusterManagerOnMaster(GatewayConfig gatewayConfig, Set<Node> allNodes, ExitCriteriaModel exitCriteriaModel); @SuppressFBWarnings("REC_CATCH_EXCEPTION") @Override void upgradeClusterManager(GatewayConfig gatewayConfig, Set<String> target, Set<Node> allNodes, SaltConfig pillarConfig,
            ExitCriteriaModel exitCriteriaModel); @Override void tearDown(List<GatewayConfig> allGatewayConfigs, Map<String, String> removeNodePrivateIPsByFQDN,
            Set<Node> remainingNodes, ExitCriteriaModel exitModel); Map<String, Map<String, String>> getPackageVersionsFromAllHosts(GatewayConfig gateway, Map<String, Optional<String>> packages); Map<String, String> runCommandOnAllHosts(GatewayConfig gateway, String command); @Override Map<String, JsonNode> getGrainOnAllHosts(GatewayConfig gateway, String grain); @Override void uploadRecipes(List<GatewayConfig> allGatewayConfigs, Map<String, List<RecipeModel>> recipes, ExitCriteriaModel exitModel); @Override void uploadKeytabs(List<GatewayConfig> allGatewayConfigs, Set<KeytabModel> keytabModels, ExitCriteriaModel exitModel); @Override Map<String, Map<String, String>> formatAndMountDisksOnNodesLegacy(List<GatewayConfig> gatewayConfigs, Set<Node> nodes, Set<Node> allNodes,
            ExitCriteriaModel exitCriteriaModel, String platformVariant); @Override void applyDiagnosticsState(List<GatewayConfig> gatewayConfigs, String state, Map<String, Object> properties,
            ExitCriteriaModel exitCriteriaModel); @Override byte[] getStateConfigZip(); @Override void preClusterManagerStartRecipes(GatewayConfig gatewayConfig, Set<Node> allNodes, ExitCriteriaModel exitCriteriaModel); @Override void postClusterManagerStartRecipes(GatewayConfig gatewayConfig, Set<Node> allNodes, ExitCriteriaModel exitCriteriaModel); @Override void postInstallRecipes(GatewayConfig gatewayConfig, Set<Node> allNodes, ExitCriteriaModel exitCriteriaModel); @Override void preTerminationRecipes(GatewayConfig gatewayConfig, Set<Node> allNodes, ExitCriteriaModel exitCriteriaModel, boolean forced); @Override void stopClusterManagerAgent(GatewayConfig gatewayConfig, Set<Node> nodes, ExitCriteriaModel exitCriteriaModel, boolean adJoinable,
            boolean ipaJoinable, boolean forced); @Override void uploadGatewayPillar(List<GatewayConfig> allGatewayConfigs, Set<Node> allNodes, ExitCriteriaModel exitModel, SaltConfig saltConfig); void leaveDomain(GatewayConfig gatewayConfig, Set<Node> allNodes, String roleToRemove, String roleToAdd, ExitCriteriaModel exitCriteriaModel); @Override List<String> getMissingNodes(GatewayConfig gatewayConfig, Set<Node> nodes); @Override List<String> getAvailableNodes(GatewayConfig gatewayConfig, Set<Node> nodes); @Override boolean isBootstrapApiAvailable(GatewayConfig gatewayConfig); @Override String name(); @Override Map<String, String> getMembers(GatewayConfig gatewayConfig, List<String> privateIps); @Override void backupDatabase(GatewayConfig primaryGateway, Set<String> target, Set<Node> allNodes, SaltConfig saltConfig,
            ExitCriteriaModel exitModel); @Override void restoreDatabase(GatewayConfig primaryGateway, Set<String> target, Set<Node> allNodes, SaltConfig saltConfig,
                                ExitCriteriaModel exitModel);  }