Search in sources :

Example 11 with SaltConnector

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

the class GrainAddRunnerTest method submitTest.

@Test
public void submitTest() {
    Set<String> targets = new HashSet<>();
    targets.add("10.0.0.1");
    targets.add("10.0.0.2");
    targets.add("10.0.0.3");
    Set<Node> allNode = new HashSet<>();
    allNode.add(new Node("10.0.0.1", "5.5.5.1", "10-0-0-1.example.com", "hg"));
    allNode.add(new Node("10.0.0.2", "5.5.5.2", "10-0-0-2.example.com", "hg"));
    allNode.add(new Node("10.0.0.3", "5.5.5.3", "10-0-0-3.example.com", "hg"));
    PowerMockito.mockStatic(SaltStates.class);
    ApplyResponse applyResponse = new ApplyResponse();
    List<Map<String, Object>> result = new ArrayList<>();
    Map<String, Object> nodes = new HashMap<>();
    nodes.put("10-0-0-1.example.com", "something");
    nodes.put("10-0-0-2.example.com", "something");
    result.add(nodes);
    applyResponse.setResult(result);
    PowerMockito.when(SaltStates.addGrain(any(), any(), anyString(), any())).thenReturn(applyResponse);
    GrainAddRunner addRoleChecker = new GrainAddRunner(targets, allNode, "ambari_server");
    SaltConnector saltConnector = Mockito.mock(SaltConnector.class);
    String missingIps = addRoleChecker.submit(saltConnector);
    assertThat(addRoleChecker.getTarget(), hasItems("10.0.0.3"));
    assertEquals("[10.0.0.3]", missingIps);
}
Also used : HashMap(java.util.HashMap) Node(com.sequenceiq.cloudbreak.orchestrator.model.Node) ArrayList(java.util.ArrayList) Matchers.anyString(org.mockito.Matchers.anyString) SaltConnector(com.sequenceiq.cloudbreak.orchestrator.salt.client.SaltConnector) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet) ApplyResponse(com.sequenceiq.cloudbreak.orchestrator.salt.domain.ApplyResponse) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 12 with SaltConnector

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

the class HighStateRunnerTest method submit.

@Test
public void submit() {
    targets = new HashSet<>();
    targets.add("10.0.0.1");
    targets.add("10.0.0.2");
    targets.add("10.0.0.3");
    allNode = new HashSet<>();
    allNode.add(new Node("10.0.0.1", "5.5.5.1", "10-0-0-1.example.com", "hg"));
    allNode.add(new Node("10.0.0.2", "5.5.5.2", "10-0-0-2.example.com", "hg"));
    allNode.add(new Node("10.0.0.3", "5.5.5.3", "10-0-0-3.example.com", "hg"));
    HighStateRunner highStateRunner = new HighStateRunner(targets, allNode);
    SaltConnector saltConnector = Mockito.mock(SaltConnector.class);
    PowerMockito.mockStatic(SaltStates.class);
    String jobId = "1";
    PowerMockito.when(SaltStates.highstate(any())).thenReturn(jobId);
    String jid = highStateRunner.submit(saltConnector);
    assertEquals(jobId, jid);
    PowerMockito.verifyStatic();
    SaltStates.highstate(eq(saltConnector));
}
Also used : Node(com.sequenceiq.cloudbreak.orchestrator.model.Node) SaltConnector(com.sequenceiq.cloudbreak.orchestrator.salt.client.SaltConnector) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 13 with SaltConnector

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

the class SyncGrainsRunnerTest method submit.

