From 6e20d7c23b3d1526428cf3060a0d81300bc21f67 Mon Sep 17 00:00:00 2001 From: Mattias Holmqvist Date: Mon, 19 Dec 2011 22:27:20 +0100 Subject: [PATCH] Merge pull request #264 from aplowe/master --- .../org/jclouds/glesys/GleSYSAsyncClient.java | 7 + .../java/org/jclouds/glesys/GleSYSClient.java | 8 ++ .../glesys/config/GleSYSRestClientModule.java | 6 +- .../org/jclouds/glesys/domain/Archive.java | 109 ++++++++++++++++ .../domain/ArchiveAllowedArguments.java | 84 ++++++++++++ .../jclouds/glesys/domain/ArchiveDetails.java | 47 +++++++ .../jclouds/glesys/domain/ServerCreated.java | 9 +- .../glesys/features/ArchiveAsyncClient.java | 104 +++++++++++++++ .../glesys/features/ArchiveClient.java | 93 +++++++++++++ .../glesys/features/ServerAsyncClient.java | 4 +- .../jclouds/glesys/features/ServerClient.java | 2 +- .../internal/CustomDeserializers.java | 18 +-- .../jclouds/glesys/GleSYSAsyncClientTest.java | 2 + .../features/ArchiveAsyncClientTest.java | 38 ++++++ .../features/ArchiveClientLiveTest.java | 123 ++++++++++++++++++ .../glesys/features/ServerClientLiveTest.java | 30 +++-- .../ParseArchiveAllowedArgumentsTest.java | 61 +++++++++ .../glesys/parse/ParseArchiveDetailsTest.java | 61 +++++++++ .../glesys/parse/ParseArchiveListTest.java | 59 +++++++++ .../glesys/parse/ParseServerCreatedTest.java | 13 +- .../resources/archive_allowed_arguments.json | 1 + .../src/test/resources/archive_details.json | 1 + .../src/test/resources/archive_list.json | 1 + 23 files changed, 838 insertions(+), 43 deletions(-) create mode 100644 sandbox-providers/glesys/src/main/java/org/jclouds/glesys/domain/Archive.java create mode 100644 sandbox-providers/glesys/src/main/java/org/jclouds/glesys/domain/ArchiveAllowedArguments.java create mode 100644 sandbox-providers/glesys/src/main/java/org/jclouds/glesys/domain/ArchiveDetails.java create mode 100644 sandbox-providers/glesys/src/main/java/org/jclouds/glesys/features/ArchiveAsyncClient.java create mode 100644 sandbox-providers/glesys/src/main/java/org/jclouds/glesys/features/ArchiveClient.java create mode 100644 sandbox-providers/glesys/src/test/java/org/jclouds/glesys/features/ArchiveAsyncClientTest.java create mode 100644 sandbox-providers/glesys/src/test/java/org/jclouds/glesys/features/ArchiveClientLiveTest.java create mode 100644 sandbox-providers/glesys/src/test/java/org/jclouds/glesys/parse/ParseArchiveAllowedArgumentsTest.java create mode 100644 sandbox-providers/glesys/src/test/java/org/jclouds/glesys/parse/ParseArchiveDetailsTest.java create mode 100644 sandbox-providers/glesys/src/test/java/org/jclouds/glesys/parse/ParseArchiveListTest.java create mode 100644 sandbox-providers/glesys/src/test/resources/archive_allowed_arguments.json create mode 100644 sandbox-providers/glesys/src/test/resources/archive_details.json create mode 100644 sandbox-providers/glesys/src/test/resources/archive_list.json diff --git a/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/GleSYSAsyncClient.java b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/GleSYSAsyncClient.java index 328b29bf57..ae62411086 100644 --- a/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/GleSYSAsyncClient.java +++ b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/GleSYSAsyncClient.java @@ -18,6 +18,7 @@ */ package org.jclouds.glesys; +import org.jclouds.glesys.features.ArchiveAsyncClient; import org.jclouds.glesys.features.IpAsyncClient; import org.jclouds.glesys.features.ServerAsyncClient; import org.jclouds.rest.annotations.Delegate; @@ -43,4 +44,10 @@ public interface GleSYSAsyncClient { */ @Delegate IpAsyncClient getIpClient(); + + /** + * Provides asynchronous access to Archive features. + */ + @Delegate + ArchiveAsyncClient getArchiveClient(); } diff --git a/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/GleSYSClient.java b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/GleSYSClient.java index aef4903f13..2fc6c6a8ff 100644 --- a/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/GleSYSClient.java +++ b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/GleSYSClient.java @@ -21,6 +21,8 @@ package org.jclouds.glesys; import java.util.concurrent.TimeUnit; import org.jclouds.concurrent.Timeout; +import org.jclouds.glesys.features.ArchiveAsyncClient; +import org.jclouds.glesys.features.ArchiveClient; import org.jclouds.glesys.features.IpClient; import org.jclouds.glesys.features.ServerClient; import org.jclouds.rest.annotations.Delegate; @@ -47,4 +49,10 @@ public interface GleSYSClient { */ @Delegate IpClient getIpClient(); + + /** + * Provides synchronous access to Archive features. + */ + @Delegate + ArchiveClient getArchiveClient(); } diff --git a/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/config/GleSYSRestClientModule.java b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/config/GleSYSRestClientModule.java index 6bc36e6e30..5cc4567c30 100644 --- a/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/config/GleSYSRestClientModule.java +++ b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/config/GleSYSRestClientModule.java @@ -22,10 +22,7 @@ import java.util.Map; import org.jclouds.glesys.GleSYSAsyncClient; import org.jclouds.glesys.GleSYSClient; -import org.jclouds.glesys.features.IpAsyncClient; -import org.jclouds.glesys.features.IpClient; -import org.jclouds.glesys.features.ServerAsyncClient; -import org.jclouds.glesys.features.ServerClient; +import org.jclouds.glesys.features.*; import org.jclouds.glesys.handlers.GleSYSErrorHandler; import org.jclouds.http.HttpErrorHandler; import org.jclouds.http.HttpRetryHandler; @@ -51,6 +48,7 @@ public class GleSYSRestClientModule extends RestClientModule, Class> DELEGATE_MAP = ImmutableMap., Class> builder()// .put(ServerClient.class, ServerAsyncClient.class)// .put(IpClient.class, IpAsyncClient.class)// + .put(ArchiveClient.class, ArchiveAsyncClient.class)// .build(); public GleSYSRestClientModule() { diff --git a/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/domain/Archive.java b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/domain/Archive.java new file mode 100644 index 0000000000..d323451987 --- /dev/null +++ b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/domain/Archive.java @@ -0,0 +1,109 @@ +package org.jclouds.glesys.domain; + +import com.google.common.base.Objects; +import com.google.gson.annotations.SerializedName; + +/** + * Information about an archive + * + * @author Adam Lowe + * @see + */ +public class Archive { + public static Builder builder() { + return new Builder(); + } + + public static class Builder { + protected String username; + protected String totalSize; + protected String freeSize; + protected boolean locked; + + public Builder username(String username) { + this.username = username; + return this; + } + + public Builder totalSize(String totalSize) { + this.totalSize = totalSize; + return this; + } + + public Builder freeSize(String freeSize) { + this.freeSize = freeSize; + return this; + } + + public Builder locked(boolean locked) { + this.locked = locked; + return this; + } + + public Archive build() { + return new Archive(username, totalSize, freeSize, locked); + } + + public Builder fromArchive(Archive in) { + return username(in.getUsername()).totalSize(in.getTotalSize()).freeSize(in.getFreeSize()).locked(in.isLocked()); + } + } + + private final String username; + @SerializedName("size_total") + private final String totalSize; + @SerializedName("size_free") + private final String freeSize; + private final boolean locked; + + public String getUsername() { + return username; + } + + public String getTotalSize() { + return totalSize; + } + + public String getFreeSize() { + return freeSize; + } + + public boolean isLocked() { + return locked; + } + + public Archive(String username, String totalSize, String freeSize, boolean locked) { + this.username = username; + this.totalSize = totalSize; + this.freeSize = freeSize; + this.locked = locked; + } + + + @Override + public int hashCode() { + return Objects.hashCode(username, totalSize, freeSize, locked); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj instanceof Archive) { + Archive other = (Archive) obj; + return Objects.equal(username, other.username) + && Objects.equal(totalSize, other.totalSize) + && Objects.equal(freeSize, other.freeSize) + && Objects.equal(locked, other.locked); + } else { + return false; + } + } + + @Override + public String toString() { + return String.format("[username=%s, totalSize=%s, freeSize=%s, locked=%b]", username, totalSize, freeSize, locked); + } + +} diff --git a/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/domain/ArchiveAllowedArguments.java b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/domain/ArchiveAllowedArguments.java new file mode 100644 index 0000000000..bab12bc4e8 --- /dev/null +++ b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/domain/ArchiveAllowedArguments.java @@ -0,0 +1,84 @@ +package org.jclouds.glesys.domain; + +import com.google.common.base.Joiner; +import com.google.common.base.Objects; +import com.google.gson.annotations.SerializedName; + +import java.util.Arrays; +import java.util.List; + +import static com.google.common.base.Preconditions.checkArgument; + +/** + * The allowed arguments for archive manipulation, such as archivesize + * + * @author Adam Lowe + * @see + */ +public class ArchiveAllowedArguments { + public static Builder builder() { + return new Builder(); + } + + public static class Builder { + private List archiveSizes; + + public Builder archiveSizes(List archiveSizes) { + this.archiveSizes = archiveSizes; + return this; + } + + public Builder archiveSizes(Integer... archiveSizes) { + return archiveSizes(Arrays.asList(archiveSizes)); + } + + public ArchiveAllowedArguments build() { + return new ArchiveAllowedArguments(archiveSizes); + } + + public Builder fromArchiveAllowedArguments(ArchiveAllowedArguments in) { + return archiveSizes(in.getArchiveSizes()); + } + } + + @SerializedName("archivesize") + private final List archiveSizes; + + public ArchiveAllowedArguments(List archiveSizes) { + checkArgument(archiveSizes != null, "archiveSizes"); + this.archiveSizes = archiveSizes; + } + + /** + * @return the list of allowed archive sizes, in GB + */ + public List getArchiveSizes() { + return archiveSizes; + } + + @Override + public boolean equals(Object object) { + if (this == object) { + return true; + } + if (object instanceof ArchiveAllowedArguments) { + ArchiveAllowedArguments other = (ArchiveAllowedArguments) object; + return Objects.equal(archiveSizes, other.archiveSizes); + } else { + return false; + } + } + + @Override + public int hashCode() { + return Objects.hashCode(archiveSizes); + } + + @Override + public String toString() { + Joiner commaJoiner = Joiner.on(", "); + return String.format( + "[archiveSizes=[%s]]", commaJoiner.join(archiveSizes)); + } + +} diff --git a/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/domain/ArchiveDetails.java b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/domain/ArchiveDetails.java new file mode 100644 index 0000000000..30b1503f14 --- /dev/null +++ b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/domain/ArchiveDetails.java @@ -0,0 +1,47 @@ +package org.jclouds.glesys.domain; + +/** + * Detailed information about an archive volume. + * + * @author Adam Lowe + * @see + */ +public class ArchiveDetails extends Archive { + public static Builder builder() { + return new Builder(); + } + + public static class Builder extends Archive.Builder { + public ArchiveDetails build() { + return new ArchiveDetails(username, totalSize, freeSize, locked); + } + + public Builder fromArchiveDetails(ArchiveDetails in) { + return username(in.getUsername()).totalSize(in.getTotalSize()).freeSize(in.getFreeSize()).locked(in.isLocked()); + } + + @Override + public Builder username(String username) { + return Builder.class.cast(super.username(username)); + } + + @Override + public Builder totalSize(String size) { + return Builder.class.cast(super.totalSize(size)); + } + + @Override + public Builder freeSize(String size) { + return Builder.class.cast(super.freeSize(size)); + } + + @Override + public Builder locked(boolean locked) { + return Builder.class.cast(super.locked(locked)); + } + } + + public ArchiveDetails(String username, String totalSize, String freeSize, boolean locked) { + super(username, totalSize, freeSize, locked); + } +} diff --git a/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/domain/ServerCreated.java b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/domain/ServerCreated.java index 7c243ca49b..d9e18f5932 100644 --- a/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/domain/ServerCreated.java +++ b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/domain/ServerCreated.java @@ -2,6 +2,7 @@ package org.jclouds.glesys.domain; import static com.google.common.base.Preconditions.checkNotNull; +import java.util.Arrays; import java.util.List; import com.google.common.base.Objects; @@ -28,10 +29,14 @@ public class ServerCreated { this.id = id; return this; } - public Builder port(List ips) { + public Builder ips(List ips) { this.ips = ips; return this; } + + public Builder ips(ServerCreatedIp... ips) { + return ips(Arrays.asList(ips)); + } public Builder hostname(String hostname) { this.hostname = hostname; @@ -43,7 +48,7 @@ public class ServerCreated { } public Builder fromServerCreated(ServerCreated in) { - return id(in.getId()).hostname(in.getHostname()).port(in.getIps()); + return id(in.getId()).hostname(in.getHostname()).ips(in.getIps()); } } diff --git a/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/features/ArchiveAsyncClient.java b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/features/ArchiveAsyncClient.java new file mode 100644 index 0000000000..688fd1f974 --- /dev/null +++ b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/features/ArchiveAsyncClient.java @@ -0,0 +1,104 @@ +/** + * 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.glesys.features; + +import com.google.common.util.concurrent.ListenableFuture; +import org.jclouds.glesys.domain.Archive; +import org.jclouds.glesys.domain.ArchiveAllowedArguments; +import org.jclouds.glesys.domain.ArchiveDetails; +import org.jclouds.http.filters.BasicAuthentication; +import org.jclouds.rest.annotations.ExceptionParser; +import org.jclouds.rest.annotations.RequestFilters; +import org.jclouds.rest.annotations.SelectJson; +import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404; +import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; + +import javax.ws.rs.*; +import javax.ws.rs.core.MediaType; +import java.util.Set; + +/** + * Provides asynchronous access to Archive data via the Glesys REST API. + *

