@Test public void callTest() throws Exception { List<Map<String, JsonNode>> result = new ArrayList<>(); Map<String, JsonNode> ipAddressesForMinions = new HashMap<>(); ipAddressesForMinions.put("10-0-0-1.example.com", JsonUtil.readTree("[\"10.0.0.1\"]")); ipAddressesForMinions.put("10-0-0-2.example.com", JsonUtil.readTree("[\"10.0.0.2\"]")); ipAddressesForMinions.put("10-0-0-3.example.com", JsonUtil.readTree("[\"10.0.0.3\"]")); result.add(ipAddressesForMinions); minionIpAddressesResponse.setResult(result); Set<Node> targets = new HashSet<>(); targets.add(new Node("10.0.0.1", null, null, "hg")); targets.add(new Node("10.0.0.2", null, null, "hg")); targets.add(new Node("10.0.0.3", null, null, "hg")); SaltBootstrap saltBootstrap = new SaltBootstrap(saltConnector, Collections.singletonList(gatewayConfig), targets, new BootstrapParams()); saltBootstrap = spy(saltBootstrap); doReturn(mock(MinionAcceptor.class)).when(saltBootstrap).createMinionAcceptor(any(SaltAction.class)); saltBootstrap.call(); }
@Override public Boolean call() throws Exception { LOGGER.debug("Bootstrapping of nodes [{}/{}]", originalTargets.size() - targets.size(), originalTargets.size()); if (!targets.isEmpty()) { LOGGER.debug("Missing targets for SaltBootstrap: {}", targets); SaltAction saltAction = createBootstrap(params.isRestartNeeded()); GenericResponses responses = sc.action(saltAction); Set<Node> failedTargets = new HashSet<>(); LOGGER.debug("SaltBootstrap responses: {}", responses); for (GenericResponse genericResponse : responses.getResponses()) { if (genericResponse.getStatusCode() != HttpStatus.OK.value()) { LOGGER.info("Failed to distributed salt run to: {}, error: {}", genericResponse.getAddress(), genericResponse.getErrorText()); String address = genericResponse.getAddress().split(":")[0]; failedTargets.addAll(originalTargets.stream().filter(a -> a.getPrivateIp().equals(address)).collect(Collectors.toList())); } } targets = failedTargets; if (!targets.isEmpty()) { LOGGER.info("Missing nodes to run saltbootstrap: {}", targets); throw new CloudbreakOrchestratorFailedException("There are missing nodes from saltbootstrap: " + targets); } if (params.isRestartNeeded()) { params.setRestartNeeded(false); } createMinionAcceptor(saltAction).acceptMinions(); } MinionIpAddressesResponse minionIpAddressesResponse = SaltStates.collectMinionIpAddresses(sc); if (minionIpAddressesResponse != null) { originalTargets.forEach(node -> { if (!minionIpAddressesResponse.getAllIpAddresses().contains(node.getPrivateIp())) { LOGGER.info("Salt-minion is not responding on host: {}, yet", node); targets.add(node); } }); } else { throw new CloudbreakOrchestratorFailedException("Minions ip address collection returned null value"); } if (!targets.isEmpty()) { throw new CloudbreakOrchestratorFailedException("There are missing nodes from salt network response: " + targets); } LOGGER.debug("Bootstrapping of nodes completed: {}", originalTargets.size()); return true; }
SaltBootstrap implements OrchestratorBootstrap { @Override public Boolean call() throws Exception { LOGGER.debug("Bootstrapping of nodes [{}/{}]", originalTargets.size() - targets.size(), originalTargets.size()); if (!targets.isEmpty()) { LOGGER.debug("Missing targets for SaltBootstrap: {}", targets); SaltAction saltAction = createBootstrap(params.isRestartNeeded()); GenericResponses responses = sc.action(saltAction); Set<Node> failedTargets = new HashSet<>(); LOGGER.debug("SaltBootstrap responses: {}", responses); for (GenericResponse genericResponse : responses.getResponses()) { if (genericResponse.getStatusCode() != HttpStatus.OK.value()) { LOGGER.info("Failed to distributed salt run to: {}, error: {}", genericResponse.getAddress(), genericResponse.getErrorText()); String address = genericResponse.getAddress().split(":")[0]; failedTargets.addAll(originalTargets.stream().filter(a -> a.getPrivateIp().equals(address)).collect(Collectors.toList())); } } targets = failedTargets; if (!targets.isEmpty()) { LOGGER.info("Missing nodes to run saltbootstrap: {}", targets); throw new CloudbreakOrchestratorFailedException("There are missing nodes from saltbootstrap: " + targets); } if (params.isRestartNeeded()) { params.setRestartNeeded(false); } createMinionAcceptor(saltAction).acceptMinions(); } MinionIpAddressesResponse minionIpAddressesResponse = SaltStates.collectMinionIpAddresses(sc); if (minionIpAddressesResponse != null) { originalTargets.forEach(node -> { if (!minionIpAddressesResponse.getAllIpAddresses().contains(node.getPrivateIp())) { LOGGER.info("Salt-minion is not responding on host: {}, yet", node); targets.add(node); } }); } else { throw new CloudbreakOrchestratorFailedException("Minions ip address collection returned null value"); } if (!targets.isEmpty()) { throw new CloudbreakOrchestratorFailedException("There are missing nodes from salt network response: " + targets); } LOGGER.debug("Bootstrapping of nodes completed: {}", originalTargets.size()); return true; } }
SaltBootstrap implements OrchestratorBootstrap { @Override public Boolean call() throws Exception { LOGGER.debug("Bootstrapping of nodes [{}/{}]", originalTargets.size() - targets.size(), originalTargets.size()); if (!targets.isEmpty()) { LOGGER.debug("Missing targets for SaltBootstrap: {}", targets); SaltAction saltAction = createBootstrap(params.isRestartNeeded()); GenericResponses responses = sc.action(saltAction); Set<Node> failedTargets = new HashSet<>(); LOGGER.debug("SaltBootstrap responses: {}", responses); for (GenericResponse genericResponse : responses.getResponses()) { if (genericResponse.getStatusCode() != HttpStatus.OK.value()) { LOGGER.info("Failed to distributed salt run to: {}, error: {}", genericResponse.getAddress(), genericResponse.getErrorText()); String address = genericResponse.getAddress().split(":")[0]; failedTargets.addAll(originalTargets.stream().filter(a -> a.getPrivateIp().equals(address)).collect(Collectors.toList())); } } targets = failedTargets; if (!targets.isEmpty()) { LOGGER.info("Missing nodes to run saltbootstrap: {}", targets); throw new CloudbreakOrchestratorFailedException("There are missing nodes from saltbootstrap: " + targets); } if (params.isRestartNeeded()) { params.setRestartNeeded(false); } createMinionAcceptor(saltAction).acceptMinions(); } MinionIpAddressesResponse minionIpAddressesResponse = SaltStates.collectMinionIpAddresses(sc); if (minionIpAddressesResponse != null) { originalTargets.forEach(node -> { if (!minionIpAddressesResponse.getAllIpAddresses().contains(node.getPrivateIp())) { LOGGER.info("Salt-minion is not responding on host: {}, yet", node); targets.add(node); } }); } else { throw new CloudbreakOrchestratorFailedException("Minions ip address collection returned null value"); } if (!targets.isEmpty()) { throw new CloudbreakOrchestratorFailedException("There are missing nodes from salt network response: " + targets); } LOGGER.debug("Bootstrapping of nodes completed: {}", originalTargets.size()); return true; } SaltBootstrap(SaltConnector sc, List<GatewayConfig> allGatewayConfigs, Set<Node> targets, BootstrapParams params); }
SaltBootstrap implements OrchestratorBootstrap { @Override public Boolean call() throws Exception { LOGGER.debug("Bootstrapping of nodes [{}/{}]", originalTargets.size() - targets.size(), originalTargets.size()); if (!targets.isEmpty()) { LOGGER.debug("Missing targets for SaltBootstrap: {}", targets); SaltAction saltAction = createBootstrap(params.isRestartNeeded()); GenericResponses responses = sc.action(saltAction); Set<Node> failedTargets = new HashSet<>(); LOGGER.debug("SaltBootstrap responses: {}", responses); for (GenericResponse genericResponse : responses.getResponses()) { if (genericResponse.getStatusCode() != HttpStatus.OK.value()) { LOGGER.info("Failed to distributed salt run to: {}, error: {}", genericResponse.getAddress(), genericResponse.getErrorText()); String address = genericResponse.getAddress().split(":")[0]; failedTargets.addAll(originalTargets.stream().filter(a -> a.getPrivateIp().equals(address)).collect(Collectors.toList())); } } targets = failedTargets; if (!targets.isEmpty()) { LOGGER.info("Missing nodes to run saltbootstrap: {}", targets); throw new CloudbreakOrchestratorFailedException("There are missing nodes from saltbootstrap: " + targets); } if (params.isRestartNeeded()) { params.setRestartNeeded(false); } createMinionAcceptor(saltAction).acceptMinions(); } MinionIpAddressesResponse minionIpAddressesResponse = SaltStates.collectMinionIpAddresses(sc); if (minionIpAddressesResponse != null) { originalTargets.forEach(node -> { if (!minionIpAddressesResponse.getAllIpAddresses().contains(node.getPrivateIp())) { LOGGER.info("Salt-minion is not responding on host: {}, yet", node); targets.add(node); } }); } else { throw new CloudbreakOrchestratorFailedException("Minions ip address collection returned null value"); } if (!targets.isEmpty()) { throw new CloudbreakOrchestratorFailedException("There are missing nodes from salt network response: " + targets); } LOGGER.debug("Bootstrapping of nodes completed: {}", originalTargets.size()); return true; } SaltBootstrap(SaltConnector sc, List<GatewayConfig> allGatewayConfigs, Set<Node> targets, BootstrapParams params); @Override Boolean call(); @Override String toString(); }
SaltBootstrap implements OrchestratorBootstrap { @Override public Boolean call() throws Exception { LOGGER.debug("Bootstrapping of nodes [{}/{}]", originalTargets.size() - targets.size(), originalTargets.size()); if (!targets.isEmpty()) { LOGGER.debug("Missing targets for SaltBootstrap: {}", targets); SaltAction saltAction = createBootstrap(params.isRestartNeeded()); GenericResponses responses = sc.action(saltAction); Set<Node> failedTargets = new HashSet<>(); LOGGER.debug("SaltBootstrap responses: {}", responses); for (GenericResponse genericResponse : responses.getResponses()) { if (genericResponse.getStatusCode() != HttpStatus.OK.value()) { LOGGER.info("Failed to distributed salt run to: {}, error: {}", genericResponse.getAddress(), genericResponse.getErrorText()); String address = genericResponse.getAddress().split(":")[0]; failedTargets.addAll(originalTargets.stream().filter(a -> a.getPrivateIp().equals(address)).collect(Collectors.toList())); } } targets = failedTargets; if (!targets.isEmpty()) { LOGGER.info("Missing nodes to run saltbootstrap: {}", targets); throw new CloudbreakOrchestratorFailedException("There are missing nodes from saltbootstrap: " + targets); } if (params.isRestartNeeded()) { params.setRestartNeeded(false); } createMinionAcceptor(saltAction).acceptMinions(); } MinionIpAddressesResponse minionIpAddressesResponse = SaltStates.collectMinionIpAddresses(sc); if (minionIpAddressesResponse != null) { originalTargets.forEach(node -> { if (!minionIpAddressesResponse.getAllIpAddresses().contains(node.getPrivateIp())) { LOGGER.info("Salt-minion is not responding on host: {}, yet", node); targets.add(node); } }); } else { throw new CloudbreakOrchestratorFailedException("Minions ip address collection returned null value"); } if (!targets.isEmpty()) { throw new CloudbreakOrchestratorFailedException("There are missing nodes from salt network response: " + targets); } LOGGER.debug("Bootstrapping of nodes completed: {}", originalTargets.size()); return true; } SaltBootstrap(SaltConnector sc, List<GatewayConfig> allGatewayConfigs, Set<Node> targets, BootstrapParams params); @Override Boolean call(); @Override String toString();  }