removed SRSC
This commit is contained in:
parent
e3875f76f6
commit
2ab5a38894
@ -1,99 +0,0 @@
|
||||
package bin.srsc;
|
||||
|
||||
import kernel.KernelSettings;
|
||||
import kernel.net.Package.NetworkID;
|
||||
import lib.CLIAppBase;
|
||||
|
||||
using tink.CoreApi;
|
||||
|
||||
class CLI extends CLIAppBase {
|
||||
public function new() {
|
||||
registerAsyncSubcommand("get", (args) -> {
|
||||
if (args.length < 1) {
|
||||
handle.writeLine("Not enough arguments");
|
||||
return Future.sync(false);
|
||||
}
|
||||
|
||||
var rpc = new SiteRessourceControllerRPC(KernelSettings.siteController);
|
||||
|
||||
return rpc.get(args[0]).map((res) -> {
|
||||
switch (res) {
|
||||
case Success(data):
|
||||
if (data == null) {
|
||||
handle.writeLine("Not found");
|
||||
} else {
|
||||
handle.writeLine("Found: " + data);
|
||||
}
|
||||
case Failure(error):
|
||||
handle.writeLine("Error: " + error);
|
||||
}
|
||||
return true;
|
||||
});
|
||||
}, "<name>");
|
||||
|
||||
registerAsyncSubcommand("register", (args) -> {
|
||||
if (args.length < 2) {
|
||||
handle.writeLine("Not enough arguments");
|
||||
return Future.sync(false);
|
||||
}
|
||||
|
||||
var id:NetworkID = Std.parseInt(args[1]);
|
||||
if (id == null) {
|
||||
handle.writeLine("Invalid id");
|
||||
return Future.sync(false);
|
||||
}
|
||||
|
||||
var rpc = new SiteRessourceControllerRPC(KernelSettings.siteController);
|
||||
|
||||
return rpc.register(args[0], id).map((res) -> {
|
||||
switch (res) {
|
||||
case Success(data):
|
||||
handle.writeLine("Success");
|
||||
case Failure(error):
|
||||
handle.writeLine("Error: " + error);
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
}, "<name> <id>");
|
||||
|
||||
registerAsyncSubcommand("unregister", (args) -> {
|
||||
if (args.length < 1) {
|
||||
handle.writeLine("Not enough arguments");
|
||||
return Future.sync(false);
|
||||
}
|
||||
|
||||
var rpc = new SiteRessourceControllerRPC(KernelSettings.siteController);
|
||||
|
||||
// FIXME
|
||||
return Future.sync(true);
|
||||
// return rpc.unregister(args[0]).map((res) -> {
|
||||
// switch (res) {
|
||||
// case Success(_):
|
||||
// handle.writeLine("Success");
|
||||
// case Failure(error):
|
||||
// handle.writeLine("Error: " + error);
|
||||
// }
|
||||
|
||||
// return true;
|
||||
// });
|
||||
}, "<name>");
|
||||
|
||||
registerAsyncSubcommand("list", (args) -> {
|
||||
var rpc = new SiteRessourceControllerRPC(KernelSettings.siteController);
|
||||
|
||||
return rpc.list().map((res) -> {
|
||||
switch (res) {
|
||||
case Success(data):
|
||||
for (name in data) {
|
||||
handle.writeLine(name);
|
||||
}
|
||||
case Failure(error):
|
||||
handle.writeLine("Error: " + error);
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
@ -1,76 +0,0 @@
|
||||
package bin.srsc;
|
||||
|
||||
import macros.rpc.RPC;
|
||||
import lib.KVStore;
|
||||
import kernel.net.Package;
|
||||
import kernel.ps.ProcessHandle;
|
||||
import kernel.ps.Process;
|
||||
|
||||
using tink.CoreApi;
|
||||
|
||||
/**
|
||||
The SiteRessourceController is responsible for the management of ressources on the site.
|
||||
It makes sure that ressources are have a unique id and that they are not duplicated.
|
||||
It also keeps track of the responsible NetID for each ressource. Kinda like a DNS.
|
||||
**/
|
||||
@:build(macros.rpc.RPC.buildRPC())
|
||||
class SiteRessourceController implements Process {
|
||||
private var handle:ProcessHandle;
|
||||
private var ressources:Map<String, NetworkID>;
|
||||
|
||||
public function new() {}
|
||||
|
||||
public function run(handle:ProcessHandle) {
|
||||
this.handle = handle;
|
||||
|
||||
load();
|
||||
|
||||
RPC.generateRPCPackageHandle();
|
||||
}
|
||||
|
||||
@rpc
|
||||
public function register(name:String, netID:NetworkID):Bool {
|
||||
if (ressources.exists(name) && ressources.get(name) != netID) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ressources.set(name, netID);
|
||||
save();
|
||||
return true;
|
||||
}
|
||||
|
||||
@rpc
|
||||
public function unregister(name:String):Void {
|
||||
if (ressources.exists(name)) {
|
||||
ressources.remove(name);
|
||||
}
|
||||
save();
|
||||
}
|
||||
|
||||
@rpc
|
||||
public function get(name:String):Null<NetworkID> {
|
||||
return ressources.get(name);
|
||||
}
|
||||
|
||||
@rpc
|
||||
public function list():Array<String> {
|
||||
return [for (k in ressources.keys()) k];
|
||||
}
|
||||
|
||||
private function load() {
|
||||
var store = KVStore.getStoreForClass();
|
||||
var data:Null<Map<String, NetworkID>> = store.get("ressources");
|
||||
|
||||
if (data != null) {
|
||||
this.ressources = data;
|
||||
} else {
|
||||
this.ressources = new Map<String, NetworkID>();
|
||||
}
|
||||
}
|
||||
|
||||
private function save() {
|
||||
var store = KVStore.getStoreForClass();
|
||||
store.set("ressources", this.ressources);
|
||||
store.save();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user