Merge pull request #264 from aplowe/master

This commit is contained in:
Mattias Holmqvist 2011-12-19 22:27:20 +01:00
parent 9cc786b130
commit 6e20d7c23b
23 changed files with 838 additions and 43 deletions

View File

@ -18,6 +18,7 @@
*/ */
package org.jclouds.glesys; package org.jclouds.glesys;
import org.jclouds.glesys.features.ArchiveAsyncClient;
import org.jclouds.glesys.features.IpAsyncClient; import org.jclouds.glesys.features.IpAsyncClient;
import org.jclouds.glesys.features.ServerAsyncClient; import org.jclouds.glesys.features.ServerAsyncClient;
import org.jclouds.rest.annotations.Delegate; import org.jclouds.rest.annotations.Delegate;
@ -43,4 +44,10 @@ public interface GleSYSAsyncClient {
*/ */
@Delegate @Delegate
IpAsyncClient getIpClient(); IpAsyncClient getIpClient();
/**
* Provides asynchronous access to Archive features.
*/
@Delegate
ArchiveAsyncClient getArchiveClient();
} }

View File

@ -21,6 +21,8 @@ package org.jclouds.glesys;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import org.jclouds.concurrent.Timeout; 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.IpClient;
import org.jclouds.glesys.features.ServerClient; import org.jclouds.glesys.features.ServerClient;
import org.jclouds.rest.annotations.Delegate; import org.jclouds.rest.annotations.Delegate;
@ -47,4 +49,10 @@ public interface GleSYSClient {
*/ */
@Delegate @Delegate
IpClient getIpClient(); IpClient getIpClient();
/**
* Provides synchronous access to Archive features.
*/
@Delegate
ArchiveClient getArchiveClient();
} }

View File

@ -22,10 +22,7 @@ import java.util.Map;
import org.jclouds.glesys.GleSYSAsyncClient; import org.jclouds.glesys.GleSYSAsyncClient;
import org.jclouds.glesys.GleSYSClient; import org.jclouds.glesys.GleSYSClient;
import org.jclouds.glesys.features.IpAsyncClient; import org.jclouds.glesys.features.*;
import org.jclouds.glesys.features.IpClient;
import org.jclouds.glesys.features.ServerAsyncClient;
import org.jclouds.glesys.features.ServerClient;
import org.jclouds.glesys.handlers.GleSYSErrorHandler; import org.jclouds.glesys.handlers.GleSYSErrorHandler;
import org.jclouds.http.HttpErrorHandler; import org.jclouds.http.HttpErrorHandler;
import org.jclouds.http.HttpRetryHandler; import org.jclouds.http.HttpRetryHandler;
@ -51,6 +48,7 @@ public class GleSYSRestClientModule extends RestClientModule<GleSYSClient, GleSY
public static final Map<Class<?>, Class<?>> DELEGATE_MAP = ImmutableMap.<Class<?>, Class<?>> builder()// public static final Map<Class<?>, Class<?>> DELEGATE_MAP = ImmutableMap.<Class<?>, Class<?>> builder()//
.put(ServerClient.class, ServerAsyncClient.class)// .put(ServerClient.class, ServerAsyncClient.class)//
.put(IpClient.class, IpAsyncClient.class)// .put(IpClient.class, IpAsyncClient.class)//
.put(ArchiveClient.class, ArchiveAsyncClient.class)//
.build(); .build();
public GleSYSRestClientModule() { public GleSYSRestClientModule() {

View File

@ -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 <a href= "https://customer.glesys.com/api.php?a=doc#archive_details" />
*/
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);
}
}

View File

@ -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 <a href= "https://customer.glesys.com/api.php?a=doc#archive_allowedarguments" />
*/
public class ArchiveAllowedArguments {
public static Builder builder() {
return new Builder();
}
public static class Builder {
private List<Integer> archiveSizes;
public Builder archiveSizes(List<Integer> 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<Integer> archiveSizes;
public ArchiveAllowedArguments(List<Integer> archiveSizes) {
checkArgument(archiveSizes != null, "archiveSizes");
this.archiveSizes = archiveSizes;
}
/**
* @return the list of allowed archive sizes, in GB
*/
public List<Integer> 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));
}
}

View File

@ -0,0 +1,47 @@
package org.jclouds.glesys.domain;
/**
* Detailed information about an archive volume.
*
* @author Adam Lowe
* @see <a href= "https://customer.glesys.com/api.php?a=doc#archive_details" />
*/
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);
}
}

View File

@ -2,6 +2,7 @@ package org.jclouds.glesys.domain;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import java.util.Arrays;
import java.util.List; import java.util.List;
import com.google.common.base.Objects; import com.google.common.base.Objects;
@ -28,10 +29,14 @@ public class ServerCreated {
this.id = id; this.id = id;
return this; return this;
} }
public Builder port(List<ServerCreatedIp> ips) { public Builder ips(List<ServerCreatedIp> ips) {
this.ips = ips; this.ips = ips;
return this; return this;
} }
public Builder ips(ServerCreatedIp... ips) {
return ips(Arrays.asList(ips));
}
public Builder hostname(String hostname) { public Builder hostname(String hostname) {
this.hostname = hostname; this.hostname = hostname;
@ -43,7 +48,7 @@ public class ServerCreated {
} }
public Builder fromServerCreated(ServerCreated in) { 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());
} }
} }

