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

COVERAGE SUMMARY FOR SOURCE FILE [SoftLayerComputeServiceContextModule.java]

nameclass, %method, %block, %line, %
SoftLayerComputeServiceContextModule.java78%  (7/9)53%  (8/15)56%  (104/186)52%  (11/21)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class SoftLayerComputeServiceContextModule$70%   (0/1)0%   (0/2)0%   (0/34)0%   (0/5)
SoftLayerComputeServiceContextModule$7 (SoftLayerComputeServiceContextModule,... 0%   (0/1)0%   (0/12)0%   (0/1)
get (): ProductPackage 0%   (0/1)0%   (0/22)0%   (0/4)
     
class SoftLayerComputeServiceContextModule$80%   (0/1)0%   (0/2)0%   (0/12)0%   (0/2)
SoftLayerComputeServiceContextModule$8 (SoftLayerComputeServiceContextModule)... 0%   (0/1)0%   (0/6)0%   (0/1)
apply (String): ProductItemPrice 0%   (0/1)0%   (0/6)0%   (0/1)
     
class SoftLayerComputeServiceContextModule100% (1/1)40%  (2/5)65%  (68/104)79%  (11/14)
getProductPackage (long, SoftLayerClient, String): Supplier 0%   (0/1)0%   (0/13)0%   (0/1)
prices (String): Iterable 0%   (0/1)0%   (0/13)0%   (0/1)
provideTemplate (Injector, TemplateBuilder): TemplateBuilder 0%   (0/1)0%   (0/10)0%   (0/1)
SoftLayerComputeServiceContextModule (): void 100% (1/1)100% (5/5)100% (2/2)
configure (): void 100% (1/1)100% (63/63)100% (9/9)
     
class SoftLayerComputeServiceContextModule$1100% (1/1)100% (1/1)100% (6/6)100% (1/1)
SoftLayerComputeServiceContextModule$1 (SoftLayerComputeServiceContextModule)... 100% (1/1)100% (6/6)100% (1/1)
     
class SoftLayerComputeServiceContextModule$2100% (1/1)100% (1/1)100% (6/6)100% (1/1)
SoftLayerComputeServiceContextModule$2 (SoftLayerComputeServiceContextModule)... 100% (1/1)100% (6/6)100% (1/1)
     
class SoftLayerComputeServiceContextModule$3100% (1/1)100% (1/1)100% (6/6)100% (1/1)
SoftLayerComputeServiceContextModule$3 (SoftLayerComputeServiceContextModule)... 100% (1/1)100% (6/6)100% (1/1)
     
class SoftLayerComputeServiceContextModule$4100% (1/1)100% (1/1)100% (6/6)100% (1/1)
SoftLayerComputeServiceContextModule$4 (SoftLayerComputeServiceContextModule)... 100% (1/1)100% (6/6)100% (1/1)
     
class SoftLayerComputeServiceContextModule$5100% (1/1)100% (1/1)100% (6/6)100% (1/1)
SoftLayerComputeServiceContextModule$5 (SoftLayerComputeServiceContextModule)... 100% (1/1)100% (6/6)100% (1/1)
     
class SoftLayerComputeServiceContextModule$6100% (1/1)100% (1/1)100% (6/6)100% (1/1)
SoftLayerComputeServiceContextModule$6 (SoftLayerComputeServiceContextModule)... 100% (1/1)100% (6/6)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.softlayer.compute.config;
20 
21import static com.google.common.base.Preconditions.checkNotNull;
22import static com.google.common.collect.Iterables.find;
23import static org.jclouds.Constants.PROPERTY_SESSION_INTERVAL;
24import static org.jclouds.softlayer.predicates.ProductPackagePredicates.named;
25import static org.jclouds.softlayer.reference.SoftLayerConstants.PROPERTY_SOFTLAYER_VIRTUALGUEST_PACKAGE_NAME;
26import static org.jclouds.softlayer.reference.SoftLayerConstants.PROPERTY_SOFTLAYER_VIRTUALGUEST_PRICES;
27 
28import javax.inject.Named;
29import javax.inject.Singleton;
30 
31import org.jclouds.collect.Memoized;
32import org.jclouds.compute.ComputeServiceAdapter;
33import org.jclouds.compute.config.ComputeServiceAdapterContextModule;
34import org.jclouds.compute.domain.NodeMetadata;
35import org.jclouds.compute.domain.OsFamily;
36import org.jclouds.compute.domain.TemplateBuilder;
37import org.jclouds.compute.options.TemplateOptions;
38import org.jclouds.domain.Location;
39import org.jclouds.location.suppliers.OnlyLocationOrFirstZone;
40import org.jclouds.rest.suppliers.MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier;
41import org.jclouds.softlayer.SoftLayerAsyncClient;
42import org.jclouds.softlayer.SoftLayerClient;
43import org.jclouds.softlayer.compute.functions.DatacenterToLocation;
44import org.jclouds.softlayer.compute.functions.ProductItemToImage;
45import org.jclouds.softlayer.compute.functions.ProductItemsToHardware;
46import org.jclouds.softlayer.compute.functions.VirtualGuestToNodeMetadata;
47import org.jclouds.softlayer.compute.options.SoftLayerTemplateOptions;
48import org.jclouds.softlayer.compute.strategy.SoftLayerComputeServiceAdapter;
49import org.jclouds.softlayer.domain.Datacenter;
50import org.jclouds.softlayer.domain.ProductItem;
51import org.jclouds.softlayer.domain.ProductItemPrice;
52import org.jclouds.softlayer.domain.ProductPackage;
53import org.jclouds.softlayer.domain.VirtualGuest;
54import org.jclouds.softlayer.features.AccountClient;
55import org.jclouds.softlayer.features.ProductPackageClient;
56 
57import com.google.common.base.Function;
58import com.google.common.base.Splitter;
59import com.google.common.base.Supplier;
60import com.google.common.collect.Iterables;
61import com.google.inject.Injector;
62import com.google.inject.Provides;
63import com.google.inject.TypeLiteral;
64 
65/**
66 * 
67 * @author Adrian Cole
68 */
69public class SoftLayerComputeServiceContextModule
70         extends
71         ComputeServiceAdapterContextModule<SoftLayerClient, SoftLayerAsyncClient, VirtualGuest, Iterable<ProductItem>, ProductItem, Datacenter> {
72 
73   public SoftLayerComputeServiceContextModule() {
74      super(SoftLayerClient.class, SoftLayerAsyncClient.class);
75   }
76 
77   @Override
78   protected void configure() {
79      super.configure();
80      bind(new TypeLiteral<ComputeServiceAdapter<VirtualGuest, Iterable<ProductItem>, ProductItem, Datacenter>>() {
81      }).to(SoftLayerComputeServiceAdapter.class);
82      bind(new TypeLiteral<Function<VirtualGuest, NodeMetadata>>() {
83      }).to(VirtualGuestToNodeMetadata.class);
84      bind(new TypeLiteral<Function<ProductItem, org.jclouds.compute.domain.Image>>() {
85      }).to(ProductItemToImage.class);
86      bind(new TypeLiteral<Function<Iterable<ProductItem>, org.jclouds.compute.domain.Hardware>>() {
87      }).to(ProductItemsToHardware.class);
88      bind(new TypeLiteral<Function<Datacenter, Location>>() {
89      }).to(DatacenterToLocation.class);
90      bind(new TypeLiteral<Supplier<Location>>() {
91      }).to(OnlyLocationOrFirstZone.class);
92      bind(TemplateOptions.class).to(SoftLayerTemplateOptions.class);
93   }
94 
95   protected TemplateBuilder provideTemplate(Injector injector, TemplateBuilder template) {
96      return template.osFamily(OsFamily.UBUNTU).osVersionMatches("1[10].[10][04]").os64Bit(true).osDescriptionMatches(
97               ".*Minimal Install.*");
98   }
99 
100   /**
101    * Many requests need the same productPackage, which is in this case the package for virtual
102    * guests. We may at some point need to make an annotation qualifying it as such. ex. @VirtualGuest
103    */
104   @Provides
105   @Singleton
106   @Memoized
107   public Supplier<ProductPackage> getProductPackage(@Named(PROPERTY_SESSION_INTERVAL) long seconds,
108            final SoftLayerClient client,
109            @Named(PROPERTY_SOFTLAYER_VIRTUALGUEST_PACKAGE_NAME) final String virtualGuestPackageName) {
110      return new MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier<ProductPackage>(authException, seconds,
111               new Supplier<ProductPackage>() {
112                  @Override
113                  public ProductPackage get() {
114                     AccountClient accountClient = client.getAccountClient();
115                     ProductPackageClient productPackageClient = client.getProductPackageClient();
116                     ProductPackage p = find(accountClient.getActivePackages(), named(virtualGuestPackageName));
117                     return productPackageClient.getProductPackage(p.getId());
118                  }
119               });
120   }
121 
122   // TODO: check the prices really do exist
123   @Provides
124   @Singleton
125   public Iterable<ProductItemPrice> prices(@Named(PROPERTY_SOFTLAYER_VIRTUALGUEST_PRICES) String prices) {
126      return Iterables.transform(Splitter.on(',').split(checkNotNull(prices, "prices")),
127               new Function<String, ProductItemPrice>() {
128                  @Override
129                  public ProductItemPrice apply(String arg0) {
130                     return ProductItemPrice.builder().id(Integer.parseInt(arg0)).build();
131                  }
132               });
133   }
134 
135}

[all classes][org.jclouds.softlayer.compute.config]
EMMA 2.0.5312 (C) Vladimir Roubtsov