Inital commit of the RimuHosting Module

git-svn-id: http://jclouds.googlecode.com/svn/trunk@2319 3d8758e0-26b5-11de-8745-db77d3ebf521
This commit is contained in:
ivan@ivan.net.nz 2009-11-25 05:57:44 +00:00
parent df75cfc2f0
commit e58f375be0
55 changed files with 4126 additions and 0 deletions

View File

@ -48,6 +48,7 @@
<module>nirvanix</module>
<module>vcloud</module>
<module>twitter</module>
<module>rimuhosting</module>
</modules>
<build>
<plugins>

View File

@ -150,6 +150,15 @@
</roles>
<timezone>+1</timezone>
</developer>
<developer>
<name>Ivan Meredith</name>
<id>barefootnz</id>
<email>ivan -at- ivan.com</email>
<roles>
<role>Java Developer</role>
</roles>
<timezone>+13</timezone>
</developer>
</developers>
<properties>

View File

@ -0,0 +1,39 @@
<?xml version="1.0" encoding="UTF-8"?>
<module relativePaths="true" MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_6" inherit-compiler-output="false">
<output url="file://$MODULE_DIR$/target/classes" />
<output-test url="file://$MODULE_DIR$/target/test-classes" />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/resources" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/target" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="Maven: org.testng:testng:jdk15:5.10" level="project" />
<orderEntry type="library" name="Maven: junit:junit:3.8.1" level="project" />
<orderEntry type="library" name="Maven: org.easymock:easymockclassextension:2.4" level="project" />
<orderEntry type="library" name="Maven: org.easymock:easymock:2.4" level="project" />
<orderEntry type="library" name="Maven: cglib:cglib-nodep:2.1_3" level="project" />
<orderEntry type="module" module-name="jclouds-jsch" />
<orderEntry type="module" module-name="jclouds-core" exported="" />
<orderEntry type="library" exported="" name="Maven: aopalliance:aopalliance:1.0" level="project" />
<orderEntry type="module" module-name="resteasy-jaxrs-client" exported="" />
<orderEntry type="library" exported="" name="Maven: org.jboss.resteasy:jaxrs-api:1.1.GA" level="project" />
<orderEntry type="library" exported="" name="Maven: commons-io:commons-io:1.4" level="project" />
<orderEntry type="library" exported="" name="Maven: com.google.code.guice:guice:2.1-r1128" level="project" />
<orderEntry type="library" exported="" name="Maven: javax.inject:inject:1.0" level="project" />
<orderEntry type="library" exported="" name="Maven: com.google.collections:google-collections:1.0-rc3" level="project" />
<orderEntry type="library" exported="" name="Maven: javax.annotation:jsr250-api:1.0" level="project" />
<orderEntry type="library" exported="" name="Maven: net.jcip:jcip-annotations:1.0" level="project" />
<orderEntry type="library" exported="" name="Maven: joda-time:joda-time:1.6" level="project" />
<orderEntry type="library" exported="" name="Maven: org.bouncycastle:bcprov-jdk15:1.44" level="project" />
<orderEntry type="library" exported="" name="Maven: com.google.code.gson:gson:1.4" level="project" />
<orderEntry type="library" name="Maven: com.jcraft:jsch:0.1.41" level="project" />
<orderEntry type="module" module-name="jclouds-core" />
<orderEntry type="library" name="Maven: log4j:log4j:1.2.14" level="project" />
<orderEntry type="module" module-name="jclouds-log4j" />
</component>
</module>

86
rimuhosting/pom.xml Normal file
View File

@ -0,0 +1,86 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
$HeadURL$
$Revision$
$Date$
Copyright (C) 2009 Adrian Cole <adrian@jclouds.org>
====================================================================
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-project</artifactId>
<version>1.0-SNAPSHOT</version>
<relativePath>../project/pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>org.jclouds</groupId>
<artifactId>jclouds-rimuhosting</artifactId>
<name>jclouds RimuHosting core</name>
<packaging>jar</packaging>
<description>jclouds components to access RimuHosting</description>
<scm>
<connection>scm:svn:http://jclouds.googlecode.com/svn/trunk/rimuhosting</connection>
<developerConnection>scm:svn:https://jclouds.googlecode.com/svn/trunk/rimuhosting</developerConnection>
<url>http://jclouds.googlecode.com/svn/trunk/rimuhosting</url>
</scm>
<properties>
<jclouds.test.user></jclouds.test.user>
<jclouds.test.key></jclouds.test.key>
</properties>
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>jclouds-jsch</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<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>

View File

@ -0,0 +1,42 @@
/**
*
* Copyright (C) 2009 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.rimuhosting.miro;
import javax.inject.Qualifier;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* Related to a RimuHosting resource.
*
* @author Adrian Cole
*/
@Retention(value = RetentionPolicy.RUNTIME)
@Target(value = {ElementType.FIELD, ElementType.PARAMETER, ElementType.METHOD})
@Qualifier
public @interface RimuHosting {
}

View File

@ -0,0 +1,116 @@
/**
*
* Copyright (C) 2009 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.rimuhosting.miro;
import org.jclouds.rest.annotations.*;
import org.jclouds.rimuhosting.miro.binder.RimuHostingJsonBinder;
import org.jclouds.rimuhosting.miro.binder.RimuHostingRebootJsonBinder;
import org.jclouds.rimuhosting.miro.data.NewInstance;
import org.jclouds.rimuhosting.miro.domain.*;
import org.jclouds.rimuhosting.miro.filters.RimuHostingAuthentication;
import org.jclouds.rimuhosting.miro.functions.*;
import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
import java.util.List;
import java.util.SortedSet;
import java.util.concurrent.Future;
/**
* Provides asynchronous access to RimuHosting via their REST API.
* <p/>
*
* @author Ivan Meredith
* @see RimuHostingClient
* @see <a href="http://apidocs.rimuhosting.com" />
*/
@RequestFilters(RimuHostingAuthentication.class)
@Endpoint(RimuHosting.class)
public interface RimuHostingAsyncClient {
@GET @Path("/distributions")
@ResponseParser(ParseImagesFromJsonResponse.class)
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@ExceptionParser(ParseRimuHostingException.class)
Future<SortedSet<Image>> getImageList();
@GET @Path("/orders")
@ResponseParser(ParseInstancesFromJsonResponse.class)
@MatrixParams(keys = "include_inactive", values = "N")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@ExceptionParser(ParseRimuHostingException.class)
Future<SortedSet<Instance>> getInstanceList();
@GET @Path("/pricing-plans")
@MatrixParams(keys = "server-type", values = "VPS")
@Consumes(MediaType.APPLICATION_JSON)
@ExceptionParser(ParseRimuHostingException.class)
@ResponseParser(ParsePricingPlansFromJsonResponse.class)
Future<SortedSet<PricingPlan>> getPricingPlanList();
@POST @Path("/orders/new-vps")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@ExceptionParser(ParseRimuHostingException.class)
@ResponseParser(ParseNewInstanceResponseFromJsonResponse.class)
Future<NewInstanceResponse> createInstance(@BinderParam(RimuHostingJsonBinder.class) NewInstance newInstance);
@GET @Path("/orders/order-{id}-blah/vps")
@Consumes(MediaType.APPLICATION_JSON)
@ResponseParser(ParseInstanceInfoFromJsonResponse.class)
Future<InstanceInfo> getInstanceInfo(@PathParam("id") Long id);
@GET @Path("/orders/order-{id}-blah")
@Consumes(MediaType.APPLICATION_JSON)
@ResponseParser(ParseInstanceFromJsonResponse.class)
@ExceptionParser(ParseRimuHostingException.class)
Future<Instance> getInstance(@PathParam("id") Long id);
//TODO fix this.
@PUT @Path("/orders/order-{id}-blah/vps/paramters")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@ResponseParser(ParseResizeResponseFromJsonResponse.class)
@ExceptionParser(ParseRimuHostingException.class)
Future<ResizeResult> resizeInstance(@PathParam("id") Long id);
@PUT @Path("/orders/order-{id}-blah/vps/running-state")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@ResponseParser(ParseInstanceInfoFromJsonResponse.class)
@MapBinder(RimuHostingRebootJsonBinder.class)
@ExceptionParser(ParseRimuHostingException.class)
Future<InstanceInfo> restartInstance(@PathParam("id") Long id);
@DELETE @Path("/orders/order-{id}-blah/vps")
@Consumes(MediaType.APPLICATION_JSON)
@ResponseParser(ParseDestroyResponseFromJsonResponse.class)
@ExceptionParser(ParseRimuHostingException.class)
Future<List<String>> destroyInstance(@PathParam("id") Long id);
}

View File

@ -0,0 +1,65 @@
/**
*
* Copyright (C) 2009 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.rimuhosting.miro;
import org.jclouds.concurrent.Timeout;
import org.jclouds.rest.annotations.BinderParam;
import org.jclouds.rimuhosting.miro.binder.RimuHostingJsonBinder;
import org.jclouds.rimuhosting.miro.data.NewInstance;
import org.jclouds.rimuhosting.miro.domain.*;
import javax.ws.rs.PathParam;
import java.util.List;
import java.util.SortedSet;
import java.util.concurrent.TimeUnit;
/**
* Provides synchronous access to RimuHosting.
* <p/>
*
* @author Ivan Meredith
* @see RimuHostingAsyncClient
* @see <a href="TODO: insert URL of client documentation" />
*/
@Timeout(duration = 10, timeUnit = TimeUnit.MINUTES)
public interface RimuHostingClient {
SortedSet<Image> getImageList();
SortedSet<Instance> getInstanceList();
SortedSet<PricingPlan> getPricingPlanList();
NewInstanceResponse createInstance(@BinderParam(RimuHostingJsonBinder.class)NewInstance newInstance);
InstanceInfo getInstanceInfo(@PathParam("id") Long id);
Instance getInstance(@PathParam("id") Long id);
InstanceInfo restartInstance(@PathParam("id") Long id);
ResizeResult resizeInstance(@PathParam("id") Long id);
List<String> destroyInstance(@PathParam("id") Long id);
}

View File

