Search in sources :

Example 1 with GenericResponse

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

the class StackCreationMock method addSaltMappings.

public void addSaltMappings() {
    Map<String, CloudVmMetaDataStatus> instanceMap = getInstanceMap();
    ObjectMapper objectMapper = new ObjectMapper();
    Service sparkService = getSparkService();
    sparkService.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));
    sparkService.post(SALT_API_ROOT + "/run", new SaltApiRunPostResponse(instanceMap));
    sparkService.post(SALT_BOOT_ROOT + "/file", (request, response) -> {
        response.status(HttpStatus.CREATED.value());
        return response;
    });
    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<>();
        for (CloudVmMetaDataStatus status : instanceMap.values()) {
            GenericResponse genericResponse = new GenericResponse();
            genericResponse.setAddress(status.getMetaData().getPrivateIp());
            genericResponse.setStatus(HostNameUtil.generateHostNameByIp(status.getMetaData().getPrivateIp()));
            genericResponse.setStatusCode(HttpStatus.OK.value());
            responses.add(genericResponse);
        }
        genericResponses.setResponses(responses);
        return genericResponses;
    }, gson()::toJson);
    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);
}
Also used : SaltApiRunPostResponse(com.sequenceiq.it.spark.salt.SaltApiRunPostResponse) CloudVmMetaDataStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmMetaDataStatus) GenericResponse(com.sequenceiq.cloudbreak.orchestrator.model.GenericResponse) ArrayList(java.util.ArrayList) Service(spark.Service) GenericResponses(com.sequenceiq.cloudbreak.orchestrator.model.GenericResponses) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 2 with GenericResponse

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

the class SaltConnector method health.

public GenericResponse health() {
    Response response = saltTarget.path(SaltEndpoint.BOOT_HEALTH.getContextPath()).request().get();
    GenericResponse responseEntity = JaxRSUtil.response(response, GenericResponse.class);
    LOGGER.info("SaltBoot. Health response: {}", responseEntity);
    return responseEntity;
}
Also used : GenericResponse(com.sequenceiq.cloudbreak.orchestrator.model.GenericResponse) Response(javax.ws.rs.core.Response) GenericResponse(com.sequenceiq.cloudbreak.orchestrator.model.GenericResponse)

Example 3 with GenericResponse

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

the class SaltConnector method members.

public Map<String, String> members(List<String> privateIps) throws CloudbreakOrchestratorFailedException {
    Map<String, List<String>> clients = singletonMap("clients", privateIps);
    Response response = saltTarget.path(BOOT_HOSTNAME_ENDPOINT.getContextPath()).request().header(SIGN_HEADER, PkiUtil.generateSignature(signatureKey, toJson(clients).getBytes())).post(Entity.json(clients));
    GenericResponses responses = JaxRSUtil.response(response, GenericResponses.class);
    List<GenericResponse> failedResponses = responses.getResponses().stream().filter(genericResponse -> !ACCEPTED_STATUSES.contains(genericResponse.getStatusCode())).collect(Collectors.toList());
    if (!failedResponses.isEmpty()) {
        failedResponseErrorLog(failedResponses);
        String failedNodeAddresses = failedResponses.stream().map(GenericResponse::getAddress).collect(Collectors.joining(","));
        throw new CloudbreakOrchestratorFailedException("Hostname resolution failed for nodes: " + failedNodeAddresses);
    }
    return responses.getResponses().stream().collect(Collectors.toMap(GenericResponse::getAddress, GenericResponse::getStatus));
}
Also used : GenericResponse(com.sequenceiq.cloudbreak.orchestrator.model.GenericResponse) Response(javax.ws.rs.core.Response) MultiPart(org.glassfish.jersey.media.multipart.MultiPart) Arrays(java.util.Arrays) Form(javax.ws.rs.core.Form) Target(com.sequenceiq.cloudbreak.orchestrator.salt.client.target.Target) Pillar(com.sequenceiq.cloudbreak.orchestrator.salt.domain.Pillar) Client(javax.ws.rs.client.Client) LoggerFactory(org.slf4j.LoggerFactory) HttpStatus(org.apache.http.HttpStatus) FormDataMultiPart(org.glassfish.jersey.media.multipart.FormDataMultiPart) GenericResponses(com.sequenceiq.cloudbreak.orchestrator.model.GenericResponses) MediaType(javax.ws.rs.core.MediaType) JaxRSUtil(com.sequenceiq.cloudbreak.util.JaxRSUtil) ByteArrayInputStream(java.io.ByteArrayInputStream) Map(java.util.Map) Collections.singletonMap(java.util.Collections.singletonMap) SaltAction(com.sequenceiq.cloudbreak.orchestrator.salt.domain.SaltAction) GenericResponse(com.sequenceiq.cloudbreak.orchestrator.model.GenericResponse) Logger(org.slf4j.Logger) BOOT_HOSTNAME_ENDPOINT(com.sequenceiq.cloudbreak.orchestrator.salt.client.SaltEndpoint.BOOT_HOSTNAME_ENDPOINT) Collection(java.util.Collection) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) IOException(java.io.IOException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) Collectors(java.util.stream.Collectors) Entity(javax.ws.rs.client.Entity) Boundary(org.glassfish.jersey.media.multipart.Boundary) List(java.util.List) Response(javax.ws.rs.core.Response) CloudbreakOrchestratorFailedException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException) Closeable(java.io.Closeable) StreamDataBodyPart(org.glassfish.jersey.media.multipart.file.StreamDataBodyPart) RestClientUtil(com.sequenceiq.cloudbreak.client.RestClientUtil) GatewayConfig(com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig) Optional(java.util.Optional) WebTarget(javax.ws.rs.client.WebTarget) HttpAuthenticationFeature(org.glassfish.jersey.client.authentication.HttpAuthenticationFeature) PkiUtil(com.sequenceiq.cloudbreak.client.PkiUtil) Collections(java.util.Collections) CloudbreakOrchestratorFailedException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException) GenericResponse(com.sequenceiq.cloudbreak.orchestrator.model.GenericResponse) List(java.util.List) GenericResponses(com.sequenceiq.cloudbreak.orchestrator.model.GenericResponses)

