Search in sources :

Example 1 with SyncAllRunner

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();
}
Also used : SaltJobIdTracker(com.sequenceiq.cloudbreak.orchestrator.salt.poller.SaltJobIdTracker) SyncAllRunner(com.sequenceiq.cloudbreak.orchestrator.salt.poller.checker.SyncAllRunner)

Example 2 with SyncAllRunner

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);
    }
}
Also used : GrainRemoveRunner(com.sequenceiq.cloudbreak.orchestrator.salt.poller.checker.GrainRemoveRunner) CloudbreakOrchestratorFailedException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException) SaltJobIdTracker(com.sequenceiq.cloudbreak.orchestrator.salt.poller.SaltJobIdTracker) GrainAddRunner(com.sequenceiq.cloudbreak.orchestrator.salt.poller.checker.GrainAddRunner) HighStateAllRunner(com.sequenceiq.cloudbreak.orchestrator.salt.poller.checker.HighStateAllRunner) SyncAllRunner(com.sequenceiq.cloudbreak.orchestrator.salt.poller.checker.SyncAllRunner) SaltConnector(com.sequenceiq.cloudbreak.orchestrator.salt.client.SaltConnector) NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException) CloudbreakOrchestratorTimeoutException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorTimeoutException) CloudbreakOrchestratorException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorException) CloudbreakOrchestratorFailedException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException)

Example 3 with SyncAllRunner

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));
}
Also used : ExitCriteriaModel(com.sequenceiq.cloudbreak.orchestrator.state.ExitCriteriaModel) HighStateRunner(com.sequenceiq.cloudbreak.orchestrator.salt.poller.checker.HighStateRunner) SaltJobIdTracker(com.sequenceiq.cloudbreak.orchestrator.salt.poller.SaltJobIdTracker) GrainAddRunner(com.sequenceiq.cloudbreak.orchestrator.salt.poller.checker.GrainAddRunner) BaseSaltJobRunner(com.sequenceiq.cloudbreak.orchestrator.salt.poller.BaseSaltJobRunner) SaltCommandTracker(com.sequenceiq.cloudbreak.orchestrator.salt.poller.SaltCommandTracker) SaltConfig(com.sequenceiq.cloudbreak.orchestrator.model.SaltConfig) SaltConnector(com.sequenceiq.cloudbreak.orchestrator.salt.client.SaltConnector) ModifyGrainBase(com.sequenceiq.cloudbreak.orchestrator.salt.poller.checker.ModifyGrainBase) ExitCriteria(com.sequenceiq.cloudbreak.orchestrator.state.ExitCriteria) MineUpdateRunner(com.sequenceiq.cloudbreak.orchestrator.salt.poller.checker.MineUpdateRunner) SyncAllRunner(com.sequenceiq.cloudbreak.orchestrator.salt.poller.checker.SyncAllRunner) SaltBootstrap(com.sequenceiq.cloudbreak.orchestrator.salt.poller.SaltBootstrap) OrchestratorBootstrapRunner(com.sequenceiq.cloudbreak.orchestrator.OrchestratorBootstrapRunner) PillarSave(com.sequenceiq.cloudbreak.orchestrator.salt.poller.PillarSave) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

SaltJobIdTracker (com.sequenceiq.cloudbreak.orchestrator.salt.poller.SaltJobIdTracker)3 SyncAllRunner (com.sequenceiq.cloudbreak.orchestrator.salt.poller.checker.SyncAllRunner)3 SaltConnector (com.sequenceiq.cloudbreak.orchestrator.salt.client.SaltConnector)2 GrainAddRunner (com.sequenceiq.cloudbreak.orchestrator.salt.poller.checker.GrainAddRunner)2 CloudbreakServiceException (com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException)1 NotFoundException (com.sequenceiq.cloudbreak.common.exception.NotFoundException)1 OrchestratorBootstrapRunner (com.sequenceiq.cloudbreak.orchestrator.OrchestratorBootstrapRunner)1 CloudbreakOrchestratorException (com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorException)1 CloudbreakOrchestratorFailedException (com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException)1 CloudbreakOrchestratorTimeoutException (com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorTimeoutException)1 SaltConfig (com.sequenceiq.cloudbreak.orchestrator.model.SaltConfig)1 BaseSaltJobRunner (com.sequenceiq.cloudbreak.orchestrator.salt.poller.BaseSaltJobRunner)1 PillarSave (com.sequenceiq.cloudbreak.orchestrator.salt.poller.PillarSave)1 SaltBootstrap (com.sequenceiq.cloudbreak.orchestrator.salt.poller.SaltBootstrap)1 SaltCommandTracker (com.sequenceiq.cloudbreak.orchestrator.salt.poller.SaltCommandTracker)1 GrainRemoveRunner (com.sequenceiq.cloudbreak.orchestrator.salt.poller.checker.GrainRemoveRunner)1 HighStateAllRunner (com.sequenceiq.cloudbreak.orchestrator.salt.poller.checker.HighStateAllRunner)1 HighStateRunner (com.sequenceiq.cloudbreak.orchestrator.salt.poller.checker.HighStateRunner)1 MineUpdateRunner (com.sequenceiq.cloudbreak.orchestrator.salt.poller.checker.MineUpdateRunner)1 ModifyGrainBase (com.sequenceiq.cloudbreak.orchestrator.salt.poller.checker.ModifyGrainBase)1