@ -0,0 +1,59 @@
/**
*
* Copyright (C) 2009 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.rimuhosting.miro;
import static com.google.common.base.Preconditions.checkNotNull;
import com.google.inject.Module;
import com.google.inject.TypeLiteral;
import org.jclouds.rest.RestContextBuilder;
import org.jclouds.rimuhosting.miro.config.RimuHostingContextModule;
import org.jclouds.rimuhosting.miro.config.RimuHostingRestClientModule;
import org.jclouds.rimuhosting.miro.reference.RimuHostingConstants;
import java.util.List;
import java.util.Properties;
/**
* @author Adrian Cole
*/
public class RimuHostingContextBuilder extends RestContextBuilder<RimuHostingAsyncClient, RimuHostingClient> {
public RimuHostingContextBuilder(Properties props) {
super(new TypeLiteral<RimuHostingAsyncClient>() {
}, new TypeLiteral<RimuHostingClient>() {
}, props);
checkNotNull(properties.getProperty(RimuHostingConstants.PROPERTY_RIMUHOSTING_USER));
checkNotNull(properties.getProperty(RimuHostingConstants.PROPERTY_RIMUHOSTING_PASSWORD));
}
protected void addClientModule(List<Module> modules) {
modules.add(new RimuHostingRestClientModule());
}
@Override
protected void addContextModule(List<Module> modules) {
modules.add(new RimuHostingContextModule());
}
}

View File

@ -0,0 +1,61 @@
/**
*
* Copyright (C) 2009 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.rimuhosting.miro;
import com.google.inject.Module;
import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule;
import org.jclouds.logging.jdk.config.JDKLoggingModule;
import org.jclouds.rest.RestContext;
import java.util.Properties;
/**
* Creates {@link RestContext} for {@link RimuHostingClient} 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
* @see RestContext
* @see RimuHostingClient
* @see RimuHostingAsyncClient
*/
public class RimuHostingContextFactory {
public static RestContext<RimuHostingAsyncClient, RimuHostingClient> createContext(String user, String password,
Module... modules) {
return new RimuHostingContextBuilder(new RimuHostingPropertiesBuilder(user, password).build())
.withModules(modules).buildContext();
}
public static RestContext<RimuHostingAsyncClient, RimuHostingClient> createContext(Properties properties, Module... modules) {
return new RimuHostingContextBuilder(new RimuHostingPropertiesBuilder(properties).build())
.withModules(modules).buildContext();
}
}

View File

@ -0,0 +1,66 @@
/**
*
* Copyright (C) 2009 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.rimuhosting.miro;
import static com.google.common.base.Preconditions.checkNotNull;
import org.jclouds.http.HttpPropertiesBuilder;
import static org.jclouds.rimuhosting.miro.reference.RimuHostingConstants.*;
import java.net.URI;
import java.util.Properties;
/**
* Builds properties used in RimuHosting Clients
*
* @author Adrian Cole
*/
public class RimuHostingPropertiesBuilder extends HttpPropertiesBuilder {
@Override
protected Properties defaultProperties() {
Properties properties = super.defaultProperties();
properties.setProperty(PROPERTY_RIMUHOSTING_ENDPOINT, "https://rimuhosting.com/r");
return properties;
}
public RimuHostingPropertiesBuilder(Properties properties) {
super(properties);
}
public RimuHostingPropertiesBuilder(String id, String secret) {
super();
withCredentials(id, secret);
}
public RimuHostingPropertiesBuilder withCredentials(String id, String secret) {
properties.setProperty(PROPERTY_RIMUHOSTING_USER, checkNotNull(id, "user"));
properties.setProperty(PROPERTY_RIMUHOSTING_PASSWORD, checkNotNull(secret, "password"));
return this;
}
public RimuHostingPropertiesBuilder withEndpoint(URI endpoint) {
properties.setProperty(PROPERTY_RIMUHOSTING_ENDPOINT, checkNotNull(endpoint, "endpoint")
.toString());
return this;
}
}

View File

@ -0,0 +1,49 @@
/**
*
* Copyright (C) 2009 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.rimuhosting.miro.binder;
import static com.google.common.base.Preconditions.checkState;
import org.jclouds.http.HttpRequest;
import org.jclouds.rest.binders.BindToJsonEntity;
import java.util.HashMap;
import java.util.Map;
/**
* Generic binder for RimuHosting POSTS/PUTS. In the form of
*
* {"request":{...}}
*/
public class RimuHostingJsonBinder extends BindToJsonEntity {
public void bindToRequest(HttpRequest request, Map<String, String> postParams) {
bindToRequest(request, (Object) postParams);
}
public void bindToRequest(HttpRequest request, Object toBind) {
checkState(gson != null, "Program error: gson should have been injected at this point");
Map<String, Object> test = new HashMap<String, Object>();
test.put("request", toBind);
super.bindToRequest(request, test);
}
}

View File

@ -0,0 +1,38 @@
/**
*
* Copyright (C) 2009 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.rimuhosting.miro.binder;
import com.google.common.collect.ImmutableMap;
import org.jclouds.http.HttpRequest;
/**
* Need to PUT a static string
*
* {"request":{"running_state":"RESTARTING"}
*/
public class RimuHostingRebootJsonBinder extends RimuHostingJsonBinder{
public void bindToRequest(HttpRequest request, Object toBind) {
super.bindToRequest(request,(Object)ImmutableMap.of("running_state", "RESTARTING"));
}
}

View File

@ -0,0 +1,60 @@
/**
*
* Copyright (C) 2009 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.rimuhosting.miro.config;
import com.google.inject.AbstractModule;
import com.google.inject.Provides;
import org.jclouds.http.functions.config.ParserModule.CDateTimeAdapter;
import org.jclouds.http.functions.config.ParserModule.DateTimeAdapter;
import org.jclouds.lifecycle.Closer;
import org.jclouds.rest.RestContext;
import org.jclouds.rest.internal.RestContextImpl;
import org.jclouds.rimuhosting.miro.RimuHosting;
import org.jclouds.rimuhosting.miro.RimuHostingAsyncClient;
import org.jclouds.rimuhosting.miro.RimuHostingClient;
import org.jclouds.rimuhosting.miro.reference.RimuHostingConstants;
import javax.inject.Named;
import javax.inject.Singleton;
import java.net.URI;
/**
* Configures the RimuHosting connection, including logging and http transport.
*
* @author Adrian Cole
*/
public class RimuHostingContextModule extends AbstractModule {
@Override
protected void configure() {
bind(DateTimeAdapter.class).to(CDateTimeAdapter.class);
}
@Provides
@Singleton
RestContext<RimuHostingAsyncClient, RimuHostingClient> provideContext(Closer closer, RimuHostingAsyncClient asyncApi,
RimuHostingClient syncApi, @RimuHosting URI endPoint, @Named(RimuHostingConstants.PROPERTY_RIMUHOSTING_USER) String account) {
return new RestContextImpl<RimuHostingAsyncClient, RimuHostingClient>(closer, asyncApi, syncApi, endPoint, account);
}
}

View File

@ -0,0 +1,94 @@
/**
*
* Copyright (C) 2009 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.rimuhosting.miro.config;
import com.google.inject.AbstractModule;
import com.google.inject.Provides;
import org.jclouds.concurrent.internal.SyncProxy;
import org.jclouds.http.RequiresHttp;
import org.jclouds.rest.ConfiguresRestClient;
import org.jclouds.rest.RestClientFactory;
import org.jclouds.rimuhosting.miro.RimuHosting;
import org.jclouds.rimuhosting.miro.RimuHostingAsyncClient;
import org.jclouds.rimuhosting.miro.RimuHostingClient;
import org.jclouds.rimuhosting.miro.filters.RimuHostingAuthentication;
import org.jclouds.rimuhosting.miro.reference.RimuHostingConstants;
import javax.inject.Named;
import javax.inject.Singleton;
import java.io.UnsupportedEncodingException;
import java.net.URI;
/**
* Configures the RimuHosting connection.
*
* @author Adrian Cole
*/
@RequiresHttp
@ConfiguresRestClient
public class RimuHostingRestClientModule extends AbstractModule {
@Override
protected void configure() {
bindErrorHandlers();
bindRetryHandlers();
}
@Provides
@Singleton
public RimuHostingAuthentication provideRimuHostingAuthentication(
@Named(RimuHostingConstants.PROPERTY_RIMUHOSTING_PASSWORD) String apikey)
throws UnsupportedEncodingException {
return new RimuHostingAuthentication(apikey);
}
@Provides
@Singleton
protected RimuHostingAsyncClient provideClient(RestClientFactory factory) {
return factory.create(RimuHostingAsyncClient.class);
}
@Provides
@Singleton
public RimuHostingClient provideClient(RimuHostingAsyncClient client) throws IllegalArgumentException,
SecurityException, NoSuchMethodException {
return SyncProxy.create(RimuHostingClient.class, client);
}
@Provides
@Singleton
@RimuHosting
protected URI provideURI(@Named(RimuHostingConstants.PROPERTY_RIMUHOSTING_ENDPOINT) String endpoint) {
return URI.create(endpoint);
}
protected void bindErrorHandlers() {
// TODO
}
protected void bindRetryHandlers() {
// TODO
}
}

View File

