Skip to content

Commit

Permalink
Renaming BulkExpand feature to StorageExpand
Browse files Browse the repository at this point in the history
  • Loading branch information
mcweba committed Feb 19, 2016
1 parent ded16b3 commit 4df8d1a
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 61 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ The following methods are supported on leaves (documents):

The following methods are supported on intermediate nodes (collections):
* GET: Returns the list of collection members. Serves JSON and HTML representations.
* POST (BulkExpand): Returns the expanded content of the sub resources of the (collection) resource. The depth is limited to 1 level. See description below
* POST (StorageExpand): Returns the expanded content of the sub resources of the (collection) resource. The depth is limited to 1 level. See description below
* DELETE: Delete the collection and all its members.

Runs either as a module or can be integrated into an existing application by instantiating the RestStorageHandler class directly.

### BulkExpand Feature
### StorageExpand Feature

The BulkExpand feature expands the hierarchical resources and returns them as a single concatenated json resource.
The StorageExpand feature expands the hierarchical resources and returns them as a single concatenated json resource.

Having the following resources in the storage

Expand All @@ -50,7 +50,7 @@ would lead to this result

##### Usage

To use the BulkExpand feature you have to make a POST request to the desired collection to expand having the url paramter **bulkExpand=true**. Also you wil have
To use the StorageExpand feature you have to make a POST request to the desired collection to expand having the url paramter **storageExpand=true**. Also you wil have
to send the names of the subresources in the body of the request. Using the example above, the request would look like this:

**POST /yourStorageURL/collection** with the body:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ public void cleanup(Handler<DocumentResource> handler, String cleanupResourcesAm
}

