Search in sources :

Example 6 with GenericResponses

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

the class SaltBootstrap method call.

@Override
public Boolean call() throws Exception {
    LOGGER.info("Bootstrapping of nodes [{}/{}]", originalTargets.size() - targets.size(), originalTargets.size());
    if (!targets.isEmpty()) {
        LOGGER.info("Missing targets for SaltBootstrap: {}", targets);
        SaltAction saltAction = createBootstrap();
        GenericResponses responses = sc.action(saltAction);
        Set<Node> failedTargets = new HashSet<>();
        LOGGER.info("SaltBootstrap responses: {}", responses);
        for (GenericResponse genericResponse : responses.getResponses()) {
            if (genericResponse.getStatusCode() != HttpStatus.OK.value()) {
                LOGGER.info("Failed to distributed salt run to: " + genericResponse.getAddress());
                String address = genericResponse.getAddress().split(":")[0];
                failedTargets.addAll(originalTargets.stream().filter(a -> a.getPrivateIp().equals(address)).collect(Collectors.toList()));
            }
        }
        targets = failedTargets;
        if (!targets.isEmpty()) {
            LOGGER.info("Missing nodes to run saltbootstrap: {}", targets);
            throw new CloudbreakOrchestratorFailedException("There are missing nodes from saltbootstrap: " + targets);
        }
    }
    String iFace = SaltStates.defaultRoute(sc, Glob.ALL).getGatewayInterfaceName();
    Map<String, String> networkResult = SaltStates.networkInterfaceIP(sc, Glob.ALL, iFace).getResultGroupByIP();
    originalTargets.forEach(node -> {
        if (!networkResult.containsKey(node.getPrivateIp())) {
            LOGGER.info("Salt-minion is not responding on host: {}, yet", node);
            targets.add(node);
        }
    });
    if (!targets.isEmpty()) {
        throw new CloudbreakOrchestratorFailedException("There are missing nodes from salt network response: " + targets);
    }
    LOGGER.info("Bootstrapping of nodes completed: {}", originalTargets.size());
    return true;
}
Also used : CloudbreakOrchestratorFailedException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException) GenericResponse(com.sequenceiq.cloudbreak.orchestrator.model.GenericResponse) Node(com.sequenceiq.cloudbreak.orchestrator.model.Node) GenericResponses(com.sequenceiq.cloudbreak.orchestrator.model.GenericResponses) SaltAction(com.sequenceiq.cloudbreak.orchestrator.salt.domain.SaltAction) HashSet(java.util.HashSet)

Example 7 with GenericResponses

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

the class SaltUpload method call.

@Override
public Boolean call() throws Exception {
    LOGGER.info("Uploading files to: {}", targets);
    if (!targets.isEmpty()) {
        LOGGER.info("Current targets for upload: {}", targets);
        GenericResponses responses = sc.upload(targets, path, fileName, content);
        Set<String> failedTargets = new HashSet<>();
        LOGGER.info("Salt file upload responses: {}", responses);
        for (GenericResponse genericResponse : responses.getResponses()) {
            if (genericResponse.getStatusCode() != HttpStatus.CREATED.value()) {
                LOGGER.info("Failed upload 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 file upload: {}", targets);
            throw new CloudbreakOrchestratorFailedException("There are missing nodes for file upload: " + targets);
        }
    }
    LOGGER.info("File upload 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)

Example 8 with GenericResponses

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

the class InstanceTerminationMock 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 9 with GenericResponses

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

the class InstanceTerminationReplicationErrorMock 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 10 with GenericResponses

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

the class InstanceTerminationReplicationMock 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)

Aggregations

GenericResponse (com.sequenceiq.cloudbreak.orchestrator.model.GenericResponse)15 GenericResponses (com.sequenceiq.cloudbreak.orchestrator.model.GenericResponses)15 ArrayList (java.util.ArrayList)8 SaltApiRunPostResponse (com.sequenceiq.it.spark.salt.SaltApiRunPostResponse)7 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 CloudbreakOrchestratorFailedException (com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException)4 HashSet (java.util.HashSet)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 SaltAction (com.sequenceiq.cloudbreak.orchestrator.salt.domain.SaltAction)3 Map (java.util.Map)3 Response (javax.ws.rs.core.Response)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 SaltConnector (com.sequenceiq.cloudbreak.orchestrator.salt.client.SaltConnector)2