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

COVERAGE SUMMARY FOR SOURCE FILE [EC2GetNodeMetadataStrategy.java]

nameclass, %method, %block, %line, %
EC2GetNodeMetadataStrategy.java100% (1/1)33%  (1/3)25%  (15/59)31%  (4/13)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class EC2GetNodeMetadataStrategy100% (1/1)33%  (1/3)25%  (15/59)31%  (4/13)
getNode (String): NodeMetadata 0%   (0/1)0%   (0/29)0%   (0/8)
getRunningInstanceInRegion (String, String): RunningInstance 0%   (0/1)0%   (0/15)0%   (0/1)
EC2GetNodeMetadataStrategy (EC2Client, Function): void 100% (1/1)100% (15/15)100% (4/4)

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.collect.Iterables.getOnlyElement;
23 
24import java.util.NoSuchElementException;
25 
26import javax.inject.Inject;
27import javax.inject.Singleton;
28 
29import org.jclouds.aws.util.AWSUtils;
30import org.jclouds.compute.domain.NodeMetadata;
31import org.jclouds.compute.strategy.GetNodeMetadataStrategy;
32import org.jclouds.ec2.EC2Client;
33import org.jclouds.ec2.domain.RunningInstance;
34 
35import com.google.common.base.Function;
36import com.google.common.collect.Iterables;
37 
38/**
39 * 
40 * @author Adrian Cole
41 */
42@Singleton
43public class EC2GetNodeMetadataStrategy implements GetNodeMetadataStrategy {
44 
45   private final EC2Client client;
46   private final Function<RunningInstance, NodeMetadata> runningInstanceToNodeMetadata;
47 
48   @Inject
49   protected EC2GetNodeMetadataStrategy(EC2Client client,
50            Function<RunningInstance, NodeMetadata> runningInstanceToNodeMetadata) {
51      this.client = checkNotNull(client, "client");
52      this.runningInstanceToNodeMetadata = checkNotNull(runningInstanceToNodeMetadata, "runningInstanceToNodeMetadata");
53   }
54 
55   @Override
56   public NodeMetadata getNode(String id) {
57      checkNotNull(id, "id");
58      String[] parts = AWSUtils.parseHandle(id);
59      String region = parts[0];
60      String instanceId = parts[1];
61      try {
62         RunningInstance runningInstance = getRunningInstanceInRegion(region, instanceId);
63         return runningInstanceToNodeMetadata.apply(runningInstance);
64      } catch (NoSuchElementException e) {
65         return null;
66      }
67   }
68 
69   public RunningInstance getRunningInstanceInRegion(String region, String id) {
70      return getOnlyElement(Iterables.concat(client.getInstanceServices().describeInstancesInRegion(region, id)));
71   }
72 
73}

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