EMMA Coverage Report (generated Wed Aug 10 12:30:04 EDT 2011)
[all classes][org.jclouds.vcloud.compute.functions]

COVERAGE SUMMARY FOR SOURCE FILE [HardwareForVApp.java]

nameclass, %method, %block, %line, %
HardwareForVApp.java100% (1/1)100% (2/2)95%  (72/76)92%  (12.9/14)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class HardwareForVApp100% (1/1)100% (2/2)95%  (72/76)92%  (12.9/14)
apply (VApp): Hardware 100% (1/1)93%  (54/58)88%  (7.9/9)
HardwareForVApp (Function, VCloudHardwareBuilderFromResourceAllocations): void 100% (1/1)100% (18/18)100% (5/5)

1/**
2 *
3 * Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
4 *
5 * ====================================================================
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * 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, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 * ====================================================================
18 */
19package org.jclouds.vcloud.compute.functions;
20 
21import static com.google.common.base.Preconditions.checkNotNull;
22 
23import javax.annotation.Resource;
24import javax.inject.Inject;
25 
26import org.jclouds.compute.domain.Hardware;
27import org.jclouds.compute.domain.HardwareBuilder;
28import org.jclouds.compute.predicates.ImagePredicates;
29import org.jclouds.domain.Location;
30import org.jclouds.logging.Logger;
31import org.jclouds.ovf.VirtualHardwareSection;
32import org.jclouds.vcloud.domain.ReferenceType;
33import org.jclouds.vcloud.domain.VApp;
34import org.jclouds.vcloud.domain.Vm;
35 
36import com.google.common.base.Function;
37import com.google.common.collect.Iterables;
38 
39/**
40 * @author Adrian Cole
41 */
42public class HardwareForVApp implements Function<VApp, Hardware> {
43 
44   @Resource
45   protected Logger logger = Logger.NULL;
46 
47   private final Function<ReferenceType, Location> findLocationForResource;
48   private final VCloudHardwareBuilderFromResourceAllocations rasdToHardwareBuilder;
49 
50   @Inject
51   protected HardwareForVApp(Function<ReferenceType, Location> findLocationForResource,
52            VCloudHardwareBuilderFromResourceAllocations rasdToHardwareBuilder) {
53      this.findLocationForResource = checkNotNull(findLocationForResource, "findLocationForResource");
54      this.rasdToHardwareBuilder = checkNotNull(rasdToHardwareBuilder, "rasdToHardwareBuilder");
55   }
56 
57   @Override
58   public Hardware apply(VApp from) {
59      checkNotNull(from, "VApp");
60      // TODO make this work with composite vApps
61      Vm vm = from.getChildren().size() == 0 ? null : Iterables.get(from.getChildren(), 0);
62      if (vm == null)
63         return null;
64 
65      VirtualHardwareSection hardware = vm.getVirtualHardwareSection();
66      HardwareBuilder builder = rasdToHardwareBuilder.apply(hardware.getItems());
67      builder.location(findLocationForResource.apply(checkNotNull(from, "from").getVDC()));
68      builder.ids(from.getHref().toASCIIString()).name(from.getName()).supportsImage(
69               ImagePredicates.idEquals(from.getHref().toASCIIString()));
70      return builder.build();
71   }
72}

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