public DataProcessingResult CookDataElement(WaLinuxAgentLogParsedEntry data, LogContext context,
                                                    CancellationToken cancellationToken)
        {
            DataProcessingResult result = DataProcessingResult.Processed;

            if (data is LogEntry logEntry)
            {
                logEntries.Add(logEntry);
                this.context = context;
            }
            else
            {
                result = DataProcessingResult.Ignored;
            }

            return(result);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Execution thread method.
 /// </summary>
 protected void ExecThread()
 {
     while (m_QueueNotEmpty.WaitOne())
     {
         while (m_Queue.Count > 0)
         {
             SySal.OperaDb.OperaDbCredentials cred = new SySal.OperaDb.OperaDbCredentials();
             DataProcessingBatchDesc          desc = null;
             System.Exception retX    = null;
             string           retXstr = "";
             m_ExecProc = new System.Diagnostics.Process();
             lock (m_ExecProc)
             {
                 m_ExecProcKilled = false;
                 lock (m_Queue)
                 {
                     desc = (DataProcessingBatchDesc)m_Queue[0];
                 }
                 m_ExecProc.StartInfo.Arguments             = desc.CommandLineArguments;
                 m_ExecProc.StartInfo.FileName              = desc.Filename;
                 m_ExecProc.StartInfo.UseShellExecute       = false;
                 m_ExecProc.StartInfo.RedirectStandardError = true;
                 desc.Started = desc.Finished = System.DateTime.Now;
                 try
                 {
                     cred.DBUserName    = (desc.AliasUsername == null) ? "" : desc.AliasUsername;
                     cred.DBPassword    = (desc.AliasPassword == null) ? "" : desc.AliasPassword;
                     cred.DBServer      = OperaDataProcessingServer.DBServer;
                     cred.OPERAUserName = (desc.Username == null) ? "" : desc.Username;
                     cred.OPERAPassword = (desc.Password == null) ? "" : desc.Password;
                     cred.RecordToEnvironment(m_ExecProc.StartInfo.EnvironmentVariables);
                     desc.Started = System.DateTime.Now;
                     m_ExecProc.Start();
                 }
                 catch (Exception x)
                 {
                     retX = new DataProcessingException("Internal error occurred during process start.", x);
                 }
                 try
                 {
                     m_ExecProc.PriorityClass = OperaDataProcessingServer.LowPriority ? System.Diagnostics.ProcessPriorityClass.BelowNormal : System.Diagnostics.ProcessPriorityClass.Normal;
                     //m_ExecProc.MaxWorkingSet = new System.IntPtr(OperaDataProcessingServer.PeakWorkingSetMB * 1048576);
                 }
                 catch (Exception) { }
             }
             if (retX == null)
             {
                 //do
                 {
                     try
                     {
                         m_ExecProc.Refresh();
                         retXstr += m_ExecProc.StandardError.ReadToEnd();
                         desc.TotalProcessorTime    = m_ExecProc.TotalProcessorTime;
                         desc.PeakVirtualMemorySize = m_ExecProc.PeakVirtualMemorySize;
                         desc.PeakWorkingSet        = m_ExecProc.PeakWorkingSet;
                     }
                     catch (Exception) {}
                 }
                 //while (m_ExecProc.WaitForExit(1000) == false);
                 desc.Finished = System.DateTime.Now;
                 lock (m_ExecProc)
                 {                        /*
                                           *     try
                                           *     {
                                           *             retXstr += m_ExecProc.StandardError.ReadToEnd();
                                           *     }
                                           *     catch (Exception) {}*/
                     if (retXstr == null || retXstr.Length == 0)
                     {
                         retX = null;
                     }
                     else
                     {
                         retX = new DataProcessingException(retXstr);
                     }
                     if (m_ExecProcKilled)
                     {
                         retX = new Exception("Process has been killed.");
                     }
                 }
             }
             else
             {
                 try
                 {
                     retXstr += m_ExecProc.StandardError.ReadToEnd();
                 }
                 catch (Exception) {}
             }
             m_ExecProc = null;
             SySal.OperaDb.OperaDbConnection conn = null;
             lock (m_ResultList)
                 lock (m_Queue)
                 {
                     DataProcessingResult dpr = new DataProcessingResult(desc, m_ResultLiveTime);
                     dpr.Processed = true;
                     dpr.X         = retX;
                     m_ResultList.Add(dpr);
                     m_Queue.RemoveAt(0);
                 }
         }
     }
 }
        public DataProcessingResult ProcessDataElement(T data, TContext context, CancellationToken cancellationToken)
        {
            Guard.NotNull(data, nameof(data));
            Guard.NotNull(context, nameof(context));
            Guard.NotNull(cancellationToken, nameof(cancellationToken));

            Debug.Assert(this.activeCookerRegistry != null);
            Debug.Assert(this.activeReceiveAllDataCookers != null);

            var key = data.GetKey();

            if (!this.activeCookerRegistry.ContainsKey(key) && !this.receiveAllDataCookers.Any())
            {
                return(DataProcessingResult.Ignored);
            }

            DataProcessingResult ProcessDataCookers(IEnumerable <ISourceDataCooker <T, TContext, TKey> > cookers)
            {
                DataProcessingResult dataResult = DataProcessingResult.Ignored;

                foreach (var sourceDataCooker in cookers)
                {
                    var result = sourceDataCooker.CookDataElement(data, context, cancellationToken);
                    if (result == DataProcessingResult.CorruptData)
                    {
                        return(result);
                    }

                    if (result == DataProcessingResult.Processed)
                    {
                        dataResult = result;
                    }
                }

                return(dataResult);
            }

            var keyedResult = DataProcessingResult.Ignored;

            if (this.activeCookerRegistry.ContainsKey(key))
            {
                var sourceDataCookers = this.activeCookerRegistry[key];
                keyedResult = ProcessDataCookers(sourceDataCookers);
                if (keyedResult == DataProcessingResult.CorruptData)
                {
                    return(keyedResult);
                }
            }

            var allDataResult = ProcessDataCookers(this.activeReceiveAllDataCookers);

            if (allDataResult == DataProcessingResult.CorruptData)
            {
                return(allDataResult);
            }

            if (keyedResult == DataProcessingResult.Processed || allDataResult == DataProcessingResult.Processed)
            {
                return(DataProcessingResult.Processed);
            }

            return(DataProcessingResult.Ignored);
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Draws a batch out ouf the queue or aborts it if it is already being executed.
 /// A non-null token or a username/password pair must be supplied that matches the one with which the batch was started.
 /// If the token is supplied, the username/password pair is ignored.
 /// </summary>
 /// <param name="id">identifier of the batch to be removed.</param>
 /// <param name="token">the process token to be used.</param>
 /// <param name="user">username of the user that started the batch. Ignored if <c>token</c> is non-null.</param>
 /// <param name="password">password of the user that started the batch. Ignored if <c>token</c> is non-null.</param>
 public void Remove(ulong id, string token, string user, string password)
 {
     lock (m_Queue)
     {
         int i;
         for (i = 0; i < m_Queue.Count && ((DataProcessingBatchDesc)m_Queue[i]).Id != id; i++)
         {
             ;
         }
         if (i == m_Queue.Count)
         {
             throw new Exception("Batch not present in processing queue.");
         }
         DataProcessingBatchDesc dpb = (DataProcessingBatchDesc)m_Queue[i];
         bool OkToRemove             = false;
         if (token != null)
         {
             if (dpb.Token != null)
             {
                 if (dpb.Token == token)
                 {
                     OkToRemove = true;
                 }
                 else
                 {
                     throw new Exception("A process operation cannot remove a batch of another process operation.");
                 }
             }
             else
             {
                 throw new Exception("A process operation cannot remove a batch that has been started with a specific user request.");
             }
         }
         else
         {
             long id_user = 0;
             SySal.OperaDb.OperaDbConnection conn = null;
             try
             {
                 conn = new SySal.OperaDb.OperaDbConnection(OperaDataProcessingServer.DBServer, OperaDataProcessingServer.DBUserName, OperaDataProcessingServer.DBPassword);
                 conn.Open();
                 id_user = SySal.OperaDb.ComputingInfrastructure.User.CheckLogin(user, password, conn, null);
                 if (dpb.Token != null)
                 {
                     try
                     {
                         SySal.OperaDb.ComputingInfrastructure.User.CheckTokenOwnership(dpb.Token, id_user, null, null, conn, null);
                         OkToRemove = true;
                     }
                     catch (Exception)
                     {
                         throw new Exception("A user cannot remove a batch started by an operation of another user.");
                     }
                 }
                 else
                 {
                     if (String.Compare(dpb.Username, user, true) != 0)
                     {
                         throw new Exception("A user cannot stop a batch scheduled by another user!");
                     }
                     else
                     {
                         OkToRemove = true;
                     }
                 }
             }
             catch (Exception)
             {
                 if (conn != null)
                 {
                     conn.Close();
                 }
             }
         }
         if (OkToRemove == false)
         {
             throw new Exception("Cannot remove the batch.");
         }
         if (i == 0)
         {
             try
             {
                 m_ExecProc.Kill();
                 m_ExecProcKilled = true;
             }
             catch (Exception) {}
         }
         else
         {
             lock (m_ResultList)
             {
                 m_Queue.RemoveAt(i);
                 DataProcessingResult dpr = null;
                 for (i = 0; i < m_ResultList.Count; i++)
                 {
                     dpr = (DataProcessingResult)m_ResultList[i];
                     if (dpr.Desc.Id == id)
                     {
                         return;
                     }
                 }
                 dpr           = new DataProcessingResult(dpb, m_ResultLiveTime);
                 dpr.X         = new Exception("The batch was removed from the queue.");
                 dpr.Processed = true;
                 m_ResultList.Add(dpr);
             }
         }
     }
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Draws a batch out ouf the queue or aborts it if it is already being executed.
 /// A non-null token or a username/password pair must be supplied that matches the one with which the batch was started.
 /// If the token is supplied, the username/password pair is ignored.
 /// </summary>
 /// <param name="id">identifier of the batch to be removed.</param>
 /// <param name="token">the process token to be used.</param>
 /// <param name="user">username of the user that started the batch. Ignored if <c>token</c> is non-null.</param>
 /// <param name="password">password of the user that started the batch. Ignored if <c>token</c> is non-null.</param>
 public void Remove(ulong id, string token, string user, string password)
 {
     lock (m_Queue)
     {
         int i;
         for (i = 0; i < m_Queue.Count; i++)
         {
             SySal.DAQSystem.DataProcessingBatchDesc desc = (SySal.DAQSystem.DataProcessingBatchDesc)m_Queue[i];
             bool OkToRemove = false;
             if (desc.Id == id)
             {
                 if (token != null)
                 {
                     if (desc.Token != null)
                     {
                         if (desc.Token == token)
                         {
                             OkToRemove = true;
                         }
                         else
                         {
                             throw new Exception("A process operation cannot remove a batch of another process operation.");
                         }
                     }
                     else
                     {
                         throw new Exception("A process operation cannot remove a batch that has been started with a specific user request.");
                     }
                 }
                 else
                 {
                     long id_user = 0;
                     SySal.OperaDb.OperaDbConnection conn = null;
                     try
                     {
                         conn = new SySal.OperaDb.OperaDbConnection(MainForm.DBServer, MainForm.DBUserName, MainForm.DBPassword);
                         conn.Open();
                         id_user = SySal.OperaDb.ComputingInfrastructure.User.CheckLogin(user, password, conn, null);
                         if (desc.Token != null)
                         {
                             try
                             {
                                 SySal.OperaDb.ComputingInfrastructure.User.CheckTokenOwnership(desc.Token, id_user, null, null, conn, null);
                                 OkToRemove = true;
                             }
                             catch (Exception)
                             {
                                 throw new Exception("A user cannot remove a batch started by an operation of another user.");
                             }
                         }
                         else
                         {
                             if (String.Compare(desc.Username, user, true) != 0)
                             {
                                 throw new Exception("A user cannot stop a batch scheduled by another user!");
                             }
                             else
                             {
                                 OkToRemove = true;
                             }
                         }
                     }
                     catch (Exception)
                     {
                         if (conn != null)
                         {
                             conn.Close();
                         }
                     }
                 }
                 if (OkToRemove == false)
                 {
                     throw new Exception("Cannot remove the batch.");
                 }
                 else
                 {
                     DataProcessingResult dpr = new DataProcessingResult(desc, new Exception("The batch was removed from the queue."), m_ResultLiveTime);
                     dpr.Processed = true;
                     m_ResultList.Add(dpr);
                     m_Queue.RemoveAt(i);
                     for (i = 0; i < m_ExeList.Count; i++)
                     {
                         if (((ExeBatch)m_ExeList[i]).Desc.Id == id)
                         {
                             ExeBatch exe = (ExeBatch)m_ExeList[i];
                             try
                             {
                                 exe.DPSW.Remove(exe.MappedDesc.Id, exe.MappedDesc.Token, exe.MappedDesc.Username, exe.MappedDesc.Password);
                             }
                             catch (Exception) {}
                             m_ExeList.RemoveAt(i);
                         }
                     }
                     return;
                 }
             }
         }
     }
 }