EMMA Coverage Report (generated Mon Oct 17 05:41:20 EDT 2011)
[all classes][org.jclouds.trmk.ecloud.suppliers]

COVERAGE SUMMARY FOR SOURCE FILE [TerremarkECloudInternetServiceAndPublicIpAddressSupplier.java]

nameclass, %method, %block, %line, %
TerremarkECloudInternetServiceAndPublicIpAddressSupplier.java0%   (0/1)0%   (0/2)0%   (0/150)0%   (0/24)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class TerremarkECloudInternetServiceAndPublicIpAddressSupplier0%   (0/1)0%   (0/2)0%   (0/150)0%   (0/24)
TerremarkECloudInternetServiceAndPublicIpAddressSupplier (TerremarkECloudClie... 0%   (0/1)0%   (0/9)0%   (0/4)
getNewInternetServiceAndIp (VApp, int, Protocol): Map$Entry 0%   (0/1)0%   (0/141)0%   (0/20)

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.trmk.ecloud.suppliers;
20 
21import static org.jclouds.trmk.vcloud_0_8.options.AddInternetServiceOptions.Builder.withDescription;
22 
23import java.util.Map;
24import java.util.Set;
25import java.util.Map.Entry;
26 
27import javax.annotation.Resource;
28import javax.inject.Inject;
29import javax.inject.Named;
30import javax.inject.Singleton;
31 
32import org.jclouds.compute.reference.ComputeServiceConstants;
33import org.jclouds.logging.Logger;
34import org.jclouds.rest.InsufficientResourcesException;
35import org.jclouds.trmk.ecloud.TerremarkECloudClient;
36import org.jclouds.trmk.vcloud_0_8.domain.InternetService;
37import org.jclouds.trmk.vcloud_0_8.domain.Protocol;
38import org.jclouds.trmk.vcloud_0_8.domain.PublicIpAddress;
39import org.jclouds.trmk.vcloud_0_8.domain.VApp;
40import org.jclouds.trmk.vcloud_0_8.suppliers.InternetServiceAndPublicIpAddressSupplier;
41 
42import com.google.common.collect.ImmutableMap;
43import com.google.common.collect.Iterables;
44 
45/**
46 * @author Adrian Cole
47 */
48@Singleton
49public class TerremarkECloudInternetServiceAndPublicIpAddressSupplier implements
50         InternetServiceAndPublicIpAddressSupplier {
51 
52   @Resource
53   @Named(ComputeServiceConstants.COMPUTE_LOGGER)
54   public Logger logger = Logger.NULL;
55   protected final TerremarkECloudClient client;
56 
57   @Inject
58   public TerremarkECloudInternetServiceAndPublicIpAddressSupplier(TerremarkECloudClient client) {
59      this.client = client;
60   }
61 
62   @Override
63   public Entry<InternetService, PublicIpAddress> getNewInternetServiceAndIp(VApp vApp, int port, Protocol protocol) {
64      logger.debug(">> creating InternetService in vDC %s:%s:%d", vApp.getVDC().getHref(), protocol, port);
65      InternetService is = null;
66      PublicIpAddress ip = null;
67      try {
68         ip = client.activatePublicIpInVDC(vApp.getVDC().getHref());
69      } catch (InsufficientResourcesException e) {
70         logger.warn(">> no more ip addresses available, looking for one to re-use");
71         Set<PublicIpAddress> publicIps = client.getPublicIpsAssociatedWithVDC(vApp.getVDC().getHref());
72         for (PublicIpAddress existingIp : publicIps) {
73            Set<InternetService> services = client.getInternetServicesOnPublicIp(existingIp.getId());
74            if (services.size() == 0) {
75               ip = existingIp;
76               break;
77            }
78         }
79         if (ip == null)
80            throw new InsufficientResourcesException(
81                     "no more ip addresses available and existing ips all have services attached: " + publicIps, e
82                              .getCause());
83      }
84      is = client.addInternetServiceToExistingIp(ip.getId(), vApp.getName() + "-" + port, protocol, port,
85               withDescription(String.format("port %d access to serverId: %s name: %s", port, vApp.getName(), vApp
86                        .getName())));
87      Map<InternetService, PublicIpAddress> result = ImmutableMap.<InternetService, PublicIpAddress> of(is, ip);
88      Entry<InternetService, PublicIpAddress> entry = Iterables.getOnlyElement(result.entrySet());
89      return entry;
90   }
91}

[all classes][org.jclouds.trmk.ecloud.suppliers]
EMMA 2.0.5312 (C) Vladimir Roubtsov