Search in sources :

Example 11 with GenericResponse

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

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

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

Example 14 with GenericResponse

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

the class InstanceTerminationUnknownMock 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 15 with GenericResponse

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

the class MockSparkServer method addSaltMappings.

private static void addSaltMappings(Map<String, CloudVmMetaDataStatus> instanceMap) {
    ObjectMapper objectMapper = new ObjectMapper();
    get(SALT_BOOT_ROOT + "/health", (request, response) -> {
        GenericResponse genericResponse = new GenericResponse();
        genericResponse.setStatusCode(HttpStatus.OK.value());
        return genericResponse;
    }, GSON::toJson);
    objectMapper.setVisibility(objectMapper.getVisibilityChecker().withGetterVisibility(Visibility.NONE));
    post(SALT_API_ROOT + "/run", new SaltApiRunPostResponse(instanceMap));
    post(SALT_BOOT_ROOT + "/file", (request, response) -> {
        response.status(HttpStatus.CREATED.value());
        return response;
    });
    post(SALT_BOOT_ROOT + "/salt/server/pillar", (request, response) -> {
        GenericResponse genericResponse = new GenericResponse();
        genericResponse.setStatusCode(HttpStatus.OK.value());
        return genericResponse;
    }, GSON::toJson);
    post(SALT_BOOT_ROOT + "/salt/action/distribute", (request, response) -> {
        GenericResponses genericResponses = new GenericResponses();
        genericResponses.setResponses(new ArrayList<>());
        return genericResponses;
    }, GSON::toJson);
    post(SALT_BOOT_ROOT + "/hostname/distribute", (request, response) -> {
        GenericResponses genericResponses = new GenericResponses();
        List<GenericResponse> responses = new ArrayList<>();
        for (Entry<String, CloudVmMetaDataStatus> stringCloudVmMetaDataStatusEntry : instanceMap.entrySet()) {
            CloudVmMetaDataStatus cloudVmMetaDataStatus = stringCloudVmMetaDataStatusEntry.getValue();
            GenericResponse genericResponse = new GenericResponse();
            genericResponse.setAddress(cloudVmMetaDataStatus.getMetaData().getPrivateIp());
            genericResponse.setStatus(HostNameUtil.generateHostNameByIp(cloudVmMetaDataStatus.getMetaData().getPrivateIp()));
            genericResponse.setStatusCode(HttpStatus.OK.value());
            responses.add(genericResponse);
        }
        genericResponses.setResponses(responses);
        return genericResponses;
    }, GSON::toJson);
    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);
    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);
}
Also used : SaltApiRunPostResponse(com.sequenceiq.it.spark.salt.SaltApiRunPostResponse) GenericResponse(com.sequenceiq.cloudbreak.orchestrator.model.GenericResponse) CloudVmMetaDataStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmMetaDataStatus) ArrayList(java.util.ArrayList) GenericResponses(com.sequenceiq.cloudbreak.orchestrator.model.GenericResponses) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

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