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

COVERAGE SUMMARY FOR SOURCE FILE [SliceToNodeMetadata.java]

nameclass, %method, %block, %line, %
SliceToNodeMetadata.java100% (5/5)100% (14/14)100% (275/275)100% (42/42)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class SliceToNodeMetadata100% (1/1)100% (4/4)100% (203/203)100% (30/30)
SliceToNodeMetadata (Map, Map, Supplier, Supplier, Supplier): void 100% (1/1)100% (36/36)100% (8/8)
apply (Slice): NodeMetadata 100% (1/1)100% (111/111)100% (14/14)
parseHardware (Slice): Hardware 100% (1/1)100% (25/25)100% (4/4)
parseOperatingSystem (Slice): OperatingSystem 100% (1/1)100% (31/31)100% (4/4)
     
class SliceToNodeMetadata$1100% (1/1)100% (2/2)100% (14/14)100% (2/2)
SliceToNodeMetadata$1 (SliceToNodeMetadata): void 100% (1/1)100% (6/6)100% (1/1)
apply (String): boolean 100% (1/1)100% (8/8)100% (1/1)
     
class SliceToNodeMetadata$2100% (1/1)100% (2/2)100% (10/10)100% (2/2)
SliceToNodeMetadata$2 (SliceToNodeMetadata): void 100% (1/1)100% (6/6)100% (1/1)
apply (String): boolean 100% (1/1)100% (4/4)100% (1/1)
     
class SliceToNodeMetadata$FindHardwareForSlice100% (1/1)100% (3/3)100% (24/24)100% (5/5)
SliceToNodeMetadata$FindHardwareForSlice (Slice): void 100% (1/1)100% (6/6)100% (3/3)
SliceToNodeMetadata$FindHardwareForSlice (Slice, SliceToNodeMetadata$1): void 100% (1/1)100% (4/4)100% (1/1)
apply (Hardware): boolean 100% (1/1)100% (14/14)100% (1/1)
     
class SliceToNodeMetadata$FindImageForSlice100% (1/1)100% (3/3)100% (24/24)100% (5/5)
SliceToNodeMetadata$FindImageForSlice (Slice): void 100% (1/1)100% (6/6)100% (3/3)
SliceToNodeMetadata$FindImageForSlice (Slice, SliceToNodeMetadata$1): void 100% (1/1)100% (4/4)100% (1/1)
apply (Image): boolean 100% (1/1)100% (14/14)100% (1/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.slicehost.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.Singleton;
31 
32import org.jclouds.collect.Memoized;
33import org.jclouds.compute.domain.Hardware;
34import org.jclouds.compute.domain.Image;
35import org.jclouds.compute.domain.NodeMetadata;
36import org.jclouds.compute.domain.NodeMetadataBuilder;
37import org.jclouds.compute.domain.NodeState;
38import org.jclouds.compute.domain.OperatingSystem;
39import org.jclouds.domain.Credentials;
40import org.jclouds.domain.Location;
41import org.jclouds.logging.Logger;
42import org.jclouds.slicehost.domain.Slice;
43 
44import com.google.common.base.Function;
45import com.google.common.base.Predicate;
46import com.google.common.base.Supplier;
47import com.google.common.collect.Iterables;
48 
49/**
50 * @author Adrian Cole
51 */
52@Singleton
53public class SliceToNodeMetadata implements Function<Slice, NodeMetadata> {
54   protected final Supplier<Location> location;
55   protected final Map<Slice.Status, NodeState> sliceToNodeState;
56   protected final Supplier<Set<? extends Image>> images;
57   protected final Supplier<Set<? extends Hardware>> hardwares;
58   protected final Map<String, Credentials> credentialStore;
59 
60   @Resource
61   protected Logger logger = Logger.NULL;
62 
63   private static class FindImageForSlice implements Predicate<Image> {
64      private final Slice slice;
65 
66      private FindImageForSlice(Slice slice) {
67         this.slice = slice;
68      }
69 
70      @Override
71      public boolean apply(Image input) {
72         return input.getProviderId().equals(slice.getImageId() + "");
73      }
74   }
75 
76   private static class FindHardwareForSlice implements Predicate<Hardware> {
77      private final Slice slice;
78 
79      private FindHardwareForSlice(Slice slice) {
80         this.slice = slice;
81      }
82 
83      @Override
84      public boolean apply(Hardware input) {
85         return input.getProviderId().equals(slice.getFlavorId() + "");
86      }
87   }
88 
89   @Inject
90   SliceToNodeMetadata(Map<Slice.Status, NodeState> sliceStateToNodeState, Map<String, Credentials> credentialStore,
91            @Memoized Supplier<Set<? extends Image>> images, Supplier<Location> location,
92            @Memoized Supplier<Set<? extends Hardware>> hardwares) {
93      this.sliceToNodeState = checkNotNull(sliceStateToNodeState, "sliceStateToNodeState");
94      this.credentialStore = checkNotNull(credentialStore, "credentialStore");
95      this.images = checkNotNull(images, "images");
96      this.location = checkNotNull(location, "location");
97      this.hardwares = checkNotNull(hardwares, "hardwares");
98   }
99 
100   @Override
101   public NodeMetadata apply(Slice from) {
102      NodeMetadataBuilder builder = new NodeMetadataBuilder();
103      builder.ids(from.getId() + "");
104      builder.name(from.getName());
105      builder.hostname(from.getName());
106      builder.location(location.get());
107      builder.group(parseGroupFromName(from.getName()));
108      builder.imageId(from.getImageId() + "");
109      builder.operatingSystem(parseOperatingSystem(from));
110      builder.hardware(parseHardware(from));
111      builder.state(sliceToNodeState.get(from.getStatus()));
112      builder.publicAddresses(Iterables.filter(from.getAddresses(), new Predicate<String>() {
113 
114         @Override
115         public boolean apply(String input) {
116            return !input.startsWith("10.");
117         }
118 
119      }));
120      builder.privateAddresses(Iterables.filter(from.getAddresses(), new Predicate<String>() {
121 
122         @Override
123         public boolean apply(String input) {
124            return input.startsWith("10.");
125         }
126 
127      }));
128      builder.credentials(credentialStore.get("node#" + from.getId()));
129      return builder.build();
130   }
131 
132   protected Hardware parseHardware(Slice from) {
133      try {
134         return Iterables.find(hardwares.get(), new FindHardwareForSlice(from));
135      } catch (NoSuchElementException e) {
136         logger.warn("could not find a matching hardware for slice %s", from);
137      }
138      return null;
139   }
140 
141   protected OperatingSystem parseOperatingSystem(Slice from) {
142      try {
143         return Iterables.find(images.get(), new FindImageForSlice(from)).getOperatingSystem();
144      } catch (NoSuchElementException e) {
145         logger.warn("could not find a matching image for slice %s in location %s", from, location);
146      }
147      return null;
148   }
149}

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