EMMA Coverage Report (generated Wed Oct 26 13:47:17 EDT 2011)
[all classes][org.jclouds.compute.strategy.impl]

COVERAGE SUMMARY FOR SOURCE FILE [AdaptingComputeServiceStrategies.java]

nameclass, %method, %block, %line, %
AdaptingComputeServiceStrategies.java100% (1/1)33%  (3/9)19%  (37/192)22%  (8/36)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class AdaptingComputeServiceStrategies100% (1/1)33%  (3/9)19%  (37/192)22%  (8/36)
createNodeWithGroupEncodedIntoName (String, String, Template): NodeMetadata 0%   (0/1)0%   (0/49)0%   (0/6)
destroyNode (String): NodeMetadata 0%   (0/1)0%   (0/17)0%   (0/5)
getNode (String): NodeMetadata 0%   (0/1)0%   (0/18)0%   (0/2)
rebootNode (String): NodeMetadata 0%   (0/1)0%   (0/21)0%   (0/5)
resumeNode (String): NodeMetadata 0%   (0/1)0%   (0/25)0%   (0/5)
suspendNode (String): NodeMetadata 0%   (0/1)0%   (0/25)0%   (0/5)
AdaptingComputeServiceStrategies (Map, ComputeServiceAdapter, Function): void 100% (1/1)100% (24/24)100% (6/6)
listDetailsOnNodesMatching (Predicate): Iterable 100% (1/1)100% (9/9)100% (1/1)
listNodes (): Iterable 100% (1/1)100% (4/4)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.compute.strategy.impl;
20 
21import static com.google.common.base.Preconditions.checkNotNull;
22import static com.google.common.base.Preconditions.checkState;
23 
24import java.util.Map;
25 
26import javax.annotation.Resource;
27import javax.inject.Inject;
28import javax.inject.Named;
29import javax.inject.Singleton;
30 
31import org.jclouds.compute.ComputeServiceAdapter;
32import org.jclouds.compute.domain.ComputeMetadata;
33import org.jclouds.compute.domain.NodeMetadata;
34import org.jclouds.compute.domain.NodeState;
35import org.jclouds.compute.domain.Template;
36import org.jclouds.compute.predicates.NodePredicates;
37import org.jclouds.compute.reference.ComputeServiceConstants;
38import org.jclouds.compute.strategy.CreateNodeWithGroupEncodedIntoName;
39import org.jclouds.compute.strategy.DestroyNodeStrategy;
40import org.jclouds.compute.strategy.GetNodeMetadataStrategy;
41import org.jclouds.compute.strategy.ListNodesStrategy;
42import org.jclouds.compute.strategy.RebootNodeStrategy;
43import org.jclouds.compute.strategy.ResumeNodeStrategy;
44import org.jclouds.compute.strategy.SuspendNodeStrategy;
45import org.jclouds.domain.Credentials;
46import org.jclouds.logging.Logger;
47 
48import com.google.common.base.Function;
49import com.google.common.base.Predicate;
50import com.google.common.collect.Iterables;
51 
52/**
53 * @author Adrian Cole
54 * 
55 */
56@Singleton
57public class AdaptingComputeServiceStrategies<N, H, I, L> implements CreateNodeWithGroupEncodedIntoName, DestroyNodeStrategy,
58         GetNodeMetadataStrategy, ListNodesStrategy, RebootNodeStrategy, ResumeNodeStrategy, SuspendNodeStrategy {
59   @Resource
60   @Named(ComputeServiceConstants.COMPUTE_LOGGER)
61   protected Logger logger = Logger.NULL;
62 
63   private final Map<String, Credentials> credentialStore;
64   private final ComputeServiceAdapter<N, H, I, L> client;
65   private final Function<N, NodeMetadata> nodeMetadataAdapter;
66 
67   @Inject
68   public AdaptingComputeServiceStrategies(Map<String, Credentials> credentialStore,
69            ComputeServiceAdapter<N, H, I, L> client, Function<N, NodeMetadata> nodeMetadataAdapter) {
70      this.credentialStore = checkNotNull(credentialStore, "credentialStore");
71      this.client = checkNotNull(client, "client");
72      this.nodeMetadataAdapter = checkNotNull(nodeMetadataAdapter, "nodeMetadataAdapter");
73   }
74 
75   @Override
76   public Iterable<? extends ComputeMetadata> listNodes() {
77      return listDetailsOnNodesMatching(NodePredicates.all());
78   }
79 
80   @Override
81   public Iterable<? extends NodeMetadata> listDetailsOnNodesMatching(Predicate<ComputeMetadata> filter) {
82      return Iterables.filter(Iterables.transform(client.listNodes(), nodeMetadataAdapter), filter);
83   }
84 
85   @Override
86   public NodeMetadata getNode(String id) {
87      N node = client.getNode(checkNotNull(id, "id"));
88      return node == null ? null : nodeMetadataAdapter.apply(node);
89   }
90 
91   @Override
92   public NodeMetadata rebootNode(String id) {
93      NodeMetadata node = getNode(checkNotNull(id, "id"));
94      if (node == null || node.getState() == NodeState.TERMINATED)
95         return node;
96      client.rebootNode(id);
97      return node;
98   }
99 
100   @Override
101   public NodeMetadata resumeNode(String id) {
102      NodeMetadata node = getNode(checkNotNull(id, "id"));
103      if (node == null || node.getState() == NodeState.TERMINATED || node.getState() == NodeState.RUNNING)
104         return node;
105      client.resumeNode(id);
106      return node;
107   }
108 
109   @Override
110   public NodeMetadata suspendNode(String id) {
111      NodeMetadata node = getNode(checkNotNull(id, "id"));
112      if (node == null || node.getState() == NodeState.TERMINATED || node.getState() == NodeState.SUSPENDED)
113         return node;
114      client.suspendNode(id);
115      return node;
116   }
117 
118   @Override
119   public NodeMetadata destroyNode(String id) {
120      NodeMetadata node = getNode(checkNotNull(id, "id"));
121      if (node == null)
122         return node;
123      client.destroyNode(id);
124      return node;
125   }
126 
127   /**
128    * {@inheritDoc}
129    */
130   @Override
131   public NodeMetadata createNodeWithGroupEncodedIntoName(String group, String name, Template template) {
132      checkState(group != null, "group (that which groups identical nodes together) must be specified");
133      checkState(name != null && name.indexOf(group) != -1, "name should have %s encoded into it", group);
134      checkState(template != null, "template must be specified");
135 
136      N from = client.createNodeWithGroupEncodedIntoNameThenStoreCredentials(group, name, template, credentialStore);
137      NodeMetadata node = nodeMetadataAdapter.apply(from);
138      return node;
139   }
140 
141}

[all classes][org.jclouds.compute.strategy.impl]
EMMA 2.0.5312 (C) Vladimir Roubtsov