Issue #1106: remove deltacloud

This commit is contained in:
Adrian Cole 2012-12-29 10:51:53 -08:00
parent 194fb45ca7
commit f2364eab26
92 changed files with 0 additions and 7220 deletions

View File

@ -35,11 +35,6 @@
<artifactId>greenhousedata-element-vcloud</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.jclouds.api</groupId>
<artifactId>deltacloud</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.jclouds.provider</groupId>
<artifactId>aws-ec2</artifactId>

View File

@ -1,84 +0,0 @@
====
Licensed to jclouds, Inc. (jclouds) under one or more
contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. jclouds licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
====
jclouds binding to deltacloud requires a minimum server version of 0.1.0.
The identity and credential specified in jclouds will pass through deltacloud to
the backend, such as gogrid.
To install deltacloud, do the following:
* OS/X and jruby
# use homebrew or equiv to install jruby
* brew install jruby
* note testing took place w/ 1.6.0
# install and configure openssl to avoid "certificate verify failed" errors
# install and link openssl
* brew install openssl
* brew link openssl
# install jruby ssl
* jruby -S gem install jruby-openssl
# setup cert directory
* mkdir $HOME/certs
* curl -o $HOME/certs/cacert.pem http://curl.haxx.se/ca/cacert.pem
# rehash cert directory
* export SSL_CERT_DIR=$HOME/certs
* export SSL_CERT_FILE=$HOME/certs/cacert.pem
* c_rehash
# test
* jruby -ropen-uri -e 'p open("https://encrypted.google.com")'
* should see something like #<StringIO:0x5330cb4b>
# install specific version of rack that doesn't conflict with deltacloud
* jruby -S gem install rack --version 1.1.0
# install net-ssh
* jruby -S gem install net-ssh
# install deltacloud core
* jruby -S gem install deltacloud-core
To run a local deltacloud server, do the following:
* jruby
# export SSL_CERT_DIR=$HOME/certs
# export SSL_CERT_FILE=$HOME/certs/cacert.pem
# jruby -S deltacloudd -i mock
* or if you are running from a src tree: jruby -S ./server/bin/deltacloudd -i <driver>
Here are some notes about specific cloud providers
* terremark
# install fog gem
* jruby -S gem install fog
* rackspace
# install cloudfiles, cloudservers gem
* jruby -S gem install cloudservers
* jruby -S gem install cloudfiles
* ec2
* using jruby --1.8, 'gem install aws' will fail with ArrayIndexOutOfBoundsException per http://jira.codehaus.org/browse/JRUBY-5581
* using jruby --1.9, 'gem install aws' works, but running './server/bin/deltacloudd -i ec2' fails per http://jira.codehaus.org/browse/JRUBY-5529
# install i18n, aws gem
* jruby -S gem install i18n
* jruby -S gem install aws
Local Development of Delta
* jruby -S gem install rack-test cucumber
* What tests are available
* jruby -S rake -T
* server/tests/drivers
* specific tests to a particular driver
* Running tests
* jruby -S rake test

View File

@ -1,131 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to jclouds, Inc. (jclouds) under one or more
contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. jclouds licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
<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">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.jclouds</groupId>
<artifactId>jclouds-project</artifactId>
<version>1.6.0-SNAPSHOT</version>
<relativePath>../../project/pom.xml</relativePath>
</parent>
<groupId>org.jclouds.api</groupId>
<artifactId>deltacloud</artifactId>
<name>jclouds deltacloud core</name>
<description>jclouds components to access deltacloud</description>
<packaging>bundle</packaging>
<!-- bootstrapping: need to fetch the project POM -->
<repositories>
<repository>
<id>sonatype-nexus-snapshots</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<properties>
<test.deltacloud.endpoint>http://localhost:3001/api</test.deltacloud.endpoint>
<test.deltacloud.api-version>0.3.0</test.deltacloud.api-version>
<test.deltacloud.build-version></test.deltacloud.build-version>
<test.deltacloud.identity>mockuser</test.deltacloud.identity>
<test.deltacloud.credential>mockpassword</test.deltacloud.credential>
<test.deltacloud.template></test.deltacloud.template>
<jclouds.osgi.export>org.jclouds.deltacloud*;version="${project.version}"</jclouds.osgi.export>
<jclouds.osgi.import>
org.jclouds.compute.internal;version="${project.version}",
org.jclouds.rest.internal;version="${project.version}",
org.jclouds*;version="${project.version}",
*
</jclouds.osgi.import>
</properties>
<dependencies>
<dependency>
<groupId>org.jclouds</groupId>
<artifactId>jclouds-compute</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.jclouds</groupId>
<artifactId>jclouds-core</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jclouds</groupId>
<artifactId>jclouds-compute</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jclouds.driver</groupId>
<artifactId>jclouds-sshj</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jclouds.driver</groupId>
<artifactId>jclouds-log4j</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<profiles>
<profile>
<id>live</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<executions>
<execution>
<id>integration</id>
<phase>integration-test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<systemPropertyVariables>
<test.deltacloud.endpoint>${test.deltacloud.endpoint}</test.deltacloud.endpoint>
<test.deltacloud.api-version>${test.deltacloud.api-version}</test.deltacloud.api-version>
<test.deltacloud.build-version>${test.deltacloud.build-version}</test.deltacloud.build-version>
<test.deltacloud.identity>${test.deltacloud.identity}</test.deltacloud.identity>
<test.deltacloud.credential>${test.deltacloud.credential}</test.deltacloud.credential>
<test.deltacloud.template>${test.deltacloud.template}</test.deltacloud.template>
</systemPropertyVariables>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>

View File

@ -1,91 +0,0 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.deltacloud;
import java.net.URI;
import java.util.Properties;
import org.jclouds.apis.ApiMetadata;
import org.jclouds.compute.ComputeServiceContext;
import org.jclouds.deltacloud.compute.config.DeltacloudComputeServiceContextModule;
import org.jclouds.deltacloud.config.DeltacloudRestClientModule;
import org.jclouds.rest.RestContext;
import org.jclouds.rest.internal.BaseRestApiMetadata;
import com.google.common.collect.ImmutableSet;
import com.google.common.reflect.TypeToken;
import com.google.inject.Module;
/**
* Implementation of {@link ApiMetadata} for Apache Deltacloud API
*
* @author Adrian Cole
*/
public class DeltacloudApiMetadata extends BaseRestApiMetadata {
public static final TypeToken<RestContext<DeltacloudClient, DeltacloudAsyncClient>> CONTEXT_TOKEN = new TypeToken<RestContext<DeltacloudClient, DeltacloudAsyncClient>>() {
};
@Override
public Builder toBuilder() {
return new Builder().fromApiMetadata(this);
}
public DeltacloudApiMetadata() {
this(new Builder());
}
protected DeltacloudApiMetadata(Builder builder) {
super(builder);
}
public static Properties defaultProperties() {
return BaseRestApiMetadata.defaultProperties();
}
public static class Builder extends BaseRestApiMetadata.Builder {
protected Builder() {
super(DeltacloudClient.class, DeltacloudAsyncClient.class);
id("deltacloud")
.name("Apache Deltacloud API")
.identityName("Username")
.credentialName("Password")
.documentation(URI.create("http://deltacloud.apache.org/api.html"))
.version("0.3.0")
.defaultEndpoint("http://localhost:3001/api")
.defaultProperties(DeltacloudApiMetadata.defaultProperties())
.view(TypeToken.of(ComputeServiceContext.class))
.defaultModules(ImmutableSet.<Class<? extends Module>>of(DeltacloudRestClientModule.class, DeltacloudComputeServiceContextModule.class));
}
@Override
public DeltacloudApiMetadata build() {
return new DeltacloudApiMetadata(this);
}
@Override
public Builder fromApiMetadata(ApiMetadata in) {
super.fromApiMetadata(in);
return this;
}
}
}

View File

@ -1,179 +0,0 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.deltacloud;
import java.net.URI;
import java.util.Set;
import javax.ws.rs.Consumes;
import javax.ws.rs.FormParam;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.core.MediaType;
import org.jclouds.Fallbacks.EmptyMultimapOnNotFoundOr404;
import org.jclouds.Fallbacks.EmptySetOnNotFoundOr404;
import org.jclouds.Fallbacks.NullOnNotFoundOr404;
import org.jclouds.deltacloud.DeltacloudFallbacks.VoidOnRedirectedDelete;
import org.jclouds.deltacloud.collections.HardwareProfiles;
import org.jclouds.deltacloud.collections.Images;
import org.jclouds.deltacloud.collections.InstanceStates;
import org.jclouds.deltacloud.collections.Instances;
import org.jclouds.deltacloud.collections.Realms;
import org.jclouds.deltacloud.domain.DeltacloudCollection;
import org.jclouds.deltacloud.domain.HardwareProfile;
import org.jclouds.deltacloud.domain.Image;
import org.jclouds.deltacloud.domain.Instance;
import org.jclouds.deltacloud.domain.Instance.State;
import org.jclouds.deltacloud.domain.Realm;
import org.jclouds.deltacloud.domain.Transition;
import org.jclouds.deltacloud.options.CreateInstanceOptions;
import org.jclouds.deltacloud.xml.DeltacloudCollectionsHandler;
import org.jclouds.deltacloud.xml.HardwareProfileHandler;
import org.jclouds.deltacloud.xml.HardwareProfilesHandler;
import org.jclouds.deltacloud.xml.ImageHandler;
import org.jclouds.deltacloud.xml.ImagesHandler;
import org.jclouds.deltacloud.xml.InstanceHandler;
import org.jclouds.deltacloud.xml.InstanceStatesHandler;
import org.jclouds.deltacloud.xml.InstancesHandler;
import org.jclouds.deltacloud.xml.RealmHandler;
import org.jclouds.deltacloud.xml.RealmsHandler;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.filters.BasicAuthentication;
import org.jclouds.rest.annotations.Endpoint;
import org.jclouds.rest.annotations.EndpointParam;
import org.jclouds.rest.annotations.Fallback;
import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.XMLResponseParser;
import com.google.common.collect.Multimap;
import com.google.common.util.concurrent.ListenableFuture;
/**
* Provides asynchronous access to deltacloud via their REST API.
* <p/>
*
* @see DeltacloudClient
* @see <a href="TODO: insert URL of provider documentation" />
* @author Adrian Cole
*/
@RequestFilters(BasicAuthentication.class)
@Consumes(MediaType.APPLICATION_XML)
public interface DeltacloudAsyncClient {
/**
* @see DeltacloudClient#getCollections
*/
@GET
@Fallback(EmptySetOnNotFoundOr404.class)
@XMLResponseParser(DeltacloudCollectionsHandler.class)
ListenableFuture<Set<DeltacloudCollection>> getCollections();
/**
* @see DeltacloudClient#getInstanceStates
*/
@GET
@Endpoint(InstanceStates.class)
@Fallback(EmptyMultimapOnNotFoundOr404.class)
@XMLResponseParser(InstanceStatesHandler.class)
ListenableFuture<Multimap<State, Transition>> getInstanceStates();
/**
* @see DeltacloudClient#listRealms
*/
@GET
@Endpoint(Realms.class)
@Fallback(EmptySetOnNotFoundOr404.class)
@XMLResponseParser(RealmsHandler.class)
ListenableFuture<Set<Realm>> listRealms();
/**
* @see DeltacloudClient#getRealm
*/
@GET
@Fallback(NullOnNotFoundOr404.class)
@XMLResponseParser(RealmHandler.class)
ListenableFuture<Realm> getRealm(@EndpointParam URI realmHref);
/**
* @see DeltacloudClient#listImages
*/
@GET
@Endpoint(Images.class)
@Fallback(EmptySetOnNotFoundOr404.class)
@XMLResponseParser(ImagesHandler.class)
ListenableFuture<Set<Image>> listImages();
/**
* @see DeltacloudClient#getImage
*/
@GET
@Fallback(NullOnNotFoundOr404.class)
@XMLResponseParser(ImageHandler.class)
ListenableFuture<Image> getImage(@EndpointParam URI imageHref);
/**
* @see DeltacloudClient#listHardwareProfiles
*/
@GET
@Endpoint(HardwareProfiles.class)
@Fallback(EmptySetOnNotFoundOr404.class)
@XMLResponseParser(HardwareProfilesHandler.class)
ListenableFuture<Set<HardwareProfile>> listHardwareProfiles();
/**
* @see DeltacloudClient#getHardwareProfile
*/
@GET
@Fallback(NullOnNotFoundOr404.class)
@XMLResponseParser(HardwareProfileHandler.class)
ListenableFuture<HardwareProfile> getHardwareProfile(@EndpointParam URI profileHref);
/**
* @see DeltacloudClient#listInstances
*/
@GET
@Endpoint(Instances.class)
@Fallback(EmptySetOnNotFoundOr404.class)
@XMLResponseParser(InstancesHandler.class)
ListenableFuture<Set<Instance>> listInstances();
/**
* @see DeltacloudClient#getInstance
*/
@GET
@Fallback(NullOnNotFoundOr404.class)
@XMLResponseParser(InstanceHandler.class)
ListenableFuture<Instance> getInstance(@EndpointParam URI instanceHref);
/**
* @see DeltacloudClient#createInstance
*/
@POST
@Endpoint(Instances.class)
@XMLResponseParser(InstanceHandler.class)
ListenableFuture<Instance> createInstance(@FormParam("image_id") String imageId, CreateInstanceOptions... options);
/**
* @see DeltacloudClient#performInstanceAction
*/
@Fallback(VoidOnRedirectedDelete.class)
ListenableFuture<Void> performAction(HttpRequest action);
}

View File

@ -1,144 +0,0 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.deltacloud;
import java.net.URI;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import org.jclouds.concurrent.Timeout;
import org.jclouds.deltacloud.domain.DeltacloudCollection;
import org.jclouds.deltacloud.domain.HardwareProfile;
import org.jclouds.deltacloud.domain.Image;
import org.jclouds.deltacloud.domain.Instance;
import org.jclouds.deltacloud.domain.Realm;
import org.jclouds.deltacloud.domain.Transition;
import org.jclouds.deltacloud.domain.Instance.State;
import org.jclouds.deltacloud.options.CreateInstanceOptions;
import org.jclouds.http.HttpRequest;
import com.google.common.collect.Multimap;
/**
* Provides synchronous access to deltacloud.
* <p/>
*
* @see DeltacloudAsyncClient
* @see <a href="TODO: insert URL of deltacloud documentation" />
* @author Adrian Cole
*/
@Timeout(duration = 60, timeUnit = TimeUnit.SECONDS)
public interface DeltacloudClient {
/**
* The result of this entry-point is a set of entry-points into other collections, such as
* images, instances, hardware profiles and realms, among others.
*
* @return named links to available collections, or empty set, if no collections are found
*/
Set<DeltacloudCollection> getCollections();
/**
*
* @return The possible states of an instance, and how to traverse between them
*/
Multimap<State, Transition> getInstanceStates();
/**
* The realms collection will return a set of all realms available to the current user.
*
* @return realms viewable to the user or empty set
*/
Set<Realm> listRealms();
/**
*
* @param realmHref
* @return realm or null, if not found
*/
Realm getRealm(URI realmHref);
/**
* The images collection will return a set of all images available to the current user.
*
* @return images viewable to the user or empty set
*/
Set<Image> listImages();
/**
*
* @param imageHref
* @return image or null, if not found
*/
Image getImage(URI imageHref);
/**
* The hardware profiles collection will return a set of all hardware profiles available to the
* current user.
*
* @return hardware profiles viewable to the user or empty set
*/
Set<HardwareProfile> listHardwareProfiles();
/**
*
* @param profileHref
* @return hardware profile or null, if not found
*/
HardwareProfile getHardwareProfile(URI profileHref);
/**
* The instances collection will return a set of all instances available to the current user.
*
* @return instances viewable to the user or empty set
*/
Set<Instance> listInstances();
/**
*
* @param instanceHref
* @return instance or null, if not found
*/
Instance getInstance(URI instanceHref);
/**
* Create a new Instance
*
* <h4>Note</h4>
*
* If options realmId or hardwareProfileName are not specified, the provider must select
* reasonable defaults. The architecture of the selected hardware profile must match the
* architecture of the specified image.
*
* @param imageId
* The identifier (not URL) of the image from which to base the instance
* @param options
* includes realm, hardware profile, etc.
* @return newly-created instance including a URL to retrieve the instance in the future.
*/
Instance createInstance(String imageId, CreateInstanceOptions... options);
/**
* perform a specific action.
*
* @param action
* reference from {@link Instance#getActions()}
*/
void performAction(HttpRequest action);
}

View File

@ -1,52 +0,0 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.deltacloud;
import static com.google.common.base.Throwables.propagate;
import static com.google.common.util.concurrent.Futures.immediateFuture;
import static org.jclouds.util.Throwables2.getFirstThrowableOfType;
import javax.ws.rs.HttpMethod;
import org.jclouds.http.HttpResponseException;
import com.google.common.util.concurrent.FutureFallback;
import com.google.common.util.concurrent.ListenableFuture;
public final class DeltacloudFallbacks {
private DeltacloudFallbacks() {
}
/**
* When a delete operation is performed, Deltacloud returns 302.
*
* @author Adrian Cole
*/
public static final class VoidOnRedirectedDelete implements FutureFallback<Void> {
@Override
public ListenableFuture<Void> create(final Throwable t) {
HttpResponseException exception = getFirstThrowableOfType(t, HttpResponseException.class);
if (exception != null && exception.getCommand().getCurrentRequest().getMethod().equals(HttpMethod.DELETE)
&& exception.getResponse().getStatusCode() == 302) {
return immediateFuture(null);
}
throw propagate(t);
}
}
}

View File

@ -1,39 +0,0 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.deltacloud.collections;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import javax.inject.Qualifier;
/**
* The images collection will return a set of all hardware profiles available to the current user.
*
* @author Adrian Cole
*
*/
@Retention(value = RetentionPolicy.RUNTIME)
@Target(value = { ElementType.TYPE, ElementType.FIELD, ElementType.PARAMETER, ElementType.METHOD })
@Qualifier
public @interface HardwareProfiles {
}

View File

@ -1,39 +0,0 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.deltacloud.collections;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import javax.inject.Qualifier;
/**
* The images collection will return a set of all images available to the current user.
*
* @author Adrian Cole
*
*/
@Retention(value = RetentionPolicy.RUNTIME)
@Target(value = { ElementType.TYPE, ElementType.FIELD, ElementType.PARAMETER, ElementType.METHOD })
@Qualifier
public @interface Images {
}

View File

@ -1,39 +0,0 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.deltacloud.collections;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import javax.inject.Qualifier;
/**
* The realms collection will return a set of all instance states available to the current user.
*
* @author Adrian Cole
*
*/
@Retention(value = RetentionPolicy.RUNTIME)
@Target(value = { ElementType.TYPE, ElementType.FIELD, ElementType.PARAMETER, ElementType.METHOD })
@Qualifier
public @interface InstanceStates {
}

View File

@ -1,39 +0,0 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.deltacloud.collections;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import javax.inject.Qualifier;
/**
* The instances collection will return a set of all instances available to the current user.
*
* @author Adrian Cole
*
*/
@Retention(value = RetentionPolicy.RUNTIME)
@Target(value = { ElementType.TYPE, ElementType.FIELD, ElementType.PARAMETER, ElementType.METHOD })
@Qualifier
public @interface Instances {
}

View File

@ -1,39 +0,0 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.deltacloud.collections;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import javax.inject.Qualifier;
/**
* The realms collection will return a set of all realms available to the current user.
*
* @author Adrian Cole
*
*/
@Retention(value = RetentionPolicy.RUNTIME)
@Target(value = { ElementType.TYPE, ElementType.FIELD, ElementType.PARAMETER, ElementType.METHOD })
@Qualifier
public @interface Realms {
}

View File

@ -1,61 +0,0 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.deltacloud.compute.config;
import org.jclouds.compute.ComputeServiceAdapter;
import org.jclouds.compute.config.ComputeServiceAdapterContextModule;
import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.deltacloud.compute.functions.DeltacloudImageToImage;
import org.jclouds.deltacloud.compute.functions.HardwareProfileToHardware;
import org.jclouds.deltacloud.compute.functions.InstanceToNodeMetadata;
import org.jclouds.deltacloud.compute.functions.RealmToLocation;
import org.jclouds.deltacloud.compute.strategy.DeltacloudComputeServiceAdapter;
import org.jclouds.deltacloud.domain.HardwareProfile;
import org.jclouds.deltacloud.domain.Instance;
import org.jclouds.deltacloud.domain.Realm;
import org.jclouds.domain.Location;
import com.google.common.base.Function;
import com.google.inject.TypeLiteral;
/**
*
* @author Adrian Cole
*/
public class DeltacloudComputeServiceContextModule extends
ComputeServiceAdapterContextModule<Instance, HardwareProfile, org.jclouds.deltacloud.domain.Image, Realm> {
@Override
protected void configure() {
super.configure();
bind(
new TypeLiteral<ComputeServiceAdapter<Instance, HardwareProfile, org.jclouds.deltacloud.domain.Image, Realm>>() {
}).to(DeltacloudComputeServiceAdapter.class);
bind(new TypeLiteral<Function<Instance, NodeMetadata>>() {
}).to(InstanceToNodeMetadata.class);
bind(new TypeLiteral<Function<org.jclouds.deltacloud.domain.Image, org.jclouds.compute.domain.Image>>() {
}).to(DeltacloudImageToImage.class);
bind(new TypeLiteral<Function<HardwareProfile, org.jclouds.compute.domain.Hardware>>() {
}).to(HardwareProfileToHardware.class);
bind(new TypeLiteral<Function<Realm, Location>>() {
}).to(RealmToLocation.class);
// to have the compute service adapter override default locations
install(new LocationsFromComputeServiceAdapterModule<Instance, HardwareProfile, org.jclouds.deltacloud.domain.Image, Realm>(){});
}
}

