| 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.savvis.vpdc.domain; |
| 20 | |
| 21 | import static com.google.common.base.Preconditions.checkNotNull; |
| 22 | |
| 23 | import java.net.URI; |
| 24 | import java.util.Set; |
| 25 | |
| 26 | import org.jclouds.javax.annotation.Nullable; |
| 27 | |
| 28 | import com.google.common.base.CaseFormat; |
| 29 | import com.google.common.collect.ImmutableSet; |
| 30 | import com.google.common.collect.Sets; |
| 31 | |
| 32 | /** |
| 33 | * VDC is a virtual data center ,the API returns a list of VAPPs own by given bill site Id. |
| 34 | * |
| 35 | * @author Adrian Cole |
| 36 | */ |
| 37 | public class VDC extends ResourceImpl { |
| 38 | public static Builder builder() { |
| 39 | return new Builder(); |
| 40 | } |
| 41 | |
| 42 | public static class Builder extends ResourceImpl.Builder { |
| 43 | private String description; |
| 44 | private Status status; |
| 45 | private Set<Resource> resourceEntities = Sets.newLinkedHashSet(); |
| 46 | private Set<Resource> availableNetworks = Sets.newLinkedHashSet(); |
| 47 | |
| 48 | public Builder description(String description) { |
| 49 | this.description = description; |
| 50 | return this; |
| 51 | } |
| 52 | |
| 53 | public Builder status(Status status) { |
| 54 | this.status = status; |
| 55 | return this; |
| 56 | } |
| 57 | |
| 58 | public Builder resourceEntity(Resource resourceEntity) { |
| 59 | this.resourceEntities.add(checkNotNull(resourceEntity, "resourceEntity")); |
| 60 | return this; |
| 61 | } |
| 62 | |
| 63 | public Builder resourceEntities(Set<Resource> resourceEntities) { |
| 64 | this.resourceEntities.addAll(checkNotNull(resourceEntities, "resourceEntities")); |
| 65 | return this; |
| 66 | } |
| 67 | |
| 68 | public Builder availableNetwork(Resource availableNetwork) { |
| 69 | this.availableNetworks.add(checkNotNull(availableNetwork, "availableNetwork")); |
| 70 | return this; |
| 71 | } |
| 72 | |
| 73 | public Builder availableNetworks(Set<Resource> availableNetworks) { |
| 74 | this.availableNetworks.addAll(checkNotNull(availableNetworks, "availableNetworks")); |
| 75 | return this; |
| 76 | } |
| 77 | |
| 78 | @Override |
| 79 | public VDC build() { |
| 80 | return new VDC(id, name, type, href, description, status, resourceEntities, availableNetworks); |
| 81 | } |
| 82 | |
| 83 | public static Builder fromVDC(VDC in) { |
| 84 | return new Builder().id(in.getId()).name(in.getName()).type(in.getType()).href(in.getHref()) |
| 85 | .status(in.getStatus()).description(in.getDescription()).availableNetworks(in.getAvailableNetworks()) |
| 86 | .resourceEntities(in.getResourceEntities()); |
| 87 | } |
| 88 | |
| 89 | @Override |
| 90 | public Builder id(String id) { |
| 91 | return Builder.class.cast(super.id(id)); |
| 92 | } |
| 93 | |
| 94 | @Override |
| 95 | public Builder name(String name) { |
| 96 | return Builder.class.cast(super.name(name)); |
| 97 | } |
| 98 | |
| 99 | @Override |
| 100 | public Builder type(String type) { |
| 101 | return Builder.class.cast(super.type(type)); |
| 102 | } |
| 103 | |
| 104 | @Override |
| 105 | public Builder href(URI href) { |
| 106 | return Builder.class.cast(super.href(href)); |
| 107 | } |
| 108 | |
| 109 | } |
| 110 | |
| 111 | public enum Status { |
| 112 | /** |
| 113 | * Savvis VPDC successfully provisioned and available for use |
| 114 | */ |
| 115 | DEPLOYED, |
| 116 | /** |
| 117 | * Savvis VPDC need to be provisioned and cannot invoke any of the VCloud (post request method |
| 118 | * type) API's |
| 119 | */ |
| 120 | DESIGNING, |
| 121 | /** |
| 122 | * Savvis VPDC need to be provisioned and cannot invoke any of the VCloud (post request method |
| 123 | * type) API's |
| 124 | */ |
| 125 | SAVED, |
| 126 | /** |
| 127 | * Please wait for the provisioning process to complete and cannot invoke any of the VCloud |
| 128 | * (post request method type) API's |
| 129 | */ |
| 130 | INQUEUE, |
| 131 | /** |
| 132 | * Please wait for the provisioning process to complete and cannot invoke any of the VCloud |
| 133 | * (post request method type) API's |
| 134 | */ |
| 135 | PROVISIONING, |
| 136 | /** |
| 137 | * Please kindly contact Savvis administrator for further clarification/assistance with the |
| 138 | * respective request data. and cannot invoke any of the VCloud (post request method type) |
| 139 | * API's |
| 140 | */ |
| 141 | PARTIALLY_DEPLOYED, |
| 142 | /** |
| 143 | * Please kindly contact Savvis administrator for further clarification/assistance with the |
| 144 | * respective request data and cannot invoke any of the VCloud (post request method type) |
| 145 | * API's |
| 146 | */ |
| 147 | FAILED, UNRECOGNIZED; |
| 148 | @Override |
| 149 | public String toString() { |
| 150 | return CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, name()); |
| 151 | } |
| 152 | |
| 153 | public static Status fromValue(String status) { |
| 154 | try { |
| 155 | return valueOf(CaseFormat.UPPER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE, checkNotNull(status, "status"))); |
| 156 | } catch (IllegalArgumentException e) { |
| 157 | return UNRECOGNIZED; |
| 158 | } |
| 159 | } |
| 160 | } |
| 161 | |
| 162 | @Nullable |
| 163 | private final String description; |
| 164 | private final VDC.Status status; |
| 165 | private final Set<Resource> resourceEntities; |
| 166 | private final Set<Resource> availableNetworks; |
| 167 | |
| 168 | public VDC(String id, String name, String type, URI href, @Nullable String description, VDC.Status status, |
| 169 | Set<Resource> resourceEntities, Set<Resource> availableNetworks) { |
| 170 | super(id, name, type, href); |
| 171 | this.description = description; |
| 172 | this.status = checkNotNull(status, "status"); |
| 173 | this.resourceEntities = ImmutableSet.copyOf(checkNotNull(resourceEntities, "resourceEntities")); |
| 174 | this.availableNetworks = ImmutableSet.copyOf(checkNotNull(availableNetworks, "availableNetworks")); |
| 175 | } |
| 176 | |
| 177 | /** |
| 178 | * {@inheritDoc} |
| 179 | */ |
| 180 | public String getDescription() { |
| 181 | return description; |
| 182 | } |
| 183 | |
| 184 | /** |
| 185 | * {@inheritDoc} |
| 186 | */ |
| 187 | public VDC.Status getStatus() { |
| 188 | return status; |
| 189 | } |
| 190 | |
| 191 | /** |
| 192 | * {@inheritDoc} |
| 193 | */ |
| 194 | public Set<Resource> getResourceEntities() { |
| 195 | return resourceEntities; |
| 196 | } |
| 197 | |
| 198 | /** |
| 199 | * {@inheritDoc} |
| 200 | */ |
| 201 | public Set<Resource> getAvailableNetworks() { |
| 202 | return availableNetworks; |
| 203 | } |
| 204 | |
| 205 | @Override |
| 206 | public Builder toBuilder() { |
| 207 | return Builder.fromVDC(this); |
| 208 | } |
| 209 | |
| 210 | @Override |
| 211 | public String toString() { |
| 212 | return "[id=" + id + ", href=" + href + ", name=" + name + ", type=" + type + ", description=" + description |
| 213 | + ", status=" + status + ", resourceEntities=" + resourceEntities + ", availableNetworks=" |
| 214 | + availableNetworks + "]"; |
| 215 | } |
| 216 | |
| 217 | } |