Issue 77: initial support for rackspace cloud servers

git-svn-id: http://jclouds.googlecode.com/svn/trunk@1632 3d8758e0-26b5-11de-8745-db77d3ebf521
This commit is contained in:
adrian.f.cole 2009-07-16 22:26:12 +00:00
parent d92f4e2750
commit 0c4b0203a8
54 changed files with 2688 additions and 35 deletions

View File

@ -1,3 +1,26 @@
/**
*
* Copyright (C) 2009 Global Cloud Specialists, Inc. <info@globalcloudspecialists.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.rackspace.cloudfiles.config;
import java.net.URI;

View File

@ -1,3 +1,26 @@
/**
*
* Copyright (C) 2009 Global Cloud Specialists, Inc. <info@globalcloudspecialists.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.rackspace.cloudfiles.internal;
import java.io.IOException;

View File

@ -23,8 +23,8 @@
*/
package org.jclouds.rackspace.cloudfiles;
import static org.jclouds.rackspace.cloudfiles.reference.CloudFilesConstants.PROPERTY_RACKSPACE_KEY;
import static org.jclouds.rackspace.cloudfiles.reference.CloudFilesConstants.PROPERTY_RACKSPACE_USER;
import static org.jclouds.rackspace.reference.RackspaceConstants.PROPERTY_RACKSPACE_KEY;
import static org.jclouds.rackspace.reference.RackspaceConstants.PROPERTY_RACKSPACE_USER;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertTrue;
@ -58,14 +58,14 @@ public class CloudFilesConnectionLiveTest {
assertNotNull(response);
long initialContainerCount = response.size();
assertTrue(initialContainerCount >= 0);
String[] containerNames = new String[] {
bucketPrefix + ".testListOwnedContainers1",bucketPrefix + ".testListOwnedContainers2"};
String[] containerNames = new String[] { bucketPrefix + ".testListOwnedContainers1",
bucketPrefix + ".testListOwnedContainers2" };
assertTrue(connection.putContainer(containerNames[0]));
assertTrue(connection.putContainer(containerNames[1]));
response = connection.listOwnedContainers();
assertEquals(response.size(), initialContainerCount + 2);
assertTrue(connection.deleteContainerIfEmpty(containerNames[0]));
assertTrue(connection.deleteContainerIfEmpty(containerNames[1]));
response = connection.listOwnedContainers();
@ -79,30 +79,29 @@ public class CloudFilesConnectionLiveTest {
AccountMetadata metadata = connection.getAccountMetadata();
assertNotNull(metadata);
long initialContainerCount = metadata.getContainerCount();
String containerName = bucketPrefix + ".testHeadAccountMetadata";
assertTrue(connection.putContainer(containerName));
metadata = connection.getAccountMetadata();
assertNotNull(metadata);
assertEquals(metadata.getContainerCount(), initialContainerCount + 1);
assertTrue(connection.deleteContainerIfEmpty(containerName));
}
@Test
public void testDeleteContainer() throws Exception {
CloudFilesConnection connection = CloudFilesContextBuilder.newBuilder(sysRackspaceUser,
sysRackspaceKey).withJsonDebug().buildContext().getConnection();
assertTrue(connection.deleteContainerIfEmpty("does-not-exist"));
String containerName = bucketPrefix + ".testDeleteContainer";
assertTrue(connection.putContainer(containerName));
assertTrue(connection.putContainer(containerName));
assertTrue(connection.deleteContainerIfEmpty(containerName));
}
@Test
public void testPutContainers() throws Exception {
CloudFilesConnection connection = CloudFilesContextBuilder.newBuilder(sysRackspaceUser,
@ -110,31 +109,30 @@ public class CloudFilesConnectionLiveTest {
String containerName1 = bucketPrefix + ".hello";
assertTrue(connection.putContainer(containerName1));
// List only the container just created, using a marker with the container name less 1 char
List<ContainerMetadata> response = connection.listOwnedContainers(ListContainerOptions.Builder
.afterMarker(containerName1.substring(0, containerName1.length() - 1))
.maxResults(1));
List<ContainerMetadata> response = connection
.listOwnedContainers(ListContainerOptions.Builder.afterMarker(
containerName1.substring(0, containerName1.length() - 1)).maxResults(1));
assertNotNull(response);
assertEquals(response.size(), 1);
assertEquals(response.get(0).getName(), bucketPrefix + ".hello");
// TODO: Contrary to the API documentation, a container can be created with '?' in the name.
String containerName2 = bucketPrefix + "?should-be-illegal-question-char";
connection.putContainer(containerName2);
// List only the container just created, using a marker with the container name less 1 char
response = connection.listOwnedContainers(ListContainerOptions.Builder
.afterMarker(containerName2.substring(0, containerName2.length() - 1))
.maxResults(1));
response = connection.listOwnedContainers(ListContainerOptions.Builder.afterMarker(
containerName2.substring(0, containerName2.length() - 1)).maxResults(1));
assertEquals(response.size(), 1);
// TODO: Should throw a specific exception, not UndeclaredThrowableException
try {
connection.putContainer(bucketPrefix + "/illegal-slash-char");
fail("Should not be able to create container with illegal '/' character");
} catch (Exception e) {
} catch (Exception e) {
}
assertTrue(connection.deleteContainerIfEmpty(containerName1));
assertTrue(connection.deleteContainerIfEmpty(containerName2));
assertTrue(connection.deleteContainerIfEmpty(containerName2));
}
}

View File

@ -29,11 +29,14 @@ import java.io.InputStream;
import java.util.List;
import org.apache.commons.io.IOUtils;
import org.jclouds.http.functions.config.ParserModule;
import org.jclouds.rackspace.cloudfiles.domain.ContainerMetadata;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableList;
import com.google.gson.Gson;
import com.google.inject.Guice;
import com.google.inject.Injector;
/**
* Tests behavior of {@code ParseContainerListFromGsonResponse}
@ -42,6 +45,7 @@ import com.google.gson.Gson;
*/
@Test(groups = "unit", testName = "cloudfiles.ParseContainerListFromGsonResponse")
public class ParseContainerListFromGsonResponseTest {
Injector i = Guice.createInjector(new ParserModule());
@Test
public void testApplyInputStream() {
@ -49,7 +53,7 @@ public class ParseContainerListFromGsonResponseTest {
.toInputStream("[ {\"name\":\"test_container_1\",\"count\":2,\"bytes\":78}, {\"name\":\"test_container_2\",\"count\":1,\"bytes\":17} ] ");
List<ContainerMetadata> expects = ImmutableList.of(new ContainerMetadata("test_container_1",
2, 78), new ContainerMetadata("test_container_2", 1, 17));
ParseContainerListFromGsonResponse parser = new ParseContainerListFromGsonResponse(new Gson());
ParseContainerListFromGsonResponse parser = new ParseContainerListFromGsonResponse(i.getInstance(Gson.class));
assertEquals(parser.apply(is), expects);
}

View File

@ -0,0 +1,48 @@
<?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-cloudservers-project</artifactId>
<version>1.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>org.jclouds</groupId>
<artifactId>jclouds-cloudservers-core</artifactId>
<name>jclouds cloudservers Components Core</name>
<packaging>jar</packaging>
<description>jclouds Core components to access cloudservers</description>
<scm>
<connection>scm:svn:http://jclouds.googlecode.com/svn/trunk/rackspace/cloudservers/core</connection>
<developerConnection>scm:svn:https://jclouds.googlecode.com/svn/trunk/rackspace/cloudservers/core</developerConnection>
<url>http://jclouds.googlecode.com/svn/trunk/rackspace/cloudservers/core</url>
</scm>
</project>

View File

@ -0,0 +1,84 @@
/**
*
* Copyright (C) 2009 Global Cloud Specialists, Inc. <info@globalcloudspecialists.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.rackspace.cloudservers;
import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import org.jclouds.rackspace.cloudservers.domain.Server;
import org.jclouds.rackspace.cloudservers.functions.ParseServerListFromGsonResponse;
import org.jclouds.rackspace.filters.AuthenticateRequest;
import org.jclouds.rest.Query;
import org.jclouds.rest.RequestFilters;
import org.jclouds.rest.ResponseParser;
import org.jclouds.rest.SkipEncoding;
/**
* Provides access to Cloud Servers via their REST API.
* <p/>
* All commands return a Future of the result from Cloud Servers. Any exceptions incurred during
* processing will be wrapped in an {@link ExecutionException} as documented in {@link Future#get()}.
*
* @see <a href="http://docs.rackspacecloud.com/servers/api/cs-devguide-latest.pdf" />
* @author Adrian Cole
*/
@SkipEncoding('/')
@RequestFilters(AuthenticateRequest.class)
public interface CloudServersConnection {
/**
*
* List all servers (IDs and names only)
*
* @see #listServerDetails()
*/
@GET
@ResponseParser(ParseServerListFromGsonResponse.class)
@Query(key = "format", value = "json")
@Path("/servers")
List<Server> listServers();
/**
* This operation provides a list of servers associated with your account. Servers that have been
* deleted are not included in this list. Servers contain a status attribute that can be used as
* an indication of the current server state. Servers with an ACTIVE status are available for
* use. Other possible values for the status attribute include: BUILD, REBUILD, SUSPENDED,
* QUEUE_RESIZE, PREP_RESIZE, VERIFY_RESIZE, PASSWORD, RESCUE, REBOOT, HARD_REBOOT, SHARE_IP,
* SHARE_IP_NO_CONFIG, DELETE_IP, and UNKNOWN. The Cloud Servers provisioning algorithm has an
* anti-affinity property that attempts to spread out customer VMs across hosts. Under certain
* situations, VMs from the same customer may be placed on the same host. hostId represents the
* host your cloud server runs on and can be used to determine this scenario if it's relevant to
* your application. Note: hostId is unique PER ACCOUNT and is not globally unique.
*/
@GET
@ResponseParser(ParseServerListFromGsonResponse.class)
@Query(key = "format", value = "json")
@Path("/servers/detail")
List<Server> listServerDetails();
}

View File

@ -0,0 +1,39 @@
/**
*
* Copyright (C) 2009 Global Cloud Specialists, Inc. <info@globalcloudspecialists.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.rackspace.cloudservers;
import org.jclouds.cloud.CloudContext;
/**
* Represents an authenticated context to Cloud Servers.
*
* @see <a href="http://docs.rackspacecloud.com/servers/api/cs-devguide-latest.pdf" />
* @see CloudServersConnection
* @see CloudContext
* @author Adrian Cole
*
*/
public interface CloudServersContext extends CloudContext<CloudServersConnection> {
}

View File

@ -0,0 +1,85 @@
/**
*
* Copyright (C) 2009 Global Cloud Specialists, Inc. <info@globalcloudspecialists.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.rackspace.cloudservers;
import java.util.List;
import java.util.Properties;
import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule;
import org.jclouds.logging.jdk.config.JDKLoggingModule;
import org.jclouds.rackspace.RackspaceContextBuilder;
import org.jclouds.rackspace.cloudservers.config.RestCloudServersConnectionModule;
import com.google.inject.Injector;
import com.google.inject.Module;
/**
* Creates {@link CloudServersContext} or {@link Injector} 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 CloudServersContext
*/
public class CloudServersContextBuilder extends
RackspaceContextBuilder<CloudServersConnection, CloudServersContext> {
public CloudServersContextBuilder(Properties props) {
super(props);
}
public static CloudServersContextBuilder newBuilder(String id, String secret) {
Properties properties = new Properties();
CloudServersContextBuilder builder = new CloudServersContextBuilder(properties);
builder.authenticate(id, secret);
return builder;
}
protected void addConnectionModule(List<Module> modules) {
super.addConnectionModule(modules);
modules.add(new RestCloudServersConnectionModule());
}
@Override
protected void addContextModule(List<Module> modules) {
//TODO
}
@Override
protected void addParserModule(List<Module> modules) {
//TODO
}
@Override
public CloudServersContext buildContext() {
return buildInjector().getInstance(CloudServersContext.class);
}
}

View File

@ -0,0 +1,61 @@
/**
*
* Copyright (C) 2009 Global Cloud Specialists, Inc. <info@globalcloudspecialists.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.rackspace.cloudservers.config;
import java.net.URI;
import org.jclouds.cloud.ConfiguresCloudConnection;
import org.jclouds.http.RequiresHttp;
import org.jclouds.rackspace.Server;
import org.jclouds.rackspace.cloudservers.CloudServersConnection;
import org.jclouds.rackspace.cloudservers.CloudServersContext;
import org.jclouds.rackspace.cloudservers.internal.GuiceCloudServersContext;
import org.jclouds.rest.RestClientFactory;
import com.google.inject.AbstractModule;
import com.google.inject.Provides;
import com.google.inject.Singleton;
/**
* Configures the Cloud Servers connection, including logging and http transport.
*
* @author Adrian Cole
*/
@ConfiguresCloudConnection
@RequiresHttp
public class RestCloudServersConnectionModule extends AbstractModule {
@Override
protected void configure() {
bind(CloudServersContext.class).to(GuiceCloudServersContext.class);
}
@Provides
@Singleton
protected CloudServersConnection provideConnection(@Server URI authenticationUri,
RestClientFactory factory) {
return factory.create(authenticationUri, CloudServersConnection.class);
}
}

View File

@ -0,0 +1,53 @@
/**
*
* Copyright (C) 2009 Global Cloud Specialists, Inc. <info@globalcloudspecialists.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.rackspace.cloudservers.domain;
/**
*
* @author Adrian Cole
*/
public class AbsoluteLimit {
protected String name;
protected int value;
public String getName() {
return name;
}
public void setName(String value) {
this.name = value;
}
public int getValue() {
return value;
}
public void setValue(int value) {
this.value = value;
}
}

View File

@ -0,0 +1,32 @@
/**
*
* Copyright (C) 2009 Global Cloud Specialists, Inc. <info@globalcloudspecialists.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.rackspace.cloudservers.domain;
/**
*
* @author Adrian Cole
*/
public enum Action {
CONFIRM_RESIZE, REBOOT, REBUILD, RESIZE, REVERT_RESIZE
}

View File

@ -0,0 +1,99 @@
/**
*
* Copyright (C) 2009 Global Cloud Specialists, Inc. <info@globalcloudspecialists.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.rackspace.cloudservers.domain;
import java.net.InetAddress;
import java.util.List;
import com.google.gson.annotations.SerializedName;
import com.google.inject.internal.Lists;
public class Addresses {
@SerializedName("public")
private List<InetAddress> publicAddresses = Lists.newArrayList();
@SerializedName("private")
private List<InetAddress> privateAddresses = Lists.newArrayList();
public Addresses() {
}
public Addresses(List<InetAddress> publicAddresses, List<InetAddress> privateAddresses) {
this.publicAddresses = publicAddresses;
this.privateAddresses = privateAddresses;
}
public void setPublicAddresses(List<InetAddress> publicAddresses) {
this.publicAddresses = publicAddresses;
}
public List<InetAddress> getPublicAddresses() {
return publicAddresses;
}
public void setPrivateAddresses(List<InetAddress> privateAddresses) {
this.privateAddresses = privateAddresses;
}
public List<InetAddress> getPrivateAddresses() {
return privateAddresses;
}
@Override
public String toString() {
return "Addresses [privateAddresses=" + privateAddresses + ", publicAddresses="
+ publicAddresses + "]";
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((privateAddresses == null) ? 0 : privateAddresses.hashCode());
result = prime * result + ((publicAddresses == null) ? 0 : publicAddresses.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Addresses other = (Addresses) obj;
if (privateAddresses == null) {
if (other.privateAddresses != null)
return false;
} else if (!privateAddresses.equals(other.privateAddresses))
return false;
if (publicAddresses == null) {
if (other.publicAddresses != null)
return false;
} else if (!publicAddresses.equals(other.publicAddresses))
return false;
return true;
}
}

View File

@ -0,0 +1,34 @@
/**
*
* Copyright (C) 2009 Global Cloud Specialists, Inc. <info@globalcloudspecialists.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.rackspace.cloudservers.domain;
public class BackupOrResizeInProgressError
extends CloudServersError
{
}

View File

@ -0,0 +1,55 @@
/**
*
* Copyright (C) 2009 Global Cloud Specialists, Inc. <info@globalcloudspecialists.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.rackspace.cloudservers.domain;
public class BackupSchedule {
protected DailyBackup daily;
protected boolean enabled;
protected String weekly;
public DailyBackup getDaily() {
return daily;
}
public void setDaily(DailyBackup value) {
this.daily = value;
}
public boolean isEnabled() {
return enabled;
}
public void setEnabled(boolean value) {
this.enabled = value;
}
public String getWeekly() {
return weekly;
}
public void setWeekly(String value) {
this.weekly = value;
}
}

View File

@ -0,0 +1,33 @@
/**
*
* Copyright (C) 2009 Global Cloud Specialists, Inc. <info@globalcloudspecialists.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.rackspace.cloudservers.domain;
public class BadMediaTypeError
extends CloudServersError
{
}

View File

@ -0,0 +1,34 @@
/**
*
* Copyright (C) 2009 Global Cloud Specialists, Inc. <info@globalcloudspecialists.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.rackspace.cloudservers.domain;
public class BadMethodError
extends CloudServersError
{
}

View File

@ -0,0 +1,28 @@
/**
*
* Copyright (C) 2009 Global Cloud Specialists, Inc. <info@globalcloudspecialists.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.rackspace.cloudservers.domain;
public class BadRequestError extends CloudServersError {
}

View File

@ -0,0 +1,28 @@
/**
*
* Copyright (C) 2009 Global Cloud Specialists, Inc. <info@globalcloudspecialists.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.rackspace.cloudservers.domain;
public class BuildInProgressError extends CloudServersError {
}

View File

@ -0,0 +1,58 @@
/**
*
* Copyright (C) 2009 Global Cloud Specialists, Inc. <info@globalcloudspecialists.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.rackspace.cloudservers.domain;
public class CloudServersError {
private String message;
private String details;
private int code;
public String getMessage() {
return message;
}
public void setMessage(String value) {
this.message = value;
}
public String getDetails() {
return details;
}
public void setDetails(String value) {
this.details = value;
}
public int getCode() {
return code;
}
public void setCode(int value) {
this.code = value;
}
}

View File

@ -0,0 +1,51 @@
/**
*
* Copyright (C) 2009 Global Cloud Specialists, Inc. <info@globalcloudspecialists.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.rackspace.cloudservers.domain;
public enum DailyBackup {
DISABLED,
H_0000_0200,
H_0200_0400,
H_0400_0600,
H_0600_0800,
H_0800_1000,
H_1000_1200,
H_1200_1400,
H_1400_1600,
H_1600_1800,
H_1800_2000,
H_2000_2200,
H_2200_0000;
public String value() {
return name();
}
public static DailyBackup fromValue(String v) {
return valueOf(v);
}
}

View File

@ -0,0 +1,47 @@
/**
*
* Copyright (C) 2009 Global Cloud Specialists, Inc. <info@globalcloudspecialists.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.rackspace.cloudservers.domain;
public class File {
private byte[] value;
private String path;
public byte[] getValue() {
return value;
}
public void setValue(byte[] value) {
this.value = ((byte[]) value);
}
public String getPath() {
return path;
}
public void setPath(String value) {
this.path = value;
}
}

View File

@ -0,0 +1,72 @@
/**
*
* Copyright (C) 2009 Global Cloud Specialists, Inc. <info@globalcloudspecialists.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.rackspace.cloudservers.domain;
public class Flavor {
public Flavor(int id, String name) {
super();
this.id = id;
this.name = name;
}
protected Integer disk;
protected int id;
protected String name;
protected Integer ram;
public Integer getDisk() {
return disk;
}
public void setDisk(Integer value) {
this.disk = value;
}
public int getId() {
return id;
}
public void setId(int value) {
this.id = value;
}
public String getName() {
return name;
}
public void setName(String value) {
this.name = value;
}
public Integer getRam() {
return ram;
}
public void setRam(Integer value) {
this.ram = value;
}
}

View File

@ -0,0 +1,98 @@
/**
*
* Copyright (C) 2009 Global Cloud Specialists, Inc. <info@globalcloudspecialists.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.rackspace.cloudservers.domain;
import org.joda.time.DateTime;
public class Image {
private DateTime created;
private Integer id;
private String name;
private Integer progress;
private Integer serverId;
private ImageStatus status;
private DateTime updated;
public Image(String name) {
this.setName(name);
}
public void setCreated(DateTime created) {
this.created = created;
}
public DateTime getCreated() {
return created;
}
public void setId(Integer id) {
this.id = id;
}
public Integer getId() {
return id;
}
public void setName(String name) {
this.name = name;
}
public String getName() {
return name;
}
public void setProgress(Integer progress) {
this.progress = progress;
}
public Integer getProgress() {
return progress;
}
public void setServerId(Integer serverId) {
this.serverId = serverId;
}
public Integer getServerId() {
return serverId;
}
public void setStatus(ImageStatus status) {
this.status = status;
}
public ImageStatus getStatus() {
return status;
}
public void setUpdated(DateTime updated) {
this.updated = updated;
}
public DateTime getUpdated() {
return updated;
}
}

View File

@ -0,0 +1,45 @@
/**
*
* Copyright (C) 2009 Global Cloud Specialists, Inc. <info@globalcloudspecialists.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.rackspace.cloudservers.domain;
public enum ImageStatus {
UNKNOWN,
ACTIVE,
SAVING,
PREPARING,
QUEUED,
FAILED;
public String value() {
return name();
}
public static ImageStatus fromValue(String v) {
return valueOf(v);
}
}

View File

@ -0,0 +1,28 @@
/**
*
* Copyright (C) 2009 Global Cloud Specialists, Inc. <info@globalcloudspecialists.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.rackspace.cloudservers.domain;
public class ItemNotFoundError extends CloudServersError {
}

View File

@ -0,0 +1,51 @@
/**
*
* Copyright (C) 2009 Global Cloud Specialists, Inc. <info@globalcloudspecialists.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.rackspace.cloudservers.domain;
import java.util.List;
import com.google.inject.internal.Lists;
public class Limits {
private List<RateLimit> rate = Lists.newArrayList();
private List<AbsoluteLimit> absolute = Lists.newArrayList();
public void setRate(List<RateLimit> rate) {
this.rate = rate;
}
public List<RateLimit> getRate() {
return rate;
}
public void setAbsolute(List<AbsoluteLimit> absolute) {
this.absolute = absolute;
}
public List<AbsoluteLimit> getAbsolute() {
return absolute;
}
}

View File

@ -0,0 +1,28 @@
/**
*
* Copyright (C) 2009 Global Cloud Specialists, Inc. <info@globalcloudspecialists.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.rackspace.cloudservers.domain;
public class NotImplementedError extends CloudServersError {
}

View File

@ -0,0 +1,40 @@
/**
*
* Copyright (C) 2009 Global Cloud Specialists, Inc. <info@globalcloudspecialists.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.rackspace.cloudservers.domain;
import org.joda.time.DateTime;
public class OverLimitError extends CloudServersError {
private DateTime retryAfter;
public void setRetryAfter(DateTime retryAfter) {
this.retryAfter = retryAfter;
}
public DateTime getRetryAfter() {
return retryAfter;
}
}

View File

@ -0,0 +1,77 @@
/**
*
* Copyright (C) 2009 Global Cloud Specialists, Inc. <info@globalcloudspecialists.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.rackspace.cloudservers.domain;
import org.jclouds.http.HttpMethod;
public class RateLimit {
private final String uri;
private final String regex;
private final int remaining;
private final long resetTime;
private final RateLimitUnit unit;
private final int value;
private final HttpMethod verb;
public RateLimit(String uri, String regex, int remaining, long resetTime, RateLimitUnit unit,
int value, HttpMethod verb) {
this.uri = uri;
this.regex = regex;
this.remaining = remaining;
this.resetTime = resetTime;
this.unit = unit;
this.value = value;
this.verb = verb;
}
public String getUri() {
return uri;
}
public String getRegex() {
return regex;
}
public int getRemaining() {
return remaining;
}
public long getResetTime() {
return resetTime;
}
public RateLimitUnit getUnit() {
return unit;
}
public int getValue() {
return value;
}
public HttpMethod getVerb() {
return verb;
}
}

View File

@ -0,0 +1,38 @@
/**
*
* Copyright (C) 2009 Global Cloud Specialists, Inc. <info@globalcloudspecialists.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.rackspace.cloudservers.domain;
public enum RateLimitUnit {
MINUTE, HOUR, DAY;
public String value() {
return name();
}
public static RateLimitUnit fromValue(String v) {
return valueOf(v);
}
}

View File

@ -0,0 +1,38 @@
/**
*
* Copyright (C) 2009 Global Cloud Specialists, Inc. <info@globalcloudspecialists.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.rackspace.cloudservers.domain;
public enum RebootType {
HARD, SOFT;
public String value() {
return name();
}
public static RebootType fromValue(String v) {
return valueOf(v);
}
}

View File

@ -0,0 +1,28 @@
/**
*
* Copyright (C) 2009 Global Cloud Specialists, Inc. <info@globalcloudspecialists.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.rackspace.cloudservers.domain;
public class RescueModeInUseError extends CloudServersError {
}

View File

@ -0,0 +1,28 @@
/**
*
* Copyright (C) 2009 Global Cloud Specialists, Inc. <info@globalcloudspecialists.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.rackspace.cloudservers.domain;
public class ResizeNotAllowedError extends CloudServersError {
}

View File

@ -0,0 +1,246 @@
/**
*
* Copyright (C) 2009 Global Cloud Specialists, Inc. <info@globalcloudspecialists.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.rackspace.cloudservers.domain;
import java.util.List;
import java.util.Map;
import com.google.inject.internal.Lists;
import com.google.inject.internal.Maps;
public class Server {
private int id;
private String name;
private Map<String, String> metadata = Maps.newHashMap();
private List<File> personality = Lists.newArrayList();
private Addresses addresses;
private String adminPass;
private Integer flavorId;
private String hostId;
private Integer imageId;
private Integer progress;
private Integer sharedIpGroupId;
private ServerStatus status;
public Server() {
}
public Server(int id, String name) {
this.id = id;
this.name = name;
}
public void setMetadata(Map<String, String> metadata) {
this.metadata = metadata;
}
public Map<String, String> getMetadata() {
return metadata;
}
public void setAddresses(Addresses addresses) {
this.addresses = addresses;
}
public Addresses getAddresses() {
return addresses;
}
public void setPersonality(List<File> personality) {
this.personality = personality;
}
public List<File> getPersonality() {
return personality;
}
public void setAdminPass(String adminPass) {
this.adminPass = adminPass;
}
public String getAdminPass() {
return adminPass;
}
public void setFlavorId(Integer flavorId) {
this.flavorId = flavorId;
}
public Integer getFlavorId() {
return flavorId;
}
public void setHostId(String hostId) {
this.hostId = hostId;
}
public String getHostId() {
return hostId;
}
public int getId() {
return id;
}
public void setImageId(Integer imageId) {
this.imageId = imageId;
}
public Integer getImageId() {
return imageId;
}
public String getName() {
return name;
}
public void setProgress(Integer progress) {
this.progress = progress;
}
public Integer getProgress() {
return progress;
}
public void setSharedIpGroupId(Integer sharedIpGroupId) {
this.sharedIpGroupId = sharedIpGroupId;
}
public Integer getSharedIpGroupId() {
return sharedIpGroupId;
}
public void setStatus(ServerStatus status) {
this.status = status;
}
public ServerStatus getStatus() {
return status;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((addresses == null) ? 0 : addresses.hashCode());
result = prime * result + ((adminPass == null) ? 0 : adminPass.hashCode());
result = prime * result + ((flavorId == null) ? 0 : flavorId.hashCode());
result = prime * result + ((hostId == null) ? 0 : hostId.hashCode());
result = prime * result + id;
result = prime * result + ((imageId == null) ? 0 : imageId.hashCode());
result = prime * result + ((metadata == null) ? 0 : metadata.hashCode());
result = prime * result + ((getName() == null) ? 0 : getName().hashCode());
result = prime * result + ((personality == null) ? 0 : personality.hashCode());
result = prime * result + ((progress == null) ? 0 : progress.hashCode());
result = prime * result + ((sharedIpGroupId == null) ? 0 : sharedIpGroupId.hashCode());
result = prime * result + ((status == null) ? 0 : status.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Server other = (Server) obj;
if (addresses == null) {
if (other.addresses != null)
return false;
} else if (!addresses.equals(other.addresses))
return false;
if (adminPass == null) {
if (other.adminPass != null)
return false;
} else if (!adminPass.equals(other.adminPass))
return false;
if (flavorId == null) {
if (other.flavorId != null)
return false;
} else if (!flavorId.equals(other.flavorId))
return false;
if (hostId == null) {
if (other.hostId != null)
return false;
} else if (!hostId.equals(other.hostId))
return false;
if (id != other.id)
return false;
if (imageId == null) {
if (other.imageId != null)
return false;
} else if (!imageId.equals(other.imageId))
return false;
if (metadata == null) {
if (other.metadata != null)
return false;
} else if (!metadata.equals(other.metadata))
return false;
if (getName() == null) {
if (other.getName() != null)
return false;
} else if (!getName().equals(other.getName()))
return false;
if (personality == null) {
if (other.personality != null)
return false;
} else if (!personality.equals(other.personality))
return false;
if (progress == null) {
if (other.progress != null)
return false;
} else if (!progress.equals(other.progress))
return false;
if (sharedIpGroupId == null) {
if (other.sharedIpGroupId != null)
return false;
} else if (!sharedIpGroupId.equals(other.sharedIpGroupId))
return false;
if (status == null) {
if (other.status != null)
return false;
} else if (!status.equals(other.status))
return false;
return true;
}
@Override
public String toString() {
return "Server [addresses=" + addresses + ", adminPass=" + adminPass + ", flavorId="
+ flavorId + ", hostId=" + hostId + ", id=" + id + ", imageId=" + imageId
+ ", metadata=" + metadata + ", name=" + getName() + ", personality=" + personality
+ ", progress=" + progress + ", sharedIpGroupId=" + sharedIpGroupId + ", status="
+ status + "]";
}
public void setName(String name) {
this.name = name;
}
}

View File

@ -0,0 +1,28 @@
/**
*
* Copyright (C) 2009 Global Cloud Specialists, Inc. <info@globalcloudspecialists.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.rackspace.cloudservers.domain;
public class ServerCapacityUnavailableError extends CloudServersError {
}

View File

@ -0,0 +1,38 @@
/**
*
* Copyright (C) 2009 Global Cloud Specialists, Inc. <info@globalcloudspecialists.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.rackspace.cloudservers.domain;
public enum ServerStatus {
ACTIVE, SUSPENDED, DELETED, QUEUE_RESIZE, PREP_RESIZE, RESIZE, VERIFY_RESIZE, QUEUE_MOVE, PREP_MOVE, MOVE, VERIFY_MOVE, RESCUE, ERROR, BUILD, RESTORING, PASSWORD, REBUILD, DELETE_IP, SHARE_IP_NO_CONFIG, SHARE_IP, REBOOT, HARD_REBOOT, UNKNOWN;
public String value() {
return name();
}
public static ServerStatus fromValue(String v) {
return valueOf(v);
}
}

View File

@ -0,0 +1,28 @@
/**
*
* Copyright (C) 2009 Global Cloud Specialists, Inc. <info@globalcloudspecialists.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.rackspace.cloudservers.domain;
public class ServiceUnavailableError extends CloudServersError {
}

View File

@ -0,0 +1,47 @@
/**
*
* Copyright (C) 2009 Global Cloud Specialists, Inc. <info@globalcloudspecialists.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.rackspace.cloudservers.domain;
public class ShareIp {
private boolean configureServer;
private int sharedIpGroupId;
public void setConfigureServer(boolean configureServer) {
this.configureServer = configureServer;
}
public boolean isConfigureServer() {
return configureServer;
}
public void setSharedIpGroupId(int sharedIpGroupId) {
this.sharedIpGroupId = sharedIpGroupId;
}
public int getSharedIpGroupId() {
return sharedIpGroupId;
}
}

View File

@ -0,0 +1,69 @@
/**
*
* Copyright (C) 2009 Global Cloud Specialists, Inc. <info@globalcloudspecialists.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.rackspace.cloudservers.domain;
import java.util.List;
import com.google.inject.internal.Lists;
public class SharedIpGroup {
private int server;
private List<Integer> servers = Lists.newArrayList();
private Integer id;
private String name;
public void setServer(int server) {
this.server = server;
}
public int getServer() {
return server;
}
public void setServers(List<Integer> servers) {
this.servers = servers;
}
public List<Integer> getServers() {
return servers;
}
public void setId(Integer id) {
this.id = id;
}
public Integer getId() {
return id;
}
public void setName(String name) {
this.name = name;
}
public String getName() {
return name;
}
}

View File

@ -0,0 +1,28 @@
/**
*
* Copyright (C) 2009 Global Cloud Specialists, Inc. <info@globalcloudspecialists.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.rackspace.cloudservers.domain;
public class UnauthorizedError extends CloudServersError {
}

View File

@ -0,0 +1,64 @@
/**
*
* Copyright (C) 2009 Global Cloud Specialists, Inc. <info@globalcloudspecialists.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.rackspace.cloudservers.domain;
public class Version {
private String docURL;
private String id = "v1.0";
private VersionStatus status;
private String wadl;
public void setDocURL(String docURL) {
this.docURL = docURL;
}
public String getDocURL() {
return docURL;
}
public void setId(String id) {
this.id = id;
}
public String getId() {
return id;
}
public void setStatus(VersionStatus status) {
this.status = status;
}
public VersionStatus getStatus() {
return status;
}
public void setWadl(String wadl) {
this.wadl = wadl;
}
public String getWadl() {
return wadl;
}
}

View File

@ -0,0 +1,38 @@
/**
*
* Copyright (C) 2009 Global Cloud Specialists, Inc. <info@globalcloudspecialists.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.rackspace.cloudservers.domain;
public enum VersionStatus {
BETA, CURRENT, DEPRECATED;
public String value() {
return name();
}
public static VersionStatus fromValue(String v) {
return valueOf(v);
}
}

View File

@ -0,0 +1,62 @@
/**
*
* Copyright (C) 2009 Global Cloud Specialists, Inc. <info@globalcloudspecialists.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.rackspace.cloudservers.functions;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.util.List;
import org.jclouds.http.functions.ParseJson;
import org.jclouds.rackspace.cloudservers.domain.Server;
import com.google.gson.Gson;
import com.google.inject.Inject;
import com.google.inject.internal.Lists;
/**
* This parses {@link Server} from a gson string.
*
* @author Adrian Cole
*/
public class ParseServerListFromGsonResponse extends ParseJson<List<Server>> {
@Inject
public ParseServerListFromGsonResponse(Gson gson) {
super(gson);
}
private static class ServerListResponse {
List<Server> servers = Lists.newArrayList();
}
public List<Server> apply(InputStream stream) {
try {
return gson.fromJson(new InputStreamReader(stream, "UTF-8"), ServerListResponse.class).servers;
} catch (UnsupportedEncodingException e) {
throw new RuntimeException("jclouds requires UTF-8 encoding", e);
}
}
}

View File

@ -0,0 +1,77 @@
/**
*
* Copyright (C) 2009 Global Cloud Specialists, Inc. <info@globalcloudspecialists.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.rackspace.cloudservers.internal;
import java.io.IOException;
import javax.annotation.Resource;
import org.jclouds.lifecycle.Closer;
import org.jclouds.logging.Logger;
import org.jclouds.rackspace.cloudservers.CloudServersConnection;
import org.jclouds.rackspace.cloudservers.CloudServersContext;
import com.google.inject.Inject;
import com.google.inject.Injector;
/**
* Uses a Guice Injector to configure the objects served by CloudServersContext methods.
*
* @author Adrian Cole
* @see Injector
*/
public class GuiceCloudServersContext implements CloudServersContext {
@Resource
private Logger logger = Logger.NULL;
private final Injector injector;
private final Closer closer;
@Inject
private GuiceCloudServersContext(Injector injector, Closer closer) {
this.injector = injector;
this.closer = closer;
}
/**
* {@inheritDoc}
*/
public CloudServersConnection getConnection() {
return injector.getInstance(CloudServersConnection.class);
}
/**
* {@inheritDoc}
*
* @see Closer
*/
public void close() {
try {
closer.close();
} catch (IOException e) {
logger.error(e, "error closing content");
}
}
}

View File

@ -0,0 +1,68 @@
/**
*
* Copyright (C) 2009 Global Cloud Specialists, Inc. <info@globalcloudspecialists.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.rackspace.cloudservers;
import static org.jclouds.rackspace.reference.RackspaceConstants.PROPERTY_RACKSPACE_KEY;
import static org.jclouds.rackspace.reference.RackspaceConstants.PROPERTY_RACKSPACE_USER;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertTrue;
import java.util.List;
import org.jclouds.rackspace.cloudservers.domain.Server;
import org.testng.annotations.Test;
/**
* Tests behavior of {@code CloudServersConnection}
*
* @author Adrian Cole
*/
@Test(groups = "live", testName = "cloudservers.CloudServersConnectionLiveTest")
public class CloudServersConnectionLiveTest {
protected static final String sysRackspaceUser = System.getProperty(PROPERTY_RACKSPACE_USER);
protected static final String sysRackspaceKey = System.getProperty(PROPERTY_RACKSPACE_KEY);
@Test
public void testListServers() throws Exception {
CloudServersConnection connection = CloudServersContextBuilder.newBuilder(sysRackspaceUser,
sysRackspaceKey).withJsonDebug().buildContext().getConnection();
List<Server> response = connection.listServers();
assertNotNull(response);
long initialContainerCount = response.size();
assertTrue(initialContainerCount >= 0);
}
@Test
public void testListServersDetail() throws Exception {
CloudServersConnection connection = CloudServersContextBuilder.newBuilder(sysRackspaceUser,
sysRackspaceKey).withJsonDebug().buildContext().getConnection();
List<Server> response = connection.listServerDetails();
assertNotNull(response);
long initialContainerCount = response.size();
assertTrue(initialContainerCount >= 0);
}
}

View File

@ -0,0 +1,108 @@
/**
*
* Copyright (C) 2009 Global Cloud Specialists, Inc. <info@globalcloudspecialists.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.rackspace.cloudservers;
import static org.testng.Assert.assertEquals;
import java.lang.reflect.Method;
import java.net.URI;
import org.jclouds.concurrent.WithinThreadExecutorService;
import org.jclouds.concurrent.config.ExecutorServiceModule;
import org.jclouds.http.HttpMethod;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule;
import org.jclouds.rackspace.Authentication;
import org.jclouds.rackspace.cloudservers.functions.ParseServerListFromGsonResponse;
import org.jclouds.rest.JaxrsAnnotationProcessor;
import org.jclouds.rest.config.JaxrsModule;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import com.google.inject.AbstractModule;
import com.google.inject.Guice;
import com.google.inject.Provides;
/**
* Tests behavior of {@code CloudServersConnection}
*
* @author Adrian Cole
*/
@Test(groups = "unit", testName = "cloudservers.CloudServersConnectionTest")
public class CloudServersConnectionTest {
JaxrsAnnotationProcessor.Factory factory;
public void testListServers() throws SecurityException, NoSuchMethodException {
Method method = CloudServersConnection.class.getMethod("listServers");
URI endpoint = URI.create("http://localhost");
HttpRequest httpMethod = factory.create(CloudServersConnection.class).createRequest(endpoint,
method, new Object[] {});
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
assertEquals(httpMethod.getEndpoint().getPath(), "/servers");
assertEquals(httpMethod.getEndpoint().getQuery(), "format=json");
assertEquals(httpMethod.getMethod(), HttpMethod.GET);
assertEquals(httpMethod.getHeaders().size(), 0);
factory.create(CloudServersConnection.class);
assertEquals(JaxrsAnnotationProcessor.getParserOrThrowException(method),
ParseServerListFromGsonResponse.class);
}
public void testListServersDetail() throws SecurityException, NoSuchMethodException {
Method method = CloudServersConnection.class.getMethod("listServerDetails");
URI endpoint = URI.create("http://localhost");
HttpRequest httpMethod = factory.create(CloudServersConnection.class).createRequest(endpoint,
method, new Object[] {});
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
assertEquals(httpMethod.getEndpoint().getPath(), "/servers/detail");
assertEquals(httpMethod.getEndpoint().getQuery(), "format=json");
assertEquals(httpMethod.getMethod(), HttpMethod.GET);
assertEquals(httpMethod.getHeaders().size(), 0);
factory.create(CloudServersConnection.class);
assertEquals(JaxrsAnnotationProcessor.getParserOrThrowException(method),
ParseServerListFromGsonResponse.class);
}
@BeforeClass
void setupFactory() {
factory = Guice.createInjector(new AbstractModule() {
@Override
protected void configure() {
bind(URI.class).toInstance(URI.create("http://localhost:8080"));
}
@SuppressWarnings("unused")
@Provides
@Authentication
public String getAuthToken() {
return "testtoken";
}
}, new JaxrsModule(), new ExecutorServiceModule(new WithinThreadExecutorService()),
new JavaUrlHttpCommandExecutorServiceModule()).getInstance(
JaxrsAnnotationProcessor.Factory.class);
}
}

View File

@ -0,0 +1,106 @@
/**
*
* Copyright (C) 2009 Global Cloud Specialists, Inc. <info@globalcloudspecialists.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.rackspace.cloudservers.functions;
import static org.testng.Assert.assertEquals;
import java.io.InputStream;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.List;
import org.jclouds.http.functions.config.ParserModule;
import org.jclouds.rackspace.cloudservers.domain.Addresses;
import org.jclouds.rackspace.cloudservers.domain.Server;
import org.jclouds.rackspace.cloudservers.domain.ServerStatus;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;
import com.google.gson.Gson;
import com.google.inject.Guice;
import com.google.inject.Injector;
/**
* Tests behavior of {@code ParseServerListFromGsonResponseTest}
*
* @author Adrian Cole
*/
@Test(groups = "unit", testName = "cloudservers.ParseServerListFromGsonResponseTest")
public class ParseServerListFromGsonResponseTest {
Injector i = Guice.createInjector(new ParserModule());
public void testApplyInputStream() {
InputStream is = getClass().getResourceAsStream("/test_list_servers.json");
List<Server> expects = ImmutableList.of(new Server(1234, "sample-server"), new Server(5678,
"sample-server2"));
ParseServerListFromGsonResponse parser = new ParseServerListFromGsonResponse(i
.getInstance(Gson.class));
assertEquals(parser.apply(is), expects);
}
public void testApplyInputStreamDetails() throws UnknownHostException {
InputStream is = getClass().getResourceAsStream("/test_list_servers_detail.json");
ParseServerListFromGsonResponse parser = new ParseServerListFromGsonResponse(i
.getInstance(Gson.class));
List<Server> response = parser.apply(is);
assertEquals(response.get(0).getId(), 1234);
assertEquals(response.get(0).getName(), "sample-server");
assertEquals(response.get(0).getImageId(), new Integer(2));
assertEquals(response.get(0).getFlavorId(), new Integer(1));
assertEquals(response.get(0).getHostId(), "e4d909c290d0fb1ca068ffaddf22cbd0");
assertEquals(response.get(0).getStatus(), ServerStatus.BUILD);
assertEquals(response.get(0).getProgress(), new Integer(60));
List<InetAddress> publicAddresses = Lists.newArrayList(InetAddress.getByName("67.23.10.132"),
InetAddress.getByName("67.23.10.131"));
List<InetAddress> privateAddresses = Lists
.newArrayList(InetAddress.getByName("10.176.42.16"));
Addresses addresses1 = new Addresses(publicAddresses, privateAddresses);
assertEquals(response.get(0).getAddresses(), addresses1);
assertEquals(response.get(0).getMetadata(), ImmutableMap.of("Server Label", "Web Head 1",
"Image Version", "2.1"));
assertEquals(response.get(1).getId(), 5678);
assertEquals(response.get(1).getName(), "sample-server2");
assertEquals(response.get(1).getImageId(), new Integer(2));
assertEquals(response.get(1).getFlavorId(), new Integer(1));
assertEquals(response.get(1).getHostId(), "9e107d9d372bb6826bd81d3542a419d6");
assertEquals(response.get(1).getStatus(), ServerStatus.ACTIVE);
assertEquals(response.get(1).getProgress(), null);
List<InetAddress> publicAddresses2 = Lists
.newArrayList(InetAddress.getByName("67.23.10.133"));
List<InetAddress> privateAddresses2 = Lists.newArrayList(InetAddress
.getByName("10.176.42.17"));
Addresses addresses2 = new Addresses(publicAddresses2, privateAddresses2);
assertEquals(response.get(1).getAddresses(), addresses2);
assertEquals(response.get(1).getMetadata(), ImmutableMap.of("Server Label", "DB 1"));
}
}

View File

@ -0,0 +1,12 @@
{
"servers" : [
{
"id" : 1234,
"name" : "sample-server"
},
{
"id" : 5678,
"name" : "sample-server2"
}
]
}

View File

@ -0,0 +1,45 @@
{
"servers" : [
{
"id" : 1234,
"name" : "sample-server",
"imageId" : 2,
"flavorId" : 1,
"hostId" : "e4d909c290d0fb1ca068ffaddf22cbd0",
"status" : "BUILD",
"progress" : 60,
"addresses" : {
"public" : [
"67.23.10.132",
"67.23.10.131"
],
"private" : [
"10.176.42.16"
]
},
"metadata" : {
"Server Label" : "Web Head 1",
"Image Version" : "2.1"
}
},
{
"id" : 5678,
"name" : "sample-server2",
"imageId" : 2,
"flavorId" : 1,
"hostId" : "9e107d9d372bb6826bd81d3542a419d6",
"status" : "ACTIVE",
"addresses" : {
"public" : [
"67.23.10.133"
],
"private" : [
"10.176.42.17"
]
},
"metadata" : {
"Server Label" : "DB 1"
}
}
]
}

56
rackspace/cloudservers/pom.xml Executable file
View File

@ -0,0 +1,56 @@
<?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>
<artifactId>jclouds-rackspace-project</artifactId>
<groupId>org.jclouds</groupId>
<version>1.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>jclouds-cloudservers-project</artifactId>
<packaging>pom</packaging>
<name>jclouds cloudservers project</name>
<modules>
<module>core</module>
</modules>
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>jclouds-rackspace-core</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>jclouds-rackspace-core</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
</dependencies>
</project>

View File

@ -1,3 +1,26 @@
/**
*
* Copyright (C) 2009 Global Cloud Specialists, Inc. <info@globalcloudspecialists.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.rackspace.config;
import static org.jclouds.rackspace.reference.RackspaceConstants.PROPERTY_RACKSPACE_KEY;
@ -41,8 +64,7 @@ public class RackspaceAuthenticationModule extends AbstractModule {
@Singleton
protected AuthenticationResponse provideAuthenticationResponse(
@Authentication URI authenticationUri, RestClientFactory factory,
@Named(PROPERTY_RACKSPACE_USER) String user,
@Named(PROPERTY_RACKSPACE_KEY) String key) {
@Named(PROPERTY_RACKSPACE_USER) String user, @Named(PROPERTY_RACKSPACE_KEY) String key) {
return factory.create(authenticationUri, RackspaceAuthentication.class).authenticate(user,
key);
}
@ -50,8 +72,7 @@ public class RackspaceAuthenticationModule extends AbstractModule {
@Provides
@Authentication
protected String provideAuthenticationToken(@Authentication URI authenticationUri,
RestClientFactory factory,
@Named(PROPERTY_RACKSPACE_USER) String user,
RestClientFactory factory, @Named(PROPERTY_RACKSPACE_USER) String user,
@Named(PROPERTY_RACKSPACE_KEY) String key) {
return factory.create(authenticationUri, RackspaceAuthentication.class).authenticate(user,
key).getAuthToken();
@ -63,7 +84,7 @@ public class RackspaceAuthenticationModule extends AbstractModule {
protected URI provideStorageUrl(AuthenticationResponse response) {
return response.getStorageUrl();
}
@Provides
@Singleton
@Server

View File

@ -38,7 +38,7 @@ import com.google.inject.Provider;
import com.google.inject.Singleton;
/**
* Signs the Cloud Files request. This will update the Authentication Token before 24 hours is up.
* Signs the Rackspace request. This will update the Authentication Token before 24 hours is up.
*
* @author Adrian Cole
*
@ -56,8 +56,8 @@ public class AuthenticateRequest implements HttpRequestFilter {
private final AtomicLong trigger = new AtomicLong(0);
/**
* Start the time update service. Cloud Files clocks need to be 24 hours of the auth token. This
* is not performed per-request, as creation of the token is a slow, synchronized command.
* Start the time update service. Rackspace clocks need to be 24 hours of the auth token. This is
* not performed per-request, as creation of the token is a slow, synchronized command.
*/
synchronized void updateIfTimeOut() {
@ -68,7 +68,7 @@ public class AuthenticateRequest implements HttpRequestFilter {
}
// this is a hotspot when submitted concurrently, so be lazy.
// cloudfiles is ok with up to 23:59 off their time, so let's
// rackspace is ok with up to 23:59 off their time, so let's
// be as lazy as possible.
public String createNewToken() {
authToken.set(authTokenProvider.get());

View File

@ -1,3 +1,26 @@
/**
*
* Copyright (C) 2009 Global Cloud Specialists, Inc. <info@globalcloudspecialists.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.rackspace.reference;
/**

View File

@ -39,6 +39,7 @@
<modules>
<module>core</module>
<module>cloudfiles</module>
<module>cloudservers</module>
</modules>
<properties>
<jclouds.rackspace.user />