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.ec2.domain; |
20 | |
21 | import static com.google.common.base.Preconditions.checkNotNull; |
22 | |
23 | import java.util.Set; |
24 | |
25 | import org.jclouds.javax.annotation.Nullable; |
26 | |
27 | /** |
28 | * |
29 | * @see <a href= |
30 | * "http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/ApiReference-ItemType-SecurityGroupItemType.html" |
31 | * /> |
32 | * @author Adrian Cole |
33 | */ |
34 | public class SecurityGroup implements Comparable<SecurityGroup> { |
35 | |
36 | private final String region; |
37 | private final String id; |
38 | private final String name; |
39 | private final String ownerId; |
40 | private final String description; |
41 | private final Set<IpPermissionImpl> ipPermissions; |
42 | |
43 | public SecurityGroup(String region, String id, String name, String ownerId, String description, |
44 | Set<IpPermissionImpl> ipPermissions) { |
45 | this.region = checkNotNull(region, "region"); |
46 | this.id = id; |
47 | this.name = name; |
48 | this.ownerId = ownerId; |
49 | this.description = description; |
50 | this.ipPermissions = ipPermissions; |
51 | } |
52 | |
53 | /** |
54 | * Security groups are not copied across Regions. Instances within the Region |
55 | * cannot communicate with instances outside the Region using group-based |
56 | * firewall rules. Traffic from instances in another Region is seen as WAN |
57 | * bandwidth. |
58 | */ |
59 | public String getRegion() { |
60 | return region; |
61 | } |
62 | |
63 | /** |
64 | * {@inheritDoc} |
65 | */ |
66 | public int compareTo(SecurityGroup o) { |
67 | return (this == o) ? 0 : getName().compareTo(o.getName()); |
68 | } |
69 | |
70 | /** |
71 | * id of the security group. Not in all EC2 impls |
72 | */ |
73 | @Nullable |
74 | public String getId() { |
75 | return id; |
76 | } |
77 | |
78 | /** |
79 | * Name of the security group. |
80 | */ |
81 | public String getName() { |
82 | return name; |
83 | } |
84 | |
85 | /** |
86 | * AWS Access Key ID of the owner of the security group. |
87 | */ |
88 | public String getOwnerId() { |
89 | return ownerId; |
90 | } |
91 | |
92 | /** |
93 | * Description of the security group. |
94 | */ |
95 | public String getDescription() { |
96 | return description; |
97 | } |
98 | |
99 | /** |
100 | * Set of IP permissions associated with the security group. |
101 | */ |
102 | public Set<IpPermissionImpl> getIpPermissions() { |
103 | return ipPermissions; |
104 | } |
105 | |
106 | @Override |
107 | public int hashCode() { |
108 | final int prime = 31; |
109 | int result = 1; |
110 | result = prime * result + ((description == null) ? 0 : description.hashCode()); |
111 | result = prime * result + ((id == null) ? 0 : id.hashCode()); |
112 | result = prime * result + ((ipPermissions == null) ? 0 : ipPermissions.hashCode()); |
113 | result = prime * result + ((name == null) ? 0 : name.hashCode()); |
114 | result = prime * result + ((ownerId == null) ? 0 : ownerId.hashCode()); |
115 | result = prime * result + ((region == null) ? 0 : region.hashCode()); |
116 | return result; |
117 | } |
118 | |
119 | @Override |
120 | public boolean equals(Object obj) { |
121 | if (this == obj) |
122 | return true; |
123 | if (obj == null) |
124 | return false; |
125 | if (getClass() != obj.getClass()) |
126 | return false; |
127 | SecurityGroup other = (SecurityGroup) obj; |
128 | if (description == null) { |
129 | if (other.description != null) |
130 | return false; |
131 | } else if (!description.equals(other.description)) |
132 | return false; |
133 | if (id == null) { |
134 | if (other.id != null) |
135 | return false; |
136 | } else if (!id.equals(other.id)) |
137 | return false; |
138 | if (ipPermissions == null) { |
139 | if (other.ipPermissions != null) |
140 | return false; |
141 | } else if (!ipPermissions.equals(other.ipPermissions)) |
142 | return false; |
143 | if (name == null) { |
144 | if (other.name != null) |
145 | return false; |
146 | } else if (!name.equals(other.name)) |
147 | return false; |
148 | if (ownerId == null) { |
149 | if (other.ownerId != null) |
150 | return false; |
151 | } else if (!ownerId.equals(other.ownerId)) |
152 | return false; |
153 | if (region == null) { |
154 | if (other.region != null) |
155 | return false; |
156 | } else if (!region.equals(other.region)) |
157 | return false; |
158 | return true; |
159 | } |
160 | |
161 | @Override |
162 | public String toString() { |
163 | return "[region=" + region + ", id=" + id + ", name=" + name + ", ownerId=" + ownerId + ", description=" |
164 | + description + ", ipPermissions=" + ipPermissions + "]"; |
165 | } |
166 | } |