| 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.aws.ec2.compute; |
| 20 | |
| 21 | import static com.google.common.base.Preconditions.checkNotNull; |
| 22 | import static com.google.common.base.Preconditions.checkState; |
| 23 | |
| 24 | import java.util.Arrays; |
| 25 | import java.util.Set; |
| 26 | |
| 27 | import javax.annotation.Nullable; |
| 28 | |
| 29 | import org.jclouds.aws.ec2.options.RequestSpotInstancesOptions; |
| 30 | import org.jclouds.compute.options.TemplateOptions; |
| 31 | import org.jclouds.domain.Credentials; |
| 32 | import org.jclouds.ec2.compute.options.EC2TemplateOptions; |
| 33 | import org.jclouds.ec2.domain.BlockDeviceMapping; |
| 34 | import org.jclouds.io.Payload; |
| 35 | import org.jclouds.scriptbuilder.domain.Statement; |
| 36 | import org.jclouds.util.Preconditions2; |
| 37 | |
| 38 | /** |
| 39 | * Contains options supported in the {@code ComputeService#runNode} operation on the "ec2" provider. |
| 40 | * <h2> |
| 41 | * Usage</h2> The recommended way to instantiate a AWSEC2TemplateOptions object is to statically |
| 42 | * import AWSEC2TemplateOptions.* and invoke a static creation method followed by an instance |
| 43 | * mutator (if needed): |
| 44 | * <p/> |
| 45 | * <code> |
| 46 | * import static org.jclouds.aws.ec2.compute.options.AWSEC2TemplateOptions.Builder.*; |
| 47 | * <p/> |
| 48 | * ComputeService client = // get connection |
| 49 | * templateBuilder.options(inboundPorts(22, 80, 8080, 443)); |
| 50 | * Set<? extends NodeMetadata> set = client.runNodesWithTag(tag, 2, templateBuilder.build()); |
| 51 | * <code> |
| 52 | * |
| 53 | * @author Adrian Cole |
| 54 | */ |
| 55 | public class AWSEC2TemplateOptions extends EC2TemplateOptions implements Cloneable { |
| 56 | @Override |
| 57 | public AWSEC2TemplateOptions clone() { |
| 58 | AWSEC2TemplateOptions options = new AWSEC2TemplateOptions(); |
| 59 | copyTo(options); |
| 60 | return options; |
| 61 | } |
| 62 | |
| 63 | @Override |
| 64 | public void copyTo(TemplateOptions to) { |
| 65 | super.copyTo(to); |
| 66 | if (to instanceof AWSEC2TemplateOptions) { |
| 67 | AWSEC2TemplateOptions eTo = AWSEC2TemplateOptions.class.cast(to); |
| 68 | if (getSubnetId() != null) |
| 69 | eTo.subnetId(getSubnetId()); |
| 70 | if (isMonitoringEnabled()) |
| 71 | eTo.enableMonitoring(); |
| 72 | if (!shouldAutomaticallyCreatePlacementGroup()) |
| 73 | eTo.noPlacementGroup(); |
| 74 | if (getPlacementGroup() != null) |
| 75 | eTo.placementGroup(getPlacementGroup()); |
| 76 | if (getSpotPrice() != null) |
| 77 | eTo.spotPrice(getSpotPrice()); |
| 78 | if (getSpotOptions() != null) |
| 79 | eTo.spotOptions(getSpotOptions()); |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | private boolean monitoringEnabled; |
| 84 | private String placementGroup = null; |
| 85 | private boolean noPlacementGroup; |
| 86 | private String subnetId; |
| 87 | private Float spotPrice; |
| 88 | private RequestSpotInstancesOptions spotOptions = RequestSpotInstancesOptions.NONE; |
| 89 | |
| 90 | public static final AWSEC2TemplateOptions NONE = new AWSEC2TemplateOptions(); |
| 91 | |
| 92 | /** |
| 93 | * Enable Cloudwatch monitoring |
| 94 | * |
| 95 | * @see CloudWatchClient |
| 96 | */ |
| 97 | public AWSEC2TemplateOptions enableMonitoring() { |
| 98 | this.monitoringEnabled = true; |
| 99 | return this; |
| 100 | } |
| 101 | |
| 102 | /** |
| 103 | * Specifies the keypair used to run instances with |
| 104 | */ |
| 105 | public AWSEC2TemplateOptions placementGroup(String placementGroup) { |
| 106 | checkNotNull(placementGroup, "use noPlacementGroup option to request boot without a keypair"); |
| 107 | checkState(!noPlacementGroup, "you cannot specify both options placementGroup and noPlacementGroup"); |
| 108 | Preconditions2.checkNotEmpty(placementGroup, "placementGroup must be non-empty"); |
| 109 | this.placementGroup = placementGroup; |
| 110 | return this; |
| 111 | } |
| 112 | |
| 113 | /** |
| 114 | * Do not use a keypair on instances |
| 115 | */ |
| 116 | public AWSEC2TemplateOptions noPlacementGroup() { |
| 117 | checkState(placementGroup == null, "you cannot specify both options placementGroup and noPlacementGroup"); |
| 118 | this.noPlacementGroup = true; |
| 119 | return this; |
| 120 | } |
| 121 | |
| 122 | /** |
| 123 | * Specifies the subnetId used to run instances in |
| 124 | */ |
| 125 | public AWSEC2TemplateOptions subnetId(String subnetId) { |
| 126 | checkNotNull(subnetId, "subnetId cannot be null"); |
| 127 | Preconditions2.checkNotEmpty(subnetId, "subnetId must be non-empty"); |
| 128 | this.subnetId = subnetId; |
| 129 | return this; |
| 130 | } |
| 131 | |
| 132 | /** |
| 133 | * Specifies the maximum spot price to use |
| 134 | */ |
| 135 | public AWSEC2TemplateOptions spotPrice(Float spotPrice) { |
| 136 | this.spotPrice = spotPrice; |
| 137 | return this; |
| 138 | } |
| 139 | |
| 140 | /** |
| 141 | * Options for starting spot instances |
| 142 | */ |
| 143 | public AWSEC2TemplateOptions spotOptions(RequestSpotInstancesOptions spotOptions) { |
| 144 | this.spotOptions = spotOptions != null ? spotOptions : RequestSpotInstancesOptions.NONE; |
| 145 | return this; |
| 146 | } |
| 147 | |
| 148 | public static class Builder { |
| 149 | /** |
| 150 | * @see EC2TemplateOptions#blockDeviceMappings |
| 151 | */ |
| 152 | public static AWSEC2TemplateOptions blockDeviceMappings(Set<? extends BlockDeviceMapping> blockDeviceMappings) { |
| 153 | AWSEC2TemplateOptions options = new AWSEC2TemplateOptions(); |
| 154 | return options.blockDeviceMappings(blockDeviceMappings); |
| 155 | } |
| 156 | |
| 157 | /** |
| 158 | * @see EC2TemplateOptions#mapEBSSnapshotToDeviceName |
| 159 | */ |
| 160 | public static AWSEC2TemplateOptions mapEBSSnapshotToDeviceName(String deviceName, String snapshotId, |
| 161 | @Nullable Integer sizeInGib, boolean deleteOnTermination) { |
| 162 | AWSEC2TemplateOptions options = new AWSEC2TemplateOptions(); |
| 163 | return options.mapEBSSnapshotToDeviceName(deviceName, snapshotId, sizeInGib, deleteOnTermination); |
| 164 | } |
| 165 | |
| 166 | /** |
| 167 | * @see EC2TemplateOptions#mapNewVolumeToDeviceName |
| 168 | */ |
| 169 | public static AWSEC2TemplateOptions mapNewVolumeToDeviceName(String deviceName, int sizeInGib, |
| 170 | boolean deleteOnTermination) { |
| 171 | AWSEC2TemplateOptions options = new AWSEC2TemplateOptions(); |
| 172 | return options.mapNewVolumeToDeviceName(deviceName, sizeInGib, deleteOnTermination); |
| 173 | } |
| 174 | |
| 175 | /** |
| 176 | * @see EC2TemplateOptions#mapEphemeralDeviceToDeviceName |
| 177 | */ |
| 178 | public static AWSEC2TemplateOptions mapEphemeralDeviceToDeviceName(String deviceName, String virtualName) { |
| 179 | AWSEC2TemplateOptions options = new AWSEC2TemplateOptions(); |
| 180 | return options.mapEphemeralDeviceToDeviceName(deviceName, virtualName); |
| 181 | } |
| 182 | |
| 183 | /** |
| 184 | * @see EC2TemplateOptions#unmapDeviceNamed |
| 185 | */ |
| 186 | public static AWSEC2TemplateOptions unmapDeviceNamed(String deviceName) { |
| 187 | AWSEC2TemplateOptions options = new AWSEC2TemplateOptions(); |
| 188 | return options.unmapDeviceNamed(deviceName); |
| 189 | } |
| 190 | |
| 191 | /** |
| 192 | * @see AWSEC2TemplateOptions#securityGroups(Iterable<String>) |
| 193 | */ |
| 194 | public static AWSEC2TemplateOptions securityGroups(String... groupIds) { |
| 195 | AWSEC2TemplateOptions options = new AWSEC2TemplateOptions(); |
| 196 | return options.securityGroups(groupIds); |
| 197 | } |
| 198 | |
| 199 | /** |
| 200 | * @see AWSEC2TemplateOptions#securityGroups(Iterable<String>) |
| 201 | */ |
| 202 | public static AWSEC2TemplateOptions securityGroups(Iterable<String> groupIds) { |
| 203 | AWSEC2TemplateOptions options = new AWSEC2TemplateOptions(); |
| 204 | return options.securityGroups(groupIds); |
| 205 | } |
| 206 | |
| 207 | /** |
| 208 | * @see AWSEC2TemplateOptions#keyPair |
| 209 | */ |
| 210 | public static AWSEC2TemplateOptions keyPair(String keyPair) { |
| 211 | AWSEC2TemplateOptions options = new AWSEC2TemplateOptions(); |
| 212 | return options.keyPair(keyPair); |
| 213 | } |
| 214 | |
| 215 | /** |
| 216 | * @see AWSEC2TemplateOptions#userData |
| 217 | */ |
| 218 | public static AWSEC2TemplateOptions userData(byte[] unencodedData) { |
| 219 | AWSEC2TemplateOptions options = new AWSEC2TemplateOptions(); |
| 220 | return options.userData(unencodedData); |
| 221 | } |
| 222 | |
| 223 | /** |
| 224 | * @see AWSEC2TemplateOptions#noKeyPair |
| 225 | */ |
| 226 | public static AWSEC2TemplateOptions noKeyPair() { |
| 227 | AWSEC2TemplateOptions options = new AWSEC2TemplateOptions(); |
| 228 | return options.noKeyPair(); |
| 229 | } |
| 230 | |
| 231 | /** |
| 232 | * @see AWSEC2TemplateOptions#placementGroup |
| 233 | */ |
| 234 | public static AWSEC2TemplateOptions placementGroup(String placementGroup) { |
| 235 | AWSEC2TemplateOptions options = new AWSEC2TemplateOptions(); |
| 236 | return options.placementGroup(placementGroup); |
| 237 | } |
| 238 | |
| 239 | /** |
| 240 | * @see AWSEC2TemplateOptions#noPlacementGroup |
| 241 | */ |
| 242 | public static AWSEC2TemplateOptions noPlacementGroup() { |
| 243 | AWSEC2TemplateOptions options = new AWSEC2TemplateOptions(); |
| 244 | return options.noPlacementGroup(); |
| 245 | } |
| 246 | |
| 247 | /** |
| 248 | * @see AWSEC2TemplateOptions#enableMonitoring |
| 249 | */ |
| 250 | public static AWSEC2TemplateOptions enableMonitoring() { |
| 251 | AWSEC2TemplateOptions options = new AWSEC2TemplateOptions(); |
| 252 | return options.enableMonitoring(); |
| 253 | } |
| 254 | |
| 255 | // methods that only facilitate returning the correct object type |
| 256 | /** |
| 257 | * @see TemplateOptions#inboundPorts |
| 258 | */ |
| 259 | public static AWSEC2TemplateOptions inboundPorts(int... ports) { |
| 260 | AWSEC2TemplateOptions options = new AWSEC2TemplateOptions(); |
| 261 | return options.inboundPorts(ports); |
| 262 | } |
| 263 | |
| 264 | /** |
| 265 | * @see TemplateOptions#port |
| 266 | */ |
| 267 | public static AWSEC2TemplateOptions blockOnPort(int port, int seconds) { |
| 268 | AWSEC2TemplateOptions options = new AWSEC2TemplateOptions(); |
| 269 | return options.blockOnPort(port, seconds); |
| 270 | } |
| 271 | |
| 272 | /** |
| 273 | * @see TemplateOptions#runScript |
| 274 | */ |
| 275 | public static AWSEC2TemplateOptions runScript(byte[] script) { |
| 276 | AWSEC2TemplateOptions options = new AWSEC2TemplateOptions(); |
| 277 | return options.runScript(script); |
| 278 | } |
| 279 | |
| 280 | /** |
| 281 | * @see TemplateOptions#installPrivateKey |
| 282 | */ |
| 283 | public static AWSEC2TemplateOptions installPrivateKey(String rsaKey) { |
| 284 | AWSEC2TemplateOptions options = new AWSEC2TemplateOptions(); |
| 285 | return options.installPrivateKey(rsaKey); |
| 286 | } |
| 287 | |
| 288 | /** |
| 289 | * @see TemplateOptions#authorizePublicKey |
| 290 | */ |
| 291 | public static AWSEC2TemplateOptions authorizePublicKey(String rsaKey) { |
| 292 | AWSEC2TemplateOptions options = new AWSEC2TemplateOptions(); |
| 293 | return options.authorizePublicKey(rsaKey); |
| 294 | } |
| 295 | |
| 296 | /** |
| 297 | * @see TemplateOptions#withDetails |
| 298 | */ |
| 299 | public static AWSEC2TemplateOptions withDetails() { |
| 300 | AWSEC2TemplateOptions options = new AWSEC2TemplateOptions(); |
| 301 | return options.withMetadata(); |
| 302 | } |
| 303 | |
| 304 | /** |
| 305 | * @see TemplateOptions#spotPrice |
| 306 | */ |
| 307 | public static AWSEC2TemplateOptions subnetId(String subnetId) { |
| 308 | AWSEC2TemplateOptions options = new AWSEC2TemplateOptions(); |
| 309 | return options.subnetId(subnetId); |
| 310 | } |
| 311 | |
| 312 | /** |
| 313 | * @see TemplateOptions#spotPrice |
| 314 | */ |
| 315 | public static AWSEC2TemplateOptions spotPrice(Float spotPrice) { |
| 316 | AWSEC2TemplateOptions options = new AWSEC2TemplateOptions(); |
| 317 | return options.spotPrice(spotPrice); |
| 318 | } |
| 319 | |
| 320 | /** |
| 321 | * @see TemplateOptions#spotOptions |
| 322 | */ |
| 323 | public static AWSEC2TemplateOptions spotOptions(RequestSpotInstancesOptions spotOptions) { |
| 324 | AWSEC2TemplateOptions options = new AWSEC2TemplateOptions(); |
| 325 | return options.spotOptions(spotOptions); |
| 326 | } |
| 327 | } |
| 328 | |
| 329 | // methods that only facilitate returning the correct object type |
| 330 | |
| 331 | /** |
| 332 | * {@inheritDoc} |
| 333 | */ |
| 334 | @Override |
| 335 | public AWSEC2TemplateOptions blockDeviceMappings(Iterable<? extends BlockDeviceMapping> blockDeviceMappings) { |
| 336 | return AWSEC2TemplateOptions.class.cast(super.blockDeviceMappings(blockDeviceMappings)); |
| 337 | } |
| 338 | |
| 339 | /** |
| 340 | * {@inheritDoc} |
| 341 | */ |
| 342 | @Override |
| 343 | public AWSEC2TemplateOptions keyPair(String keyPair) { |
| 344 | return AWSEC2TemplateOptions.class.cast(super.keyPair(keyPair)); |
| 345 | } |
| 346 | |
| 347 | /** |
| 348 | * {@inheritDoc} |
| 349 | */ |
| 350 | |
| 351 | @Override |
| 352 | public AWSEC2TemplateOptions mapEBSSnapshotToDeviceName(String deviceName, String snapshotId, Integer sizeInGib, |
| 353 | boolean deleteOnTermination) { |
| 354 | return AWSEC2TemplateOptions.class.cast(super.mapEBSSnapshotToDeviceName(deviceName, snapshotId, sizeInGib, |
| 355 | deleteOnTermination)); |
| 356 | } |
| 357 | |
| 358 | /** |
| 359 | * {@inheritDoc} |
| 360 | */ |
| 361 | @Override |
| 362 | public AWSEC2TemplateOptions mapEphemeralDeviceToDeviceName(String deviceName, String virtualName) { |
| 363 | return AWSEC2TemplateOptions.class.cast(super.mapEphemeralDeviceToDeviceName(deviceName, virtualName)); |
| 364 | } |
| 365 | |
| 366 | /** |
| 367 | * {@inheritDoc} |
| 368 | */ |
| 369 | @Override |
| 370 | public AWSEC2TemplateOptions mapNewVolumeToDeviceName(String deviceName, int sizeInGib, boolean deleteOnTermination) { |
| 371 | return AWSEC2TemplateOptions.class.cast(super |
| 372 | .mapNewVolumeToDeviceName(deviceName, sizeInGib, deleteOnTermination)); |
| 373 | } |
| 374 | |
| 375 | /** |
| 376 | * {@inheritDoc} |
| 377 | */ |
| 378 | @Override |
| 379 | public AWSEC2TemplateOptions noKeyPair() { |
| 380 | return AWSEC2TemplateOptions.class.cast(super.noKeyPair()); |
| 381 | } |
| 382 | |
| 383 | /** |
| 384 | * {@inheritDoc} |
| 385 | */ |
| 386 | @Override |
| 387 | public AWSEC2TemplateOptions securityGroups(Iterable<String> groupIds) { |
| 388 | return AWSEC2TemplateOptions.class.cast(super.securityGroups(groupIds)); |
| 389 | } |
| 390 | |
| 391 | /** |
| 392 | * {@inheritDoc} |
| 393 | */ |
| 394 | @Override |
| 395 | public AWSEC2TemplateOptions securityGroups(String... groupIds) { |
| 396 | return AWSEC2TemplateOptions.class.cast(super.securityGroups(groupIds)); |
| 397 | } |
| 398 | |
| 399 | /** |
| 400 | * {@inheritDoc} |
| 401 | */ |
| 402 | @Override |
| 403 | public AWSEC2TemplateOptions unmapDeviceNamed(String deviceName) { |
| 404 | return AWSEC2TemplateOptions.class.cast(super.unmapDeviceNamed(deviceName)); |
| 405 | } |
| 406 | |
| 407 | /** |
| 408 | * {@inheritDoc} |
| 409 | */ |
| 410 | @Override |
| 411 | public AWSEC2TemplateOptions userData(byte[] unencodedData) { |
| 412 | return AWSEC2TemplateOptions.class.cast(super.userData(unencodedData)); |
| 413 | } |
| 414 | |
| 415 | /** |
| 416 | * {@inheritDoc} |
| 417 | */ |
| 418 | @Override |
| 419 | public AWSEC2TemplateOptions blockOnPort(int port, int seconds) { |
| 420 | return AWSEC2TemplateOptions.class.cast(super.blockOnPort(port, seconds)); |
| 421 | } |
| 422 | |
| 423 | /** |
| 424 | * {@inheritDoc} |
| 425 | */ |
| 426 | @Override |
| 427 | public AWSEC2TemplateOptions inboundPorts(int... ports) { |
| 428 | return AWSEC2TemplateOptions.class.cast(super.inboundPorts(ports)); |
| 429 | } |
| 430 | |
| 431 | /** |
| 432 | * {@inheritDoc} |
| 433 | */ |
| 434 | @Override |
| 435 | public AWSEC2TemplateOptions authorizePublicKey(String publicKey) { |
| 436 | return AWSEC2TemplateOptions.class.cast(super.authorizePublicKey(publicKey)); |
| 437 | } |
| 438 | |
| 439 | /** |
| 440 | * {@inheritDoc} |
| 441 | */ |
| 442 | @Override |
| 443 | @Deprecated |
| 444 | public AWSEC2TemplateOptions authorizePublicKey(Payload publicKey) { |
| 445 | return AWSEC2TemplateOptions.class.cast(super.authorizePublicKey(publicKey)); |
| 446 | } |
| 447 | |
| 448 | /** |
| 449 | * {@inheritDoc} |
| 450 | */ |
| 451 | @Override |
| 452 | public AWSEC2TemplateOptions installPrivateKey(String privateKey) { |
| 453 | return AWSEC2TemplateOptions.class.cast(super.installPrivateKey(privateKey)); |
| 454 | } |
| 455 | |
| 456 | /** |
| 457 | * {@inheritDoc} |
| 458 | */ |
| 459 | @Override |
| 460 | @Deprecated |
| 461 | public AWSEC2TemplateOptions installPrivateKey(Payload privateKey) { |
| 462 | return AWSEC2TemplateOptions.class.cast(super.installPrivateKey(privateKey)); |
| 463 | } |
| 464 | |
| 465 | /** |
| 466 | * {@inheritDoc} |
| 467 | */ |
| 468 | @Override |
| 469 | public AWSEC2TemplateOptions runScript(Payload script) { |
| 470 | return AWSEC2TemplateOptions.class.cast(super.runScript(script)); |
| 471 | } |
| 472 | |
| 473 | /** |
| 474 | * {@inheritDoc} |
| 475 | */ |
| 476 | @Override |
| 477 | @Deprecated |
| 478 | public AWSEC2TemplateOptions runScript(byte[] script) { |
| 479 | return AWSEC2TemplateOptions.class.cast(super.runScript(script)); |
| 480 | } |
| 481 | |
| 482 | /** |
| 483 | * {@inheritDoc} |
| 484 | */ |
| 485 | @Override |
| 486 | public AWSEC2TemplateOptions withMetadata() { |
| 487 | return AWSEC2TemplateOptions.class.cast(super.withMetadata()); |
| 488 | } |
| 489 | |
| 490 | /** |
| 491 | * {@inheritDoc} |
| 492 | */ |
| 493 | @Override |
| 494 | public AWSEC2TemplateOptions blockUntilRunning(boolean blockUntilRunning) { |
| 495 | return AWSEC2TemplateOptions.class.cast(super.blockUntilRunning(blockUntilRunning)); |
| 496 | } |
| 497 | |
| 498 | /** |
| 499 | * {@inheritDoc} |
| 500 | */ |
| 501 | @Override |
| 502 | public AWSEC2TemplateOptions dontAuthorizePublicKey() { |
| 503 | return AWSEC2TemplateOptions.class.cast(super.dontAuthorizePublicKey()); |
| 504 | } |
| 505 | |
| 506 | /** |
| 507 | * {@inheritDoc} |
| 508 | */ |
| 509 | @Override |
| 510 | public AWSEC2TemplateOptions nameTask(String name) { |
| 511 | return AWSEC2TemplateOptions.class.cast(super.nameTask(name)); |
| 512 | } |
| 513 | |
| 514 | /** |
| 515 | * {@inheritDoc} |
| 516 | */ |
| 517 | @Override |
| 518 | public AWSEC2TemplateOptions runAsRoot(boolean runAsRoot) { |
| 519 | return AWSEC2TemplateOptions.class.cast(super.runAsRoot(runAsRoot)); |
| 520 | } |
| 521 | |
| 522 | /** |
| 523 | * {@inheritDoc} |
| 524 | */ |
| 525 | @Override |
| 526 | public AWSEC2TemplateOptions runScript(Statement script) { |
| 527 | return AWSEC2TemplateOptions.class.cast(super.runScript(script)); |
| 528 | } |
| 529 | |
| 530 | /** |
| 531 | * {@inheritDoc} |
| 532 | */ |
| 533 | @Override |
| 534 | public AWSEC2TemplateOptions overrideCredentialsWith(Credentials overridingCredentials) { |
| 535 | return AWSEC2TemplateOptions.class.cast(super.overrideCredentialsWith(overridingCredentials)); |
| 536 | } |
| 537 | |
| 538 | /** |
| 539 | * @return placementGroup to use when running the instance or null, to generate a placementGroup. |
| 540 | */ |
| 541 | public String getPlacementGroup() { |
| 542 | return placementGroup; |
| 543 | } |
| 544 | |
| 545 | /** |
| 546 | * @return true (default) if we are supposed to use a placementGroup |
| 547 | */ |
| 548 | public boolean shouldAutomaticallyCreatePlacementGroup() { |
| 549 | return !noPlacementGroup; |
| 550 | } |
| 551 | |
| 552 | /** |
| 553 | * @return true (default) if we are supposed to enable cloudwatch |
| 554 | */ |
| 555 | public boolean isMonitoringEnabled() { |
| 556 | return monitoringEnabled; |
| 557 | } |
| 558 | |
| 559 | /** |
| 560 | * @return subnetId to use when running the instance or null. |
| 561 | */ |
| 562 | public String getSubnetId() { |
| 563 | return subnetId; |
| 564 | } |
| 565 | |
| 566 | /** |
| 567 | * @return maximum spot price or null. |
| 568 | */ |
| 569 | public Float getSpotPrice() { |
| 570 | return spotPrice; |
| 571 | } |
| 572 | |
| 573 | /** |
| 574 | * @return options for controlling spot instance requests. |
| 575 | */ |
| 576 | public RequestSpotInstancesOptions getSpotOptions() { |
| 577 | return spotOptions; |
| 578 | } |
| 579 | |
| 580 | @Override |
| 581 | public int hashCode() { |
| 582 | final int prime = 31; |
| 583 | int result = super.hashCode(); |
| 584 | result = prime * result + (monitoringEnabled ? 1231 : 1237); |
| 585 | result = prime * result + (noPlacementGroup ? 1231 : 1237); |
| 586 | result = prime * result + ((placementGroup == null) ? 0 : placementGroup.hashCode()); |
| 587 | result = prime * result + ((spotOptions == null) ? 0 : spotOptions.hashCode()); |
| 588 | result = prime * result + ((spotPrice == null) ? 0 : spotPrice.hashCode()); |
| 589 | result = prime * result + ((subnetId == null) ? 0 : subnetId.hashCode()); |
| 590 | return result; |
| 591 | } |
| 592 | |
| 593 | @Override |
| 594 | public boolean equals(Object obj) { |
| 595 | if (this == obj) |
| 596 | return true; |
| 597 | if (!super.equals(obj)) |
| 598 | return false; |
| 599 | if (getClass() != obj.getClass()) |
| 600 | return false; |
| 601 | AWSEC2TemplateOptions other = (AWSEC2TemplateOptions) obj; |
| 602 | if (monitoringEnabled != other.monitoringEnabled) |
| 603 | return false; |
| 604 | if (noPlacementGroup != other.noPlacementGroup) |
| 605 | return false; |
| 606 | if (placementGroup == null) { |
| 607 | if (other.placementGroup != null) |
| 608 | return false; |
| 609 | } else if (!placementGroup.equals(other.placementGroup)) |
| 610 | return false; |
| 611 | if (spotOptions == null) { |
| 612 | if (other.spotOptions != null) |
| 613 | return false; |
| 614 | } else if (!spotOptions.equals(other.spotOptions)) |
| 615 | return false; |
| 616 | if (spotPrice == null) { |
| 617 | if (other.spotPrice != null) |
| 618 | return false; |
| 619 | } else if (!spotPrice.equals(other.spotPrice)) |
| 620 | return false; |
| 621 | if (subnetId == null) { |
| 622 | if (other.subnetId != null) |
| 623 | return false; |
| 624 | } else if (!subnetId.equals(other.subnetId)) |
| 625 | return false; |
| 626 | return true; |
| 627 | } |
| 628 | |
| 629 | @Override |
| 630 | public String toString() { |
| 631 | |
| 632 | return "[groupIds=" + getGroupIds() + ", keyPair=" + getKeyPair() + ", noKeyPair=" |
| 633 | + !shouldAutomaticallyCreateKeyPair() + ", monitoringEnabled=" + monitoringEnabled + ", placementGroup=" |
| 634 | + placementGroup + ", noPlacementGroup=" + noPlacementGroup + ", subnetId=" + subnetId + ", userData=" |
| 635 | + Arrays.toString(getUserData()) + ", blockDeviceMappings=" + getBlockDeviceMappings() + ", spotPrice=" |
| 636 | + spotPrice + ", spotOptions=" + spotOptions + "]"; |
| 637 | } |
| 638 | |
| 639 | } |