-
Notifications
You must be signed in to change notification settings - Fork 612
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ISPN-14229 Implement RESP "cluster" commands
* Implements the `CLUSTER SHARDS` command.
- Loading branch information
Showing
12 changed files
with
540 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
{ | ||
"definitions": [ | ||
{ | ||
"protopath": "generated:/:persistence.resp.proto", | ||
"def": { | ||
"messages": [ | ||
{ | ||
"name": "NodeInformation", | ||
"fields": [ | ||
{ | ||
"id": 1, | ||
"name": "name", | ||
"type": "string" | ||
}, | ||
{ | ||
"id": 2, | ||
"name": "address", | ||
"type": "string" | ||
}, | ||
{ | ||
"id": 3, | ||
"name": "port", | ||
"type": "int32", | ||
"options": [ | ||
{ | ||
"name": "default", | ||
"value": "-1" | ||
} | ||
] | ||
} | ||
] | ||
} | ||
], | ||
"package": { | ||
"name": "org.infinispan.persistence.resp" | ||
} | ||
} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
server/resp/src/main/java/org/infinispan/server/resp/cluster/NodeInformation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package org.infinispan.server.resp.cluster; | ||
|
||
import static org.infinispan.commons.marshall.ProtoStreamTypeIds.RESP_NODE_INFORMATION; | ||
|
||
import org.infinispan.protostream.annotations.ProtoFactory; | ||
import org.infinispan.protostream.annotations.ProtoField; | ||
import org.infinispan.protostream.annotations.ProtoTypeId; | ||
|
||
@ProtoTypeId(RESP_NODE_INFORMATION) | ||
public class NodeInformation { | ||
|
||
private final String name; | ||
private final String address; | ||
private final int port; | ||
|
||
@ProtoFactory | ||
public NodeInformation(String name, String address, int port) { | ||
this.name = name; | ||
this.address = address; | ||
this.port = port; | ||
} | ||
|
||
@ProtoField(1) | ||
public String name() { | ||
return name; | ||
} | ||
|
||
@ProtoField(2) | ||
public String address() { | ||
return address; | ||
} | ||
|
||
@ProtoField(value = 3, defaultValue = "-1") | ||
public int port() { | ||
return port; | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
server/resp/src/main/java/org/infinispan/server/resp/commands/CLUSTER.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package org.infinispan.server.resp.commands; | ||
|
||
import org.infinispan.server.resp.RespCommand; | ||
import org.infinispan.server.resp.commands.cluster.SHARDS; | ||
|
||
public class CLUSTER extends FamilyCommand { | ||
|
||
private static final RespCommand[] CLUSTER_COMMANDS; | ||
|
||
static { | ||
CLUSTER_COMMANDS = new RespCommand[] { | ||
new SHARDS() | ||
}; | ||
} | ||
|
||
@Override | ||
public RespCommand[] getFamilyCommands() { | ||
return CLUSTER_COMMANDS; | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
server/resp/src/main/java/org/infinispan/server/resp/commands/FamilyCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package org.infinispan.server.resp.commands; | ||
|
||
import java.util.List; | ||
import java.util.concurrent.CompletionStage; | ||
|
||
import org.infinispan.server.resp.ByteBufferUtils; | ||
import org.infinispan.server.resp.Resp3Handler; | ||
import org.infinispan.server.resp.RespCommand; | ||
import org.infinispan.server.resp.RespRequestHandler; | ||
|
||
import io.netty.channel.ChannelHandlerContext; | ||
|
||
/** | ||
* An umbrella command. | ||
* <p> | ||
* This command represents a family of commands. Usually, the ones with multiple keywords, for example, | ||
* {@link CLUSTER} or ACL. | ||
* | ||
* @since 15.0 | ||
*/ | ||
public abstract class FamilyCommand extends RespCommand implements Resp3Command { | ||
|
||
public FamilyCommand() { | ||
super(0, 0, 0, 0); | ||
} | ||
|
||
@Override | ||
public CompletionStage<RespRequestHandler> perform(Resp3Handler handler, ChannelHandlerContext ctx, List<byte[]> arguments) { | ||
byte[] subCommand = arguments.get(0); | ||
for (RespCommand cmd : getFamilyCommands()) { | ||
if (cmd.match(subCommand)) { | ||
if (cmd instanceof Resp3Command) { | ||
return ((Resp3Command) cmd).perform(handler, ctx, arguments); | ||
} | ||
|
||
if (cmd instanceof AuthResp3Command) { | ||
return ((AuthResp3Command) cmd).perform(handler, ctx, arguments); | ||
} | ||
|
||
break; | ||
} | ||
} | ||
ByteBufferUtils.stringToByteBuf("-ERR unknown command\r\n", handler.allocatorToUse()); | ||
return handler.myStage(); | ||
} | ||
|
||
public abstract RespCommand[] getFamilyCommands(); | ||
} |
Oops, something went wrong.