Search in sources :

Example 1 with MinionStatus

use of com.sequenceiq.cloudbreak.orchestrator.salt.domain.MinionStatus in project cloudbreak by hortonworks.

the class SaltOrchestratorTest method testRemoveDeadSaltMinions.

@Test
public void testRemoveDeadSaltMinions() throws Exception {
    PowerMockito.mockStatic(SaltStates.class);
    MinionStatusSaltResponse minionStatusSaltResponse = new MinionStatusSaltResponse();
    List<MinionStatus> minionStatusList = new ArrayList<>();
    MinionStatus minionStatus = new MinionStatus();
    List<String> upNodes = Lists.newArrayList("10-0-0-1.example.com", "10-0-0-2.example.com", "10-0-0-3.example.com");
    minionStatus.setUp(upNodes);
    List<String> downNodes = Lists.newArrayList("10-0-0-4.example.com", "10-0-0-5.example.com");
    minionStatus.setDown(downNodes);
    minionStatusList.add(minionStatus);
    minionStatusSaltResponse.setResult(minionStatusList);
    when(SaltStates.collectNodeStatus(eq(saltConnector))).thenReturn(minionStatusSaltResponse);
    saltOrchestrator.removeDeadSaltMinions(gatewayConfig);
    verify(saltConnector, times(1)).wheel("key.delete", downNodes, Object.class);
}
Also used : MinionStatus(com.sequenceiq.cloudbreak.orchestrator.salt.domain.MinionStatus) ArrayList(java.util.ArrayList) MinionStatusSaltResponse(com.sequenceiq.cloudbreak.orchestrator.salt.domain.MinionStatusSaltResponse) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 2 with MinionStatus

use of com.sequenceiq.cloudbreak.orchestrator.salt.domain.MinionStatus in project cloudbreak by hortonworks.

the class SaltOrchestratorTest method testDontRemoveDeadSaltMinions.

@Test
public void testDontRemoveDeadSaltMinions() throws Exception {
    PowerMockito.mockStatic(SaltStates.class);
    MinionStatusSaltResponse minionStatusSaltResponse = new MinionStatusSaltResponse();
    List<MinionStatus> minionStatusList = new ArrayList<>();
    MinionStatus minionStatus = new MinionStatus();
    List<String> upNodes = Lists.newArrayList("10-0-0-1.example.com", "10-0-0-2.example.com", "10-0-0-3.example.com");
    minionStatus.setUp(upNodes);
    List<String> downNodes = new ArrayList<>();
    minionStatus.setDown(downNodes);
    minionStatusList.add(minionStatus);
    minionStatusSaltResponse.setResult(minionStatusList);
    when(SaltStates.collectNodeStatus(eq(saltConnector))).thenReturn(minionStatusSaltResponse);
    saltOrchestrator.removeDeadSaltMinions(gatewayConfig);
    verify(saltConnector, never()).wheel("key.delete", downNodes, Object.class);
}
Also used : MinionStatus(com.sequenceiq.cloudbreak.orchestrator.salt.domain.MinionStatus) ArrayList(java.util.ArrayList) MinionStatusSaltResponse(com.sequenceiq.cloudbreak.orchestrator.salt.domain.MinionStatusSaltResponse) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 3 with MinionStatus

use of com.sequenceiq.cloudbreak.orchestrator.salt.domain.MinionStatus in project cloudbreak by hortonworks.

the class SaltOrchestratorTest method tearDownReusedIpAddressTest.

