View Javadoc
1   /*
2    * Licensed to The Apereo Foundation under one or more contributor license
3    * agreements. See the NOTICE file distributed with this work for additional
4    * information regarding copyright ownership.
5    *
6    *
7    * The Apereo Foundation licenses this file to you under the Educational
8    * Community License, Version 2.0 (the "License"); you may not use this file
9    * except in compliance with the License. You may obtain a copy of the License
10   * at:
11   *
12   *   http://opensource.org/licenses/ecl2.txt
13   *
14   * Unless required by applicable law or agreed to in writing, software
15   * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
16   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
17   * License for the specific language governing permissions and limitations under
18   * the License.
19   *
20   */
21  
22  package org.opencastproject.serviceregistry.api;
23  
24  import javax.xml.bind.annotation.XmlAccessType;
25  import javax.xml.bind.annotation.XmlAccessorType;
26  import javax.xml.bind.annotation.XmlElement;
27  import javax.xml.bind.annotation.XmlRootElement;
28  import javax.xml.bind.annotation.XmlType;
29  
30  /**
31   * A record of a host.
32   */
33  @XmlAccessorType(XmlAccessType.NONE)
34  @XmlType(name = "host", namespace = "http://serviceregistry.opencastproject.org")
35  @XmlRootElement(name = "host", namespace = "http://serviceregistry.opencastproject.org")
36  public class JaxbHostRegistration implements HostRegistration {
37  
38    /**
39     * The base URL for this host. The length was chosen this short because MySQL complains when trying to create an index
40     * larger than this
41     */
42    @XmlElement(name = "base_url")
43    protected String baseUrl;
44  
45    @XmlElement(name = "address")
46    protected String address;
47  
48    @XmlElement(name = "node_name")
49    protected String nodeName;
50  
51    @XmlElement(name = "memory")
52    protected long memory;
53  
54    @XmlElement(name = "cores")
55    protected int cores;
56  
57    /**
58     * The maximum load this host can run.  This is not necessarily 1-to-1 with the number of jobs.
59     */
60    @XmlElement(name = "max_load")
61    protected float maxLoad;
62  
63    @XmlElement(name = "online")
64    protected boolean online;
65  
66    @XmlElement(name = "active")
67    protected boolean active;
68  
69    @XmlElement(name = "maintenance")
70    protected boolean maintenanceMode;
71  
72    /**
73     * Creates a new host registration which is online and not in maintenance mode.
74     */
75    public JaxbHostRegistration() {
76      this.online = true;
77      this.active = true;
78      this.maintenanceMode = false;
79    }
80  
81    /**
82     * Constructs a new HostRegistration with the parameters provided
83     *
84     * @param baseUrl
85     *          the base URL for this host
86     * @param address
87     *          the IP address for this host
88     * @param nodeName
89     *          descriptive node name for this host
90     * @param memory
91     *          the allocated memory of this host
92     * @param cores
93     *          the available cores of this host
94     * @param maxLoad
95     *          the maximum load that this host can support
96     * @param online
97     *          whether the host is online and available for service
98     * @param online
99     *          whether the host is in maintenance mode
100    */
101   public JaxbHostRegistration(String baseUrl, String address, String nodeName, long memory, int cores, float maxLoad, boolean online,
102           boolean maintenance) {
103     this.baseUrl = baseUrl;
104     this.address = address;
105     this.nodeName = nodeName;
106     this.memory = memory;
107     this.cores = cores;
108     this.maxLoad = maxLoad;
109     this.online = online;
110     this.maintenanceMode = maintenance;
111     this.active = true;
112   }
113 
114   /**
115    * Creates a new JAXB host registration based on an existing host registration
116    *
117    * @param hostRegistration
118    */
119   public JaxbHostRegistration(HostRegistration hostRegistration) {
120     this.baseUrl = hostRegistration.getBaseUrl();
121     this.address = hostRegistration.getIpAddress();
122     this.nodeName = hostRegistration.getNodeName();
123     this.memory = hostRegistration.getMemory();
124     this.cores = hostRegistration.getCores();
125     this.maxLoad = hostRegistration.getMaxLoad();
126     this.online = hostRegistration.isOnline();
127     this.active = hostRegistration.isActive();
128     this.maintenanceMode = hostRegistration.isMaintenanceMode();
129   }
130 
131   @Override
132   public Long getId() {
133     return (long) baseUrl.hashCode();
134   }
135 
136   /**
137    * {@inheritDoc}
138    *
139    * @see org.opencastproject.serviceregistry.api.HostRegistration#getBaseUrl()
140    */
141   @Override
142   public String getBaseUrl() {
143     return baseUrl;
144   }
145 
146   /**
147    * {@inheritDoc}
148    *
149    * @see org.opencastproject.serviceregistry.api.HostRegistration#setBaseUrl(String)
150    */
151   @Override
152   public void setBaseUrl(String baseUrl) {
153     this.baseUrl = baseUrl;
154   }
155 
156   /**
157    * {@inheritDoc}
158    *
159    * @see org.opencastproject.serviceregistry.api.HostRegistration#getIpAddress()
160    */
161   @Override
162   public String getIpAddress() {
163     return address;
164   }
165 
166   /**
167    * {@inheritDoc}
168    *
169    * @see org.opencastproject.serviceregistry.api.HostRegistration#setIpAddress(String)
170    */
171   @Override
172   public void setIpAddress(String address) {
173     this.address = address;
174   }
175 
176   /**
177    * {@inheritDoc}
178    *
179    * @see org.opencastproject.serviceregistry.api.HostRegistration#getMemory()
180    */
181   @Override
182   public long getMemory() {
183     return memory;
184   }
185 
186   /**
187    * {@inheritDoc}
188    *
189    * @see org.opencastproject.serviceregistry.api.HostRegistration#setMemory(long)
190    */
191   @Override
192   public void setMemory(long memory) {
193     this.memory = memory;
194   }
195 
196   /**
197    * {@inheritDoc}
198    *
199    * @see org.opencastproject.serviceregistry.api.HostRegistration#getCores()
200    */
201   @Override
202   public int getCores() {
203     return cores;
204   }
205 
206   /**
207    * {@inheritDoc}
208    *
209    * @see org.opencastproject.serviceregistry.api.HostRegistration#setCores(int)
210    */
211   @Override
212   public void setCores(int cores) {
213     this.cores = cores;
214   }
215 
216   /**
217    * {@inheritDoc}
218    *
219    * @see org.opencastproject.serviceregistry.api.HostRegistration#getMaxLoad()
220    */
221   @Override
222   public float getMaxLoad() {
223     return maxLoad;
224   }
225 
226   @Override
227   public void setMaxLoad(float maxLoad) {
228     this.maxLoad = maxLoad;
229   }
230 
231   /**
232    * {@inheritDoc}
233    *
234    * @see org.opencastproject.serviceregistry.api.HostRegistration#isActive()
235    */
236   @Override
237   public boolean isActive() {
238     return active;
239   }
240 
241   /**
242    * {@inheritDoc}
243    *
244    * @see org.opencastproject.serviceregistry.api.HostRegistration#setActive(boolean)
245    */
246   @Override
247   public void setActive(boolean active) {
248     this.active = active;
249   }
250 
251   /**
252    * {@inheritDoc}
253    *
254    * @see org.opencastproject.serviceregistry.api.HostRegistration#isOnline()
255    */
256   @Override
257   public boolean isOnline() {
258     return online;
259   }
260 
261   /**
262    * {@inheritDoc}
263    *
264    * @see org.opencastproject.serviceregistry.api.HostRegistration#setOnline(boolean)
265    */
266   @Override
267   public void setOnline(boolean online) {
268     this.online = online;
269   }
270 
271   /**
272    * {@inheritDoc}
273    *
274    * @see org.opencastproject.serviceregistry.api.HostRegistration#isMaintenanceMode()
275    */
276   @Override
277   public boolean isMaintenanceMode() {
278     return maintenanceMode;
279   }
280 
281   /**
282    * {@inheritDoc}
283    *
284    * @see org.opencastproject.serviceregistry.api.HostRegistration#setMaintenanceMode(boolean)
285    */
286   @Override
287   public void setMaintenanceMode(boolean maintenanceMode) {
288     this.maintenanceMode = maintenanceMode;
289   }
290 
291   /**
292    * {@inheritDoc}
293    *
294    * @see java.lang.Object#hashCode()
295    */
296   @Override
297   public int hashCode() {
298     return toString().hashCode();
299   }
300 
301   /**
302    * {@inheritDoc}
303    *
304    * @see java.lang.Object#equals(java.lang.Object)
305    */
306   @Override
307   public boolean equals(Object obj) {
308     if (!(obj instanceof HostRegistration))
309       return false;
310     HostRegistration registration = (HostRegistration) obj;
311     return baseUrl.equals(registration.getBaseUrl());
312   }
313 
314   /**
315    * {@inheritDoc}
316    *
317    * @see java.lang.Object#toString()
318    */
319   @Override
320   public String toString() {
321     return baseUrl;
322   }
323 
324   /**
325    * {@inheritDoc}
326    *
327    * @see org.opencastproject.serviceregistry.api.HostRegistration#getNodeName()
328    */
329   @Override
330   public String getNodeName() {
331     return nodeName;
332   }
333 
334   /**
335    * {@inheritDoc}
336    *
337    * @see org.opencastproject.serviceregistry.api.HostRegistration#setNodeName(String)
338    */
339   @Override
340   public void setNodeName(String nodeName) {
341     this.nodeName = nodeName;
342   }
343 }