| 1 | /** |
| 2 | * |
| 3 | * Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com> |
| 4 | * |
| 5 | * ==================================================================== |
| 6 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | * you may not use this file except in compliance with the License. |
| 8 | * 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, software |
| 13 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | * See the License for the specific language governing permissions and |
| 16 | * limitations under the License. |
| 17 | * ==================================================================== |
| 18 | */ |
| 19 | package org.jclouds.gogrid.compute.options; |
| 20 | |
| 21 | import org.jclouds.compute.ComputeService; |
| 22 | import org.jclouds.compute.options.TemplateOptions; |
| 23 | import org.jclouds.io.Payload; |
| 24 | |
| 25 | /** |
| 26 | * Contains options supported by the {@link ComputeService#createNodesInGroup(String, int, TemplateOptions)} |
| 27 | * and {@link ComputeService#runNodesWithTag(String, int, TemplateOptions)} operations on |
| 28 | * the <em>gogrid</em> provider. |
| 29 | * |
| 30 | * <h2>Usage</h2> |
| 31 | * The recommended way to instantiate a {@link GoGridTemplateOptions} object is to statically |
| 32 | * import {@code GoGridTemplateOptions.*} and invoke a static creation method followed by an |
| 33 | * instance mutator (if needed): |
| 34 | * <p> |
| 35 | * <pre> |
| 36 | * import static org.jclouds.compute.options.GoGridTemplateOptions.Builder.*; |
| 37 | * ComputeService client = // get connection |
| 38 | * templateBuilder.options(inboundPorts(22, 80, 8080, 443)); |
| 39 | * Set<? extends NodeMetadata> set = client.runNodesWithTag(tag, 2, templateBuilder.build()); |
| 40 | * </pre> |
| 41 | * |
| 42 | * TODO add GoGrid specific options |
| 43 | * |
| 44 | * @author Adrian Cole |
| 45 | * @author Andrew Kennedy |
| 46 | */ |
| 47 | public class GoGridTemplateOptions extends TemplateOptions implements Cloneable { |
| 48 | @Override |
| 49 | public GoGridTemplateOptions clone() { |
| 50 | GoGridTemplateOptions options = new GoGridTemplateOptions(); |
| 51 | copyTo(options); |
| 52 | return options; |
| 53 | } |
| 54 | |
| 55 | @Override |
| 56 | public void copyTo(TemplateOptions to) { |
| 57 | super.copyTo(to); |
| 58 | if (to instanceof GoGridTemplateOptions) { |
| 59 | @SuppressWarnings("unused") |
| 60 | GoGridTemplateOptions eTo = GoGridTemplateOptions.class.cast(to); |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | public static final GoGridTemplateOptions NONE = new GoGridTemplateOptions(); |
| 65 | |
| 66 | public static class Builder { |
| 67 | // methods that only facilitate returning the correct object type |
| 68 | |
| 69 | /** |
| 70 | * @see TemplateOptions#inboundPorts(int...) |
| 71 | */ |
| 72 | public static GoGridTemplateOptions inboundPorts(int... ports) { |
| 73 | GoGridTemplateOptions options = new GoGridTemplateOptions(); |
| 74 | return GoGridTemplateOptions.class.cast(options.inboundPorts(ports)); |
| 75 | } |
| 76 | |
| 77 | /** |
| 78 | * @see TemplateOptions#blockOnPort(int, int) |
| 79 | */ |
| 80 | public static GoGridTemplateOptions blockOnPort(int port, int seconds) { |
| 81 | GoGridTemplateOptions options = new GoGridTemplateOptions(); |
| 82 | return GoGridTemplateOptions.class.cast(options.blockOnPort(port, seconds)); |
| 83 | } |
| 84 | |
| 85 | /** |
| 86 | * @see TemplateOptions#runScript(Payload) |
| 87 | */ |
| 88 | public static GoGridTemplateOptions runScript(Payload script) { |
| 89 | GoGridTemplateOptions options = new GoGridTemplateOptions(); |
| 90 | return GoGridTemplateOptions.class.cast(options.runScript(script)); |
| 91 | } |
| 92 | |
| 93 | /** |
| 94 | * @see TemplateOptions#installPrivateKey(Payload) |
| 95 | */ |
| 96 | @Deprecated |
| 97 | public static GoGridTemplateOptions installPrivateKey(Payload rsaKey) { |
| 98 | GoGridTemplateOptions options = new GoGridTemplateOptions(); |
| 99 | return GoGridTemplateOptions.class.cast(options.installPrivateKey(rsaKey)); |
| 100 | } |
| 101 | |
| 102 | /** |
| 103 | * @see TemplateOptions#authorizePublicKey(Payload) |
| 104 | */ |
| 105 | @Deprecated |
| 106 | public static GoGridTemplateOptions authorizePublicKey(Payload rsaKey) { |
| 107 | GoGridTemplateOptions options = new GoGridTemplateOptions(); |
| 108 | return GoGridTemplateOptions.class.cast(options.authorizePublicKey(rsaKey)); |
| 109 | } |
| 110 | |
| 111 | /** |
| 112 | * @see TemplateOptions#withMetadata() |
| 113 | */ |
| 114 | public static GoGridTemplateOptions withMetadata() { |
| 115 | GoGridTemplateOptions options = new GoGridTemplateOptions(); |
| 116 | return GoGridTemplateOptions.class.cast(options.withMetadata()); |
| 117 | } |
| 118 | } |
| 119 | |
| 120 | // methods that only facilitate returning the correct object type |
| 121 | |
| 122 | /** |
| 123 | * @see TemplateOptions#blockOnPort(int, int) |
| 124 | */ |
| 125 | @Override |
| 126 | public GoGridTemplateOptions blockOnPort(int port, int seconds) { |
| 127 | return GoGridTemplateOptions.class.cast(super.blockOnPort(port, seconds)); |
| 128 | } |
| 129 | |
| 130 | /** |
| 131 | * @see TemplateOptions#inboundPorts(int...) |
| 132 | */ |
| 133 | @Override |
| 134 | public GoGridTemplateOptions inboundPorts(int... ports) { |
| 135 | return GoGridTemplateOptions.class.cast(super.inboundPorts(ports)); |
| 136 | } |
| 137 | |
| 138 | /** |
| 139 | * @see TemplateOptions#authorizePublicKey(String) |
| 140 | */ |
| 141 | @Override |
| 142 | public GoGridTemplateOptions authorizePublicKey(String publicKey) { |
| 143 | return GoGridTemplateOptions.class.cast(super.authorizePublicKey(publicKey)); |
| 144 | } |
| 145 | |
| 146 | /** |
| 147 | * @see TemplateOptions#authorizePublicKey(Payload) |
| 148 | */ |
| 149 | @Override |
| 150 | @Deprecated |
| 151 | public GoGridTemplateOptions authorizePublicKey(Payload publicKey) { |
| 152 | return GoGridTemplateOptions.class.cast(super.authorizePublicKey(publicKey)); |
| 153 | } |
| 154 | |
| 155 | /** |
| 156 | * @see TemplateOptions#installPrivateKey(String) |
| 157 | */ |
| 158 | @Override |
| 159 | public GoGridTemplateOptions installPrivateKey(String privateKey) { |
| 160 | return GoGridTemplateOptions.class.cast(super.installPrivateKey(privateKey)); |
| 161 | } |
| 162 | |
| 163 | /** |
| 164 | * @see TemplateOptions#installPrivateKey(Payload) |
| 165 | */ |
| 166 | @Override |
| 167 | @Deprecated |
| 168 | public GoGridTemplateOptions installPrivateKey(Payload privateKey) { |
| 169 | return GoGridTemplateOptions.class.cast(super.installPrivateKey(privateKey)); |
| 170 | } |
| 171 | |
| 172 | /** |
| 173 | * @see TemplateOptions#runScript(Payload) |
| 174 | */ |
| 175 | @Override |
| 176 | public GoGridTemplateOptions runScript(Payload script) { |
| 177 | return GoGridTemplateOptions.class.cast(super.runScript(script)); |
| 178 | } |
| 179 | |
| 180 | /** |
| 181 | * @see TemplateOptions#runScript(byte[]) |
| 182 | */ |
| 183 | @Override |
| 184 | @Deprecated |
| 185 | public GoGridTemplateOptions runScript(byte[] script) { |
| 186 | return GoGridTemplateOptions.class.cast(super.runScript(script)); |
| 187 | } |
| 188 | |
| 189 | /** |
| 190 | * @see TemplateOptions#withMetadata() |
| 191 | */ |
| 192 | @Override |
| 193 | public GoGridTemplateOptions withMetadata() { |
| 194 | return GoGridTemplateOptions.class.cast(super.withMetadata()); |
| 195 | } |
| 196 | } |