EMMA Coverage Report (generated Wed Aug 10 12:30:04 EDT 2011)
[all classes][org.jclouds.aws.ec2]

COVERAGE SUMMARY FOR SOURCE FILE [AWSEC2PropertiesBuilder.java]

nameclass, %method, %block, %line, %
AWSEC2PropertiesBuilder.java100% (1/1)83%  (5/6)98%  (172/175)94%  (33/35)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class AWSEC2PropertiesBuilder100% (1/1)83%  (5/6)98%  (172/175)94%  (33/35)
AWSEC2PropertiesBuilder (): void 0%   (0/1)0%   (0/3)0%   (0/2)
AWSEC2PropertiesBuilder (Properties): void 100% (1/1)100% (4/4)100% (2/2)
build (): Properties 100% (1/1)100% (11/11)100% (4/4)
defaultProperties (): Properties 100% (1/1)100% (47/47)100% (11/11)
warnAndReplaceIfUsingOldCCImageKey (Properties): void 100% (1/1)100% (46/46)100% (6/6)
warnAndReplaceIfUsingOldImageKey (Properties): void 100% (1/1)100% (64/64)100% (10/10)

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;
20 
21import static org.jclouds.Constants.PROPERTY_ENDPOINT;
22import static org.jclouds.aws.ec2.reference.AWSEC2Constants.PROPERTY_EC2_AMI_QUERY;
23import static org.jclouds.aws.ec2.reference.AWSEC2Constants.PROPERTY_EC2_CC_AMI_QUERY;
24import static org.jclouds.aws.ec2.reference.AWSEC2Constants.PROPERTY_EC2_CC_AMIs;
25import static org.jclouds.aws.ec2.reference.AWSEC2Constants.PROPERTY_EC2_CC_REGIONS;
26import static org.jclouds.compute.reference.ComputeServiceConstants.PROPERTY_TIMEOUT_NODE_SUSPENDED;
27import static org.jclouds.ec2.reference.EC2Constants.PROPERTY_EC2_AMI_OWNERS;
28 
29import java.util.Properties;
30import java.util.logging.Logger;
31 
32import org.jclouds.aws.domain.Region;
33 
34/**
35 * Builds properties used in EC2 Clients
36 * 
37 * @author Adrian Cole
38 */
39public class AWSEC2PropertiesBuilder extends org.jclouds.ec2.EC2PropertiesBuilder {
40   @Override
41   protected Properties defaultProperties() {
42      Properties properties = super.defaultProperties();
43      // sometimes, like in ec2, stop takes a very long time, perhaps
44      // due to volume management. one example spent 2 minutes moving
45      // from stopping->stopped state on an ec2 micro
46      properties.setProperty(PROPERTY_TIMEOUT_NODE_SUSPENDED, 120 * 1000 + "");
47      // auth fail sometimes happens in EC2, as the rc.local script that injects the
48      // authorized key executes after ssh has started
49      properties.setProperty("jclouds.ssh.max-retries", "7");
50      properties.setProperty("jclouds.ssh.retry-auth", "true");
51      properties.setProperty(PROPERTY_ENDPOINT, "https://ec2.us-east-1.amazonaws.com");
52      properties.putAll(Region.regionProperties());
53      properties.remove(PROPERTY_EC2_AMI_OWNERS);
54      // amazon, alestic, canonical, and rightscale
55      properties.setProperty(PROPERTY_EC2_AMI_QUERY,
56               "owner-id=137112412989,063491364108,099720109477,411009282317;state=available;image-type=machine");
57      // amis that work with the cluster instances
58      properties.setProperty(PROPERTY_EC2_CC_REGIONS, Region.US_EAST_1);
59      properties
60               .setProperty(
61                        PROPERTY_EC2_CC_AMI_QUERY,
62                        "virtualization-type=hvm;architecture=x86_64;owner-id=137112412989,099720109477;hypervisor=xen;state=available;image-type=machine;root-device-type=ebs");
63      return properties;
64   }
65 
66   public AWSEC2PropertiesBuilder() {
67      super();
68   }
69 
70   public AWSEC2PropertiesBuilder(Properties properties) {
71      super(properties);
72   }
73 
74   @Override
75   public Properties build() {
76      Properties props = super.build();
77      warnAndReplaceIfUsingOldImageKey(props);
78      warnAndReplaceIfUsingOldCCImageKey(props);
79      return props;
80   }
81 
82   protected void warnAndReplaceIfUsingOldImageKey(Properties props) {
83      if (props.containsKey(PROPERTY_EC2_AMI_OWNERS)) {
84         StringBuilder query = new StringBuilder();
85         String owners = properties.remove(PROPERTY_EC2_AMI_OWNERS).toString();
86         if (!"*".equals(owners) && !"".equals(owners))
87            query.append("owner-id=").append(owners).append(';');
88         if (!"".equals(owners))
89            query.append("state=available;image-type=machine");
90         props.setProperty(PROPERTY_EC2_AMI_QUERY, query.toString());
91         Logger.getAnonymousLogger().warning(
92                  String.format("Property %s is deprecated, please use new syntax: %s=%s", PROPERTY_EC2_AMI_OWNERS,
93                           PROPERTY_EC2_AMI_QUERY, query.toString()));
94      }
95   }
96 
97   protected void warnAndReplaceIfUsingOldCCImageKey(Properties props) {
98      if (props.containsKey(PROPERTY_EC2_CC_AMIs)) {
99         String amis = properties.remove(PROPERTY_EC2_CC_AMIs).toString();
100         String value = "image-id=" + amis.replace("us-east-1/", "");
101         props.setProperty(PROPERTY_EC2_CC_AMI_QUERY, value);
102         Logger.getAnonymousLogger().warning(
103                  String.format("Property %s is deprecated, please use new syntax: %s=%s", PROPERTY_EC2_CC_AMIs,
104                           PROPERTY_EC2_CC_AMI_QUERY, value));
105      }
106   }
107 
108}

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