Esempio n. 1
0
        static void Handle_read(string[] cmd, GSTOREClient client)
        {
            if (cmd.Length < 3)
            {
                Console.WriteLine("Invalid command format!");
                Console.WriteLine("Use: `read <partition_id> <object_id> [<server_id>]`");
                return;
            }

            string partitionId = cmd[1];
            string objectId    = cmd[2];
            string serverId    = string.Empty;

            if (cmd.Length == 4)
            {
                serverId = cmd[3];
            }

            // Console.WriteLine($"read {partitionId} {objectId} {serverId}");
            Console.WriteLine("read " + partitionId + " " + objectId + " " + serverId);



            if (serverId != string.Empty)
            {
                client.ReadObject(partitionId, objectId, serverId);
            }
            else
            {
                client.ReadObject(partitionId, objectId, "-1");
            }
        }
Esempio n. 2
0
        static void Handle_listGlobal(string[] cmd, GSTOREClient client)
        {
            if (cmd.Length != 1)
            {
                Console.WriteLine("Invalid command format!");
                Console.WriteLine("Use: `listGlobal`");
                return;
            }

            Console.WriteLine("listGlobal");
            client.ListGlobal();
        }
Esempio n. 3
0
        static void Handle_listServer(string[] cmd, GSTOREClient client)
        {
            if (cmd.Length != 2)
            {
                Console.WriteLine("Invalid command format!");
                Console.WriteLine("Use: `listServer <server_id>`");
                return;
            }

            string serverId = cmd[1];

            // Console.WriteLine($"listServer {serverId}");
            Console.WriteLine("listServer " + serverId);

            client.ListServer(serverId);
        }
Esempio n. 4
0
        static void CommandDispatcher(string[] cmd, System.IO.StreamReader file, GSTOREClient client)
        {
            switch (cmd[0])
            {
            case "read":
                Handle_read(cmd, client);
                break;

            case "write":
                Handle_write(cmd, client);
                break;

            case "listServer":
                Handle_listServer(cmd, client);
                break;

            case "listGlobal":
                Handle_listGlobal(cmd, client);
                break;

            case "wait":
                Handle_wait(cmd, client);
                break;

            case "begin-repeat":
                List <string[]> commands = new List <string[]>();
                string          line;
                while ((line = file.ReadLine()) != null && !line.Equals("end-repeat"))
                {
                    commands.Add(line.Split());
                }
                if (line == null)
                {
                    Console.WriteLine("Repeat command does not end. Exiting...");
                }
                Handle_repeat(cmd, commands, file, client);
                break;

            case "end-repeat":
                Console.WriteLine("Invalid end-repeat: Not inside repeat statement!");
                break;

            default:
                Console.WriteLine("Command not recognized! >:(");
                break;
            }
        }
Esempio n. 5
0
        static void Handle_wait(string[] cmd, GSTOREClient client)
        {
            if (cmd.Length != 2)
            {
                Console.WriteLine("Invalid command format!");
                Console.WriteLine("Use: `wait <miliseconds>`");
                return;
            }

            string miliseconds = cmd[1];

            // Console.WriteLine($"listServer {miliseconds}");
            Console.WriteLine("wait " + miliseconds);
            if (!int.TryParse(miliseconds, out int n))
            {
                Console.WriteLine("Unable to parse miliseconds");
                Environment.Exit(-1);
            }
            Thread.Sleep(n);
        }
Esempio n. 6
0
        static void Handle_write(string[] cmd, GSTOREClient client)
        {
            if (cmd.Length < 4)
            {
                Console.WriteLine("Invalid command format!");
                Console.WriteLine("Use: `write <partition_id> <object_id> <value>`");
                return;
            }

            // Join value
            string value = String.Join(' ', cmd.Skip(3));

            // Verify if bigger then 4

            string partitionId = cmd[1];
            string objectId    = cmd[2];

            // Console.WriteLine($"write {partitionId} {objectId} {value}");
            Console.WriteLine("write " + partitionId + " " + objectId + " " + value);


            client.WriteObject(partitionId, objectId, value);
        }
Esempio n. 7
0
        static void Handle_repeat(string[] command, List <string[]> commands, System.IO.StreamReader file, GSTOREClient client)
        {
            if (!int.TryParse(command[1], out int n))
            {
                Console.WriteLine("Unable to parse repeat");
                Environment.Exit(-1);
            }

            Console.WriteLine("Iterating " + n + " times");

            for (var i = 1; i <= n; i++)
            {
                foreach (string[] cmd in commands)
                {
                    string[] tmp_command = new string[cmd.Length];
                    for (var arg_ix = 0; arg_ix < cmd.Length; arg_ix++)
                    {
                        tmp_command[arg_ix] = cmd[arg_ix].Replace("$i", i.ToString());
                    }
                    CommandDispatcher(tmp_command, file, client);
                }
            }
        }
Esempio n. 8
0
        static void Main(string[] args)
        {
            if (args.Length != 4)
            {
                Console.WriteLine("Usage: Client.exe <host> <port> <script_file> <id>");
                return;
            }


            if (!int.TryParse(args[1], out int Port))
            {
                Console.WriteLine("Invalid port value");
                return;
            }

            if (!int.TryParse(args[3], out int id))
            {
                Console.WriteLine("Invalid id");
                return;
            }

            AppContext.SetSwitch(
                "System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true);

            string host = args[0];

            var serverIdsByPartition = new ConcurrentDictionary <string, List <string> >();

            var serverUrls = new ConcurrentDictionary <string, string>();

            var crashedServers = new ConcurrentBag <string>();

            var client = new GSTOREClient(id, serverIdsByPartition, serverUrls, crashedServers);

            BoolWrapper continueExecution = new BoolWrapper(false);

            var server = new Grpc.Core.Server
            {
                Services =
                {
                    PuppetMasterClientGrpcService.BindService(new PuppetMasterCommunicationService(serverIdsByPartition, serverUrls, crashedServers, continueExecution))
                },
                Ports = { new ServerPort(host, Port, ServerCredentials.Insecure) }
            };

            server.Start();

            // Lock until information is received
            lock (continueExecution.WaitForInformationLock)
            {
                while (!continueExecution.Value)
                {
                    Monitor.Wait(continueExecution.WaitForInformationLock);
                }
            }

            try {
                string line;

                string filePath = Directory.GetCurrentDirectory() + "\\" + args[2] + ".txt";
                Console.WriteLine("File Path: " + filePath);

                System.IO.StreamReader file = new System.IO.StreamReader(filePath);
                while ((line = file.ReadLine()) != null)
                {
                    string[] cmd = line.Split((char[])null, StringSplitOptions.RemoveEmptyEntries);
                    CommandDispatcher(cmd, file, client);
                }

                file.Close();

                // We need to stay up, in order to respond to status commands by the Puppet Master
                // Start gRPC server of connection with PM
                // For now, just wait for user input
                Console.ReadKey();
            } catch (System.IO.FileNotFoundException) {
                Console.WriteLine("File not found. Exiting...");
            } finally
            {
                Console.ReadKey();
                server.ShutdownAsync().Wait();
            }
        }