EMMA Coverage Report (generated Wed Jun 22 19:47:49 EDT 2011)
[all classes][org.jclouds.aws.ec2.compute.strategy]

COVERAGE SUMMARY FOR SOURCE FILE [AWSEC2CreateNodesInGroupThenAddToSet.java]

nameclass, %method, %block, %line, %
AWSEC2CreateNodesInGroupThenAddToSet.java0%   (0/1)0%   (0/3)0%   (0/122)0%   (0/14)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class AWSEC2CreateNodesInGroupThenAddToSet0%   (0/1)0%   (0/3)0%   (0/122)0%   (0/14)
AWSEC2CreateNodesInGroupThenAddToSet (AWSEC2Client, Provider, CreateKeyPairPl... 0%   (0/1)0%   (0/26)0%   (0/5)
createNodesInRegionAndZone (String, String, int, Template, RunInstancesOption... 0%   (0/1)0%   (0/85)0%   (0/8)
getSpotPriceOrNull (TemplateOptions): Float 0%   (0/1)0%   (0/11)0%   (0/1)

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.aws.ec2.compute.strategy;
20 
21import static com.google.common.base.Preconditions.checkNotNull;
22 
23import java.util.Map;
24 
25import javax.annotation.Resource;
26import javax.inject.Inject;
27import javax.inject.Named;
28import javax.inject.Provider;
29import javax.inject.Singleton;
30 
31import org.jclouds.aws.ec2.AWSEC2Client;
32import org.jclouds.aws.ec2.compute.AWSEC2TemplateOptions;
33import org.jclouds.aws.ec2.compute.predicates.AWSEC2InstancePresent;
34import org.jclouds.aws.ec2.domain.LaunchSpecification;
35import org.jclouds.aws.ec2.functions.SpotInstanceRequestToAWSRunningInstance;
36import org.jclouds.aws.ec2.options.AWSRunInstancesOptions;
37import org.jclouds.aws.ec2.options.RequestSpotInstancesOptions;
38import org.jclouds.compute.domain.NodeMetadata;
39import org.jclouds.compute.domain.Template;
40import org.jclouds.compute.domain.TemplateBuilder;
41import org.jclouds.compute.options.TemplateOptions;
42import org.jclouds.compute.reference.ComputeServiceConstants;
43import org.jclouds.compute.util.ComputeUtils;
44import org.jclouds.domain.Credentials;
45import org.jclouds.ec2.compute.strategy.EC2CreateNodesInGroupThenAddToSet;
46import org.jclouds.ec2.domain.RunningInstance;
47import org.jclouds.ec2.options.RunInstancesOptions;
48import org.jclouds.logging.Logger;
49 
50import com.google.common.annotations.VisibleForTesting;
51import com.google.common.base.Function;
52import com.google.common.collect.Iterables;
53 
54/**
55 * 
56 * @author Adrian Cole
57 */
58@Singleton
59public class AWSEC2CreateNodesInGroupThenAddToSet extends EC2CreateNodesInGroupThenAddToSet {
60 
61   @Resource
62   @Named(ComputeServiceConstants.COMPUTE_LOGGER)
63   protected Logger logger = Logger.NULL;
64 
65   @VisibleForTesting
66   final AWSEC2Client client;
67   final SpotInstanceRequestToAWSRunningInstance spotConverter;
68 
69   @Inject
70   protected AWSEC2CreateNodesInGroupThenAddToSet(
71            AWSEC2Client client,
72            Provider<TemplateBuilder> templateBuilderProvider,
73            CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptions createKeyPairAndSecurityGroupsAsNeededAndReturncustomize,
74            AWSEC2InstancePresent instancePresent,
75            Function<RunningInstance, NodeMetadata> runningInstanceToNodeMetadata,
76            Function<RunningInstance, Credentials> instanceToCredentials, Map<String, Credentials> credentialStore,
77            ComputeUtils utils, SpotInstanceRequestToAWSRunningInstance spotConverter) {
78 
79      super(client, templateBuilderProvider, createKeyPairAndSecurityGroupsAsNeededAndReturncustomize, instancePresent,
80               runningInstanceToNodeMetadata, instanceToCredentials, credentialStore, utils);
81      this.client = checkNotNull(client, "client");
82      this.spotConverter = checkNotNull(spotConverter, "spotConverter");
83   }
84 
85   protected Iterable<? extends RunningInstance> createNodesInRegionAndZone(String region, String zone, int count,
86            Template template, RunInstancesOptions instanceOptions) {
87      Float spotPrice = getSpotPriceOrNull(template.getOptions());
88      if (spotPrice != null) {
89         LaunchSpecification spec = AWSRunInstancesOptions.class.cast(instanceOptions).getLaunchSpecificationBuilder()
90                  .imageId(template.getImage().getProviderId()).availabilityZone(zone).build();
91         RequestSpotInstancesOptions options = AWSEC2TemplateOptions.class.cast(template.getOptions()).getSpotOptions();
92         if (logger.isDebugEnabled())
93            logger.debug(">> requesting %d spot instances region(%s) price(%f) spec(%s) options(%s)", count, region,
94                     spotPrice, spec, options);
95 
96         return Iterables.transform(client.getSpotInstanceServices().requestSpotInstancesInRegion(region, spotPrice,
97                  count, spec, options), spotConverter);
98      } else {
99         return super.createNodesInRegionAndZone(zone, zone, count, template, instanceOptions);
100      }
101 
102   }
103 
104   private Float getSpotPriceOrNull(TemplateOptions options) {
105      return options instanceof AWSEC2TemplateOptions ? AWSEC2TemplateOptions.class.cast(options).getSpotPrice() : null;
106   }
107 
108}

[all classes][org.jclouds.aws.ec2.compute.strategy]
EMMA 2.0.5312 (C) Vladimir Roubtsov