@ -0,0 +1,69 @@
/**
*
* Copyright (C) 2009 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.rimuhosting.miro.data;
import com.google.gson.annotations.SerializedName;
/**
* Options for a clone.
* TODO: test and add contructors.
* @author Ivan Meredith <ivan@ivan.net.nz>
*/
public class CloneOptions implements PostData {
/**
* Select this if you want the newly setup VPS to be a clone of
* another VPS you have with us.&nbsp; We will need to pause (but
* not restart) the clone source VPS for a few seconds to a few
* minutes to take the snapshot.
*/
@SerializedName("vps_order_oid_to_clone")
private Long instanceId;
/**
* The label you want to give the server.&nbsp; It will need to be a
* fully qualified domain name (FQDN).&nbsp; e.g. example.com. Will
* default to the domain name used on the order id provided.
*/
@SerializedName("domain_name")
private String name;
public long getInstanceId() {
return instanceId;
}
public void setInstanceId(long instanceId) {
this.instanceId = instanceId;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public void validate(){
assert(instanceId == null || instanceId < 0);
}
}

View File

@ -0,0 +1,108 @@
/**
*
* Copyright (C) 2009 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.rimuhosting.miro.data;
import com.google.gson.annotations.SerializedName;
import org.jclouds.rimuhosting.miro.domain.Image;
/**
* Some options we need to create a new server/VPS.
*
* @author Ivan Meredith <ivan@ivan.net.nz>
*/
public class CreateOptions implements PostData{
public CreateOptions(){}
public CreateOptions(String name, String password, Image image){
this.name = name;
this.password = password;
if(image != null){
this.imageId = image.getId();
}
}
public CreateOptions(String name, String password, String imageId){
this.name = name;
this.password = password;
this.imageId = imageId;
}
/**
* The control panel to install on the VPS. Currently only webmin is installable manually.
* Currently null/empty string works. For none. Or webmin.
* TODO: Control panels need a rest @GET interface. Or enum
*/
@SerializedName("control_panel")
private String controlPanel;
/**
* Must be a valid Image id.
*/
@SerializedName("distro")
private String imageId;
/**
* Must be FQDN.
*/
@SerializedName("domain_name")
private String name;
/**
* The password to use when setting up the server. If not provided we will set a random one.
*/
private String password;
public String getControlPanel() {
return controlPanel;
}
public void setControlPanel(String controlPanel) {
this.controlPanel = controlPanel;
}
public String getImageId() {
return imageId;
}
public void setImageId(String imageId) {
this.imageId = imageId;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
@Override
public void validate() {
assert(imageId != null && imageId.length() != 0);
//TODO validation of FQDN
}
}

View File

@ -0,0 +1,72 @@
/**
*
* Copyright (C) 2009 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.rimuhosting.miro.data;
import com.google.gson.annotations.SerializedName;
/**
* Number of IPs VPS needs.&nbsp; In a separate data structure so that
* at a later date we can add more IPs to a provisioned server.
*
* @author Ivan Meredith &lt;ivan@ivan.net.nz>
*/
public class IpRequest implements PostData {
/**
* How many IPs you need.&nbsp; Typically 1.&nbsp; Typically you
* only need more than one IP if your server has SSL certs for more
* than one domains.
*/
@SerializedName("num_ips")
private int numberOfIps = 1;
/**
* The reason for requiring more than one IP address.&nbsp; The
* number of IP addresses will be limited.&nbsp; If you hit that
* limit, then contact support to manually allocate the IPs (and in
* the mean time just use fewer IPs).
*/
@SerializedName("extra_ip_reason")
private String extraIpReason = "";
public int getNumberOfIps() {
return numberOfIps;
}
public void setNumberOfIps(int numberOfIps) {
this.numberOfIps = numberOfIps;
}
public String getExtraIpReason() {
return extraIpReason;
}
public void setExtraIpReason(String extraIpReason) {
this.extraIpReason = extraIpReason;
}
@Override
public void validate() {
assert(numberOfIps < 1 && numberOfIps > 5);
assert(numberOfIps > 1 && extraIpReason == null || extraIpReason.length() == 0);
}
}

View File

@ -0,0 +1,206 @@
/**
*
* Copyright (C) 2009 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.rimuhosting.miro.data;
import com.google.gson.annotations.SerializedName;
import org.jclouds.rimuhosting.miro.domain.InstanceParameters;
import org.jclouds.rimuhosting.miro.domain.PricingPlan;
/**
* This structure defines the VPS to be setup.
*
* @author Ivan Meredith
*/
public class NewInstance implements PostData{
public NewInstance(){}
public NewInstance(CreateOptions createOptions, PricingPlan pricingPlan){
this.createOptions = createOptions;
if(pricingPlan != null){
this.planId = pricingPlan.getId();
}
}
public NewInstance(CreateOptions createOptions, String pricingPlanId){
this.createOptions = createOptions;
this.planId = pricingPlanId;
}
public NewInstance(CloneOptions cloneOptions){
this.cloneOptions = cloneOptions;
}
/**
* Set the billing id if you want to control how it is billed.&nbsp;
* Else we will, for example, try to use, say, the credit card you used
* on your last order that had a credit card.&nbsp; Or use a wire
* transfer method if you are using that on other orders.&nbsp; See the
* billing methods resource for how to find what billing methods/ids you
* have setup on your account.
*/
@SerializedName("billing_oid")
private Long billingId;
/**
* The host server on which to setup the server.&nbsp; Typically you
* will want to leave this blank and let the API decide what is
* best/available.&nbsp; And exception may be if you are a customer with
* a dedicated server that is a VPS host with us.&nbsp; And in that case
* you may want to force a VPS to be setup on a particular server of
* yours.
*/
@SerializedName("host_server_oid")
private String hostServerId;
/**
* These are the instantiation options.&nbsp; e.g. domain name,
* password, etc.&nbsp; Only provide these if you are not cloning a VPS
* (the vps_order_oid_to_clone setting). i.e. utually exclusive to
* instantiation_via_clone_options
*/
@SerializedName("instantiation_options")
private CreateOptions createOptions;
/**
* These are the instantiation options if you are creating a new VPS as
* a clone of an existing VPS. Mutually exclusive to
* instantiation_options.
*/
@SerializedName("instantiation_via_clone_options")
private CloneOptions cloneOptions;
/**
* The number of IPs you need on the VPS and a justification for having
* more than one.&nbsp; Just leave blank for a single IP (which is all
* most servers need).
*/
@SerializedName("ip_request")
private IpRequest ipRequest;
/**
* The pricing plan code you want to use.&nbsp; Per the pricing plans
* resource.
*/
@SerializedName("pricing_plan_code")
private String planId;
/**
* To whom will the order belong? Leave this blank and we will assign it
* to you.&nbsp; If you set it and you do not have permissions on that
* user's account you will get an error.
*/
@SerializedName("user_oid")
private Long userId;
/**
* Any particular memory/disk size overrides you want to make.&nbsp; If
* they are compatible with the pricing plan you selected we will use
* them.&nbsp; We will calculate the cost based on the resources we
* setup you up with.&nbsp; We can provision VPSs in most sizes,
* provided that the host has space for them.&nbsp; The low contention
* plans are an exception.&nbsp; You will likely need to use the
* provided memory and disk sizes.&nbsp; Since those plans are designed
* so there is a specific (small) number of VPSs per host.&nbsp; And
* having VPSs with 'odd' sizes stops them all fitting in 'neatly'
* (that's not a problem on the bigger-, non-low contention-plans.
*/
@SerializedName("vps_paramters")
private InstanceParameters instanceParameters;
public Long getBillingId() {
return billingId;
}
public void setBillingId(Long billingId) {
this.billingId = billingId;
}
public String getHostServerId() {
return hostServerId;
}
public void setHostServerId(String hostServerId) {
this.hostServerId = hostServerId;
}
public CreateOptions getCreateOptions() {
return createOptions;
}
public void setCreateOptions(CreateOptions createOptions) {
this.createOptions = createOptions;
}
public CloneOptions getCloneOptions() {
return cloneOptions;
}
public void setCloneOptions(CloneOptions cloneOptions) {
this.cloneOptions = cloneOptions;
}
public IpRequest getIpRequest() {
return ipRequest;
}
public void setIpRequest(IpRequest ipRequest) {
this.ipRequest = ipRequest;
}
public String getPlanId() {
return planId;
}
public void setPlanId(String planId) {
this.planId = planId;
}
public Long getUserId() {
return userId;
}
public void setUserId(Long userId) {
this.userId = userId;
}
public InstanceParameters getInstanceParameters() {
return instanceParameters;
}
public void setInstanceParameters(InstanceParameters instanceParameters) {
this.instanceParameters = instanceParameters;
}
public void validate(){
//bitwise XOR, works with boolean :)
assert(this.cloneOptions == null ^ this.createOptions == null);
if(this.cloneOptions != null){
this.cloneOptions.validate();
}
if(this.createOptions != null){
this.createOptions.validate();
assert(this.planId != null && this.planId.length() == 0);
}
if(this.ipRequest != null){
this.ipRequest.validate();
}
if(this.instanceParameters != null){
this.instanceParameters.validate();
}
}
}

View File

@ -0,0 +1,31 @@
/**
*
* Copyright (C) 2009 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.rimuhosting.miro.data;
/**
* Do as much validation as possible to save http requests. No need to go overboard though.
*/
public interface PostData {
public void validate();
}

View File

@ -0,0 +1,85 @@
/**
*
* Copyright (C) 2009 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.rimuhosting.miro.domain;
import com.google.gson.annotations.SerializedName;
import java.sql.Timestamp;
/**
* Billing data. Need to make it inteface with jclouds.
* TODO: test
*/
public class BillingData {
@SerializedName("cancellation_date")
private Timestamp dateCancelled;
@SerializedName("monthly_recurring_fee")
private Double monthlyCharge;
@SerializedName("order_date")
private Timestamp dateOrdered;
@SerializedName("prepaid_until")
private Timestamp dataPrepaidUntil;
@SerializedName("suspended_date")
private Timestamp dateSuspended;
public Timestamp getDateCancelled() {
return dateCancelled;
}
public void setDateCancelled(Timestamp dateCancelled) {
this.dateCancelled = dateCancelled;
}
public Double getMonthlyCharge() {
return monthlyCharge;
}
public void setMonthlyCharge(Double monthlyCharge) {
this.monthlyCharge = monthlyCharge;
}
public Timestamp getDateOrdered() {
return dateOrdered;
}
public void setDateOrdered(Timestamp dateOrdered) {
this.dateOrdered = dateOrdered;
}
public Timestamp getDataPrepaidUntil() {
return dataPrepaidUntil;
}
public void setDataPrepaidUntil(Timestamp dataPrepaidUntil) {
this.dataPrepaidUntil = dataPrepaidUntil;
}
public Timestamp getDateSuspended() {
return dateSuspended;
}
public void setDateSuspended(Timestamp dateSuspended) {
this.dateSuspended = dateSuspended;
}
}

View File

@ -0,0 +1,57 @@
/**
*
* Copyright (C) 2009 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.rimuhosting.miro.domain;
import com.google.gson.annotations.SerializedName;
/**
* TODO: test
*/
public class DataCenter implements Comparable<DataCenter> {
@SerializedName("data_center_location_code")
private String id;
@SerializedName("data_center_location_name")
private String name;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Override
public int compareTo(DataCenter dataCenter) {
return id.compareTo(dataCenter.getId());
}
}

View File

@ -0,0 +1,47 @@
/**
*
* Copyright (C) 2009 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.rimuhosting.miro.domain;
import com.google.gson.annotations.SerializedName;
/**
* TODO: test
*/
public class DataTransferAllowance implements Comparable<DataTransferAllowance>{
@SerializedName("data_transfer_gb")
private Integer dataTransferGb;
public Integer getDataTransferGb() {
return dataTransferGb;
}
public void setDataTransferGb(Integer dataTransferGb) {
this.dataTransferGb = dataTransferGb;
}
@Override
public int compareTo(DataTransferAllowance dataTransferAllowance) {
return dataTransferGb - dataTransferAllowance.getDataTransferGb();
}
}

View File

@ -0,0 +1,57 @@
/**
*
* Copyright (C) 2009 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.rimuhosting.miro.domain;
import com.google.gson.annotations.SerializedName;
/**
* Image object.
*/
public class Image implements Comparable<Image> {
@SerializedName("distro_code")
private String id;
@SerializedName("distro_desciption")
private String description;
@Override
public int compareTo(Image image) {
return id.compareTo(image.getId());
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
}

View File

@ -0,0 +1,183 @@
/**
*
* Copyright (C) 2009 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.rimuhosting.miro.domain;
import com.google.gson.annotations.SerializedName;
import org.jclouds.rimuhosting.miro.data.NewInstance;
/**
* Instance Object.
* TODO: javadoc
*/
public class Instance implements Comparable<Instance> {
@SerializedName("allocated_ips")
private IpAddresses ipAddresses;
@SerializedName("billing_info")
private BillingData billingData;
@SerializedName("billing_oid")
private Long billingId;
@SerializedName("data_transfer_allowance")
private DataTransferAllowance allowance;
@SerializedName("distro")
private String imageId;
@SerializedName("domain_name")
private String name;
@SerializedName("host_server_oid")
private String hostServerId;
@SerializedName("is_on_customers_own_physical_server")
private Boolean onDedicatedHardware;
@SerializedName("order_oid")
private Long id;
@SerializedName("running_state")
private String state;
@SerializedName("server_type")
private String type;
private String slug;
@SerializedName("vps_parameters")
private InstanceParameters instanceParameters;
//Object returned back with
private transient NewInstance instanceRequest;
public IpAddresses getIpAddresses() {
return ipAddresses;
}
public void setIpAddresses(IpAddresses ipAddresses) {
this.ipAddresses = ipAddresses;
}
public BillingData getBillingData() {
return billingData;
}
public void setBillingData(BillingData billingData) {
this.billingData = billingData;
}
public Long getBillingId() {
return billingId;
}
public void setBillingId(Long billingId) {
this.billingId = billingId;
}
public DataTransferAllowance getAllowance() {
return allowance;
}
public void setAllowance(DataTransferAllowance allowance) {
this.allowance = allowance;
}
public String getImageId() {
return imageId;
}
public void setImageId(String imageId) {
this.imageId = imageId;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getHostServerId() {
return hostServerId;
}
public void setHostServerId(String hostServerId) {
this.hostServerId = hostServerId;
}
public Boolean isOnDedicatedHardware() {
return onDedicatedHardware;
}
public void setOnDedicatedHardware(Boolean onDedicatedHardware) {
this.onDedicatedHardware = onDedicatedHardware;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getState() {
return state;
}
public void setState(String state) {
this.state = state;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getSlug() {
return slug;
}
public void setSlug(String slug) {
this.slug = slug;
}
public InstanceParameters getInstanceParameters() {
return instanceParameters;
}
public void setInstanceParameters(InstanceParameters instanceParameters) {
this.instanceParameters = instanceParameters;
}
public NewInstance getInstanceRequest() {
return instanceRequest;
}
public void setInstanceRequest(NewInstance instanceRequest) {
this.instanceRequest = instanceRequest;
}
@Override
public int compareTo(Instance instance) {
return name.compareTo(instance.getName());
}
}

View File

@ -0,0 +1,230 @@
/**
*
* Copyright (C) 2009 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.rimuhosting.miro.domain;
import com.google.gson.annotations.SerializedName;
import org.jclouds.rimuhosting.miro.domain.internal.RimuHostingTimestamp;
import org.jclouds.rimuhosting.miro.domain.internal.RunningState;
public class InstanceInfo {
/**
* Whether the server pinged from the host server.
*/
@SerializedName("pings_ok")
private boolean instancePings;
/**
* The current kernel label.&nbsp; e.g. default is the recommended
* one.
*/
@SerializedName("current_kernel")
private String kernel;
/**
* Some current_kernel labels are symlinks to different
* kernel.&nbsp; e.g. 'default' is a symlink to kernel that we think
* will work best for the host server and its VPSs.&nbsp; Over time
* we may change it (e.g. so it points to a newer server).&nbsp; In
* which case your server would get that new kernel the next time it
* is restarted.&nbsp; Note that to get the new kernel you need to
* restart the server from _outside_ the VPS (i.e. not with a reboot
* command).
*/
@SerializedName("current_kernel_canonical")
private String kernelCanonical;
/**
* The last backup message stored for the VPS.
*/
@SerializedName("last_backup_message")
private String backupMessage;
/**
* Whether the console-over-ssh login feature is enabled.
*/
@SerializedName("is_console_login_enabled")
private boolean isConsoleLoginEnabled;
/**
* The console-over-sshes authorized keys (if they are set).&nbsp;
* Else the console access would be controlled by a password.
*/
@SerializedName("console_public_authorized_keys")
private String consolePublicKeys;
/**
* true when the host server is running a backup of the VPS.&nbsp;
* On new hosts we use LVM file systems so backups can be performed
* by only pausing VPSs for a fraction of a second.
*/
@SerializedName("is_backup_running")
private boolean isBackupRunning;
/**
* true on almost all servers.&nbsp; false when the backups are
* enabled.&nbsp; e.g. if a customer had requested we disable them.
*/
@SerializedName("is_backups_enabled")
private boolean backupsEnabled;
//public boolean is_one_week_backup;
/**
* The time we next expect a backup to run.&nbsp; The actual time
* may be a bit later (e.g. if other VPSs are due to run at this
* time slot).&nbsp; We run VPS backups sequentially (one after the
* other).&nbsp; So if two VPSs were scheduled for a backup at the
* same time one may run a few minutes after the other.
*/
@SerializedName("next_backup_time")
private RimuHostingTimestamp nextBackup;
/**
* How long Xen reports the VPS has been up and running for.&nbsp;
* In seconds.&nbsp; Divide by your time unit of choice :)
*/
@SerializedName("vps_uptime_s")
private long instanceUptime;
/**
* The number of CPU seconds consumed by a VPS.&nbsp; Note that if a
* VPS is using more than one core or CPU then this number can be
* higher than the uptime number.
*/
@SerializedName("vps_cpu_time_s")
private long instanceCpuTime;
/**
* Whether the VPS is, for example, running or not.&nbsp; Typically
* VPSs will all be running.&nbsp; A VPS may be in a non-running
* state, for example, for a short time after its host server is
* restarted.&nbsp; Since we start VPSs sequentially (one after the
* other) to keep server load to a manageable level.&nbsp;
*/
@SerializedName("running_state")
private RunningState state;
/**
* Whether the VPS is marked to not run.&nbsp; e.g. some host server
* operations (like a disk resize) set the suspended state to
* prevent the VPS running or other actions being performed while
* that operation is being performed.&nbsp; Sometimes we may set
* this if the server is 'administratively down', e.g. as a
* consequence of the server breaching our terms of service.
*/
@SerializedName("is_suspended")
private boolean isSuspended;
public boolean isInstancePings() {
return instancePings;
}
public void setInstancePings(boolean instancePings) {
this.instancePings = instancePings;
}
public String getKernel() {
return kernel;
}
public void setKernel(String kernel) {
this.kernel = kernel;
}
public String getKernelCanonical() {
return kernelCanonical;
}
public void setKernelCanonical(String kernelCanonical) {
this.kernelCanonical = kernelCanonical;
}
public String getBackupMessage() {
return backupMessage;
}
public void setBackupMessage(String backupMessage) {
this.backupMessage = backupMessage;
}
public boolean isConsoleLoginEnabled() {
return isConsoleLoginEnabled;
}
public void setConsoleLoginEnabled(boolean consoleLoginEnabled) {
isConsoleLoginEnabled = consoleLoginEnabled;
}
public String getConsolePublicKeys() {
return consolePublicKeys;
}
public void setConsolePublicKeys(String consolePublicKeys) {
this.consolePublicKeys = consolePublicKeys;
}
public boolean isBackupRunning() {
return isBackupRunning;
}
public void setBackupRunning(boolean backupRunning) {
isBackupRunning = backupRunning;
}
public boolean isBackupsEnabled() {
return backupsEnabled;
}
public void setBackupsEnabled(boolean backupsEnabled) {
this.backupsEnabled = backupsEnabled;
}
public RimuHostingTimestamp getNextBackup() {
return nextBackup;
}
public void setNextBackup(RimuHostingTimestamp nextBackup) {
this.nextBackup = nextBackup;
}
public long getInstanceUptime() {
return instanceUptime;
}
public void setInstanceUptime(long instanceUptime) {
this.instanceUptime = instanceUptime;
}
public long getInstanceCpuTime() {
return instanceCpuTime;
}
public void setInstanceCpuTime(long instanceCpuTime) {
this.instanceCpuTime = instanceCpuTime;
}
public RunningState getState() {
return state;
}
public void setState(RunningState state) {
this.state = state;
}
public boolean isSuspended() {
return isSuspended;
}
public void setSuspended(boolean suspended) {
isSuspended = suspended;
}
}

View File

@ -0,0 +1,82 @@
/**
*
* Copyright (C) 2009 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.rimuhosting.miro.domain;
import com.google.gson.annotations.SerializedName;
import org.jclouds.rimuhosting.miro.data.PostData;
/**
* Attributes about a running VPS.&nbsp; Implicit with any changes to
* these attributes on a VPS is that we'd need to restart the VPS for
* the changes to happen.&nbsp; At least at this point in time.
*
* @author Ivan Meredith
*/
public class InstanceParameters implements PostData {
/**
* File system image size.
*/
@SerializedName("disk_space_mb")
private Integer primaryDisk;
/**
* Some VPSs have a secondary partition.&nbsp; One that is not part
* of the regular backup setups.&nbsp; Mostly not used.
*/
@SerializedName("disk_space_2_mb")
private Integer secondaryDisk;
/**
* Memory size.
*/
@SerializedName("memory_mb")
private Integer ram;
public Integer getPrimaryDisk() {
return primaryDisk;
}
public void setPrimaryDisk(Integer primaryDisk) {
this.primaryDisk = primaryDisk;
}
public Integer getSecondaryDisk() {
return secondaryDisk;
}
public void setSecondaryDisk(Integer secondaryDisk) {
this.secondaryDisk = secondaryDisk;
}
public Integer getRam() {
return ram;
}
public void setRam(Integer ram) {
this.ram = ram;
}
@Override
public void validate() {
//XXX: do we need to do anything here?
}
}

View File

@ -0,0 +1,46 @@
/**
*
* Copyright (C) 2009 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.rimuhosting.miro.domain;
import com.google.gson.annotations.SerializedName;
import java.util.SortedSet;
/**
* IpAddresses assigned to an Interface. Not rimuhosting doesnt have private IPs.
*/
public class IpAddresses {
@SerializedName("primary_ip")
private String primaryIp;
@SerializedName("secondary_ips")
private SortedSet<String> secondaryIps;
public String getPrimaryIp() {
return primaryIp;
}
public void setPrimaryIp(String primaryIp) {
this.primaryIp = primaryIp;
}
}

View File

@ -0,0 +1,71 @@
/**
*
* Copyright (C) 2009 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.rimuhosting.miro.domain;
import com.google.gson.annotations.SerializedName;
import org.jclouds.rimuhosting.miro.data.NewInstance;
/**
* Wrapper object to get back all data from a Instance create. The Password has been populated the NewInstance
* object.
*/
public class NewInstanceResponse implements Comparable<NewInstanceResponse> {
@SerializedName("about_order")
private Instance instance;
@SerializedName("new_order_request")
private NewInstance newInstanceRequest;
@SerializedName("running_vps_info")
private InstanceInfo instanceInfo;
public Instance getInstance() {
return instance;
}
public void setInstance(Instance instaince) {
this.instance = instaince;
}
public NewInstance getNewInstanceRequest() {
return newInstanceRequest;
}
public void setNewInstanceRequest(NewInstance newInstanceRequest) {
this.newInstanceRequest = newInstanceRequest;
}
public InstanceInfo getInstanceInfo() {
return instanceInfo;
}
public void setInstanceInfo(InstanceInfo instanceInfo) {
this.instanceInfo = instanceInfo;
}
@Override
public int compareTo(NewInstanceResponse instance) {
return this.instance.getId().compareTo(instance.getInstance().getId());
}
}

View File

@ -0,0 +1,125 @@
/**
*
* Copyright (C) 2009 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.rimuhosting.miro.domain;
import com.google.gson.annotations.SerializedName;
import org.jclouds.rimuhosting.miro.domain.internal.ServerType;
public class PricingPlan implements Comparable<PricingPlan>{
@SerializedName("minimum_data_transfer_allowance_gb")
private Long dataTransfer;
@SerializedName("minimum_disk_gb")
private Integer diskSize;
@SerializedName("minimum_memory_mb")
private Integer ram;
@SerializedName("monthly_recurring_fee_usd")
private Double monthlyCharge;
@SerializedName("offered_at_data_center")
private DataCenter dataCenter;
@SerializedName("pricing_plan_code")
private String id;
@SerializedName("pricing_plan_description")
private String description;
@SerializedName("see_also_url")
private String see_also_url;
@SerializedName("server_type")
private ServerType serverType;
public Long getDataTransfer() {
return dataTransfer;
}
public void setDataTransfer(Long dataTransfer) {
this.dataTransfer = dataTransfer;
}
public Integer getDiskSize() {
return diskSize;
}
public void setDiskSize(Integer diskSize) {
this.diskSize = diskSize;
}
public Integer getRam() {
return ram;
}
public void setRam(Integer ram) {
this.ram = ram;
}
public Double getMonthlyCharge() {
return monthlyCharge;
}
public void setMonthlyCharge(Double monthlyCharge) {
this.monthlyCharge = monthlyCharge;
}
public DataCenter getDataCenter() {
return dataCenter;
}
public void setDataCenter(DataCenter dataCenter) {
this.dataCenter = dataCenter;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getSee_also_url() {
return see_also_url;
}
public void setSee_also_url(String see_also_url) {
this.see_also_url = see_also_url;
}
public ServerType getServerType() {
return serverType;
}
public void setServerType(ServerType serverType) {
this.serverType = serverType;
}
@Override
public int compareTo(PricingPlan pricingPlan) {
return id.compareTo(pricingPlan.getId());
}
}

View File

@ -0,0 +1,98 @@
/**
*
* Copyright (C) 2009 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.rimuhosting.miro.domain;
import com.google.gson.annotations.SerializedName;
import java.util.List;
/**
* Information about a resource change.
*/
public class ResizeResult {
/**
* Original monthly pricing, in USD.
*/
@SerializedName("original_pricing")
private Double originalPricing;
/**
* New monthly pricing, in USD, after the resource changes.
*/
@SerializedName("new_pricing")
private Double newPricing;
/**
* Information about the change.&nbsp; e.g. may include information
* about how we calculate pro-rated credits or fees.&nbsp; Or what
* paypal subscriptions need to get changed to.&nbsp; Or what
* prepayment date changes were made.
* <p/>
* You will need to check these messages in some cases.&nbsp; e.g.
* if you are decreasing pricing and you are paying via a paypal
* subscription.&nbsp; Since you would be overpaying your account,
* unless you followed the directions to modify your paypal
* subscription.
*/
@SerializedName("resource_change_messages")
private List<String> messages;
/**
* true if we made the resource changes.&nbsp; False if we did not
* make them, e.g. if we hit a billing issue, or if the host server
* did not have the resources to accomodate the change.
*/
@SerializedName("were_resources_changed")
private Boolean success;
public double getNewPricing() {
return newPricing;
}
public void setNewPricing(double newPricing) {
this.newPricing = newPricing;
}
public List<String> getMessages() {
return messages;
}
public void setMessages(List<String> messages) {
this.messages = messages;
}
public boolean isSuccess() {
return success;
}
public void setSuccess(boolean success) {
this.success = success;
}
public double getOriginalPricing() {
return originalPricing;
}
public void setOriginalPricing(double originalPricing) {
this.originalPricing = originalPricing;
}
}

View File

@ -0,0 +1,64 @@
/**
*
* Copyright (C) 2009 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.rimuhosting.miro.domain.internal;
import com.google.gson.annotations.SerializedName;
/**
* Error Object from a response
*/
public class RimuHostingError {
@SerializedName("error_class")
private String errorClass;
@SerializedName("full_error_message")
private String errorMessage;
@SerializedName("error_title")
private String error;
public String getErrorClass() {
return errorClass;
}
public void setErrorClass(String errorClass) {
this.errorClass = errorClass;
}
public String getErrorMessage() {
return errorMessage;
}
public void setErrorMessage(String errorMessage) {
this.errorMessage = errorMessage;
}
public String getError() {
return error;
}
public void setError(String error) {
this.error = error;
}
}

View File

@ -0,0 +1,57 @@
/**
*
* Copyright (C) 2009 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.rimuhosting.miro.domain.internal;
/**
* Object that the payload on requests is wrapped in.
*/
public class RimuHostingResponse {
private String status_message;
private Integer status_code;
private RimuHostingError error_info;
public String getStatusMessage() {
return status_message;
}
public void setStatusMessage(String status_message) {
this.status_message = status_message;
}
public Integer getStatusCode() {
return status_code;
}
public void setStatusCode(Integer status_code) {
this.status_code = status_code;
}
public RimuHostingError getErrorInfo() {
return error_info;
}
public void setErrorInfo(RimuHostingError error_info) {
this.error_info = error_info;
}
}

View File

@ -0,0 +1,45 @@
/**
*
* Copyright (C) 2009 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.rimuhosting.miro.domain.internal;
import java.sql.Timestamp;
/**
* Handles a timestamp JSON object from rimuhosting
*/
public class RimuHostingTimestamp {
private Long ms_since_epoch;
public Long getMs() {
return ms_since_epoch;
}
public void setMs(Long ms_since_epoch) {
this.ms_since_epoch = ms_since_epoch;
}
public Timestamp getTimestamp(){
return new Timestamp(ms_since_epoch);
}
}

View File

@ -0,0 +1,32 @@
/**
*
* Copyright (C) 2009 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.rimuhosting.miro.domain.internal;
/**
* States an instance can be in.
*/
public enum RunningState {
RUNNING, NOTRUNNING, RESTARTING, POWERCYCLING
}

View File

@ -0,0 +1,32 @@
/**
*
* Copyright (C) 2009 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.rimuhosting.miro.domain.internal;
/**
* Jclouds is only interested in VPS.
*/
public enum ServerType {
PHYSICAL, VPS
}

View File

@ -0,0 +1,53 @@
/**
*
* Copyright (C) 2009 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.rimuhosting.miro.filters;
import static com.google.common.base.Preconditions.checkNotNull;
import org.jclouds.http.HttpException;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpRequestFilter;
import javax.inject.Singleton;
import javax.ws.rs.core.HttpHeaders;
import java.util.Collections;
import java.util.List;
/**
* RimuHosting Authentication is a Authorization Header.
*
* Authorization: rimuhosting apikey=&lt;key>
*/
@Singleton
public class RimuHostingAuthentication implements HttpRequestFilter {
private List<String> credentialList;
public RimuHostingAuthentication(String apikey){
this.credentialList = Collections.singletonList(String.format("rimuhosting apikey=%s", checkNotNull(apikey, "apikey")));
}
@Override
public void filter(HttpRequest request) throws HttpException {
request.getHeaders().replaceValues(HttpHeaders.AUTHORIZATION, credentialList);
}
}

View File

@ -0,0 +1,70 @@
/**
*
* Copyright (C) 2009 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.rimuhosting.miro.functions;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import org.jclouds.http.functions.ParseJson;
import org.jclouds.rimuhosting.miro.domain.internal.RimuHostingResponse;
import javax.inject.Inject;
import javax.inject.Singleton;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.Type;
import java.util.List;
import java.util.Map;
@Singleton
public class ParseDestroyResponseFromJsonResponse extends ParseJson<List<String>> {
@Inject
public ParseDestroyResponseFromJsonResponse(Gson gson) {
super(gson);
}
private static class DestroyResponse extends RimuHostingResponse {
private List<String> cancel_messages;
public List<String> getCancelMessages() {
return cancel_messages;
}
public void setCancelMessages(List<String> cancel_messages) {
this.cancel_messages = cancel_messages;
}
}
@Override
protected List<String> apply(InputStream stream) {
Type setType = new TypeToken<Map<String, DestroyResponse>>() {
}.getType();
try {
Map<String, DestroyResponse> responseMap = gson.fromJson(new InputStreamReader(stream, "UTF-8"), setType);
return responseMap.values().iterator().next().getCancelMessages();
} catch (UnsupportedEncodingException e) {
throw new RuntimeException("jclouds requires UTF-8 encoding", e);
}
}
}

View File

@ -0,0 +1,72 @@
/**
*
* Copyright (C) 2009 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.rimuhosting.miro.functions;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import org.jclouds.http.functions.ParseJson;
import org.jclouds.rimuhosting.miro.domain.Image;
import org.jclouds.rimuhosting.miro.domain.internal.RimuHostingResponse;
import javax.inject.Inject;
import javax.inject.Singleton;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.Type;
import java.util.Map;
import java.util.SortedSet;
@Singleton
public class ParseImagesFromJsonResponse extends ParseJson<SortedSet<Image>> {
@Inject
public ParseImagesFromJsonResponse(Gson gson) {
super(gson);
}
private static class DistroResponse extends RimuHostingResponse {
private SortedSet<Image> distro_infos;
public SortedSet<Image> getDistroInfos() {
return distro_infos;
}
public void setDistroInfos(SortedSet<Image> distro_infos) {
this.distro_infos = distro_infos;
}
}
public SortedSet<Image> apply(InputStream stream) {
Type setType = new TypeToken<Map<String, DistroResponse>>() {
}.getType();
try {
Map<String, DistroResponse> t = gson.fromJson(new InputStreamReader(stream, "UTF-8"), setType);
return t.values().iterator().next().getDistroInfos();
} catch (UnsupportedEncodingException e) {
throw new RuntimeException("jclouds requires UTF-8 encoding", e);
}
}
}

View File

@ -0,0 +1,69 @@
/**
*
* Copyright (C) 2009 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.rimuhosting.miro.functions;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import org.jclouds.http.functions.ParseJson;
import org.jclouds.rimuhosting.miro.domain.Instance;
import org.jclouds.rimuhosting.miro.domain.internal.RimuHostingResponse;
import javax.inject.Inject;
import javax.inject.Singleton;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.Type;
import java.util.Map;
@Singleton
public class ParseInstanceFromJsonResponse extends ParseJson<Instance> {
@Inject
public ParseInstanceFromJsonResponse(Gson gson) {
super(gson);
}
private static class OrderResponse extends RimuHostingResponse {
private Instance about_order;
public Instance getAboutOrder() {
return about_order;
}
public void setAboutOrder(Instance about_orders) {
this.about_order = about_orders;
}
}
@Override
protected Instance apply(InputStream stream) {
Type setType = new TypeToken<Map<String, OrderResponse>>() {
}.getType();
try {
Map<String, OrderResponse> responseMap = gson.fromJson(new InputStreamReader(stream, "UTF-8"), setType);
return responseMap.values().iterator().next().getAboutOrder();
} catch (UnsupportedEncodingException e) {
throw new RuntimeException("jclouds requires UTF-8 encoding", e);
}
}
}

View File

@ -0,0 +1,69 @@
/**
*
* Copyright (C) 2009 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.rimuhosting.miro.functions;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import org.jclouds.http.functions.ParseJson;
import org.jclouds.rimuhosting.miro.domain.InstanceInfo;
import org.jclouds.rimuhosting.miro.domain.internal.RimuHostingResponse;
import javax.inject.Inject;
import javax.inject.Singleton;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.Type;
import java.util.Map;
@Singleton
public class ParseInstanceInfoFromJsonResponse extends ParseJson<InstanceInfo> {
@Inject
public ParseInstanceInfoFromJsonResponse(Gson gson) {
super(gson);
}
private static class OrderResponse extends RimuHostingResponse {
private InstanceInfo running_vps_info;
public InstanceInfo getInstanceInfo() {
return running_vps_info;
}
public void setInstanceInfo(InstanceInfo running_vps_info) {
this.running_vps_info = running_vps_info;
}
}
@Override
protected InstanceInfo apply(InputStream stream) {
Type setType = new TypeToken<Map<String, OrderResponse>>() {
}.getType();
try {
Map<String, OrderResponse> responseMap = gson.fromJson(new InputStreamReader(stream, "UTF-8"), setType);
return responseMap.values().iterator().next().getInstanceInfo();
} catch (UnsupportedEncodingException e) {
throw new RuntimeException("jclouds requires UTF-8 encoding", e);
}
}
}

View File

@ -0,0 +1,70 @@
/**
*
* Copyright (C) 2009 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.rimuhosting.miro.functions;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import org.jclouds.http.functions.ParseJson;
import org.jclouds.rimuhosting.miro.domain.Instance;
import org.jclouds.rimuhosting.miro.domain.internal.RimuHostingResponse;
import javax.inject.Inject;
import javax.inject.Singleton;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.Type;
import java.util.Map;
import java.util.SortedSet;
@Singleton
public class ParseInstancesFromJsonResponse extends ParseJson<SortedSet<Instance>> {
@Inject
public ParseInstancesFromJsonResponse(Gson gson) {
super(gson);
}
private static class OrderResponse extends RimuHostingResponse {
private SortedSet<Instance> about_orders;
public SortedSet<Instance> getAboutOrders() {
return about_orders;
}
public void setAboutOrders(SortedSet<Instance> about_orders) {
this.about_orders = about_orders;
}
}
@Override
protected SortedSet<Instance> apply(InputStream stream) {
Type setType = new TypeToken<Map<String, OrderResponse>>() {
}.getType();
try {
Map<String, OrderResponse> responseMap = gson.fromJson(new InputStreamReader(stream, "UTF-8"), setType);
return responseMap.values().iterator().next().getAboutOrders();
} catch (UnsupportedEncodingException e) {
throw new RuntimeException("jclouds requires UTF-8 encoding", e);
}
}
}

View File

@ -0,0 +1,58 @@
/**
*
* Copyright (C) 2009 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.rimuhosting.miro.functions;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import org.jclouds.http.functions.ParseJson;
import org.jclouds.rimuhosting.miro.domain.NewInstanceResponse;
import javax.inject.Inject;
import javax.inject.Singleton;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.Type;
import java.util.Map;
@Singleton
public class ParseNewInstanceResponseFromJsonResponse extends ParseJson<NewInstanceResponse> {
@Inject
public ParseNewInstanceResponseFromJsonResponse(Gson gson) {
super(gson);
}
@Override
protected NewInstanceResponse apply(InputStream stream) {
Type setType = new TypeToken<Map<String, NewInstanceResponse>>() {
}.getType();
try {
Map<String, NewInstanceResponse> responseMap = gson.fromJson(new InputStreamReader(stream, "UTF-8"), setType);
return responseMap.values().iterator().next();
} catch (UnsupportedEncodingException e) {
throw new RuntimeException("jclouds requires UTF-8 encoding", e);
}
}
}

View File

@ -0,0 +1,70 @@
/**
*
* Copyright (C) 2009 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.rimuhosting.miro.functions;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import org.jclouds.http.functions.ParseJson;
import org.jclouds.rimuhosting.miro.domain.PricingPlan;
import org.jclouds.rimuhosting.miro.domain.internal.RimuHostingResponse;
import javax.inject.Inject;
import javax.inject.Singleton;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.Type;
import java.util.Map;
import java.util.SortedSet;
@Singleton
public class ParsePricingPlansFromJsonResponse extends ParseJson<SortedSet<PricingPlan>> {
@Inject
public ParsePricingPlansFromJsonResponse(Gson gson) {
super(gson);
}
private static class PlansResponse extends RimuHostingResponse {
private SortedSet<PricingPlan> pricing_plan_infos;
public SortedSet<PricingPlan> getPricingPlanInfos() {
return pricing_plan_infos;
}
public void setPricingPlanInfos(SortedSet<PricingPlan> pricing_plan_infos) {
this.pricing_plan_infos = pricing_plan_infos;
}
}
@Override
protected SortedSet<PricingPlan> apply(InputStream stream) {
Type setType = new TypeToken<Map<String, PlansResponse>>() {
}.getType();
try {
Map<String, PlansResponse> responseMap = gson.fromJson(new InputStreamReader(stream, "UTF-8"), setType);
return responseMap.values().iterator().next().getPricingPlanInfos();
} catch (UnsupportedEncodingException e) {
throw new RuntimeException("jclouds requires UTF-8 encoding", e);
}
}
}

View File

@ -0,0 +1,78 @@
/**
*
* Copyright (C) 2009 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.rimuhosting.miro.functions;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import org.jclouds.http.functions.ParseJson;
import org.jclouds.rimuhosting.miro.domain.Instance;
import org.jclouds.rimuhosting.miro.domain.internal.RimuHostingResponse;
import javax.inject.Inject;
import javax.inject.Singleton;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.Type;
import java.util.Map;
@Singleton
public class ParseResizeResponseFromJsonResponse extends ParseJson<ParseResizeResponseFromJsonResponse.ResizeResponse> {
@Inject
public ParseResizeResponseFromJsonResponse(Gson gson) {
super(gson);
}
public static class ResizeResponse extends RimuHostingResponse {
private Instance about_order;
private ResizeResponse resource_change_result;
public ResizeResponse getResourceChangeResult() {
return resource_change_result;
}
public void setResourceChangeResult(ResizeResponse resource_change_result) {
this.resource_change_result = resource_change_result;
}
public Instance getAboutOrder() {
return about_order;
}
public void setAboutOrder(Instance about_orders) {
this.about_order = about_orders;
}
}
@Override
protected ResizeResponse apply(InputStream stream) {
Type setType = new TypeToken<Map<String, ResizeResponse>>() {
}.getType();
try {
Map<String, ResizeResponse> responseMap = gson.fromJson(new InputStreamReader(stream, "UTF-8"), setType);
return responseMap.values().iterator().next();
} catch (UnsupportedEncodingException e) {
throw new RuntimeException("jclouds requires UTF-8 encoding", e);
}
}
}

View File

@ -0,0 +1,62 @@
/**
*
* Copyright (C) 2009 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.rimuhosting.miro.functions;
import com.google.common.base.Function;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import org.jclouds.http.HttpResponseException;
import org.jclouds.rimuhosting.miro.domain.internal.RimuHostingResponse;
import javax.inject.Inject;
import javax.inject.Singleton;
import java.lang.reflect.Type;
import java.util.Map;
/**
* On non 2xx we have an error. RimuHosting using the same json base object.
*
* TODO: map exceptions out into something that suits jclouds.
*/
@Singleton
public class ParseRimuHostingException implements Function<Exception, Object> {
private Gson gson;
@Inject
public ParseRimuHostingException(Gson gson) {
this.gson = gson;
}
@Override
public Object apply(Exception e) {
if(e instanceof HttpResponseException){
HttpResponseException responseException = (HttpResponseException)e;
Type setType = new TypeToken<Map<String, RimuHostingResponse>>() {
}.getType();
Map<String, RimuHostingResponse> responseMap = gson.fromJson(responseException.getContent(), setType);
throw new RuntimeException(responseMap.values().iterator().next().getErrorInfo().getErrorClass());
}
return null;
}
}

View File

@ -0,0 +1,35 @@
/**
*
* Copyright (C) 2009 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.rimuhosting.miro.reference;
/**
* Configuration properties and constants used in RimuHosting connections.
*
* @author Adrian Cole
*/
public interface RimuHostingConstants {
public static final String PROPERTY_RIMUHOSTING_ENDPOINT = "jclouds.rimuhosting.endpoint";
public static final String PROPERTY_RIMUHOSTING_USER = "jclouds.rimuhosting.user";
public static final String PROPERTY_RIMUHOSTING_PASSWORD = "jclouds.rimuhosting.password";
}

View File

@ -0,0 +1,103 @@
/**
*
* Copyright (C) 2009 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.rimuhosting.miro;
import com.google.inject.AbstractModule;
import com.google.inject.Module;
import com.google.inject.Provides;
import com.google.inject.TypeLiteral;
import org.jclouds.http.filters.BasicAuthentication;
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 static org.testng.Assert.assertEquals;
import org.testng.annotations.Test;
import javax.inject.Singleton;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URI;
/**
* Tests annotation parsing of {@code RimuHostingAsyncClient}
*
* @author Ivan Meredith
*/
@Test(groups = "unit", testName = "rimuhosting.RimuHostingAsyncClientTest")
public class RimuHostingAsyncClientTest extends RestClientTest<RimuHostingAsyncClient> {
public void testGetMyMentions() throws SecurityException, NoSuchMethodException, IOException {
/* Method method = RimuHostingAsyncClient.class.getMethod("TODO: insert test method name");
GeneratedHttpRequest<RimuHostingAsyncClient> httpMethod = processor.createRequest(method);
assertRequestLineEquals(httpMethod, "TODO: insert expected request");
assertHeadersEqual(httpMethod, "");
assertEntityEquals(httpMethod, null);
assertResponseParserClassEquals(method, httpMethod, ParseStatusesFromJsonResponse.class);
assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod);*/
}
@Override
protected void checkFilters(GeneratedHttpRequest<RimuHostingAsyncClient> httpMethod) {
assertEquals(httpMethod.getFilters().size(), 1);
assertEquals(httpMethod.getFilters().get(0).getClass(), BasicAuthentication.class);
}
@Override
protected TypeLiteral<RestAnnotationProcessor<RimuHostingAsyncClient>> createTypeLiteral() {
return new TypeLiteral<RestAnnotationProcessor<RimuHostingAsyncClient>>() {
};
}
@Override
protected Module createModule() {
return new AbstractModule() {
@Override
protected void configure() {
bind(URI.class).annotatedWith(RimuHosting.class).toInstance(
URI.create("https://rimuhosting.com/r"));
bind(Logger.LoggerFactory.class).toInstance(new LoggerFactory() {
public Logger getLogger(String category) {
return Logger.NULL;
}
});
}
@SuppressWarnings("unused")
@Provides
@Singleton
public BasicAuthentication provideBasicAuthentication()
throws UnsupportedEncodingException {
return new BasicAuthentication("foo", "bar");
}
};
}
}

View File

@ -0,0 +1,95 @@
/**
*
* Copyright (C) 2009 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.rimuhosting.miro;
import static com.google.common.base.Preconditions.checkNotNull;
import org.jclouds.logging.log4j.config.Log4JLoggingModule;
import org.jclouds.rimuhosting.miro.data.CreateOptions;
import org.jclouds.rimuhosting.miro.data.NewInstance;
import org.jclouds.rimuhosting.miro.domain.*;
import org.jclouds.rimuhosting.miro.domain.internal.RunningState;
import static org.testng.Assert.*;
import org.testng.annotations.BeforeGroups;
import org.testng.annotations.Test;
import java.util.SortedSet;
/**
* Tests behavior of {@code RimuHostingClient}
*
* @author Adrian Cole
*/
@Test(groups = "live", testName = "rimuhosting.RimuHostingClientLiveTest")
public class RimuHostingClientLiveTest {
private RimuHostingClient connection;
@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");
connection = RimuHostingContextFactory.createContext(user, password, new Log4JLoggingModule())
.getApi();
}
@Test
public void testPricingPlans(){
SortedSet<PricingPlan> plans = connection.getPricingPlanList();
for(PricingPlan plan : plans){
if(plan.getId().equalsIgnoreCase("miro1")){
assertTrue(true);
return;
}
}
assertTrue(false);
}
@Test
public void testImages(){
SortedSet<Image> images = connection.getImageList();
for(Image image : images){
if(image.getId().equalsIgnoreCase("lenny")){
assertTrue(true);
return;
}
}
assertTrue(false, "lenny not found");
}
@Test
public void testLifeCycle() {
//Get the first image, we dont really care what it is in this test.
NewInstance inst = new NewInstance(new CreateOptions("test.jclouds.org",null,"lenny"),"MIRO1") ;
NewInstanceResponse instanceResponse = connection.createInstance(inst);
Instance instance = instanceResponse.getInstance();
//Now we have the instance, lets restart it
assertNotNull(instance.getId());
InstanceInfo instanceInfo = connection.restartInstance(instance.getId());
connection.destroyInstance(instance.getId());
//Should be running now.
assertEquals(instanceInfo.getState(), RunningState.RUNNING);
assertEquals(instance.getName(),"test.jclouds.org");
assertEquals(instance.getImageId(), "lenny");
}
}

View File

@ -0,0 +1,79 @@
/**
*
* Copyright (C) 2009 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.rimuhosting.miro;
import com.google.common.base.Predicate;
import org.jclouds.logging.Logger;
import org.jclouds.rimuhosting.miro.data.CreateOptions;
import org.jclouds.rimuhosting.miro.data.NewInstance;
import org.jclouds.rimuhosting.miro.domain.Instance;
import org.jclouds.rimuhosting.miro.domain.NewInstanceResponse;
import org.jclouds.ssh.SshClient.Factory;
import javax.annotation.Resource;
import javax.inject.Inject;
import java.net.InetSocketAddress;
public class RimuHostingComputeClient {
@Resource
protected Logger logger = Logger.NULL;
private final Predicate<InetSocketAddress> socketTester;
private final RimuHostingClient rhClient;
@Inject
public RimuHostingComputeClient(RimuHostingClient rhClient, Factory sshFactory,
Predicate<InetSocketAddress> socketTester) {
this.rhClient = rhClient;
this.sshFactory = sshFactory;
this.socketTester = socketTester;
}
private final Factory sshFactory;
public Long start(String name, String planId, String imageId) {
logger.debug(">> instantiating RimuHosting VPS name(%s) plan(%s) image(%s)", name, planId, imageId);
NewInstanceResponse instanceRespone = rhClient.createInstance(new NewInstance(new CreateOptions(name,null,imageId), planId));
logger.debug(">> VPS id(%d) started and running.", instanceRespone.getInstance().getId());
return instanceRespone.getInstance().getId();
}
public void reboot(Long id) {
Instance instance = rhClient.getInstance(id);
logger.debug(">> rebooting VPS(%d)", instance.getId());
rhClient.restartInstance(id);
logger.debug("<< on VPS(%d)", instance.getId());
}
public void destroy(Long id) {
Instance instance = rhClient.getInstance(id);
logger.debug(">> destroy VPS(%d)", instance.getId());
rhClient.destroyInstance(id);
logger.debug(">> destroyed VPS");
}
}

View File

@ -0,0 +1,117 @@
/**
*
* Copyright (C) 2009 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.rimuhosting.miro;
import static com.google.common.base.Preconditions.checkNotNull;
import com.google.common.base.Predicate;
import com.google.inject.*;
import org.jclouds.logging.log4j.config.Log4JLoggingModule;
import org.jclouds.predicates.AddressReachable;
import org.jclouds.predicates.RetryablePredicate;
import org.jclouds.predicates.SocketOpen;
import org.jclouds.rimuhosting.miro.domain.Instance;
import org.jclouds.ssh.jsch.config.JschSshClientModule;
import static org.testng.Assert.assertEquals;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeGroups;
import org.testng.annotations.Test;
import java.io.IOException;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
/**
* Tests behavior of {@code TerremarkVCloudClient}
*
* @author Adrian Cole
*/
@Test(groups = "live", sequential = true, testName = "rimuhosting.RimuHostingComputeClientLiveTest")
public class RimuHostingComputeClientLiveTest {
RimuHostingComputeClient client;
RimuHostingClient rhClient;
private Long id;
private InetAddress publicIp;
private Predicate<InetAddress> addressTester;
@Test
public void testPowerOn() throws InterruptedException, ExecutionException, TimeoutException,
IOException {
String imageId = "lenny";
String serverName = "test.jclouds.org";
String planId = "MIRO1";
id = client.start(serverName, planId, imageId);
Instance instance = rhClient.getInstance(id);
assertEquals(imageId, instance.getImageId());
assertEquals(serverName, instance.getName());
assertEquals(new Integer(160), instance.getInstanceParameters().getRam());
}
@AfterTest
void cleanup() throws InterruptedException, ExecutionException, TimeoutException {
if (id != null)
client.destroy(id);
}
@BeforeGroups(groups = { "live" })
public void setupClient() {
String account = checkNotNull(System.getProperty("jclouds.test.user"), "jclouds.test.user");
String key = checkNotNull(System.getProperty("jclouds.test.key"), "jclouds.test.key");
Injector injector = new RimuHostingContextBuilder(new RimuHostingPropertiesBuilder(
account, key).relaxSSLHostname().build()).withModules(new Log4JLoggingModule(),
new JschSshClientModule(), new AbstractModule() {
@Override
protected void configure() {
}
@SuppressWarnings("unused")
@Provides
private Predicate<InetSocketAddress> socketTester(SocketOpen open) {
return new RetryablePredicate<InetSocketAddress>(open, 130, 10,
TimeUnit.SECONDS);// make it longer then
// default internet
}
@SuppressWarnings("unused")
@Provides
private Predicate<InetAddress> addressTester(AddressReachable reachable) {
return new RetryablePredicate<InetAddress>(reachable, 60, 5, TimeUnit.SECONDS);
}
}).buildInjector();
client = injector.getInstance(RimuHostingComputeClient.class);
rhClient = injector.getInstance(RimuHostingClient.class);
addressTester = injector.getInstance(Key.get(new TypeLiteral<Predicate<InetAddress>>() {
}));
}
}

View File

@ -0,0 +1,96 @@
/**
*
* Copyright (C) 2009 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.rimuhosting.miro;
import com.google.inject.Injector;
import com.google.inject.Key;
import com.google.inject.Module;
import com.google.inject.TypeLiteral;
import org.jclouds.rest.RestContext;
import org.jclouds.rest.internal.RestContextImpl;
import org.jclouds.rimuhosting.miro.config.RimuHostingRestClientModule;
import org.jclouds.rimuhosting.miro.filters.RimuHostingAuthentication;
import org.jclouds.rimuhosting.miro.reference.RimuHostingConstants;
import static org.testng.Assert.assertEquals;
import org.testng.annotations.Test;
import java.net.URI;
import java.util.ArrayList;
import java.util.List;
/**
* Tests behavior of modules configured in RimuHostingContextBuilder
*
* @author Adrian Cole
*/
@Test(groups = "unit", testName = "rimuhosting.RimuHostingContextBuilderTest")
public class RimuHostingContextBuilderTest {
public void testNewBuilder() {
RimuHostingContextBuilder builder = newBuilder();
assertEquals(builder.getProperties().getProperty(RimuHostingConstants.PROPERTY_RIMUHOSTING_ENDPOINT),
"https://rimuhosting.com/r");
assertEquals(builder.getProperties().getProperty(RimuHostingConstants.PROPERTY_RIMUHOSTING_USER),
"user");
assertEquals(builder.getProperties().getProperty(RimuHostingConstants.PROPERTY_RIMUHOSTING_PASSWORD),
"password");
}
public void testBuildContext() {
RestContext<RimuHostingAsyncClient, RimuHostingClient> context = newBuilder().buildContext();
assertEquals(context.getClass(), RestContextImpl.class);
assertEquals(context.getAccount(), "user");
assertEquals(context.getEndPoint(), URI.create("https://rimuhosting.com/r"));
}
public void testBuildInjector() {
Injector i = newBuilder().buildInjector();
assert i.getInstance(Key.get(new TypeLiteral<RestContext<RimuHostingAsyncClient, RimuHostingClient>>() {
})) != null; // TODO: test all things taken from context
assert i.getInstance(RimuHostingAuthentication.class) != null;
}
protected void testAddContextModule() {
List<Module> modules = new ArrayList<Module>();
RimuHostingContextBuilder builder = newBuilder();
builder.addContextModule(modules);
assertEquals(modules.size(), 1);
assertEquals(modules.get(0).getClass(), RimuHostingRestClientModule.class);
}
private RimuHostingContextBuilder newBuilder() {
RimuHostingContextBuilder builder = new RimuHostingContextBuilder(new RimuHostingPropertiesBuilder(
"user", "password").build());
return builder;
}
protected void addClientModule() {
List<Module> modules = new ArrayList<Module>();
RimuHostingContextBuilder builder = newBuilder();
builder.addClientModule(modules);
assertEquals(modules.size(), 1);
assertEquals(modules.get(0).getClass(), RimuHostingRestClientModule.class);
}
}

View File

@ -0,0 +1,105 @@
/**
*
* Copyright (C) 2009 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.rimuhosting.miro.config;
import com.google.inject.Guice;
import com.google.inject.Injector;
import org.jclouds.concurrent.WithinThreadExecutorService;
import org.jclouds.concurrent.config.ExecutorServiceModule;
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.CDateTimeAdapter;
import org.jclouds.http.functions.config.ParserModule.DateTimeAdapter;
import org.jclouds.http.handlers.CloseContentAndSetExceptionErrorHandler;
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.rimuhosting.miro.reference.RimuHostingConstants;
import org.jclouds.util.Jsr330;
import static org.testng.Assert.assertEquals;
import org.testng.annotations.Test;
/**
* @author Adrian Cole
*/
@Test(groups = "unit", testName = "rimuhosting.RimuHostingContextModule")
public class RimuHostingContextModuleTest {
Injector createInjector() {
return Guice.createInjector(new RimuHostingRestClientModule(), new RimuHostingContextModule() {
@Override
protected void configure() {
bindConstant().annotatedWith(Jsr330.named(RimuHostingConstants.PROPERTY_RIMUHOSTING_USER)).to(
"user");
bindConstant().annotatedWith(Jsr330.named(RimuHostingConstants.PROPERTY_RIMUHOSTING_PASSWORD))
.to("password");
bindConstant().annotatedWith(Jsr330.named(RimuHostingConstants.PROPERTY_RIMUHOSTING_ENDPOINT))
.to("http://localhost");
bind(Logger.LoggerFactory.class).toInstance(new LoggerFactory() {
public Logger getLogger(String category) {
return Logger.NULL;
}
});
super.configure();
}
}, new ParserModule(), new JavaUrlHttpCommandExecutorServiceModule(),
new ExecutorServiceModule(new WithinThreadExecutorService()));
}
@Test
void testServerErrorHandler() {
DelegatingErrorHandler handler = createInjector().getInstance(DelegatingErrorHandler.class);
assertEquals(handler.getServerErrorHandler().getClass(),
CloseContentAndSetExceptionErrorHandler.class);
}
@Test
void testDateTimeAdapter() {
assertEquals(this.createInjector().getInstance(DateTimeAdapter.class).getClass(),
CDateTimeAdapter.class);
}
@Test
void testClientErrorHandler() {
DelegatingErrorHandler handler = createInjector().getInstance(DelegatingErrorHandler.class);
assertEquals(handler.getClientErrorHandler().getClass(),
CloseContentAndSetExceptionErrorHandler.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);
}
}

View File

@ -0,0 +1,50 @@
/**
*
* Copyright (C) 2009 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.rimuhosting.miro.functions;
import com.google.inject.Guice;
import com.google.inject.Injector;
import org.jclouds.http.functions.config.ParserModule;
import org.jclouds.util.DateService;
import org.testng.annotations.Test;
/**
* Tests behavior of {@code ParseStatusesFromJsonResponse}
*
* @author Adrian Cole
*/
@Test(groups = "unit", testName = "twitter.ParseStatusesFromJsonResponseTest")
public class ParseStatusesFromJsonResponseTest {
Injector i = Guice.createInjector(new ParserModule() {
@Override
protected void configure() {
bind(DateTimeAdapter.class).to(CDateTimeAdapter.class);
super.configure();
}
});
DateService dateService = new DateService();
}

View File

@ -0,0 +1,113 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (C) 2009 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.
====================================================================
-->
<!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.http.headers">
<priority value="DEBUG" />
<appender-ref ref="ASYNCWIRE" />
</category>
<category name="jclouds.http.wire">
<priority value="DEBUG" />
<appender-ref ref="ASYNCWIRE" />
</category>
<!-- ======================= -->
<!-- Setup the Root category -->
<!-- ======================= -->
<root>
<priority value="WARN" />
</root>
</log4j:configuration>

View File

@ -0,0 +1,80 @@
[
{
"created_at" : "Sat Oct 31 09:35:27 +0000 2009",
"favorited" : false,
"geo" : null,
"id" : 5310690603,
"in_reply_to_screen_name" : null,
"in_reply_to_status_id" : null,
"in_reply_to_user_id" : null,
"source" : "<a href=\"http://www.tweetdeck.com/\" rel=\"nofollow\">TweetDeck</a>",
"text" : "RT @jclouds: live multi #cloud demo of jclouds connecting to 3 storage clouds from google appengine http://is.gd/4IXMh",
"truncated" : false,
"user" : { "created_at" : "Tue Apr 28 15:29:42 +0000 2009",
"description" : "Some random guy who seems to care about cloud collisions at siliconANGLE.com",
"favourites_count" : 245,
"followers_count" : 572,
"following" : false,
"friends_count" : 325,
"geo_enabled" : false,
"id" : 36093693,
"location" : "San Francisco ",
"name" : "James Watters",
"notifications" : false,
"profile_background_color" : "C6E2EE",
"profile_background_image_url" : "http://a1.twimg.com/profile_background_images/24067016/17361976.jpg",
"profile_background_tile" : true,
"profile_image_url" : "http://a3.twimg.com/profile_images/445071063/tiktaalik-transitional-fossil_normal.png",
"profile_link_color" : "1F98C7",
"profile_sidebar_border_color" : "C6E2EE",
"profile_sidebar_fill_color" : "DAECF4",
"profile_text_color" : "663B12",
"protected" : false,
"screen_name" : "wattersjames",
"statuses_count" : 1964,
"time_zone" : "Pacific Time (US & Canada)",
"url" : "http://siliconangle.net/ver2/author/jwatters/",
"utc_offset" : -28800,
"verified" : false
}
},
{
"created_at" : "Sat Oct 31 01:45:14 +0000 2009",
"favorited" : false,
"geo" : null,
"id" : 5303839785,
"in_reply_to_screen_name" : null,
"in_reply_to_status_id" : null,
"in_reply_to_user_id" : null,
"source" : "<a href=\"http://www.tweetdeck.com/\" rel=\"nofollow\">TweetDeck</a>",
"text" : "RT @jclouds: come find out about #cloud storage and how to access it from #java in palo alto this Tuesday: http://is.gd/4IFA9",
"truncated" : false,
"user" : { "created_at" : "Sat Apr 26 06:13:08 +0000 2008",
"description" : "Jack of All Trades: Dad to anZel and Arden, VMware, vCloud, Security, Compliance, Former Developer",
"favourites_count" : 0,
"followers_count" : 474,
"following" : false,
"friends_count" : 199,
"geo_enabled" : false,
"id" : 14540593,
"location" : "Bay Area, CA",
"name" : "Jian Zhen",
"notifications" : false,
"profile_background_color" : "C6E2EE",
"profile_background_image_url" : "http://s.twimg.com/a/1256778767/images/themes/theme2/bg.gif",
"profile_background_tile" : false,
"profile_image_url" : "http://a3.twimg.com/profile_images/64445411/30b8b19_bigger_normal.jpg",
"profile_link_color" : "1F98C7",
"profile_sidebar_border_color" : "C6E2EE",
"profile_sidebar_fill_color" : "DAECF4",
"profile_text_color" : "663B12",
"protected" : false,
"screen_name" : "zhenjl",
"statuses_count" : 1981,
"time_zone" : "Pacific Time (US & Canada)",
"url" : "http://zhen.org",
"utc_offset" : -28800,
"verified" : false
}
}
]