mirror of https://github.com/apache/jclouds.git
Merge branch 'master' of github.com:jclouds/jclouds
This commit is contained in:
commit
362d79d879
|
@ -133,7 +133,7 @@ public class AMIClientLiveTest {
|
|||
}
|
||||
|
||||
public void testDescribeImagesCC() {
|
||||
Set<? extends Image> twoResults = client.describeImagesInRegion(Region.US_EAST_1, filters(
|
||||
Set<? extends Image> ccResults = client.describeImagesInRegion(Region.US_EAST_1, filters(
|
||||
ImmutableMultimap.<String, String> builder()//
|
||||
.put("virtualization-type", "hvm")//
|
||||
.put("architecture", "x86_64")//
|
||||
|
@ -143,8 +143,8 @@ public class AMIClientLiveTest {
|
|||
.put("image-type", "machine")//
|
||||
.put("root-device-type", "ebs")//
|
||||
.build()).ownedBy("137112412989", "099720109477"));
|
||||
assertNotNull(twoResults);
|
||||
assertEquals(twoResults.size(), 35);
|
||||
assertNotNull(ccResults);
|
||||
assert (ccResults.size() >= 34) : ccResults;
|
||||
}
|
||||
|
||||
@Test(enabled = false)
|
||||
|
|
|
@ -25,70 +25,74 @@ import com.google.common.primitives.Longs;
|
|||
*/
|
||||
public class BillingToken implements Comparable<BillingToken> {
|
||||
|
||||
private long id;
|
||||
private String name;
|
||||
private double price;
|
||||
private long id;
|
||||
private String name;
|
||||
private double price;
|
||||
|
||||
/**
|
||||
* A no-args constructor is required for deserialization
|
||||
*/
|
||||
public BillingToken() {
|
||||
}
|
||||
/**
|
||||
* A no-args constructor is required for deserialization
|
||||
*/
|
||||
public BillingToken() {
|
||||
}
|
||||
|
||||
public BillingToken(long id, String name, double price) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.price = price;
|
||||
}
|
||||
public BillingToken(long id, String name, double price) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.price = price;
|
||||
}
|
||||
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public double getPrice() {
|
||||
return price;
|
||||
}
|
||||
public double getPrice() {
|
||||
return price;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
BillingToken other = (BillingToken) obj;
|
||||
if (id != other.id)
|
||||
return false;
|
||||
if (name == null) {
|
||||
if (other.name != null)
|
||||
return false;
|
||||
} else if (!name.equals(other.name))
|
||||
return false;
|
||||
if (Double.doubleToLongBits(price) != Double.doubleToLongBits(other.price))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
BillingToken that = (BillingToken) o;
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + (int) (id ^ (id >>> 32));
|
||||
result = prime * result + ((name == null) ? 0 : name.hashCode());
|
||||
long temp;
|
||||
temp = Double.doubleToLongBits(price);
|
||||
result = prime * result + (int) (temp ^ (temp >>> 32));
|
||||
return result;
|
||||
}
|
||||
|
||||
if (id != that.id) return false;
|
||||
if (Double.compare(that.price, price) != 0) return false;
|
||||
if (!name.equals(that.name)) return false;
|
||||
@Override
|
||||
public int compareTo(BillingToken o) {
|
||||
return Longs.compare(id, o.getId());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result;
|
||||
long temp;
|
||||
result = (int) (id ^ (id >>> 32));
|
||||
result = 31 * result + name.hashCode();
|
||||
temp = price != +0.0d ? Double.doubleToLongBits(price) : 0L;
|
||||
result = 31 * result + (int) (temp ^ (temp >>> 32));
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(BillingToken o) {
|
||||
return Longs.compare(id, o.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "BillingToken{" +
|
||||
"id=" + id +
|
||||
", name='" + name + '\'' +
|
||||
", price=" + price +
|
||||
'}';
|
||||
}
|
||||
@Override
|
||||
public String toString() {
|
||||
return "BillingToken{" + "id=" + id + ", name='" + name + '\'' + ", price=" + price + '}';
|
||||
}
|
||||
}
|
||||
|
|
|
@ -36,29 +36,25 @@ import org.jclouds.http.options.BaseHttpRequestOptions;
|
|||
public class GetImageListOptions extends BaseHttpRequestOptions {
|
||||
|
||||
public GetImageListOptions setType(ServerImageType imageType) {
|
||||
checkState(!queryParameters.containsKey(IMAGE_TYPE_KEY),
|
||||
"Can't have duplicate image type restrictions");
|
||||
checkState(!queryParameters.containsKey(IMAGE_TYPE_KEY), "Can't have duplicate image type restrictions");
|
||||
queryParameters.put(IMAGE_TYPE_KEY, imageType.toString());
|
||||
return this;
|
||||
}
|
||||
|
||||
public GetImageListOptions setState(ServerImageState imageState) {
|
||||
checkState(!queryParameters.containsKey(IMAGE_STATE_KEY),
|
||||
"Can't have duplicate image state restrictions");
|
||||
checkState(!queryParameters.containsKey(IMAGE_STATE_KEY), "Can't have duplicate image state restrictions");
|
||||
queryParameters.put(IMAGE_STATE_KEY, imageState.toString());
|
||||
return this;
|
||||
}
|
||||
|
||||
public GetImageListOptions onlyPublic() {
|
||||
checkState(!queryParameters.containsKey(IS_PUBLIC_KEY),
|
||||
"Can't have duplicate image visibility restrictions");
|
||||
checkState(!queryParameters.containsKey(IS_PUBLIC_KEY), "Can't have duplicate image visibility restrictions");
|
||||
queryParameters.put(IS_PUBLIC_KEY, "true");
|
||||
return this;
|
||||
}
|
||||
|
||||
public GetImageListOptions onlyPrivate() {
|
||||
checkState(!queryParameters.containsKey(IS_PUBLIC_KEY),
|
||||
"Can't have duplicate image visibility restrictions");
|
||||
checkState(!queryParameters.containsKey(IS_PUBLIC_KEY), "Can't have duplicate image visibility restrictions");
|
||||
queryParameters.put(IS_PUBLIC_KEY, "false");
|
||||
return this;
|
||||
}
|
||||
|
@ -70,26 +66,28 @@ public class GetImageListOptions extends BaseHttpRequestOptions {
|
|||
}
|
||||
|
||||
public GetImageListOptions maxItemsNumber(Integer maxNumber) {
|
||||
checkState(!queryParameters.containsKey(MAX_NUMBER_KEY),
|
||||
"Can't have duplicate parameter of max returned items");
|
||||
checkState(!queryParameters.containsKey(MAX_NUMBER_KEY), "Can't have duplicate parameter of max returned items");
|
||||
queryParameters.put(MAX_NUMBER_KEY, maxNumber.toString());
|
||||
return this;
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
public GetImageListOptions inDatacenter(String datacenterId) {
|
||||
GetImageListOptions getImageListOptions = new GetImageListOptions();
|
||||
return getImageListOptions.inDatacenter(checkNotNull(datacenterId));
|
||||
public static GetImageListOptions maxItems(int maxNumber) {
|
||||
return new GetImageListOptions().maxItemsNumber(maxNumber);
|
||||
}
|
||||
|
||||
public GetImageListOptions publicWebServers() {
|
||||
public static GetImageListOptions inDatacenter(String datacenterId) {
|
||||
return new GetImageListOptions().inDatacenter(checkNotNull(datacenterId, "datacenterId"));
|
||||
}
|
||||
|
||||
public static GetImageListOptions publicWebServers() {
|
||||
return new GetImageListOptions().setState(ServerImageState.AVAILABLE).setType(
|
||||
ServerImageType.WEB_APPLICATION_SERVER).onlyPublic();
|
||||
}
|
||||
|
||||
public GetImageListOptions publicDatabaseServers() {
|
||||
return new GetImageListOptions().setState(ServerImageState.AVAILABLE).setType(
|
||||
ServerImageType.DATABASE_SERVER).onlyPublic();
|
||||
public static GetImageListOptions publicDatabaseServers() {
|
||||
return new GetImageListOptions().setState(ServerImageState.AVAILABLE).setType(ServerImageType.DATABASE_SERVER)
|
||||
.onlyPublic();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -18,87 +18,102 @@
|
|||
*/
|
||||
package org.jclouds.gogrid.options;
|
||||
|
||||
import org.jclouds.gogrid.domain.JobState;
|
||||
import org.jclouds.gogrid.domain.ObjectType;
|
||||
import org.jclouds.http.options.BaseHttpRequestOptions;
|
||||
import static com.google.common.base.Preconditions.checkState;
|
||||
import static org.jclouds.gogrid.reference.GoGridQueryParams.END_DATE_KEY;
|
||||
import static org.jclouds.gogrid.reference.GoGridQueryParams.JOB_OBJECT_TYPE_KEY;
|
||||
import static org.jclouds.gogrid.reference.GoGridQueryParams.JOB_STATE_KEY;
|
||||
import static org.jclouds.gogrid.reference.GoGridQueryParams.MAX_NUMBER_KEY;
|
||||
import static org.jclouds.gogrid.reference.GoGridQueryParams.OBJECT_KEY;
|
||||
import static org.jclouds.gogrid.reference.GoGridQueryParams.OWNER_KEY;
|
||||
import static org.jclouds.gogrid.reference.GoGridQueryParams.START_DATE_KEY;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkState;
|
||||
import static org.jclouds.gogrid.reference.GoGridQueryParams.*;
|
||||
import org.jclouds.gogrid.domain.JobState;
|
||||
import org.jclouds.gogrid.domain.ObjectType;
|
||||
import org.jclouds.http.options.BaseHttpRequestOptions;
|
||||
|
||||
/**
|
||||
* @author Oleksiy Yarmula
|
||||
*/
|
||||
public class GetJobListOptions extends BaseHttpRequestOptions {
|
||||
|
||||
public static final GetJobListOptions NONE = new GetJobListOptions();
|
||||
public static final GetJobListOptions NONE = new GetJobListOptions();
|
||||
|
||||
public GetJobListOptions maxItemsNumber(Integer maxNumber) {
|
||||
checkState(!queryParameters.containsKey(MAX_NUMBER_KEY), "Can't have duplicate parameter of max returned items");
|
||||
queryParameters.put(MAX_NUMBER_KEY, maxNumber.toString());
|
||||
return this;
|
||||
}
|
||||
public GetJobListOptions maxItemsNumber(Integer maxNumber) {
|
||||
checkState(!queryParameters.containsKey(MAX_NUMBER_KEY), "Can't have duplicate parameter of max returned items");
|
||||
queryParameters.put(MAX_NUMBER_KEY, maxNumber.toString());
|
||||
return this;
|
||||
}
|
||||
|
||||
public GetJobListOptions withStartDate(Date startDate) {
|
||||
checkState(!queryParameters.containsKey(START_DATE_KEY), "Can't have duplicate start date for filtering");
|
||||
queryParameters.put(START_DATE_KEY, String.valueOf(startDate.getTime()));
|
||||
return this;
|
||||
}
|
||||
public GetJobListOptions withStartDate(Date startDate) {
|
||||
checkState(!queryParameters.containsKey(START_DATE_KEY), "Can't have duplicate start date for filtering");
|
||||
queryParameters.put(START_DATE_KEY, String.valueOf(startDate.getTime()));
|
||||
return this;
|
||||
}
|
||||
|
||||
public GetJobListOptions withEndDate(Date endDate) {
|
||||
checkState(!queryParameters.containsKey(END_DATE_KEY), "Can't have duplicate end date for filtering");
|
||||
queryParameters.put(END_DATE_KEY, String.valueOf(endDate.getTime()));
|
||||
return this;
|
||||
}
|
||||
public GetJobListOptions withEndDate(Date endDate) {
|
||||
checkState(!queryParameters.containsKey(END_DATE_KEY), "Can't have duplicate end date for filtering");
|
||||
queryParameters.put(END_DATE_KEY, String.valueOf(endDate.getTime()));
|
||||
return this;
|
||||
}
|
||||
|
||||
public GetJobListOptions withOwner(String owner) {
|
||||
checkState(!queryParameters.containsKey(OWNER_KEY), "Can't have duplicate owner name for filtering");
|
||||
queryParameters.put(OWNER_KEY, owner);
|
||||
return this;
|
||||
}
|
||||
public GetJobListOptions withOwner(String owner) {
|
||||
checkState(!queryParameters.containsKey(OWNER_KEY), "Can't have duplicate owner name for filtering");
|
||||
queryParameters.put(OWNER_KEY, owner);
|
||||
return this;
|
||||
}
|
||||
|
||||
public GetJobListOptions onlyForState(JobState jobState) {
|
||||
checkState(!queryParameters.containsKey(JOB_STATE_KEY), "Can't have duplicate job state for filtering");
|
||||
queryParameters.put(JOB_STATE_KEY, jobState.toString());
|
||||
return this;
|
||||
}
|
||||
public GetJobListOptions onlyForState(JobState jobState) {
|
||||
checkState(!queryParameters.containsKey(JOB_STATE_KEY), "Can't have duplicate job state for filtering");
|
||||
queryParameters.put(JOB_STATE_KEY, jobState.toString());
|
||||
return this;
|
||||
}
|
||||
|
||||
public GetJobListOptions onlyForObjectType(ObjectType objectType) {
|
||||
checkState(!queryParameters.containsKey(JOB_OBJECT_TYPE_KEY), "Can't have duplicate object type for filtering");
|
||||
queryParameters.put(JOB_OBJECT_TYPE_KEY, objectType.toString());
|
||||
return this;
|
||||
}
|
||||
public GetJobListOptions onlyForObjectType(ObjectType objectType) {
|
||||
checkState(!queryParameters.containsKey(JOB_OBJECT_TYPE_KEY), "Can't have duplicate object type for filtering");
|
||||
queryParameters.put(JOB_OBJECT_TYPE_KEY, objectType.toString());
|
||||
return this;
|
||||
}
|
||||
|
||||
public GetJobListOptions onlyForObjectName(String objectName) {
|
||||
checkState(!queryParameters.containsKey(OBJECT_KEY), "Can't have duplicate object name for filtering");
|
||||
queryParameters.put(OBJECT_KEY, objectName);
|
||||
return this;
|
||||
}
|
||||
public GetJobListOptions onlyForObjectName(String objectName) {
|
||||
checkState(!queryParameters.containsKey(OBJECT_KEY), "Can't have duplicate object name for filtering");
|
||||
queryParameters.put(OBJECT_KEY, objectName);
|
||||
return this;
|
||||
}
|
||||
|
||||
/*
|
||||
public GetJobListOptions latestJobForObjectByName(String serverName) {
|
||||
return maxItemsNumber(1).onlyForObjectName(serverName);
|
||||
}
|
||||
|
||||
/*
|
||||
* This method is intended for testing
|
||||
*/
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o)
|
||||
return true;
|
||||
if (o == null || getClass() != o.getClass())
|
||||
return false;
|
||||
|
||||
GetJobListOptions options = (GetJobListOptions) o;
|
||||
GetJobListOptions options = (GetJobListOptions) o;
|
||||
|
||||
return buildQueryParameters().equals(options.buildQueryParameters());
|
||||
}
|
||||
return buildQueryParameters().equals(options.buildQueryParameters());
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
public GetJobListOptions create() {
|
||||
return new GetJobListOptions();
|
||||
}
|
||||
public static class Builder {
|
||||
|
||||
public GetJobListOptions latestJobForObjectByName(String serverName) {
|
||||
return new GetJobListOptions().
|
||||
maxItemsNumber(1).
|
||||
onlyForObjectName(serverName);
|
||||
}
|
||||
}
|
||||
public static GetJobListOptions maxItems(int maxNumber) {
|
||||
return new GetJobListOptions().maxItemsNumber(maxNumber);
|
||||
}
|
||||
|
||||
public static GetJobListOptions startDate(Date startDate){
|
||||
return new GetJobListOptions().withStartDate(startDate);
|
||||
}
|
||||
|
||||
public static GetJobListOptions latestJobForObjectByName(String serverName) {
|
||||
return new GetJobListOptions().latestJobForObjectByName(serverName);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -18,20 +18,21 @@
|
|||
*/
|
||||
package org.jclouds.gogrid.predicates;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.inject.Inject;
|
||||
import org.jclouds.gogrid.domain.Job;
|
||||
import org.jclouds.gogrid.domain.JobState;
|
||||
import org.jclouds.gogrid.domain.LoadBalancer;
|
||||
import org.jclouds.gogrid.options.GetJobListOptions;
|
||||
import org.jclouds.gogrid.services.GridJobClient;
|
||||
import org.jclouds.logging.Logger;
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static org.jclouds.gogrid.options.GetJobListOptions.Builder.latestJobForObjectByName;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import org.jclouds.gogrid.domain.Job;
|
||||
import org.jclouds.gogrid.domain.JobState;
|
||||
import org.jclouds.gogrid.domain.LoadBalancer;
|
||||
import org.jclouds.gogrid.services.GridJobClient;
|
||||
import org.jclouds.logging.Logger;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.inject.Inject;
|
||||
|
||||
/**
|
||||
* @author Oleksiy Yarmula
|
||||
|
@ -39,23 +40,21 @@ import static com.google.common.base.Preconditions.checkNotNull;
|
|||
@Singleton
|
||||
public class LoadBalancerLatestJobCompleted implements Predicate<LoadBalancer> {
|
||||
|
||||
protected GridJobClient jobClient;
|
||||
protected GridJobClient jobClient;
|
||||
|
||||
@Resource
|
||||
protected Logger logger = Logger.NULL;
|
||||
@Resource
|
||||
protected Logger logger = Logger.NULL;
|
||||
|
||||
@Inject
|
||||
public LoadBalancerLatestJobCompleted(GridJobClient jobClient) {
|
||||
this.jobClient = jobClient;
|
||||
}
|
||||
@Inject
|
||||
public LoadBalancerLatestJobCompleted(GridJobClient jobClient) {
|
||||
this.jobClient = jobClient;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(LoadBalancer loadBalancer) {
|
||||
checkNotNull(loadBalancer, "Load balancer must be a valid instance");
|
||||
checkNotNull(loadBalancer.getName(), "Load balancer must be a valid name");
|
||||
GetJobListOptions jobOptions = new GetJobListOptions.Builder().
|
||||
latestJobForObjectByName(loadBalancer.getName());
|
||||
Job latestJob = Iterables.getOnlyElement(jobClient.getJobList(jobOptions));
|
||||
return JobState.SUCCEEDED.equals(latestJob.getCurrentState());
|
||||
}
|
||||
@Override
|
||||
public boolean apply(LoadBalancer loadBalancer) {
|
||||
checkNotNull(loadBalancer, "Load balancer must be a valid instance");
|
||||
checkNotNull(loadBalancer.getName(), "Load balancer must be a valid name");
|
||||
Job latestJob = Iterables.getOnlyElement(jobClient.getJobList(latestJobForObjectByName(loadBalancer.getName())));
|
||||
return JobState.SUCCEEDED.equals(latestJob.getCurrentState());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,50 +18,49 @@
|
|||
*/
|
||||
package org.jclouds.gogrid.predicates;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.inject.Inject;
|
||||
import org.jclouds.gogrid.domain.Job;
|
||||
import org.jclouds.gogrid.domain.JobState;
|
||||
import org.jclouds.gogrid.domain.Server;
|
||||
import org.jclouds.gogrid.options.GetJobListOptions;
|
||||
import org.jclouds.gogrid.services.GridJobClient;
|
||||
import org.jclouds.logging.Logger;
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static org.jclouds.gogrid.options.GetJobListOptions.Builder.latestJobForObjectByName;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import org.jclouds.gogrid.domain.Job;
|
||||
import org.jclouds.gogrid.domain.JobState;
|
||||
import org.jclouds.gogrid.domain.Server;
|
||||
import org.jclouds.gogrid.services.GridJobClient;
|
||||
import org.jclouds.logging.Logger;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.inject.Inject;
|
||||
|
||||
/**
|
||||
* Checks if the latest job for the server is in "Succeeded" state.
|
||||
* To achieve meaningful results, this must be run in a sequential
|
||||
* environment when a server has only one job related to it at a time.
|
||||
*
|
||||
* Checks if the latest job for the server is in "Succeeded" state. To achieve meaningful results,
|
||||
* this must be run in a sequential environment when a server has only one job related to it at a
|
||||
* time.
|
||||
*
|
||||
* The passed server instance must not be null and must have a name.
|
||||
*
|
||||
*
|
||||
* @author Oleksiy Yarmula
|
||||
*/
|
||||
@Singleton
|
||||
public class ServerLatestJobCompleted implements Predicate<Server> {
|
||||
|
||||
protected GridJobClient jobClient;
|
||||
protected GridJobClient jobClient;
|
||||
|
||||
@Resource
|
||||
protected Logger logger = Logger.NULL;
|
||||
@Resource
|
||||
protected Logger logger = Logger.NULL;
|
||||
|
||||
@Inject
|
||||
public ServerLatestJobCompleted(GridJobClient jobClient) {
|
||||
this.jobClient = jobClient;
|
||||
}
|
||||
@Inject
|
||||
public ServerLatestJobCompleted(GridJobClient jobClient) {
|
||||
this.jobClient = jobClient;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(Server server) {
|
||||
checkNotNull(server, "Server must be a valid instance");
|
||||
checkNotNull(server.getName(), "Server must be a valid name");
|
||||
GetJobListOptions jobOptions = new GetJobListOptions.Builder().
|
||||
latestJobForObjectByName(server.getName());
|
||||
Job latestJob = Iterables.getOnlyElement(jobClient.getJobList(jobOptions));
|
||||
return JobState.SUCCEEDED.equals(latestJob.getCurrentState());
|
||||
}
|
||||
@Override
|
||||
public boolean apply(Server server) {
|
||||
checkNotNull(server, "Server must be a valid instance");
|
||||
checkNotNull(server.getName(), "Server must be a valid name");
|
||||
Job latestJob = Iterables.getOnlyElement(jobClient.getJobList(latestJobForObjectByName(server.getName())));
|
||||
return JobState.SUCCEEDED.equals(latestJob.getCurrentState());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -45,6 +45,7 @@ public interface GridJobClient {
|
|||
*
|
||||
* @return jobs found by request
|
||||
*/
|
||||
@Timeout(duration = 90, timeUnit = TimeUnit.SECONDS)
|
||||
Set<Job> getJobList(GetJobListOptions... options);
|
||||
|
||||
/**
|
||||
|
|
|
@ -21,12 +21,12 @@ package org.jclouds.gogrid.predicates;
|
|||
import static org.easymock.EasyMock.expect;
|
||||
import static org.easymock.classextension.EasyMock.createMock;
|
||||
import static org.easymock.classextension.EasyMock.replay;
|
||||
import static org.jclouds.gogrid.options.GetJobListOptions.Builder.latestJobForObjectByName;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
|
||||
import org.jclouds.gogrid.domain.Job;
|
||||
import org.jclouds.gogrid.domain.JobState;
|
||||
import org.jclouds.gogrid.domain.Server;
|
||||
import org.jclouds.gogrid.options.GetJobListOptions;
|
||||
import org.jclouds.gogrid.services.GridJobClient;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
|
@ -35,33 +35,29 @@ import com.google.common.collect.ImmutableSet;
|
|||
/**
|
||||
* @author Oleksiy Yarmula
|
||||
*/
|
||||
//NOTE:without testName, this will not call @Before* and fail w/NPE during surefire
|
||||
// NOTE:without testName, this will not call @Before* and fail w/NPE during surefire
|
||||
@Test(groups = "unit", testName = "ServerLatestJobCompletedTest")
|
||||
public class ServerLatestJobCompletedTest {
|
||||
|
||||
@Test
|
||||
public void testPredicate() {
|
||||
final String serverName = "SERVER_NAME";
|
||||
Server server = createMock(Server.class);
|
||||
expect(server.getName()).andStubReturn(serverName);
|
||||
@Test
|
||||
public void testPredicate() {
|
||||
final String serverName = "SERVER_NAME";
|
||||
Server server = createMock(Server.class);
|
||||
expect(server.getName()).andStubReturn(serverName);
|
||||
|
||||
GetJobListOptions jobOptions = new GetJobListOptions.Builder().
|
||||
latestJobForObjectByName(serverName);
|
||||
Job job = createMock(Job.class);
|
||||
expect(job.getCurrentState()).andReturn(JobState.SUCCEEDED);
|
||||
|
||||
Job job = createMock(Job.class);
|
||||
expect(job.getCurrentState()).andReturn(JobState.SUCCEEDED);
|
||||
GridJobClient client = createMock(GridJobClient.class);
|
||||
expect(client.getJobList(latestJobForObjectByName(serverName))).andReturn(ImmutableSet.<Job> of(job));
|
||||
|
||||
GridJobClient client = createMock(GridJobClient.class);
|
||||
expect(client.getJobList(jobOptions)).
|
||||
andReturn(ImmutableSet.<Job>of(job));
|
||||
replay(job);
|
||||
replay(client);
|
||||
replay(server);
|
||||
|
||||
replay(job);
|
||||
replay(client);
|
||||
replay(server);
|
||||
ServerLatestJobCompleted predicate = new ServerLatestJobCompleted(client);
|
||||
assertTrue(predicate.apply(server), "The result of the predicate should've been 'true'");
|
||||
|
||||
ServerLatestJobCompleted predicate = new ServerLatestJobCompleted(client);
|
||||
assertTrue(predicate.apply(server), "The result of the predicate should've been 'true'");
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,90 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.jclouds.gogrid.services;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import org.jclouds.compute.ComputeServiceContext;
|
||||
import org.jclouds.compute.ComputeServiceContextFactory;
|
||||
import org.jclouds.gogrid.GoGridAsyncClient;
|
||||
import org.jclouds.gogrid.GoGridClient;
|
||||
import org.jclouds.logging.log4j.config.Log4JLoggingModule;
|
||||
import org.jclouds.rest.RestContext;
|
||||
import org.jclouds.sshj.config.SshjSshClientModule;
|
||||
import org.testng.annotations.AfterGroups;
|
||||
import org.testng.annotations.BeforeGroups;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.inject.Module;
|
||||
|
||||
/**
|
||||
* Tests behavior of {@code GoGridClient}
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Test(groups = "live")
|
||||
public class BaseGoGridClientLiveTest {
|
||||
|
||||
protected RestContext<GoGridClient, GoGridAsyncClient> restContext;
|
||||
protected String provider = "gogrid";
|
||||
protected String identity;
|
||||
protected String credential;
|
||||
protected String endpoint;
|
||||
protected String apiversion;
|
||||
protected ComputeServiceContext context;
|
||||
protected String prefix = System.getProperty("user.name");
|
||||
|
||||
protected void setupCredentials() {
|
||||
identity = checkNotNull(System.getProperty("test." + provider + ".identity"), "test." + provider + ".identity");
|
||||
credential = checkNotNull(System.getProperty("test." + provider + ".credential"), "test." + provider
|
||||
+ ".credential");
|
||||
endpoint = System.getProperty("test." + provider + ".endpoint");
|
||||
apiversion = System.getProperty("test." + provider + ".apiversion");
|
||||
}
|
||||
|
||||
protected Properties setupProperties() {
|
||||
Properties overrides = new Properties();
|
||||
overrides.setProperty(provider + ".identity", identity);
|
||||
overrides.setProperty(provider + ".credential", credential);
|
||||
if (endpoint != null)
|
||||
overrides.setProperty(provider + ".endpoint", endpoint);
|
||||
if (apiversion != null)
|
||||
overrides.setProperty(provider + ".apiversion", apiversion);
|
||||
return overrides;
|
||||
}
|
||||
|
||||
@BeforeGroups(groups = { "live" })
|
||||
public void setupClient() {
|
||||
setupCredentials();
|
||||
Properties overrides = setupProperties();
|
||||
context = new ComputeServiceContextFactory().createContext(provider, ImmutableSet.<Module> of(
|
||||
new Log4JLoggingModule(), new SshjSshClientModule()), overrides);
|
||||
restContext = context.getProviderSpecificContext();
|
||||
}
|
||||
|
||||
@AfterGroups(groups = "live")
|
||||
protected void tearDown() {
|
||||
if (context != null)
|
||||
context.close();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,72 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.jclouds.gogrid.services;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.jclouds.gogrid.domain.ServerImage;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.collect.Iterables;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
// NOTE:without testName, this will not call @Before* and fail w/NPE during surefire
|
||||
@Test(groups = "unit", testName = "GridImageClientLiveTest")
|
||||
public class GridImageClientLiveTest extends BaseGoGridClientLiveTest {
|
||||
|
||||
public void testListImages() throws Exception {
|
||||
Set<ServerImage> response = restContext.getApi().getImageServices().getImageList();
|
||||
assert null != response;
|
||||
for (ServerImage image : response) {
|
||||
assert image.getId() >= 0 : image;
|
||||
checkImage(image);
|
||||
|
||||
ServerImage query = Iterables.getOnlyElement(restContext.getApi().getImageServices().getImagesById(
|
||||
image.getId()));
|
||||
assertEquals(query.getId(), image.getId());
|
||||
|
||||
checkImage(query);
|
||||
}
|
||||
}
|
||||
|
||||
private void checkImage(ServerImage image) {
|
||||
assert image.getArchitecture() != null : image;
|
||||
assert image.getBillingTokens() != null : image;
|
||||
if (image.getCreatedTime() == null)
|
||||
Logger.getAnonymousLogger().warning("image " + image.getId() + " is missing the createdon field");
|
||||
assert image.getDescription() != null : image;
|
||||
assert image.getFriendlyName() != null : image;
|
||||
assert image.getId() >= 0 : image;
|
||||
assert image.getLocation() != null : image;
|
||||
assert image.getName() != null : image;
|
||||
assert image.getOs() != null : image;
|
||||
assert image.getOwner() != null : image;
|
||||
assert image.getPrice() >= 0 : image;
|
||||
assert image.getState() != null : image;
|
||||
assert image.getType() != null : image;
|
||||
if (image.getUpdatedTime() == null)
|
||||
Logger.getAnonymousLogger().warning("image " + image.getId() + " is missing the updatedon field");
|
||||
}
|
||||
}
|
|
@ -18,6 +18,8 @@
|
|||
*/
|
||||
package org.jclouds.gogrid.services;
|
||||
|
||||
import static org.jclouds.gogrid.options.GetJobListOptions.Builder.startDate;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Date;
|
||||
|
@ -45,14 +47,13 @@ public class GridJobAsyncClientTest extends BaseGoGridAsyncClientTest<GridJobAsy
|
|||
@Test
|
||||
public void testGetJobListWithOptions() throws NoSuchMethodException, IOException {
|
||||
Method method = GridJobAsyncClient.class.getMethod("getJobList", GetJobListOptions[].class);
|
||||
HttpRequest httpRequest = processor.createRequest(method,
|
||||
new GetJobListOptions.Builder().create().withStartDate(new Date(1267385381770L)).withEndDate(
|
||||
new Date(1267385382770L)).onlyForObjectType(ObjectType.VIRTUAL_SERVER).onlyForState(
|
||||
JobState.PROCESSING));
|
||||
HttpRequest httpRequest = processor
|
||||
.createRequest(method, startDate(new Date(1267385381770L)).withEndDate(new Date(1267385382770L))
|
||||
.onlyForObjectType(ObjectType.VIRTUAL_SERVER).onlyForState(JobState.PROCESSING));
|
||||
|
||||
assertRequestLineEquals(httpRequest,
|
||||
"GET https://api.gogrid.com/api/grid/job/list?v=1.5&startdate=1267385381770&"
|
||||
+ "enddate=1267385382770&job.objecttype=VirtualServer&" + "job.state=Processing HTTP/1.1");
|
||||
"GET https://api.gogrid.com/api/grid/job/list?v=1.5&startdate=1267385381770&"
|
||||
+ "enddate=1267385382770&job.objecttype=VirtualServer&" + "job.state=Processing HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
|
||||
|
@ -64,9 +65,9 @@ public class GridJobAsyncClientTest extends BaseGoGridAsyncClientTest<GridJobAsy
|
|||
httpRequest = Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest);
|
||||
|
||||
assertRequestLineEquals(httpRequest,
|
||||
"GET https://api.gogrid.com/api/grid/job/list?v=1.5&startdate=1267385381770&"
|
||||
+ "enddate=1267385382770&job.objecttype=VirtualServer&" + "job.state=Processing&"
|
||||
+ "sig=3f446f171455fbb5574aecff4997b273&api_key=foo HTTP/1.1");
|
||||
"GET https://api.gogrid.com/api/grid/job/list?v=1.5&startdate=1267385381770&"
|
||||
+ "enddate=1267385382770&job.objecttype=VirtualServer&" + "job.state=Processing&"
|
||||
+ "sig=3f446f171455fbb5574aecff4997b273&api_key=foo HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
}
|
||||
|
@ -87,7 +88,7 @@ public class GridJobAsyncClientTest extends BaseGoGridAsyncClientTest<GridJobAsy
|
|||
HttpRequest httpRequest = processor.createRequest(method, "MyServer");
|
||||
|
||||
assertRequestLineEquals(httpRequest, "GET https://api.gogrid.com/api/grid/job/list?v=1.5&"
|
||||
+ "object=MyServer HTTP/1.1");
|
||||
+ "object=MyServer HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
|
||||
|
@ -99,7 +100,7 @@ public class GridJobAsyncClientTest extends BaseGoGridAsyncClientTest<GridJobAsy
|
|||
httpRequest = Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest);
|
||||
|
||||
assertRequestLineEquals(httpRequest, "GET https://api.gogrid.com/api/grid/job/list?v=1.5&"
|
||||
+ "object=MyServer&sig=3f446f171455fbb5574aecff4997b273&api_key=foo " + "HTTP/1.1");
|
||||
+ "object=MyServer&sig=3f446f171455fbb5574aecff4997b273&api_key=foo " + "HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
}
|
||||
|
@ -110,7 +111,7 @@ public class GridJobAsyncClientTest extends BaseGoGridAsyncClientTest<GridJobAsy
|
|||
HttpRequest httpRequest = processor.createRequest(method, 123L, 456L);
|
||||
|
||||
assertRequestLineEquals(httpRequest, "GET https://api.gogrid.com/api/grid/job/get?v=1.5&"
|
||||
+ "id=123&id=456 HTTP/1.1");
|
||||
+ "id=123&id=456 HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
|
||||
|
@ -122,7 +123,7 @@ public class GridJobAsyncClientTest extends BaseGoGridAsyncClientTest<GridJobAsy
|
|||
httpRequest = Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest);
|
||||
|
||||
assertRequestLineEquals(httpRequest, "GET https://api.gogrid.com/api/grid/job/get?v=1.5&"
|
||||
+ "id=123&id=456&sig=3f446f171455fbb5574aecff4997b273&api_key=foo " + "HTTP/1.1");
|
||||
+ "id=123&id=456&sig=3f446f171455fbb5574aecff4997b273&api_key=foo " + "HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,66 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.jclouds.gogrid.services;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import org.jclouds.gogrid.domain.Job;
|
||||
import org.jclouds.gogrid.options.GetJobListOptions;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.collect.Iterables;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
// NOTE:without testName, this will not call @Before* and fail w/NPE during surefire
|
||||
@Test(groups = "unit", testName = "GridJobClientLiveTest")
|
||||
public class GridJobClientLiveTest extends BaseGoGridClientLiveTest {
|
||||
|
||||
public void testListJobs() throws Exception {
|
||||
Set<Job> response = restContext.getApi().getJobServices().getJobList(GetJobListOptions.Builder.maxItems(10));
|
||||
assert null != response;
|
||||
assert response.size() <= 10 : response;
|
||||
for (Job job : response) {
|
||||
assert job.getId() >= 0 : job;
|
||||
checkJob(job);
|
||||
|
||||
Job query = Iterables.getOnlyElement(restContext.getApi().getJobServices().getJobsById(job.getId()));
|
||||
assertEquals(query.getId(), job.getId());
|
||||
|
||||
checkJob(query);
|
||||
}
|
||||
}
|
||||
|
||||
private void checkJob(Job job) {
|
||||
assert job.getAttempts() >= 0 : job;
|
||||
assert job.getCommand() != null : job;
|
||||
assert job.getCreatedOn() != null : job;
|
||||
assert job.getCreatedOn() != null : job;
|
||||
assert job.getDetails() != null : job;
|
||||
assert job.getHistory() != null : job;
|
||||
assert job.getId() >= 0 : job;
|
||||
assert job.getLastUpdatedOn() != null : job;
|
||||
assert job.getObjectType() != null : job;
|
||||
assert job.getOwner() != null : job;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue