Search in sources :

Example 16 with SaltConnector

use of com.sequenceiq.cloudbreak.orchestrator.salt.client.SaltConnector in project cloudbreak by hortonworks.

the class SaltCommandTrackerTest method callHasTargetNodesTest.

@Test
public void callHasTargetNodesTest() throws Exception {
    SaltConnector saltConnector = Mockito.mock(SaltConnector.class);
    SaltJobRunner saltJobRunner = Mockito.mock(SaltJobRunner.class);
    Set<String> targets = new HashSet<>();
    targets.add("10.0.0.1");
    targets.add("10.0.0.2");
    targets.add("10.0.0.3");
    when(saltJobRunner.getTarget()).thenReturn(targets);
    SaltCommandTracker saltCommandTracker = new SaltCommandTracker(saltConnector, saltJobRunner);
    try {
        saltCommandTracker.call();
        fail("shoud throw exception");
    } catch (CloudbreakOrchestratorFailedException e) {
        for (String target : targets) {
            assertTrue(e.getMessage().contains(target));
        }
    }
}
Also used : CloudbreakOrchestratorFailedException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException) SaltConnector(com.sequenceiq.cloudbreak.orchestrator.salt.client.SaltConnector) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 17 with SaltConnector

use of com.sequenceiq.cloudbreak.orchestrator.salt.client.SaltConnector in project cloudbreak by hortonworks.

the class SaltCommandTrackerTest method callTest.

@Test
public void callTest() throws Exception {
    SaltConnector saltConnector = Mockito.mock(SaltConnector.class);
    SaltJobRunner saltJobRunner = Mockito.mock(SaltJobRunner.class);
    Set<String> targets = new HashSet<>();
    when(saltJobRunner.getTarget()).thenReturn(targets);
    SaltCommandTracker saltCommandTracker = new SaltCommandTracker(saltConnector, saltJobRunner);
    saltCommandTracker.call();
}
Also used : SaltConnector(com.sequenceiq.cloudbreak.orchestrator.salt.client.SaltConnector) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 18 with SaltConnector

use of com.sequenceiq.cloudbreak.orchestrator.salt.client.SaltConnector in project cloudbreak by hortonworks.

the class SaltJobIdTrackerTest method callWithFailed.

@Test
public void callWithFailed() throws Exception {
    String jobId = "1";
    SaltConnector saltConnector = Mockito.mock(SaltConnector.class);
    PowerMockito.mockStatic(SaltStates.class);
    PowerMockito.when(SaltStates.jobIsRunning(any(), any())).thenReturn(true);
    SaltJobRunner saltJobRunner = Mockito.mock(BaseSaltJobRunner.class);
    when(saltJobRunner.getJid()).thenReturn(JobId.jobId(jobId));
    when(saltJobRunner.getJobState()).thenCallRealMethod();
    doCallRealMethod().when(saltJobRunner).setJobState(any());
    when(saltJobRunner.submit(any(SaltConnector.class))).thenReturn(jobId);
    saltJobRunner.setJobState(JobState.FAILED);
    SaltJobIdTracker saltJobIdTracker = new SaltJobIdTracker(saltConnector, saltJobRunner);
    try {
        saltJobIdTracker.call();
        fail("should throw exception");
    } catch (CloudbreakOrchestratorFailedException e) {
        assertThat(e.getMessage(), both(containsString("jobId='" + jobId + '\'')).and(containsString("is running")));
    }
    PowerMockito.verifyStatic();
    SaltStates.jobIsRunning(any(), eq(jobId));
}
Also used : CloudbreakOrchestratorFailedException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException) StringContains.containsString(org.hamcrest.core.StringContains.containsString) SaltConnector(com.sequenceiq.cloudbreak.orchestrator.salt.client.SaltConnector) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 19 with SaltConnector

use of com.sequenceiq.cloudbreak.orchestrator.salt.client.SaltConnector in project cloudbreak by hortonworks.

the class SaltOrchestratorTest method setUp.

