Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id AFFB8200B99 for ; Wed, 21 Sep 2016 00:34:24 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id AE7B7160AC9; Tue, 20 Sep 2016 22:34:24 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id A627E160AC5 for ; Wed, 21 Sep 2016 00:34:23 +0200 (CEST) Received: (qmail 98232 invoked by uid 500); 20 Sep 2016 22:34:22 -0000 Mailing-List: contact commits-help@geode.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@geode.incubator.apache.org Delivered-To: mailing list commits@geode.incubator.apache.org Received: (qmail 98223 invoked by uid 99); 20 Sep 2016 22:34:22 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd2-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 20 Sep 2016 22:34:22 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd2-us-west.apache.org (ASF Mail Server at spamd2-us-west.apache.org) with ESMTP id 5F8041A61BF for ; Tue, 20 Sep 2016 22:34:22 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd2-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -4.646 X-Spam-Level: X-Spam-Status: No, score=-4.646 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, KAM_LAZY_DOMAIN_SECURITY=1, RCVD_IN_DNSWL_HI=-5, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, RP_MATCHES_RCVD=-1.426] autolearn=disabled Received: from mx1-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd2-us-west.apache.org [10.40.0.9]) (amavisd-new, port 10024) with ESMTP id 5AbsKOMgBbgD for ; Tue, 20 Sep 2016 22:34:20 +0000 (UTC) Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx1-lw-eu.apache.org (ASF Mail Server at mx1-lw-eu.apache.org) with SMTP id 9DFB060E30 for ; Tue, 20 Sep 2016 22:34:19 +0000 (UTC) Received: (qmail 96562 invoked by uid 99); 20 Sep 2016 22:34:18 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 20 Sep 2016 22:34:18 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 7541AEF9A3; Tue, 20 Sep 2016 22:34:18 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: hiteshkhamesra@apache.org To: commits@geode.incubator.apache.org Date: Tue, 20 Sep 2016 22:34:37 -0000 Message-Id: <9d6e6a979e424bfc957b0b05a969a5b2@git.apache.org> In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [20/35] incubator-geode git commit: GEODE-37 renamed pulse package to geode archived-at: Tue, 20 Sep 2016 22:34:24 -0000 http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/9a2b5d7b/geode-pulse/src/main/java/org/apache/geode/tools/pulse/internal/data/DataBrowser.java ---------------------------------------------------------------------- diff --git a/geode-pulse/src/main/java/org/apache/geode/tools/pulse/internal/data/DataBrowser.java b/geode-pulse/src/main/java/org/apache/geode/tools/pulse/internal/data/DataBrowser.java new file mode 100644 index 0000000..668b74c --- /dev/null +++ b/geode-pulse/src/main/java/org/apache/geode/tools/pulse/internal/data/DataBrowser.java @@ -0,0 +1,248 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package com.vmware.geode.tools.pulse.internal.data; + +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.node.ArrayNode; +import com.fasterxml.jackson.databind.node.ObjectNode; +import com.vmware.geode.tools.pulse.internal.log.PulseLogWriter; +import com.vmware.geode.tools.pulse.internal.util.StringUtils; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.text.SimpleDateFormat; +import java.util.Iterator; +import java.util.ResourceBundle; +import java.util.Scanner; + +/** + * Class DataBrowser This class contains Data browser functionalities for + * managing queries and histories. + * + * @since GemFire version 7.5.Beta 2013-03-25 + */ +public class DataBrowser { + + private final PulseLogWriter LOGGER = PulseLogWriter.getLogger(); + private final ResourceBundle resourceBundle = Repository.get() + .getResourceBundle(); + + private SimpleDateFormat simpleDateFormat = new SimpleDateFormat( + PulseConstants.PULSE_QUERY_HISTORY_DATE_PATTERN); + + private final ObjectMapper mapper = new ObjectMapper(); + + /** + * addQueryInHistory method adds user's query into query history file + * + * @param userId + * Logged in User's Id + * @param queryText + * Query text to execute + */ + public boolean addQueryInHistory(String queryText, String userId) { + boolean operationStatus = false; + if (StringUtils.isNotNullNotEmptyNotWhiteSpace(queryText) + && StringUtils.isNotNullNotEmptyNotWhiteSpace(userId)) { + + // Fetch all queries from query log file + ObjectNode queries = fetchAllQueriesFromFile(); + + // Get user's query history list + ObjectNode userQueries = (ObjectNode) queries.get(userId); + if (userQueries == null) { + userQueries = mapper.createObjectNode(); + } + + // Add query in user's query history list + userQueries.put(Long.toString(System.currentTimeMillis()), queryText); + queries.put(userId, userQueries); + + // Store queries in file back + operationStatus = storeQueriesInFile(queries); + } + + return operationStatus; + } + + /** + * deleteQueryById method deletes query from query history file + * + * @param userId + * Logged in user's Unique Id + * @param queryId + * Unique Id of Query to be deleted + * @return boolean + */ + public boolean deleteQueryById(String userId, String queryId) { + + boolean operationStatus = false; + if (StringUtils.isNotNullNotEmptyNotWhiteSpace(queryId) + && StringUtils.isNotNullNotEmptyNotWhiteSpace(userId)) { + + // Fetch all queries from query log file + ObjectNode queries = fetchAllQueriesFromFile(); + + // Get user's query history list + ObjectNode userQueries = (ObjectNode) queries.get(userId); + + if (userQueries != null) { + // Remove user's query + userQueries.remove(queryId); + queries.put(userId, userQueries); + + // Store queries in file back + operationStatus = storeQueriesInFile(queries); + } + } + + return operationStatus; + } + + /** + * getQueryHistoryByUserId method reads and lists out the queries from history + * file + * + * @param userId + * Logged in User's Id + */ + public ArrayNode getQueryHistoryByUserId(String userId) { + + ArrayNode queryList = mapper.createArrayNode(); + + if (StringUtils.isNotNullNotEmptyNotWhiteSpace(userId)) { + + // Fetch all queries from query log file + ObjectNode queries = fetchAllQueriesFromFile(); + + // Get user's query history list + ObjectNode userQueries = (ObjectNode) queries.get(userId); + + if (userQueries != null) { + Iterator it = userQueries.fieldNames(); + while (it.hasNext()) { + String key = it.next(); + ObjectNode queryItem = mapper.createObjectNode(); + queryItem.put("queryId", key); + queryItem.put("queryText", userQueries.get(key).toString()); + queryItem.put("queryDateTime", simpleDateFormat.format(Long.valueOf(key))); + queryList.add(queryItem); + } + } + } + + return queryList; + } + + /** + * generateQueryKey method fetches queries from query history file + * + * @return Properties A collection queries in form of key and values + */ + private ObjectNode fetchAllQueriesFromFile() { + InputStream inputStream = null; + JsonNode queriesJSON = mapper.createObjectNode(); + + try { + inputStream = new FileInputStream(Repository.get().getPulseConfig().getQueryHistoryFileName()); + String inputStreamString = new Scanner(inputStream, "UTF-8").useDelimiter("\\A").next(); + queriesJSON = mapper.readTree(inputStreamString); + } catch (FileNotFoundException e) { + if (LOGGER.fineEnabled()) { + LOGGER.fine(resourceBundle + .getString("LOG_MSG_DATA_BROWSER_QUERY_HISTORY_FILE_NOT_FOUND") + + " : " + e.getMessage()); + } + } catch (Exception e) { + if (LOGGER.infoEnabled()) { + LOGGER.info(e.getMessage()); + } + } finally { + // Close input stream + if (inputStream != null) { + try { + inputStream.close(); + } catch (IOException e) { + if (LOGGER.infoEnabled()) { + LOGGER.info(e.getMessage()); + } + } + } + } + + return (ObjectNode) queriesJSON; + } + + /** + * generateQueryKey method stores queries in query history file. + * + * @return Boolean true is operation is successful, false otherwise + */ + private boolean storeQueriesInFile(ObjectNode queries) { + boolean operationStatus = false; + FileOutputStream fileOut = null; + + File file = new File(Repository.get().getPulseConfig().getQueryHistoryFileName()); + try { + fileOut = new FileOutputStream(file); + + // if file does not exists, then create it + if (!file.exists()) { + file.createNewFile(); + } + + // get the content in bytes + byte[] contentInBytes = queries.toString().getBytes(); + + fileOut.write(contentInBytes); + fileOut.flush(); + + operationStatus = true; + } catch (FileNotFoundException e) { + + if (LOGGER.fineEnabled()) { + LOGGER.fine(resourceBundle + .getString("LOG_MSG_DATA_BROWSER_QUERY_HISTORY_FILE_NOT_FOUND") + + " : " + e.getMessage()); + } + } catch (IOException e) { + if (LOGGER.infoEnabled()) { + LOGGER.info(e.getMessage()); + } + } finally { + if (fileOut != null) { + try { + fileOut.close(); + } catch (IOException e) { + if (LOGGER.infoEnabled()) { + LOGGER.info(e.getMessage()); + } + } + } + } + return operationStatus; + } + +} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/9a2b5d7b/geode-pulse/src/main/java/org/apache/geode/tools/pulse/internal/data/IClusterUpdater.java ---------------------------------------------------------------------- diff --git a/geode-pulse/src/main/java/org/apache/geode/tools/pulse/internal/data/IClusterUpdater.java b/geode-pulse/src/main/java/org/apache/geode/tools/pulse/internal/data/IClusterUpdater.java new file mode 100644 index 0000000..106ea63 --- /dev/null +++ b/geode-pulse/src/main/java/org/apache/geode/tools/pulse/internal/data/IClusterUpdater.java @@ -0,0 +1,35 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package com.vmware.geode.tools.pulse.internal.data; + +import com.fasterxml.jackson.databind.node.ObjectNode; + +/** + * Interface having updateData() function which is getting Override by both + * MockDataUpdater and JMXDataUpdater + * + * @since GemFire version 7.0.Beta 2012-09-23 + * + */ +public interface IClusterUpdater { + boolean updateData(); + + ObjectNode executeQuery(String queryText, String members, int limit); +}