Search in sources :

Example 1 with ApplyResponse

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

the class SaltApiRunPostResponse method grainsResponse.

protected Object grainsResponse() throws JsonProcessingException {
    ApplyResponse applyResponse = new ApplyResponse();
    List<Map<String, Object>> responseList = new ArrayList<>();
    Map<String, Object> hostMap = new HashMap<>();
    for (Entry<String, CloudVmMetaDataStatus> stringCloudVmMetaDataStatusEntry : instanceMap.entrySet()) {
        CloudVmMetaDataStatus cloudVmMetaDataStatus = stringCloudVmMetaDataStatusEntry.getValue();
        if (InstanceStatus.STARTED == cloudVmMetaDataStatus.getCloudVmInstanceStatus().getStatus()) {
            String privateIp = cloudVmMetaDataStatus.getMetaData().getPrivateIp();
            hostMap.put("host-" + privateIp.replace(".", "-"), privateIp);
        }
    }
    responseList.add(hostMap);
    applyResponse.setResult(responseList);
    return objectMapper.writeValueAsString(applyResponse);
}
Also used : HashMap(java.util.HashMap) CloudVmMetaDataStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmMetaDataStatus) ArrayList(java.util.ArrayList) HashMap(java.util.HashMap) Map(java.util.Map) ApplyResponse(com.sequenceiq.cloudbreak.orchestrator.salt.domain.ApplyResponse)

Example 2 with ApplyResponse

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

the class BaseSaltJobRunnerTest method collectNodesTest.

@Test
public void collectNodesTest() {
    Set<Node> allNode = allNodeWithPostFix();
    baseSaltJobRunner = new BaseSaltJobRunner(targets, allNode) {

        @Override
        public String submit(SaltConnector saltConnector) {
            return "";
        }
    };
    ApplyResponse applyResponse = new ApplyResponse();
    List<Map<String, Object>> resultList = new ArrayList<>();
    Map<String, Object> resultMap = new HashMap<>();
    resultMap.put("host-10-0-0-1.example.com", "10.0.0.1");
    resultMap.put("host-10-0-0-2.example.com", "10.0.0.2");
    resultMap.put("host-10-0-0-3.example.com", "10.0.0.3");
    resultList.add(resultMap);
    applyResponse.setResult(resultList);
    Set<String> collectedNodes = baseSaltJobRunner.collectNodes(applyResponse);
    Assert.assertEquals(3, collectedNodes.size());
    Assert.assertTrue(collectedNodes.contains("host-10-0-0-1.example.com"));
    Assert.assertTrue(collectedNodes.contains("host-10-0-0-2.example.com"));
    Assert.assertTrue(collectedNodes.contains("host-10-0-0-3.example.com"));
}
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) Map(java.util.Map) HashMap(java.util.HashMap) ApplyResponse(com.sequenceiq.cloudbreak.orchestrator.salt.domain.ApplyResponse) Test(org.junit.Test)

Example 3 with ApplyResponse

use of com.sequenceiq.cloudbreak.orchestrator.salt.domain.ApplyResponse 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 4 with ApplyResponse

use of com.sequenceiq.cloudbreak.orchestrator.salt.domain.ApplyResponse 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 5 with ApplyResponse

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

the class MineUpdateRunner method submit.

@Override
public String submit(SaltConnector saltConnector) {
    ApplyResponse grainsResult = SaltStates.updateMine(saltConnector);
    Set<String> strings = collectMissingNodes(collectNodes(grainsResult));
    setTarget(strings);
    return strings.toString();
}
Also used : ApplyResponse(com.sequenceiq.cloudbreak.orchestrator.salt.domain.ApplyResponse)

Aggregations

ApplyResponse (com.sequenceiq.cloudbreak.orchestrator.salt.domain.ApplyResponse)9 ArrayList (java.util.ArrayList)6 HashMap (java.util.HashMap)6 Map (java.util.Map)6 Test (org.junit.Test)4 Node (com.sequenceiq.cloudbreak.orchestrator.model.Node)3 SaltConnector (com.sequenceiq.cloudbreak.orchestrator.salt.client.SaltConnector)3 CloudVmMetaDataStatus (com.sequenceiq.cloudbreak.cloud.model.CloudVmMetaDataStatus)2 HashSet (java.util.HashSet)2 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2 Compound (com.sequenceiq.cloudbreak.orchestrator.salt.client.target.Compound)1 Matchers.anyString (org.mockito.Matchers.anyString)1