Example 4 with GenericResponse

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

the class SaltConnector method pillar.

public GenericResponses pillar(Iterable<String> targets, Pillar pillar) {
    Response distributeResponse = saltTarget.path(SaltEndpoint.BOOT_PILLAR_DISTRIBUTE.getContextPath()).request().header(SIGN_HEADER, PkiUtil.generateSignature(signatureKey, toJson(pillar).getBytes())).post(Entity.json(pillar));
    if (distributeResponse.getStatus() == HttpStatus.SC_NOT_FOUND) {
        // simple pillar save for CB <= 1.14
        distributeResponse.close();
        Response singleResponse = saltTarget.path(SaltEndpoint.BOOT_PILLAR_SAVE.getContextPath()).request().header(SIGN_HEADER, PkiUtil.generateSignature(signatureKey, toJson(pillar).getBytes())).post(Entity.json(pillar));
        GenericResponses genericResponses = new GenericResponses();
        GenericResponse genericResponse = new GenericResponse();
        genericResponse.setAddress(targets.iterator().next());
        genericResponse.setStatusCode(singleResponse.getStatus());
        genericResponses.setResponses(Collections.singletonList(genericResponse));
        singleResponse.close();
        return genericResponses;
    }
    return JaxRSUtil.response(distributeResponse, GenericResponses.class);
}
Also used : GenericResponse(com.sequenceiq.cloudbreak.orchestrator.model.GenericResponse) Response(javax.ws.rs.core.Response) GenericResponse(com.sequenceiq.cloudbreak.orchestrator.model.GenericResponse) GenericResponses(com.sequenceiq.cloudbreak.orchestrator.model.GenericResponses)

Example 5 with GenericResponse

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

the class PillarSaveTest method testDiscovery.

@Test
public void testDiscovery() throws Exception {
    SaltConnector saltConnector = mock(SaltConnector.class);
    GenericResponses responses = new GenericResponses();
    GenericResponse response = new GenericResponse();
    response.setStatusCode(HttpStatus.OK.value());
    response.setAddress("10.0.0.2");
    responses.setResponses(Collections.singletonList(response));
    when(saltConnector.pillar(any(), any(Pillar.class))).thenReturn(responses);
    Set<Node> nodes = new HashSet<>();
    nodes.add(new Node("10.0.0.1", "1.1.1.1", "10-0-0-1.example.com", "hg"));
    nodes.add(new Node("10.0.0.2", "1.1.1.2", "10-0-0-2.example.com", "hg"));
    nodes.add(new Node("10.0.0.3", "1.1.1.3", "10-0-0-3.example.com", "hg"));
    PillarSave pillarSave = new PillarSave(saltConnector, Sets.newHashSet("10.0.0.1"), nodes);
    pillarSave.call();
    ArgumentCaptor<Pillar> pillarCaptor = ArgumentCaptor.forClass(Pillar.class);
    ArgumentCaptor<Set> targetCaptor = ArgumentCaptor.forClass(Set.class);
    verify(saltConnector).pillar(targetCaptor.capture(), pillarCaptor.capture());
    Pillar pillar = pillarCaptor.getValue();
    Map<String, Map<String, Map<String, Object>>> pillarJson = (Map<String, Map<String, Map<String, Object>>>) pillar.getJson();
    Map<String, Map<String, Object>> hostMap = pillarJson.entrySet().iterator().next().getValue();
    for (Node node : nodes) {
        Assert.assertEquals(node.getHostname(), hostMap.get(node.getPrivateIp()).get("fqdn"));
        Assert.assertEquals(node.getHostname().split("\\.")[0], hostMap.get(node.getPrivateIp()).get("hostname"));
        Assert.assertEquals(Boolean.TRUE, hostMap.get(node.getPrivateIp()).get("public_address"));
    }
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) GenericResponse(com.sequenceiq.cloudbreak.orchestrator.model.GenericResponse) Node(com.sequenceiq.cloudbreak.orchestrator.model.Node) GenericResponses(com.sequenceiq.cloudbreak.orchestrator.model.GenericResponses) SaltConnector(com.sequenceiq.cloudbreak.orchestrator.salt.client.SaltConnector) Pillar(com.sequenceiq.cloudbreak.orchestrator.salt.domain.Pillar) Map(java.util.Map) HashSet(java.util.HashSet) Test(org.junit.Test)

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