Exemplo n.º 1
0
        private Task <DataTable> RelayReadCommand(string podName, ReadCommand command, IConnectionManager connection)
        {
            return(Task.Run <DataTable>(() =>
            {
                V1Pod pod = GetWorkerPod(podName);
                if (string.IsNullOrEmpty(pod.Status.PodIP))
                {
                    throw new NotImplementedException("Pod IP not set.");
                }

                // Create a new socket connection to the pod.
                string ip = pod.Status.PodIP;
                ushort port = GetPortNo(pod);
                WriteToLog($"Attempting connection to pod {podName} on {ip}:{port}");
                using (NetworkSocketClient conn = new NetworkSocketClient(relayOptions.Verbose, ip, port, Protocol.Managed))
                {
                    WriteToLog($"Connection to {podName} established. Sending command...");

                    // Relay the command to the pod.
                    try
                    {
                        return conn.ReadOutput(command);
                    }
                    catch (Exception err)
                    {
                        throw new Exception($"Unable to read output from pod {podName}", err);
                    }
                }
            }));
        }
Exemplo n.º 2
0
        private Task RelayCommand(string podName, ICommand command, IConnectionManager connection)
        {
            return(Task.Run(() =>
            {
                V1Pod pod = GetWorkerPod(podName);
                if (string.IsNullOrEmpty(pod.Status.PodIP))
                {
                    throw new NotImplementedException("Pod IP not set.");
                }

                // Create a new socket connection to the pod.
                string ip = pod.Status.PodIP;
                ushort port = GetPortNo(pod);
                WriteToLog($"Attempting connection to pod {podName} on {ip}:{port}");
                using (NetworkSocketClient conn = new NetworkSocketClient(relayOptions.Verbose, ip, port, Protocol.Managed))
                {
                    WriteToLog($"Connection to {podName} established. Sending command...");

                    // Relay the command to the pod.
                    conn.SendCommand(command);

                    WriteToLog($"Closing connection to {podName}...");
                }
            }));
        }
Exemplo n.º 3
0
        /// <summary>
        /// We've received a command. Instead of running it, we instead
        /// relay the command to each worker pod.
        /// </summary>
        /// <param name="command">Command to be run.</param>
        /// <param name="connection">Connection on which we received the command.</param>
        protected override void RunCommand(ICommand command, IConnectionManager connection)
        {
            // Relay the command to all workers.
            if (command is ReadCommand readCommand)
            {
                DoReadCommand(readCommand, connection);
                return;
            }

            foreach (string podName in workers)
            {
                V1Pod pod = GetWorkerPod(podName);
                if (string.IsNullOrEmpty(pod.Status.PodIP))
                {
                    throw new NotImplementedException("Pod IP not set.");
                }

                // Create a new socket connection to the pod.
                string ip = pod.Status.PodIP;
                WriteToLog($"Attempting connection to pod {podName} on {ip}:{portNo}");
                using (NetworkSocketClient conn = new NetworkSocketClient(relayOptions.Verbose, ip, portNo, Protocol.Managed))
                {
                    WriteToLog($"Connection to {podName} established. Sending command...");

                    // Relay the command to the pod.
                    conn.SendCommand(command);

                    WriteToLog($"Closing connection to {podName}...");
                }
            }
            connection.OnCommandFinished(command);
        }
Exemplo n.º 4
0
        private void DoReadCommand(ReadCommand command, IConnectionManager connection)
        {
            List <DataTable> tables = new List <DataTable>();

            foreach (string podName in workers)
            {
                V1Pod pod = GetWorkerPod(podName);
                if (string.IsNullOrEmpty(pod.Status.PodIP))
                {
                    throw new NotImplementedException("Pod IP not set.");
                }

                // Create a new socket connection to the pod.
                string ip = pod.Status.PodIP;
                WriteToLog($"Attempting connection to pod {podName} on {ip}:{portNo}");
                using (NetworkSocketClient conn = new NetworkSocketClient(relayOptions.Verbose, ip, portNo, Protocol.Managed))
                {
                    WriteToLog($"Connection to {podName} established. Sending command...");

                    // Relay the command to the pod.
                    try
                    {
                        tables.Add(conn.ReadOutput(command));
                    }
                    catch (Exception err)
                    {
                        WriteToLog($"Unable to read output from pod {podName}:");
                        WriteToLog(err.ToString());
                    }

                    WriteToLog($"Closing connection to {podName}...");
                }
            }
            WriteToLog($"Merging {tables.Count} DataTables (from {workers.Count()} pods)...");
            command.Result = DataTableUtilities.Merge(tables);
            connection.OnCommandFinished(command);
        }