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

COVERAGE SUMMARY FOR SOURCE FILE [RimuHostingImageSupplier.java]

nameclass, %method, %block, %line, %
RimuHostingImageSupplier.java0%   (0/1)0%   (0/4)0%   (0/155)0%   (0/32)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class RimuHostingImageSupplier0%   (0/1)0%   (0/4)0%   (0/155)0%   (0/32)
<static initializer> 0%   (0/1)0%   (0/4)0%   (0/1)
RimuHostingImageSupplier (RimuHostingClient): void 0%   (0/1)0%   (0/9)0%   (0/4)
get (): Set 0%   (0/1)0%   (0/80)0%   (0/13)
parseOs (Image): OperatingSystem 0%   (0/1)0%   (0/62)0%   (0/14)

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.rimuhosting.miro.compute.suppliers;
20 
21import java.util.Set;
22import java.util.regex.Matcher;
23import java.util.regex.Pattern;
24 
25import javax.annotation.Resource;
26import javax.inject.Inject;
27import javax.inject.Named;
28import javax.inject.Singleton;
29 
30import org.jclouds.compute.domain.Image;
31import org.jclouds.compute.domain.ImageBuilder;
32import org.jclouds.compute.domain.OperatingSystem;
33import org.jclouds.compute.domain.OsFamily;
34import org.jclouds.compute.reference.ComputeServiceConstants;
35import org.jclouds.domain.Credentials;
36import org.jclouds.logging.Logger;
37import org.jclouds.rimuhosting.miro.RimuHostingClient;
38 
39import com.google.common.base.Supplier;
40import com.google.common.collect.Sets;
41 
42/**
43 * 
44 * @author Adrian Cole
45 */
46@Singleton
47public class RimuHostingImageSupplier implements Supplier<Set<? extends Image>> {
48   public static final Pattern RIMU_PATTERN = Pattern.compile("([a-zA-Z]+) ?([0-9.]+) .*");
49   private final RimuHostingClient sync;
50 
51   @Inject
52   RimuHostingImageSupplier(RimuHostingClient sync) {
53      this.sync = sync;
54   }
55 
56   @Resource
57   @Named(ComputeServiceConstants.COMPUTE_LOGGER)
58   protected Logger logger = Logger.NULL;
59 
60   @Override
61   public Set<? extends Image> get() {
62      final Set<Image> images = Sets.newHashSet();
63      logger.debug(">> providing images");
64      for (org.jclouds.rimuhosting.miro.domain.Image from : sync.getImageList()) {
65         ImageBuilder builder = new ImageBuilder();
66         builder.ids(from.getId() + "");
67         builder.name(from.getDescription());
68         builder.description(from.getDescription());
69         builder.operatingSystem(parseOs(from));
70         builder.defaultCredentials(new Credentials("root", null));
71         images.add(builder.build());
72      }
73      logger.debug("<< images(%d)", images.size());
74      return images;
75   }
76 
77   protected OperatingSystem parseOs(final org.jclouds.rimuhosting.miro.domain.Image from) {
78      OsFamily osFamily = null;
79      String osName = from.getId();
80      String osArch = null;
81      String osVersion = null;
82      String osDescription = from.getDescription();
83      boolean is64Bit = from.getId().indexOf("64") != -1;
84 
85      Matcher matcher = RIMU_PATTERN.matcher(osDescription);
86      if (matcher.find()) {
87         try {
88            osFamily = OsFamily.fromValue(matcher.group(1).toLowerCase());
89            osVersion = matcher.group(2).toLowerCase();
90         } catch (IllegalArgumentException e) {
91            logger.debug("<< didn't match os(%s)", osDescription);
92         }
93      }
94      return new OperatingSystem(osFamily, osName, osVersion, osArch, osDescription, is64Bit);
95   }
96}

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