1 | #region License Information
|
---|
2 |
|
---|
3 | /* HeuristicLab
|
---|
4 | * Copyright (C) 2002-2008 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
5 | *
|
---|
6 | * This file is part of HeuristicLab.
|
---|
7 | *
|
---|
8 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
9 | * it under the terms of the GNU General Public License as published by
|
---|
10 | * the Free Software Foundation, either version 3 of the License, or
|
---|
11 | * (at your option) any later version.
|
---|
12 | *
|
---|
13 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
16 | * GNU General Public License for more details.
|
---|
17 | *
|
---|
18 | * You should have received a copy of the GNU General Public License
|
---|
19 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
20 | */
|
---|
21 |
|
---|
22 | #endregion
|
---|
23 |
|
---|
24 | using System;
|
---|
25 | using System.Collections.Generic;
|
---|
26 | using System.Linq;
|
---|
27 | using System.Text;
|
---|
28 | using HeuristicLab.Hive.Contracts.Interfaces;
|
---|
29 | using HeuristicLab.Hive.Contracts.BusinessObjects;
|
---|
30 | using HeuristicLab.Hive.Contracts;
|
---|
31 | using HeuristicLab.Hive.Server.DataAccess;
|
---|
32 | using HeuristicLab.DataAccess.Interfaces;
|
---|
33 | using HeuristicLab.Hive.Server.LINQDataAccess;
|
---|
34 | using SlaveGroup=HeuristicLab.Hive.Contracts.BusinessObjects.SlaveGroupDto;
|
---|
35 | using HeuristicLab.Hive.Contracts.ResponseObjects;
|
---|
36 |
|
---|
37 | namespace HeuristicLab.Hive.Server.Core {
|
---|
38 | internal class SlaveManager : ISlaveManager {
|
---|
39 | private List<SlaveGroup> slaveGroups;
|
---|
40 |
|
---|
41 | public SlaveManager() {
|
---|
42 | slaveGroups = new List<SlaveGroup>();
|
---|
43 | }
|
---|
44 |
|
---|
45 | #region ISlaveManager Members
|
---|
46 |
|
---|
47 | /// <summary>
|
---|
48 | /// Returns all slaves stored in the database
|
---|
49 | /// </summary>
|
---|
50 | /// <returns></returns>
|
---|
51 | public ResponseList<SlaveDto> GetAllSlaves() {
|
---|
52 | ResponseList<SlaveDto> response = new ResponseList<SlaveDto>();
|
---|
53 | response.List = new List<SlaveDto>(DaoLocator.SlaveDao.FindAll());
|
---|
54 | return response;
|
---|
55 | }
|
---|
56 |
|
---|
57 | /// <summary>
|
---|
58 | /// returns all slave groups stored in the database
|
---|
59 | /// </summary>
|
---|
60 | /// <returns></returns>
|
---|
61 | public ResponseList<SlaveGroup> GetAllSlaveGroups() {
|
---|
62 | ResponseList<SlaveGroup> response = new ResponseList<SlaveGroup>();
|
---|
63 |
|
---|
64 | List<SlaveGroup> allSlaveGroups = new List<SlaveGroup>(DaoLocator.SlaveGroupDao.FindAllWithSubGroupsAndSlaves());
|
---|
65 | SlaveGroup emptySlaveGroup = new SlaveGroup();
|
---|
66 | IEnumerable<SlaveDto> groupLessSlaves = DaoLocator.SlaveDao.FindAllSlavesWithoutGroup();
|
---|
67 | if (groupLessSlaves != null) {
|
---|
68 | foreach (SlaveDto currSlave in groupLessSlaves) {
|
---|
69 | emptySlaveGroup.Resources.Add(currSlave);
|
---|
70 | }
|
---|
71 | }
|
---|
72 | emptySlaveGroup.Id = Guid.Empty;
|
---|
73 | allSlaveGroups.Add(emptySlaveGroup);
|
---|
74 |
|
---|
75 | response.List = allSlaveGroups;
|
---|
76 |
|
---|
77 | return response;
|
---|
78 | }
|
---|
79 |
|
---|
80 | /// <summary>
|
---|
81 | /// [chn] check usage
|
---|
82 | /// </summary>
|
---|
83 | public ResponseList<UpTimeStatisticsDto> GetAllUpTimeStatistics() {
|
---|
84 | return new ResponseList<UpTimeStatisticsDto>();
|
---|
85 | }
|
---|
86 |
|
---|
87 | /// <summary>
|
---|
88 | /// Add a slave group into the database
|
---|
89 | /// </summary>
|
---|
90 | /// <param name="slaveGroup"></param>
|
---|
91 | /// <returns></returns>
|
---|
92 | public ResponseObject<SlaveGroup> AddSlaveGroup(SlaveGroup slaveGroup) {
|
---|
93 | ResponseObject<SlaveGroup> response = new ResponseObject<SlaveGroup>();
|
---|
94 |
|
---|
95 | if (slaveGroup.Id != Guid.Empty) {
|
---|
96 | //response.Success = false;
|
---|
97 | response.StatusMessage = ResponseStatus.AddSlaveGroup_SlaveIdMustNotBeSet;
|
---|
98 | }
|
---|
99 | else {
|
---|
100 | slaveGroup = DaoLocator.SlaveGroupDao.Insert(slaveGroup);
|
---|
101 | //slaveGroupAdapter.Update(slaveGroup);
|
---|
102 | response.Obj = slaveGroup;
|
---|
103 | }
|
---|
104 |
|
---|
105 | return response;
|
---|
106 | }
|
---|
107 |
|
---|
108 | /// <summary>
|
---|
109 | /// Add a resource to a group
|
---|
110 | /// </summary>
|
---|
111 | /// <param name="slaveGroupId"></param>
|
---|
112 | /// <param name="resource"></param>
|
---|
113 | /// <returns></returns>
|
---|
114 | public Response AddResourceToGroup(Guid slaveGroupId, ResourceDto resource) {
|
---|
115 | Response response = new Response();
|
---|
116 |
|
---|
117 | SlaveGroup slaveGroup = DaoLocator.SlaveGroupDao.FindById(slaveGroupId);
|
---|
118 | if (slaveGroup == null) {
|
---|
119 | //response.Success = false;
|
---|
120 | response.StatusMessage = ResponseStatus.AddResourceToGroup_SlaveGroupDoesNotExist;
|
---|
121 | return response;
|
---|
122 | }
|
---|
123 |
|
---|
124 | slaveGroup.Resources.Add(resource);
|
---|
125 | DaoLocator.SlaveGroupDao.AddRessourceToSlaveGroup(resource.Id, slaveGroup.Id);
|
---|
126 |
|
---|
127 | //If our resource is in fact a slave => set the callendar from the resource as current one.
|
---|
128 |
|
---|
129 | SlaveDto dbr = DaoLocator.SlaveDao.FindById(resource.Id);
|
---|
130 | if(dbr != null) {
|
---|
131 | DaoLocator.SlaveDao.SetServerSideCalendar(dbr, slaveGroup.Id);
|
---|
132 | }
|
---|
133 |
|
---|
134 | return response;
|
---|
135 | }
|
---|
136 |
|
---|
137 | /// <summary>
|
---|
138 | /// Remove a resource from a group
|
---|
139 | /// </summary>
|
---|
140 | /// <param name="slaveGroupId"></param>
|
---|
141 | /// <param name="resourceId"></param>
|
---|
142 | /// <returns></returns>
|
---|
143 | public Response DeleteResourceFromGroup(Guid slaveGroupId, Guid resourceId) {
|
---|
144 | Response response = new Response();
|
---|
145 |
|
---|
146 | SlaveGroup slaveGroup = DaoLocator.SlaveGroupDao.FindById(slaveGroupId);
|
---|
147 | if (slaveGroup == null) {
|
---|
148 | // response.Success = false;
|
---|
149 | response.StatusMessage = ResponseStatus.AddResourceToGroup_SlaveGroupDoesNotExist;
|
---|
150 | return response;
|
---|
151 | }
|
---|
152 |
|
---|
153 | DaoLocator.SlaveGroupDao.RemoveRessourceFromSlaveGroup(resourceId, slaveGroup.Id);
|
---|
154 | return response;
|
---|
155 | }
|
---|
156 |
|
---|
157 | public ResponseObject<SlaveGroupDtoList> GetAllGroupsOfResource(Guid resourceId) {
|
---|
158 | ResponseObject<SlaveGroupDtoList> response = new ResponseObject<SlaveGroupDtoList>();
|
---|
159 |
|
---|
160 | SlaveDto slave = DaoLocator.SlaveDao.FindById(resourceId);
|
---|
161 | if (slave != null) {
|
---|
162 | SlaveGroupDtoList groupsOfSlave = new SlaveGroupDtoList(DaoLocator.SlaveGroupDao.MemberOf(slave));
|
---|
163 | response.Obj = groupsOfSlave;
|
---|
164 | } else {
|
---|
165 | response.Obj = new SlaveGroupDtoList();
|
---|
166 | //response.Success = false;
|
---|
167 | response.StatusMessage = ResponseStatus.GetAllGroupsOfResource_ResourceNotFound;
|
---|
168 | }
|
---|
169 |
|
---|
170 | return response;
|
---|
171 | }
|
---|
172 |
|
---|
173 | public Response DeleteSlaveGroup(Guid slaveGroupId) {
|
---|
174 | Response response = new Response();
|
---|
175 |
|
---|
176 | SlaveGroup slaveGroup = DaoLocator.SlaveGroupDao.FindById(slaveGroupId);
|
---|
177 | if (slaveGroup == null) {
|
---|
178 | response.StatusMessage = ResponseStatus.DeleteSlaveGroup_SlaveGroupDoesNotExist;
|
---|
179 | return response;
|
---|
180 | }
|
---|
181 |
|
---|
182 | DaoLocator.SlaveGroupDao.Delete(slaveGroup);
|
---|
183 | return response;
|
---|
184 | }
|
---|
185 |
|
---|
186 | public ResponseList<AppointmentDto> GetUptimeCalendarForResource(Guid guid) {
|
---|
187 | ResponseList<AppointmentDto> response = new ResponseList<AppointmentDto>();
|
---|
188 | response.List = new List<AppointmentDto>(DaoLocator.UptimeCalendarDao.GetUptimeCalendarForResource(guid));
|
---|
189 | return response;
|
---|
190 | }
|
---|
191 |
|
---|
192 | public Response SetUptimeCalendarForResource(Guid guid, IEnumerable<AppointmentDto> appointments, bool isForced) {
|
---|
193 | DaoLocator.UptimeCalendarDao.SetUptimeCalendarForResource(guid, appointments);
|
---|
194 | DaoLocator.UptimeCalendarDao.NotifySlavesOfNewCalendar(guid, isForced);
|
---|
195 | return new Response();
|
---|
196 | }
|
---|
197 | #endregion
|
---|
198 | }
|
---|
199 | } |
---|