EMMA Coverage Report (generated Wed Jun 22 19:47:49 EDT 2011)
[all classes][org.jclouds.gogrid.predicates]

COVERAGE SUMMARY FOR SOURCE FILE [ServerLatestJobCompleted.java]

nameclass, %method, %block, %line, %
ServerLatestJobCompleted.java100% (1/1)100% (2/2)100% (42/42)100% (9/9)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class ServerLatestJobCompleted100% (1/1)100% (2/2)100% (42/42)100% (9/9)
ServerLatestJobCompleted (GridJobClient): void 100% (1/1)100% (9/9)100% (4/4)
apply (Server): boolean 100% (1/1)100% (33/33)100% (5/5)

1/**
2 *
3 * Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
4 *
5 * ====================================================================
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * 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, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 * ====================================================================
18 */
19package org.jclouds.gogrid.predicates;
20 
21import com.google.common.base.Predicate;
22import com.google.common.collect.Iterables;
23import com.google.inject.Inject;
24import org.jclouds.gogrid.domain.Job;
25import org.jclouds.gogrid.domain.JobState;
26import org.jclouds.gogrid.domain.Server;
27import org.jclouds.gogrid.options.GetJobListOptions;
28import org.jclouds.gogrid.services.GridJobClient;
29import org.jclouds.logging.Logger;
30 
31import javax.annotation.Resource;
32import javax.inject.Singleton;
33 
34import static com.google.common.base.Preconditions.checkNotNull;
35 
36/**
37 * Checks if the latest job for the server is in "Succeeded" state.
38 * To achieve meaningful results, this must be run in a sequential
39 * environment when a server has only one job related to it at a time.
40 *
41 * The passed server instance must not be null and must have a name.
42 *
43 * @author Oleksiy Yarmula
44 */
45@Singleton
46public class ServerLatestJobCompleted implements Predicate<Server> {
47 
48    protected GridJobClient jobClient;
49 
50    @Resource
51    protected Logger logger = Logger.NULL;
52 
53    @Inject
54    public ServerLatestJobCompleted(GridJobClient jobClient) {
55        this.jobClient = jobClient;
56    }
57 
58    @Override
59    public boolean apply(Server server) {
60        checkNotNull(server, "Server must be a valid instance");
61        checkNotNull(server.getName(), "Server must be a valid name");
62        GetJobListOptions jobOptions = new GetJobListOptions.Builder().
63                latestJobForObjectByName(server.getName());
64        Job latestJob = Iterables.getOnlyElement(jobClient.getJobList(jobOptions));
65        return JobState.SUCCEEDED.equals(latestJob.getCurrentState());
66    }
67}

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