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.compute.domain;
20  
21  import static com.google.common.base.Preconditions.checkNotNull;
22  
23  import javax.annotation.Nullable;
24  
25  import com.google.common.annotations.Beta;
26  
27  /**
28   * Running Operating system
29   * 
30   * @author Adrian Cole
31   */
32  @Beta
33  public class OperatingSystem {
34     @Nullable
35     private OsFamily family;
36     @Nullable
37     private String name;
38     @Nullable
39     private String arch;
40     @Nullable
41     private String version;
42     private String description;
43     private boolean is64Bit;
44  
45     // for serialization/deserialization
46     protected OperatingSystem() {
47  
48     }
49  
50     public OperatingSystem(@Nullable OsFamily family, @Nullable String name, @Nullable String version,
51           @Nullable String arch, String description, boolean is64Bit) {
52        this.family = family;
53        this.name = name;
54        this.arch = arch;
55        this.version = version;
56        this.description = checkNotNull(description, "description");
57        this.is64Bit = is64Bit;
58     }
59  
60     /**
61      * Type of the operating system
62      * <p/>
63      * generally, this is used to compare the means by which you use an operating
64      * system. For example, to determine compatibility of a particular
65      * bootstrapping or package installation approach.
66      */
67     @Nullable
68     public OsFamily getFamily() {
69        return family;
70     }
71  
72     /**
73      * name of the operating system; ex. {@code Red Hat Enterprise Linux}
74      * 
75      * <h2>note</h2> While this looks similar to, and may in some cases be the
76      * same as the java system property {@code os.name} it isn't guaranteed to
77      * match a particular value. For example, this value could be derived from
78      * data parsed for a cloud api or the OVF CIM OSType enum value;
79      * 
80      * @return operating system name or null if it couldn't be determined.
81      */
82     @Nullable
83     public String getName() {
84        return name;
85     }
86  
87     /**
88      * architecture of the operating system; ex. {@code x86_64}
89      * <p/>
90      * generally, this is used to decide whether an operating system will run
91      * certain binaries, for example, a 64bit JDK.
92      * 
93      * <h2>note</h2>
94      * While this looks similar to, and may in some cases be the same as the java
95      * system property {@code os.arch} it isn't guaranteed to match a particular
96      * value. For example, this value could be derived from data parsed for a
97      * cloud api or the OVF CIM OSType enum value;
98      * 
99      * @return operating system architecture or null if it couldn't be
100     *         determined.
101     */
102    @Nullable
103    public String getArch() {
104       return arch;
105    }
106 
107    /**
108     * version of the operating system; ex. {@code 10.0.4}
109     * <p/>
110     * generally, this is used to compare versions of the same operating system
111     * name. It should be meaningful when sorted against, although this isn't
112     * necessary.
113     * <h2>note</h2>
114     * While this looks similar to, and may in some cases be the same as the java
115     * system property {@code os.version} it isn't guaranteed to match a
116     * particular value. For example, this value could be derived from data
117     * parsed for a cloud api or the OVF CIM OSType enum value;
118     * 
119     * @return operating system version or null if it couldn't be determined.
120     */
121    @Nullable
122    public String getVersion() {
123       return version;
124    }
125 
126    /**
127     * description of the operating system; ex. {@code CentOS 32-bit},{@code
128     * Other Linux (32-bit)}
129     * <p/>
130     * This is the only required field in the operating system object. In some
131     * implementations, it is this data that is used to parse the value of the
132     * {@link #name}, {@link #version}, and {@link #arch} fields.
133     * 
134     * @return operating system description
135     */
136    public String getDescription() {
137       return description;
138    }
139 
140    /**
141     * 
142     * @return whether this operating system supports 64 bit computation.
143     */
144    public boolean is64Bit() {
145       return is64Bit;
146    }
147 
148    @Override
149    public int hashCode() {
150       final int prime = 31;
151       int result = 1;
152       result = prime * result + ((arch == null) ? 0 : arch.hashCode());
153       result = prime * result + ((description == null) ? 0 : description.hashCode());
154       result = prime * result + ((family == null) ? 0 : family.hashCode());
155       result = prime * result + (is64Bit ? 1231 : 1237);
156       result = prime * result + ((name == null) ? 0 : name.hashCode());
157       result = prime * result + ((version == null) ? 0 : version.hashCode());
158       return result;
159    }
160 
161    @Override
162    public boolean equals(Object obj) {
163       if (this == obj)
164          return true;
165       if (obj == null)
166          return false;
167       if (getClass() != obj.getClass())
168          return false;
169       OperatingSystem other = (OperatingSystem) obj;
170       if (arch == null) {
171          if (other.arch != null)
172             return false;
173       } else if (!arch.equals(other.arch))
174          return false;
175       if (description == null) {
176          if (other.description != null)
177             return false;
178       } else if (!description.equals(other.description))
179          return false;
180       if (family == null) {
181          if (other.family != null)
182             return false;
183       } else if (!family.equals(other.family))
184          return false;
185       if (is64Bit != other.is64Bit)
186          return false;
187       if (name == null) {
188          if (other.name != null)
189             return false;
190       } else if (!name.equals(other.name))
191          return false;
192       if (version == null) {
193          if (other.version != null)
194             return false;
195       } else if (!version.equals(other.version))
196          return false;
197       return true;
198    }
199 
200    @Override
201    public String toString() {
202       return "[name=" + name + ", family=" + family + ", version=" + version + ", arch=" + arch + ", is64Bit="
203             + is64Bit + ", description=" + description + "]";
204    }
205 
206 }