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

COVERAGE SUMMARY FOR SOURCE FILE [GoGridImageSupplier.java]

nameclass, %method, %block, %line, %
GoGridImageSupplier.java0%   (0/1)0%   (0/4)0%   (0/198)0%   (0/40)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class GoGridImageSupplier0%   (0/1)0%   (0/4)0%   (0/198)0%   (0/40)
<static initializer> 0%   (0/1)0%   (0/7)0%   (0/2)
GoGridImageSupplier (GoGridClient, PopulateDefaultLoginCredentialsForImageStr... 0%   (0/1)0%   (0/15)0%   (0/6)
get (): Set 0%   (0/1)0%   (0/84)0%   (0/14)
parseOs (ServerImage): OperatingSystem 0%   (0/1)0%   (0/92)0%   (0/18)

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.gogrid.compute.suppliers;
20 
21import java.util.Map;
22import java.util.Set;
23import java.util.regex.Matcher;
24import java.util.regex.Pattern;
25 
26import javax.annotation.Resource;
27import javax.inject.Inject;
28import javax.inject.Named;
29import javax.inject.Singleton;
30 
31import org.jclouds.compute.domain.Image;
32import org.jclouds.compute.domain.ImageBuilder;
33import org.jclouds.compute.domain.OperatingSystem;
34import org.jclouds.compute.domain.OsFamily;
35import org.jclouds.compute.reference.ComputeServiceConstants;
36import org.jclouds.compute.strategy.PopulateDefaultLoginCredentialsForImageStrategy;
37import org.jclouds.compute.util.ComputeServiceUtils;
38import org.jclouds.gogrid.GoGridClient;
39import org.jclouds.gogrid.domain.ServerImage;
40import org.jclouds.logging.Logger;
41 
42import com.google.common.base.Supplier;
43import com.google.common.collect.Sets;
44 
45/**
46 * 
47 * @author Adrian Cole
48 */
49@Singleton
50public class GoGridImageSupplier implements Supplier<Set<? extends Image>> {
51   public static final Pattern GOGRID_OS_PATTERN = Pattern.compile("([a-zA-Z]*).*");
52   public static final Pattern GOGRID_VERSION_PATTERN = Pattern.compile(".* ([0-9.]+) .*");
53 
54   @Resource
55   @Named(ComputeServiceConstants.COMPUTE_LOGGER)
56   protected Logger logger = Logger.NULL;
57 
58   private final GoGridClient sync;
59   private final PopulateDefaultLoginCredentialsForImageStrategy authenticator;
60   private final Map<OsFamily, Map<String, String>> osVersionMap;
61 
62   @Inject
63   GoGridImageSupplier(GoGridClient sync, PopulateDefaultLoginCredentialsForImageStrategy authenticator,
64         Map<OsFamily, Map<String, String>> osVersionMap) {
65      this.osVersionMap = osVersionMap;
66      this.sync = sync;
67      this.authenticator = authenticator;
68   }
69 
70   @Override
71   public Set<? extends Image> get() {
72      final Set<Image> images = Sets.newHashSet();
73      logger.debug(">> providing images");
74      Set<ServerImage> allImages = sync.getImageServices().getImageList();
75      for (ServerImage from : allImages) {
76         ImageBuilder builder = new ImageBuilder();
77         builder.ids(from.getId() + "");
78         builder.name(from.getFriendlyName());
79         builder.description(from.getDescription());
80         builder.defaultCredentials(authenticator.execute(from));
81         builder.operatingSystem(parseOs(from));
82         images.add(builder.build());
83      }
84      logger.debug("<< images(%d)", images.size());
85      return images;
86   }
87 
88   protected OperatingSystem parseOs(ServerImage from) {
89      OsFamily osFamily = null;
90      String osName = from.getOs().getName();
91      String osArch = from.getArchitecture().getDescription();
92      String osVersion = null;
93      String osDescription = from.getOs().getDescription();
94      boolean is64Bit = (from.getOs().getName().indexOf("64") != -1 || from.getDescription().indexOf("64") != -1);
95 
96      if (osName.startsWith("Windows")) {
97         osFamily = OsFamily.WINDOWS;
98      } else {
99         Matcher matcher = GOGRID_OS_PATTERN.matcher(from.getName());
100         if (matcher.find()) {
101            try {
102               osFamily = OsFamily.fromValue(matcher.group(1).toLowerCase());
103            } catch (IllegalArgumentException e) {
104               logger.debug("<< didn't match os(%s)", from.getName());
105            }
106         }
107      }
108      Matcher matcher = GOGRID_VERSION_PATTERN.matcher(osName);
109      if (matcher.find()) {
110         osVersion = ComputeServiceUtils.parseVersionOrReturnEmptyString(osFamily, matcher.group(1), osVersionMap);
111      }
112      // TODO determine DC images are in
113      return new OperatingSystem(osFamily, osName, osVersion, osArch, osDescription, is64Bit);
114   }
115 
116}

[all classes][org.jclouds.gogrid.compute.suppliers]
EMMA 2.0.5312 (C) Vladimir Roubtsov