| 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.compute.options; |
| 20 | |
| 21 | import java.util.Map; |
| 22 | |
| 23 | import org.jclouds.compute.ComputeService; |
| 24 | import org.jclouds.compute.options.TemplateOptions; |
| 25 | import org.jclouds.io.Payload; |
| 26 | |
| 27 | /** |
| 28 | * Contains options supported by the |
| 29 | * {@link ComputeService#createNodesInGroup(String, int, TemplateOptions)} and |
| 30 | * {@link ComputeService#runNodesWithTag(String, int, TemplateOptions)} |
| 31 | * operations on the <em>gogrid</em> provider. |
| 32 | * |
| 33 | * <h2>Usage</h2> The recommended way to instantiate a |
| 34 | * {@link GoGridTemplateOptions} object is to statically import |
| 35 | * {@code GoGridTemplateOptions.*} and invoke a static creation method followed |
| 36 | * by an instance mutator (if needed): |
| 37 | * <p> |
| 38 | * |
| 39 | * <pre> |
| 40 | * import static org.jclouds.compute.options.GoGridTemplateOptions.Builder.*; |
| 41 | * ComputeService client = // get connection |
| 42 | * templateBuilder.options(inboundPorts(22, 80, 8080, 443)); |
| 43 | * Set<? extends NodeMetadata> set = client.runNodesWithTag(tag, 2, templateBuilder.build()); |
| 44 | * </pre> |
| 45 | * |
| 46 | * TODO add GoGrid specific options |
| 47 | * |
| 48 | * @author Adrian Cole |
| 49 | * @author Andrew Kennedy |
| 50 | */ |
| 51 | public class GoGridTemplateOptions extends TemplateOptions implements Cloneable { |
| 52 | @Override |
| 53 | public GoGridTemplateOptions clone() { |
| 54 | GoGridTemplateOptions options = new GoGridTemplateOptions(); |
| 55 | copyTo(options); |
| 56 | return options; |
| 57 | } |
| 58 | |
| 59 | @Override |
| 60 | public void copyTo(TemplateOptions to) { |
| 61 | super.copyTo(to); |
| 62 | if (to instanceof GoGridTemplateOptions) { |
| 63 | @SuppressWarnings("unused") |
| 64 | GoGridTemplateOptions eTo = GoGridTemplateOptions.class.cast(to); |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | public static final GoGridTemplateOptions NONE = new GoGridTemplateOptions(); |
| 69 | |
| 70 | public static class Builder { |
| 71 | // methods that only facilitate returning the correct object type |
| 72 | |
| 73 | /** |
| 74 | * @see TemplateOptions#inboundPorts(int...) |
| 75 | */ |
| 76 | public static GoGridTemplateOptions inboundPorts(int... ports) { |
| 77 | GoGridTemplateOptions options = new GoGridTemplateOptions(); |
| 78 | return GoGridTemplateOptions.class.cast(options.inboundPorts(ports)); |
| 79 | } |
| 80 | |
| 81 | /** |
| 82 | * @see TemplateOptions#blockOnPort(int, int) |
| 83 | */ |
| 84 | public static GoGridTemplateOptions blockOnPort(int port, int seconds) { |
| 85 | GoGridTemplateOptions options = new GoGridTemplateOptions(); |
| 86 | return GoGridTemplateOptions.class.cast(options.blockOnPort(port, seconds)); |
| 87 | } |
| 88 | |
| 89 | /** |
| 90 | * @see TemplateOptions#runScript(Payload) |
| 91 | */ |
| 92 | public static GoGridTemplateOptions runScript(Payload script) { |
| 93 | GoGridTemplateOptions options = new GoGridTemplateOptions(); |
| 94 | return GoGridTemplateOptions.class.cast(options.runScript(script)); |
| 95 | } |
| 96 | |
| 97 | /** |
| 98 | * @see TemplateOptions#installPrivateKey(Payload) |
| 99 | */ |
| 100 | @Deprecated |
| 101 | public static GoGridTemplateOptions installPrivateKey(Payload rsaKey) { |
| 102 | GoGridTemplateOptions options = new GoGridTemplateOptions(); |
| 103 | return GoGridTemplateOptions.class.cast(options.installPrivateKey(rsaKey)); |
| 104 | } |
| 105 | |
| 106 | /** |
| 107 | * @see TemplateOptions#authorizePublicKey(Payload) |
| 108 | */ |
| 109 | @Deprecated |
| 110 | public static GoGridTemplateOptions authorizePublicKey(Payload rsaKey) { |
| 111 | GoGridTemplateOptions options = new GoGridTemplateOptions(); |
| 112 | return GoGridTemplateOptions.class.cast(options.authorizePublicKey(rsaKey)); |
| 113 | } |
| 114 | |
| 115 | /** |
| 116 | * @see TemplateOptions#userMetadata(Map) |
| 117 | */ |
| 118 | public static GoGridTemplateOptions userMetadata(Map<String, String> userMetadata) { |
| 119 | GoGridTemplateOptions options = new GoGridTemplateOptions(); |
| 120 | return GoGridTemplateOptions.class.cast(options.userMetadata(userMetadata)); |
| 121 | } |
| 122 | |
| 123 | /** |
| 124 | * @see TemplateOptions#userMetadata(String, String) |
| 125 | */ |
| 126 | public static GoGridTemplateOptions userMetadata(String key, String value) { |
| 127 | GoGridTemplateOptions options = new GoGridTemplateOptions(); |
| 128 | return GoGridTemplateOptions.class.cast(options.userMetadata(key, value)); |
| 129 | } |
| 130 | } |
| 131 | |
| 132 | // methods that only facilitate returning the correct object type |
| 133 | |
| 134 | /** |
| 135 | * @see TemplateOptions#blockOnPort(int, int) |
| 136 | */ |
| 137 | @Override |
| 138 | public GoGridTemplateOptions blockOnPort(int port, int seconds) { |
| 139 | return GoGridTemplateOptions.class.cast(super.blockOnPort(port, seconds)); |
| 140 | } |
| 141 | |
| 142 | /** |
| 143 | * @see TemplateOptions#inboundPorts(int...) |
| 144 | */ |
| 145 | @Override |
| 146 | public GoGridTemplateOptions inboundPorts(int... ports) { |
| 147 | return GoGridTemplateOptions.class.cast(super.inboundPorts(ports)); |
| 148 | } |
| 149 | |
| 150 | /** |
| 151 | * @see TemplateOptions#authorizePublicKey(String) |
| 152 | */ |
| 153 | @Override |
| 154 | public GoGridTemplateOptions authorizePublicKey(String publicKey) { |
| 155 | return GoGridTemplateOptions.class.cast(super.authorizePublicKey(publicKey)); |
| 156 | } |
| 157 | |
| 158 | /** |
| 159 | * @see TemplateOptions#authorizePublicKey(Payload) |
| 160 | */ |
| 161 | @Override |
| 162 | @Deprecated |
| 163 | public GoGridTemplateOptions authorizePublicKey(Payload publicKey) { |
| 164 | return GoGridTemplateOptions.class.cast(super.authorizePublicKey(publicKey)); |
| 165 | } |
| 166 | |
| 167 | /** |
| 168 | * @see TemplateOptions#installPrivateKey(String) |
| 169 | */ |
| 170 | @Override |
| 171 | public GoGridTemplateOptions installPrivateKey(String privateKey) { |
| 172 | return GoGridTemplateOptions.class.cast(super.installPrivateKey(privateKey)); |
| 173 | } |
| 174 | |
| 175 | /** |
| 176 | * @see TemplateOptions#installPrivateKey(Payload) |
| 177 | */ |
| 178 | @Override |
| 179 | @Deprecated |
| 180 | public GoGridTemplateOptions installPrivateKey(Payload privateKey) { |
| 181 | return GoGridTemplateOptions.class.cast(super.installPrivateKey(privateKey)); |
| 182 | } |
| 183 | |
| 184 | /** |
| 185 | * @see TemplateOptions#runScript(Payload) |
| 186 | */ |
| 187 | @Override |
| 188 | public GoGridTemplateOptions runScript(Payload script) { |
| 189 | return GoGridTemplateOptions.class.cast(super.runScript(script)); |
| 190 | } |
| 191 | |
| 192 | /** |
| 193 | * @see TemplateOptions#runScript(byte[]) |
| 194 | */ |
| 195 | @Override |
| 196 | @Deprecated |
| 197 | public GoGridTemplateOptions runScript(byte[] script) { |
| 198 | return GoGridTemplateOptions.class.cast(super.runScript(script)); |
| 199 | } |
| 200 | |
| 201 | /** |
| 202 | * {@inheritDoc} |
| 203 | */ |
| 204 | @Override |
| 205 | public GoGridTemplateOptions userMetadata(Map<String, String> userMetadata) { |
| 206 | return GoGridTemplateOptions.class.cast(super.userMetadata(userMetadata)); |
| 207 | } |
| 208 | |
| 209 | /** |
| 210 | * {@inheritDoc} |
| 211 | */ |
| 212 | @Override |
| 213 | public GoGridTemplateOptions userMetadata(String key, String value) { |
| 214 | return GoGridTemplateOptions.class.cast(super.userMetadata(key, value)); |
| 215 | } |
| 216 | } |