Package org.graylog2.restclient.models

Examples of org.graylog2.restclient.models.ClusterEntity


        String to = Tools.stringSearchParamOrEmpty(request, "to");
        String keyword = Tools.stringSearchParamOrEmpty(request, "keyword");
        String fields = Tools.stringSearchParamOrEmpty(request, "fields");

        String query = search.getQuery();
        TimeRange timeRange = search.getTimeRange();

        if (stream == null) {
            return routes.SearchController.exportAsCsv(
                    query,
                    "",
                    timeRange.getType().toString().toLowerCase(),
                    relative,
                    from,
                    to,
                    keyword,
                    fields
            );
        } else {
            return routes.StreamSearchController.exportAsCsv(
                    query,
                    stream.getId(),
                    timeRange.getType().toString().toLowerCase(),
                    relative,
                    from,
                    to,
                    keyword,
                    fields
View Full Code Here


        final Form<LaunchInputRequest> form = launchInputRequestForm.bindFromRequest();
        final LaunchInputRequest request = form.get();

        try {
            ClusterEntity node = null;
            InputTypeSummaryResponse inputInfo = null;

            String nodeId = null;
            if (nodeIdParam != null && !nodeIdParam.isEmpty()) {
                nodeId = nodeIdParam;
            } else {
                if (request.node != null && !request.node.isEmpty()) {
                    nodeId = request.node;
                }
            }

            if (nodeId != null) {
                try {
                    node = nodeService.loadNode(nodeId);
                } catch (NodeService.NodeNotFoundException e) {
                    node = nodeService.loadRadio(nodeId);
                }
            }

            if (request.global)
                node = nodeService.loadMasterNode();

            if (node == null)
                return status(404, views.html.errors.error.render(ApiClient.ERROR_MSG_NODE_NOT_FOUND, new RuntimeException("Could not find Node to launch input on!"), request()));

            inputInfo = node.getInputTypeInformation(request.type);

            final Map<String, Object> configuration;

            try {
                configuration = extractConfiguration(request.configuration, inputInfo);
            } catch (IllegalArgumentException e) {
                return status(400, views.html.errors.error.render("Invalid input configuration", new RuntimeException("Invalid configuration for input " + request.title, e), request()));
            }

            try {
                Boolean result;
                if (request.global) {
                    result = (inputService.launchGlobal(request.title, request.type, configuration, currentUser(), inputInfo.isExclusive) != null);
                } else {
                    result = (node.launchInput(request.title, request.type, request.global, configuration, currentUser(), inputInfo.isExclusive) != null);
                }

                if (!result) {
                    return status(500, views.html.errors.error.render(ApiClient.ERROR_MSG_IO, new RuntimeException("Could not launch input " + request.title), request()));
                }
View Full Code Here

        public T execute() throws APIException, IOException {
            if (radio != null && (node != null || nodes != null)) {
                throw new RuntimeException("You set both and a Node and a Radio as target. This is not possible.");
            }

            final ClusterEntity target;

            if (radio == null) {
                if (node == null) {
                    if (nodes != null) {
                        LOG.error("Multiple nodes are set, but execute() was called. This is most likely a bug and you meant to call executeOnAll()!", new Throwable());
                    }
                    node(serverNodes.any());
                }

                target = node;
            } else {
                target = radio;
            }

            ensureAuthentication();
            final URL url = prepareUrl(target);
            final AsyncHttpClient.BoundRequestBuilder requestBuilder = requestBuilderForUrl(url);
            requestBuilder.addHeader(Http.HeaderNames.ACCEPT, mediaType.toString());

            final Request request = requestBuilder.build();
            if (LOG.isDebugEnabled()) {
                LOG.debug("API Request: {}", request.toString());
            }

            // Set 200 OK as standard if not defined.
            if (expectedResponseCodes.isEmpty()) {
                expectedResponseCodes.add(Http.Status.OK);
            }

            try {
                // TODO implement streaming responses
                Response response = requestBuilder.execute().get(timeoutValue, timeoutUnit);

                target.touch();

                // TODO this is wrong, shouldn't it accept some callback instead of throwing an exception?
                if (!expectedResponseCodes.contains(response.getStatusCode())) {
                    throw new APIException(request, response);
                }

                // TODO: once we switch to jackson we can take the media type into account automatically
                final MediaType responseContentType;
                if (response.getContentType() == null) {
                    responseContentType = MediaType.JSON_UTF_8;
                } else {
                    responseContentType = MediaType.parse(response.getContentType());
                }

                if (!responseContentType.is(mediaType.withoutParameters())) {
                    LOG.warn("We said we'd accept {} but got {} back, let's see how that's going to work out...", mediaType, responseContentType);
                }
                if (responseClass.equals(String.class)) {
                    return responseClass.cast(response.getResponseBody("UTF-8"));
                }

                if (expectedResponseCodes.contains(response.getStatusCode())
                        || (response.getStatusCode() >= 200 && response.getStatusCode() < 300)) {
                    T result;
                    try {
                        if (response.getResponseBody().isEmpty()) {
                            return null;
                        }

                        if (responseContentType.is(MediaType.JSON_UTF_8.withoutParameters())) {
                            result = deserializeJson(response, responseClass);
                        } else {
                            LOG.error("Don't know how to deserialize objects with content in {}, expected {}, failing.", responseContentType, mediaType);
                            throw new APIException(request, response);
                        }

                        if (result == null) {
                            throw new APIException(request, response);
                        }

                        return result;
                    } catch (Exception e) {
                        LOG.error("Caught Exception while deserializing JSON request: ", e);
                        LOG.debug("Response from backend was: " + response.getResponseBody("UTF-8"));

                        throw new APIException(request, response, e);
                    }
                } else {
                    return null;
                }
            } catch (InterruptedException e) {
                // TODO
                target.markFailure();
            } catch (MalformedURLException e) {
                LOG.error("Malformed URL", e);
                throw new RuntimeException("Malformed URL.", e);
            } catch (ExecutionException e) {
                if (e.getCause() instanceof ConnectException) {
                    LOG.warn("Graylog2 server unavailable. Connection refused.");
                    target.markFailure();
                    throw new Graylog2ServerUnavailableException(e);
                }
                LOG.error("REST call failed", rootCause(e));
                throw new APIException(request, e);
            } catch (IOException e) {
                // TODO
                LOG.error("unhandled IOException", rootCause(e));
                target.markFailure();
                throw e;
            } catch (TimeoutException e) {
                LOG.warn("Timed out requesting {}", request);
                target.markFailure();
            }
            throw new APIException(request, new IllegalStateException("Unhandled error condition in API client"));
        }
View Full Code Here

    @Test
    public void testTransportAddressPathNormalization() {
        setupNodes(AddressNodeId.create("http://localhost:65535"));
        api.setHttpClient(client);
        final Node node = serverNodes.any();
        assertEquals("transport address should have no path", "http://localhost:65535", node.getTransportAddress());
    }
View Full Code Here

    @Test
    public void testFailureCountSingleExecute() throws Exception {
        setupNodes(AddressNodeId.create("http://localhost:65535"));
        api.setHttpClient(client);

        final Node node = serverNodes.any();

        try {
            api.put().path("/").node(node).execute();
        } catch (Graylog2ServerUnavailableException e) {
            Node failedNode = serverNodes.any(true);
            assertFalse("Node should be from configuration", failedNode.isActive());
            assertEquals(1, failedNode.getFailureCount());
        }
    }
View Full Code Here

        final Map<Node, EmptyResponse> emptyResponses = api.put().path("/").executeOnAll();

        assertTrue("Request should have failed", emptyResponses.isEmpty());
        final List<Node> nodes = serverNodes.all(true);
        Node failedNode = nodes.get(0);
        Node failedNode2 = nodes.get(1);
        assertFalse("Node should be inactive" , failedNode.isActive());
        assertFalse("Node should be inactive", failedNode2.isActive());
        assertEquals(1, failedNode.getFailureCount());
        assertEquals(1, failedNode2.getFailureCount());
    }
View Full Code Here

    public void testNodeObjectsRememberedByAddress() throws Exception {
        final AddressNodeId addressNodeId = AddressNodeId.create("http://localhost:65535", UUID.randomUUID().toString());
        setupNodes(addressNodeId);

        api.setHttpClient(client);
        final Node firstNode = serverNodes.any();

        Throwable t = null;
        try {
            api.put().path("/").node(firstNode).execute();
        } catch (Graylog2ServerUnavailableException e) {
            t = e;
        }
        assertNotNull("Should have thrown an Graylog2ServerUnavailableException", t);
        assertEquals("First node failure count should be 1", 1, firstNode.getFailureCount());

        final Node.Factory nodeFactory = injector.getInstance(Node.Factory.class);
        final NodeSummaryResponse r1 = new NodeSummaryResponse();
        r1.transportAddress = "http://localhost:65534";
        r1.id = UUID.randomUUID().toString();

        final Node newNode = nodeFactory.fromSummaryResponse(r1);
        newNode.touch();
        final NodeSummaryResponse r2 = new NodeSummaryResponse();
        r2.transportAddress = firstNode.getTransportAddress();
        r2.id = firstNode.getNodeId();
        final Node sameAsInitialNode = nodeFactory.fromSummaryResponse(r2);
        sameAsInitialNode.touch();
        serverNodes.put(ImmutableList.of(newNode, sameAsInitialNode));

        final Map<Node, EmptyResponse> responses = api.put().nodes(serverNodes.all().toArray(new Node[0])).path("/").executeOnAll();

        assertTrue(responses.isEmpty());
View Full Code Here

    @Test
    public void testBuildTarget() throws Exception {
        setupNodes(AddressNodeId.create("http://horst:12900"));

        // we only have one node configured here
        final Node node = serverNodes.any();
        api.setHttpClient(client);

        final URL url = api.get(EmptyResponse.class).path("/some/resource").session("foo").node(node).prepareUrl(node);
        final URL queryParamWithPlus = api.get(EmptyResponse.class).path("/some/resource").queryParam("query", " (.+)").node(node).unauthenticated().prepareUrl(node);
View Full Code Here

    @Test
    public void testSingleExecute() throws Exception {
        setupNodes(AddressNodeId.create("http://horst:12900"));

        // we only have one node configured here
        final Node node = serverNodes.any();
        api.setHttpClient(client);

        final ApiRequestBuilder<EmptyResponse> requestBuilder =
                api.get(EmptyResponse.class)
                        .path("/some/resource")
View Full Code Here

    public void testParallelExecution() throws Exception {
        setupNodes(AddressNodeId.create("http://horst1:12900"), AddressNodeId.create("http://horst2:12900"));

        final Collection<Node> nodes = serverNodes.all();
        final Iterator<Node> it = nodes.iterator();
        Node node1 = it.next();
        Node node2 = it.next();
        api.setHttpClient(client);

        final ApiRequestBuilder<EmptyResponse> requestBuilder = api.get(EmptyResponse.class).path("/some/resource");
        final URL url1 = requestBuilder.prepareUrl(node1);
        final URL url2 = requestBuilder.prepareUrl(node2);
View Full Code Here

TOP

Related Classes of org.graylog2.restclient.models.ClusterEntity

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.