| 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.deltacloud.domain; |
| 20 | |
| 21 | import static com.google.common.base.Preconditions.checkNotNull; |
| 22 | |
| 23 | import java.net.URI; |
| 24 | |
| 25 | import org.jclouds.javax.annotation.Nullable; |
| 26 | |
| 27 | /** |
| 28 | * Within a cloud provider a realm represents a boundary containing resources. The exact definition |
| 29 | * of a realm is left to the cloud provider. In some cases, a realm may represent different |
| 30 | * datacenters, different continents, or different pools of resources within a single datacenter. A |
| 31 | * cloud provider may insist that resources must all exist within a single realm in order to |
| 32 | * cooperate. For instance, storage volumes may only be allowed to be mounted to instances within |
| 33 | * the same realm. |
| 34 | * |
| 35 | * @author Adrian Cole |
| 36 | */ |
| 37 | public class Realm { |
| 38 | public enum State { |
| 39 | |
| 40 | /** |
| 41 | * the realm is available |
| 42 | */ |
| 43 | AVAILABLE, |
| 44 | |
| 45 | /** |
| 46 | * the realm is unavailable |
| 47 | */ |
| 48 | UNAVAILABLE, |
| 49 | |
| 50 | /** |
| 51 | * state returned as something besides the above. |
| 52 | */ |
| 53 | UNRECOGNIZED; |
| 54 | |
| 55 | public static State fromValue(String state) { |
| 56 | try { |
| 57 | return valueOf(checkNotNull(state, "state")); |
| 58 | } catch (IllegalArgumentException e) { |
| 59 | return UNRECOGNIZED; |
| 60 | } |
| 61 | } |
| 62 | } |
| 63 | private final URI href; |
| 64 | private final String id; |
| 65 | @Nullable |
| 66 | private final String limit; |
| 67 | private final String name; |
| 68 | private final State state; |
| 69 | |
| 70 | public Realm(URI href, String id, String name, @Nullable String limit, State state) { |
| 71 | this.href = checkNotNull(href, "href"); |
| 72 | this.id = checkNotNull(id, "id"); |
| 73 | this.name = checkNotNull(name, "name"); |
| 74 | this.limit = limit; |
| 75 | this.state = checkNotNull(state, "state"); |
| 76 | } |
| 77 | |
| 78 | /** |
| 79 | * |
| 80 | * @return URL to manipulate a specific realm |
| 81 | */ |
| 82 | public URI getHref() { |
| 83 | return href; |
| 84 | } |
| 85 | |
| 86 | /** |
| 87 | * |
| 88 | * @return A unique identifier for the realm |
| 89 | */ |
| 90 | public String getId() { |
| 91 | return id; |
| 92 | } |
| 93 | |
| 94 | /** |
| 95 | * |
| 96 | * @return A short label |
| 97 | */ |
| 98 | public String getName() { |
| 99 | return name; |
| 100 | } |
| 101 | |
| 102 | /** |
| 103 | * for example limitation of how many machine you can launch in given region / how much computing |
| 104 | * power is available for you. |
| 105 | * |
| 106 | * @return Limits applicable for the current requester |
| 107 | */ |
| 108 | @Nullable |
| 109 | public String getLimit() { |
| 110 | return limit; |
| 111 | } |
| 112 | |
| 113 | /** |
| 114 | * |
| 115 | * @return indicator of the realm's current state |
| 116 | */ |
| 117 | public State getState() { |
| 118 | return state; |
| 119 | } |
| 120 | |
| 121 | @Override |
| 122 | public int hashCode() { |
| 123 | final int prime = 31; |
| 124 | int result = 1; |
| 125 | result = prime * result + ((href == null) ? 0 : href.hashCode()); |
| 126 | result = prime * result + ((id == null) ? 0 : id.hashCode()); |
| 127 | result = prime * result + ((limit == null) ? 0 : limit.hashCode()); |
| 128 | result = prime * result + ((name == null) ? 0 : name.hashCode()); |
| 129 | result = prime * result + ((state == null) ? 0 : state.hashCode()); |
| 130 | return result; |
| 131 | } |
| 132 | |
| 133 | @Override |
| 134 | public boolean equals(Object obj) { |
| 135 | if (this == obj) |
| 136 | return true; |
| 137 | if (obj == null) |
| 138 | return false; |
| 139 | if (getClass() != obj.getClass()) |
| 140 | return false; |
| 141 | Realm other = (Realm) obj; |
| 142 | if (href == null) { |
| 143 | if (other.href != null) |
| 144 | return false; |
| 145 | } else if (!href.equals(other.href)) |
| 146 | return false; |
| 147 | if (id == null) { |
| 148 | if (other.id != null) |
| 149 | return false; |
| 150 | } else if (!id.equals(other.id)) |
| 151 | return false; |
| 152 | if (limit == null) { |
| 153 | if (other.limit != null) |
| 154 | return false; |
| 155 | } else if (!limit.equals(other.limit)) |
| 156 | return false; |
| 157 | if (name == null) { |
| 158 | if (other.name != null) |
| 159 | return false; |
| 160 | } else if (!name.equals(other.name)) |
| 161 | return false; |
| 162 | if (state != other.state) |
| 163 | return false; |
| 164 | return true; |
| 165 | } |
| 166 | |
| 167 | @Override |
| 168 | public String toString() { |
| 169 | return "[href=" + href + ", id=" + id + ", limit=" + limit + ", name=" + name + ", state=" + state + "]"; |
| 170 | } |
| 171 | |
| 172 | } |