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

COVERAGE SUMMARY FOR SOURCE FILE [VPDCRestClientModule.java]

nameclass, %method, %block, %line, %
VPDCRestClientModule.java67%  (2/3)57%  (8/14)63%  (114/182)62%  (15/24)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class VPDCRestClientModule$20%   (0/1)0%   (0/3)0%   (0/38)0%   (0/6)
<static initializer> 0%   (0/1)0%   (0/8)0%   (0/1)
VPDCRestClientModule$2 (VPDCRestClientModule, LoginAsyncClient): void 0%   (0/1)0%   (0/9)0%   (0/1)
get (): VCloudSession 0%   (0/1)0%   (0/21)0%   (0/5)
     
class VPDCRestClientModule100% (1/1)70%  (7/10)78%  (108/138)82%  (14/17)
provideVCloudToken (Supplier): String 0%   (0/1)0%   (0/8)0%   (0/1)
provideVCloudTokenCache (long, LoginAsyncClient): Supplier 0%   (0/1)0%   (0/12)0%   (0/1)
successTester (Injector, long): Predicate 0%   (0/1)0%   (0/9)0%   (0/1)
provideOrgs (Supplier, String): Set 100% (1/1)96%  (22/23)98%  (3/3)
<static initializer> 100% (1/1)100% (16/16)100% (1/1)
VPDCRestClientModule (): void 100% (1/1)100% (11/11)100% (3/3)
bindErrorHandlers (): void 100% (1/1)100% (25/25)100% (4/4)
provideDefaultOrgId (Set): String 100% (1/1)100% (6/6)100% (1/1)
provideOperatingSystems (Json, String): Set 100% (1/1)100% (23/23)100% (1/1)
provideVCloudVersions (AsyncClientFactory): LoginAsyncClient 100% (1/1)100% (5/5)100% (1/1)
     
