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

COVERAGE SUMMARY FOR SOURCE FILE [AWSRunningInstanceToNodeMetadata.java]

nameclass, %method, %block, %line, %
AWSRunningInstanceToNodeMetadata.java100% (1/1)100% (3/3)61%  (68/111)69%  (9/13)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class AWSRunningInstanceToNodeMetadata100% (1/1)100% (3/3)61%  (68/111)69%  (9/13)
addCredentialsForInstance (NodeMetadataBuilder, RunningInstance): void 100% (1/1)43%  (32/75)56%  (5/9)
AWSRunningInstanceToNodeMetadata (Map, Map, Supplier, Supplier, Supplier): void 100% (1/1)100% (8/8)100% (2/2)
buildInstance (RunningInstance, NodeMetadataBuilder): NodeMetadataBuilder 100% (1/1)100% (28/28)100% (2/2)

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.aws.ec2.compute.functions;
20 
21import static com.google.common.base.Predicates.*;
22import static com.google.common.collect.Maps.*;
23 
24import java.util.Map;
25import java.util.Set;
26 
27import javax.inject.Inject;
28import javax.inject.Singleton;
29 
30import org.jclouds.aws.ec2.domain.AWSRunningInstance;
31import org.jclouds.collect.Memoized;
32import org.jclouds.compute.domain.Hardware;
33import org.jclouds.compute.domain.Image;
34import org.jclouds.compute.domain.NodeMetadataBuilder;
35import org.jclouds.compute.domain.NodeState;
36import org.jclouds.domain.Credentials;
37import org.jclouds.domain.Location;
38import org.jclouds.ec2.compute.domain.RegionAndName;
39import org.jclouds.ec2.compute.functions.RunningInstanceToNodeMetadata;
40import org.jclouds.ec2.domain.InstanceState;
41import org.jclouds.ec2.domain.RunningInstance;
42 
43import com.google.common.base.Supplier;
44import com.google.common.cache.Cache;
45 
46/**
47 * @author Adrian Cole
48 */
49@Singleton
50public class AWSRunningInstanceToNodeMetadata extends RunningInstanceToNodeMetadata {
51 
52   @Inject
53   protected AWSRunningInstanceToNodeMetadata(Map<InstanceState, NodeState> instanceToNodeState,
54         Map<String, Credentials> credentialStore, Supplier<Cache<RegionAndName, ? extends Image>> imageMap,
55         @Memoized Supplier<Set<? extends Location>> locations, @Memoized Supplier<Set<? extends Hardware>> hardware) {
56      super(instanceToNodeState, credentialStore, imageMap, locations, hardware);
57   }
58 
59   @Override
60   protected void addCredentialsForInstance(NodeMetadataBuilder builder, RunningInstance instance) {
61      Credentials creds = credentialStore.get("node#" + instance.getRegion() + "/" + instance.getId());
62      String spotRequestId = AWSRunningInstance.class.cast(instance).getSpotInstanceRequestId();
63      if (creds == null && spotRequestId != null) {
64         creds = credentialStore.get("node#" + instance.getRegion() + "/" + spotRequestId);
65         if (creds != null)
66            credentialStore.put("node#" + instance.getRegion() + "/" + instance.getId(), creds);
67      }
68      if (creds != null)
69         builder.credentials(creds);
70   }
71 
72   @Override
73   protected NodeMetadataBuilder buildInstance(RunningInstance instance, NodeMetadataBuilder builder) {
74      Map<String, String> tags = AWSRunningInstance.class.cast(instance).getTags();
75      return super.buildInstance(instance, builder).name(tags.get("Name")).tags(
76               filterValues(tags, equalTo("")).keySet()).userMetadata(filterValues(tags, not(equalTo(""))));
77   }
78}

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