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

COVERAGE SUMMARY FOR SOURCE FILE [GoGridComputeServiceDependenciesModule.java]

nameclass, %method, %block, %line, %
GoGridComputeServiceDependenciesModule.java86%  (6/7)67%  (8/12)62%  (112/181)48%  (10/21)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class GoGridComputeServiceDependenciesModule$60%   (0/1)0%   (0/2)0%   (0/62)0%   (0/10)
GoGridComputeServiceDependenciesModule$6 (GoGridComputeServiceDependenciesMod... 0%   (0/1)0%   (0/6)0%   (0/1)
apply (Hardware): String 0%   (0/1)0%   (0/56)0%   (0/9)
     
class GoGridComputeServiceDependenciesModule100% (1/1)60%  (3/5)92%  (82/89)80%  (8/10)
provideServerToNodeState (): Map 0%   (0/1)0%   (0/2)0%   (0/1)
provideSizeToRam (): Function 0%   (0/1)0%   (0/5)0%   (0/1)
<static initializer> 100% (1/1)100% (31/31)100% (1/1)
GoGridComputeServiceDependenciesModule (): void 100% (1/1)100% (3/3)100% (1/1)
configure (): void 100% (1/1)100% (48/48)100% (6/6)
     
class GoGridComputeServiceDependenciesModule$1100% (1/1)100% (1/1)100% (6/6)100% (1/1)
GoGridComputeServiceDependenciesModule$1 (GoGridComputeServiceDependenciesMod... 100% (1/1)100% (6/6)100% (1/1)
     
class GoGridComputeServiceDependenciesModule$2100% (1/1)100% (1/1)100% (6/6)100% (1/1)
GoGridComputeServiceDependenciesModule$2 (GoGridComputeServiceDependenciesMod... 100% (1/1)100% (6/6)100% (1/1)
     
class GoGridComputeServiceDependenciesModule$3100% (1/1)100% (1/1)100% (6/6)100% (1/1)
GoGridComputeServiceDependenciesModule$3 (GoGridComputeServiceDependenciesMod... 100% (1/1)100% (6/6)100% (1/1)
     
class GoGridComputeServiceDependenciesModule$4100% (1/1)100% (1/1)100% (6/6)100% (1/1)
GoGridComputeServiceDependenciesModule$4 (GoGridComputeServiceDependenciesMod... 100% (1/1)100% (6/6)100% (1/1)
     
class GoGridComputeServiceDependenciesModule$5100% (1/1)100% (1/1)100% (6/6)100% (1/1)
GoGridComputeServiceDependenciesModule$5 (GoGridComputeServiceDependenciesMod... 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.gogrid.compute.config;
20 
21import static org.jclouds.compute.util.ComputeServiceUtils.*;
22 
23import java.util.Map;
24 
25import javax.inject.Singleton;
26 
27import org.jclouds.compute.ComputeService;
28import org.jclouds.compute.ComputeServiceContext;
29import org.jclouds.compute.domain.Hardware;
30import org.jclouds.compute.domain.NodeMetadata;
31import org.jclouds.compute.domain.NodeState;
32import org.jclouds.compute.internal.ComputeServiceContextImpl;
33import org.jclouds.compute.options.TemplateOptions;
34import org.jclouds.gogrid.GoGridAsyncClient;
35import org.jclouds.gogrid.GoGridClient;
36import org.jclouds.gogrid.compute.GoGridComputeService;
37import org.jclouds.gogrid.compute.functions.ServerToNodeMetadata;
38import org.jclouds.gogrid.compute.options.GoGridTemplateOptions;
39import org.jclouds.gogrid.domain.Server;
40import org.jclouds.gogrid.domain.ServerState;
41import org.jclouds.rest.RestContext;
42import org.jclouds.rest.internal.RestContextImpl;
43 
44import com.google.common.annotations.VisibleForTesting;
45import com.google.common.base.Function;
46import com.google.common.collect.ImmutableMap;
47import com.google.inject.AbstractModule;
48import com.google.inject.Provides;
49import com.google.inject.Scopes;
50import com.google.inject.TypeLiteral;
51 
52/**
53 * @author Oleksiy Yarmula
54 * @author Adrian Cole
55 * @author Andrew Kennedy
56 */
57public class GoGridComputeServiceDependenciesModule extends AbstractModule {
58   protected void configure() {
59      bind(TemplateOptions.class).to(GoGridTemplateOptions.class);
60      bind(ComputeService.class).to(GoGridComputeService.class);
61      bind(new TypeLiteral<Function<Server, NodeMetadata>>() {
62      }).to(ServerToNodeMetadata.class);
63      bind(new TypeLiteral<ComputeServiceContext>() {
64      }).to(new TypeLiteral<ComputeServiceContextImpl<GoGridClient, GoGridAsyncClient>>() {
65      }).in(Scopes.SINGLETON);
66      bind(new TypeLiteral<RestContext<GoGridClient, GoGridAsyncClient>>() {
67      }).to(new TypeLiteral<RestContextImpl<GoGridClient, GoGridAsyncClient>>() {
68      }).in(Scopes.SINGLETON);
69   }
70 
71   @VisibleForTesting
72   static final Map<ServerState, NodeState> serverStateToNodeState = ImmutableMap.<ServerState, NodeState> builder()
73            .put(ServerState.ON, NodeState.RUNNING)//
74            .put(ServerState.STARTING, NodeState.PENDING)//
75            .put(ServerState.OFF, NodeState.SUSPENDED)//
76            .put(ServerState.STOPPING, NodeState.PENDING)//
77            .put(ServerState.RESTARTING, NodeState.PENDING)//
78            .put(ServerState.SAVING, NodeState.PENDING)//
79            .put(ServerState.UNRECOGNIZED, NodeState.UNRECOGNIZED)//
80            .put(ServerState.RESTORING, NodeState.PENDING)//
81            .put(ServerState.UPDATING, NodeState.PENDING).build();
82 
83   @Singleton
84   @Provides
85   Map<ServerState, NodeState> provideServerToNodeState() {
86      return serverStateToNodeState;
87   }
88 
89   /**
90    * Finds matches to required configurations. GoGrid's documentation only specifies how much RAM
91    * one can get with different instance types. The # of cores and disk sizes are purely empyrical
92    * and aren't guaranteed. However, these are the matches found: Ram: 512MB, CPU: 1 core, HDD: 28
93    * GB Ram: 1GB, CPU: 1 core, HDD: 57 GB Ram: 2GB, CPU: 1 core, HDD: 113 GB Ram: 4GB, CPU: 3
94    * cores, HDD: 233 GB Ram: 8GB, CPU: 6 cores, HDD: 462 GB (as of March 2010)
95    * 
96    * @return matched size
97    */
98   @Singleton
99   @Provides
100   Function<Hardware, String> provideSizeToRam() {
101      return new Function<Hardware, String>() {
102         @Override
103         public String apply(Hardware hardware) {
104            if (hardware.getRam() >= 8 * 1024 || getCores(hardware) >= 6 || getSpace(hardware) >= 450)
105               return "8GB";
106            if (hardware.getRam() >= 4 * 1024 || getCores(hardware) >= 3 || getSpace(hardware) >= 230)
107               return "4GB";
108            if (hardware.getRam() >= 2 * 1024 || getSpace(hardware) >= 110)
109               return "2GB";
110            if (hardware.getRam() >= 1024 || getSpace(hardware) >= 55)
111               return "1GB";
112            return "512MB"; /* smallest */
113         }
114      };
115   }
116}

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