View File

@ -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.
* <p/>
*
* @author Adam Lowe
* @see ArchiveClient
* @see <a href="https://customer.glesys.com/api.php" />
*/
@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<Set<Archive>> listArchives();
/**
* @see ArchiveClient#archiveDetails
*/
@GET
@Path("/archive/details/format/json")
@SelectJson("details")
@Consumes(MediaType.APPLICATION_JSON)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<ArchiveDetails> archiveDetails(@FormParam("username") String username);
/**
* @see ArchiveClient#createArchive
*/
@POST
@Path("/archive/create/format/json")
ListenableFuture<Void> createArchive(@FormParam("username") String username, @FormParam("password") String password,
@FormParam("size")int size);
/**
* @see ArchiveClient#deleteArchive
*/
@POST
@Path("/archive/delete/format/json")
ListenableFuture<Void> deleteArchive(@FormParam("username") String username);
/**
* @see ArchiveClient#resizeArchive
*/
@POST
@Path("/archive/resize/format/json")
ListenableFuture<Void> resizeArchive(@FormParam("username") String username, @FormParam("size")int size);
/**
* @see ArchiveClient#changeArchivePassword
*/
@POST
@Path("/archive/changepassword/format/json")
ListenableFuture<Void> 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<ArchiveAllowedArguments> getArchiveAllowedArguments();
}

View File

@ -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.
* <p/>
*
* @author Adam Lowe
* @see ArchiveAsyncClient
* @see <a href="https://customer.glesys.com/api.php" />
*/
@Timeout(duration = 30, timeUnit = TimeUnit.SECONDS)
public interface ArchiveClient {
/**
* Lists all active disks on this account.
*/
Set<Archive> 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();
}

View File

@ -96,13 +96,13 @@ public interface ServerAsyncClient {
/** /**
* @see ServerClient#getAllowedArguments * @see ServerClient#getServerAllowedArguments
*/ */
@GET @GET
@Path("/server/allowedarguments/format/json") @Path("/server/allowedarguments/format/json")
@SelectJson("argumentslist") @SelectJson("argumentslist")
@Consumes(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON)
ListenableFuture<Map<String, ServerAllowedArguments>> getAllowedArguments(); ListenableFuture<Map<String, ServerAllowedArguments>> getServerAllowedArguments();
/** /**
* @see ServerClient#getTemplates * @see ServerClient#getTemplates

View File

@ -95,7 +95,7 @@ public interface ServerClient {
* *
* @return a map of argument lists, keyed on platform * @return a map of argument lists, keyed on platform
*/ */
Map<String, ServerAllowedArguments> getAllowedArguments(); Map<String, ServerAllowedArguments> getServerAllowedArguments();
/** /**
* Reset the fail count for a server limit (for OpenVZ only). * Reset the fail count for a server limit (for OpenVZ only).

View File

@ -4,16 +4,13 @@ import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer; import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement; import com.google.gson.JsonElement;
import com.google.gson.JsonParseException; import com.google.gson.JsonParseException;
import org.jclouds.glesys.domain.ServerAllowedArguments;
import org.jclouds.glesys.domain.ServerState; import org.jclouds.glesys.domain.ServerState;
import org.jclouds.glesys.domain.ServerUptime; import org.jclouds.glesys.domain.ServerUptime;
import java.lang.reflect.Type; import java.lang.reflect.Type;
import java.util.HashSet;
import java.util.Set;
/** /**
* @Author Adam Lowe * @author Adam Lowe
*/ */
public class CustomDeserializers { public class CustomDeserializers {
@ -34,17 +31,4 @@ public class CustomDeserializers {
return ServerUptime.fromValue(toParse); return ServerUptime.fromValue(toParse);
} }
} }
public static class ServerAllowedArgumentsAdaptor implements JsonDeserializer<Set<ServerAllowedArguments>> {
@Override
public Set<ServerAllowedArguments> deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) throws JsonParseException {
Set<ServerAllowedArguments> result = new HashSet<ServerAllowedArguments>();
for(JsonElement e : jsonElement.getAsJsonObject().get("OpenVZ").getAsJsonArray()) {
result.add(jsonDeserializationContext.<ServerAllowedArguments>deserialize(e, ServerAllowedArguments.class));
}
return result;
}
}
} }

View File

@ -45,11 +45,13 @@ public class GleSYSAsyncClientTest extends BaseGleSYSAsyncClientTest<GleSYSAsync
public void testSync() throws SecurityException, NoSuchMethodException, InterruptedException, ExecutionException { public void testSync() throws SecurityException, NoSuchMethodException, InterruptedException, ExecutionException {
assert syncClient.getServerClient() != null; assert syncClient.getServerClient() != null;
assert syncClient.getIpClient() != null; assert syncClient.getIpClient() != null;
assert syncClient.getArchiveClient() != null;
} }
public void testAsync() throws SecurityException, NoSuchMethodException, InterruptedException, ExecutionException { public void testAsync() throws SecurityException, NoSuchMethodException, InterruptedException, ExecutionException {
assert asyncClient.getServerClient() != null; assert asyncClient.getServerClient() != null;
assert asyncClient.getIpClient() != null; assert asyncClient.getIpClient() != null;
assert asyncClient.getArchiveClient() != null;
} }
@Override @Override

