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