use of com.sequenceiq.cloudbreak.orchestrator.model.BootstrapParams in project cloudbreak by hortonworks.
the class SaltBootstrapTest method restartNeededFalseAndFlagSupportedBySaltBootstrap.
@Test
public void restartNeededFalseAndFlagSupportedBySaltBootstrap() 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"));
BootstrapParams params = new BootstrapParams();
params.setRestartNeeded(false);
params.setRestartNeededFlagSupported(true);
SaltBootstrap saltBootstrap = new SaltBootstrap(saltConnector, List.of(saltConnector), Collections.singletonList(gatewayConfig), targets, params);
saltBootstrap = spy(saltBootstrap);
doReturn(mock(MinionAcceptor.class)).when(saltBootstrap).createMinionAcceptor();
saltBootstrap.call();
ArgumentCaptor<SaltAction> captor = ArgumentCaptor.forClass(SaltAction.class);
verify(saltConnector, times(1)).action(captor.capture());
SaltAction saltAction = captor.getValue();
List<Minion> minions = saltAction.getMinions();
assertEquals(3, minions.size());
assertEquals(Collections.singletonList("172.16.252.43"), minions.get(0).getServers());
assertEquals(Collections.singletonList("172.16.252.43"), minions.get(1).getServers());
assertEquals(Collections.singletonList("172.16.252.43"), minions.get(2).getServers());
assertFalse(minions.get(0).isRestartNeeded());
assertFalse(minions.get(1).isRestartNeeded());
assertFalse(minions.get(2).isRestartNeeded());
}
use of com.sequenceiq.cloudbreak.orchestrator.model.BootstrapParams in project cloudbreak by hortonworks.
the class SaltBootstrapTest method restartNeededTrueButFlagNotSupportedBySaltBootstrap.
@Test
public void restartNeededTrueButFlagNotSupportedBySaltBootstrap() 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"));
BootstrapParams params = new BootstrapParams();
params.setRestartNeeded(true);
params.setRestartNeededFlagSupported(false);
SaltBootstrap saltBootstrap = new SaltBootstrap(saltConnector, List.of(saltConnector), Collections.singletonList(gatewayConfig), targets, params);
saltBootstrap = spy(saltBootstrap);
doReturn(mock(MinionAcceptor.class)).when(saltBootstrap).createMinionAcceptor();
saltBootstrap.call();
ArgumentCaptor<SaltAction> captor = ArgumentCaptor.forClass(SaltAction.class);
verify(saltConnector, times(1)).action(captor.capture());
SaltAction saltAction = captor.getValue();
List<Minion> minions = saltAction.getMinions();
assertEquals(3, minions.size());
assertEquals(Collections.singletonList("127.0.0.1"), minions.get(0).getServers());
assertEquals(Collections.singletonList("127.0.0.1"), minions.get(1).getServers());
assertEquals(Collections.singletonList("127.0.0.1"), minions.get(2).getServers());
assertTrue(minions.get(0).isRestartNeeded());
assertTrue(minions.get(1).isRestartNeeded());
assertTrue(minions.get(2).isRestartNeeded());
}
use of com.sequenceiq.cloudbreak.orchestrator.model.BootstrapParams in project cloudbreak by hortonworks.
the class SaltBootstrapTest method restartNeededTrueAndFlagSupportedBySaltBootstrap.
@Test
public void restartNeededTrueAndFlagSupportedBySaltBootstrap() 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"));
BootstrapParams params = new BootstrapParams();
params.setRestartNeeded(true);
params.setRestartNeededFlagSupported(true);
SaltBootstrap saltBootstrap = new SaltBootstrap(saltConnector, List.of(saltConnector), Collections.singletonList(gatewayConfig), targets, params);
saltBootstrap = spy(saltBootstrap);
doReturn(mock(MinionAcceptor.class)).when(saltBootstrap).createMinionAcceptor();
saltBootstrap.call();
ArgumentCaptor<SaltAction> captor = ArgumentCaptor.forClass(SaltAction.class);
verify(saltConnector, times(1)).action(captor.capture());
SaltAction saltAction = captor.getValue();
List<Minion> minions = saltAction.getMinions();
assertEquals(3, minions.size());
assertEquals(Collections.singletonList("172.16.252.43"), minions.get(0).getServers());
assertEquals(Collections.singletonList("172.16.252.43"), minions.get(1).getServers());
assertEquals(Collections.singletonList("172.16.252.43"), minions.get(2).getServers());
assertTrue(minions.get(0).isRestartNeeded());
assertTrue(minions.get(1).isRestartNeeded());
assertTrue(minions.get(2).isRestartNeeded());
}
use of com.sequenceiq.cloudbreak.orchestrator.model.BootstrapParams in project cloudbreak by hortonworks.
the class SaltOrchestrator method bootstrapNewNodes.
@Override
public void bootstrapNewNodes(List<GatewayConfig> allGatewayConfigs, Set<Node> targets, Set<Node> allNodes, byte[] stateConfigZip, BootstrapParams params, ExitCriteriaModel exitModel) throws CloudbreakOrchestratorException {
LOGGER.info("Bootstrap new nodes: {}", targets);
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());
List<SaltConnector> saltConnectors = saltService.createSaltConnector(allGatewayConfigs);
try (SaltConnector sc = saltService.createSaltConnector(primaryGateway)) {
if (!gatewayTargets.isEmpty()) {
LOGGER.info("Gateway targets are not empty, upload salt config: {}", gatewayTargets);
uploadSaltConfig(sc, gatewayTargets, stateConfigZip, exitModel);
params.setRestartNeeded(true);
}
uploadSignKey(sc, primaryGateway, gatewayTargets, targets.stream().map(Node::getPrivateIp).collect(Collectors.toSet()), exitModel);
// if there is a new salt master then re-bootstrap all nodes
Set<Node> nodes = gatewayTargets.isEmpty() ? targets : allNodes;
OrchestratorBootstrap saltBootstrap = new SaltBootstrap(sc, saltConnectors, 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.getMessage(), e);
} finally {
saltConnectors.forEach(SaltConnector::close);
}
}
use of com.sequenceiq.cloudbreak.orchestrator.model.BootstrapParams in project cloudbreak by hortonworks.
the class SaltOrchestratorTest method bootstrapNewNodesTest.
@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);
when(compressUtil.generateCompressedOutputFromFolders("salt-common", "salt")).thenReturn(new byte[] {});
saltOrchestrator.bootstrapNewNodes(Collections.singletonList(gatewayConfig), targets, targets, null, bootstrapParams, exitCriteriaModel);
verify(saltRunner, times(4)).runner(any(OrchestratorBootstrap.class), any(ExitCriteria.class), any(ExitCriteriaModel.class));
verifyNew(SaltBootstrap.class, times(1)).withArguments(eq(saltConnector), eq(saltConnectors), eq(Collections.singletonList(gatewayConfig)), eq(targets), eq(bootstrapParams));
}
Aggregations