Merge pull request #271 from aplowe/master

Adding Glesys Domain service and improving Archive and Server services
This commit is contained in:
Adrian Cole 2011-12-21 18:42:53 -08:00
commit ce7d09fc5e
40 changed files with 1827 additions and 179 deletions

View File

@ -19,6 +19,7 @@
package org.jclouds.glesys; package org.jclouds.glesys;
import org.jclouds.glesys.features.ArchiveAsyncClient; import org.jclouds.glesys.features.ArchiveAsyncClient;
import org.jclouds.glesys.features.DomainAsyncClient;
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;
@ -50,4 +51,11 @@ public interface GleSYSAsyncClient {
*/ */
@Delegate @Delegate
ArchiveAsyncClient getArchiveClient(); ArchiveAsyncClient getArchiveClient();
/**
* Provides asynchronous access to DNS features.
*/
@Delegate
DomainAsyncClient getDomainClient();
} }

View File

@ -18,15 +18,15 @@
*/ */
package org.jclouds.glesys; package org.jclouds.glesys;
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.ArchiveClient;
import org.jclouds.glesys.features.DomainClient;
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;
import java.util.concurrent.TimeUnit;
/** /**
* Provides synchronous access to GleSYS. * Provides synchronous access to GleSYS.
* <p/> * <p/>
@ -55,4 +55,10 @@ public interface GleSYSClient {
*/ */
@Delegate @Delegate
ArchiveClient getArchiveClient(); ArchiveClient getArchiveClient();
/**
* Provides synchronous access to DNS features.
*/
@Delegate
DomainClient getDomainClient();
} }

View File

@ -24,6 +24,7 @@ import com.google.inject.Provides;
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 org.jclouds.glesys.functions.internal.CustomDeserializers; import org.jclouds.glesys.functions.internal.CustomDeserializers;
import org.jclouds.glesys.functions.internal.GlesysDateAdapter;
import org.jclouds.json.config.GsonModule; import org.jclouds.json.config.GsonModule;
import org.jclouds.json.config.GsonModule.DateAdapter; import org.jclouds.json.config.GsonModule.DateAdapter;
@ -47,7 +48,7 @@ public class GleSYSParserModule extends AbstractModule {
@Override @Override
protected void configure() { protected void configure() {
bind(DateAdapter.class).to(GsonModule.Iso8601DateAdapter.class); bind(DateAdapter.class).to(GlesysDateAdapter.class);
} }
} }

View File

