Search in sources :

Example 11 with GenericResponses

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

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

Example 13 with GenericResponses

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

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

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