View File

@ -1,54 +0,0 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.deltacloud.compute.functions;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.compute.domain.Image;
import org.jclouds.compute.domain.ImageBuilder;
import org.jclouds.compute.domain.Image.Status;
import com.google.common.base.Function;
/**
* @author Adrian Cole
*/
@Singleton
public class DeltacloudImageToImage implements Function<org.jclouds.deltacloud.domain.Image, Image> {
private final DeltacloudImageToOperatingSystem imageToOperatingSystem;
@Inject
public DeltacloudImageToImage(DeltacloudImageToOperatingSystem imageToOperatingSystem) {
this.imageToOperatingSystem = imageToOperatingSystem;
}
@Override
public Image apply(org.jclouds.deltacloud.domain.Image from) {
ImageBuilder builder = new ImageBuilder();
builder.id(from.getHref().toASCIIString());
builder.providerId(from.getId());
builder.uri(from.getHref());
builder.name(from.getName());
builder.description(from.getDescription());
builder.operatingSystem(imageToOperatingSystem.apply(from));
builder.status(Status.AVAILABLE);
return builder.build();
}
}

View File

@ -1,89 +0,0 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.deltacloud.compute.functions;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.annotation.Resource;
import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;
import org.jclouds.compute.domain.OperatingSystem;
import org.jclouds.compute.domain.OsFamily;
import org.jclouds.compute.reference.ComputeServiceConstants;
import org.jclouds.compute.util.ComputeServiceUtils;
import org.jclouds.logging.Logger;
import com.google.common.base.Function;
/**
* @author Adrian Cole
*/
@Singleton
public class DeltacloudImageToOperatingSystem implements Function<org.jclouds.deltacloud.domain.Image, OperatingSystem> {
public static final Pattern DEFAULT_PATTERN = Pattern.compile("(([^ ]*) ([0-9.]+) ?.*)");
// Windows Server 2008 R2 x64
public static final Pattern WINDOWS_PATTERN = Pattern.compile("Windows (.*) (x[86][64])");
@Resource
@Named(ComputeServiceConstants.COMPUTE_LOGGER)
protected Logger logger = Logger.NULL;
private final Map<OsFamily, Map<String, String>> osVersionMap;
@Inject
public DeltacloudImageToOperatingSystem(Map<OsFamily, Map<String, String>> osVersionMap) {
this.osVersionMap = osVersionMap;
}
public OperatingSystem apply(org.jclouds.deltacloud.domain.Image from) {
OsFamily osFamily = null;
String osName = null;
String osArch = null;
String osVersion = null;
String osDescription = from.getName();
boolean is64Bit = true;
if (from.getName().indexOf("Red Hat EL") != -1) {
osFamily = OsFamily.RHEL;
} else if (from.getName().indexOf("Oracle EL") != -1) {
osFamily = OsFamily.OEL;
} else if (from.getName().indexOf("Windows") != -1) {
osFamily = OsFamily.WINDOWS;
Matcher matcher = WINDOWS_PATTERN.matcher(from.getName());
if (matcher.find()) {
osVersion = ComputeServiceUtils.parseVersionOrReturnEmptyString(osFamily, matcher.group(1), osVersionMap);
is64Bit = matcher.group(2).equals("x64");
}
} else {
Matcher matcher = DEFAULT_PATTERN.matcher(from.getName());
if (matcher.find()) {
try {
osFamily = OsFamily.fromValue(matcher.group(2).toLowerCase());
} catch (IllegalArgumentException e) {
logger.debug("<< didn't match os(%s)", matcher.group(2));
}
osVersion = ComputeServiceUtils.parseVersionOrReturnEmptyString(osFamily, matcher.group(3), osVersionMap);
}
}
return new OperatingSystem(osFamily, osName, osVersion, osArch, osDescription, is64Bit);
}
}

View File

@ -1,60 +0,0 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.deltacloud.compute.functions;
import javax.inject.Singleton;
import org.jclouds.compute.domain.Hardware;
import org.jclouds.compute.domain.HardwareBuilder;
import org.jclouds.compute.domain.Processor;
import org.jclouds.compute.domain.Volume;
import org.jclouds.compute.domain.VolumeBuilder;
import org.jclouds.deltacloud.domain.HardwareProfile;
import org.jclouds.deltacloud.domain.HardwareProperty;
import com.google.common.base.Function;
import com.google.common.collect.ImmutableList;
/**
* @author Adrian Cole
*/
@Singleton
public class HardwareProfileToHardware implements Function<HardwareProfile, Hardware> {
@Override
public Hardware apply(HardwareProfile from) {
HardwareBuilder builder = new HardwareBuilder();
builder.ids(from.getId());
builder.name(from.getName());
builder.uri(from.getHref());
for (HardwareProperty property : from.getProperties()) {
if (property.getName().equals("memory")) {
builder.ram(Integer.parseInt(property.getValue().toString()));
} else if (property.getName().equals("storage")) {
Float gigs = new Float(property.getValue().toString());
builder.processors(ImmutableList.of(new Processor(gigs / 10.0, 1.0)));
builder.volume(new VolumeBuilder().type(Volume.Type.LOCAL).device("/").size(gigs).bootDevice(true).durable(
true).build());
}
}
return builder.build();
}
}

View File

@ -1,163 +0,0 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.deltacloud.compute.functions;
import static com.google.common.base.Preconditions.checkNotNull;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Set;
import javax.annotation.Resource;
import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;
import org.jclouds.collect.Memoized;
import org.jclouds.compute.domain.Hardware;
import org.jclouds.compute.domain.Image;
import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.compute.domain.NodeMetadataBuilder;
import org.jclouds.compute.domain.OperatingSystem;
import org.jclouds.compute.domain.NodeMetadata.Status;
import org.jclouds.compute.functions.GroupNamingConvention;
import org.jclouds.compute.reference.ComputeServiceConstants;
import org.jclouds.deltacloud.domain.Instance;
import org.jclouds.domain.Location;
import org.jclouds.logging.Logger;
import com.google.common.base.Function;
import com.google.common.base.Predicate;
import com.google.common.base.Supplier;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Iterables;
/**
* @author Adrian Cole
*/
@Singleton
public class InstanceToNodeMetadata implements Function<Instance, NodeMetadata> {
public static final Map<Instance.State, Status> instanceToNodeStatus = ImmutableMap
.<Instance.State, Status> builder().put(Instance.State.STOPPED, Status.SUSPENDED)
.put(Instance.State.RUNNING, Status.RUNNING).put(Instance.State.PENDING, Status.PENDING)
.put(Instance.State.UNRECOGNIZED, Status.UNRECOGNIZED).put(Instance.State.SHUTTING_DOWN, Status.PENDING)
.put(Instance.State.START, Status.PENDING).build();
@Resource
@Named(ComputeServiceConstants.COMPUTE_LOGGER)
protected Logger logger = Logger.NULL;
protected final Supplier<Set<? extends Location>> locations;
protected final Supplier<Set<? extends Image>> images;
protected final Supplier<Set<? extends Hardware>> hardwares;
protected final GroupNamingConvention nodeNamingConvention;
private static class FindImageForInstance implements Predicate<Image> {
private final Instance instance;
private FindImageForInstance(Instance instance) {
this.instance = instance;
}
@Override
public boolean apply(Image input) {
return input.getUri().equals(instance.getImage());
}
}
private static class FindHardwareForInstance implements Predicate<Hardware> {
private final Instance instance;
private FindHardwareForInstance(Instance instance) {
this.instance = instance;
}
@Override
public boolean apply(Hardware input) {
return input.getUri().equals(instance.getHardwareProfile());
}
}
protected Hardware parseHardware(Instance from) {
try {
return Iterables.find(hardwares.get(), new FindHardwareForInstance(from));
} catch (NoSuchElementException e) {
logger.debug("could not find a matching hardware for instance %s", from);
}
return null;
}
protected OperatingSystem parseOperatingSystem(Instance from) {
try {
return Iterables.find(images.get(), new FindImageForInstance(from)).getOperatingSystem();
} catch (NoSuchElementException e) {
logger.debug("could not find a matching image for instance %s", from);
}
return null;
}
private static class FindLocationForInstance implements Predicate<Location> {
private final Instance instance;
private FindLocationForInstance(Instance instance) {
this.instance = instance;
}
@Override
public boolean apply(Location input) {
return input.getId().equals(instance.getRealm().toASCIIString());
}
}
protected Location parseLocation(Instance from) {
try {
return Iterables.find(locations.get(), new FindLocationForInstance(from));
} catch (NoSuchElementException e) {
logger.debug("could not find a matching realm for instance %s", from);
}
return null;
}
@Inject
InstanceToNodeMetadata(@Memoized Supplier<Set<? extends Location>> locations,
@Memoized Supplier<Set<? extends Image>> images, @Memoized Supplier<Set<? extends Hardware>> hardwares,
GroupNamingConvention.Factory namingConvention) {
this.nodeNamingConvention = checkNotNull(namingConvention, "namingConvention").createWithoutPrefix();
this.images = checkNotNull(images, "images");
this.locations = checkNotNull(locations, "locations");
this.hardwares = checkNotNull(hardwares, "hardwares");
}
@Override
public NodeMetadata apply(org.jclouds.deltacloud.domain.Instance from) {
NodeMetadataBuilder builder = new NodeMetadataBuilder();
builder.ids(from.getHref().toASCIIString());
builder.name(from.getName());
builder.location(parseLocation(from));
builder.group(nodeNamingConvention.groupInUniqueNameOrNull(from.getName()));
builder.imageId(from.getImage().toASCIIString());
builder.operatingSystem(parseOperatingSystem(from));
builder.hardware(parseHardware(from));
builder.status(instanceToNodeStatus.get(from.getState()));
builder.publicAddresses(from.getPublicAddresses());
builder.privateAddresses(from.getPrivateAddresses());
return builder.build();
}
}

View File

@ -1,62 +0,0 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.deltacloud.compute.functions;
import static com.google.common.base.Preconditions.checkNotNull;
import java.net.URI;
import java.util.Set;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.deltacloud.domain.Realm;
import org.jclouds.domain.Location;
import org.jclouds.domain.LocationBuilder;
import org.jclouds.domain.LocationScope;
import org.jclouds.location.Iso3166;
import org.jclouds.location.Provider;
import com.google.common.base.Function;
import com.google.common.base.Supplier;
/**
* @author Adrian Cole
*/
@Singleton
public class RealmToLocation implements Function<Realm, Location> {
private final String providerName;
private final Supplier<URI> endpoint;
private final Set<String> isoCodes;
@Inject
public RealmToLocation(@Iso3166 Set<String> isoCodes, @Provider String providerName, @Provider Supplier<URI> endpoint) {
this.providerName = checkNotNull(providerName, "providerName");
this.endpoint = checkNotNull(endpoint, "endpoint");
this.isoCodes = checkNotNull(isoCodes, "isoCodes");
}
@Override
public Location apply(Realm from) {
return new LocationBuilder().scope(LocationScope.ZONE).id(from.getHref().toASCIIString()).description(from.getName()).parent(
new LocationBuilder().scope(LocationScope.PROVIDER).iso3166Codes(isoCodes).id(providerName).description(
endpoint.get().toASCIIString()).parent(null).build()).build();
}
}

View File

@ -1,176 +0,0 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.deltacloud.compute.strategy;
import static com.google.common.base.Preconditions.checkNotNull;
import java.net.URI;
import java.util.concurrent.TimeUnit;
import javax.annotation.Resource;
import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;
import org.jclouds.compute.ComputeServiceAdapter;
import org.jclouds.compute.domain.Template;
import org.jclouds.compute.reference.ComputeServiceConstants;
import org.jclouds.deltacloud.DeltacloudClient;
import org.jclouds.deltacloud.domain.HardwareProfile;
import org.jclouds.deltacloud.domain.Instance;
import org.jclouds.deltacloud.domain.PasswordAuthentication;
import org.jclouds.deltacloud.domain.Realm;
import org.jclouds.deltacloud.domain.Transition;
import org.jclouds.deltacloud.domain.TransitionOnAction;
import org.jclouds.deltacloud.domain.Instance.State;
import org.jclouds.deltacloud.options.CreateInstanceOptions;
import org.jclouds.deltacloud.predicates.InstanceFinished;
import org.jclouds.deltacloud.predicates.InstanceRunning;
import org.jclouds.domain.LoginCredentials;
import org.jclouds.http.HttpRequest;
import org.jclouds.logging.Logger;
import org.jclouds.predicates.RetryablePredicate;
import com.google.common.base.Predicate;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
import com.google.common.collect.Multimap;
/**
* defines the connection between the {@link DeltacloudClient} implementation
* and the jclouds {@link ComputeService}
*
*/
@Singleton
public class DeltacloudComputeServiceAdapter implements
ComputeServiceAdapter<Instance, HardwareProfile, org.jclouds.deltacloud.domain.Image, Realm> {
@Resource
@Named(ComputeServiceConstants.COMPUTE_LOGGER)
protected Logger logger = Logger.NULL;
private final org.jclouds.deltacloud.DeltacloudClient client;
private final ImmutableMap<State, Predicate<Instance>> stateChanges;
@Inject
public DeltacloudComputeServiceAdapter(DeltacloudClient client) {
this.client = checkNotNull(client, "client");
// TODO: parameterize
stateChanges = ImmutableMap.<Instance.State, Predicate<Instance>> of(//
Instance.State.RUNNING, new RetryablePredicate<Instance>(new InstanceRunning(client), 600, 1,
TimeUnit.SECONDS),//
Instance.State.FINISH, new RetryablePredicate<Instance>(new InstanceFinished(client), 30, 1,
TimeUnit.SECONDS)//
);
}
@Override
public NodeAndInitialCredentials<Instance> createNodeWithGroupEncodedIntoName(String tag, String name,
Template template) {
Instance instance = client.createInstance(template.getImage().getProviderId(), CreateInstanceOptions.Builder
.named(name).hardwareProfile(template.getHardware().getId()).realm(template.getLocation().getId()));
LoginCredentials creds = null;
if (instance.getAuthentication() != null && instance.getAuthentication() instanceof PasswordAuthentication) {
creds = PasswordAuthentication.class.cast(instance.getAuthentication()).getLoginCredentials();
}
return new NodeAndInitialCredentials<Instance>(instance, instance.getId(), creds);
}
@Override
public Iterable<HardwareProfile> listHardwareProfiles() {
return client.listHardwareProfiles();
}
@Override
public Iterable<org.jclouds.deltacloud.domain.Image> listImages() {
return client.listImages();
}
@Override
public Iterable<Instance> listNodes() {
return client.listInstances();
}
@Override
public Iterable<Realm> listLocations() {
return client.listRealms();
}
@Override
public org.jclouds.deltacloud.domain.Instance getNode(String id) {
return client.getInstance(URI.create(checkNotNull(id, "id")));
}
@Override
public org.jclouds.deltacloud.domain.Image getImage(String id) {
return client.getImage(URI.create(checkNotNull(id, "id")));
}
@Override
public void destroyNode(String id) {
Instance instance = getNode(id);
for (Transition transition : findChainTo(Instance.State.FINISH, instance.getState(), client.getInstanceStates())) {
instance = getNode(id);
if (instance == null)
break;
if (transition instanceof TransitionOnAction) {
client.performAction(instance.getActions().get(TransitionOnAction.class.cast(transition).getAction()));
}
Predicate<Instance> stateTester = stateChanges.get(transition.getTo());
if (stateTester != null)
stateTester.apply(instance);
else
logger.debug(String.format("no state tester for: %s", transition));
}
}
Iterable<Transition> findChainTo(Instance.State desired, Instance.State currentState,
Multimap<Instance.State, ? extends Transition> states) {
for (Transition transition : states.get(currentState)) {
if (currentState.ordinal() >= transition.getTo().ordinal())
continue;
if (transition.getTo() == desired)
return ImmutableSet.<Transition> of(transition);
Iterable<Transition> transitions = findChainTo(desired, transition.getTo(), states);
if (Iterables.size(transitions) > 0)
return Iterables.concat(ImmutableSet.of(transition), transitions);
}
return ImmutableSet.<Transition> of();
}
@Override
public void rebootNode(String id) {
HttpRequest rebootUri = getNode(id).getActions().get(Instance.Action.REBOOT);
if (rebootUri != null) {
client.performAction(rebootUri);
} else {
throw new UnsupportedOperationException();
}
}
@Override
public void resumeNode(String id) {
throw new UnsupportedOperationException();
}
@Override
public void suspendNode(String id) {
throw new UnsupportedOperationException();
}
}

View File

@ -1,158 +0,0 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.deltacloud.config;
import static org.jclouds.Constants.PROPERTY_SESSION_INTERVAL;
import java.net.URI;
import java.util.NoSuchElementException;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
import javax.inject.Named;
import javax.inject.Singleton;
import org.jclouds.deltacloud.DeltacloudAsyncClient;
import org.jclouds.deltacloud.DeltacloudClient;
import org.jclouds.deltacloud.collections.HardwareProfiles;
import org.jclouds.deltacloud.collections.Images;
import org.jclouds.deltacloud.collections.InstanceStates;
import org.jclouds.deltacloud.collections.Instances;
import org.jclouds.deltacloud.collections.Realms;
import org.jclouds.deltacloud.domain.DeltacloudCollection;
import org.jclouds.deltacloud.handlers.DeltacloudErrorHandler;
import org.jclouds.deltacloud.handlers.DeltacloudRedirectionRetryHandler;
import org.jclouds.http.HttpErrorHandler;
import org.jclouds.http.HttpRetryHandler;
import org.jclouds.http.annotation.ClientError;
import org.jclouds.http.annotation.Redirection;
import org.jclouds.http.annotation.ServerError;
import org.jclouds.rest.AuthorizationException;
import org.jclouds.rest.ConfiguresRestClient;
import org.jclouds.rest.config.RestClientModule;
import org.jclouds.rest.suppliers.MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier;
import org.jclouds.util.Suppliers2;
import com.google.common.base.Function;
import com.google.common.base.Objects;
import com.google.common.base.Predicate;
import com.google.common.base.Supplier;
import com.google.common.collect.Iterables;
import com.google.common.util.concurrent.Atomics;
import com.google.inject.Provides;
/**
* Configures the deltacloud connection.
*
* @author Adrian Cole
*/
@ConfiguresRestClient
public class DeltacloudRestClientModule extends RestClientModule<DeltacloudClient, DeltacloudAsyncClient> {
@Override
protected void bindErrorHandlers() {
bind(HttpErrorHandler.class).annotatedWith(Redirection.class).to(DeltacloudErrorHandler.class);
bind(HttpErrorHandler.class).annotatedWith(ClientError.class).to(DeltacloudErrorHandler.class);
bind(HttpErrorHandler.class).annotatedWith(ServerError.class).to(DeltacloudErrorHandler.class);
}
@Override
protected void bindRetryHandlers() {
bind(HttpRetryHandler.class).annotatedWith(Redirection.class).to(DeltacloudRedirectionRetryHandler.class);
}
protected AtomicReference<AuthorizationException> authException = Atomics.newReference();
@Provides
@Singleton
protected Supplier<Set<? extends DeltacloudCollection>> provideCollections(
@Named(PROPERTY_SESSION_INTERVAL) long seconds, final DeltacloudClient client) {
return MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier.create(
authException, new Supplier<Set<? extends DeltacloudCollection>>() {
@Override
public Set<? extends DeltacloudCollection> get() {
return client.getCollections();
}
@Override
public String toString() {
return Objects.toStringHelper(client).add("method", "getCollections").toString();
}
}, seconds, TimeUnit.SECONDS);
}
/**
* since the supplier is memoized, and there are no objects created here, this doesn't need to be
* singleton.
*/
@Provides
@Images
protected Supplier<URI> provideImageCollection(Supplier<Set<? extends DeltacloudCollection>> collectionSupplier) {
return Suppliers2.compose(new FindCollectionWithRelAndReturnHref("images"), collectionSupplier);
}
public static class FindCollectionWithRelAndReturnHref implements Function<Set<? extends DeltacloudCollection>, URI> {
private final String rel;
public FindCollectionWithRelAndReturnHref(String rel) {
this.rel = rel;
}
@Override
public URI apply(Set<? extends DeltacloudCollection> arg0) {
try {
return Iterables.find(arg0, new Predicate<DeltacloudCollection>() {
@Override
public boolean apply(DeltacloudCollection arg0) {
return arg0.getRel().equals(rel);
}
}).getHref();
} catch (NoSuchElementException e) {
throw new NoSuchElementException("could not find rel " + rel + " in collections " + arg0);
}
}
}
@Provides
@HardwareProfiles
protected Supplier<URI> provideHardwareProfileCollection(Supplier<Set<? extends DeltacloudCollection>> collectionSupplier) {
return Suppliers2.compose(new FindCollectionWithRelAndReturnHref("hardware_profiles"), collectionSupplier);
}
@Provides
@Instances
protected Supplier<URI> provideInstanceCollection(Supplier<Set<? extends DeltacloudCollection>> collectionSupplier) {
return Suppliers2.compose(new FindCollectionWithRelAndReturnHref("instances"), collectionSupplier);
}
@Provides
@Realms
protected Supplier<URI> provideRealmCollection(Supplier<Set<? extends DeltacloudCollection>> collectionSupplier) {
return Suppliers2.compose(new FindCollectionWithRelAndReturnHref("realms"), collectionSupplier);
}
@Provides
@InstanceStates
protected Supplier<URI> provideInstanceStateCollection(Supplier<Set<? extends DeltacloudCollection>> collectionSupplier) {
return Suppliers2.compose(new FindCollectionWithRelAndReturnHref("instance_states"), collectionSupplier);
}
}

