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

COVERAGE SUMMARY FOR SOURCE FILE [GoGridLifeCycleStrategy.java]

nameclass, %method, %block, %line, %
GoGridLifeCycleStrategy.java0%   (0/1)0%   (0/5)0%   (0/131)0%   (0/18)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class GoGridLifeCycleStrategy0%   (0/1)0%   (0/5)0%   (0/131)0%   (0/18)
GoGridLifeCycleStrategy (GoGridClient, GetNodeMetadataStrategy, ComputeServic... 0%   (0/1)0%   (0/41)0%   (0/6)
executeCommandOnServer (PowerCommand, String): boolean 0%   (0/1)0%   (0/30)0%   (0/3)
rebootNode (String): NodeMetadata 0%   (0/1)0%   (0/40)0%   (0/5)
resumeNode (String): NodeMetadata 0%   (0/1)0%   (0/10)0%   (0/2)
suspendNode (String): NodeMetadata 0%   (0/1)0%   (0/10)0%   (0/2)

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.strategy;
20 
21import javax.inject.Inject;
22import javax.inject.Singleton;
23 
24import org.jclouds.compute.domain.NodeMetadata;
25import org.jclouds.compute.reference.ComputeServiceConstants.Timeouts;
26import org.jclouds.compute.strategy.GetNodeMetadataStrategy;
27import org.jclouds.compute.strategy.RebootNodeStrategy;
28import org.jclouds.compute.strategy.ResumeNodeStrategy;
29import org.jclouds.compute.strategy.SuspendNodeStrategy;
30import org.jclouds.gogrid.GoGridClient;
31import org.jclouds.gogrid.domain.PowerCommand;
32import org.jclouds.gogrid.domain.Server;
33import org.jclouds.gogrid.predicates.ServerLatestJobCompleted;
34import org.jclouds.predicates.RetryablePredicate;
35 
36import com.google.common.collect.Iterables;
37 
38/**
39 * 
40 * @author Adrian Cole
41 */
42@Singleton
43public class GoGridLifeCycleStrategy implements RebootNodeStrategy, ResumeNodeStrategy, SuspendNodeStrategy {
44   private final GoGridClient client;
45   private final RetryablePredicate<Server> serverLatestJobCompleted;
46   private final RetryablePredicate<Server> serverLatestJobCompletedShort;
47   private final GetNodeMetadataStrategy getNode;
48 
49   @Inject
50   protected GoGridLifeCycleStrategy(GoGridClient client, GetNodeMetadataStrategy getNode, Timeouts timeouts) {
51      this.client = client;
52      this.serverLatestJobCompleted = new RetryablePredicate<Server>(new ServerLatestJobCompleted(client
53               .getJobServices()), timeouts.nodeRunning * 9l / 10l);
54      this.serverLatestJobCompletedShort = new RetryablePredicate<Server>(new ServerLatestJobCompleted(client
55               .getJobServices()), timeouts.nodeRunning * 1l / 10l);
56      this.getNode = getNode;
57   }
58 
59   @Override
60   public NodeMetadata rebootNode(String id) {
61      executeCommandOnServer(PowerCommand.RESTART, id);
62      Server server = Iterables.getOnlyElement(client.getServerServices().getServersById(new Long(id)));
63      client.getServerServices().power(server.getName(), PowerCommand.START);
64      serverLatestJobCompletedShort.apply(server);
65      return getNode.getNode(id);
66   }
67 
68   @Override
69   public NodeMetadata resumeNode(String id) {
70      executeCommandOnServer(PowerCommand.START, id);
71      return getNode.getNode(id);
72 
73   }
74 
75   @Override
76   public NodeMetadata suspendNode(String id) {
77      executeCommandOnServer(PowerCommand.STOP, id);
78      return getNode.getNode(id);
79 
80   }
81 
82   private boolean executeCommandOnServer(PowerCommand command, String id) {
83      Server server = Iterables.getOnlyElement(client.getServerServices().getServersById(new Long(id)));
84      client.getServerServices().power(server.getName(), command);
85      return serverLatestJobCompleted.apply(server);
86   }
87}

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