00001 package org.gridlab.gat.resources;
00002
00003 import java.util.List;
00004 import java.util.Map;
00005 import java.util.NoSuchElementException;
00006
00007 /**
00008 * An instance of this class is a description of a hardware resource, a physical
00009 * thing, which a may be required by a hardware or software component.
00010 * <p>
00011 *
00012 * To clarify the concept of a HardwareResourceDescription,
00013 * let us give various examples. Memory is described by a
00014 * HardwareResourceDescription; a network is described by a
00015 * HardwareResourceDescription; disk space is described by a
00016 * HardwareResourceDescription; a monitor is described a
00017 * HardwareResourceDescription\ldots
00018 * However, an application is not described by
00019 * a HardwareResourceDescription. In general any resource which corresponds to a
00020 * physical thing is described by a HardwareResourceDescription.
00021 * <p>
00022 * Hardware is generally useless without software. For example, a disk drive
00023 * without the appropriate software driver is all but useless. Similarly,
00024 * hardware often depends upon other hardware. For example, having a disk drive
00025 * without a computer again is not of much use. Hence, in describing a hardware
00026 * component one needs to also describe the software and hardware that this
00027 * hardware component requires. This is reflected in the fact that a
00028 * HardwareResourceDescription contains in addition to a description of a
00029 * hardware component a list of HardwareResourceDescriptions, each
00030 * element of which describes a hardware component upon which the parent
00031 * hardware component depends, and a list of
00032 * SoftwareResourceDescriptions, each element of which describes a software
00033 * component upon which the parent hardware component depends. Hence, the entire
00034 * structure is recursive.
00035 * <p>
00036 * To construct an instance of a HardwareResourceDescription one requires three
00037 * quantities:
00038 * <ul>
00039 * <li>A map which contains a set of name/value pairs, detailed
00040 * later, which describe a hardware resource.</li>
00041 * <li>A list of SoftwareResourceDescription instances each of which
00042 * describes a software resource upon which the parent hardware resource
00043 * depends.</li>
00044 * <i>A list of HardwareResourceDescription instances each of which
00045 * describes a hardware resource upon which the parent hardware resource
00046 * depends.</li>
00047 * </ul>
00048 * The GAT-API defines a minimum set of supported name/value pairs which can be
00049 * included in the java.util.Map used to construct a HardwareResourceDescription
00050 * instance. This minimum set of name/value pairs MUST be supported by any
00051 * implementation of the GAT-API. This minimum set of supported name/values is
00052 * given in the table
00053 *
00054 * <TABLE border="2" frame="box" rules="groups" summary="Minimum set of
00055 * supported name/value pairs"> <CAPTION>Minimum set of supported name/value
00056 * pairs </CAPTION> <COLGROUP align="left"> <COLGROUP align="center"> <COLGROUP
00057 * align="left" > <THEAD valign="top">
00058 * <TR>
00059 * <TH>Name
00060 * <TH>Type
00061 * <TH>Description <TBODY>
00062 * <TR>
00063 * <TD>memory.size
00064 * <TD>java.lang.Float
00065 * <TD>The minimum memory in GB.
00066 * <TR>
00067 * <TD>memory.accesstime
00068 * <TD>java.lang.Float
00069 * <TD>The minimum memory access time in ns.
00070 * <TR>
00071 * <TD>memory.str
00072 * <TD>java.lang.Float
00073 * <TD>The minimum sustained transfer rate in GB/s.
00074 * <TR>
00075 * <TD>machine.type
00076 * <TD>java.lang.String
00077 * <TD>The machine type as returned from uname -m
00078 * <TR>
00079 * <TD>machine.node
00080 * <TD>java.lang.String
00081 * <TD>The machine node as returned from uname -n
00082 * <TR>
00083 * <TD>cpu.type
00084 * <TD>java.lang.String
00085 * <TD>The generic cpu type as returned from uname -p
00086 * <TR>
00087 * <TD>cpu.speed
00088 * <TD>java.lang.Float
00089 * <TD>The minimum cpu speed in GHz.
00090 * <TR>
00091 * <TD>disk.size
00092 * <TD>java.lang.Float
00093 * <TD>The minimum size of the hard drive in GB.
00094 * <TR>
00095 * <TD>disk.accesstime
00096 * <TD>java.lang.Float
00097 * <TD>The minimum disk access time in ms.
00098 * <TR>
00099 * <TD>disk.str
00100 * <TD>java.lang.Float
00101 * <TD>The minimum sustained transfer rate in MB/s. <TBODY></TABLE>
00102 */00103publicclass HardwareResourceDescriptionimplementsResourceDescription {
00104
00105 /**
00106 * This member variable holds the Map which describes the "parent" hardware
00107 * component
00108 */00109private Map hardwareResourceDescription = null;
00110
00111 /**
00112 * This member variable holds a List of SoftwareResourceDescription's
00113 * describing each of which describes a software component upon which the
00114 * "parent" hardware component depends.
00115 */00116private List softwareResourceDescriptions = null;
00117
00118 /**
00119 * This member variable holds a List of HardwareResourceDescription's
00120 * describing each of which describes a hardware component upon which the
00121 * "parent" hardware component depends.
00122 */00123private List hardwareResourceDescriptions = null;
00124
00125 /**
00126 * Constructs a HardwareResourceDescription associated with the passed
00127 * objects:
00128 * <ul>
00129 * <li><em>HardwareResourceDescription</em> --- A java.util.Map, which
00130 * describes the "parent" hardware component.</li>
00131 * <li><em>SoftwareResourceDescriptions</em> --- A java.util.List, which
00132 * is a list of SoftwareResourceDescriptions each of which describes a
00133 * software component upon which the "parent" hardware component depends.
00134 * </li>
00135 * <li>
00136 * <em>HardwareResourceDescriptions</li> --- A java.util.List, which is a list
00137 * of HardwareResourceDescriptions each of which describes a hardware component
00138 * upon which the "parent" hardware component depends.</li>
00139 * </ul>
00140 *
00141 * @param hardwareResourceDescription A java.util.Map, which describes the "parent"
00142 * hardware component.
00143 * @param softwareResourceDescriptions A java.util.List, which is a list of
00144 * SoftwareResourceDescriptions each of which describes a software component upon
00145 * which the "parent" hardware component depends.
00146 * @param hardwareResourceDescriptions A java.util.List, which is a list of
00147 * HardwareResourceDescriptions each of which describes a hardware component upon
00148 * which the "parent" hardware component depends.
00149 */00150publicHardwareResourceDescription(Map hardwareResourceDescription,
00151 List softwareResourceDescriptions, List hardwareResourceDescriptions) {
00152 this.hardwareResourceDescription = hardwareResourceDescription;
00153 this.softwareResourceDescriptions = softwareResourceDescriptions;
00154 this.hardwareResourceDescriptions = hardwareResourceDescriptions;
00155 }
00156
00157 /**
00158 * Tests this HardwareResourceDescription for equality with the passed
00159 * Object.
00160 * <p>
00161 * If the given object is not a HardwareResourceDescription, then this
00162 * method immediately returns false.
00163 * <p>
00164 * If the passed object is a HardwareResourceDescription, then it is deemed
00165 * equal if it has an equivalent HardwareResourceDescription, as determined
00166 * by the Equals method on java.util.Map, and an equivalent
00167 * SoftwareResourceDescriptions, as determined by the Equals method on
00168 * java.util.List, and an equivalent HardwareResourceDescriptions, as
00169 * determined by the Equals method on java.util.List.
00170 *
00171 * @param object
00172 * The Object to test for equality
00173 * @return A boolean indicating equality
00174 */00175publicbooleanequals(Object object) {
00176 HardwareResourceDescription hResourceDescription = null;
00177
00178 if (false == (object instanceof HardwareResourceDescription))
00179 returnfalse;
00180
00181 hResourceDescription = (HardwareResourceDescription) object;
00182
00183 if (false == hardwareResourceDescription
00184 .equals(hResourceDescription.hardwareResourceDescription))
00185 returnfalse;
00186 if (false == softwareResourceDescriptions
00187 .equals(hResourceDescription.softwareResourceDescriptions))
00188 returnfalse;
00189 if (false == hardwareResourceDescriptions
00190 .equals(hResourceDescription.hardwareResourceDescriptions))
00191 returnfalse;
00192
00193 returntrue;
00194 }
00195
00196 /**
00197 * Returns the HardwareResourceDescription of this instance
00198 *
00199 * @return The HardwareResourceDescription of this instance
00200 */00201public Map getDescription() {
00202 returnhardwareResourceDescription;
00203 }
00204
00205 /**
00206 * Sets the HardwareResourceDescription of this instance
00207 *
00208 * @param hrd
00209 * The HardwareResourceDescription of this instance
00210 */00211publicvoidsetDescription(Map hrd) {
00212 hardwareResourceDescription = hrd;
00213 }
00214
00215 /**
00216 * Adds the name/value pair to the java.util.Map of name/value pairs which
00217 * describe the "parent" hardware component.
00218 *
00219 * @param name
00220 * The Name, a java.lang.String, to add to the name/value pairs
00221 * which describe the "parent" hardware component.
00222 * @param value
00223 * The Value, an Object, to add to the name/value pairs which
00224 * describe the "parent" hardware component.
00225 */00226publicvoidaddResourceAttribute(String name, Object value) {
00227 hardwareResourceDescription.put(name, value);
00228 }
00229
00230 /**
00231 * Removes the name/value pair with the passed name from the java.util.Map
00232 * of name/value pairs which describe the "parent" hardware component.
00233 *
00234 * @param name
00235 * The Name, a java.lang.String, to of the name/value pair to
00236 * remove from the name/value pairs which describe the "parent"
00237 * hardware component.
00238 */00239publicvoidremoveResourceAttribute(String name)
00240 throws NoSuchElementException {
00241 hardwareResourceDescription.remove(name);
00242 }
00243
00244 /**
00245 * Adds the passed HardwareResourceDescription to the java.util.List of
00246 * HardwareResourceDescriptions which describe this
00247 * HardwareResourceDescription.
00248 *
00249 * @param hardwareResourceDescription
00250 * The HardwareResourceDescription to add to the java.util.List
00251 * of HardwareResourceDescriptions which describe this
00252 * HardwareResourceDescription.
00253 */00254publicvoidaddResourceDescription(
00255 ResourceDescriptionhardwareResourceDescription) {
00256 hardwareResourceDescriptions.add(hardwareResourceDescription);
00257 }
00258
00259 /**
00260 * Removes the passed HardwareResourceDescription from the java.util.List of
00261 * HardwareResourceDescriptions which describe this
00262 * HardwareResourceDescription.
00263 *
00264 * @param hardwareResourceDescription
00265 * The HardwareResourceDescription to remove from the
00266 * java.util.List of HardwareResourceDescriptions which describe
00267 * this HardwareResourceDescription.
00268 */00269publicvoidremoveResourceDescription(
00270 ResourceDescriptionhardwareResourceDescription) {
00271 hardwareResourceDescriptions.remove(hardwareResourceDescription);
00272 }
00273
00274 /**
00275 * Sets the java.util.List of HardwareResourceDescriptions which describe
00276 * this HardwareResourceDescription to the passed java.util.List.
00277 *
00278 * @param hardwareResourceDescriptions
00279 * The new java.util.List of HardwareResourceDescriptions which
00280 * describe this HardwareResourceDescription.
00281 */00282publicvoidsetHardwareResourceDescriptions(
00283 List hardwareResourceDescriptions) {
00284 this.hardwareResourceDescriptions = hardwareResourceDescriptions;
00285 }
00286
00287 /**
00288 * Gets the java.util.List of HardwareResourceDescriptions which describe
00289 * this HardwareResourceDescription.
00290 *
00291 * @return The java.util.List of HardwareResourceDescriptions which describe
00292 * this HardwareResourceDescription.
00293 */00294public List getHardwareResourceDescriptions() {
00295 returnhardwareResourceDescriptions;
00296 }
00297
00298 /**
00299 * Adds the passed SoftwareResourceDescription to the java.util.List of
00300 * SoftwareResourceDescriptions which describe this
00301 * HardwareResourceDescription.
00302 *
00303 * @param softwareResourceDescription
00304 * The SoftwareResourceDescription to add to the java.util.List
00305 * of SoftwareResourceDescriptions which describe this
00306 * HardwareResourceDescription.
00307 */00308publicvoidaddSoftwareResourceDescription(
00309 SoftwareResourceDescription softwareResourceDescription) {
00310 softwareResourceDescriptions.add(softwareResourceDescription);
00311 }
00312
00313 /**
00314 * Removes the passed SoftwareResourceDescription from the java.util.List of
00315 * SoftwareResourceDescriptions which describe this
00316 * HardwareResourceDescription.
00317 *
00318 * @param softwareResourceDescription
00319 * The SoftwareResourceDescription to remove from the
00320 * java.util.List of SoftwareResourceDescriptions which describe
00321 * this HardwareResourceDescription.
00322 */00323publicvoidremoveSoftwareResourceDescription(
00324 SoftwareResourceDescription softwareResourceDescription) {
00325 softwareResourceDescriptions.remove(softwareResourceDescription);
00326 }
00327
00328 /**
00329 * Sets the java.util.List of SoftwareResourceDescriptions which describe
00330 * this HardwareResourceDescription to the passed java.util.List.
00331 *
00332 * @param softwareResourceDescriptions
00333 * The new java.util.List of SoftwareResourceDescriptions which
00334 * describe this HardwareResourceDescription.
00335 */00336publicvoidsetSoftwareResourceDescriptions(
00337 List softwareResourceDescriptions) {
00338 this.softwareResourceDescriptions = softwareResourceDescriptions;
00339 }
00340
00341 /**
00342 * Gets the java.util.List of SoftwareResourceDescriptions which describe
00343 * this HardwareResourceDescription.
00344 *
00345 * @return The java.util.List of SoftwareResourceDescriptions which describe
00346 * this HardwareResourceDescription.
00347 */00348public List getSoftwareResourceDescriptions() {
00349 returnsoftwareResourceDescriptions;
00350 }
00351 }