Search in sources :

Example 1 with OrchestrationNode

use of com.sequenceiq.cloudbreak.common.orchestration.OrchestrationNode in project cloudbreak by hortonworks.

the class SaltOrchestratorTest method testStopClusterManagerAgent.

@Test
public void testStopClusterManagerAgent() throws Exception {
    Set<Node> downscaleTargets = new HashSet<>();
    downscaleTargets.add(new Node("10.0.0.2", "1.1.1.2", "10-0-0-2.example.com", "hg", "fqdn2", null));
    downscaleTargets.add(new Node("10.0.0.3", "1.1.1.3", "10-0-0-3.example.com", "hg", "fqdn3", null));
    PowerMockito.mockStatic(SaltStates.class);
    Set<String> responsiveAddresses = new HashSet<>();
    responsiveAddresses.add("10.0.0.1");
    responsiveAddresses.add("10.0.0.2");
    responsiveAddresses.add("10.0.0.3");
    PowerMockito.when(SaltStates.collectMinionIpAddresses(any(), any())).thenReturn(responsiveAddresses);
    Set<OrchestrationNode> allNodes = new HashSet<>();
    allNodes.add(() -> new Node("10.0.0.1", "1.1.1.1", "10-0-0-1.example.com", "hg", "fqdn3", null));
    allNodes.addAll(downscaleTargets.stream().map(node -> (OrchestrationNode) () -> node).collect(Collectors.toSet()));
    Callable pillarSaveCallable = mock(Callable.class);
    when(saltRunner.runner(any(), any(), any())).thenReturn(pillarSaveCallable);
    when(saltRunner.runner(any(), any(), any(), anyInt(), anyBoolean())).thenReturn(mock(Callable.class));
    saltOrchestrator.stopClusterManagerAgent(() -> allNodes, gatewayConfig, targets, downscaleTargets, exitCriteriaModel, new CmAgentStopFlags(false, false, false));
    ArgumentCaptor<ModifyGrainBase> modifyGrainBaseArgumentCaptor = ArgumentCaptor.forClass(ModifyGrainBase.class);
    ArgumentCaptor<PillarSave> pillarSaveArgumentCaptor = ArgumentCaptor.forClass(PillarSave.class);
    verify(pillarSaveCallable, times(1)).call();
    InOrder inOrder = inOrder(saltCommandRunner, saltRunner);
    inOrder.verify(saltCommandRunner).runModifyGrainCommand(any(), modifyGrainBaseArgumentCaptor.capture(), any(), any());
    ModifyGrainBase modifyGrainBase = modifyGrainBaseArgumentCaptor.getValue();
    assertThat(modifyGrainBase, instanceOf(GrainAddRunner.class));
    assertEquals("roles", modifyGrainBase.getKey());
    assertEquals("cloudera_manager_agent_stop", modifyGrainBase.getValue());
    inOrder.verify(saltRunner).runner(pillarSaveArgumentCaptor.capture(), any(), any());
    PillarSave capturedPillarSave = pillarSaveArgumentCaptor.getValue();
    ArgumentCaptor<SaltJobIdTracker> saltJobIdCaptor = ArgumentCaptor.forClass(SaltJobIdTracker.class);
    inOrder.verify(saltRunner).runner(saltJobIdCaptor.capture(), any(), any(), anyInt(), anyBoolean());
    inOrder.verify(saltCommandRunner).runModifyGrainCommand(any(), modifyGrainBaseArgumentCaptor.capture(), any(), any());
    inOrder.verifyNoMoreInteractions();
    modifyGrainBase = modifyGrainBaseArgumentCaptor.getValue();
    assertThat(modifyGrainBase, instanceOf(GrainRemoveRunner.class));
    assertEquals("roles", modifyGrainBase.getKey());
    assertEquals("cloudera_manager_agent_stop", modifyGrainBase.getValue());
    Set<String> targets = Whitebox.getInternalState(capturedPillarSave, "targets");
    assertTrue(targets.contains("10.0.0.1"));
    Pillar pillar = Whitebox.getInternalState(capturedPillarSave, "pillar");
    Map<String, Map> hosts = (Map) ((Map) pillar.getJson()).get("hosts");
    assertTrue(hosts.keySet().contains("10.0.0.1"));
    assertTrue(hosts.keySet().contains("10.0.0.2"));
    assertTrue(hosts.keySet().contains("10.0.0.3"));
}
Also used : InOrder(org.mockito.InOrder) JsonNode(com.fasterxml.jackson.databind.JsonNode) OrchestrationNode(com.sequenceiq.cloudbreak.common.orchestration.OrchestrationNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) Node(com.sequenceiq.cloudbreak.common.orchestration.Node) SaltJobIdTracker(com.sequenceiq.cloudbreak.orchestrator.salt.poller.SaltJobIdTracker) GrainAddRunner(com.sequenceiq.cloudbreak.orchestrator.salt.poller.checker.GrainAddRunner) OrchestrationNode(com.sequenceiq.cloudbreak.common.orchestration.OrchestrationNode) Callable(java.util.concurrent.Callable) ModifyGrainBase(com.sequenceiq.cloudbreak.orchestrator.salt.poller.checker.ModifyGrainBase) CmAgentStopFlags(com.sequenceiq.cloudbreak.orchestrator.model.CmAgentStopFlags) GrainRemoveRunner(com.sequenceiq.cloudbreak.orchestrator.salt.poller.checker.GrainRemoveRunner) Pillar(com.sequenceiq.cloudbreak.orchestrator.salt.domain.Pillar) Map(java.util.Map) HashMap(java.util.HashMap) HashSet(java.util.HashSet) PillarSave(com.sequenceiq.cloudbreak.orchestrator.salt.poller.PillarSave) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 Node (com.sequenceiq.cloudbreak.common.orchestration.Node)1 OrchestrationNode (com.sequenceiq.cloudbreak.common.orchestration.OrchestrationNode)1 CmAgentStopFlags (com.sequenceiq.cloudbreak.orchestrator.model.CmAgentStopFlags)1 Pillar (com.sequenceiq.cloudbreak.orchestrator.salt.domain.Pillar)1 PillarSave (com.sequenceiq.cloudbreak.orchestrator.salt.poller.PillarSave)1 SaltJobIdTracker (com.sequenceiq.cloudbreak.orchestrator.salt.poller.SaltJobIdTracker)1 GrainAddRunner (com.sequenceiq.cloudbreak.orchestrator.salt.poller.checker.GrainAddRunner)1 GrainRemoveRunner (com.sequenceiq.cloudbreak.orchestrator.salt.poller.checker.GrainRemoveRunner)1 ModifyGrainBase (com.sequenceiq.cloudbreak.orchestrator.salt.poller.checker.ModifyGrainBase)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Callable (java.util.concurrent.Callable)1 Test (org.junit.Test)1 InOrder (org.mockito.InOrder)1 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)1