EMMA Coverage Report (generated Wed Oct 26 13:47:17 EDT 2011)
[all classes][org.jclouds.compute.options]

COVERAGE SUMMARY FOR SOURCE FILE [RunScriptOptions.java]

nameclass, %method, %block, %line, %
RunScriptOptions.java100% (3/3)33%  (14/43)34%  (111/330)43%  (31.6/74)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class RunScriptOptions$ImmutableRunScriptOptions100% (1/1)6%   (1/16)8%   (6/74)17%  (3/18)
blockOnComplete (boolean): RunScriptOptions 0%   (0/1)0%   (0/5)0%   (0/1)
blockOnPort (int, int): RunScriptOptions 0%   (0/1)0%   (0/5)0%   (0/1)
getOverridingCredentials (): Credentials 0%   (0/1)0%   (0/4)0%   (0/1)
getPort (): int 0%   (0/1)0%   (0/4)0%   (0/1)
getSeconds (): int 0%   (0/1)0%   (0/4)0%   (0/1)
getTaskName (): String 0%   (0/1)0%   (0/4)0%   (0/1)
nameTask (String): RunScriptOptions 0%   (0/1)0%   (0/5)0%   (0/1)
overrideCredentialsWith (Credentials): RunScriptOptions 0%   (0/1)0%   (0/5)0%   (0/1)
overrideLoginCredentialWith (String): RunScriptOptions 0%   (0/1)0%   (0/5)0%   (0/1)
overrideLoginUserWith (String): RunScriptOptions 0%   (0/1)0%   (0/5)0%   (0/1)
runAsRoot (boolean): RunScriptOptions 0%   (0/1)0%   (0/5)0%   (0/1)
shouldBlockOnComplete (): boolean 0%   (0/1)0%   (0/4)0%   (0/1)
shouldRunAsRoot (): boolean 0%   (0/1)0%   (0/4)0%   (0/1)
toString (): String 0%   (0/1)0%   (0/4)0%   (0/1)
wrapInInitScript (boolean): RunScriptOptions 0%   (0/1)0%   (0/5)0%   (0/1)
RunScriptOptions$ImmutableRunScriptOptions (RunScriptOptions): void 100% (1/1)100% (6/6)100% (3/3)
     
class RunScriptOptions$Builder100% (1/1)11%  (1/9)12%  (8/68)12%  (2/17)
RunScriptOptions$Builder (): void 0%   (0/1)0%   (0/3)0%   (0/1)
blockOnComplete (boolean): RunScriptOptions 0%   (0/1)0%   (0/8)0%   (0/2)
blockOnPort (int, int): RunScriptOptions 0%   (0/1)0%   (0/9)0%   (0/2)
nameTask (String): RunScriptOptions 0%   (0/1)0%   (0/8)0%   (0/2)
overrideCredentialsWith (Credentials): RunScriptOptions 0%   (0/1)0%   (0/8)0%   (0/2)
overrideLoginCredentialWith (String): RunScriptOptions 0%   (0/1)0%   (0/8)0%   (0/2)
overrideLoginUserWith (String): RunScriptOptions 0%   (0/1)0%   (0/8)0%   (0/2)
runAsRoot (boolean): RunScriptOptions 0%   (0/1)0%   (0/8)0%   (0/2)
wrapInInitScript (boolean): RunScriptOptions 100% (1/1)100% (8/8)100% (2/2)
     
