Search in sources :

Example 6 with SaltConnector

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

the class PillarSaveTest method testDiscovery.

@Test
public void testDiscovery() throws Exception {
    SaltConnector saltConnector = mock(SaltConnector.class);
    GenericResponses responses = new GenericResponses();
    GenericResponse response = new GenericResponse();
    response.setStatusCode(HttpStatus.OK.value());
    response.setAddress("10.0.0.2");
    responses.setResponses(Collections.singletonList(response));
    when(saltConnector.pillar(any(), any(Pillar.class))).thenReturn(responses);
    Set<Node> nodes = new HashSet<>();
    nodes.add(new Node("10.0.0.1", "1.1.1.1", "10-0-0-1.example.com", "hg"));
    nodes.add(new Node("10.0.0.2", "1.1.1.2", "10-0-0-2.example.com", "hg"));
    nodes.add(new Node("10.0.0.3", "1.1.1.3", "10-0-0-3.example.com", "hg"));
    PillarSave pillarSave = new PillarSave(saltConnector, Sets.newHashSet("10.0.0.1"), nodes);
    pillarSave.call();
    ArgumentCaptor<Pillar> pillarCaptor = ArgumentCaptor.forClass(Pillar.class);
    ArgumentCaptor<Set> targetCaptor = ArgumentCaptor.forClass(Set.class);
    verify(saltConnector).pillar(targetCaptor.capture(), pillarCaptor.capture());
    Pillar pillar = pillarCaptor.getValue();
    Map<String, Map<String, Map<String, Object>>> pillarJson = (Map<String, Map<String, Map<String, Object>>>) pillar.getJson();
    Map<String, Map<String, Object>> hostMap = pillarJson.entrySet().iterator().next().getValue();
    for (Node node : nodes) {
        Assert.assertEquals(node.getHostname(), hostMap.get(node.getPrivateIp()).get("fqdn"));
        Assert.assertEquals(node.getHostname().split("\\.")[0], hostMap.get(node.getPrivateIp()).get("hostname"));
        Assert.assertEquals(Boolean.TRUE, hostMap.get(node.getPrivateIp()).get("public_address"));
    }
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) GenericResponse(com.sequenceiq.cloudbreak.orchestrator.model.GenericResponse) Node(com.sequenceiq.cloudbreak.orchestrator.model.Node) GenericResponses(com.sequenceiq.cloudbreak.orchestrator.model.GenericResponses) SaltConnector(com.sequenceiq.cloudbreak.orchestrator.salt.client.SaltConnector) Pillar(com.sequenceiq.cloudbreak.orchestrator.salt.domain.Pillar) Map(java.util.Map) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 7 with SaltConnector

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

the class SaltJobIdTrackerTest method callWithInProgressAndJobIsRunning.

@Test
public void callWithInProgressAndJobIsRunning() throws Exception {
    String jobId = "1";
    SaltConnector saltConnector = Mockito.mock(SaltConnector.class);
    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.IN_PROGRESS);
    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);
    PowerMockito.mockStatic(SaltStates.class);
    PowerMockito.when(SaltStates.jobIsRunning(any(), any())).thenReturn(true);
    SaltJobIdTracker saltJobIdTracker = new SaltJobIdTracker(saltConnector, saltJobRunner);
    try {
        saltJobIdTracker.call();
    } catch (CloudbreakOrchestratorFailedException e) {
        assertThat(e.getMessage(), both(containsString("jobId='" + jobId + '\'')).and(containsString("is running")));
    }
    PowerMockito.verifyStatic();
    SaltStates.jobIsRunning(any(), eq(jobId));
    checkTargets(targets, targetCaptor.getAllValues());
}
Also used : CloudbreakOrchestratorFailedException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException) StringContains.containsString(org.hamcrest.core.StringContains.containsString) SaltConnector(com.sequenceiq.cloudbreak.orchestrator.salt.client.SaltConnector) HashSet(java.util.HashSet) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 8 with SaltConnector

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

the class SaltJobIdTrackerTest method callWithInProgressAndJobIsFinished.

