View Javadoc

1   /**
2    *
3    * Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
4    *
5    * ====================================================================
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10   * http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   * ====================================================================
18   */
19  package org.jclouds.cloudsigma.domain;
20  
21  import java.util.Date;
22  import java.util.Map;
23  
24  import javax.annotation.Nullable;
25  
26  /**
27   * 
28   * @author Adrian Cole
29   */
30  public class ServerInfo extends Server {
31  
32     public static class Builder extends Server.Builder {
33        protected ServerStatus status;
34        protected Date started;
35        protected String user;
36        protected ServerMetrics metrics;
37  
38        public Builder status(ServerStatus status) {
39           this.status = status;
40           return this;
41        }
42  
43        public Builder started(Date started) {
44           this.started = started;
45           return this;
46        }
47  
48        public Builder user(String user) {
49           this.user = user;
50           return this;
51        }
52  
53        public Builder metrics(ServerMetrics metrics) {
54           this.metrics = metrics;
55           return this;
56        }
57  
58        /**
59         * {@inheritDoc}
60         */
61        @Override
62        public Builder cpu(int cpu) {
63           return Builder.class.cast(super.cpu(cpu));
64        }
65  
66        /**
67         * {@inheritDoc}
68         */
69        @Override
70        public Builder smp(Integer smp) {
71           return Builder.class.cast(super.smp(smp));
72        }
73  
74        /**
75         * {@inheritDoc}
76         */
77        @Override
78        public Builder mem(int mem) {
79           return Builder.class.cast(super.mem(mem));
80        }
81  
82        /**
83         * {@inheritDoc}
84         */
85        @Override
86        public Builder persistent(boolean persistent) {
87           return Builder.class.cast(super.persistent(persistent));
88        }
89  
90        /**
91         * {@inheritDoc}
92         */
93        @Override
94        public Builder devices(Map<String, ? extends Device> devices) {
95           return Builder.class.cast(super.devices(devices));
96        }
97  
98        /**
99         * {@inheritDoc}
100        */
101       @Override
102       public Builder bootDeviceIds(Iterable<String> bootDeviceIds) {
103          return Builder.class.cast(super.bootDeviceIds(bootDeviceIds));
104       }
105 
106       /**
107        * {@inheritDoc}
108        */
109       @Override
110       public Builder nics(Iterable<NIC> nics) {
111          return Builder.class.cast(super.nics(nics));
112       }
113 
114       /**
115        * {@inheritDoc}
116        */
117       @Override
118       public Builder vnc(VNC vnc) {
119          return Builder.class.cast(super.vnc(vnc));
120       }
121 
122       /**
123        * {@inheritDoc}
124        */
125       @Override
126       public Builder description(String description) {
127          return Builder.class.cast(super.description(description));
128       }
129 
130       /**
131        * {@inheritDoc}
132        */
133       @Override
134       public Builder uuid(String uuid) {
135          return Builder.class.cast(super.uuid(uuid));
136       }
137 
138       /**
139        * {@inheritDoc}
140        */
141       @Override
142       public Builder name(String name) {
143          return Builder.class.cast(super.name(name));
144       }
145 
146       /**
147        * {@inheritDoc}
148        */
149       @Override
150       public Builder use(Iterable<String> use) {
151          return Builder.class.cast(super.use(use));
152       }
153 
154       public ServerInfo build() {
155          return new ServerInfo(uuid, name, cpu, smp, mem, persistent, devices, bootDeviceIds, use, nics, vnc,
156                description, status, started, user, metrics);
157       }
158    }
159 
160    protected final ServerStatus status;
161    @Nullable
162    protected final Date started;
163    @Nullable
164    protected final String user;
165    protected final ServerMetrics metrics;
166 
167    public ServerInfo(String uuid, String name, int cpu, Integer smp, int mem, boolean persistent,
168          Map<String, ? extends Device> devices, Iterable<String> bootDeviceIds, Iterable<String> use,
169          Iterable<NIC> nics, VNC vnc, String description, ServerStatus status, Date started, String user,
170          @Nullable ServerMetrics metrics) {
171       super(uuid, name, cpu, smp, mem, persistent, devices, bootDeviceIds, use, nics, vnc, description);
172       this.status = status;
173       this.started = started;
174       this.user = user;
175       this.metrics = metrics;
176    }
177 
178    /**
179     * 
180     * @return active | stopped | paused | dumped | dead
181     */
182    public ServerStatus getStatus() {
183       return status;
184    }
185 
186    // TODO undocumented
187    public Date getStarted() {
188       return started;
189    }
190 
191    /**
192     * 
193     * @return metrics, if the server is running, or null
194     */
195    @Nullable
196    public ServerMetrics getMetrics() {
197       return metrics;
198    }
199 
200    // TODO undocumented
201    /**
202     * 
203     * @return owner of the server.
204     */
205    public String getUser() {
206       return user;
207    }
208 
209    @Override
210    public int hashCode() {
211       final int prime = 31;
212       int result = super.hashCode();
213       result = prime * result + ((metrics == null) ? 0 : metrics.hashCode());
214       result = prime * result + ((started == null) ? 0 : started.hashCode());
215       result = prime * result + ((status == null) ? 0 : status.hashCode());
216       result = prime * result + ((user == null) ? 0 : user.hashCode());
217       return result;
218    }
219 
220    @Override
221    public boolean equals(Object obj) {
222       if (this == obj)
223          return true;
224       if (!super.equals(obj))
225          return false;
226       if (getClass() != obj.getClass())
227          return false;
228       ServerInfo other = (ServerInfo) obj;
229       if (metrics == null) {
230          if (other.metrics != null)
231             return false;
232       } else if (!metrics.equals(other.metrics))
233          return false;
234       if (started == null) {
235          if (other.started != null)
236             return false;
237       } else if (!started.equals(other.started))
238          return false;
239       if (status != other.status)
240          return false;
241       if (user == null) {
242          if (other.user != null)
243             return false;
244       } else if (!user.equals(other.user))
245          return false;
246       return true;
247    }
248 
249    @Override
250    public String toString() {
251       return "[cpu=" + cpu + ", smp=" + smp + ", mem=" + mem + ", persistent=" + persistent + ", devices=" + devices
252             + ", bootDeviceIds=" + bootDeviceIds + ", nics=" + nics + ", vnc=" + vnc + ", uuid=" + uuid + ", name="
253             + name + ", use=" + use + ", status=" + status + ", started=" + started + ", user=" + user + ", metrics="
254             + metrics + "]";
255    }
256 
257 }