Search in sources :

Example 16 with Cluster

use of org.apache.geode.tools.pulse.internal.data.Cluster in project geode by apache.

the class PulseController method dataBrowserQuery.

@RequestMapping(value = "/dataBrowserQuery", method = RequestMethod.GET)
public void dataBrowserQuery(HttpServletRequest request, HttpServletResponse response) throws IOException {
    // get query string
    String query = request.getParameter("query");
    String members = request.getParameter("members");
    int limit = 0;
    try {
        limit = Integer.valueOf(request.getParameter("limit"));
    } catch (NumberFormatException e) {
        limit = 0;
        logger.debug(e);
    }
    ObjectNode queryResult = mapper.createObjectNode();
    try {
        if (StringUtils.isNotBlank(query)) {
            // get cluster object
            Cluster cluster = Repository.get().getCluster();
            String userName = request.getUserPrincipal().getName();
            // Call execute query method
            queryResult = cluster.executeQuery(query, members, limit);
            // Add query in history if query is executed successfully
            if (!queryResult.has("error")) {
                // Add html escaped query to history
                String escapedQuery = StringEscapeUtils.escapeHtml(query);
                cluster.addQueryInHistory(escapedQuery, userName);
            }
        }
    } catch (Exception e) {
        logger.debug("Exception Occurred : ", e);
    }
    response.getOutputStream().write(queryResult.toString().getBytes());
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Cluster(org.apache.geode.tools.pulse.internal.data.Cluster) IOException(java.io.IOException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 17 with Cluster

use of org.apache.geode.tools.pulse.internal.data.Cluster in project geode by apache.

the class PulseController method acknowledgeAlert.

@RequestMapping(value = "/acknowledgeAlert", method = RequestMethod.GET)
public void acknowledgeAlert(HttpServletRequest request, HttpServletResponse response) throws IOException {
    int alertId;
    ObjectNode responseJSON = mapper.createObjectNode();
    try {
        alertId = Integer.valueOf(request.getParameter("alertId"));
    } catch (NumberFormatException e) {
        // Empty json response
        response.getOutputStream().write(responseJSON.toString().getBytes());
        logger.debug(e);
        return;
    }
    try {
        // get cluster object
        Cluster cluster = Repository.get().getCluster();
        // set alert is acknowledged
        cluster.acknowledgeAlert(alertId);
        responseJSON.put("status", "deleted");
    } catch (Exception e) {
        logger.debug("Exception Occurred : {}", e);
    }
    // Send json response
    response.getOutputStream().write(responseJSON.toString().getBytes());
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Cluster(org.apache.geode.tools.pulse.internal.data.Cluster) IOException(java.io.IOException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 18 with Cluster

use of org.apache.geode.tools.pulse.internal.data.Cluster in project geode by apache.

the class PulseController method getQueryStatisticsGridModel.

@RequestMapping(value = "/getQueryStatisticsGridModel", method = RequestMethod.GET)
public void getQueryStatisticsGridModel(HttpServletRequest request, HttpServletResponse response) throws IOException {
    ObjectNode responseJSON = mapper.createObjectNode();
    // get cluster object
    Cluster cluster = Repository.get().getCluster();
    String userName = request.getUserPrincipal().getName();
    try {
        String[] arrColNames = Cluster.Statement.getGridColumnNames();
        String[] arrColAttribs = Cluster.Statement.getGridColumnAttributes();
        int[] arrColWidths = Cluster.Statement.getGridColumnWidths();
        ArrayNode colNamesList = mapper.createArrayNode();
        for (int i = 0; i < arrColNames.length; ++i) {
            colNamesList.add(arrColNames[i]);
        }
        ArrayNode colModelList = mapper.createArrayNode();
        for (int i = 0; i < arrColAttribs.length; ++i) {
            ObjectNode columnJSON = mapper.createObjectNode();
            columnJSON.put("name", arrColAttribs[i]);
            columnJSON.put("index", arrColAttribs[i]);
            columnJSON.put("width", arrColWidths[i]);
            columnJSON.put("sortable", "true");
            columnJSON.put("sorttype", ((i == 0) ? "String" : "integer"));
            colModelList.add(columnJSON);
        }
        responseJSON.put("columnNames", colNamesList);
        responseJSON.put("columnModels", colModelList);
        responseJSON.put("clusterName", cluster.getServerName());
        responseJSON.put("userName", userName);
        // Send json response
        response.getOutputStream().write(responseJSON.toString().getBytes());
    } catch (Exception e) {
        logger.debug("Exception Occurred : ", e);
    }
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Cluster(org.apache.geode.tools.pulse.internal.data.Cluster) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) IOException(java.io.IOException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 19 with Cluster

use of org.apache.geode.tools.pulse.internal.data.Cluster in project geode by apache.

the class PulseVerificationTest method testConnectToLocator.

@Test
public void testConnectToLocator() throws Exception {
    pulse.useLocatorPort(locator.getPort());
    Cluster cluster = pulse.getRepository().getCluster("admin", null);
    assertThat(cluster.isConnectedFlag()).isTrue();
    assertThat(cluster.getServerCount()).isEqualTo(0);
}
Also used : Cluster(org.apache.geode.tools.pulse.internal.data.Cluster) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 20 with Cluster

use of org.apache.geode.tools.pulse.internal.data.Cluster in project geode by apache.

the class PulseVerificationTest method testConnectToJmx.

@Test
public void testConnectToJmx() throws Exception {
    pulse.useJmxPort(locator.getJmxPort());
    Cluster cluster = pulse.getRepository().getCluster("admin", null);
    assertThat(cluster.isConnectedFlag()).isTrue();
    assertThat(cluster.getServerCount()).isEqualTo(0);
}
Also used : Cluster(org.apache.geode.tools.pulse.internal.data.Cluster) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Aggregations

Cluster (org.apache.geode.tools.pulse.internal.data.Cluster)43 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)39 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)18 JsonNode (com.fasterxml.jackson.databind.JsonNode)12 IOException (java.io.IOException)7 DecimalFormat (java.text.DecimalFormat)7 ArrayList (java.util.ArrayList)7 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)7 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)3 Test (org.junit.Test)3 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 Repository (org.apache.geode.tools.pulse.internal.data.Repository)2 File (java.io.File)1 Random (java.util.Random)1 CircularFifoBuffer (org.apache.commons.collections.buffer.CircularFifoBuffer)1 Client (org.apache.geode.tools.pulse.internal.data.Cluster.Client)1 Member (org.apache.geode.tools.pulse.internal.data.Cluster.Member)1 Region (org.apache.geode.tools.pulse.internal.data.Cluster.Region)1