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

COVERAGE SUMMARY FOR SOURCE FILE [NodePresentAndInIntendedState.java]

nameclass, %method, %block, %line, %
NodePresentAndInIntendedState.java100% (1/1)100% (4/4)96%  (109/114)89%  (16.9/19)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class NodePresentAndInIntendedState100% (1/1)100% (4/4)96%  (109/114)89%  (16.9/19)
refresh (NodeMetadata): NodeMetadata 100% (1/1)85%  (11/13)67%  (2/3)
apply (NodeMetadata): boolean 100% (1/1)96%  (76/79)86%  (6.9/8)
NodePresentAndInIntendedState (NodeState, ComputeService): void 100% (1/1)100% (7/7)100% (2/2)
NodePresentAndInIntendedState (NodeState, Set, ComputeService): void 100% (1/1)100% (15/15)100% (6/6)

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.predicates;
20 
21import static com.google.common.base.Preconditions.checkNotNull;
22 
23import java.util.Set;
24 
25import javax.annotation.Resource;
26import javax.inject.Singleton;
27 
28import org.jclouds.compute.ComputeService;
29import org.jclouds.compute.domain.NodeMetadata;
30import org.jclouds.compute.domain.NodeState;
31import org.jclouds.logging.Logger;
32 
33import com.google.common.base.Predicate;
34import com.google.common.collect.ImmutableSet;
35import com.google.inject.Inject;
36 
37/**
38 * 
39 * Tests to see if a node is active.
40 * 
41 * @author Adrian Cole
42 */
43@Singleton
44public class NodePresentAndInIntendedState implements Predicate<NodeMetadata> {
45 
46   private final ComputeService client;
47   private final NodeState intended;
48   private final Set<NodeState> invalids;
49   @Resource
50   protected Logger logger = Logger.NULL;
51 
52   @Inject
53   public NodePresentAndInIntendedState(NodeState intended, ComputeService client) {
54      this(intended, ImmutableSet.of(NodeState.ERROR), client);
55   }
56 
57   public NodePresentAndInIntendedState(NodeState intended, Set<NodeState> invalids, ComputeService client) {
58      this.intended = intended;
59      this.client = client;
60      this.invalids = invalids;
61   }
62 
63   public boolean apply(NodeMetadata node) {
64      logger.trace("looking for state on node %s", checkNotNull(node, "node"));
65      node = refresh(node);
66      if (node == null)
67         return false;
68      logger.trace("%s: looking for node state %s: currently: %s", node.getId(), intended, node.getState());
69      if (invalids.contains(node.getState()))
70         throw new IllegalStateException("node " + node.getId() + " in location " + node.getLocation()
71                  + " is in invalid state "+node.getState());
72      return node.getState() == intended;
73   }
74 
75   private NodeMetadata refresh(NodeMetadata node) {
76      if (node == null || node.getId() == null)
77         return null;
78      return client.getNodeMetadata(node.getId());
79   }
80}

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