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

COVERAGE SUMMARY FOR SOURCE FILE [InstanceToNodeMetadata.java]

nameclass, %method, %block, %line, %
InstanceToNodeMetadata.java0%   (0/5)0%   (0/15)0%   (0/256)0%   (0/48)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class InstanceToNodeMetadata0%   (0/1)0%   (0/6)0%   (0/204)0%   (0/33)
<static initializer> 0%   (0/1)0%   (0/22)0%   (0/1)
InstanceToNodeMetadata (Map, Supplier, Supplier, Supplier): void 0%   (0/1)0%   (0/30)0%   (0/7)
apply (Instance): NodeMetadata 0%   (0/1)0%   (0/76)0%   (0/13)
parseHardware (Instance): Hardware 0%   (0/1)0%   (0/25)0%   (0/4)
parseLocation (Instance): Location 0%   (0/1)0%   (0/25)0%   (0/4)
parseOperatingSystem (Instance): OperatingSystem 0%   (0/1)0%   (0/26)0%   (0/4)
     
class InstanceToNodeMetadata$10%   (0/1)100% (0/0)100% (0/0)100% (0/0)
     
class InstanceToNodeMetadata$FindHardwareForInstance0%   (0/1)0%   (0/3)0%   (0/17)0%   (0/5)
InstanceToNodeMetadata$FindHardwareForInstance (Instance): void 0%   (0/1)0%   (0/6)0%   (0/3)
InstanceToNodeMetadata$FindHardwareForInstance (Instance, InstanceToNodeMetad... 0%   (0/1)0%   (0/4)0%   (0/1)
apply (Hardware): boolean 0%   (0/1)0%   (0/7)0%   (0/1)
     
class InstanceToNodeMetadata$FindImageForInstance0%   (0/1)0%   (0/3)0%   (0/17)0%   (0/5)
InstanceToNodeMetadata$FindImageForInstance (Instance): void 0%   (0/1)0%   (0/6)0%   (0/3)
InstanceToNodeMetadata$FindImageForInstance (Instance, InstanceToNodeMetadata... 0%   (0/1)0%   (0/4)0%   (0/1)
apply (Image): boolean 0%   (0/1)0%   (0/7)0%   (0/1)
     
class InstanceToNodeMetadata$FindLocationForInstance0%   (0/1)0%   (0/3)0%   (0/18)0%   (0/5)
InstanceToNodeMetadata$FindLocationForInstance (Instance): void 0%   (0/1)0%   (0/6)0%   (0/3)
InstanceToNodeMetadata$FindLocationForInstance (Instance, InstanceToNodeMetad... 0%   (0/1)0%   (0/4)0%   (0/1)
apply (Location): boolean 0%   (0/1)0%   (0/8)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.deltacloud.compute.functions;
20 
21import static com.google.common.base.Preconditions.checkNotNull;
22import static org.jclouds.compute.util.ComputeServiceUtils.parseGroupFromName;
23 
24import java.util.Map;
25import java.util.NoSuchElementException;
26import java.util.Set;
27 
28import javax.annotation.Resource;
29import javax.inject.Inject;
30import javax.inject.Named;
31import javax.inject.Singleton;
32 
33import org.jclouds.collect.Memoized;
34import org.jclouds.compute.domain.Hardware;
35import org.jclouds.compute.domain.Image;
36import org.jclouds.compute.domain.NodeMetadata;
37import org.jclouds.compute.domain.NodeMetadataBuilder;
38import org.jclouds.compute.domain.NodeState;
39import org.jclouds.compute.domain.OperatingSystem;
40import org.jclouds.compute.reference.ComputeServiceConstants;
41import org.jclouds.deltacloud.domain.Instance;
42import org.jclouds.domain.Credentials;
43import org.jclouds.domain.Location;
44import org.jclouds.logging.Logger;
45 
46import com.google.common.base.Function;
47import com.google.common.base.Predicate;
48import com.google.common.base.Supplier;
49import com.google.common.collect.ImmutableMap;
50import com.google.common.collect.Iterables;
51 
52/**
53 * @author Adrian Cole
54 */
55@Singleton
56public class InstanceToNodeMetadata implements Function<Instance, NodeMetadata> {
57 
58   public static final Map<Instance.State, NodeState> instanceToNodeState = ImmutableMap
59            .<Instance.State, NodeState> builder().put(Instance.State.STOPPED, NodeState.SUSPENDED).put(
60                     Instance.State.RUNNING, NodeState.RUNNING).put(Instance.State.PENDING, NodeState.PENDING).put(
61                     Instance.State.UNRECOGNIZED, NodeState.UNRECOGNIZED).put(Instance.State.SHUTTING_DOWN,
62                     NodeState.PENDING).put(Instance.State.START, NodeState.PENDING).build();
63 
64   @Resource
65   @Named(ComputeServiceConstants.COMPUTE_LOGGER)
66   protected Logger logger = Logger.NULL;
67 
68   protected final Map<String, Credentials> credentialStore;
69   protected final Supplier<Set<? extends Location>> locations;
70   protected final Supplier<Set<? extends Image>> images;
71   protected final Supplier<Set<? extends Hardware>> hardwares;
72 
73   private static class FindImageForInstance implements Predicate<Image> {
74      private final Instance instance;
75 
76      private FindImageForInstance(Instance instance) {
77         this.instance = instance;
78      }
79 
80      @Override
81      public boolean apply(Image input) {
82         return input.getUri().equals(instance.getImage());
83      }
84   }
85 
86   private static class FindHardwareForInstance implements Predicate<Hardware> {
87      private final Instance instance;
88 
89      private FindHardwareForInstance(Instance instance) {
90         this.instance = instance;
91      }
92 
93      @Override
94      public boolean apply(Hardware input) {
95         return input.getUri().equals(instance.getHardwareProfile());
96      }
97   }
98 
99   protected Hardware parseHardware(Instance from) {
100      try {
101         return Iterables.find(hardwares.get(), new FindHardwareForInstance(from));
102      } catch (NoSuchElementException e) {
103         logger.warn("could not find a matching hardware for instance %s", from);
104      }
105      return null;
106   }
107 
108   protected OperatingSystem parseOperatingSystem(Instance from) {
109      try {
110         return Iterables.find(images.get(), new FindImageForInstance(from)).getOperatingSystem();
111      } catch (NoSuchElementException e) {
112         logger.warn("could not find a matching image for instance %s", from);
113      }
114      return null;
115   }
116 
117   private static class FindLocationForInstance implements Predicate<Location> {
118      private final Instance instance;
119 
120      private FindLocationForInstance(Instance instance) {
121         this.instance = instance;
122      }
123 
124      @Override
125      public boolean apply(Location input) {
126         return input.getId().equals(instance.getRealm().toASCIIString());
127      }
128   }
129 
130   protected Location parseLocation(Instance from) {
131      try {
132         return Iterables.find(locations.get(), new FindLocationForInstance(from));
133      } catch (NoSuchElementException e) {
134         logger.warn("could not find a matching realm for instance %s", from);
135      }
136      return null;
137   }
138 
139   @Inject
140   InstanceToNodeMetadata(Map<String, Credentials> credentialStore,
141            @Memoized Supplier<Set<? extends Location>> locations, @Memoized Supplier<Set<? extends Image>> images,
142            @Memoized Supplier<Set<? extends Hardware>> hardwares) {
143      this.credentialStore = checkNotNull(credentialStore, "credentialStore");
144      this.images = checkNotNull(images, "images");
145      this.locations = checkNotNull(locations, "locations");
146      this.hardwares = checkNotNull(hardwares, "hardwares");
147   }
148 
149   @Override
150   public NodeMetadata apply(org.jclouds.deltacloud.domain.Instance from) {
151      NodeMetadataBuilder builder = new NodeMetadataBuilder();
152      builder.ids(from.getHref().toASCIIString());
153      builder.name(from.getName());
154      builder.location(parseLocation(from));
155      builder.group(parseGroupFromName(from.getName()));
156      builder.imageId(from.getImage().toASCIIString());
157      builder.operatingSystem(parseOperatingSystem(from));
158      builder.hardware(parseHardware(from));
159      builder.state(instanceToNodeState.get(from.getState()));
160      builder.publicAddresses(from.getPublicAddresses());
161      builder.privateAddresses(from.getPrivateAddresses());
162      builder.credentials(credentialStore.get(from.getHref().toASCIIString()));
163      return builder.build();
164   }
165}

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