1 /* 2 Copyright (C) 2000 - 2007 Grid Systems, S.A. 3 4 This program is free software; you can redistribute it and/or modify 5 it under the terms of the GNU General Public License, version 2, as 6 published by the Free Software Foundation. 7 8 This program is distributed in the hope that it will be useful, 9 but WITHOUT ANY WARRANTY; without even the implied warranty of 10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 GNU General Public License for more details. 12 13 You should have received a copy of the GNU General Public License 14 along with this program; if not, write to the Free Software 15 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 16 */ 17 18 package com.gridsystems.resource.api; 19 20 import com.gridsystems.innergrid.api.CloneUtils; 21 22 /** 23 * A group is a set of resources (computational resources 24 * than can execute some work). Each group has a set of labour hours that dictate the 25 * periods of time when the group will be active. The schedule of labour hours 26 * is repeated every week. 27 * <p> 28 * Groups can be heterogeneous. 29 * 30 * @author Antonia Tugores 31 * @author Xmas 32 * @version 1.0 33 */ 34 public class Group implements Cloneable { 35 36 /** 37 * Domain for the ACL (Access Control List) corresponding to a group. 38 * <p> 39 * The ACL is created when the group is added, using {@link 40 * com.gridsystems.resource.api.ApiResourceGroup#addGroup 41 * ApiResourceGroup.addGroup}. 42 * After that, the ACL can be managed through ApiAcl (from the plug-in IXOS), 43 * using this domain and the name of the group. 44 */ 45 public static final String ACL_DOMAIN = "ResourceGroups"; 46 47 /** 48 * Name of the only permission related to groups that can be granted to or revoked from 49 * users or roles. The granting of this permission allows the user or role to launch 50 * jobs or tasks to be executed by the resources of the group. 51 */ 52 public static final String GRP_EXECUTION = "execution"; 53 54 /** 55 * Index to access the labour hours of Sunday. 56 */ 57 public static final int SUNDAY = 0; 58 59 /** 60 * Index to access the labour hours of Monday. 61 */ 62 public static final int MONDAY = 1; 63 64 /** 65 * Index to access the labour hours of Tuesday. 66 */ 67 public static final int TUESDAY = 2; 68 69 /** 70 * Index to access the labour hours of Wednesday. 71 */ 72 public static final int WEDNESDAY = 3; 73 74 /** 75 * Index to access the labour hours of Thursday. 76 */ 77 public static final int THURSDAY = 4; 78 79 /** 80 * Index to access the labour hours of Friday. 81 */ 82 public static final int FRIDAY = 5; 83 84 /** 85 * Index to access the labour hours of Saturday. 86 */ 87 public static final int SATURDAY = 6; 88 89 /** 90 * This group accepts any tasks. 91 */ 92 public static final int SCHEDULE_POLICY_ANY_TASK = 0; 93 94 /** 95 * This group only can belong to scheduled tasks. 96 */ 97 public static final int SCHEDULE_POLICY_ONLY_SCHEDULED_TASKS = 1; 98 99 /** 100 * This group only can belong to interactive tasks. 101 */ 102 public static final int SCHEDULE_POLICY_ONLY_INTERACTIVE_TASKS = 2; 103 104 105 /** Name of the group. */ 106 private String name = null; 107 108 /** Description of the group. */ 109 private String description = null; 110 111 /** Allows the execution of jobs or tasks from other groups. */ 112 private boolean acceptOnlyGroupAssignments = false; 113 114 /** Array with the identifiers of the Resources assigned to this group. */ 115 private ResourceId[] resources = null; 116 117 /** This group works as a queue. */ 118 private boolean queue = false; 119 120 /** 121 * Policy used when this Group has market 'queue' field to true. 122 */ 123 private int schedulingPolicy; 124 125 /** 126 * If true, this group requires definition of wallTime in superior instances. 127 */ 128 private boolean wallTimeRequested; 129 130 /** 131 * Labour hours of this group, including a time interval for each day of the week. 132 */ 133 private TimeInterval[] labourHours = { 134 new TimeInterval(), 135 new TimeInterval(), 136 new TimeInterval(), 137 new TimeInterval(), 138 new TimeInterval(), 139 new TimeInterval(), 140 new TimeInterval() 141 }; 142 143 /** 144 * Default constructor. 145 */ 146 public Group() { } 147 148 /** 149 * Sets the name of the group. 150 * <p> 151 * Once the group has been added (using 152 * {@link com.gridsystems.resource.api.ApiResourceGroup#addGroup 153 * ApiResourceGroup.addGroup}), its name 154 * cannot be changed. 155 * 156 * @param name a string with the name of the group. 157 */ 158 public void setName(String name) { 159 this.name = name; 160 } 161 162 /** 163 * Gets the name of the group. 164 * 165 * @return a string with the name of the group. 166 */ 167 public String getName() { 168 return this.name; 169 } 170 171 /** 172 * Sets the description of this group. 173 * <p> 174 * Once the group has been added (using 175 * {@link com.gridsystems.resource.api.ApiResourceGroup#addGroup 176 * ApiResourceGroup.addGroup}), its description must be changed using 177 * {@link com.gridsystems.resource.api.ApiResourceGroup#updateGroup(Group) 178 * ApiResourceGroup.updateGroup}. 179 * 180 * @param description a string with the description of this group 181 */ 182 public void setDescription(String description) { 183 this.description = description; 184 } 185 186 /** 187 * Gets the description of this group. 188 * 189 * @return a string with the description of this group 190 */ 191 public String getDescription() { 192 return this.description; 193 } 194 195 /** 196 * Allows or forbids the execution of work from other groups. If allowed, resources 197 * from this group could work on jobs or tasks not targeted to this group. 198 * <p> 199 * Once the group has been added (using {@link 200 * com.gridsystems.resource.api.ApiResourceGroup#addGroup 201 * ApiResourceGroup.addGroup}), this behavior must be changed using {@link 202 * com.gridsystems.resource.api.ApiResourceGroup#updateGroup 203 * ApiResourceGroup.updateGroup}. 204 * 205 * @param accept a boolean, set to <code>true</code> if the resources in this 206 * group are not allowed to execute job or tasks not directly assigned to 207 * this group; 208 * <code>false</code> otherwise. 209 */ 210 public void setAcceptOnlyGroupAssignments(boolean accept) { 211 this.acceptOnlyGroupAssignments = accept; 212 } 213 214 /** 215 * Checks if this group allows its resources to work on jobs or tasks from other groups. 216 * 217 * @return a boolean,set to <code>true</code> if the resources in this 218 * group are not allowed to execute job or tasks from other groups; 219 * <code>false</code> otherwise 220 */ 221 public boolean isAcceptOnlyGroupAssignments() { 222 return this.acceptOnlyGroupAssignments; 223 } 224 225 /** 226 * Sets the resources identifiers. 227 * 228 * @param resources the resources to be part of this group 229 */ 230 public void setResources(ResourceId[] resources) { 231 this.resources = resources; 232 } 233 234 /** 235 * Gets current group resources. 236 * 237 * @return current group resources 238 */ 239 public ResourceId[] getResources() { 240 return this.resources; 241 } 242 /** 243 * Gets the labour hours of this group which dictate the periods of time when this 244 * group will be active. The schedule of labour hours of a group is repeated every week. 245 * 246 * @return an array of time intervals with the labour hours of this group 247 */ 248 public TimeInterval[] getLabourHours() { 249 return this.labourHours; 250 } 251 252 /** 253 * Sets the labour hours of this group dictated by the periods of time when this 254 * group will be active. The schedule of labour hours of a group is repeated every week. 255 * <p> 256 * Once the group has been added (using {@link 257 * com.gridsystems.resource.api.ApiResourceGroup#addGroup 258 * ApiResourceGroup.addGroup}), its labour hours must be changed using {@link 259 * com.gridsystems.resource.api.ApiResourceGroup#updateGroup 260 * ApiResourceGroup.updateGroup}. 261 * 262 * @param newLabourHours an array of time intervals with the labour hours of this group 263 */ 264 public void setLabourHours(TimeInterval[] newLabourHours) { 265 this.labourHours = newLabourHours; 266 } 267 268 /** 269 * {@inheritDoc} 270 */ 271 public Object clone() throws CloneNotSupportedException { 272 Group clone = (Group) super.clone(); 273 clone.labourHours = (TimeInterval[])CloneUtils.cloneArray(this.labourHours); 274 clone.resources = (ResourceId[])CloneUtils.cloneArray(this.resources); 275 return clone; 276 } 277 278 /** 279 * @return true, if this Group works as a queue. Otherwise, false. 280 */ 281 public boolean isQueue() { 282 return queue; 283 } 284 285 /** 286 * @param queue Sets whether this group works as a queue. 287 */ 288 public void setQueue(boolean queue) { 289 this.queue = queue; 290 } 291 292 /** 293 * @return Returns the schedulingPolicy. 294 * 295 * @see #SCHEDULE_POLICY_ANY_TASK 296 * @see #SCHEDULE_POLICY_ONLY_INTERACTIVE_TASKS 297 * @see #SCHEDULE_POLICY_ONLY_SCHEDULED_TASKS 298 * 299 */ 300 public int getSchedulingPolicy() { 301 return schedulingPolicy; 302 } 303 304 /** 305 * @param schedulingPolicy The schedulingPolicy to set. 306 * 307 * @see #SCHEDULE_POLICY_ANY_TASK 308 * @see #SCHEDULE_POLICY_ONLY_INTERACTIVE_TASKS 309 * @see #SCHEDULE_POLICY_ONLY_SCHEDULED_TASKS 310 */ 311 public void setSchedulingPolicy(int schedulingPolicy) { 312 this.schedulingPolicy = schedulingPolicy; 313 } 314 315 /** 316 * Sets the wallTimeRequested value. 317 * @return Returns the wallTimeRequested. 318 */ 319 public boolean isWallTimeRequested() { 320 return wallTimeRequested; 321 } 322 323 /** 324 * Sets the wallTimeRequested value. 325 * @param wallTimeRequested If true, this group requires definition 326 * of wallTime in superior instances. 327 * 328 */ 329 public void setWallTimeRequested(boolean wallTimeRequested) { 330 this.wallTimeRequested = wallTimeRequested; 331 } 332 }