EMMA Coverage Report (generated Tue Jun 21 05:51:52 EDT 2011)
[all classes][org.jclouds.compute.predicates]

COVERAGE SUMMARY FOR SOURCE FILE [ScriptStatusReturnsZero.java]

nameclass, %method, %block, %line, %
ScriptStatusReturnsZero.java0%   (0/2)0%   (0/6)0%   (0/95)0%   (0/14)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class ScriptStatusReturnsZero0%   (0/1)0%   (0/3)0%   (0/80)0%   (0/10)
ScriptStatusReturnsZero (): void 0%   (0/1)0%   (0/6)0%   (0/3)
apply (ScriptStatusReturnsZero$CommandUsingClient): boolean 0%   (0/1)0%   (0/68)0%   (0/6)
refresh (ScriptStatusReturnsZero$CommandUsingClient): ExecResponse 0%   (0/1)0%   (0/6)0%   (0/1)
     
class ScriptStatusReturnsZero$CommandUsingClient0%   (0/1)0%   (0/3)0%   (0/15)0%   (0/5)
ScriptStatusReturnsZero$CommandUsingClient (String, SshClient): void 0%   (0/1)0%   (0/9)0%   (0/4)
access$000 (ScriptStatusReturnsZero$CommandUsingClient): String 0%   (0/1)0%   (0/3)0%   (0/1)
access$100 (ScriptStatusReturnsZero$CommandUsingClient): SshClient 0%   (0/1)0%   (0/3)0%   (0/1)

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 */
19package org.jclouds.compute.predicates;
20 
21import javax.annotation.Resource;
22import javax.inject.Singleton;
23 
24import org.jclouds.compute.domain.ExecResponse;
25import org.jclouds.logging.Logger;
26import org.jclouds.ssh.SshClient;
27 
28import com.google.common.base.Predicate;
29 
30/**
31 * 
32 * Tests to if the runscript is still running
33 * 
34 * @author Adrian Cole
35 */
36@Singleton
37public class ScriptStatusReturnsZero implements
38         Predicate<ScriptStatusReturnsZero.CommandUsingClient> {
39 
40   @Resource
41   protected Logger logger = Logger.NULL;
42 
43   @Override
44   public boolean apply(CommandUsingClient commandUsingClient) {
45      logger.trace("looking for [%s] state on %s@%s", commandUsingClient.command,
46               commandUsingClient.client.getUsername(), commandUsingClient.client.getHostAddress());
47      ExecResponse response = refresh(commandUsingClient);
48      while (response.getExitCode() == -1)
49         response = refresh(commandUsingClient);
50      logger.trace("%s@%s: looking for exit code 0: currently: %s", commandUsingClient.client
51               .getUsername(), commandUsingClient.client.getHostAddress(), response.getExitCode());
52      return 0 == response.getExitCode();
53   }
54 
55   private ExecResponse refresh(CommandUsingClient commandUsingClient) {
56      return commandUsingClient.client.exec(commandUsingClient.command);
57   }
58 
59   public static class CommandUsingClient {
60 
61      public CommandUsingClient(String command, SshClient client) {
62         this.command = command;
63         this.client = client;
64      }
65 
66      private final String command;
67      private final SshClient client;
68   }
69}

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