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

COVERAGE SUMMARY FOR SOURCE FILE [VMToNodeMetadata.java]

nameclass, %method, %block, %line, %
VMToNodeMetadata.java0%   (0/2)0%   (0/5)0%   (0/129)0%   (0/22)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class VMToNodeMetadata0%   (0/1)0%   (0/3)0%   (0/114)0%   (0/19)
<static initializer> 0%   (0/1)0%   (0/25)0%   (0/1)
VMToNodeMetadata (Map, VMToNodeMetadata$FindLocationForVM): void 0%   (0/1)0%   (0/15)0%   (0/4)
apply (VM): NodeMetadata 0%   (0/1)0%   (0/74)0%   (0/14)
     
class VMToNodeMetadata$FindLocationForVM0%   (0/1)0%   (0/2)0%   (0/15)0%   (0/3)
VMToNodeMetadata$FindLocationForVM (Supplier): void 0%   (0/1)0%   (0/4)0%   (0/2)
matches (VM, Location): boolean 0%   (0/1)0%   (0/11)0%   (0/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.savvis.vpdc.compute.functions;
20 
21import static com.google.common.base.Preconditions.checkNotNull;
22import static com.google.common.base.Predicates.not;
23import static com.google.common.collect.Iterables.filter;
24import static org.jclouds.compute.util.ComputeServiceUtils.parseGroupFromName;
25 
26import java.util.Map;
27import java.util.Set;
28 
29import javax.inject.Inject;
30import javax.inject.Singleton;
31 
32import org.jclouds.collect.FindResourceInSet;
33import org.jclouds.collect.Memoized;
34import org.jclouds.compute.domain.CIMOperatingSystem;
35import org.jclouds.compute.domain.NodeMetadata;
36import org.jclouds.compute.domain.NodeMetadataBuilder;
37import org.jclouds.compute.domain.NodeState;
38import org.jclouds.domain.Credentials;
39import org.jclouds.domain.Location;
40import org.jclouds.savvis.vpdc.domain.VM;
41import org.jclouds.savvis.vpdc.util.Utils;
42import org.jclouds.util.InetAddresses2.IsPrivateIPAddress;
43 
44import com.google.common.base.Function;
45import com.google.common.base.Supplier;
46import com.google.common.collect.ImmutableMap;
47import com.google.common.collect.Iterables;
48 
49/**
50 * @author Adrian Cole
51 */
52@Singleton
53public class VMToNodeMetadata implements Function<VM, NodeMetadata> {
54 
55   public static final Map<VM.Status, NodeState> VAPPSTATUS_TO_NODESTATE = ImmutableMap
56            .<VM.Status, NodeState> builder().put(VM.Status.OFF, NodeState.SUSPENDED).put(VM.Status.ON,
57                     NodeState.RUNNING).put(VM.Status.RESOLVED, NodeState.PENDING).put(VM.Status.UNRECOGNIZED,
58                     NodeState.UNRECOGNIZED).put(VM.Status.UNKNOWN, NodeState.UNRECOGNIZED).put(VM.Status.SUSPENDED,
59                     NodeState.SUSPENDED).put(VM.Status.UNRESOLVED, NodeState.PENDING).build();
60 
61   private final FindLocationForVM findLocationForVM;
62   private final Map<String, Credentials> credentialStore;
63 
64   @Inject
65   VMToNodeMetadata(Map<String, Credentials> credentialStore, FindLocationForVM findLocationForVM) {
66      this.credentialStore = checkNotNull(credentialStore, "credentialStore");
67      this.findLocationForVM = checkNotNull(findLocationForVM, "findLocationForVM");
68   }
69 
70   @Override
71   public NodeMetadata apply(VM from) {
72      NodeMetadataBuilder builder = new NodeMetadataBuilder();
73      builder.ids(from.getHref().toASCIIString());
74      builder.name(from.getName());
75      builder.location(findLocationForVM.apply(from));
76      builder.group(parseGroupFromName(from.getName()));
77      try {
78         builder.operatingSystem(CIMOperatingSystem.toComputeOs(from.getOperatingSystemSection()));
79      } catch (NullPointerException e) {
80         // os section was null
81      }
82      // TODO build from resource allocation section
83      // builder.hardware(findHardwareForVM.apply(from));
84      builder.state(VAPPSTATUS_TO_NODESTATE.get(from.getStatus()));
85      Set<String> addresses = Utils.getIpsFromVM(from);
86      builder.publicAddresses(filter(addresses, not(IsPrivateIPAddress.INSTANCE)));
87      builder.privateAddresses(filter(addresses, IsPrivateIPAddress.INSTANCE));
88      builder.credentials(credentialStore.get(from.getHref().toASCIIString()));
89      return builder.build();
90   }
91 
92   @Singleton
93   public static class FindLocationForVM extends FindResourceInSet<VM, Location> {
94 
95      @Inject
96      public FindLocationForVM(@Memoized Supplier<Set<? extends Location>> hardware) {
97         super(hardware);
98      }
99 
100      @Override
101      public boolean matches(VM from, Location input) {
102         return input.getId().equals(Iterables.get(from.getNetworkSection().getNetworks(), 0).getName());
103      }
104   }
105}

[all classes][org.jclouds.savvis.vpdc.compute.functions]
EMMA 2.0.5312 (C) Vladimir Roubtsov