| 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.gogrid.options; |
| 20 | |
| 21 | import static com.google.common.base.Preconditions.checkArgument; |
| 22 | import static com.google.common.base.Preconditions.checkState; |
| 23 | import static org.jclouds.gogrid.reference.GoGridQueryParams.DESCRIPTION_KEY; |
| 24 | import static org.jclouds.gogrid.reference.GoGridQueryParams.IS_SANDBOX_KEY; |
| 25 | |
| 26 | import org.jclouds.http.options.BaseHttpRequestOptions; |
| 27 | |
| 28 | /** |
| 29 | * @author Oleksiy Yarmula |
| 30 | */ |
| 31 | public class AddServerOptions extends BaseHttpRequestOptions { |
| 32 | |
| 33 | public AddServerOptions withDescription(String description) { |
| 34 | checkArgument(description.length() <= 500, "Description cannot be longer than 500 characters"); |
| 35 | checkState(!queryParameters.containsKey(DESCRIPTION_KEY), |
| 36 | "Can't have duplicate server description"); |
| 37 | queryParameters.put(DESCRIPTION_KEY, description); |
| 38 | return this; |
| 39 | } |
| 40 | |
| 41 | /** |
| 42 | * Make server a sandbox instance. By default, it's not. |
| 43 | * |
| 44 | * @return itself for convenience |
| 45 | */ |
| 46 | public AddServerOptions asSandboxType() { |
| 47 | checkState(!queryParameters.containsKey(IS_SANDBOX_KEY), |
| 48 | "Can only have one sandbox option per server"); |
| 49 | queryParameters.put(IS_SANDBOX_KEY, "true"); |
| 50 | return this; |
| 51 | } |
| 52 | |
| 53 | public static class Builder { |
| 54 | /** |
| 55 | * @see AddServerOptions#withDescription(String) |
| 56 | */ |
| 57 | public static AddServerOptions withDescription(String description) { |
| 58 | AddServerOptions options = new AddServerOptions(); |
| 59 | return options.withDescription(description); |
| 60 | } |
| 61 | |
| 62 | /** |
| 63 | * @see AddServerOptions#asSandboxType() |
| 64 | */ |
| 65 | public static AddServerOptions asSandboxType() { |
| 66 | AddServerOptions options = new AddServerOptions(); |
| 67 | return options.asSandboxType(); |
| 68 | } |
| 69 | } |
| 70 | } |