@Test
public void submit() {
    Set<String> targets = new HashSet<>();
    targets.add("10.0.0.1");
    targets.add("10.0.0.2");
    targets.add("10.0.0.3");
    Set<Node> allNode = new HashSet<>();
    allNode.add(new Node("10.0.0.1", "5.5.5.1", "10-0-0-1.example.com", "hg"));
    allNode.add(new Node("10.0.0.2", "5.5.5.2", "10-0-0-2.example.com", "hg"));
    allNode.add(new Node("10.0.0.3", "5.5.5.3", "10-0-0-3.example.com", "hg"));
    PowerMockito.mockStatic(SaltStates.class);
    ApplyResponse applyResponse = new ApplyResponse();
    List<Map<String, Object>> result = new ArrayList<>();
    Map<String, Object> nodes = new HashMap<>();
    nodes.put("10-0-0-1.example.com", "something");
    nodes.put("10-0-0-2.example.com", "something");
    result.add(nodes);
    applyResponse.setResult(result);
    PowerMockito.when(SaltStates.syncGrains(any())).thenReturn(applyResponse);
    SyncGrainsRunner syncGrainsRunner = new SyncGrainsRunner(targets, allNode);
    SaltConnector saltConnector = Mockito.mock(SaltConnector.class);
    String missingIps = syncGrainsRunner.submit(saltConnector);
    assertThat(syncGrainsRunner.getTarget(), hasItems("10.0.0.3"));
    assertEquals("[10.0.0.3]", missingIps);
}
Also used : HashMap(java.util.HashMap) Node(com.sequenceiq.cloudbreak.orchestrator.model.Node) ArrayList(java.util.ArrayList) SaltConnector(com.sequenceiq.cloudbreak.orchestrator.salt.client.SaltConnector) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet) ApplyResponse(com.sequenceiq.cloudbreak.orchestrator.salt.domain.ApplyResponse) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 14 with SaltConnector

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

the class SaltStatesTest method setUp.

@Before
public void setUp() {
    Set<String> targets = new HashSet<>();
    targets.add("10-0-0-1.example.com");
    targets.add("10-0-0-2.example.com");
    targets.add("10-0-0-3.example.com");
    target = new Compound(targets);
    saltConnector = mock(SaltConnector.class);
}
Also used : Compound(com.sequenceiq.cloudbreak.orchestrator.salt.client.target.Compound) SaltConnector(com.sequenceiq.cloudbreak.orchestrator.salt.client.SaltConnector) HashSet(java.util.HashSet) Before(org.junit.Before)

Example 15 with SaltConnector

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

the class SaltBootstrapTest method setUp.

@Before
public void setUp() {
    saltConnector = mock(SaltConnector.class);
    gatewayConfig = new GatewayConfig("1.1.1.1", "10.0.0.1", "172.16.252.43", "10-0-0-1.example.com", 9443, "serverCert", "clientCert", "clientKey", "saltpasswd", "saltbootpassword", "signkey", false, true, null, null);
    GenericResponse response = new GenericResponse();
    response.setStatusCode(HttpStatus.OK.value());
    GenericResponses genericResponses = new GenericResponses();
    genericResponses.setResponses(Collections.singletonList(response));
    when(saltConnector.action(Mockito.any(SaltAction.class))).thenReturn(genericResponses);
    when(saltConnector.run(Mockito.any(), Mockito.eq("network.default_route"), Mockito.any(), Mockito.any())).thenReturn(new DefaultRouteResponse(Collections.emptyList()));
    NetworkInterfaceResponse networkInterfaceResponse = new NetworkInterfaceResponse();
    List<Map<String, String>> networkResultList = new ArrayList<>();
    networkMap = new HashMap<>();
    networkMap.put("host-10-0-0-1.example.com", "10.0.0.1");
    networkMap.put("host-10-0-0-2.example.com", "10.0.0.2");
    networkMap.put("host-10-0-0-3.example.com", "10.0.0.3");
    networkResultList.add(networkMap);
    networkInterfaceResponse.setResult(networkResultList);
    when(saltConnector.run(Mockito.any(), Mockito.eq("network.interface_ip"), Mockito.any(), Mockito.any(), Mockito.any())).thenReturn(networkInterfaceResponse);
}
Also used : NetworkInterfaceResponse(com.sequenceiq.cloudbreak.orchestrator.salt.domain.NetworkInterfaceResponse) DefaultRouteResponse(com.sequenceiq.cloudbreak.orchestrator.salt.domain.DefaultRouteResponse) GenericResponse(com.sequenceiq.cloudbreak.orchestrator.model.GenericResponse) ArrayList(java.util.ArrayList) GenericResponses(com.sequenceiq.cloudbreak.orchestrator.model.GenericResponses) HashMap(java.util.HashMap) Map(java.util.Map) SaltConnector(com.sequenceiq.cloudbreak.orchestrator.salt.client.SaltConnector) GatewayConfig(com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig) SaltAction(com.sequenceiq.cloudbreak.orchestrator.salt.domain.SaltAction) Before(org.junit.Before)

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