Changeset 1468
- Timestamp:
- 03/31/09 01:33:37 (15 years ago)
- Location:
- trunk/sources
- Files:
-
- 14 added
- 4 deleted
- 25 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.DataAccess.ADOHelper/DataAdapterBase.cs
r1449 r1468 34 34 where ObjT : IPersistableObject, new() { 35 35 36 private ISession session; 37 38 private IDataAdapterWrapper<AdapterT, ObjT, RowT> dataAdapter; 39 36 40 private static Mutex lockersMutex = 37 41 new Mutex(); … … 42 46 private static IDictionary<object, int> lockCount = 43 47 new Dictionary<object, int>(); 48 49 protected DataAdapterBase( 50 IDataAdapterWrapper<AdapterT, ObjT, RowT> dataAdapter) { 51 this.dataAdapter = dataAdapter; 52 } 44 53 45 54 protected void LockRow(object id) { … … 79 88 protected AdapterT Adapter { 80 89 get { 81 return new AdapterT(); 90 return dataAdapter.TransactionalAdapter; 91 } 92 } 93 94 public ISession Session { 95 get { 96 return this.session; 97 } 98 99 set { 100 this.session = value; 101 this.dataAdapter.Session = value; 102 } 103 } 104 105 public object InnerAdapter { 106 get { 107 return this.Adapter; 82 108 } 83 109 } … … 87 113 88 114 protected abstract ObjT ConvertRow(RowT row, ObjT obj); 89 90 protected abstract RowT InsertNewRow(ObjT obj);91 92 protected abstract void UpdateRow(RowT row);93 94 protected abstract IEnumerable<RowT> FindById(Guid id);95 96 protected abstract IEnumerable<RowT> FindAll();97 115 #endregion 98 116 … … 112 130 } 113 131 114 protected virtualRowT FindSingleRow(Selector selector) {132 protected RowT FindSingleRow(Selector selector) { 115 133 RowT row = default(RowT); 116 134 … … 124 142 } 125 143 126 protected virtual ObjT FindSingle(Selector selector) { 127 RowT row = FindSingleRow(selector); 128 129 if (row != null) { 130 ObjT obj = new ObjT(); 131 obj = Convert(row, obj); 132 133 return obj; 134 } else { 135 return default(ObjT); 136 } 137 } 138 139 protected virtual ICollection<ObjT> FindMultiple(Selector selector) { 140 IEnumerable<RowT> found = 141 selector(); 142 143 IList<ObjT> result = 144 new List<ObjT>(); 145 146 foreach (RowT row in found) { 147 ObjT obj = new ObjT(); 148 obj = Convert(row, obj); 149 if(obj != null) 150 result.Add(obj); 151 } 152 153 return result; 144 protected ObjT FindSingle(Selector selector) { 145 ITransaction trans = 146 session.GetTransactionForCurrentThread(); 147 bool transactionExists = trans != null; 148 if (!transactionExists) { 149 trans = session.BeginTransaction(); 150 } 151 152 try { 153 RowT row = FindSingleRow(selector); 154 155 ObjT result; 156 if (row != null) { 157 ObjT obj = new ObjT(); 158 obj = Convert(row, obj); 159 160 result = obj; 161 } else { 162 result = default(ObjT); 163 } 164 165 return result; 166 } 167 finally { 168 if (!transactionExists && trans != null) { 169 trans.Commit(); 170 } 171 } 172 } 173 174 protected ICollection<ObjT> FindMultiple(Selector selector) { 175 ITransaction trans = 176 session.GetTransactionForCurrentThread(); 177 bool transactionExists = trans != null; 178 if (!transactionExists) { 179 trans = session.BeginTransaction(); 180 } 181 182 try { 183 IEnumerable<RowT> found = 184 selector(); 185 186 IList<ObjT> result = 187 new List<ObjT>(); 188 189 foreach (RowT row in found) { 190 ObjT obj = new ObjT(); 191 obj = Convert(row, obj); 192 if (obj != null) 193 result.Add(obj); 194 } 195 196 return result; 197 } 198 finally { 199 if (!transactionExists && trans != null) { 200 trans.Commit(); 201 } 202 } 154 203 } 155 204 … … 157 206 return FindSingleRow( 158 207 delegate() { 159 return FindById(id);208 return dataAdapter.FindById(id); 160 209 }); 161 210 } 162 211 163 p ublic virtual voidUpdate(ObjT obj) {212 protected virtual void doUpdate(ObjT obj) { 164 213 if (obj != null) { 165 214 RowT row = null; … … 176 225 177 226 if (row == null) { 178 row = InsertNewRow(obj); 179 UpdateRow(row); 227 row = dataAdapter.InsertNewRow(obj); 180 228 } 181 229 … … 186 234 187 235 ConvertObj(obj, row); 188 UpdateRow(row);236 dataAdapter.UpdateRow(row); 189 237 190 238 UnlockRow(locked); 239 } 240 } 241 242 public void Update(ObjT obj) { 243 ITransaction trans = 244 session.GetTransactionForCurrentThread(); 245 bool transactionExists = trans != null; 246 if (!transactionExists) { 247 trans = session.BeginTransaction(); 248 } 249 250 try { 251 doUpdate(obj); 252 } 253 finally { 254 if (!transactionExists && trans != null) { 255 trans.Commit(); 256 } 191 257 } 192 258 } … … 194 260 public virtual ObjT GetById(Guid id) { 195 261 return FindSingle(delegate() { 196 return FindById(id);262 return dataAdapter.FindById(id); 197 263 }); 198 264 } … … 201 267 return new List<ObjT>( 202 268 FindMultiple( 203 new Selector( FindAll)));204 } 205 206 p ublic virtual boolDelete(ObjT obj) {269 new Selector(dataAdapter.FindAll))); 270 } 271 272 protected virtual bool doDelete(ObjT obj) { 207 273 bool success = false; 208 274 209 275 if (obj != null) { 210 276 LockRow(obj.Id); … … 215 281 if (row != null) { 216 282 row.Delete(); 217 UpdateRow(row);283 dataAdapter.UpdateRow(row); 218 284 219 285 success = true; … … 224 290 225 291 return success; 292 } 293 294 public bool Delete(ObjT obj) { 295 ITransaction trans = 296 session.GetTransactionForCurrentThread(); 297 bool transactionExists = trans != null; 298 if (!transactionExists) { 299 trans = session.BeginTransaction(); 300 } 301 302 try { 303 return doDelete(obj); 304 } 305 finally { 306 if (!transactionExists && trans != null) { 307 trans.Commit(); 308 } 309 } 226 310 } 227 311 } -
trunk/sources/HeuristicLab.DataAccess.ADOHelper/HeuristicLab.DataAccess.ADOHelper.csproj
r1402 r1468 64 64 </ItemGroup> 65 65 <ItemGroup> 66 <Compile Include="CachedDataAdapter.cs" />67 66 <Compile Include="DataAccessADOHelperPlugin.cs" /> 68 67 <Compile Include="DataAdapterBase.cs" /> 68 <Compile Include="DataAdapterWrapperBase.cs" /> 69 <Compile Include="IDataAdapterWrapper.cs" /> 70 <Compile Include="Session.cs" /> 71 <Compile Include="SessionFactory.cs" /> 72 <Compile Include="Transaction.cs" /> 73 <Compile Include="TransactionManager.cs" /> 69 74 </ItemGroup> 70 75 <ItemGroup> -
trunk/sources/HeuristicLab.DataAccess/HeuristicLab.DataAccess.csproj
r1402 r1468 80 80 <ItemGroup> 81 81 <Compile Include="DataAccessPlugin.cs" /> 82 <Compile Include="Interfaces\IDBSynchronizer.cs" /> 82 <Compile Include="Interfaces\ISession.cs" /> 83 <Compile Include="Interfaces\ISessionFactory.cs" /> 84 <Compile Include="Interfaces\ITransaction.cs" /> 85 <Compile Include="Interfaces\ITransactionManager.cs" /> 83 86 <Compile Include="PersistableObject.cs" /> 84 <Compile Include="Interfaces\ICachedDataAdapter.cs" />85 87 <Compile Include="Interfaces\IDataAdapter.cs" /> 86 88 <Compile Include="Interfaces\IPersistableObject.cs" /> 87 <Compile Include="DBSynchronizer.cs" />88 89 </ItemGroup> 89 90 <ItemGroup> … … 139 140 <ItemGroup> 140 141 <Reference Include="System" /> 142 <Reference Include="System.Data" /> 141 143 <Reference Include="System.Runtime.Serialization"> 142 144 <RequiredTargetFramework>3.0</RequiredTargetFramework> 143 145 </Reference> 146 <Reference Include="System.Xml" /> 144 147 </ItemGroup> 145 148 </Project> -
trunk/sources/HeuristicLab.DataAccess/Interfaces/IDataAdapter.cs
r1449 r1468 23 23 using System.Collections.Generic; 24 24 using System.Text; 25 using System.Data.Common; 25 26 26 27 namespace HeuristicLab.DataAccess.Interfaces { … … 52 53 /// <param name="user"></param> 53 54 bool Delete(ObjT obj); 55 56 /// <summary> 57 /// sets the session 58 /// </summary> 59 ISession Session { set; } 54 60 } 55 61 } -
trunk/sources/HeuristicLab.Hive.Contracts/ApplicationConstants.cs
r1369 r1468 28 28 public class ApplicationConstants { 29 29 30 public static int HEARTBEAT_MAX_DIF = 30; // value in seconds30 public static int HEARTBEAT_MAX_DIF = 120; // value in seconds 31 31 32 32 public static string RESPONSE_SERVERCONSOLE_LOGIN_SUCCESS = "Logged in"; -
trunk/sources/HeuristicLab.Hive.Contracts/Interfaces/ILifecycleManager.cs
r1377 r1468 52 52 53 53 /// <summary> 54 /// Gets the transaction manager55 /// </summary>56 /// <returns></returns>57 IDBSynchronizer GetDBSynchronizer();58 59 /// <summary>60 54 /// Shuts the application down 61 55 /// </summary> -
trunk/sources/HeuristicLab.Hive.Server.ADODataAccess/ClientAdapter.cs
r1449 r1468 29 29 using HeuristicLab.DataAccess.Interfaces; 30 30 using HeuristicLab.DataAccess.ADOHelper; 31 using HeuristicLab.Hive.Server.ADODataAccess.dsHiveServerTableAdapters; 32 using System.Data.Common; 33 using System.Data.SqlClient; 31 34 32 35 namespace HeuristicLab.Hive.Server.ADODataAccess { 36 class ClientAdapterWrapper : 37 DataAdapterWrapperBase< 38 dsHiveServerTableAdapters.ClientTableAdapter, 39 ClientInfo, 40 dsHiveServer.ClientRow> { 41 public override void UpdateRow(dsHiveServer.ClientRow row) { 42 TransactionalAdapter.Update(row); 43 } 44 45 public override dsHiveServer.ClientRow 46 InsertNewRow(ClientInfo client) { 47 dsHiveServer.ClientDataTable data = 48 new dsHiveServer.ClientDataTable(); 49 50 dsHiveServer.ClientRow row = data.NewClientRow(); 51 row.ResourceId = client.Id; 52 data.AddClientRow(row); 53 54 return row; 55 } 56 57 public override IEnumerable<dsHiveServer.ClientRow> 58 FindById(Guid id) { 59 return TransactionalAdapter.GetDataById(id); 60 } 61 62 public override IEnumerable<dsHiveServer.ClientRow> 63 FindAll() { 64 return TransactionalAdapter.GetData(); 65 } 66 67 protected override void SetConnection(DbConnection connection) { 68 adapter.Connection = connection as SqlConnection; 69 } 70 71 protected override void SetTransaction(DbTransaction transaction) { 72 adapter.Transaction = transaction as SqlTransaction; 73 } 74 } 75 33 76 class ClientAdapter: 34 CachedDataAdapter<77 DataAdapterBase< 35 78 dsHiveServerTableAdapters.ClientTableAdapter, 36 79 ClientInfo, 37 dsHiveServer.ClientRow, 38 dsHiveServer.ClientDataTable>, 80 dsHiveServer.ClientRow>, 39 81 IClientAdapter { 40 82 #region Fields … … 44 86 get { 45 87 if (resAdapter == null) 46 resAdapter = ServiceLocator.GetResourceAdapter(); 88 resAdapter = 89 this.Session.GetDataAdapter<Resource, IResourceAdapter>(); 47 90 48 91 return resAdapter; … … 55 98 get { 56 99 if (clientGroupAdapter == null) { 57 clientGroupAdapter = ServiceLocator.GetClientGroupAdapter(); 100 clientGroupAdapter = 101 this.Session.GetDataAdapter<ClientGroup, IClientGroupAdapter>(); 58 102 } 59 103 … … 67 111 get { 68 112 if (jobAdapter == null) { 69 jobAdapter = ServiceLocator.GetJobAdapter();113 this.Session.GetDataAdapter<Job, IJobAdapter>(); 70 114 } 71 115 … … 75 119 #endregion 76 120 77 public ClientAdapter(): 78 base(ServiceLocator.GetDBSynchronizer()) { 79 parentAdapters.Add(this.ResAdapter as ICachedDataAdapter); 80 } 81 121 public ClientAdapter(): 122 base(new ClientAdapterWrapper()) { 123 } 82 124 83 125 #region Overrides … … 146 188 } 147 189 148 protected override void UpdateRow(dsHiveServer.ClientRow row) {149 Adapter.Update(row);150 }151 152 protected override dsHiveServer.ClientRow153 InsertNewRow(ClientInfo client) {154 dsHiveServer.ClientDataTable data =155 new dsHiveServer.ClientDataTable();156 157 dsHiveServer.ClientRow row = data.NewClientRow();158 row.ResourceId = client.Id;159 data.AddClientRow(row);160 161 return row;162 }163 164 protected override dsHiveServer.ClientRow165 InsertNewRowInCache(ClientInfo client) {166 dsHiveServer.ClientRow row = cache.NewClientRow();167 row.ResourceId = client.Id;168 cache.AddClientRow(row);169 170 return row;171 }172 173 protected override void FillCache() {174 Adapter.FillByActive(cache);175 }176 177 protected override void SynchronizeWithDb() {178 Adapter.Update(cache);179 }180 181 protected override bool PutInCache(ClientInfo obj) {182 return (obj.State != State.offline && obj.State != State.nullState);183 }184 185 protected override IEnumerable<dsHiveServer.ClientRow>186 FindById(Guid id) {187 return Adapter.GetDataById(id);188 }189 190 protected override dsHiveServer.ClientRow191 FindCachedById(Guid id) {192 return cache.FindByResourceId(id);193 }194 195 protected override IEnumerable<dsHiveServer.ClientRow>196 FindAll() {197 return FindMultipleRows(198 new Selector(Adapter.GetData),199 new Selector(cache.AsEnumerable<dsHiveServer.ClientRow>));200 }201 202 190 #endregion 203 191 204 192 #region IClientAdapter Members 205 p ublic override voidUpdate(ClientInfo client) {193 protected override void doUpdate(ClientInfo client) { 206 194 if (client != null) { 207 195 ResAdapter.Update(client); 208 196 209 base. Update(client);197 base.doUpdate(client); 210 198 } 211 199 } … … 219 207 } 220 208 221 p ublic override boolDelete(ClientInfo client) {209 protected override bool doDelete(ClientInfo client) { 222 210 bool success = false; 223 211 Guid locked = Guid.Empty; … … 240 228 } 241 229 242 success = base. Delete(client) &&230 success = base.doDelete(client) && 243 231 ResAdapter.Delete(client); 244 232 } -
trunk/sources/HeuristicLab.Hive.Server.ADODataAccess/ClientGroupAdapter.cs
r1449 r1468 29 29 using System.Data; 30 30 using HeuristicLab.DataAccess.ADOHelper; 31 using HeuristicLab.Hive.Server.ADODataAccess.dsHiveServerTableAdapters; 32 using System.Data.Common; 33 using System.Data.SqlClient; 31 34 32 35 namespace HeuristicLab.Hive.Server.ADODataAccess { 36 class ClientGroupAdapterWrapper : 37 DataAdapterWrapperBase<dsHiveServerTableAdapters.ClientGroupTableAdapter, 38 ClientGroup, 39 dsHiveServer.ClientGroupRow> { 40 public override dsHiveServer.ClientGroupRow 41 InsertNewRow(ClientGroup group) { 42 dsHiveServer.ClientGroupDataTable data = 43 new dsHiveServer.ClientGroupDataTable(); 44 45 dsHiveServer.ClientGroupRow row = 46 data.NewClientGroupRow(); 47 48 row.ResourceId = group.Id; 49 50 data.AddClientGroupRow(row); 51 TransactionalAdapter.Update(row); 52 53 return row; 54 } 55 56 public override void 57 UpdateRow(dsHiveServer.ClientGroupRow row) { 58 TransactionalAdapter.Update(row); 59 } 60 61 public override IEnumerable<dsHiveServer.ClientGroupRow> 62 FindById(Guid id) { 63 return TransactionalAdapter.GetDataById(id); 64 } 65 66 public override IEnumerable<dsHiveServer.ClientGroupRow> 67 FindAll() { 68 return TransactionalAdapter.GetData(); 69 } 70 71 protected override void SetConnection(DbConnection connection) { 72 adapter.Connection = connection as SqlConnection; 73 } 74 75 protected override void SetTransaction(DbTransaction transaction) { 76 adapter.Transaction = transaction as SqlTransaction; 77 } 78 } 79 33 80 class ClientGroupAdapter : 34 81 DataAdapterBase<dsHiveServerTableAdapters.ClientGroupTableAdapter, … … 45 92 get { 46 93 if (resourceAdapter == null) 47 resourceAdapter = ServiceLocator.GetResourceAdapter(); 94 resourceAdapter = 95 this.Session.GetDataAdapter<Resource, IResourceAdapter>(); 48 96 49 97 return resourceAdapter; … … 56 104 get { 57 105 if (clientAdapter == null) 58 clientAdapter = ServiceLocator.GetClientAdapter(); 106 clientAdapter = 107 this.Session.GetDataAdapter<ClientInfo, IClientAdapter>(); 59 108 60 109 return clientAdapter; … … 62 111 } 63 112 #endregion 113 114 public ClientGroupAdapter(): 115 base(new ClientGroupAdapterWrapper()) { 116 } 64 117 65 118 #region Overrides … … 199 252 return row; 200 253 } 201 202 protected override dsHiveServer.ClientGroupRow203 InsertNewRow(ClientGroup group) {204 dsHiveServer.ClientGroupDataTable data =205 new dsHiveServer.ClientGroupDataTable();206 207 dsHiveServer.ClientGroupRow row =208 data.NewClientGroupRow();209 210 row.ResourceId = group.Id;211 212 data.AddClientGroupRow(row);213 Adapter.Update(row);214 215 return row;216 }217 218 protected override void219 UpdateRow(dsHiveServer.ClientGroupRow row) {220 Adapter.Update(row);221 }222 223 protected override IEnumerable<dsHiveServer.ClientGroupRow>224 FindById(Guid id) {225 return Adapter.GetDataById(id);226 }227 228 protected override IEnumerable<dsHiveServer.ClientGroupRow>229 FindAll() {230 return Adapter.GetData();231 }232 254 #endregion 233 255 234 256 #region IClientGroupAdapter Members 235 p ublic override voidUpdate(ClientGroup group) {257 protected override void doUpdate(ClientGroup group) { 236 258 if (group != null) { 237 259 ResAdapter.Update(group); 238 260 239 base. Update(group);261 base.doUpdate(group); 240 262 } 241 263 } … … 272 294 } 273 295 274 p ublic override boolDelete(ClientGroup group) {296 protected override bool doDelete(ClientGroup group) { 275 297 if (group != null) { 276 return base. Delete(group) &&298 return base.doDelete(group) && 277 299 ResAdapter.Delete(group); 278 300 } -
trunk/sources/HeuristicLab.Hive.Server.ADODataAccess/HeuristicLab.Hive.Server.ADODataAccess.csproj
r1377 r1468 119 119 <Name>HeuristicLab.Hive.Contracts</Name> 120 120 </ProjectReference> 121 <ProjectReference Include="..\HeuristicLab.Hive.Server.Core\HeuristicLab.Hive.Server.Core.csproj">122 <Project>{898B31CF-81DC-453B-AEB3-BDF83197A7EE}</Project>123 <Name>HeuristicLab.Hive.Server.Core</Name>124 </ProjectReference>125 121 <ProjectReference Include="..\HeuristicLab.Hive.Server.DataAccess\HeuristicLab.Hive.Server.DataAccess.csproj"> 126 122 <Project>{4D5A2A16-66C2-431D-9AA3-BD3041E64B84}</Project> -
trunk/sources/HeuristicLab.Hive.Server.ADODataAccess/JobAdapter.cs
r1449 r1468 28 28 using System.Linq.Expressions; 29 29 using HeuristicLab.DataAccess.ADOHelper; 30 using HeuristicLab.Hive.Server.ADODataAccess.dsHiveServerTableAdapters; 31 using System.Data.Common; 32 using System.Data.SqlClient; 30 33 31 34 namespace HeuristicLab.Hive.Server.ADODataAccess { 35 class JobAdapterWrapper : 36 DataAdapterWrapperBase<dsHiveServerTableAdapters.JobTableAdapter, 37 Job, 38 dsHiveServer.JobRow> { 39 public override void UpdateRow(dsHiveServer.JobRow row) { 40 TransactionalAdapter.Update(row); 41 } 42 43 public override dsHiveServer.JobRow 44 InsertNewRow(Job job) { 45 dsHiveServer.JobDataTable data = 46 new dsHiveServer.JobDataTable(); 47 48 dsHiveServer.JobRow row = data.NewJobRow(); 49 row.JobId = job.Id; 50 data.AddJobRow(row); 51 52 return row; 53 } 54 55 public override IEnumerable<dsHiveServer.JobRow> 56 FindById(Guid id) { 57 return TransactionalAdapter.GetDataById(id); 58 } 59 60 public override IEnumerable<dsHiveServer.JobRow> 61 FindAll() { 62 return TransactionalAdapter.GetData(); 63 } 64 65 protected override void SetConnection(DbConnection connection) { 66 adapter.Connection = connection as SqlConnection; 67 } 68 69 protected override void SetTransaction(DbTransaction transaction) { 70 adapter.Transaction = transaction as SqlTransaction; 71 } 72 } 73 32 74 class JobAdapter : 33 CachedDataAdapter<dsHiveServerTableAdapters.JobTableAdapter,75 DataAdapterBase<dsHiveServerTableAdapters.JobTableAdapter, 34 76 Job, 35 dsHiveServer.JobRow, 36 dsHiveServer.JobDataTable>, 77 dsHiveServer.JobRow>, 37 78 IJobAdapter { 38 public JobAdapter() :39 base(ServiceLocator.GetDBSynchronizer()) {40 }41 42 79 #region Fields 43 80 private IClientAdapter clientAdapter = null; … … 46 83 get { 47 84 if (clientAdapter == null) 48 clientAdapter = ServiceLocator.GetClientAdapter(); 85 clientAdapter = 86 this.Session.GetDataAdapter<ClientInfo, IClientAdapter>(); 49 87 50 88 return clientAdapter; … … 57 95 get { 58 96 if (resultsAdapter == null) { 59 resultsAdapter = ServiceLocator.GetJobResultsAdapter(); 97 resultsAdapter = 98 this.Session.GetDataAdapter<JobResult, IJobResultsAdapter>(); 60 99 } 61 100 … … 64 103 } 65 104 #endregion 105 106 public JobAdapter(): base(new JobAdapterWrapper()) { 107 } 66 108 67 109 #region Overrides … … 176 218 return row; 177 219 } 178 179 protected override void UpdateRow(dsHiveServer.JobRow row) {180 Adapter.Update(row);181 }182 183 protected override dsHiveServer.JobRow184 InsertNewRow(Job job) {185 dsHiveServer.JobDataTable data =186 new dsHiveServer.JobDataTable();187 188 dsHiveServer.JobRow row = data.NewJobRow();189 row.JobId = job.Id;190 data.AddJobRow(row);191 192 return row;193 }194 195 protected override dsHiveServer.JobRow196 InsertNewRowInCache(Job job) {197 dsHiveServer.JobRow row = cache.NewJobRow();198 row.JobId = job.Id;199 cache.AddJobRow(row);200 201 return row;202 }203 204 protected override void FillCache() {205 Adapter.FillByActive(cache);206 }207 208 protected override void SynchronizeWithDb() {209 this.Adapter.Update(cache);210 }211 212 protected override bool PutInCache(Job job) {213 return job != null214 && (job.State == State.calculating215 || job.State == State.idle);216 }217 218 protected override IEnumerable<dsHiveServer.JobRow>219 FindById(Guid id) {220 return Adapter.GetDataById(id);221 }222 223 protected override dsHiveServer.JobRow224 FindCachedById(Guid id) {225 return cache.FindByJobId(id);226 }227 228 protected override IEnumerable<dsHiveServer.JobRow>229 FindAll() {230 return FindMultipleRows(231 new Selector(Adapter.GetData),232 new Selector(cache.AsEnumerable<dsHiveServer.JobRow>));233 }234 235 220 #endregion 236 221 … … 242 227 delegate() { 243 228 return Adapter.GetDataByParentJob(job.Id); 244 },245 delegate() {246 return from j in247 cache.AsEnumerable<dsHiveServer.JobRow>()248 where !j.IsParentJobIdNull() &&249 j.ParentJobId == job.Id250 select j;251 229 }); 252 230 } … … 260 238 delegate() { 261 239 return Adapter.GetDataByState(state.ToString()); 262 },263 delegate() {264 return from job in265 cache.AsEnumerable<dsHiveServer.JobRow>()266 where !job.IsJobStateNull() &&267 job.JobState == state.ToString()268 select job;269 240 }); 270 241 } … … 276 247 delegate() { 277 248 return Adapter.GetDataByClient(client.Id); 278 },279 delegate() {280 return from job in281 cache.AsEnumerable<dsHiveServer.JobRow>()282 where !job.IsResourceIdNull() &&283 job.ResourceId == client.Id284 select job;285 249 }); 286 250 } … … 296 260 delegate() { 297 261 return Adapter.GetDataByCalculatingClient(client.Id); 298 },299 delegate() {300 return from job in301 cache.AsEnumerable<dsHiveServer.JobRow>()302 where !job.IsResourceIdNull() &&303 job.ResourceId == client.Id &&304 !job.IsJobStateNull() &&305 job.JobState == "calculating"306 select job;307 262 }); 308 263 } … … 311 266 } 312 267 313 public ICollection<Job> GetJobsOf(Guid userId) { 314 throw new NotImplementedException(); 315 268 public ICollection<Job> GetJobsOf(Guid userId) { 316 269 return 317 270 base.FindMultiple( 318 271 delegate() { 319 272 return Adapter.GetDataByUser(userId); 320 }, 321 delegate() { 322 return from job in 323 cache.AsEnumerable<dsHiveServer.JobRow>() 324 where !job.IsUserIdNull() && 325 job.UserId == Guid.Empty 326 select job; 327 }); 328 } 329 330 public override bool Delete(Job job) { 273 }); 274 } 275 276 protected override bool doDelete(Job job) { 331 277 if (job != null) { 332 278 dsHiveServer.JobRow row = … … 342 288 } 343 289 344 return base. Delete(job);290 return base.doDelete(job); 345 291 } 346 292 } -
trunk/sources/HeuristicLab.Hive.Server.ADODataAccess/JobResultsAdapter.cs
r1449 r1468 6 6 using HeuristicLab.Hive.Contracts.BusinessObjects; 7 7 using HeuristicLab.DataAccess.ADOHelper; 8 using HeuristicLab.Hive.Server.ADODataAccess.dsHiveServerTableAdapters; 9 using System.Data.Common; 10 using System.Data.SqlClient; 8 11 9 12 namespace HeuristicLab.Hive.Server.ADODataAccess { 13 class JobResultsAdapterWrapper : 14 DataAdapterWrapperBase<dsHiveServerTableAdapters.JobResultTableAdapter, 15 JobResult, 16 dsHiveServer.JobResultRow> { 17 public override void UpdateRow(dsHiveServer.JobResultRow row) { 18 TransactionalAdapter.Update(row); 19 } 20 21 public override dsHiveServer.JobResultRow InsertNewRow(JobResult obj) { 22 dsHiveServer.JobResultDataTable data = 23 new dsHiveServer.JobResultDataTable(); 24 25 dsHiveServer.JobResultRow row = data.NewJobResultRow(); 26 row.JobResultId = obj.Id; 27 data.AddJobResultRow(row); 28 29 return row; 30 } 31 32 public override IEnumerable<dsHiveServer.JobResultRow> FindById(Guid id) { 33 return TransactionalAdapter.GetDataById(id); 34 } 35 36 public override IEnumerable<dsHiveServer.JobResultRow> FindAll() { 37 return TransactionalAdapter.GetData(); 38 } 39 40 protected override void SetConnection(DbConnection connection) { 41 adapter.Connection = connection as SqlConnection; 42 } 43 44 protected override void SetTransaction(DbTransaction transaction) { 45 adapter.Transaction = transaction as SqlTransaction; 46 } 47 } 48 10 49 class JobResultsAdapter: 11 50 DataAdapterBase<dsHiveServerTableAdapters.JobResultTableAdapter, … … 19 58 get { 20 59 if (clientAdapter == null) 21 clientAdapter = ServiceLocator.GetClientAdapter(); 60 clientAdapter = 61 this.Session.GetDataAdapter<ClientInfo, IClientAdapter>(); 22 62 23 63 return clientAdapter; … … 30 70 get { 31 71 if (jobAdapter == null) 32 jobAdapter = ServiceLocator.GetJobAdapter(); 72 jobAdapter = 73 this.Session.GetDataAdapter<Job, IJobAdapter>(); 33 74 34 75 return jobAdapter; … … 36 77 } 37 78 #endregion 79 80 public JobResultsAdapter(): base(new JobResultsAdapterWrapper()) { 81 } 38 82 39 83 #region Overrides … … 117 161 return null; 118 162 } 119 120 protected override void UpdateRow(dsHiveServer.JobResultRow row) {121 Adapter.Update(row);122 }123 124 protected override dsHiveServer.JobResultRow InsertNewRow(JobResult obj) {125 dsHiveServer.JobResultDataTable data =126 new dsHiveServer.JobResultDataTable();127 128 dsHiveServer.JobResultRow row = data.NewJobResultRow();129 row.JobResultId = obj.Id;130 data.AddJobResultRow(row);131 132 return row;133 }134 135 protected override IEnumerable<dsHiveServer.JobResultRow> FindById(Guid id) {136 return Adapter.GetDataById(id);137 }138 139 protected override IEnumerable<dsHiveServer.JobResultRow> FindAll() {140 return Adapter.GetData();141 }142 163 #endregion 143 164 144 165 #region IJobResultsAdapter Members 145 p ublic override voidUpdate(JobResult result) {166 protected override void doUpdate(JobResult result) { 146 167 if (result != null) { 147 168 ClientAdapter.Update(result.Client); 148 169 JobAdapter.Update(result.Job); 149 170 150 base. Update(result);171 base.doUpdate(result); 151 172 } 152 173 } -
trunk/sources/HeuristicLab.Hive.Server.ADODataAccess/ResourceAdapter.cs
r1449 r1468 27 27 using HeuristicLab.Hive.Contracts.BusinessObjects; 28 28 using HeuristicLab.DataAccess.ADOHelper; 29 using HeuristicLab.Hive.Server.ADODataAccess.dsHiveServerTableAdapters; 30 using System.Data.Common; 31 using System.Data.SqlClient; 29 32 30 33 namespace HeuristicLab.Hive.Server.ADODataAccess { 34 class ResourceAdapterWrapper : 35 DataAdapterWrapperBase< 36 dsHiveServerTableAdapters.ResourceTableAdapter, 37 Resource, 38 dsHiveServer.ResourceRow> { 39 public override void UpdateRow(dsHiveServer.ResourceRow row) { 40 TransactionalAdapter.Update(row); 41 } 42 43 public override dsHiveServer.ResourceRow 44 InsertNewRow(Resource resource) { 45 dsHiveServer.ResourceDataTable data = 46 new dsHiveServer.ResourceDataTable(); 47 48 dsHiveServer.ResourceRow row = data.NewResourceRow(); 49 row.ResourceId = resource.Id; 50 data.AddResourceRow(row); 51 52 return row; 53 } 54 55 public override IEnumerable<dsHiveServer.ResourceRow> 56 FindById(Guid id) { 57 return TransactionalAdapter.GetDataById(id); 58 } 59 60 public override IEnumerable<dsHiveServer.ResourceRow> 61 FindAll() { 62 return TransactionalAdapter.GetData(); 63 } 64 65 protected override void SetConnection(DbConnection connection) { 66 adapter.Connection = connection as SqlConnection; 67 } 68 69 protected override void SetTransaction(DbTransaction transaction) { 70 adapter.Transaction = transaction as SqlTransaction; 71 } 72 } 73 31 74 class ResourceAdapter: 32 CachedDataAdapter<75 DataAdapterBase< 33 76 dsHiveServerTableAdapters.ResourceTableAdapter, 34 77 Resource, 35 dsHiveServer.ResourceRow, 36 dsHiveServer.ResourceDataTable>, 78 dsHiveServer.ResourceRow>, 37 79 IResourceAdapter { 38 public ResourceAdapter():39 base(ServiceLocator.GetDBSynchronizer()) {40 }41 42 80 #region Fields 43 81 private IClientAdapter clientAdapter = null; … … 46 84 get { 47 85 if (clientAdapter == null) 48 clientAdapter = ServiceLocator.GetClientAdapter(); 86 clientAdapter = 87 this.Session.GetDataAdapter<ClientInfo, IClientAdapter>(); 49 88 50 89 return clientAdapter; … … 52 91 } 53 92 #endregion 93 94 public ResourceAdapter(): base(new ResourceAdapterWrapper()) { 95 } 54 96 55 97 #region Overrides … … 78 120 return null; 79 121 } 80 81 protected override void UpdateRow(dsHiveServer.ResourceRow row) {82 Adapter.Update(row);83 }84 85 protected override dsHiveServer.ResourceRow86 InsertNewRow(Resource resource) {87 dsHiveServer.ResourceDataTable data =88 new dsHiveServer.ResourceDataTable();89 90 dsHiveServer.ResourceRow row = data.NewResourceRow();91 row.ResourceId = resource.Id;92 data.AddResourceRow(row);93 94 return row;95 }96 97 protected override dsHiveServer.ResourceRow98 InsertNewRowInCache(Resource resource) {99 dsHiveServer.ResourceRow row = cache.NewResourceRow();100 row.ResourceId = resource.Id;101 cache.AddResourceRow(row);102 103 return row;104 }105 106 protected override void FillCache() {107 Adapter.FillByActive(cache);108 }109 110 protected override void SynchronizeWithDb() {111 Adapter.Update(cache);112 }113 114 protected override bool PutInCache(Resource obj) {115 return (obj is ClientInfo &&116 (obj as ClientInfo).State != State.offline);117 }118 119 protected override IEnumerable<dsHiveServer.ResourceRow>120 FindById(Guid id) {121 return Adapter.GetDataById(id);122 }123 124 protected override dsHiveServer.ResourceRow125 FindCachedById(Guid id) {126 return cache.FindByResourceId(id);127 }128 129 protected override IEnumerable<dsHiveServer.ResourceRow>130 FindAll() {131 return FindMultipleRows(132 new Selector(Adapter.GetData),133 new Selector(cache.AsEnumerable<dsHiveServer.ResourceRow>));134 }135 136 122 #endregion 137 123 … … 157 143 delegate() { 158 144 return Adapter.GetDataByName(name); 159 },160 delegate() {161 return from r in162 cache.AsEnumerable<dsHiveServer.ResourceRow>()163 where !r.IsNameNull() &&164 r.Name == name165 select r;166 145 }); 167 146 -
trunk/sources/HeuristicLab.Hive.Server.ADODataAccess/app.config
r1449 r1468 5 5 <connectionStrings> 6 6 <add name="HeuristicLab.Hive.Server.ADODataAccess.Properties.Settings.HiveServerConnectionString" 7 connectionString="Data Source=10.20.71.10;Initial Catalog=HeuristicLab.Hive;Persist Security Info=True;User ID=hive;Password=hive "7 connectionString="Data Source=10.20.71.10;Initial Catalog=HeuristicLab.Hive;Persist Security Info=True;User ID=hive;Password=hive;Pooling=true;MultipleActiveResultSets=true" 8 8 providerName="System.Data.SqlClient" /> 9 9 </connectionStrings> -
trunk/sources/HeuristicLab.Hive.Server.Core/ClientCommunicator.cs
r1449 r1468 35 35 using System.Threading; 36 36 using HeuristicLab.PluginInfrastructure; 37 using HeuristicLab.DataAccess.Interfaces; 37 38 38 39 namespace HeuristicLab.Hive.Server.Core { … … 47 48 new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion); 48 49 49 private IClientAdapter clientAdapter; 50 private IJobAdapter jobAdapter; 51 private IJobResultsAdapter jobResultAdapter; 50 private ISessionFactory factory; 52 51 private ILifecycleManager lifecycleManager; 53 52 private IInternalJobManager jobManager; … … 60 59 /// </summary> 61 60 public ClientCommunicator() { 62 clientAdapter = ServiceLocator.GetClientAdapter(); 63 jobAdapter = ServiceLocator.GetJobAdapter(); 64 jobResultAdapter = ServiceLocator.GetJobResultsAdapter(); 61 factory = ServiceLocator.GetSessionFactory(); 62 65 63 lifecycleManager = ServiceLocator.GetLifecycleManager(); 66 64 jobManager = ServiceLocator.GetJobManager() as … … 79 77 /// <param name="e"></param> 80 78 void lifecycleManager_OnServerHeartbeat(object sender, EventArgs e) { 81 List<ClientInfo> allClients = new List<ClientInfo>(clientAdapter.GetAll()); 82 83 foreach (ClientInfo client in allClients) { 84 if (client.State != State.offline && client.State != State.nullState) { 85 heartbeatLock.EnterUpgradeableReadLock(); 86 87 if (!lastHeartbeats.ContainsKey(client.Id)) { 88 client.State = State.offline; 89 clientAdapter.Update(client); 90 foreach (Job job in jobAdapter.GetActiveJobsOf(client)) { 91 jobManager.ResetJobsDependingOnResults(job); 92 } 93 } else { 94 DateTime lastHbOfClient = lastHeartbeats[client.Id]; 95 96 TimeSpan dif = DateTime.Now.Subtract(lastHbOfClient); 97 // check if time between last hearbeat and now is greather than HEARTBEAT_MAX_DIF 98 if (dif.Seconds > ApplicationConstants.HEARTBEAT_MAX_DIF) { 99 // if client calculated jobs, the job must be reset 100 if (client.State == State.calculating) { 101 // check wich job the client was calculating and reset it 102 foreach (Job job in jobAdapter.GetActiveJobsOf(client)) { 103 jobManager.ResetJobsDependingOnResults(job); 104 } 105 } 106 107 // client must be set offline 79 ISession session = factory.GetSessionForCurrentThread(); 80 81 try { 82 IClientAdapter clientAdapter = 83 session.GetDataAdapter<ClientInfo, IClientAdapter>(); 84 IJobAdapter jobAdapter = 85 session.GetDataAdapter<Job, IJobAdapter>(); 86 87 List<ClientInfo> allClients = new List<ClientInfo>(clientAdapter.GetAll()); 88 89 foreach (ClientInfo client in allClients) { 90 if (client.State != State.offline && client.State != State.nullState) { 91 heartbeatLock.EnterUpgradeableReadLock(); 92 93 if (!lastHeartbeats.ContainsKey(client.Id)) { 108 94 client.State = State.offline; 109 95 clientAdapter.Update(client); 110 111 heartbeatLock.EnterWriteLock(); 96 foreach (Job job in jobAdapter.GetActiveJobsOf(client)) { 97 jobManager.ResetJobsDependingOnResults(job); 98 } 99 } else { 100 DateTime lastHbOfClient = lastHeartbeats[client.Id]; 101 102 TimeSpan dif = DateTime.Now.Subtract(lastHbOfClient); 103 // check if time between last hearbeat and now is greather than HEARTBEAT_MAX_DIF 104 if (dif.TotalSeconds > ApplicationConstants.HEARTBEAT_MAX_DIF) { 105 // if client calculated jobs, the job must be reset 106 if (client.State == State.calculating) { 107 // check wich job the client was calculating and reset it 108 foreach (Job job in jobAdapter.GetActiveJobsOf(client)) { 109 jobManager.ResetJobsDependingOnResults(job); 110 } 111 } 112 113 // client must be set offline 114 client.State = State.offline; 115 clientAdapter.Update(client); 116 117 heartbeatLock.EnterWriteLock(); 118 lastHeartbeats.Remove(client.Id); 119 heartbeatLock.ExitWriteLock(); 120 } 121 } 122 123 heartbeatLock.ExitUpgradeableReadLock(); 124 } else { 125 heartbeatLock.EnterWriteLock(); 126 if (lastHeartbeats.ContainsKey(client.Id)) 112 127 lastHeartbeats.Remove(client.Id); 113 heartbeatLock.ExitWriteLock(); 114 } 128 heartbeatLock.ExitWriteLock(); 115 129 } 116 117 heartbeatLock.ExitUpgradeableReadLock(); 118 } else { 119 heartbeatLock.EnterWriteLock(); 120 if (lastHeartbeats.ContainsKey(client.Id)) 121 lastHeartbeats.Remove(client.Id); 122 heartbeatLock.ExitWriteLock(); 123 } 130 } 131 } 132 finally { 133 if (session != null) 134 session.EndSession(); 124 135 } 125 136 } … … 134 145 /// <returns></returns> 135 146 public Response Login(ClientInfo clientInfo) { 136 Response response = new Response(); 137 138 heartbeatLock.EnterWriteLock(); 139 if (lastHeartbeats.ContainsKey(clientInfo.Id)) { 140 lastHeartbeats[clientInfo.Id] = DateTime.Now; 141 } else { 142 lastHeartbeats.Add(clientInfo.Id, DateTime.Now); 143 } 144 heartbeatLock.ExitWriteLock(); 145 146 // todo: allClients legacy ? 147 ClientInfo client = clientAdapter.GetById(clientInfo.Id); 148 if (client != null && client.State != State.offline && client.State != State.nullState) { 149 response.Success = false; 150 response.StatusMessage = ApplicationConstants.RESPONSE_COMMUNICATOR_LOGIN_USER_ALLREADY_ONLINE; 147 ISession session = factory.GetSessionForCurrentThread(); 148 149 try { 150 IClientAdapter clientAdapter = 151 session.GetDataAdapter<ClientInfo, IClientAdapter>(); 152 153 Response response = new Response(); 154 155 heartbeatLock.EnterWriteLock(); 156 if (lastHeartbeats.ContainsKey(clientInfo.Id)) { 157 lastHeartbeats[clientInfo.Id] = DateTime.Now; 158 } else { 159 lastHeartbeats.Add(clientInfo.Id, DateTime.Now); 160 } 161 heartbeatLock.ExitWriteLock(); 162 163 // todo: allClients legacy ? 164 ClientInfo client = clientAdapter.GetById(clientInfo.Id); 165 if (client != null && client.State != State.offline && client.State != State.nullState) { 166 response.Success = false; 167 response.StatusMessage = ApplicationConstants.RESPONSE_COMMUNICATOR_LOGIN_USER_ALLREADY_ONLINE; 168 return response; 169 } 170 clientInfo.State = State.idle; 171 clientAdapter.Update(clientInfo); 172 response.Success = true; 173 response.StatusMessage = ApplicationConstants.RESPONSE_COMMUNICATOR_LOGIN_SUCCESS; 174 151 175 return response; 152 176 } 153 clientInfo.State = State.idle; 154 clientAdapter.Update(clientInfo); 155 response.Success = true; 156 response.StatusMessage = ApplicationConstants.RESPONSE_COMMUNICATOR_LOGIN_SUCCESS; 157 158 return response; 177 finally { 178 if (session != null) 179 session.EndSession(); 180 } 159 181 } 160 182 … … 167 189 /// <returns></returns> 168 190 public ResponseHB ProcessHeartBeat(HeartBeatData hbData) { 169 ResponseHB response = new ResponseHB(); 170 171 // check if the client is logged in 172 response.ActionRequest = new List<MessageContainer>(); 173 if (clientAdapter.GetById(hbData.ClientId).State == State.offline || 174 clientAdapter.GetById(hbData.ClientId).State == State.nullState) { 175 response.Success = false; 176 response.StatusMessage = ApplicationConstants.RESPONSE_COMMUNICATOR_USER_NOT_LOGGED_IN; 177 response.ActionRequest.Add(new MessageContainer(MessageContainer.MessageType.NoMessage)); 178 return response; 179 } 180 181 // save timestamp of this heartbeat 182 heartbeatLock.EnterWriteLock(); 183 if (lastHeartbeats.ContainsKey(hbData.ClientId)) { 184 lastHeartbeats[hbData.ClientId] = DateTime.Now; 185 } else { 186 lastHeartbeats.Add(hbData.ClientId, DateTime.Now); 187 } 188 heartbeatLock.ExitWriteLock(); 189 190 response.Success = true; 191 response.StatusMessage = ApplicationConstants.RESPONSE_COMMUNICATOR_HEARTBEAT_RECEIVED; 192 // check if client has a free core for a new job 193 // if true, ask scheduler for a new job for this client 194 if (hbData.FreeCores > 0 && scheduler.ExistsJobForClient(hbData)) 195 response.ActionRequest.Add(new MessageContainer(MessageContainer.MessageType.FetchJob)); 196 else 197 response.ActionRequest.Add(new MessageContainer(MessageContainer.MessageType.NoMessage)); 198 199 if (hbData.JobProgress != null) { 200 List<Job> jobsOfClient = new List<Job>(jobAdapter.GetActiveJobsOf(clientAdapter.GetById(hbData.ClientId))); 201 if (jobsOfClient == null || jobsOfClient.Count == 0) { 202 response.Success = false; 203 response.StatusMessage = ApplicationConstants.RESPONSE_COMMUNICATOR_JOB_IS_NOT_BEEING_CALCULATED; 204 return response; 205 } 206 207 foreach (KeyValuePair<Guid, double> jobProgress in hbData.JobProgress) { 208 Job curJob = jobAdapter.GetById(jobProgress.Key); 209 if (curJob.Client == null || curJob.Client.Id != hbData.ClientId) { 191 ISession session = factory.GetSessionForCurrentThread(); 192 193 try { 194 IClientAdapter clientAdapter = 195 session.GetDataAdapter<ClientInfo, IClientAdapter>(); 196 197 IJobAdapter jobAdapter = 198 session.GetDataAdapter<Job, IJobAdapter>(); 199 200 ResponseHB response = new ResponseHB(); 201 202 // check if the client is logged in 203 response.ActionRequest = new List<MessageContainer>(); 204 if (clientAdapter.GetById(hbData.ClientId).State == State.offline || 205 clientAdapter.GetById(hbData.ClientId).State == State.nullState) { 206 response.Success = false; 207 response.StatusMessage = ApplicationConstants.RESPONSE_COMMUNICATOR_USER_NOT_LOGGED_IN; 208 response.ActionRequest.Add(new MessageContainer(MessageContainer.MessageType.NoMessage)); 209 return response; 210 } 211 212 // save timestamp of this heartbeat 213 heartbeatLock.EnterWriteLock(); 214 if (lastHeartbeats.ContainsKey(hbData.ClientId)) { 215 lastHeartbeats[hbData.ClientId] = DateTime.Now; 216 } else { 217 lastHeartbeats.Add(hbData.ClientId, DateTime.Now); 218 } 219 heartbeatLock.ExitWriteLock(); 220 221 response.Success = true; 222 response.StatusMessage = ApplicationConstants.RESPONSE_COMMUNICATOR_HEARTBEAT_RECEIVED; 223 // check if client has a free core for a new job 224 // if true, ask scheduler for a new job for this client 225 if (hbData.FreeCores > 0 && scheduler.ExistsJobForClient(hbData)) 226 response.ActionRequest.Add(new MessageContainer(MessageContainer.MessageType.FetchJob)); 227 else 228 response.ActionRequest.Add(new MessageContainer(MessageContainer.MessageType.NoMessage)); 229 230 if (hbData.JobProgress != null) { 231 List<Job> jobsOfClient = new List<Job>(jobAdapter.GetActiveJobsOf(clientAdapter.GetById(hbData.ClientId))); 232 if (jobsOfClient == null || jobsOfClient.Count == 0) { 210 233 response.Success = false; 211 234 response.StatusMessage = ApplicationConstants.RESPONSE_COMMUNICATOR_JOB_IS_NOT_BEEING_CALCULATED; 212 } else if(curJob.State == State.finished) { 213 // another client has finished this job allready 214 // the client can abort it 215 response.ActionRequest.Add(new MessageContainer(MessageContainer.MessageType.AbortJob, curJob.Id)); 216 } else { 217 // save job progress 218 curJob.Percentage = jobProgress.Value; 219 jobAdapter.Update(curJob); 235 return response; 220 236 } 221 } 222 } 223 224 return response; 237 238 foreach (KeyValuePair<Guid, double> jobProgress in hbData.JobProgress) { 239 Job curJob = jobAdapter.GetById(jobProgress.Key); 240 if (curJob.Client == null || curJob.Client.Id != hbData.ClientId) { 241 response.Success = false; 242 response.StatusMessage = ApplicationConstants.RESPONSE_COMMUNICATOR_JOB_IS_NOT_BEEING_CALCULATED; 243 } else if (curJob.State == State.finished) { 244 // another client has finished this job allready 245 // the client can abort it 246 response.ActionRequest.Add(new MessageContainer(MessageContainer.MessageType.AbortJob, curJob.Id)); 247 } else { 248 // save job progress 249 curJob.Percentage = jobProgress.Value; 250 jobAdapter.Update(curJob); 251 } 252 } 253 } 254 255 return response; 256 } 257 finally { 258 if (session != null) 259 session.EndSession(); 260 } 225 261 } 226 262 … … 253 289 Exception exception, 254 290 bool finished) { 255 256 ResponseResultReceived response = new ResponseResultReceived(); 257 ClientInfo client = 258 clientAdapter.GetById(clientId); 259 260 Job job = 261 jobAdapter.GetById(jobId); 262 263 if (job.Client == null) { 264 response.Success = false; 265 response.StatusMessage = ApplicationConstants.RESPONSE_COMMUNICATOR_JOB_IS_NOT_BEEING_CALCULATED; 291 ISession session = factory.GetSessionForCurrentThread(); 292 293 try { 294 IClientAdapter clientAdapter = 295 session.GetDataAdapter<ClientInfo, IClientAdapter>(); 296 IJobAdapter jobAdapter = 297 session.GetDataAdapter<Job, IJobAdapter>(); 298 IJobResultsAdapter jobResultAdapter = 299 session.GetDataAdapter<JobResult, IJobResultsAdapter>(); 300 301 ResponseResultReceived response = new ResponseResultReceived(); 302 ClientInfo client = 303 clientAdapter.GetById(clientId); 304 305 Job job = 306 jobAdapter.GetById(jobId); 307 308 if (job.Client == null) { 309 response.Success = false; 310 response.StatusMessage = ApplicationConstants.RESPONSE_COMMUNICATOR_JOB_IS_NOT_BEEING_CALCULATED; 311 return response; 312 } 313 if (job.Client.Id != clientId) { 314 response.Success = false; 315 response.StatusMessage = ApplicationConstants.RESPONSE_COMMUNICATOR_WRONG_CLIENT_FOR_JOB; 316 return response; 317 } 318 if (job == null) { 319 response.Success = false; 320 response.StatusMessage = ApplicationConstants.RESPONSE_COMMUNICATOR_NO_JOB_WITH_THIS_ID; 321 return response; 322 } 323 if (job.State == State.finished) { 324 response.Success = true; 325 response.StatusMessage = ApplicationConstants.RESPONSE_COMMUNICATOR_JOBRESULT_RECEIVED; 326 return response; 327 } 328 if (job.State != State.calculating) { 329 response.Success = false; 330 response.StatusMessage = ApplicationConstants.RESPONSE_COMMUNICATOR_WRONG_JOB_STATE; 331 return response; 332 } 333 job.SerializedJob = result; 334 job.Percentage = percentage; 335 336 if (finished) { 337 job.State = State.finished; 338 jobAdapter.Update(job); 339 340 client.State = State.idle; 341 clientAdapter.Update(client); 342 343 List<JobResult> jobResults = new List<JobResult>(jobResultAdapter.GetResultsOf(job)); 344 foreach (JobResult currentResult in jobResults) 345 jobResultAdapter.Delete(currentResult); 346 } 347 348 JobResult jobResult = 349 new JobResult(); 350 jobResult.Client = client; 351 jobResult.Job = job; 352 jobResult.Result = result; 353 jobResult.Percentage = percentage; 354 jobResult.Exception = exception; 355 jobResult.DateFinished = DateTime.Now; 356 357 jobResultAdapter.Update(jobResult); 358 jobAdapter.Update(job); 359 360 response.Success = true; 361 response.StatusMessage = ApplicationConstants.RESPONSE_COMMUNICATOR_JOBRESULT_RECEIVED; 362 response.JobId = jobId; 363 response.finished = finished; 364 266 365 return response; 267 366 } 268 if (job.Client.Id != clientId) { 269 response.Success = false; 270 response.StatusMessage = ApplicationConstants.RESPONSE_COMMUNICATOR_WRONG_CLIENT_FOR_JOB; 271 return response; 272 } 273 if (job == null) { 274 response.Success = false; 275 response.StatusMessage = ApplicationConstants.RESPONSE_COMMUNICATOR_NO_JOB_WITH_THIS_ID; 276 return response; 277 } 278 if (job.State == State.finished) { 279 response.Success = true; 280 response.StatusMessage = ApplicationConstants.RESPONSE_COMMUNICATOR_JOBRESULT_RECEIVED; 281 return response; 282 } 283 if (job.State != State.calculating) { 284 response.Success = false; 285 response.StatusMessage = ApplicationConstants.RESPONSE_COMMUNICATOR_WRONG_JOB_STATE; 286 return response; 287 } 288 job.SerializedJob = result; 289 job.Percentage = percentage; 290 291 if (finished) { 292 job.State = State.finished; 293 jobAdapter.Update(job); 294 295 client.State = State.idle; 296 clientAdapter.Update(client); 297 298 List<JobResult> jobResults = new List<JobResult>(jobResultAdapter.GetResultsOf(job)); 299 foreach (JobResult currentResult in jobResults) 300 jobResultAdapter.Delete(currentResult); 301 } 302 303 JobResult jobResult = 304 new JobResult(); 305 jobResult.Client = client; 306 jobResult.Job = job; 307 jobResult.Result = result; 308 jobResult.Percentage = percentage; 309 jobResult.Exception = exception; 310 jobResult.DateFinished = DateTime.Now; 311 312 jobResultAdapter.Update(jobResult); 313 jobAdapter.Update(job); 314 315 response.Success = true; 316 response.StatusMessage = ApplicationConstants.RESPONSE_COMMUNICATOR_JOBRESULT_RECEIVED; 317 response.JobId = jobId; 318 response.finished = finished; 319 320 return response; 367 finally { 368 if (session != null) 369 session.EndSession(); 370 } 321 371 } 322 372 … … 354 404 /// <returns></returns> 355 405 public Response Logout(Guid clientId) { 356 Response response = new Response(); 357 358 heartbeatLock.EnterWriteLock(); 359 if (lastHeartbeats.ContainsKey(clientId)) 360 lastHeartbeats.Remove(clientId); 361 heartbeatLock.ExitWriteLock(); 362 363 ClientInfo client = clientAdapter.GetById(clientId); 364 if (client == null) { 365 response.Success = false; 366 response.StatusMessage = ApplicationConstants.RESPONSE_COMMUNICATOR_LOGOUT_CLIENT_NOT_REGISTERED; 406 ISession session = factory.GetSessionForCurrentThread(); 407 408 try { 409 IClientAdapter clientAdapter = 410 session.GetDataAdapter<ClientInfo, IClientAdapter>(); 411 IJobAdapter jobAdapter = 412 session.GetDataAdapter<Job, IJobAdapter>(); 413 414 Response response = new Response(); 415 416 heartbeatLock.EnterWriteLock(); 417 if (lastHeartbeats.ContainsKey(clientId)) 418 lastHeartbeats.Remove(clientId); 419 heartbeatLock.ExitWriteLock(); 420 421 ClientInfo client = clientAdapter.GetById(clientId); 422 if (client == null) { 423 response.Success = false; 424 response.StatusMessage = ApplicationConstants.RESPONSE_COMMUNICATOR_LOGOUT_CLIENT_NOT_REGISTERED; 425 return response; 426 } 427 List<Job> allJobs = new List<Job>(jobAdapter.GetAll()); 428 if (client.State == State.calculating) { 429 // check wich job the client was calculating and reset it 430 foreach (Job job in allJobs) { 431 if (job.Client.Id == client.Id) { 432 jobManager.ResetJobsDependingOnResults(job); 433 } 434 } 435 } 436 437 client.State = State.offline; 438 clientAdapter.Update(client); 439 440 response.Success = true; 441 response.StatusMessage = ApplicationConstants.RESPONSE_COMMUNICATOR_LOGOUT_SUCCESS; 442 367 443 return response; 368 444 } 369 List<Job> allJobs = new List<Job>(jobAdapter.GetAll()); 370 if (client.State == State.calculating) { 371 // check wich job the client was calculating and reset it 372 foreach (Job job in allJobs) { 373 if (job.Client.Id == client.Id) { 374 jobManager.ResetJobsDependingOnResults(job); 375 } 376 } 377 } 378 379 client.State = State.offline; 380 clientAdapter.Update(client); 381 382 response.Success = true; 383 response.StatusMessage = ApplicationConstants.RESPONSE_COMMUNICATOR_LOGOUT_SUCCESS; 384 385 return response; 445 finally { 446 if (session != null) 447 session.EndSession(); 448 } 386 449 } 387 450 … … 393 456 /// <returns></returns> 394 457 public Response IsJobStillNeeded(Guid jobId) { 395 Response response = new Response(); 396 Job job = jobAdapter.GetById(jobId); 397 if (job == null) { 398 response.Success = false; 399 response.StatusMessage = ApplicationConstants.RESPONSE_COMMUNICATOR_JOB_DOESNT_EXIST; 458 ISession session = factory.GetSessionForCurrentThread(); 459 460 try { 461 IJobAdapter jobAdapter = 462 session.GetDataAdapter<Job, IJobAdapter>(); 463 464 Response response = new Response(); 465 Job job = jobAdapter.GetById(jobId); 466 if (job == null) { 467 response.Success = false; 468 response.StatusMessage = ApplicationConstants.RESPONSE_COMMUNICATOR_JOB_DOESNT_EXIST; 469 return response; 470 } 471 if (job.State == State.finished) { 472 response.Success = true; 473 response.StatusMessage = ApplicationConstants.RESPONSE_COMMUNICATOR_JOB_ALLREADY_FINISHED; 474 return response; 475 } 476 job.State = State.finished; 477 jobAdapter.Update(job); 478 479 response.Success = true; 480 response.StatusMessage = ApplicationConstants.RESPONSE_COMMUNICATOR_SEND_JOBRESULT; 400 481 return response; 401 482 } 402 if (job.State == State.finished) { 403 response.Success = true; 404 response.StatusMessage = ApplicationConstants.RESPONSE_COMMUNICATOR_JOB_ALLREADY_FINISHED; 405 return response; 406 } 407 job.State = State.finished; 408 jobAdapter.Update(job); 409 410 response.Success = true; 411 response.StatusMessage = ApplicationConstants.RESPONSE_COMMUNICATOR_SEND_JOBRESULT; 412 return response; 483 finally { 484 if (session != null) 485 session.EndSession(); 486 } 413 487 } 414 488 -
trunk/sources/HeuristicLab.Hive.Server.Core/ClientManager.cs
r1449 r1468 28 28 using HeuristicLab.Hive.Contracts; 29 29 using HeuristicLab.Hive.Server.DataAccess; 30 using HeuristicLab.DataAccess.Interfaces; 30 31 31 32 namespace HeuristicLab.Hive.Server.Core { 32 33 class ClientManager: IClientManager { 33 34 34 IClientAdapter clientAdapter; 35 IClientGroupAdapter clientGroupAdapter; 36 35 ISessionFactory factory; 37 36 List<ClientGroup> clientGroups; 38 37 39 38 public ClientManager() { 40 clientAdapter = ServiceLocator.GetClientAdapter(); 41 clientGroupAdapter = ServiceLocator.GetClientGroupAdapter(); 42 39 factory = ServiceLocator.GetSessionFactory(); 40 43 41 clientGroups = new List<ClientGroup>(); 44 45 ClientGroup cg = new ClientGroup { Id = Guid.NewGuid(), Name = "SuperGroup" };46 cg.Resources = new List<Resource>();47 48 clientGroups.Add(cg);49 42 } 50 43 … … 56 49 /// <returns></returns> 57 50 public ResponseList<ClientInfo> GetAllClients() { 58 ResponseList<ClientInfo> response = new ResponseList<ClientInfo>(); 59 60 response.List = new List<ClientInfo>(clientAdapter.GetAll()); 61 response.StatusMessage = ApplicationConstants.RESPONSE_CLIENT_GET_ALL_CLIENTS; 62 response.Success = true; 63 64 return response; 51 ISession session = factory.GetSessionForCurrentThread(); 52 53 try { 54 IClientAdapter clientAdapter = 55 session.GetDataAdapter<ClientInfo, IClientAdapter>(); 56 57 ResponseList<ClientInfo> response = new ResponseList<ClientInfo>(); 58 59 response.List = new List<ClientInfo>(clientAdapter.GetAll()); 60 response.StatusMessage = ApplicationConstants.RESPONSE_CLIENT_GET_ALL_CLIENTS; 61 response.Success = true; 62 63 return response; 64 } 65 finally { 66 if (session != null) 67 session.EndSession(); 68 } 65 69 } 66 70 … … 70 74 /// <returns></returns> 71 75 public ResponseList<ClientGroup> GetAllClientGroups() { 72 ResponseList<ClientGroup> response = new ResponseList<ClientGroup>(); 73 74 response.List = new List<ClientGroup>(clientGroupAdapter.GetAll()); 75 response.StatusMessage = ApplicationConstants.RESPONSE_CLIENT_GET_ALL_CLIENTGROUPS; 76 response.Success = true; 77 78 return response; 76 ISession session = factory.GetSessionForCurrentThread(); 77 78 try { 79 IClientGroupAdapter clientGroupAdapter = 80 session.GetDataAdapter<ClientGroup, IClientGroupAdapter>(); 81 ResponseList<ClientGroup> response = new ResponseList<ClientGroup>(); 82 83 response.List = new List<ClientGroup>(clientGroupAdapter.GetAll()); 84 response.StatusMessage = ApplicationConstants.RESPONSE_CLIENT_GET_ALL_CLIENTGROUPS; 85 response.Success = true; 86 87 return response; 88 } 89 finally { 90 if (session != null) 91 session.EndSession(); 92 } 79 93 } 80 94 … … 91 105 /// <returns></returns> 92 106 public Response AddClientGroup(ClientGroup clientGroup) { 93 Response response = new Response(); 94 95 if (clientGroup.Id != Guid.Empty) { 96 response.Success = false; 97 response.StatusMessage = ApplicationConstants.RESPONSE_CLIENT_ID_MUST_NOT_BE_SET; 98 return response; 99 } 100 clientGroupAdapter.Update(clientGroup); 101 response.Success = true; 102 response.StatusMessage = ApplicationConstants.RESPONSE_CLIENT_CLIENTGROUP_ADDED; 103 104 return response; 107 ISession session = factory.GetSessionForCurrentThread(); 108 109 try { 110 IClientGroupAdapter clientGroupAdapter = 111 session.GetDataAdapter<ClientGroup, IClientGroupAdapter>(); 112 113 Response response = new Response(); 114 115 if (clientGroup.Id != Guid.Empty) { 116 response.Success = false; 117 response.StatusMessage = ApplicationConstants.RESPONSE_CLIENT_ID_MUST_NOT_BE_SET; 118 } else { 119 clientGroupAdapter.Update(clientGroup); 120 response.Success = true; 121 response.StatusMessage = ApplicationConstants.RESPONSE_CLIENT_CLIENTGROUP_ADDED; 122 } 123 124 return response; 125 } 126 finally { 127 if (session != null) 128 session.EndSession(); 129 } 105 130 } 106 131 … … 112 137 /// <returns></returns> 113 138 public Response AddResourceToGroup(Guid clientGroupId, Resource resource) { 114 Response response = new Response(); 115 116 if (resource.Id != Guid.Empty) { 117 response.Success = false; 118 response.StatusMessage = ApplicationConstants.RESPONSE_CLIENT_ID_MUST_NOT_BE_SET; 119 return response; 120 } 121 122 ClientGroup clientGroup = clientGroupAdapter.GetById(clientGroupId); 123 if (clientGroup == null) { 124 response.Success = false; 125 response.StatusMessage = ApplicationConstants.RESPONSE_CLIENT_CLIENTGROUP_DOESNT_EXIST; 126 return response; 127 } 128 clientGroup.Resources.Add(resource); 129 130 response.Success = true; 131 response.StatusMessage = ApplicationConstants.RESPONSE_CLIENT_RESOURCE_ADDED_TO_GROUP; 132 133 return response; 139 ISession session = factory.GetSessionForCurrentThread(); 140 141 try { 142 IClientGroupAdapter clientGroupAdapter = 143 session.GetDataAdapter<ClientGroup, IClientGroupAdapter>(); 144 145 Response response = new Response(); 146 147 if (resource.Id != Guid.Empty) { 148 response.Success = false; 149 response.StatusMessage = ApplicationConstants.RESPONSE_CLIENT_ID_MUST_NOT_BE_SET; 150 return response; 151 } 152 153 ClientGroup clientGroup = clientGroupAdapter.GetById(clientGroupId); 154 if (clientGroup == null) { 155 response.Success = false; 156 response.StatusMessage = ApplicationConstants.RESPONSE_CLIENT_CLIENTGROUP_DOESNT_EXIST; 157 return response; 158 } 159 clientGroup.Resources.Add(resource); 160 161 response.Success = true; 162 response.StatusMessage = ApplicationConstants.RESPONSE_CLIENT_RESOURCE_ADDED_TO_GROUP; 163 164 return response; 165 } 166 finally { 167 if (session != null) 168 session.EndSession(); 169 } 134 170 } 135 171 … … 141 177 /// <returns></returns> 142 178 public Response DeleteResourceFromGroup(Guid clientGroupId, Guid resourceId) { 143 Response response = new Response(); 144 145 ClientGroup clientGroup = clientGroupAdapter.GetById(clientGroupId); 146 if (clientGroup == null) { 179 ISession session = factory.GetSessionForCurrentThread(); 180 181 try { 182 IClientGroupAdapter clientGroupAdapter = 183 session.GetDataAdapter<ClientGroup, IClientGroupAdapter>(); 184 185 Response response = new Response(); 186 187 ClientGroup clientGroup = clientGroupAdapter.GetById(clientGroupId); 188 if (clientGroup == null) { 189 response.Success = false; 190 response.StatusMessage = ApplicationConstants.RESPONSE_CLIENT_CLIENTGROUP_DOESNT_EXIST; 191 return response; 192 } 193 foreach (Resource resource in clientGroup.Resources) { 194 if (resource.Id == resourceId) { 195 clientGroup.Resources.Remove(resource); 196 response.Success = true; 197 response.StatusMessage = ApplicationConstants.RESPONSE_CLIENT_RESOURCE_REMOVED; 198 return response; 199 } 200 } 147 201 response.Success = false; 148 response.StatusMessage = ApplicationConstants.RESPONSE_CLIENT_CLIENTGROUP_DOESNT_EXIST; 149 return response; 150 } 151 foreach (Resource resource in clientGroup.Resources) { 152 if (resource.Id == resourceId) { 153 clientGroup.Resources.Remove(resource); 154 response.Success = true; 155 response.StatusMessage = ApplicationConstants.RESPONSE_CLIENT_RESOURCE_REMOVED; 156 return response; 157 } 158 } 159 response.Success = false; 160 response.StatusMessage = ApplicationConstants.RESPONSE_CLIENT_RESOURCE_NOT_FOUND; 161 162 return response; 202 response.StatusMessage = ApplicationConstants.RESPONSE_CLIENT_RESOURCE_NOT_FOUND; 203 204 return response; 205 } 206 finally { 207 if (session != null) 208 session.EndSession(); 209 } 163 210 } 164 211 #endregion -
trunk/sources/HeuristicLab.Hive.Server.Core/DbTestApp.cs
r1449 r1468 37 37 AutoRestart = true)] 38 38 class HiveDbTestApplication : ApplicationBase { 39 private void TestClientAdapter() {39 /* private void TestClientAdapter() { 40 40 IClientAdapter clientAdapter = 41 41 ServiceLocator.GetClientAdapter(); … … 199 199 ServiceLocator.GetClientAdapter(); 200 200 clientAdapter.Delete(client); 201 } 201 } */ 202 202 203 203 public override void Run() { 204 IDBSynchronizer transactionManager = 205 ServiceLocator.GetDBSynchronizer(); 206 207 TestClientAdapter(); 208 transactionManager.UpdateDB(); 209 210 TestClientGroupAdapter(); 211 transactionManager.UpdateDB(); 212 213 TestJobAdapter(); 214 transactionManager.UpdateDB(); 215 216 TestJobResultsAdapter(); 217 transactionManager.UpdateDB(); 218 } 204 ISessionFactory factory = 205 ServiceLocator.GetSessionFactory(); 206 207 ISession session = 208 factory.GetSessionForCurrentThread(); 209 210 IClientAdapter clientAdapter = 211 session.GetDataAdapter<ClientInfo, IClientAdapter>(); 212 213 ITransaction trans = 214 session.BeginTransaction(); 215 216 ClientInfo client = new ClientInfo(); 217 client.Login = DateTime.Now; 218 clientAdapter.Update(client); 219 220 trans.Rollback(); 221 222 session.EndSession(); 223 } 219 224 } 220 225 } -
trunk/sources/HeuristicLab.Hive.Server.Core/HeuristicLab.Hive.Server.Core.csproj
r1377 r1468 80 80 <Compile Include="ServerConsoleFacade.cs" /> 81 81 <Compile Include="ServiceLocator.cs" /> 82 <Compile Include="Properties\Settings.Designer.cs"> 83 <AutoGen>True</AutoGen> 84 <DesignTimeSharedInput>True</DesignTimeSharedInput> 85 <DependentUpon>Settings.settings</DependentUpon> 86 </Compile> 87 <Compile Include="Settings.cs" /> 82 88 </ItemGroup> 83 89 <ItemGroup> 90 <None Include="app.config" /> 84 91 <None Include="HeuristicLab.snk" /> 85 92 <None Include="Properties\AssemblyInfo.frame" /> 93 <None Include="Properties\Settings.settings"> 94 <Generator>PublicSettingsSingleFileGenerator</Generator> 95 <LastGenOutput>Settings.Designer.cs</LastGenOutput> 96 </None> 86 97 </ItemGroup> 87 98 <ItemGroup> -
trunk/sources/HeuristicLab.Hive.Server.Core/JobManager.cs
r1449 r1468 29 29 using HeuristicLab.Hive.Server.DataAccess; 30 30 using HeuristicLab.Hive.Server.Core.InternalInterfaces; 31 using HeuristicLab.DataAccess.Interfaces; 31 32 32 33 namespace HeuristicLab.Hive.Server.Core { 33 34 class JobManager: IJobManager, IInternalJobManager { 34 35 35 IJobAdapter jobAdapter; 36 IJobResultsAdapter jobResultAdapter; 36 ISessionFactory factory; 37 37 ILifecycleManager lifecycleManager; 38 38 … … 40 40 41 41 public JobManager() { 42 jobAdapter = ServiceLocator.GetJobAdapter(); 43 jobResultAdapter = ServiceLocator.GetJobResultsAdapter(); 44 42 factory = ServiceLocator.GetSessionFactory(); 45 43 lifecycleManager = ServiceLocator.GetLifecycleManager(); 46 44 … … 50 48 51 49 private JobResult GetLastJobResult(Job job) { 52 List<JobResult> allJobResults = new List<JobResult>(jobResultAdapter.GetResultsOf(job)); 53 JobResult lastJobResult = null; 54 foreach (JobResult jR in allJobResults) { 55 // if lastJobResult was before the current jobResult the lastJobResult must be updated 56 if (lastJobResult == null || 57 (jR.timestamp > lastJobResult.timestamp)) 58 lastJobResult = jR; 59 } 60 return lastJobResult; 50 ISession session = factory.GetSessionForCurrentThread(); 51 52 try { 53 IJobResultsAdapter jobResultAdapter = 54 session.GetDataAdapter<JobResult, IJobResultsAdapter>(); 55 56 List<JobResult> allJobResults = new List<JobResult>(jobResultAdapter.GetResultsOf(job)); 57 JobResult lastJobResult = null; 58 foreach (JobResult jR in allJobResults) { 59 // if lastJobResult was before the current jobResult the lastJobResult must be updated 60 if (lastJobResult == null || 61 (jR.timestamp > lastJobResult.timestamp)) 62 lastJobResult = jR; 63 } 64 return lastJobResult; 65 } 66 finally { 67 if (session != null) 68 session.EndSession(); 69 } 61 70 } 62 71 63 72 public void ResetJobsDependingOnResults(Job job) { 64 JobResult lastJobResult = GetLastJobResult(job); 65 if (lastJobResult != null) { 66 job.Percentage = lastJobResult.Percentage; 67 job.SerializedJob = lastJobResult.Result; 68 } else { 69 job.Percentage = 0; 70 } 71 72 job.Client = null; 73 job.State = State.offline; 74 75 jobAdapter.Update(job); 73 ISession session = factory.GetSessionForCurrentThread(); 74 75 try { 76 IJobAdapter jobAdapter = 77 session.GetDataAdapter<Job, IJobAdapter>(); 78 79 JobResult lastJobResult = GetLastJobResult(job); 80 if (lastJobResult != null) { 81 job.Percentage = lastJobResult.Percentage; 82 job.SerializedJob = lastJobResult.Result; 83 } else { 84 job.Percentage = 0; 85 } 86 87 job.Client = null; 88 job.State = State.offline; 89 90 jobAdapter.Update(job); 91 } 92 finally { 93 if (session != null) 94 session.EndSession(); 95 } 76 96 } 77 97 78 98 void checkForDeadJobs() { 79 List<Job> allJobs = new List<Job>(jobAdapter.GetAll()); 80 foreach (Job curJob in allJobs) { 81 if (curJob.State == State.calculating) { 82 ResetJobsDependingOnResults(curJob); 83 } 84 } 99 ISession session = factory.GetSessionForCurrentThread(); 100 101 try { 102 IJobAdapter jobAdapter = 103 session.GetDataAdapter<Job, IJobAdapter>(); 104 105 List<Job> allJobs = new List<Job>(jobAdapter.GetAll()); 106 foreach (Job curJob in allJobs) { 107 if (curJob.State == State.calculating) { 108 ResetJobsDependingOnResults(curJob); 109 } 110 } 111 } 112 finally { 113 if (session != null) 114 session.EndSession(); 115 } 85 116 } 86 117 … … 98 129 /// <returns></returns> 99 130 public ResponseList<Job> GetAllJobs() { 100 ResponseList<Job> response = new ResponseList<Job>(); 101 102 response.List = new List<Job>(jobAdapter.GetAll()); 103 response.Success = true; 104 response.StatusMessage = ApplicationConstants.RESPONSE_JOB_ALL_JOBS; 105 106 return response; 131 ISession session = factory.GetSessionForCurrentThread(); 132 133 try { 134 IJobAdapter jobAdapter = 135 session.GetDataAdapter<Job, IJobAdapter>(); 136 137 ResponseList<Job> response = new ResponseList<Job>(); 138 139 response.List = new List<Job>(jobAdapter.GetAll()); 140 response.Success = true; 141 response.StatusMessage = ApplicationConstants.RESPONSE_JOB_ALL_JOBS; 142 143 return response; 144 } 145 finally { 146 if (session != null) 147 session.EndSession(); 148 } 107 149 } 108 150 … … 113 155 /// <returns></returns> 114 156 public ResponseObject<Job> AddNewJob(Job job) { 115 ResponseObject<Job> response = new ResponseObject<Job>(); 116 117 if (job != null) { 118 if (job.State != State.offline) { 157 ISession session = factory.GetSessionForCurrentThread(); 158 159 try { 160 IJobAdapter jobAdapter = 161 session.GetDataAdapter<Job, IJobAdapter>(); 162 163 ResponseObject<Job> response = new ResponseObject<Job>(); 164 165 if (job != null) { 166 if (job.State != State.offline) { 167 response.Success = false; 168 response.StatusMessage = ApplicationConstants.RESPONSE_JOB_JOBSTATE_MUST_BE_OFFLINE; 169 return response; 170 } 171 if (job.Id != Guid.Empty) { 172 response.Success = false; 173 response.StatusMessage = ApplicationConstants.RESPONSE_JOB_ID_MUST_NOT_BE_SET; 174 return response; 175 } 176 if (job.SerializedJob == null) { 177 response.StatusMessage = ApplicationConstants.RESPONSE_JOB_JOB_NULL; 178 response.Success = false; 179 return response; 180 } 181 182 job.DateCreated = DateTime.Now; 183 jobAdapter.Update(job); 184 response.Success = true; 185 response.Obj = job; 186 response.StatusMessage = ApplicationConstants.RESPONSE_JOB_JOB_ADDED; 187 } else { 119 188 response.Success = false; 120 response.StatusMessage = ApplicationConstants.RESPONSE_JOB_JOBSTATE_MUST_BE_OFFLINE;121 return response;122 }123 if (job.Id != Guid.Empty) {124 response.Success = false;125 response.StatusMessage = ApplicationConstants.RESPONSE_JOB_ID_MUST_NOT_BE_SET;126 return response;127 }128 if (job.SerializedJob == null) {129 189 response.StatusMessage = ApplicationConstants.RESPONSE_JOB_JOB_NULL; 130 response.Success = false; 131 return response; 132 } 133 134 job.DateCreated = DateTime.Now; 135 jobAdapter.Update(job); 136 response.Success = true; 137 response.Obj = job; 138 response.StatusMessage = ApplicationConstants.RESPONSE_JOB_JOB_ADDED; 139 } else { 140 response.Success = false; 141 response.StatusMessage = ApplicationConstants.RESPONSE_JOB_JOB_NULL; 142 } 143 144 return response; 190 } 191 192 return response; 193 } 194 finally { 195 if (session != null) 196 session.EndSession(); 197 } 145 198 } 146 199 … … 151 204 /// <returns></returns> 152 205 public Response RemoveJob(Guid jobId) { 153 Response response = new Response(); 154 155 Job job = jobAdapter.GetById(jobId); 156 if (job == null) { 206 ISession session = factory.GetSessionForCurrentThread(); 207 208 try { 209 IJobAdapter jobAdapter = 210 session.GetDataAdapter<Job, IJobAdapter>(); 211 Response response = new Response(); 212 213 Job job = jobAdapter.GetById(jobId); 214 if (job == null) { 215 response.Success = false; 216 response.StatusMessage = ApplicationConstants.RESPONSE_JOB_JOB_DOESNT_EXIST; 217 return response; 218 } 219 jobAdapter.Delete(job); 157 220 response.Success = false; 158 response.StatusMessage = ApplicationConstants.RESPONSE_JOB_JOB_DOESNT_EXIST; 221 response.StatusMessage = ApplicationConstants.RESPONSE_JOB_JOB_REMOVED; 222 159 223 return response; 160 224 } 161 jobAdapter.Delete(job); 162 response.Success = false; 163 response.StatusMessage = ApplicationConstants.RESPONSE_JOB_JOB_REMOVED; 164 165 return response; 225 finally { 226 if (session != null) 227 session.EndSession(); 228 } 166 229 } 167 230 168 231 public ResponseObject<JobResult> GetLastJobResultOf(Guid jobId) { 169 ResponseObject<JobResult> response = new ResponseObject<JobResult>(); 170 response.Success = true; 171 response.StatusMessage = ApplicationConstants.RESPONSE_JOB_JOB_RESULT_SENT; 172 response.Obj = GetLastJobResult(jobAdapter.GetById(jobId)); 173 174 return response; 232 ISession session = factory.GetSessionForCurrentThread(); 233 234 try { 235 IJobAdapter jobAdapter = 236 session.GetDataAdapter<Job, IJobAdapter>(); 237 238 ResponseObject<JobResult> response = new ResponseObject<JobResult>(); 239 response.Success = true; 240 response.StatusMessage = ApplicationConstants.RESPONSE_JOB_JOB_RESULT_SENT; 241 response.Obj = GetLastJobResult(jobAdapter.GetById(jobId)); 242 243 return response; 244 } 245 finally { 246 if(session != null) 247 session.EndSession(); 248 } 175 249 } 176 250 -
trunk/sources/HeuristicLab.Hive.Server.Core/LifecycleManager.cs
r1377 r1468 65 65 } 66 66 67 public IDBSynchronizer GetDBSynchronizer() {68 return ServiceLocator.GetDBSynchronizer();69 }70 71 67 public void Shutdown() { 72 ServiceLocator.GetDBSynchronizer().UpdateDB();73 74 68 if (OnShutdown != null) 75 69 OnShutdown(this, null); -
trunk/sources/HeuristicLab.Hive.Server.Core/ServiceLocator.cs
r1377 r1468 27 27 using HeuristicLab.Hive.Server.Core.InternalInterfaces; 28 28 using HeuristicLab.DataAccess.Interfaces; 29 using System.Data.SqlClient; 29 30 30 31 /// <summary> … … 34 35 private static DiscoveryService discoveryService = 35 36 new DiscoveryService(); 36 37 private static IDBSynchronizer transManager = null;38 37 39 38 private static IClientManager clientManager = null; … … 45 44 private static ILifecycleManager lifecycleManager = null; 46 45 47 private static IClientAdapter clientAdapter = null; 48 49 private static IClientGroupAdapter clientGroupAdapter = null; 50 51 private static IResourceAdapter resourceAdapter = null; 52 53 private static IJobAdapter jobAdapter = null; 54 55 private static IJobResultsAdapter jobResultsAdapter = null; 46 private static ISessionFactory sessionFactory = null; 56 47 57 48 private static IScheduler scheduler = null; 58 59 60 /// <summary>61 /// Gets the db transaction manager62 /// </summary>63 /// <returns></returns>64 [MethodImpl(MethodImplOptions.Synchronized)]65 public static IDBSynchronizer GetDBSynchronizer() {66 if (transManager == null) {67 transManager = discoveryService.GetInstances<IDBSynchronizer>()[0];68 }69 70 return transManager;71 }72 49 73 50 /// <summary> … … 121 98 122 99 /// <summary> 123 /// Gets the client database adapter100 /// Gets the db session factory 124 101 /// </summary> 125 102 /// <returns></returns> 126 103 [MethodImpl(MethodImplOptions.Synchronized)] 127 public static IClientAdapter GetClientAdapter() { 128 if (clientAdapter == null) { 129 clientAdapter = discoveryService.GetInstances<IClientAdapter>()[0]; 104 public static ISessionFactory GetSessionFactory() { 105 if (sessionFactory == null) { 106 sessionFactory = 107 discoveryService.GetInstances<ISessionFactory>()[0]; 108 109 sessionFactory.DbConnectionType = 110 typeof(SqlConnection); 111 112 sessionFactory.DbConnectionString = 113 HeuristicLab.Hive.Server.Core.Properties.Settings.Default.HiveServerConnectionString; 130 114 } 131 115 132 return clientAdapter; 133 } 134 135 /// <summary> 136 /// Gets the client group database adapter 137 /// </summary> 138 /// <returns></returns> 139 [MethodImpl(MethodImplOptions.Synchronized)] 140 public static IClientGroupAdapter GetClientGroupAdapter() { 141 if (clientGroupAdapter == null) { 142 clientGroupAdapter = discoveryService.GetInstances<IClientGroupAdapter>()[0]; 143 } 144 145 return clientGroupAdapter; 146 } 147 148 /// <summary> 149 /// Gets the resource database adapter 150 /// </summary> 151 /// <returns></returns> 152 [MethodImpl(MethodImplOptions.Synchronized)] 153 public static IResourceAdapter GetResourceAdapter() { 154 if (resourceAdapter == null) { 155 resourceAdapter = discoveryService.GetInstances<IResourceAdapter>()[0]; 156 } 157 158 return resourceAdapter; 159 } 160 161 /// <summary> 162 /// Gets the job database adapter 163 /// </summary> 164 /// <returns></returns> 165 [MethodImpl(MethodImplOptions.Synchronized)] 166 public static IJobAdapter GetJobAdapter() { 167 if (jobAdapter == null) { 168 jobAdapter = discoveryService.GetInstances<IJobAdapter>()[0]; 169 } 170 171 return jobAdapter; 172 } 173 174 /// <summary> 175 /// Gets the job results database adapter 176 /// </summary> 177 /// <returns></returns> 178 [MethodImpl(MethodImplOptions.Synchronized)] 179 public static IJobResultsAdapter GetJobResultsAdapter() { 180 if (jobResultsAdapter == null) { 181 jobResultsAdapter = discoveryService.GetInstances<IJobResultsAdapter>()[0]; 182 } 183 184 return jobResultsAdapter; 116 return sessionFactory; 185 117 } 186 118 -
trunk/sources/HeuristicLab.Hive.Server.DataAccess/IClientAdapter.cs
r1377 r1468 37 37 /// <returns></returns> 38 38 ClientInfo GetByName(string name); 39 40 /// <summary>41 /// Get the client with the specified id42 /// </summary>43 /// <param name="clientId"></param>44 /// <returns></returns>45 ClientInfo GetById(Guid id);46 39 } 47 40 } -
trunk/sources/HeuristicLab.Hive.Server.Scheduler/DefaultScheduler.cs
r1377 r1468 7 7 using HeuristicLab.Hive.Server.DataAccess; 8 8 using System.Threading; 9 using HeuristicLab.DataAccess.Interfaces; 9 10 10 11 namespace HeuristicLab.Hive.Server.Scheduler { 11 12 class DefaultScheduler: IScheduler { 12 13 13 IJobAdapter jobAdapter; 14 IClientAdapter clientAdapter; 14 private ISessionFactory factory; 15 15 16 16 private static Mutex jobLock = … … 20 20 21 21 public DefaultScheduler() { 22 jobAdapter = ServiceLocator.GetJobAdapter(); 23 clientAdapter = ServiceLocator.GetClientAdapter(); 22 factory = ServiceLocator.GetSessionFactory(); 24 23 } 25 24 26 25 public bool ExistsJobForClient(HeuristicLab.Hive.Contracts.BusinessObjects.HeartBeatData hbData) { 27 List<Job> allOfflineJobs = new List<Job>(jobAdapter.GetJobsByState(State.offline)); 28 return (allOfflineJobs.Count > 0); 26 ISession session = factory.GetSessionForCurrentThread(); 27 28 try { 29 IJobAdapter jobAdapter = 30 session.GetDataAdapter<Job, IJobAdapter>(); 31 32 List<Job> allOfflineJobs = new List<Job>(jobAdapter.GetJobsByState(State.offline)); 33 return (allOfflineJobs.Count > 0); 34 } 35 finally { 36 if (session != null) 37 session.EndSession(); 38 } 29 39 } 30 40 31 41 public HeuristicLab.Hive.Contracts.BusinessObjects.Job GetNextJobForClient(Guid clientId) { 42 ISession session = factory.GetSessionForCurrentThread(); 32 43 33 /// Critical section /// 34 jobLock.WaitOne(); 44 try { 45 IJobAdapter jobAdapter = 46 session.GetDataAdapter<Job, IJobAdapter>(); 35 47 36 LinkedList<Job> allOfflineJobs = new LinkedList<Job>(jobAdapter.GetJobsByState(State.offline)); 48 IClientAdapter clientAdapter = 49 session.GetDataAdapter<ClientInfo, IClientAdapter>(); 37 50 38 Job job2Calculate = null; 39 if (allOfflineJobs != null && allOfflineJobs.Count > 0) { 40 job2Calculate = allOfflineJobs.First.Value; 41 job2Calculate.State = State.calculating; 42 job2Calculate.Client = clientAdapter.GetById(clientId); 43 job2Calculate.Client.State = State.calculating; 51 /// Critical section /// 52 jobLock.WaitOne(); 44 53 45 job2Calculate.DateCalculated = DateTime.Now; 46 jobAdapter.Update(job2Calculate); 54 LinkedList<Job> allOfflineJobs = new LinkedList<Job>(jobAdapter.GetJobsByState(State.offline)); 55 56 Job job2Calculate = null; 57 if (allOfflineJobs != null && allOfflineJobs.Count > 0) { 58 job2Calculate = allOfflineJobs.First.Value; 59 job2Calculate.State = State.calculating; 60 job2Calculate.Client = clientAdapter.GetById(clientId); 61 job2Calculate.Client.State = State.calculating; 62 63 job2Calculate.DateCalculated = DateTime.Now; 64 jobAdapter.Update(job2Calculate); 65 } 66 jobLock.ReleaseMutex(); 67 /// End Critical section /// 68 69 return job2Calculate; 47 70 } 48 jobLock.ReleaseMutex();49 /// End Critical section ///50 51 return job2Calculate;71 finally { 72 if (session != null) 73 session.EndSession(); 74 } 52 75 } 53 76 -
trunk/sources/HeuristicLab.Hive.Server.Scheduler/HeuristicLab.Hive.Server.Scheduler.csproj
r1377 r1468 73 73 </ItemGroup> 74 74 <ItemGroup> 75 <ProjectReference Include="..\HeuristicLab.DataAccess.ADOHelper\HeuristicLab.DataAccess.ADOHelper.csproj"> 76 <Project>{5CDACE54-5FB2-4344-A21C-963F63CB7C2B}</Project> 77 <Name>HeuristicLab.DataAccess.ADOHelper</Name> 78 </ProjectReference> 75 79 <ProjectReference Include="..\HeuristicLab.DataAccess\HeuristicLab.DataAccess.csproj"> 76 80 <Project>{9076697B-C151-46CD-95BC-1D059492B478}</Project> -
trunk/sources/HeuristicLab.Hive.Server/HiveServerApplication.cs
r1377 r1468 158 158 159 159 lifecycleManager.Init(); 160 //sync with db every 30 seconds161 lifecycleManager.GetDBSynchronizer().EnableAutoUpdate(162 new TimeSpan(0, 0, 30));163 160 164 161 Form mainForm = new MainForm(baseAddrDict); -
trunk/sources/HeuristicLab/MergeConfigs.cmd
r1467 r1468 3 3 ConfigMerger "%SolutionDir%\HeuristicLab.Hive.Client.Core\%Outdir%\HeuristicLab.Hive.Client.Core-3.2.dll.config" "HeuristicLab.exe.config" 4 4 ConfigMerger "%SolutionDir%\HeuristicLab.Hive.Client.Console\%Outdir%\HeuristicLab.Hive.Client.Console-3.2.dll.config" "HeuristicLab.exe.config" 5 ConfigMerger "%SolutionDir%\HeuristicLab.Hive.Server. ADODataAccess\%Outdir%\HeuristicLab.Hive.Server.ADODataAccess-3.2.dll.config" "HeuristicLab.exe.config"5 ConfigMerger "%SolutionDir%\HeuristicLab.Hive.Server.Core\%Outdir%\HeuristicLab.Hive.Server.Core-3.2.dll.config" "HeuristicLab.exe.config" 6 6 ConfigMerger "%SolutionDir%\HeuristicLab.Persistence\%Outdir%\HeuristicLab.Persistence-3.3.dll.config" "HeuristicLab.exe.config" 7 7 ConfigMerger "%SolutionDir%\HeuristicLab.Tracing\%Outdir%\HeuristicLab.Tracing-1.0.dll.config" "HeuristicLab.exe.config"
Note: See TracChangeset
for help on using the changeset viewer.