EMMA Coverage Report (generated Mon Oct 17 05:41:20 EDT 2011)
[all classes][org.jclouds.ec2.compute.strategy]

COVERAGE SUMMARY FOR SOURCE FILE [EC2ListNodesStrategy.java]

nameclass, %method, %block, %line, %
EC2ListNodesStrategy.java0%   (0/2)0%   (0/6)0%   (0/84)0%   (0/15)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class EC2ListNodesStrategy0%   (0/1)0%   (0/4)0%   (0/69)0%   (0/13)
EC2ListNodesStrategy (EC2AsyncClient, Set, Function, ExecutorService): void 0%   (0/1)0%   (0/30)0%   (0/7)
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/18)0%   (0/2)
     
class EC2ListNodesStrategy$10%   (0/1)0%   (0/2)0%   (0/15)0%   (0/2)
EC2ListNodesStrategy$1 (EC2ListNodesStrategy): void 0%   (0/1)0%   (0/6)0%   (0/1)
apply (String): Future 0%   (0/1)0%   (0/9)0%   (0/1)

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.collect.ImmutableSet;
53 
54/**
55 * 
56 * @author Adrian Cole
57 */
58@Singleton
59public class EC2ListNodesStrategy implements ListNodesStrategy {
60   @Resource
61   @Named(ComputeServiceConstants.COMPUTE_LOGGER)
62   protected Logger logger = Logger.NULL;
63 
64   protected final EC2AsyncClient client;
65   protected final Set<String> regions;
66   protected final Function<RunningInstance, NodeMetadata> runningInstanceToNodeMetadata;
67   protected final ExecutorService executor;
68 
69   @Inject
70   protected EC2ListNodesStrategy(EC2AsyncClient client, @Region Set<String> regions,
71            Function<RunningInstance, NodeMetadata> runningInstanceToNodeMetadata,
72            @Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor) {
73      this.client =  checkNotNull(client, "client");
74      this.regions =  checkNotNull(regions, "regions");
75      this.runningInstanceToNodeMetadata = checkNotNull(runningInstanceToNodeMetadata, "runningInstanceToNodeMetadata");
76      this.executor =  checkNotNull(executor, "executor");
77   }
78 
79   @Override
80   public Set<? extends ComputeMetadata> listNodes() {
81      return listDetailsOnNodesMatching(NodePredicates.all());
82   }
83 
84   @Override
85   public Set<? extends NodeMetadata> listDetailsOnNodesMatching(Predicate<ComputeMetadata> filter) {
86      Iterable<? extends RunningInstance> instances = pollRunningInstances();
87      Iterable<? extends NodeMetadata> nodes = filter(transform(filter(instances, notNull()),
88               runningInstanceToNodeMetadata), and(notNull(), filter));
89      return ImmutableSet.copyOf(nodes);
90   }
91 
92   protected Iterable<? extends RunningInstance> pollRunningInstances() {
93      Iterable<? extends Set<? extends Reservation<? extends RunningInstance>>> reservations = transformParallel(
94               regions, new Function<String, Future<Set<? extends Reservation<? extends RunningInstance>>>>() {
95 
96                  @SuppressWarnings("unchecked")
97                  @Override
98                  public Future<Set<? extends Reservation<? extends RunningInstance>>> apply(String from) {
99                     return (Future<Set<? extends Reservation<? extends RunningInstance>>>) client
100                              .getInstanceServices().describeInstancesInRegion(from);
101                  }
102 
103               }, executor, null, logger, "reservations");
104 
105      return concat(concat(reservations));
106   }
107}

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