| 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.domain; |
| 20 | |
| 21 | import static com.google.common.base.Preconditions.checkNotNull; |
| 22 | |
| 23 | /** |
| 24 | * A placement group is a logical grouping of instances. |
| 25 | * |
| 26 | * <p/> |
| 27 | * You first create a cluster placement group, then launch multiple cluster compute instances into |
| 28 | * the group. Currently cluster compute instances are available only in the US-East (Northern |
| 29 | * Virginia) Region. You must give each placement group a name that is unique within your account. |
| 30 | * For more information about cluster placement groups, see Cluster Compute Instance Concepts. |
| 31 | * <p/> |
| 32 | * Note |
| 33 | * <p/> |
| 34 | * You can't merge cluster placement groups. Instead you must terminate the instances in one of the |
| 35 | * groups, and then relaunch the instances into the other group. |
| 36 | * |
| 37 | * @see <a href="http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/ApiReference-query-DescribePlacementGroups.html" |
| 38 | * /> |
| 39 | * @author Adrian Cole |
| 40 | */ |
| 41 | public class PlacementGroup implements Comparable<PlacementGroup> { |
| 42 | public static enum State { |
| 43 | PENDING, AVAILABLE, DELETING, DELETED, UNRECOGNIZED; |
| 44 | public String value() { |
| 45 | return name().toLowerCase(); |
| 46 | } |
| 47 | |
| 48 | @Override |
| 49 | public String toString() { |
| 50 | return value(); |
| 51 | } |
| 52 | |
| 53 | public static State fromValue(String state) { |
| 54 | try { |
| 55 | return valueOf(checkNotNull(state, "state").toUpperCase()); |
| 56 | } catch (IllegalArgumentException e) { |
| 57 | return UNRECOGNIZED; |
| 58 | } |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | private final String region; |
| 63 | private final String name; |
| 64 | private final String strategy; |
| 65 | private final State state; |
| 66 | |
| 67 | public PlacementGroup(String region, String name, String strategy, State state) { |
| 68 | this.region = checkNotNull(region, "region"); |
| 69 | this.name = checkNotNull(name, "name"); |
| 70 | this.strategy = checkNotNull(strategy, "strategy"); |
| 71 | this.state = checkNotNull(state, "state"); |
| 72 | } |
| 73 | |
| 74 | @Override |
| 75 | public int compareTo(PlacementGroup o) { |
| 76 | return name.compareTo(o.name); |
| 77 | } |
| 78 | |
| 79 | /** |
| 80 | * @return placement groups are in a region, however the namescope is global. |
| 81 | */ |
| 82 | public String getRegion() { |
| 83 | return region; |
| 84 | } |
| 85 | |
| 86 | /** |
| 87 | * @return Name of the placement group. |
| 88 | */ |
| 89 | public String getName() { |
| 90 | return name; |
| 91 | } |
| 92 | |
| 93 | /** |
| 94 | * @return The placement strategy. |
| 95 | */ |
| 96 | public String getStrategy() { |
| 97 | return strategy; |
| 98 | } |
| 99 | |
| 100 | /** |
| 101 | * @return Status of the placement group. |
| 102 | */ |
| 103 | public State getState() { |
| 104 | return state; |
| 105 | } |
| 106 | |
| 107 | @Override |
| 108 | public int hashCode() { |
| 109 | final int prime = 31; |
| 110 | int result = 1; |
| 111 | result = prime * result + ((name == null) ? 0 : name.hashCode()); |
| 112 | result = prime * result + ((region == null) ? 0 : region.hashCode()); |
| 113 | result = prime * result + ((state == null) ? 0 : state.hashCode()); |
| 114 | result = prime * result + ((strategy == null) ? 0 : strategy.hashCode()); |
| 115 | return result; |
| 116 | } |
| 117 | |
| 118 | @Override |
| 119 | public boolean equals(Object obj) { |
| 120 | if (this == obj) |
| 121 | return true; |
| 122 | if (obj == null) |
| 123 | return false; |
| 124 | if (getClass() != obj.getClass()) |
| 125 | return false; |
| 126 | PlacementGroup other = (PlacementGroup) obj; |
| 127 | if (name == null) { |
| 128 | if (other.name != null) |
| 129 | return false; |
| 130 | } else if (!name.equals(other.name)) |
| 131 | return false; |
| 132 | if (region == null) { |
| 133 | if (other.region != null) |
| 134 | return false; |
| 135 | } else if (!region.equals(other.region)) |
| 136 | return false; |
| 137 | if (state == null) { |
| 138 | if (other.state != null) |
| 139 | return false; |
| 140 | } else if (!state.equals(other.state)) |
| 141 | return false; |
| 142 | if (strategy == null) { |
| 143 | if (other.strategy != null) |
| 144 | return false; |
| 145 | } else if (!strategy.equals(other.strategy)) |
| 146 | return false; |
| 147 | return true; |
| 148 | } |
| 149 | |
| 150 | @Override |
| 151 | public String toString() { |
| 152 | return "[name=" + name + ", region=" + region + ", state=" + state + ", strategy=" + strategy + "]"; |
| 153 | } |
| 154 | |
| 155 | } |