EMMA Coverage Report (generated Fri Apr 27 15:03:37 EDT 2012)
[all classes][org.jclouds.ec2.util]

COVERAGE SUMMARY FOR SOURCE FILE [IpPermissions.java]

nameclass, %method, %block, %line, %
IpPermissions.java100% (8/8)96%  (23/24)98%  (394/404)98%  (49.8/51)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class IpPermissions$PortSelection100% (1/1)67%  (2/3)74%  (23/31)75%  (3/4)
port (int): IpPermissions$ToSourceSelection 0%   (0/1)0%   (0/8)0%   (0/1)
IpPermissions$PortSelection (IpProtocol): void 100% (1/1)100% (16/16)100% (2/2)
fromPort (int): IpPermissions$ToPortSelection 100% (1/1)100% (7/7)100% (1/1)
     
class IpPermissions$ToPortSelection100% (1/1)100% (2/2)90%  (18/20)94%  (2.8/3)
IpPermissions$ToPortSelection (IpProtocol, int): void 100% (1/1)82%  (9/11)90%  (1.8/2)
to (int): IpPermissions$ToSourceSelection 100% (1/1)100% (9/9)100% (1/1)
     
class IpPermissions100% (1/1)100% (5/5)100% (229/229)100% (27/27)
IpPermissions (IpProtocol, int, int, Multimap, Iterable, Iterable): void 100% (1/1)100% (14/14)100% (2/2)
buildFormParametersForIndex (int, IpPermission): Multimap 100% (1/1)100% (196/196)100% (22/22)
permit (IpProtocol): IpPermissions$PortSelection 100% (1/1)100% (8/8)100% (1/1)
permitAnyProtocol (): IpPermissions$ToSourceSelection 100% (1/1)100% (7/7)100% (1/1)
permitICMP (): IpPermissions$ICMPTypeSelection 100% (1/1)100% (4/4)100% (1/1)
     
class IpPermissions$1100% (1/1)100% (2/2)100% (17/17)100% (2/2)
IpPermissions$1 (int): void 100% (1/1)100% (6/6)100% (1/1)
apply (String): String 100% (1/1)100% (11/11)100% (1/1)
     
class IpPermissions$AndCodeSelection100% (1/1)100% (2/2)100% (15/15)100% (3/3)
IpPermissions$AndCodeSelection (int): void 100% (1/1)100% (6/6)100% (2/2)
andCode (int): IpPermissions$ToSourceSelection 100% (1/1)100% (9/9)100% (1/1)
     
class IpPermissions$ICMPTypeSelection100% (1/1)100% (2/2)100% (11/11)100% (3/3)
IpPermissions$ICMPTypeSelection (): void 100% (1/1)100% (6/6)100% (2/2)
type (int): IpPermissions$AndCodeSelection 100% (1/1)100% (5/5)100% (1/1)
     
class IpPermissions$ToSourceSelection100% (1/1)100% (5/5)100% (50/50)100% (6/6)
IpPermissions$ToSourceSelection (IpProtocol, int, int): void 100% (1/1)100% (6/6)100% (2/2)
originatingFromCidrBlock (String): IpPermissions 100% (1/1)100% (7/7)100% (1/1)
originatingFromCidrBlocks (Iterable): IpPermissions 100% (1/1)100% (13/13)100% (1/1)
originatingFromUserAndSecurityGroup (String, String): IpPermissions 100% (1/1)100% (10/10)100% (1/1)
toEC2SecurityGroups (Multimap): IpPermissions 100% (1/1)100% (14/14)100% (1/1)
     
