You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by kl...@apache.org on 2017/08/25 22:52:40 UTC
[1/2] geode git commit: GEODE-3506: improve validation/error checking
for process file control
Repository: geode
Updated Branches:
refs/heads/develop cb011c5c9 -> 0af313241
GEODE-3506: improve validation/error checking for process file control
This closes #738
Project: http://git-wip-us.apache.org/repos/asf/geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/geode/commit/a2ab230d
Tree: http://git-wip-us.apache.org/repos/asf/geode/tree/a2ab230d
Diff: http://git-wip-us.apache.org/repos/asf/geode/diff/a2ab230d
Branch: refs/heads/develop
Commit: a2ab230d685b8ac897a7e155474f797608f711fa
Parents: cb011c5
Author: Kirk Lund <kl...@apache.org>
Authored: Wed Aug 23 14:20:18 2017 -0700
Committer: Kirk Lund <kl...@apache.org>
Committed: Fri Aug 25 14:50:06 2017 -0700
----------------------------------------------------------------------
.../internal/process/ControllableProcess.java | 93 +++++++++++++-------
.../internal/process/FileProcessController.java | 2 +-
2 files changed, 61 insertions(+), 34 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/geode/blob/a2ab230d/geode-core/src/main/java/org/apache/geode/internal/process/ControllableProcess.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/internal/process/ControllableProcess.java b/geode-core/src/main/java/org/apache/geode/internal/process/ControllableProcess.java
index 2fdd116..e44b34f 100755
--- a/geode-core/src/main/java/org/apache/geode/internal/process/ControllableProcess.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/process/ControllableProcess.java
@@ -19,6 +19,7 @@ import static org.apache.commons.lang.Validate.notNull;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
+import java.io.UncheckedIOException;
import org.apache.logging.log4j.Logger;
@@ -137,15 +138,14 @@ public class ControllableProcess {
}
private void deleteFiles(final File directory, final ProcessType processType) {
- deleteFile(directory, processType.getStatusRequestFileName());
- deleteFile(directory, processType.getStatusFileName());
- deleteFile(directory, processType.getStopRequestFileName());
- }
-
- private void deleteFile(final File directory, final String fileName) {
- File file = new File(directory, fileName);
- if (file.exists()) {
- file.delete();
+ try {
+ deleteFileWithValidation(new File(directory, processType.getStatusRequestFileName()),
+ "statusRequestFile");
+ deleteFileWithValidation(new File(directory, processType.getStatusFileName()), "statusFile");
+ deleteFileWithValidation(new File(directory, processType.getStopRequestFileName()),
+ "stopRequestFile");
+ } catch (IOException e) {
+ throw new UncheckedIOException(e);
}
}
@@ -165,30 +165,7 @@ public class ControllableProcess {
private static ControlRequestHandler createStatusHandler(final ControlNotificationHandler handler,
final File directory, final ProcessType processType) {
return () -> {
- ServiceState<?> state = handler.handleStatus();
-
- File statusFile = new File(directory, processType.getStatusFileName());
- if (statusFile.exists()) {
- boolean deleted = statusFile.delete();
- assert deleted;
- }
-
- File statusFileTmp = new File(directory, processType.getStatusFileName() + ".tmp");
- if (statusFileTmp.exists()) {
- boolean deleted = statusFileTmp.delete();
- assert deleted;
- }
-
- boolean created = statusFileTmp.createNewFile();
- assert created;
-
- FileWriter writer = new FileWriter(statusFileTmp);
- writer.write(state.toJson());
- writer.flush();
- writer.close();
-
- boolean renamed = statusFileTmp.renameTo(statusFile);
- assert renamed;
+ writeStatusToFile(fetchStatusWithValidation(handler), directory, processType);
};
}
@@ -203,4 +180,54 @@ public class ControllableProcess {
return new ControlFileWatchdog(directory, processType.getStatusRequestFileName(), statusHandler,
false);
}
+
+ private static String fetchStatusWithValidation(final ControlNotificationHandler handler) {
+ ServiceState<?> state = handler.handleStatus();
+ if (state == null) {
+ throw new IllegalStateException("Null ServiceState is invalid");
+ }
+
+ String jsonContent = state.toJson();
+ if (jsonContent == null) {
+ throw new IllegalStateException("Null JSON for status is invalid");
+ } else if (jsonContent.isEmpty()) {
+ throw new IllegalStateException("Empty JSON for status is invalid");
+ }
+
+ return jsonContent;
+ }
+
+ private static void deleteFileWithValidation(final File file, final String fileNameForMessage)
+ throws IOException {
+ if (file.exists()) {
+ if (!file.delete()) {
+ throw new IOException(
+ "Unable to delete " + fileNameForMessage + "'" + file.getCanonicalPath() + "'");
+ }
+ }
+ }
+
+ private static void writeStatusToFile(final String jsonContent, final File directory,
+ final ProcessType processType) throws IOException {
+ File statusFile = new File(directory, processType.getStatusFileName());
+ File statusFileTmp = new File(directory, processType.getStatusFileName() + ".tmp");
+
+ deleteFileWithValidation(statusFile, "statusFile");
+ deleteFileWithValidation(statusFileTmp, "statusFileTmp");
+
+ if (!statusFileTmp.createNewFile()) {
+ throw new IOException(
+ "Unable to create statusFileTmp '" + statusFileTmp.getCanonicalPath() + "'");
+ }
+
+ FileWriter writer = new FileWriter(statusFileTmp);
+ writer.write(jsonContent);
+ writer.flush();
+ writer.close();
+
+ if (!statusFileTmp.renameTo(statusFile)) {
+ throw new IOException("Unable to rename statusFileTmp '" + statusFileTmp.getCanonicalPath()
+ + "' to '" + statusFile.getCanonicalPath() + "'");
+ }
+ }
}
http://git-wip-us.apache.org/repos/asf/geode/blob/a2ab230d/geode-core/src/main/java/org/apache/geode/internal/process/FileProcessController.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/internal/process/FileProcessController.java b/geode-core/src/main/java/org/apache/geode/internal/process/FileProcessController.java
index 062cfb6..fcb61d1 100755
--- a/geode-core/src/main/java/org/apache/geode/internal/process/FileProcessController.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/process/FileProcessController.java
@@ -149,7 +149,7 @@ class FileProcessController implements ProcessController {
String lines = statusRef.get();
if (isBlank(lines)) {
- throw new IllegalStateException("Failed to read status file");
+ throw new IllegalStateException("Status file '" + statusFile + "' is blank");
}
return lines;
}
[2/2] geode git commit: GEODE-2842: Removed redundant default
annotation parameter values.
Posted by kl...@apache.org.
GEODE-2842: Removed redundant default annotation parameter values.
This closes #731
Project: http://git-wip-us.apache.org/repos/asf/geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/geode/commit/0af31324
Tree: http://git-wip-us.apache.org/repos/asf/geode/tree/0af31324
Diff: http://git-wip-us.apache.org/repos/asf/geode/diff/0af31324
Branch: refs/heads/develop
Commit: 0af313241b9e6125443468752bd18d2104acc627
Parents: a2ab230
Author: Patrick Rhomberg <pr...@pivotal.io>
Authored: Tue Aug 22 14:20:12 2017 -0700
Committer: Kirk Lund <kl...@apache.org>
Committed: Fri Aug 25 14:50:40 2017 -0700
----------------------------------------------------------------------
.../cli/commands/ExportLogsCommand.java | 37 +++++++--------
.../internal/cli/commands/MemberCommands.java | 24 +++++-----
.../internal/cli/commands/ShellCommands.java | 4 +-
.../MiscellaneousCommandsController.java | 13 +++---
.../management/internal/web/domain/Link.java | 13 +++---
.../internal/cli/CommandManagerJUnitTest.java | 23 +++++----
.../web/controllers/CommonCrudController.java | 14 +++---
.../controllers/FunctionAccessController.java | 32 +++++++------
.../web/controllers/PdxBasedCrudController.java | 38 ++++++++-------
.../web/controllers/QueryAccessController.java | 49 ++++++++++++--------
10 files changed, 127 insertions(+), 120 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/geode/blob/0af31324/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ExportLogsCommand.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ExportLogsCommand.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ExportLogsCommand.java
index 2075776..70e1e60 100644
--- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ExportLogsCommand.java
+++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ExportLogsCommand.java
@@ -14,8 +14,22 @@
*/
package org.apache.geode.management.internal.cli.commands;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.StringUtils;
+import org.apache.logging.log4j.Logger;
+import org.springframework.shell.core.annotation.CliCommand;
+import org.springframework.shell.core.annotation.CliOption;
+
import org.apache.geode.cache.Region;
import org.apache.geode.cache.execute.ResultCollector;
import org.apache.geode.distributed.DistributedMember;
@@ -34,19 +48,6 @@ import org.apache.geode.management.internal.cli.util.ExportLogsCacheWriter;
import org.apache.geode.management.internal.configuration.utils.ZipUtils;
import org.apache.geode.management.internal.security.ResourceOperation;
import org.apache.geode.security.ResourcePermission;
-import org.apache.logging.log4j.Logger;
-import org.springframework.shell.core.annotation.CliCommand;
-import org.springframework.shell.core.annotation.CliOption;
-
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.nio.file.Paths;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
public class ExportLogsCommand implements GfshCommand {
@@ -60,20 +61,18 @@ public class ExportLogsCommand implements GfshCommand {
private static final Pattern DISK_SPACE_LIMIT_PATTERN = Pattern.compile("(\\d+)([kmgtKMGT]?)");
@CliCommand(value = CliStrings.EXPORT_LOGS, help = CliStrings.EXPORT_LOGS__HELP)
- @CliMetaData(shellOnly = false, isFileDownloadOverHttp = true,
+ @CliMetaData(isFileDownloadOverHttp = true,
interceptor = "org.apache.geode.management.internal.cli.commands.ExportLogsInterceptor",
relatedTopic = {CliStrings.TOPIC_GEODE_SERVER, CliStrings.TOPIC_GEODE_DEBUG_UTIL})
@ResourceOperation(resource = ResourcePermission.Resource.CLUSTER,
operation = ResourcePermission.Operation.READ)
public Result exportLogs(
- @CliOption(key = CliStrings.EXPORT_LOGS__DIR, help = CliStrings.EXPORT_LOGS__DIR__HELP,
- mandatory = false) String dirName,
+ @CliOption(key = CliStrings.EXPORT_LOGS__DIR,
+ help = CliStrings.EXPORT_LOGS__DIR__HELP) String dirName,
@CliOption(key = {CliStrings.GROUP, CliStrings.GROUPS},
- unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE,
optionContext = ConverterHint.MEMBERGROUP,
help = CliStrings.EXPORT_LOGS__GROUP__HELP) String[] groups,
@CliOption(key = {CliStrings.MEMBER, CliStrings.MEMBERS},
- unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE,
optionContext = ConverterHint.ALL_MEMBER_IDNAME,
help = CliStrings.EXPORT_LOGS__MEMBER__HELP) String[] memberIds,
@CliOption(key = CliStrings.EXPORT_LOGS__LOGLEVEL,
@@ -85,10 +84,8 @@ public class ExportLogsCommand implements GfshCommand {
@CliOption(key = CliStrings.EXPORT_LOGS__MERGELOG, unspecifiedDefaultValue = "false",
help = CliStrings.EXPORT_LOGS__MERGELOG__HELP) boolean mergeLog,
@CliOption(key = CliStrings.EXPORT_LOGS__STARTTIME,
- unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE,
help = CliStrings.EXPORT_LOGS__STARTTIME__HELP) String start,
@CliOption(key = CliStrings.EXPORT_LOGS__ENDTIME,
- unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE,
help = CliStrings.EXPORT_LOGS__ENDTIME__HELP) String end,
@CliOption(key = CliStrings.EXPORT_LOGS__LOGSONLY, unspecifiedDefaultValue = "false",
specifiedDefaultValue = "true",
http://git-wip-us.apache.org/repos/asf/geode/blob/0af31324/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/MemberCommands.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/MemberCommands.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/MemberCommands.java
index 12820f2..45642f6 100644
--- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/MemberCommands.java
+++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/MemberCommands.java
@@ -14,8 +14,16 @@
*/
package org.apache.geode.management.internal.cli.commands;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+import java.util.TreeSet;
+
+import org.springframework.shell.core.annotation.CliCommand;
+import org.springframework.shell.core.annotation.CliOption;
+
import org.apache.geode.cache.CacheClosedException;
-import org.apache.geode.cache.CacheFactory;
import org.apache.geode.cache.execute.FunctionInvocationTargetException;
import org.apache.geode.cache.execute.ResultCollector;
import org.apache.geode.distributed.DistributedMember;
@@ -33,19 +41,9 @@ import org.apache.geode.management.internal.cli.result.CompositeResultData;
import org.apache.geode.management.internal.cli.result.CompositeResultData.SectionResultData;
import org.apache.geode.management.internal.cli.result.ResultBuilder;
import org.apache.geode.management.internal.cli.result.TabularResultData;
-import org.apache.geode.management.internal.cli.shell.Gfsh;
import org.apache.geode.management.internal.security.ResourceOperation;
import org.apache.geode.security.ResourcePermission.Operation;
import org.apache.geode.security.ResourcePermission.Resource;
-import org.springframework.shell.core.CommandMarker;
-import org.springframework.shell.core.annotation.CliCommand;
-import org.springframework.shell.core.annotation.CliOption;
-
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Set;
-import java.util.TreeSet;
/**
* @since GemFire 7.0
@@ -56,7 +54,7 @@ public class MemberCommands implements GfshCommand {
new GetMemberInformationFunction();
@CliCommand(value = {CliStrings.LIST_MEMBER}, help = CliStrings.LIST_MEMBER__HELP)
- @CliMetaData(shellOnly = false, relatedTopic = CliStrings.TOPIC_GEODE_SERVER)
+ @CliMetaData(relatedTopic = CliStrings.TOPIC_GEODE_SERVER)
@ResourceOperation(resource = Resource.CLUSTER, operation = Operation.READ)
public Result listMember(@CliOption(key = {CliStrings.GROUP}, unspecifiedDefaultValue = "",
optionContext = ConverterHint.MEMBERGROUP,
@@ -99,7 +97,7 @@ public class MemberCommands implements GfshCommand {
}
@CliCommand(value = {CliStrings.DESCRIBE_MEMBER}, help = CliStrings.DESCRIBE_MEMBER__HELP)
- @CliMetaData(shellOnly = false, relatedTopic = CliStrings.TOPIC_GEODE_SERVER)
+ @CliMetaData(relatedTopic = CliStrings.TOPIC_GEODE_SERVER)
@ResourceOperation(resource = Resource.CLUSTER, operation = Operation.READ)
public Result describeMember(@CliOption(key = CliStrings.DESCRIBE_MEMBER__IDENTIFIER,
optionContext = ConverterHint.ALL_MEMBER_IDNAME, help = CliStrings.DESCRIBE_MEMBER__HELP,
http://git-wip-us.apache.org/repos/asf/geode/blob/0af31324/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ShellCommands.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ShellCommands.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ShellCommands.java
index 84ee5db..d2f9371 100644
--- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ShellCommands.java
+++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/ShellCommands.java
@@ -236,8 +236,7 @@ public class ShellCommands implements GfshCommand {
@CliCommand(value = {CliStrings.ECHO}, help = CliStrings.ECHO__HELP)
@CliMetaData(shellOnly = true, relatedTopic = {CliStrings.TOPIC_GFSH})
- public Result echo(@CliOption(key = {CliStrings.ECHO__STR, ""},
- unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, specifiedDefaultValue = "",
+ public Result echo(@CliOption(key = {CliStrings.ECHO__STR, ""}, specifiedDefaultValue = "",
mandatory = true, help = CliStrings.ECHO__STR__HELP) String stringToEcho) {
Result result = null;
@@ -319,7 +318,6 @@ public class ShellCommands implements GfshCommand {
@CliMetaData(shellOnly = true, relatedTopic = {CliStrings.TOPIC_GFSH})
public Result history(
@CliOption(key = {CliStrings.HISTORY__FILE},
- unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE,
help = CliStrings.HISTORY__FILE__HELP) String saveHistoryTo,
@CliOption(key = {CliStrings.HISTORY__CLEAR}, specifiedDefaultValue = "true",
unspecifiedDefaultValue = "false",
http://git-wip-us.apache.org/repos/asf/geode/blob/0af31324/geode-core/src/main/java/org/apache/geode/management/internal/web/controllers/MiscellaneousCommandsController.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/web/controllers/MiscellaneousCommandsController.java b/geode-core/src/main/java/org/apache/geode/management/internal/web/controllers/MiscellaneousCommandsController.java
index fd28fed..79952b9 100644
--- a/geode-core/src/main/java/org/apache/geode/management/internal/web/controllers/MiscellaneousCommandsController.java
+++ b/geode-core/src/main/java/org/apache/geode/management/internal/web/controllers/MiscellaneousCommandsController.java
@@ -14,9 +14,6 @@
*/
package org.apache.geode.management.internal.web.controllers;
-import org.apache.geode.internal.lang.StringUtils;
-import org.apache.geode.management.internal.cli.i18n.CliStrings;
-import org.apache.geode.management.internal.cli.util.CommandStringBuilder;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
@@ -24,6 +21,10 @@ import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
+import org.apache.geode.internal.lang.StringUtils;
+import org.apache.geode.management.internal.cli.i18n.CliStrings;
+import org.apache.geode.management.internal.cli.util.CommandStringBuilder;
+
/**
* The MiscellaneousCommandsController class implements GemFire Management REST API web service
* endpoints for the Gfsh Miscellaneous Commands.
@@ -200,16 +201,14 @@ public class MiscellaneousCommandsController extends AbstractCommandsController
@RequestMapping(method = RequestMethod.POST, value = "/groups/{groups}/loglevel")
@ResponseBody
public String changeLogLevelForGroups(@PathVariable("groups") final String groups,
- @RequestParam(value = CliStrings.CHANGE_LOGLEVEL__LOGLEVEL,
- required = true) final String logLevel) {
+ @RequestParam(value = CliStrings.CHANGE_LOGLEVEL__LOGLEVEL) final String logLevel) {
return internalChangeLogLevel(groups, null, logLevel);
}
@RequestMapping(method = RequestMethod.POST, value = "/members/{members}/loglevel")
@ResponseBody
public String changeLogLevelForMembers(@PathVariable("members") final String members,
- @RequestParam(value = CliStrings.CHANGE_LOGLEVEL__LOGLEVEL,
- required = true) final String logLevel) {
+ @RequestParam(value = CliStrings.CHANGE_LOGLEVEL__LOGLEVEL) final String logLevel) {
return internalChangeLogLevel(null, members, logLevel);
}
http://git-wip-us.apache.org/repos/asf/geode/blob/0af31324/geode-core/src/main/java/org/apache/geode/management/internal/web/domain/Link.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/web/domain/Link.java b/geode-core/src/main/java/org/apache/geode/management/internal/web/domain/Link.java
index 0dbd5f3..9058eaa 100644
--- a/geode-core/src/main/java/org/apache/geode/management/internal/web/domain/Link.java
+++ b/geode-core/src/main/java/org/apache/geode/management/internal/web/domain/Link.java
@@ -14,16 +14,17 @@
*/
package org.apache.geode.management.internal.web.domain;
-import org.apache.geode.internal.lang.ObjectUtils;
-import org.apache.geode.internal.lang.StringUtils;
-import org.apache.geode.management.internal.web.http.HttpMethod;
-import org.apache.geode.management.internal.web.util.UriUtils;
-
import java.io.Serializable;
import java.net.URI;
+
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlType;
+import org.apache.geode.internal.lang.ObjectUtils;
+import org.apache.geode.internal.lang.StringUtils;
+import org.apache.geode.management.internal.web.http.HttpMethod;
+import org.apache.geode.management.internal.web.util.UriUtils;
+
/**
* The Link class models hypermedia controls/link relations.
* <p/>
@@ -82,7 +83,7 @@ public class Link implements Comparable<Link>, Serializable {
this.href = href;
}
- @XmlAttribute(name = METHOD_ATTRIBUTE_NAME, required = false)
+ @XmlAttribute(name = METHOD_ATTRIBUTE_NAME)
public HttpMethod getMethod() {
return method;
}
http://git-wip-us.apache.org/repos/asf/geode/blob/0af31324/geode-core/src/test/java/org/apache/geode/management/internal/cli/CommandManagerJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/cli/CommandManagerJUnitTest.java b/geode-core/src/test/java/org/apache/geode/management/internal/cli/CommandManagerJUnitTest.java
index 3189f9f..cde0b23 100644
--- a/geode-core/src/test/java/org/apache/geode/management/internal/cli/CommandManagerJUnitTest.java
+++ b/geode-core/src/test/java/org/apache/geode/management/internal/cli/CommandManagerJUnitTest.java
@@ -18,12 +18,8 @@ import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
-import org.apache.geode.management.cli.CliMetaData;
-import org.apache.geode.management.cli.Result;
-import org.apache.geode.management.internal.security.ResourceOperation;
-import org.apache.geode.security.ResourcePermission.Operation;
-import org.apache.geode.security.ResourcePermission.Resource;
-import org.apache.geode.test.junit.categories.UnitTest;
+import java.util.List;
+
import org.junit.Before;
import org.junit.Test;
import org.junit.experimental.categories.Category;
@@ -35,7 +31,12 @@ import org.springframework.shell.core.annotation.CliAvailabilityIndicator;
import org.springframework.shell.core.annotation.CliCommand;
import org.springframework.shell.core.annotation.CliOption;
-import java.util.List;
+import org.apache.geode.management.cli.CliMetaData;
+import org.apache.geode.management.cli.Result;
+import org.apache.geode.management.internal.security.ResourceOperation;
+import org.apache.geode.security.ResourcePermission.Operation;
+import org.apache.geode.security.ResourcePermission.Resource;
+import org.apache.geode.test.junit.categories.UnitTest;
/**
* CommandManagerTest - Includes tests to check the CommandManager functions
@@ -138,15 +139,13 @@ public class CommandManagerJUnitTest {
@CliOption(key = ARGUMENT1_NAME, optionContext = ARGUMENT1_CONTEXT, help = ARGUMENT1_HELP,
mandatory = true) String argument1,
@CliOption(key = ARGUMENT2_NAME, optionContext = ARGUMENT2_CONTEXT, help = ARGUMENT2_HELP,
- mandatory = false, unspecifiedDefaultValue = ARGUMENT2_UNSPECIFIED_DEFAULT_VALUE,
- systemProvided = false) String argument2,
+ unspecifiedDefaultValue = ARGUMENT2_UNSPECIFIED_DEFAULT_VALUE) String argument2,
@CliOption(key = {OPTION1_NAME, OPTION1_SYNONYM}, help = OPTION1_HELP, mandatory = true,
optionContext = OPTION1_CONTEXT,
specifiedDefaultValue = OPTION1_SPECIFIED_DEFAULT_VALUE) String option1,
- @CliOption(key = {OPTION2_NAME}, help = OPTION2_HELP, mandatory = false,
- optionContext = OPTION2_CONTEXT,
+ @CliOption(key = {OPTION2_NAME}, help = OPTION2_HELP, optionContext = OPTION2_CONTEXT,
specifiedDefaultValue = OPTION2_SPECIFIED_DEFAULT_VALUE) String option2,
- @CliOption(key = {OPTION3_NAME, OPTION3_SYNONYM}, help = OPTION3_HELP, mandatory = false,
+ @CliOption(key = {OPTION3_NAME, OPTION3_SYNONYM}, help = OPTION3_HELP,
optionContext = OPTION3_CONTEXT,
unspecifiedDefaultValue = OPTION3_UNSPECIFIED_DEFAULT_VALUE,
specifiedDefaultValue = OPTION3_SPECIFIED_DEFAULT_VALUE) String option3) {
http://git-wip-us.apache.org/repos/asf/geode/blob/0af31324/geode-web-api/src/main/java/org/apache/geode/rest/internal/web/controllers/CommonCrudController.java
----------------------------------------------------------------------
diff --git a/geode-web-api/src/main/java/org/apache/geode/rest/internal/web/controllers/CommonCrudController.java b/geode-web-api/src/main/java/org/apache/geode/rest/internal/web/controllers/CommonCrudController.java
index 3190cd7..93b2144 100644
--- a/geode-web-api/src/main/java/org/apache/geode/rest/internal/web/controllers/CommonCrudController.java
+++ b/geode-web-api/src/main/java/org/apache/geode/rest/internal/web/controllers/CommonCrudController.java
@@ -63,7 +63,7 @@ public abstract class CommonCrudController extends AbstractBaseController {
*/
@RequestMapping(method = RequestMethod.GET, produces = {MediaType.APPLICATION_JSON_UTF8_VALUE})
@ApiOperation(value = "list all resources (Regions)",
- notes = "List all available resources (Regions) in the Geode cluster", response = void.class)
+ notes = "List all available resources (Regions) in the Geode cluster")
@ApiResponses({@ApiResponse(code = 200, message = "OK."),
@ApiResponse(code = 401, message = "Invalid Username or Password."),
@ApiResponse(code = 403, message = "Insufficient privileges for operation."),
@@ -86,7 +86,7 @@ public abstract class CommonCrudController extends AbstractBaseController {
*/
@RequestMapping(method = RequestMethod.GET, value = "/{region}/keys",
produces = {MediaType.APPLICATION_JSON_UTF8_VALUE})
- @ApiOperation(value = "list all keys", notes = "List all keys in region", response = void.class)
+ @ApiOperation(value = "list all keys", notes = "List all keys in region")
@ApiResponses({@ApiResponse(code = 200, message = "OK"),
@ApiResponse(code = 401, message = "Invalid Username or Password."),
@ApiResponse(code = 403, message = "Insufficient privileges for operation."),
@@ -116,7 +116,7 @@ public abstract class CommonCrudController extends AbstractBaseController {
@RequestMapping(method = RequestMethod.DELETE, value = "/{region}/{keys}",
produces = {MediaType.APPLICATION_JSON_VALUE})
@ApiOperation(value = "delete data for key(s)",
- notes = "Delete data for single key or specific keys in region", response = void.class)
+ notes = "Delete data for single key or specific keys in region")
@ApiResponses({@ApiResponse(code = 200, message = "OK"),
@ApiResponse(code = 401, message = "Invalid Username or Password."),
@ApiResponse(code = 403, message = "Insufficient privileges for operation."),
@@ -141,8 +141,7 @@ public abstract class CommonCrudController extends AbstractBaseController {
* @return JSON document containing result
*/
@RequestMapping(method = RequestMethod.DELETE, value = "/{region}")
- @ApiOperation(value = "delete all data", notes = "Delete all data in the region",
- response = void.class)
+ @ApiOperation(value = "delete all data", notes = "Delete all data in the region")
@ApiResponses({@ApiResponse(code = 200, message = "OK"),
@ApiResponse(code = 401, message = "Invalid Username or Password."),
@ApiResponse(code = 403, message = "Insufficient privileges for operation."),
@@ -163,7 +162,7 @@ public abstract class CommonCrudController extends AbstractBaseController {
*/
@RequestMapping(method = {RequestMethod.GET, RequestMethod.HEAD}, value = "/ping")
@ApiOperation(value = "Check Rest service status ",
- notes = "Check whether gemfire REST service is up and running!", response = void.class)
+ notes = "Check whether gemfire REST service is up and running!")
@ApiResponses({@ApiResponse(code = 200, message = "OK"),
@ApiResponse(code = 500, message = "if GemFire throws an error or exception")})
public ResponseEntity<?> ping() {
@@ -173,8 +172,7 @@ public abstract class CommonCrudController extends AbstractBaseController {
@RequestMapping(method = {RequestMethod.GET}, value = "/servers",
produces = {MediaType.APPLICATION_JSON_UTF8_VALUE})
@ApiOperation(value = "fetch all REST enabled servers in the DS",
- notes = "Find all gemfire node where developer REST service is up and running!",
- response = void.class)
+ notes = "Find all gemfire node where developer REST service is up and running!")
@ApiResponses({@ApiResponse(code = 200, message = "OK"),
@ApiResponse(code = 401, message = "Invalid Username or Password."),
@ApiResponse(code = 403, message = "Insufficient privileges for operation."),
http://git-wip-us.apache.org/repos/asf/geode/blob/0af31324/geode-web-api/src/main/java/org/apache/geode/rest/internal/web/controllers/FunctionAccessController.java
----------------------------------------------------------------------
diff --git a/geode-web-api/src/main/java/org/apache/geode/rest/internal/web/controllers/FunctionAccessController.java b/geode-web-api/src/main/java/org/apache/geode/rest/internal/web/controllers/FunctionAccessController.java
index edfdeaa..61a1aad 100644
--- a/geode-web-api/src/main/java/org/apache/geode/rest/internal/web/controllers/FunctionAccessController.java
+++ b/geode-web-api/src/main/java/org/apache/geode/rest/internal/web/controllers/FunctionAccessController.java
@@ -14,17 +14,15 @@
*/
package org.apache.geode.rest.internal.web.controllers;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
-import org.apache.geode.cache.LowMemoryException;
-import org.apache.geode.cache.execute.*;
-import org.apache.geode.internal.cache.execute.NoResult;
-import org.apache.geode.internal.logging.LogService;
-import org.apache.geode.rest.internal.web.exception.GemfireRestException;
-import org.apache.geode.rest.internal.web.util.ArrayUtils;
-import org.apache.geode.rest.internal.web.util.JSONUtils;
import org.apache.logging.log4j.Logger;
import org.json.JSONException;
import org.springframework.http.HttpHeaders;
@@ -42,10 +40,17 @@ import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
+import org.apache.geode.cache.LowMemoryException;
+import org.apache.geode.cache.execute.Execution;
+import org.apache.geode.cache.execute.Function;
+import org.apache.geode.cache.execute.FunctionException;
+import org.apache.geode.cache.execute.FunctionService;
+import org.apache.geode.cache.execute.ResultCollector;
+import org.apache.geode.internal.cache.execute.NoResult;
+import org.apache.geode.internal.logging.LogService;
+import org.apache.geode.rest.internal.web.exception.GemfireRestException;
+import org.apache.geode.rest.internal.web.util.ArrayUtils;
+import org.apache.geode.rest.internal.web.util.JSONUtils;
/**
* The FunctionsController class serving REST Requests related to the function execution
@@ -80,7 +85,7 @@ public class FunctionAccessController extends AbstractBaseController {
*/
@RequestMapping(method = RequestMethod.GET, produces = {MediaType.APPLICATION_JSON_UTF8_VALUE})
@ApiOperation(value = "list all functions",
- notes = "list all functions available in the GemFire cluster", response = void.class)
+ notes = "list all functions available in the GemFire cluster")
@ApiResponses({@ApiResponse(code = 200, message = "OK."),
@ApiResponse(code = 401, message = "Invalid Username or Password."),
@ApiResponse(code = 403, message = "Insufficient privileges for operation."),
@@ -116,8 +121,7 @@ public class FunctionAccessController extends AbstractBaseController {
@RequestMapping(method = RequestMethod.POST, value = "/{functionId:.+}",
produces = {MediaType.APPLICATION_JSON_VALUE})
@ApiOperation(value = "execute function",
- notes = "Execute function with arguments on regions, members, or group(s). By default function will be executed on all nodes if none of (onRegion, onMembers, onGroups) specified",
- response = void.class)
+ notes = "Execute function with arguments on regions, members, or group(s). By default function will be executed on all nodes if none of (onRegion, onMembers, onGroups) specified")
@ApiResponses({@ApiResponse(code = 200, message = "OK."),
@ApiResponse(code = 401, message = "Invalid Username or Password."),
@ApiResponse(code = 403, message = "Insufficient privileges for operation."),
http://git-wip-us.apache.org/repos/asf/geode/blob/0af31324/geode-web-api/src/main/java/org/apache/geode/rest/internal/web/controllers/PdxBasedCrudController.java
----------------------------------------------------------------------
diff --git a/geode-web-api/src/main/java/org/apache/geode/rest/internal/web/controllers/PdxBasedCrudController.java b/geode-web-api/src/main/java/org/apache/geode/rest/internal/web/controllers/PdxBasedCrudController.java
index 3dd987f..9743078 100644
--- a/geode-web-api/src/main/java/org/apache/geode/rest/internal/web/controllers/PdxBasedCrudController.java
+++ b/geode-web-api/src/main/java/org/apache/geode/rest/internal/web/controllers/PdxBasedCrudController.java
@@ -14,16 +14,14 @@
*/
package org.apache.geode.rest.internal.web.controllers;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
-import org.apache.geode.internal.logging.LogService;
-import org.apache.geode.rest.internal.web.controllers.support.JSONTypes;
-import org.apache.geode.rest.internal.web.controllers.support.RegionData;
-import org.apache.geode.rest.internal.web.controllers.support.RegionEntryData;
-import org.apache.geode.rest.internal.web.exception.ResourceNotFoundException;
-import org.apache.geode.rest.internal.web.util.ArrayUtils;
import org.apache.logging.log4j.Logger;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
@@ -32,11 +30,18 @@ import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
-import org.springframework.web.bind.annotation.*;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RequestParam;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
+import org.apache.geode.internal.logging.LogService;
+import org.apache.geode.rest.internal.web.controllers.support.JSONTypes;
+import org.apache.geode.rest.internal.web.controllers.support.RegionData;
+import org.apache.geode.rest.internal.web.controllers.support.RegionEntryData;
+import org.apache.geode.rest.internal.web.exception.ResourceNotFoundException;
+import org.apache.geode.rest.internal.web.util.ArrayUtils;
/**
* The PdxBasedCrudController class serving REST Requests related to the REST CRUD operation on
@@ -72,8 +77,7 @@ public class PdxBasedCrudController extends CommonCrudController {
*/
@RequestMapping(method = RequestMethod.POST, value = "/{region}",
consumes = MediaType.APPLICATION_JSON_VALUE, produces = {MediaType.APPLICATION_JSON_VALUE})
- @ApiOperation(value = "create entry", notes = "Create (put-if-absent) data in region",
- response = void.class)
+ @ApiOperation(value = "create entry", notes = "Create (put-if-absent) data in region")
@ApiResponses({@ApiResponse(code = 201, message = "Created."),
@ApiResponse(code = 400,
message = "Data specified (JSON doc) in the request body is invalid."),
@@ -125,8 +129,7 @@ public class PdxBasedCrudController extends CommonCrudController {
@RequestMapping(method = RequestMethod.GET, value = "/{region}",
produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
@ApiOperation(value = "read all data for region",
- notes = "Read all data for region. Use limit param to get fixed or limited number of entries.",
- response = void.class)
+ notes = "Read all data for region. Use limit param to get fixed or limited number of entries.")
@ApiResponses({@ApiResponse(code = 200, message = "OK."),
@ApiResponse(code = 400, message = "Bad request."),
@ApiResponse(code = 401, message = "Invalid Username or Password."),
@@ -200,7 +203,7 @@ public class PdxBasedCrudController extends CommonCrudController {
@RequestMapping(method = RequestMethod.GET, value = "/{region}/{keys}",
produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
@ApiOperation(value = "read data for specific keys",
- notes = "Read data for specific set of keys in region.", response = void.class)
+ notes = "Read data for specific set of keys in region.")
@ApiResponses({@ApiResponse(code = 200, message = "OK."),
@ApiResponse(code = 400, message = "Bad Request."),
@ApiResponse(code = 401, message = "Invalid Username or Password."),
@@ -280,8 +283,7 @@ public class PdxBasedCrudController extends CommonCrudController {
@ApiOperation(value = "update data for key",
notes = "Update or insert (put) data for key in region."
+ "op=REPLACE, update (replace) data with key if and only if the key exists in region"
- + "op=CAS update (compare-and-set) value having key with a new value if and only if the \"@old\" value sent matches the current value for the key in region",
- response = void.class)
+ + "op=CAS update (compare-and-set) value having key with a new value if and only if the \"@old\" value sent matches the current value for the key in region")
@ApiResponses({@ApiResponse(code = 200, message = "OK."),
@ApiResponse(code = 400, message = "Bad Request."),
@ApiResponse(code = 401, message = "Invalid Username or Password."),
@@ -312,7 +314,7 @@ public class PdxBasedCrudController extends CommonCrudController {
@RequestMapping(method = RequestMethod.HEAD, value = "/{region}",
produces = MediaType.APPLICATION_JSON_VALUE)
@ApiOperation(value = "Get total number of entries",
- notes = "Get total number of entries into the specified region", response = void.class)
+ notes = "Get total number of entries into the specified region")
@ApiResponses({@ApiResponse(code = 200, message = "OK."),
@ApiResponse(code = 400, message = "Bad request."),
@ApiResponse(code = 401, message = "Invalid Username or Password."),
http://git-wip-us.apache.org/repos/asf/geode/blob/0af31324/geode-web-api/src/main/java/org/apache/geode/rest/internal/web/controllers/QueryAccessController.java
----------------------------------------------------------------------
diff --git a/geode-web-api/src/main/java/org/apache/geode/rest/internal/web/controllers/QueryAccessController.java b/geode-web-api/src/main/java/org/apache/geode/rest/internal/web/controllers/QueryAccessController.java
index e6b6303..4ff806f 100644
--- a/geode-web-api/src/main/java/org/apache/geode/rest/internal/web/controllers/QueryAccessController.java
+++ b/geode-web-api/src/main/java/org/apache/geode/rest/internal/web/controllers/QueryAccessController.java
@@ -14,18 +14,12 @@
*/
package org.apache.geode.rest.internal.web.controllers;
+import java.util.concurrent.ConcurrentHashMap;
+
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
-import org.apache.geode.cache.Region;
-import org.apache.geode.cache.query.*;
-import org.apache.geode.cache.query.internal.DefaultQuery;
-import org.apache.geode.internal.logging.LogService;
-import org.apache.geode.rest.internal.web.exception.GemfireRestException;
-import org.apache.geode.rest.internal.web.exception.ResourceNotFoundException;
-import org.apache.geode.rest.internal.web.util.JSONUtils;
-import org.apache.geode.rest.internal.web.util.ValidationUtils;
import org.apache.logging.log4j.Logger;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
@@ -33,9 +27,29 @@ import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
-import org.springframework.web.bind.annotation.*;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.ResponseBody;
+import org.springframework.web.bind.annotation.ResponseStatus;
-import java.util.concurrent.ConcurrentHashMap;
+import org.apache.geode.cache.Region;
+import org.apache.geode.cache.query.FunctionDomainException;
+import org.apache.geode.cache.query.NameResolutionException;
+import org.apache.geode.cache.query.Query;
+import org.apache.geode.cache.query.QueryExecutionLowMemoryException;
+import org.apache.geode.cache.query.QueryExecutionTimeoutException;
+import org.apache.geode.cache.query.QueryInvalidException;
+import org.apache.geode.cache.query.QueryInvocationTargetException;
+import org.apache.geode.cache.query.TypeMismatchException;
+import org.apache.geode.cache.query.internal.DefaultQuery;
+import org.apache.geode.internal.logging.LogService;
+import org.apache.geode.rest.internal.web.exception.GemfireRestException;
+import org.apache.geode.rest.internal.web.exception.ResourceNotFoundException;
+import org.apache.geode.rest.internal.web.util.JSONUtils;
+import org.apache.geode.rest.internal.web.util.ValidationUtils;
/**
* The QueryingController class serves all HTTP REST requests related to the gemfire querying
@@ -76,7 +90,7 @@ public class QueryAccessController extends AbstractBaseController {
*/
@RequestMapping(method = RequestMethod.GET, produces = {MediaType.APPLICATION_JSON_UTF8_VALUE})
@ApiOperation(value = "list all parametrized queries",
- notes = "List all parametrized queries by id/name", response = void.class)
+ notes = "List all parametrized queries by id/name")
@ApiResponses({@ApiResponse(code = 200, message = "OK."),
@ApiResponse(code = 401, message = "Invalid Username or Password."),
@ApiResponse(code = 403, message = "Insufficient privileges for operation."),
@@ -106,8 +120,7 @@ public class QueryAccessController extends AbstractBaseController {
*/
@RequestMapping(method = RequestMethod.POST)
@ApiOperation(value = "create a parametrized Query",
- notes = "Prepare the specified parametrized query and assign the corresponding ID for lookup",
- response = void.class)
+ notes = "Prepare the specified parametrized query and assign the corresponding ID for lookup")
@ApiResponses({@ApiResponse(code = 201, message = "Successfully created."),
@ApiResponse(code = 401, message = "Invalid Username or Password."),
@ApiResponse(code = 403, message = "Insufficient privileges for operation."),
@@ -148,8 +161,7 @@ public class QueryAccessController extends AbstractBaseController {
@RequestMapping(method = RequestMethod.GET, value = "/adhoc",
produces = {MediaType.APPLICATION_JSON_UTF8_VALUE})
@ApiOperation(value = "run an adhoc query",
- notes = "Run an unnamed (unidentified), ad-hoc query passed as a URL parameter",
- response = void.class)
+ notes = "Run an unnamed (unidentified), ad-hoc query passed as a URL parameter")
@ApiResponses({@ApiResponse(code = 200, message = "OK."),
@ApiResponse(code = 401, message = "Invalid Username or Password."),
@ApiResponse(code = 403, message = "Insufficient privileges for operation."),
@@ -207,8 +219,7 @@ public class QueryAccessController extends AbstractBaseController {
@RequestMapping(method = RequestMethod.POST, value = "/{query}",
produces = {MediaType.APPLICATION_JSON_VALUE})
@ApiOperation(value = "run parametrized query",
- notes = "run the specified named query passing in scalar values for query parameters in the GemFire cluster",
- response = void.class)
+ notes = "run the specified named query passing in scalar values for query parameters in the GemFire cluster")
@ApiResponses({@ApiResponse(code = 200, message = "Query successfully executed."),
@ApiResponse(code = 401, message = "Invalid Username or Password."),
@ApiResponse(code = 403, message = "Insufficient privileges for operation."),
@@ -291,7 +302,7 @@ public class QueryAccessController extends AbstractBaseController {
*/
@RequestMapping(method = RequestMethod.PUT, value = "/{query}")
@ApiOperation(value = "update parametrized query",
- notes = "Update named, parametrized query by ID", response = void.class)
+ notes = "Update named, parametrized query by ID")
@ApiResponses({@ApiResponse(code = 200, message = "Updated successfully."),
@ApiResponse(code = 401, message = "Invalid Username or Password."),
@ApiResponse(code = 403, message = "Insufficient privileges for operation."),
@@ -322,7 +333,7 @@ public class QueryAccessController extends AbstractBaseController {
*/
@RequestMapping(method = RequestMethod.DELETE, value = "/{query}")
@ApiOperation(value = "delete parametrized query",
- notes = "delete named, parametrized query by ID", response = void.class)
+ notes = "delete named, parametrized query by ID")
@ApiResponses({@ApiResponse(code = 200, message = "Deleted successfully."),
@ApiResponse(code = 401, message = "Invalid Username or Password."),
@ApiResponse(code = 403, message = "Insufficient privileges for operation."),