@Test public void bootstrapNewNodesTest() 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)); BootstrapParams bootstrapParams = mock(BootstrapParams.class); saltOrchestrator.bootstrapNewNodes(Collections.singletonList(gatewayConfig), targets, targets, null, bootstrapParams, exitCriteriaModel); verify(saltRunner, times(2)).runner(any(OrchestratorBootstrap.class), any(ExitCriteria.class), any(ExitCriteriaModel.class)); verifyNew(SaltBootstrap.class, times(1)).withArguments(eq(saltConnector), eq(Collections.singletonList(gatewayConfig)), eq(targets), eq(bootstrapParams)); }
@Override public void bootstrapNewNodes(List<GatewayConfig> allGatewayConfigs, Set<Node> targets, Set<Node> allNodes, byte[] stateConfigZip, BootstrapParams params, ExitCriteriaModel exitModel) throws CloudbreakOrchestratorException { GatewayConfig primaryGateway = saltService.getPrimaryGatewayConfig(allGatewayConfigs); Set<String> gatewayTargets = allGatewayConfigs.stream().filter(gc -> targets.stream().anyMatch(n -> gc.getPrivateAddress().equals(n.getPrivateIp()))) .map(GatewayConfig::getPrivateAddress).collect(Collectors.toSet()); try (SaltConnector sc = saltService.createSaltConnector(primaryGateway)) { if (!gatewayTargets.isEmpty()) { uploadSaltConfig(sc, gatewayTargets, stateConfigZip, exitModel); params.setRestartNeeded(true); } uploadSignKey(sc, primaryGateway, gatewayTargets, targets.stream().map(Node::getPrivateIp).collect(Collectors.toSet()), exitModel); Set<Node> nodes = gatewayTargets.isEmpty() ? targets : allNodes; OrchestratorBootstrap saltBootstrap = new SaltBootstrap(sc, allGatewayConfigs, nodes, params); Callable<Boolean> saltBootstrapRunner = saltRunner.runner(saltBootstrap, exitCriteria, exitModel); saltBootstrapRunner.call(); } catch (Exception e) { LOGGER.info("Error occurred during salt upscale", e); throw new CloudbreakOrchestratorFailedException(e); } }
SaltOrchestrator implements HostOrchestrator { @Override public void bootstrapNewNodes(List<GatewayConfig> allGatewayConfigs, Set<Node> targets, Set<Node> allNodes, byte[] stateConfigZip, BootstrapParams params, ExitCriteriaModel exitModel) throws CloudbreakOrchestratorException { GatewayConfig primaryGateway = saltService.getPrimaryGatewayConfig(allGatewayConfigs); Set<String> gatewayTargets = allGatewayConfigs.stream().filter(gc -> targets.stream().anyMatch(n -> gc.getPrivateAddress().equals(n.getPrivateIp()))) .map(GatewayConfig::getPrivateAddress).collect(Collectors.toSet()); try (SaltConnector sc = saltService.createSaltConnector(primaryGateway)) { if (!gatewayTargets.isEmpty()) { uploadSaltConfig(sc, gatewayTargets, stateConfigZip, exitModel); params.setRestartNeeded(true); } uploadSignKey(sc, primaryGateway, gatewayTargets, targets.stream().map(Node::getPrivateIp).collect(Collectors.toSet()), exitModel); Set<Node> nodes = gatewayTargets.isEmpty() ? targets : allNodes; OrchestratorBootstrap saltBootstrap = new SaltBootstrap(sc, allGatewayConfigs, nodes, params); Callable<Boolean> saltBootstrapRunner = saltRunner.runner(saltBootstrap, exitCriteria, exitModel); saltBootstrapRunner.call(); } catch (Exception e) { LOGGER.info("Error occurred during salt upscale", e); throw new CloudbreakOrchestratorFailedException(e); } } }
SaltOrchestrator implements HostOrchestrator { @Override public void bootstrapNewNodes(List<GatewayConfig> allGatewayConfigs, Set<Node> targets, Set<Node> allNodes, byte[] stateConfigZip, BootstrapParams params, ExitCriteriaModel exitModel) throws CloudbreakOrchestratorException { GatewayConfig primaryGateway = saltService.getPrimaryGatewayConfig(allGatewayConfigs); Set<String> gatewayTargets = allGatewayConfigs.stream().filter(gc -> targets.stream().anyMatch(n -> gc.getPrivateAddress().equals(n.getPrivateIp()))) .map(GatewayConfig::getPrivateAddress).collect(Collectors.toSet()); try (SaltConnector sc = saltService.createSaltConnector(primaryGateway)) { if (!gatewayTargets.isEmpty()) { uploadSaltConfig(sc, gatewayTargets, stateConfigZip, exitModel); params.setRestartNeeded(true); } uploadSignKey(sc, primaryGateway, gatewayTargets, targets.stream().map(Node::getPrivateIp).collect(Collectors.toSet()), exitModel); Set<Node> nodes = gatewayTargets.isEmpty() ? targets : allNodes; OrchestratorBootstrap saltBootstrap = new SaltBootstrap(sc, allGatewayConfigs, nodes, params); Callable<Boolean> saltBootstrapRunner = saltRunner.runner(saltBootstrap, exitCriteria, exitModel); saltBootstrapRunner.call(); } catch (Exception e) { LOGGER.info("Error occurred during salt upscale", e); throw new CloudbreakOrchestratorFailedException(e); } }  }
SaltOrchestrator implements HostOrchestrator { @Override public void bootstrapNewNodes(List<GatewayConfig> allGatewayConfigs, Set<Node> targets, Set<Node> allNodes, byte[] stateConfigZip, BootstrapParams params, ExitCriteriaModel exitModel) throws CloudbreakOrchestratorException { GatewayConfig primaryGateway = saltService.getPrimaryGatewayConfig(allGatewayConfigs); Set<String> gatewayTargets = allGatewayConfigs.stream().filter(gc -> targets.stream().anyMatch(n -> gc.getPrivateAddress().equals(n.getPrivateIp()))) .map(GatewayConfig::getPrivateAddress).collect(Collectors.toSet()); try (SaltConnector sc = saltService.createSaltConnector(primaryGateway)) { if (!gatewayTargets.isEmpty()) { uploadSaltConfig(sc, gatewayTargets, stateConfigZip, exitModel); params.setRestartNeeded(true); } uploadSignKey(sc, primaryGateway, gatewayTargets, targets.stream().map(Node::getPrivateIp).collect(Collectors.toSet()), exitModel); Set<Node> nodes = gatewayTargets.isEmpty() ? targets : allNodes; OrchestratorBootstrap saltBootstrap = new SaltBootstrap(sc, allGatewayConfigs, nodes, params); Callable<Boolean> saltBootstrapRunner = saltRunner.runner(saltBootstrap, exitCriteria, exitModel); saltBootstrapRunner.call(); } catch (Exception e) { LOGGER.info("Error occurred during salt upscale", e); throw new CloudbreakOrchestratorFailedException(e); } }  @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 { @Override public void bootstrapNewNodes(List<GatewayConfig> allGatewayConfigs, Set<Node> targets, Set<Node> allNodes, byte[] stateConfigZip, BootstrapParams params, ExitCriteriaModel exitModel) throws CloudbreakOrchestratorException { GatewayConfig primaryGateway = saltService.getPrimaryGatewayConfig(allGatewayConfigs); Set<String> gatewayTargets = allGatewayConfigs.stream().filter(gc -> targets.stream().anyMatch(n -> gc.getPrivateAddress().equals(n.getPrivateIp()))) .map(GatewayConfig::getPrivateAddress).collect(Collectors.toSet()); try (SaltConnector sc = saltService.createSaltConnector(primaryGateway)) { if (!gatewayTargets.isEmpty()) { uploadSaltConfig(sc, gatewayTargets, stateConfigZip, exitModel); params.setRestartNeeded(true); } uploadSignKey(sc, primaryGateway, gatewayTargets, targets.stream().map(Node::getPrivateIp).collect(Collectors.toSet()), exitModel); Set<Node> nodes = gatewayTargets.isEmpty() ? targets : allNodes; OrchestratorBootstrap saltBootstrap = new SaltBootstrap(sc, allGatewayConfigs, nodes, params); Callable<Boolean> saltBootstrapRunner = saltRunner.runner(saltBootstrap, exitCriteria, exitModel); saltBootstrapRunner.call(); } catch (Exception e) { LOGGER.info("Error occurred during salt upscale", e); throw new CloudbreakOrchestratorFailedException(e); } }  @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);  }