View File

@ -0,0 +1,38 @@
/**
* 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.inject.TypeLiteral;
import org.jclouds.rest.internal.RestAnnotationProcessor;
import org.testng.annotations.Test;
/**
* Tests annotation parsing of {@code ArchiveAsyncClient}
*
* @author Adam Lowe
*/
@Test(groups = "unit", testName = "ArchiveAsyncClientTest")
public class ArchiveAsyncClientTest extends BaseGleSYSAsyncClientTest<ArchiveAsyncClient> {
@Override
protected TypeLiteral<RestAnnotationProcessor<ArchiveAsyncClient>> createTypeLiteral() {
return new TypeLiteral<RestAnnotationProcessor<ArchiveAsyncClient>>() {
};
}
}

View File

@ -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<Integer>(
new Predicate<Integer>() {
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<Integer> 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<String>(
new Predicate<String>() {
public boolean apply(String value){
return client.archiveDetails(archiveUser) != null && value.equals(client.archiveDetails(archiveUser).getTotalSize());
}
}, 30, 1, TimeUnit.SECONDS).apply("20 GB"));
}
}

View File

@ -18,16 +18,15 @@
*/ */
package org.jclouds.glesys.features; package org.jclouds.glesys.features;
import static org.testng.Assert.assertEquals; import com.google.common.base.Predicate;
import static org.testng.Assert.assertNotNull; import org.jclouds.glesys.domain.*;
import static org.testng.Assert.assertTrue; import org.testng.annotations.BeforeGroups;
import org.testng.annotations.Test;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import org.jclouds.glesys.domain.*; import static org.testng.Assert.*;
import org.testng.annotations.BeforeGroups;
import org.testng.annotations.Test;
/** /**
* Tests behavior of {@code ServerClient} * Tests behavior of {@code ServerClient}
@ -42,12 +41,25 @@ public class ServerClientLiveTest extends BaseGleSYSClientLiveTest {
super.setupClient(); super.setupClient();
client = context.getApi().getServerClient(); client = context.getApi().getServerClient();
} }
private ServerClient client;
public static class ServerStatePredicate implements Predicate<ServerClient> {
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 @Test
public void testAllowedArguments() throws Exception { public void testAllowedArguments() throws Exception {
Map<String,ServerAllowedArguments> templates = client.getAllowedArguments(); Map<String,ServerAllowedArguments> templates = client.getServerAllowedArguments();
assertTrue(templates.containsKey("OpenVZ")); assertTrue(templates.containsKey("OpenVZ"));
assertTrue(templates.containsKey("Xen")); assertTrue(templates.containsKey("Xen"));

View File

@ -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<ArchiveAllowedArguments> {
@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());
}
}

View File

@ -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<ArchiveDetails> {
@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());
}
}

View File

@ -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<Archive> {
@Override
public String resource() {
return "/archive_list.json";
}
@Override
@SelectJson("archives")
@Consumes(MediaType.APPLICATION_JSON)
public Set<Archive> 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());
}
}

View File

@ -19,20 +19,19 @@
package org.jclouds.glesys.parse; 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.Guice;
import com.google.inject.Injector; import com.google.inject.Injector;
import org.jclouds.glesys.config.GleSYSParserModule; import org.jclouds.glesys.config.GleSYSParserModule;
import org.jclouds.glesys.domain.ServerCreatedIp;
import org.jclouds.glesys.domain.ServerCreated; import org.jclouds.glesys.domain.ServerCreated;
import org.jclouds.glesys.domain.ServerCreatedIp;
import org.jclouds.json.BaseItemParserTest; import org.jclouds.json.BaseItemParserTest;
import org.jclouds.json.config.GsonModule; import org.jclouds.json.config.GsonModule;
import org.jclouds.rest.annotations.SelectJson; import org.jclouds.rest.annotations.SelectJson;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import javax.ws.rs.Consumes;
import javax.ws.rs.core.MediaType;
/** /**
* @author Adam Lowe * @author Adam Lowe
*/ */
@ -48,9 +47,7 @@ public class ParseServerCreatedTest extends BaseItemParserTest<ServerCreated> {
@SelectJson("server") @SelectJson("server")
@Consumes(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON)
public ServerCreated expected() { public ServerCreated expected() {
List<ServerCreatedIp> ips = new ArrayList<ServerCreatedIp>(); return ServerCreated.builder().id("xm3630641").hostname("jclouds-test-host").ips(ServerCreatedIp.builder().ip("109.74.10.27").version(4).cost(2.00).build()).build();
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();
} }

View File

@ -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":[]}}}

View File

@ -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"}}}}

View File

@ -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":[]}}}