mirror of https://github.com/apache/jclouds.git
added load balancer methods, enums replaced for several option-based objects, tests
This commit is contained in:
parent
4892b843d8
commit
9df9d45859
|
@ -125,5 +125,9 @@ public interface Constants {
|
|||
* Name of the logger that records the steps of the request signing process of the HTTP_service.
|
||||
*/
|
||||
public static final String LOGGER_SIGNATURE = "jclouds.signature";
|
||||
/**
|
||||
* Name of the custom adapter bindings map for Gson
|
||||
*/
|
||||
public static final String PROPERTY_GSON_ADAPTERS = "jclouds.gson.adapters";
|
||||
|
||||
}
|
||||
|
|
|
@ -21,15 +21,16 @@ package org.jclouds.http.functions.config;
|
|||
import java.lang.reflect.Type;
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.Comparator;
|
||||
import java.util.Date;
|
||||
import java.util.SortedSet;
|
||||
import java.util.*;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
import javax.xml.parsers.SAXParser;
|
||||
import javax.xml.parsers.SAXParserFactory;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.inject.name.Named;
|
||||
import org.jclouds.Constants;
|
||||
import org.jclouds.date.DateService;
|
||||
import org.jclouds.http.functions.ParseSax;
|
||||
import org.jclouds.http.functions.ParseSax.HandlerWithResult;
|
||||
|
@ -127,12 +128,16 @@ public class ParserModule extends AbstractModule {
|
|||
|
||||
@Provides
|
||||
@Singleton
|
||||
Gson provideGson(DateAdapter adapter, SortedSetOfInetAddressCreator addressSetCreator) {
|
||||
Gson provideGson(DateAdapter adapter, SortedSetOfInetAddressCreator addressSetCreator,
|
||||
GsonAdapterBindings bindings) {
|
||||
GsonBuilder gson = new GsonBuilder();
|
||||
gson.registerTypeAdapter(InetAddress.class, new InetAddressAdapter());
|
||||
gson.registerTypeAdapter(Date.class, adapter);
|
||||
gson.registerTypeAdapter(new TypeToken<SortedSet<InetAddress>>() {
|
||||
}.getType(), addressSetCreator);
|
||||
for(Map.Entry<Class, Object> binding : bindings.getBindings().entrySet()) {
|
||||
gson.registerTypeAdapter(binding.getKey(), binding.getValue());
|
||||
}
|
||||
return gson.create();
|
||||
}
|
||||
|
||||
|
@ -187,4 +192,18 @@ public class ParserModule extends AbstractModule {
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
@Singleton
|
||||
public static class GsonAdapterBindings {
|
||||
private final Map<Class, Object> bindings = Maps.newHashMap();
|
||||
|
||||
@com.google.inject.Inject(optional=true)
|
||||
public void setBindings(@Named(Constants.PROPERTY_GSON_ADAPTERS) Map<Class, Object> bindings) {
|
||||
this.bindings.putAll(bindings);
|
||||
}
|
||||
|
||||
public Map<Class, Object> getBindings() {
|
||||
return bindings;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,9 +25,7 @@ package org.jclouds.gogrid;
|
|||
|
||||
import com.google.inject.ImplementedBy;
|
||||
import org.jclouds.gogrid.internal.GoGridAsyncClientImpl;
|
||||
import org.jclouds.gogrid.services.GridIpAsyncClient;
|
||||
import org.jclouds.gogrid.services.GridJobAsyncClient;
|
||||
import org.jclouds.gogrid.services.GridServerAsyncClient;
|
||||
import org.jclouds.gogrid.services.*;
|
||||
|
||||
/**
|
||||
* @author Oleksiy Yarmula
|
||||
|
@ -50,4 +48,9 @@ public interface GoGridAsyncClient {
|
|||
*/
|
||||
GridIpAsyncClient getIpServices();
|
||||
|
||||
/**
|
||||
* @see GoGridClient#getLoadBalancerServices()
|
||||
*/
|
||||
GridLoadBalancerAsyncClient getLoadBalancerServices();
|
||||
|
||||
}
|
||||
|
|
|
@ -27,6 +27,7 @@ import com.google.inject.ImplementedBy;
|
|||
import org.jclouds.gogrid.internal.GoGridClientImpl;
|
||||
import org.jclouds.gogrid.services.GridIpClient;
|
||||
import org.jclouds.gogrid.services.GridJobClient;
|
||||
import org.jclouds.gogrid.services.GridLoadBalancerClient;
|
||||
import org.jclouds.gogrid.services.GridServerClient;
|
||||
|
||||
/**
|
||||
|
@ -54,4 +55,10 @@ public interface GoGridClient {
|
|||
*/
|
||||
GridIpClient getIpServices();
|
||||
|
||||
/**
|
||||
* Returns method, related to managing load balancers.
|
||||
* @return loadBalancerServices
|
||||
*/
|
||||
GridLoadBalancerClient getLoadBalancerServices();
|
||||
|
||||
}
|
||||
|
|
|
@ -1,21 +1,3 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed 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.
|
||||
* ====================================================================
|
||||
*/
|
||||
/**
|
||||
*
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
|
@ -44,11 +26,14 @@ package org.jclouds.gogrid.config;
|
|||
import java.lang.reflect.Type;
|
||||
import java.net.URI;
|
||||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.inject.Named;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.gson.*;
|
||||
import org.jclouds.Constants;
|
||||
import org.jclouds.gogrid.GoGridAsyncClient;
|
||||
import org.jclouds.gogrid.GoGridClient;
|
||||
import org.jclouds.http.functions.config.ParserModule.DateAdapter;
|
||||
|
@ -92,7 +77,5 @@ public class GoGridContextModule extends AbstractModule {
|
|||
String toParse = json.getAsJsonPrimitive().getAsString();
|
||||
return new Date(Long.valueOf(toParse));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -42,18 +42,20 @@
|
|||
package org.jclouds.gogrid.config;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import javax.inject.Named;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import com.google.common.base.Supplier;
|
||||
import com.google.common.collect.Maps;
|
||||
import org.jclouds.Constants;
|
||||
import org.jclouds.concurrent.ExpirableSupplier;
|
||||
import org.jclouds.concurrent.internal.SyncProxy;
|
||||
import org.jclouds.date.DateService;
|
||||
import org.jclouds.date.TimeStamp;
|
||||
import org.jclouds.gogrid.GoGridAsyncClient;
|
||||
import org.jclouds.gogrid.GoGridClient;
|
||||
import org.jclouds.gogrid.domain.*;
|
||||
import org.jclouds.gogrid.functions.internal.CustomDeserializers;
|
||||
import org.jclouds.gogrid.handlers.GoGridErrorHandler;
|
||||
import org.jclouds.gogrid.services.*;
|
||||
import org.jclouds.http.HttpErrorHandler;
|
||||
|
@ -127,6 +129,19 @@ public class GoGridRestClientModule extends AbstractModule {
|
|||
return SyncProxy.create(GridIpClient.class, client);
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
protected GridLoadBalancerAsyncClient provideLoadBalancerClient(RestClientFactory factory) {
|
||||
return factory.create(GridLoadBalancerAsyncClient.class);
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
public GridLoadBalancerClient provideLoadBalancerClient(GridLoadBalancerAsyncClient client) throws IllegalArgumentException,
|
||||
SecurityException, NoSuchMethodException {
|
||||
return SyncProxy.create(GridLoadBalancerClient.class, client);
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
@GoGrid
|
||||
|
@ -140,6 +155,21 @@ public class GoGridRestClientModule extends AbstractModule {
|
|||
return cache.get();
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
@com.google.inject.name.Named(Constants.PROPERTY_GSON_ADAPTERS)
|
||||
public Map<Class, Object> provideCustomAdapterBindings() {
|
||||
Map<Class, Object> bindings = Maps.newHashMap();
|
||||
bindings.put(ObjectType.class, new CustomDeserializers.ObjectTypeAdapter());
|
||||
bindings.put(LoadBalancerOs.class, new CustomDeserializers.LoadBalancerOsAdapter());
|
||||
bindings.put(LoadBalancerState.class, new CustomDeserializers.LoadBalancerStateAdapter());
|
||||
bindings.put(LoadBalancerPersistenceType.class, new CustomDeserializers.LoadBalancerPersistenceTypeAdapter());
|
||||
bindings.put(LoadBalancerType.class, new CustomDeserializers.LoadBalancerTypeAdapter());
|
||||
bindings.put(IpState.class, new CustomDeserializers.IpStateAdapter());
|
||||
return bindings;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* borrowing concurrency code to ensure that caching takes place properly
|
||||
*/
|
||||
|
|
|
@ -37,7 +37,7 @@ public class Ip implements Comparable<Ip> {
|
|||
private String subnet;
|
||||
@SerializedName("public")
|
||||
private boolean isPublic;
|
||||
private Option state;
|
||||
private IpState state;
|
||||
|
||||
/**
|
||||
* A no-args constructor is required for deserialization
|
||||
|
@ -45,7 +45,7 @@ public class Ip implements Comparable<Ip> {
|
|||
public Ip() {
|
||||
}
|
||||
|
||||
public Ip(long id, String ip, String subnet, boolean isPublic, Option state) {
|
||||
public Ip(long id, String ip, String subnet, boolean isPublic, IpState state) {
|
||||
this.id = id;
|
||||
this.ip = ip;
|
||||
this.subnet = subnet;
|
||||
|
@ -69,7 +69,7 @@ public class Ip implements Comparable<Ip> {
|
|||
return isPublic;
|
||||
}
|
||||
|
||||
public Option getState() {
|
||||
public IpState getState() {
|
||||
return state;
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,67 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed 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.domain;
|
||||
|
||||
/**
|
||||
* @author Oleksiy Yarmula
|
||||
*/
|
||||
public class IpPortPair {
|
||||
|
||||
private Ip ip;
|
||||
private int port;
|
||||
|
||||
/**
|
||||
* A no-args constructor is required for deserialization
|
||||
*/
|
||||
public IpPortPair() {
|
||||
}
|
||||
|
||||
public IpPortPair(Ip ip, int port) {
|
||||
this.ip = ip;
|
||||
this.port = port;
|
||||
}
|
||||
|
||||
public Ip getIp() {
|
||||
return ip;
|
||||
}
|
||||
|
||||
public int getPort() {
|
||||
return port;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
|
||||
IpPortPair that = (IpPortPair) o;
|
||||
|
||||
if (port != that.port) return false;
|
||||
if (ip != null ? !ip.equals(that.ip) : that.ip != null) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = ip != null ? ip.hashCode() : 0;
|
||||
result = 31 * result + port;
|
||||
return result;
|
||||
}
|
||||
}
|
|
@ -20,6 +20,8 @@ package org.jclouds.gogrid.domain;
|
|||
|
||||
import com.google.common.base.CaseFormat;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
/**
|
||||
* @author Oleksiy Yarmula
|
||||
*/
|
||||
|
@ -29,4 +31,8 @@ public enum IpState {
|
|||
public String toString() {
|
||||
return (CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, name()));
|
||||
}
|
||||
|
||||
public static IpState fromValue(String state) {
|
||||
return valueOf(CaseFormat.UPPER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE, checkNotNull(state, "state")));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -38,7 +38,7 @@ public class Job implements Comparable<Job> {
|
|||
private long id;
|
||||
private Option command;
|
||||
@SerializedName("objecttype")
|
||||
private Option objectType;
|
||||
private ObjectType objectType;
|
||||
@SerializedName("createdon")
|
||||
private Date createdOn;
|
||||
@SerializedName("lastupdatedon")
|
||||
|
@ -60,7 +60,7 @@ public class Job implements Comparable<Job> {
|
|||
public Job() {
|
||||
}
|
||||
|
||||
public Job(long id, Option command, Option objectType,
|
||||
public Job(long id, Option command, ObjectType objectType,
|
||||
Date createdOn, Date lastUpdatedOn, Option currentState,
|
||||
int attempts, String owner, List<JobState> history,
|
||||
Map<String, String> details) {
|
||||
|
@ -84,7 +84,7 @@ public class Job implements Comparable<Job> {
|
|||
return command;
|
||||
}
|
||||
|
||||
public Option getObjectType() {
|
||||
public ObjectType getObjectType() {
|
||||
return objectType;
|
||||
}
|
||||
|
||||
|
@ -158,4 +158,20 @@ public class Job implements Comparable<Job> {
|
|||
return Longs.compare(createdOn.getTime(), o.getCreatedOn().getTime());
|
||||
return Longs.compare(id, o.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Job{" +
|
||||
"id=" + id +
|
||||
", command=" + command +
|
||||
", objectType=" + objectType +
|
||||
", createdOn=" + createdOn +
|
||||
", lastUpdatedOn=" + lastUpdatedOn +
|
||||
", currentState=" + currentState +
|
||||
", attempts=" + attempts +
|
||||
", owner='" + owner + '\'' +
|
||||
", history=" + history +
|
||||
", details=" + details +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
|
|
@ -90,4 +90,14 @@ public class JobState {
|
|||
result = 31 * result + (note != null ? note.hashCode() : 0);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "JobState{" +
|
||||
"id=" + id +
|
||||
", updatedOn=" + updatedOn +
|
||||
", state=" + state +
|
||||
", note='" + note + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,138 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed 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.domain;
|
||||
|
||||
import com.google.common.primitives.Longs;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Oleksiy Yarmula
|
||||
*/
|
||||
public class LoadBalancer implements Comparable<LoadBalancer> {
|
||||
|
||||
private long id;
|
||||
private String name;
|
||||
private String description;
|
||||
@SerializedName("virtualip")
|
||||
private IpPortPair virtualIp;
|
||||
@SerializedName("realiplist")
|
||||
private List<IpPortPair> realIpList;
|
||||
private LoadBalancerType type;
|
||||
private LoadBalancerPersistenceType persistence;
|
||||
private LoadBalancerOs os;
|
||||
private LoadBalancerState state;
|
||||
|
||||
/**
|
||||
* A no-args constructor is required for deserialization
|
||||
*/
|
||||
public LoadBalancer() {
|
||||
}
|
||||
|
||||
public LoadBalancer(long id, String name, String description,
|
||||
IpPortPair virtualIp, List<IpPortPair> realIpList, LoadBalancerType type,
|
||||
LoadBalancerPersistenceType persistence, LoadBalancerOs os,
|
||||
LoadBalancerState state) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
this.virtualIp = virtualIp;
|
||||
this.realIpList = realIpList;
|
||||
this.type = type;
|
||||
this.persistence = persistence;
|
||||
this.os = os;
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public IpPortPair getVirtualIp() {
|
||||
return virtualIp;
|
||||
}
|
||||
|
||||
public List<IpPortPair> getRealIpList() {
|
||||
return realIpList;
|
||||
}
|
||||
|
||||
public LoadBalancerType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public LoadBalancerPersistenceType getPersistence() {
|
||||
return persistence;
|
||||
}
|
||||
|
||||
public LoadBalancerOs getOs() {
|
||||
return os;
|
||||
}
|
||||
|
||||
public LoadBalancerState getState() {
|
||||
return state;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
|
||||
LoadBalancer that = (LoadBalancer) o;
|
||||
|
||||
if (id != that.id) return false;
|
||||
if (description != null ? !description.equals(that.description) : that.description != null) return false;
|
||||
if (name != null ? !name.equals(that.name) : that.name != null) return false;
|
||||
if (os != null ? !os.equals(that.os) : that.os != null) return false;
|
||||
if (persistence != null ? !persistence.equals(that.persistence) : that.persistence != null) return false;
|
||||
if (realIpList != null ? !realIpList.equals(that.realIpList) : that.realIpList != null) return false;
|
||||
if (state != null ? !state.equals(that.state) : that.state != null) return false;
|
||||
if (type != null ? !type.equals(that.type) : that.type != null) return false;
|
||||
if (virtualIp != null ? !virtualIp.equals(that.virtualIp) : that.virtualIp != null) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = (int) (id ^ (id >>> 32));
|
||||
result = 31 * result + (name != null ? name.hashCode() : 0);
|
||||
result = 31 * result + (description != null ? description.hashCode() : 0);
|
||||
result = 31 * result + (virtualIp != null ? virtualIp.hashCode() : 0);
|
||||
result = 31 * result + (realIpList != null ? realIpList.hashCode() : 0);
|
||||
result = 31 * result + (type != null ? type.hashCode() : 0);
|
||||
result = 31 * result + (persistence != null ? persistence.hashCode() : 0);
|
||||
result = 31 * result + (os != null ? os.hashCode() : 0);
|
||||
result = 31 * result + (state != null ? state.hashCode() : 0);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(LoadBalancer o) {
|
||||
return Longs.compare(id, o.getId());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed 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.domain;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
/**
|
||||
* @author Oleksiy Yarmula
|
||||
*/
|
||||
public enum LoadBalancerOs {
|
||||
|
||||
F5,
|
||||
UNKNOWN;
|
||||
|
||||
public static LoadBalancerOs fromValue(String value) {
|
||||
try {
|
||||
return valueOf(checkNotNull(value));
|
||||
} catch(IllegalArgumentException e) {
|
||||
return UNKNOWN;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,51 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed 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.domain;
|
||||
|
||||
import com.google.common.base.CaseFormat;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
/**
|
||||
* @author Oleksiy Yarmula
|
||||
*/
|
||||
public enum LoadBalancerPersistenceType {
|
||||
|
||||
NONE("None"),
|
||||
SSL_STICKY("SSL Sticky"),
|
||||
SOURCE_ADDRESS("Source Address"),
|
||||
UNKNOWN("Unknown");
|
||||
|
||||
String type;
|
||||
LoadBalancerPersistenceType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public static LoadBalancerPersistenceType fromValue(String type) {
|
||||
for(LoadBalancerPersistenceType persistenceType : values()) {
|
||||
if(persistenceType.type.equals(checkNotNull(type))) return persistenceType;
|
||||
}
|
||||
return UNKNOWN;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,52 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed 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.domain;
|
||||
|
||||
import com.google.common.base.CaseFormat;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
/**
|
||||
* @author Oleksiy Yarmula
|
||||
*/
|
||||
public enum LoadBalancerState {
|
||||
|
||||
ON,
|
||||
OFF,
|
||||
UNAVAILABLE,
|
||||
UNKNOWN;
|
||||
|
||||
public String value() {
|
||||
return (CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, name()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return value();
|
||||
}
|
||||
|
||||
public static LoadBalancerState fromValue(String state) {
|
||||
try {
|
||||
return valueOf(CaseFormat.UPPER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE, checkNotNull(state, "state")));
|
||||
} catch(IllegalArgumentException e) {
|
||||
return UNKNOWN;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,49 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed 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.domain;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
/**
|
||||
* @author Oleksiy Yarmula
|
||||
*/
|
||||
public enum LoadBalancerType {
|
||||
|
||||
ROUND_ROBIN("Round Robin"),
|
||||
LEAST_CONNECTED("Least Connect"),
|
||||
UNKNOWN("Unknown");
|
||||
|
||||
String type;
|
||||
LoadBalancerType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public static LoadBalancerType fromValue(String type) {
|
||||
for(LoadBalancerType persistenceType : values()) {
|
||||
if(persistenceType.type.equals(checkNotNull(type))) return persistenceType;
|
||||
}
|
||||
return UNKNOWN;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,56 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed 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.domain;
|
||||
|
||||
import com.google.common.base.CaseFormat;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
/**
|
||||
* @author Oleksiy Yarmula
|
||||
*/
|
||||
public enum ObjectType {
|
||||
|
||||
VIRTUAL_SERVER,
|
||||
LOAD_BALANCER,
|
||||
CLOUD_STORAGE,
|
||||
STORAGE_DNS,
|
||||
SERVER_IMAGE,
|
||||
DEDICATED_SERVER,
|
||||
UNKNOWN;
|
||||
|
||||
public String value() {
|
||||
return (CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, name()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return value();
|
||||
}
|
||||
|
||||
public static ObjectType fromValue(String type) {
|
||||
if("StorageDNS".equals(type)) return STORAGE_DNS;
|
||||
try {
|
||||
return valueOf(CaseFormat.UPPER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE, checkNotNull(type, "type")));
|
||||
} catch(IllegalArgumentException e) {
|
||||
return UNKNOWN;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -88,9 +88,8 @@ public class SharedKeyLiteAuthentication implements HttpRequestFilter {
|
|||
try {
|
||||
return encryptionService.md5Hex(stringToHash.getBytes());
|
||||
} catch(Exception e) {
|
||||
throw Throwables.propagate(e);
|
||||
}
|
||||
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,58 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed 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.functions;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import org.jclouds.gogrid.domain.Job;
|
||||
import org.jclouds.gogrid.domain.LoadBalancer;
|
||||
import org.jclouds.gogrid.domain.internal.GenericResponseContainer;
|
||||
import org.jclouds.http.functions.ParseJson;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.SortedSet;
|
||||
|
||||
/**
|
||||
* Parses {@link org.jclouds.gogrid.domain.LoadBalancer jobs} from a json string.
|
||||
*
|
||||
* @author Oleksiy Yarmula
|
||||
*/
|
||||
public class ParseLoadBalancerListFromJsonResponse extends ParseJson<SortedSet<LoadBalancer>> {
|
||||
|
||||
@Inject
|
||||
public ParseLoadBalancerListFromJsonResponse(Gson gson) {
|
||||
super(gson);
|
||||
}
|
||||
|
||||
public SortedSet<LoadBalancer> apply(InputStream stream) {
|
||||
Type setType = new TypeToken<GenericResponseContainer<LoadBalancer>>() {
|
||||
}.getType();
|
||||
GenericResponseContainer<LoadBalancer> response;
|
||||
try {
|
||||
response = gson.fromJson(new InputStreamReader(stream, "UTF-8"), setType);
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
throw new RuntimeException("jclouds requires UTF-8 encoding", e);
|
||||
}
|
||||
return response.getList();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,79 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed 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.functions.internal;
|
||||
|
||||
import com.google.gson.*;
|
||||
import org.jclouds.gogrid.domain.*;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
/**
|
||||
* @author Oleksiy Yarmula
|
||||
*/
|
||||
public class CustomDeserializers {
|
||||
|
||||
public static class ObjectTypeAdapter implements JsonDeserializer<ObjectType> {
|
||||
@Override
|
||||
public ObjectType deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext context) throws JsonParseException {
|
||||
String name = ((JsonObject) jsonElement).get("name").getAsString();
|
||||
return ObjectType.fromValue(name);
|
||||
}
|
||||
}
|
||||
|
||||
public static class LoadBalancerOsAdapter implements JsonDeserializer<LoadBalancerOs> {
|
||||
@Override
|
||||
public LoadBalancerOs deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext context) throws JsonParseException {
|
||||
String name = ((JsonObject) jsonElement).get("name").getAsString();
|
||||
return LoadBalancerOs.fromValue(name);
|
||||
}
|
||||
}
|
||||
|
||||
public static class LoadBalancerStateAdapter implements JsonDeserializer<LoadBalancerState> {
|
||||
@Override
|
||||
public LoadBalancerState deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext context) throws JsonParseException {
|
||||
String name = ((JsonObject) jsonElement).get("name").getAsString();
|
||||
return LoadBalancerState.fromValue(name);
|
||||
}
|
||||
}
|
||||
|
||||
public static class LoadBalancerPersistenceTypeAdapter implements JsonDeserializer<LoadBalancerPersistenceType> {
|
||||
@Override
|
||||
public LoadBalancerPersistenceType deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext context) throws JsonParseException {
|
||||
String name = ((JsonObject) jsonElement).get("name").getAsString();
|
||||
return LoadBalancerPersistenceType.fromValue(name);
|
||||
}
|
||||
}
|
||||
|
||||
public static class LoadBalancerTypeAdapter implements JsonDeserializer<LoadBalancerType> {
|
||||
@Override
|
||||
public LoadBalancerType deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext context) throws JsonParseException {
|
||||
String name = ((JsonObject) jsonElement).get("name").getAsString();
|
||||
return LoadBalancerType.fromValue(name);
|
||||
}
|
||||
}
|
||||
|
||||
public static class IpStateAdapter implements JsonDeserializer<IpState> {
|
||||
@Override
|
||||
public IpState deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext context) throws JsonParseException {
|
||||
String name = ((JsonObject) jsonElement).get("name").getAsString();
|
||||
return IpState.fromValue(name);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -37,14 +37,17 @@ public class GoGridAsyncClientImpl implements GoGridAsyncClient {
|
|||
private GridServerAsyncClient gridServerAsyncClient;
|
||||
private GridJobAsyncClient gridJobAsyncClient;
|
||||
private GridIpAsyncClient gridIpAsyncClient;
|
||||
private GridLoadBalancerAsyncClient gridLoadBalancerAsyncClient;
|
||||
|
||||
@Inject
|
||||
public GoGridAsyncClientImpl(GridServerAsyncClient gridServerClient,
|
||||
GridJobAsyncClient gridJobAsyncClient,
|
||||
GridIpAsyncClient gridIpAsyncClient) {
|
||||
GridIpAsyncClient gridIpAsyncClient,
|
||||
GridLoadBalancerAsyncClient gridLoadBalancerAsyncClient) {
|
||||
this.gridServerAsyncClient = gridServerClient;
|
||||
this.gridJobAsyncClient = gridJobAsyncClient;
|
||||
this.gridIpAsyncClient = gridIpAsyncClient;
|
||||
this.gridLoadBalancerAsyncClient = gridLoadBalancerAsyncClient;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -57,7 +60,13 @@ public class GoGridAsyncClientImpl implements GoGridAsyncClient {
|
|||
return gridJobAsyncClient;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GridIpAsyncClient getIpServices() {
|
||||
return gridIpAsyncClient;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GridLoadBalancerAsyncClient getLoadBalancerServices() {
|
||||
return gridLoadBalancerAsyncClient;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,9 +26,7 @@ package org.jclouds.gogrid.internal;
|
|||
import com.google.inject.Inject;
|
||||
import com.google.inject.Singleton;
|
||||
import org.jclouds.gogrid.GoGridClient;
|
||||
import org.jclouds.gogrid.services.GridIpClient;
|
||||
import org.jclouds.gogrid.services.GridJobClient;
|
||||
import org.jclouds.gogrid.services.GridServerClient;
|
||||
import org.jclouds.gogrid.services.*;
|
||||
|
||||
/**
|
||||
* @author Oleksiy Yarmula
|
||||
|
@ -39,14 +37,17 @@ public class GoGridClientImpl implements GoGridClient {
|
|||
private GridServerClient gridServerClient;
|
||||
private GridJobClient gridJobClient;
|
||||
private GridIpClient gridIpClient;
|
||||
private GridLoadBalancerClient gridLoadBalancerClient;
|
||||
|
||||
@Inject
|
||||
public GoGridClientImpl(GridServerClient gridServerClient,
|
||||
GridJobClient gridJobClient,
|
||||
GridIpClient gridIpClient) {
|
||||
GridIpClient gridIpClient,
|
||||
GridLoadBalancerClient gridLoadBalancerClient) {
|
||||
this.gridServerClient = gridServerClient;
|
||||
this.gridJobClient = gridJobClient;
|
||||
this.gridIpClient = gridIpClient;
|
||||
this.gridLoadBalancerClient = gridLoadBalancerClient;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -63,4 +64,9 @@ public class GoGridClientImpl implements GoGridClient {
|
|||
public GridIpClient getIpServices() {
|
||||
return gridIpClient;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GridLoadBalancerClient getLoadBalancerServices() {
|
||||
return gridLoadBalancerClient;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,53 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed 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 com.google.common.util.concurrent.ListenableFuture;
|
||||
import org.jclouds.gogrid.GoGrid;
|
||||
import org.jclouds.gogrid.domain.LoadBalancer;
|
||||
import org.jclouds.gogrid.filters.SharedKeyLiteAuthentication;
|
||||
import org.jclouds.gogrid.functions.ParseLoadBalancerListFromJsonResponse;
|
||||
import org.jclouds.rest.annotations.Endpoint;
|
||||
import org.jclouds.rest.annotations.QueryParams;
|
||||
import org.jclouds.rest.annotations.RequestFilters;
|
||||
import org.jclouds.rest.annotations.ResponseParser;
|
||||
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.Path;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.jclouds.gogrid.reference.GoGridHeaders.VERSION;
|
||||
|
||||
/**
|
||||
* @author Oleksiy Yarmula
|
||||
*/
|
||||
@Endpoint(GoGrid.class)
|
||||
@RequestFilters(SharedKeyLiteAuthentication.class)
|
||||
@QueryParams(keys = VERSION, values = "1.4")
|
||||
public interface GridLoadBalancerAsyncClient {
|
||||
|
||||
/**
|
||||
* @see GridJobClient#getJobList(org.jclouds.gogrid.options.GetJobListOptions...)
|
||||
*/
|
||||
@GET
|
||||
@ResponseParser(ParseLoadBalancerListFromJsonResponse.class)
|
||||
@Path("/grid/loadbalancer/list")
|
||||
ListenableFuture<Set<LoadBalancer>> getLoadBalancerList();
|
||||
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed 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 org.jclouds.concurrent.Timeout;
|
||||
import org.jclouds.gogrid.domain.LoadBalancer;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* @author Oleksiy Yarmula
|
||||
*/
|
||||
@Timeout(duration = 30, timeUnit = TimeUnit.SECONDS)
|
||||
public interface GridLoadBalancerClient {
|
||||
|
||||
/**
|
||||
* Returns all load balancers found for the current user.
|
||||
* @return load balancers found
|
||||
*/
|
||||
Set<LoadBalancer> getLoadBalancerList();
|
||||
}
|
|
@ -19,10 +19,7 @@
|
|||
package org.jclouds.gogrid;
|
||||
|
||||
import com.google.common.collect.Iterables;
|
||||
import org.jclouds.gogrid.domain.Ip;
|
||||
import org.jclouds.gogrid.domain.Job;
|
||||
import org.jclouds.gogrid.domain.PowerCommand;
|
||||
import org.jclouds.gogrid.domain.Server;
|
||||
import org.jclouds.gogrid.domain.*;
|
||||
import org.jclouds.gogrid.predicates.ServerLatestJobCompleted;
|
||||
import org.jclouds.logging.log4j.config.Log4JLoggingModule;
|
||||
import org.jclouds.predicates.RetryablePredicate;
|
||||
|
@ -165,6 +162,12 @@ public class GoGridLiveTest {
|
|||
client.getServerServices().deleteByName(nameOfServer);
|
||||
}
|
||||
|
||||
|
||||
@Test(enabled=false)
|
||||
public void testLoadBalancers() {
|
||||
Set<LoadBalancer> balancers = client.getLoadBalancerServices().getLoadBalancerList();
|
||||
}
|
||||
|
||||
/**
|
||||
* In case anything went wrong during the tests, removes the objects
|
||||
* created in the tests.
|
||||
|
|
|
@ -39,14 +39,6 @@ import java.net.UnknownHostException;
|
|||
*/
|
||||
public class ParseErrorFromJsonResponseTest {
|
||||
|
||||
Injector i = Guice.createInjector(new ParserModule() {
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(DateAdapter.class).to(GoGridContextModule.DateSecondsAdapter.class);
|
||||
super.configure();
|
||||
}
|
||||
});
|
||||
|
||||
@Test
|
||||
public void testApplyInputStreamDetails() throws UnknownHostException {
|
||||
InputStream is = getClass().getResourceAsStream("/test_error_handler.json");
|
||||
|
@ -57,4 +49,14 @@ public class ParseErrorFromJsonResponseTest {
|
|||
assert "No object found that matches your input criteria.".equals(response.getMessage());
|
||||
assert "IllegalArgumentException".equals(response.getErrorCode());
|
||||
}
|
||||
|
||||
|
||||
Injector i = Guice.createInjector(new ParserModule() {
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(DateAdapter.class).to(GoGridContextModule.DateSecondsAdapter.class);
|
||||
super.configure();
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,109 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed 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.functions;
|
||||
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.common.collect.Multimap;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.Provides;
|
||||
import com.google.inject.internal.ImmutableMap;
|
||||
import org.jclouds.Constants;
|
||||
import org.jclouds.gogrid.config.GoGridContextModule;
|
||||
import org.jclouds.gogrid.domain.Job;
|
||||
import org.jclouds.gogrid.domain.JobState;
|
||||
import org.jclouds.gogrid.domain.ObjectType;
|
||||
import org.jclouds.gogrid.domain.Option;
|
||||
import org.jclouds.gogrid.functions.internal.CustomDeserializers;
|
||||
import org.jclouds.http.functions.config.ParserModule;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
import java.io.InputStream;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
import java.util.SortedSet;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* @author Oleksiy Yarmula
|
||||
*/
|
||||
@Test(groups = "unit", testName = "gogrid.ParseJobsFromJsonResponseTest")
|
||||
public class ParseJobsFromJsonResponseTest {
|
||||
|
||||
@Test
|
||||
public void testApplyInputStreamDetails() throws UnknownHostException {
|
||||
InputStream is = getClass().getResourceAsStream("/test_get_job_list.json");
|
||||
|
||||
ParseJobListFromJsonResponse parser = new ParseJobListFromJsonResponse(i
|
||||
.getInstance(Gson.class));
|
||||
SortedSet<Job> response = parser.apply(is);
|
||||
|
||||
Map<String, String> details = Maps.newTreeMap();
|
||||
details.put("description", null);
|
||||
details.put("image", "GSI-f8979644-e646-4711-ad58-d98a5fa3612c");
|
||||
details.put("ip", "204.51.240.189");
|
||||
details.put("name", "ServerCreated40562");
|
||||
details.put("type", "virtual_server");
|
||||
|
||||
Job job = new Job(250628L,
|
||||
new Option(7L, "DeleteVirtualServer", "Delete Virtual Server"),
|
||||
ObjectType.VIRTUAL_SERVER,
|
||||
new Date(1267404528895L),
|
||||
new Date(1267404538592L),
|
||||
new Option(3L, "Succeeded", "Change request has succeeded."),
|
||||
1,
|
||||
"3116784158f0af2d-24076@api.gogrid.com",
|
||||
Arrays.asList(
|
||||
new JobState(940263L, new Date(1267404528897L),
|
||||
new Option(7L, "Created",
|
||||
"Change request is created but not queued yet"), null),
|
||||
new JobState(940264L, new Date(1267404528967L),
|
||||
new Option(1L, "Queued",
|
||||
"Change request is new to the system."), null)
|
||||
),
|
||||
details);
|
||||
assertEquals(job, Iterables.getOnlyElement(response));
|
||||
}
|
||||
|
||||
|
||||
Injector i = Guice.createInjector(new ParserModule() {
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(DateAdapter.class).to(GoGridContextModule.DateSecondsAdapter.class);
|
||||
super.configure();
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
@com.google.inject.name.Named(Constants.PROPERTY_GSON_ADAPTERS)
|
||||
public Map<Class, Object> provideCustomAdapterBindings() {
|
||||
Map<Class, Object> bindings = Maps.newHashMap();
|
||||
bindings.put(ObjectType.class, new CustomDeserializers.ObjectTypeAdapter());
|
||||
return bindings;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,105 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed 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.functions;
|
||||
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.Provides;
|
||||
import org.jclouds.Constants;
|
||||
import org.jclouds.gogrid.config.GoGridContextModule;
|
||||
import org.jclouds.gogrid.domain.*;
|
||||
import org.jclouds.gogrid.functions.internal.CustomDeserializers;
|
||||
import org.jclouds.http.functions.config.ParserModule;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
import java.io.InputStream;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Map;
|
||||
import java.util.SortedSet;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* @author Oleksiy Yarmula
|
||||
*/
|
||||
@Test(groups = "unit", testName = "gogrid.ParseLoadBalancersFromJsonResponseTest")
|
||||
public class ParseLoadBalancersFromJsonResponseTest {
|
||||
|
||||
@Test
|
||||
public void testApplyInputStreamDetails() throws UnknownHostException {
|
||||
InputStream is = getClass().getResourceAsStream("/test_get_load_balancer_list.json");
|
||||
|
||||
ParseLoadBalancerListFromJsonResponse parser = new ParseLoadBalancerListFromJsonResponse(i
|
||||
.getInstance(Gson.class));
|
||||
SortedSet<LoadBalancer> response = parser.apply(is);
|
||||
|
||||
LoadBalancer loadBalancer = new LoadBalancer(6372L,
|
||||
"Balancer", null, new IpPortPair(new Ip(1313082L,
|
||||
"204.51.240.181",
|
||||
"204.51.240.176/255.255.255.240",
|
||||
true,
|
||||
IpState.ASSIGNED),
|
||||
80),
|
||||
Arrays.asList(
|
||||
new IpPortPair(new Ip(1313086L,
|
||||
"204.51.240.185",
|
||||
"204.51.240.176/255.255.255.240",
|
||||
true,
|
||||
IpState.ASSIGNED),
|
||||
80),
|
||||
new IpPortPair(new Ip(1313089L,
|
||||
"204.51.240.188",
|
||||
"204.51.240.176/255.255.255.240",
|
||||
true,
|
||||
IpState.ASSIGNED),
|
||||
80)
|
||||
),
|
||||
LoadBalancerType.ROUND_ROBIN,
|
||||
LoadBalancerPersistenceType.NONE,
|
||||
LoadBalancerOs.F5,
|
||||
LoadBalancerState.ON);
|
||||
assertEquals(Iterables.getOnlyElement(response), loadBalancer);
|
||||
}
|
||||
|
||||
Injector i = Guice.createInjector(new ParserModule() {
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(DateAdapter.class).to(GoGridContextModule.DateSecondsAdapter.class);
|
||||
super.configure();
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
@com.google.inject.name.Named(Constants.PROPERTY_GSON_ADAPTERS)
|
||||
public Map<Class, Object> provideCustomAdapterBindings() {
|
||||
Map<Class, Object> bindings = Maps.newHashMap();
|
||||
bindings.put(LoadBalancerOs.class, new CustomDeserializers.LoadBalancerOsAdapter());
|
||||
bindings.put(LoadBalancerState.class, new CustomDeserializers.LoadBalancerStateAdapter());
|
||||
bindings.put(LoadBalancerPersistenceType.class, new CustomDeserializers.LoadBalancerPersistenceTypeAdapter());
|
||||
bindings.put(LoadBalancerType.class, new CustomDeserializers.LoadBalancerTypeAdapter());
|
||||
bindings.put(IpState.class, new CustomDeserializers.IpStateAdapter());
|
||||
return bindings;
|
||||
}
|
||||
});
|
||||
}
|
|
@ -29,11 +29,16 @@ import java.io.InputStream;
|
|||
import java.net.UnknownHostException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
import java.util.SortedSet;
|
||||
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.inject.Provides;
|
||||
import org.jclouds.Constants;
|
||||
import org.jclouds.gogrid.config.GoGridContextModule;
|
||||
import org.jclouds.gogrid.domain.*;
|
||||
import org.jclouds.gogrid.functions.internal.CustomDeserializers;
|
||||
import org.jclouds.http.functions.config.ParserModule;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
|
@ -41,22 +46,17 @@ import com.google.gson.Gson;
|
|||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
|
||||
/**
|
||||
* Tests behavior of {@code ParseStatusesFromJsonResponse}
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Test(groups = "unit", testName = "twitter.ParseStatusesFromJsonResponseTest")
|
||||
public class ParseStatusesFromJsonResponseTest {
|
||||
|
||||
Injector i = Guice.createInjector(new ParserModule() {
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(DateAdapter.class).to(GoGridContextModule.DateSecondsAdapter.class);
|
||||
super.configure();
|
||||
}
|
||||
});
|
||||
@Test(groups = "unit", testName = "gogrid.ParseServersFromJsonResponseTest")
|
||||
public class ParseServersFromJsonResponseTest {
|
||||
|
||||
@Test
|
||||
public void testApplyInputStreamDetails() throws UnknownHostException {
|
||||
InputStream is = getClass().getResourceAsStream("/test_get_server_list.json");
|
||||
|
||||
|
@ -72,7 +72,7 @@ public class ParseStatusesFromJsonResponseTest {
|
|||
new Option(1L, "512MB", "Server with 512MB RAM"),
|
||||
centOs,
|
||||
new Ip(1313079L, "204.51.240.178", "204.51.240.176/255.255.255.240", true,
|
||||
new Option(2L, "Assigned", "IP is reserved or in use")),
|
||||
IpState.ASSIGNED),
|
||||
new ServerImage(1946L, "GSI-f8979644-e646-4711-ad58-d98a5fa3612c",
|
||||
"BitNami Gallery 2.3.1-0", "http://bitnami.org/stack/gallery",
|
||||
centOs, null, webServer,
|
||||
|
@ -88,4 +88,23 @@ public class ParseStatusesFromJsonResponseTest {
|
|||
new Customer(24732L, "BitRock")));
|
||||
assertEquals(Iterables.getOnlyElement(response), server);
|
||||
}
|
||||
|
||||
|
||||
Injector i = Guice.createInjector(new ParserModule() {
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(DateAdapter.class).to(GoGridContextModule.DateSecondsAdapter.class);
|
||||
super.configure();
|
||||
}
|
||||
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
@com.google.inject.name.Named(Constants.PROPERTY_GSON_ADAPTERS)
|
||||
public Map<Class, Object> provideCustomAdapterBindings() {
|
||||
Map<Class, Object> bindings = Maps.newHashMap();
|
||||
bindings.put(IpState.class, new CustomDeserializers.IpStateAdapter());
|
||||
return bindings;
|
||||
}
|
||||
});
|
||||
}
|
|
@ -0,0 +1,109 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed 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 com.google.common.collect.Iterables;
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.Module;
|
||||
import com.google.inject.Provides;
|
||||
import com.google.inject.TypeLiteral;
|
||||
import org.jclouds.encryption.EncryptionService;
|
||||
import org.jclouds.gogrid.GoGrid;
|
||||
import org.jclouds.gogrid.filters.SharedKeyLiteAuthentication;
|
||||
import org.jclouds.gogrid.functions.ParseLoadBalancerListFromJsonResponse;
|
||||
import org.jclouds.logging.Logger;
|
||||
import org.jclouds.rest.RestClientTest;
|
||||
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
||||
import org.jclouds.rest.internal.RestAnnotationProcessor;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.URI;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* @author Oleksiy Yarmula
|
||||
*/
|
||||
public class GridLoadBalancerAsyncClientTest extends RestClientTest<GridLoadBalancerAsyncClient> {
|
||||
|
||||
@Test
|
||||
public void testGetAssignedIpList() throws NoSuchMethodException, IOException {
|
||||
Method method = GridLoadBalancerAsyncClient.class.getMethod("getLoadBalancerList");
|
||||
GeneratedHttpRequest<GridLoadBalancerAsyncClient> httpRequest = processor.createRequest(method);
|
||||
|
||||
assertRequestLineEquals(httpRequest,
|
||||
"GET https://api.gogrid.com/api/grid/loadbalancer/list?v=1.4 HTTP/1.1");
|
||||
assertHeadersEqual(httpRequest, "");
|
||||
assertPayloadEquals(httpRequest, null);
|
||||
|
||||
assertResponseParserClassEquals(method, httpRequest, ParseLoadBalancerListFromJsonResponse.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, null);
|
||||
|
||||
checkFilters(httpRequest);
|
||||
Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest);
|
||||
|
||||
assertRequestLineEquals(httpRequest,
|
||||
"GET https://api.gogrid.com/api/grid/loadbalancer/list?v=1.4&" +
|
||||
"sig=3f446f171455fbb5574aecff4997b273&api_key=foo " +
|
||||
"HTTP/1.1");
|
||||
assertHeadersEqual(httpRequest, "");
|
||||
assertPayloadEquals(httpRequest, null);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void checkFilters(GeneratedHttpRequest<GridLoadBalancerAsyncClient> httpMethod) {
|
||||
assertEquals(httpMethod.getFilters().size(), 1);
|
||||
assertEquals(httpMethod.getFilters().get(0).getClass(), SharedKeyLiteAuthentication.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected TypeLiteral<RestAnnotationProcessor<GridLoadBalancerAsyncClient>> createTypeLiteral() {
|
||||
return new TypeLiteral<RestAnnotationProcessor<GridLoadBalancerAsyncClient>>() {
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Module createModule() {
|
||||
return new AbstractModule() {
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(URI.class).annotatedWith(GoGrid.class).toInstance(
|
||||
URI.create("https://api.gogrid.com/api"));
|
||||
bind(Logger.LoggerFactory.class).toInstance(new Logger.LoggerFactory() {
|
||||
public Logger getLogger(String category) {
|
||||
return Logger.NULL;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
public SharedKeyLiteAuthentication provideAuthentication(EncryptionService encryptionService)
|
||||
throws UnsupportedEncodingException {
|
||||
return new SharedKeyLiteAuthentication("foo", "bar", 1267243795L, encryptionService);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
|
@ -0,0 +1,67 @@
|
|||
{
|
||||
"list": [
|
||||
{
|
||||
"object": "job",
|
||||
"command": {
|
||||
"object": "option",
|
||||
"description": "Delete Virtual Server",
|
||||
"name": "DeleteVirtualServer",
|
||||
"id": 7
|
||||
},
|
||||
"currentstate": {
|
||||
"object": "option",
|
||||
"description": "Change request has succeeded.",
|
||||
"name": "Succeeded",
|
||||
"id": 3
|
||||
},
|
||||
"owner": "3116784158f0af2d-24076@api.gogrid.com",
|
||||
"objecttype": {
|
||||
"object": "option",
|
||||
"description": null,
|
||||
"name": "VirtualServer",
|
||||
"id": 1
|
||||
},
|
||||
"detail": {
|
||||
"type": "virtual_server",
|
||||
"description": null,
|
||||
"image": "GSI-f8979644-e646-4711-ad58-d98a5fa3612c",
|
||||
"name": "ServerCreated40562",
|
||||
"ip": "204.51.240.189"
|
||||
},
|
||||
"history": [
|
||||
{
|
||||
"state": {
|
||||
"object": "option",
|
||||
"description": "Change request is created but not queued yet",
|
||||
"name": "Created",
|
||||
"id": 7
|
||||
},
|
||||
"id": 940263,
|
||||
"updatedon": 1267404528897
|
||||
},
|
||||
{
|
||||
"state": {
|
||||
"object": "option",
|
||||
"description": "Change request is new to the system.",
|
||||
"name": "Queued",
|
||||
"id": 1
|
||||
},
|
||||
"id": 940264,
|
||||
"updatedon": 1267404528967
|
||||
}
|
||||
],
|
||||
"attempts": 1,
|
||||
"createdon": 1267404528895,
|
||||
"lastupdatedon": 1267404538592,
|
||||
"id": 250628
|
||||
}
|
||||
],
|
||||
"summary": {
|
||||
"total": 68,
|
||||
"start": 0,
|
||||
"numpages": 14,
|
||||
"returned": 5
|
||||
},
|
||||
"status": "success",
|
||||
"method": "/grid/job/list"
|
||||
}
|
|
@ -0,0 +1,92 @@
|
|||
{
|
||||
"list": [
|
||||
{
|
||||
"object": "loadbalancer",
|
||||
"virtualip": {
|
||||
"object": "ipportpair",
|
||||
"ip": {
|
||||
"object": "ip",
|
||||
"public": true,
|
||||
"subnet": "204.51.240.176/255.255.255.240",
|
||||
"state": {
|
||||
"object": "option",
|
||||
"description": "IP is reserved or in use",
|
||||
"name": "Assigned",
|
||||
"id": 2
|
||||
},
|
||||
"ip": "204.51.240.181",
|
||||
"id": 1313082
|
||||
},
|
||||
"port": 80
|
||||
},
|
||||
"type": {
|
||||
"object": "option",
|
||||
"description": "",
|
||||
"name": "Round Robin",
|
||||
"id": 1
|
||||
},
|
||||
"os": {
|
||||
"object": "option",
|
||||
"description": "The F5 Load Balancer.",
|
||||
"name": "F5",
|
||||
"id": 1
|
||||
},
|
||||
"state": {
|
||||
"object": "option",
|
||||
"description": "Loadbalancer is enabled and on.",
|
||||
"name": "On",
|
||||
"id": 1
|
||||
},
|
||||
"name": "Balancer",
|
||||
"realiplist": [
|
||||
{
|
||||
"ip": {
|
||||
"object": "ip",
|
||||
"public": true,
|
||||
"subnet": "204.51.240.176/255.255.255.240",
|
||||
"state": {
|
||||
"object": "option",
|
||||
"description": "IP is reserved or in use",
|
||||
"name": "Assigned",
|
||||
"id": 2
|
||||
},
|
||||
"ip": "204.51.240.185",
|
||||
"id": 1313086
|
||||
},
|
||||
"port": 80
|
||||
},
|
||||
{
|
||||
"ip": {
|
||||
"object": "ip",
|
||||
"public": true,
|
||||
"subnet": "204.51.240.176/255.255.255.240",
|
||||
"state": {
|
||||
"object": "option",
|
||||
"description": "IP is reserved or in use",
|
||||
"name": "Assigned",
|
||||
"id": 2
|
||||
},
|
||||
"ip": "204.51.240.188",
|
||||
"id": 1313089
|
||||
},
|
||||
"port": 80
|
||||
}
|
||||
],
|
||||
"id": 6372,
|
||||
"persistence": {
|
||||
"object": "option",
|
||||
"description": "",
|
||||
"name": "None",
|
||||
"id": 1
|
||||
}
|
||||
}
|
||||
],
|
||||
"summary": {
|
||||
"total": 1,
|
||||
"start": 0,
|
||||
"numpages": 0,
|
||||
"returned": 1
|
||||
},
|
||||
"status": "success",
|
||||
"method": "/grid/loadbalancer/list"
|
||||
}
|
Loading…
Reference in New Issue