Skip to content

Commit

Permalink
GEODE-7869: Cleanup warnings in geode-pulse
Browse files Browse the repository at this point in the history
  • Loading branch information
jake-at-work committed Mar 16, 2020
1 parent feab561 commit d7a2bae
Show file tree
Hide file tree
Showing 35 changed files with 854 additions and 1,036 deletions.
6 changes: 6 additions & 0 deletions boms/geode-all-bom/src/test/resources/expected-pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,12 @@
<version>3.9</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-text</artifactId>
<version>1.8</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.derby</groupId>
<artifactId>derby</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ class DependencyConstraints implements Plugin<Project> {
api(group: 'net.spy', name: 'spymemcached', version: '2.12.3')
api(group: 'org.apache.bcel', name: 'bcel', version: '6.2')
api(group: 'org.apache.commons', name: 'commons-lang3', version: get('commons-lang3.version'))
api(group: 'org.apache.commons', name: 'commons-text', version: 1.8)
api(group: 'org.apache.derby', name: 'derby', version: '10.14.2.0')
api(group: 'org.apache.httpcomponents', name: 'httpclient', version: '4.5.10')
api(group: 'org.apache.httpcomponents', name: 'httpcore', version: '4.4.12')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ commons-lang
commons-logging
commons-math
commons-modeler
commons-text
commons-validator
error_prone_annotations
failureaccess
Expand Down
2 changes: 2 additions & 0 deletions geode-pulse/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ apply from: "${rootDir}/${scriptDir}/standard-subproject-configuration.gradle"
apply plugin: 'war'

apply from: "${project.projectDir}/../gradle/publish-war.gradle"
apply from: "${project.projectDir}/../gradle/warnings.gradle"

jar.enabled = true

Expand Down Expand Up @@ -55,6 +56,7 @@ dependencies {
implementation('commons-collections:commons-collections')
implementation('commons-digester:commons-digester')
implementation('org.apache.commons:commons-lang3')
implementation('org.apache.commons:commons-text')
implementation('org.springframework.ldap:spring-ldap-core')

implementation('org.springframework.security:spring-security-config') {
Expand Down
1 change: 1 addition & 0 deletions geode-pulse/geode-pulse-test/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/

apply from: "${rootDir}/${scriptDir}/standard-subproject-configuration.gradle"
apply from: "${rootDir}/${scriptDir}/warnings.gradle"

dependencies {
compile(platform(project(':boms:geode-all-bom')))
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import org.apache.commons.lang3.StringEscapeUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.text.StringEscapeUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -39,7 +39,6 @@
import org.springframework.web.bind.annotation.RequestMethod;

import org.apache.geode.tools.pulse.internal.data.Cluster;
import org.apache.geode.tools.pulse.internal.data.PulseConstants;
import org.apache.geode.tools.pulse.internal.data.PulseVersion;
import org.apache.geode.tools.pulse.internal.data.Repository;
import org.apache.geode.tools.pulse.internal.service.PulseService;
Expand All @@ -58,27 +57,22 @@ public class PulseController {

private static final Logger logger = LogManager.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 static final String QUERYSTRING_PARAM_ACTION = "action";
private static final String QUERYSTRING_PARAM_QUERYID = "queryId";
private static final String ACTION_VIEW = "view";
private static final String ACTION_DELETE = "delete";

private String STATUS_REPSONSE_SUCCESS = "success";
private String STATUS_REPSONSE_FAIL = "fail";
private static final String STATUS_REPSONSE_SUCCESS = "success";
private static final 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 ERROR_REPSONSE_QUERYNOTFOUND = "No queries found";
private static final 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
Expand All @@ -91,19 +85,16 @@ public void getPulseUpdate(HttpServletRequest request, HttpServletResponse respo

ObjectNode responseMap = mapper.createObjectNode();

JsonNode requestMap = null;


try {
requestMap = mapper.readTree(pulseData);
JsonNode 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));
responseMap.set(serviceName, pulseService.execute(request));
} catch (Exception serviceException) {
logger.warn("serviceException [for service {}] = {}", serviceName,
serviceException.getMessage());
Expand All @@ -119,13 +110,12 @@ public void getPulseUpdate(HttpServletRequest request, HttpServletResponse respo
}

@RequestMapping(value = "/authenticateUser", method = RequestMethod.GET)
public void authenticateUser(HttpServletRequest request, HttpServletResponse response)
throws IOException {
public void authenticateUser(HttpServletRequest request, HttpServletResponse response) {
// json object to be sent as response
ObjectNode responseJSON = mapper.createObjectNode();

try {
responseJSON.put("isUserLoggedIn", this.isUserLoggedIn(request));
responseJSON.put("isUserLoggedIn", isUserLoggedIn(request));
// Send json response
response.getOutputStream().write(responseJSON.toString().getBytes());
} catch (Exception e) {
Expand All @@ -142,7 +132,8 @@ protected boolean isUserLoggedIn(HttpServletRequest request) {
}

@RequestMapping(value = "/pulseVersion", method = RequestMethod.GET)
public void pulseVersion(HttpServletRequest request, HttpServletResponse response)
public void pulseVersion(@SuppressWarnings("unused") HttpServletRequest request,
HttpServletResponse response)
throws IOException {

// json object to be sent as response
Expand Down Expand Up @@ -172,7 +163,7 @@ public void clearAlerts(HttpServletRequest request, HttpServletResponse response
ObjectNode responseJSON = mapper.createObjectNode();

try {
alertType = Integer.valueOf(request.getParameter("alertType"));
alertType = Integer.parseInt(request.getParameter("alertType"));
} catch (NumberFormatException e) {
// Empty json response
response.getOutputStream().write(responseJSON.toString().getBytes());
Expand All @@ -181,12 +172,12 @@ public void clearAlerts(HttpServletRequest request, HttpServletResponse response
}

try {
boolean isClearAll = Boolean.valueOf(request.getParameter("clearAll"));
boolean isClearAll = Boolean.parseBoolean(request.getParameter("clearAll"));
// get cluster object
Cluster cluster = Repository.get().getCluster();
cluster.clearAlerts(alertType, isClearAll);
responseJSON.put("status", "deleted");
responseJSON.put("systemAlerts",
responseJSON.set("systemAlerts",
SystemAlertsService.getAlertsJson(cluster, cluster.getNotificationPageNumber()));
responseJSON.put("pageNumber", cluster.getNotificationPageNumber());

Expand All @@ -212,7 +203,7 @@ public void acknowledgeAlert(HttpServletRequest request, HttpServletResponse res
ObjectNode responseJSON = mapper.createObjectNode();

try {
alertId = Integer.valueOf(request.getParameter("alertId"));
alertId = Integer.parseInt(request.getParameter("alertId"));
} catch (NumberFormatException e) {
// Empty json response
response.getOutputStream().write(responseJSON.toString().getBytes());
Expand All @@ -228,32 +219,32 @@ public void acknowledgeAlert(HttpServletRequest request, HttpServletResponse res
cluster.acknowledgeAlert(alertId);
responseJSON.put("status", "deleted");
} catch (Exception e) {
logger.debug("Exception Occurred : {}", e);
logger.debug("Exception Occurred", e);
}

// Send json response
response.getOutputStream().write(responseJSON.toString().getBytes());
}

@RequestMapping(value = "/dataBrowserRegions", method = RequestMethod.GET)
public void dataBrowserRegions(HttpServletRequest request, HttpServletResponse response)
public void dataBrowserRegions(@SuppressWarnings("unused") 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);
ArrayNode regionsData = getRegionsJson(cluster);
responseJSON.set("clusterRegions", regionsData);
responseJSON.put("connectedFlag", cluster.isConnectedFlag());
responseJSON.put("connectedErrorMsg", cluster.getConnectionErrorMsg());
} catch (Exception e) {
logger.debug("Exception Occurred : {}", e);
logger.debug("Exception Occurred", e);
}

// Send json response
Expand Down Expand Up @@ -287,17 +278,17 @@ private ArrayNode getRegionsJson(Cluster cluster) {
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));
for (String regionsMember : regionsMembers) {
Cluster.Member member = cluster.getMembersHMap().get(regionsMember);
ObjectNode jsonMember = mapper.createObjectNode();
jsonMember.put("key", regionsMembers.get(i));
jsonMember.put("key", regionsMember);
jsonMember.put("id", member.getId());
jsonMember.put("name", member.getName());

jsonRegionMembers.add(jsonMember);
}

regionJSON.put("members", jsonRegionMembers);
regionJSON.set("members", jsonRegionMembers);
regionsListJson.add(regionJSON);
}
}
Expand All @@ -310,10 +301,10 @@ public void dataBrowserQuery(HttpServletRequest request, HttpServletResponse res
// get query string
String query = request.getParameter("query");
String members = request.getParameter("members");
int limit = 0;
int limit;

try {
limit = Integer.valueOf(request.getParameter("limit"));
limit = Integer.parseInt(request.getParameter("limit"));
} catch (NumberFormatException e) {
limit = 0;
logger.debug(e);
Expand All @@ -328,16 +319,14 @@ public void dataBrowserQuery(HttpServletRequest request, HttpServletResponse res
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);
String action = request.getParameter(QUERYSTRING_PARAM_ACTION);
if (StringUtils.isBlank(action)) {
action = ACTION_VIEW;
}
Expand All @@ -360,8 +349,8 @@ public void dataBrowserQueryHistory(HttpServletRequest request, HttpServletRespo
}

// Get list of past executed queries
queryResult = cluster.getQueryHistoryByUserId(userName);
responseJSON.put("queryHistory", queryResult);
ArrayNode queryResult = cluster.getQueryHistoryByUserId(userName);
responseJSON.set("queryHistory", queryResult);
} catch (Exception e) {
logger.debug("Exception Occurred : ", e);
}
Expand All @@ -377,10 +366,10 @@ public void dataBrowserExport(HttpServletRequest request, HttpServletResponse re
// get query string
String query = request.getParameter("query");
String members = request.getParameter("members");
int limit = 0;
int limit;

try {
limit = Integer.valueOf(request.getParameter("limit"));
limit = Integer.parseInt(request.getParameter("limit"));
} catch (NumberFormatException e) {
limit = 0;
logger.debug(e);
Expand All @@ -394,8 +383,8 @@ public void dataBrowserExport(HttpServletRequest request, HttpServletResponse re
}

@RequestMapping(value = "/getQueryStatisticsGridModel", method = RequestMethod.GET)
public void getQueryStatisticsGridModel(HttpServletRequest request, HttpServletResponse response)
throws IOException {
public void getQueryStatisticsGridModel(HttpServletRequest request,
HttpServletResponse response) {

ObjectNode responseJSON = mapper.createObjectNode();
// get cluster object
Expand All @@ -408,8 +397,8 @@ public void getQueryStatisticsGridModel(HttpServletRequest request, HttpServletR
int[] arrColWidths = Cluster.Statement.getGridColumnWidths();

ArrayNode colNamesList = mapper.createArrayNode();
for (int i = 0; i < arrColNames.length; ++i) {
colNamesList.add(arrColNames[i]);
for (String arrColName : arrColNames) {
colNamesList.add(arrColName);
}

ArrayNode colModelList = mapper.createArrayNode();
Expand All @@ -423,8 +412,8 @@ public void getQueryStatisticsGridModel(HttpServletRequest request, HttpServletR
colModelList.add(columnJSON);
}

responseJSON.put("columnNames", colNamesList);
responseJSON.put("columnModels", colModelList);
responseJSON.set("columnNames", colNamesList);
responseJSON.set("columnModels", colModelList);
responseJSON.put("clusterName", cluster.getServerName());
responseJSON.put("userName", userName);

Expand Down
Loading

0 comments on commit d7a2bae

Please sign in to comment.