GEODE-2632: refactor code to reduce GemFireCacheImpl dependencies * extract fetching GemFireCacheImpl to Provider interface/class * use InternalCache instead of casting to Impl * delete useless javadocs and comments * reduce scope of constants, vars and methods
Project: http://git-wip-us.apache.org/repos/asf/geode/repo Commit: http://git-wip-us.apache.org/repos/asf/geode/commit/47d8c820 Tree: http://git-wip-us.apache.org/repos/asf/geode/tree/47d8c820 Diff: http://git-wip-us.apache.org/repos/asf/geode/diff/47d8c820 Branch: refs/heads/feature/GEM-1299 Commit: 47d8c82036a9863c9fa7c9142c170c9f8552abb4 Parents: 60ec931 Author: Kirk Lund <kl...@apache.org> Authored: Wed Apr 19 09:56:24 2017 -0700 Committer: Kirk Lund <kl...@apache.org> Committed: Fri Apr 21 14:47:50 2017 -0700 ---------------------------------------------------------------------- .../web/controllers/AbstractBaseController.java | 194 +++++++++---------- .../web/controllers/BaseControllerAdvice.java | 28 ++- .../web/controllers/CommonCrudController.java | 29 +-- .../controllers/FunctionAccessController.java | 39 ++-- .../web/controllers/PdxBasedCrudController.java | 28 ++- .../web/controllers/QueryAccessController.java | 49 ++--- .../web/controllers/support/CacheProvider.java | 22 +++ .../controllers/support/CacheProviderImpl.java | 29 +++ 8 files changed, 219 insertions(+), 199 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/geode/blob/47d8c820/geode-web-api/src/main/java/org/apache/geode/rest/internal/web/controllers/AbstractBaseController.java ---------------------------------------------------------------------- diff --git a/geode-web-api/src/main/java/org/apache/geode/rest/internal/web/controllers/AbstractBaseController.java b/geode-web-api/src/main/java/org/apache/geode/rest/internal/web/controllers/AbstractBaseController.java index 68080a3..d8eb572 100644 --- a/geode-web-api/src/main/java/org/apache/geode/rest/internal/web/controllers/AbstractBaseController.java +++ b/geode-web-api/src/main/java/org/apache/geode/rest/internal/web/controllers/AbstractBaseController.java @@ -12,15 +12,44 @@ * or implied. See the License for the specific language governing permissions and limitations under * the License. */ - package org.apache.geode.rest.internal.web.controllers; +import java.io.IOException; +import java.io.UnsupportedEncodingException; +import java.net.URI; +import java.net.URLDecoder; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.atomic.AtomicLong; + +import javax.annotation.PostConstruct; + import com.fasterxml.jackson.core.JsonParseException; import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; +import org.apache.logging.log4j.Logger; +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; +import org.json.JSONTokener; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.util.Assert; +import org.springframework.util.ClassUtils; +import org.springframework.util.CollectionUtils; +import org.springframework.util.StringUtils; +import org.springframework.web.servlet.support.ServletUriComponentsBuilder; + import org.apache.geode.SerializationException; -import org.apache.geode.cache.Cache; import org.apache.geode.cache.CacheLoaderException; import org.apache.geode.cache.CacheWriterException; import org.apache.geode.cache.LowMemoryException; @@ -33,11 +62,12 @@ import org.apache.geode.distributed.DistributedMember; import org.apache.geode.distributed.LeaseExpiredException; import org.apache.geode.distributed.internal.DistributionManager; import org.apache.geode.distributed.internal.membership.InternalDistributedMember; -import org.apache.geode.internal.cache.GemFireCacheImpl; +import org.apache.geode.internal.cache.InternalCache; import org.apache.geode.internal.logging.LogService; import org.apache.geode.pdx.JSONFormatter; import org.apache.geode.pdx.JSONFormatterException; import org.apache.geode.pdx.PdxInstance; +import org.apache.geode.rest.internal.web.controllers.support.CacheProvider; import org.apache.geode.rest.internal.web.controllers.support.JSONTypes; import org.apache.geode.rest.internal.web.controllers.support.UpdateOp; import org.apache.geode.rest.internal.web.exception.DataTypeNotSupportedException; @@ -51,79 +81,49 @@ import org.apache.geode.rest.internal.web.util.IdentifiableUtils; import org.apache.geode.rest.internal.web.util.JSONUtils; import org.apache.geode.rest.internal.web.util.NumberUtils; import org.apache.geode.rest.internal.web.util.ValidationUtils; -import org.apache.logging.log4j.Logger; -import org.json.JSONArray; -import org.json.JSONException; -import org.json.JSONObject; -import org.json.JSONTokener; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.HttpHeaders; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.util.Assert; -import org.springframework.util.ClassUtils; -import org.springframework.util.CollectionUtils; -import org.springframework.util.StringUtils; -import org.springframework.web.servlet.support.ServletUriComponentsBuilder; - -import java.io.IOException; -import java.io.UnsupportedEncodingException; -import java.net.URI; -import java.net.URLDecoder; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.concurrent.atomic.AtomicLong; -import javax.annotation.PostConstruct; - /** * AbstractBaseController class contains common functionalities required for other controllers. * * @since GemFire 8.0 */ - @SuppressWarnings("unused") public abstract class AbstractBaseController { - protected static final String NEW_META_DATA_PROPERTY = "@new"; - protected static final String OLD_META_DATA_PROPERTY = "@old"; - protected static final String TYPE_META_DATA_PROPERTY = "@type"; - protected static final String UTF_8 = "UTF-8"; - protected static final String DEFAULT_ENCODING = UTF_8; + private static final String NEW_META_DATA_PROPERTY = "@new"; + private static final String OLD_META_DATA_PROPERTY = "@old"; + private static final String TYPE_META_DATA_PROPERTY = "@type"; + private static final String UTF_8 = "UTF-8"; + private static final String DEFAULT_ENCODING = UTF_8; private static final Logger logger = LogService.getLogger(); private static final AtomicLong ID_SEQUENCE = new AtomicLong(0l); - // private Cache cache = GemFireCacheImpl.getExisting(null); @Autowired - protected RestSecurityService securityService; + private RestSecurityService securityService; @Autowired private ObjectMapper objectMapper; + @Autowired + private CacheProvider cacheProvider; @PostConstruct private void init() { JSONUtils.setObjectMapper(objectMapper); } - protected Cache getCache() { - Cache cache = GemFireCacheImpl.getExisting(); + protected InternalCache getCache() { + InternalCache cache = cacheProvider.getInternalCache(); Assert.state(cache != null, "The Gemfire Cache reference was not properly initialized"); return cache; } - protected URI toUri(final String... pathSegments) { + URI toUri(final String... pathSegments) { return ServletUriComponentsBuilder.fromCurrentContextPath().path(getRestApiVersion()) .pathSegment(pathSegments).build().toUri(); } protected abstract String getRestApiVersion(); - protected String validateQuery(String queryInUrl, String queryInBody) { + String validateQuery(String queryInUrl, String queryInBody) { if (!(StringUtils.hasText(queryInUrl) || StringUtils.hasText(queryInBody))) { throw new GemfireRestException("could not process null value specified in query String"); @@ -131,7 +131,7 @@ public abstract class AbstractBaseController { return (StringUtils.hasText(queryInUrl) ? decode(queryInUrl) : queryInBody); } - protected String decode(final String value) { + String decode(final String value) { if (value == null) { throw new GemfireRestException("could not process null value specified in query String"); } @@ -175,7 +175,7 @@ public abstract class AbstractBaseController { } @SuppressWarnings("unchecked") - protected <T> T casValue(String regionNamePath, String key, String jsonData) { + private <T> T casValue(String regionNamePath, String key, String jsonData) { JSONObject jsonObject; try { jsonObject = new JSONObject(jsonData); @@ -189,7 +189,7 @@ public abstract class AbstractBaseController { } } - public ResponseEntity<String> processQueryResponse(Query query, Object args[], Object queryResult) + ResponseEntity<String> processQueryResponse(Query query, Object args[], Object queryResult) throws JSONException { if (queryResult instanceof Collection<?>) { Collection processedResults = new ArrayList(((Collection) queryResult).size()); @@ -207,7 +207,7 @@ public abstract class AbstractBaseController { } } - protected Collection<PdxInstance> convertJsonArrayIntoPdxCollection(final String jsonArray) { + Collection<PdxInstance> convertJsonArrayIntoPdxCollection(final String jsonArray) { JSONArray jsonArr = null; try { jsonArr = new JSONArray(jsonArray); @@ -229,18 +229,7 @@ public abstract class AbstractBaseController { } } - - /* - * protected PdxInstance convertJsonIntoPdxCollection(final String jsonArray) { JSONArray jsonArr - * = null; - * - * PdxInstance pi = convert(jsonArray); - * System.out.println("Successfully converted into PdxInstance..!!"); return pi; - * - * } - */ - - protected Object casValue(final String regionNamePath, final Object key, final Object oldValue, + private Object casValue(final String regionNamePath, final Object key, final Object oldValue, final Object newValue) { final Region<Object, Object> region = getRegion(regionNamePath); try { @@ -281,7 +270,7 @@ public abstract class AbstractBaseController { } } - protected void replaceValue(final String regionNamePath, final Object key, + private void replaceValue(final String regionNamePath, final Object key, final PdxInstance value) { try { if (getRegion(regionNamePath).replace(key, value) == null) { @@ -367,7 +356,7 @@ public abstract class AbstractBaseController { } } - protected void putValue(final String regionNamePath, final Object key, final Object value) { + private void putValue(final String regionNamePath, final Object key, final Object value) { try { getRegion(regionNamePath).put(key, value); } catch (NullPointerException npe) { @@ -397,23 +386,23 @@ public abstract class AbstractBaseController { } } - protected void deleteQueryId(final String regionNamePath, final String key) { + private void deleteQueryId(final String regionNamePath, final String key) { getQueryStore(regionNamePath).remove(key); } - protected void deleteNamedQuery(final String regionNamePath, final String key) { + void deleteNamedQuery(final String regionNamePath, final String key) { // Check whether query ID exist in region or not checkForQueryIdExist(regionNamePath, key); deleteQueryId(regionNamePath, key); } - protected void checkForQueryIdExist(String region, String key) { + void checkForQueryIdExist(String region, String key) { if (!getQueryStore(region).containsKey(key)) { throw new ResourceNotFoundException(String.format("Named query (%1$s) does not exist!", key)); } } - protected Region<String, String> getQueryStore(final String namePath) { + Region<String, String> getQueryStore(final String namePath) { return ValidationUtils.returnValueThrowOnNull(getCache().<String, String>getRegion(namePath), new GemfireRestException(String.format("Query store does not exist!", namePath))); } @@ -436,8 +425,7 @@ public abstract class AbstractBaseController { } } - protected void updateNamedQuery(final String regionNamePath, final String key, - final String value) { + void updateNamedQuery(final String regionNamePath, final String key, final String value) { try { getQueryStore(regionNamePath).put(key, value); } catch (NullPointerException npe) { @@ -457,8 +445,7 @@ public abstract class AbstractBaseController { } @SuppressWarnings("unchecked") - protected <T> T createNamedQuery(final String regionNamePath, final String key, - final String value) { + <T> T createNamedQuery(final String regionNamePath, final String key, final String value) { try { return (T) getQueryStore(regionNamePath).putIfAbsent(key, value); } catch (UnsupportedOperationException use) { @@ -482,7 +469,7 @@ public abstract class AbstractBaseController { } } - protected void putPdxValues(final String regionNamePath, final Map<Object, PdxInstance> map) { + private void putPdxValues(final String regionNamePath, final Map<Object, PdxInstance> map) { try { getRegion(regionNamePath).putAll(map); } catch (LowMemoryException lme) { @@ -490,7 +477,7 @@ public abstract class AbstractBaseController { } } - protected void putValues(final String regionNamePath, final Map<Object, Object> values) { + private void putValues(final String regionNamePath, final Map<Object, Object> values) { getRegion(regionNamePath).putAll(values); } @@ -510,7 +497,7 @@ public abstract class AbstractBaseController { } @SuppressWarnings("unchecked") - protected <T> T postValue(final String regionNamePath, final Object key, final Object value) { + <T> T postValue(final String regionNamePath, final Object key, final Object value) { try { return (T) getRegion(regionNamePath).putIfAbsent(key, value); } catch (UnsupportedOperationException use) { @@ -561,11 +548,11 @@ public abstract class AbstractBaseController { return actualValue; } - protected String generateKey(final String existingKey) { + String generateKey(final String existingKey) { return generateKey(existingKey, null); } - protected String generateKey(final String existingKey, final Object domainObject) { + private String generateKey(final String existingKey, final Object domainObject) { Object domainObjectId = IdentifiableUtils.getId(domainObject); String newKey; @@ -597,7 +584,7 @@ public abstract class AbstractBaseController { return newKey; } - protected String decode(final String value, final String encoding) { + private String decode(final String value, final String encoding) { try { return URLDecoder.decode(value, encoding); } catch (UnsupportedEncodingException e) { @@ -612,19 +599,17 @@ public abstract class AbstractBaseController { String.format("The Region identified by name (%1$s) could not be found!", namePath))); } - protected void checkForKeyExist(String region, String key) { + private void checkForKeyExist(String region, String key) { if (!getRegion(region).containsKey(key)) { throw new ResourceNotFoundException( String.format("Key (%1$s) does not exist for region (%2$s) in cache!", key, region)); } } - protected List<String> checkForMultipleKeysExist(String region, String... keys) { + List<String> checkForMultipleKeysExist(String region, String... keys) { List<String> unknownKeys = new ArrayList<String>(); for (int index = 0; index < keys.length; index++) { if (!getRegion(region).containsKey(keys[index])) { - // throw new ResourceNotFoundException(String.format("Key [(%1$s)] does not exist for region - // [(%2$s)] in cache!", key, region)); unknownKeys.add(keys[index]); } } @@ -664,11 +649,11 @@ public abstract class AbstractBaseController { return entries.values(); } - protected void deleteValue(final String regionNamePath, final Object key) { + private void deleteValue(final String regionNamePath, final Object key) { getRegion(regionNamePath).remove(key); } - protected void deleteValues(final String regionNamePath, final Object... keys) { + void deleteValues(final String regionNamePath, final Object... keys) { // Check whether all keys exist in cache or not for (final Object key : keys) { checkForKeyExist(regionNamePath, key.toString()); @@ -679,7 +664,7 @@ public abstract class AbstractBaseController { } } - protected void deleteValues(String regionNamePath) { + void deleteValues(String regionNamePath) { try { getRegion(regionNamePath).clear(); } catch (UnsupportedOperationException ue) { @@ -694,7 +679,7 @@ public abstract class AbstractBaseController { } @SuppressWarnings("unchecked") - protected <T> T introspectAndConvert(final T value) { + private <T> T introspectAndConvert(final T value) { if (value instanceof Map) { final Map rawDataBinding = (Map) value; @@ -736,15 +721,15 @@ public abstract class AbstractBaseController { return value; } - protected String convertErrorAsJson(String errorMessage) { + String convertErrorAsJson(String errorMessage) { return ("{" + "\"message\"" + ":" + "\"" + errorMessage + "\"" + "}"); } - protected String convertErrorAsJson(Throwable t) { + String convertErrorAsJson(Throwable t) { return String.format("{\"message\" : \"%1$s\"}", t.getMessage()); } - protected Map<?, ?> convertJsonToMap(final String jsonString) { + private Map<?, ?> convertJsonToMap(final String jsonString) { Map<String, String> map = new HashMap<String, String>(); // convert JSON string to Map @@ -762,11 +747,11 @@ public abstract class AbstractBaseController { return map; } - protected Object jsonToObject(final String jsonString) { + private Object jsonToObject(final String jsonString) { return introspectAndConvert(convertJsonToMap(jsonString)); } - protected Object[] jsonToObjectArray(final String arguments) { + Object[] jsonToObjectArray(final String arguments) { final JSONTypes jsonType = validateJsonAndFindType(arguments); if (JSONTypes.JSON_ARRAY.equals(jsonType)) { try { @@ -787,8 +772,8 @@ public abstract class AbstractBaseController { } } - public ResponseEntity<String> updateSingleKey(final String region, final String key, - final String json, final String opValue) { + ResponseEntity<String> updateSingleKey(final String region, final String key, final String json, + final String opValue) { final JSONTypes jsonType = validateJsonAndFindType(json); @@ -822,7 +807,7 @@ public abstract class AbstractBaseController { } - public ResponseEntity<String> updateMultipleKeys(final String region, final String[] keys, + ResponseEntity<String> updateMultipleKeys(final String region, final String[] keys, final String json) { JSONArray jsonArr = null; @@ -862,7 +847,7 @@ public abstract class AbstractBaseController { return new ResponseEntity<String>(headers, HttpStatus.OK); } - public JSONTypes validateJsonAndFindType(String json) { + JSONTypes validateJsonAndFindType(String json) { try { Object jsonObj = new JSONTokener(json).nextValue(); @@ -927,17 +912,16 @@ public abstract class AbstractBaseController { } protected Set<DistributedMember> getMembers(final String... memberIdNames) { - ValidationUtils.returnValueThrowOnNull(memberIdNames, new GemfireRestException("No member found to run function")); - final Set<DistributedMember> targetedMembers = - new HashSet<DistributedMember>(ArrayUtils.length(memberIdNames)); + final Set<DistributedMember> targetedMembers = new HashSet<>(ArrayUtils.length(memberIdNames)); final List<String> memberIdNameList = Arrays.asList(memberIdNames); - GemFireCacheImpl c = (GemFireCacheImpl) getCache(); - Set<DistributedMember> distMembers = c.getDistributedSystem().getAllOtherMembers(); + + InternalCache cache = getCache(); + Set<DistributedMember> distMembers = cache.getDistributedSystem().getAllOtherMembers(); // Add the local node to list - distMembers.add(c.getDistributedSystem().getDistributedMember()); + distMembers.add(cache.getDistributedSystem().getDistributedMember()); for (DistributedMember member : distMembers) { if (memberIdNameList.contains(member.getId()) || memberIdNameList.contains(member.getName())) { @@ -947,10 +931,10 @@ public abstract class AbstractBaseController { return targetedMembers; } - protected Set<DistributedMember> getAllMembersInDS() { - GemFireCacheImpl c = (GemFireCacheImpl) getCache(); - Set<DistributedMember> distMembers = c.getDistributedSystem().getAllOtherMembers(); - final Set<DistributedMember> targetedMembers = new HashSet<DistributedMember>(); + Set<DistributedMember> getAllMembersInDS() { + InternalCache cache = getCache(); + Set<DistributedMember> distMembers = cache.getDistributedSystem().getAllOtherMembers(); + final Set<DistributedMember> targetedMembers = new HashSet<>(); // find valid data nodes, i.e non locator, non-admin, non-loner nodes for (DistributedMember member : distMembers) { @@ -960,7 +944,7 @@ public abstract class AbstractBaseController { } } // Add the local node to list - targetedMembers.add(c.getDistributedSystem().getDistributedMember()); + targetedMembers.add(cache.getDistributedSystem().getDistributedMember()); return targetedMembers; } } http://git-wip-us.apache.org/repos/asf/geode/blob/47d8c820/geode-web-api/src/main/java/org/apache/geode/rest/internal/web/controllers/BaseControllerAdvice.java ---------------------------------------------------------------------- diff --git a/geode-web-api/src/main/java/org/apache/geode/rest/internal/web/controllers/BaseControllerAdvice.java b/geode-web-api/src/main/java/org/apache/geode/rest/internal/web/controllers/BaseControllerAdvice.java index 8939542..751e6a0 100644 --- a/geode-web-api/src/main/java/org/apache/geode/rest/internal/web/controllers/BaseControllerAdvice.java +++ b/geode-web-api/src/main/java/org/apache/geode/rest/internal/web/controllers/BaseControllerAdvice.java @@ -12,16 +12,11 @@ * or implied. See the License for the specific language governing permissions and limitations under * the License. */ - package org.apache.geode.rest.internal.web.controllers; -import org.apache.geode.internal.logging.LogService; -import org.apache.geode.rest.internal.web.exception.DataTypeNotSupportedException; -import org.apache.geode.rest.internal.web.exception.GemfireRestException; -import org.apache.geode.rest.internal.web.exception.MalformedJsonException; -import org.apache.geode.rest.internal.web.exception.RegionNotFoundException; -import org.apache.geode.rest.internal.web.exception.ResourceNotFoundException; -import org.apache.geode.security.NotAuthorizedException; +import java.io.PrintWriter; +import java.io.StringWriter; + import org.apache.logging.log4j.Logger; import org.springframework.http.HttpStatus; import org.springframework.security.access.AccessDeniedException; @@ -31,24 +26,26 @@ import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.ResponseStatus; -import java.io.PrintWriter; -import java.io.StringWriter; - +import org.apache.geode.internal.logging.LogService; +import org.apache.geode.rest.internal.web.exception.DataTypeNotSupportedException; +import org.apache.geode.rest.internal.web.exception.GemfireRestException; +import org.apache.geode.rest.internal.web.exception.MalformedJsonException; +import org.apache.geode.rest.internal.web.exception.RegionNotFoundException; +import org.apache.geode.rest.internal.web.exception.ResourceNotFoundException; +import org.apache.geode.security.NotAuthorizedException; /** * The CrudControllerAdvice class handles exception thrown while serving the REST request - * <p/> - * + * * @since GemFire 8.0 */ - @ControllerAdvice @SuppressWarnings("unused") public class BaseControllerAdvice extends AbstractBaseController { private static final Logger logger = LogService.getLogger(); - protected static final String REST_API_VERSION = "/v1"; + private static final String REST_API_VERSION = "/v1"; @Override protected String getRestApiVersion() { @@ -186,4 +183,3 @@ public class BaseControllerAdvice extends AbstractBaseController { } } - http://git-wip-us.apache.org/repos/asf/geode/blob/47d8c820/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 62ce860..0449a45 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 @@ -14,9 +14,24 @@ */ package org.apache.geode.rest.internal.web.controllers; +import java.util.ArrayList; +import java.util.List; +import java.util.Set; + import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiResponse; import io.swagger.annotations.ApiResponses; +import org.apache.logging.log4j.Logger; +import org.json.JSONException; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; + import org.apache.geode.cache.LowMemoryException; import org.apache.geode.cache.Region; import org.apache.geode.cache.execute.Execution; @@ -29,20 +44,6 @@ import org.apache.geode.rest.internal.web.controllers.support.RestServersResultC 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; -import org.springframework.http.HttpStatus; -import org.springframework.http.MediaType; -import org.springframework.http.ResponseEntity; -import org.springframework.security.access.prepost.PreAuthorize; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; - -import java.util.ArrayList; -import java.util.List; -import java.util.Set; /** * The CommonCrudController serves REST Requests related to listing regions, listing keys in region, http://git-wip-us.apache.org/repos/asf/geode/blob/47d8c820/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 80996c3..473b8b9 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 @@ -12,24 +12,17 @@ * or implied. See the License for the specific language governing permissions and limitations under * the License. */ - 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.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; import org.apache.logging.log4j.Logger; import org.json.JSONException; import org.springframework.http.HttpHeaders; @@ -47,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 @@ -58,20 +58,18 @@ import java.util.Set; * @see org.springframework.stereotype.Controller * @since GemFire 8.0 */ - @Controller("functionController") @Api(value = "functions", description = "Rest api for gemfire function execution") @RequestMapping(FunctionAccessController.REST_API_VERSION + "/functions") @SuppressWarnings("unused") public class FunctionAccessController extends AbstractBaseController { // Constant String value indicating the version of the REST API. - protected static final String REST_API_VERSION = "/v1"; + static final String REST_API_VERSION = "/v1"; private static final Logger logger = LogService.getLogger(); /** * Gets the version of the REST API implemented by this @Controller. - * <p> - * + * * @return a String indicating the REST API version. */ @Override @@ -256,4 +254,3 @@ public class FunctionAccessController extends AbstractBaseController { } } } - http://git-wip-us.apache.org/repos/asf/geode/blob/47d8c820/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 3b08c5f..a6f10b1 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; @@ -38,19 +36,20 @@ 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 * region - * <p/> - * + * * @see org.springframework.stereotype.Controller * @since GemFire 8.0 */ - @Controller("pdxCrudController") @Api(value = "region", description = "region CRUD operations") @RequestMapping(PdxBasedCrudController.REST_API_VERSION) @@ -59,9 +58,9 @@ public class PdxBasedCrudController extends CommonCrudController { private static final Logger logger = LogService.getLogger(); - protected static final String REST_API_VERSION = "/v1"; + static final String REST_API_VERSION = "/v1"; - protected static final String DEFAULT_GETALL_RESULT_LIMIT = "50"; + private static final String DEFAULT_GETALL_RESULT_LIMIT = "50"; @Override protected String getRestApiVersion() { @@ -76,7 +75,6 @@ public class PdxBasedCrudController extends CommonCrudController { * @param json JSON document that is stored against the key * @return JSON document */ - @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", http://git-wip-us.apache.org/repos/asf/geode/blob/47d8c820/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 b00a7aa..8007491 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 @@ -12,28 +12,14 @@ * or implied. See the License for the specific language governing permissions and limitations under * the License. */ - 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.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; import org.apache.logging.log4j.Logger; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; @@ -49,17 +35,28 @@ 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 - * <p/> - * + * * @see org.springframework.stereotype.Controller * @since GemFire 8.0 */ - @Controller("queryController") @Api(value = "queries", description = "Rest api for geode query execution", produces = MediaType.APPLICATION_JSON_VALUE) @@ -69,17 +66,16 @@ public class QueryAccessController extends AbstractBaseController { private static final Logger logger = LogService.getLogger(); - protected static final String PARAMETERIZED_QUERIES_REGION = "__ParameterizedQueries__"; + private static final String PARAMETERIZED_QUERIES_REGION = "__ParameterizedQueries__"; private final ConcurrentHashMap<String, DefaultQuery> compiledQueries = new ConcurrentHashMap<>(); // Constant String value indicating the version of the REST API. - protected static final String REST_API_VERSION = "/v1"; + static final String REST_API_VERSION = "/v1"; /** * Gets the version of the REST API implemented by this @Controller. - * <p/> - * + * * @return a String indicating the REST API version. */ @Override @@ -324,7 +320,6 @@ public class QueryAccessController extends AbstractBaseController { logger.debug("Updating a named, parametrized Query ({}) with ID ({})...", oqlStatement, queryId); - // update the OQL statement with 'queryId' as the Key into the hidden, Parametrized Queries // Region... checkForQueryIdExist(PARAMETERIZED_QUERIES_REGION, queryId); @@ -334,7 +329,6 @@ public class QueryAccessController extends AbstractBaseController { return new ResponseEntity<>(HttpStatus.OK); } - // delete named, parametrized query /** * Delete named, parametrized Query * @@ -360,4 +354,3 @@ public class QueryAccessController extends AbstractBaseController { } } - http://git-wip-us.apache.org/repos/asf/geode/blob/47d8c820/geode-web-api/src/main/java/org/apache/geode/rest/internal/web/controllers/support/CacheProvider.java ---------------------------------------------------------------------- diff --git a/geode-web-api/src/main/java/org/apache/geode/rest/internal/web/controllers/support/CacheProvider.java b/geode-web-api/src/main/java/org/apache/geode/rest/internal/web/controllers/support/CacheProvider.java new file mode 100644 index 0000000..19d2755 --- /dev/null +++ b/geode-web-api/src/main/java/org/apache/geode/rest/internal/web/controllers/support/CacheProvider.java @@ -0,0 +1,22 @@ +/* + * 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 org.apache.geode.rest.internal.web.controllers.support; + +import org.apache.geode.internal.cache.InternalCache; + +public interface CacheProvider { + + InternalCache getInternalCache(); +} http://git-wip-us.apache.org/repos/asf/geode/blob/47d8c820/geode-web-api/src/main/java/org/apache/geode/rest/internal/web/controllers/support/CacheProviderImpl.java ---------------------------------------------------------------------- diff --git a/geode-web-api/src/main/java/org/apache/geode/rest/internal/web/controllers/support/CacheProviderImpl.java b/geode-web-api/src/main/java/org/apache/geode/rest/internal/web/controllers/support/CacheProviderImpl.java new file mode 100644 index 0000000..8c00923 --- /dev/null +++ b/geode-web-api/src/main/java/org/apache/geode/rest/internal/web/controllers/support/CacheProviderImpl.java @@ -0,0 +1,29 @@ +/* + * 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 org.apache.geode.rest.internal.web.controllers.support; + +import org.springframework.stereotype.Component; + +import org.apache.geode.internal.cache.GemFireCacheImpl; +import org.apache.geode.internal.cache.InternalCache; + +@Component("cacheProvider") +public class CacheProviderImpl implements CacheProvider { + + @Override + public InternalCache getInternalCache() { + return GemFireCacheImpl.getExisting(); + } +}