@Test
public void callWithInProgressAndJobIsFinished() throws Exception {
    String jobId = "1";
    SaltConnector saltConnector = Mockito.mock(SaltConnector.class);
    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.IN_PROGRESS);
    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);
    PowerMockito.mockStatic(SaltStates.class);
    PowerMockito.when(SaltStates.jobIsRunning(any(), any())).thenReturn(false);
    Multimap<String, String> missingNodesWithReason = ArrayListMultimap.create();
    PowerMockito.when(SaltStates.jidInfo(any(), any(), any(), any())).thenReturn(missingNodesWithReason);
    SaltJobIdTracker saltJobIdTracker = new SaltJobIdTracker(saltConnector, saltJobRunner);
    assertTrue(saltJobIdTracker.call());
    assertEquals(JobState.FINISHED, saltJobRunner.getJobState());
    PowerMockito.verifyStatic();
    SaltStates.jobIsRunning(any(), eq(jobId));
    checkTargets(targets, targetCaptor.getAllValues());
}
Also used : StringContains.containsString(org.hamcrest.core.StringContains.containsString) SaltConnector(com.sequenceiq.cloudbreak.orchestrator.salt.client.SaltConnector) HashSet(java.util.HashSet) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 9 with SaltConnector

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

the class SaltJobIdTrackerTest method callWithNotStarted.

@SuppressFBWarnings("RV_RETURN_VALUE_IGNORED_NO_SIDE_EFFECT")
@Test
public void callWithNotStarted() throws Exception {
    String jobId = "1";
    SaltConnector saltConnector = Mockito.mock(SaltConnector.class);
    SaltJobRunner saltJobRunner = Mockito.mock(SaltJobRunner.class);
    PowerMockito.mockStatic(SaltStates.class);
    PowerMockito.when(SaltStates.jobIsRunning(any(), any())).thenReturn(true);
    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);
    when(saltJobRunner.getJid()).thenReturn(JobId.jobId(jobId));
    when(saltJobRunner.getJobState()).thenReturn(JobState.NOT_STARTED, JobState.IN_PROGRESS);
    when(saltJobRunner.submit(any(SaltConnector.class))).thenReturn(jobId);
    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));
    checkTargets(targets, targetCaptor.getAllValues());
    verify(saltJobRunner, times(2)).getJobState();
}
Also used : CloudbreakOrchestratorFailedException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException) StringContains.containsString(org.hamcrest.core.StringContains.containsString) SaltConnector(com.sequenceiq.cloudbreak.orchestrator.salt.client.SaltConnector) HashSet(java.util.HashSet) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 10 with SaltConnector

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

the class SaltJobIdTrackerTest method callWithInProgressAndMissingNodes.

@Test
public void callWithInProgressAndMissingNodes() throws Exception {
    String jobId = "1";
    SaltConnector saltConnector = Mockito.mock(SaltConnector.class);
    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.IN_PROGRESS);
    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);
    PowerMockito.mockStatic(SaltStates.class);
    PowerMockito.when(SaltStates.jobIsRunning(any(), any())).thenReturn(false);
    Multimap<String, String> missingNodesWithReason = ArrayListMultimap.create();
    String missingMachine = "10.0.0.1";
    String errorMessage = "error happened";
    missingNodesWithReason.put(missingMachine, errorMessage);
    when(saltJobRunner.getNodesWithError()).thenReturn(missingNodesWithReason);
    SaltJobIdTracker saltJobIdTracker = new SaltJobIdTracker(saltConnector, saltJobRunner);
    try {
        saltJobIdTracker.call();
        fail("should throw exception");
    } catch (CloudbreakOrchestratorFailedException e) {
        assertThat(e.getMessage(), both(containsString(missingMachine)).and(containsString(errorMessage)));
    }
    PowerMockito.verifyStatic();
    SaltStates.jobIsRunning(any(), eq(jobId));
    checkTargets(targets, targetCaptor.getAllValues());
}
Also used : CloudbreakOrchestratorFailedException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException) StringContains.containsString(org.hamcrest.core.StringContains.containsString) SaltConnector(com.sequenceiq.cloudbreak.orchestrator.salt.client.SaltConnector) HashSet(java.util.HashSet) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

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