@Override
public void bulkExpand(String path, String etag, List<String> subResources, Handler<Resource> handler) {
throw new UnsupportedOperationException("Method 'bulkExpand' is not yet implemented for the FileSystemStorage");
public void storageExpand(String path, String etag, List<String> subResources, Handler<Resource> handler) {
throw new UnsupportedOperationException("Method 'storageExpand' is not yet implemented for the FileSystemStorage");
}
}
24 changes: 12 additions & 12 deletions src/main/java/li/chee/vertx/reststorage/RedisStorage.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ public RedisStorage(Vertx vertx, Logger log, JsonObject config) {
luaGetScriptState.loadLuaScript(new RedisCommandDoNothing(), 0);
luaScripts.put(LuaScript.GET, luaGetScriptState);

LuaScriptState luaBulkExpandScriptState = new LuaScriptState(LuaScript.BULK_EXPAND, false);
luaBulkExpandScriptState.loadLuaScript(new RedisCommandDoNothing(), 0);
luaScripts.put(LuaScript.BULK_EXPAND, luaBulkExpandScriptState);
LuaScriptState luaStorageExpandScriptState = new LuaScriptState(LuaScript.STORAGE_EXPAND, false);
luaStorageExpandScriptState.loadLuaScript(new RedisCommandDoNothing(), 0);
luaScripts.put(LuaScript.STORAGE_EXPAND, luaStorageExpandScriptState);

LuaScriptState luaPutScriptState = new LuaScriptState(LuaScript.PUT, false);
luaPutScriptState.loadLuaScript(new RedisCommandDoNothing(), 0);
Expand All @@ -74,7 +74,7 @@ public RedisStorage(Vertx vertx, Logger log, JsonObject config) {
}

private enum LuaScript {
GET("get.lua"), BULK_EXPAND("bulkExpand.lua"), PUT("put.lua"), DELETE("del.lua"), CLEANUP("cleanup.lua");
GET("get.lua"), STORAGE_EXPAND("storageExpand.lua"), PUT("put.lua"), DELETE("del.lua"), CLEANUP("cleanup.lua");

private String file;

Expand Down Expand Up @@ -391,7 +391,7 @@ public void exec(final int executionCounter) {
}

@Override
public void bulkExpand(String path, String etag, List<String> subResources, Handler<Resource> handler) {
public void storageExpand(String path, String etag, List<String> subResources, Handler<Resource> handler) {
final String key = encodePath(path);
List<String> keys = Collections.singletonList(key);
List<String> arguments = Arrays.asList(
Expand All @@ -403,30 +403,30 @@ public void bulkExpand(String path, String etag, List<String> subResources, Hand
StringUtils.join(subResources, ";"),
String.valueOf(subResources.size())
);
reloadScriptIfLoglevelChangedAndExecuteRedisCommand(LuaScript.BULK_EXPAND, new BulkExpand(keys, arguments, handler, etag), 0);
reloadScriptIfLoglevelChangedAndExecuteRedisCommand(LuaScript.STORAGE_EXPAND, new StorageExpand(keys, arguments, handler, etag), 0);
}

/**
* The BulkExpand Command Execution.
* The StorageExpand Command Execution.
* If the get script cannot be found under the sha in luaScriptState, reload the script.
* To avoid infinite recursion, we limit the recursion.
*/
private class BulkExpand implements RedisCommand {
private class StorageExpand implements RedisCommand {

private List<String> keys;
private List<String> arguments;
private Handler<Resource> handler;
private String etag;

public BulkExpand(List<String> keys, List<String> arguments, final Handler<Resource> handler, String etag) {
public StorageExpand(List<String> keys, List<String> arguments, final Handler<Resource> handler, String etag) {
this.keys = keys;
this.arguments = arguments;
this.handler = handler;
this.etag = etag;
}

public void exec(final int executionCounter) {
redisClient.evalsha(luaScripts.get(LuaScript.BULK_EXPAND).getSha(), keys, arguments, event -> {
redisClient.evalsha(luaScripts.get(LuaScript.STORAGE_EXPAND).getSha(), keys, arguments, event -> {
if(event.succeeded()){
Object value = event.result().getValue(0);
if (log.isTraceEnabled()) {
Expand Down Expand Up @@ -474,12 +474,12 @@ public void exec(final int executionCounter) {
} else {
String message = event.cause().getMessage();
if(message != null && message.startsWith("NOSCRIPT")) {
log.warn("bulkExpand script couldn't be found, reload it");
log.warn("storageExpand script couldn't be found, reload it");
log.warn("amount the script got loaded: " + String.valueOf(executionCounter));
if(executionCounter > 10) {
log.error("amount the script got loaded is higher than 10, we abort");
} else {
luaScripts.get(LuaScript.BULK_EXPAND).loadLuaScript(new BulkExpand(keys, arguments, handler, etag), executionCounter);
luaScripts.get(LuaScript.STORAGE_EXPAND).loadLuaScript(new StorageExpand(keys, arguments, handler, etag), executionCounter);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class RestStorageHandler implements Handler<HttpServerRequest> {

private static final String OFFSET_PARAMETER = "offset";
private static final String LIMIT_PARAMETER = "limit";
private static final String BULK_EXPAND_PARAMETER = "bulkExpand";
private static final String STORAGE_EXPAND_PARAMETER = "storageExpand";
private static final String CONTENT_TYPE = "Content-Type";
private static final String CONTENT_LENGTH = "Content-Length";

Expand Down Expand Up @@ -70,7 +70,7 @@ public RestStorageHandler(Vertx vertx, final Logger log, final Storage storage,
});

router.postWithRegex(prefix + ".*").handler(ctx -> {
if (!ctx.request().params().contains(BULK_EXPAND_PARAMETER)) {
if (!ctx.request().params().contains(STORAGE_EXPAND_PARAMETER)) {
respondWithNotAllowed(ctx.request());
} else {
ctx.request().bodyHandler(new Handler<Buffer>() {
Expand All @@ -89,13 +89,13 @@ public void handle(Buffer event) {
subResourceNames.add(subResourcesArray.getString(i));
}
} catch(RuntimeException ex){
respondWithBadRequest(ctx.request(), "Bad Request: Unable to parse body of bulkExpand POST request");
respondWithBadRequest(ctx.request(), "Bad Request: Unable to parse body of storageExpand POST request");
return;
}

final String path = cleanPath(ctx.request().path().substring(prefix.length()));
final String etag = ctx.request().headers().get(IF_NONE_MATCH_HEADER);
storage.bulkExpand(path, etag, subResourceNames, resource -> {
storage.storageExpand(path, etag, subResourceNames, resource -> {

if(resource.invalid){
ctx.response().setStatusCode(INTERNAL_SERVER_ERROR.getStatusCode());
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/li/chee/vertx/reststorage/Storage.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public interface Storage {

void get(String path, String etag, int offset, int count, Handler<Resource> handler);

void bulkExpand(String path, String etag, List<String> subResources, Handler<Resource> handler);
void storageExpand(String path, String etag, List<String> subResources, Handler<Resource> handler);

void put(String path, String etag, boolean merge, long expire, Handler<Resource> handler);

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@


@RunWith(VertxUnitRunner.class)
public class BulkExpandTest extends AbstractTestCase {
public class StorageExpandTest extends AbstractTestCase {

final String ETAG_HEADER = "Etag";
final String IF_NONE_MATCH_HEADER = "if-none-match";
final String POST_STORAGE_EXP = "/server/resources?bulkExpand=true";
final String POST_STORAGE_EXP = "/server/resources?storageExpand=true";
final int BAD_REQUEST = 400;
final String BAD_REQUEST_PARSE_MSG = "Bad Request: Unable to parse body of bulkExpand POST request";
final String BAD_REQUEST_PARSE_MSG = "Bad Request: Unable to parse body of storageExpand POST request";

@Before
public void setPath() {
Expand Down
Loading

0 comments on commit 4df8d1a

Please sign in to comment.