class RunScriptOptions100% (1/1)67%  (12/18)52%  (97/188)67%  (26.8/40)
blockOnComplete (boolean): RunScriptOptions 0%   (0/1)0%   (0/5)0%   (0/2)
nameTask (String): RunScriptOptions 0%   (0/1)0%   (0/5)0%   (0/2)
overrideCredentialsWith (Credentials): RunScriptOptions 0%   (0/1)0%   (0/9)0%   (0/3)
overrideLoginUserWith (String): RunScriptOptions 0%   (0/1)0%   (0/23)0%   (0/4)
shouldWrapInInitScript (): boolean 0%   (0/1)0%   (0/3)0%   (0/1)
toString (): String 0%   (0/1)0%   (0/41)0%   (0/1)
overrideLoginCredentialWith (String): RunScriptOptions 100% (1/1)83%  (19/23)96%  (3.8/4)
blockOnPort (int, int): RunScriptOptions 100% (1/1)96%  (24/25)99%  (4.9/5)
<static initializer> 100% (1/1)100% (8/8)100% (1/1)
RunScriptOptions (): void 100% (1/1)100% (18/18)100% (7/7)
getOverridingCredentials (): Credentials 100% (1/1)100% (3/3)100% (1/1)
getPort (): int 100% (1/1)100% (3/3)100% (1/1)
getSeconds (): int 100% (1/1)100% (3/3)100% (1/1)
getTaskName (): String 100% (1/1)100% (3/3)100% (1/1)
runAsRoot (boolean): RunScriptOptions 100% (1/1)100% (5/5)100% (2/2)
shouldBlockOnComplete (): boolean 100% (1/1)100% (3/3)100% (1/1)
shouldRunAsRoot (): boolean 100% (1/1)100% (3/3)100% (1/1)
wrapInInitScript (boolean): RunScriptOptions 100% (1/1)100% (5/5)100% (2/2)

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 */
19package org.jclouds.compute.options;
20 
21import static com.google.common.base.Preconditions.checkArgument;
22import static com.google.common.base.Preconditions.checkNotNull;
23 
24import org.jclouds.domain.Credentials;
25 
26/**
27 * Enables additional options for running a script.
28 * 
29 * @author Oleksiy Yarmula
30 */
31public class RunScriptOptions {
32 
33   /**
34    * Default options. The default settings are:
35    * <ul>
36    * <li>override the credentials with ones supplied in call to
37    * {@link org.jclouds.compute.ComputeService#runScriptOnNodesWithTag}</li>
38    * <li>run the script as root (versus running with current privileges)</li>
39    * </ul>
40    */
41   public static final RunScriptOptions NONE = new ImmutableRunScriptOptions(new RunScriptOptions());
42 
43   public static class ImmutableRunScriptOptions extends RunScriptOptions {
44      private final RunScriptOptions delegate;
45 
46      public ImmutableRunScriptOptions(RunScriptOptions delegate) {
47         this.delegate = delegate;
48      }
49 
50      @Override
51      public String toString() {
52         return delegate.toString();
53      }
54 
55      @Override
56      public Credentials getOverridingCredentials() {
57         return delegate.getOverridingCredentials();
58 
59      }
60 
61      @Override
62      public boolean shouldRunAsRoot() {
63         return delegate.shouldRunAsRoot();
64 
65      }
66 
67      @Override
68      public RunScriptOptions runAsRoot(boolean runAsRoot) {
69         throw new IllegalArgumentException("runAsRoot is immutable");
70      }
71 
72      @Override
73      public boolean shouldBlockOnComplete() {
74         return delegate.shouldBlockOnComplete();
75 
76      }
77 
78      @Override
79      public RunScriptOptions blockOnComplete(boolean blockOnComplete) {
80         throw new IllegalArgumentException("blockOnComplete is immutable");
81      }
82 
83      @Override
84      public RunScriptOptions overrideLoginUserWith(String loginUser) {
85         throw new IllegalArgumentException("loginUser is immutable");
86      }
87 
88      @Override
89      public RunScriptOptions overrideLoginCredentialWith(String loginCredential) {
90         throw new IllegalArgumentException("loginCredential is immutable");
91      }
92 
93      @Override
94      public RunScriptOptions wrapInInitScript(boolean wrapInInitScript) {
95         throw new IllegalArgumentException("wrapInInitScript is immutable");
96      }
97 
98      @Override
99      public RunScriptOptions overrideCredentialsWith(Credentials overridingCredentials) {
100         throw new IllegalArgumentException("overridingCredentials is immutable");
101      }
102 
103      @Override
104      public String getTaskName() {
105         return delegate.getTaskName();
106      }
107 
108      @Override
109      public RunScriptOptions nameTask(String name) {
110         throw new IllegalArgumentException("taskName is immutable");
111      }
112 
113      @Override
114      public RunScriptOptions blockOnPort(int port, int seconds) {
115         throw new IllegalArgumentException("port, seconds are immutable");
116      }
117 
118      @Override
119      public int getPort() {
120         return delegate.getPort();
121      }
122 
123      @Override
124      public int getSeconds() {
125         return delegate.getSeconds();
126      }
127   }
128 
129   protected int port = -1;
130   protected int seconds = -1;
131   protected String taskName;
132   protected Credentials overridingCredentials;
133   protected boolean runAsRoot = true;
134   protected boolean blockOnComplete = true;
135   protected boolean wrapInInitScript = true;
136 
137   public RunScriptOptions overrideCredentialsWith(Credentials overridingCredentials) {
138      checkNotNull(overridingCredentials, "overridingCredentials");
139      this.overridingCredentials = overridingCredentials;
140      return this;
141   }
142 
143   public RunScriptOptions overrideLoginUserWith(String loginUser) {
144      checkNotNull(loginUser, "loginUser");
145      org.jclouds.domain.Credentials.Builder<? extends Credentials> builder = overridingCredentials != null ? overridingCredentials
146            .toBuilder() : new Credentials.Builder<Credentials>();
147      this.overridingCredentials = builder.identity(loginUser).build();
148      return this;
149   }
150 
151   public RunScriptOptions overrideLoginCredentialWith(String loginCredential) {
152      checkNotNull(loginCredential, "loginCredential");
153      org.jclouds.domain.Credentials.Builder<? extends Credentials> builder = overridingCredentials != null ? overridingCredentials
154            .toBuilder() : new Credentials.Builder<Credentials>();
155      this.overridingCredentials = builder.credential(loginCredential).build();
156      return this;
157   }
158 
159   /**
160    * @return What to call the task relating to this script; default
161    *         {@code jclouds-script-timestamp} where timestamp is millis since epoch
162    * 
163    */
164   public RunScriptOptions nameTask(String name) {
165      this.taskName = name;
166      return this;
167   }
168 
169   public RunScriptOptions runAsRoot(boolean runAsRoot) {
170      this.runAsRoot = runAsRoot;
171      return this;
172   }
173 
174   /**
175    * default true
176    * <p/>
177    * 
178    * @param wrapInInitScript
179    *           if the command is long-running, use this option to ensure it is wrapInInitScripted
180    *           properly. (ex. have jclouds wrap it an init script, nohup, etc)
181    * @return
182    */
183   public RunScriptOptions wrapInInitScript(boolean wrapInInitScript) {
184      this.wrapInInitScript = wrapInInitScript;
185      return this;
186   }
187 
188   /**
189    * As of version 1.1.0, we cannot kick off a script unless a node is in
190    * RUNNING state.
191    * 
192    * @param blockOnComplete (default true)
193    *           false means kick off the script in the background, but don't
194    *           wait for it to finish. (as of version 1.1.0, implemented as
195    *           nohup)
196    */
197   public RunScriptOptions blockOnComplete(boolean blockOnComplete) {
198      this.blockOnComplete = blockOnComplete;
199      return this;
200   }
201 
202   /**
203    * When the node is started, wait until the following port is active
204    */
205   public RunScriptOptions blockOnPort(int port, int seconds) {
206      checkArgument(port > 0 && port < 65536, "port must be a positive integer < 65535");
207      checkArgument(seconds > 0, "seconds must be a positive integer");
208      this.port = port;
209      this.seconds = seconds;
210      return this;
211   }
212 
213   public String getTaskName() {
214      return taskName;
215   }
216 
217   public int getPort() {
218      return port;
219   }
220 
221   public int getSeconds() {
222      return seconds;
223   }
224 
225   /**
226    * Whether to override the credentials with ones supplied in call to
227    * {@link org.jclouds.compute.ComputeService#runScriptOnNodesWithTag}. By default, true.
228    * 
229    * @return value
230    */
231   public Credentials getOverridingCredentials() {
232      return overridingCredentials;
233   }
234 
235   /**
236    * Whether to run the script as root (or run with current privileges). By default, true.
237    * 
238    * @return value
239    */
240   public boolean shouldRunAsRoot() {
241      return runAsRoot;
242   }
243 
244   /**
245    * @see #blockOnComplete(boolean)
246    */
247   public boolean shouldBlockOnComplete() {
248      return blockOnComplete;
249   }
250 
251   /**
252    * Whether to wait until the script has completed. By default, true.
253    * 
254    * @return value
255    */
256   public boolean shouldWrapInInitScript() {
257      return wrapInInitScript;
258   }
259 
260   public static class Builder {
261 
262      public static RunScriptOptions nameTask(String name) {
263         RunScriptOptions options = new RunScriptOptions();
264         return options.nameTask(name);
265      }
266 
267      public static RunScriptOptions overrideLoginUserWith(String user) {
268         RunScriptOptions options = new RunScriptOptions();
269         return options.overrideLoginUserWith(user);
270      }
271 
272      public static RunScriptOptions overrideLoginCredentialWith(String credential) {
273         RunScriptOptions options = new RunScriptOptions();
274         return options.overrideLoginCredentialWith(credential);
275      }
276 
277      public static RunScriptOptions overrideCredentialsWith(Credentials credentials) {
278         RunScriptOptions options = new RunScriptOptions();
279         return options.overrideCredentialsWith(credentials);
280      }
281 
282      public static RunScriptOptions runAsRoot(boolean value) {
283         RunScriptOptions options = new RunScriptOptions();
284         return options.runAsRoot(value);
285      }
286      
287      /**
288       * @see RunScriptOptions#blockOnComplete(boolean)
289       */
290      public static RunScriptOptions blockOnComplete(boolean value) {
291         RunScriptOptions options = new RunScriptOptions();
292         return options.blockOnComplete(value);
293      }
294 
295      public static RunScriptOptions wrapInInitScript(boolean value) {
296         RunScriptOptions options = new RunScriptOptions();
297         return options.wrapInInitScript(value);
298      }
299 
300      public static RunScriptOptions blockOnPort(int port, int seconds) {
301         RunScriptOptions options = new RunScriptOptions();
302         return options.blockOnPort(port, seconds);
303      }
304 
305   }
306 
307   @Override
308   public String toString() {
309      return "[overridingCredentials=" + (overridingCredentials != null) + ", port:seconds=" + port + ":" + seconds
310            + ", runAsRoot=" + runAsRoot + ", blockOnComplete=" + blockOnComplete + ", wrapInInitScript="
311            + wrapInInitScript + "]";
312   }
313 
314}

[all classes][org.jclouds.compute.options]
EMMA 2.0.5312 (C) Vladimir Roubtsov