+ * + * @author Adam Lowe + * @see ArchiveClient + * @see + */ +@RequestFilters(BasicAuthentication.class) +public interface ArchiveAsyncClient { + + /** + * @see ArchiveClient#listArchives + */ + @GET + @Path("/archive/list/format/json") + @SelectJson("archives") + @Consumes(MediaType.APPLICATION_JSON) + @ExceptionParser(ReturnEmptySetOnNotFoundOr404.class) + ListenableFuture> listArchives(); + + /** + * @see ArchiveClient#archiveDetails + */ + @GET + @Path("/archive/details/format/json") + @SelectJson("details") + @Consumes(MediaType.APPLICATION_JSON) + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + ListenableFuture archiveDetails(@FormParam("username") String username); + + /** + * @see ArchiveClient#createArchive + */ + @POST + @Path("/archive/create/format/json") + ListenableFuture createArchive(@FormParam("username") String username, @FormParam("password") String password, + @FormParam("size")int size); + + /** + * @see ArchiveClient#deleteArchive + */ + @POST + @Path("/archive/delete/format/json") + ListenableFuture deleteArchive(@FormParam("username") String username); + + /** + * @see ArchiveClient#resizeArchive + */ + @POST + @Path("/archive/resize/format/json") + ListenableFuture resizeArchive(@FormParam("username") String username, @FormParam("size")int size); + /** + * @see ArchiveClient#changeArchivePassword + */ + @POST + @Path("/archive/changepassword/format/json") + ListenableFuture changeArchivePassword(@FormParam("username") String username, @FormParam("password") String password); + + /** + * @see org.jclouds.glesys.features.ArchiveClient#getArchiveAllowedArguments + */ + @GET + @Path("/archive/allowedarguments/format/json") + @SelectJson("argumentslist") + @Consumes(MediaType.APPLICATION_JSON) + ListenableFuture getArchiveAllowedArguments(); + +} diff --git a/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/features/ArchiveClient.java b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/features/ArchiveClient.java new file mode 100644 index 0000000000..039fb52a91 --- /dev/null +++ b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/features/ArchiveClient.java @@ -0,0 +1,93 @@ +/** + * 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.glesys.features; + +import org.jclouds.concurrent.Timeout; +import org.jclouds.glesys.domain.Archive; +import org.jclouds.glesys.domain.ArchiveAllowedArguments; +import org.jclouds.glesys.domain.ArchiveDetails; + +import java.util.Set; +import java.util.concurrent.TimeUnit; + +/** + * Provides synchronous access to Archive requests. + *

+ * + * @author Adam Lowe + * @see ArchiveAsyncClient + * @see + */ +@Timeout(duration = 30, timeUnit = TimeUnit.SECONDS) +public interface ArchiveClient { + + /** + * Lists all active disks on this account. + */ + Set listArchives(); + + /** + * Get detailed information about an archive volume. + * + * @param username the username associated with the archive + * @return the archive information or null if not found + */ + ArchiveDetails archiveDetails(String username); + + /** + * Create a new backup volume. + * + * @param username the archive username, this must be prefixed by Glesys account name (in lower case) and an + * underscore, ex. "c100005_archive1" + * @param password the new password + * @param size the new size required in GB + */ + void createArchive(String username, String password, int size); + + /** + * Delete an archive volume. All files on the volume + * + * @param username the username associated with the archive + */ + void deleteArchive(String username); + + /** + * Resize an archive volume. It is only possible to upgrade the size of the disk. Downgrading is currently not + * supported. If you need to downgrade, please create a new volume and transfer all data to the new volume. + * Then delete the old volume. + * + * @param username the username associated with the archive + * @param size the new size required in GB + */ + void resizeArchive(String username, int size); + + /** + * Change the password for an archive user. + * + * @param username the archive username + * @param password the new password + */ + void changeArchivePassword(String username, String password); + + /** + * Lists the allowed arguments for some of the functions in this module such as archive size. + */ + ArchiveAllowedArguments getArchiveAllowedArguments(); + +} \ No newline at end of file diff --git a/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/features/ServerAsyncClient.java b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/features/ServerAsyncClient.java index 30400e60f7..df95604de8 100644 --- a/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/features/ServerAsyncClient.java +++ b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/features/ServerAsyncClient.java @@ -96,13 +96,13 @@ public interface ServerAsyncClient { /** - * @see ServerClient#getAllowedArguments + * @see ServerClient#getServerAllowedArguments */ @GET @Path("/server/allowedarguments/format/json") @SelectJson("argumentslist") @Consumes(MediaType.APPLICATION_JSON) - ListenableFuture> getAllowedArguments(); + ListenableFuture> getServerAllowedArguments(); /** * @see ServerClient#getTemplates diff --git a/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/features/ServerClient.java b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/features/ServerClient.java index 8bbd00b669..05c4a3aa50 100644 --- a/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/features/ServerClient.java +++ b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/features/ServerClient.java @@ -95,7 +95,7 @@ public interface ServerClient { * * @return a map of argument lists, keyed on platform */ - Map getAllowedArguments(); + Map getServerAllowedArguments(); /** * Reset the fail count for a server limit (for OpenVZ only). diff --git a/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/functions/internal/CustomDeserializers.java b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/functions/internal/CustomDeserializers.java index 85a158a6ab..dd4b477a9f 100644 --- a/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/functions/internal/CustomDeserializers.java +++ b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/functions/internal/CustomDeserializers.java @@ -4,16 +4,13 @@ import com.google.gson.JsonDeserializationContext; import com.google.gson.JsonDeserializer; import com.google.gson.JsonElement; import com.google.gson.JsonParseException; -import org.jclouds.glesys.domain.ServerAllowedArguments; import org.jclouds.glesys.domain.ServerState; import org.jclouds.glesys.domain.ServerUptime; import java.lang.reflect.Type; -import java.util.HashSet; -import java.util.Set; /** - * @Author Adam Lowe + * @author Adam Lowe */ public class CustomDeserializers { @@ -34,17 +31,4 @@ public class CustomDeserializers { return ServerUptime.fromValue(toParse); } } - - public static class ServerAllowedArgumentsAdaptor implements JsonDeserializer> { - - @Override - public Set deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) throws JsonParseException { - Set result = new HashSet(); - for(JsonElement e : jsonElement.getAsJsonObject().get("OpenVZ").getAsJsonArray()) { - result.add(jsonDeserializationContext.deserialize(e, ServerAllowedArguments.class)); - } - return result; - } - } - } \ No newline at end of file diff --git a/sandbox-providers/glesys/src/test/java/org/jclouds/glesys/GleSYSAsyncClientTest.java b/sandbox-providers/glesys/src/test/java/org/jclouds/glesys/GleSYSAsyncClientTest.java index d69c8c887e..bfd3ebfec5 100644 --- a/sandbox-providers/glesys/src/test/java/org/jclouds/glesys/GleSYSAsyncClientTest.java +++ b/sandbox-providers/glesys/src/test/java/org/jclouds/glesys/GleSYSAsyncClientTest.java @@ -45,11 +45,13 @@ public class GleSYSAsyncClientTest extends BaseGleSYSAsyncClientTest { + + @Override + protected TypeLiteral> createTypeLiteral() { + return new TypeLiteral>() { + }; + } +} diff --git a/sandbox-providers/glesys/src/test/java/org/jclouds/glesys/features/ArchiveClientLiveTest.java b/sandbox-providers/glesys/src/test/java/org/jclouds/glesys/features/ArchiveClientLiveTest.java new file mode 100644 index 0000000000..f4ac3dcbac --- /dev/null +++ b/sandbox-providers/glesys/src/test/java/org/jclouds/glesys/features/ArchiveClientLiveTest.java @@ -0,0 +1,123 @@ +/** + * 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.glesys.features; + +import com.google.common.base.Predicate; +import com.google.common.base.Predicates; +import org.jclouds.glesys.domain.*; +import org.jclouds.predicates.RetryablePredicate; +import org.testng.annotations.AfterGroups; +import org.testng.annotations.BeforeGroups; +import org.testng.annotations.Test; + +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.TimeUnit; + +import static com.google.common.base.Predicates.equalTo; +import static org.testng.Assert.*; + +/** + * Tests behavior of {@code ArchiveClient} + * + * @author Adam Lowe + */ +@Test(groups = "live", testName = "ArchiveClientLiveTest") +public class ArchiveClientLiveTest extends BaseGleSYSClientLiveTest { + + @BeforeGroups(groups = {"live"}) + public void setupClient() { + super.setupClient(); + + client = context.getApi().getArchiveClient(); + archiveUser = context.getIdentity().toLowerCase() + "_jcloudstest9"; + archiveCounter = new RetryablePredicate( + new Predicate() { + public boolean apply(Integer value){ + return client.listArchives().size() == value; + } + }, 30, 1, TimeUnit.SECONDS); + } + + @AfterGroups(alwaysRun = true, groups={"live"}) + public void teardownClient() { + int before = client.listArchives().size(); + client.deleteArchive(archiveUser); + assertTrue(archiveCounter.apply(before - 1)); + } + + private ArchiveClient client; + private String archiveUser; + private RetryablePredicate archiveCounter; + + @Test + public void testAllowedArguments() throws Exception { + ArchiveAllowedArguments args = client.getArchiveAllowedArguments(); + assertNotNull(args); + assertNotNull(args.getArchiveSizes()); + assertTrue(args.getArchiveSizes().size() > 0); + + for (int size : args.getArchiveSizes()) { + assertTrue(size > 0); + } + } + + @Test + public void testCreateArchive() throws Exception { + try { + client.deleteArchive(archiveUser); + } catch(Exception ex) { + } + + int before = client.listArchives().size(); + + client.createArchive(archiveUser, "password", 10); + + assertTrue(archiveCounter.apply(before + 1)); + } + + @Test(dependsOnMethods = "testCreateArchive") + public void testArchiveDetails() throws Exception { + ArchiveDetails details = client.archiveDetails(archiveUser); + assertEquals(details.getUsername(), archiveUser); + assertNotNull(details.getFreeSize()); + assertNotNull(details.getTotalSize()); + } + + @Test(dependsOnMethods = "testCreateArchive") + public void testChangePassword() throws Exception { + client.changeArchivePassword(archiveUser, "newpassword"); + // TODO assert something useful! + } + + // TODO enable this once issue is resolved + @Test(enabled=false, dependsOnMethods = "testCreateArchive") + public void testResizeArchive() throws Exception { + client.resizeArchive(archiveUser, 30); + + assertTrue(new RetryablePredicate( + new Predicate() { + public boolean apply(String value){ + return client.archiveDetails(archiveUser) != null && value.equals(client.archiveDetails(archiveUser).getTotalSize()); + } + }, 30, 1, TimeUnit.SECONDS).apply("20 GB")); + } + +} diff --git a/sandbox-providers/glesys/src/test/java/org/jclouds/glesys/features/ServerClientLiveTest.java b/sandbox-providers/glesys/src/test/java/org/jclouds/glesys/features/ServerClientLiveTest.java index ce4329edae..b90cb494e0 100644 --- a/sandbox-providers/glesys/src/test/java/org/jclouds/glesys/features/ServerClientLiveTest.java +++ b/sandbox-providers/glesys/src/test/java/org/jclouds/glesys/features/ServerClientLiveTest.java @@ -18,16 +18,15 @@ */ package org.jclouds.glesys.features; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertNotNull; -import static org.testng.Assert.assertTrue; +import com.google.common.base.Predicate; +import org.jclouds.glesys.domain.*; +import org.testng.annotations.BeforeGroups; +import org.testng.annotations.Test; import java.util.Map; import java.util.Set; -import org.jclouds.glesys.domain.*; -import org.testng.annotations.BeforeGroups; -import org.testng.annotations.Test; +import static org.testng.Assert.*; /** * Tests behavior of {@code ServerClient} @@ -42,12 +41,25 @@ public class ServerClientLiveTest extends BaseGleSYSClientLiveTest { super.setupClient(); client = context.getApi().getServerClient(); } - - private ServerClient client; + public static class ServerStatePredicate implements Predicate { + private ServerState state; + private String serverId; + public ServerStatePredicate(ServerState state, String serverId) { + this.state = state; + this.serverId = serverId; + } + @Override + public boolean apply(ServerClient client) { + return client.getServerStatus(serverId) != null && client.getServerStatus(serverId).getState() == state; + } + } + + private ServerClient client; + @Test public void testAllowedArguments() throws Exception { - Map templates = client.getAllowedArguments(); + Map templates = client.getServerAllowedArguments(); assertTrue(templates.containsKey("OpenVZ")); assertTrue(templates.containsKey("Xen")); diff --git a/sandbox-providers/glesys/src/test/java/org/jclouds/glesys/parse/ParseArchiveAllowedArgumentsTest.java b/sandbox-providers/glesys/src/test/java/org/jclouds/glesys/parse/ParseArchiveAllowedArgumentsTest.java new file mode 100644 index 0000000000..d42147b58c --- /dev/null +++ b/sandbox-providers/glesys/src/test/java/org/jclouds/glesys/parse/ParseArchiveAllowedArgumentsTest.java @@ -0,0 +1,61 @@ +/** + * 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.glesys.parse; + + +import com.google.inject.Guice; +import com.google.inject.Injector; +import org.jclouds.glesys.config.GleSYSParserModule; +import org.jclouds.glesys.domain.ArchiveAllowedArguments; +import org.jclouds.glesys.domain.ServerAllowedArguments; +import org.jclouds.json.BaseItemParserTest; +import org.jclouds.json.config.GsonModule; +import org.jclouds.rest.annotations.SelectJson; +import org.testng.annotations.Test; + +import javax.ws.rs.Consumes; +import javax.ws.rs.core.MediaType; +import java.util.LinkedHashMap; +import java.util.Map; + +/** + * @author Adam Lowe + */ +@Test(groups = "unit", testName = "ParseServerAllowedArgumentsTest") +public class ParseArchiveAllowedArgumentsTest extends BaseItemParserTest { + + @Override + public String resource() { + return "/archive_allowed_arguments.json"; + } + + @Override + @SelectJson("argumentslist") + @Consumes(MediaType.APPLICATION_JSON) + public ArchiveAllowedArguments expected() { + return ArchiveAllowedArguments.builder().archiveSizes(new Integer[] { + 10,20,30,40,50,60,70,80,90,100,125,150,175,200,225,250,275,300,325,350,375,400,425,450,475,500,550,600,650,700,750,800,850,900,950,1000 + }).build(); + } + + + protected Injector injector() { + return Guice.createInjector(new GleSYSParserModule(), new GsonModule()); + } +} diff --git a/sandbox-providers/glesys/src/test/java/org/jclouds/glesys/parse/ParseArchiveDetailsTest.java b/sandbox-providers/glesys/src/test/java/org/jclouds/glesys/parse/ParseArchiveDetailsTest.java new file mode 100644 index 0000000000..36f2c1f790 --- /dev/null +++ b/sandbox-providers/glesys/src/test/java/org/jclouds/glesys/parse/ParseArchiveDetailsTest.java @@ -0,0 +1,61 @@ +/** + * 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.glesys.parse; + +import com.google.common.collect.ImmutableSet; +import com.google.inject.Guice; +import com.google.inject.Injector; +import org.jclouds.glesys.config.GleSYSParserModule; +import org.jclouds.glesys.domain.Archive; +import org.jclouds.glesys.domain.ArchiveDetails; +import org.jclouds.json.BaseItemParserTest; +import org.jclouds.json.BaseParserTest; +import org.jclouds.json.BaseSetParserTest; +import org.jclouds.json.config.GsonModule; +import org.jclouds.rest.annotations.SelectJson; +import org.testng.annotations.Test; + +import javax.ws.rs.Consumes; +import javax.ws.rs.core.MediaType; +import java.util.Set; + +/** + * + * @author Adrian Cole + */ +@Test(groups = "unit", testName = "ParseArchiveDetailsTest") +public class ParseArchiveDetailsTest extends BaseItemParserTest { + + @Override + public String resource() { + return "/archive_details.json"; + } + + @Override + @SelectJson("details") + @Consumes(MediaType.APPLICATION_JSON) + public ArchiveDetails expected() { + return ArchiveDetails.builder().username("xxxxxx_test1").totalSize("30 GB").freeSize("30 GB").locked(false).build(); + } + + protected Injector injector() { + return Guice.createInjector(new GleSYSParserModule(), new GsonModule()); + } + +} diff --git a/sandbox-providers/glesys/src/test/java/org/jclouds/glesys/parse/ParseArchiveListTest.java b/sandbox-providers/glesys/src/test/java/org/jclouds/glesys/parse/ParseArchiveListTest.java new file mode 100644 index 0000000000..a79e74f742 --- /dev/null +++ b/sandbox-providers/glesys/src/test/java/org/jclouds/glesys/parse/ParseArchiveListTest.java @@ -0,0 +1,59 @@ +/** + * 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.glesys.parse; + +import com.google.common.collect.ImmutableSet; +import com.google.inject.Guice; +import com.google.inject.Injector; +import org.jclouds.glesys.config.GleSYSParserModule; +import org.jclouds.glesys.domain.Archive; +import org.jclouds.glesys.domain.Server; +import org.jclouds.json.BaseSetParserTest; +import org.jclouds.json.config.GsonModule; +import org.jclouds.rest.annotations.SelectJson; +import org.testng.annotations.Test; + +import javax.ws.rs.Consumes; +import javax.ws.rs.core.MediaType; +import java.util.Set; + +/** + * + * @author Adrian Cole + */ +@Test(groups = "unit", testName = "ParseArchiveListTest") +public class ParseArchiveListTest extends BaseSetParserTest { + + @Override + public String resource() { + return "/archive_list.json"; + } + + @Override + @SelectJson("archives") + @Consumes(MediaType.APPLICATION_JSON) + public Set expected() { + return ImmutableSet.of(Archive.builder().username("xxxxx_test1").totalSize("30 GB").freeSize("30 GB").locked(false).build()); + } + + protected Injector injector() { + return Guice.createInjector(new GleSYSParserModule(), new GsonModule()); + } + +} diff --git a/sandbox-providers/glesys/src/test/java/org/jclouds/glesys/parse/ParseServerCreatedTest.java b/sandbox-providers/glesys/src/test/java/org/jclouds/glesys/parse/ParseServerCreatedTest.java index 7023f33694..cd1b64812c 100644 --- a/sandbox-providers/glesys/src/test/java/org/jclouds/glesys/parse/ParseServerCreatedTest.java +++ b/sandbox-providers/glesys/src/test/java/org/jclouds/glesys/parse/ParseServerCreatedTest.java @@ -19,20 +19,19 @@ package org.jclouds.glesys.parse; -import javax.ws.rs.Consumes; -import javax.ws.rs.core.MediaType; -import java.util.*; - import com.google.inject.Guice; import com.google.inject.Injector; import org.jclouds.glesys.config.GleSYSParserModule; -import org.jclouds.glesys.domain.ServerCreatedIp; import org.jclouds.glesys.domain.ServerCreated; +import org.jclouds.glesys.domain.ServerCreatedIp; import org.jclouds.json.BaseItemParserTest; import org.jclouds.json.config.GsonModule; import org.jclouds.rest.annotations.SelectJson; import org.testng.annotations.Test; +import javax.ws.rs.Consumes; +import javax.ws.rs.core.MediaType; + /** * @author Adam Lowe */ @@ -48,9 +47,7 @@ public class ParseServerCreatedTest extends BaseItemParserTest { @SelectJson("server") @Consumes(MediaType.APPLICATION_JSON) public ServerCreated expected() { - List ips = new ArrayList(); - ips.add(ServerCreatedIp.builder().ip("109.74.10.27").version(4).cost(2.00).build()); - return ServerCreated.builder().id("xm3630641").hostname("jclouds-test-host").port(ips).build(); + return ServerCreated.builder().id("xm3630641").hostname("jclouds-test-host").ips(ServerCreatedIp.builder().ip("109.74.10.27").version(4).cost(2.00).build()).build(); } diff --git a/sandbox-providers/glesys/src/test/resources/archive_allowed_arguments.json b/sandbox-providers/glesys/src/test/resources/archive_allowed_arguments.json new file mode 100644 index 0000000000..266522dab0 --- /dev/null +++ b/sandbox-providers/glesys/src/test/resources/archive_allowed_arguments.json @@ -0,0 +1 @@ +{"response":{"status":{"code":"200","text":"OK"},"argumentslist":{"archivesize":["10","20","30","40","50","60","70","80","90","100","125","150","175","200","225","250","275","300","325","350","375","400","425","450","475","500","550","600","650","700","750","800","850","900","950","1000"]},"debug":{"input":[]}}} \ No newline at end of file diff --git a/sandbox-providers/glesys/src/test/resources/archive_details.json b/sandbox-providers/glesys/src/test/resources/archive_details.json new file mode 100644 index 0000000000..04be81faa7 --- /dev/null +++ b/sandbox-providers/glesys/src/test/resources/archive_details.json @@ -0,0 +1 @@ +{"response":{"status":{"code":"200","text":"OK"},"details":{"username":"xxxxxx_test1","size_total":"30 GB","size_free":"30 GB","locked":false},"debug":{"input":{"username":"xxxxxx_test1"}}}} \ No newline at end of file diff --git a/sandbox-providers/glesys/src/test/resources/archive_list.json b/sandbox-providers/glesys/src/test/resources/archive_list.json new file mode 100644 index 0000000000..0144c66e94 --- /dev/null +++ b/sandbox-providers/glesys/src/test/resources/archive_list.json @@ -0,0 +1 @@ +{"response":{"status":{"code":"200","text":"OK"},"archives":[{"username":"xxxxx_test1","size_total":"30 GB","size_free":"30 GB","locked":false}],"debug":{"input":[]}}} \ No newline at end of file