EMMA Coverage Report (generated Mon Oct 17 05:41:20 EDT 2011)
[all classes][org.jclouds.aws.ec2.functions]

COVERAGE SUMMARY FOR SOURCE FILE [CreatePlacementGroupIfNeeded.java]

nameclass, %method, %block, %line, %
CreatePlacementGroupIfNeeded.java100% (1/1)0%   (0/3)0%   (0/104)0%   (0/19)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class CreatePlacementGroupIfNeeded100% (1/1)0%   (0/3)0%   (0/104)0%   (0/19)
CreatePlacementGroupIfNeeded (AWSEC2Client, Predicate): void 0%   (0/1)0%   (0/12)0%   (0/5)
createPlacementGroupInRegion (String, String): void 0%   (0/1)0%   (0/83)0%   (0/12)
load (RegionAndName): String 0%   (0/1)0%   (0/9)0%   (0/2)

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.aws.ec2.functions;
20 
21import static com.google.common.base.Preconditions.checkNotNull;
22import static com.google.common.base.Preconditions.checkState;
23 
24import javax.annotation.Resource;
25import javax.inject.Inject;
26import javax.inject.Named;
27import javax.inject.Singleton;
28 
29import org.jclouds.aws.AWSResponseException;
30import org.jclouds.aws.ec2.AWSEC2Client;
31import org.jclouds.aws.ec2.domain.PlacementGroup;
32import org.jclouds.aws.ec2.domain.PlacementGroup.State;
33import org.jclouds.compute.reference.ComputeServiceConstants;
34import org.jclouds.ec2.compute.domain.RegionAndName;
35import org.jclouds.logging.Logger;
36 
37import com.google.common.base.Predicate;
38import com.google.common.cache.CacheLoader;
39 
40/**
41 * 
42 * @author Adrian Cole
43 */
44@Singleton
45public class CreatePlacementGroupIfNeeded extends CacheLoader<RegionAndName, String> {
46   @Resource
47   @Named(ComputeServiceConstants.COMPUTE_LOGGER)
48   protected Logger logger = Logger.NULL;
49   protected final AWSEC2Client ec2Client;
50   protected final Predicate<PlacementGroup> placementGroupAvailable;
51 
52   @Inject
53   public CreatePlacementGroupIfNeeded(AWSEC2Client ec2Client,
54            @Named("AVAILABLE") Predicate<PlacementGroup> placementGroupAvailable) {
55      this.ec2Client = ec2Client;
56      this.placementGroupAvailable = placementGroupAvailable;
57   }
58 
59   @Override
60   public String load(RegionAndName from) {
61      createPlacementGroupInRegion(from.getRegion(), from.getName());
62      return from.getName();
63   }
64 
65   private void createPlacementGroupInRegion(String region, String name) {
66      checkNotNull(region, "region");
67      checkNotNull(name, "name");
68      logger.debug(">> creating placementGroup region(%s) name(%s)", region, name);
69      try {
70         ec2Client.getPlacementGroupServices().createPlacementGroupInRegion(region, name);
71         logger.debug("<< created placementGroup(%s)", name);
72         checkState(placementGroupAvailable.apply(new PlacementGroup(region, name, "cluster", State.PENDING)), String
73                  .format("placementGroup region(%s) name(%s) failed to become available", region, name));
74      } catch (AWSResponseException e) {
75         if (e.getError().getCode().equals("InvalidPlacementGroup.Duplicate")) {
76            logger.debug("<< reused placementGroup(%s)", name);
77         } else {
78            throw e;
79         }
80      }
81   }
82 
83}

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