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

COVERAGE SUMMARY FOR SOURCE FILE [AWSEC2ComputeService.java]

nameclass, %method, %block, %line, %
AWSEC2ComputeService.java0%   (0/1)0%   (0/4)0%   (0/168)0%   (0/24)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class AWSEC2ComputeService0%   (0/1)0%   (0/4)0%   (0/168)0%   (0/24)
AWSEC2ComputeService (ComputeServiceContext, Map, Supplier, Supplier, Supplie... 0%   (0/1)0%   (0/38)0%   (0/5)
cleanUpIncidentalResources (Map$Entry): void 0%   (0/1)0%   (0/12)0%   (0/3)
deletePlacementGroup (String, String): void 0%   (0/1)0%   (0/112)0%   (0/15)
templateOptions (): EC2TemplateOptions 0%   (0/1)0%   (0/6)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;
20 
21import static com.google.common.base.Preconditions.checkState;
22 
23import java.util.Map;
24import java.util.Map.Entry;
25import java.util.Set;
26import java.util.concurrent.ExecutorService;
27 
28import javax.inject.Inject;
29import javax.inject.Named;
30import javax.inject.Provider;
31import javax.inject.Singleton;
32 
33import org.jclouds.Constants;
34import org.jclouds.aws.ec2.AWSEC2Client;
35import org.jclouds.aws.ec2.domain.PlacementGroup;
36import org.jclouds.aws.ec2.domain.PlacementGroup.State;
37import org.jclouds.collect.Memoized;
38import org.jclouds.compute.ComputeServiceContext;
39import org.jclouds.compute.callables.RunScriptOnNode;
40import org.jclouds.compute.domain.Hardware;
41import org.jclouds.compute.domain.Image;
42import org.jclouds.compute.domain.NodeMetadata;
43import org.jclouds.compute.domain.TemplateBuilder;
44import org.jclouds.compute.internal.PersistNodeCredentials;
45import org.jclouds.compute.options.TemplateOptions;
46import org.jclouds.compute.reference.ComputeServiceConstants.Timeouts;
47import org.jclouds.compute.strategy.CreateNodesInGroupThenAddToSet;
48import org.jclouds.compute.strategy.DestroyNodeStrategy;
49import org.jclouds.compute.strategy.GetNodeMetadataStrategy;
50import org.jclouds.compute.strategy.InitializeRunScriptOnNodeOrPlaceInBadMap;
51import org.jclouds.compute.strategy.ListNodesStrategy;
52import org.jclouds.compute.strategy.RebootNodeStrategy;
53import org.jclouds.compute.strategy.ResumeNodeStrategy;
54import org.jclouds.compute.strategy.SuspendNodeStrategy;
55import org.jclouds.domain.Credentials;
56import org.jclouds.domain.Location;
57import org.jclouds.ec2.compute.EC2ComputeService;
58import org.jclouds.ec2.compute.domain.RegionAndName;
59import org.jclouds.ec2.compute.options.EC2TemplateOptions;
60import org.jclouds.ec2.domain.KeyPair;
61import org.jclouds.scriptbuilder.functions.InitAdminAccess;
62import org.jclouds.util.Preconditions2;
63 
64import com.google.common.annotations.VisibleForTesting;
65import com.google.common.base.Predicate;
66import com.google.common.base.Supplier;
67 
68/**
69 * @author Adrian Cole
70 */
71@Singleton
72public class AWSEC2ComputeService extends EC2ComputeService {
73 
74   private final Map<RegionAndName, String> placementGroupMap;
75   private final Predicate<PlacementGroup> placementGroupDeleted;
76   private final AWSEC2Client ec2Client;
77 
78   @Inject
79   protected AWSEC2ComputeService(ComputeServiceContext context, Map<String, Credentials> credentialStore,
80         @Memoized Supplier<Set<? extends Image>> images, @Memoized Supplier<Set<? extends Hardware>> sizes,
81         @Memoized Supplier<Set<? extends Location>> locations, ListNodesStrategy listNodesStrategy,
82         GetNodeMetadataStrategy getNodeMetadataStrategy, CreateNodesInGroupThenAddToSet runNodesAndAddToSetStrategy,
83         RebootNodeStrategy rebootNodeStrategy, DestroyNodeStrategy destroyNodeStrategy,
84         ResumeNodeStrategy startNodeStrategy, SuspendNodeStrategy stopNodeStrategy,
85         Provider<TemplateBuilder> templateBuilderProvider, Provider<TemplateOptions> templateOptionsProvider,
86         @Named("NODE_RUNNING") Predicate<NodeMetadata> nodeRunning,
87         @Named("NODE_TERMINATED") Predicate<NodeMetadata> nodeTerminated,
88         @Named("NODE_SUSPENDED") Predicate<NodeMetadata> nodeSuspended,
89         InitializeRunScriptOnNodeOrPlaceInBadMap.Factory initScriptRunnerFactory,
90         RunScriptOnNode.Factory runScriptOnNodeFactory, InitAdminAccess initAdminAccess,
91         PersistNodeCredentials persistNodeCredentials, Timeouts timeouts,
92         @Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor, AWSEC2Client ec2Client,
93         Map<RegionAndName, KeyPair> credentialsMap, @Named("SECURITY") Map<RegionAndName, String> securityGroupMap,
94         @Named("PLACEMENT") Map<RegionAndName, String> placementGroupMap,
95         @Named("DELETED") Predicate<PlacementGroup> placementGroupDeleted) {
96      super(context, credentialStore, images, sizes, locations, listNodesStrategy, getNodeMetadataStrategy,
97            runNodesAndAddToSetStrategy, rebootNodeStrategy, destroyNodeStrategy, startNodeStrategy, stopNodeStrategy,
98            templateBuilderProvider, templateOptionsProvider, nodeRunning, nodeTerminated, nodeSuspended,
99            initScriptRunnerFactory, runScriptOnNodeFactory, initAdminAccess, persistNodeCredentials, timeouts,
100            executor, ec2Client, credentialsMap, securityGroupMap);
101      this.ec2Client = ec2Client;
102      this.placementGroupMap = placementGroupMap;
103      this.placementGroupDeleted = placementGroupDeleted;
104   }
105 
106   @VisibleForTesting
107   void deletePlacementGroup(String region, String group) {
108      Preconditions2.checkNotEmpty(group, "group");
109      // placementGroupName must be unique within an account per
110      // http://docs.amazonwebservices.com/AWSEC2/latest/UserGuide/index.html?using_cluster_computing.html
111      String placementGroup = String.format("jclouds#%s#%s", group, region);
112      try {
113         if (ec2Client.getPlacementGroupServices().describePlacementGroupsInRegion(region, placementGroup).size() > 0) {
114            logger.debug(">> deleting placementGroup(%s)", placementGroup);
115            try {
116               ec2Client.getPlacementGroupServices().deletePlacementGroupInRegion(region, placementGroup);
117               checkState(
118                     placementGroupDeleted.apply(new PlacementGroup(region, placementGroup, "cluster", State.PENDING)),
119                     String.format("placementGroup region(%s) name(%s) failed to delete", region, placementGroup));
120               placementGroupMap.remove(new RegionAndName(region, placementGroup));
121               logger.debug("<< deleted placementGroup(%s)", placementGroup);
122            } catch (IllegalStateException e) {
123               logger.debug("<< inUse placementGroup(%s)", placementGroup);
124            }
125         }
126      } catch (UnsupportedOperationException e) {
127         logger.trace("<< placementGroups unsupported in region %s", region);
128      }
129   }
130 
131   @Override
132   protected void cleanUpIncidentalResources(Entry<String, String> regionTag) {
133      super.cleanUpIncidentalResources(regionTag);
134      deletePlacementGroup(regionTag.getKey(), regionTag.getValue());
135   }
136 
137   /**
138    * returns template options, except of type {@link EC2TemplateOptions}.
139    */
140   @Override
141   public EC2TemplateOptions templateOptions() {
142      return EC2TemplateOptions.class.cast(super.templateOptions());
143   }
144 
145}

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