class IpPermissions$ToVPCSourceSelection100% (1/1)100% (3/3)100% (31/31)100% (4/4)
IpPermissions$ToVPCSourceSelection (IpProtocol, int, int): void 100% (1/1)100% (10/10)100% (2/2)
originatingFromSecurityGroupId (String): IpPermissions 100% (1/1)100% (7/7)100% (1/1)
toVPCSecurityGroups (Iterable): IpPermissions 100% (1/1)100% (14/14)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.ec2.util;
20 
21import static com.google.common.base.Preconditions.checkNotNull;
22 
23import java.util.Map;
24import java.util.Map.Entry;
25 
26import org.jclouds.ec2.domain.IpPermission;
27import org.jclouds.ec2.domain.IpPermissionImpl;
28import org.jclouds.ec2.domain.IpProtocol;
29import org.jclouds.util.Maps2;
30 
31import com.google.common.annotations.Beta;
32import com.google.common.base.Function;
33import com.google.common.collect.ImmutableMultimap;
34import com.google.common.collect.ImmutableSet;
35import com.google.common.collect.Maps;
36import com.google.common.collect.Multimap;
37import com.google.common.collect.Multimaps;
38 
39/**
40 * 
41 * Shortcut to create ingress rules
42 * 
43 * @author Adrian Cole
44 */
45public class IpPermissions extends IpPermissionImpl {
46 
47   protected IpPermissions(IpProtocol ipProtocol, int fromPort, int toPort,
48         Multimap<String, String> userIdGroupPairs, Iterable<String> groupIds, Iterable<String> ipRanges) {
49      super(ipProtocol, fromPort, toPort, userIdGroupPairs, groupIds, userIdGroupPairs.size() == 0 ? ipRanges
50            : ImmutableSet.<String> of());
51   }
52 
53   /**
54    * don't rely on this being here.. it will move
55    */
56   @Beta
57   public static Multimap<String, String> buildFormParametersForIndex(final int index, IpPermission permission) {
58      Map<String, String> headers = Maps.newLinkedHashMap();
59      headers.put("IpPermissions.%d.IpProtocol", permission.getIpProtocol().toString());
60      headers.put("IpPermissions.%d.FromPort", permission.getFromPort() + "");
61      headers.put("IpPermissions.%d.ToPort", permission.getToPort() + "");
62      String prefix = "IpPermissions.%d.IpRanges.";
63      int i = 0;
64      for (String cidrIp : checkNotNull(permission.getIpRanges(), "cidrIps")) {
65         headers.put(prefix + i++ + ".CidrIp", cidrIp);
66      }
67      prefix = "IpPermissions.%d.Groups.";
68      i = 0;
69      for (String groupId : checkNotNull(permission.getGroupIds(), "groupIds")) {
70         headers.put(prefix + i++ + ".GroupId", groupId);
71      }
72      prefix = "IpPermissions.%d.Groups.";
73      i = 0;
74      for (Entry<String, String> userIdGroupNamePair : checkNotNull(permission.getUserIdGroupPairs(),
75            "userIdGroupNamePairs").entries()) {
76         headers.put(prefix + i++ + ".UserId", userIdGroupNamePair.getKey());
77         headers.put(prefix + i + ".GroupName", userIdGroupNamePair.getValue());
78      }
79      prefix = "IpPermissions.%d.IpRanges.";
80      i = 0;
81      for (String cidrIp : checkNotNull(permission.getIpRanges(), "cidrIps")) {
82         headers.put(prefix + i++ + ".CidrIp", cidrIp);
83      }
84      return Multimaps.forMap(Maps2.transformKeys(headers, new Function<String, String>() {
85 
86         @Override
87         public String apply(String arg0) {
88            return String.format(arg0, index);
89         }
90 
91      }));
92   }
93 
94   public static ICMPTypeSelection permitICMP() {
95      return new ICMPTypeSelection();
96   }
97 
98   public static ToSourceSelection permitAnyProtocol() {
99      return new ToSourceSelection(IpProtocol.ALL, 1, 65535);
100   }
101 
102   public static PortSelection permit(IpProtocol protocol) {
103      return new PortSelection(checkNotNull(protocol, "protocol"));
104   }
105 
106   public static class ICMPTypeSelection extends ToSourceSelection {
107 
108      ICMPTypeSelection() {
109         super(IpProtocol.ICMP, -1, -1);
110      }
111 
112      /**
113       * @param type ex. 8 for ECHO (i.e. Ping)
114       * @see <a href="http://www.iana.org/assignments/icmp-parameters/icmp-parameters.xml"> ICMP Types</a>
115       */
116      public AndCodeSelection type(int type) {
117         return new AndCodeSelection(type);
118      }
119   }
120 
121   public static class AndCodeSelection extends ToSourceSelection {
122      AndCodeSelection(int type) {
123         super(IpProtocol.ICMP, type, -1);
124      }
125 
126      public ToSourceSelection andCode(int code) {
127         return new ToSourceSelection(getIpProtocol(), getFromPort(), code);
128      }
129 
130   }
131 
132   public static class PortSelection extends ToSourceSelection {
133 
134      PortSelection(IpProtocol ipProtocol) {
135         super(ipProtocol, ipProtocol == IpProtocol.ICMP ? -1 : 1, ipProtocol == IpProtocol.ICMP ? -1 : 65535);
136      }
137 
138      public ToPortSelection fromPort(int port) {
139         return new ToPortSelection(getIpProtocol(), port);
140      }
141      
142      public ToSourceSelection port(int port) {
143         return new ToSourceSelection(getIpProtocol(), port, port);
144      }
145   }
146 
147   public static class ToPortSelection extends ToSourceSelection {
148 
149      ToPortSelection(IpProtocol ipProtocol, int fromPort) {
150         super(ipProtocol, fromPort, ipProtocol == IpProtocol.ICMP ? -1 : 65535);
151      }
152 
153      public ToSourceSelection to(int port) {
154         return new ToSourceSelection(getIpProtocol(), getFromPort(), port);
155      }
156   }
157 
158   public static class ToVPCSourceSelection extends IpPermissions {
159 
160      protected ToVPCSourceSelection(IpProtocol ipProtocol, int fromPort, int toPort) {
161         super(ipProtocol, fromPort, toPort, ImmutableMultimap.<String, String> of(), ImmutableSet.<String> of(),
162               ImmutableSet.of("0.0.0.0/0"));
163      }
164 
165      public IpPermissions originatingFromSecurityGroupId(String groupId) {
166         return toVPCSecurityGroups(ImmutableSet.of(checkNotNull(groupId, "groupId")));
167      }
168 
169      public IpPermissions toVPCSecurityGroups(Iterable<String> groupIds) {
170         return new IpPermissions(getIpProtocol(), getFromPort(), getToPort(), getUserIdGroupPairs(), groupIds,
171               ImmutableSet.<String> of());
172      }
173   }
174 
175   public static class ToSourceSelection extends ToVPCSourceSelection {
176      ToSourceSelection(IpProtocol ipProtocol, int fromPort, int toPort) {
177         super(ipProtocol, fromPort, toPort);
178      }
179 
180      public IpPermissions originatingFromCidrBlock(String cidrIp) {
181         return originatingFromCidrBlocks(ImmutableSet.of(checkNotNull(cidrIp, "cidrIp")));
182      }
183 
184      public IpPermissions originatingFromCidrBlocks(Iterable<String> cidrIps) {
185         return new IpPermissions(getIpProtocol(), getFromPort(), getToPort(),
186               ImmutableMultimap.<String, String> of(), ImmutableSet.<String> of(), cidrIps);
187      }
188 
189      public IpPermissions originatingFromUserAndSecurityGroup(String userId, String groupName) {
190         return toEC2SecurityGroups(ImmutableMultimap.of(checkNotNull(userId, "userId"),
191               checkNotNull(groupName, "groupName")));
192      }
193 
194      public IpPermissions toEC2SecurityGroups(Multimap<String, String> userIdGroupNamePairs) {
195         return new IpPermissions(getIpProtocol(), getFromPort(), getToPort(), userIdGroupNamePairs, getGroupIds(),
196               ImmutableSet.<String> of());
197      }
198   }
199}

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