use of com.sequenceiq.cloudbreak.orchestrator.salt.poller.checker.SyncAllRunner in project cloudbreak by hortonworks.
the class SaltOrchestrator method runSyncAll.
private void runSyncAll(SaltConnector sc, Set<String> targetHostnames, Set<Node> allNode, ExitCriteriaModel exitCriteriaModel) throws Exception {
SaltJobIdTracker syncAllTracker = new SaltJobIdTracker(sc, new SyncAllRunner(targetHostnames, allNode));
saltRunner.runner(syncAllTracker, exitCriteria, exitCriteriaModel, maxRetry, true).call();
}
use of com.sequenceiq.cloudbreak.orchestrator.salt.poller.checker.SyncAllRunner in project cloudbreak by hortonworks.
the class SaltOrchestrator method leaveDomain.
public void leaveDomain(GatewayConfig gatewayConfig, Set<Node> allNodes, String roleToRemove, String roleToAdd, ExitCriteriaModel exitCriteriaModel) throws CloudbreakOrchestratorFailedException {
try (SaltConnector sc = saltService.createSaltConnector(gatewayConfig)) {
if (isChangingRolesNecessary(gatewayConfig, sc, roleToRemove)) {
Set<String> targetHostnames = allNodes.stream().map(Node::getHostname).collect(Collectors.toSet());
saltCommandRunner.runSaltCommand(sc, new GrainAddRunner(targetHostnames, allNodes, "roles", roleToAdd), exitCriteriaModel, maxRetryLeave, exitCriteria);
saltCommandRunner.runSaltCommand(sc, new GrainRemoveRunner(targetHostnames, allNodes, "roles", roleToRemove), exitCriteriaModel, maxRetryLeave, exitCriteria);
Set<String> allHostnames = allNodes.stream().map(Node::getHostname).collect(Collectors.toSet());
SaltJobIdTracker syncAllTracker = new SaltJobIdTracker(sc, new SyncAllRunner(allHostnames, allNodes));
saltRunner.runner(syncAllTracker, exitCriteria, exitCriteriaModel, maxRetryLeave, false).call();
runNewService(sc, new HighStateAllRunner(allHostnames, allNodes), exitCriteriaModel, maxRetryLeave, true);
}
} catch (Exception e) {
LOGGER.info("Error occurred during executing highstate (for recipes).", e);
throw new CloudbreakOrchestratorFailedException(e.getMessage(), e);
}
}
use of com.sequenceiq.cloudbreak.orchestrator.salt.poller.checker.SyncAllRunner in project cloudbreak by hortonworks.
the class SaltOrchestratorTest method runServiceTest.
@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);
HighStateRunner highStateRunner = mock(HighStateRunner.class);
whenNew(HighStateRunner.class).withAnyArguments().thenReturn(highStateRunner);
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(() -> Set.of(), Collections.singletonList(gatewayConfig), targets, targets, saltConfig, exitCriteriaModel, "testPlatform");
saltOrchestrator.runService(Collections.singletonList(gatewayConfig), targets, saltConfig, exitCriteriaModel);
Set<String> allNodes = targets.stream().map(Node::getHostname).collect(Collectors.toSet());
// verify syncgrains command
verifyNew(SyncAllRunner.class, times(1)).withArguments(eq(allNodes), eq(targets));
// verify run new service
verifyNew(HighStateRunner.class, atLeastOnce()).withArguments(eq(allNodes), eq(targets));
verifyNew(SaltJobIdTracker.class, atLeastOnce()).withArguments(eq(saltConnector), eq(highStateRunner), eq(true));
verify(saltCommandRunner, times(1)).runSaltCommand(any(SaltConnector.class), any(BaseSaltJobRunner.class), any(ExitCriteriaModel.class), any(ExitCriteria.class));
verify(saltCommandRunner, times(2)).runModifyGrainCommand(any(SaltConnector.class), any(ModifyGrainBase.class), any(ExitCriteriaModel.class), any(ExitCriteria.class));
verify(grainUploader, times(1)).uploadGrains(anySet(), anyList(), any(ExitCriteriaModel.class), any(SaltConnector.class), any(ExitCriteria.class));
}
Aggregations