private MessageFromServerToClient HandleFailureReport([NotNull] MessageFromClientToServer req)
        {
            var task = ActiveTasks.FirstOrDefault(x => x.Guid == req.TaskGuid);

            if (task == null)
            {
                throw new DistSimException("Invalid guid: " + req.TaskGuid);
            }

            task.FinishStatusMessage = req.ClientRequest + " " + req.Message;
            SaveExecuteHelper.Get().SaveExecuteWithWait(() => ActiveTasks.Remove(task));
            SaveExecuteHelper.Get().SaveExecuteWithWait(() => FinishedTasks.Add(task));
            _errorLogger.Error(task.OriginalJsonFilePath + " - no output at all at client " + req.ClientName, _threadId);
            Logger.Error(task.OriginalJsonFilePath + " - no output at all at client " + req.ClientName, _threadId);
            return(new MessageFromServerToClient(ServerResponseEnum.JobFinishAck, req.TaskGuid));
        }
Exemple #2
0
        public void Run()
        {
            DirectoryInfo lpgRawDir  = new DirectoryInfo(_settings.ClientSettings.LPGRawDirectory);
            DirectoryInfo workingDir = new DirectoryInfo(_settings.ClientSettings.LPGCalcDirectory);

            if (workingDir.Exists)
            {
                try {
                    workingDir.Delete(true);
                }
                catch (Exception ex) {
                    _logger.Error(ex.Message, _threadId);
                }

                Thread.Sleep(250);
            }

            workingDir.Create();
            FileInfo[] fis = lpgRawDir.GetFiles();
            foreach (FileInfo fi in fis)
            {
                string dstFullName = Path.Combine(workingDir.FullName, fi.Name);
                _logger.Info("DirectoryPreparer: Copying to " + dstFullName, _threadId);
                fi.CopyTo(dstFullName, true);
            }
        }
        public void TryRun()
        {
            try {
                _logger.Info("Started the client " + _threadId.Name + " and connecting to " + _mySettings.ServerIP, _threadId);
                using (var client = new RequestSocket()) {
                    client.Connect(_mySettings.ServerIP);
                    _logger.Info("connected to " + _mySettings.ServerIP, _threadId);
                    while (_mySettings.ContinueRunning)
                    {
                        var calcExecutor = new CalcExecutor(_threadId, _logger, _mySettings);
                        while (calcExecutor.IsWorkingDirFull())
                        {
                            ReportDiskFullAndWait(client);
                            if (!_mySettings.ContinueRunning)
                            {
                                return;
                            }
                        }

                        if (_mySettings.RequestNewJobs)
                        {
                            var job = RequestNewJobFromServer(client);
                            if (job == null)
                            {
                                Thread.Sleep(5000);
                                continue;
                            }

                            // ReSharper disable once SwitchStatementMissingSomeCases
                            switch (job.ServerResponse)
                            {
                            case ServerResponseEnum.NothingToDo:
                                _logger.Info("Client #" + _threadId.Name + ": Nothing to do, waiting 60s.", _threadId);
                                Thread.Sleep(60000);
                                break;

                            case ServerResponseEnum.ServeCalcJob: {
                                if (!AreAllFilesIdentical(job) && !RequestAndSaveNewLPGFiles(client))
                                {
                                    _logger.Error("Failed to synchronize the lpg", _threadId);
                                    continue;
                                }

                                ExecuteCalcJob(job, calcExecutor, client);
                                break;
                            }

                            default:
                                throw new DistSimException("Unknown command");
                            }
                        }
                        else
                        {
                            _logger.Info("Client #" + _threadId.Name + ": Not requesting new jobs, waiting 5s.", _threadId);
                            Thread.Sleep(5000);
                        }
                    }
                }

                _logger.Info("Stopped client " + _threadId.Name, _threadId);
            }
            catch (Exception ex) {
                _logger.Exception(ex, "general failure", _threadId);
                ThreadException = ex;
                throw;
            }
        }
        public void TryRunning()
        {
            try {
                RefreshOpenTasks();
                using (var responseSocket = new ResponseSocket()) {
                    _logger.Info("Started the server", _threadId);
                    responseSocket.Bind(_settings.ServerIP);
                    DateTime lastRefresh = DateTime.Now;
                    while (_settings.ContinueRunning)
                    {
                        if (AutomaticRefresh && (DateTime.Now - lastRefresh).TotalMinutes > 3 && OpenTasks.Count < 500)
                        {
                            lastRefresh = DateTime.Now;
                            RefreshOpenTasks();
                        }

                        try {
                            _logger.Info("Waiting for frame", _threadId);
                            var requestBytes = responseSocket.ReceiveFrameBytes();
                            if (!_settings.ContinueRunning)
                            {
                                _logger.Info("don't continue received, quitting server...", _threadId);
                                return;
                            }

                            string prettySize = AutomationUtili.MakePrettySize(requestBytes.Length);
                            _logger.Info("received a byte[] with a length of " + prettySize, _threadId);
                            MessageFromClientToServer req;
                            try {
                                req = LZ4MessagePackSerializer.Deserialize <MessageFromClientToServer>(requestBytes);
                            }
                            catch (Exception ex) {
                                _logger.Exception(ex, "failed to deserialize string with  " + requestBytes.Length + " bytes", _threadId);
                                AnswerRequest(responseSocket,
                                              new MessageFromServerToClient(ServerResponseEnum.NothingToDo, Guid.NewGuid().ToString()));
                                continue;
                            }

                            _logger.Info("Received: " + req.ClientName + ": " + req.ClientRequest + " ## ", _threadId);
                            MessageFromServerToClient answer;

                            // ReSharper disable once SwitchStatementMissingSomeCases
                            _clients.TrackLastRequest(req);
                            switch (req.ClientRequest)
                            {
                            case ClientRequestEnum.RequestForJob:
                                answer = HandleRequestForJob(req);
                                break;

                            case ClientRequestEnum.ReportFinish:
                                answer = HandleTaskFinishReport(req);
                                break;

                            case ClientRequestEnum.ReportFailure:
                                answer = HandleFailureReport(req);
                                break;

                            case ClientRequestEnum.RequestForLPGFiles:
                                answer = HandleRequestForLpgFiles(req);
                                break;

                            case ClientRequestEnum.ReportDiskspaceFull:
                                answer = HandleDiskFullReport(req);
                                break;

                            default:
                                _logger.Error("Invalid client request: " + req.ClientRequest, _threadId);
                                AnswerRequest(responseSocket,
                                              new MessageFromServerToClient(ServerResponseEnum.NothingToDo, "no idea what you want"));
                                throw new DistSimException("Invalid request");
                            }

                            _logger.Info("Sent: " + req.ClientName + ": " + answer.ServerResponse, _threadId);
                            AnswerRequest(responseSocket, answer);
                            _clients.TrackLastAnswer(req.ClientName, answer);
                        }
                        catch (Exception ex) {
                            ThreadException = ex;
                            _logger.Exception(ex, "Exception in the server thread inner loop: \n" + ex.StackTrace);
                            throw;
                        }
                    }
                }
            }
            catch (Exception ex) {
                ThreadException = ex;
                _logger.Exception(ex, "Exception in the server thread: \n");
                throw;
            }
        }