@Test
public void tearDownReusedIpAddressTest() throws Exception {
    Map<String, String> privateIpsByFQDN = new HashMap<>();
    privateIpsByFQDN.put("10-0-0-1.example.com", "10.0.0.1");
    privateIpsByFQDN.put("10-0-0-2.example.com", "10.0.0.2");
    privateIpsByFQDN.put("10-0-0-3.example.com", "10.0.0.3");
    Set<String> privateIps = privateIpsByFQDN.values().stream().collect(Collectors.toSet());
    mockStatic(SaltStates.class);
    SaltStates.stopMinions(eq(saltConnector), eq(privateIps));
    MinionStatusSaltResponse minionStatusSaltResponse = new MinionStatusSaltResponse();
    List<MinionStatus> minionStatusList = new ArrayList<>();
    MinionStatus minionStatus = new MinionStatus();
    List<String> upNodes = Lists.newArrayList("10-0-0-1.example.com", "10-0-0-2.example.com", "10-0-0-3.example.com");
    minionStatus.setUp(upNodes);
    List<String> downNodes = Lists.newArrayList("10-0-0-4.example.com", "10-0-0-5.example.com");
    minionStatus.setDown(downNodes);
    minionStatusList.add(minionStatus);
    minionStatusSaltResponse.setResult(minionStatusList);
    when(SaltStates.collectNodeStatus(eq(saltConnector))).thenReturn(minionStatusSaltResponse);
    Callable<Boolean> callable = mock(Callable.class);
    when(saltRunner.runner(any(OrchestratorBootstrap.class), any(ExitCriteria.class), any(ExitCriteriaModel.class))).thenReturn(callable);
    Node remainingNode = mock(Node.class);
    when(remainingNode.getPrivateIp()).thenReturn("10.0.0.1");
    when(remainingNode.getHostname()).thenReturn("hostname");
    ExitCriteriaModel exitCriteriaModel = mock(ExitCriteriaModel.class);
    saltOrchestrator.tearDown(() -> Set.of(), Collections.singletonList(gatewayConfig), privateIpsByFQDN, Set.of(remainingNode), exitCriteriaModel);
    verify(saltConnector, times(1)).wheel(eq("key.delete"), eq(downNodes), eq(Object.class));
    verifyStatic(SaltStates.class);
    SaltStates.stopMinions(eq(saltConnector), eq(Set.of("10.0.0.2", "10.0.0.3")));
}
Also used : ExitCriteriaModel(com.sequenceiq.cloudbreak.orchestrator.state.ExitCriteriaModel) HashMap(java.util.HashMap) OrchestratorBootstrap(com.sequenceiq.cloudbreak.orchestrator.OrchestratorBootstrap) 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) ArrayList(java.util.ArrayList) MinionStatus(com.sequenceiq.cloudbreak.orchestrator.salt.domain.MinionStatus) ExitCriteria(com.sequenceiq.cloudbreak.orchestrator.state.ExitCriteria) MinionStatusSaltResponse(com.sequenceiq.cloudbreak.orchestrator.salt.domain.MinionStatusSaltResponse) ArgumentMatchers.anyBoolean(org.mockito.ArgumentMatchers.anyBoolean) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 4 with MinionStatus

use of com.sequenceiq.cloudbreak.orchestrator.salt.domain.MinionStatus in project cloudbreak by hortonworks.

the class SaltOrchestratorTest method tearDownTest.

