EMMA Coverage Report (generated Fri Apr 27 15:03:37 EDT 2012)
[all classes][org.jclouds.ec2.compute.strategy]

COVERAGE SUMMARY FOR SOURCE FILE [EC2ListNodesStrategy.java]

nameclass, %method, %block, %line, %
EC2ListNodesStrategy.java50%  (1/2)12%  (1/8)33%  (30/92)41%  (7/17)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class EC2ListNodesStrategy$10%   (0/1)0%   (0/2)0%   (0/16)0%   (0/2)
EC2ListNodesStrategy$1 (EC2ListNodesStrategy): void 0%   (0/1)0%   (0/6)0%   (0/1)
apply (String): Future 0%   (0/1)0%   (0/10)0%   (0/1)
     
class EC2ListNodesStrategy100% (1/1)17%  (1/6)39%  (30/76)47%  (7/15)
access$000 (Future): Future 0%   (0/1)0%   (0/3)0%   (0/1)
castToSpecificTypedFuture (Future): Future 0%   (0/1)0%   (0/2)0%   (0/1)
listDetailsOnNodesMatching (Predicate): Set 0%   (0/1)0%   (0/17)0%   (0/3)
listNodes (): Set 0%   (0/1)0%   (0/4)0%   (0/1)
pollRunningInstances (): Iterable 0%   (0/1)0%   (0/20)0%   (0/2)
EC2ListNodesStrategy (EC2AsyncClient, Supplier, Function, ExecutorService): void 100% (1/1)100% (30/30)100% (7/7)

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.ec2.compute.strategy;
20 
21import static com.google.common.base.Preconditions.checkNotNull;
22import static com.google.common.base.Predicates.and;
23import static com.google.common.base.Predicates.notNull;
24import static com.google.common.collect.Iterables.concat;
25import static com.google.common.collect.Iterables.filter;
26import static com.google.common.collect.Iterables.transform;
27import static org.jclouds.concurrent.FutureIterables.transformParallel;
28 
29import java.util.Set;
30import java.util.concurrent.ExecutorService;
31import java.util.concurrent.Future;
32 
33import javax.annotation.Resource;
34import javax.inject.Inject;
35import javax.inject.Named;
36import javax.inject.Singleton;
37 
38import org.jclouds.Constants;
39import org.jclouds.compute.domain.ComputeMetadata;
40import org.jclouds.compute.domain.NodeMetadata;
41import org.jclouds.compute.predicates.NodePredicates;
42import org.jclouds.compute.reference.ComputeServiceConstants;
43import org.jclouds.compute.strategy.ListNodesStrategy;
44import org.jclouds.ec2.EC2AsyncClient;
45import org.jclouds.ec2.domain.Reservation;
46import org.jclouds.ec2.domain.RunningInstance;
47import org.jclouds.location.Region;
48import org.jclouds.logging.Logger;
49 
50import com.google.common.base.Function;
51import com.google.common.base.Predicate;
52import com.google.common.base.Supplier;
53import com.google.common.collect.ImmutableSet;
54 
55/**
56 * 
57 * @author Adrian Cole
58 */
59@Singleton
60public class EC2ListNodesStrategy implements ListNodesStrategy {
61   @Resource
62   @Named(ComputeServiceConstants.COMPUTE_LOGGER)
63   protected Logger logger = Logger.NULL;
64 
65   protected final EC2AsyncClient client;
66   protected final Supplier<Set<String>> regions;
67   protected final Function<RunningInstance, NodeMetadata> runningInstanceToNodeMetadata;
68   protected final ExecutorService executor;
69 
70   @Inject
71   protected EC2ListNodesStrategy(EC2AsyncClient client, @Region Supplier<Set<String>> regions,
72            Function<RunningInstance, NodeMetadata> runningInstanceToNodeMetadata,
73            @Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor) {
74      this.client =  checkNotNull(client, "client");
75      this.regions =  checkNotNull(regions, "regions");
76      this.runningInstanceToNodeMetadata = checkNotNull(runningInstanceToNodeMetadata, "runningInstanceToNodeMetadata");
77      this.executor =  checkNotNull(executor, "executor");
78   }
79 
80   @Override
81   public Set<? extends ComputeMetadata> listNodes() {
82      return listDetailsOnNodesMatching(NodePredicates.all());
83   }
84 
85   @Override
86   public Set<? extends NodeMetadata> listDetailsOnNodesMatching(Predicate<ComputeMetadata> filter) {
87      Iterable<? extends RunningInstance> instances = pollRunningInstances();
88      Iterable<? extends NodeMetadata> nodes = filter(transform(filter(instances, notNull()),
89               runningInstanceToNodeMetadata), and(notNull(), filter));
90      return ImmutableSet.copyOf(nodes);
91   }
92 
93   protected Iterable<? extends RunningInstance> pollRunningInstances() {
94      Iterable<? extends Set<? extends Reservation<? extends RunningInstance>>> reservations = transformParallel(
95               regions.get(), new Function<String, Future<? extends Set<? extends Reservation<? extends RunningInstance>>>>() {
96 
97                  @Override
98                  public Future<Set<? extends Reservation<? extends RunningInstance>>> apply(String from) {
99                     // see http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=7126754
100                     return castToSpecificTypedFuture(client.getInstanceServices().describeInstancesInRegion(from));
101                  }
102 
103               }, executor, null, logger, "reservations");
104 
105      return concat(concat(reservations));
106   }
107 
108   @SuppressWarnings("unchecked")
109   private static <T> Future<T> castToSpecificTypedFuture(Future<? extends T> input) {
110       return (Future<T>) input;
111   }
112}

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