@ -49,6 +49,7 @@ public class GleSYSRestClientModule extends RestClientModule<GleSYSClient, GleSY
.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)// .put(ArchiveClient.class, ArchiveAsyncClient.class)//
.put(DomainClient.class, DomainAsyncClient.class)//
.build(); .build();
public GleSYSRestClientModule() { public GleSYSRestClientModule() {

View File

@ -9,7 +9,7 @@ import com.google.gson.annotations.SerializedName;
* @author Adam Lowe * @author Adam Lowe
* @see <a href= "https://customer.glesys.com/api.php?a=doc#archive_details" /> * @see <a href= "https://customer.glesys.com/api.php?a=doc#archive_details" />
*/ */
public class Archive { public class Archive implements Comparable<Archive> {
public static Builder builder() { public static Builder builder() {
return new Builder(); return new Builder();
} }
@ -82,23 +82,21 @@ public class Archive {
@Override @Override
public int hashCode() { public int hashCode() {
return Objects.hashCode(username, totalSize, freeSize, locked); return Objects.hashCode(username);
} }
@Override
public int compareTo(Archive other) {
return username.compareTo(other.getUsername());
}
@Override @Override
public boolean equals(Object obj) { public boolean equals(Object obj) {
if (this == obj) { if (this == obj) {
return true; return true;
} }
if (obj instanceof Archive) { return obj instanceof Archive
Archive other = (Archive) obj; && Objects.equal(username, ((Archive) obj).username);
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 @Override

View File

@ -61,12 +61,8 @@ public class ArchiveAllowedArguments {
if (this == object) { if (this == object) {
return true; return true;
} }
if (object instanceof ArchiveAllowedArguments) { return object instanceof ArchiveAllowedArguments
ArchiveAllowedArguments other = (ArchiveAllowedArguments) object; && Objects.equal(archiveSizes, ((ArchiveAllowedArguments) object).archiveSizes);
return Objects.equal(archiveSizes, other.archiveSizes);
} else {
return false;
}
} }
@Override @Override

View File

@ -0,0 +1,129 @@
/**
* 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.domain;
import com.google.common.base.Objects;
import com.google.gson.annotations.SerializedName;
import java.util.Date;
/**
* Domain data for a Glesys account.
*
* @author Adam Lowe
*/
public class Domain implements Comparable<Domain> {
public static Builder builder() {
return new Builder();
}
public static class Builder {
private String domain;
private Date createTime;
private int recordCount;
private boolean glesysNameServer;
public Builder domain(String domain) {
this.domain = domain;
return this;
}
public Builder createTime(Date createTime) {
this.createTime = createTime;
return this;
}
public Builder recordCount(int recordCount) {
this.recordCount = recordCount;
return this;
}
public Builder glesysNameServer(boolean glesysNameServer) {
this.glesysNameServer = glesysNameServer;
return this;
}
public Domain build() {
return new Domain(domain, createTime, recordCount, glesysNameServer);
}
public Builder fromDomain(Domain in) {
return new Builder();
}
}
private final String domain;
@SerializedName("create_time")
private final Date createTime;
@SerializedName("count")
private final int recordCount;
@SerializedName("glesysnameserver")
private final boolean glesysNameServer;
public Domain(String domain, Date createTime, int recordCount, boolean glesysNameServer) {
this.domain = domain;
this.createTime = createTime;
this.recordCount = recordCount;
this.glesysNameServer = glesysNameServer;
}
public String getDomain() {
return domain;
}
public Date getCreateTime() {
return createTime;
}
public int getRecordCount() {
return recordCount;
}
public boolean getGlesysNameServer() {
return glesysNameServer;
}
@Override
public int hashCode() {
return Objects.hashCode(domain);
}
@Override
public int compareTo(Domain other) {
return domain.compareTo(other.getDomain());
}
@Override
public boolean equals(Object object) {
if (this == object) {
return true;
}
if (object instanceof Domain) {
return Objects.equal(domain, ((Domain) object).domain);
} else {
return false;
}
}
@Override
public String toString() {
return String.format("[domain=%s, createTime=%s, count=%d, glesysnameserver=%b]", domain, createTime, recordCount, glesysNameServer);
}
}

View File

@ -0,0 +1,149 @@
/**
* 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.domain;
import com.google.common.base.Objects;
/**
* DNS record data.
*
* @author Adam Lowe
*/
public class DomainRecord implements Comparable<DomainRecord> {
public static Builder builder() {
return new Builder();
}
public static class Builder {
private String id;
private String zone;
private String host;
private String type;
private String data;
private int ttl;
public Builder id(String id) {
this.id = id;
return this;
}
public Builder zone(String zone) {
this.zone = zone;
return this;
}
public Builder host(String host) {
this.host = host;
return this;
}
public Builder type(String type) {
this.type = type;
return this;
}
public Builder data(String data) {
this.data = data;
return this;
}
public Builder ttl(int ttl) {
this.ttl = ttl;
return this;
}
public DomainRecord build() {
return new DomainRecord(id, zone, host, type, data, ttl);
}
public Builder fromDomainRecord(DomainRecord in) {
return new Builder().id(in.getId()).zone(in.getZone()).host(in.getHost()).type(in.getType()).data(in.getData()).ttl(in.getTtl());
}
}
private final String id;
private final String zone;
private final String host;
private final String type;
private final String data;
private final int ttl;
public DomainRecord(String id, String zone, String host, String type, String data, int ttl) {
this.id = id;
this.zone = zone;
this.host = host;
this.type = type;
this.data = data;
this.ttl = ttl;
}
public String getId() {
return id;
}
public String getZone() {
return zone;
}
public String getHost() {
return host;
}
public String getType() {
return type;
}
public String getData() {
return data;
}
public int getTtl() {
return ttl;
}
@Override
public int compareTo(DomainRecord other) {
return id.compareTo(other.getId());
}
@Override
public int hashCode() {
return Objects.hashCode(id);
}
@Override
public boolean equals(Object object) {
if (this == object) {
return true;
}
if (object instanceof DomainRecord) {
DomainRecord other = (DomainRecord) object;
return Objects.equal(id, other.id);
} else {
return false;
}
}
@Override
public String toString() {
return String.format("[id=%s, zone=%s, host=%s, type=%s, data=%s, ttl=%d]", id, zone, host, type, data, ttl);
}
}

View File

@ -29,7 +29,7 @@ import static com.google.common.base.Preconditions.checkNotNull;
* @author Adrian Cole * @author Adrian Cole
* @see <a href= "https://customer.glesys.com/api.php?a=doc#server_list" /> * @see <a href= "https://customer.glesys.com/api.php?a=doc#server_list" />
*/ */
public class Server { public class Server implements Comparable<Server> {
public static Builder builder() { public static Builder builder() {
return new Builder(); return new Builder();
} }
@ -109,6 +109,11 @@ public class Server {
public String getDatacenter() { public String getDatacenter() {
return datacenter; return datacenter;
} }
@Override
public int compareTo(Server other) {
return id.compareTo(other.getId());
}
@Override @Override
public boolean equals(Object object) { public boolean equals(Object object) {
@ -116,11 +121,7 @@ public class Server {
return true; return true;
} }
if (object instanceof Server) { if (object instanceof Server) {
final Server other = (Server) object; return Objects.equal(id, ((Server) object).id);
return Objects.equal(datacenter, other.datacenter)
&& Objects.equal(hostname, other.hostname)
&& Objects.equal(id, other.id)
&& Objects.equal(platform, other.platform);
} else { } else {
return false; return false;
} }
@ -128,7 +129,7 @@ public class Server {
@Override @Override
public int hashCode() { public int hashCode() {
return Objects.hashCode(datacenter, hostname, id, platform); return Objects.hashCode(id);
} }
@Override @Override

View File

@ -82,8 +82,7 @@ public class ServerConsole {
if (object instanceof ServerConsole) { if (object instanceof ServerConsole) {
final ServerConsole other = (ServerConsole) object; final ServerConsole other = (ServerConsole) object;
return Objects.equal(host, other.host) return Objects.equal(host, other.host)
&& Objects.equal(port, other.port) && Objects.equal(port, other.port);
&& Objects.equal(password, other.password);
} else { } else {
return false; return false;
} }
@ -91,7 +90,7 @@ public class ServerConsole {
@Override @Override
public int hashCode() { public int hashCode() {
return Objects.hashCode(host, port, password); return Objects.hashCode(host, port);
} }
@Override @Override

View File

@ -3,9 +3,11 @@ 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.Arrays;
import java.util.Collections;
import java.util.List; import java.util.List;
import com.google.common.base.Objects; import com.google.common.base.Objects;
import com.google.common.collect.ImmutableList;
import com.google.gson.annotations.SerializedName; import com.google.gson.annotations.SerializedName;
import org.jclouds.javax.annotation.Nullable; import org.jclouds.javax.annotation.Nullable;
@ -74,7 +76,7 @@ public class ServerCreated {
} }
public List<ServerCreatedIp> getIps() { public List<ServerCreatedIp> getIps() {
return ips; return ips == null ? ImmutableList.<ServerCreatedIp>of() : ips;
} }
@Override @Override
@ -82,18 +84,13 @@ public class ServerCreated {
if (this == object) { if (this == object) {
return true; return true;
} }
if (object instanceof ServerCreated) { return object instanceof ServerCreated
final ServerCreated other = (ServerCreated) object; && Objects.equal(id, ((ServerCreated) object).id);
return Objects.equal(id, other.id)
&& Objects.equal(ips, other.ips);
} else {
return false;
}
} }
@Override @Override
public int hashCode() { public int hashCode() {
return Objects.hashCode(id, ips); return Objects.hashCode(id);
} }
@Override @Override

View File

@ -161,27 +161,4 @@ public class ServerDetails extends Server {
hostname, datacenter, platform, description, cpuCores, memory, disk, cost); hostname, datacenter, platform, description, cpuCores, memory, disk, cost);
} }
@Override
public int hashCode() {
return super.hashCode() + Objects.hashCode(description, cpuCores, disk, memory, cost);
}
@Override
public boolean equals(Object object) {
if (this == object) {
return true;
}
if (object instanceof ServerDetails) {
final ServerDetails other = (ServerDetails) object;
return super.equals(other)
&& Objects.equal(description, other.description)
&& Objects.equal(cpuCores, other.cpuCores)
&& Objects.equal(disk, other.disk)
&& Objects.equal(memory, other.memory)
&& Objects.equal(cost, other.cost);
} else {
return false;
}
}
} }

View File

@ -30,7 +30,7 @@ import static com.google.common.base.Preconditions.checkNotNull;
*/ */
public enum ServerState { public enum ServerState {
RUNNING, UNRECOGNIZED; RUNNING, STOPPED, UNRECOGNIZED;
public String value() { public String value() {
return (CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, name())); return (CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, name()));

View File

@ -115,9 +115,6 @@ public class ServerTemplate {
if (object instanceof ServerTemplate) { if (object instanceof ServerTemplate) {
final ServerTemplate other = (ServerTemplate) object; final ServerTemplate other = (ServerTemplate) object;
return Objects.equal(name, other.name) return Objects.equal(name, other.name)
&& Objects.equal(minDiskSize, other.minDiskSize)
&& Objects.equal(minMemSize, other.minMemSize)
&& Objects.equal(os, other.os)
&& Objects.equal(platform, other.platform); && Objects.equal(platform, other.platform);
} else { } else {
return false; return false;
@ -126,7 +123,7 @@ public class ServerTemplate {
@Override @Override
public int hashCode() { public int hashCode() {
return Objects.hashCode(name, minDiskSize, minMemSize, os, platform); return Objects.hashCode(name, platform);
} }
@Override @Override

View File

@ -47,7 +47,7 @@ public interface ArchiveAsyncClient {
/** /**
* @see ArchiveClient#listArchives * @see ArchiveClient#listArchives
*/ */
@GET @POST
@Path("/archive/list/format/json") @Path("/archive/list/format/json")
@SelectJson("archives") @SelectJson("archives")
@Consumes(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON)
@ -57,7 +57,7 @@ public interface ArchiveAsyncClient {
/** /**
* @see ArchiveClient#archiveDetails * @see ArchiveClient#archiveDetails
*/ */
@GET @POST
@Path("/archive/details/format/json") @Path("/archive/details/format/json")
@SelectJson("details") @SelectJson("details")
@Consumes(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON)
@ -99,6 +99,7 @@ public interface ArchiveAsyncClient {
@Path("/archive/allowedarguments/format/json") @Path("/archive/allowedarguments/format/json")
@SelectJson("argumentslist") @SelectJson("argumentslist")
@Consumes(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON)
@ExceptionParser(ReturnEmptySetOnNotFoundOr404.class)
ListenableFuture<ArchiveAllowedArguments> getArchiveAllowedArguments(); ListenableFuture<ArchiveAllowedArguments> getArchiveAllowedArguments();
} }

View File

@ -0,0 +1,99 @@
/**
* 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.Domain;
import org.jclouds.glesys.domain.DomainRecord;
import org.jclouds.glesys.options.DomainOptions;
import org.jclouds.glesys.options.DomainRecordAddOptions;
import org.jclouds.glesys.options.DomainRecordModifyOptions;
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 javax.ws.rs.Consumes;
import javax.ws.rs.FormParam;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.core.MediaType;
import java.util.Set;
/**
* Provides asynchronous access to Domain (DNS) data via the Glesys REST API.
* <p/>
*
* @author Adam Lowe
* @see DomainClient
* @see <a href="https://customer.glesys.com/api.php" />
*/
@RequestFilters(BasicAuthentication.class)
public interface DomainAsyncClient {
/**
* @see org.jclouds.glesys.features.DomainClient#listDomains
*/
@POST
@Path("/domain/list/format/json")
@SelectJson("domains")
@Consumes(MediaType.APPLICATION_JSON)
@ExceptionParser(ReturnEmptySetOnNotFoundOr404.class)
ListenableFuture<Set<Domain>> listDomains();
/**
* @see DomainClient#addDomain
*/
@POST
@Path("/domain/add/format/json")
ListenableFuture<Void> addDomain(@FormParam("name") String name, DomainOptions... options);
/**
* @see DomainClient#editDomain
*/
@POST
@Path("/domain/edit/format/json")
ListenableFuture<Void> editDomain(@FormParam("domain") String domain, DomainOptions... options);
@POST
@Path("/domain/delete/format/json")
ListenableFuture<Void> deleteDomain(@FormParam("domain") String domain);
@POST
@Path("/domain/list_records/format/json")
@SelectJson("records")
@Consumes(MediaType.APPLICATION_JSON)
ListenableFuture<Set<DomainRecord>> listRecords(@FormParam("domain") String domain);
@POST
@Path("/domain/add_record/format/json")
ListenableFuture<Void> addRecord(@FormParam("domain") String domain, @FormParam("host") String host,
@FormParam("type") String type, @FormParam("data") String data,
DomainRecordAddOptions... options);
@POST
@Path("/domain/update_record/format/json")
ListenableFuture<Void> editRecord(@FormParam("record_id") String record_id, DomainRecordModifyOptions... options);
@POST
@Path("/domain/delete_record/format/json")
ListenableFuture<Void> deleteRecord(@FormParam("record_id") String recordId);
}

View File

@ -0,0 +1,107 @@
/**
* 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.Domain;
import org.jclouds.glesys.domain.DomainRecord;
import org.jclouds.glesys.options.DomainOptions;
import org.jclouds.glesys.options.DomainRecordAddOptions;
import org.jclouds.glesys.options.DomainRecordModifyOptions;
import java.util.Set;
import java.util.concurrent.TimeUnit;
/**
* Provides synchronous access to Invoice requests.
* <p/>
*
* @author Adam Lowe
* @see DomainAsyncClient
* @see <a href="https://customer.glesys.com/api.php" />
*/
@Timeout(duration = 30, timeUnit = TimeUnit.SECONDS)
public interface DomainClient {
/**
* Get a list of all invoices for this account.
*
* @return an account's associated invoice objects.
*/
Set<Domain> listDomains();
/**
* Add a domain to the Glesys dns-system
*
* @param domain the name of the domain to add.
* @param options optional parameters
*/
void addDomain(String domain, DomainOptions... options);
/**
* Add a domain to the Glesys dns-system
*
* @param domain the name of the domain to add.
* @param options optional parameters
*/
void editDomain(String domain, DomainOptions... options);
/**
* Remove a domain to the Glesys dns-system
*
* @param domain the name of the domain to remove
*/
void deleteDomain(String domain);
/**
* Retrieve the DNS records for a given domain
*
* @param domain the name of the domain to retrieve records for
*/
Set<DomainRecord> listRecords(String domain);
/**
* Add a DNS Record
*
* @param domain the domain to add the record to
* @param host
* @param type
* @param data
* @param options optional settings for the record
*/
void addRecord(String domain, String host, String type, String data, DomainRecordAddOptions... options);
/**
* Modify a specific DNS Record
*
* @param recordId the id for the record to edit
* @param options the settings to change
* @see #listRecords to retrieve the necessary ids
*/
void editRecord(String recordId, DomainRecordModifyOptions... options);
/**
* Delete a DNS record
*
* @param recordId the id for the record to delete
* @see #listRecords to retrieve the necessary ids
*/
void deleteRecord(String recordId);
}

View File

@ -20,6 +20,7 @@ package org.jclouds.glesys.features;
import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.ListenableFuture;
import org.jclouds.glesys.domain.*; import org.jclouds.glesys.domain.*;
import org.jclouds.glesys.options.*;
import org.jclouds.http.filters.BasicAuthentication; import org.jclouds.http.filters.BasicAuthentication;
import org.jclouds.rest.annotations.ExceptionParser; import org.jclouds.rest.annotations.ExceptionParser;
import org.jclouds.rest.annotations.RequestFilters; import org.jclouds.rest.annotations.RequestFilters;
@ -46,7 +47,7 @@ public interface ServerAsyncClient {
/** /**
* @see ServerClient#listServers * @see ServerClient#listServers
*/ */
@GET @POST
@Path("/server/list/format/json") @Path("/server/list/format/json")
@SelectJson("servers") @SelectJson("servers")
@Consumes(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON)
@ -56,43 +57,43 @@ public interface ServerAsyncClient {
/** /**
* @see ServerClient#getServerDetails * @see ServerClient#getServerDetails
*/ */
@GET @POST
@Path("/server/details/serverid/{id}/format/json") @Path("/server/details/format/json")
@SelectJson("server") @SelectJson("server")
@Consumes(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON)
@ExceptionParser(ReturnNullOnNotFoundOr404.class) @ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<ServerDetails> getServerDetails(@PathParam("id") String id); ListenableFuture<ServerDetails> getServerDetails(@FormParam("serverid") String id);
/** /**
* @see ServerClient#getServerStatus * @see ServerClient#getServerStatus
*/ */
@GET @POST
@Path("/server/status/serverid/{id}/format/json") @Path("/server/status/format/json")
@SelectJson("server") @SelectJson("server")
@Consumes(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON)
@ExceptionParser(ReturnNullOnNotFoundOr404.class) @ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<ServerStatus> getServerStatus(@PathParam("id") String id); ListenableFuture<ServerStatus> getServerStatus(@FormParam("serverid") String id, ServerStatusOptions... options);
/** /**
* @see ServerClient#getServerLimits * @see ServerClient#getServerLimits
*/ */
@GET @POST
@Path("/server/limits/serverid/{id}/format/json") @Path("/server/limits/format/json")
@SelectJson("limits") @SelectJson("limits")
@Consumes(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON)
@ExceptionParser(ReturnNullOnNotFoundOr404.class) @ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<SortedMap<String, ServerLimit>> getServerLimits(@PathParam("id") String id); ListenableFuture<SortedMap<String, ServerLimit>> getServerLimits(@FormParam("serverid") String id);
/** /**
* @see ServerClient#getServerConsole * @see ServerClient#getServerConsole
*/ */
@GET @POST
@Path("/server/console/serverid/{id}/format/json") @Path("/server/console/format/json")
@SelectJson("server") @SelectJson("server")
@Consumes(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON)
@ExceptionParser(ReturnNullOnNotFoundOr404.class) @ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<ServerConsole> getServerConsole(@PathParam("id") String id); ListenableFuture<ServerConsole> getServerConsole(@FormParam("serverid") String id);
/** /**
@ -116,30 +117,30 @@ public interface ServerAsyncClient {
/** /**
* @see ServerClient#stopServer * @see ServerClient#stopServer
*/ */
@GET @POST
@Path("/server/resetlimit/serverid/{id}/type/{type}/format/json") @Path("/server/resetlimit/format/json")
ListenableFuture<Void> resetServerLimit(@PathParam("id") String id, @PathParam("type") String type); ListenableFuture<Void> resetServerLimit(@FormParam("serverid") String id, @FormParam("type") String type);
/** /**
* @see ServerClient#rebootServer * @see ServerClient#rebootServer
*/ */
@GET @POST
@Path("/server/reboot/serverid/{id}/format/json") @Path("/server/reboot/format/json")
ListenableFuture<Void> rebootServer(@PathParam("id") String id); ListenableFuture<Void> rebootServer(@FormParam("serverid") String id);
/** /**
* @see ServerClient#startServer * @see ServerClient#startServer
*/ */
@GET @POST
@Path("/server/start/serverid/{id}/format/json") @Path("/server/start/format/json")
ListenableFuture<Void> startServer(@PathParam("id") String id); ListenableFuture<Void> startServer(@FormParam("serverid") String id);
/** /**
* @see ServerClient#stopServer * @see ServerClient#stopServer
*/ */
@GET @POST
@Path("/server/stop/serverid/{id}/format/json") @Path("/server/stop/format/json")
ListenableFuture<Void> stopServer(@PathParam("id") String id); ListenableFuture<Void> stopServer(@FormParam("serverid") String id, ServerStopOptions... options);
/** /**
* @see ServerClient#createServer * @see ServerClient#createServer
@ -157,25 +158,26 @@ public interface ServerAsyncClient {
@FormParam("cpucores") int cpucores, @FormParam("cpucores") int cpucores,
@FormParam("rootpw") String rootpw, @FormParam("rootpw") String rootpw,
@FormParam("transfer") int transfer, @FormParam("transfer") int transfer,
String description, ServerCreateOptions... options);
String ip);
/** /**
* @see ServerClient#createServer * @see ServerClient#cloneServer
*/ */
@POST @POST
@Path("/server/clone/format/json") @Path("/server/clone/format/json")
@SelectJson("server") @SelectJson("server")
@Consumes(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON)
ListenableFuture<ServerCreated> cloneServer(@FormParam("serverid") String serverid, ListenableFuture<ServerCreated> cloneServer(@FormParam("serverid") String serverid,
@FormParam("hostname") String hostname, @FormParam("hostname") String hostname,
@FormParam("disksize") int diskSize, ServerCloneOptions... options);
@FormParam("memorysize") int memorySize,
@FormParam("cpucores") int cpucores, /**
@FormParam("transfer") int transfer, * @see ServerClient#editServer
@FormParam("description") String description, */
@FormParam("datacenter") String dataCenter); @POST
@Path("/server/edit/format/json")
ListenableFuture<Void> editServer(@FormParam("serverid") String serverid, ServerEditOptions... options);
/** /**
* @see ServerClient#destroyServer * @see ServerClient#destroyServer
*/ */

View File

@ -20,6 +20,7 @@ package org.jclouds.glesys.features;
import org.jclouds.concurrent.Timeout; import org.jclouds.concurrent.Timeout;
import org.jclouds.glesys.domain.*; import org.jclouds.glesys.domain.*;
import org.jclouds.glesys.options.*;
import org.jclouds.javax.annotation.Nullable; import org.jclouds.javax.annotation.Nullable;
import javax.ws.rs.FormParam; import javax.ws.rs.FormParam;
@ -60,10 +61,11 @@ public interface ServerClient {
* Get detailed information about a server status including up-time and hardware usage * Get detailed information about a server status including up-time and hardware usage
* (cpu, disk, memory and bandwidth) * (cpu, disk, memory and bandwidth)
* *
* @param id id of the server * @param id id of the server
* @param options optional parameters
* @return the status of the server or null if not found * @return the status of the server or null if not found
*/ */
ServerStatus getServerStatus(String id); ServerStatus getServerStatus(String id, ServerStatusOptions... options);
/** /**
* Get detailed information about a server's limits (for OpenVZ only). * Get detailed information about a server's limits (for OpenVZ only).
@ -123,28 +125,45 @@ public interface ServerClient {
/** /**
* Stop a server * Stop a server
* *
* @param id id of the server * @param id id of the server
* @param options optional parameters
*/ */
void stopServer(String id); void stopServer(String id, ServerStopOptions... options);
/** /**
* Create a new server * Create a new server
* *
* @param datacenter the data center to create the new server in * @param datacenter the data center to create the new server in
* @param platform the platform to use (i.e. "Xen" or "OpenVZ") * @param platform the platform to use (i.e. "Xen" or "OpenVZ")
* @param hostname the host name of the new server * @param hostname the host name of the new server
* @param template the template to use to create the new server * @param template the template to use to create the new server
* @param disksize the amount of disk space, in GB, to allocate * @param disksize the amount of disk space, in GB, to allocate
* @param memorysize the memory, in MB, to allocate * @param memorysize the memory, in MB, to allocate
* @param cpucores the number of CPU cores to allocate * @param cpucores the number of CPU cores to allocate
* @param rootpw the root password to use * @param rootpw the root password to use
* @param transfer the transfer size * @param transfer the transfer size
* @param description a description of the server * @param options optional settings ex. description
* @param ip ip address to assign to the new server, required by Xen platform
*/ */
ServerCreated createServer(String datacenter, String platform, ServerCreated createServer(String datacenter, String platform,
String hostname, String template, int disksize, int memorysize, String hostname, String template, int disksize, int memorysize,
int cpucores, String rootpw, int transfer, @Nullable String description, @Nullable String ip); int cpucores, String rootpw, int transfer, ServerCreateOptions... options);
/**
* Edit the configuration of a server
*
* @param serverid the serverId of the server to edit
* @param options the settings to change
*/
void editServer(String serverid, ServerEditOptions... options);
/**
* Clone a server
*
* @param serverid the serverId of the server to clone
* @param hostname the new host name of the cloned server
* @param options the settings to change
*/
ServerCreated cloneServer(String serverid, String hostname, ServerCloneOptions... options);
/** /**
* Destroy a server * Destroy a server

View File

@ -0,0 +1,39 @@
package org.jclouds.glesys.functions.internal;
import com.google.gson.*;
import org.jclouds.json.config.GsonModule;
import javax.inject.Singleton;
import java.lang.reflect.Type;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
/**
* Parser for Glesys Date formats
*
* @author Adam Lowe
*/
@Singleton
public class GlesysDateAdapter implements GsonModule.DateAdapter {
private final DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
public JsonElement serialize(Date src, Type typeOfSrc, JsonSerializationContext context) {
synchronized (dateFormat) {
return new JsonPrimitive(dateFormat.format(src));
}
}
public Date deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
throws JsonParseException {
String toParse = json.getAsJsonPrimitive().getAsString();
try {
synchronized (dateFormat) {
return dateFormat.parse(toParse);
}
} catch (ParseException e) {
throw new RuntimeException(e);
}
}
}

View File

@ -0,0 +1,101 @@
package org.jclouds.glesys.options;
import org.jclouds.http.options.BaseHttpRequestOptions;
/**
* @author Adam Lowe
*/
public class DomainOptions extends BaseHttpRequestOptions {
public static class Builder {
/**
* @see DomainOptions#primaryNameServer
*/
public static DomainOptions primaryNameServer(String primaryNameServer) {
DomainOptions options = new DomainOptions();
return options.primaryNameServer(primaryNameServer);
}
/**
* @see DomainOptions#responsiblePerson
*/
public static DomainOptions responsiblePerson(String responsiblePerson) {
DomainOptions options = new DomainOptions();
return options.responsiblePerson(responsiblePerson);
}
/**
* @see DomainOptions#ttl
*/
public static DomainOptions ttl(int ttl) {
DomainOptions options = new DomainOptions();
return options.ttl(ttl);
}
/**
* @see DomainOptions#refresh
*/
public static DomainOptions refresh(String refresh) {
DomainOptions options = new DomainOptions();
return options.refresh(refresh);
}
/**
* @see DomainOptions#retry
*/
public static DomainOptions retry(String retry) {
DomainOptions options = new DomainOptions();
return options.retry(retry);
}
/**
* @see DomainOptions#expire
*/
public static DomainOptions expire(String expire) {
DomainOptions options = new DomainOptions();
return options.expire(expire);
}
/**
* @see DomainOptions#minimum
*/
public static DomainOptions minimum(String minimum) {
DomainOptions options = new DomainOptions();
return options.minimum(minimum);
}
}
public DomainOptions primaryNameServer(String primaryNameServer) {
formParameters.put("primary_ns", primaryNameServer);
return this;
}
public DomainOptions responsiblePerson(String responsiblePerson) {
formParameters.put("resp_person", responsiblePerson);
return this;
}
public DomainOptions ttl(int ttl) {
formParameters.put("ttl", Integer.toString(ttl));
return this;
}
public DomainOptions refresh(String refresh) {
formParameters.put("refresh", refresh);
return this;
}
public DomainOptions retry(String retry) {
formParameters.put("retry", retry);
return this;
}
public DomainOptions expire(String expire) {
formParameters.put("primary_ns", expire);
return this;
}
public DomainOptions minimum(String minimum) {
formParameters.put("minimum", minimum);
return this;
}
}

View File

@ -0,0 +1,43 @@
package org.jclouds.glesys.options;
import org.jclouds.http.options.BaseHttpRequestOptions;
/**
* @author Adam Lowe
*/
public class DomainRecordAddOptions extends BaseHttpRequestOptions {
public static class Builder {
/**
* @see DomainRecordAddOptions#ttl
*/
public static DomainRecordAddOptions ttl(int ttl) {
DomainRecordAddOptions options = new DomainRecordAddOptions();
return options.ttl(ttl);
}
/**
* @see DomainRecordAddOptions#mxPriority
*/
public static DomainRecordAddOptions mxPriority(String mxPriority) {
DomainRecordAddOptions options = new DomainRecordAddOptions();
return options.mxPriority(mxPriority);
}
}
public DomainRecordAddOptions host(String host) {
formParameters.put("host", host);
return this;
}
public DomainRecordAddOptions ttl(int ttl) {
formParameters.put("ttl", Integer.toString(ttl));
return this;
}
public DomainRecordAddOptions mxPriority(String mxPriority) {
formParameters.put("mx_priority", mxPriority);
return this;
}
}

View File

@ -0,0 +1,65 @@
package org.jclouds.glesys.options;
/**
* @author Adam Lowe
*/
public class DomainRecordModifyOptions extends DomainRecordAddOptions {
public static class Builder {
/**
* @see org.jclouds.glesys.options.DomainRecordAddOptions#host
*/
public static DomainRecordModifyOptions host(String host) {
DomainRecordModifyOptions options = new DomainRecordModifyOptions();
return options.host(host);
}
/**
* @see org.jclouds.glesys.options.DomainRecordModifyOptions#type
*/
public static DomainRecordModifyOptions type(String type) {
DomainRecordModifyOptions options = new DomainRecordModifyOptions();
return options.type(type);
}
/**
* @see org.jclouds.glesys.options.DomainRecordModifyOptions#data
*/
public static DomainRecordModifyOptions data(String data) {
DomainRecordModifyOptions options = new DomainRecordModifyOptions();
return options.data(data);
}
/**
* @see org.jclouds.glesys.options.DomainRecordModifyOptions#ttl
*/
public static DomainRecordModifyOptions ttl(int ttl) {
DomainRecordModifyOptions options = new DomainRecordModifyOptions();
return DomainRecordModifyOptions.class.cast(options.ttl(ttl));
}
/**
* @see org.jclouds.glesys.options.DomainRecordModifyOptions#mxPriority
*/
public static DomainRecordModifyOptions mxPriority(String mxPriority) {
DomainRecordModifyOptions options = new DomainRecordModifyOptions();
return DomainRecordModifyOptions.class.cast(options.mxPriority(mxPriority));
}
}
public DomainRecordModifyOptions host(String host) {
formParameters.put("host", host);
return this;
}
public DomainRecordModifyOptions type(String type) {
formParameters.put("type", type);
return this;
}
public DomainRecordModifyOptions data(String data) {
formParameters.put("data", data);
return this;
}
}

View File

@ -0,0 +1,69 @@
package org.jclouds.glesys.options;
/**
* @author Adam Lowe
*/
public class ServerCloneOptions extends ServerEditOptions {
public static class Builder {
/**
* @see org.jclouds.glesys.options.ServerCloneOptions#disksize
*/
public static ServerCloneOptions disksize(int disksize) {
ServerCloneOptions options = new ServerCloneOptions();
return ServerCloneOptions.class.cast(options.disksize(disksize));
}
/**
* @see org.jclouds.glesys.options.ServerCloneOptions#memorysize
*/
public static ServerCloneOptions memorysize(int memorysize) {
ServerCloneOptions options = new ServerCloneOptions();
return ServerCloneOptions.class.cast(options.memorysize(memorysize));
}
/**
* @see org.jclouds.glesys.options.ServerCloneOptions#cpucores
*/
public static ServerCloneOptions cpucores(int cpucores) {
ServerCloneOptions options = new ServerCloneOptions();
return ServerCloneOptions.class.cast(options.cpucores(cpucores));
}
/**
* @see org.jclouds.glesys.options.ServerCloneOptions#cpucores
*/
public static ServerCloneOptions transfer(int transfer) {
ServerCloneOptions options = new ServerCloneOptions();
return ServerCloneOptions.class.cast(options.transfer(transfer));
}
/**
* @see org.jclouds.glesys.options.ServerCloneOptions#hostname
*/
public static ServerCloneOptions hostname(String hostname) {
ServerCloneOptions options = new ServerCloneOptions();
return ServerCloneOptions.class.cast(options.hostname(hostname));
}
/**
* @see org.jclouds.glesys.options.ServerEditOptions#description
*/
public static ServerCloneOptions description(String description) {
ServerCloneOptions options = new ServerCloneOptions();
return ServerCloneOptions.class.cast(options.description(description));
}
/**
* @see org.jclouds.glesys.options.ServerCloneOptions#dataCenter
*/
public static ServerCloneOptions dataCenter(String dataCenter) {
ServerCloneOptions options = new ServerCloneOptions();
return options.dataCenter(dataCenter);
}
}
public ServerCloneOptions dataCenter(String dataCenter) {
formParameters.put("datacenter", dataCenter);
return this;
}
}

View File

@ -0,0 +1,43 @@
package org.jclouds.glesys.options;
import org.jclouds.http.options.BaseHttpRequestOptions;
/**
* @author Adam Lowe
*/
public class ServerCreateOptions extends BaseHttpRequestOptions {
public static class Builder {
/**
* @see ServerCreateOptions#description
*/
public static ServerCreateOptions description(String primaryNameServer) {
ServerCreateOptions options = new ServerCreateOptions();
return options.description(primaryNameServer);
}
/**
* @see ServerCreateOptions#ip
*/
public static ServerCreateOptions ip(String ip) {
ServerCreateOptions options = new ServerCreateOptions();
return options.ip(ip);
}
}
/**
* @param description the description of the server
*/
public ServerCreateOptions description(String description) {
formParameters.put("description", description);
return this;
}
/**
* @param ip the ip address to assign to the server
*/
public ServerCreateOptions ip(String ip) {
formParameters.put("ip", ip);
return this;
}
}

View File

@ -0,0 +1,91 @@
package org.jclouds.glesys.options;
import org.jclouds.http.options.BaseHttpRequestOptions;
/**
*
* @author Adam Lowe
*/
public class ServerEditOptions extends BaseHttpRequestOptions {
public static class Builder {
/**
* @see org.jclouds.glesys.options.ServerEditOptions#disksize
*/
public static ServerEditOptions disksize(int disksize) {
ServerEditOptions options = new ServerEditOptions();
return options.disksize(disksize);
}
/**
* @see org.jclouds.glesys.options.ServerEditOptions#memorysize
*/
public static ServerEditOptions memorysize(int memorysize) {
ServerEditOptions options = new ServerEditOptions();
return options.memorysize(memorysize);
}
/**
* @see org.jclouds.glesys.options.ServerEditOptions#cpucores
*/
public static ServerEditOptions cpucores(int cpucores) {
ServerEditOptions options = new ServerEditOptions();
return options.cpucores(cpucores);
}
/**
* @see org.jclouds.glesys.options.ServerEditOptions#cpucores
*/
public static ServerEditOptions transfer(int transfer) {
ServerEditOptions options = new ServerEditOptions();
return options.transfer(transfer);
}
/**
* @see org.jclouds.glesys.options.ServerEditOptions#hostname
*/
public static ServerEditOptions hostname(String hostname) {
ServerEditOptions options = new ServerEditOptions();
return options.hostname(hostname);
}
/**
* @see org.jclouds.glesys.options.ServerEditOptions#description
*/
public static ServerEditOptions description(String description) {
ServerEditOptions options = new ServerEditOptions();
return options.description(description);
}
}
public ServerEditOptions disksize(int disksize) {
formParameters.put("disksize", Integer.toString(disksize));
return this;
}
public ServerEditOptions memorysize(int memorysize) {
formParameters.put("memorysize", Integer.toString(memorysize));
return this;
}
public ServerEditOptions cpucores(int cpucores) {
formParameters.put("cpucores", Integer.toString(cpucores));
return this;
}
public ServerEditOptions transfer(int transfer) {
formParameters.put("cpucores", Integer.toString(transfer));
return this;
}
public ServerEditOptions hostname(String hostname) {
formParameters.put("hostname", hostname);
return this;
}
public ServerEditOptions description(String description) {
formParameters.put("description", description);
return this;
}
}

View File

@ -0,0 +1,64 @@
package org.jclouds.glesys.options;
import com.google.common.collect.Iterables;
import org.jclouds.http.options.BaseHttpRequestOptions;
/**
* @author Adam Lowe
*/
public class ServerStatusOptions extends BaseHttpRequestOptions {
public enum StatusTypes {
state, cpu, memory, disk, bandwidth, uptime
}
public static class Builder {
/**
* @see org.jclouds.glesys.options.ServerStatusOptions#statusType
*/
public static ServerStatusOptions state() {
ServerStatusOptions options = new ServerStatusOptions();
return options.statusType(StatusTypes.state);
}
/**
* @see org.jclouds.glesys.options.ServerStatusOptions#statusType
*/
public static ServerStatusOptions cpu() {
ServerStatusOptions options = new ServerStatusOptions();
return options.statusType(StatusTypes.cpu);
}
/**
* @see org.jclouds.glesys.options.ServerStatusOptions#statusType
*/
public static ServerStatusOptions memory() {
ServerStatusOptions options = new ServerStatusOptions();
return options.statusType(StatusTypes.memory);
}
/**
* @see org.jclouds.glesys.options.ServerStatusOptions#statusType
*/
public static ServerStatusOptions disk() {
ServerStatusOptions options = new ServerStatusOptions();
return options.statusType(StatusTypes.disk);
}
/**
* @see org.jclouds.glesys.options.ServerStatusOptions#statusType
*/
public static ServerStatusOptions bandwidth() {
ServerStatusOptions options = new ServerStatusOptions();
return options.statusType(StatusTypes.bandwidth);
}
}
/**
* Select the given type of information form the server
*/
public ServerStatusOptions statusType(StatusTypes type) {
formParameters.put("statustype", type.name());
return this;
}
}

View File

@ -0,0 +1,25 @@
package org.jclouds.glesys.options;
/**
* @author Adam Lowe
*/
public class ServerStopOptions extends ServerEditOptions {
public static class Builder {
/**
* @see org.jclouds.glesys.options.ServerStopOptions#hard
*/
public static ServerStopOptions hard() {
ServerStopOptions options = new ServerStopOptions();
return options.hard();
}
}
/**
* Hard stop - only supported on Xen platform
*/
public ServerStopOptions hard() {
formParameters.put("type", "hard");
return this;
}
}

View File

@ -46,12 +46,14 @@ public class GleSYSAsyncClientTest extends BaseGleSYSAsyncClientTest<GleSYSAsync
assert syncClient.getServerClient() != null; assert syncClient.getServerClient() != null;
assert syncClient.getIpClient() != null; assert syncClient.getIpClient() != null;
assert syncClient.getArchiveClient() != null; assert syncClient.getArchiveClient() != null;
assert syncClient.getDomainClient() != 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; assert asyncClient.getArchiveClient() != null;
assert asyncClient.getDomainClient() != null;
} }
@Override @Override

View File

@ -19,9 +19,15 @@
package org.jclouds.glesys.features; package org.jclouds.glesys.features;
import com.google.inject.TypeLiteral; import com.google.inject.TypeLiteral;
import org.jclouds.rest.functions.MapHttp4xxCodesToExceptions;
import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404;
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
import org.jclouds.rest.internal.RestAnnotationProcessor; import org.jclouds.rest.internal.RestAnnotationProcessor;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import javax.ws.rs.FormParam;
import java.util.Map;
/** /**
* Tests annotation parsing of {@code ArchiveAsyncClient} * Tests annotation parsing of {@code ArchiveAsyncClient}
* *
@ -29,6 +35,43 @@ import org.testng.annotations.Test;
*/ */
@Test(groups = "unit", testName = "ArchiveAsyncClientTest") @Test(groups = "unit", testName = "ArchiveAsyncClientTest")
public class ArchiveAsyncClientTest extends BaseGleSYSAsyncClientTest<ArchiveAsyncClient> { public class ArchiveAsyncClientTest extends BaseGleSYSAsyncClientTest<ArchiveAsyncClient> {
public ArchiveAsyncClientTest() {
asyncClientClass = ArchiveAsyncClient.class;
remoteServicePrefix = "archive";
}
private Map.Entry<String, String> userName = newEntry("username", "x");
public void testListArchives() throws Exception {
testMethod("listArchives", "list", "POST", true, ReturnEmptySetOnNotFoundOr404.class);
}
public void testArchiveDetails() throws Exception {
testMethod("archiveDetails", "details", "POST", true, ReturnNullOnNotFoundOr404.class, userName);
}
public void testCreateArchive() throws Exception {
testMethod("createArchive", "create", "POST", false, MapHttp4xxCodesToExceptions.class, userName,
newEntry("password", "somepass"), newEntry("size", 5));
}
public void testDeleteArchive() throws Exception {
testMethod("deleteArchive", "delete", "POST", false, MapHttp4xxCodesToExceptions.class, userName);
}
public void testResizeArchive() throws Exception {
testMethod("resizeArchive", "resize", "POST", false, MapHttp4xxCodesToExceptions.class, userName,
newEntry("size", 5));
}
public void testChangeArchivePassword() throws Exception {
testMethod("changeArchivePassword", "changepassword", "POST", false, MapHttp4xxCodesToExceptions.class, userName,
newEntry("password", "newpass"));
}
public void testGetArchiveAllowedArguments() throws Exception {
testMethod("getArchiveAllowedArguments", "allowedarguments", "GET", true, ReturnEmptySetOnNotFoundOr404.class);
}
@Override @Override
protected TypeLiteral<RestAnnotationProcessor<ArchiveAsyncClient>> createTypeLiteral() { protected TypeLiteral<RestAnnotationProcessor<ArchiveAsyncClient>> createTypeLiteral() {

View File

@ -56,11 +56,13 @@ public class ArchiveClientLiveTest extends BaseGleSYSClientLiveTest {
}, 30, 1, TimeUnit.SECONDS); }, 30, 1, TimeUnit.SECONDS);
} }
@AfterGroups(alwaysRun = true, groups={"live"}) @AfterGroups(groups={"live"})
public void teardownClient() { public void tearDown() {
int before = client.listArchives().size(); int before = client.listArchives().size();
client.deleteArchive(archiveUser); client.deleteArchive(archiveUser);
assertTrue(archiveCounter.apply(before - 1)); assertTrue(archiveCounter.apply(before - 1));
super.tearDown();
} }
private ArchiveClient client; private ArchiveClient client;

View File

@ -18,22 +18,34 @@
*/ */
package org.jclouds.glesys.features; package org.jclouds.glesys.features;
import static org.testng.Assert.assertEquals; import com.google.common.base.Splitter;
import com.google.common.collect.ImmutableSortedSet;
import java.util.Properties; import com.google.common.collect.Maps;
import org.jclouds.glesys.GleSYSAsyncClient;
import org.jclouds.glesys.GleSYSClient;
import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpRequest;
import org.jclouds.http.filters.BasicAuthentication; import org.jclouds.http.filters.BasicAuthentication;
import org.jclouds.http.functions.ParseFirstJsonValueNamed;
import org.jclouds.http.options.BaseHttpRequestOptions;
import org.jclouds.rest.RestClientTest; import org.jclouds.rest.RestClientTest;
import org.jclouds.rest.RestContextFactory; import org.jclouds.rest.RestContextFactory;
import org.jclouds.rest.RestContextSpec; import org.jclouds.rest.RestContextSpec;
import org.jclouds.glesys.GleSYSAsyncClient;
import org.jclouds.glesys.GleSYSClient; import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import static org.testng.Assert.*;
/** /**
* @author Adrian Cole * @author Adrian Cole
* @author Adam Lowe
*/ */
public abstract class BaseGleSYSAsyncClientTest<T> extends RestClientTest<T> { public abstract class BaseGleSYSAsyncClientTest<T> extends RestClientTest<T> {
protected Class asyncClientClass;
protected String remoteServicePrefix;
@Override @Override
protected void checkFilters(HttpRequest request) { protected void checkFilters(HttpRequest request) {
@ -47,4 +59,73 @@ public abstract class BaseGleSYSAsyncClientTest<T> extends RestClientTest<T> {
return new RestContextFactory().createContextSpec("glesys", "username", "apiKey", props); return new RestContextFactory().createContextSpec("glesys", "username", "apiKey", props);
} }
protected Map.Entry<String, String> newEntry(String key, Object value) {
return Maps.immutableEntry(key, value.toString());
}
/**
* Test that a method call is annotated correctly.
* <p/>
* TODO de-code ampersands and spaces in args properly
*
* @param localMethod the method to call in asyncClientClass
* @param remoteCall the name of the expected call on the remote server
* @param httpMethod "GET" or "POST"
* @param expectResponse if true check Accept header and response parsers
* @param exceptionParser the class of exception handler expected
* @param args either Map.Entry or BaseHttpRequestOptions that make up the arguments to the method
*/
protected void testMethod(String localMethod, String remoteCall, String httpMethod, boolean expectResponse, Class exceptionParser, Object... args) throws Exception {
List<String> argStrings = new ArrayList<String>();
List<Object> argValues = new ArrayList<Object>();
for (Object arg : args) {
if (arg instanceof BaseHttpRequestOptions) {
for (Map.Entry<String, String> httpEntry : ((BaseHttpRequestOptions) arg).buildFormParameters().entries()) {
argStrings.add(httpEntry.getKey() + "=" + httpEntry.getValue());
}
argValues.add(arg);
} else {
Map.Entry<String, String> entry = (Map.Entry<String, String>) arg;
argStrings.add(entry.getKey() + "=" + entry.getValue());
argValues.add(entry.getValue());
}
}
Method method = null;
for (Method m : asyncClientClass.getMethods()) {
if (m.getName().equals(localMethod)) {
assertNull(method, "More than one method called " + localMethod + " in class " + asyncClientClass);
method = m;
}
}
assertNotNull(method, "Failed to locate method " + localMethod + " in class " + asyncClientClass);
HttpRequest httpRequest = processor.createRequest(method, argValues.toArray());
assertRequestLineEquals(httpRequest, httpMethod + " https://api.glesys.com/" + remoteServicePrefix + "/" + remoteCall + "/format/json HTTP/1.1");
if (expectResponse) {
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
assertResponseParserClassEquals(method, httpRequest, ParseFirstJsonValueNamed.class);
}
if (argStrings.isEmpty()) {
assertPayloadEquals(httpRequest, null, null, false);
} else {
assertNotNull(httpRequest.getPayload());
String payload = (String) httpRequest.getPayload().getRawContent();
Iterable<String> in = Splitter.on("&").split(payload);
assertContentHeadersEqual(httpRequest, "application/x-www-form-urlencoded", null, null, null, 0L + payload.length(), null);
assertEquals(ImmutableSortedSet.copyOf(in), ImmutableSortedSet.copyOf(argStrings));
}
assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, exceptionParser);
checkFilters(httpRequest);
}
} }

View File

@ -0,0 +1,69 @@
/**
* 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.glesys.options.DomainOptions;
import org.jclouds.rest.functions.MapHttp4xxCodesToExceptions;
import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404;
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
import org.jclouds.rest.internal.RestAnnotationProcessor;
import org.testng.annotations.Test;
import java.util.Map;
/**
* Tests annotation parsing of {@code DomainAsyncClient}
*
* @author Adam Lowe
*/
@Test(groups = "unit", testName = "DomainAsyncClientTest")
public class DomainAsyncClientTest extends BaseGleSYSAsyncClientTest<DomainAsyncClient> {
public DomainAsyncClientTest() {
asyncClientClass = DomainAsyncClient.class;
remoteServicePrefix = "domain";
}
private Map.Entry<String, String> domainName = newEntry("domain", "cl666666someuser");
public void testListDomains() throws Exception {
testMethod("listDomains", "list", "POST", true, ReturnEmptySetOnNotFoundOr404.class);
}
public void testAddDomain() throws Exception {
testMethod("addDomain", "add", "POST", false, MapHttp4xxCodesToExceptions.class, newEntry("name", "cl66666_x"),
DomainOptions.Builder.primaryNameServer("ns1.somewhere.x").expire("1").minimum("1").refresh("1").
responsiblePerson("Tester").retry("1").ttl(1));
testMethod("addDomain", "add", "POST", false, MapHttp4xxCodesToExceptions.class, newEntry("name", "cl66666_x"));
}
public void testEditDomain() throws Exception {
testMethod("editDomain", "edit", "POST", false, MapHttp4xxCodesToExceptions.class, newEntry("domain", "x"));
}
public void testDeleteDomain() throws Exception {
testMethod("deleteDomain", "delete", "POST", false, MapHttp4xxCodesToExceptions.class, domainName);
}
@Override
protected TypeLiteral<RestAnnotationProcessor<DomainAsyncClient>> createTypeLiteral() {
return new TypeLiteral<RestAnnotationProcessor<DomainAsyncClient>>() {
};
}
}

View File

@ -0,0 +1,106 @@
/**
* 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 org.jclouds.glesys.domain.DomainRecord;
import org.jclouds.predicates.RetryablePredicate;
import org.testng.annotations.AfterGroups;
import org.testng.annotations.BeforeGroups;
import org.testng.annotations.Test;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import static org.testng.Assert.assertTrue;
/**
* Tests behavior of {@code DomainClient}
*
* @author Adam Lowe
*/
@Test(groups = "live", testName = "DomainClientLiveTest")
public class DomainClientLiveTest extends BaseGleSYSClientLiveTest {
@BeforeGroups(groups = {"live"})
public void setupClient() {
super.setupClient();
client = context.getApi().getDomainClient();
domainCounter = new RetryablePredicate<Integer>(
new Predicate<Integer>() {
public boolean apply(Integer value) {
return client.listDomains().size() == value;
}
}, 30, 1, TimeUnit.SECONDS);
recordCounter = new RetryablePredicate<Integer>(
new Predicate<Integer>() {
public boolean apply(Integer value) {
return client.listRecords(testDomain).size() == value;
}
}, 30, 1, TimeUnit.SECONDS);
}
@AfterGroups(groups = {"live"})
public void tearDown() {
int before = client.listDomains().size();
client.deleteDomain(testDomain);
assertTrue(domainCounter.apply(before - 1));
super.tearDown();
}
private DomainClient client;
private String testDomain = "glesystest.jclouds.org";
private String testRecordId;
private RetryablePredicate<Integer> domainCounter;
private RetryablePredicate<Integer> recordCounter;
@Test
public void testCreateDomain() throws Exception {
try {
client.deleteDomain(testDomain);
} catch (Exception ex) {
}
int before = client.listDomains().size();
client.addDomain(testDomain);
assertTrue(domainCounter.apply(before + 1));
}
@Test(dependsOnMethods = "testCreateDomain")
public void testCreateRecord() throws Exception {
int before = client.listRecords(testDomain).size();
client.addRecord(testDomain, "test", "A", "127.0.0.1");
assertTrue(recordCounter.apply(before + 1));
}
@Test(dependsOnMethods = "testCreateRecord")
public void testDeleteRecord() throws Exception {
Set<DomainRecord> domainRecords = client.listRecords(testDomain);
int before = domainRecords.size();
client.deleteRecord(domainRecords.iterator().next().getId());
assertTrue(recordCounter.apply(before - 1));
}
}

View File

@ -18,57 +18,106 @@
*/ */
package org.jclouds.glesys.features; package org.jclouds.glesys.features;
import java.io.IOException; import com.google.common.collect.Maps;
import java.lang.reflect.Method; import com.google.inject.TypeLiteral;
import org.jclouds.glesys.options.*;
import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpRequest;
import org.jclouds.http.functions.ParseFirstJsonValueNamed; import org.jclouds.http.functions.ParseFirstJsonValueNamed;
import org.jclouds.rest.functions.MapHttp4xxCodesToExceptions;
import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404; import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404;
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
import org.jclouds.rest.internal.RestAnnotationProcessor; import org.jclouds.rest.internal.RestAnnotationProcessor;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.inject.TypeLiteral; import java.io.IOException;
import java.lang.reflect.Method;
import java.util.Map;
/** /**
* Tests annotation parsing of {@code ServerAsyncClient} * Tests annotation parsing of {@code ServerAsyncClient}
* *
* @author Adrian Cole * @author Adrian Cole
* @author Adam Lowe
*/ */
@Test(groups = "unit", testName = "ServerAsyncClientTest") @Test(groups = "unit", testName = "ServerAsyncClientTest")
public class ServerAsyncClientTest extends BaseGleSYSAsyncClientTest<ServerAsyncClient> { public class ServerAsyncClientTest extends BaseGleSYSAsyncClientTest<ServerAsyncClient> {
public void testListServers() throws SecurityException, NoSuchMethodException, IOException { public ServerAsyncClientTest() {
Method method = ServerAsyncClient.class.getMethod("listServers"); asyncClientClass = ServerAsyncClient.class;
HttpRequest httpRequest = processor.createRequest(method); remoteServicePrefix = "server";
}
assertRequestLineEquals(httpRequest, "GET https://api.glesys.com/server/list/format/json HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n"); private Map.Entry<String, String> serverIdOnly = newEntry("serverid", "abcd");
assertPayloadEquals(httpRequest, null, null, false);
public void testListServers() throws Exception {
assertResponseParserClassEquals(method, httpRequest, ParseFirstJsonValueNamed.class); testMethod("listServers", "list", "POST", true, ReturnEmptySetOnNotFoundOr404.class);
assertSaxResponseParserClassEquals(method, null); }
assertExceptionParserClassEquals(method, ReturnEmptySetOnNotFoundOr404.class);
public void testGetAllowedArguments() throws Exception {
checkFilters(httpRequest); testMethod("getServerAllowedArguments", "allowedarguments", "GET", true, MapHttp4xxCodesToExceptions.class);
} }
public void testGetServer() throws SecurityException, NoSuchMethodException, IOException { public void testGetTemplates() throws Exception {
Method method = ServerAsyncClient.class.getMethod("getServerDetails", String.class); testMethod("getTemplates", "templates", "GET", true, MapHttp4xxCodesToExceptions.class);
HttpRequest httpRequest = processor.createRequest(method, "abcd"); }
assertRequestLineEquals(httpRequest, public void testGetServer() throws Exception {
"GET https://api.glesys.com/server/details/serverid/abcd/format/json HTTP/1.1"); testMethod("getServerDetails", "details", "POST", true, ReturnNullOnNotFoundOr404.class, serverIdOnly);
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n"); }
assertPayloadEquals(httpRequest, null, null, false);
@Test
public void testCreateServer() throws Exception {
testMethod("createServer", "create", "POST", true, MapHttp4xxCodesToExceptions.class,
newEntry("datacenter", "Falkenberg"), newEntry("platform", "OpenVZ"),
newEntry("hostname", "jclouds-test"), newEntry("template", "Ubuntu%2032-bit"),
newEntry("disksize", 5), newEntry("memorysize", 512), newEntry("cpucores", 1),
newEntry("rootpw", "password"), newEntry("transfer", 50));
testMethod("createServer", "create", "POST", true, MapHttp4xxCodesToExceptions.class,
newEntry("datacenter", "Falkenberg"), newEntry("platform", "OpenVZ"),
newEntry("hostname", "jclouds-test"), newEntry("template", "Ubuntu%2032-bit"),
newEntry("disksize", 5), newEntry("memorysize", 512), newEntry("cpucores", 1),
newEntry("rootpw", "password"), newEntry("transfer", 50),
ServerCreateOptions.Builder.description("Description-of-server").ip("10.0.0.1"));
}
assertResponseParserClassEquals(method, httpRequest, ParseFirstJsonValueNamed.class); @Test
assertSaxResponseParserClassEquals(method, null); public void testEditServer() throws Exception {
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class); testMethod("editServer", "edit", "POST", false, MapHttp4xxCodesToExceptions.class, serverIdOnly);
testMethod("editServer", "edit", "POST", false, MapHttp4xxCodesToExceptions.class, serverIdOnly,
ServerEditOptions.Builder.description("Description-of-server").disksize(1).memorysize(512).cpucores(1).hostname("jclouds-test"));
}
checkFilters(httpRequest); @Test
public void testCloneServer() throws Exception {
testMethod("cloneServer", "clone", "POST", false, MapHttp4xxCodesToExceptions.class, serverIdOnly, newEntry("hostname", "somename"));
testMethod("cloneServer", "clone", "POST", false, MapHttp4xxCodesToExceptions.class, serverIdOnly, newEntry("hostname", "somename"),
ServerCloneOptions.Builder.description("Description-of-server").disksize(1).memorysize(512).cpucores(1).hostname("jclouds-test"));
}
public void testGetServerStatus() throws Exception {
testMethod("getServerStatus", "status", "POST", true, ReturnNullOnNotFoundOr404.class, serverIdOnly);
testMethod("getServerStatus", "status", "POST", true, ReturnNullOnNotFoundOr404.class, serverIdOnly, ServerStatusOptions.Builder.state());
}
public void testGetServerLimits() throws Exception {
testMethod("getServerLimits", "limits", "POST", true, ReturnNullOnNotFoundOr404.class, serverIdOnly);
}
public void testGetServerConsole() throws Exception {
testMethod("getServerConsole", "console", "POST", true, ReturnNullOnNotFoundOr404.class, serverIdOnly);
}
public void testStartServer() throws Exception {
testMethod("startServer", "start", "POST", false, MapHttp4xxCodesToExceptions.class, serverIdOnly);
}
public void testStopServer() throws Exception {
testMethod("stopServer", "stop", "POST", false, MapHttp4xxCodesToExceptions.class, serverIdOnly);
testMethod("stopServer", "stop", "POST", false, MapHttp4xxCodesToExceptions.class, serverIdOnly, ServerStopOptions.Builder.hard());
}
public void testRebootServer() throws Exception {
testMethod("rebootServer", "reboot", "POST", false, MapHttp4xxCodesToExceptions.class, serverIdOnly);
} }
@Override @Override

View File

@ -20,11 +20,16 @@ package org.jclouds.glesys.features;
import com.google.common.base.Predicate; import com.google.common.base.Predicate;
import org.jclouds.glesys.domain.*; import org.jclouds.glesys.domain.*;
import org.jclouds.glesys.options.ServerCloneOptions;
import org.jclouds.glesys.options.ServerStatusOptions;
import org.jclouds.predicates.RetryablePredicate;
import org.testng.annotations.AfterGroups;
import org.testng.annotations.BeforeGroups; import org.testng.annotations.BeforeGroups;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.concurrent.TimeUnit;
import static org.testng.Assert.*; import static org.testng.Assert.*;
@ -32,6 +37,7 @@ import static org.testng.Assert.*;
* Tests behavior of {@code ServerClient} * Tests behavior of {@code ServerClient}
* *
* @author Adrian Cole * @author Adrian Cole
* @author Adam Lowe
*/ */
@Test(groups = "live", testName = "ServerClientLiveTest") @Test(groups = "live", testName = "ServerClientLiveTest")
public class ServerClientLiveTest extends BaseGleSYSClientLiveTest { public class ServerClientLiveTest extends BaseGleSYSClientLiveTest {
@ -41,22 +47,35 @@ public class ServerClientLiveTest extends BaseGleSYSClientLiveTest {
super.setupClient(); super.setupClient();
client = context.getApi().getServerClient(); client = context.getApi().getServerClient();
} }
public static class ServerStatePredicate implements Predicate<ServerClient> { @AfterGroups(groups = {"live"})
private ServerState state; public void tearDown() {
private String serverId; client.destroyServer(testServer.getId(), 0);
public ServerStatePredicate(ServerState state, String serverId) { if (testServer2 != null) {
this.state = state; client.destroyServer(testServer2.getId(), 0);
this.serverId = serverId;
}
@Override
public boolean apply(ServerClient client) {
return client.getServerStatus(serverId) != null && client.getServerStatus(serverId).getState() == state;
} }
super.tearDown();
}
private ServerClient client;
private ServerCreated testServer;
private ServerCreated testServer2;
// note this is initialized by testCreateServer()
private RetryablePredicate<ServerState> runningServerCounter;
@Test
public void testCreateServer() throws Exception {
testServer = client.createServer("Falkenberg", "OpenVZ", "jclouds-test", "Ubuntu 10.04 LTS 32-bit", 5, 512, 1, "password", 50);
assertNotNull(testServer.getId());
assertEquals(testServer.getHostname(), "jclouds-test");
assertFalse(testServer.getIps().isEmpty());
runningServerCounter = new ServerStatusChecker(testServer.getId(), 120, 2, TimeUnit.SECONDS);
assertTrue(runningServerCounter.apply(ServerState.RUNNING));
} }
private ServerClient client;
@Test @Test
public void testAllowedArguments() throws Exception { public void testAllowedArguments() throws Exception {
Map<String,ServerAllowedArguments> templates = client.getServerAllowedArguments(); Map<String,ServerAllowedArguments> templates = client.getServerAllowedArguments();
@ -106,11 +125,12 @@ public class ServerClientLiveTest extends BaseGleSYSClientLiveTest {
assert t.getMinMemSize() > 0 : t; assert t.getMinMemSize() > 0 : t;
} }
@Test @Test(dependsOnMethods = "testCreateServer")
public void testListServers() throws Exception { public void testListServers() throws Exception {
Set<Server> response = client.listServers(); Set<Server> response = client.listServers();
assert null != response; assertNotNull(response);
assertTrue(response.size() >= 0); assertTrue(response.size() > 0);
for (Server server : response) { for (Server server : response) {
ServerDetails newDetails = client.getServerDetails(server.getId()); ServerDetails newDetails = client.getServerDetails(server.getId());
assertEquals(newDetails.getId(), server.getId()); assertEquals(newDetails.getId(), server.getId());
@ -118,11 +138,97 @@ public class ServerClientLiveTest extends BaseGleSYSClientLiveTest {
assertEquals(newDetails.getPlatform(), server.getPlatform()); assertEquals(newDetails.getPlatform(), server.getPlatform());
assertEquals(newDetails.getDatacenter(), server.getDatacenter()); assertEquals(newDetails.getDatacenter(), server.getDatacenter());
checkServer(newDetails); checkServer(newDetails);
ServerStatus newStatus = client.getServerStatus(server.getId());
checkStatus(newStatus);
} }
} }
@Test(dependsOnMethods = "testCreateServer")
public void testServerDetails() throws Exception {
ServerStatus newStatus = client.getServerStatus(testServer.getId());
checkStatus(newStatus);
}
@Test(dependsOnMethods = "testCreateServer")
public void testRebootServer() throws Exception {
client.rebootServer(testServer.getId());
assertTrue(runningServerCounter.apply(ServerState.STOPPED));
assertTrue(runningServerCounter.apply(ServerState.RUNNING));
}
@Test(dependsOnMethods = "testCreateServer")
public void testStopAndStartServer() throws Exception {
client.stopServer(testServer.getId());
assertTrue(runningServerCounter.apply(ServerState.STOPPED));
client.startServer(testServer.getId());
assertTrue(runningServerCounter.apply(ServerState.RUNNING));
}
@Test(dependsOnMethods = "testCreateServer")
public void testServerLimits() throws Exception {
Map<String, ServerLimit> limits = client.getServerLimits(testServer.getId());
assertNotNull(limits);
for (Map.Entry<String, ServerLimit> entry : limits.entrySet()) {
assertNotNull(entry.getKey());
assertNotNull(entry.getValue());
ServerLimit limit = entry.getValue();
assertTrue(limit.getBarrier() >= 0);
assertTrue(limit.getFailCount() == 0);
assertTrue(limit.getHeld() >= 0);
assertTrue(limit.getLimit() > 0);
assertTrue(limit.getMaxHeld() >= 0);
}
}
// TODO in progress
@Test(enabled=false, dependsOnMethods = "testCreateServer")
public void testServerConsole() throws Exception {
ServerConsole console = client.getServerConsole(testServer.getId());
assertNotNull(console);
assertNotNull(console.getHost());
assertTrue(console.getPort() > 0 && console.getPort() < 65537);
assertNotNull(console.getPassword());
}
// takes a few minutes
@Test(enabled=false, dependsOnMethods = "testCreateServer")
public void testCloneServer() throws Exception {
testServer2 = client.cloneServer(testServer.getId(), "jclouds-test2", ServerCloneOptions.Builder.cpucores(1));
assertNotNull(testServer2.getId());
assertEquals(testServer2.getHostname(), "jclouds-test2");
assertTrue(testServer2.getIps().isEmpty());
RetryablePredicate<ServerState> cloneChecker = new ServerStatusChecker(testServer2.getId(), 300, 10, TimeUnit.SECONDS);
assertTrue(cloneChecker.apply(ServerState.STOPPED));
client.startServer(testServer2.getId());
// TODO ServerStatus==STOPPED suggests the previous call to start should have worked
cloneChecker = new RetryablePredicate<ServerState>(
new Predicate<ServerState>() {
public boolean apply(ServerState value) {
ServerStatus status = client.getServerStatus(testServer2.getId(), ServerStatusOptions.Builder.state());
if (status.getState() == value) {
return true;
}
client.startServer(testServer2.getId());
return false;
}
}, 300, 10, TimeUnit.SECONDS);
assertTrue(cloneChecker.apply(ServerState.RUNNING)
);
}
private void checkServer(ServerDetails server) { private void checkServer(ServerDetails server) {
// description can be null // description can be null
assert server.getCpuCores() > 0 : server; assert server.getCpuCores() > 0 : server;
@ -143,7 +249,9 @@ public class ServerClientLiveTest extends BaseGleSYSClientLiveTest {
assertNotNull(status.getCpu()); assertNotNull(status.getCpu());
assert status.getCpu().getSystem() >= 0.0 : status; assert status.getCpu().getSystem() >= 0.0 : status;
assert status.getCpu().getUser() >= 0.0 : status; assert status.getCpu().getUser() >= 0.0 : status;
assert status.getCpu().getNice() >= 0.0 : status; if (status.getCpu().getNice() != null) {
assert status.getCpu().getNice() >= 0.0 : status;
}
assert status.getCpu().getIdle() >= 0.0 : status; assert status.getCpu().getIdle() >= 0.0 : status;
assertNotNull(status.getCpu().getUnit()); assertNotNull(status.getCpu().getUnit());
@ -157,4 +265,17 @@ public class ServerClientLiveTest extends BaseGleSYSClientLiveTest {
assert status.getMemory().getUsage() >= 0 : status; assert status.getMemory().getUsage() >= 0 : status;
assertNotNull(status.getMemory().getUnit()); assertNotNull(status.getMemory().getUnit());
} }
private class ServerStatusChecker extends RetryablePredicate<ServerState> {
public ServerStatusChecker(final String serverId, long maxWait, long period, TimeUnit unit) {
super(new Predicate<ServerState>() {
public boolean apply(ServerState value) {
ServerStatus status = client.getServerStatus(serverId, ServerStatusOptions.Builder.state());
return status.getState() == value;
}
}, maxWait, period, unit);
}
}
} }

View File

@ -0,0 +1,70 @@
/**
* 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.Sets;
import com.google.inject.Guice;
import com.google.inject.Injector;
import org.jclouds.glesys.config.GleSYSParserModule;
import org.jclouds.glesys.domain.Domain;
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.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Set;
import static org.testng.Assert.fail;
/**
* @author Adam Lowe
*/
@Test(groups = "unit", testName = "ParseDomainListTest")
public class ParseDomainListTest extends BaseSetParserTest<Domain> {
@Override
public String resource() {
return "/domain_list.json";
}
@Override
@SelectJson("domains")
@Consumes(MediaType.APPLICATION_JSON)
public Set<Domain> expected() {
Date creationTime = null;
try {
creationTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse("2011-12-20 10:58:51");
} catch (ParseException e) {
fail("Bad dates!");
}
Domain domain = Domain.builder().domain("adamlowe.net").createTime(creationTime).recordCount(9).glesysNameServer(false).build();
return Sets.newHashSet(domain);
}
protected Injector injector() {
return Guice.createInjector(new GleSYSParserModule(), new GsonModule());
}
}

View File

@ -0,0 +1,76 @@
/**
* 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.ImmutableSortedSet;
import com.google.common.collect.Sets;
import com.google.inject.Guice;
import com.google.inject.Injector;
import org.jclouds.glesys.config.GleSYSParserModule;
import org.jclouds.glesys.domain.Domain;
import org.jclouds.glesys.domain.DomainRecord;
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.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Date;
import java.util.Set;
import static org.testng.Assert.fail;
/**
* @author Adam Lowe
*/
@Test(groups = "unit", testName = "ParseDomainRecordListTest")
public class ParseDomainRecordListTest extends BaseSetParserTest<DomainRecord> {
@Override
public String resource() {
return "/domain_list_records.json";
}
@Override
@SelectJson("records")
@Consumes(MediaType.APPLICATION_JSON)
public Set<DomainRecord> expected() {
return ImmutableSortedSet.copyOf(
Arrays.asList(
DomainRecord.builder().id("213227").zone("adamlowe.net").host("@").type("NS").data("ns1.namesystem.se.").ttl(3600).build(),
DomainRecord.builder().id("213228").zone("adamlowe.net").host("@").type("NS").data("ns2.namesystem.se.").ttl(3600).build(),
DomainRecord.builder().id("213229").zone("adamlowe.net").host("@").type("NS").data("ns3.namesystem.se.").ttl(3600).build(),
DomainRecord.builder().id("213230").zone("adamlowe.net").host("@").type("A").data("127.0.0.1").ttl(3600).build(),
DomainRecord.builder().id("213231").zone("adamlowe.net").host("www").type("A").data("127.0.0.1").ttl(3600).build(),
DomainRecord.builder().id("213232").zone("adamlowe.net").host("mail").type("A").data("79.99.4.40").ttl(3600).build(),
DomainRecord.builder().id("213233").zone("adamlowe.net").host("@").type("MX").data("mx01.glesys.se.").ttl(3600).build(),
DomainRecord.builder().id("213234").zone("adamlowe.net").host("@").type("MX").data("mx02.glesys.se.").ttl(3600).build(),
DomainRecord.builder().id("213235").zone("adamlowe.net").host("@").type("TXT").data("v=spf1 include:spf.glesys.se -all").ttl(3600).build()
));
}
protected Injector injector() {
return Guice.createInjector(new GleSYSParserModule(), new GsonModule());
}
}

View File

@ -0,0 +1 @@
{"response":{"status":{"code":"200","text":"OK"},"domains":[{"domain":"adamlowe.net","create_time":"2011-12-20 10:58:51","count":"9","glesysnameserver":false}],"debug":{"input":[]}}}

View File

@ -0,0 +1 @@
{"response":{"status":{"code":"200","text":"OK"},"records":[{"id":"213227","zone":"adamlowe.net","host":"@","type":"NS","data":"ns1.namesystem.se.","ttl":"3600"},{"id":"213228","zone":"adamlowe.net","host":"@","type":"NS","data":"ns2.namesystem.se.","ttl":"3600"},{"id":"213229","zone":"adamlowe.net","host":"@","type":"NS","data":"ns3.namesystem.se.","ttl":"3600"},{"id":"213230","zone":"adamlowe.net","host":"@","type":"A","data":"127.0.0.1","ttl":"3600"},{"id":"213231","zone":"adamlowe.net","host":"www","type":"A","data":"127.0.0.1","ttl":"3600"},{"id":"213232","zone":"adamlowe.net","host":"mail","type":"A","data":"79.99.4.40","ttl":"3600"},{"id":"213233","zone":"adamlowe.net","host":"@","type":"MX","data":"mx01.glesys.se.","ttl":"3600"},{"id":"213234","zone":"adamlowe.net","host":"@","type":"MX","data":"mx02.glesys.se.","ttl":"3600"},{"id":"213235","zone":"adamlowe.net","host":"@","type":"TXT","data":"v=spf1 include:spf.glesys.se -all","ttl":"3600"}],"debug":{"input":{"domain":"adamlowe.net"}}}}