@Test
public void tearDownTest() throws Exception {
    Map<String, String> privateIpsByFQDN = new HashMap<>();
    privateIpsByFQDN.put("10-0-0-1.example.com", "10.0.0.1");
    privateIpsByFQDN.put("10-0-0-2.example.com", "10.0.0.2");
    privateIpsByFQDN.put("10-0-0-3.example.com", "10.0.0.3");
    Set<String> privateIps = privateIpsByFQDN.values().stream().collect(Collectors.toSet());
    mockStatic(SaltStates.class);
    SaltStates.stopMinions(eq(saltConnector), eq(privateIps));
    MinionStatusSaltResponse minionStatusSaltResponse = new MinionStatusSaltResponse();
    List<MinionStatus> minionStatusList = new ArrayList<>();
    MinionStatus minionStatus = new MinionStatus();
    List<String> upNodes = Lists.newArrayList("10-0-0-1.example.com", "10-0-0-2.example.com", "10-0-0-3.example.com");
    minionStatus.setUp(upNodes);
    List<String> downNodes = Lists.newArrayList("10-0-0-4.example.com", "10-0-0-5.example.com");
    minionStatus.setDown(downNodes);
    minionStatusList.add(minionStatus);
    minionStatusSaltResponse.setResult(minionStatusList);
    when(SaltStates.collectNodeStatus(eq(saltConnector))).thenReturn(minionStatusSaltResponse);
    saltOrchestrator.tearDown(null, Collections.singletonList(gatewayConfig), privateIpsByFQDN, Set.of(), null);
    verify(saltConnector, never()).wheel(eq("key.delete"), eq(downNodes), eq(Object.class));
    verifyStatic(SaltStates.class);
    SaltStates.stopMinions(eq(saltConnector), eq(privateIps));
}
Also used : HashMap(java.util.HashMap) MinionStatus(com.sequenceiq.cloudbreak.orchestrator.salt.domain.MinionStatus) ArrayList(java.util.ArrayList) MinionStatusSaltResponse(com.sequenceiq.cloudbreak.orchestrator.salt.domain.MinionStatusSaltResponse) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 5 with MinionStatus

use of com.sequenceiq.cloudbreak.orchestrator.salt.domain.MinionStatus in project cloudbreak by hortonworks.

the class ManageStatusSaltResponse method run.

@Override
public Object run(String mockUuid, Map<String, List<String>> params) throws Exception {
    MinionStatusSaltResponse minionStatusSaltResponse = new MinionStatusSaltResponse();
    List<MinionStatus> minionStatusList = new ArrayList<>();
    MinionStatus minionStatus = new MinionStatus();
    ArrayList<String> upList = new ArrayList<>();
    minionStatus.setUp(upList);
    ArrayList<String> downList = new ArrayList<>();
    minionStatus.setDown(downList);
    minionStatusList.add(minionStatus);
    minionStatusSaltResponse.setResult(minionStatusList);
    for (CloudVmMetaDataStatus cloudVmMetaDataStatus : spiStoreService.getMetadata(mockUuid)) {
        if (InstanceStatus.STARTED == cloudVmMetaDataStatus.getCloudVmInstanceStatus().getStatus()) {
            String privateIp = cloudVmMetaDataStatus.getMetaData().getPrivateIp();
            upList.add(hostNameService.getHostName(mockUuid, privateIp));
        }
    }
    return minionStatusSaltResponse;
}
Also used : CloudVmMetaDataStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmMetaDataStatus) MinionStatus(com.sequenceiq.cloudbreak.orchestrator.salt.domain.MinionStatus) ArrayList(java.util.ArrayList) MinionStatusSaltResponse(com.sequenceiq.cloudbreak.orchestrator.salt.domain.MinionStatusSaltResponse)

Aggregations

MinionStatus (com.sequenceiq.cloudbreak.orchestrator.salt.domain.MinionStatus)5 MinionStatusSaltResponse (com.sequenceiq.cloudbreak.orchestrator.salt.domain.MinionStatusSaltResponse)5 ArrayList (java.util.ArrayList)5 Test (org.junit.Test)4 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)4 HashMap (java.util.HashMap)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 CloudVmMetaDataStatus (com.sequenceiq.cloudbreak.cloud.model.CloudVmMetaDataStatus)1 Node (com.sequenceiq.cloudbreak.common.orchestration.Node)1 OrchestrationNode (com.sequenceiq.cloudbreak.common.orchestration.OrchestrationNode)1 OrchestratorBootstrap (com.sequenceiq.cloudbreak.orchestrator.OrchestratorBootstrap)1 ExitCriteria (com.sequenceiq.cloudbreak.orchestrator.state.ExitCriteria)1 ExitCriteriaModel (com.sequenceiq.cloudbreak.orchestrator.state.ExitCriteriaModel)1 ArgumentMatchers.anyBoolean (org.mockito.ArgumentMatchers.anyBoolean)1