View File

@ -1,28 +0,0 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.deltacloud.domain;
/**
*
* @author Adrian Cole
*/
public interface Architecture {
public static final String I386 = "i386";
public static final String X86_64 = "x86_64";
}

View File

@ -1,100 +0,0 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.deltacloud.domain;
import static com.google.common.base.Preconditions.checkNotNull;
import java.net.URI;
import java.util.Set;
import com.google.common.collect.ImmutableSet;
/**
*
* @author Adrian Cole
*/
public class DeltacloudCollection {
private final URI href;
private final String rel;
private final Set<? extends Feature> features;
public DeltacloudCollection(URI href, String rel) {
this(href, rel, ImmutableSet.<Feature> of());
}
public DeltacloudCollection(URI href, String rel, Set<? extends Feature> features) {
this.href = checkNotNull(href, "href");
this.rel = checkNotNull(rel, "rel");
this.features = ImmutableSet.copyOf(checkNotNull(features, "features"));
}
public URI getHref() {
return href;
}
public String getRel() {
return rel;
}
public Set<? extends Feature> getFeatures() {
return features;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((features == null) ? 0 : features.hashCode());
result = prime * result + ((href == null) ? 0 : href.hashCode());
result = prime * result + ((rel == null) ? 0 : rel.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;
DeltacloudCollection other = (DeltacloudCollection) obj;
if (features == null) {
if (other.features != null)
return false;
} else if (!features.equals(other.features))
return false;
if (href == null) {
if (other.href != null)
return false;
} else if (!href.equals(other.href))
return false;
if (rel == null) {
if (other.rel != null)
return false;
} else if (!rel.equals(other.rel))
return false;
return true;
}
@Override
public String toString() {
return "[href=" + href + ", rel=" + rel + ", features=" + features + "]";
}
}

View File

@ -1,54 +0,0 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.deltacloud.domain;
import static com.google.common.base.Preconditions.checkNotNull;
import java.util.Set;
import com.google.common.collect.ImmutableSet;
/**
*
* @author Adrian Cole
*/
public class EnumHardwareProperty extends ParameterizedHardwareProperty {
private final Set<Object> availableValues;
public EnumHardwareProperty(String name, String unit, Object value, HardwareParameter param,
Set<Object> availableValues) {
super(Kind.FIXED, name, unit, value, param);
this.availableValues = ImmutableSet.copyOf(checkNotNull(availableValues, "availableValues"));
}
/**
*
* @return a set of available values
*/
public Set<Object> getAvailableValues() {
return availableValues;
}
@Override
public String toString() {
return "[kind=" + getKind() + ", name=" + getName() + ", unit=" + getUnit() + ", value=" + getValue()
+ ", param=" + getParam() + ", availableValues=" + availableValues + "]";
}
}

View File

@ -1,67 +0,0 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.deltacloud.domain;
import static com.google.common.base.Preconditions.checkNotNull;
/**
*
* @author Adrian Cole
*/
public class Feature {
private final String name;
public Feature(String name) {
this.name = checkNotNull(name, "name");
}
public String getName() {
return name;
}
@Override
public String toString() {
return "[name=" + name + "]";
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((name == null) ? 0 : name.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;
Feature other = (Feature) obj;
if (name == null) {
if (other.name != null)
return false;
} else if (!name.equals(other.name))
return false;
return true;
}
}

View File

@ -1,33 +0,0 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.deltacloud.domain;
import org.jclouds.deltacloud.domain.internal.BaseHardwareProperty;
/**
*
* @author Adrian Cole
*/
public class FixedHardwareProperty extends BaseHardwareProperty {
public FixedHardwareProperty(String name, String unit, Object value) {
super(Kind.FIXED, name, unit, value);
}
}

View File

@ -1,122 +0,0 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.deltacloud.domain;
import static com.google.common.base.Preconditions.checkNotNull;
import java.net.URI;
/**
* A parameter corresponding to a hardware option.
*
* @author Adrian Cole
*/
public class HardwareParameter {
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((href == null) ? 0 : href.hashCode());
result = prime * result + ((method == null) ? 0 : method.hashCode());
result = prime * result + ((name == null) ? 0 : name.hashCode());
result = prime * result + ((operation == null) ? 0 : operation.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;
HardwareParameter other = (HardwareParameter) obj;
if (href == null) {
if (other.href != null)
return false;
} else if (!href.equals(other.href))
return false;
if (method == null) {
if (other.method != null)
return false;
} else if (!method.equals(other.method))
return false;
if (name == null) {
if (other.name != null)
return false;
} else if (!name.equals(other.name))
return false;
if (operation == null) {
if (other.operation != null)
return false;
} else if (!operation.equals(other.operation))
return false;
return true;
}
private final URI href;
private final String method;
private final String name;
private final String operation;
public HardwareParameter(URI href, String method, String name, String operation) {
this.href = checkNotNull(href, "href");
this.method = checkNotNull(method, "method");
this.name = checkNotNull(name, "name");
this.operation = checkNotNull(operation, "operation");
}
/**
*
* @return URI of the action this applies to
*/
public URI getHref() {
return href;
}
/**
*
* @return HTTP method of the action this applies to
*/
public String getMethod() {
return method;
}
/**
*
* @return name of the HTTP request parameter related to this
*/
public String getName() {
return name;
}
/**
*
* @return name of the action this applies to
*/
public String getOperation() {
return operation;
}
@Override
public String toString() {
return "[href=" + href + ", method=" + method + ", name=" + name + ", operation=" + operation + "]";
}
}

View File

@ -1,128 +0,0 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.deltacloud.domain;
import static com.google.common.base.Preconditions.checkNotNull;
import java.net.URI;
import java.util.Set;
import com.google.common.collect.ImmutableSet;
/**
* A hardware profile represents a configuration of resources upon which a machine may be deployed.
* It defines aspects such as local disk storage, available RAM, and architecture. Each provider is
* free to define as many (or as few) hardware profiles as desired.
*
* @author Adrian Cole
*/
public class HardwareProfile {
private final URI href;
private final String id;
private final String name;
private final Set<? extends HardwareProperty> properties;
public HardwareProfile(URI href, String id, String name, Set<? extends HardwareProperty> properties) {
this.href = checkNotNull(href, "href");
this.id = checkNotNull(id, "id");
this.name = checkNotNull(name, "name");
this.properties = ImmutableSet.copyOf(checkNotNull(properties, "properties"));
}
/**
*
* @return URL to manipulate a specific profile
*/
public URI getHref() {
return href;
}
/**
*
* @return A unique identifier for the profile
*/
public String getId() {
return id;
}
/**
*
* @return A short label
*/
public String getName() {
return name;
}
/**
*
* @return properties included in this hardware profile
*/
public Set<? extends HardwareProperty> getProperties() {
return properties;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((href == null) ? 0 : href.hashCode());
result = prime * result + ((id == null) ? 0 : id.hashCode());
result = prime * result + ((name == null) ? 0 : name.hashCode());
result = prime * result + ((properties == null) ? 0 : properties.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;
HardwareProfile other = (HardwareProfile) obj;
if (href == null) {
if (other.href != null)
return false;
} else if (!href.equals(other.href))
return false;
if (id == null) {
if (other.id != null)
return false;
} else if (!id.equals(other.id))
return false;
if (name == null) {
if (other.name != null)
return false;
} else if (!name.equals(other.name))
return false;
if (properties == null) {
if (other.properties != null)
return false;
} else if (!properties.equals(other.properties))
return false;
return true;
}
@Override
public String toString() {
return "[href=" + href + ", id=" + id + ", name=" + name + ", properties=" + properties + "]";
}
}

View File

@ -1,78 +0,0 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.deltacloud.domain;
import static com.google.common.base.Preconditions.checkNotNull;
/**
*
* @author Adrian Cole
*/
public interface HardwareProperty {
public static enum Kind {
/**
* only the value specified in the property is available
*/
FIXED,
/**
* a list of available values is provided
*/
ENUM,
/**
* available values are described by a numeric range
*/
RANGE,
/**
* type returned as something besides the above.
*/
UNRECOGNIZED;
public static HardwareProperty.Kind fromValue(String kind) {
try {
return valueOf(checkNotNull(kind, "kind").toUpperCase());
} catch (IllegalArgumentException e) {
return UNRECOGNIZED;
}
}
}
/**
*
* @return describes the values to chose from.
*/
HardwareProperty.Kind getKind();
/**
*
* @return the type of the property: e.g. memory or storage
*/
String getName();
/**
*
* @return the units in which the value is specified: MB, GB, count or label
*/
String getUnit();
/**
*
* @return the actual value of the property. It depends on the specified unit: 1024, 2 on x86_64
*/
Object getValue();
}

View File

@ -1,163 +0,0 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.deltacloud.domain;
import static com.google.common.base.Preconditions.checkNotNull;
import java.net.URI;
import org.jclouds.javax.annotation.Nullable;
/**
* An image is a platonic form of a machine. Images are not directly executable, but are a template
* for creating actual instances of machines.
*
* @author Adrian Cole
*/
public class Image {
private final URI href;
private final String id;
private final String ownerId;
@Nullable
private final String name;
@Nullable
private final String description;
private final String architecture;
public Image(URI href, String id, String ownerId, @Nullable String name, String description, String architecture) {
this.href = checkNotNull(href, "href");
this.id = checkNotNull(id, "id");
this.ownerId = checkNotNull(ownerId, "ownerId");
this.name = name;
this.description = description;
this.architecture = checkNotNull(architecture, "architecture");
}
/**
*
* @return URL to manipulate a specific image
*/
public URI getHref() {
return href;
}
/**
*
* @return A unique identifier for the image
*/
public String getId() {
return id;
}
/**
*
* @return An opaque identifier which indicates the owner of an image
*/
public String getOwnerId() {
return ownerId;
}
/**
*
* @return An optional short label describing the image
*/
@Nullable
public String getName() {
return name;
}
/**
*
* @return An optional description describing the image more fully
*/
@Nullable
public String getDescription() {
return description;
}
/**
*
* @return A description of the machine architecture of the image which may contain values such
* as: i386, x86_64
*/
public String getArchitecture() {
return architecture;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((architecture == null) ? 0 : architecture.hashCode());
result = prime * result + ((description == null) ? 0 : description.hashCode());
result = prime * result + ((href == null) ? 0 : href.hashCode());
result = prime * result + ((id == null) ? 0 : id.hashCode());
result = prime * result + ((name == null) ? 0 : name.hashCode());
result = prime * result + ((ownerId == null) ? 0 : ownerId.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;
Image other = (Image) obj;
if (architecture == null) {
if (other.architecture != null)
return false;
} else if (!architecture.equals(other.architecture))
return false;
if (description == null) {
if (other.description != null)
return false;
} else if (!description.equals(other.description))
return false;
if (href == null) {
if (other.href != null)
return false;
} else if (!href.equals(other.href))
return false;
if (id == null) {
if (other.id != null)
return false;
} else if (!id.equals(other.id))
return false;
if (name == null) {
if (other.name != null)
return false;
} else if (!name.equals(other.name))
return false;
if (ownerId == null) {
if (other.ownerId != null)
return false;
} else if (!ownerId.equals(other.ownerId))
return false;
return true;
}
@Override
public String toString() {
return "[href=" + href + ", id=" + id + ", ownerId=" + ownerId + ", name=" + name + ", description="
+ description + ", architecture=" + architecture + "]";
}
}

View File

@ -1,281 +0,0 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.deltacloud.domain;
import static com.google.common.base.Preconditions.checkNotNull;
import java.net.URI;
import java.util.Map;
import java.util.Set;
import org.jclouds.http.HttpRequest;
import org.jclouds.javax.annotation.Nullable;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
/**
* An instance is a concrete machine realized from an image.
*
* @author Adrian Cole
*/
public class Instance {
public static interface Authentication {
}
public static enum State {
/**
* initial state, before instance is created.
*/
START,
/**
* the instance is in the process of being launched
*/
PENDING,
/**
* the instance launched (although the boot process might not be completed)
*/
RUNNING,
/**
* the instance is shutting down
*/
SHUTTING_DOWN,
/**
* the instance is stopped
*/
STOPPED,
/**
* the instance is terminated
*/
FINISH,
/**
* state returned as something besides the above.
*/
UNRECOGNIZED;
public static State fromValue(String state) {
try {
return valueOf(checkNotNull(state, "state").toUpperCase());
} catch (IllegalArgumentException e) {
return UNRECOGNIZED;
}
}
}
public static enum Action {
CREATE,
RUN,
REBOOT,
START,
STOP,
DESTROY,
UNRECOGNIZED;
public String value() {
return name().toLowerCase();
}
@Override
public String toString() {
return value();
}
public static Action fromValue(String action) {
try {
return valueOf(checkNotNull(action, "action").toUpperCase());
} catch (IllegalArgumentException e) {
return UNRECOGNIZED;
}
}
}
private final URI href;
private final String id;
private final String ownerId;
@Nullable
private final String name;
private final URI image;
private final URI hardwareProfile;
private final URI realm;
private final State state;
private final Map<Action, HttpRequest> actions;
@Nullable
private final Authentication authentication;
private final Set<String> publicAddresses;
private final Set<String> privateAddresses;
public Instance(URI href, String id, String ownerId, @Nullable String name, URI image, URI hardwareProfile,
URI realm, State state, Map<Action, HttpRequest> actions, @Nullable Authentication authentication,
Set<String> publicAddresses, Set<String> privateAddresses) {
this.href = checkNotNull(href, "href");
this.id = checkNotNull(id, "id");
this.ownerId = checkNotNull(ownerId, "ownerId");
this.name = name;
this.image = checkNotNull(image, "image");
this.hardwareProfile = checkNotNull(hardwareProfile, "hardwareProfile");
this.realm = checkNotNull(realm, "realm");
this.state = checkNotNull(state, "state");
this.actions = ImmutableMap.copyOf(checkNotNull(actions, "actions"));
this.authentication = authentication;
this.publicAddresses = ImmutableSet.copyOf(checkNotNull(publicAddresses, "publicAddresses"));
this.privateAddresses = ImmutableSet.copyOf(checkNotNull(privateAddresses, "privateAddresses"));
}
/**
*
* @return URL to manipulate a specific instance
*/
public URI getHref() {
return href;
}
/**
*
* @return A unique identifier for the instance
*/
public String getId() {
return id;
}
/**
*
* @return An opaque identifier which indicates the owner of an instance
*/
public String getOwnerId() {
return ownerId;
}
/**
*
* @return An optional short label describing the instance
*/
@Nullable
public String getName() {
return name;
}
/**
*
* @return
*/
public URI getImage() {
return image;
}
/**
*
* @return a link to the hardware profile in use by the instance
*/
public URI getHardwareProfile() {
return hardwareProfile;
}
/**
*
* @return a link to the realm where the instance is deployed
*/
public URI getRealm() {
return realm;
}
/**
*
* @return indicator of the instance's current state
*/
public State getState() {
return state;
}
/**
*
* @return valid actions for the instance, along with the URL which may be used to perform the
* action
*/
public Map<Action, HttpRequest> getActions() {
return actions;
}
/**
*
* @return authentication of the instance or null
*/
@Nullable
public Authentication getAuthentication() {
return authentication;
}
/**
*
* @return publicly routable IP addresses or names for the instance
*/
public Set<String> getPublicAddresses() {
return publicAddresses;
}
/**
*
* @return Private network IP addresses or names for the instance
*/
public Set<String> getPrivateAddresses() {
return privateAddresses;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((href == null) ? 0 : href.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;
Instance other = (Instance) obj;
if (href == null) {
if (other.href != null)
return false;
} else if (!href.equals(other.href))
return false;
return true;
}
@Override
public String toString() {
return String
.format(
"[id=%s, href=%s, image=%s, name=%s, state=%s, realm=%s, ownerId=%s, hardwareProfile=%s, actions=%s, authentication=%s, privateAddresses=%s, publicAddresses=%s]",
id, href, image, name, state, realm, ownerId, hardwareProfile, actions, authentication,
privateAddresses, publicAddresses);
}
}

View File

@ -1,70 +0,0 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.deltacloud.domain;
import static com.google.common.base.Preconditions.checkNotNull;
/**
*
* @author Adrian Cole
*/
public class KeyAuthentication implements Instance.Authentication {
private final String keyName;
public KeyAuthentication(String keyName) {
this.keyName = checkNotNull(keyName, "keyName");
}
public String getKeyName() {
return keyName;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((keyName == null) ? 0 : keyName.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;
KeyAuthentication other = (KeyAuthentication) obj;
if (keyName == null) {
if (other.keyName != null)
return false;
} else if (!keyName.equals(other.keyName))
return false;
return true;
}
@Override
public String toString() {
return String.format("[keyName=%s]", keyName);
}
}

View File

@ -1,76 +0,0 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.deltacloud.domain;
import static com.google.common.base.Preconditions.checkNotNull;
import org.jclouds.deltacloud.domain.internal.BaseHardwareProperty;
/**
*
* @author Adrian Cole
*/
public class ParameterizedHardwareProperty extends BaseHardwareProperty {
private final HardwareParameter param;
public ParameterizedHardwareProperty(Kind kind, String name, String unit, Object value, HardwareParameter param) {
super(kind, name, unit, value);
this.param = checkNotNull(param, "param");
}
/**
*
* @return how to associate a non-default value with a request against an instance.
*/
public HardwareParameter getParam() {
return param;
}
@Override
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
result = prime * result + ((param == null) ? 0 : param.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (!super.equals(obj))
return false;
if (getClass() != obj.getClass())
return false;
ParameterizedHardwareProperty other = (ParameterizedHardwareProperty) obj;
if (param == null) {
if (other.param != null)
return false;
} else if (!param.equals(other.param))
return false;
return true;
}
@Override
public String toString() {
return "[kind=" + getKind() + ", name=" + getName() + ", unit=" + getUnit() + ", value=" + getValue()
+ ", param=" + getParam() + "]";
}
}

View File

@ -1,72 +0,0 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.deltacloud.domain;
import static com.google.common.base.Preconditions.checkNotNull;
import org.jclouds.domain.LoginCredentials;
/**
*
* @author Adrian Cole
*/
public class PasswordAuthentication implements Instance.Authentication {
private final LoginCredentials login;
public PasswordAuthentication(LoginCredentials login) {
this.login = checkNotNull(login, "login");
}
public LoginCredentials getLoginCredentials() {
return login;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((login == null) ? 0 : login.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;
PasswordAuthentication other = (PasswordAuthentication) obj;
if (login == null) {
if (other.login != null)
return false;
} else if (!login.equals(other.login))
return false;
return true;
}
@Override
public String toString() {
return String.format("[login=%s]", login);
}
}

View File

@ -1,91 +0,0 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.deltacloud.domain;
import static com.google.common.base.Preconditions.checkNotNull;
/**
*
* @author Adrian Cole
*/
public class RangeHardwareProperty extends ParameterizedHardwareProperty {
private final Number first;
private final Number last;
public RangeHardwareProperty(String name, String unit, Number value, HardwareParameter param, Number first,
Number last) {
super(Kind.FIXED, name, unit, value, param);
this.first = checkNotNull(first, "first");
this.last = checkNotNull(last, "last");
}
/**
*
* @return minimum value
*/
public Number getFirst() {
return first;
}
/**
*
* @return maximum value
*/
public Number getLast() {
return last;
}
@Override
public String toString() {
return "[kind=" + getKind() + ", name=" + getName() + ", unit=" + getUnit() + ", value=" + getValue()
+ ", param=" + getParam() + ", first=" + first + ", last=" + last + "]";
}
@Override
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
result = prime * result + ((first == null) ? 0 : first.hashCode());
result = prime * result + ((last == null) ? 0 : last.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (!super.equals(obj))
return false;
if (getClass() != obj.getClass())
return false;
RangeHardwareProperty other = (RangeHardwareProperty) obj;
if (first == null) {
if (other.first != null)
return false;
} else if (!first.equals(other.first))
return false;
if (last == null) {
if (other.last != null)
return false;
} else if (!last.equals(other.last))
return false;
return true;
}
}

View File

@ -1,172 +0,0 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.deltacloud.domain;
import static com.google.common.base.Preconditions.checkNotNull;
import java.net.URI;
import org.jclouds.javax.annotation.Nullable;
/**
* Within a cloud provider a realm represents a boundary containing resources. The exact definition
* of a realm is left to the cloud provider. In some cases, a realm may represent different
* datacenters, different continents, or different pools of resources within a single datacenter. A
* cloud provider may insist that resources must all exist within a single realm in order to
* cooperate. For instance, storage volumes may only be allowed to be mounted to instances within
* the same realm.
*
* @author Adrian Cole
*/
public class Realm {
public enum State {
/**
* the realm is available
*/
AVAILABLE,
/**
* the realm is unavailable
*/
UNAVAILABLE,
/**
* state returned as something besides the above.
*/
UNRECOGNIZED;
public static State fromValue(String state) {
try {
return valueOf(checkNotNull(state, "state"));
} catch (IllegalArgumentException e) {
return UNRECOGNIZED;
}
}
}
private final URI href;
private final String id;
@Nullable
private final String limit;
private final String name;
private final State state;
public Realm(URI href, String id, String name, @Nullable String limit, State state) {
this.href = checkNotNull(href, "href");
this.id = checkNotNull(id, "id");
this.name = checkNotNull(name, "name");
this.limit = limit;
this.state = checkNotNull(state, "state");
}
/**
*
* @return URL to manipulate a specific realm
*/
public URI getHref() {
return href;
}
/**
*
* @return A unique identifier for the realm
*/
public String getId() {
return id;
}
/**
*
* @return A short label
*/
public String getName() {
return name;
}
/**
* for example limitation of how many machine you can launch in given region / how much computing
* power is available for you.
*
* @return Limits applicable for the current requester
*/
@Nullable
public String getLimit() {
return limit;
}
/**
*
* @return indicator of the realm's current state
*/
public State getState() {
return state;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((href == null) ? 0 : href.hashCode());
result = prime * result + ((id == null) ? 0 : id.hashCode());
result = prime * result + ((limit == null) ? 0 : limit.hashCode());
result = prime * result + ((name == null) ? 0 : name.hashCode());
result = prime * result + ((state == null) ? 0 : state.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;
Realm other = (Realm) obj;
if (href == null) {
if (other.href != null)
return false;
} else if (!href.equals(other.href))
return false;
if (id == null) {
if (other.id != null)
return false;
} else if (!id.equals(other.id))
return false;
if (limit == null) {
if (other.limit != null)
return false;
} else if (!limit.equals(other.limit))
return false;
if (name == null) {
if (other.name != null)
return false;
} else if (!name.equals(other.name))
return false;
if (state != other.state)
return false;
return true;
}
@Override
public String toString() {
return "[href=" + href + ", id=" + id + ", limit=" + limit + ", name=" + name + ", state=" + state + "]";
}
}

View File

@ -1,27 +0,0 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.deltacloud.domain;
/**
*
* @author Adrian Cole
*/
public interface Transition {
Instance.State getTo();
}

View File

@ -1,67 +0,0 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.deltacloud.domain;
import static com.google.common.base.Preconditions.checkNotNull;
/**
*
* @author Adrian Cole
*/
public class TransitionAutomatically implements Transition {
private final Instance.State to;
public TransitionAutomatically(Instance.State to) {
this.to = checkNotNull(to, "to");
}
public Instance.State getTo() {
return to;
}
@Override
public String toString() {
return "[to=" + to + "]";
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((to == null) ? 0 : to.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;
TransitionAutomatically other = (TransitionAutomatically) obj;
if (to == null) {
if (other.to != null)
return false;
} else if (!to.equals(other.to))
return false;
return true;
}
}

View File

@ -1,76 +0,0 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.deltacloud.domain;
import static com.google.common.base.Preconditions.checkNotNull;
/**
*
* @author Adrian Cole
*/
public class TransitionOnAction implements Transition {
private final Instance.Action action;
private final Instance.State to;
public TransitionOnAction(Instance.Action action, Instance.State to) {
this.to = checkNotNull(to, "to");
this.action = checkNotNull(action, "action");
}
public Instance.State getTo() {
return to;
}
public Instance.Action getAction() {
return action;
}
@Override
public String toString() {
return "[action=" + action + ", to=" + to + "]";
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((action == null) ? 0 : action.hashCode());
result = prime * result + ((to == null) ? 0 : to.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;
TransitionOnAction other = (TransitionOnAction) obj;
if (action == null) {
if (other.action != null)
return false;
} else if (!action.equals(other.action))
return false;
if (to != other.to)
return false;
return true;
}
}

View File

@ -1,119 +0,0 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.deltacloud.domain.internal;
import static com.google.common.base.Preconditions.checkNotNull;
import org.jclouds.deltacloud.domain.HardwareProperty;
/**
*
* @author Adrian Cole
*/
public class BaseHardwareProperty implements HardwareProperty {
private final Kind kind;
private final String name;
private final String unit;
private final Object value;
public BaseHardwareProperty(Kind kind, String name, String unit, Object value) {
this.kind = checkNotNull(kind, "kind");
this.name = checkNotNull(name, "name");
this.unit = checkNotNull(unit, "unit");
this.value = checkNotNull(value, "value");
}
/**
* {@inheritDoc}
*/
@Override
public Kind getKind() {
return kind;
}
/**
* {@inheritDoc}
*/
@Override
public String getName() {
return name;
}
/**
* {@inheritDoc}
*/
@Override
public String getUnit() {
return unit;
}
/**
* {@inheritDoc}
*/
@Override
public Object getValue() {
return value;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((kind == null) ? 0 : kind.hashCode());
result = prime * result + ((name == null) ? 0 : name.hashCode());
result = prime * result + ((unit == null) ? 0 : unit.hashCode());
result = prime * result + ((value == null) ? 0 : value.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;
BaseHardwareProperty other = (BaseHardwareProperty) obj;
if (kind != other.kind)
return false;
if (name == null) {
if (other.name != null)
return false;
} else if (!name.equals(other.name))
return false;
if (unit == null) {
if (other.unit != null)
return false;
} else if (!unit.equals(other.unit))
return false;
if (value == null) {
if (other.value != null)
return false;
} else if (!value.equals(other.value))
return false;
return true;
}
@Override
public String toString() {
return "[kind=" + kind + ", name=" + name + ", unit=" + unit + ", value=" + value + "]";
}
}

View File

@ -1,100 +0,0 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.deltacloud.handlers;
import java.io.IOException;
import javax.annotation.Resource;
import javax.inject.Singleton;
import org.jclouds.http.HttpCommand;
import org.jclouds.http.HttpErrorHandler;
import org.jclouds.http.HttpResponse;
import org.jclouds.http.HttpResponseException;
import org.jclouds.logging.Logger;
import org.jclouds.rest.AuthorizationException;
import org.jclouds.rest.ResourceNotFoundException;
import org.jclouds.util.Strings2;
import com.google.common.base.Throwables;
import com.google.common.io.Closeables;
/**
*
* @author Adrian Cole
*
*/
@Singleton
public class DeltacloudErrorHandler implements HttpErrorHandler {
@Resource
protected Logger logger = Logger.NULL;
public void handleError(HttpCommand command, HttpResponse response) {
// it is important to always read fully and close streams
String message = parseMessage(response);
Exception exception = message != null ? new HttpResponseException(command, response, message)
: new HttpResponseException(command, response);
try {
message = message != null ? message : String.format("%s -> %s", command.getCurrentRequest().getRequestLine(),
response.getStatusLine());
if (message.indexOf("ItemNotFound") != -1) {
exception = new ResourceNotFoundException(message, exception);
} else {
switch (response.getStatusCode()) {
case 400:
exception = new IllegalArgumentException(message, exception);
break;
case 401:
exception = new AuthorizationException(message, exception);
break;
case 404:
if (!command.getCurrentRequest().getMethod().equals("DELETE")) {
exception = new ResourceNotFoundException(message, exception);
}
break;
case 405:
exception = new IllegalArgumentException(message, exception);
break;
case 409:
exception = new IllegalStateException(message, exception);
break;
}
}
} finally {
Closeables.closeQuietly(response.getPayload());
command.setException(exception);
}
}
public String parseMessage(HttpResponse response) {
if (response.getPayload() == null)
return null;
try {
return Strings2.toString(response.getPayload());
} catch (IOException e) {
throw new RuntimeException(e);
} finally {
try {
response.getPayload().getInput().close();
} catch (IOException e) {
Throwables.propagate(e);
}
}
}
}

View File

@ -1,50 +0,0 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.deltacloud.handlers;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.http.HttpCommand;
import org.jclouds.http.HttpResponse;
import org.jclouds.http.handlers.BackoffLimitedRetryHandler;
import org.jclouds.http.handlers.RedirectionRetryHandler;
/**
* Handles Retryable responses with error codes in the 3xx range
*
* @author Adrian Cole
*/
@Singleton
public class DeltacloudRedirectionRetryHandler extends RedirectionRetryHandler {
@Inject
public DeltacloudRedirectionRetryHandler(BackoffLimitedRetryHandler backoffHandler) {
super(backoffHandler);
}
@Override
public boolean shouldRetryRequest(HttpCommand command, HttpResponse response) {
if (command.getCurrentRequest().getMethod().equals("DELETE")) {
return false;
} else {
return super.shouldRetryRequest(command, response);
}
}
}

View File

@ -1,101 +0,0 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.deltacloud.options;
import static com.google.common.base.Preconditions.checkNotNull;
import org.jclouds.http.options.BaseHttpRequestOptions;
/**
* Contains options supported in the Deltacloud API for the Create Instance operation. <h2>
* Usage</h2> The recommended way to instantiate a CreateInstanceOptions object is to statically
* import CreateInstanceOptions.Builder.* and invoke a static creation method followed by an
* instance mutator (if needed):
* <p/>
* <code>
* import static org.jclouds.deltacloud.options.CreateInstanceOptions.Builder.*
* <p/>
* DeltacloudClient connection = // get connection
* ListenableFuture<Instance> instance = client.createInstance(collection, "imageId", named("robot"));
* <code>
*
* @author Adrian Cole
* @see <a href="http://deltacloud.org/api.html#h1" />
*/
public class CreateInstanceOptions extends BaseHttpRequestOptions {
public static final CreateInstanceOptions NONE = new CreateInstanceOptions();
/**
* A short label to identify the instance.
*
*/
public CreateInstanceOptions named(String name) {
formParameters.put("name", checkNotNull(name, "name"));
return this;
}
/**
* The realm in which to launch the instance
*
*/
public CreateInstanceOptions realm(String realmId) {
formParameters.put("realm_id", checkNotNull(realmId, "realmId"));
return this;
}
/**
* The hardware profile upon which to launch the instance
*/
public CreateInstanceOptions hardwareProfile(String hwpName) {
formParameters.put("hwp_name", checkNotNull(hwpName, "hwpName"));
return this;
}
public String getName() {
return this.getFirstFormOrNull("name");
}
public static class Builder {
/**
* @see CreateInstanceOptions#named
*/
public static CreateInstanceOptions named(String name) {
CreateInstanceOptions options = new CreateInstanceOptions();
return options.named(name);
}
/**
* @see CreateInstanceOptions#realm
*/
public static CreateInstanceOptions realm(String realmId) {
CreateInstanceOptions options = new CreateInstanceOptions();
return options.realm(realmId);
}
/**
* @see CreateInstanceOptions#hardwareProfile
*/
public static CreateInstanceOptions hardwareProfile(String hwpName) {
CreateInstanceOptions options = new CreateInstanceOptions();
return options.hardwareProfile(hwpName);
}
}
}

View File

@ -1,47 +0,0 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.deltacloud.predicates;
import javax.inject.Singleton;
import org.jclouds.deltacloud.DeltacloudClient;
import org.jclouds.deltacloud.domain.Instance;
import com.google.inject.Inject;
/**
*
* Tests to see if a instance is terminated
*
* @author Adrian Cole
*/
@Singleton
public class InstanceFinished extends InstanceState {
@Inject
public InstanceFinished(DeltacloudClient client) {
super(client);
}
@Override
protected Instance.State getState() {
return Instance.State.FINISH;
}
}

View File

@ -1,47 +0,0 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.deltacloud.predicates;
import javax.inject.Singleton;
import org.jclouds.deltacloud.DeltacloudClient;
import org.jclouds.deltacloud.domain.Instance;
import com.google.inject.Inject;
/**
*
* Tests to see if a instance is running
*
* @author Adrian Cole
*/
@Singleton
public class InstanceRunning extends InstanceState {
@Inject
public InstanceRunning(DeltacloudClient client) {
super(client);
}
@Override
protected Instance.State getState() {
return Instance.State.RUNNING;
}
}

View File

@ -1,67 +0,0 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.deltacloud.predicates;
import static com.google.common.base.Preconditions.checkNotNull;
import javax.annotation.Resource;
import javax.inject.Singleton;
import org.jclouds.deltacloud.DeltacloudClient;
import org.jclouds.deltacloud.domain.Instance;
import org.jclouds.logging.Logger;
import com.google.common.base.Predicate;
import com.google.inject.Inject;
/**
*
* Tests to see if a instance is at a specific state
*
* @author Adrian Cole
*/
@Singleton
public abstract class InstanceState implements Predicate<Instance> {
private final DeltacloudClient client;
@Resource
protected Logger logger = Logger.NULL;
@Inject
public InstanceState(DeltacloudClient client) {
this.client = client;
}
public boolean apply(Instance instance) {
logger.trace("looking for state on instance %s", checkNotNull(instance, "instance"));
instance = refresh(instance);
if (instance == null || instance.getState() == Instance.State.FINISH)
return false;
logger.trace("%s: looking for instance state %s: currently: %s", instance.getId(), getState(), instance
.getState());
return instance.getState() == getState();
}
protected abstract Instance.State getState();
private Instance refresh(Instance instance) {
return client.getInstance(instance.getHref());
}
}

View File

@ -1,69 +0,0 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.deltacloud.xml;
import java.net.URI;
import java.util.Map;
import java.util.Set;
import org.jclouds.deltacloud.domain.DeltacloudCollection;
import org.jclouds.deltacloud.domain.Feature;
import org.jclouds.http.functions.ParseSax;
import org.jclouds.util.SaxUtils;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import com.google.common.collect.Sets;
/**
* @author Adrian Cole
*/
public class DeltacloudCollectionHandler extends ParseSax.HandlerWithResult<DeltacloudCollection> {
private URI href;
private String rel;
private Set<Feature> features = Sets.newLinkedHashSet();
private DeltacloudCollection realm;
public DeltacloudCollection getResult() {
return realm;
}
@Override
public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException {
Map<String, String> attributes = SaxUtils.cleanseAttributes(attrs);
if (qName.equalsIgnoreCase("link")) {
this.href = URI.create(attributes.get("href"));
this.rel = attributes.get("rel");
} else if (qName.equalsIgnoreCase("feature")) {
features.add(new Feature(attributes.get("name")));
}
}
@Override
public void endElement(String uri, String localName, String qName) throws SAXException {
if (qName.equalsIgnoreCase("link")) {
this.realm = new DeltacloudCollection(href, rel, features);
this.href = null;
this.rel = null;
this.features = Sets.newLinkedHashSet();
}
}
}

View File

@ -1,67 +0,0 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.deltacloud.xml;
import java.util.Set;
import javax.inject.Inject;
import org.jclouds.deltacloud.domain.DeltacloudCollection;
import org.jclouds.http.functions.ParseSax;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import com.google.common.collect.Sets;
/**
* @author Adrian Cole
*/
public class DeltacloudCollectionsHandler extends ParseSax.HandlerWithResult<Set<? extends DeltacloudCollection>> {
private StringBuilder currentText = new StringBuilder();
private Set<DeltacloudCollection> links = Sets.newLinkedHashSet();
private final DeltacloudCollectionHandler linkHandler;
@Inject
public DeltacloudCollectionsHandler(DeltacloudCollectionHandler linkHandler) {
this.linkHandler = linkHandler;
}
public Set<? extends DeltacloudCollection> getResult() {
return links;
}
@Override
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
linkHandler.startElement(uri, localName, qName, attributes);
}
@Override
public void endElement(String uri, String localName, String qName) throws SAXException {
linkHandler.endElement(uri, localName, qName);
if (qName.equals("link") && currentText.toString().trim().equals("")) {
this.links.add(linkHandler.getResult());
}
currentText = new StringBuilder();
}
public void characters(char ch[], int start, int length) {
currentText.append(ch, start, length);
}
}

View File

@ -1,102 +0,0 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.deltacloud.xml;
import java.net.URI;
import java.util.Map;
import java.util.Set;
import javax.inject.Inject;
import org.jclouds.deltacloud.domain.HardwareProfile;
import org.jclouds.deltacloud.domain.HardwareProperty;
import org.jclouds.http.functions.ParseSax;
import org.jclouds.util.SaxUtils;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import com.google.common.collect.Sets;
/**
* @author Adrian Cole
*/
public class HardwareProfileHandler extends ParseSax.HandlerWithResult<HardwareProfile> {
private StringBuilder currentText = new StringBuilder();
private final HardwarePropertyHandler propertyHandler;
@Inject
HardwareProfileHandler(HardwarePropertyHandler propertyHandler) {
this.propertyHandler = propertyHandler;
}
private URI href;
private String id;
private String name;
private Set<HardwareProperty> properties = Sets.newLinkedHashSet();
private boolean inProperty;
private HardwareProfile profile;
public HardwareProfile getResult() {
return profile;
}
@Override
public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException {
Map<String, String> attributes = SaxUtils.cleanseAttributes(attrs);
if (qName.equals("property")) {
inProperty = true;
}
if (inProperty) {
propertyHandler.startElement(uri, localName, qName, attrs);
} else if (qName.equals("hardware_profile")) {
String href = attributes.get("href");
if (href != null) {
this.href = URI.create(href);
}
this.id = attributes.get("id");
}
}
@Override
public void endElement(String uri, String localName, String qName) throws SAXException {
if (inProperty)
propertyHandler.endElement(uri, localName, qName);
if (qName.endsWith("property")) {
inProperty = false;
this.properties.add(propertyHandler.getResult());
} else if (qName.equalsIgnoreCase("name")) {
this.name = currentText.toString().trim();
} else if (qName.equalsIgnoreCase("hardware_profile")) {
this.profile = new HardwareProfile(href, id, name, properties);
this.href = null;
this.id = null;
this.name = null;
this.properties = Sets.newLinkedHashSet();
}
currentText = new StringBuilder();
}
public void characters(char ch[], int start, int length) {
currentText.append(ch, start, length);
}
}

View File

@ -1,68 +0,0 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.deltacloud.xml;
import java.util.Set;
import javax.inject.Inject;
import org.jclouds.deltacloud.domain.HardwareProfile;
import org.jclouds.http.functions.ParseSax;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import com.google.common.collect.Sets;
/**
* @author Adrian Cole
*/
public class HardwareProfilesHandler extends ParseSax.HandlerWithResult<Set<? extends HardwareProfile>> {
private StringBuilder currentText = new StringBuilder();
private Set<HardwareProfile> hardwareProfiles = Sets.newLinkedHashSet();
private final HardwareProfileHandler hardwareProfileHandler;
@Inject
public HardwareProfilesHandler(HardwareProfileHandler locationHandler) {
this.hardwareProfileHandler = locationHandler;
}
public Set<? extends HardwareProfile> getResult() {
return hardwareProfiles;
}
@Override
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
hardwareProfileHandler.startElement(uri, localName, qName, attributes);
}
@Override
public void endElement(String uri, String localName, String qName) throws SAXException {
hardwareProfileHandler.endElement(uri, localName, qName);
if (qName.equals("hardware_profile") && currentText.toString().trim().equals("")) {
this.hardwareProfiles.add(hardwareProfileHandler.getResult());
}
currentText = new StringBuilder();
}
public void characters(char ch[], int start, int length) {
hardwareProfileHandler.characters(ch, start, length);
currentText.append(ch, start, length);
}
}

View File

@ -1,119 +0,0 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.deltacloud.xml;
import java.net.URI;
import java.util.Map;
import java.util.Set;
import java.util.regex.Pattern;
import org.jclouds.deltacloud.domain.EnumHardwareProperty;
import org.jclouds.deltacloud.domain.FixedHardwareProperty;
import org.jclouds.deltacloud.domain.HardwareParameter;
import org.jclouds.deltacloud.domain.HardwareProperty;
import org.jclouds.deltacloud.domain.RangeHardwareProperty;
import org.jclouds.deltacloud.domain.HardwareProperty.Kind;
import org.jclouds.http.functions.ParseSax;
import org.jclouds.javax.annotation.Nullable;
import org.jclouds.util.SaxUtils;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import com.google.common.collect.Sets;
/**
* @author Adrian Cole
*/
public class HardwarePropertyHandler extends ParseSax.HandlerWithResult<HardwareProperty> {
private Kind kind;
private String name;
private String unit;
private Object value;
private HardwareParameter param;
private Set<Object> availableValues = Sets.newLinkedHashSet();
private Number first;
private Number last;
/**
* resets state of the handler when called.
*
* @return property or null
*/
public HardwareProperty getResult() {
try {
switch (kind) {
case FIXED:
return new FixedHardwareProperty(name, unit, value);
case ENUM:
return new EnumHardwareProperty(name, unit, value, param, availableValues);
case RANGE:
return new RangeHardwareProperty(name, unit, (Number) value, param, first, last);
default:
return null;
}
} finally {
this.kind = null;
this.name = null;
this.unit = null;
this.value = null;
this.param = null;
this.availableValues = Sets.newLinkedHashSet();
this.first = null;
this.last = null;
}
}
private static final Pattern LONG = Pattern.compile("^[0-9]+$");
private static final Pattern DOUBLE = Pattern.compile("^[0-9]+\\.[0-9]+$");
@Nullable public static
Number parseNumberOrNull(String in) {
if (DOUBLE.matcher(in).matches())
return new Double(in);
else if (LONG.matcher(in).matches())
return Long.valueOf(in);
return null;
}
@Override
public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException {
Map<String, String> attributes = SaxUtils.cleanseAttributes(attrs);
if (qName.equals("property")) {
this.kind = Kind.fromValue(attributes.get("kind"));
this.name = attributes.get("name");
this.unit = attributes.get("unit");
if (attributes.containsKey("value")) {
this.value = stringOrNumber(attributes.get("value"));
}
} else if (qName.equals("param")) {
this.param = new HardwareParameter(URI.create(attributes.get("href")), attributes.get("method"),
attributes.get("name"), attributes.get("operation"));
} else if (qName.equals("range")) {
this.first = parseNumberOrNull(attributes.get("first"));
this.last = parseNumberOrNull(attributes.get("last"));
} else if (qName.equals("entry")) {
this.availableValues.add(stringOrNumber(attributes.get("value")));
}
}
public static Object stringOrNumber(String in) {
Number number = parseNumberOrNull(in);
return number != null ? number : in;
}
}

View File

@ -1,86 +0,0 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.deltacloud.xml;
import java.net.URI;
import java.util.Map;
import org.jclouds.deltacloud.domain.Image;
import org.jclouds.http.functions.ParseSax;
import org.jclouds.util.SaxUtils;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
/**
* @author Adrian Cole
*/
public class ImageHandler extends ParseSax.HandlerWithResult<Image> {
private StringBuilder currentText = new StringBuilder();
private URI href;
private String id;
private String ownerId;
private String name;
private String description;
private String architecture;
private Image image;
public Image getResult() {
return image;
}
@Override
public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException {
Map<String, String> attributes = SaxUtils.cleanseAttributes(attrs);
if (qName.equals("image")) {
String href = attributes.get("href");
if (href != null) {
this.href = URI.create(href);
}
this.id = attributes.get("id");
}
}
@Override
public void endElement(String uri, String localName, String qName) throws SAXException {
if (qName.equalsIgnoreCase("owner_id")) {
this.ownerId = currentText.toString().trim();
} else if (qName.equalsIgnoreCase("name")) {
this.name = currentText.toString().trim();
} else if (qName.equalsIgnoreCase("description")) {
this.description = currentText.toString().trim();
} else if (qName.equalsIgnoreCase("architecture")) {
this.architecture = currentText.toString().trim();
} else if (qName.equalsIgnoreCase("image")) {
this.image = new Image(href, id, ownerId, name, description, architecture);
this.href = null;
this.id = null;
this.ownerId = null;
this.name = null;
this.description = null;
this.architecture = null;
}
currentText = new StringBuilder();
}
public void characters(char ch[], int start, int length) {
currentText.append(ch, start, length);
}
}

View File

@ -1,68 +0,0 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.deltacloud.xml;
import java.util.Set;
import javax.inject.Inject;
import org.jclouds.deltacloud.domain.Image;
import org.jclouds.http.functions.ParseSax;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import com.google.common.collect.Sets;
/**
* @author Adrian Cole
*/
public class ImagesHandler extends ParseSax.HandlerWithResult<Set<? extends Image>> {
private StringBuilder currentText = new StringBuilder();
private Set<Image> images = Sets.newLinkedHashSet();
private final ImageHandler imageHandler;
@Inject
public ImagesHandler(ImageHandler locationHandler) {
this.imageHandler = locationHandler;
}
public Set<? extends Image> getResult() {
return images;
}
@Override
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
imageHandler.startElement(uri, localName, qName, attributes);
}
@Override
public void endElement(String uri, String localName, String qName) throws SAXException {
imageHandler.endElement(uri, localName, qName);
if (qName.equals("image") && currentText.toString().trim().equals("")) {
this.images.add(imageHandler.getResult());
}
currentText = new StringBuilder();
}
public void characters(char ch[], int start, int length) {
imageHandler.characters(ch, start, length);
currentText.append(ch, start, length);
}
}

View File

@ -1,171 +0,0 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.deltacloud.xml;
import static org.jclouds.util.SaxUtils.currentOrNull;
import java.net.URI;
import java.util.Map;
import java.util.Set;
import javax.annotation.Resource;
import org.jclouds.deltacloud.domain.Instance;
import org.jclouds.deltacloud.domain.KeyAuthentication;
import org.jclouds.deltacloud.domain.PasswordAuthentication;
import org.jclouds.deltacloud.domain.Instance.Authentication;
import org.jclouds.domain.LoginCredentials;
import org.jclouds.domain.LoginCredentials.Builder;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.functions.ParseSax;
import org.jclouds.logging.Logger;
import org.jclouds.util.SaxUtils;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
/**
* @author Adrian Cole
*/
public class InstanceHandler extends ParseSax.HandlerWithResult<Instance> {
private StringBuilder currentText = new StringBuilder();
@Resource
protected Logger logger = Logger.NULL;
private URI href;
private String id;
private String ownerId;
private String name;
private URI image;
private URI hardwareProfile;
private URI realm;
private Instance.State state;
private Map<Instance.Action, HttpRequest> actions = Maps.newLinkedHashMap();
private Set<String> publicAddresses = Sets.newLinkedHashSet();
private Set<String> privateAddresses = Sets.newLinkedHashSet();
private boolean inPublicAddresses;
private boolean inPrivateAddresses;
private Instance instance;
private Builder credentialsBuilder = LoginCredentials.builder();
private String keyName;
private Authentication authentication;
public Instance getResult() {
return instance;
}
@Override
public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException {
Map<String, String> attributes = SaxUtils.cleanseAttributes(attrs);
if (qName.equals("public_addresses")) {
inPublicAddresses = true;
} else if (qName.equals("private_addresses")) {
inPrivateAddresses = true;
} else if (qName.equals("instance")) {
String href = attributes.get("href");
if (href != null) {
this.href = URI.create(href);
}
this.id = attributes.get("id");
} else if (qName.equals("link")) {
try {
Instance.Action action = Instance.Action.fromValue(attributes.get("rel"));
if (action != Instance.Action.UNRECOGNIZED) {
HttpRequest request = HttpRequest.builder().method(attributes.get("method").toUpperCase()).endpoint(attributes
.get("href")).build();
actions.put(action, request);
}
} catch (RuntimeException e) {
if (logger.isDebugEnabled())
logger.warn(e, "error parsing into action: %s, %s", qName, attributes);
}
} else if (attributes.containsKey("href")) {
URI href = URI.create(attributes.get("href"));
if (qName.equals("image"))
this.image = href;
else if (qName.equals("hardware_profile"))
this.hardwareProfile = href;
else if (qName.equals("realm"))
this.realm = href;
}
}
@Override
public void endElement(String uri, String localName, String qName) throws SAXException {
if (qName.endsWith("public_addresses")) {
inPublicAddresses = false;
} else if (qName.endsWith("private_addresses")) {
inPrivateAddresses = false;
}
if (qName.equalsIgnoreCase("owner_id")) {
this.ownerId = currentOrNull(currentText);
} else if (qName.equalsIgnoreCase("name")) {
this.name = currentOrNull(currentText);
} else if (qName.equalsIgnoreCase("keyname")) {
this.keyName = currentOrNull(currentText);
} else if (qName.equalsIgnoreCase("username")) {
this.credentialsBuilder.user(currentOrNull(currentText));
} else if (qName.equalsIgnoreCase("password")) {
this.credentialsBuilder.password(currentOrNull(currentText));
} else if (qName.equalsIgnoreCase("authentication")) {
if (keyName != null) {
this.authentication = new KeyAuthentication(keyName);
} else {
LoginCredentials creds = credentialsBuilder.build();
if (creds != null && creds.identity != null)
this.authentication = new PasswordAuthentication(creds);
}
this.keyName = null;
this.credentialsBuilder = LoginCredentials.builder();
} else if (qName.equalsIgnoreCase("state")) {
this.state = Instance.State.fromValue(currentOrNull(currentText));
} else if (qName.equalsIgnoreCase("address")) {
if (inPublicAddresses)
this.publicAddresses.add(currentOrNull(currentText));
else if (inPrivateAddresses)
this.privateAddresses.add(currentOrNull(currentText));
} else if (qName.equalsIgnoreCase("instance")) {
this.instance = new Instance(href, id, ownerId, name, image, hardwareProfile, realm, state, actions,
authentication, publicAddresses, privateAddresses);
this.href = null;
this.id = null;
this.ownerId = null;
this.name = null;
this.image = null;
this.hardwareProfile = null;
this.realm = null;
this.state = null;
this.authentication = null;
this.actions = Maps.newLinkedHashMap();
this.publicAddresses = Sets.newLinkedHashSet();
this.privateAddresses = Sets.newLinkedHashSet();
}
currentText = new StringBuilder();
}
public void characters(char ch[], int start, int length) {
currentText.append(ch, start, length);
}
}

View File

@ -1,82 +0,0 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.deltacloud.xml;
import java.util.Map;
import javax.annotation.Resource;
import org.jclouds.deltacloud.domain.Transition;
import org.jclouds.deltacloud.domain.TransitionAutomatically;
import org.jclouds.deltacloud.domain.TransitionOnAction;
import org.jclouds.deltacloud.domain.Instance.Action;
import org.jclouds.deltacloud.domain.Instance.State;
import org.jclouds.http.functions.ParseSax;
import org.jclouds.logging.Logger;
import org.jclouds.util.SaxUtils;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import com.google.common.collect.LinkedHashMultimap;
import com.google.common.collect.Multimap;
/**
* @author Adrian Cole
*/
public class InstanceStatesHandler extends ParseSax.HandlerWithResult<Multimap<State, ? extends Transition>> {
@Resource
protected Logger logger = Logger.NULL;
private Multimap<State, Transition> states = LinkedHashMultimap.create();
private State state;
public Multimap<State, ? extends Transition> getResult() {
return states;
}
@Override
public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException {
Map<String, String> attributes = SaxUtils.cleanseAttributes(attrs);
if (qName.equals("state")) {
state = instanceStateWarningOnUnrecognized(attributes.get("name"));
} else if (qName.equals("transition")) {
if (attributes.containsKey("auto"))
states.put(state, new TransitionAutomatically(instanceStateWarningOnUnrecognized(attributes.get("to"))));
else
states.put(state, new TransitionOnAction(instanceActionWarningOnUnrecognized(attributes.get("action")),
instanceStateWarningOnUnrecognized(attributes.get("to"))));
}
}
State instanceStateWarningOnUnrecognized(String input) {
State state = State.fromValue(input);
if (state == State.UNRECOGNIZED)
logger.warn("unrecognized state: %s", input);
return state;
}
Action instanceActionWarningOnUnrecognized(String input) {
Action action = Action.fromValue(input);
if (action == Action.UNRECOGNIZED)
logger.warn("unrecognized action: %s", input);
return action;
}
}

View File

@ -1,68 +0,0 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.deltacloud.xml;
import java.util.Set;
import javax.inject.Inject;
import org.jclouds.deltacloud.domain.Instance;
import org.jclouds.http.functions.ParseSax;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import com.google.common.collect.Sets;
/**
* @author Adrian Cole
*/
public class InstancesHandler extends ParseSax.HandlerWithResult<Set<? extends Instance>> {
private StringBuilder currentText = new StringBuilder();
private Set<Instance> instances = Sets.newLinkedHashSet();
private final InstanceHandler instanceHandler;
@Inject
public InstancesHandler(InstanceHandler locationHandler) {
this.instanceHandler = locationHandler;
}
public Set<? extends Instance> getResult() {
return instances;
}
@Override
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
instanceHandler.startElement(uri, localName, qName, attributes);
}
@Override
public void endElement(String uri, String localName, String qName) throws SAXException {
instanceHandler.endElement(uri, localName, qName);
if (qName.equals("instance") && currentText.toString().trim().equals("")) {
this.instances.add(instanceHandler.getResult());
}
currentText = new StringBuilder();
}
public void characters(char ch[], int start, int length) {
instanceHandler.characters(ch, start, length);
currentText.append(ch, start, length);
}
}

View File

@ -1,82 +0,0 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.deltacloud.xml;
import java.net.URI;
import java.util.Map;
import org.jclouds.deltacloud.domain.Realm;
import org.jclouds.deltacloud.domain.Realm.State;
import org.jclouds.http.functions.ParseSax;
import org.jclouds.util.SaxUtils;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
/**
* @author Adrian Cole
*/
public class RealmHandler extends ParseSax.HandlerWithResult<Realm> {
private StringBuilder currentText = new StringBuilder();
private URI href;
private String id;
private String name;
private String limit;
private State state;
private Realm realm;
public Realm getResult() {
return realm;
}
@Override
public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException {
Map<String, String> attributes = SaxUtils.cleanseAttributes(attrs);
if (attributes.containsKey("href")) {
this.href = URI.create(attributes.get("href"));
this.id = attributes.get("id");
}
}
@Override
public void endElement(String uri, String localName, String qName) throws SAXException {
if (qName.equalsIgnoreCase("limit")) {
this.limit = currentText.toString().trim();
if ("".equals(limit))
limit = null;
} else if (qName.equalsIgnoreCase("name")) {
this.name = currentText.toString().trim();
} else if (qName.equalsIgnoreCase("state")) {
this.state = State.fromValue(currentText.toString().trim());
} else if (qName.equalsIgnoreCase("realm")) {
this.realm = new Realm(href, id, name, limit, state);
this.href = null;
this.id = null;
this.name = null;
this.limit = null;
this.state = null;
}
currentText = new StringBuilder();
}
public void characters(char ch[], int start, int length) {
currentText.append(ch, start, length);
}
}

View File

@ -1,68 +0,0 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.deltacloud.xml;
import java.util.Set;
import javax.inject.Inject;
import org.jclouds.deltacloud.domain.Realm;
import org.jclouds.http.functions.ParseSax;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import com.google.common.collect.Sets;
/**
* @author Adrian Cole
*/
public class RealmsHandler extends ParseSax.HandlerWithResult<Set<? extends Realm>> {
private StringBuilder currentText = new StringBuilder();
private Set<Realm> realms = Sets.newLinkedHashSet();
private final RealmHandler realmHandler;
@Inject
public RealmsHandler(RealmHandler realmHandler) {
this.realmHandler = realmHandler;
}
public Set<? extends Realm> getResult() {
return realms;
}
@Override
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
realmHandler.startElement(uri, localName, qName, attributes);
}
@Override
public void endElement(String uri, String localName, String qName) throws SAXException {
realmHandler.endElement(uri, localName, qName);
if (qName.equals("realm") && currentText.toString().trim().equals("")) {
this.realms.add(realmHandler.getResult());
}
currentText = new StringBuilder();
}
public void characters(char ch[], int start, int length) {
realmHandler.characters(ch, start, length);
currentText.append(ch, start, length);
}
}

View File

@ -1 +0,0 @@
org.jclouds.deltacloud.DeltacloudApiMetadata

View File

@ -1,34 +0,0 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.deltacloud;
import org.jclouds.compute.internal.BaseComputeServiceApiMetadataTest;
import org.testng.annotations.Test;
/**
*
* @author Adrian Cole
*/
@Test(groups = "unit", testName = "DeltacloudApiMetadataTest")
public class DeltacloudApiMetadataTest extends BaseComputeServiceApiMetadataTest {
public DeltacloudApiMetadataTest() {
super(new DeltacloudApiMetadata());
}
}

View File

@ -1,339 +0,0 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.deltacloud;
import static org.testng.Assert.assertEquals;
import java.io.IOException;
import java.lang.reflect.Method;
import java.net.URI;
import java.util.Set;
import org.jclouds.Fallbacks.EmptyMultimapOnNotFoundOr404;
import org.jclouds.Fallbacks.EmptySetOnNotFoundOr404;
import org.jclouds.Fallbacks.NullOnNotFoundOr404;
import org.jclouds.apis.ApiMetadata;
import org.jclouds.deltacloud.DeltacloudFallbacks.VoidOnRedirectedDelete;
import org.jclouds.deltacloud.config.DeltacloudRestClientModule;
import org.jclouds.deltacloud.domain.DeltacloudCollection;
import org.jclouds.deltacloud.options.CreateInstanceOptions;
import org.jclouds.deltacloud.xml.DeltacloudCollectionsHandler;
import org.jclouds.deltacloud.xml.HardwareProfileHandler;
import org.jclouds.deltacloud.xml.HardwareProfilesHandler;
import org.jclouds.deltacloud.xml.ImageHandler;
import org.jclouds.deltacloud.xml.ImagesHandler;
import org.jclouds.deltacloud.xml.InstanceHandler;
import org.jclouds.deltacloud.xml.InstanceStatesHandler;
import org.jclouds.deltacloud.xml.InstancesHandler;
import org.jclouds.deltacloud.xml.RealmHandler;
import org.jclouds.deltacloud.xml.RealmsHandler;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.filters.BasicAuthentication;
import org.jclouds.http.functions.ParseSax;
import org.jclouds.http.functions.ReleasePayloadAndReturn;
import org.jclouds.rest.ConfiguresRestClient;
import org.jclouds.rest.internal.BaseAsyncClientTest;
import org.jclouds.rest.internal.GeneratedHttpRequest;
import org.jclouds.rest.internal.RestAnnotationProcessor;
import org.testng.annotations.Test;
import com.google.common.base.Supplier;
import com.google.common.base.Suppliers;
import com.google.common.collect.Iterables;
import com.google.inject.Module;
import com.google.inject.TypeLiteral;
/**
* Tests behavior of {@code DeltacloudAsyncClient}
*
* @author Adrian Cole
*/
// NOTE:without testName, this will not call @Before* and fail w/NPE during
// surefire
@Test(groups = "unit", testName = "DeltacloudAsyncClientTest")
public class DeltacloudAsyncClientTest extends BaseAsyncClientTest<DeltacloudAsyncClient> {
public void testGetCollections() throws SecurityException, NoSuchMethodException, IOException {
Method method = DeltacloudAsyncClient.class.getMethod("getCollections");
HttpRequest httpRequest = processor.createRequest(method);
assertRequestLineEquals(httpRequest, "GET http://localhost:3001/api HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/xml\n");
assertPayloadEquals(httpRequest, null, null, false);
// now make sure request filters apply by replaying
httpRequest = Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest);
httpRequest = Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest);
assertRequestLineEquals(httpRequest, "GET http://localhost:3001/api HTTP/1.1");
// for example, using basic authentication, we should get "only one"
// header
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/xml\nAuthorization: Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==\n");
assertPayloadEquals(httpRequest, null, null, false);
assertResponseParserClassEquals(method, httpRequest, ParseSax.class);
assertSaxResponseParserClassEquals(method, DeltacloudCollectionsHandler.class);
assertFallbackClassEquals(method, EmptySetOnNotFoundOr404.class);
checkFilters(httpRequest);
}
public void testGetInstanceStates() throws IOException, SecurityException, NoSuchMethodException {
Method method = DeltacloudAsyncClient.class.getMethod("getInstanceStates");
HttpRequest request = processor.createRequest(method);
assertRequestLineEquals(request, "GET http://localhost:3001/api/instance_states HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/xml\n");
assertPayloadEquals(request, null, null, false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, InstanceStatesHandler.class);
assertFallbackClassEquals(method, EmptyMultimapOnNotFoundOr404.class);
checkFilters(request);
}
public void testListRealms() throws IOException, SecurityException, NoSuchMethodException {
Method method = DeltacloudAsyncClient.class.getMethod("listRealms");
HttpRequest request = processor.createRequest(method);
assertRequestLineEquals(request, "GET http://localhost:3001/api/realms HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/xml\n");
assertPayloadEquals(request, null, null, false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, RealmsHandler.class);
assertFallbackClassEquals(method, EmptySetOnNotFoundOr404.class);
checkFilters(request);
}
public void testGetRealm() throws IOException, SecurityException, NoSuchMethodException {
Method method = DeltacloudAsyncClient.class.getMethod("getRealm", URI.class);
HttpRequest request = processor.createRequest(method, URI.create("https://delta/realm1"));
assertRequestLineEquals(request, "GET https://delta/realm1 HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/xml\n");
assertPayloadEquals(request, null, null, false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, RealmHandler.class);
assertFallbackClassEquals(method, NullOnNotFoundOr404.class);
checkFilters(request);
}
public void testListImages() throws IOException, SecurityException, NoSuchMethodException {
Method method = DeltacloudAsyncClient.class.getMethod("listImages");
HttpRequest request = processor.createRequest(method);
assertRequestLineEquals(request, "GET http://localhost:3001/api/images HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/xml\n");
assertPayloadEquals(request, null, null, false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, ImagesHandler.class);
assertFallbackClassEquals(method, EmptySetOnNotFoundOr404.class);
checkFilters(request);
}
public void testGetImage() throws IOException, SecurityException, NoSuchMethodException {
Method method = DeltacloudAsyncClient.class.getMethod("getImage", URI.class);
HttpRequest request = processor.createRequest(method, URI.create("https://delta/image1"));
assertRequestLineEquals(request, "GET https://delta/image1 HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/xml\n");
assertPayloadEquals(request, null, null, false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, ImageHandler.class);
assertFallbackClassEquals(method, NullOnNotFoundOr404.class);
checkFilters(request);
}
public void testListHardwareProfiles() throws IOException, SecurityException, NoSuchMethodException {
Method method = DeltacloudAsyncClient.class.getMethod("listHardwareProfiles");
HttpRequest request = processor.createRequest(method);
assertRequestLineEquals(request, "GET http://localhost:3001/api/profiles HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/xml\n");
assertPayloadEquals(request, null, null, false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, HardwareProfilesHandler.class);
assertFallbackClassEquals(method, EmptySetOnNotFoundOr404.class);
checkFilters(request);
}
public void testGetHardwareProfile() throws IOException, SecurityException, NoSuchMethodException {
Method method = DeltacloudAsyncClient.class.getMethod("getHardwareProfile", URI.class);
HttpRequest request = processor.createRequest(method, URI.create("https://delta/profile1"));
assertRequestLineEquals(request, "GET https://delta/profile1 HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/xml\n");
assertPayloadEquals(request, null, null, false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, HardwareProfileHandler.class);
assertFallbackClassEquals(method, NullOnNotFoundOr404.class);
checkFilters(request);
}
public void testListInstances() throws IOException, SecurityException, NoSuchMethodException {
Method method = DeltacloudAsyncClient.class.getMethod("listInstances");
HttpRequest request = processor.createRequest(method);
assertRequestLineEquals(request, "GET http://localhost:3001/api/instances HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/xml\n");
assertPayloadEquals(request, null, null, false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, InstancesHandler.class);
assertFallbackClassEquals(method, EmptySetOnNotFoundOr404.class);
checkFilters(request);
}
public void testGetInstance() throws IOException, SecurityException, NoSuchMethodException {
Method method = DeltacloudAsyncClient.class.getMethod("getInstance", URI.class);
HttpRequest request = processor.createRequest(method, URI.create("https://delta/instance1"));
assertRequestLineEquals(request, "GET https://delta/instance1 HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/xml\n");
assertPayloadEquals(request, null, null, false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, InstanceHandler.class);
assertFallbackClassEquals(method, NullOnNotFoundOr404.class);
checkFilters(request);
}
public void testCreateInstance() throws SecurityException, NoSuchMethodException, IOException {
Method method = DeltacloudAsyncClient.class.getMethod("createInstance", String.class,
CreateInstanceOptions[].class);
GeneratedHttpRequest httpRequest = processor.createRequest(method, "imageId-1");
assertRequestLineEquals(httpRequest, "POST http://localhost:3001/api/instances HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/xml\n");
assertPayloadEquals(httpRequest, "image_id=imageId-1", "application/x-www-form-urlencoded", false);
assertResponseParserClassEquals(method, httpRequest, ParseSax.class);
assertSaxResponseParserClassEquals(method, InstanceHandler.class);
assertFallbackClassEquals(method, null);
checkFilters(httpRequest);
}
public void testCreateInstanceWithOptions() throws SecurityException, NoSuchMethodException, IOException {
Method method = DeltacloudAsyncClient.class.getMethod("createInstance", String.class,
CreateInstanceOptions[].class);
GeneratedHttpRequest httpRequest = processor.createRequest(method, "imageId-1",
CreateInstanceOptions.Builder.named("foo"));
assertRequestLineEquals(httpRequest, "POST http://localhost:3001/api/instances HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/xml\n");
assertPayloadEquals(httpRequest, "image_id=imageId-1&name=foo", "application/x-www-form-urlencoded", false);
assertResponseParserClassEquals(method, httpRequest, ParseSax.class);
assertSaxResponseParserClassEquals(method, InstanceHandler.class);
assertFallbackClassEquals(method, null);
checkFilters(httpRequest);
}
public void testPerformAction() throws IOException, SecurityException, NoSuchMethodException {
Method method = DeltacloudAsyncClient.class.getMethod("performAction", HttpRequest.class);
HttpRequest request = processor.createRequest(method,
HttpRequest.builder().method("POST").endpoint("https://delta/instance1/reboot").build());
assertRequestLineEquals(request, "POST https://delta/instance1/reboot HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/xml\n");
assertPayloadEquals(request, null, null, false);
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
assertSaxResponseParserClassEquals(method, null);
assertFallbackClassEquals(method, VoidOnRedirectedDelete.class);
checkFilters(request);
}
@Override
protected void checkFilters(HttpRequest request) {
assertEquals(request.getFilters().size(), 1);
assertEquals(request.getFilters().get(0).getClass(), BasicAuthentication.class);
}
@Override
protected TypeLiteral<RestAnnotationProcessor<DeltacloudAsyncClient>> createTypeLiteral() {
return new TypeLiteral<RestAnnotationProcessor<DeltacloudAsyncClient>>() {
};
}
@Override
protected Module createModule() {
return new DeltacloudRestClientModuleExtension();
}
@ConfiguresRestClient
public static class DeltacloudRestClientModuleExtension extends DeltacloudRestClientModule {
@Override
protected Supplier<Set<? extends DeltacloudCollection>> provideCollections(long seconds, DeltacloudClient client) {
return Suppliers.ofInstance(null);
}
@Override
protected Supplier<URI> provideImageCollection(Supplier<Set<? extends DeltacloudCollection>> collectionSupplier) {
return Suppliers.ofInstance(URI.create("http://localhost:3001/api/images"));
}
@Override
protected Supplier<URI> provideHardwareProfileCollection(
Supplier<Set<? extends DeltacloudCollection>> collectionSupplier) {
return Suppliers.ofInstance(URI.create("http://localhost:3001/api/profiles"));
}
@Override
protected Supplier<URI> provideInstanceCollection(Supplier<Set<? extends DeltacloudCollection>> collectionSupplier) {
return Suppliers.ofInstance(URI.create("http://localhost:3001/api/instances"));
}
@Override
protected Supplier<URI> provideRealmCollection(Supplier<Set<? extends DeltacloudCollection>> collectionSupplier) {
return Suppliers.ofInstance(URI.create("http://localhost:3001/api/realms"));
}
@Override
protected Supplier<URI> provideInstanceStateCollection(
Supplier<Set<? extends DeltacloudCollection>> collectionSupplier) {
return Suppliers.ofInstance(URI.create("http://localhost:3001/api/instance_states"));
}
}
protected ApiMetadata createApiMetadata() {
return new DeltacloudApiMetadata();
}
}

View File

@ -1,159 +0,0 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.deltacloud;
import static org.testng.Assert.assertEquals;
import java.io.IOException;
import java.util.logging.Logger;
import org.jclouds.compute.domain.ExecResponse;
import org.jclouds.deltacloud.domain.Image;
import org.jclouds.deltacloud.domain.Instance;
import org.jclouds.deltacloud.domain.PasswordAuthentication;
import org.jclouds.deltacloud.domain.Transition;
import org.jclouds.deltacloud.domain.TransitionOnAction;
import org.jclouds.deltacloud.options.CreateInstanceOptions;
import org.jclouds.domain.LoginCredentials;
import org.jclouds.http.HttpRequest;
import org.jclouds.ssh.SshClient;
import org.jclouds.sshj.config.SshjSshClientModule;
import org.testng.annotations.AfterClass;
import org.testng.annotations.Test;
import com.google.common.base.Predicate;
import com.google.common.collect.Iterables;
import com.google.common.net.HostAndPort;
import com.google.gson.Gson;
import com.google.inject.Guice;
/**
* Tests behavior of {@code DeltacloudClient}
*
* @author Adrian Cole
*/
@Test(groups = "live", sequential = true, testName = "DeltacloudClientLiveTest")
public class DeltacloudClientLiveTest extends ReadOnlyDeltacloudClientLiveTest {
protected String prefix = System.getProperty("user.name") + ".test";
protected Instance instance;
protected LoginCredentials creds;
public void testCreateInstance() throws Exception {
Logger.getAnonymousLogger().info("starting instance");
instance = client.createInstance(Iterables.find(client.listImages(), new Predicate<Image>() {
@Override
public boolean apply(Image input) {
return input.getDescription().toLowerCase().indexOf("fedora") != -1;
}
}).getId(), CreateInstanceOptions.Builder.named(prefix).hardwareProfile("1").realm("us"));
if (instance.getAuthentication() != null && instance.getAuthentication() instanceof PasswordAuthentication)
creds = PasswordAuthentication.class.cast(instance.getAuthentication()).getLoginCredentials();
refreshInstance();
checkStartedInstance();
Instance newInfo = client.getInstance(instance.getHref());
checkInstanceMatchesGet(newInfo);
}
protected void checkInstanceMatchesGet(Instance newInfo) {
assertEquals(newInfo.getHref(), instance.getHref());
}
protected void checkStartedInstance() {
System.out.println(new Gson().toJson(instance));
assertEquals(instance.getName(), prefix);
assert stateChanges.get(Instance.State.RUNNING).apply(instance) : instance;
refreshInstance();
assertEquals(instance.getState(), Instance.State.RUNNING);
}
private Instance refreshInstance() {
if (instance != null)
return instance = client.getInstance(instance.getHref());
return null;
}
@Test(dependsOnMethods = "testCreateInstance")
public void testConnectivity() throws Exception {
Logger.getAnonymousLogger().info("awaiting ssh");
assert socketTester.apply(HostAndPort.fromParts(Iterables.get(instance.getPublicAddresses(), 0), 22)) : instance;
if (creds != null) {
Logger.getAnonymousLogger().info("will connect ssh");
doConnectViaSsh(instance, creds);
}
}
public HttpRequest getAction(Instance.Action action) {
return instance.getActions().get(action);
}
@Test(dependsOnMethods = "testConnectivity")
public void testLifeCycle() {
HttpRequest rebootUri = getAction(Instance.Action.REBOOT);
if (rebootUri != null) {
client.performAction(rebootUri);
assert stateChanges.get(Instance.State.RUNNING).apply(instance) : instance;
}
}
@Test(dependsOnMethods = "testLifeCycle")
public void testDestroyInstance() {
for (Transition transition : findChainTo(Instance.State.FINISH, refreshInstance().getState(), client
.getInstanceStates())) {
if (refreshInstance() == null)
break;
if (transition instanceof TransitionOnAction) {
client.performAction(getAction(TransitionOnAction.class.cast(transition).getAction()));
}
Predicate<Instance> stateTester = stateChanges.get(transition.getTo());
if (stateTester != null)
assert stateTester.apply(instance) : transition + " : " + instance;
else
Logger.getAnonymousLogger().warning(String.format("no state tester for: %s", transition));
}
assert refreshInstance() == null;
}
protected void doConnectViaSsh(Instance instance, LoginCredentials creds) throws IOException {
SshClient ssh = Guice.createInjector(new SshjSshClientModule()).getInstance(SshClient.Factory.class).create(
HostAndPort.fromParts(Iterables.get(instance.getPublicAddresses(), 0), 22), creds);
try {
ssh.connect();
ExecResponse hello = ssh.exec("echo hello");
assertEquals(hello.getOutput().trim(), "hello");
System.err.println(ssh.exec("df -k").getOutput());
System.err.println(ssh.exec("mount").getOutput());
System.err.println(ssh.exec("uname -a").getOutput());
} finally {
if (ssh != null)
ssh.disconnect();
}
}
@Override
@AfterClass(groups = { "integration", "live" })
protected void tearDownContext() {
testDestroyInstance();
super.tearDownContext();
}
}

View File

@ -1,167 +0,0 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.deltacloud;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertTrue;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import org.jclouds.compute.internal.BaseComputeServiceContextLiveTest;
import org.jclouds.deltacloud.domain.DeltacloudCollection;
import org.jclouds.deltacloud.domain.HardwareProfile;
import org.jclouds.deltacloud.domain.Image;
import org.jclouds.deltacloud.domain.Instance;
import org.jclouds.deltacloud.domain.Instance.State;
import org.jclouds.deltacloud.domain.Realm;
import org.jclouds.deltacloud.domain.Transition;
import org.jclouds.deltacloud.predicates.InstanceFinished;
import org.jclouds.deltacloud.predicates.InstanceRunning;
import org.jclouds.predicates.InetSocketAddressConnect;
import org.jclouds.predicates.RetryablePredicate;
import org.jclouds.sshj.config.SshjSshClientModule;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import com.google.common.base.Predicate;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
import com.google.common.collect.Multimap;
import com.google.common.net.HostAndPort;
import com.google.inject.Module;
/**
* Tests behavior of {@code DeltacloudClient}
*
* @author Adrian Cole
*/
@Test(groups = "live", singleThreaded = true, testName = "ReadOnlyDeltacloudClientLiveTest")
public class ReadOnlyDeltacloudClientLiveTest extends BaseComputeServiceContextLiveTest {
public ReadOnlyDeltacloudClientLiveTest() {
provider = "deltacloud";
}
protected DeltacloudClient client;
protected Predicate<HostAndPort> socketTester;
protected ImmutableMap<State, Predicate<Instance>> stateChanges;
@Override
@BeforeClass(groups = { "integration", "live" })
public void setupContext() {
super.setupContext();
client = view.unwrap(DeltacloudApiMetadata.CONTEXT_TOKEN).getApi();
socketTester = new RetryablePredicate<HostAndPort>(new InetSocketAddressConnect(), 180, 1, TimeUnit.SECONDS);
stateChanges = ImmutableMap.<Instance.State, Predicate<Instance>> of(//
Instance.State.RUNNING, new RetryablePredicate<Instance>(new InstanceRunning(client), 600, 1,
TimeUnit.SECONDS),//
Instance.State.FINISH, new RetryablePredicate<Instance>(new InstanceFinished(client), 30, 1,
TimeUnit.SECONDS)//
);
}
@Test
public void testGetLinksContainsAll() throws Exception {
Set<? extends DeltacloudCollection> links = client.getCollections();
assertNotNull(links);
}
@Test
public void testGetInstanceStatesCanGoFromStartToFinish() throws Exception {
Multimap<Instance.State, ? extends Transition> states = client.getInstanceStates();
assertNotNull(states);
Iterable<Transition> toFinishFromStart = findChainTo(Instance.State.FINISH, Instance.State.START, states);
assert Iterables.size(toFinishFromStart) > 0 : toFinishFromStart;
Iterable<Transition> toRunningFromStart = findChainTo(Instance.State.RUNNING, Instance.State.START, states);
assert Iterables.size(toRunningFromStart) > 0 : toRunningFromStart;
Iterable<Transition> toFinishFromRunning = findChainTo(Instance.State.FINISH, Instance.State.RUNNING, states);
assert Iterables.size(toFinishFromRunning) > 0 : toFinishFromRunning;
assertEquals(ImmutableList.copyOf(Iterables.concat(toRunningFromStart, toFinishFromRunning)), ImmutableList
.copyOf(toFinishFromStart));
}
Iterable<Transition> findChainTo(Instance.State desired, Instance.State currentState,
Multimap<Instance.State, ? extends Transition> states) {
for (Transition transition : states.get(currentState)) {
if (currentState.ordinal() >= transition.getTo().ordinal())
continue;
if (transition.getTo() == desired)
return ImmutableSet.<Transition> of(transition);
Iterable<Transition> transitions = findChainTo(desired, transition.getTo(), states);
if (Iterables.size(transitions) > 0)
return Iterables.concat(ImmutableSet.of(transition), transitions);
}
return ImmutableSet.<Transition> of();
}
public void testListAndGetRealms() throws Exception {
Set<? extends Realm> response = client.listRealms();
assert null != response;
long realmCount = response.size();
assertTrue(realmCount >= 0);
for (Realm realm : response) {
Realm newDetails = client.getRealm(realm.getHref());
assertEquals(realm, newDetails);
}
}
public void testListAndGetImages() throws Exception {
Set<? extends Image> response = client.listImages();
assert null != response;
long imageCount = response.size();
assertTrue(imageCount >= 0);
for (Image image : response) {
Image newDetails = client.getImage(image.getHref());
assertEquals(image, newDetails);
}
}
public void testListAndGetHardwareProfiles() throws Exception {
Set<? extends HardwareProfile> response = client.listHardwareProfiles();
assert null != response;
long profileCount = response.size();
assertTrue(profileCount >= 0);
for (HardwareProfile profile : response) {
HardwareProfile newDetails = client.getHardwareProfile(profile.getHref());
assertEquals(profile, newDetails);
}
}
public void testListAndGetInstances() throws Exception {
Set<? extends Instance> response = client.listInstances();
assert null != response;
long instanceCount = response.size();
assertTrue(instanceCount >= 0);
for (Instance instance : response) {
Instance newDetails = client.getInstance(instance.getHref());
assertEquals(instance, newDetails);
}
}
@Override
protected Module getSshModule() {
return new SshjSshClientModule();
}
}

View File

@ -1,88 +0,0 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.deltacloud.compute;
import static org.testng.Assert.assertEquals;
import java.io.IOException;
import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.compute.internal.BaseComputeServiceLiveTest;
import org.jclouds.domain.LocationScope;
import org.jclouds.sshj.config.SshjSshClientModule;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableMap;
import com.google.inject.Module;
/**
*
*
* @author Adrian Cole
*/
@Test(groups = "live", enabled = true, singleThreaded = true, testName = "DeltacloudComputeServiceLiveTest")
public class DeltacloudComputeServiceLiveTest extends BaseComputeServiceLiveTest {
public DeltacloudComputeServiceLiveTest() {
provider = "deltacloud";
}
@Override
protected Module getSshModule() {
return new SshjSshClientModule();
}
// deltacloud does not support metadata
@Override
protected void checkUserMetadataInNodeEquals(NodeMetadata node, ImmutableMap<String, String> userMetadata) {
assert node.getUserMetadata().equals(ImmutableMap.<String, String> of()) : String.format(
"node userMetadata did not match %s %s", userMetadata, node);
}
@Override
protected void checkNodes(Iterable<? extends NodeMetadata> nodes, String group, String task) throws IOException {
super.checkNodes(nodes, group, task);
for (NodeMetadata node : nodes) {
assertEquals(node.getLocation().getScope(), LocationScope.ZONE);
}
}
@Test(enabled = true, dependsOnMethods = "testReboot", expectedExceptions = UnsupportedOperationException.class)
public void testSuspendResume() throws Exception {
super.testSuspendResume();
}
@Test(enabled = true, dependsOnMethods = "testSuspendResume")
@Override
public void testGetNodesWithDetails() throws Exception {
super.testGetNodesWithDetails();
}
@Test(enabled = true, dependsOnMethods = "testSuspendResume")
@Override
public void testListNodes() throws Exception {
super.testListNodes();
}
@Test(enabled = true, dependsOnMethods = { "testListNodes", "testGetNodesWithDetails" })
@Override
public void testDestroyNodes() {
super.testDestroyNodes();
}
}

View File

@ -1,85 +0,0 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.deltacloud.compute;
import static org.jclouds.compute.util.ComputeServiceUtils.getCores;
import static org.testng.Assert.assertEquals;
import java.util.Set;
import org.jclouds.compute.domain.OsFamily;
import org.jclouds.compute.domain.OsFamilyVersion64Bit;
import org.jclouds.compute.domain.Template;
import org.jclouds.compute.internal.BaseTemplateBuilderLiveTest;
import org.testng.annotations.Test;
import com.google.common.base.Predicate;
import com.google.common.base.Predicates;
import com.google.common.collect.ImmutableSet;
/**
*
* @author Adrian Cole
*/
@Test(groups = "live")
public class DeltacloudTemplateBuilderLiveTest extends BaseTemplateBuilderLiveTest {
public DeltacloudTemplateBuilderLiveTest() {
provider = "deltacloud";
}
@Override
protected Predicate<OsFamilyVersion64Bit> defineUnsupportedOperatingSystems() {
return Predicates.not(new Predicate<OsFamilyVersion64Bit>() {
@Override
public boolean apply(OsFamilyVersion64Bit input) {
switch (input.family) {
case UBUNTU:
return !(input.version.startsWith("11") || input.version.equals("8.04")) && input.is64Bit;
case DEBIAN:
return !(input.version.equals("6.0")) && input.is64Bit;
case CENTOS:
return !(input.version.matches("5.[023]") || input.version.equals("8.04")) && input.is64Bit;
case WINDOWS:
return input.version.equals("2008 SP2") || input.version.equals("")
|| (input.version.equals("2008 R2") && input.is64Bit);
default:
return false;
}
}
});
}
@Test
public void testTemplateBuilder() {
Template defaultTemplate = this.view.getComputeService().templateBuilder().build();
assertEquals(defaultTemplate.getImage().getOperatingSystem().is64Bit(), true);
assertEquals(defaultTemplate.getImage().getOperatingSystem().getVersion(), "10.04");
assertEquals(defaultTemplate.getImage().getOperatingSystem().getFamily(), OsFamily.UBUNTU);
assertEquals(defaultTemplate.getLocation().getId(), "http://localhost:3001/api/realms/us");
assertEquals(getCores(defaultTemplate.getHardware()), 1.0d);
}
@Override
protected Set<String> getIso3166Codes() {
return ImmutableSet.<String> of();
}
}

View File

@ -1,125 +0,0 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.deltacloud.handlers;
import static org.easymock.EasyMock.createMock;
import static org.easymock.EasyMock.expect;
import static org.easymock.EasyMock.replay;
import static org.easymock.EasyMock.reportMatcher;
import static org.easymock.EasyMock.verify;
import java.net.URI;
import org.easymock.IArgumentMatcher;
import org.jclouds.http.HttpCommand;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpResponse;
import org.jclouds.rest.AuthorizationException;
import org.jclouds.rest.ResourceNotFoundException;
import org.testng.annotations.Test;
import com.google.inject.Guice;
/**
*
* @author Adrian Cole
*/
@Test(groups = { "unit" })
public class DeltacloudErrorHandlerTest {
@Test
public void test400MakesIllegalArgumentException() {
assertCodeMakes("GET", URI.create("https://deltacloud.com/foo"), 400, "", "Bad Request",
IllegalArgumentException.class);
}
@Test
public void test401MakesAuthorizationException() {
assertCodeMakes("GET", URI.create("https://deltacloud.com/foo"), 401, "", "Unauthorized",
AuthorizationException.class);
}
@Test
public void test404MakesResourceNotFoundException() {
assertCodeMakes("GET", URI.create("https://deltacloud.com/foo"), 404, "", "Not Found",
ResourceNotFoundException.class);
}
@Test
public void testItemNotFoundMakesResourceNotFoundException() {
assertCodeMakes("GET", URI.create("https://deltacloud.com/foo"), 500, "", "ItemNotFound",
ResourceNotFoundException.class);
}
@Test
public void test405MakesIllegalArgumentException() {
assertCodeMakes("GET", URI.create("https://deltacloud.com/foo"), 405, "", "Method Not Allowed",
IllegalArgumentException.class);
}
@Test
public void test409MakesIllegalStateException() {
assertCodeMakes("GET", URI.create("https://deltacloud.com/foo"), 409, "", "Conflict", IllegalStateException.class);
}
private void assertCodeMakes(String method, URI uri, int statusCode, String message, String content,
Class<? extends Exception> expected) {
assertCodeMakes(method, uri, statusCode, message, "text/xml", content, expected);
}
private void assertCodeMakes(String method, URI uri, int statusCode, String message, String contentType,
String content, Class<? extends Exception> expected) {
DeltacloudErrorHandler function = Guice.createInjector().getInstance(DeltacloudErrorHandler.class);
HttpCommand command = createMock(HttpCommand.class);
HttpRequest request = HttpRequest.builder().method(method).endpoint(uri).build();
HttpResponse response = HttpResponse.builder().statusCode(statusCode).message(message).payload(content).build();
response.getPayload().getContentMetadata().setContentType(contentType);
expect(command.getCurrentRequest()).andReturn(request).atLeastOnce();
command.setException(classEq(expected));
replay(command);
function.handleError(command, response);
verify(command);
}
public static Exception classEq(final Class<? extends Exception> in) {
reportMatcher(new IArgumentMatcher() {
@Override
public void appendTo(StringBuffer buffer) {
buffer.append("classEq(");
buffer.append(in);
buffer.append(")");
}
@Override
public boolean matches(Object arg) {
return arg.getClass() == in;
}
});
return null;
}
}

View File

@ -1,83 +0,0 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.deltacloud.handlers;
import static org.easymock.EasyMock.createMock;
import static org.easymock.EasyMock.expect;
import static org.easymock.EasyMock.replay;
import static org.easymock.EasyMock.verify;
import org.jclouds.ContextBuilder;
import org.jclouds.http.HttpCommand;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpResponse;
import org.testng.annotations.Test;
import com.google.inject.Injector;
/**
* Tests behavior of {@code DeltacloudRedirectionRetry}
*
* @author Adrian Cole
*/
@Test(groups = "unit")
public class DeltacloudRedirectionRetryHandlerTest {
Injector injector = ContextBuilder.newBuilder("stub").buildInjector();
@Test
public void test302DoesNotRetryOnDelete() {
HttpCommand command = createMock(HttpCommand.class);
HttpRequest request = HttpRequest.builder().method("DELETE").endpoint("http://localhost").build();
HttpResponse response = HttpResponse.builder().statusCode(302).message("HTTP/1.1 302 Found").build();
expect(command.getCurrentRequest()).andReturn(request).atLeastOnce();
replay(command);
DeltacloudRedirectionRetryHandler retry = injector.getInstance(
DeltacloudRedirectionRetryHandler.class);
assert !retry.shouldRetryRequest(command, response);
verify(command);
}
@Test
public void test302DoesRetryOnGET() {
HttpCommand command = createMock(HttpCommand.class);
HttpRequest request = HttpRequest.builder().method("GET").endpoint("http://localhost").build();
HttpResponse response = HttpResponse.builder().statusCode(302).message("HTTP/1.1 302 Found").build();
expect(command.getCurrentRequest()).andReturn(request).atLeastOnce();
expect(command.incrementRedirectCount()).andReturn(1);
replay(command);
DeltacloudRedirectionRetryHandler retry = injector.getInstance(
DeltacloudRedirectionRetryHandler.class);
assert !retry.shouldRetryRequest(command, response);
verify(command);
}
}

View File

@ -1,66 +0,0 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.deltacloud.options;
import static org.jclouds.deltacloud.options.CreateInstanceOptions.Builder.named;
import static org.testng.Assert.assertEquals;
import com.google.common.collect.ImmutableList;
import org.jclouds.http.options.HttpRequestOptions;
import org.testng.annotations.Test;
/**
* Tests possible uses of CreateInstanceOptions and CreateInstanceOptions.Builder.*
*
* @author Adrian Cole
*/
public class CreateInstanceOptionsTest {
@Test
public void testAssignability() {
assert HttpRequestOptions.class.isAssignableFrom(CreateInstanceOptions.class);
assert !String.class.isAssignableFrom(CreateInstanceOptions.class);
}
@Test
public void testWithNamed() {
CreateInstanceOptions options = new CreateInstanceOptions();
options.named("test");
assertEquals(options.buildFormParameters().get("name"), ImmutableList.of("test"));
}
@Test
public void testNullWithNamed() {
CreateInstanceOptions options = new CreateInstanceOptions();
assertEquals(options.buildFormParameters().get("name"), ImmutableList.of());
}
@Test
public void testWithNamedStatic() {
CreateInstanceOptions options = named("test");
assertEquals(options.buildFormParameters().get("name"), ImmutableList.of("test"));
}
@Test(expectedExceptions = NullPointerException.class)
public void testWithNamedNPE() {
named(null);
}
}

View File

@ -1,61 +0,0 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.deltacloud.xml;
import static org.testng.Assert.assertEquals;
import java.io.InputStream;
import java.net.URI;
import java.util.Set;
import org.jclouds.deltacloud.domain.DeltacloudCollection;
import org.jclouds.deltacloud.domain.Feature;
import org.jclouds.http.functions.BaseHandlerTest;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableSet;
/**
* Tests behavior of {@code DeltacloudCollectionsHandler}
*
* @author Adrian Cole
*/
// NOTE:without testName, this will not call @Before* and fail w/NPE during surefire
@Test(groups = "unit", testName = "DeltacloudCollectionsHandlerTest")
public class DeltacloudCollectionsHandlerTest extends BaseHandlerTest {
public void test() {
InputStream is = getClass().getResourceAsStream("/links.xml");
Set<DeltacloudCollection> expects = ImmutableSet.of(
new DeltacloudCollection(URI.create("http://localhost:3001/api/realms"), "realms"),
new DeltacloudCollection(URI.create("http://localhost:3001/api/images"), "images"),
new DeltacloudCollection(URI.create("http://localhost:3001/api/instance_states"), "instance_states"),
new DeltacloudCollection(URI.create("http://localhost:3001/api/instances"), "instances", ImmutableSet
.<Feature> of(new Feature("hardware_profiles"), new Feature("user_name"), new Feature(
"authentication_key"))),
new DeltacloudCollection(URI.create("http://localhost:3001/api/hardware_profiles"), "hardware_profiles"),
new DeltacloudCollection(URI.create("http://localhost:3001/api/storage_snapshots"), "storage_snapshots"),
new DeltacloudCollection(URI.create("http://localhost:3001/api/storage_volumes"), "storage_volumes"),
new DeltacloudCollection(URI.create("http://localhost:3001/api/keys"), "keys"), new DeltacloudCollection(
URI.create("http://localhost:3001/api/buckets"), "buckets")
);
assertEquals(factory.create(injector.getInstance(DeltacloudCollectionsHandler.class)).parse(is), expects);
}
}

View File

@ -1,79 +0,0 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.deltacloud.xml;
import static org.testng.Assert.assertEquals;
import java.io.InputStream;
import java.net.URI;
import org.jclouds.deltacloud.domain.EnumHardwareProperty;
import org.jclouds.deltacloud.domain.FixedHardwareProperty;
import org.jclouds.deltacloud.domain.HardwareParameter;
import org.jclouds.deltacloud.domain.HardwareProfile;
import org.jclouds.deltacloud.domain.HardwareProperty;
import org.jclouds.deltacloud.domain.RangeHardwareProperty;
import org.jclouds.http.functions.ParseSax;
import org.jclouds.http.functions.config.SaxParserModule;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableSet;
import com.google.inject.Guice;
import com.google.inject.Injector;
/**
* Tests behavior of {@code HardwareProfileHandler}
*
* @author Adrian Cole
*/
@Test(groups = "unit")
public class HardwareProfileHandlerTest {
static ParseSax<HardwareProfile> createParser() {
Injector injector = Guice.createInjector(new SaxParserModule());
ParseSax<HardwareProfile> parser = (ParseSax<HardwareProfile>) injector.getInstance(ParseSax.Factory.class)
.create(injector.getInstance(HardwareProfileHandler.class));
return parser;
}
public static HardwareProfile parseHardwareProfile() {
return parseHardwareProfile("/test_get_hardware_profile.xml");
}
public static HardwareProfile parseHardwareProfile(String resource) {
InputStream is = HardwareProfileHandlerTest.class.getResourceAsStream(resource);
return createParser().parse(is);
}
public void test() {
HardwareProfile expects = new HardwareProfile(
URI.create("http://localhost:3001/api/hardware_profiles/m1-xlarge"), "m1-xlarge", "m1-xlarge",
ImmutableSet.<HardwareProperty> of(
new FixedHardwareProperty("cpu", "count", Long.valueOf(4)),
new RangeHardwareProperty("memory", "MB", Long.valueOf(12288), new HardwareParameter(URI
.create("http://localhost:3001/api/instances"), "post", "hwp_memory", "create"),
Long.valueOf(12288), Long.valueOf(32768)),
new EnumHardwareProperty("storage", "GB", Long.valueOf(1024), new HardwareParameter(URI
.create("http://localhost:3001/api/instances"), "post", "hwp_storage", "create"),
ImmutableSet.<Object> of(Long.valueOf(1024), Long.valueOf(2048), Long.valueOf(4096))),
new FixedHardwareProperty("architecture", "label", "x86_64"))
);
assertEquals(parseHardwareProfile(), expects);
}
}

View File

@ -1,79 +0,0 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.deltacloud.xml;
import static org.testng.Assert.assertEquals;
import java.io.InputStream;
import java.net.URI;
import java.util.Set;
import org.jclouds.deltacloud.domain.EnumHardwareProperty;
import org.jclouds.deltacloud.domain.FixedHardwareProperty;
import org.jclouds.deltacloud.domain.HardwareParameter;
import org.jclouds.deltacloud.domain.HardwareProfile;
import org.jclouds.deltacloud.domain.HardwareProperty;
import org.jclouds.deltacloud.domain.RangeHardwareProperty;
import org.jclouds.http.functions.BaseHandlerTest;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableSet;
/**
* Tests behavior of {@code HardwareProfilesHandler}
*
* @author Adrian Cole
*/
// NOTE:without testName, this will not call @Before* and fail w/NPE during surefire
@Test(groups = "unit", testName = "HardwareProfilesHandlerTest")
public class HardwareProfilesHandlerTest extends BaseHandlerTest {
@Test
public void test() {
InputStream is = getClass().getResourceAsStream("/test_list_hardware_profiles.xml");
Set<? extends HardwareProfile> expects = ImmutableSet.of(
new HardwareProfile(URI.create("http://localhost:3001/api/hardware_profiles/m1-small"), "m1-small",
"m1-small", ImmutableSet.<HardwareProperty> of(
new FixedHardwareProperty("cpu", "count", Long.valueOf(1)), new FixedHardwareProperty("memory",
"MB", new Double(1740.8)), new FixedHardwareProperty("storage", "GB", Long.valueOf(160)),
new FixedHardwareProperty("architecture", "label", "i386"))),
new HardwareProfile(URI.create("http://localhost:3001/api/hardware_profiles/m1-large"), "m1-large",
"m1-large", ImmutableSet.<HardwareProperty> of(
new FixedHardwareProperty("cpu", "count", Long.valueOf(2)),
new RangeHardwareProperty("memory", "MB", Long.valueOf(10240), new HardwareParameter(URI
.create("http://localhost:3001/api/instances"), "post", "hwp_memory", "create"),
new Double(7680.0), Long.valueOf(15360)), new EnumHardwareProperty("storage", "GB", Long.valueOf(
850), new HardwareParameter(URI.create("http://localhost:3001/api/instances"), "post",
"hwp_storage", "create"), ImmutableSet.<Object> of(Long.valueOf(850), Long.valueOf(1024))),
new FixedHardwareProperty("architecture", "label", "x86_64"))),
new HardwareProfile(URI.create("http://localhost:3001/api/hardware_profiles/m1-xlarge"), "m1-xlarge",
"m1-xlarge", ImmutableSet.<HardwareProperty> of(
new FixedHardwareProperty("cpu", "count", Long.valueOf(4)),
new RangeHardwareProperty("memory", "MB", Long.valueOf(12288), new HardwareParameter(URI
.create("http://localhost:3001/api/instances"), "post", "hwp_memory", "create"),
Long.valueOf(12288), Long.valueOf(32768)),
new EnumHardwareProperty("storage", "GB", Long.valueOf(1024), new HardwareParameter(URI
.create("http://localhost:3001/api/instances"), "post", "hwp_storage", "create"),
ImmutableSet.<Object> of(Long.valueOf(1024), Long.valueOf(2048), Long.valueOf(4096))),
new FixedHardwareProperty("architecture", "label", "x86_64"))),
new HardwareProfile(URI.create("http://localhost:3001/api/hardware_profiles/opaque"), "opaque", "opaque",
ImmutableSet.<HardwareProperty> of()));
assertEquals(factory.create(injector.getInstance(HardwareProfilesHandler.class)).parse(is), expects);
}
}

View File

@ -1,63 +0,0 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.deltacloud.xml;
import static org.testng.Assert.assertEquals;
import java.io.InputStream;
import java.net.URI;
import org.jclouds.deltacloud.domain.Image;
import org.jclouds.http.functions.ParseSax;
import org.jclouds.http.functions.config.SaxParserModule;
import org.testng.annotations.Test;
import com.google.inject.Guice;
import com.google.inject.Injector;
/**
* Tests behavior of {@code ImageHandler}
*
* @author Adrian Cole
*/
@Test(groups = "unit")
public class ImageHandlerTest {
static ParseSax<Image> createParser() {
Injector injector = Guice.createInjector(new SaxParserModule());
ParseSax<Image> parser = (ParseSax<Image>) injector.getInstance(ParseSax.Factory.class).create(
injector.getInstance(ImageHandler.class));
return parser;
}
public static Image parseImage() {
return parseImage("/test_get_image.xml");
}
public static Image parseImage(String resource) {
InputStream is = ImageHandlerTest.class.getResourceAsStream(resource);
return createParser().parse(is);
}
public void test() {
Image expects = new Image(URI.create("http://fancycloudprovider.com/api/images/img1"), "img1", "fedoraproject",
"Fedora 10", "Fedora 10", "x86_64");
assertEquals(parseImage(), expects);
}
}

View File

@ -1,54 +0,0 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.deltacloud.xml;
import static org.testng.Assert.assertEquals;
import java.io.InputStream;
import java.net.URI;
import java.util.Set;
import org.jclouds.deltacloud.domain.Image;
import org.jclouds.http.functions.BaseHandlerTest;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableSet;
/**
* Tests behavior of {@code ImagesHandler}
*
* @author Adrian Cole
*/
// NOTE:without testName, this will not call @Before* and fail w/NPE during surefire
@Test(groups = "unit", testName = "ImagesHandlerTest")
public class ImagesHandlerTest extends BaseHandlerTest {
@Test
public void test() {
InputStream is = getClass().getResourceAsStream("/test_list_images.xml");
Set<? extends Image> expects = ImmutableSet.of(
new Image(URI.create("http://fancycloudprovider.com/api/images/img1"), "img1", "fedoraproject", "Fedora 10",
"Fedora 10", "x86_64"), new Image(URI.create("http://fancycloudprovider.com/api/images/img2"), "img2",
"fedoraproject", "Fedora 10", "Fedora 10", "i386"),
new Image(URI.create("http://fancycloudprovider.com/api/images/img3"), "img3", "ted", "JBoss", "JBoss",
"i386"));
assertEquals(factory.create(injector.getInstance(ImagesHandler.class)).parse(is), expects);
}
}

View File

@ -1,99 +0,0 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.deltacloud.xml;
import static org.testng.Assert.assertEquals;
import java.io.InputStream;
import java.net.URI;
import org.jclouds.deltacloud.domain.Instance;
import org.jclouds.deltacloud.domain.KeyAuthentication;
import org.jclouds.deltacloud.domain.PasswordAuthentication;
import org.jclouds.deltacloud.domain.Instance.Authentication;
import org.jclouds.domain.LoginCredentials;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.functions.ParseSax;
import org.jclouds.http.functions.config.SaxParserModule;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.inject.Guice;
import com.google.inject.Injector;
/**
* Tests behavior of {@code InstanceHandler}
*
* @author Adrian Cole
*/
@Test(groups = "unit")
public class InstanceHandlerTest {
static ParseSax<Instance> createParser() {
Injector injector = Guice.createInjector(new SaxParserModule());
ParseSax<Instance> parser = injector.getInstance(ParseSax.Factory.class).create(
injector.getInstance(InstanceHandler.class));
return parser;
}
public static Instance parseInstance() {
return parseInstance("/test_get_instance.xml");
}
public static Instance parseInstance(String resource) {
InputStream is = InstanceHandlerTest.class.getResourceAsStream(resource);
return createParser().parse(is);
}
public void testWithNoAuthentication() {
Instance expects = instanceWithAuthentication(null);
assertEquals(parseInstance("/test_get_instance.xml").toString(), expects.toString());
}
public void testWithPasswordAuthentication() {
Instance expects = instanceWithAuthentication(new PasswordAuthentication(LoginCredentials.builder().user("root")
.password("FOO").build()));
assertEquals(parseInstance("/test_get_instance_pw.xml").toString(), expects.toString());
}
public void testWithKeyAuthentication() {
Instance expects = instanceWithAuthentication(new KeyAuthentication("keyname"));
assertEquals(parseInstance("/test_get_instance_key.xml").toString(), expects.toString());
}
public void testWithKeyAuthenticationBlank() {
Instance expects = instanceWithAuthentication(null);
assertEquals(parseInstance("/test_get_instance_nokey.xml").toString(), expects.toString());
}
private Instance instanceWithAuthentication(Authentication authentication) {
return new Instance(URI.create("http://fancycloudprovider.com/api/instances/inst1"), "inst1", "larry",
"Production JBoss Instance", URI.create("http://fancycloudprovider.com/api/images/img3"),
URI.create("http://fancycloudprovider.com/api/hardware_profiles/m1-small"),
URI.create("http://fancycloudprovider.com/api/realms/us"), Instance.State.RUNNING, ImmutableMap.of(
Instance.Action.REBOOT,
HttpRequest.builder().method("POST").endpoint("http://fancycloudprovider.com/api/instances/inst1/reboot").build(),
Instance.Action.STOP,
HttpRequest.builder().method("POST").endpoint("http://fancycloudprovider.com/api/instances/inst1/stop").build()),
authentication, ImmutableSet.of("inst1.larry.fancycloudprovider.com"),
ImmutableSet.of("inst1.larry.internal"));
}
}

View File

@ -1,58 +0,0 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.deltacloud.xml;
import static org.testng.Assert.assertEquals;
import java.io.InputStream;
import org.jclouds.deltacloud.domain.Transition;
import org.jclouds.deltacloud.domain.TransitionAutomatically;
import org.jclouds.deltacloud.domain.TransitionOnAction;
import org.jclouds.deltacloud.domain.Instance.Action;
import org.jclouds.deltacloud.domain.Instance.State;
import org.jclouds.http.functions.BaseHandlerTest;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableMultimap;
import com.google.common.collect.Multimap;
/**
* Tests behavior of {@code StatesHandler}
*
* @author Adrian Cole
*/
// NOTE:without testName, this will not call @Before* and fail w/NPE during surefire
@Test(groups = "unit", testName = "StatesHandlerTest")
public class InstanceStatesHandlerTest extends BaseHandlerTest {
public void test() {
InputStream is = getClass().getResourceAsStream("/test_get_states.xml");
Multimap<State, ? extends Transition> expects = ImmutableMultimap.<State, Transition> builder().put(State.START,
new TransitionOnAction(Action.CREATE, State.PENDING)).put(State.PENDING,
new TransitionAutomatically(State.RUNNING))
.putAll(State.RUNNING, new TransitionOnAction(Action.REBOOT, State.RUNNING),
new TransitionOnAction(Action.STOP, State.STOPPED)).putAll(State.STOPPED,
new TransitionOnAction(Action.START, State.RUNNING),
new TransitionOnAction(Action.DESTROY, State.FINISH)).build();
assertEquals(factory.create(injector.getInstance(InstanceStatesHandler.class)).parse(is).entries(), expects
.entries());
}
}

View File

@ -1,57 +0,0 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.deltacloud.xml;
import static org.testng.Assert.assertEquals;
import java.io.InputStream;
import java.net.URI;
import java.util.Set;
import org.jclouds.deltacloud.domain.Instance;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.functions.BaseHandlerTest;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
/**
* Tests behavior of {@code InstancesHandler}
*
* @author Adrian Cole
*/
// NOTE:without testName, this will not call @Before* and fail w/NPE during surefire
@Test(groups = "unit", testName = "InstancesHandlerTest")
public class InstancesHandlerTest extends BaseHandlerTest {
@Test
public void test() {
InputStream is = getClass().getResourceAsStream("/test_list_instances.xml");
Set<? extends Instance> expects = ImmutableSet.of(new Instance(URI
.create("http://fancycloudprovider.com/api/instances/inst1"), "inst1", "larry",
"Production JBoss Instance", URI.create("http://fancycloudprovider.com/api/images/img3"), URI
.create("http://fancycloudprovider.com/api/hardware_profiles/m1-small"), URI
.create("http://fancycloudprovider.com/api/realms/us"), Instance.State.RUNNING, ImmutableMap
.of(Instance.Action.REBOOT, HttpRequest.builder().method("POST").endpoint("http://fancycloudprovider.com/api/instances/inst1/reboot").build(),
Instance.Action.STOP, HttpRequest.builder().method("POST").endpoint("http://fancycloudprovider.com/api/instances/inst1/stop").build()), null,
ImmutableSet.of("inst1.larry.fancycloudprovider.com"), ImmutableSet.of("inst1.larry.internal")));
assertEquals(factory.create(injector.getInstance(InstancesHandler.class)).parse(is).toString(), expects.toString());
}
}

View File

@ -1,64 +0,0 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.deltacloud.xml;
import static org.testng.Assert.assertEquals;
import java.io.InputStream;
import java.net.URI;
import org.jclouds.deltacloud.domain.Realm;
import org.jclouds.http.functions.ParseSax;
import org.jclouds.http.functions.config.SaxParserModule;
import org.testng.annotations.Test;
import com.google.inject.Guice;
import com.google.inject.Injector;
/**
* Tests behavior of {@code RealmHandler}
*
* @author Adrian Cole
*/
@Test(groups = "unit")
public class RealmHandlerTest {
static ParseSax<Realm> createParser() {
Injector injector = Guice.createInjector(new SaxParserModule());
ParseSax<Realm> parser = injector.getInstance(ParseSax.Factory.class).create(
injector.getInstance(RealmHandler.class));
return parser;
}
public static Realm parseRealm() {
return parseRealm("/test_get_realm.xml");
}
public static Realm parseRealm(String resource) {
InputStream is = RealmHandlerTest.class.getResourceAsStream(resource);
return createParser().parse(is);
}
public void test() {
Realm expects = new Realm(URI.create("http://fancycloudprovider.com/api/realms/us"), "us", "United States", null,
Realm.State.AVAILABLE);
assertEquals(parseRealm(), expects);
}
}

View File

@ -1,51 +0,0 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.deltacloud.xml;
import static org.testng.Assert.assertEquals;
import java.io.InputStream;
import java.net.URI;
import java.util.Set;
import org.jclouds.deltacloud.domain.Realm;
import org.jclouds.http.functions.BaseHandlerTest;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableSet;
/**
* Tests behavior of {@code RealmsHandler}
*
* @author Adrian Cole
*/
// NOTE:without testName, this will not call @Before* and fail w/NPE during surefire
@Test(groups = "unit", testName = "RealmsHandlerTest")
public class RealmsHandlerTest extends BaseHandlerTest {
@Test
public void test() {
InputStream is = getClass().getResourceAsStream("/test_list_realms.xml");
Set<? extends Realm> expects = ImmutableSet.of(new Realm(URI
.create("http://fancycloudprovider.com/api/realms/us"), "us", "United States", null,
Realm.State.AVAILABLE), new Realm(URI.create("http://fancycloudprovider.com/api/realms/eu"), "eu",
"Europe", null, Realm.State.AVAILABLE));
assertEquals(factory.create(injector.getInstance(RealmsHandler.class)).parse(is), expects);
}
}

View File

@ -1,23 +0,0 @@
<api driver='mock' version='0.1.0'>
<link href='http://localhost:3001/api/realms' rel='realms'>
</link>
<link href='http://localhost:3001/api/images' rel='images'>
</link>
<link href='http://localhost:3001/api/instance_states' rel='instance_states'>
</link>
<link href='http://localhost:3001/api/instances' rel='instances'>
<feature name='hardware_profiles'></feature>
<feature name='user_name'></feature>
<feature name='authentication_key'></feature>
</link>
<link href='http://localhost:3001/api/hardware_profiles' rel='hardware_profiles'>
</link>
<link href='http://localhost:3001/api/storage_snapshots' rel='storage_snapshots'>
</link>
<link href='http://localhost:3001/api/storage_volumes' rel='storage_volumes'>
</link>
<link href='http://localhost:3001/api/keys' rel='keys'>
</link>
<link href='http://localhost:3001/api/buckets' rel='buckets'>
</link>
</api>

View File

@ -1,151 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<!--
For more configuration infromation and examples see the Apache
Log4j website: http://logging.apache.org/log4j/
-->
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/"
debug="false">
<!-- A time/date based rolling appender -->
<appender name="WIREFILE" class="org.apache.log4j.DailyRollingFileAppender">
<param name="File" value="target/test-data/jclouds-wire.log" />
<param name="Append" value="true" />
<!-- Rollover at midnight each day -->
<param name="DatePattern" value="'.'yyyy-MM-dd" />
<param name="Threshold" value="TRACE" />
<layout class="org.apache.log4j.PatternLayout">
<!-- The default pattern: Date Priority [Category] Message\n -->
<param name="ConversionPattern" value="%d %-5p [%c] (%t) %m%n" />
<!--
The full pattern: Date MS Priority [Category]
(Thread:NDC) Message\n <param name="ConversionPattern"
value="%d %-5r %-5p [%c] (%t:%x) %m%n"/>
-->
</layout>
</appender>
<!-- A time/date based rolling appender -->
<appender name="FILE" class="org.apache.log4j.DailyRollingFileAppender">
<param name="File" value="target/test-data/jclouds.log" />
<param name="Append" value="true" />
<!-- Rollover at midnight each day -->
<param name="DatePattern" value="'.'yyyy-MM-dd" />
<param name="Threshold" value="TRACE" />
<layout class="org.apache.log4j.PatternLayout">
<!-- The default pattern: Date Priority [Category] Message\n -->
<param name="ConversionPattern" value="%d %-5p [%c] (%t) %m%n" />
<!--
The full pattern: Date MS Priority [Category]
(Thread:NDC) Message\n <param name="ConversionPattern"
value="%d %-5r %-5p [%c] (%t:%x) %m%n"/>
-->
</layout>
</appender>
<!-- A time/date based rolling appender -->
<appender name="COMPUTEFILE" class="org.apache.log4j.DailyRollingFileAppender">
<param name="File" value="target/test-data/jclouds-compute.log" />
<param name="Append" value="true" />
<!-- Rollover at midnight each day -->
<param name="DatePattern" value="'.'yyyy-MM-dd" />
<param name="Threshold" value="TRACE" />
<layout class="org.apache.log4j.PatternLayout">
<!-- The default pattern: Date Priority [Category] Message\n -->
<param name="ConversionPattern" value="%d %-5p [%c] (%t) %m%n" />
<!--
The full pattern: Date MS Priority [Category]
(Thread:NDC) Message\n <param name="ConversionPattern"
value="%d %-5r %-5p [%c] (%t:%x) %m%n"/>
-->
</layout>
</appender>
<!-- A time/date based rolling appender -->
<appender name="SSHFILE" class="org.apache.log4j.DailyRollingFileAppender">
<param name="File" value="target/test-data/jclouds-ssh.log" />
<param name="Append" value="true" />
<!-- Rollover at midnight each day -->
<param name="DatePattern" value="'.'yyyy-MM-dd" />
<param name="Threshold" value="TRACE" />
<layout class="org.apache.log4j.PatternLayout">
<!-- The default pattern: Date Priority [Category] Message\n -->
<param name="ConversionPattern" value="%d %-5p [%c] (%t) %m%n" />
<!--
The full pattern: Date MS Priority [Category]
(Thread:NDC) Message\n <param name="ConversionPattern"
value="%d %-5r %-5p [%c] (%t:%x) %m%n"/>
-->
</layout>
</appender>
<appender name="ASYNCCOMPUTE" class="org.apache.log4j.AsyncAppender">
<appender-ref ref="COMPUTEFILE" />
</appender>
<appender name="ASYNCSSH" class="org.apache.log4j.AsyncAppender">
<appender-ref ref="SSHFILE" />
</appender>
<appender name="ASYNC" class="org.apache.log4j.AsyncAppender">
<appender-ref ref="FILE" />
</appender>
<appender name="ASYNCWIRE" class="org.apache.log4j.AsyncAppender">
<appender-ref ref="WIREFILE" />
</appender>
<!-- ================ -->
<!-- Limit categories -->
<!-- ================ -->
<category name="org.jclouds">
<priority value="DEBUG" />
<appender-ref ref="ASYNC" />
</category>
<category name="jclouds.headers">
<priority value="DEBUG" />
<appender-ref ref="ASYNCWIRE" />
</category>
<category name="jclouds.ssh">
<priority value="DEBUG" />
<appender-ref ref="ASYNCSSH" />
</category>
<category name="jclouds.wire">
<priority value="DEBUG" />
<appender-ref ref="ASYNCWIRE" />
</category>
<category name="jclouds.compute">
<priority value="TRACE" />
<appender-ref ref="ASYNCCOMPUTE" />
</category>
<!-- ======================= -->
<!-- Setup the Root category -->
<!-- ======================= -->
<root>
<priority value="WARN" />
</root>
</log4j:configuration>

View File

@ -1,18 +0,0 @@
<?xml version='1.0' encoding='utf-8' ?>
<hardware_profile href='http://localhost:3001/api/hardware_profiles/m1-xlarge' id='m1-xlarge'>
<name>m1-xlarge</name>
<property kind='fixed' name='cpu' unit='count' value='4' />
<property kind='range' name='memory' unit='MB' value='12288'>
<param href='http://localhost:3001/api/instances' method='post' name='hwp_memory' operation='create' />
<range first='12288' last='32768' />
</property>
<property kind='enum' name='storage' unit='GB' value='1024'>
<param href='http://localhost:3001/api/instances' method='post' name='hwp_storage' operation='create' />
<enum>
<entry value='1024' />
<entry value='2048' />
<entry value='4096' />
</enum>
</property>
<property kind='fixed' name='architecture' unit='label' value='x86_64' />
</hardware_profile>

View File

@ -1,7 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<image href="http://fancycloudprovider.com/api/images/img1" id='img1'>
<owner_id>fedoraproject</owner_id>
<name>Fedora 10</name>
<description>Fedora 10</description>
<architecture>x86_64</architecture>
</image>

View File

@ -1,20 +0,0 @@
<instance href="http://fancycloudprovider.com/api/instances/inst1" id='inst1'>
<owner_id>larry</owner_id>
<name>Production JBoss Instance</name>
<image href="http://fancycloudprovider.com/api/images/img3"/>
<hardware_profile href="http://fancycloudprovider.com/api/hardware_profiles/m1-small"/>
<realm href="http://fancycloudprovider.com/api/realms/us"/>
<state>RUNNING</state>
<actions>
<link rel="reboot" href="http://fancycloudprovider.com/api/instances/inst1/reboot" method="post" />
<link rel="stop" href="http://fancycloudprovider.com/api/instances/inst1/stop" method="post" />
</actions>
<public_addresses>
<address>inst1.larry.fancycloudprovider.com</address>
</public_addresses>
<private_addresses>
<address>inst1.larry.internal</address>
</private_addresses>
</instance>

View File

@ -1,24 +0,0 @@
<?xml version='1.0' encoding='utf-8' ?>
<instance href="http://fancycloudprovider.com/api/instances/inst1" id='inst1'>
<owner_id>larry</owner_id>
<name>Production JBoss Instance</name>
<image href="http://fancycloudprovider.com/api/images/img3"/>
<hardware_profile href="http://fancycloudprovider.com/api/hardware_profiles/m1-small"/>
<realm href="http://fancycloudprovider.com/api/realms/us"/>
<state>RUNNING</state>
<actions>
<link rel="reboot" href="http://fancycloudprovider.com/api/instances/inst1/reboot" method="post" />
<link rel="stop" href="http://fancycloudprovider.com/api/instances/inst1/stop" method="post" />
</actions>
<public_addresses>
<address>inst1.larry.fancycloudprovider.com</address>
</public_addresses>
<private_addresses>
<address>inst1.larry.internal</address>
</private_addresses>
<authentication type='key'>
<keyname>keyname</keyname>
</authentication>
</instance>

View File

@ -1,24 +0,0 @@
<?xml version='1.0' encoding='utf-8' ?>
<instance href="http://fancycloudprovider.com/api/instances/inst1" id='inst1'>
<owner_id>larry</owner_id>
<name>Production JBoss Instance</name>
<image href="http://fancycloudprovider.com/api/images/img3"/>
<hardware_profile href="http://fancycloudprovider.com/api/hardware_profiles/m1-small"/>
<realm href="http://fancycloudprovider.com/api/realms/us"/>
<state>RUNNING</state>
<actions>
<link rel="reboot" href="http://fancycloudprovider.com/api/instances/inst1/reboot" method="post" />
<link rel="stop" href="http://fancycloudprovider.com/api/instances/inst1/stop" method="post" />
</actions>
<public_addresses>
<address>inst1.larry.fancycloudprovider.com</address>
</public_addresses>
<private_addresses>
<address>inst1.larry.internal</address>
</private_addresses>
<authentication type='key'>
<keyname></keyname>
</authentication>
</instance>

View File

@ -1,27 +0,0 @@
<?xml version='1.0' encoding='utf-8' ?>
<instance href="http://fancycloudprovider.com/api/instances/inst1" id='inst1'>
<owner_id>larry</owner_id>
<name>Production JBoss Instance</name>
<image href="http://fancycloudprovider.com/api/images/img3"/>
<hardware_profile href="http://fancycloudprovider.com/api/hardware_profiles/m1-small"/>
<realm href="http://fancycloudprovider.com/api/realms/us"/>
<state>RUNNING</state>
<actions>
<link rel="reboot" href="http://fancycloudprovider.com/api/instances/inst1/reboot" method="post" />
<link rel="stop" href="http://fancycloudprovider.com/api/instances/inst1/stop" method="post" />
</actions>
<public_addresses>
<address>inst1.larry.fancycloudprovider.com</address>
</public_addresses>
<private_addresses>
<address>inst1.larry.internal</address>
</private_addresses>
<authentication type='password'>
<login>
<username>root</username>
<password>FOO</password>
</login>
</authentication>
</instance>

View File

@ -1,5 +0,0 @@
<realm href="http://fancycloudprovider.com/api/realms/us" id='us'>
<name>United States</name>
<state>AVAILABLE</state>
<limit/>
</realm>

View File

@ -1,18 +0,0 @@
<states>
<state name='start'>
<transition action='create' to='pending'></transition>
</state>
<state name='pending'>
<transition auto='true' to='running'></transition>
</state>
<state name='running'>
<transition action='reboot' to='running'></transition>
<transition action='stop' to='stopped'></transition>
</state>
<state name='stopped'>
<transition action='start' to='running'></transition>
<transition action='destroy' to='finish'></transition>
</state>
<state name='finish'>
</state>
</states>

View File

@ -1,46 +0,0 @@
<?xml version='1.0' encoding='utf-8' ?>
<hardware_profiles>
<hardware_profile href='http://localhost:3001/api/hardware_profiles/m1-small' id='m1-small'>
<name>m1-small</name>
<property kind='fixed' name='cpu' unit='count' value='1' />
<property kind='fixed' name='memory' unit='MB' value='1740.8' />
<property kind='fixed' name='storage' unit='GB' value='160' />
<property kind='fixed' name='architecture' unit='label' value='i386' />
</hardware_profile>
<hardware_profile href='http://localhost:3001/api/hardware_profiles/m1-large' id='m1-large'>
<name>m1-large</name>
<property kind='fixed' name='cpu' unit='count' value='2' />
<property kind='range' name='memory' unit='MB' value='10240'>
<param href='http://localhost:3001/api/instances' method='post' name='hwp_memory' operation='create' />
<range first='7680.0' last='15360' />
</property>
<property kind='enum' name='storage' unit='GB' value='850'>
<param href='http://localhost:3001/api/instances' method='post' name='hwp_storage' operation='create' />
<enum>
<entry value='850' />
<entry value='1024' />
</enum>
</property>
<property kind='fixed' name='architecture' unit='label' value='x86_64' />
</hardware_profile>
<hardware_profile href='http://localhost:3001/api/hardware_profiles/m1-xlarge' id='m1-xlarge'>
<name>m1-xlarge</name>
<property kind='fixed' name='cpu' unit='count' value='4' />
<property kind='range' name='memory' unit='MB' value='12288'>
<param href='http://localhost:3001/api/instances' method='post' name='hwp_memory' operation='create' />
<range first='12288' last='32768' />
</property>
<property kind='enum' name='storage' unit='GB' value='1024'>
<param href='http://localhost:3001/api/instances' method='post' name='hwp_storage' operation='create' />
<enum>
<entry value='1024' />
<entry value='2048' />
<entry value='4096' />
</enum>
</property>
<property kind='fixed' name='architecture' unit='label' value='x86_64' />
</hardware_profile>
<hardware_profile href='http://localhost:3001/api/hardware_profiles/opaque' id='opaque'>
<name>opaque</name>
</hardware_profile>
</hardware_profiles>

View File

@ -1,20 +0,0 @@
<images>
<image href="http://fancycloudprovider.com/api/images/img1" id='img1'>
<owner_id>fedoraproject</owner_id>
<name>Fedora 10</name>
<description>Fedora 10</description>
<architecture>x86_64</architecture>
</image>
<image href="http://fancycloudprovider.com/api/images/img2" id='img2'>
<owner_id>fedoraproject</owner_id>
<name>Fedora 10</name>
<description>Fedora 10</description>
<architecture>i386</architecture>
</image>
<image href="http://fancycloudprovider.com/api/images/img3" id='img3'>
<owner_id>ted</owner_id>
<name>JBoss</name>
<description>JBoss</description>
<architecture>i386</architecture>
</image>
</images>

View File

@ -1,22 +0,0 @@
<instances>
<instance href="http://fancycloudprovider.com/api/instances/inst1" id='inst1'>
<owner_id>larry</owner_id>
<name>Production JBoss Instance</name>
<image href="http://fancycloudprovider.com/api/images/img3"/>
<hardware_profile href="http://fancycloudprovider.com/api/hardware_profiles/m1-small"/>
<realm href="http://fancycloudprovider.com/api/realms/us"/>
<state>RUNNING</state>
<actions>
<link rel="reboot" href="http://fancycloudprovider.com/api/instances/inst1/reboot" method="post" />
<link rel="stop" href="http://fancycloudprovider.com/api/instances/inst1/stop" method="post" />
</actions>
<public_addresses>
<address>inst1.larry.fancycloudprovider.com</address>
</public_addresses>
<private_addresses>
<address>inst1.larry.internal</address>
</private_addresses>
</instance>
</instances>

View File

@ -1,12 +0,0 @@
<realms>
<realm href="http://fancycloudprovider.com/api/realms/us" id='us'>
<name>United States</name>
<state>AVAILABLE</state>
<limit/>
</realm>
<realm href="http://fancycloudprovider.com/api/realms/eu" id='eu'>
<name>Europe</name>
<state>AVAILABLE</state>
<limit/>
</realm>
</realms>

View File

@ -40,7 +40,6 @@
<module>s3</module>
<module>ec2</module>
<module>sqs</module>
<module>deltacloud</module>
<module>vcloud</module>
<module>elasticstack</module>
<module>atmos</module>