mirror of https://github.com/apache/jclouds.git
Merge branch 'master' of git@github.com:jclouds/jclouds
This commit is contained in:
commit
4747272667
|
@ -125,5 +125,9 @@ public interface Constants {
|
||||||
* Name of the logger that records the steps of the request signing process of the HTTP_service.
|
* 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";
|
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.lang.reflect.Type;
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
import java.util.Comparator;
|
import java.util.*;
|
||||||
import java.util.Date;
|
|
||||||
import java.util.SortedSet;
|
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
import javax.xml.parsers.SAXParser;
|
import javax.xml.parsers.SAXParser;
|
||||||
import javax.xml.parsers.SAXParserFactory;
|
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.date.DateService;
|
||||||
import org.jclouds.http.functions.ParseSax;
|
import org.jclouds.http.functions.ParseSax;
|
||||||
import org.jclouds.http.functions.ParseSax.HandlerWithResult;
|
import org.jclouds.http.functions.ParseSax.HandlerWithResult;
|
||||||
|
@ -127,12 +128,16 @@ public class ParserModule extends AbstractModule {
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
Gson provideGson(DateAdapter adapter, SortedSetOfInetAddressCreator addressSetCreator) {
|
Gson provideGson(DateAdapter adapter, SortedSetOfInetAddressCreator addressSetCreator,
|
||||||
|
GsonAdapterBindings bindings) {
|
||||||
GsonBuilder gson = new GsonBuilder();
|
GsonBuilder gson = new GsonBuilder();
|
||||||
gson.registerTypeAdapter(InetAddress.class, new InetAddressAdapter());
|
gson.registerTypeAdapter(InetAddress.class, new InetAddressAdapter());
|
||||||
gson.registerTypeAdapter(Date.class, adapter);
|
gson.registerTypeAdapter(Date.class, adapter);
|
||||||
gson.registerTypeAdapter(new TypeToken<SortedSet<InetAddress>>() {
|
gson.registerTypeAdapter(new TypeToken<SortedSet<InetAddress>>() {
|
||||||
}.getType(), addressSetCreator);
|
}.getType(), addressSetCreator);
|
||||||
|
for(Map.Entry<Class, Object> binding : bindings.getBindings().entrySet()) {
|
||||||
|
gson.registerTypeAdapter(binding.getKey(), binding.getValue());
|
||||||
|
}
|
||||||
return gson.create();
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -435,22 +435,27 @@ public class RestAnnotationProcessor<T> {
|
||||||
Multimap<String, String> map = LinkedListMultimap.create();
|
Multimap<String, String> map = LinkedListMultimap.create();
|
||||||
if (in == null) {
|
if (in == null) {
|
||||||
} else if (in.indexOf('&') == -1) {
|
} else if (in.indexOf('&') == -1) {
|
||||||
map.put(in, null);
|
if(in.contains("=")) parseKeyValueFromStringToMap(in, map);
|
||||||
|
else map.put(in, null);
|
||||||
} else {
|
} else {
|
||||||
String[] parts = HttpUtils.urlDecode(in).split("&");
|
String[] parts = HttpUtils.urlDecode(in).split("&");
|
||||||
for (int partIndex = 0; partIndex < parts.length; partIndex++) {
|
for(String part : parts) {
|
||||||
// note that '=' can be a valid part of the value
|
parseKeyValueFromStringToMap(part, map);
|
||||||
int indexOfFirstEquals = parts[partIndex].indexOf('=');
|
|
||||||
String key = indexOfFirstEquals == -1 ? parts[partIndex] : parts[partIndex].substring(
|
|
||||||
0, indexOfFirstEquals);
|
|
||||||
String value = indexOfFirstEquals == -1 ? null : parts[partIndex]
|
|
||||||
.substring(indexOfFirstEquals + 1);
|
|
||||||
map.put(key, value);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void parseKeyValueFromStringToMap(String stringToParse, Multimap<String, String> map) {
|
||||||
|
// note that '=' can be a valid part of the value
|
||||||
|
int indexOfFirstEquals = stringToParse.indexOf('=');
|
||||||
|
String key = indexOfFirstEquals == -1 ? stringToParse : stringToParse.substring(
|
||||||
|
0, indexOfFirstEquals);
|
||||||
|
String value = indexOfFirstEquals == -1 ? null : stringToParse
|
||||||
|
.substring(indexOfFirstEquals + 1);
|
||||||
|
map.put(key, value);
|
||||||
|
}
|
||||||
|
|
||||||
public static SortedSet<Entry<String, String>> sortEntries(
|
public static SortedSet<Entry<String, String>> sortEntries(
|
||||||
Collection<Map.Entry<String, String>> in, Comparator<Map.Entry<String, String>> sorter) {
|
Collection<Map.Entry<String, String>> in, Comparator<Map.Entry<String, String>> sorter) {
|
||||||
SortedSet<Entry<String, String>> entries = Sets.newTreeSet(sorter);
|
SortedSet<Entry<String, String>> entries = Sets.newTreeSet(sorter);
|
||||||
|
|
|
@ -56,6 +56,7 @@ import javax.ws.rs.Produces;
|
||||||
import javax.ws.rs.QueryParam;
|
import javax.ws.rs.QueryParam;
|
||||||
import javax.ws.rs.core.MediaType;
|
import javax.ws.rs.core.MediaType;
|
||||||
|
|
||||||
|
import com.google.common.collect.*;
|
||||||
import org.jclouds.PropertiesBuilder;
|
import org.jclouds.PropertiesBuilder;
|
||||||
import org.jclouds.concurrent.config.ExecutorServiceModule;
|
import org.jclouds.concurrent.config.ExecutorServiceModule;
|
||||||
import org.jclouds.date.DateService;
|
import org.jclouds.date.DateService;
|
||||||
|
@ -105,11 +106,6 @@ import org.testng.annotations.DataProvider;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
import com.google.common.base.Function;
|
||||||
import com.google.common.collect.ImmutableMap;
|
|
||||||
import com.google.common.collect.ImmutableMultimap;
|
|
||||||
import com.google.common.collect.LinkedHashMultimap;
|
|
||||||
import com.google.common.collect.LinkedListMultimap;
|
|
||||||
import com.google.common.collect.Multimap;
|
|
||||||
import com.google.common.util.concurrent.ListenableFuture;
|
import com.google.common.util.concurrent.ListenableFuture;
|
||||||
import com.google.inject.AbstractModule;
|
import com.google.inject.AbstractModule;
|
||||||
import com.google.inject.Guice;
|
import com.google.inject.Guice;
|
||||||
|
@ -820,6 +816,30 @@ public class RestAnnotationProcessorTest {
|
||||||
assertEquals(query, "x-amz-copy-source=/robot");
|
assertEquals(query, "x-amz-copy-source=/robot");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testParseQueryToMapSingleParam() {
|
||||||
|
Multimap<String, String> parsedMap = RestAnnotationProcessor.parseQueryToMap("v=1.3");
|
||||||
|
assert parsedMap.keySet().size() == 1 : "Expected 1 key, found: " + parsedMap.keySet().size();
|
||||||
|
assert parsedMap.keySet().contains("v") : "Expected v to be a part of the keys";
|
||||||
|
String valueForV = Iterables.getOnlyElement(parsedMap.get("v"));
|
||||||
|
assert valueForV.equals("1.3") :
|
||||||
|
"Expected the value for 'v' to be '1.3', found: " + valueForV;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testParseQueryToMapMultiParam() {
|
||||||
|
Multimap<String, String> parsedMap = RestAnnotationProcessor.parseQueryToMap("v=1.3&sig=123");
|
||||||
|
assert parsedMap.keySet().size() == 2 : "Expected 2 keys, found: " + parsedMap.keySet().size();
|
||||||
|
assert parsedMap.keySet().contains("v") : "Expected v to be a part of the keys";
|
||||||
|
assert parsedMap.keySet().contains("sig") : "Expected sig to be a part of the keys";
|
||||||
|
String valueForV = Iterables.getOnlyElement(parsedMap.get("v"));
|
||||||
|
assert valueForV.equals("1.3") :
|
||||||
|
"Expected the value for 'v' to be '1.3', found: " + valueForV;
|
||||||
|
String valueForSig = Iterables.getOnlyElement(parsedMap.get("sig"));
|
||||||
|
assert valueForSig.equals("123") :
|
||||||
|
"Expected the value for 'v' to be '123', found: " + valueForSig;
|
||||||
|
}
|
||||||
|
|
||||||
@Endpoint(Localhost.class)
|
@Endpoint(Localhost.class)
|
||||||
private interface TestMapMatrixParams {
|
private interface TestMapMatrixParams {
|
||||||
@POST
|
@POST
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
target
|
||||||
|
.settings
|
||||||
|
.classpath
|
||||||
|
.project
|
||||||
|
jclouds-gogrid.iml
|
||||||
|
jclouds-gogrid.ipr
|
||||||
|
jclouds-gogrid.iws
|
|
@ -0,0 +1,76 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!--
|
||||||
|
$HeadURL$
|
||||||
|
$Revision$
|
||||||
|
$Date$
|
||||||
|
|
||||||
|
Copyright (C) 2010 Cloud Conscious, LLC <info@cloudconscious.com>
|
||||||
|
|
||||||
|
====================================================================
|
||||||
|
Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
or more contributor license agreements. See the NOTICE file
|
||||||
|
distributed with this work for additional information
|
||||||
|
regarding copyright ownership. The ASF 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.html
|
||||||
|
|
||||||
|
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.
|
||||||
|
====================================================================
|
||||||
|
--><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||||
|
<parent>
|
||||||
|
<groupId>org.jclouds</groupId>
|
||||||
|
<artifactId>jclouds-multi</artifactId>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
<relativePath>../pom.xml</relativePath>
|
||||||
|
</parent>
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<groupId>org.jclouds</groupId>
|
||||||
|
<artifactId>jclouds-gogrid</artifactId>
|
||||||
|
<name>jclouds GoGrid core</name>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
<description>jclouds components to access GoGrid</description>
|
||||||
|
|
||||||
|
<scm>
|
||||||
|
<connection>scm:svn:http://jclouds.googlecode.com/svn/trunk/gogrid</connection>
|
||||||
|
<developerConnection>scm:svn:https://jclouds.googlecode.com/svn/trunk/gogrid</developerConnection>
|
||||||
|
<url>http://jclouds.googlecode.com/svn/trunk/gogrid</url>
|
||||||
|
</scm>
|
||||||
|
<properties>
|
||||||
|
<jclouds.test.user>apiKey</jclouds.test.user>
|
||||||
|
<jclouds.test.key>secret</jclouds.test.key>
|
||||||
|
</properties>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>${project.groupId}</groupId>
|
||||||
|
<artifactId>jclouds-core</artifactId>
|
||||||
|
<version>${project.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>${project.groupId}</groupId>
|
||||||
|
<artifactId>jclouds-core</artifactId>
|
||||||
|
<version>${project.version}</version>
|
||||||
|
<type>test-jar</type>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>log4j</groupId>
|
||||||
|
<artifactId>log4j</artifactId>
|
||||||
|
<version>1.2.14</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>${project.groupId}</groupId>
|
||||||
|
<artifactId>jclouds-log4j</artifactId>
|
||||||
|
<version>${project.version}</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</project>
|
|
@ -0,0 +1,44 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||||
|
*
|
||||||
|
* ====================================================================
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF 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;
|
||||||
|
|
||||||
|
import java.lang.annotation.ElementType;
|
||||||
|
import java.lang.annotation.Retention;
|
||||||
|
import java.lang.annotation.RetentionPolicy;
|
||||||
|
import java.lang.annotation.Target;
|
||||||
|
|
||||||
|
import javax.inject.Qualifier;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Related to a GoGrid resource.
|
||||||
|
*
|
||||||
|
* @author Adrian Cole
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@Retention(value = RetentionPolicy.RUNTIME)
|
||||||
|
@Target(value = { ElementType.FIELD, ElementType.PARAMETER, ElementType.METHOD })
|
||||||
|
@Qualifier
|
||||||
|
public @interface GoGrid {
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,61 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||||
|
*
|
||||||
|
* ====================================================================
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF 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;
|
||||||
|
|
||||||
|
import com.google.inject.ImplementedBy;
|
||||||
|
import org.jclouds.gogrid.internal.GoGridAsyncClientImpl;
|
||||||
|
import org.jclouds.gogrid.services.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Oleksiy Yarmula
|
||||||
|
*/
|
||||||
|
@ImplementedBy(GoGridAsyncClientImpl.class)
|
||||||
|
public interface GoGridAsyncClient {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see GoGridClient#getServerServices()
|
||||||
|
*/
|
||||||
|
GridServerAsyncClient getServerServices();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see GoGridClient#getJobServices()
|
||||||
|
*/
|
||||||
|
GridJobAsyncClient getJobServices();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see GoGridClient#getIpServices()
|
||||||
|
*/
|
||||||
|
GridIpAsyncClient getIpServices();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see GoGridClient#getLoadBalancerServices()
|
||||||
|
*/
|
||||||
|
GridLoadBalancerAsyncClient getLoadBalancerServices();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see GoGridClient#getImageServices()
|
||||||
|
*/
|
||||||
|
GridImageAsyncClient getImageServices();
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,62 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||||
|
*
|
||||||
|
* ====================================================================
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF 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;
|
||||||
|
|
||||||
|
import com.google.inject.ImplementedBy;
|
||||||
|
import org.jclouds.gogrid.internal.GoGridClientImpl;
|
||||||
|
import org.jclouds.gogrid.services.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Oleksiy Yarmula
|
||||||
|
*/
|
||||||
|
@ImplementedBy(GoGridClientImpl.class)
|
||||||
|
|
||||||
|
public interface GoGridClient {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Services with methods, related to managing servers
|
||||||
|
*/
|
||||||
|
GridServerClient getServerServices();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Services with methods, related to retrieving jobs
|
||||||
|
*/
|
||||||
|
GridJobClient getJobServices();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Services with methods, related to retrieving IP addresses
|
||||||
|
*/
|
||||||
|
GridIpClient getIpServices();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Services with methods, related to managing load balancers.
|
||||||
|
*/
|
||||||
|
GridLoadBalancerClient getLoadBalancerServices();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Services with methods, related to managing images.
|
||||||
|
*/
|
||||||
|
GridImageClient getImageServices();
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,62 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||||
|
*
|
||||||
|
* ====================================================================
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF 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;
|
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
|
import org.jclouds.rest.RestContextBuilder;
|
||||||
|
import org.jclouds.gogrid.config.GoGridContextModule;
|
||||||
|
import org.jclouds.gogrid.config.GoGridRestClientModule;
|
||||||
|
import org.jclouds.gogrid.reference.GoGridConstants;
|
||||||
|
|
||||||
|
import com.google.inject.Module;
|
||||||
|
import com.google.inject.TypeLiteral;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Adrian Cole
|
||||||
|
*/
|
||||||
|
public class GoGridContextBuilder extends RestContextBuilder<GoGridAsyncClient, GoGridClient> {
|
||||||
|
|
||||||
|
public GoGridContextBuilder(Properties props) {
|
||||||
|
super(new TypeLiteral<GoGridAsyncClient>() {
|
||||||
|
}, new TypeLiteral<GoGridClient>() {
|
||||||
|
}, props);
|
||||||
|
checkNotNull(properties.getProperty(GoGridConstants.PROPERTY_GOGRID_USER));
|
||||||
|
checkNotNull(properties.getProperty(GoGridConstants.PROPERTY_GOGRID_PASSWORD));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void addClientModule(List<Module> modules) {
|
||||||
|
modules.add(new GoGridRestClientModule());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void addContextModule(List<Module> modules) {
|
||||||
|
modules.add(new GoGridContextModule());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,66 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||||
|
*
|
||||||
|
* ====================================================================
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF 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;
|
||||||
|
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
|
import org.jclouds.gogrid.services.GridServerAsyncClient;
|
||||||
|
import org.jclouds.gogrid.services.GridServerClient;
|
||||||
|
import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule;
|
||||||
|
import org.jclouds.logging.jdk.config.JDKLoggingModule;
|
||||||
|
import org.jclouds.rest.RestContext;
|
||||||
|
|
||||||
|
import com.google.inject.Module;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates {@link RestContext} for {@link GridServerClient} instances based on the most commonly
|
||||||
|
* requested arguments.
|
||||||
|
* <p/>
|
||||||
|
* Note that Threadsafe objects will be bound as singletons to the Injector or Context provided.
|
||||||
|
* <p/>
|
||||||
|
* <p/>
|
||||||
|
* If no <code>Module</code>s are specified, the default {@link JDKLoggingModule logging} and
|
||||||
|
* {@link JavaUrlHttpCommandExecutorServiceModule http transports} will be installed.
|
||||||
|
*
|
||||||
|
* @author Adrian Cole
|
||||||
|
* @author Oleksiy Yarmula
|
||||||
|
*
|
||||||
|
* @see RestContext
|
||||||
|
* @see GridServerClient
|
||||||
|
* @see GridServerAsyncClient
|
||||||
|
*/
|
||||||
|
public class GoGridContextFactory {
|
||||||
|
|
||||||
|
public static RestContext<GoGridAsyncClient, GoGridClient> createContext(String user, String password,
|
||||||
|
Module... modules) {
|
||||||
|
return new GoGridContextBuilder(new GoGridPropertiesBuilder(user, password).build())
|
||||||
|
.withModules(modules).buildContext();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static RestContext<GoGridAsyncClient, GoGridClient> createContext(Properties properties, Module... modules) {
|
||||||
|
return new GoGridContextBuilder(new GoGridPropertiesBuilder(properties).build())
|
||||||
|
.withModules(modules).buildContext();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,89 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* 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>
|
||||||
|
*
|
||||||
|
* ====================================================================
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF 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;
|
||||||
|
|
||||||
|
import org.jclouds.PropertiesBuilder;
|
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
import static org.jclouds.gogrid.reference.GoGridConstants.*;
|
||||||
|
|
||||||
|
import java.net.URI;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Builds properties used in GoGrid Clients
|
||||||
|
*
|
||||||
|
* @author Adrian Cole
|
||||||
|
* @author Oleksiy Yarmula
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class GoGridPropertiesBuilder extends PropertiesBuilder {
|
||||||
|
@Override
|
||||||
|
protected Properties defaultProperties() {
|
||||||
|
Properties properties = super.defaultProperties();
|
||||||
|
properties.setProperty(PROPERTY_GOGRID_ENDPOINT, "https://api.gogrid.com/api");
|
||||||
|
properties.setProperty(PROPERTY_GOGRID_SESSIONINTERVAL, 60 + "");
|
||||||
|
|
||||||
|
return properties;
|
||||||
|
}
|
||||||
|
|
||||||
|
public GoGridPropertiesBuilder(Properties properties) {
|
||||||
|
super(properties);
|
||||||
|
}
|
||||||
|
|
||||||
|
public GoGridPropertiesBuilder(String id, String secret) {
|
||||||
|
super();
|
||||||
|
withCredentials(id, secret);
|
||||||
|
}
|
||||||
|
|
||||||
|
public GoGridPropertiesBuilder withCredentials(String id, String secret) {
|
||||||
|
properties.setProperty(PROPERTY_GOGRID_USER, checkNotNull(id, "user"));
|
||||||
|
properties.setProperty(PROPERTY_GOGRID_PASSWORD, checkNotNull(secret, "password"));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public GoGridPropertiesBuilder withEndpoint(URI endpoint) {
|
||||||
|
properties.setProperty(PROPERTY_GOGRID_ENDPOINT, checkNotNull(endpoint, "endpoint")
|
||||||
|
.toString());
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,66 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||||
|
*
|
||||||
|
* ====================================================================
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF 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;
|
||||||
|
|
||||||
|
import org.jclouds.gogrid.domain.internal.ErrorResponse;
|
||||||
|
import org.jclouds.http.HttpCommand;
|
||||||
|
import org.jclouds.http.HttpResponse;
|
||||||
|
import org.jclouds.http.HttpResponseException;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import static java.lang.String.format;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Oleksiy Yarmula
|
||||||
|
*/
|
||||||
|
public class GoGridResponseException extends HttpResponseException {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1924589L;
|
||||||
|
|
||||||
|
private Set<ErrorResponse> errors;
|
||||||
|
|
||||||
|
public GoGridResponseException(HttpCommand command, HttpResponse response, Set<ErrorResponse> errors) {
|
||||||
|
super(buildMessage(command, response, errors), command, response);
|
||||||
|
this.setErrors(errors);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Set<ErrorResponse> getError() {
|
||||||
|
return errors;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setErrors(Set<ErrorResponse> errors) {
|
||||||
|
this.errors = errors;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String buildMessage(HttpCommand command, HttpResponse response, Set<ErrorResponse> errors) {
|
||||||
|
StringBuilder builder = new StringBuilder();
|
||||||
|
builder.append(format("command %s failed with code %s. ", command.toString(),
|
||||||
|
response.getStatusCode()));
|
||||||
|
for(ErrorResponse error : errors) {
|
||||||
|
builder.append(format("Error [%s]: %s. ", error.getErrorCode(), error.getMessage()));
|
||||||
|
}
|
||||||
|
return builder.toString();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,71 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||||
|
*
|
||||||
|
* ====================================================================
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF 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.binders;
|
||||||
|
|
||||||
|
import org.jclouds.http.HttpRequest;
|
||||||
|
import org.jclouds.rest.Binder;
|
||||||
|
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.checkArgument;
|
||||||
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
|
import static org.jclouds.gogrid.reference.GoGridQueryParams.ID_KEY;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Binds IDs to corresponding query parameters
|
||||||
|
*
|
||||||
|
* @author Oleksiy Yarmula
|
||||||
|
*/
|
||||||
|
public class BindIdsToQueryParams implements Binder {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Binds the ids to query parameters. The pattern, as
|
||||||
|
* specified by GoGrid's specification, is:
|
||||||
|
*
|
||||||
|
* https://api.gogrid.com/api/grid/server/get
|
||||||
|
* ?id=5153
|
||||||
|
* &id=3232
|
||||||
|
*
|
||||||
|
* @param request
|
||||||
|
* request where the query params will be set
|
||||||
|
* @param input array of String params
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void bindToRequest(HttpRequest request, Object input) {
|
||||||
|
checkArgument(checkNotNull(request, "request is null") instanceof GeneratedHttpRequest,
|
||||||
|
"this binder is only valid for GeneratedHttpRequests!");
|
||||||
|
checkArgument(checkNotNull(input, "input is null") instanceof Long[],
|
||||||
|
"this binder is only valid for Long[] arguments");
|
||||||
|
|
||||||
|
Long[] names = (Long[]) input;
|
||||||
|
GeneratedHttpRequest generatedRequest = (GeneratedHttpRequest) request;
|
||||||
|
|
||||||
|
for(Long id : names) {
|
||||||
|
generatedRequest.addQueryParam(ID_KEY, checkNotNull(id.toString(),
|
||||||
|
/*or throw*/ "id must have a non-null value"));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,70 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||||
|
*
|
||||||
|
* ====================================================================
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF 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.binders;
|
||||||
|
|
||||||
|
import org.jclouds.http.HttpRequest;
|
||||||
|
import org.jclouds.rest.Binder;
|
||||||
|
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.checkArgument;
|
||||||
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
|
import static org.jclouds.gogrid.reference.GoGridQueryParams.NAME_KEY;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Binds names to corresponding query parameters
|
||||||
|
|
||||||
|
* @author Oleksiy Yarmula
|
||||||
|
*/
|
||||||
|
public class BindNamesToQueryParams implements Binder {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Binds the names to query parameters. The pattern, as
|
||||||
|
* specified by GoGrid's specification, is:
|
||||||
|
*
|
||||||
|
* https://api.gogrid.com/api/grid/server/get
|
||||||
|
* ?name=My+Server
|
||||||
|
* &name=My+Server+2
|
||||||
|
* &name=My+Server+3
|
||||||
|
* &name=My+Server+4
|
||||||
|
* @param request
|
||||||
|
* request where the query params will be set
|
||||||
|
* @param input array of String params
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void bindToRequest(HttpRequest request, Object input) {
|
||||||
|
checkArgument(checkNotNull(request, "request is null") instanceof GeneratedHttpRequest,
|
||||||
|
"this binder is only valid for GeneratedHttpRequests!");
|
||||||
|
checkArgument(checkNotNull(input, "input is null") instanceof String[],
|
||||||
|
"this binder is only valid for String[] arguments");
|
||||||
|
|
||||||
|
String[] names = (String[]) input;
|
||||||
|
GeneratedHttpRequest generatedRequest = (GeneratedHttpRequest) request;
|
||||||
|
|
||||||
|
for(String name : names) {
|
||||||
|
generatedRequest.addQueryParam(NAME_KEY, name);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,54 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* 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.binders;
|
||||||
|
|
||||||
|
import org.jclouds.http.HttpRequest;
|
||||||
|
import org.jclouds.rest.Binder;
|
||||||
|
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.checkArgument;
|
||||||
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
import static org.jclouds.gogrid.reference.GoGridQueryParams.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @see org.jclouds.gogrid.services.GridJobClient#getJobsForObjectName(String)
|
||||||
|
*
|
||||||
|
* @author Oleksiy Yarmula
|
||||||
|
*/
|
||||||
|
public class BindObjectNameToGetJobsRequestQueryParams implements Binder {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Maps the object's name to the
|
||||||
|
* input of <a href="http://wiki.gogrid.com/wiki/index.php/API:grid.job.list/>.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void bindToRequest(HttpRequest request, Object input) {
|
||||||
|
checkArgument(checkNotNull(request, "request is null") instanceof GeneratedHttpRequest,
|
||||||
|
"this binder is only valid for GeneratedHttpRequests!");
|
||||||
|
checkArgument(checkNotNull(input, "input is null") instanceof String,
|
||||||
|
"this binder is only valid for String arguments");
|
||||||
|
|
||||||
|
String serverName = (String) input;
|
||||||
|
GeneratedHttpRequest generatedRequest = (GeneratedHttpRequest) request;
|
||||||
|
|
||||||
|
generatedRequest.addQueryParam(OBJECT_KEY, serverName);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -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.binders;
|
||||||
|
|
||||||
|
import org.jclouds.gogrid.domain.IpPortPair;
|
||||||
|
import org.jclouds.http.HttpRequest;
|
||||||
|
import org.jclouds.rest.Binder;
|
||||||
|
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.checkArgument;
|
||||||
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
import static com.google.common.base.Preconditions.checkState;
|
||||||
|
import static org.jclouds.gogrid.reference.GoGridQueryParams.REAL_IP_LIST_KEY;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Binds a list of real IPs to the request.
|
||||||
|
*
|
||||||
|
* The {@link IpPortPair pairs} must have a {@link IpPortPair#ip} set with a valid
|
||||||
|
* IP address.
|
||||||
|
*
|
||||||
|
* @author Oleksiy Yarmula
|
||||||
|
*/
|
||||||
|
public class BindRealIpPortPairsToQueryParams implements Binder {
|
||||||
|
|
||||||
|
@SuppressWarnings({"unchecked"})
|
||||||
|
@Override
|
||||||
|
public void bindToRequest(HttpRequest request, Object input) {
|
||||||
|
checkArgument(checkNotNull(request, "request is null") instanceof GeneratedHttpRequest,
|
||||||
|
"this binder is only valid for GeneratedHttpRequests!");
|
||||||
|
checkArgument(checkNotNull(input, "input is null") instanceof List,
|
||||||
|
"this binder is only valid for a List argument");
|
||||||
|
|
||||||
|
List<IpPortPair> ipPortPairs = (List<IpPortPair>) input;
|
||||||
|
GeneratedHttpRequest generatedRequest = (GeneratedHttpRequest) request;
|
||||||
|
|
||||||
|
int i= 0;
|
||||||
|
for(IpPortPair ipPortPair : ipPortPairs) {
|
||||||
|
checkNotNull(ipPortPair.getIp(), "There must be an IP address defined");
|
||||||
|
checkNotNull(ipPortPair.getIp().getIp(), "There must be an IP address defined in Ip object");
|
||||||
|
checkState(ipPortPair.getPort() > 0, "The port number must be a positive integer");
|
||||||
|
|
||||||
|
generatedRequest.addQueryParam(REAL_IP_LIST_KEY + i + ".ip",
|
||||||
|
ipPortPair.getIp().getIp());
|
||||||
|
generatedRequest.addQueryParam(REAL_IP_LIST_KEY + i + ".port",
|
||||||
|
String.valueOf(ipPortPair.getPort()));
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -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.binders;
|
||||||
|
|
||||||
|
import org.jclouds.gogrid.domain.IpPortPair;
|
||||||
|
import org.jclouds.http.HttpRequest;
|
||||||
|
import org.jclouds.rest.Binder;
|
||||||
|
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
||||||
|
import static org.jclouds.gogrid.reference.GoGridQueryParams.VIRTUAL_IP_KEY;
|
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.checkArgument;
|
||||||
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
import static com.google.common.base.Preconditions.checkState;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Binds a virtual IP to the request.
|
||||||
|
*
|
||||||
|
* The {@link IpPortPair} must have a {@link IpPortPair#ip} set with a valid
|
||||||
|
* IP address.
|
||||||
|
*
|
||||||
|
* @author Oleksiy Yarmula
|
||||||
|
*/
|
||||||
|
public class BindVirtualIpPortPairToQueryParams implements Binder {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void bindToRequest(HttpRequest request, Object input) {
|
||||||
|
checkArgument(checkNotNull(request, "request is null") instanceof GeneratedHttpRequest,
|
||||||
|
"this binder is only valid for GeneratedHttpRequests!");
|
||||||
|
checkArgument(checkNotNull(input, "input is null") instanceof IpPortPair,
|
||||||
|
"this binder is only valid for a IpPortPair argument");
|
||||||
|
|
||||||
|
IpPortPair ipPortPair = (IpPortPair) input;
|
||||||
|
GeneratedHttpRequest generatedRequest = (GeneratedHttpRequest) request;
|
||||||
|
|
||||||
|
checkNotNull(ipPortPair.getIp(), "There must be an IP address defined");
|
||||||
|
checkNotNull(ipPortPair.getIp().getIp(), "There must be an IP address defined in Ip object");
|
||||||
|
checkState(ipPortPair.getPort() > 0, "The port number must be a positive integer");
|
||||||
|
|
||||||
|
generatedRequest.addQueryParam(VIRTUAL_IP_KEY + "ip", ipPortPair.getIp().getIp());
|
||||||
|
generatedRequest.addQueryParam(VIRTUAL_IP_KEY + "port", String.valueOf(ipPortPair.getPort()));
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,81 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||||
|
*
|
||||||
|
* ====================================================================
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF 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.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;
|
||||||
|
import org.jclouds.lifecycle.Closer;
|
||||||
|
import org.jclouds.rest.RestContext;
|
||||||
|
import org.jclouds.rest.internal.RestContextImpl;
|
||||||
|
import org.jclouds.gogrid.GoGrid;
|
||||||
|
import org.jclouds.gogrid.reference.GoGridConstants;
|
||||||
|
|
||||||
|
import com.google.inject.AbstractModule;
|
||||||
|
import com.google.inject.Provides;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Configures the GoGrid connection, including logging and http transport.
|
||||||
|
*
|
||||||
|
* @author Adrian Cole
|
||||||
|
* @author Oleksiy Yarmula
|
||||||
|
*/
|
||||||
|
public class GoGridContextModule extends AbstractModule {
|
||||||
|
@Override
|
||||||
|
protected void configure() {
|
||||||
|
bind(DateAdapter.class).to(DateSecondsAdapter.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
@Singleton
|
||||||
|
RestContext<GoGridAsyncClient, GoGridClient> provideContext(Closer closer, GoGridAsyncClient asyncApi,
|
||||||
|
GoGridClient syncApi, @GoGrid URI endPoint, @Named(GoGridConstants.PROPERTY_GOGRID_USER) String account) {
|
||||||
|
return new RestContextImpl<GoGridAsyncClient, GoGridClient>(closer, asyncApi, syncApi, endPoint, account);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Singleton
|
||||||
|
public static class DateSecondsAdapter implements DateAdapter {
|
||||||
|
|
||||||
|
public JsonElement serialize(Date src, Type typeOfSrc, JsonSerializationContext context) {
|
||||||
|
return new JsonPrimitive(src.getTime());
|
||||||
|
}
|
||||||
|
|
||||||
|
public Date deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
|
||||||
|
throws JsonParseException {
|
||||||
|
String toParse = json.getAsJsonPrimitive().getAsString();
|
||||||
|
return new Date(Long.valueOf(toParse));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,216 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* 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>
|
||||||
|
*
|
||||||
|
* ====================================================================
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF 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.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.TimeStamp;
|
||||||
|
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;
|
||||||
|
import org.jclouds.http.RequiresHttp;
|
||||||
|
import org.jclouds.http.annotation.ClientError;
|
||||||
|
import org.jclouds.http.annotation.Redirection;
|
||||||
|
import org.jclouds.http.annotation.ServerError;
|
||||||
|
import org.jclouds.rest.ConfiguresRestClient;
|
||||||
|
import org.jclouds.rest.RestClientFactory;
|
||||||
|
|
||||||
|
import org.jclouds.gogrid.GoGrid;
|
||||||
|
import org.jclouds.gogrid.reference.GoGridConstants;
|
||||||
|
|
||||||
|
import com.google.inject.AbstractModule;
|
||||||
|
import com.google.inject.Provides;
|
||||||
|
|
||||||
|
import static org.jclouds.gogrid.reference.GoGridConstants.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Configures the GoGrid connection.
|
||||||
|
*
|
||||||
|
* @author Adrian Cole
|
||||||
|
* @author Oleksiy Yarmula
|
||||||
|
*/
|
||||||
|
@RequiresHttp
|
||||||
|
@ConfiguresRestClient
|
||||||
|
public class GoGridRestClientModule extends AbstractModule {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void configure() {
|
||||||
|
bindErrorHandlers();
|
||||||
|
bindRetryHandlers();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
@Singleton
|
||||||
|
protected GridServerAsyncClient provideServerClient(RestClientFactory factory) {
|
||||||
|
return factory.create(GridServerAsyncClient.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
@Singleton
|
||||||
|
public GridServerClient provideServerClient(GridServerAsyncClient client) throws IllegalArgumentException,
|
||||||
|
SecurityException, NoSuchMethodException {
|
||||||
|
return SyncProxy.create(GridServerClient.class, client);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
@Singleton
|
||||||
|
protected GridJobAsyncClient provideJobClient(RestClientFactory factory) {
|
||||||
|
return factory.create(GridJobAsyncClient.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
@Singleton
|
||||||
|
public GridJobClient provideJobClient(GridJobAsyncClient client) throws IllegalArgumentException,
|
||||||
|
SecurityException, NoSuchMethodException {
|
||||||
|
return SyncProxy.create(GridJobClient.class, client);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
@Singleton
|
||||||
|
protected GridIpAsyncClient provideIpClient(RestClientFactory factory) {
|
||||||
|
return factory.create(GridIpAsyncClient.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
@Singleton
|
||||||
|
public GridIpClient provideIpClient(GridIpAsyncClient client) throws IllegalArgumentException,
|
||||||
|
SecurityException, NoSuchMethodException {
|
||||||
|
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
|
||||||
|
protected GridImageAsyncClient provideImageClient(RestClientFactory factory) {
|
||||||
|
return factory.create(GridImageAsyncClient.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
@Singleton
|
||||||
|
public GridImageClient provideImageClient(GridImageAsyncClient client) throws IllegalArgumentException,
|
||||||
|
SecurityException, NoSuchMethodException {
|
||||||
|
return SyncProxy.create(GridImageClient.class, client);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
@Singleton
|
||||||
|
@GoGrid
|
||||||
|
protected URI provideURI(@Named(GoGridConstants.PROPERTY_GOGRID_ENDPOINT) String endpoint) {
|
||||||
|
return URI.create(endpoint);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
@TimeStamp
|
||||||
|
protected Long provideTimeStamp(@TimeStamp Supplier<Long> cache) {
|
||||||
|
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());
|
||||||
|
bindings.put(JobState.class, new CustomDeserializers.JobStateAdapter());
|
||||||
|
bindings.put(ServerImageState.class, new CustomDeserializers.ServerImageStateAdapter());
|
||||||
|
bindings.put(ServerImageType.class, new CustomDeserializers.ServerImageTypeAdapter());
|
||||||
|
return bindings;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* borrowing concurrency code to ensure that caching takes place properly
|
||||||
|
*/
|
||||||
|
@Provides
|
||||||
|
@TimeStamp
|
||||||
|
Supplier<Long> provideTimeStampCache(
|
||||||
|
@Named(PROPERTY_GOGRID_SESSIONINTERVAL) long seconds) {
|
||||||
|
return new ExpirableSupplier<Long>(new Supplier<Long>() {
|
||||||
|
public Long get() {
|
||||||
|
return System.currentTimeMillis() / 1000;
|
||||||
|
}
|
||||||
|
}, seconds, TimeUnit.SECONDS);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void bindErrorHandlers() {
|
||||||
|
bind(HttpErrorHandler.class).annotatedWith(Redirection.class).to(
|
||||||
|
GoGridErrorHandler.class);
|
||||||
|
bind(HttpErrorHandler.class).annotatedWith(ClientError.class).to(
|
||||||
|
GoGridErrorHandler.class);
|
||||||
|
bind(HttpErrorHandler.class).annotatedWith(ServerError.class).to(
|
||||||
|
GoGridErrorHandler.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void bindRetryHandlers() {
|
||||||
|
// TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,99 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||||
|
*
|
||||||
|
* ====================================================================
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF 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.domain;
|
||||||
|
|
||||||
|
import com.google.common.primitives.Longs;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Oleksiy Yarmula
|
||||||
|
*/
|
||||||
|
public class BillingToken implements Comparable<BillingToken> {
|
||||||
|
|
||||||
|
private long id;
|
||||||
|
private String name;
|
||||||
|
private double price;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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 long getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getPrice() {
|
||||||
|
return price;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (this == o) return true;
|
||||||
|
if (o == null || getClass() != o.getClass()) return false;
|
||||||
|
|
||||||
|
BillingToken that = (BillingToken) o;
|
||||||
|
|
||||||
|
if (id != that.id) return false;
|
||||||
|
if (Double.compare(that.price, price) != 0) return false;
|
||||||
|
if (!name.equals(that.name)) return false;
|
||||||
|
|
||||||
|
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 +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,72 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||||
|
*
|
||||||
|
* ====================================================================
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF 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.domain;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Oleksiy Yarmula
|
||||||
|
*/
|
||||||
|
public class Customer {
|
||||||
|
|
||||||
|
private long id;
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
public Customer(long id, String name) {
|
||||||
|
this.id = id;
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A no-args constructor is required for deserialization
|
||||||
|
*/
|
||||||
|
public Customer() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (this == o) return true;
|
||||||
|
if (o == null || getClass() != o.getClass()) return false;
|
||||||
|
|
||||||
|
Customer customer = (Customer) o;
|
||||||
|
|
||||||
|
if (id != customer.id) return false;
|
||||||
|
if (name != null ? !name.equals(customer.name) : customer.name != null) return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
int result = (int) (id ^ (id >>> 32));
|
||||||
|
result = 31 * result + (name != null ? name.hashCode() : 0);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,127 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||||
|
*
|
||||||
|
* ====================================================================
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF 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.domain;
|
||||||
|
|
||||||
|
import com.google.common.primitives.Longs;
|
||||||
|
import com.google.gson.annotations.SerializedName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Oleksiy Yarmula
|
||||||
|
*/
|
||||||
|
public class Ip implements Comparable<Ip> {
|
||||||
|
|
||||||
|
private long id;
|
||||||
|
|
||||||
|
private String ip;
|
||||||
|
private String subnet;
|
||||||
|
@SerializedName("public")
|
||||||
|
private boolean isPublic;
|
||||||
|
private IpState state;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A no-args constructor is required for deserialization
|
||||||
|
*/
|
||||||
|
public Ip() {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs a generic IP address
|
||||||
|
* without any additional options.
|
||||||
|
*
|
||||||
|
* @param ip ip address
|
||||||
|
*/
|
||||||
|
public Ip(String ip) {
|
||||||
|
this.ip = ip;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Ip(long id, String ip, String subnet, boolean isPublic, IpState state) {
|
||||||
|
this.id = id;
|
||||||
|
this.ip = ip;
|
||||||
|
this.subnet = subnet;
|
||||||
|
this.isPublic = isPublic;
|
||||||
|
this.state = state;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getIp() {
|
||||||
|
return ip;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSubnet() {
|
||||||
|
return subnet;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isPublic() {
|
||||||
|
return isPublic;
|
||||||
|
}
|
||||||
|
|
||||||
|
public IpState getState() {
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (this == o) return true;
|
||||||
|
if (o == null || getClass() != o.getClass()) return false;
|
||||||
|
|
||||||
|
Ip ip1 = (Ip) o;
|
||||||
|
|
||||||
|
if (id != ip1.id) return false;
|
||||||
|
if (isPublic != ip1.isPublic) return false;
|
||||||
|
if (!ip.equals(ip1.ip)) return false;
|
||||||
|
if (state != null ? !state.equals(ip1.state) : ip1.state != null) return false;
|
||||||
|
if (subnet != null ? !subnet.equals(ip1.subnet) : ip1.subnet != null) return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
int result = (int) (id ^ (id >>> 32));
|
||||||
|
result = 31 * result + ip.hashCode();
|
||||||
|
result = 31 * result + (subnet != null ? subnet.hashCode() : 0);
|
||||||
|
result = 31 * result + (isPublic ? 1 : 0);
|
||||||
|
result = 31 * result + (state != null ? state.hashCode() : 0);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "Ip{" +
|
||||||
|
"id=" + id +
|
||||||
|
", ip='" + ip + '\'' +
|
||||||
|
", subnet='" + subnet + '\'' +
|
||||||
|
", isPublic=" + isPublic +
|
||||||
|
", state=" + state +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int compareTo(Ip o) {
|
||||||
|
return Longs.compare(id, o.getId());
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,76 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* 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.Ints;
|
||||||
|
import com.google.common.primitives.Longs;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Oleksiy Yarmula
|
||||||
|
*/
|
||||||
|
public class IpPortPair implements Comparable<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;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int compareTo(IpPortPair o) {
|
||||||
|
if(ip != null && o.getIp() != null) return Longs.compare(ip.getId(), o.getIp().getId());
|
||||||
|
return Ints.compare(port, o.getPort());
|
||||||
|
}
|
||||||
|
}
|
|
@ -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.domain;
|
||||||
|
|
||||||
|
import com.google.common.base.CaseFormat;
|
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Oleksiy Yarmula
|
||||||
|
*/
|
||||||
|
public enum IpState {
|
||||||
|
UNASSIGNED, ASSIGNED;
|
||||||
|
|
||||||
|
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")));
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,42 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* 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 enum IpType {
|
||||||
|
PRIVATE("Private"),
|
||||||
|
PRIVATE_2("Private 2"),
|
||||||
|
PUBLIC("Public"),
|
||||||
|
PUBLIC_2("Public 2"),
|
||||||
|
PUBLIC_3("Public 3"),
|
||||||
|
PUBLIC_4("Public 4");
|
||||||
|
|
||||||
|
final String name;
|
||||||
|
|
||||||
|
IpType(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,177 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* 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.collect.ImmutableSortedSet;
|
||||||
|
import com.google.common.primitives.Longs;
|
||||||
|
import com.google.gson.annotations.SerializedName;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.SortedSet;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents any job in GoGrid system
|
||||||
|
* (jobs include server creation, stopping, etc)
|
||||||
|
*
|
||||||
|
* @see <a href="http://wiki.gogrid.com/wiki/index.php/API:Job_(Object)" />
|
||||||
|
* @author Oleksiy Yarmula
|
||||||
|
*/
|
||||||
|
public class Job implements Comparable<Job> {
|
||||||
|
|
||||||
|
private long id;
|
||||||
|
private Option command;
|
||||||
|
@SerializedName("objecttype")
|
||||||
|
private ObjectType objectType;
|
||||||
|
@SerializedName("createdon")
|
||||||
|
private Date createdOn;
|
||||||
|
@SerializedName("lastupdatedon")
|
||||||
|
private Date lastUpdatedOn;
|
||||||
|
@SerializedName("currentstate")
|
||||||
|
private JobState currentState;
|
||||||
|
private int attempts;
|
||||||
|
private String owner;
|
||||||
|
private SortedSet<JobProperties> history;
|
||||||
|
@SerializedName("detail") /*NOTE: as of Feb 28, 10,
|
||||||
|
there is a contradiction b/w the name in
|
||||||
|
documentation (details) and actual param
|
||||||
|
name (detail)*/
|
||||||
|
private Map<String, String> details;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A no-args constructor is required for deserialization
|
||||||
|
*/
|
||||||
|
public Job() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public Job(long id, Option command, ObjectType objectType,
|
||||||
|
Date createdOn, Date lastUpdatedOn, JobState currentState,
|
||||||
|
int attempts, String owner, SortedSet<JobProperties> history,
|
||||||
|
Map<String, String> details) {
|
||||||
|
this.id = id;
|
||||||
|
this.command = command;
|
||||||
|
this.objectType = objectType;
|
||||||
|
this.createdOn = createdOn;
|
||||||
|
this.lastUpdatedOn = lastUpdatedOn;
|
||||||
|
this.currentState = currentState;
|
||||||
|
this.attempts = attempts;
|
||||||
|
this.owner = owner;
|
||||||
|
this.history = history;
|
||||||
|
this.details = details;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Option getCommand() {
|
||||||
|
return command;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ObjectType getObjectType() {
|
||||||
|
return objectType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Date getCreatedOn() {
|
||||||
|
return createdOn;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Date getLastUpdatedOn() {
|
||||||
|
return lastUpdatedOn;
|
||||||
|
}
|
||||||
|
|
||||||
|
public JobState getCurrentState() {
|
||||||
|
return currentState;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getAttempts() {
|
||||||
|
return attempts;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getOwner() {
|
||||||
|
return owner;
|
||||||
|
}
|
||||||
|
|
||||||
|
public SortedSet<JobProperties> getHistory() {
|
||||||
|
return ImmutableSortedSet.copyOf(history);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Map<String, String> getDetails() {
|
||||||
|
return details;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (this == o) return true;
|
||||||
|
if (o == null || getClass() != o.getClass()) return false;
|
||||||
|
|
||||||
|
Job job = (Job) o;
|
||||||
|
|
||||||
|
if (attempts != job.attempts) return false;
|
||||||
|
if (id != job.id) return false;
|
||||||
|
if (command != null ? !command.equals(job.command) : job.command != null) return false;
|
||||||
|
if (createdOn != null ? !createdOn.equals(job.createdOn) : job.createdOn != null) return false;
|
||||||
|
if (currentState != null ? !currentState.equals(job.currentState) : job.currentState != null) return false;
|
||||||
|
if (details != null ? !details.equals(job.details) : job.details != null) return false;
|
||||||
|
if (history != null ? !history.equals(job.history) : job.history != null) return false;
|
||||||
|
if (lastUpdatedOn != null ? !lastUpdatedOn.equals(job.lastUpdatedOn) : job.lastUpdatedOn != null) return false;
|
||||||
|
if (objectType != null ? !objectType.equals(job.objectType) : job.objectType != null) return false;
|
||||||
|
if (owner != null ? !owner.equals(job.owner) : job.owner != null) return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
int result = (int) (id ^ (id >>> 32));
|
||||||
|
result = 31 * result + (command != null ? command.hashCode() : 0);
|
||||||
|
result = 31 * result + (objectType != null ? objectType.hashCode() : 0);
|
||||||
|
result = 31 * result + (createdOn != null ? createdOn.hashCode() : 0);
|
||||||
|
result = 31 * result + (lastUpdatedOn != null ? lastUpdatedOn.hashCode() : 0);
|
||||||
|
result = 31 * result + (currentState != null ? currentState.hashCode() : 0);
|
||||||
|
result = 31 * result + attempts;
|
||||||
|
result = 31 * result + (owner != null ? owner.hashCode() : 0);
|
||||||
|
result = 31 * result + (history != null ? history.hashCode() : 0);
|
||||||
|
result = 31 * result + (details != null ? details.hashCode() : 0);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int compareTo(Job o) {
|
||||||
|
if(createdOn != null && o.getCreatedOn() != null)
|
||||||
|
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 +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
}
|
|
@ -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.domain;
|
||||||
|
|
||||||
|
import com.google.common.primitives.Longs;
|
||||||
|
import com.google.gson.annotations.SerializedName;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* State of a job.
|
||||||
|
*
|
||||||
|
* @see <a href="http://wiki.gogrid.com/wiki/index.php/API:Job_State_(Object)"/>
|
||||||
|
*
|
||||||
|
* @author Oleksiy Yarmula
|
||||||
|
*/
|
||||||
|
public class JobProperties implements Comparable<JobProperties> {
|
||||||
|
|
||||||
|
private long id;
|
||||||
|
@SerializedName("updatedon")
|
||||||
|
private Date updatedOn;
|
||||||
|
private JobState state;
|
||||||
|
private String note;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A no-args constructor is required for deserialization
|
||||||
|
*/
|
||||||
|
public JobProperties() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public JobProperties(long id, Date updatedOn, JobState state, String note) {
|
||||||
|
this.id = id;
|
||||||
|
this.updatedOn = updatedOn;
|
||||||
|
this.state = state;
|
||||||
|
this.note = note;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Date getUpdatedOn() {
|
||||||
|
return updatedOn;
|
||||||
|
}
|
||||||
|
|
||||||
|
public JobState getState() {
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getNote() {
|
||||||
|
return note;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (this == o) return true;
|
||||||
|
if (o == null || getClass() != o.getClass()) return false;
|
||||||
|
|
||||||
|
JobProperties jobState = (JobProperties) o;
|
||||||
|
|
||||||
|
if (id != jobState.id) return false;
|
||||||
|
if (note != null ? !note.equals(jobState.note) : jobState.note != null) return false;
|
||||||
|
if (state != null ? !state.equals(jobState.state) : jobState.state != null) return false;
|
||||||
|
if (updatedOn != null ? !updatedOn.equals(jobState.updatedOn) : jobState.updatedOn != null) return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
int result = (int) (id ^ (id >>> 32));
|
||||||
|
result = 31 * result + (updatedOn != null ? updatedOn.hashCode() : 0);
|
||||||
|
result = 31 * result + (state != null ? state.hashCode() : 0);
|
||||||
|
result = 31 * result + (note != null ? note.hashCode() : 0);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "JobState{" +
|
||||||
|
"id=" + id +
|
||||||
|
", updatedOn=" + updatedOn +
|
||||||
|
", state=" + state +
|
||||||
|
", note='" + note + '\'' +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int compareTo(JobProperties o) {
|
||||||
|
return Longs.compare(id, o.getId());
|
||||||
|
}
|
||||||
|
}
|
|
@ -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.domain;
|
||||||
|
|
||||||
|
import org.omg.CORBA.UNKNOWN;
|
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Oleksiy Yarmula
|
||||||
|
*/
|
||||||
|
public enum JobState {
|
||||||
|
|
||||||
|
QUEUED("Queued", "Change request is new to the system."),
|
||||||
|
PROCESSING("Processing", "Change request is is transient state...Processing."),
|
||||||
|
SUCCEEDED("Succeeded", "Change request has succeeded."),
|
||||||
|
FAILED("Failed", "Change request has failed."),
|
||||||
|
CANCELED("Canceled", "Change request has been canceled."),
|
||||||
|
FATAL("Fatal", "Change request had Fatal or Unrecoverable Failure"),
|
||||||
|
CREATED("Created", "Change request is created but not queued yet"),
|
||||||
|
UNKNOWN("Unknown", "The state is unknown to JClouds");
|
||||||
|
|
||||||
|
String name;
|
||||||
|
String description;
|
||||||
|
JobState(String name, String description) {
|
||||||
|
this.name = name;
|
||||||
|
this.description = description;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static JobState fromValue(String state) {
|
||||||
|
for(JobState jobState : values()) {
|
||||||
|
if(jobState.name.equals(checkNotNull(state))) return jobState;
|
||||||
|
}
|
||||||
|
return UNKNOWN;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,139 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* 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.collect.ImmutableSortedSet;
|
||||||
|
import com.google.common.primitives.Longs;
|
||||||
|
import com.google.gson.annotations.SerializedName;
|
||||||
|
|
||||||
|
import java.util.SortedSet;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @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 SortedSet<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, SortedSet<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 SortedSet<IpPortPair> getRealIpList() {
|
||||||
|
return ImmutableSortedSet.copyOf(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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,89 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||||
|
*
|
||||||
|
* ====================================================================
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF 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.domain;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Oleksiy Yarmula
|
||||||
|
*/
|
||||||
|
public class Option {
|
||||||
|
|
||||||
|
private Long id;
|
||||||
|
private String name;
|
||||||
|
private String description;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A no-args constructor is required for deserialization
|
||||||
|
*/
|
||||||
|
public Option() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public Option(Long id) {
|
||||||
|
this(id, null, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Option(String name) {
|
||||||
|
this(null, name, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Option(Long id, String name, String description) {
|
||||||
|
this.id = id;
|
||||||
|
this.name = name;
|
||||||
|
this.description = description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDescription() {
|
||||||
|
return description;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (this == o) return true;
|
||||||
|
if (o == null || getClass() != o.getClass()) return false;
|
||||||
|
|
||||||
|
Option option = (Option) o;
|
||||||
|
|
||||||
|
if (description != null ? !description.equals(option.description) : option.description != null) return false;
|
||||||
|
if (id != null ? !id.equals(option.id) : option.id != null) return false;
|
||||||
|
if (name != null ? !name.equals(option.name) : option.name != null) return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
int result = id != null ? id.hashCode() : 0;
|
||||||
|
result = 31 * result + (name != null ? name.hashCode() : 0);
|
||||||
|
result = 31 * result + (description != null ? description.hashCode() : 0);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,54 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||||
|
*
|
||||||
|
* ====================================================================
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF 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.domain;
|
||||||
|
|
||||||
|
import com.google.common.base.CaseFormat;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Server's state transition.
|
||||||
|
*
|
||||||
|
* Using this value, server's state will be changed
|
||||||
|
* to one of the following:
|
||||||
|
* <ul>
|
||||||
|
* <li>Start</li>
|
||||||
|
* <li>Stop</li>
|
||||||
|
* <li>Restart</li>
|
||||||
|
* </ul>
|
||||||
|
*
|
||||||
|
* @see org.jclouds.gogrid.services.GridServerClient#power(String, PowerCommand)
|
||||||
|
* @see <a href="http://wiki.gogrid.com/wiki/index.php/API:grid.server.power" />
|
||||||
|
*
|
||||||
|
* @author Oleksiy Yarmula
|
||||||
|
*/
|
||||||
|
public enum PowerCommand {
|
||||||
|
START,
|
||||||
|
STOP /*NOTE: This is a hard shutdown, equivalent to powering off a server.*/,
|
||||||
|
RESTART;
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return name().toLowerCase();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,163 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||||
|
*
|
||||||
|
* ====================================================================
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF 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.domain;
|
||||||
|
|
||||||
|
import com.google.common.primitives.Longs;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Oleksiy Yarmula
|
||||||
|
*/
|
||||||
|
public class Server implements Comparable<Server> {
|
||||||
|
|
||||||
|
private long id;
|
||||||
|
private boolean isSandbox;
|
||||||
|
private String name;
|
||||||
|
private String description;
|
||||||
|
private Option state;
|
||||||
|
|
||||||
|
private Option type;
|
||||||
|
private Option ram;
|
||||||
|
private Option os;
|
||||||
|
private Ip ip;
|
||||||
|
|
||||||
|
private ServerImage image;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A no-args constructor is required for deserialization
|
||||||
|
*/
|
||||||
|
public Server() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public Server(long id, boolean sandbox, String name,
|
||||||
|
String description, Option state, Option type,
|
||||||
|
Option ram, Option os, Ip ip, ServerImage image) {
|
||||||
|
this.id = id;
|
||||||
|
this.isSandbox = sandbox;
|
||||||
|
this.name = name;
|
||||||
|
this.description = description;
|
||||||
|
this.state = state;
|
||||||
|
this.type = type;
|
||||||
|
this.ram = ram;
|
||||||
|
this.os = os;
|
||||||
|
this.ip = ip;
|
||||||
|
this.image = image;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isSandbox() {
|
||||||
|
return isSandbox;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDescription() {
|
||||||
|
return description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Option getState() {
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Option getType() {
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Option getRam() {
|
||||||
|
return ram;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Option getOs() {
|
||||||
|
return os;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Ip getIp() {
|
||||||
|
return ip;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ServerImage getImage() {
|
||||||
|
return image;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (this == o) return true;
|
||||||
|
if (o == null || getClass() != o.getClass()) return false;
|
||||||
|
|
||||||
|
Server server = (Server) o;
|
||||||
|
|
||||||
|
if (id != server.id) return false;
|
||||||
|
if (isSandbox != server.isSandbox) return false;
|
||||||
|
if (description != null ? !description.equals(server.description) : server.description != null) return false;
|
||||||
|
if (image != null ? !image.equals(server.image) : server.image != null) return false;
|
||||||
|
if (ip != null ? !ip.equals(server.ip) : server.ip != null) return false;
|
||||||
|
if (!name.equals(server.name)) return false;
|
||||||
|
if (os != null ? !os.equals(server.os) : server.os != null) return false;
|
||||||
|
if (ram != null ? !ram.equals(server.ram) : server.ram != null) return false;
|
||||||
|
if (!state.equals(server.state)) return false;
|
||||||
|
if (!type.equals(server.type)) return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
int result = (int) (id ^ (id >>> 32));
|
||||||
|
result = 31 * result + (isSandbox ? 1 : 0);
|
||||||
|
result = 31 * result + name.hashCode();
|
||||||
|
result = 31 * result + (description != null ? description.hashCode() : 0);
|
||||||
|
result = 31 * result + state.hashCode();
|
||||||
|
result = 31 * result + type.hashCode();
|
||||||
|
result = 31 * result + (ram != null ? ram.hashCode() : 0);
|
||||||
|
result = 31 * result + (os != null ? os.hashCode() : 0);
|
||||||
|
result = 31 * result + (ip != null ? ip.hashCode() : 0);
|
||||||
|
result = 31 * result + (image != null ? image.hashCode() : 0);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int compareTo(Server o) {
|
||||||
|
return Longs.compare(id, o.getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "Server{" +
|
||||||
|
"id=" + id +
|
||||||
|
", isSandbox=" + isSandbox +
|
||||||
|
", name='" + name + '\'' +
|
||||||
|
", description='" + description + '\'' +
|
||||||
|
", state=" + state +
|
||||||
|
", type=" + type +
|
||||||
|
", ram=" + ram +
|
||||||
|
", os=" + os +
|
||||||
|
", ip=" + ip +
|
||||||
|
", image=" + image +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,226 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||||
|
*
|
||||||
|
* ====================================================================
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF 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.domain;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableSortedSet;
|
||||||
|
import com.google.common.primitives.Longs;
|
||||||
|
import com.google.gson.annotations.SerializedName;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.SortedSet;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Oleksiy Yarmula
|
||||||
|
*/
|
||||||
|
public class ServerImage implements Comparable<ServerImage> {
|
||||||
|
|
||||||
|
private long id;
|
||||||
|
private String name;
|
||||||
|
private String friendlyName;
|
||||||
|
private String description;
|
||||||
|
private Option os;
|
||||||
|
private Option architecture;
|
||||||
|
private ServerImageType type;
|
||||||
|
private ServerImageState state;
|
||||||
|
private double price;
|
||||||
|
private String location;
|
||||||
|
private boolean isActive;
|
||||||
|
private boolean isPublic;
|
||||||
|
private Date createdTime;
|
||||||
|
private Date updatedTime;
|
||||||
|
@SerializedName("billingtokens")
|
||||||
|
private SortedSet<BillingToken> billingTokens;
|
||||||
|
private Customer owner;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A no-args constructor is required for deserialization
|
||||||
|
*/
|
||||||
|
public ServerImage() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public ServerImage(long id, String name, String friendlyName,
|
||||||
|
String description, Option os, Option architecture,
|
||||||
|
ServerImageType type, ServerImageState state, double price, String location,
|
||||||
|
boolean active, boolean aPublic, Date createdTime,
|
||||||
|
Date updatedTime, SortedSet<BillingToken> billingTokens, Customer owner) {
|
||||||
|
this.id = id;
|
||||||
|
this.name = name;
|
||||||
|
this.friendlyName = friendlyName;
|
||||||
|
this.description = description;
|
||||||
|
this.os = os;
|
||||||
|
this.architecture = architecture;
|
||||||
|
this.type = type;
|
||||||
|
this.state = state;
|
||||||
|
this.price = price;
|
||||||
|
this.location = location;
|
||||||
|
isActive = active;
|
||||||
|
isPublic = aPublic;
|
||||||
|
this.createdTime = createdTime;
|
||||||
|
this.updatedTime = updatedTime;
|
||||||
|
this.billingTokens = billingTokens;
|
||||||
|
this.owner = owner;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getFriendlyName() {
|
||||||
|
return friendlyName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDescription() {
|
||||||
|
return description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Option getOs() {
|
||||||
|
return os;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Option getArchitecture() {
|
||||||
|
return architecture;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ServerImageType getType() {
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ServerImageState getState() {
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getPrice() {
|
||||||
|
return price;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getLocation() {
|
||||||
|
return location;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isActive() {
|
||||||
|
return isActive;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isPublic() {
|
||||||
|
return isPublic;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Date getCreatedTime() {
|
||||||
|
return createdTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Date getUpdatedTime() {
|
||||||
|
return updatedTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public SortedSet<BillingToken> getBillingTokens() {
|
||||||
|
return ImmutableSortedSet.copyOf(billingTokens);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Customer getOwner() {
|
||||||
|
return owner;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (this == o) return true;
|
||||||
|
if (o == null || getClass() != o.getClass()) return false;
|
||||||
|
|
||||||
|
ServerImage that = (ServerImage) o;
|
||||||
|
|
||||||
|
if (id != that.id) return false;
|
||||||
|
if (isActive != that.isActive) return false;
|
||||||
|
if (isPublic != that.isPublic) return false;
|
||||||
|
if (Double.compare(that.price, price) != 0) return false;
|
||||||
|
if (architecture != null ? !architecture.equals(that.architecture) : that.architecture != null) return false;
|
||||||
|
if (billingTokens != null ? !billingTokens.equals(that.billingTokens) : that.billingTokens != null)
|
||||||
|
return false;
|
||||||
|
if (!createdTime.equals(that.createdTime)) return false;
|
||||||
|
if (description != null ? !description.equals(that.description) : that.description != null) return false;
|
||||||
|
if (friendlyName != null ? !friendlyName.equals(that.friendlyName) : that.friendlyName != null) return false;
|
||||||
|
if (location != null ? !location.equals(that.location) : that.location != null) return false;
|
||||||
|
if (!name.equals(that.name)) return false;
|
||||||
|
if (!os.equals(that.os)) return false;
|
||||||
|
if (owner != null ? !owner.equals(that.owner) : that.owner != null) return false;
|
||||||
|
if (!state.equals(that.state)) return false;
|
||||||
|
if (!type.equals(that.type)) return false;
|
||||||
|
if (updatedTime != null ? !updatedTime.equals(that.updatedTime) : that.updatedTime != null) return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
int result;
|
||||||
|
long temp;
|
||||||
|
result = (int) (id ^ (id >>> 32));
|
||||||
|
result = 31 * result + name.hashCode();
|
||||||
|
result = 31 * result + (friendlyName != null ? friendlyName.hashCode() : 0);
|
||||||
|
result = 31 * result + (description != null ? description.hashCode() : 0);
|
||||||
|
result = 31 * result + os.hashCode();
|
||||||
|
result = 31 * result + type.hashCode();
|
||||||
|
result = 31 * result + state.hashCode();
|
||||||
|
temp = price != +0.0d ? Double.doubleToLongBits(price) : 0L;
|
||||||
|
result = 31 * result + (int) (temp ^ (temp >>> 32));
|
||||||
|
result = 31 * result + (location != null ? location.hashCode() : 0);
|
||||||
|
result = 31 * result + (isActive ? 1 : 0);
|
||||||
|
result = 31 * result + (isPublic ? 1 : 0);
|
||||||
|
result = 31 * result + createdTime.hashCode();
|
||||||
|
result = 31 * result + (updatedTime != null ? updatedTime.hashCode() : 0);
|
||||||
|
result = 31 * result + (billingTokens != null ? billingTokens.hashCode() : 0);
|
||||||
|
result = 31 * result + (owner != null ? owner.hashCode() : 0);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int compareTo(ServerImage o) {
|
||||||
|
return Longs.compare(id, o.getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "ServerImage{" +
|
||||||
|
"id=" + id +
|
||||||
|
", name='" + name + '\'' +
|
||||||
|
", friendlyName='" + friendlyName + '\'' +
|
||||||
|
", description='" + description + '\'' +
|
||||||
|
", os=" + os +
|
||||||
|
", architecture=" + architecture +
|
||||||
|
", type=" + type +
|
||||||
|
", state=" + state +
|
||||||
|
", price=" + price +
|
||||||
|
", location='" + location + '\'' +
|
||||||
|
", isActive=" + isActive +
|
||||||
|
", isPublic=" + isPublic +
|
||||||
|
", createdTime=" + createdTime +
|
||||||
|
", updatedTime=" + updatedTime +
|
||||||
|
", billingTokens=" + billingTokens +
|
||||||
|
", owner=" + owner +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,48 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* 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 ServerImageState {
|
||||||
|
|
||||||
|
AVAILABLE("Available"),
|
||||||
|
SAVING("Saving"),
|
||||||
|
UNKNOWN("Unknown");
|
||||||
|
|
||||||
|
String type;
|
||||||
|
ServerImageState(String type) {
|
||||||
|
this.type = type;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ServerImageState fromValue(String type) {
|
||||||
|
for(ServerImageState serverImageState : values()) {
|
||||||
|
if(serverImageState.type.equals(checkNotNull(type))) return serverImageState;
|
||||||
|
}
|
||||||
|
return UNKNOWN;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,48 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* 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 ServerImageType {
|
||||||
|
|
||||||
|
WEB_APPLICATION_SERVER("Web Server"),
|
||||||
|
DATABASE_SERVER("Database Server"),
|
||||||
|
UNKNOWN("Unknown");
|
||||||
|
|
||||||
|
String type;
|
||||||
|
ServerImageType(String type) {
|
||||||
|
this.type = type;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ServerImageType fromValue(String type) {
|
||||||
|
for(ServerImageType serverImageType : values()) {
|
||||||
|
if(serverImageType.type.equals(checkNotNull(type))) return serverImageType;
|
||||||
|
}
|
||||||
|
return UNKNOWN;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,60 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||||
|
*
|
||||||
|
* ====================================================================
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF 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.domain.internal;
|
||||||
|
|
||||||
|
import com.google.gson.annotations.SerializedName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Oleksiy Yarmula
|
||||||
|
*/
|
||||||
|
public class ErrorResponse implements Comparable<ErrorResponse> {
|
||||||
|
|
||||||
|
private String message;
|
||||||
|
@SerializedName("errorcode")
|
||||||
|
private String errorCode;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A no-args constructor is required for deserialization
|
||||||
|
*/
|
||||||
|
public ErrorResponse() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public ErrorResponse(String message, String errorCode) {
|
||||||
|
this.message = message;
|
||||||
|
this.errorCode = errorCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getMessage() {
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getErrorCode() {
|
||||||
|
return errorCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int compareTo(ErrorResponse o) {
|
||||||
|
return message.compareTo(o.getMessage());
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,84 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||||
|
*
|
||||||
|
* ====================================================================
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF 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.domain.internal;
|
||||||
|
|
||||||
|
import java.util.SortedSet;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* General format of GoGrid's response.
|
||||||
|
*
|
||||||
|
* This is the wrapper for most responses, and the actual
|
||||||
|
* result (or error) will be set to {@link #list}.
|
||||||
|
* Note that even the single returned item will be set to
|
||||||
|
* {@link #list} per GoGrid's design.
|
||||||
|
*
|
||||||
|
* @author Oleksiy Yarmula
|
||||||
|
*/
|
||||||
|
public class GenericResponseContainer<T> {
|
||||||
|
|
||||||
|
private Summary summary;
|
||||||
|
private String status;
|
||||||
|
private String method;
|
||||||
|
private SortedSet<T> list;
|
||||||
|
|
||||||
|
public Summary getSummary() {
|
||||||
|
return summary;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getStatus() {
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getMethod() {
|
||||||
|
return method;
|
||||||
|
}
|
||||||
|
|
||||||
|
public SortedSet<T> getList() {
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
static class Summary {
|
||||||
|
private int total;
|
||||||
|
private int start;
|
||||||
|
private int numPages;
|
||||||
|
private int returned;
|
||||||
|
|
||||||
|
public int getTotal() {
|
||||||
|
return total;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getStart() {
|
||||||
|
return start;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getNumPages() {
|
||||||
|
return numPages;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getReturned() {
|
||||||
|
return returned;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,95 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||||
|
*
|
||||||
|
* ====================================================================
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF 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.filters;
|
||||||
|
|
||||||
|
import com.google.common.base.Throwables;
|
||||||
|
import org.jclouds.Constants;
|
||||||
|
import org.jclouds.date.TimeStamp;
|
||||||
|
import org.jclouds.encryption.EncryptionService;
|
||||||
|
import org.jclouds.gogrid.reference.GoGridConstants;
|
||||||
|
import org.jclouds.http.HttpRequest;
|
||||||
|
import org.jclouds.http.HttpRequestFilter;
|
||||||
|
import org.jclouds.http.HttpUtils;
|
||||||
|
import org.jclouds.logging.Logger;
|
||||||
|
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import javax.inject.Inject;
|
||||||
|
import javax.inject.Named;
|
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.checkArgument;
|
||||||
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
import static java.lang.String.format;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Oleksiy Yarmula
|
||||||
|
*/
|
||||||
|
public class SharedKeyLiteAuthentication implements HttpRequestFilter {
|
||||||
|
|
||||||
|
private final String apiKey;
|
||||||
|
private final String secret;
|
||||||
|
private final Long timeStamp;
|
||||||
|
private final EncryptionService encryptionService;
|
||||||
|
@Resource
|
||||||
|
@Named(Constants.LOGGER_SIGNATURE)
|
||||||
|
Logger signatureLog = Logger.NULL;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
public SharedKeyLiteAuthentication(@Named(GoGridConstants.PROPERTY_GOGRID_USER) String apiKey,
|
||||||
|
@Named(GoGridConstants.PROPERTY_GOGRID_PASSWORD) String secret,
|
||||||
|
@TimeStamp Long timeStamp,
|
||||||
|
EncryptionService encryptionService) {
|
||||||
|
this.encryptionService = encryptionService;
|
||||||
|
this.apiKey = apiKey;
|
||||||
|
this.secret = secret;
|
||||||
|
this.timeStamp = timeStamp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void filter(HttpRequest request) {
|
||||||
|
checkArgument(checkNotNull(request, "input") instanceof GeneratedHttpRequest<?>,
|
||||||
|
"this decorator is only valid for GeneratedHttpRequests!");
|
||||||
|
GeneratedHttpRequest<?> generatedRequest = (GeneratedHttpRequest<?>) request;
|
||||||
|
|
||||||
|
String toSign = createStringToSign();
|
||||||
|
String signatureMd5 = getMd5For(toSign);
|
||||||
|
|
||||||
|
generatedRequest.addQueryParam("sig", signatureMd5);
|
||||||
|
generatedRequest.addQueryParam("api_key", apiKey);
|
||||||
|
|
||||||
|
HttpUtils.logRequest(signatureLog, request, "<<");
|
||||||
|
}
|
||||||
|
|
||||||
|
private String createStringToSign() {
|
||||||
|
return format("%s%s%s", apiKey, secret, timeStamp);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getMd5For(String stringToHash) {
|
||||||
|
try {
|
||||||
|
return encryptionService.md5Hex(stringToHash.getBytes());
|
||||||
|
} catch(Exception e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,70 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||||
|
*
|
||||||
|
* ====================================================================
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF 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.functions;
|
||||||
|
|
||||||
|
import com.google.common.collect.Iterables;
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
import com.google.gson.reflect.TypeToken;
|
||||||
|
import com.google.inject.Singleton;
|
||||||
|
import org.jclouds.gogrid.domain.internal.ErrorResponse;
|
||||||
|
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;
|
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.checkState;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parses {@link org.jclouds.gogrid.domain.internal.ErrorResponse
|
||||||
|
* error response} from a json string.
|
||||||
|
*
|
||||||
|
* GoGrid may return multiple error objects, if multiple errors were found.
|
||||||
|
*
|
||||||
|
* @author Oleksiy Yarmula
|
||||||
|
*/
|
||||||
|
@Singleton
|
||||||
|
public class ParseErrorFromJsonResponse extends ParseJson<SortedSet<ErrorResponse>> {
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
public ParseErrorFromJsonResponse(Gson gson) {
|
||||||
|
super(gson);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SortedSet<ErrorResponse> apply(InputStream stream) {
|
||||||
|
Type setType = new TypeToken<GenericResponseContainer<ErrorResponse>>() {
|
||||||
|
}.getType();
|
||||||
|
GenericResponseContainer<ErrorResponse> 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,45 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* 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.gson.Gson;
|
||||||
|
import org.jclouds.gogrid.domain.ServerImage;
|
||||||
|
import org.jclouds.http.functions.ParseJson;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.util.SortedSet;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Oleksiy Yarmula
|
||||||
|
*/
|
||||||
|
public class ParseImageFromJsonResponse extends ParseJson<ServerImage> {
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
public ParseImageFromJsonResponse(Gson gson) {
|
||||||
|
super(gson);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ServerImage apply(InputStream stream) {
|
||||||
|
SortedSet<ServerImage> allImages =
|
||||||
|
new ParseImageListFromJsonResponse(gson).apply(stream);
|
||||||
|
return Iterables.getOnlyElement(allImages);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,55 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* 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.ServerImage;
|
||||||
|
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;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Oleksiy Yarmula
|
||||||
|
*/
|
||||||
|
public class ParseImageListFromJsonResponse extends ParseJson<SortedSet<ServerImage>> {
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
public ParseImageListFromJsonResponse(Gson gson) {
|
||||||
|
super(gson);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SortedSet<ServerImage> apply(InputStream stream) {
|
||||||
|
Type setType = new TypeToken<GenericResponseContainer<ServerImage>>() {
|
||||||
|
}.getType();
|
||||||
|
GenericResponseContainer<ServerImage> 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,57 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* 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.Ip;
|
||||||
|
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.Ip ips} from a json string.
|
||||||
|
*
|
||||||
|
* @author Oleksiy Yarmula
|
||||||
|
*/
|
||||||
|
public class ParseIpListFromJsonResponse extends ParseJson<SortedSet<Ip>> {
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
public ParseIpListFromJsonResponse(Gson gson) {
|
||||||
|
super(gson);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SortedSet<Ip> apply(InputStream stream) {
|
||||||
|
Type setType = new TypeToken<GenericResponseContainer<Ip>>() {
|
||||||
|
}.getType();
|
||||||
|
GenericResponseContainer<Ip> 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,57 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* 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.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.Job jobs} from a json string.
|
||||||
|
*
|
||||||
|
* @author Oleksiy Yarmula
|
||||||
|
*/
|
||||||
|
public class ParseJobListFromJsonResponse extends ParseJson<SortedSet<Job>> {
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
public ParseJobListFromJsonResponse(Gson gson) {
|
||||||
|
super(gson);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SortedSet<Job> apply(InputStream stream) {
|
||||||
|
Type setType = new TypeToken<GenericResponseContainer<Job>>() {
|
||||||
|
}.getType();
|
||||||
|
GenericResponseContainer<Job> 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,50 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* 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.gson.Gson;
|
||||||
|
import org.jclouds.gogrid.domain.LoadBalancer;
|
||||||
|
import org.jclouds.http.functions.ParseJson;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.util.SortedSet;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parses the single load balancer out of the response.
|
||||||
|
*
|
||||||
|
* This class delegates parsing to {@link ParseLoadBalancerListFromJsonResponse}.
|
||||||
|
*
|
||||||
|
* @author Oleksiy Yarmula
|
||||||
|
*/
|
||||||
|
public class ParseLoadBalancerFromJsonResponse extends ParseJson<LoadBalancer> {
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
public ParseLoadBalancerFromJsonResponse(Gson gson) {
|
||||||
|
super(gson);
|
||||||
|
}
|
||||||
|
|
||||||
|
public LoadBalancer apply(InputStream stream) {
|
||||||
|
SortedSet<LoadBalancer> allLoadBalancers =
|
||||||
|
new ParseLoadBalancerListFromJsonResponse(gson).apply(stream);
|
||||||
|
return Iterables.getOnlyElement(allLoadBalancers);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -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,53 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||||
|
*
|
||||||
|
* ====================================================================
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF 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.functions;
|
||||||
|
|
||||||
|
import com.google.common.collect.Iterables;
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
import org.jclouds.gogrid.domain.Server;
|
||||||
|
import org.jclouds.http.functions.ParseJson;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.util.SortedSet;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parses a single {@link Server} from a json string.
|
||||||
|
*
|
||||||
|
* This class delegates parsing to {@link ParseServerListFromJsonResponse}.
|
||||||
|
*
|
||||||
|
* @author Oleksiy Yarmula
|
||||||
|
*/
|
||||||
|
public class ParseServerFromJsonResponse extends ParseJson<Server> {
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
public ParseServerFromJsonResponse(Gson gson) {
|
||||||
|
super(gson);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Server apply(InputStream stream) {
|
||||||
|
SortedSet<Server> allServers = new ParseServerListFromJsonResponse(gson).apply(stream);
|
||||||
|
return Iterables.getOnlyElement(allServers);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,67 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||||
|
*
|
||||||
|
* ====================================================================
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF 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.functions;
|
||||||
|
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.io.UnsupportedEncodingException;
|
||||||
|
import java.lang.reflect.Type;
|
||||||
|
import java.util.SortedSet;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
|
import com.google.common.collect.Sets;
|
||||||
|
import org.jclouds.gogrid.domain.Server;
|
||||||
|
import org.jclouds.gogrid.domain.internal.GenericResponseContainer;
|
||||||
|
import org.jclouds.http.functions.ParseJson;
|
||||||
|
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
import com.google.gson.reflect.TypeToken;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parses {@link Server servers} from a json string.
|
||||||
|
*
|
||||||
|
* @author Adrian Cole
|
||||||
|
*/
|
||||||
|
@Singleton
|
||||||
|
public class ParseServerListFromJsonResponse extends ParseJson<SortedSet<Server>> {
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
public ParseServerListFromJsonResponse(Gson gson) {
|
||||||
|
super(gson);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SortedSet<Server> apply(InputStream stream) {
|
||||||
|
Type setType = new TypeToken<GenericResponseContainer<Server>>() {
|
||||||
|
}.getType();
|
||||||
|
GenericResponseContainer<Server> 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,103 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class JobStateAdapter implements JsonDeserializer<JobState> {
|
||||||
|
@Override
|
||||||
|
public JobState deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext context) throws JsonParseException {
|
||||||
|
String name = ((JsonObject) jsonElement).get("name").getAsString();
|
||||||
|
return JobState.fromValue(name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class ServerImageStateAdapter implements JsonDeserializer<ServerImageState> {
|
||||||
|
@Override
|
||||||
|
public ServerImageState deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext context) throws JsonParseException {
|
||||||
|
String name = ((JsonObject) jsonElement).get("name").getAsString();
|
||||||
|
return ServerImageState.fromValue(name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class ServerImageTypeAdapter implements JsonDeserializer<ServerImageType> {
|
||||||
|
@Override
|
||||||
|
public ServerImageType deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext context) throws JsonParseException {
|
||||||
|
String name = ((JsonObject) jsonElement).get("name").getAsString();
|
||||||
|
return ServerImageType.fromValue(name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,73 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||||
|
*
|
||||||
|
* ====================================================================
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF 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.handlers;
|
||||||
|
|
||||||
|
import com.google.common.io.Closeables;
|
||||||
|
import com.google.inject.Inject;
|
||||||
|
import org.jclouds.gogrid.GoGridResponseException;
|
||||||
|
import org.jclouds.gogrid.domain.internal.ErrorResponse;
|
||||||
|
import org.jclouds.gogrid.functions.ParseErrorFromJsonResponse;
|
||||||
|
import org.jclouds.http.HttpCommand;
|
||||||
|
import org.jclouds.http.HttpErrorHandler;
|
||||||
|
import org.jclouds.http.HttpResponse;
|
||||||
|
import org.jclouds.http.HttpResponseException;
|
||||||
|
import org.jclouds.rest.AuthorizationException;
|
||||||
|
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Oleksiy Yarmula
|
||||||
|
*/
|
||||||
|
public class GoGridErrorHandler implements HttpErrorHandler {
|
||||||
|
|
||||||
|
private final ParseErrorFromJsonResponse errorParser;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
public GoGridErrorHandler(ParseErrorFromJsonResponse errorParser) {
|
||||||
|
this.errorParser = errorParser;
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings({"ThrowableInstanceNeverThrown"})
|
||||||
|
@Override
|
||||||
|
public void handleError(HttpCommand command, HttpResponse response) {
|
||||||
|
Exception exception;
|
||||||
|
Set<ErrorResponse> errors = parseErrorsFromContentOrNull(response.getContent());
|
||||||
|
switch (response.getStatusCode()) {
|
||||||
|
default:
|
||||||
|
exception = errors != null ?
|
||||||
|
new GoGridResponseException(command, response, errors) :
|
||||||
|
new HttpResponseException(command, response);
|
||||||
|
}
|
||||||
|
command.setException(exception);
|
||||||
|
Closeables.closeQuietly(response.getContent());
|
||||||
|
}
|
||||||
|
|
||||||
|
Set<ErrorResponse> parseErrorsFromContentOrNull(InputStream content) {
|
||||||
|
if (content != null) {
|
||||||
|
return errorParser.apply(content);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,80 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||||
|
*
|
||||||
|
* ====================================================================
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF 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.internal;
|
||||||
|
|
||||||
|
import com.google.inject.Inject;
|
||||||
|
import com.google.inject.Singleton;
|
||||||
|
import org.jclouds.gogrid.GoGridAsyncClient;
|
||||||
|
import org.jclouds.gogrid.services.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Oleksiy Yarmula
|
||||||
|
*/
|
||||||
|
@Singleton
|
||||||
|
public class GoGridAsyncClientImpl implements GoGridAsyncClient {
|
||||||
|
|
||||||
|
private GridServerAsyncClient gridServerAsyncClient;
|
||||||
|
private GridJobAsyncClient gridJobAsyncClient;
|
||||||
|
private GridIpAsyncClient gridIpAsyncClient;
|
||||||
|
private GridLoadBalancerAsyncClient gridLoadBalancerAsyncClient;
|
||||||
|
private GridImageAsyncClient gridImageAsyncClient;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
public GoGridAsyncClientImpl(GridServerAsyncClient gridServerClient,
|
||||||
|
GridJobAsyncClient gridJobAsyncClient,
|
||||||
|
GridIpAsyncClient gridIpAsyncClient,
|
||||||
|
GridLoadBalancerAsyncClient gridLoadBalancerAsyncClient,
|
||||||
|
GridImageAsyncClient gridImageAsyncClient) {
|
||||||
|
this.gridServerAsyncClient = gridServerClient;
|
||||||
|
this.gridJobAsyncClient = gridJobAsyncClient;
|
||||||
|
this.gridIpAsyncClient = gridIpAsyncClient;
|
||||||
|
this.gridLoadBalancerAsyncClient = gridLoadBalancerAsyncClient;
|
||||||
|
this.gridImageAsyncClient = gridImageAsyncClient;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public GridServerAsyncClient getServerServices() {
|
||||||
|
return gridServerAsyncClient;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public GridJobAsyncClient getJobServices() {
|
||||||
|
return gridJobAsyncClient;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public GridIpAsyncClient getIpServices() {
|
||||||
|
return gridIpAsyncClient;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public GridLoadBalancerAsyncClient getLoadBalancerServices() {
|
||||||
|
return gridLoadBalancerAsyncClient;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public GridImageAsyncClient getImageServices() {
|
||||||
|
return gridImageAsyncClient;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,80 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||||
|
*
|
||||||
|
* ====================================================================
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF 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.internal;
|
||||||
|
|
||||||
|
import com.google.inject.Inject;
|
||||||
|
import com.google.inject.Singleton;
|
||||||
|
import org.jclouds.gogrid.GoGridClient;
|
||||||
|
import org.jclouds.gogrid.services.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Oleksiy Yarmula
|
||||||
|
*/
|
||||||
|
@Singleton
|
||||||
|
public class GoGridClientImpl implements GoGridClient {
|
||||||
|
|
||||||
|
private GridServerClient gridServerClient;
|
||||||
|
private GridJobClient gridJobClient;
|
||||||
|
private GridIpClient gridIpClient;
|
||||||
|
private GridLoadBalancerClient gridLoadBalancerClient;
|
||||||
|
private GridImageClient gridImageClient;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
public GoGridClientImpl(GridServerClient gridServerClient,
|
||||||
|
GridJobClient gridJobClient,
|
||||||
|
GridIpClient gridIpClient,
|
||||||
|
GridLoadBalancerClient gridLoadBalancerClient,
|
||||||
|
GridImageClient gridImageClient) {
|
||||||
|
this.gridServerClient = gridServerClient;
|
||||||
|
this.gridJobClient = gridJobClient;
|
||||||
|
this.gridIpClient = gridIpClient;
|
||||||
|
this.gridLoadBalancerClient = gridLoadBalancerClient;
|
||||||
|
this.gridImageClient = gridImageClient;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public GridServerClient getServerServices() {
|
||||||
|
return gridServerClient;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public GridJobClient getJobServices() {
|
||||||
|
return gridJobClient;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public GridIpClient getIpServices() {
|
||||||
|
return gridIpClient;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public GridLoadBalancerClient getLoadBalancerServices() {
|
||||||
|
return gridLoadBalancerClient;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public GridImageClient getImageServices() {
|
||||||
|
return gridImageClient;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,65 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* 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.options;
|
||||||
|
|
||||||
|
import org.jclouds.gogrid.domain.LoadBalancerPersistenceType;
|
||||||
|
import org.jclouds.gogrid.domain.LoadBalancerType;
|
||||||
|
import org.jclouds.http.options.BaseHttpRequestOptions;
|
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.checkState;
|
||||||
|
import static org.jclouds.gogrid.reference.GoGridQueryParams.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Optional parameters for adding a load balancer.
|
||||||
|
*
|
||||||
|
* @see org.jclouds.gogrid.services.GridLoadBalancerClient#addLoadBalancer
|
||||||
|
* @see <a href="http://wiki.gogrid.com/wiki/index.php/API:grid.loadbalancer.add"/>
|
||||||
|
*
|
||||||
|
* @author Oleksiy Yarmula
|
||||||
|
*/
|
||||||
|
public class AddLoadBalancerOptions extends BaseHttpRequestOptions {
|
||||||
|
|
||||||
|
public AddLoadBalancerOptions setDescription(String description) {
|
||||||
|
checkState(!queryParameters.containsKey(DESCRIPTION_KEY), "Can't have duplicate " +
|
||||||
|
"load balancer description");
|
||||||
|
queryParameters.put(DESCRIPTION_KEY, description);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AddLoadBalancerOptions setType(LoadBalancerType loadBalancerType) {
|
||||||
|
checkState(!queryParameters.containsKey(LOAD_BALANCER_TYPE_KEY), "Can't have duplicate " +
|
||||||
|
"load balancer type limitation");
|
||||||
|
queryParameters.put(LOAD_BALANCER_TYPE_KEY, loadBalancerType.toString());
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AddLoadBalancerOptions setPersistenceType(LoadBalancerPersistenceType loadBalancerPersistenceType) {
|
||||||
|
checkState(!queryParameters.containsKey(LOAD_BALANCER_PERSISTENCE_TYPE_KEY), "Can't have duplicate " +
|
||||||
|
"load balancer type limitation");
|
||||||
|
queryParameters.put(LOAD_BALANCER_PERSISTENCE_TYPE_KEY, loadBalancerPersistenceType.toString());
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class Builder {
|
||||||
|
public AddLoadBalancerOptions create(LoadBalancerType type,
|
||||||
|
LoadBalancerPersistenceType persistenceType) {
|
||||||
|
return new AddLoadBalancerOptions().setType(type).setPersistenceType(persistenceType);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,54 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||||
|
*
|
||||||
|
* ====================================================================
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF 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.options;
|
||||||
|
|
||||||
|
import org.jclouds.http.options.BaseHttpRequestOptions;
|
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.checkState;
|
||||||
|
import static org.jclouds.gogrid.reference.GoGridQueryParams.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Oleksiy Yarmula
|
||||||
|
*/
|
||||||
|
public class AddServerOptions extends BaseHttpRequestOptions {
|
||||||
|
|
||||||
|
public AddServerOptions setDescription(String description) {
|
||||||
|
checkState(!queryParameters.containsKey(DESCRIPTION_KEY), "Can't have duplicate server description");
|
||||||
|
queryParameters.put(DESCRIPTION_KEY, description);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Make server a sandbox instance.
|
||||||
|
* By default, it's not.
|
||||||
|
*
|
||||||
|
* @return itself for convenience
|
||||||
|
*/
|
||||||
|
public AddServerOptions makeSandboxType() {
|
||||||
|
checkState(!queryParameters.containsKey(IS_SANDBOX_KEY), "Can only have one sandbox option per server");
|
||||||
|
queryParameters.put(IS_SANDBOX_KEY, "true");
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,77 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* 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.options;
|
||||||
|
|
||||||
|
import org.jclouds.gogrid.domain.ServerImageState;
|
||||||
|
import org.jclouds.gogrid.domain.ServerImageType;
|
||||||
|
import org.jclouds.http.options.BaseHttpRequestOptions;
|
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.checkState;
|
||||||
|
import static org.jclouds.gogrid.reference.GoGridQueryParams.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Oleksiy Yarmula
|
||||||
|
*/
|
||||||
|
public class GetImageListOptions extends BaseHttpRequestOptions {
|
||||||
|
|
||||||
|
public GetImageListOptions setType(ServerImageType imageType) {
|
||||||
|
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");
|
||||||
|
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");
|
||||||
|
queryParameters.put(IS_PUBLIC_KEY, "true");
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public GetImageListOptions onlyPrivate() {
|
||||||
|
checkState(!queryParameters.containsKey(IS_PUBLIC_KEY), "Can't have duplicate image visibility restrictions");
|
||||||
|
queryParameters.put(IS_PUBLIC_KEY, "false");
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public GetImageListOptions 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 static class Builder {
|
||||||
|
public 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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,68 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* 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.options;
|
||||||
|
|
||||||
|
import org.jclouds.gogrid.domain.IpState;
|
||||||
|
import org.jclouds.gogrid.domain.IpType;
|
||||||
|
import org.jclouds.http.options.BaseHttpRequestOptions;
|
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.checkState;
|
||||||
|
import static org.jclouds.gogrid.reference.GoGridQueryParams.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Oleksiy Yarmula
|
||||||
|
*/
|
||||||
|
public class GetIpListOptions extends BaseHttpRequestOptions {
|
||||||
|
|
||||||
|
public static final GetIpListOptions NONE = new GetIpListOptions();
|
||||||
|
|
||||||
|
public GetIpListOptions onlyAssigned() {
|
||||||
|
checkState(!queryParameters.containsKey(IP_STATE_KEY), "Can't have multiple values for whether IP is assigned");
|
||||||
|
queryParameters.put(IP_STATE_KEY, IpState.ASSIGNED.toString());
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public GetIpListOptions onlyUnassigned() {
|
||||||
|
checkState(!queryParameters.containsKey(IP_STATE_KEY), "Can't have multiple values for whether IP is assigned");
|
||||||
|
queryParameters.put(IP_STATE_KEY, IpState.UNASSIGNED.toString());
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public GetIpListOptions onlyWithType(IpType type) {
|
||||||
|
checkState(!queryParameters.containsKey(IP_TYPE_KEY), "Can't have multiple values for ip type limit");
|
||||||
|
queryParameters.put(IP_TYPE_KEY, type.toString());
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class Builder {
|
||||||
|
|
||||||
|
public GetIpListOptions create() {
|
||||||
|
return new GetIpListOptions();
|
||||||
|
}
|
||||||
|
|
||||||
|
public GetIpListOptions limitToType(IpType type) {
|
||||||
|
return new GetIpListOptions().onlyWithType(type);
|
||||||
|
}
|
||||||
|
|
||||||
|
public GetIpListOptions unassignedPublicIps() {
|
||||||
|
return new GetIpListOptions().onlyWithType(IpType.PUBLIC).onlyUnassigned();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,104 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* 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.options;
|
||||||
|
|
||||||
|
import org.jclouds.gogrid.domain.JobState;
|
||||||
|
import org.jclouds.gogrid.domain.ObjectType;
|
||||||
|
import org.jclouds.http.options.BaseHttpRequestOptions;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.checkState;
|
||||||
|
import static org.jclouds.gogrid.reference.GoGridQueryParams.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Oleksiy Yarmula
|
||||||
|
*/
|
||||||
|
public class GetJobListOptions extends BaseHttpRequestOptions {
|
||||||
|
|
||||||
|
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 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 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 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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;
|
||||||
|
|
||||||
|
GetJobListOptions options = (GetJobListOptions) o;
|
||||||
|
|
||||||
|
return buildQueryParameters().equals(options.buildQueryParameters());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class Builder {
|
||||||
|
public GetJobListOptions create() {
|
||||||
|
return new GetJobListOptions();
|
||||||
|
}
|
||||||
|
|
||||||
|
public GetJobListOptions latestJobForObjectByName(String serverName) {
|
||||||
|
return new GetJobListOptions().
|
||||||
|
maxItemsNumber(1).
|
||||||
|
onlyForObjectName(serverName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,80 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||||
|
*
|
||||||
|
* ====================================================================
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF 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.options;
|
||||||
|
|
||||||
|
import org.jclouds.http.options.BaseHttpRequestOptions;
|
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.*;
|
||||||
|
import static org.jclouds.gogrid.reference.GoGridQueryParams.SERVER_TYPE_KEY;
|
||||||
|
import static org.jclouds.gogrid.reference.GoGridQueryParams.IS_SANDBOX_KEY;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Oleksiy Yarmula
|
||||||
|
*/
|
||||||
|
public class GetServerListOptions extends BaseHttpRequestOptions {
|
||||||
|
|
||||||
|
public final static GetServerListOptions NONE = new GetServerListOptions();
|
||||||
|
|
||||||
|
public GetServerListOptions limitServerTypeTo(String serverType) {
|
||||||
|
checkState(!queryParameters.containsKey(SERVER_TYPE_KEY), "Can't have duplicate server type limit");
|
||||||
|
queryParameters.put(SERVER_TYPE_KEY, serverType);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public GetServerListOptions onlySandboxServers() {
|
||||||
|
checkState(!queryParameters.containsKey(IS_SANDBOX_KEY), "Can't have duplicate sandbox type limit");
|
||||||
|
queryParameters.put(IS_SANDBOX_KEY, "true");
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public GetServerListOptions excludeSandboxServers() {
|
||||||
|
checkState(!queryParameters.containsKey(IS_SANDBOX_KEY), "Can't have duplicate sandbox type limit");
|
||||||
|
queryParameters.put(IS_SANDBOX_KEY, "false");
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class Builder {
|
||||||
|
|
||||||
|
public GetServerListOptions limitServerTypeTo(String serverType) {
|
||||||
|
GetServerListOptions getServerListOptions = new GetServerListOptions();
|
||||||
|
getServerListOptions.limitServerTypeTo(checkNotNull(serverType));
|
||||||
|
return getServerListOptions;
|
||||||
|
}
|
||||||
|
|
||||||
|
public GetServerListOptions onlySandboxServers() {
|
||||||
|
GetServerListOptions getServerListOptions = new GetServerListOptions();
|
||||||
|
getServerListOptions.onlySandboxServers();
|
||||||
|
return getServerListOptions;
|
||||||
|
}
|
||||||
|
|
||||||
|
public GetServerListOptions excludeSandboxServers() {
|
||||||
|
GetServerListOptions getServerListOptions = new GetServerListOptions();
|
||||||
|
getServerListOptions.excludeSandboxServers();
|
||||||
|
return getServerListOptions;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,61 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* 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.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 javax.annotation.Resource;
|
||||||
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Oleksiy Yarmula
|
||||||
|
*/
|
||||||
|
@Singleton
|
||||||
|
public class LoadBalancerLatestJobCompleted implements Predicate<LoadBalancer> {
|
||||||
|
|
||||||
|
protected GridJobClient jobClient;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
protected Logger logger = Logger.NULL;
|
||||||
|
|
||||||
|
@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());
|
||||||
|
}
|
||||||
|
}
|
|
@ -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.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 javax.annotation.Resource;
|
||||||
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
protected Logger logger = Logger.NULL;
|
||||||
|
|
||||||
|
@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());
|
||||||
|
}
|
||||||
|
}
|
|
@ -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.
|
||||||
|
* ====================================================================
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||||
|
*
|
||||||
|
* ====================================================================
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF 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.reference;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Configuration properties and constants used in GoGrid connections.
|
||||||
|
*
|
||||||
|
* @author Adrian Cole
|
||||||
|
*/
|
||||||
|
public interface GoGridConstants {
|
||||||
|
public static final String PROPERTY_GOGRID_ENDPOINT = "jclouds.gogrid.endpoint";
|
||||||
|
public static final String PROPERTY_GOGRID_USER = "jclouds.gogrid.api.key";
|
||||||
|
public static final String PROPERTY_GOGRID_PASSWORD = "jclouds.gogrid.secret";
|
||||||
|
/**
|
||||||
|
* how long do we wait before obtaining a new timestamp for requests.
|
||||||
|
*/
|
||||||
|
public static final String PROPERTY_GOGRID_SESSIONINTERVAL = "jclouds.gogrid.sessioninterval";
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,31 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||||
|
*
|
||||||
|
* ====================================================================
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF 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.reference;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Oleksiy Yarmula
|
||||||
|
*/
|
||||||
|
public interface GoGridHeaders {
|
||||||
|
public static final String VERSION = "v";
|
||||||
|
}
|
|
@ -0,0 +1,69 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||||
|
*
|
||||||
|
* ====================================================================
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF 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.reference;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Oleksiy Yarmula
|
||||||
|
*/
|
||||||
|
public interface GoGridQueryParams {
|
||||||
|
|
||||||
|
public static final String ID_KEY = "id";
|
||||||
|
public static final String NAME_KEY = "name";
|
||||||
|
public static final String SERVER_ID_OR_NAME_KEY = "server";
|
||||||
|
public static final String SERVER_TYPE_KEY = "server.type";
|
||||||
|
|
||||||
|
public static final String IS_SANDBOX_KEY = "isSandbox";
|
||||||
|
public static final String IMAGE_KEY = "image";
|
||||||
|
public static final String IP_KEY = "ip";
|
||||||
|
|
||||||
|
public static final String SERVER_RAM_KEY = "server.ram";
|
||||||
|
|
||||||
|
public static final String DESCRIPTION_KEY = "server.ram";
|
||||||
|
public static final String POWER_KEY = "power";
|
||||||
|
|
||||||
|
public static final String MAX_NUMBER_KEY = "num_items";
|
||||||
|
public static final String START_DATE_KEY = "startdate";
|
||||||
|
public static final String END_DATE_KEY = "enddate";
|
||||||
|
public static final String OWNER_KEY = "owner";
|
||||||
|
|
||||||
|
public static final String JOB_STATE_KEY = "job.state";
|
||||||
|
public static final String JOB_OBJECT_TYPE_KEY = "job.objecttype";
|
||||||
|
|
||||||
|
public static final String OBJECT_KEY = "object";
|
||||||
|
|
||||||
|
public static final String IP_STATE_KEY = "ip.state";
|
||||||
|
public static final String IP_TYPE_KEY = "ip.type";
|
||||||
|
|
||||||
|
public static final String LOAD_BALANCER_KEY = "loadbalancer";
|
||||||
|
public static final String LOAD_BALANCER_TYPE_KEY = "loadbalancer.type";
|
||||||
|
public static final String LOAD_BALANCER_PERSISTENCE_TYPE_KEY = "loadbalancer.persistence";
|
||||||
|
public static final String VIRTUAL_IP_KEY = "virtualip.";
|
||||||
|
public static final String REAL_IP_LIST_KEY = "realiplist.";
|
||||||
|
|
||||||
|
public static final String IS_PUBLIC_KEY = "isPublic";
|
||||||
|
public static final String IMAGE_TYPE_KEY = "image.type";
|
||||||
|
public static final String IMAGE_STATE_KEY = "image.state";
|
||||||
|
public static final String IMAGE_FRIENDLY_NAME_KEY = "friendlyName";
|
||||||
|
public static final String IMAGE_DESCRIPTION_KEY = "description";
|
||||||
|
}
|
|
@ -0,0 +1,75 @@
|
||||||
|
package org.jclouds.gogrid.services;
|
||||||
|
|
||||||
|
import com.google.common.util.concurrent.ListenableFuture;
|
||||||
|
import org.jclouds.gogrid.GoGrid;
|
||||||
|
import org.jclouds.gogrid.binders.BindIdsToQueryParams;
|
||||||
|
import org.jclouds.gogrid.binders.BindNamesToQueryParams;
|
||||||
|
import org.jclouds.gogrid.domain.ServerImage;
|
||||||
|
import org.jclouds.gogrid.filters.SharedKeyLiteAuthentication;
|
||||||
|
import org.jclouds.gogrid.functions.ParseImageFromJsonResponse;
|
||||||
|
import org.jclouds.gogrid.functions.ParseImageListFromJsonResponse;
|
||||||
|
import org.jclouds.gogrid.options.GetImageListOptions;
|
||||||
|
import org.jclouds.rest.annotations.*;
|
||||||
|
|
||||||
|
import javax.ws.rs.GET;
|
||||||
|
import javax.ws.rs.Path;
|
||||||
|
import javax.ws.rs.QueryParam;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import static org.jclouds.gogrid.reference.GoGridHeaders.VERSION;
|
||||||
|
import static org.jclouds.gogrid.reference.GoGridQueryParams.IMAGE_KEY;
|
||||||
|
import static org.jclouds.gogrid.reference.GoGridQueryParams.IMAGE_DESCRIPTION_KEY;
|
||||||
|
import static org.jclouds.gogrid.reference.GoGridQueryParams.IMAGE_FRIENDLY_NAME_KEY;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Oleksiy Yarmula
|
||||||
|
*/
|
||||||
|
@Endpoint(GoGrid.class)
|
||||||
|
@RequestFilters(SharedKeyLiteAuthentication.class)
|
||||||
|
@QueryParams(keys = VERSION, values = "1.4")
|
||||||
|
public interface GridImageAsyncClient {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see GridImageClient#getImageList
|
||||||
|
*/
|
||||||
|
@GET
|
||||||
|
@ResponseParser(ParseImageListFromJsonResponse.class)
|
||||||
|
@Path("/grid/image/list")
|
||||||
|
ListenableFuture<Set<ServerImage>> getImageList(GetImageListOptions... options);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see GridImageClient#getImagesById
|
||||||
|
*/
|
||||||
|
@GET
|
||||||
|
@ResponseParser(ParseImageListFromJsonResponse.class)
|
||||||
|
@Path("/grid/image/get")
|
||||||
|
ListenableFuture<Set<ServerImage>> getImagesById(@BinderParam(BindIdsToQueryParams.class) Long... ids);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see GridImageClient#getImagesByName
|
||||||
|
*/
|
||||||
|
@GET
|
||||||
|
@ResponseParser(ParseImageListFromJsonResponse.class)
|
||||||
|
@Path("/grid/image/get")
|
||||||
|
ListenableFuture<Set<ServerImage>> getImagesByName(@BinderParam(BindNamesToQueryParams.class) String... names);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see GridImageClient#editImageDescription
|
||||||
|
*/
|
||||||
|
@GET
|
||||||
|
@ResponseParser(ParseImageFromJsonResponse.class)
|
||||||
|
@Path("/grid/image/edit")
|
||||||
|
ListenableFuture<ServerImage> editImageDescription(@QueryParam(IMAGE_KEY) String idOrName,
|
||||||
|
@QueryParam(IMAGE_DESCRIPTION_KEY) String newDescription);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see GridImageClient#editImageFriendlyName
|
||||||
|
*/
|
||||||
|
@GET
|
||||||
|
@ResponseParser(ParseImageFromJsonResponse.class)
|
||||||
|
@Path("/grid/image/edit")
|
||||||
|
ListenableFuture<ServerImage> editImageFriendlyName(@QueryParam(IMAGE_KEY) String idOrName,
|
||||||
|
@QueryParam(IMAGE_FRIENDLY_NAME_KEY) String newFriendlyName);
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,61 @@
|
||||||
|
package org.jclouds.gogrid.services;
|
||||||
|
|
||||||
|
import org.jclouds.concurrent.Timeout;
|
||||||
|
import org.jclouds.gogrid.binders.BindIdsToQueryParams;
|
||||||
|
import org.jclouds.gogrid.domain.ServerImage;
|
||||||
|
import org.jclouds.gogrid.options.GetImageListOptions;
|
||||||
|
import org.jclouds.rest.annotations.BinderParam;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Manages the server images
|
||||||
|
*
|
||||||
|
* @see <a href="http://wiki.gogrid.com/wiki/index.php/API#Server_Image_Methods"/>
|
||||||
|
* @author Oleksiy Yarmula
|
||||||
|
*/
|
||||||
|
@Timeout(duration = 30, timeUnit = TimeUnit.SECONDS)
|
||||||
|
public interface GridImageClient {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns all server images.
|
||||||
|
*
|
||||||
|
* @param options options to narrow the search down
|
||||||
|
* @return server images found
|
||||||
|
*/
|
||||||
|
Set<ServerImage> getImageList(GetImageListOptions... options);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns images, found by specified ids
|
||||||
|
* @param ids the ids that match existing images
|
||||||
|
* @return images found
|
||||||
|
*/
|
||||||
|
Set<ServerImage> getImagesById(Long... ids);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns images, found by specified names
|
||||||
|
* @param names the names that march existing images
|
||||||
|
* @return images found
|
||||||
|
*/
|
||||||
|
Set<ServerImage> getImagesByName(String... names);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Edits an existing image
|
||||||
|
*
|
||||||
|
* @param idOrName id or name of the existing image
|
||||||
|
* @param newDescription description to replace the current one
|
||||||
|
* @return edited server image
|
||||||
|
*/
|
||||||
|
ServerImage editImageDescription(String idOrName, String newDescription);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Edits an existing image
|
||||||
|
*
|
||||||
|
* @param idOrName id or name of the existing image
|
||||||
|
* @param newFriendlyName friendly name to replace the current one
|
||||||
|
* @return edited server image
|
||||||
|
*/
|
||||||
|
ServerImage editImageFriendlyName(String idOrName, String newFriendlyName);
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,78 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* 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.Ip;
|
||||||
|
import org.jclouds.gogrid.domain.IpState;
|
||||||
|
import org.jclouds.gogrid.domain.IpType;
|
||||||
|
import org.jclouds.gogrid.filters.SharedKeyLiteAuthentication;
|
||||||
|
import org.jclouds.gogrid.functions.ParseIpListFromJsonResponse;
|
||||||
|
import org.jclouds.gogrid.options.GetIpListOptions;
|
||||||
|
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;
|
||||||
|
import static org.jclouds.gogrid.reference.GoGridQueryParams.IP_STATE_KEY;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.jclouds.gogrid.services.GridImageClient
|
||||||
|
*
|
||||||
|
* @author Oleksiy Yarmula
|
||||||
|
*/
|
||||||
|
@Endpoint(GoGrid.class)
|
||||||
|
@RequestFilters(SharedKeyLiteAuthentication.class)
|
||||||
|
@QueryParams(keys = VERSION, values = "1.3")
|
||||||
|
public interface GridIpAsyncClient {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see GridIpClient#getIpList(org.jclouds.gogrid.options.GetIpListOptions...)
|
||||||
|
*/
|
||||||
|
@GET
|
||||||
|
@ResponseParser(ParseIpListFromJsonResponse.class)
|
||||||
|
@Path("/grid/ip/list")
|
||||||
|
ListenableFuture<Set<Ip>> getIpList(GetIpListOptions... options);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.jclouds.gogrid.services.GridIpClient#getUnassignedIpList()
|
||||||
|
*/
|
||||||
|
@GET
|
||||||
|
@ResponseParser(ParseIpListFromJsonResponse.class)
|
||||||
|
@Path("/grid/ip/list")
|
||||||
|
@QueryParams(keys = IP_STATE_KEY, values = "Unassigned")
|
||||||
|
ListenableFuture<Set<Ip>> getUnassignedIpList();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.jclouds.gogrid.services.GridIpClient#getAssignedIpList()
|
||||||
|
*/
|
||||||
|
@GET
|
||||||
|
@ResponseParser(ParseIpListFromJsonResponse.class)
|
||||||
|
@Path("/grid/ip/list")
|
||||||
|
@QueryParams(keys = IP_STATE_KEY, values = "Assigned")
|
||||||
|
ListenableFuture<Set<Ip>> getAssignedIpList();
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -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 org.jclouds.concurrent.Timeout;
|
||||||
|
import org.jclouds.gogrid.domain.Ip;
|
||||||
|
import org.jclouds.gogrid.options.GetIpListOptions;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Oleksiy Yarmula
|
||||||
|
*/
|
||||||
|
@Timeout(duration = 30, timeUnit = TimeUnit.SECONDS)
|
||||||
|
public interface GridIpClient {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns all IPs in the system
|
||||||
|
* that match the options
|
||||||
|
* @param options options to narrow the search down
|
||||||
|
* @return IPs found by the search
|
||||||
|
*/
|
||||||
|
Set<Ip> getIpList(GetIpListOptions... options);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the list of unassigned IPs
|
||||||
|
* @return unassigned IPs
|
||||||
|
*/
|
||||||
|
Set<Ip> getUnassignedIpList();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the list of assigned IPs
|
||||||
|
* @return assigned IPs
|
||||||
|
*/
|
||||||
|
Set<Ip> getAssignedIpList();
|
||||||
|
}
|
|
@ -0,0 +1,71 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* 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.binders.BindIdsToQueryParams;
|
||||||
|
import org.jclouds.gogrid.binders.BindObjectNameToGetJobsRequestQueryParams;
|
||||||
|
import org.jclouds.gogrid.domain.Job;
|
||||||
|
import org.jclouds.gogrid.filters.SharedKeyLiteAuthentication;
|
||||||
|
import org.jclouds.gogrid.functions.ParseJobListFromJsonResponse;
|
||||||
|
import org.jclouds.gogrid.options.GetJobListOptions;
|
||||||
|
import org.jclouds.rest.annotations.*;
|
||||||
|
|
||||||
|
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.3")
|
||||||
|
public interface GridJobAsyncClient {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see GridJobClient#getJobList(org.jclouds.gogrid.options.GetJobListOptions...)
|
||||||
|
*/
|
||||||
|
@GET
|
||||||
|
@ResponseParser(ParseJobListFromJsonResponse.class)
|
||||||
|
@Path("/grid/job/list")
|
||||||
|
ListenableFuture<Set<Job>> getJobList(GetJobListOptions... options);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see GridJobClient#getJobsForObjectName(String)
|
||||||
|
*/
|
||||||
|
@GET
|
||||||
|
@ResponseParser(ParseJobListFromJsonResponse.class)
|
||||||
|
@Path("/grid/job/list")
|
||||||
|
ListenableFuture<Set<Job>> getJobsForObjectName(
|
||||||
|
@BinderParam(BindObjectNameToGetJobsRequestQueryParams.class) String objectName);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see GridJobClient#getJobsById(Long...)
|
||||||
|
*/
|
||||||
|
@GET
|
||||||
|
@ResponseParser(ParseJobListFromJsonResponse.class)
|
||||||
|
@Path("/grid/job/get")
|
||||||
|
ListenableFuture<Set<Job>> getJobsById(@BinderParam(BindIdsToQueryParams.class) Long... ids);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,76 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* 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.Job;
|
||||||
|
import org.jclouds.gogrid.options.GetJobListOptions;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Manages the customer's jobs.
|
||||||
|
*
|
||||||
|
* @see <a href="http://wiki.gogrid.com/wiki/index.php/API#Job_Methods" />
|
||||||
|
*
|
||||||
|
* @author Oleksiy Yarmula
|
||||||
|
*/
|
||||||
|
@Timeout(duration = 30, timeUnit = TimeUnit.SECONDS)
|
||||||
|
public interface GridJobClient {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns all jobs found.
|
||||||
|
* The resulting set may be narrowed
|
||||||
|
* down by providing {@link GetJobListOptions}.
|
||||||
|
*
|
||||||
|
* By default, the result is <=100 items from
|
||||||
|
* the date range of 4 weeks ago to now.
|
||||||
|
*
|
||||||
|
* NOTE: this method results in a big
|
||||||
|
* volume of data in response
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
* jobs found by request
|
||||||
|
*/
|
||||||
|
Set<Job> getJobList(GetJobListOptions... options);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns jobs found for an object with a provided name.
|
||||||
|
*
|
||||||
|
* Usually, in GoGrid a name will uniquely identify the object,
|
||||||
|
* or, as the docs state, some API methods will cause errors.
|
||||||
|
*
|
||||||
|
* @param serverName name of the object
|
||||||
|
* @return found jobs for the object
|
||||||
|
*/
|
||||||
|
Set<Job> getJobsForObjectName(String serverName);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns jobs for the corresponding id(s).
|
||||||
|
*
|
||||||
|
* NOTE: there is a 1:1 relation between a
|
||||||
|
* job and its ID.
|
||||||
|
*
|
||||||
|
* @param ids ids for the jobs
|
||||||
|
* @return jobs found by the ids
|
||||||
|
*/
|
||||||
|
Set<Job> getJobsById(Long... ids);
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,114 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* 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.binders.BindIdsToQueryParams;
|
||||||
|
import org.jclouds.gogrid.binders.BindNamesToQueryParams;
|
||||||
|
import org.jclouds.gogrid.binders.BindRealIpPortPairsToQueryParams;
|
||||||
|
import org.jclouds.gogrid.binders.BindVirtualIpPortPairToQueryParams;
|
||||||
|
import org.jclouds.gogrid.domain.IpPortPair;
|
||||||
|
import org.jclouds.gogrid.domain.LoadBalancer;
|
||||||
|
import org.jclouds.gogrid.filters.SharedKeyLiteAuthentication;
|
||||||
|
import org.jclouds.gogrid.functions.ParseLoadBalancerFromJsonResponse;
|
||||||
|
import org.jclouds.gogrid.functions.ParseLoadBalancerListFromJsonResponse;
|
||||||
|
import org.jclouds.gogrid.options.AddLoadBalancerOptions;
|
||||||
|
import org.jclouds.rest.annotations.*;
|
||||||
|
|
||||||
|
import javax.ws.rs.GET;
|
||||||
|
import javax.ws.rs.Path;
|
||||||
|
import javax.ws.rs.QueryParam;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import static org.jclouds.gogrid.reference.GoGridHeaders.VERSION;
|
||||||
|
import static org.jclouds.gogrid.reference.GoGridQueryParams.ID_KEY;
|
||||||
|
import static org.jclouds.gogrid.reference.GoGridQueryParams.NAME_KEY;
|
||||||
|
import static org.jclouds.gogrid.reference.GoGridQueryParams.LOAD_BALANCER_KEY;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @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();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see GridLoadBalancerClient#getLoadBalancersByName
|
||||||
|
*/
|
||||||
|
@GET
|
||||||
|
@ResponseParser(ParseLoadBalancerListFromJsonResponse.class)
|
||||||
|
@Path("/grid/loadbalancer/get")
|
||||||
|
ListenableFuture<Set<LoadBalancer>> getLoadBalancersByName(@BinderParam(BindNamesToQueryParams.class) String... names);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see GridLoadBalancerClient#getLoadBalancersById
|
||||||
|
*/
|
||||||
|
@GET
|
||||||
|
@ResponseParser(ParseLoadBalancerListFromJsonResponse.class)
|
||||||
|
@Path("/grid/loadbalancer/get")
|
||||||
|
ListenableFuture<Set<LoadBalancer>> getLoadBalancersById(@BinderParam(BindIdsToQueryParams.class) Long... ids);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see GridLoadBalancerClient#addLoadBalancer
|
||||||
|
*/
|
||||||
|
@GET
|
||||||
|
@ResponseParser(ParseLoadBalancerFromJsonResponse.class)
|
||||||
|
@Path("/grid/loadbalancer/add")
|
||||||
|
ListenableFuture<LoadBalancer> addLoadBalancer(@QueryParam(NAME_KEY) String name,
|
||||||
|
@BinderParam(BindVirtualIpPortPairToQueryParams.class) IpPortPair virtualIp,
|
||||||
|
@BinderParam(BindRealIpPortPairsToQueryParams.class) List<IpPortPair> realIps,
|
||||||
|
AddLoadBalancerOptions... options);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see GridLoadBalancerClient#editLoadBalancer
|
||||||
|
*/
|
||||||
|
@GET
|
||||||
|
@ResponseParser(ParseLoadBalancerFromJsonResponse.class)
|
||||||
|
@Path("/grid/loadbalancer/edit")
|
||||||
|
ListenableFuture<LoadBalancer> editLoadBalancer(@QueryParam(LOAD_BALANCER_KEY) String idOrName,
|
||||||
|
@BinderParam(BindRealIpPortPairsToQueryParams.class) List<IpPortPair> realIps);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see GridLoadBalancerClient#
|
||||||
|
*/
|
||||||
|
@GET
|
||||||
|
@ResponseParser(ParseLoadBalancerFromJsonResponse.class)
|
||||||
|
@Path("/grid/loadbalancer/delete")
|
||||||
|
ListenableFuture<LoadBalancer> deleteById(@QueryParam(ID_KEY) Long id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see GridLoadBalancerClient#
|
||||||
|
*/
|
||||||
|
@GET
|
||||||
|
@ResponseParser(ParseLoadBalancerFromJsonResponse.class)
|
||||||
|
@Path("/grid/loadbalancer/delete")
|
||||||
|
ListenableFuture<LoadBalancer> deleteByName(@QueryParam(NAME_KEY) String name);
|
||||||
|
}
|
|
@ -0,0 +1,118 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* 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.IpPortPair;
|
||||||
|
import org.jclouds.gogrid.domain.LoadBalancer;
|
||||||
|
import org.jclouds.gogrid.options.AddLoadBalancerOptions;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
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();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the load balancer(s) by unique name(s).
|
||||||
|
*
|
||||||
|
* Given a name or a set of names, finds one or
|
||||||
|
* multiple load balancers.
|
||||||
|
* @param names to get the load balancers
|
||||||
|
* @return load balancer(s) matching the name(s)
|
||||||
|
*/
|
||||||
|
Set<LoadBalancer> getLoadBalancersByName(String... names);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the load balancer(s) by unique id(s).
|
||||||
|
*
|
||||||
|
* Given an id or a set of ids, finds one or
|
||||||
|
* multiple load balancers.
|
||||||
|
* @param ids to get the load balancers
|
||||||
|
* @return load balancer(s) matching the ids
|
||||||
|
*/
|
||||||
|
Set<LoadBalancer> getLoadBalancersById(Long... ids);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a load balancer with given properties.
|
||||||
|
*
|
||||||
|
* @param name name of the load balancer
|
||||||
|
* @param virtualIp virtual IP with IP address set in
|
||||||
|
* {@link org.jclouds.gogrid.domain.Ip#ip} and
|
||||||
|
* port set in {@link IpPortPair#port}
|
||||||
|
* @param realIps real IPs to bind the virtual IP to, with
|
||||||
|
* IP address set in
|
||||||
|
* {@link org.jclouds.gogrid.domain.Ip#ip} and
|
||||||
|
* port set in {@link IpPortPair#port}
|
||||||
|
* @param options options that specify load balancer's type (round robin,
|
||||||
|
* least load), persistence strategy, or description.
|
||||||
|
* @return created load balancer object
|
||||||
|
*/
|
||||||
|
LoadBalancer addLoadBalancer(String name,
|
||||||
|
IpPortPair virtualIp,
|
||||||
|
List<IpPortPair> realIps,
|
||||||
|
AddLoadBalancerOptions... options);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Edits the existing load balancer to change the real
|
||||||
|
* IP mapping.
|
||||||
|
*
|
||||||
|
* @param idOrName id or name of the existing load balancer
|
||||||
|
* @param realIps real IPs to bind the virtual IP to, with
|
||||||
|
* IP address set in
|
||||||
|
* {@link org.jclouds.gogrid.domain.Ip#ip} and
|
||||||
|
* port set in {@link IpPortPair#port}
|
||||||
|
* @return edited object
|
||||||
|
*/
|
||||||
|
LoadBalancer editLoadBalancer(String idOrName,
|
||||||
|
List<IpPortPair> realIps);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deletes the load balancer by Id
|
||||||
|
*
|
||||||
|
* @param id
|
||||||
|
* id of the load balancer to delete
|
||||||
|
* @return load balancer before the command is executed
|
||||||
|
*/
|
||||||
|
LoadBalancer deleteById(Long id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deletes the load balancer by name;
|
||||||
|
*
|
||||||
|
* NOTE: Using this parameter may generate an
|
||||||
|
* error if one or more load balancers share a
|
||||||
|
* non-unique name.
|
||||||
|
*
|
||||||
|
* @param name
|
||||||
|
* name of the load balancer to be deleted
|
||||||
|
*
|
||||||
|
* @return load balancer before the command is executed
|
||||||
|
*/
|
||||||
|
LoadBalancer deleteByName(String name);
|
||||||
|
}
|
|
@ -0,0 +1,126 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||||
|
*
|
||||||
|
* ====================================================================
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF 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 com.google.common.util.concurrent.ListenableFuture;
|
||||||
|
|
||||||
|
import javax.ws.rs.GET;
|
||||||
|
import javax.ws.rs.Path;
|
||||||
|
import javax.ws.rs.QueryParam;
|
||||||
|
|
||||||
|
import org.jclouds.gogrid.GoGrid;
|
||||||
|
import org.jclouds.gogrid.binders.BindIdsToQueryParams;
|
||||||
|
import org.jclouds.gogrid.binders.BindNamesToQueryParams;
|
||||||
|
import org.jclouds.gogrid.domain.PowerCommand;
|
||||||
|
import org.jclouds.gogrid.domain.Server;
|
||||||
|
import org.jclouds.gogrid.filters.SharedKeyLiteAuthentication;
|
||||||
|
import org.jclouds.gogrid.functions.ParseServerFromJsonResponse;
|
||||||
|
import org.jclouds.gogrid.functions.ParseServerListFromJsonResponse;
|
||||||
|
import org.jclouds.gogrid.options.AddServerOptions;
|
||||||
|
import org.jclouds.gogrid.options.GetServerListOptions;
|
||||||
|
import org.jclouds.rest.annotations.*;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import static org.jclouds.gogrid.reference.GoGridQueryParams.*;
|
||||||
|
import static org.jclouds.gogrid.reference.GoGridHeaders.VERSION;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides asynchronous access to GoGrid via their REST API.
|
||||||
|
* <p/>
|
||||||
|
*
|
||||||
|
* @see GridServerClient
|
||||||
|
* @see <a href="http://wiki.gogrid.com/wiki/index.php/API" />
|
||||||
|
* @author Adrian Cole
|
||||||
|
* @author Oleksiy Yarmula
|
||||||
|
*/
|
||||||
|
@Endpoint(GoGrid.class)
|
||||||
|
@RequestFilters(SharedKeyLiteAuthentication.class)
|
||||||
|
@QueryParams(keys = VERSION, values = "1.3")
|
||||||
|
public interface GridServerAsyncClient {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see GridServerClient#getServerList(org.jclouds.gogrid.options.GetServerListOptions...)
|
||||||
|
*/
|
||||||
|
@GET
|
||||||
|
@ResponseParser(ParseServerListFromJsonResponse.class)
|
||||||
|
@Path("/grid/server/list")
|
||||||
|
ListenableFuture<Set<Server>> getServerList(GetServerListOptions... getServerListOptions);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see GridServerClient#getServersByName(String...)
|
||||||
|
*/
|
||||||
|
@GET
|
||||||
|
@ResponseParser(ParseServerListFromJsonResponse.class)
|
||||||
|
@Path("/grid/server/get")
|
||||||
|
ListenableFuture<Set<Server>> getServersByName(@BinderParam(BindNamesToQueryParams.class) String... names);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see GridServerClient#getServersById(Long...)
|
||||||
|
*/
|
||||||
|
@GET
|
||||||
|
@ResponseParser(ParseServerListFromJsonResponse.class)
|
||||||
|
@Path("/grid/server/get")
|
||||||
|
ListenableFuture<Set<Server>> getServersById(@BinderParam(BindIdsToQueryParams.class) Long... ids);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see GridServerClient#addServer(String, String, String, String, org.jclouds.gogrid.options.AddServerOptions...)
|
||||||
|
*/
|
||||||
|
@GET
|
||||||
|
@ResponseParser(ParseServerFromJsonResponse.class)
|
||||||
|
@Path("/grid/server/add")
|
||||||
|
ListenableFuture<Server> addServer(@QueryParam(NAME_KEY) String name,
|
||||||
|
@QueryParam(IMAGE_KEY) String image,
|
||||||
|
@QueryParam(SERVER_RAM_KEY) String ram,
|
||||||
|
@QueryParam(IP_KEY) String ip,
|
||||||
|
AddServerOptions... addServerOptions);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see GridServerClient#power(String, org.jclouds.gogrid.domain.PowerCommand)
|
||||||
|
*/
|
||||||
|
@GET
|
||||||
|
@ResponseParser(ParseServerFromJsonResponse.class)
|
||||||
|
@Path("/grid/server/power")
|
||||||
|
ListenableFuture<Server> power(@QueryParam(SERVER_ID_OR_NAME_KEY) String idOrName,
|
||||||
|
@QueryParam(POWER_KEY) PowerCommand power);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see GridServerClient#deleteById(Long)
|
||||||
|
*/
|
||||||
|
@GET
|
||||||
|
@ResponseParser(ParseServerFromJsonResponse.class)
|
||||||
|
@Path("/grid/server/delete")
|
||||||
|
ListenableFuture<Server> deleteById(@QueryParam(ID_KEY) Long id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see GridServerClient#deleteByName(String)
|
||||||
|
*/
|
||||||
|
@GET
|
||||||
|
@ResponseParser(ParseServerFromJsonResponse.class)
|
||||||
|
@Path("/grid/server/delete")
|
||||||
|
ListenableFuture<Server> deleteByName(@QueryParam(NAME_KEY) String name);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,131 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||||
|
*
|
||||||
|
* ====================================================================
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF 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 java.util.Set;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
import org.jclouds.concurrent.Timeout;
|
||||||
|
import org.jclouds.gogrid.domain.PowerCommand;
|
||||||
|
import org.jclouds.gogrid.domain.Server;
|
||||||
|
import org.jclouds.gogrid.options.AddServerOptions;
|
||||||
|
import org.jclouds.gogrid.options.GetServerListOptions;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides synchronous access to GoGrid.
|
||||||
|
* <p/>
|
||||||
|
*
|
||||||
|
* @see GridServerAsyncClient
|
||||||
|
* @see <a href="http://wiki.gogrid.com/wiki/index.php/API" />
|
||||||
|
*
|
||||||
|
* @author Adrian Cole
|
||||||
|
* @author Oleksiy Yarmula
|
||||||
|
*/
|
||||||
|
@Timeout(duration = 30, timeUnit = TimeUnit.SECONDS)
|
||||||
|
public interface GridServerClient {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the list of all servers.
|
||||||
|
*
|
||||||
|
* The result can be narrowed down by providing the options.
|
||||||
|
* @param getServerListOptions options to narrow down the result
|
||||||
|
* @return servers found by the request
|
||||||
|
*/
|
||||||
|
Set<Server> getServerList(GetServerListOptions... getServerListOptions);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the server(s) by unique name(s).
|
||||||
|
*
|
||||||
|
* Given a name or a set of names, finds one or
|
||||||
|
* multiple servers.
|
||||||
|
* @param names to get the servers
|
||||||
|
* @return server(s) matching the name(s)
|
||||||
|
*/
|
||||||
|
Set<Server> getServersByName(String... names);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the server(s) by unique id(s).
|
||||||
|
*
|
||||||
|
* Given an id or a set of ids, finds one or
|
||||||
|
* multiple servers.
|
||||||
|
* @param ids to get the servers
|
||||||
|
* @return server(s) matching the ids
|
||||||
|
*/
|
||||||
|
Set<Server> getServersById(Long... ids);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a server with specified attributes
|
||||||
|
*
|
||||||
|
* @param name name of the server
|
||||||
|
* @param image
|
||||||
|
* image (id or name)
|
||||||
|
* @param ram
|
||||||
|
* ram type (id or name)
|
||||||
|
* @param ip
|
||||||
|
* ip address
|
||||||
|
* @param addServerOptions
|
||||||
|
* options to make it a sandbox instance or/and description
|
||||||
|
* @return created server
|
||||||
|
*/
|
||||||
|
Server addServer(String name,
|
||||||
|
String image,
|
||||||
|
String ram,
|
||||||
|
String ip,
|
||||||
|
AddServerOptions... addServerOptions);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Changes the server's state according to {@link PowerCommand}
|
||||||
|
*
|
||||||
|
* @param idOrName
|
||||||
|
* id or name of the server to apply the command
|
||||||
|
* @param power
|
||||||
|
* new desired state
|
||||||
|
* @return server immediately after applying the command
|
||||||
|
*/
|
||||||
|
Server power(String idOrName,
|
||||||
|
PowerCommand power);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deletes the server by Id
|
||||||
|
*
|
||||||
|
* @param id
|
||||||
|
* id of the server to delete
|
||||||
|
* @return server before the command is executed
|
||||||
|
*/
|
||||||
|
Server deleteById(Long id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deletes the server by name;
|
||||||
|
*
|
||||||
|
* NOTE: Using this parameter may generate an
|
||||||
|
* error if one or more servers share a non-unique name.
|
||||||
|
*
|
||||||
|
* @param name
|
||||||
|
* name of the server to be deleted
|
||||||
|
*
|
||||||
|
* @return server before the command is executed
|
||||||
|
*/
|
||||||
|
Server deleteByName(String name);
|
||||||
|
}
|
|
@ -0,0 +1,30 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||||
|
*
|
||||||
|
* ====================================================================
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF 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.util;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Oleksiy Yarmula
|
||||||
|
*/
|
||||||
|
public class GoGridUtils {
|
||||||
|
}
|
|
@ -0,0 +1,102 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||||
|
*
|
||||||
|
* ====================================================================
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF 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;
|
||||||
|
|
||||||
|
import static org.testng.Assert.assertEquals;
|
||||||
|
|
||||||
|
import java.net.URI;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.jclouds.gogrid.filters.SharedKeyLiteAuthentication;
|
||||||
|
import org.jclouds.gogrid.functions.ParseServerListFromJsonResponse;
|
||||||
|
import org.jclouds.gogrid.services.GridServerAsyncClient;
|
||||||
|
import org.jclouds.gogrid.services.GridServerClient;
|
||||||
|
import org.jclouds.rest.RestContext;
|
||||||
|
import org.jclouds.rest.internal.RestContextImpl;
|
||||||
|
import org.jclouds.gogrid.config.GoGridRestClientModule;
|
||||||
|
import org.jclouds.gogrid.reference.GoGridConstants;
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
import com.google.inject.Injector;
|
||||||
|
import com.google.inject.Key;
|
||||||
|
import com.google.inject.Module;
|
||||||
|
import com.google.inject.TypeLiteral;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests behavior of modules configured in GoGridContextBuilder
|
||||||
|
*
|
||||||
|
* @author Adrian Cole
|
||||||
|
*/
|
||||||
|
@Test(groups = "unit", testName = "gogrid.GoGridContextBuilderTest")
|
||||||
|
public class GoGridContextBuilderTest {
|
||||||
|
|
||||||
|
public void testNewBuilder() {
|
||||||
|
GoGridContextBuilder builder = newBuilder();
|
||||||
|
assertEquals(builder.getProperties().getProperty(GoGridConstants.PROPERTY_GOGRID_ENDPOINT),
|
||||||
|
"https://api.gogrid.com/api");
|
||||||
|
assertEquals(builder.getProperties().getProperty(GoGridConstants.PROPERTY_GOGRID_USER),
|
||||||
|
"user");
|
||||||
|
assertEquals(builder.getProperties().getProperty(GoGridConstants.PROPERTY_GOGRID_PASSWORD),
|
||||||
|
"password");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testBuildContext() {
|
||||||
|
RestContext<GoGridAsyncClient, GoGridClient> context = newBuilder().buildContext();
|
||||||
|
assertEquals(context.getClass(), RestContextImpl.class);
|
||||||
|
assertEquals(context.getAccount(), "user");
|
||||||
|
assertEquals(context.getEndPoint(), URI.create("https://api.gogrid.com/api"));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testBuildInjector() {
|
||||||
|
Injector i = newBuilder().buildInjector();
|
||||||
|
assert i.getInstance(Key.get(new TypeLiteral<RestContext<GoGridAsyncClient, GoGridClient>>() {
|
||||||
|
})) != null;
|
||||||
|
assert i.getInstance(SharedKeyLiteAuthentication.class) != null;
|
||||||
|
assert i.getInstance(ParseServerListFromJsonResponse.class) != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void testAddContextModule() {
|
||||||
|
List<Module> modules = new ArrayList<Module>();
|
||||||
|
GoGridContextBuilder builder = newBuilder();
|
||||||
|
builder.addContextModule(modules);
|
||||||
|
assertEquals(modules.size(), 1);
|
||||||
|
assertEquals(modules.get(0).getClass(), GoGridRestClientModule.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
private GoGridContextBuilder newBuilder() {
|
||||||
|
GoGridContextBuilder builder = new GoGridContextBuilder(new GoGridPropertiesBuilder(
|
||||||
|
"user", "password").build());
|
||||||
|
return builder;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void addClientModule() {
|
||||||
|
List<Module> modules = new ArrayList<Module>();
|
||||||
|
GoGridContextBuilder builder = newBuilder();
|
||||||
|
builder.addClientModule(modules);
|
||||||
|
assertEquals(modules.size(), 1);
|
||||||
|
assertEquals(modules.get(0).getClass(), GoGridRestClientModule.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,297 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* 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;
|
||||||
|
|
||||||
|
import com.google.common.base.Predicate;
|
||||||
|
import com.google.common.collect.Iterables;
|
||||||
|
import org.jclouds.gogrid.domain.*;
|
||||||
|
import org.jclouds.gogrid.options.AddLoadBalancerOptions;
|
||||||
|
import org.jclouds.gogrid.options.GetImageListOptions;
|
||||||
|
import org.jclouds.gogrid.options.GetIpListOptions;
|
||||||
|
import org.jclouds.gogrid.predicates.LoadBalancerLatestJobCompleted;
|
||||||
|
import org.jclouds.gogrid.predicates.ServerLatestJobCompleted;
|
||||||
|
import org.jclouds.logging.log4j.config.Log4JLoggingModule;
|
||||||
|
import org.jclouds.predicates.RetryablePredicate;
|
||||||
|
import org.testng.SkipException;
|
||||||
|
import org.testng.TestException;
|
||||||
|
import org.testng.annotations.AfterTest;
|
||||||
|
import org.testng.annotations.BeforeGroups;
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
import static org.testng.Assert.*;
|
||||||
|
import static java.lang.String.format;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* End to end live test for GoGrid
|
||||||
|
*
|
||||||
|
* @author Oleksiy Yarmula
|
||||||
|
*/
|
||||||
|
@Test(groups = "live", testName = "gogrid.GoGridLiveTest")
|
||||||
|
|
||||||
|
public class GoGridLiveTest {
|
||||||
|
|
||||||
|
private GoGridClient client;
|
||||||
|
|
||||||
|
private RetryablePredicate<Server> serverLatestJobCompleted;
|
||||||
|
private RetryablePredicate<LoadBalancer> loadBalancerLatestJobCompleted;
|
||||||
|
/**
|
||||||
|
* Keeps track of the servers, created during the tests,
|
||||||
|
* to remove them after all tests complete
|
||||||
|
*/
|
||||||
|
private List<String> serversToDeleteAfterTheTests = new ArrayList<String>();
|
||||||
|
private List<String> loadBalancersToDeleteAfterTest = new ArrayList<String>();
|
||||||
|
|
||||||
|
@BeforeGroups(groups = { "live" })
|
||||||
|
public void setupClient() {
|
||||||
|
String user = checkNotNull(System.getProperty("jclouds.test.user"), "jclouds.test.user");
|
||||||
|
String password = checkNotNull(System.getProperty("jclouds.test.key"), "jclouds.test.key");
|
||||||
|
|
||||||
|
client = GoGridContextFactory.createContext(user, password, new Log4JLoggingModule())
|
||||||
|
.getApi();
|
||||||
|
|
||||||
|
serverLatestJobCompleted = new RetryablePredicate<Server>(
|
||||||
|
new ServerLatestJobCompleted(client.getJobServices()),
|
||||||
|
800, 20, TimeUnit.SECONDS);
|
||||||
|
loadBalancerLatestJobCompleted = new RetryablePredicate<LoadBalancer>(
|
||||||
|
new LoadBalancerLatestJobCompleted(client.getJobServices()),
|
||||||
|
800, 20, TimeUnit.SECONDS);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests server start, reboot and deletion.
|
||||||
|
* Also verifies IP services and job services.
|
||||||
|
*/
|
||||||
|
@Test(enabled=false)
|
||||||
|
public void testServerLifecycle() {
|
||||||
|
int serverCountBeforeTest = client.getServerServices().getServerList().size();
|
||||||
|
|
||||||
|
final String nameOfServer = "Server" + String.valueOf(new Date().getTime()).substring(6);
|
||||||
|
serversToDeleteAfterTheTests.add(nameOfServer);
|
||||||
|
|
||||||
|
Set<Ip> availableIps = client.getIpServices().getUnassignedIpList();
|
||||||
|
Ip availableIp = Iterables.getLast(availableIps);
|
||||||
|
|
||||||
|
Server createdServer = client.getServerServices().addServer(nameOfServer,
|
||||||
|
"GSI-f8979644-e646-4711-ad58-d98a5fa3612c",
|
||||||
|
"1",
|
||||||
|
availableIp.getIp());
|
||||||
|
assertNotNull(createdServer);
|
||||||
|
assert serverLatestJobCompleted.apply(createdServer);
|
||||||
|
|
||||||
|
//get server by name
|
||||||
|
Set<Server> response = client.getServerServices().getServersByName(nameOfServer);
|
||||||
|
assert (response.size() == 1);
|
||||||
|
|
||||||
|
//restart the server
|
||||||
|
client.getServerServices().power(nameOfServer, PowerCommand.RESTART);
|
||||||
|
|
||||||
|
Set<Job> jobs = client.getJobServices().getJobsForObjectName(nameOfServer);
|
||||||
|
assert("RestartVirtualServer".equals(Iterables.getLast(jobs).getCommand().getName()));
|
||||||
|
|
||||||
|
assert serverLatestJobCompleted.apply(createdServer);
|
||||||
|
|
||||||
|
int serverCountAfterAddingOneServer = client.getServerServices().getServerList().size();
|
||||||
|
assert serverCountAfterAddingOneServer == serverCountBeforeTest + 1 :
|
||||||
|
"There should be +1 increase in the number of servers since the test started";
|
||||||
|
|
||||||
|
//delete the server
|
||||||
|
client.getServerServices().deleteByName(nameOfServer);
|
||||||
|
|
||||||
|
jobs = client.getJobServices().getJobsForObjectName(nameOfServer);
|
||||||
|
assert("DeleteVirtualServer".equals(Iterables.getLast(jobs).getCommand().getName()));
|
||||||
|
|
||||||
|
assert serverLatestJobCompleted.apply(createdServer);
|
||||||
|
|
||||||
|
int serverCountAfterDeletingTheServer = client.getServerServices().getServerList().size();
|
||||||
|
assert serverCountAfterDeletingTheServer == serverCountBeforeTest :
|
||||||
|
"There should be the same # of servers as since the test started";
|
||||||
|
|
||||||
|
//make sure that IP is put back to "unassigned"
|
||||||
|
assert client.getIpServices().getUnassignedIpList().contains(availableIp);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Starts a servers, verifies that jobs are created correctly and
|
||||||
|
* an be retrieved from the job services
|
||||||
|
*/
|
||||||
|
@Test(dependsOnMethods = "testServerLifecycle", enabled=false)
|
||||||
|
public void testJobs() {
|
||||||
|
final String nameOfServer = "Server" + String.valueOf(new Date().getTime()).substring(6);
|
||||||
|
serversToDeleteAfterTheTests.add(nameOfServer);
|
||||||
|
|
||||||
|
Set<Ip> availableIps = client.getIpServices().getUnassignedIpList();
|
||||||
|
|
||||||
|
Server createdServer = client.getServerServices().addServer(nameOfServer,
|
||||||
|
"GSI-f8979644-e646-4711-ad58-d98a5fa3612c",
|
||||||
|
"1",
|
||||||
|
Iterables.getLast(availableIps).getIp());
|
||||||
|
|
||||||
|
assert serverLatestJobCompleted.apply(createdServer);
|
||||||
|
|
||||||
|
//restart the server
|
||||||
|
client.getServerServices().power(nameOfServer, PowerCommand.RESTART);
|
||||||
|
|
||||||
|
Set<Job> jobs = client.getJobServices().getJobsForObjectName(nameOfServer);
|
||||||
|
|
||||||
|
Job latestJob = Iterables.getLast(jobs);
|
||||||
|
Long latestJobId = latestJob.getId();
|
||||||
|
|
||||||
|
Job latestJobFetched = Iterables.getOnlyElement(client.getJobServices().getJobsById(latestJobId));
|
||||||
|
|
||||||
|
assert latestJob.equals(latestJobFetched) : "Job and its reprentation found by ID don't match";
|
||||||
|
|
||||||
|
List<Long> idsOfAllJobs = new ArrayList<Long>();
|
||||||
|
for(Job job : jobs) {
|
||||||
|
idsOfAllJobs.add(job.getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
Set<Job> jobsFetched = client.getJobServices().getJobsById(idsOfAllJobs.toArray(new Long[jobs.size()]));
|
||||||
|
assert jobsFetched.size() == jobs.size() : format("Number of jobs fetched by ids doesn't match the number of jobs " +
|
||||||
|
"requested. Requested/expected: %d. Found: %d.",
|
||||||
|
jobs.size(), jobsFetched.size());
|
||||||
|
|
||||||
|
//delete the server
|
||||||
|
client.getServerServices().deleteByName(nameOfServer);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests common load balancer operations.
|
||||||
|
* Also verifies IP services and job services.
|
||||||
|
*/
|
||||||
|
@Test(enabled=false)
|
||||||
|
public void testLoadBalancerLifecycle() {
|
||||||
|
int lbCountBeforeTest = client.getLoadBalancerServices().getLoadBalancerList().size();
|
||||||
|
|
||||||
|
final String nameOfLoadBalancer = "LoadBalancer" + String.valueOf(new Date().getTime()).substring(6);
|
||||||
|
loadBalancersToDeleteAfterTest.add(nameOfLoadBalancer);
|
||||||
|
|
||||||
|
GetIpListOptions ipOptions = new GetIpListOptions.Builder().unassignedPublicIps();
|
||||||
|
Set<Ip> availableIps = client.getIpServices().getIpList(ipOptions);
|
||||||
|
|
||||||
|
if(availableIps.size() < 4) throw new SkipException("Not enough available IPs (4 needed) to run the test");
|
||||||
|
Iterator<Ip> ipIterator = availableIps.iterator();
|
||||||
|
Ip vip = ipIterator.next();
|
||||||
|
Ip realIp1 = ipIterator.next();
|
||||||
|
Ip realIp2 = ipIterator.next();
|
||||||
|
Ip realIp3 = ipIterator.next();
|
||||||
|
|
||||||
|
AddLoadBalancerOptions options = new AddLoadBalancerOptions.Builder().
|
||||||
|
create(LoadBalancerType.LEAST_CONNECTED, LoadBalancerPersistenceType.SOURCE_ADDRESS);
|
||||||
|
LoadBalancer createdLoadBalancer = client.getLoadBalancerServices().
|
||||||
|
addLoadBalancer(nameOfLoadBalancer, new IpPortPair(vip, 80),
|
||||||
|
Arrays.asList(new IpPortPair(realIp1, 80),
|
||||||
|
new IpPortPair(realIp2, 80)), options);
|
||||||
|
assertNotNull(createdLoadBalancer);
|
||||||
|
assert loadBalancerLatestJobCompleted.apply(createdLoadBalancer);
|
||||||
|
|
||||||
|
//get load balancer by name
|
||||||
|
Set<LoadBalancer> response = client.getLoadBalancerServices().getLoadBalancersByName(nameOfLoadBalancer);
|
||||||
|
assert (response.size() == 1);
|
||||||
|
createdLoadBalancer = Iterables.getOnlyElement(response);
|
||||||
|
assertNotNull(createdLoadBalancer.getRealIpList());
|
||||||
|
assertEquals(createdLoadBalancer.getRealIpList().size(), 2);
|
||||||
|
assertNotNull(createdLoadBalancer.getVirtualIp());
|
||||||
|
assertEquals(createdLoadBalancer.getVirtualIp().getIp().getIp(), vip.getIp());
|
||||||
|
|
||||||
|
LoadBalancer editedLoadBalancer = client.getLoadBalancerServices().
|
||||||
|
editLoadBalancer(nameOfLoadBalancer, Arrays.asList(new IpPortPair(realIp3, 8181)));
|
||||||
|
assert loadBalancerLatestJobCompleted.apply(editedLoadBalancer);
|
||||||
|
assertNotNull(editedLoadBalancer.getRealIpList());
|
||||||
|
assertEquals(editedLoadBalancer.getRealIpList().size(), 1);
|
||||||
|
assertEquals(Iterables.getOnlyElement(editedLoadBalancer.getRealIpList()).getIp().getIp(), realIp3.getIp());
|
||||||
|
|
||||||
|
int lbCountAfterAddingOneServer = client.getLoadBalancerServices().getLoadBalancerList().size();
|
||||||
|
assert lbCountAfterAddingOneServer == lbCountBeforeTest + 1 :
|
||||||
|
"There should be +1 increase in the number of load balancers since the test started";
|
||||||
|
|
||||||
|
//delete the load balancer
|
||||||
|
client.getLoadBalancerServices().deleteByName(nameOfLoadBalancer);
|
||||||
|
|
||||||
|
Set<Job> jobs = client.getJobServices().getJobsForObjectName(nameOfLoadBalancer);
|
||||||
|
assert("DeleteLoadBalancer".equals(Iterables.getLast(jobs).getCommand().getName()));
|
||||||
|
|
||||||
|
assert loadBalancerLatestJobCompleted.apply(createdLoadBalancer);
|
||||||
|
|
||||||
|
int lbCountAfterDeletingTheServer = client.getLoadBalancerServices().getLoadBalancerList().size();
|
||||||
|
assert lbCountAfterDeletingTheServer == lbCountBeforeTest :
|
||||||
|
"There should be the same # of load balancers as since the test started";
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests common server image operations.
|
||||||
|
*/
|
||||||
|
@Test(enabled=false)
|
||||||
|
public void testImageLifecycle() {
|
||||||
|
GetImageListOptions options = new GetImageListOptions.Builder().publicDatabaseServers();
|
||||||
|
Set<ServerImage> images = client.getImageServices().getImageList(options);
|
||||||
|
|
||||||
|
Predicate<ServerImage> isDatabaseServer = new Predicate<ServerImage>() {
|
||||||
|
@Override
|
||||||
|
public boolean apply(@Nullable ServerImage serverImage) {
|
||||||
|
return checkNotNull(serverImage).getType() == ServerImageType.DATABASE_SERVER;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
assert Iterables.all(images, isDatabaseServer) : "All of the images should've been of database type";
|
||||||
|
|
||||||
|
ServerImage image = Iterables.getLast(images);
|
||||||
|
ServerImage imageFromServer = Iterables.getOnlyElement(
|
||||||
|
client.getImageServices().getImagesByName(image.getName()));
|
||||||
|
assertEquals(image, imageFromServer);
|
||||||
|
|
||||||
|
try {
|
||||||
|
client.getImageServices().editImageDescription(image.getName(), "newDescription");
|
||||||
|
throw new TestException("An exception hasn't been thrown where expected; expected GoGridResponseException");
|
||||||
|
} catch(GoGridResponseException e) {
|
||||||
|
//expected situation - check and proceed
|
||||||
|
assertTrue(e.getMessage().contains("GoGridIllegalArgumentException"));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* In case anything went wrong during the tests, removes the objects
|
||||||
|
* created in the tests.
|
||||||
|
*/
|
||||||
|
@AfterTest
|
||||||
|
public void cleanup() {
|
||||||
|
for(String serverName : serversToDeleteAfterTheTests) {
|
||||||
|
try {
|
||||||
|
client.getServerServices().deleteByName(serverName);
|
||||||
|
} catch(Exception e) {
|
||||||
|
// it's already been deleted - proceed
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for(String loadBalancerName : loadBalancersToDeleteAfterTest) {
|
||||||
|
try {
|
||||||
|
client.getLoadBalancerServices().deleteByName(loadBalancerName);
|
||||||
|
} catch(Exception e) {
|
||||||
|
// it's already been deleted - proceed
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,48 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* 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.binders;
|
||||||
|
|
||||||
|
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
import static org.easymock.classextension.EasyMock.createMock;
|
||||||
|
import static org.easymock.classextension.EasyMock.replay;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests that id bindings are proper for request
|
||||||
|
*
|
||||||
|
* @author Oleksiy Yarmula
|
||||||
|
*/
|
||||||
|
public class BindIdsToQueryParamsTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testBinding() {
|
||||||
|
GeneratedHttpRequest<?> request = createMock(GeneratedHttpRequest.class);
|
||||||
|
Long[] input = {123L, 456L};
|
||||||
|
|
||||||
|
BindIdsToQueryParams binder = new BindIdsToQueryParams();
|
||||||
|
|
||||||
|
request.addQueryParam("id", "123");
|
||||||
|
request.addQueryParam("id", "456");
|
||||||
|
replay(request);
|
||||||
|
|
||||||
|
binder.bindToRequest(request, input);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -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.binders;
|
||||||
|
|
||||||
|
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
import static org.easymock.classextension.EasyMock.createMock;
|
||||||
|
import static org.easymock.classextension.EasyMock.replay;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests that name bindings are proper for request
|
||||||
|
*
|
||||||
|
* @author Oleksiy Yarmula
|
||||||
|
*/
|
||||||
|
public class BindNamesToQueryParamsTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testBinding() {
|
||||||
|
GeneratedHttpRequest<?> request = createMock(GeneratedHttpRequest.class);
|
||||||
|
String[] input = {"hello", "world"};
|
||||||
|
|
||||||
|
BindNamesToQueryParams binder = new BindNamesToQueryParams();
|
||||||
|
|
||||||
|
request.addQueryParam("name", "hello");
|
||||||
|
request.addQueryParam("name", "world");
|
||||||
|
replay(request);
|
||||||
|
|
||||||
|
binder.bindToRequest(request, input);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,116 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* 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.config;
|
||||||
|
|
||||||
|
import static org.testng.Assert.assertEquals;
|
||||||
|
import static com.google.common.util.concurrent.Executors.sameThreadExecutor;
|
||||||
|
|
||||||
|
import org.jclouds.concurrent.config.ExecutorServiceModule;
|
||||||
|
import org.jclouds.gogrid.handlers.GoGridErrorHandler;
|
||||||
|
import org.jclouds.http.HttpRetryHandler;
|
||||||
|
import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule;
|
||||||
|
import org.jclouds.http.functions.config.ParserModule;
|
||||||
|
import org.jclouds.http.functions.config.ParserModule.DateAdapter;
|
||||||
|
import org.jclouds.http.handlers.DelegatingErrorHandler;
|
||||||
|
import org.jclouds.http.handlers.DelegatingRetryHandler;
|
||||||
|
import org.jclouds.http.handlers.RedirectionRetryHandler;
|
||||||
|
import org.jclouds.logging.Logger;
|
||||||
|
import org.jclouds.logging.Logger.LoggerFactory;
|
||||||
|
import org.jclouds.gogrid.reference.GoGridConstants;
|
||||||
|
import org.jclouds.util.Jsr330;
|
||||||
|
import org.jclouds.Constants;
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
import com.google.inject.Guice;
|
||||||
|
import com.google.inject.Injector;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Adrian Cole
|
||||||
|
*/
|
||||||
|
@Test(groups = "unit", testName = "gogrid.GoGridContextModule")
|
||||||
|
public class GoGridContextModuleTest {
|
||||||
|
|
||||||
|
Injector createInjector() {
|
||||||
|
return Guice.createInjector(new GoGridRestClientModule(), new GoGridContextModule() {
|
||||||
|
@Override
|
||||||
|
protected void configure() {
|
||||||
|
bindConstant().annotatedWith(Jsr330.named(GoGridConstants.PROPERTY_GOGRID_USER)).to(
|
||||||
|
"user");
|
||||||
|
bindConstant().annotatedWith(Jsr330.named(GoGridConstants.PROPERTY_GOGRID_PASSWORD))
|
||||||
|
.to("password");
|
||||||
|
bindConstant().annotatedWith(Jsr330.named(GoGridConstants.PROPERTY_GOGRID_ENDPOINT))
|
||||||
|
.to("http://localhost");
|
||||||
|
bindConstant().annotatedWith(Jsr330.named(GoGridConstants.PROPERTY_GOGRID_SESSIONINTERVAL))
|
||||||
|
.to("30");
|
||||||
|
bindConstant().annotatedWith(Jsr330.named(Constants.PROPERTY_MAX_CONNECTIONS_PER_HOST))
|
||||||
|
.to("1");
|
||||||
|
bindConstant().annotatedWith(Jsr330.named(Constants.PROPERTY_MAX_CONNECTIONS_PER_CONTEXT))
|
||||||
|
.to("0");
|
||||||
|
bindConstant().annotatedWith(Jsr330.named(Constants.PROPERTY_IO_WORKER_THREADS))
|
||||||
|
.to("1");
|
||||||
|
bindConstant().annotatedWith(Jsr330.named(Constants.PROPERTY_USER_THREADS))
|
||||||
|
.to("1");
|
||||||
|
bindConstant().annotatedWith(Jsr330.named(Constants.PROPERTY_CONNECTION_TIMEOUT))
|
||||||
|
.to("30");
|
||||||
|
bindConstant().annotatedWith(Jsr330.named(Constants.PROPERTY_SO_TIMEOUT))
|
||||||
|
.to("10");
|
||||||
|
bind(Logger.LoggerFactory.class).toInstance(new LoggerFactory() {
|
||||||
|
public Logger getLogger(String category) {
|
||||||
|
return Logger.NULL;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
super.configure();
|
||||||
|
}
|
||||||
|
}, new ParserModule(), new JavaUrlHttpCommandExecutorServiceModule(),
|
||||||
|
new ExecutorServiceModule(sameThreadExecutor(), sameThreadExecutor()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testServerErrorHandler() {
|
||||||
|
DelegatingErrorHandler handler = createInjector().getInstance(DelegatingErrorHandler.class);
|
||||||
|
assertEquals(handler.getServerErrorHandler().getClass(),
|
||||||
|
GoGridErrorHandler.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testDateTimeAdapter() {
|
||||||
|
assertEquals(this.createInjector().getInstance(DateAdapter.class).getClass(),
|
||||||
|
GoGridContextModule.DateSecondsAdapter.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testClientErrorHandler() {
|
||||||
|
DelegatingErrorHandler handler = createInjector().getInstance(DelegatingErrorHandler.class);
|
||||||
|
assertEquals(handler.getClientErrorHandler().getClass(),
|
||||||
|
GoGridErrorHandler.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testClientRetryHandler() {
|
||||||
|
DelegatingRetryHandler handler = createInjector().getInstance(DelegatingRetryHandler.class);
|
||||||
|
assertEquals(handler.getClientErrorRetryHandler(), HttpRetryHandler.NEVER_RETRY);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testRedirectionRetryHandler() {
|
||||||
|
DelegatingRetryHandler handler = createInjector().getInstance(DelegatingRetryHandler.class);
|
||||||
|
assertEquals(handler.getRedirectionRetryHandler().getClass(), RedirectionRetryHandler.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,63 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||||
|
*
|
||||||
|
* ====================================================================
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF 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.functions;
|
||||||
|
|
||||||
|
import com.google.common.collect.Iterables;
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
import com.google.inject.Guice;
|
||||||
|
import com.google.inject.Injector;
|
||||||
|
import org.jclouds.gogrid.config.GoGridContextModule;
|
||||||
|
import org.jclouds.gogrid.domain.internal.ErrorResponse;
|
||||||
|
import org.jclouds.http.functions.config.ParserModule;
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.net.UnknownHostException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Oleksiy Yarmula
|
||||||
|
*/
|
||||||
|
public class ParseErrorFromJsonResponseTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testApplyInputStreamDetails() throws UnknownHostException {
|
||||||
|
InputStream is = getClass().getResourceAsStream("/test_error_handler.json");
|
||||||
|
|
||||||
|
ParseErrorFromJsonResponse parser = new ParseErrorFromJsonResponse(i
|
||||||
|
.getInstance(Gson.class));
|
||||||
|
ErrorResponse response = Iterables.getOnlyElement(parser.apply(is));
|
||||||
|
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,103 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* 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.ImmutableSortedSet;
|
||||||
|
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.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),
|
||||||
|
JobState.SUCCEEDED,
|
||||||
|
1,
|
||||||
|
"3116784158f0af2d-24076@api.gogrid.com",
|
||||||
|
ImmutableSortedSet.of(
|
||||||
|
new JobProperties(940263L, new Date(1267404528897L),
|
||||||
|
JobState.CREATED, null),
|
||||||
|
new JobProperties(940264L, new Date(1267404528967L),
|
||||||
|
JobState.QUEUED, 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());
|
||||||
|
bindings.put(JobState.class, new CustomDeserializers.JobStateAdapter());
|
||||||
|
return bindings;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,106 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* 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.ImmutableSortedSet;
|
||||||
|
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),
|
||||||
|
ImmutableSortedSet.of(
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
|
@ -0,0 +1,113 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||||
|
*
|
||||||
|
* ====================================================================
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF 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.functions;
|
||||||
|
|
||||||
|
import static org.testng.Assert.assertEquals;
|
||||||
|
|
||||||
|
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.ImmutableSortedSet;
|
||||||
|
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;
|
||||||
|
|
||||||
|
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 = "gogrid.ParseServersFromJsonResponseTest")
|
||||||
|
public class ParseServersFromJsonResponseTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testApplyInputStreamDetails() throws UnknownHostException {
|
||||||
|
InputStream is = getClass().getResourceAsStream("/test_get_server_list.json");
|
||||||
|
|
||||||
|
ParseServerListFromJsonResponse parser = new ParseServerListFromJsonResponse(i
|
||||||
|
.getInstance(Gson.class));
|
||||||
|
SortedSet<Server> response = parser.apply(is);
|
||||||
|
|
||||||
|
Option centOs = new Option(13L, "CentOS 5.2 (32-bit)", "CentOS 5.2 (32-bit)");
|
||||||
|
Option webServer = new Option(1L, "Web Server", "Web or Application Server");
|
||||||
|
Server server = new Server(75245L, false, "PowerServer", "server to test the api. created by Alex",
|
||||||
|
new Option(1L, "On", "Server is in active state."),
|
||||||
|
webServer,
|
||||||
|
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,
|
||||||
|
IpState.ASSIGNED),
|
||||||
|
new ServerImage(1946L, "GSI-f8979644-e646-4711-ad58-d98a5fa3612c",
|
||||||
|
"BitNami Gallery 2.3.1-0", "http://bitnami.org/stack/gallery",
|
||||||
|
centOs, null, ServerImageType.WEB_APPLICATION_SERVER,
|
||||||
|
ServerImageState.AVAILABLE,
|
||||||
|
0.0, "24732/GSI-f8979644-e646-4711-ad58-d98a5fa3612c.img",
|
||||||
|
true, true,
|
||||||
|
new Date(1261504577971L),
|
||||||
|
new Date(1262649582180L),
|
||||||
|
ImmutableSortedSet.of(
|
||||||
|
new BillingToken(38L, "CentOS 5.2 32bit", 0.0),
|
||||||
|
new BillingToken(56L, "BitNami: Gallery", 0.0)
|
||||||
|
),
|
||||||
|
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());
|
||||||
|
bindings.put(ServerImageType.class, new CustomDeserializers.ServerImageTypeAdapter());
|
||||||
|
bindings.put(ServerImageState.class, new CustomDeserializers.ServerImageStateAdapter());
|
||||||
|
return bindings;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
|
@ -0,0 +1,97 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||||
|
*
|
||||||
|
* ====================================================================
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF 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.handlers;
|
||||||
|
|
||||||
|
import static org.testng.Assert.*;
|
||||||
|
|
||||||
|
import com.google.gson.GsonBuilder;
|
||||||
|
import org.jclouds.gogrid.functions.ParseErrorFromJsonResponse;
|
||||||
|
import org.jclouds.gogrid.mock.HttpCommandMock;
|
||||||
|
import org.jclouds.http.*;
|
||||||
|
import org.testng.TestException;
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
import java.io.ByteArrayInputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests that the GoGridErrorHandler is
|
||||||
|
* correctly handling the exceptions.
|
||||||
|
*
|
||||||
|
* @author Oleksiy Yarmula
|
||||||
|
*/
|
||||||
|
public class GoGridErrorHandlerTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testHandler() {
|
||||||
|
InputStream is = getClass().getResourceAsStream("/test_error_handler.json");
|
||||||
|
|
||||||
|
GoGridErrorHandler handler =
|
||||||
|
new GoGridErrorHandler(new ParseErrorFromJsonResponse(new GsonBuilder().create()));
|
||||||
|
|
||||||
|
HttpCommand command = createHttpCommand();
|
||||||
|
handler.handleError(command, new HttpResponse(is));
|
||||||
|
|
||||||
|
Exception createdException = command.getException();
|
||||||
|
|
||||||
|
assertNotNull(createdException, "There should've been an exception generated");
|
||||||
|
String message = createdException.getMessage();
|
||||||
|
assertTrue(message.contains("No object found that matches your input criteria."),
|
||||||
|
"Didn't find the expected error cause in the exception message");
|
||||||
|
assertTrue(message.contains("IllegalArgumentException"),
|
||||||
|
"Didn't find the expected error code in the exception message");
|
||||||
|
|
||||||
|
//make sure the InputStream is closed
|
||||||
|
try {
|
||||||
|
is.available();
|
||||||
|
throw new TestException("Stream wasn't closed by the GoGridErrorHandler when it should've");
|
||||||
|
} catch(IOException e) {
|
||||||
|
//this is the excepted output
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
HttpCommand createHttpCommand() {
|
||||||
|
return new HttpCommandMock() {
|
||||||
|
private Exception exception;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setException(Exception exception) {
|
||||||
|
this.exception = exception;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Exception getException() {
|
||||||
|
return exception;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
InputStream createInputStreamFromString(String s) {
|
||||||
|
return new ByteArrayInputStream(s.getBytes());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,84 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||||
|
*
|
||||||
|
* ====================================================================
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF 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.mock;
|
||||||
|
|
||||||
|
import org.jclouds.http.HttpCommand;
|
||||||
|
import org.jclouds.http.HttpRequest;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Oleksiy Yarmula
|
||||||
|
*/
|
||||||
|
public class HttpCommandMock implements HttpCommand {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int incrementRedirectCount() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getRedirectCount() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isReplayable() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void changeSchemeHostAndPortTo(String scheme, String host, int port) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void changeToGETRequest() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void changePathTo(String newPath) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int incrementFailureCount() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getFailureCount() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public HttpRequest getRequest() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setException(Exception exception) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Exception getException() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,64 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* 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.predicates;
|
||||||
|
|
||||||
|
import com.google.inject.internal.ImmutableSet;
|
||||||
|
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;
|
||||||
|
|
||||||
|
import static org.easymock.EasyMock.expect;
|
||||||
|
import static org.easymock.classextension.EasyMock.createMock;
|
||||||
|
import static org.easymock.classextension.EasyMock.replay;
|
||||||
|
import static org.testng.Assert.assertTrue;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Oleksiy Yarmula
|
||||||
|
*/
|
||||||
|
public class ServerLatestJobCompletedTest {
|
||||||
|
|
||||||
|
@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);
|
||||||
|
|
||||||
|
GridJobClient client = createMock(GridJobClient.class);
|
||||||
|
expect(client.getJobList(jobOptions)).
|
||||||
|
andReturn(ImmutableSet.<Job>of(job));
|
||||||
|
|
||||||
|
replay(job);
|
||||||
|
replay(client);
|
||||||
|
replay(server);
|
||||||
|
|
||||||
|
ServerLatestJobCompleted predicate = new ServerLatestJobCompleted(client);
|
||||||
|
assertTrue(predicate.apply(server), "The result of the predicate should've been 'true'");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,202 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* 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.domain.ServerImageState;
|
||||||
|
import org.jclouds.gogrid.domain.ServerImageType;
|
||||||
|
import org.jclouds.gogrid.filters.SharedKeyLiteAuthentication;
|
||||||
|
import org.jclouds.gogrid.functions.ParseImageFromJsonResponse;
|
||||||
|
import org.jclouds.gogrid.functions.ParseImageListFromJsonResponse;
|
||||||
|
import org.jclouds.gogrid.options.GetImageListOptions;
|
||||||
|
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 GridImageAsyncClientTest extends RestClientTest<GridImageAsyncClient> {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetImageListWithOptions() throws NoSuchMethodException, IOException {
|
||||||
|
Method method = GridImageAsyncClient.class.getMethod("getImageList", GetImageListOptions[].class);
|
||||||
|
GeneratedHttpRequest<GridImageAsyncClient> httpRequest = processor.createRequest(method,
|
||||||
|
new GetImageListOptions().onlyPublic().setState(ServerImageState.AVAILABLE).
|
||||||
|
setType(ServerImageType.WEB_APPLICATION_SERVER));
|
||||||
|
|
||||||
|
assertRequestLineEquals(httpRequest,
|
||||||
|
"GET https://api.gogrid.com/api/grid/image/list?v=1.4&" +
|
||||||
|
"isPublic=true&image.state=Available&" +
|
||||||
|
"image.type=Web%20Server HTTP/1.1");
|
||||||
|
assertHeadersEqual(httpRequest, "");
|
||||||
|
assertPayloadEquals(httpRequest, null);
|
||||||
|
|
||||||
|
assertResponseParserClassEquals(method, httpRequest, ParseImageListFromJsonResponse.class);
|
||||||
|
assertSaxResponseParserClassEquals(method, null);
|
||||||
|
assertExceptionParserClassEquals(method, null);
|
||||||
|
|
||||||
|
checkFilters(httpRequest);
|
||||||
|
Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest);
|
||||||
|
|
||||||
|
assertRequestLineEquals(httpRequest,
|
||||||
|
"GET https://api.gogrid.com/api/grid/image/list?" +
|
||||||
|
"v=1.4&isPublic=true&image.state=Available&" +
|
||||||
|
"image.type=Web%20Server&" +
|
||||||
|
"sig=3f446f171455fbb5574aecff4997b273&api_key=foo " +
|
||||||
|
"HTTP/1.1");
|
||||||
|
assertHeadersEqual(httpRequest, "");
|
||||||
|
assertPayloadEquals(httpRequest, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetImagesByName() throws NoSuchMethodException, IOException {
|
||||||
|
Method method = GridImageAsyncClient.class.getMethod("getImagesByName", String[].class);
|
||||||
|
GeneratedHttpRequest<GridImageAsyncClient> httpRequest = processor.createRequest(method,
|
||||||
|
"name1", "name2");
|
||||||
|
|
||||||
|
assertRequestLineEquals(httpRequest,
|
||||||
|
"GET https://api.gogrid.com/api/grid/image/get?v=1.4&" +
|
||||||
|
"name=name1&name=name2 HTTP/1.1");
|
||||||
|
assertHeadersEqual(httpRequest, "");
|
||||||
|
assertPayloadEquals(httpRequest, null);
|
||||||
|
|
||||||
|
assertResponseParserClassEquals(method, httpRequest, ParseImageListFromJsonResponse.class);
|
||||||
|
assertSaxResponseParserClassEquals(method, null);
|
||||||
|
assertExceptionParserClassEquals(method, null);
|
||||||
|
|
||||||
|
checkFilters(httpRequest);
|
||||||
|
Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest);
|
||||||
|
|
||||||
|
assertRequestLineEquals(httpRequest,
|
||||||
|
"GET https://api.gogrid.com/api/grid/image/get?v=1.4&" +
|
||||||
|
"name=name1&name=name2&" +
|
||||||
|
"sig=3f446f171455fbb5574aecff4997b273&api_key=foo " +
|
||||||
|
"HTTP/1.1");
|
||||||
|
assertHeadersEqual(httpRequest, "");
|
||||||
|
assertPayloadEquals(httpRequest, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testEditImageDescription() throws NoSuchMethodException, IOException {
|
||||||
|
Method method = GridImageAsyncClient.class.getMethod("editImageDescription", String.class, String.class);
|
||||||
|
GeneratedHttpRequest<GridImageAsyncClient> httpRequest = processor.createRequest(method,
|
||||||
|
"imageName", "newDesc");
|
||||||
|
|
||||||
|
assertRequestLineEquals(httpRequest,
|
||||||
|
"GET https://api.gogrid.com/api/grid/image/edit?v=1.4&" +
|
||||||
|
"image=imageName&description=newDesc HTTP/1.1");
|
||||||
|
assertHeadersEqual(httpRequest, "");
|
||||||
|
assertPayloadEquals(httpRequest, null);
|
||||||
|
|
||||||
|
assertResponseParserClassEquals(method, httpRequest, ParseImageFromJsonResponse.class);
|
||||||
|
assertSaxResponseParserClassEquals(method, null);
|
||||||
|
assertExceptionParserClassEquals(method, null);
|
||||||
|
|
||||||
|
checkFilters(httpRequest);
|
||||||
|
Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest);
|
||||||
|
|
||||||
|
assertRequestLineEquals(httpRequest,
|
||||||
|
"GET https://api.gogrid.com/api/grid/image/edit?v=1.4&" +
|
||||||
|
"image=imageName&description=newDesc&" +
|
||||||
|
"sig=3f446f171455fbb5574aecff4997b273&api_key=foo " +
|
||||||
|
"HTTP/1.1");
|
||||||
|
assertHeadersEqual(httpRequest, "");
|
||||||
|
assertPayloadEquals(httpRequest, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testEditImageFriendlyName() throws NoSuchMethodException, IOException {
|
||||||
|
Method method = GridImageAsyncClient.class.getMethod("editImageFriendlyName", String.class, String.class);
|
||||||
|
GeneratedHttpRequest<GridImageAsyncClient> httpRequest = processor.createRequest(method,
|
||||||
|
"imageName", "newFriendlyName");
|
||||||
|
|
||||||
|
assertRequestLineEquals(httpRequest,
|
||||||
|
"GET https://api.gogrid.com/api/grid/image/edit?v=1.4&" +
|
||||||
|
"image=imageName&friendlyName=newFriendlyName HTTP/1.1");
|
||||||
|
assertHeadersEqual(httpRequest, "");
|
||||||
|
assertPayloadEquals(httpRequest, null);
|
||||||
|
|
||||||
|
assertResponseParserClassEquals(method, httpRequest, ParseImageFromJsonResponse.class);
|
||||||
|
assertSaxResponseParserClassEquals(method, null);
|
||||||
|
assertExceptionParserClassEquals(method, null);
|
||||||
|
|
||||||
|
checkFilters(httpRequest);
|
||||||
|
Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest);
|
||||||
|
|
||||||
|
assertRequestLineEquals(httpRequest,
|
||||||
|
"GET https://api.gogrid.com/api/grid/image/edit?v=1.4&" +
|
||||||
|
"image=imageName&friendlyName=newFriendlyName&" +
|
||||||
|
"sig=3f446f171455fbb5574aecff4997b273&api_key=foo " +
|
||||||
|
"HTTP/1.1");
|
||||||
|
assertHeadersEqual(httpRequest, "");
|
||||||
|
assertPayloadEquals(httpRequest, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void checkFilters(GeneratedHttpRequest<GridImageAsyncClient> httpMethod) {
|
||||||
|
assertEquals(httpMethod.getFilters().size(), 1);
|
||||||
|
assertEquals(httpMethod.getFilters().get(0).getClass(), SharedKeyLiteAuthentication.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected TypeLiteral<RestAnnotationProcessor<GridImageAsyncClient>> createTypeLiteral() {
|
||||||
|
return new TypeLiteral<RestAnnotationProcessor<GridImageAsyncClient>>() {
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
@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,142 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* 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.domain.IpType;
|
||||||
|
import org.jclouds.gogrid.filters.SharedKeyLiteAuthentication;
|
||||||
|
import org.jclouds.gogrid.functions.ParseIpListFromJsonResponse;
|
||||||
|
import org.jclouds.gogrid.functions.ParseJobListFromJsonResponse;
|
||||||
|
import org.jclouds.gogrid.options.GetIpListOptions;
|
||||||
|
import org.jclouds.gogrid.options.GetJobListOptions;
|
||||||
|
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 java.util.Date;
|
||||||
|
|
||||||
|
import static org.testng.Assert.assertEquals;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Oleksiy Yarmula
|
||||||
|
*/
|
||||||
|
public class GridIpAsyncClientTest extends RestClientTest<GridIpAsyncClient> {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetIpListWithOptions() throws NoSuchMethodException, IOException {
|
||||||
|
Method method = GridIpAsyncClient.class.getMethod("getIpList", GetIpListOptions[].class);
|
||||||
|
GeneratedHttpRequest<GridIpAsyncClient> httpRequest = processor.createRequest(method,
|
||||||
|
new GetIpListOptions().onlyUnassigned().onlyWithType(IpType.PUBLIC));
|
||||||
|
|
||||||
|
assertRequestLineEquals(httpRequest,
|
||||||
|
"GET https://api.gogrid.com/api/grid/ip/list?v=1.3&ip.state=Unassigned&" +
|
||||||
|
"ip.type=Public HTTP/1.1");
|
||||||
|
assertHeadersEqual(httpRequest, "");
|
||||||
|
assertPayloadEquals(httpRequest, null);
|
||||||
|
|
||||||
|
assertResponseParserClassEquals(method, httpRequest, ParseIpListFromJsonResponse.class);
|
||||||
|
assertSaxResponseParserClassEquals(method, null);
|
||||||
|
assertExceptionParserClassEquals(method, null);
|
||||||
|
|
||||||
|
checkFilters(httpRequest);
|
||||||
|
Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest);
|
||||||
|
|
||||||
|
assertRequestLineEquals(httpRequest,
|
||||||
|
"GET https://api.gogrid.com/api/grid/ip/list?v=1.3&ip.state=Unassigned&" +
|
||||||
|
"ip.type=Public&sig=3f446f171455fbb5574aecff4997b273&api_key=foo " +
|
||||||
|
"HTTP/1.1");
|
||||||
|
assertHeadersEqual(httpRequest, "");
|
||||||
|
assertPayloadEquals(httpRequest, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetAssignedIpList() throws NoSuchMethodException, IOException {
|
||||||
|
Method method = GridIpAsyncClient.class.getMethod("getAssignedIpList");
|
||||||
|
GeneratedHttpRequest<GridIpAsyncClient> httpRequest = processor.createRequest(method);
|
||||||
|
|
||||||
|
assertRequestLineEquals(httpRequest,
|
||||||
|
"GET https://api.gogrid.com/api/grid/ip/list?v=1.3&ip.state=Assigned HTTP/1.1");
|
||||||
|
assertHeadersEqual(httpRequest, "");
|
||||||
|
assertPayloadEquals(httpRequest, null);
|
||||||
|
|
||||||
|
assertResponseParserClassEquals(method, httpRequest, ParseIpListFromJsonResponse.class);
|
||||||
|
assertSaxResponseParserClassEquals(method, null);
|
||||||
|
assertExceptionParserClassEquals(method, null);
|
||||||
|
|
||||||
|
checkFilters(httpRequest);
|
||||||
|
Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest);
|
||||||
|
|
||||||
|
assertRequestLineEquals(httpRequest,
|
||||||
|
"GET https://api.gogrid.com/api/grid/ip/list?v=1.3&ip.state=Assigned&" +
|
||||||
|
"sig=3f446f171455fbb5574aecff4997b273&api_key=foo " +
|
||||||
|
"HTTP/1.1");
|
||||||
|
assertHeadersEqual(httpRequest, "");
|
||||||
|
assertPayloadEquals(httpRequest, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void checkFilters(GeneratedHttpRequest<GridIpAsyncClient> httpMethod) {
|
||||||
|
assertEquals(httpMethod.getFilters().size(), 1);
|
||||||
|
assertEquals(httpMethod.getFilters().get(0).getClass(), SharedKeyLiteAuthentication.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected TypeLiteral<RestAnnotationProcessor<GridIpAsyncClient>> createTypeLiteral() {
|
||||||
|
return new TypeLiteral<RestAnnotationProcessor<GridIpAsyncClient>>() {
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
@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,179 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* 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.domain.JobState;
|
||||||
|
import org.jclouds.gogrid.domain.ObjectType;
|
||||||
|
import org.jclouds.gogrid.filters.SharedKeyLiteAuthentication;
|
||||||
|
import org.jclouds.gogrid.functions.ParseJobListFromJsonResponse;
|
||||||
|
import org.jclouds.gogrid.options.GetJobListOptions;
|
||||||
|
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 java.util.Date;
|
||||||
|
|
||||||
|
import static org.testng.Assert.assertEquals;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Oleksiy Yarmula
|
||||||
|
*/
|
||||||
|
public class GridJobAsyncClientTest extends RestClientTest<GridJobAsyncClient> {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetJobListWithOptions() throws NoSuchMethodException, IOException {
|
||||||
|
Method method = GridJobAsyncClient.class.getMethod("getJobList", GetJobListOptions[].class);
|
||||||
|
GeneratedHttpRequest<GridJobAsyncClient> httpRequest = processor.createRequest(method,
|
||||||
|
new GetJobListOptions.Builder().
|
||||||
|
create().
|
||||||
|
withStartDate(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.3&startdate=1267385381770&" +
|
||||||
|
"enddate=1267385382770&job.objecttype=VirtualServer&" +
|
||||||
|
"job.state=Processing HTTP/1.1");
|
||||||
|
assertHeadersEqual(httpRequest, "");
|
||||||
|
assertPayloadEquals(httpRequest, null);
|
||||||
|
|
||||||
|
assertResponseParserClassEquals(method, httpRequest, ParseJobListFromJsonResponse.class);
|
||||||
|
assertSaxResponseParserClassEquals(method, null);
|
||||||
|
assertExceptionParserClassEquals(method, null);
|
||||||
|
|
||||||
|
checkFilters(httpRequest);
|
||||||
|
Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest);
|
||||||
|
|
||||||
|
assertRequestLineEquals(httpRequest,
|
||||||
|
"GET https://api.gogrid.com/api/grid/job/list?v=1.3&startdate=1267385381770&" +
|
||||||
|
"enddate=1267385382770&job.objecttype=VirtualServer&" +
|
||||||
|
"job.state=Processing&" +
|
||||||
|
"sig=3f446f171455fbb5574aecff4997b273&api_key=foo HTTP/1.1");
|
||||||
|
assertHeadersEqual(httpRequest, "");
|
||||||
|
assertPayloadEquals(httpRequest, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetJobsForServerName() throws NoSuchMethodException, IOException {
|
||||||
|
Method method = GridJobAsyncClient.class.getMethod("getJobsForObjectName", String.class);
|
||||||
|
GeneratedHttpRequest<GridJobAsyncClient> httpRequest = processor.createRequest(method,
|
||||||
|
"MyServer");
|
||||||
|
|
||||||
|
assertRequestLineEquals(httpRequest,
|
||||||
|
"GET https://api.gogrid.com/api/grid/job/list?v=1.3&" +
|
||||||
|
"object=MyServer HTTP/1.1");
|
||||||
|
assertHeadersEqual(httpRequest, "");
|
||||||
|
assertPayloadEquals(httpRequest, null);
|
||||||
|
|
||||||
|
assertResponseParserClassEquals(method, httpRequest, ParseJobListFromJsonResponse.class);
|
||||||
|
assertSaxResponseParserClassEquals(method, null);
|
||||||
|
assertExceptionParserClassEquals(method, null);
|
||||||
|
|
||||||
|
checkFilters(httpRequest);
|
||||||
|
Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest);
|
||||||
|
|
||||||
|
assertRequestLineEquals(httpRequest,
|
||||||
|
"GET https://api.gogrid.com/api/grid/job/list?v=1.3&" +
|
||||||
|
"object=MyServer&sig=3f446f171455fbb5574aecff4997b273&api_key=foo " +
|
||||||
|
"HTTP/1.1");
|
||||||
|
assertHeadersEqual(httpRequest, "");
|
||||||
|
assertPayloadEquals(httpRequest, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetJobsById() throws NoSuchMethodException, IOException {
|
||||||
|
Method method = GridJobAsyncClient.class.getMethod("getJobsById", Long[].class);
|
||||||
|
GeneratedHttpRequest<GridJobAsyncClient> httpRequest = processor.createRequest(method,
|
||||||
|
123L, 456L);
|
||||||
|
|
||||||
|
assertRequestLineEquals(httpRequest,
|
||||||
|
"GET https://api.gogrid.com/api/grid/job/get?v=1.3&" +
|
||||||
|
"id=123&id=456 HTTP/1.1");
|
||||||
|
assertHeadersEqual(httpRequest, "");
|
||||||
|
assertPayloadEquals(httpRequest, null);
|
||||||
|
|
||||||
|
assertResponseParserClassEquals(method, httpRequest, ParseJobListFromJsonResponse.class);
|
||||||
|
assertSaxResponseParserClassEquals(method, null);
|
||||||
|
assertExceptionParserClassEquals(method, null);
|
||||||
|
|
||||||
|
checkFilters(httpRequest);
|
||||||
|
Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest);
|
||||||
|
|
||||||
|
assertRequestLineEquals(httpRequest,
|
||||||
|
"GET https://api.gogrid.com/api/grid/job/get?v=1.3&" +
|
||||||
|
"id=123&id=456&sig=3f446f171455fbb5574aecff4997b273&api_key=foo " +
|
||||||
|
"HTTP/1.1");
|
||||||
|
assertHeadersEqual(httpRequest, "");
|
||||||
|
assertPayloadEquals(httpRequest, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void checkFilters(GeneratedHttpRequest<GridJobAsyncClient> httpMethod) {
|
||||||
|
assertEquals(httpMethod.getFilters().size(), 1);
|
||||||
|
assertEquals(httpMethod.getFilters().get(0).getClass(), SharedKeyLiteAuthentication.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected TypeLiteral<RestAnnotationProcessor<GridJobAsyncClient>> createTypeLiteral() {
|
||||||
|
return new TypeLiteral<RestAnnotationProcessor<GridJobAsyncClient>>() {
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
@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,244 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* 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.domain.Ip;
|
||||||
|
import org.jclouds.gogrid.domain.IpPortPair;
|
||||||
|
import org.jclouds.gogrid.domain.LoadBalancerPersistenceType;
|
||||||
|
import org.jclouds.gogrid.domain.LoadBalancerType;
|
||||||
|
import org.jclouds.gogrid.filters.SharedKeyLiteAuthentication;
|
||||||
|
import org.jclouds.gogrid.functions.ParseLoadBalancerFromJsonResponse;
|
||||||
|
import org.jclouds.gogrid.functions.ParseLoadBalancerListFromJsonResponse;
|
||||||
|
import org.jclouds.gogrid.options.AddLoadBalancerOptions;
|
||||||
|
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 java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static org.testng.Assert.assertEquals;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Oleksiy Yarmula
|
||||||
|
*/
|
||||||
|
public class GridLoadBalancerAsyncClientTest extends RestClientTest<GridLoadBalancerAsyncClient> {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetLoadBalancerList() 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testAddLoadBalancer() throws NoSuchMethodException, IOException {
|
||||||
|
Method method = GridLoadBalancerAsyncClient.class.getMethod("addLoadBalancer",
|
||||||
|
String.class, IpPortPair.class, List.class, AddLoadBalancerOptions[].class);
|
||||||
|
GeneratedHttpRequest<GridLoadBalancerAsyncClient> httpRequest = processor.createRequest(method,
|
||||||
|
"BalanceIt", new IpPortPair(new Ip("127.0.0.1"), 80),
|
||||||
|
Arrays.asList(new IpPortPair(new Ip("127.0.0.1"), 8080),
|
||||||
|
new IpPortPair(new Ip("127.0.0.1"), 9090)),
|
||||||
|
new AddLoadBalancerOptions.Builder().create(LoadBalancerType.LEAST_CONNECTED,
|
||||||
|
LoadBalancerPersistenceType.SSL_STICKY));
|
||||||
|
|
||||||
|
assertRequestLineEquals(httpRequest,
|
||||||
|
"GET https://api.gogrid.com/api/grid/loadbalancer/" +
|
||||||
|
"add?v=1.4&name=BalanceIt&loadbalancer.type=Least%20Connect&" +
|
||||||
|
"loadbalancer.persistence=SSL%20Sticky&realiplist.0.ip=127.0.0.1&" +
|
||||||
|
"realiplist.0.port=8080&realiplist.1.ip=127.0.0.1&realiplist.1.port=9090&" +
|
||||||
|
"virtualip.ip=127.0.0.1&virtualip.port=80 HTTP/1.1");
|
||||||
|
assertHeadersEqual(httpRequest, "");
|
||||||
|
assertPayloadEquals(httpRequest, null);
|
||||||
|
|
||||||
|
assertResponseParserClassEquals(method, httpRequest, ParseLoadBalancerFromJsonResponse.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/" +
|
||||||
|
"add?v=1.4&name=BalanceIt&loadbalancer.type=Least%20Connect&" +
|
||||||
|
"loadbalancer.persistence=SSL%20Sticky&realiplist.0.ip=127.0.0.1&" +
|
||||||
|
"realiplist.0.port=8080&realiplist.1.ip=127.0.0.1&realiplist.1.port=9090&" +
|
||||||
|
"virtualip.ip=127.0.0.1&virtualip.port=80&" +
|
||||||
|
"sig=3f446f171455fbb5574aecff4997b273&api_key=foo " +
|
||||||
|
"HTTP/1.1");
|
||||||
|
assertHeadersEqual(httpRequest, "");
|
||||||
|
assertPayloadEquals(httpRequest, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testEditLoadBalancer() throws NoSuchMethodException, IOException {
|
||||||
|
Method method = GridLoadBalancerAsyncClient.class.getMethod("editLoadBalancer",
|
||||||
|
String.class, List.class);
|
||||||
|
GeneratedHttpRequest<GridLoadBalancerAsyncClient> httpRequest = processor.createRequest(method,
|
||||||
|
"BalanceIt", Arrays.asList(new IpPortPair(new Ip("127.0.0.1"), 8080),
|
||||||
|
new IpPortPair(new Ip("127.0.0.1"), 9090)));
|
||||||
|
|
||||||
|
assertRequestLineEquals(httpRequest,
|
||||||
|
"GET https://api.gogrid.com/api/grid/loadbalancer/" +
|
||||||
|
"edit?v=1.4&loadbalancer=BalanceIt&realiplist.0.ip=127.0.0.1&" +
|
||||||
|
"realiplist.0.port=8080&realiplist.1.ip=127.0.0.1&realiplist.1.port=9090 HTTP/1.1");
|
||||||
|
assertHeadersEqual(httpRequest, "");
|
||||||
|
assertPayloadEquals(httpRequest, null);
|
||||||
|
|
||||||
|
assertResponseParserClassEquals(method, httpRequest, ParseLoadBalancerFromJsonResponse.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/" +
|
||||||
|
"edit?v=1.4&loadbalancer=BalanceIt&realiplist.0.ip=127.0.0.1&" +
|
||||||
|
"realiplist.0.port=8080&realiplist.1.ip=127.0.0.1&realiplist.1.port=9090&" +
|
||||||
|
"sig=3f446f171455fbb5574aecff4997b273&api_key=foo " +
|
||||||
|
"HTTP/1.1");
|
||||||
|
assertHeadersEqual(httpRequest, "");
|
||||||
|
assertPayloadEquals(httpRequest, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetLoadBalancersByName() throws NoSuchMethodException, IOException {
|
||||||
|
Method method = GridLoadBalancerAsyncClient.class.getMethod("getLoadBalancersByName", String[].class);
|
||||||
|
GeneratedHttpRequest<GridLoadBalancerAsyncClient> httpRequest = processor.createRequest(method,
|
||||||
|
"My Load Balancer", "My Load Balancer 2");
|
||||||
|
|
||||||
|
assertRequestLineEquals(httpRequest,
|
||||||
|
"GET https://api.gogrid.com/api/grid/loadbalancer/" +
|
||||||
|
"get?v=1.4&name=My%20Load%20Balancer&name=My%20Load%20Balancer%202 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/" +
|
||||||
|
"get?v=1.4&name=My%20Load%20Balancer&name=My%20Load%20Balancer%202&" +
|
||||||
|
"sig=3f446f171455fbb5574aecff4997b273&api_key=foo " +
|
||||||
|
"HTTP/1.1");
|
||||||
|
assertHeadersEqual(httpRequest, "");
|
||||||
|
assertPayloadEquals(httpRequest, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDeleteLoadBalancerById() throws NoSuchMethodException, IOException {
|
||||||
|
Method method = GridLoadBalancerAsyncClient.class.getMethod("deleteById", Long.class);
|
||||||
|
GeneratedHttpRequest<GridLoadBalancerAsyncClient> httpRequest = processor.createRequest(method,
|
||||||
|
55L);
|
||||||
|
|
||||||
|
assertRequestLineEquals(httpRequest,
|
||||||
|
"GET https://api.gogrid.com/api/grid/loadbalancer/" +
|
||||||
|
"delete?v=1.4&id=55 HTTP/1.1");
|
||||||
|
assertHeadersEqual(httpRequest, "");
|
||||||
|
assertPayloadEquals(httpRequest, null);
|
||||||
|
|
||||||
|
assertResponseParserClassEquals(method, httpRequest, ParseLoadBalancerFromJsonResponse.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/" +
|
||||||
|
"delete?v=1.4&id=55&" +
|
||||||
|
"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,317 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* 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>
|
||||||
|
*
|
||||||
|
* ====================================================================
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF 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.io.IOException;
|
||||||
|
import java.io.UnsupportedEncodingException;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.net.URI;
|
||||||
|
|
||||||
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
|
import com.google.common.collect.Iterables;
|
||||||
|
import org.jclouds.gogrid.GoGrid;
|
||||||
|
import org.jclouds.gogrid.domain.PowerCommand;
|
||||||
|
import org.jclouds.gogrid.filters.SharedKeyLiteAuthentication;
|
||||||
|
import org.jclouds.gogrid.functions.ParseServerFromJsonResponse;
|
||||||
|
import org.jclouds.gogrid.options.AddServerOptions;
|
||||||
|
import org.jclouds.gogrid.options.GetServerListOptions;
|
||||||
|
import org.jclouds.gogrid.services.GridServerAsyncClient;
|
||||||
|
import org.jclouds.logging.Logger;
|
||||||
|
import org.jclouds.logging.Logger.LoggerFactory;
|
||||||
|
import org.jclouds.rest.RestClientTest;
|
||||||
|
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
||||||
|
import org.jclouds.rest.internal.RestAnnotationProcessor;
|
||||||
|
import org.jclouds.gogrid.functions.ParseServerListFromJsonResponse;
|
||||||
|
import org.jclouds.encryption.EncryptionService;
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
import com.google.inject.AbstractModule;
|
||||||
|
import com.google.inject.Module;
|
||||||
|
import com.google.inject.Provides;
|
||||||
|
import com.google.inject.TypeLiteral;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests annotation parsing of {@code GoGridAsyncClient}
|
||||||
|
*
|
||||||
|
* @author Adrian Cole
|
||||||
|
* @author Oleksiy Yarmula
|
||||||
|
*/
|
||||||
|
@Test(groups = "unit", testName = "gogrid.GoGridAsyncClientTest")
|
||||||
|
public class GridServerAsyncClientTest extends RestClientTest<GridServerAsyncClient> {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetServerListNoOptions() throws NoSuchMethodException, IOException {
|
||||||
|
Method method = GridServerAsyncClient.class.getMethod("getServerList", GetServerListOptions[].class);
|
||||||
|
GeneratedHttpRequest<GridServerAsyncClient> httpRequest = processor.createRequest(method);
|
||||||
|
|
||||||
|
assertRequestLineEquals(httpRequest, "GET https://api.gogrid.com/api/grid/server/list?v=1.3 HTTP/1.1");
|
||||||
|
assertHeadersEqual(httpRequest, "");
|
||||||
|
assertPayloadEquals(httpRequest, null);
|
||||||
|
|
||||||
|
assertResponseParserClassEquals(method, httpRequest, ParseServerListFromJsonResponse.class);
|
||||||
|
assertSaxResponseParserClassEquals(method, null);
|
||||||
|
assertExceptionParserClassEquals(method, null);
|
||||||
|
|
||||||
|
checkFilters(httpRequest);
|
||||||
|
Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest);
|
||||||
|
|
||||||
|
assertRequestLineEquals(httpRequest,
|
||||||
|
"GET https://api.gogrid.com/api/grid/server/list?" +
|
||||||
|
"v=1.3&sig=3f446f171455fbb5574aecff4997b273&api_key=foo " +
|
||||||
|
"HTTP/1.1");
|
||||||
|
assertHeadersEqual(httpRequest, "");
|
||||||
|
assertPayloadEquals(httpRequest, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetServerListWithOptions() throws NoSuchMethodException, IOException {
|
||||||
|
Method method = GridServerAsyncClient.class.getMethod("getServerList", GetServerListOptions[].class);
|
||||||
|
GeneratedHttpRequest<GridServerAsyncClient> httpRequest = processor.createRequest(method,
|
||||||
|
new GetServerListOptions.Builder().onlySandboxServers());
|
||||||
|
|
||||||
|
assertRequestLineEquals(httpRequest,
|
||||||
|
"GET https://api.gogrid.com/api/grid/server/list?v=1.3&isSandbox=true HTTP/1.1");
|
||||||
|
assertHeadersEqual(httpRequest, "");
|
||||||
|
assertPayloadEquals(httpRequest, null);
|
||||||
|
|
||||||
|
assertResponseParserClassEquals(method, httpRequest, ParseServerListFromJsonResponse.class);
|
||||||
|
assertSaxResponseParserClassEquals(method, null);
|
||||||
|
assertExceptionParserClassEquals(method, null);
|
||||||
|
|
||||||
|
checkFilters(httpRequest);
|
||||||
|
Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest);
|
||||||
|
|
||||||
|
assertRequestLineEquals(httpRequest,
|
||||||
|
"GET https://api.gogrid.com/api/grid/server/list?" +
|
||||||
|
"v=1.3&isSandbox=true&sig=3f446f171455fbb5574aecff4997b273&api_key=foo " +
|
||||||
|
"HTTP/1.1");
|
||||||
|
assertHeadersEqual(httpRequest, "");
|
||||||
|
assertPayloadEquals(httpRequest, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetServersByName() throws NoSuchMethodException, IOException {
|
||||||
|
Method method = GridServerAsyncClient.class.getMethod("getServersByName", String[].class);
|
||||||
|
GeneratedHttpRequest<GridServerAsyncClient> httpRequest = processor.createRequest(method, "server1");
|
||||||
|
|
||||||
|
assertRequestLineEquals(httpRequest,
|
||||||
|
"GET https://api.gogrid.com/api/grid/server/get?v=1.3&name=server1 HTTP/1.1");
|
||||||
|
assertHeadersEqual(httpRequest, "");
|
||||||
|
assertPayloadEquals(httpRequest, null);
|
||||||
|
|
||||||
|
assertResponseParserClassEquals(method, httpRequest, ParseServerListFromJsonResponse.class);
|
||||||
|
assertSaxResponseParserClassEquals(method, null);
|
||||||
|
assertExceptionParserClassEquals(method, null);
|
||||||
|
|
||||||
|
checkFilters(httpRequest);
|
||||||
|
Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest);
|
||||||
|
|
||||||
|
assertRequestLineEquals(httpRequest,
|
||||||
|
"GET https://api.gogrid.com/api/grid/server/get?" +
|
||||||
|
"v=1.3&name=server1&" +
|
||||||
|
"sig=3f446f171455fbb5574aecff4997b273&api_key=foo " +
|
||||||
|
"HTTP/1.1");
|
||||||
|
assertHeadersEqual(httpRequest, "");
|
||||||
|
assertPayloadEquals(httpRequest, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetServersById() throws NoSuchMethodException, IOException {
|
||||||
|
Method method = GridServerAsyncClient.class.getMethod("getServersById", Long[].class);
|
||||||
|
GeneratedHttpRequest<GridServerAsyncClient> httpRequest = processor.createRequest(method, 123L);
|
||||||
|
|
||||||
|
assertRequestLineEquals(httpRequest,
|
||||||
|
"GET https://api.gogrid.com/api/grid/server/get?v=1.3&id=123 HTTP/1.1");
|
||||||
|
assertHeadersEqual(httpRequest, "");
|
||||||
|
assertPayloadEquals(httpRequest, null);
|
||||||
|
|
||||||
|
assertResponseParserClassEquals(method, httpRequest, ParseServerListFromJsonResponse.class);
|
||||||
|
assertSaxResponseParserClassEquals(method, null);
|
||||||
|
assertExceptionParserClassEquals(method, null);
|
||||||
|
|
||||||
|
checkFilters(httpRequest);
|
||||||
|
Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest);
|
||||||
|
|
||||||
|
assertRequestLineEquals(httpRequest,
|
||||||
|
"GET https://api.gogrid.com/api/grid/server/get?" +
|
||||||
|
"v=1.3&id=123&" +
|
||||||
|
"sig=3f446f171455fbb5574aecff4997b273&api_key=foo " +
|
||||||
|
"HTTP/1.1");
|
||||||
|
assertHeadersEqual(httpRequest, "");
|
||||||
|
assertPayloadEquals(httpRequest, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testAddServerNoOptions() throws NoSuchMethodException, IOException {
|
||||||
|
Method method = GridServerAsyncClient.class.getMethod("addServer", String.class, String.class,
|
||||||
|
String.class, String.class,
|
||||||
|
AddServerOptions[].class);
|
||||||
|
GeneratedHttpRequest<GridServerAsyncClient> httpRequest =
|
||||||
|
processor.createRequest(method, "serverName", "img55",
|
||||||
|
"memory", "127.0.0.1");
|
||||||
|
|
||||||
|
assertRequestLineEquals(httpRequest,
|
||||||
|
"GET https://api.gogrid.com/api/grid/server/add?v=1.3&" +
|
||||||
|
"name=serverName&server.ram=memory&image=img55&ip=127.0.0.1 " +
|
||||||
|
"HTTP/1.1");
|
||||||
|
assertHeadersEqual(httpRequest, "");
|
||||||
|
assertPayloadEquals(httpRequest, null);
|
||||||
|
|
||||||
|
assertResponseParserClassEquals(method, httpRequest, ParseServerFromJsonResponse.class);
|
||||||
|
assertSaxResponseParserClassEquals(method, null);
|
||||||
|
assertExceptionParserClassEquals(method, null);
|
||||||
|
|
||||||
|
checkFilters(httpRequest);
|
||||||
|
Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest);
|
||||||
|
|
||||||
|
assertRequestLineEquals(httpRequest,
|
||||||
|
"GET https://api.gogrid.com/api/grid/server/add?" +
|
||||||
|
"v=1.3&name=serverName&server.ram=memory&" +
|
||||||
|
"image=img55&ip=127.0.0.1&" +
|
||||||
|
"sig=3f446f171455fbb5574aecff4997b273&api_key=foo " +
|
||||||
|
"HTTP/1.1");
|
||||||
|
assertHeadersEqual(httpRequest, "");
|
||||||
|
assertPayloadEquals(httpRequest, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testPowerServer() throws NoSuchMethodException, IOException {
|
||||||
|
Method method = GridServerAsyncClient.class.getMethod("power", String.class, PowerCommand.class);
|
||||||
|
GeneratedHttpRequest<GridServerAsyncClient> httpRequest =
|
||||||
|
processor.createRequest(method, "PowerServer", PowerCommand.RESTART);
|
||||||
|
|
||||||
|
assertRequestLineEquals(httpRequest,
|
||||||
|
"GET https://api.gogrid.com/api/grid/server/power?v=1.3&" +
|
||||||
|
"server=PowerServer&power=restart " +
|
||||||
|
"HTTP/1.1");
|
||||||
|
assertHeadersEqual(httpRequest, "");
|
||||||
|
assertPayloadEquals(httpRequest, null);
|
||||||
|
|
||||||
|
assertResponseParserClassEquals(method, httpRequest, ParseServerFromJsonResponse.class);
|
||||||
|
assertSaxResponseParserClassEquals(method, null);
|
||||||
|
assertExceptionParserClassEquals(method, null);
|
||||||
|
|
||||||
|
checkFilters(httpRequest);
|
||||||
|
Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest);
|
||||||
|
|
||||||
|
assertRequestLineEquals(httpRequest,
|
||||||
|
"GET https://api.gogrid.com/api/grid/server/power?v=1.3&" +
|
||||||
|
"server=PowerServer&power=restart&" +
|
||||||
|
"sig=3f446f171455fbb5574aecff4997b273&api_key=foo " +
|
||||||
|
"HTTP/1.1");
|
||||||
|
assertHeadersEqual(httpRequest, "");
|
||||||
|
assertPayloadEquals(httpRequest, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDeleteByName() throws NoSuchMethodException, IOException {
|
||||||
|
Method method = GridServerAsyncClient.class.getMethod("deleteByName", String.class);
|
||||||
|
GeneratedHttpRequest<GridServerAsyncClient> httpRequest =
|
||||||
|
processor.createRequest(method, "PowerServer");
|
||||||
|
|
||||||
|
assertRequestLineEquals(httpRequest,
|
||||||
|
"GET https://api.gogrid.com/api/grid/server/delete?v=1.3&" +
|
||||||
|
"name=PowerServer " +
|
||||||
|
"HTTP/1.1");
|
||||||
|
assertHeadersEqual(httpRequest, "");
|
||||||
|
assertPayloadEquals(httpRequest, null);
|
||||||
|
|
||||||
|
assertResponseParserClassEquals(method, httpRequest, ParseServerFromJsonResponse.class);
|
||||||
|
assertSaxResponseParserClassEquals(method, null);
|
||||||
|
assertExceptionParserClassEquals(method, null);
|
||||||
|
|
||||||
|
checkFilters(httpRequest);
|
||||||
|
Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest);
|
||||||
|
|
||||||
|
assertRequestLineEquals(httpRequest,
|
||||||
|
"GET https://api.gogrid.com/api/grid/server/delete?v=1.3&" +
|
||||||
|
"name=PowerServer&" +
|
||||||
|
"sig=3f446f171455fbb5574aecff4997b273&api_key=foo " +
|
||||||
|
"HTTP/1.1");
|
||||||
|
assertHeadersEqual(httpRequest, "");
|
||||||
|
assertPayloadEquals(httpRequest, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void checkFilters(GeneratedHttpRequest<GridServerAsyncClient> httpMethod) {
|
||||||
|
assertEquals(httpMethod.getFilters().size(), 1);
|
||||||
|
assertEquals(httpMethod.getFilters().get(0).getClass(), SharedKeyLiteAuthentication.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected TypeLiteral<RestAnnotationProcessor<GridServerAsyncClient>> createTypeLiteral() {
|
||||||
|
return new TypeLiteral<RestAnnotationProcessor<GridServerAsyncClient>>() {
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
@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 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,110 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!--
|
||||||
|
|
||||||
|
|
||||||
|
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.
|
||||||
|
====================================================================
|
||||||
|
|
||||||
|
-->
|
||||||
|
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
|
||||||
|
|
||||||
|
<!--
|
||||||
|
For more configuration infromation and examples see the Apache Log4j
|
||||||
|
website: http://logging.apache.org/log4j/
|
||||||
|
-->
|
||||||
|
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/"
|
||||||
|
debug="false">
|
||||||
|
|
||||||
|
<!-- A time/date based rolling appender -->
|
||||||
|
<appender name="WIREFILE" class="org.apache.log4j.DailyRollingFileAppender">
|
||||||
|
<param name="File" value="target/test-data/jclouds-wire.log" />
|
||||||
|
<param name="Append" value="true" />
|
||||||
|
|
||||||
|
<!-- Rollover at midnight each day -->
|
||||||
|
<param name="DatePattern" value="'.'yyyy-MM-dd" />
|
||||||
|
|
||||||
|
<param name="Threshold" value="TRACE" />
|
||||||
|
|
||||||
|
<layout class="org.apache.log4j.PatternLayout">
|
||||||
|
<!-- The default pattern: Date Priority [Category] Message${symbol_escape}n -->
|
||||||
|
<param name="ConversionPattern" value="%d %-5p [%c] (%t) %m%n" />
|
||||||
|
|
||||||
|
<!--
|
||||||
|
The full pattern: Date MS Priority [Category] (Thread:NDC) Message${symbol_escape}n
|
||||||
|
<param name="ConversionPattern" value="%d %-5r %-5p [%c] (%t:%x)
|
||||||
|
%m%n"/>
|
||||||
|
-->
|
||||||
|
</layout>
|
||||||
|
</appender>
|
||||||
|
|
||||||
|
<!-- A time/date based rolling appender -->
|
||||||
|
<appender name="FILE" class="org.apache.log4j.DailyRollingFileAppender">
|
||||||
|
<param name="File" value="target/test-data/jclouds.log" />
|
||||||
|
<param name="Append" value="true" />
|
||||||
|
|
||||||
|
<!-- Rollover at midnight each day -->
|
||||||
|
<param name="DatePattern" value="'.'yyyy-MM-dd" />
|
||||||
|
|
||||||
|
<param name="Threshold" value="TRACE" />
|
||||||
|
|
||||||
|
<layout class="org.apache.log4j.PatternLayout">
|
||||||
|
<!-- The default pattern: Date Priority [Category] Message${symbol_escape}n -->
|
||||||
|
<param name="ConversionPattern" value="%d %-5p [%c] (%t) %m%n" />
|
||||||
|
|
||||||
|
<!--
|
||||||
|
The full pattern: Date MS Priority [Category] (Thread:NDC) Message${symbol_escape}n
|
||||||
|
<param name="ConversionPattern" value="%d %-5r %-5p [%c] (%t:%x)
|
||||||
|
%m%n"/>
|
||||||
|
-->
|
||||||
|
</layout>
|
||||||
|
</appender>
|
||||||
|
|
||||||
|
<appender name="ASYNC" class="org.apache.log4j.AsyncAppender">
|
||||||
|
<appender-ref ref="FILE" />
|
||||||
|
</appender>
|
||||||
|
|
||||||
|
<appender name="ASYNCWIRE" class="org.apache.log4j.AsyncAppender">
|
||||||
|
<appender-ref ref="WIREFILE" />
|
||||||
|
</appender>
|
||||||
|
|
||||||
|
<!-- ================ -->
|
||||||
|
<!-- Limit categories -->
|
||||||
|
<!-- ================ -->
|
||||||
|
|
||||||
|
<category name="org.jclouds">
|
||||||
|
<priority value="DEBUG" />
|
||||||
|
<appender-ref ref="ASYNC" />
|
||||||
|
</category>
|
||||||
|
|
||||||
|
<category name="jclouds.headers">
|
||||||
|
<priority value="DEBUG" />
|
||||||
|
<appender-ref ref="ASYNCWIRE" />
|
||||||
|
</category><!--
|
||||||
|
|
||||||
|
<category name="jclouds.wire">
|
||||||
|
<priority value="DEBUG" />
|
||||||
|
<appender-ref ref="ASYNCWIRE" />
|
||||||
|
</category>
|
||||||
|
|
||||||
|
--><!-- ======================= -->
|
||||||
|
<!-- Setup the Root category -->
|
||||||
|
<!-- ======================= -->
|
||||||
|
|
||||||
|
<root>
|
||||||
|
<priority value="WARN" />
|
||||||
|
</root>
|
||||||
|
|
||||||
|
</log4j:configuration>
|
|
@ -0,0 +1,16 @@
|
||||||
|
{
|
||||||
|
"list": [
|
||||||
|
{
|
||||||
|
"object": "error",
|
||||||
|
"message": "No object found that matches your input criteria.",
|
||||||
|
"errorcode": "IllegalArgumentException"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"summary": {
|
||||||
|
"total": 1,
|
||||||
|
"start": 0,
|
||||||
|
"returned": 1
|
||||||
|
},
|
||||||
|
"status": "failure",
|
||||||
|
"method": "/grid/server/get"
|
||||||
|
}
|
|
@ -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"
|
||||||
|
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue