You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by hi...@apache.org on 2016/09/09 21:44:18 UTC
[81/83] [abbrv] incubator-geode git commit: GEODE-37 renamed pulse
package
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/eff7f216/geode-pulse/src/main/java/com/vmware/gemfire/tools/pulse/internal/PulseAppListener.java
----------------------------------------------------------------------
diff --git a/geode-pulse/src/main/java/com/vmware/gemfire/tools/pulse/internal/PulseAppListener.java b/geode-pulse/src/main/java/com/vmware/gemfire/tools/pulse/internal/PulseAppListener.java
deleted file mode 100644
index 408eed3..0000000
--- a/geode-pulse/src/main/java/com/vmware/gemfire/tools/pulse/internal/PulseAppListener.java
+++ /dev/null
@@ -1,742 +0,0 @@
-/*
- *
- * 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;
-
-import com.vmware.geode.tools.pulse.internal.controllers.PulseController;
-import com.vmware.geode.tools.pulse.internal.data.PulseConfig;
-import com.vmware.geode.tools.pulse.internal.data.PulseConstants;
-import com.vmware.geode.tools.pulse.internal.data.Repository;
-import com.vmware.geode.tools.pulse.internal.log.PulseLogWriter;
-import com.vmware.geode.tools.pulse.internal.util.StringUtils;
-import org.springframework.web.context.WebApplicationContext;
-import org.springframework.web.context.support.WebApplicationContextUtils;
-
-import javax.servlet.ServletContextEvent;
-import javax.servlet.ServletContextListener;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.PrintWriter;
-import java.io.StringWriter;
-import java.net.InetAddress;
-import java.net.UnknownHostException;
-import java.text.DateFormat;
-import java.text.SimpleDateFormat;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map.Entry;
-import java.util.Properties;
-import java.util.ResourceBundle;
-import java.util.Set;
-import java.util.logging.Level;
-
-/**
- * This class is used for checking the application running mode i.e. Embedded or
- * not
- *
- * @since GemFire version 7.0.Beta 2012-09-23
- *
- */
-// @WebListener
-public class PulseAppListener implements ServletContextListener {
- private PulseLogWriter LOGGER;
- private final ResourceBundle resourceBundle = Repository.get()
- .getResourceBundle();
-
- // String object to store all messages which needs to be logged into the log
- // file before logger gets initialized
- private String messagesToBeLogged = "";
-
- private Properties pulseProperties;
- private Properties pulseSecurityProperties;
- private Boolean sysPulseUseLocator;
- private String sysPulseHost;
- private String sysPulsePort;
- private String jmxUserName;
- private String jmxUserPassword;
-
- private boolean sysPulseUseSSLLocator;
- private boolean sysPulseUseSSLManager;
-
- //This property determines if pulse webApp login is authenticated against
- //GemFire integrated security or custom spring-security config provided
- //in pulse-authentication-custom.xml
- private boolean useGemFireCredentials;
-
- @Override
- public void contextDestroyed(ServletContextEvent event) {
-
- // Stop all running threads those are created in Pulse
- // Stop cluster threads
- Repository.get().removeAllClusters();
-
- if (LOGGER.infoEnabled()) {
- LOGGER.info(resourceBundle.getString("LOG_MSG_CONTEXT_DESTROYED")
- + event.getServletContext().getContextPath());
- }
- }
-
- @Override
- public void contextInitialized(ServletContextEvent event) {
-
- messagesToBeLogged = messagesToBeLogged
- .concat(formatLogString(resourceBundle
- .getString("LOG_MSG_CONTEXT_INITIALIZED")));
-
- // Load Pulse version details
- loadPulseVersionDetails();
-
- // Load Pulse Properties
- pulseProperties = loadProperties(PulseConstants.PULSE_PROPERTIES_FILE);
-
- if (pulseProperties.isEmpty()) {
- messagesToBeLogged = messagesToBeLogged
- .concat(formatLogString(resourceBundle
- .getString("LOG_MSG_PROPERTIES_NOT_FOUND")));
- } else {
- messagesToBeLogged = messagesToBeLogged
- .concat(formatLogString(resourceBundle
- .getString("LOG_MSG_PROPERTIES_FOUND")));
-
- // set Pulse product support into the Pulse controller for access from
- // client side
- // to display the appropriate ui depending on which product is supported
- // in present deployment
- String pulseProduct = pulseProperties.getProperty(PulseConstants.APPLICATION_PROPERTY_PULSE_PRODUCTSUPPORT);
- // default is gemfire
-
- if ((pulseProduct != null) && (pulseProduct.trim().equalsIgnoreCase(PulseConstants.PRODUCT_NAME_SQLFIRE))) {
- PulseController.setPulseProductSupport(PulseConstants.PRODUCT_NAME_SQLFIRE);
- }
- }
-
- pulseSecurityProperties = loadProperties(PulseConstants.PULSE_SECURITY_PROPERTIES_FILE);
-
- // Initialize logger
- initializeLogger();
-
- // Reference to repository
- Repository repository = Repository.get();
-
- if (LOGGER.infoEnabled()) {
- LOGGER.info(resourceBundle.getString("LOG_MSG_CHECK_APP_RUNNING_MODE"));
- }
-
- boolean sysIsEmbedded = Boolean
- .getBoolean(PulseConstants.SYSTEM_PROPERTY_PULSE_EMBEDDED);
-
- if (sysIsEmbedded) {
- // Application Pulse is running in Embedded Mode
- if (LOGGER.infoEnabled()) {
- LOGGER.info(resourceBundle
- .getString("LOG_MSG_APP_RUNNING_EMBEDDED_MODE"));
- }
- repository.setIsEmbeddedMode(true);
-
- sysPulseUseLocator = Boolean.FALSE;
- try{
- // Get host name of machine running pulse in embedded mode
- sysPulseHost = InetAddress.getLocalHost().getCanonicalHostName();
- } catch (UnknownHostException e) {
- if (LOGGER.fineEnabled()) {
- LOGGER.fine(resourceBundle
- .getString("LOG_MSG_JMX_CONNECTION_UNKNOWN_HOST")
- + e.getMessage());
- }
- // Set default host name
- sysPulseHost = PulseConstants.GEMFIRE_DEFAULT_HOST;
- } catch (Exception e) {
- if (LOGGER.fineEnabled()) {
- LOGGER.fine(resourceBundle
- .getString("LOG_MSG_JMX_CONNECTION_UNKNOWN_HOST")
- + e.getMessage());
- }
- // Set default host name
- sysPulseHost = PulseConstants.GEMFIRE_DEFAULT_HOST;
- }
- sysPulsePort = PulseConstants.GEMFIRE_DEFAULT_PORT;
-
- boolean pulseEmbededSqlf = Boolean.getBoolean(PulseConstants.SYSTEM_PROPERTY_PULSE_EMBEDDED_SQLF);
- if(pulseEmbededSqlf){
- PulseController.setPulseProductSupport(PulseConstants.PRODUCT_NAME_SQLFIRE);
- if (LOGGER.infoEnabled()) {
- LOGGER.info(resourceBundle
- .getString("LOG_MSG_APP_RUNNING_EMBEDDED_SQLF_MODE"));
- }
- }
-
- } else {
- // Application Pulse is running in Non-Embedded Mode
- if (LOGGER.infoEnabled()) {
- LOGGER.info(resourceBundle
- .getString("LOG_MSG_APP_RUNNING_NONEMBEDDED_MODE"));
- }
- repository.setIsEmbeddedMode(false);
-
- // Load JMX User Details
- loadJMXUserDetails();
- // Load locator and/or manager details
- loadLocatorManagerDetails();
-
- useGemFireCredentials = areWeUsingGemFireSecurityProfile(event);
- }
-
- // Set user details in repository
- repository.setJmxUserName(jmxUserName);
- repository.setJmxUserPassword(jmxUserPassword);
-
- // Set locator/Manager details in repository
- repository.setJmxUseLocator(sysPulseUseLocator);
- repository.setJmxHost(sysPulseHost);
- repository.setJmxPort(sysPulsePort);
-
- //set SSL info
- initializeSSL();
- repository.setUseSSLLocator(sysPulseUseSSLLocator);
- repository.setUseSSLManager(sysPulseUseSSLManager);
-
- repository.setUseGemFireCredentials(useGemFireCredentials);
-
- }
-
- /**
- * Return true if pulse is configure to authenticate using gemfire
- * integrated security
- *
- * @param event
- * @return
- */
- private boolean areWeUsingGemFireSecurityProfile(ServletContextEvent event) {
- String profile = null;
- WebApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(event.getServletContext());
- if (ctx.getEnvironment() != null) {
- String[] profiles = ctx.getEnvironment().getActiveProfiles();
- if (profiles != null && profiles.length > 0) {
- StringBuilder sb = new StringBuilder();
- for (String p : profiles)
- sb.append(p).append(",");
- LOGGER.info("#SpringProfilesConfigured : " + sb.toString());
- profile = ctx.getEnvironment().getActiveProfiles()[0];
- LOGGER.info("#First Profile : " + profile);
- } else {
- LOGGER.info("No SpringProfileConfigured using default spring profile");
- return false;
- }
- }
- if (PulseConstants.APPLICATION_PROPERTY_PULSE_SEC_PROFILE_GEMFIRE.equals(profile)) {
- LOGGER.info("Using gemfire integrated security profile");
- return true;
- }
- return false;
- }
-
- // Function to load pulse version details from properties file
- private void loadPulseVersionDetails() {
-
- // Read version details from version property file
- ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
- InputStream inputStream = classLoader
- .getResourceAsStream(PulseConstants.PULSE_VERSION_PROPERTIES_FILE);
-
- if (inputStream != null) {
- Properties properties = new Properties();
- try {
- properties.load(inputStream);
- } catch (IOException e) {
- messagesToBeLogged = messagesToBeLogged
- .concat(formatLogString(resourceBundle
- .getString("LOG_MSG_EXCEPTION_LOADING_PROPERTIES_FILE")));
- } finally {
- try {
- inputStream.close();
- } catch (IOException e) {
- messagesToBeLogged = messagesToBeLogged
- .concat(formatLogString(resourceBundle
- .getString("LOG_MSG_EXCEPTION_CLOSING_INPUT_STREAM")));
- }
- }
- // Set pulse version details in common object
- PulseController.pulseVersion.setPulseVersion(properties.getProperty(
- PulseConstants.PROPERTY_PULSE_VERSION, ""));
- PulseController.pulseVersion.setPulseBuildId(properties.getProperty(
- PulseConstants.PROPERTY_BUILD_ID, ""));
- PulseController.pulseVersion.setPulseBuildDate(properties.getProperty(
- PulseConstants.PROPERTY_BUILD_DATE, ""));
- PulseController.pulseVersion.setPulseSourceDate(properties.getProperty(
- PulseConstants.PROPERTY_SOURCE_DATE, ""));
- PulseController.pulseVersion.setPulseSourceRevision(properties
- .getProperty(PulseConstants.PROPERTY_SOURCE_REVISION, ""));
- PulseController.pulseVersion.setPulseSourceRepository(properties
- .getProperty(PulseConstants.PROPERTY_SOURCE_REPOSITORY, ""));
- }
-
- // Log Pulse Version details into log file
- messagesToBeLogged = messagesToBeLogged
- .concat(formatLogString(PulseController.pulseVersion
- .getPulseVersionLogMessage()));
- }
-
- private void initializeLogger() {
-
- // Override default log configuration by properties which are provided in
- // properties file.
- loadLogDetailsFromPropertyFile();
-
- // Override log configuration by properties which are provided in
- // through system properties.
- loadLogDetailsFromSystemProperties();
-
- // Initialize logger object
- LOGGER = PulseLogWriter.getLogger();
-
- // Log messages stored in messagesToBeLogged
- if (LOGGER.infoEnabled()) {
- LOGGER.info(messagesToBeLogged);
- messagesToBeLogged = "";
- }
- }
-
- // Function to load pulse properties from pulse.properties file
- private Properties loadProperties(String propertyFile) {
-
- ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
- InputStream inputStream = classLoader.getResourceAsStream(propertyFile);
- Properties properties = new Properties();
-
- if (inputStream != null) {
- messagesToBeLogged = messagesToBeLogged.concat(formatLogString(propertyFile + " "
- + resourceBundle.getString("LOG_MSG_FILE_FOUND")));
-
- try {
- // Load properties from input stream
- properties.load(inputStream);
- } catch (IOException e1) {
- messagesToBeLogged = messagesToBeLogged.concat(formatLogString(resourceBundle
- .getString("LOG_MSG_EXCEPTION_LOADING_PROPERTIES_FILE")
- + " " + propertyFile));
- } finally {
- // Close input stream
- try {
- inputStream.close();
- } catch (IOException e) {
- messagesToBeLogged = messagesToBeLogged.concat(formatLogString(resourceBundle
- .getString("LOG_MSG_EXCEPTION_CLOSING_INPUT_STREAM")
- + " " + propertyFile));
- }
- }
-
- } else {
- messagesToBeLogged = messagesToBeLogged.concat(formatLogString(resourceBundle
- .getString("LOG_MSG_COULD_NOT_READ_FILE")
- + " " + propertyFile));
- }
- return properties;
- }
-
- // Function to load Logging details from properties file
- private void loadLogDetailsFromPropertyFile() {
-
- // return, if Pulse Properties are not provided
- if (pulseProperties.size() == 0) {
- return;
- }
-
- messagesToBeLogged = messagesToBeLogged
- .concat(formatLogString(resourceBundle
- .getString("LOG_MSG_CHECK_LOG_PROPERTIES_IN_FILE")));
-
- HashMap<String, String> logPropertiesHM = new HashMap<String, String>();
-
- logPropertiesHM.put(PulseConstants.APPLICATION_PROPERTY_PULSE_LOGFILENAME,
- pulseProperties.getProperty(
- PulseConstants.APPLICATION_PROPERTY_PULSE_LOGFILENAME, ""));
-
- logPropertiesHM.put(
- PulseConstants.APPLICATION_PROPERTY_PULSE_LOGFILELOCATION,
- pulseProperties.getProperty(
- PulseConstants.APPLICATION_PROPERTY_PULSE_LOGFILELOCATION, ""));
-
- logPropertiesHM.put(PulseConstants.APPLICATION_PROPERTY_PULSE_LOGFILESIZE,
- pulseProperties.getProperty(
- PulseConstants.APPLICATION_PROPERTY_PULSE_LOGFILESIZE, ""));
-
- logPropertiesHM.put(PulseConstants.APPLICATION_PROPERTY_PULSE_LOGFILECOUNT,
- pulseProperties.getProperty(
- PulseConstants.APPLICATION_PROPERTY_PULSE_LOGFILECOUNT, ""));
-
- logPropertiesHM.put(
- PulseConstants.APPLICATION_PROPERTY_PULSE_LOGDATEPATTERN,
- pulseProperties.getProperty(
- PulseConstants.APPLICATION_PROPERTY_PULSE_LOGDATEPATTERN, ""));
-
- logPropertiesHM.put(PulseConstants.APPLICATION_PROPERTY_PULSE_LOGLEVEL,
- pulseProperties.getProperty(
- PulseConstants.APPLICATION_PROPERTY_PULSE_LOGLEVEL, ""));
-
- logPropertiesHM.put(PulseConstants.APPLICATION_PROPERTY_PULSE_LOGAPPEND,
- pulseProperties.getProperty(
- PulseConstants.APPLICATION_PROPERTY_PULSE_LOGAPPEND, ""));
-
- if (logPropertiesHM.size() == 0) {
- messagesToBeLogged = messagesToBeLogged
- .concat(formatLogString(resourceBundle
- .getString("LOG_MSG_LOG_PROPERTIES_NOT_FOUND_IN_FILE")));
- } else {
- messagesToBeLogged = messagesToBeLogged
- .concat(formatLogString(resourceBundle
- .getString("LOG_MSG_LOG_PROPERTIES_FOUND_IN_FILE")));
- }
-
- setLogConfigurations(logPropertiesHM);
- }
-
- // Function to load Logging details from system properties
- private void loadLogDetailsFromSystemProperties() {
-
- messagesToBeLogged = messagesToBeLogged
- .concat(formatLogString(resourceBundle
- .getString("LOG_MSG_CHECK_LOG_PROPERTIES_IN_SYSTEM_PROPERTIES")));
-
- HashMap<String, String> logPropertiesHM = new HashMap<String, String>();
-
- String sysLogFileName = System
- .getProperty(PulseConstants.APPLICATION_PROPERTY_PULSE_LOGFILENAME);
- String sysLogFileLocation = System
- .getProperty(PulseConstants.APPLICATION_PROPERTY_PULSE_LOGFILELOCATION);
- String sysLogFileSize = System
- .getProperty(PulseConstants.APPLICATION_PROPERTY_PULSE_LOGFILESIZE);
- String sysLogFileCount = System
- .getProperty(PulseConstants.APPLICATION_PROPERTY_PULSE_LOGFILECOUNT);
- String sysLogDatePattern = System
- .getProperty(PulseConstants.APPLICATION_PROPERTY_PULSE_LOGDATEPATTERN);
- String sysLogLevel = System
- .getProperty(PulseConstants.APPLICATION_PROPERTY_PULSE_LOGLEVEL);
- String sysLogAppend = System
- .getProperty(PulseConstants.APPLICATION_PROPERTY_PULSE_LOGAPPEND);
-
- if (sysLogFileName == null || sysLogFileName.isEmpty()) {
- logPropertiesHM.put(
- PulseConstants.APPLICATION_PROPERTY_PULSE_LOGFILENAME, "");
- } else {
- logPropertiesHM
- .put(PulseConstants.APPLICATION_PROPERTY_PULSE_LOGFILENAME,
- sysLogFileName);
- }
-
- if (sysLogFileLocation == null || sysLogFileLocation.isEmpty()) {
- logPropertiesHM.put(
- PulseConstants.APPLICATION_PROPERTY_PULSE_LOGFILELOCATION, "");
- } else {
- logPropertiesHM.put(
- PulseConstants.APPLICATION_PROPERTY_PULSE_LOGFILELOCATION,
- sysLogFileLocation);
- }
-
- if (sysLogFileSize == null || sysLogFileSize.isEmpty()) {
- logPropertiesHM.put(
- PulseConstants.APPLICATION_PROPERTY_PULSE_LOGFILESIZE, "");
- } else {
- logPropertiesHM
- .put(PulseConstants.APPLICATION_PROPERTY_PULSE_LOGFILESIZE,
- sysLogFileSize);
- }
-
- if (sysLogFileCount == null || sysLogFileCount.isEmpty()) {
- logPropertiesHM.put(
- PulseConstants.APPLICATION_PROPERTY_PULSE_LOGFILECOUNT, "");
- } else {
- logPropertiesHM.put(
- PulseConstants.APPLICATION_PROPERTY_PULSE_LOGFILECOUNT,
- sysLogFileCount);
- }
-
- if (sysLogDatePattern == null || sysLogDatePattern.isEmpty()) {
- logPropertiesHM.put(
- PulseConstants.APPLICATION_PROPERTY_PULSE_LOGDATEPATTERN, "");
- } else {
- logPropertiesHM.put(
- PulseConstants.APPLICATION_PROPERTY_PULSE_LOGDATEPATTERN,
- sysLogDatePattern);
- }
-
- if (sysLogLevel == null || sysLogLevel.isEmpty()) {
- logPropertiesHM.put(PulseConstants.APPLICATION_PROPERTY_PULSE_LOGLEVEL,
- "");
- } else {
- logPropertiesHM.put(PulseConstants.APPLICATION_PROPERTY_PULSE_LOGLEVEL,
- sysLogLevel);
- }
-
- if (sysLogAppend == null || sysLogAppend.isEmpty()) {
- logPropertiesHM.put(PulseConstants.APPLICATION_PROPERTY_PULSE_LOGAPPEND,
- "");
- } else {
- logPropertiesHM.put(PulseConstants.APPLICATION_PROPERTY_PULSE_LOGAPPEND,
- sysLogAppend);
- }
-
- if (logPropertiesHM.size() == 0) {
- messagesToBeLogged = messagesToBeLogged
- .concat(formatLogString(resourceBundle
- .getString("LOG_MSG_LOG_PROPERTIES_NOT_FOUND_IN_SYSTEM_PROPERTIES")));
- } else {
- messagesToBeLogged = messagesToBeLogged
- .concat(formatLogString(resourceBundle
- .getString("LOG_MSG_LOG_PROPERTIES_FOUND_IN_SYSTEM_PROPERTIES")));
- }
-
- setLogConfigurations(logPropertiesHM);
- }
-
- private void setLogConfigurations(HashMap<String, String> logPropertiesHM) {
-
- PulseConfig pulseConfig = Repository.get().getPulseConfig();
-
- // log file name
- if (StringUtils.isNotNullNotEmptyNotWhiteSpace(logPropertiesHM
- .get(PulseConstants.APPLICATION_PROPERTY_PULSE_LOGFILENAME))) {
- pulseConfig.setLogFileName(logPropertiesHM
- .get(PulseConstants.APPLICATION_PROPERTY_PULSE_LOGFILENAME));
- }
-
- // log file location
- if (StringUtils.isNotNullNotEmptyNotWhiteSpace(logPropertiesHM
- .get(PulseConstants.APPLICATION_PROPERTY_PULSE_LOGFILELOCATION))) {
- pulseConfig.setLogFileLocation(logPropertiesHM
- .get(PulseConstants.APPLICATION_PROPERTY_PULSE_LOGFILELOCATION));
- }
-
- // log file size
- if (StringUtils.isNotNullNotEmptyNotWhiteSpace(logPropertiesHM
- .get(PulseConstants.APPLICATION_PROPERTY_PULSE_LOGFILESIZE))) {
- pulseConfig.setLogFileSize(Integer.parseInt(logPropertiesHM
- .get(PulseConstants.APPLICATION_PROPERTY_PULSE_LOGFILESIZE)));
- }
-
- // log file count
- if (StringUtils.isNotNullNotEmptyNotWhiteSpace(logPropertiesHM
- .get(PulseConstants.APPLICATION_PROPERTY_PULSE_LOGFILECOUNT))) {
- pulseConfig.setLogFileCount(Integer.parseInt(logPropertiesHM
- .get(PulseConstants.APPLICATION_PROPERTY_PULSE_LOGFILECOUNT)));
- }
-
- // log message date pattern
- if (StringUtils.isNotNullNotEmptyNotWhiteSpace(logPropertiesHM
- .get(PulseConstants.APPLICATION_PROPERTY_PULSE_LOGDATEPATTERN))) {
- pulseConfig.setLogDatePattern(logPropertiesHM
- .get(PulseConstants.APPLICATION_PROPERTY_PULSE_LOGDATEPATTERN));
- }
-
- // log level
- if (StringUtils.isNotNullNotEmptyNotWhiteSpace(logPropertiesHM
- .get(PulseConstants.APPLICATION_PROPERTY_PULSE_LOGLEVEL))) {
- pulseConfig.setLogLevel(Level.parse(logPropertiesHM.get(
- PulseConstants.APPLICATION_PROPERTY_PULSE_LOGLEVEL).toUpperCase()));
- }
-
- // log append
- if (StringUtils.isNotNullNotEmptyNotWhiteSpace(logPropertiesHM
- .get(PulseConstants.APPLICATION_PROPERTY_PULSE_LOGAPPEND))) {
- pulseConfig.setLogAppend(Boolean.valueOf(logPropertiesHM
- .get(PulseConstants.APPLICATION_PROPERTY_PULSE_LOGAPPEND)));
- }
-
- }
-
- // Function to load JMX User details from properties
- private void loadJMXUserDetails() {
-
- if (LOGGER.infoEnabled()) {
- LOGGER.info(resourceBundle.getString("LOG_MSG_GET_JMX_USER_DETAILS"));
- }
-
- if (pulseProperties.isEmpty()) {
- if (LOGGER.infoEnabled()) {
- LOGGER
- .info(resourceBundle
- .getString("LOG_MSG_JMX_USER_DETAILS_NOT_FOUND")
- + resourceBundle
- .getString("LOG_MSG_REASON_USER_DETAILS_NOT_FOUND"));
- }
- } else {
- jmxUserName = pulseProperties.getProperty(
- PulseConstants.APPLICATION_PROPERTY_PULSE_JMXUSERNAME, "");
- jmxUserPassword = pulseProperties.getProperty(
- PulseConstants.APPLICATION_PROPERTY_PULSE_JMXPASSWORD, "");
-
- if (jmxUserName.isEmpty() || jmxUserPassword.isEmpty()) {
- if (LOGGER.infoEnabled()) {
- LOGGER.info(resourceBundle
- .getString("LOG_MSG_JMX_USER_DETAILS_NOT_FOUND")
- + resourceBundle
- .getString("LOG_MSG_REASON_USER_DETAILS_NOT_FOUND"));
- }
- } else {
- if (LOGGER.infoEnabled()) {
- LOGGER.info(resourceBundle
- .getString("LOG_MSG_JMX_USER_DETAILS_FOUND"));
- }
- }
- }
- }
-
-//Function to set SSL VM arguments
- private void initializeSSL() {
- if (LOGGER.infoEnabled()) {
- LOGGER.info(resourceBundle.getString("LOG_MSG_GET_SSL_DETAILS"));
- }
-
-
- this.sysPulseUseSSLLocator = Boolean.valueOf(pulseProperties.getProperty(
- PulseConstants.SYSTEM_PROPERTY_PULSE_USESSL_LOCATOR, "false"));
-
- this.sysPulseUseSSLManager = Boolean.valueOf(pulseProperties.getProperty(
- PulseConstants.SYSTEM_PROPERTY_PULSE_USESSL_MANAGER, "false"));
-
-
- if ((sysPulseUseSSLLocator || sysPulseUseSSLManager)) {
- Properties sslProperties = new Properties();
- if (!pulseSecurityProperties.isEmpty()) {
- Set entrySet = pulseSecurityProperties.entrySet();
- for (Iterator it = entrySet.iterator(); it.hasNext();) {
- Entry<String, String> entry = (Entry<String, String>) it.next();
- String key = entry.getKey();
- if (key.startsWith("javax.net.ssl.")) {
-
- String val = entry.getValue();
- System.setProperty(key, val);
- sslProperties.setProperty(key, val);
- }
- }
- }
- if (sslProperties.isEmpty()) {
- if (LOGGER.warningEnabled()) {
- LOGGER.warning(resourceBundle.getString("LOG_MSG_SSL_NOT_SET"));
- }
- }
- }
-
- }
-
- // Function to load locator and/or manager details
- private void loadLocatorManagerDetails() {
-
- // Get locator details through System Properties
- if (LOGGER.infoEnabled()) {
- LOGGER.info(resourceBundle.getString("LOG_MSG_GET_LOCATOR_DETAILS_1"));
- }
-
- // Required System properties are
- // -Dpulse.embedded="false" -Dpulse.useLocator="false"
- // -Dpulse.host="192.168.2.11" -Dpulse.port="2099"
- sysPulseUseLocator = Boolean
- .getBoolean(PulseConstants.SYSTEM_PROPERTY_PULSE_USELOCATOR);
- sysPulseHost = System
- .getProperty(PulseConstants.SYSTEM_PROPERTY_PULSE_HOST);
- sysPulsePort = System
- .getProperty(PulseConstants.SYSTEM_PROPERTY_PULSE_PORT);
-
- if (sysPulseHost == null || sysPulseHost.isEmpty() || sysPulsePort == null
- || sysPulsePort.isEmpty()) {
- if (LOGGER.infoEnabled()) {
- LOGGER.info(resourceBundle
- .getString("LOG_MSG_LOCATOR_DETAILS_NOT_FOUND")
- + resourceBundle
- .getString("LOG_MSG_REASON_LOCATOR_DETAILS_NOT_FOUND_1"));
- LOGGER.info(resourceBundle.getString("LOG_MSG_GET_LOCATOR_DETAILS_2"));
- }
-
- if (pulseProperties.isEmpty()) {
- if (LOGGER.infoEnabled()) {
- LOGGER.info(resourceBundle
- .getString("LOG_MSG_LOCATOR_DETAILS_NOT_FOUND")
- + resourceBundle
- .getString("LOG_MSG_REASON_LOCATOR_DETAILS_NOT_FOUND_2"));
- }
-
- sysPulseHost = "";
- sysPulsePort = "";
- } else {
- if (LOGGER.infoEnabled()) {
- LOGGER
- .info(resourceBundle.getString("LOG_MSG_LOCATOR_DETAILS_FOUND"));
- }
-
- sysPulseUseLocator = Boolean.valueOf(pulseProperties.getProperty(
- PulseConstants.APPLICATION_PROPERTY_PULSE_USELOCATOR, ""));
- sysPulseHost = pulseProperties.getProperty(
- PulseConstants.APPLICATION_PROPERTY_PULSE_HOST, "");
- sysPulsePort = pulseProperties.getProperty(
- PulseConstants.APPLICATION_PROPERTY_PULSE_PORT, "");
- }
- } else {
- if (LOGGER.infoEnabled()) {
- LOGGER.info(resourceBundle.getString("LOG_MSG_LOCATOR_DETAILS_FOUND"));
- }
- }
- }
-
- private String formatLogString(String logMessage) {
-
- DateFormat df = new SimpleDateFormat(
- PulseConstants.LOG_MESSAGE_DATE_PATTERN);
- // DateFormat df = new
- // SimpleDateFormat(Repository.get().getPulseConfig().getLogDatePattern());
- StringWriter sw = new StringWriter();
- PrintWriter pw = new PrintWriter(sw);
-
- pw.println();
- pw.print("[");
- pw.print("INFO");
- pw.print(" ");
- pw.print(df.format(new Date(System.currentTimeMillis())));
- String threadName = Thread.currentThread().getName();
- if (threadName != null) {
- pw.print(" ");
- pw.print(threadName);
- }
- pw.print(" tid=0x");
- pw.print(Long.toHexString(Thread.currentThread().getId()));
- pw.print("] ");
- pw.print("(msgTID=");
- pw.print("");
-
- pw.print(" msgSN=");
- pw.print("");
-
- pw.print(") ");
-
- pw.println("[" + PulseConstants.APP_NAME + "]");
-
- pw.println(PulseLogWriter.class.getName());
-
- pw.println(logMessage);
-
- pw.close();
- try {
- sw.close();
- } catch (IOException ignore) {
- }
- String result = sw.toString();
- return result;
-
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/eff7f216/geode-pulse/src/main/java/com/vmware/gemfire/tools/pulse/internal/controllers/ExceptionHandlingAdvice.java
----------------------------------------------------------------------
diff --git a/geode-pulse/src/main/java/com/vmware/gemfire/tools/pulse/internal/controllers/ExceptionHandlingAdvice.java b/geode-pulse/src/main/java/com/vmware/gemfire/tools/pulse/internal/controllers/ExceptionHandlingAdvice.java
deleted file mode 100644
index 9e86637..0000000
--- a/geode-pulse/src/main/java/com/vmware/gemfire/tools/pulse/internal/controllers/ExceptionHandlingAdvice.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- *
- * 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.controllers;
-
-import java.io.IOException;
-import java.io.PrintWriter;
-import java.io.StringWriter;
-
-import org.springframework.http.HttpStatus;
-import org.springframework.web.bind.annotation.ControllerAdvice;
-import org.springframework.web.bind.annotation.ExceptionHandler;
-import org.springframework.web.bind.annotation.ResponseStatus;
-
-import com.vmware.geode.tools.pulse.internal.log.PulseLogWriter;
-
-/**
- * For handling IO exception in our controllers
- *
- *
- */
-@ControllerAdvice
-public class ExceptionHandlingAdvice {
-
- @ExceptionHandler(IOException.class)
- @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
- public void handleExc(IOException ext) {
- PulseLogWriter LOGGER = PulseLogWriter.getLogger();
- // write errors
- StringWriter swBuffer = new StringWriter();
- PrintWriter prtWriter = new PrintWriter(swBuffer);
- ext.printStackTrace(prtWriter);
- LOGGER.severe("IOException Details : " + swBuffer.toString() + "\n");
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/eff7f216/geode-pulse/src/main/java/com/vmware/gemfire/tools/pulse/internal/controllers/PulseController.java
----------------------------------------------------------------------
diff --git a/geode-pulse/src/main/java/com/vmware/gemfire/tools/pulse/internal/controllers/PulseController.java b/geode-pulse/src/main/java/com/vmware/gemfire/tools/pulse/internal/controllers/PulseController.java
deleted file mode 100644
index 32fd810..0000000
--- a/geode-pulse/src/main/java/com/vmware/gemfire/tools/pulse/internal/controllers/PulseController.java
+++ /dev/null
@@ -1,524 +0,0 @@
-/*
- *
- * 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.controllers;
-
-import java.io.IOException;
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.List;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-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.data.Cluster;
-import com.vmware.geode.tools.pulse.internal.data.PulseConstants;
-import com.vmware.geode.tools.pulse.internal.data.PulseVersion;
-import com.vmware.geode.tools.pulse.internal.data.Repository;
-import com.vmware.geode.tools.pulse.internal.log.PulseLogWriter;
-import com.vmware.geode.tools.pulse.internal.service.PulseService;
-import com.vmware.geode.tools.pulse.internal.service.PulseServiceFactory;
-import com.vmware.geode.tools.pulse.internal.service.SystemAlertsService;
-import com.vmware.geode.tools.pulse.internal.util.StringUtils;
-
-import org.apache.commons.lang.StringEscapeUtils;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Controller;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestMethod;
-
-/**
- * Class PulseController
- *
- * This class contains the implementations for all http Ajax requests needs to
- * be served in Pulse.
- *
- * @since GemFire version 7.5
- */
-@Controller
-public class PulseController {
-
- private static final PulseLogWriter LOGGER = PulseLogWriter.getLogger();
-
- // CONSTANTS
- private final String DEFAULT_EXPORT_FILENAME = "DataBrowserQueryResult.json";
- private final String QUERYSTRING_PARAM_ACTION = "action";
- private final String QUERYSTRING_PARAM_QUERYID = "queryId";
- private final String ACTION_VIEW = "view";
- private final String ACTION_DELETE = "delete";
-
- private String STATUS_REPSONSE_SUCCESS = "success";
- private String STATUS_REPSONSE_FAIL = "fail";
-
- private String ERROR_REPSONSE_QUERYNOTFOUND = "No queries found";
- private String ERROR_REPSONSE_QUERYIDMISSING = "Query id is missing";
-
- private static final String EMPTY_JSON = "{}";
-
- // Shared object to hold pulse version details
- public static PulseVersion pulseVersion = new PulseVersion();
-
- //default is gemfire
- private static String pulseProductSupport = PulseConstants.PRODUCT_NAME_GEMFIRE;
-
- private final ObjectMapper mapper = new ObjectMapper();
-
- @Autowired
- PulseServiceFactory pulseServiceFactory;
-
- @RequestMapping(value = "/pulseUpdate", method = RequestMethod.POST)
- public void getPulseUpdate(HttpServletRequest request,
- HttpServletResponse response) throws IOException {
- String pulseData = request.getParameter("pulseData");
-
- ObjectNode responseMap = mapper.createObjectNode();
-
- JsonNode requestMap = null;
-
- try {
- requestMap = mapper.readTree(pulseData);
- Iterator<?> keys = requestMap.fieldNames();
-
- // Execute Services
- while (keys.hasNext()) {
- String serviceName = keys.next().toString();
- try {
- PulseService pulseService = pulseServiceFactory
- .getPulseServiceInstance(serviceName);
- responseMap.put(serviceName, pulseService.execute(request));
- } catch (Exception serviceException) {
- LOGGER.warning("serviceException [for service "+serviceName+"] = " + serviceException.getMessage());
- responseMap.put(serviceName, EMPTY_JSON);
- }
- }
- } catch (Exception e) {
- if (LOGGER.fineEnabled()) {
- LOGGER.fine("Exception Occurred : " + e.getMessage());
- }
- }
-
- // Create Response
- response.getOutputStream().write(responseMap.toString().getBytes());
- }
-
- @RequestMapping(value = "/authenticateUser", method = RequestMethod.GET)
- public void authenticateUser(HttpServletRequest request,
- HttpServletResponse response) throws IOException {
- // json object to be sent as response
- ObjectNode responseJSON = mapper.createObjectNode();
-
- try {
- responseJSON.put("isUserLoggedIn", this.isUserLoggedIn(request));
- // Send json response
- response.getOutputStream().write(responseJSON.toString().getBytes());
- } catch (Exception e) {
- if (LOGGER.fineEnabled()) {
- LOGGER.fine("Exception Occurred : " + e.getMessage());
- }
- }
- }
-
- /**
- * Method isUserLoggedIn Check whether user is logged in or not.
- *
- * @param request
- * @return boolean
- */
- protected boolean isUserLoggedIn(HttpServletRequest request) {
- return null != request.getUserPrincipal();
- }
-
- @RequestMapping(value = "/pulseVersion", method = RequestMethod.GET)
- public void pulseVersion(HttpServletRequest request,
- HttpServletResponse response) throws IOException {
-
- // json object to be sent as response
- ObjectNode responseJSON = mapper.createObjectNode();
-
- try {
- // Reference to repository
- Repository repository = Repository.get();
- // set pulse web app url
- String pulseWebAppUrl = request.getScheme() + "://"
- + request.getServerName() + ":" + request.getServerPort()
- + request.getContextPath();
-
- repository.setPulseWebAppUrl(pulseWebAppUrl);
-
- // Response
- responseJSON.put("pulseVersion", PulseController.pulseVersion.getPulseVersion());
- responseJSON.put("buildId", PulseController.pulseVersion.getPulseBuildId());
- responseJSON.put("buildDate", PulseController.pulseVersion.getPulseBuildDate());
- responseJSON.put("sourceDate", PulseController.pulseVersion.getPulseSourceDate());
- responseJSON.put("sourceRevision", PulseController.pulseVersion.getPulseSourceRevision());
- responseJSON.put("sourceRepository", PulseController.pulseVersion.getPulseSourceRepository());
-
- } catch (Exception e) {
- if (LOGGER.fineEnabled()) {
- LOGGER.fine("Exception Occured : " + e.getMessage());
- }
- }
-
- // Send json response
- response.getOutputStream().write(responseJSON.toString().getBytes());
- }
-
- @RequestMapping(value = "/clearAlerts", method = RequestMethod.GET)
- public void clearAlerts(HttpServletRequest request, HttpServletResponse response) throws IOException {
- int alertType;
- ObjectNode responseJSON = mapper.createObjectNode();
-
- try {
- alertType = Integer.valueOf(request.getParameter("alertType"));
- } catch (NumberFormatException e) {
- // Empty json response
- response.getOutputStream().write(responseJSON.toString().getBytes());
- if (LOGGER.finerEnabled()) {
- LOGGER.finer(e.getMessage());
- }
- return;
- }
-
- try {
- boolean isClearAll = Boolean.valueOf(request.getParameter("clearAll"));
- // get cluster object
- Cluster cluster = Repository.get().getCluster();
- cluster.clearAlerts(alertType, isClearAll);
- responseJSON.put("status", "deleted");
- responseJSON.put(
- "systemAlerts", SystemAlertsService.getAlertsJson(cluster,
- cluster.getNotificationPageNumber()));
- responseJSON.put("pageNumber", cluster.getNotificationPageNumber());
-
- boolean isGFConnected = cluster.isConnectedFlag();
- if(isGFConnected){
- responseJSON.put("connectedFlag", isGFConnected);
- }else{
- responseJSON.put("connectedFlag", isGFConnected);
- responseJSON.put("connectedErrorMsg", cluster.getConnectionErrorMsg());
- }
- } catch (Exception e) {
- if (LOGGER.fineEnabled()) {
- LOGGER.fine("Exception Occurred : " + e.getMessage());
- }
- }
-
- // Send json response
- response.getOutputStream().write(responseJSON.toString().getBytes());
- }
-
- @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());
- if (LOGGER.finerEnabled()) {
- LOGGER.finer(e.getMessage());
- }
- return;
- }
-
- try {
- // get cluster object
- Cluster cluster = Repository.get().getCluster();
-
- // set alert is acknowledged
- cluster.acknowledgeAlert(alertId);
- responseJSON.put("status", "deleted");
- } catch (Exception e) {
- if (LOGGER.fineEnabled()) {
- LOGGER.fine("Exception Occured : " + e.getMessage());
- }
- }
-
- // Send json response
- response.getOutputStream().write(responseJSON.toString().getBytes());
- }
-
- @RequestMapping(value = "/dataBrowserRegions", method = RequestMethod.GET)
- public void dataBrowserRegions(HttpServletRequest request,
- HttpServletResponse response) throws IOException {
- // get cluster object
- Cluster cluster = Repository.get().getCluster();
-
- // json object to be sent as response
- ObjectNode responseJSON = mapper.createObjectNode();
- ArrayNode regionsData = mapper.createArrayNode();
-
- try {
- // getting cluster's Regions
- responseJSON.put("clusterName", cluster.getServerName());
- regionsData = getRegionsJson(cluster);
- responseJSON.put("clusterRegions", regionsData);
- responseJSON.put("connectedFlag", cluster.isConnectedFlag());
- responseJSON.put("connectedErrorMsg", cluster.getConnectionErrorMsg());
- } catch (Exception e) {
- if (LOGGER.fineEnabled()) {
- LOGGER.fine("Exception Occured : " + e.getMessage());
- }
- }
-
- // Send json response
- response.getOutputStream().write(responseJSON.toString().getBytes());
- }
-
- /**
- * This method creates json for list of cluster regions
- *
- * @param cluster
- * @return ArrayNode JSON array
- */
- private ArrayNode getRegionsJson(Cluster cluster) {
-
- Collection<Cluster.Region> clusterRegions = cluster.getClusterRegions().values();
- ArrayNode regionsListJson = mapper.createArrayNode();
-
- if (!clusterRegions.isEmpty()) {
- for (Cluster.Region region : clusterRegions) {
- ObjectNode regionJSON = mapper.createObjectNode();
- regionJSON.put("name", region.getName());
- regionJSON.put("fullPath", region.getFullPath());
- regionJSON.put("regionType", region.getRegionType());
-
- if (region.getRegionType().contains("PARTITION")) {
- regionJSON.put("isPartition", true);
- } else {
- regionJSON.put("isPartition", false);
- }
-
- regionJSON.put("memberCount", region.getMemberCount());
- List<String> regionsMembers = region.getMemberName();
- ArrayNode jsonRegionMembers = mapper.createArrayNode();
-
- for (int i = 0; i < regionsMembers.size(); i++) {
- Cluster.Member member = cluster.getMembersHMap().get(
- regionsMembers.get(i));
- ObjectNode jsonMember = mapper.createObjectNode();
- jsonMember.put("key", regionsMembers.get(i));
- jsonMember.put("id", member.getId());
- jsonMember.put("name", member.getName());
-
- jsonRegionMembers.add(jsonMember);
- }
-
- regionJSON.put("members", jsonRegionMembers);
- regionsListJson.add(regionJSON);
- }
- }
- return regionsListJson;
- }
-
- @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;
- if (LOGGER.finerEnabled()) {
- LOGGER.finer(e.getMessage());
- }
- }
-
- ObjectNode queryResult = mapper.createObjectNode();
- try {
-
- if (StringUtils.isNotNullNotEmptyNotWhiteSpace(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) {
- if (LOGGER.fineEnabled()) {
- LOGGER.fine("Exception Occured : " + e.getMessage());
- }
- }
-
- response.getOutputStream().write(queryResult.toString().getBytes());
- }
-
- @RequestMapping(value = "/dataBrowserQueryHistory", method = RequestMethod.GET)
- public void dataBrowserQueryHistory(HttpServletRequest request,
- HttpServletResponse response) throws IOException {
- ObjectNode responseJSON = mapper.createObjectNode();
- ArrayNode queryResult = null;
- String action = "";
-
- try {
- // get cluster object
- Cluster cluster = Repository.get().getCluster();
- String userName = request.getUserPrincipal().getName();
-
- // get query string
- action = request.getParameter(QUERYSTRING_PARAM_ACTION);
- if (!StringUtils.isNotNullNotEmptyNotWhiteSpace(action)) {
- action = ACTION_VIEW;
- }
-
- if (action.toLowerCase().equalsIgnoreCase(ACTION_DELETE)) {
- String queryId = request.getParameter(QUERYSTRING_PARAM_QUERYID);
- if (StringUtils.isNotNullNotEmptyNotWhiteSpace(queryId)) {
-
- boolean deleteStatus = cluster.deleteQueryById(userName, queryId);
- if (deleteStatus) {
- responseJSON.put("status", STATUS_REPSONSE_SUCCESS);
- } else {
- responseJSON.put("status", STATUS_REPSONSE_FAIL);
- responseJSON.put("error", ERROR_REPSONSE_QUERYNOTFOUND);
- }
- } else {
- responseJSON.put("status", STATUS_REPSONSE_FAIL);
- responseJSON.put("error", ERROR_REPSONSE_QUERYIDMISSING);
- }
- }
-
- // Get list of past executed queries
- queryResult = cluster.getQueryHistoryByUserId(userName);
- responseJSON.put("queryHistory", queryResult);
- } catch (Exception e) {
- if (LOGGER.fineEnabled()) {
- LOGGER.fine("Exception Occured : " + e.getMessage());
- }
- }
- response.getOutputStream().write(responseJSON.toString().getBytes());
- }
-
- @RequestMapping(value = "/dataBrowserExport", method = RequestMethod.POST)
- public void dataBrowserExport(HttpServletRequest request,
- HttpServletResponse response) throws IOException {
-
- // get query string
- String filename = request.getParameter("filename");
- String resultContent = request.getParameter("content");
-
- response.setHeader("Cache-Control", "");
- response.setHeader("Content-type", "text/plain");
- if (StringUtils.isNotNullNotEmptyNotWhiteSpace(filename)) {
- response.setHeader("Content-Disposition", "attachment; filename=" + filename);
- } else {
- response.setHeader("Content-Disposition", "attachment; filename=" + DEFAULT_EXPORT_FILENAME);
- }
-
- if (!StringUtils.isNotNullNotEmptyNotWhiteSpace(resultContent)) {
- resultContent = "";
- }
-
- response.getOutputStream().write(resultContent.getBytes());
- }
-
- @RequestMapping(value = "/pulseProductSupport", method = RequestMethod.GET)
- public void getConfiguredPulseProduct(HttpServletRequest request,
- HttpServletResponse response) throws IOException {
- ObjectNode responseJSON = mapper.createObjectNode();
-
- try {
- responseJSON.put("product", pulseProductSupport);
-
- // Send json response
- response.getOutputStream().write(responseJSON.toString().getBytes());
- } catch (Exception e) {
- if (LOGGER.fineEnabled()) {
- LOGGER.fine("Exception Occurred : " + e.getMessage());
- }
- }
- }
-
- @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) {
- if (LOGGER.fineEnabled()) {
- LOGGER.fine("Exception Occured : " + e.getMessage());
- }
- }
- }
-
- /**
- * @return the pulseProductSupport
- */
- public static String getPulseProductSupport() {
- return pulseProductSupport;
- }
-
- /**
- * @param pulseProductSupport
- * the pulseProductSupport to set
- */
- public static void setPulseProductSupport(String pulseProductSupport) {
- PulseController.pulseProductSupport = pulseProductSupport;
- }
-}
\ No newline at end of file