class VPDCRestClientModule$1100% (1/1)100% (1/1)100% (6/6)100% (1/1)
VPDCRestClientModule$1 (VPDCRestClientModule): void 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.savvis.vpdc.config;
20 
21import static com.google.common.base.Preconditions.checkNotNull;
22import static com.google.common.base.Preconditions.checkState;
23import static com.google.common.base.Throwables.propagate;
24import static org.jclouds.Constants.PROPERTY_IDENTITY;
25import static org.jclouds.Constants.PROPERTY_SESSION_INTERVAL;
26import static org.jclouds.savvis.vpdc.reference.VPDCConstants.PROPERTY_VPDC_TIMEOUT_TASK_COMPLETED;
27 
28import java.io.IOException;
29import java.util.Map;
30import java.util.Set;
31import java.util.concurrent.TimeUnit;
32import java.util.concurrent.atomic.AtomicReference;
33 
34import javax.inject.Named;
35import javax.inject.Singleton;
36 
37import org.jclouds.compute.domain.CIMOperatingSystem;
38import org.jclouds.http.HttpErrorHandler;
39import org.jclouds.http.annotation.ClientError;
40import org.jclouds.http.annotation.Redirection;
41import org.jclouds.http.annotation.ServerError;
42import org.jclouds.json.Json;
43import org.jclouds.location.Provider;
44import org.jclouds.predicates.RetryablePredicate;
45import org.jclouds.rest.AsyncClientFactory;
46import org.jclouds.rest.AuthorizationException;
47import org.jclouds.rest.config.RestClientModule;
48import org.jclouds.rest.suppliers.MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier;
49import org.jclouds.savvis.vpdc.VPDCAsyncClient;
50import org.jclouds.savvis.vpdc.VPDCClient;
51import org.jclouds.savvis.vpdc.domain.Resource;
52import org.jclouds.savvis.vpdc.domain.internal.VCloudSession;
53import org.jclouds.savvis.vpdc.features.BrowsingAsyncClient;
54import org.jclouds.savvis.vpdc.features.BrowsingClient;
55import org.jclouds.savvis.vpdc.features.FirewallAsyncClient;
56import org.jclouds.savvis.vpdc.features.FirewallClient;
57import org.jclouds.savvis.vpdc.features.ServiceManagementAsyncClient;
58import org.jclouds.savvis.vpdc.features.ServiceManagementClient;
59import org.jclouds.savvis.vpdc.features.VMAsyncClient;
60import org.jclouds.savvis.vpdc.features.VMClient;
61import org.jclouds.savvis.vpdc.handlers.VPDCErrorHandler;
62import org.jclouds.savvis.vpdc.internal.LoginAsyncClient;
63import org.jclouds.savvis.vpdc.internal.VCloudToken;
64import org.jclouds.savvis.vpdc.predicates.TaskSuccess;
65import org.jclouds.util.Strings2;
66 
67import com.google.common.base.Predicate;
68import com.google.common.base.Supplier;
69import com.google.common.collect.ImmutableMap;
70import com.google.common.collect.Iterables;
71import com.google.inject.Injector;
72import com.google.inject.Provides;
73import com.google.inject.TypeLiteral;
74 
75/**
76 * 
77 * @author Adrian Cole
78 * 
79 */
80public class VPDCRestClientModule extends RestClientModule<VPDCClient, VPDCAsyncClient> {
81   @Provides
82   @Singleton
83   protected LoginAsyncClient provideVCloudVersions(AsyncClientFactory factory) {
84      return factory.create(LoginAsyncClient.class);
85   }
86 
87   @VCloudToken
88   @Provides
89   String provideVCloudToken(Supplier<VCloudSession> cache) {
90      return checkNotNull(cache.get().getVCloudToken(), "No token present in session");
91   }
92 
93   @Provides
94   @org.jclouds.savvis.vpdc.internal.Org
95   @Singleton
96   protected Set<org.jclouds.savvis.vpdc.domain.Resource> provideOrgs(Supplier<VCloudSession> cache,
97            @Named(PROPERTY_IDENTITY) String user) {
98      VCloudSession discovery = cache.get();
99      checkState(discovery.getOrgs().size() > 0, "No orgs present for user: " + user);
100      return discovery.getOrgs();
101   }
102 
103   @Provides
104   @org.jclouds.savvis.vpdc.internal.Org
105   @Singleton
106   protected String provideDefaultOrgId(@org.jclouds.savvis.vpdc.internal.Org Set<Resource> orgs) {
107      return Iterables.get(orgs, 0).getId();
108   }
109 
110   protected AtomicReference<AuthorizationException> authException = new AtomicReference<AuthorizationException>();
111 
112   @Provides
113   @Singleton
114   protected Predicate<String> successTester(Injector injector,
115            @Named(PROPERTY_VPDC_TIMEOUT_TASK_COMPLETED) long completed) {
116      return new RetryablePredicate<String>(injector.getInstance(TaskSuccess.class), completed);
117   }
118 
119   public static final Map<Class<?>, Class<?>> DELEGATE_MAP = ImmutableMap.<Class<?>, Class<?>> builder()//
120            .put(BrowsingClient.class, BrowsingAsyncClient.class)//
121            .put(VMClient.class, VMAsyncClient.class)//
122            .put(FirewallClient.class, FirewallAsyncClient.class)//
123            .put(ServiceManagementClient.class, ServiceManagementAsyncClient.class)//
124            .build();
125 
126   public VPDCRestClientModule() {
127      super(VPDCClient.class, VPDCAsyncClient.class, DELEGATE_MAP);
128   }
129 
130   @Singleton
131   @Provides
132   protected Set<CIMOperatingSystem> provideOperatingSystems(Json json, @Provider String providerName)
133            throws IOException {
134      return json.fromJson(Strings2.toStringAndClose(getClass().getResourceAsStream(
135               "/" + providerName + "/predefined_operatingsystems.json")), new TypeLiteral<Set<CIMOperatingSystem>>() {
136      }.getType());
137   }
138 
139   @Provides
140   @Singleton
141   protected Supplier<VCloudSession> provideVCloudTokenCache(@Named(PROPERTY_SESSION_INTERVAL) long seconds,
142            final LoginAsyncClient login) {
143      return new MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier<VCloudSession>(authException, seconds,
144               new Supplier<VCloudSession>() {
145 
146                  @Override
147                  public VCloudSession get() {
148                     try {
149                        return login.login().get(10, TimeUnit.SECONDS);
150                     } catch (Exception e) {
151                        propagate(e);
152                        assert false : e;
153                        return null;
154                     }
155                  }
156 
157               });
158   }
159 
160   @Override
161   protected void bindErrorHandlers() {
162      bind(HttpErrorHandler.class).annotatedWith(Redirection.class).to(VPDCErrorHandler.class);
163      bind(HttpErrorHandler.class).annotatedWith(ClientError.class).to(VPDCErrorHandler.class);
164      bind(HttpErrorHandler.class).annotatedWith(ServerError.class).to(VPDCErrorHandler.class);
165   }
166 
167}

[all classes][org.jclouds.savvis.vpdc.config]
EMMA 2.0.5312 (C) Vladimir Roubtsov