@Before
public void setUp() throws Exception {
    gatewayConfig = new GatewayConfig("1.1.1.1", "10.0.0.1", "172.16.252.43", "10-0-0-1", 9443, "servercert", "clientcert", "clientkey", "saltpasswd", "saltbootpassword", "signkey", false, true, null, null);
    targets = new HashSet<>();
    targets.add(new Node("10.0.0.1", "1.1.1.1", "10-0-0-1.example.com", "hg"));
    targets.add(new Node("10.0.0.2", "1.1.1.2", "10-0-0-2.example.com", "hg"));
    targets.add(new Node("10.0.0.3", "1.1.1.3", "10-0-0-3.example.com", "hg"));
    saltConnector = mock(SaltConnector.class);
    whenNew(SaltConnector.class).withAnyArguments().thenReturn(saltConnector);
    parallelOrchestratorComponentRunner = mock(ParallelOrchestratorComponentRunner.class);
    when(parallelOrchestratorComponentRunner.submit(any())).thenReturn(CompletableFuture.completedFuture(true));
    when(hostDiscoveryService.determineDomain("test", "test", false)).thenReturn(".example.com");
    exitCriteria = mock(ExitCriteria.class);
    exitCriteriaModel = mock(ExitCriteriaModel.class);
}
Also used : ExitCriteriaModel(com.sequenceiq.cloudbreak.orchestrator.state.ExitCriteriaModel) ParallelOrchestratorComponentRunner(com.sequenceiq.cloudbreak.orchestrator.executor.ParallelOrchestratorComponentRunner) ExitCriteria(com.sequenceiq.cloudbreak.orchestrator.state.ExitCriteria) Node(com.sequenceiq.cloudbreak.orchestrator.model.Node) SaltConnector(com.sequenceiq.cloudbreak.orchestrator.salt.client.SaltConnector) GatewayConfig(com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig) Before(org.junit.Before)

Example 20 with SaltConnector

use of com.sequenceiq.cloudbreak.orchestrator.salt.client.SaltConnector in project cloudbreak by hortonworks.

the class SaltOrchestrator method resetAmbari.

@Override
public void resetAmbari(GatewayConfig gatewayConfig, Set<String> target, Set<Node> allNodes, ExitCriteriaModel exitCriteriaModel) throws CloudbreakOrchestratorException {
    try (SaltConnector saltConnector = new SaltConnector(gatewayConfig, restDebug)) {
        BaseSaltJobRunner baseSaltJobRunner = new BaseSaltJobRunner(target, allNodes) {

            @Override
            public String submit(SaltConnector saltConnector) {
                return SaltStates.ambariReset(saltConnector, new Compound(getTarget(), CompoundType.HOST));
            }
        };
        OrchestratorBootstrap saltJobIdTracker = new SaltJobIdTracker(saltConnector, baseSaltJobRunner);
        Callable<Boolean> saltJobRunBootstrapRunner = runner(saltJobIdTracker, exitCriteria, exitCriteriaModel);
        Future<Boolean> saltJobRunBootstrapFuture = parallelOrchestratorComponentRunner.submit(saltJobRunBootstrapRunner);
        saltJobRunBootstrapFuture.get();
    } catch (Exception e) {
        LOGGER.error("Error occurred during reset", e);
        throw new CloudbreakOrchestratorFailedException(e);
    }
}
Also used : CloudbreakOrchestratorFailedException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException) OrchestratorBootstrap(com.sequenceiq.cloudbreak.orchestrator.OrchestratorBootstrap) SaltJobIdTracker(com.sequenceiq.cloudbreak.orchestrator.salt.poller.SaltJobIdTracker) BaseSaltJobRunner(com.sequenceiq.cloudbreak.orchestrator.salt.poller.BaseSaltJobRunner) Compound(com.sequenceiq.cloudbreak.orchestrator.salt.client.target.Compound) SaltConnector(com.sequenceiq.cloudbreak.orchestrator.salt.client.SaltConnector) CloudbreakOrchestratorException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorException) CloudbreakOrchestratorFailedException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException)

Aggregations

SaltConnector (com.sequenceiq.cloudbreak.orchestrator.salt.client.SaltConnector)24 CloudbreakOrchestratorFailedException (com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException)14 Node (com.sequenceiq.cloudbreak.orchestrator.model.Node)12 Test (org.junit.Test)12 HashSet (java.util.HashSet)10 CloudbreakOrchestratorException (com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorException)9 IOException (java.io.IOException)9 ExecutionException (java.util.concurrent.ExecutionException)9 GatewayConfig (com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig)8 Map (java.util.Map)8 OrchestratorBootstrap (com.sequenceiq.cloudbreak.orchestrator.OrchestratorBootstrap)7 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)7 ArrayList (java.util.ArrayList)7 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)7 GrainAddRunner (com.sequenceiq.cloudbreak.orchestrator.salt.poller.checker.GrainAddRunner)6 GrainRemoveRunner (com.sequenceiq.cloudbreak.orchestrator.salt.poller.checker.GrainRemoveRunner)6 HighStateRunner (com.sequenceiq.cloudbreak.orchestrator.salt.poller.checker.HighStateRunner)6 Compound (com.sequenceiq.cloudbreak.orchestrator.salt.client.target.Compound)5 PillarSave (com.sequenceiq.cloudbreak.orchestrator.salt.poller.PillarSave)5 SyncGrainsRunner (com.sequenceiq.cloudbreak.orchestrator.salt.poller.checker.SyncGrainsRunner)5