Search in sources :

Example 16 with GenericResponse

use of com.sequenceiq.cloudbreak.orchestrator.model.GenericResponse in project cloudbreak by hortonworks.

the class ScalingMock method addMockEndpoints.

public void addMockEndpoints() {
    Service sparkService = getSparkService();
    sparkService.get(SALT_BOOT_ROOT + "/health", (request, response) -> {
        GenericResponse genericResponse = new GenericResponse();
        genericResponse.setStatusCode(HttpStatus.OK.value());
        return genericResponse;
    }, gson()::toJson);
    sparkService.post(SALT_BOOT_ROOT + "/salt/server/pillar", (request, response) -> {
        GenericResponse genericResponse = new GenericResponse();
        genericResponse.setStatusCode(HttpStatus.OK.value());
        return genericResponse;
    }, gson()::toJson);
    sparkService.post(SALT_BOOT_ROOT + "/salt/action/distribute", (request, response) -> {
        GenericResponses genericResponses = new GenericResponses();
        genericResponses.setResponses(new ArrayList<>());
        return genericResponses;
    }, gson()::toJson);
    sparkService.post(SALT_BOOT_ROOT + "/hostname/distribute", (request, response) -> {
        GenericResponses genericResponses = new GenericResponses();
        List<GenericResponse> responses = new ArrayList<>();
        JsonObject parsedRequest = new JsonParser().parse(request.body()).getAsJsonObject();
        JsonArray nodeArray = parsedRequest.getAsJsonArray("clients");
        for (int i = 0; i < nodeArray.size(); i++) {
            String address = nodeArray.get(i).getAsString();
            GenericResponse genericResponse = new GenericResponse();
            genericResponse.setAddress(address);
            genericResponse.setStatus(HostNameUtil.generateHostNameByIp(address));
            genericResponse.setStatusCode(200);
            responses.add(genericResponse);
        }
        genericResponses.setResponses(responses);
        return genericResponses;
    }, gson()::toJson);
    sparkService.post(SALT_API_ROOT + "/run", new SaltApiRunPostResponse(getInstanceMap()));
    sparkService.post(SALT_BOOT_ROOT + "/file/distribute", (request, response) -> {
        GenericResponses genericResponses = new GenericResponses();
        GenericResponse genericResponse = new GenericResponse();
        genericResponse.setStatusCode(HttpStatus.CREATED.value());
        genericResponses.setResponses(Collections.singletonList(genericResponse));
        return genericResponses;
    }, gson()::toJson);
    sparkService.post(SALT_BOOT_ROOT + "/salt/server/pillar/distribute", (request, response) -> {
        GenericResponses genericResponses = new GenericResponses();
        GenericResponse genericResponse = new GenericResponse();
        genericResponse.setStatusCode(HttpStatus.OK.value());
        genericResponses.setResponses(Collections.singletonList(genericResponse));
        return genericResponses;
    }, gson()::toJson);
    sparkService.get("/ws/v1/cluster/apps", (request, response) -> {
        ObjectNode rootNode = JsonNodeFactory.instance.objectNode();
        ArrayNode appNode = rootNode.putObject("apps").putArray("app");
        appNode.addObject().put("amHostHttpAddress", "192.168.1.1");
        return rootNode;
    });
}
Also used : SaltApiRunPostResponse(com.sequenceiq.it.spark.salt.SaltApiRunPostResponse) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) GenericResponse(com.sequenceiq.cloudbreak.orchestrator.model.GenericResponse) ArrayList(java.util.ArrayList) Service(spark.Service) JsonObject(com.google.gson.JsonObject) GenericResponses(com.sequenceiq.cloudbreak.orchestrator.model.GenericResponses) JsonArray(com.google.gson.JsonArray) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) JsonParser(com.google.gson.JsonParser)

Example 17 with GenericResponse

use of com.sequenceiq.cloudbreak.orchestrator.model.GenericResponse 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)

Example 18 with GenericResponse

use of com.sequenceiq.cloudbreak.orchestrator.model.GenericResponse in project cloudbreak by hortonworks.

the class SaltConnector method failedResponseErrorLog.

private void failedResponseErrorLog(Iterable<GenericResponse> failedResponses) {
    StringBuilder failedResponsesErrorMessage = new StringBuilder();
    failedResponsesErrorMessage.append("Failed response from salt bootstrap, endpoint: ").append(BOOT_HOSTNAME_ENDPOINT);
    for (GenericResponse failedResponse : failedResponses) {
        failedResponsesErrorMessage.append('\n').append("Status code: ").append(failedResponse.getStatusCode());
        failedResponsesErrorMessage.append(" Error message: ").append(failedResponse.getStatus());
    }
    LOGGER.error(failedResponsesErrorMessage.toString());
}
Also used : GenericResponse(com.sequenceiq.cloudbreak.orchestrator.model.GenericResponse)

Example 19 with GenericResponse

use of com.sequenceiq.cloudbreak.orchestrator.model.GenericResponse in project cloudbreak by hortonworks.

the class PillarSave method call.

@Override
public Boolean call() throws Exception {
    LOGGER.info("Distribute pillar configs to: {}", targets);
    if (!targets.isEmpty()) {
        GenericResponses responses = sc.pillar(targets, pillar);
        Set<String> failedTargets = new HashSet<>();
        LOGGER.info("Salt pillar save responses: {}", responses);
        for (GenericResponse genericResponse : responses.getResponses()) {
            if (genericResponse.getStatusCode() != HttpStatus.OK.value()) {
                LOGGER.info("Failed pillar save attempt to: " + genericResponse.getAddress());
                String address = genericResponse.getAddress().split(":")[0];
                failedTargets.addAll(originalTargets.stream().filter(a -> a.equals(address)).collect(Collectors.toList()));
            }
        }
        targets = failedTargets;
        if (!targets.isEmpty()) {
            LOGGER.info("Missing nodes for pillar save: {}", targets);
            throw new CloudbreakOrchestratorFailedException("There are missing nodes for pillar save: " + targets);
        }
    }
    LOGGER.info("Pillar save has been completed on nodes: {}", originalTargets);
    return true;
}
Also used : CloudbreakOrchestratorFailedException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException) GenericResponse(com.sequenceiq.cloudbreak.orchestrator.model.GenericResponse) GenericResponses(com.sequenceiq.cloudbreak.orchestrator.model.GenericResponses) HashSet(java.util.HashSet)

Aggregations

GenericResponse (com.sequenceiq.cloudbreak.orchestrator.model.GenericResponse)19 GenericResponses (com.sequenceiq.cloudbreak.orchestrator.model.GenericResponses)14 SaltApiRunPostResponse (com.sequenceiq.it.spark.salt.SaltApiRunPostResponse)8 ArrayList (java.util.ArrayList)8 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)5 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)5 JsonArray (com.google.gson.JsonArray)5 JsonObject (com.google.gson.JsonObject)5 JsonParser (com.google.gson.JsonParser)5 Service (spark.Service)5 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)4 CloudbreakOrchestratorFailedException (com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException)4 HashSet (java.util.HashSet)4 SaltAction (com.sequenceiq.cloudbreak.orchestrator.salt.domain.SaltAction)3 Map (java.util.Map)3 Response (javax.ws.rs.core.Response)3 Test (org.junit.Test)3 CloudVmMetaDataStatus (com.sequenceiq.cloudbreak.cloud.model.CloudVmMetaDataStatus)2 GatewayConfig (com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig)2 Node (com.sequenceiq.cloudbreak.orchestrator.model.Node)2