/// <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; } } } } }
/// <summary> /// Schedules batches onto DataProcessingServers. /// </summary> protected void FeedDataProcessingServers() { if (m_ExeList.Count < m_DPSHandlers.Length) { lock (m_Queue) { if (m_Queue.Count > m_ExeList.Count) { DataProcSrvHandler [] l_AvDPSHandlers = (DataProcSrvHandler [])m_DPSHandlers.Clone(); int i, j; for (j = 0; j < m_ExeList.Count; j++) { for (i = 0; i < l_AvDPSHandlers.Length; i++) { if (l_AvDPSHandlers[i] != null && l_AvDPSHandlers[i].Srv == ((ExeBatch)m_ExeList[j]).DPSW) { l_AvDPSHandlers[i] = null; break; } } } for (i = 0; i < m_Queue.Count; i++) { SySal.DAQSystem.DataProcessingBatchDesc desc = (SySal.DAQSystem.DataProcessingBatchDesc)m_Queue[i]; for (j = 0; j < m_ExeList.Count; j++) { if (((ExeBatch)m_ExeList[j]).Desc == desc) { break; } } if (j == m_ExeList.Count) { for (j = 0; j < l_AvDPSHandlers.Length; j++) { try { if (l_AvDPSHandlers[j] != null && l_AvDPSHandlers[j].IsAvailable && l_AvDPSHandlers[j].MachinePowerClass >= desc.MachinePowerClass) { ExeBatch exe = new ExeBatch(); exe.Desc = desc; exe.MappedDesc = (SySal.DAQSystem.DataProcessingBatchDesc)desc.Clone(); exe.MappedDesc.Id = l_AvDPSHandlers[j].Srv.SuggestId; exe.MappedDesc.Description = exe.Desc.Id.ToString("X16") + " _DPS_REMAP_ " + exe.Desc.Description; if (MainForm.ImpersonateBatchUser == false) { exe.MappedDesc.Username = MainForm.OPERAUserName; exe.MappedDesc.Password = MainForm.OPERAPassword; exe.MappedDesc.Token = null; } exe.DPSW = l_AvDPSHandlers[j].Srv; if (exe.DPSW.Enqueue(exe.MappedDesc) == false) { long ticks = System.DateTime.Now.Ticks; if (ticks < 0) { ticks = -ticks; } exe.MappedDesc.Id = (ulong)ticks; exe.MappedDesc.Description = exe.MappedDesc.Id.ToString("X16") + " _OWN_REMAP_ " + exe.Desc.Description; if (l_AvDPSHandlers[j].Srv.Enqueue(exe.MappedDesc) == false) { m_ResultList.Add(new DataProcessingResult(exe.Desc, new Exception("Unknown error!"), MainForm.ResultLiveTime)); } else { m_ExeList.Add(exe); l_AvDPSHandlers[j] = null; break; } } else { m_ExeList.Add(exe); l_AvDPSHandlers[j] = null; break; } } } catch (Exception) { lock (m_DPSHandlers) { l_AvDPSHandlers[j].Srv = null; l_AvDPSHandlers[j].IsAvailable = false; l_AvDPSHandlers[j].MachinePowerClass = 0; } } } } } } } } }