mirror of https://github.com/apache/jclouds.git
Joyent server and Dataset features
This commit is contained in:
parent
bc0e512c81
commit
c1d9a7c47c
|
@ -19,6 +19,9 @@
|
|||
package org.jclouds.joyent.sdc.v6_5;
|
||||
|
||||
import org.jclouds.joyent.sdc.v6_5.features.DatacenterAsyncClient;
|
||||
import org.jclouds.joyent.sdc.v6_5.features.DatasetAsyncClient;
|
||||
import org.jclouds.joyent.sdc.v6_5.features.MachineAsyncClient;
|
||||
import org.jclouds.joyent.sdc.v6_5.features.PackageAsyncClient;
|
||||
import org.jclouds.rest.annotations.Delegate;
|
||||
|
||||
/**
|
||||
|
@ -36,5 +39,22 @@ public interface SDCAsyncClient {
|
|||
*/
|
||||
@Delegate
|
||||
DatacenterAsyncClient getDatacenterClient();
|
||||
|
||||
/**
|
||||
* Provides asynchronous access to Machine features.
|
||||
*/
|
||||
@Delegate
|
||||
MachineAsyncClient getMachineClient();
|
||||
|
||||
/**
|
||||
* Provides asynchronous access to Dataset features.
|
||||
*/
|
||||
@Delegate
|
||||
DatasetAsyncClient getDatasetClient();
|
||||
|
||||
/**
|
||||
* Provides asynchronous access to Package features.
|
||||
*/
|
||||
@Delegate
|
||||
PackageAsyncClient getPackageClient();
|
||||
}
|
||||
|
|
|
@ -22,6 +22,9 @@ import java.util.concurrent.TimeUnit;
|
|||
|
||||
import org.jclouds.concurrent.Timeout;
|
||||
import org.jclouds.joyent.sdc.v6_5.features.DatacenterClient;
|
||||
import org.jclouds.joyent.sdc.v6_5.features.DatasetClient;
|
||||
import org.jclouds.joyent.sdc.v6_5.features.MachineClient;
|
||||
import org.jclouds.joyent.sdc.v6_5.features.PackageClient;
|
||||
import org.jclouds.rest.annotations.Delegate;
|
||||
|
||||
/**
|
||||
|
@ -40,5 +43,22 @@ public interface SDCClient {
|
|||
*/
|
||||
@Delegate
|
||||
DatacenterClient getDatacenterClient();
|
||||
|
||||
/**
|
||||
* Provides synchronous access to Machine features.
|
||||
*/
|
||||
@Delegate
|
||||
MachineClient getMachineClient();
|
||||
|
||||
/**
|
||||
* Provides synchronous access to Dataset features.
|
||||
*/
|
||||
@Delegate
|
||||
DatasetClient getDatasetClient();
|
||||
|
||||
/**
|
||||
* Provides synchronous access to Package features.
|
||||
*/
|
||||
@Delegate
|
||||
PackageClient getPackageClient();
|
||||
}
|
||||
|
|
|
@ -0,0 +1,49 @@
|
|||
/**
|
||||
* 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.joyent.sdc.v6_5.config;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.joyent.sdc.v6_5.domain.Machine;
|
||||
import org.jclouds.joyent.sdc.v6_5.functions.internal.SDCTypeAdapters;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.Provides;
|
||||
|
||||
/**
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class SDCParserModule extends AbstractModule {
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
public Map<Type, Object> provideCustomAdapterBindings() {
|
||||
return ImmutableMap.<Type, Object> of(Machine.State.class, new SDCTypeAdapters.ServerStateAdapter(),
|
||||
Type.class, new SDCTypeAdapters.SDCTypeAdapter());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void configure() {
|
||||
}
|
||||
|
||||
}
|
|
@ -28,6 +28,12 @@ import org.jclouds.joyent.sdc.v6_5.SDCAsyncClient;
|
|||
import org.jclouds.joyent.sdc.v6_5.SDCClient;
|
||||
import org.jclouds.joyent.sdc.v6_5.features.DatacenterAsyncClient;
|
||||
import org.jclouds.joyent.sdc.v6_5.features.DatacenterClient;
|
||||
import org.jclouds.joyent.sdc.v6_5.features.DatasetAsyncClient;
|
||||
import org.jclouds.joyent.sdc.v6_5.features.DatasetClient;
|
||||
import org.jclouds.joyent.sdc.v6_5.features.MachineAsyncClient;
|
||||
import org.jclouds.joyent.sdc.v6_5.features.MachineClient;
|
||||
import org.jclouds.joyent.sdc.v6_5.features.PackageAsyncClient;
|
||||
import org.jclouds.joyent.sdc.v6_5.features.PackageClient;
|
||||
import org.jclouds.joyent.sdc.v6_5.handlers.SDCErrorHandler;
|
||||
import org.jclouds.json.config.GsonModule.DateAdapter;
|
||||
import org.jclouds.json.config.GsonModule.Iso8601DateAdapter;
|
||||
|
@ -45,6 +51,9 @@ import com.google.common.collect.ImmutableMap;
|
|||
public class SDCRestClientModule extends RestClientModule<SDCClient, SDCAsyncClient> {
|
||||
public static final Map<Class<?>, Class<?>> DELEGATE_MAP = ImmutableMap.<Class<?>, Class<?>> builder()
|
||||
.put(DatacenterClient.class, DatacenterAsyncClient.class)
|
||||
.put(MachineClient.class, MachineAsyncClient.class)
|
||||
.put(DatasetClient.class, DatasetAsyncClient.class)
|
||||
.put(PackageClient.class, PackageAsyncClient.class)
|
||||
.build();
|
||||
|
||||
public SDCRestClientModule() {
|
||||
|
@ -54,6 +63,7 @@ public class SDCRestClientModule extends RestClientModule<SDCClient, SDCAsyncCli
|
|||
@Override
|
||||
protected void configure() {
|
||||
bind(DateAdapter.class).to(Iso8601DateAdapter.class);
|
||||
install(new SDCParserModule());
|
||||
super.configure();
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,162 @@
|
|||
package org.jclouds.joyent.sdc.v6_5.domain;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
/**
|
||||
* Listing of a dataset.
|
||||
*
|
||||
* @author Gerald Pereira
|
||||
* @see <a href= "http://apidocs.joyent.com/sdcapidoc/cloudapi/#datasets" />
|
||||
*/
|
||||
public class Dataset implements Comparable<Dataset> {
|
||||
|
||||
public static Builder builder() {
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
private String id;
|
||||
private String name;
|
||||
private Type type;
|
||||
private String version;
|
||||
private String urn;
|
||||
private boolean defaultDataset;
|
||||
private Date created;
|
||||
|
||||
public Builder id(String id) {
|
||||
this.id = id;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder name(String name) {
|
||||
this.name = name;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder type(Type type) {
|
||||
this.type = type;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder version(String version) {
|
||||
this.version = version;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder urn(String urn) {
|
||||
this.urn = urn;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder defaultDataset(boolean defaultDataset) {
|
||||
this.defaultDataset = defaultDataset;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder created(Date created) {
|
||||
this.created = created;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Dataset build() {
|
||||
return new Dataset(id, name, type, version, urn, defaultDataset, created);
|
||||
}
|
||||
|
||||
public Builder fromDataset(Dataset in) {
|
||||
return id(in.getId()).name(in.getName()).type(in.getType()).version(
|
||||
in.getVersion()).urn(in.getUrn()).defaultDataset(
|
||||
in.isDefaultDataset()).created(
|
||||
in.getCreated());
|
||||
}
|
||||
}
|
||||
|
||||
// The globally unique id for this dataset
|
||||
protected final String id;
|
||||
// The "friendly" name for this dataset
|
||||
protected final String name;
|
||||
// Whether this is a smartmachine or virtualmachine
|
||||
protected final Type type;
|
||||
// The version for this dataset
|
||||
protected final String version;
|
||||
// The full URN for this dataset
|
||||
protected final String urn;
|
||||
// Whether this is the default dataset in this datacenter
|
||||
@SerializedName("default")
|
||||
protected final boolean defaultDataset;
|
||||
// Date (ISO8601) When this dataset was created
|
||||
protected final Date created;
|
||||
|
||||
public Dataset(String id, String name, Type type, String version,
|
||||
String urn, boolean defaultDataset, Date created) {
|
||||
super();
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.type = type;
|
||||
this.version = version;
|
||||
this.urn = urn;
|
||||
this.defaultDataset = defaultDataset;
|
||||
this.created = created;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public Type getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public String getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
public String getUrn() {
|
||||
return urn;
|
||||
}
|
||||
|
||||
public boolean isDefaultDataset() {
|
||||
return defaultDataset;
|
||||
}
|
||||
|
||||
public Date getCreated() {
|
||||
return created;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(Dataset other) {
|
||||
return id.compareTo(other.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object object) {
|
||||
if (this == object) {
|
||||
return true;
|
||||
}
|
||||
if (object instanceof Machine) {
|
||||
return Objects.equal(id, ((Machine) object).id);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hashCode(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String
|
||||
.format(
|
||||
"[id=%s, name=%s, type=%s, version=%s, urn=%s, default=%s, created=%s]",
|
||||
id, name, type.name(), type.name(), version, urn,
|
||||
defaultDataset, created);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,271 @@
|
|||
/**
|
||||
* 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.joyent.sdc.v6_5.domain;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import com.google.common.base.CaseFormat;
|
||||
import com.google.common.base.Objects;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
/**
|
||||
* Listing of a machine.
|
||||
*
|
||||
* @author Gerald Pereira
|
||||
* @see <a href= "http://apidocs.joyent.com/sdcapidoc/cloudapi/#machines" />
|
||||
*/
|
||||
public class Machine implements Comparable<Machine> {
|
||||
|
||||
public static enum State {
|
||||
PUBLISHING, RUNNING, STOPPED, UNRECOGNIZED;
|
||||
|
||||
public static State fromValue(String state) {
|
||||
try {
|
||||
return valueOf(CaseFormat.UPPER_CAMEL.to(
|
||||
CaseFormat.UPPER_UNDERSCORE, checkNotNull(state,
|
||||
"state")));
|
||||
} catch (IllegalArgumentException e) {
|
||||
return UNRECOGNIZED;
|
||||
}
|
||||
}
|
||||
|
||||
public String value() {
|
||||
return (CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL,
|
||||
name()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return value();
|
||||
}
|
||||
}
|
||||
|
||||
public static Builder builder() {
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
private String id;
|
||||
private String name;
|
||||
private Type type;
|
||||
private State state;
|
||||
private String dataset;
|
||||
private int memorySizeMb;
|
||||
private int diskSizeGb;
|
||||
private Set<String> ips;
|
||||
private Date created;
|
||||
private Date updated;
|
||||
private Map<String, String> metadata = ImmutableMap.of();
|
||||
|
||||
public Builder id(String id) {
|
||||
this.id = id;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder name(String name) {
|
||||
this.name = name;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder type(Type type) {
|
||||
this.type = type;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder state(State state) {
|
||||
this.state = state;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder dataset(String dataset) {
|
||||
this.dataset = dataset;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder memorySizeMb(int memorySizeMb) {
|
||||
this.memorySizeMb = memorySizeMb;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder diskSizeGb(int diskSizeGb) {
|
||||
this.diskSizeGb = diskSizeGb;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder ips(Set<String> ips) {
|
||||
this.ips = ips;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder created(Date created) {
|
||||
this.created = created;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder updated(Date updated) {
|
||||
this.updated = updated;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Machine#getMetadata()
|
||||
*/
|
||||
public Builder metadata(Map<String, String> metadata) {
|
||||
this.metadata = metadata;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Machine build() {
|
||||
return new Machine(id, name, type, state, dataset, memorySizeMb,
|
||||
diskSizeGb, ips, created, updated, metadata);
|
||||
}
|
||||
|
||||
public Builder fromMachine(Machine in) {
|
||||
return id(in.getId()).name(in.getName()).type(in.getType()).state(
|
||||
in.getState()).dataset(in.getDataset()).memorySizeMb(
|
||||
in.getMemorySizeMb()).diskSizeGb(in.getDiskSizeGb()).ips(
|
||||
in.getIps()).metadata(in.getMetadata()).created(
|
||||
in.getCreated()).updated(in.getUpdated());
|
||||
}
|
||||
}
|
||||
|
||||
// The globally unique id for this machine
|
||||
protected final String id;
|
||||
// The "friendly" name for this machine
|
||||
protected final String name;
|
||||
// Whether this is a smartmachine or virtualmachine
|
||||
protected final Type type;
|
||||
// The current state of this machine
|
||||
protected final State state;
|
||||
// The dataset urn this machine was provisioned with
|
||||
protected final String dataset;
|
||||
// The amount of memory this machine has (Mb)
|
||||
@SerializedName("memory")
|
||||
protected final int memorySizeMb;
|
||||
// The amount of disk this machine has (Gb)
|
||||
@SerializedName("disk")
|
||||
protected final int diskSizeGb;
|
||||
// The IP addresses this machine has
|
||||
protected final Set<String> ips;
|
||||
// Date (ISO8601) When this machine was created
|
||||
protected final Date created;
|
||||
// Date (ISO8601) When this machine was updated
|
||||
protected final Date updated;
|
||||
|
||||
// metadata Object[String => String] Any "extra" metadata this machine has
|
||||
private final Map<String, String> metadata;
|
||||
|
||||
@Override
|
||||
public int compareTo(Machine other) {
|
||||
return id.compareTo(other.getId());
|
||||
}
|
||||
|
||||
public Machine(String id, String name, Type type, State state,
|
||||
String dataset, int memorySizeMb, int diskSizeGb, Set<String> ips,
|
||||
Date created, Date updated, final Map<String, String> metadata) {
|
||||
super();
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.type = type;
|
||||
this.state = state;
|
||||
this.dataset = dataset;
|
||||
this.memorySizeMb = memorySizeMb;
|
||||
this.diskSizeGb = diskSizeGb;
|
||||
this.ips = ImmutableSet.<String> copyOf(ips);
|
||||
this.created = created;
|
||||
this.updated = updated;
|
||||
this.metadata = metadata;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public Type getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public State getState() {
|
||||
return state;
|
||||
}
|
||||
|
||||
public String getDataset() {
|
||||
return dataset;
|
||||
}
|
||||
|
||||
public int getMemorySizeMb() {
|
||||
return memorySizeMb;
|
||||
}
|
||||
|
||||
public int getDiskSizeGb() {
|
||||
return diskSizeGb;
|
||||
}
|
||||
|
||||
public Set<String> getIps() {
|
||||
return ips;
|
||||
}
|
||||
|
||||
public Date getCreated() {
|
||||
return created;
|
||||
}
|
||||
|
||||
public Date getUpdated() {
|
||||
return updated;
|
||||
}
|
||||
|
||||
public Map<String, String> getMetadata() {
|
||||
return metadata;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object object) {
|
||||
if (this == object) {
|
||||
return true;
|
||||
}
|
||||
if (object instanceof Machine) {
|
||||
return Objects.equal(id, ((Machine) object).id);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hashCode(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String
|
||||
.format(
|
||||
"[id=%s, name=%s, type=%s, state=%s, memory=%s, disk=%s, ips=%s, created=%s, updated=%s]",
|
||||
id, name, type.name(), state.name(), memorySizeMb,
|
||||
diskSizeGb, ips, created, updated);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,156 @@
|
|||
/**
|
||||
* 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.joyent.sdc.v6_5.domain;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
/**
|
||||
* Listing of a package.
|
||||
*
|
||||
* @author Gerald Pereira
|
||||
* @see <a href= "http://apidocs.joyent.com/sdcapidoc/cloudapi/#machines" />
|
||||
*/
|
||||
public class Package implements Comparable<Package> {
|
||||
|
||||
|
||||
public static Builder builder() {
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
private String name;
|
||||
private int memorySizeMb;
|
||||
private int diskSizeGb;
|
||||
private int swapSizeMb;
|
||||
private boolean defaultPackage;
|
||||
|
||||
public Builder name(String name) {
|
||||
this.name = name;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder memorySizeMb(int memorySizeMb) {
|
||||
this.memorySizeMb = memorySizeMb;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder diskSizeGb(int diskSizeGb) {
|
||||
this.diskSizeGb = diskSizeGb;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder swapSizeMb(int swapSizeMb) {
|
||||
this.swapSizeMb = swapSizeMb;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder isDefault(boolean defaultPackage) {
|
||||
this.defaultPackage = defaultPackage;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public Package build() {
|
||||
return new Package(name, memorySizeMb,
|
||||
diskSizeGb, swapSizeMb, defaultPackage);
|
||||
}
|
||||
|
||||
public Builder fromPackage(Package in) {
|
||||
return name(in.getName()).memorySizeMb(
|
||||
in.getMemorySizeMb()).diskSizeGb(in.getDiskSizeGb()).swapSizeMb(in.getSwapSizeMb()).isDefault(in.isDefault());
|
||||
}
|
||||
}
|
||||
|
||||
// The "friendly" name for this machine
|
||||
protected final String name;
|
||||
// The amount of memory this package has (Mb)
|
||||
@SerializedName("memory")
|
||||
protected final int memorySizeMb;
|
||||
// The amount of disk this package has (Gb)
|
||||
@SerializedName("disk")
|
||||
protected final int diskSizeGb;
|
||||
// The amount of swap this package has (Gb)
|
||||
@SerializedName("swap")
|
||||
protected final int swapSizeMb;
|
||||
// Whether this is the default package in this datacenter
|
||||
@SerializedName("default")
|
||||
protected final boolean defaultPackage;
|
||||
|
||||
@Override
|
||||
public int compareTo(Package other) {
|
||||
return name.compareTo(other.getName());
|
||||
}
|
||||
|
||||
public Package(String name, int memorySizeMb, int diskSizeGb,
|
||||
int swapSizeMb, boolean defaultPackage) {
|
||||
super();
|
||||
this.name = name;
|
||||
this.memorySizeMb = memorySizeMb;
|
||||
this.diskSizeGb = diskSizeGb;
|
||||
this.swapSizeMb = swapSizeMb;
|
||||
this.defaultPackage = defaultPackage;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public int getMemorySizeMb() {
|
||||
return memorySizeMb;
|
||||
}
|
||||
|
||||
public int getDiskSizeGb() {
|
||||
return diskSizeGb;
|
||||
}
|
||||
|
||||
public int getSwapSizeMb() {
|
||||
return swapSizeMb;
|
||||
}
|
||||
|
||||
public boolean isDefault() {
|
||||
return defaultPackage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object object) {
|
||||
if (this == object) {
|
||||
return true;
|
||||
}
|
||||
if (object instanceof Package) {
|
||||
return Objects.equal(name, ((Package) object).name);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hashCode(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String
|
||||
.format(
|
||||
"[name=%s, memory=%s, disk=%s, swap=%s, default=%s]",
|
||||
name, memorySizeMb,
|
||||
diskSizeGb, swapSizeMb, defaultPackage);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
package org.jclouds.joyent.sdc.v6_5.domain;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import com.google.common.base.CaseFormat;
|
||||
|
||||
public enum Type {
|
||||
VIRTUALMACHINE, SMARTMACHINE, UNRECOGNIZED;
|
||||
|
||||
public static Type fromValue(String type) {
|
||||
try {
|
||||
return valueOf(CaseFormat.UPPER_CAMEL
|
||||
.to(CaseFormat.UPPER_UNDERSCORE, checkNotNull(type,
|
||||
"type")));
|
||||
} catch (IllegalArgumentException e) {
|
||||
return UNRECOGNIZED;
|
||||
}
|
||||
}
|
||||
|
||||
public String value() {
|
||||
return (CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL,
|
||||
name()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return value();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,51 @@
|
|||
package org.jclouds.joyent.sdc.v6_5.features;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.PathParam;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
|
||||
import org.jclouds.http.filters.BasicAuthentication;
|
||||
import org.jclouds.joyent.sdc.v6_5.domain.Dataset;
|
||||
import org.jclouds.rest.annotations.ExceptionParser;
|
||||
import org.jclouds.rest.annotations.Headers;
|
||||
import org.jclouds.rest.annotations.RequestFilters;
|
||||
import org.jclouds.rest.annotations.SkipEncoding;
|
||||
import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404;
|
||||
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
|
||||
|
||||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
|
||||
/**
|
||||
* Provides asynchronous access to Dataset via their REST API.
|
||||
* <p/>
|
||||
*
|
||||
* @author Gerald Pereira
|
||||
* @see DatasetClient
|
||||
* @see <a href="http://apidocs.joyent.com/sdcapidoc/cloudapi">api doc</a>
|
||||
*/
|
||||
@SkipEncoding( { '/', '=' })
|
||||
@Headers(keys = "X-Api-Version", values = "{jclouds.api-version}")
|
||||
@RequestFilters(BasicAuthentication.class)
|
||||
public interface DatasetAsyncClient {
|
||||
/**
|
||||
* @see DatasetClient#listMachines
|
||||
*/
|
||||
@GET
|
||||
@Path("/my/datasets")
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@ExceptionParser(ReturnEmptySetOnNotFoundOr404.class)
|
||||
ListenableFuture<Set<Dataset>> listDatasets();
|
||||
|
||||
/**
|
||||
* @see DatasetClient#getMachineDetails
|
||||
*/
|
||||
@GET
|
||||
@Path("/my/datasets/{id}")
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||
ListenableFuture<Dataset> getDataset(@PathParam("id") String id);
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
package org.jclouds.joyent.sdc.v6_5.features;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.jclouds.concurrent.Timeout;
|
||||
import org.jclouds.joyent.sdc.v6_5.domain.Dataset;
|
||||
|
||||
/**
|
||||
* Provides synchronous access to Datasets.
|
||||
* <p/>
|
||||
*
|
||||
* @author Gerald Pereira
|
||||
* @see DatasetAsyncClient
|
||||
* @see <a href="http://apidocs.joyent.com/sdcapidoc/cloudapi">api doc</a>
|
||||
*/
|
||||
@Timeout(duration = 30, timeUnit = TimeUnit.SECONDS)
|
||||
public interface DatasetClient {
|
||||
|
||||
/**
|
||||
* Provides a list of datasets available in this datacenter.
|
||||
* @return
|
||||
*/
|
||||
Set<Dataset> listDatasets();
|
||||
|
||||
/**
|
||||
* Gets an individual dataset by id.
|
||||
*
|
||||
* @param id
|
||||
* the id of the dataset
|
||||
* @return
|
||||
*/
|
||||
Dataset getDataset(String id);
|
||||
}
|
|
@ -0,0 +1,71 @@
|
|||
/**
|
||||
* 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.joyent.sdc.v6_5.features;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.PathParam;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
|
||||
import org.jclouds.http.filters.BasicAuthentication;
|
||||
import org.jclouds.joyent.sdc.v6_5.domain.Machine;
|
||||
import org.jclouds.rest.annotations.ExceptionParser;
|
||||
import org.jclouds.rest.annotations.Headers;
|
||||
import org.jclouds.rest.annotations.RequestFilters;
|
||||
import org.jclouds.rest.annotations.SkipEncoding;
|
||||
import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404;
|
||||
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
|
||||
|
||||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
|
||||
/**
|
||||
* Provides asynchronous access to Machine via their REST API.
|
||||
* <p/>
|
||||
*
|
||||
* @author Gerald Pereira
|
||||
* @see MachineClient
|
||||
* @see <a href="http://apidocs.joyent.com/sdcapidoc/cloudapi">api doc</a>
|
||||
*/
|
||||
@SkipEncoding( { '/', '=' })
|
||||
@Headers(keys = "X-Api-Version", values = "{jclouds.api-version}")
|
||||
@RequestFilters(BasicAuthentication.class)
|
||||
public interface MachineAsyncClient {
|
||||
|
||||
/**
|
||||
* @see MachineClient#listMachines
|
||||
*/
|
||||
@GET
|
||||
@Path("/my/machines")
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@ExceptionParser(ReturnEmptySetOnNotFoundOr404.class)
|
||||
ListenableFuture<Set<Machine>> listMachines();
|
||||
|
||||
/**
|
||||
* @see MachineClient#getMachineDetails
|
||||
*/
|
||||
@GET
|
||||
@Path("/my/machines/{id}")
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||
ListenableFuture<Machine> getMachine(@PathParam("id") String id);
|
||||
|
||||
}
|
|
@ -0,0 +1,55 @@
|
|||
/**
|
||||
* 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.joyent.sdc.v6_5.features;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.jclouds.concurrent.Timeout;
|
||||
import org.jclouds.joyent.sdc.v6_5.domain.Machine;
|
||||
|
||||
|
||||
/**
|
||||
* Provides synchronous access to Machine.
|
||||
* <p/>
|
||||
*
|
||||
* @author Gerald Pereira
|
||||
* @see MachineAsyncClient
|
||||
* @see <a href="http://apidocs.joyent.com/sdcapidoc/cloudapi">api doc</a>
|
||||
*/
|
||||
@Timeout(duration = 30, timeUnit = TimeUnit.SECONDS)
|
||||
public interface MachineClient {
|
||||
|
||||
/**
|
||||
* Lists all machines we have on record for your account.
|
||||
*
|
||||
* @return an account's associated machine objects.
|
||||
*/
|
||||
Set<Machine> listMachines();
|
||||
|
||||
|
||||
/**
|
||||
* Gets the details for an individual machine.
|
||||
*
|
||||
* @param id the id of the machine
|
||||
* @return
|
||||
*/
|
||||
Machine getMachine(String id);
|
||||
|
||||
}
|
|
@ -0,0 +1,50 @@
|
|||
package org.jclouds.joyent.sdc.v6_5.features;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.PathParam;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
|
||||
import org.jclouds.http.filters.BasicAuthentication;
|
||||
import org.jclouds.rest.annotations.ExceptionParser;
|
||||
import org.jclouds.rest.annotations.Headers;
|
||||
import org.jclouds.rest.annotations.RequestFilters;
|
||||
import org.jclouds.rest.annotations.SkipEncoding;
|
||||
import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404;
|
||||
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
|
||||
|
||||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
|
||||
/**
|
||||
* Provides asynchronous access to Dataset via their REST API.
|
||||
* <p/>
|
||||
*
|
||||
* @author Gerald Pereira
|
||||
* @see PackageClient
|
||||
* @see <a href="http://apidocs.joyent.com/sdcapidoc/cloudapi">api doc</a>
|
||||
*/
|
||||
@SkipEncoding( { '/', '=' })
|
||||
@Headers(keys = "X-Api-Version", values = "{jclouds.api-version}")
|
||||
@RequestFilters(BasicAuthentication.class)
|
||||
public interface PackageAsyncClient {
|
||||
/**
|
||||
* @see PackageClient#listPackages
|
||||
*/
|
||||
@GET
|
||||
@Path("/my/packages")
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@ExceptionParser(ReturnEmptySetOnNotFoundOr404.class)
|
||||
ListenableFuture<Set<org.jclouds.joyent.sdc.v6_5.domain.Package>> listPackages();
|
||||
|
||||
/**
|
||||
* @see PackageClient#getPackageDetails
|
||||
*/
|
||||
@GET
|
||||
@Path("/my/packages/{name}")
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||
ListenableFuture<org.jclouds.joyent.sdc.v6_5.domain.Package> getPackage(@PathParam("name") String name);
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
package org.jclouds.joyent.sdc.v6_5.features;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.jclouds.concurrent.Timeout;
|
||||
|
||||
/**
|
||||
* Provides synchronous access to Packages.
|
||||
* <p/>
|
||||
*
|
||||
* @author Gerald Pereira
|
||||
* @see PackageAsyncClient
|
||||
* @see <a href="http://apidocs.joyent.com/sdcapidoc/cloudapi">api doc</a>
|
||||
*/
|
||||
@Timeout(duration = 30, timeUnit = TimeUnit.SECONDS)
|
||||
public interface PackageClient {
|
||||
|
||||
/**
|
||||
* Provides a list of packages available in this datacenter.
|
||||
* @return
|
||||
*/
|
||||
Set<org.jclouds.joyent.sdc.v6_5.domain.Package> listPackages();
|
||||
|
||||
/**
|
||||
* Gets an individual package by id.
|
||||
*
|
||||
* @param name
|
||||
* the name of the package
|
||||
* @return
|
||||
*/
|
||||
org.jclouds.joyent.sdc.v6_5.domain.Package getPackage(String name);
|
||||
}
|
|
@ -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.joyent.sdc.v6_5.functions.internal;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.jclouds.joyent.sdc.v6_5.domain.Machine;
|
||||
import org.jclouds.joyent.sdc.v6_5.domain.Type;
|
||||
|
||||
import com.google.gson.TypeAdapter;
|
||||
import com.google.gson.stream.JsonReader;
|
||||
import com.google.gson.stream.JsonWriter;
|
||||
|
||||
/**
|
||||
* @author Adam Lowe
|
||||
*/
|
||||
public class SDCTypeAdapters {
|
||||
|
||||
public static class ServerStateAdapter extends TypeAdapter<Machine.State> {
|
||||
@Override
|
||||
public void write(JsonWriter writer, Machine.State value) throws IOException {
|
||||
writer.value(value.value());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Machine.State read(JsonReader reader) throws IOException {
|
||||
return Machine.State.fromValue(reader.nextString());
|
||||
}
|
||||
}
|
||||
|
||||
public static class SDCTypeAdapter extends TypeAdapter<Type> {
|
||||
@Override
|
||||
public void write(JsonWriter writer, Type value) throws IOException {
|
||||
writer.value(value.value());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Type read(JsonReader reader) throws IOException {
|
||||
return Type.fromValue(reader.nextString());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -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
|
||||
*
|
||||
* Unles 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 expres or implied. See the License for the
|
||||
* specific language governing permisions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.jclouds.joyent.sdc.v6_5.features;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.joyent.sdc.v6_5.SDCClient;
|
||||
import org.jclouds.joyent.sdc.v6_5.internal.BaseSDCClientExpectTest;
|
||||
import org.jclouds.joyent.sdc.v6_5.parse.ParseDatasetListTest;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.collect.ImmutableMultimap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
/**
|
||||
* @author Gerald Pereira
|
||||
*/
|
||||
@Test(groups = "unit", testName = "DatasetClientExpectTest")
|
||||
public class DatasetClientExpectTest extends BaseSDCClientExpectTest {
|
||||
HttpRequest listDatasets = HttpRequest.builder().method("GET").endpoint(
|
||||
URI.create("https://api.joyentcloud.com/my/datasets")).headers(
|
||||
ImmutableMultimap.<String, String> builder().put("X-Api-Version",
|
||||
"~6.5").put("Accept", "application/json").put(
|
||||
"Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==")
|
||||
.build()).build();
|
||||
|
||||
public void testListDatasetsWhenResponseIs2xx() {
|
||||
HttpResponse listDatasetsResponse = HttpResponse.builder()
|
||||
.statusCode(200).payload(
|
||||
payloadFromResource("/dataset_list.json")).build();
|
||||
|
||||
SDCClient clientWhenDatasetsExists = requestSendsResponse(listDatasets,
|
||||
listDatasetsResponse);
|
||||
|
||||
assertEquals(
|
||||
clientWhenDatasetsExists.getDatasetClient().listDatasets().toString(),
|
||||
new ParseDatasetListTest().expected().toString());
|
||||
}
|
||||
|
||||
public void testListDatasetsWhenResponseIs404() {
|
||||
HttpResponse listDatasetsResponse = HttpResponse.builder().statusCode(
|
||||
404).build();
|
||||
|
||||
SDCClient listDatasetsWhenNone = requestSendsResponse(listDatasets,
|
||||
listDatasetsResponse);
|
||||
|
||||
assertEquals(listDatasetsWhenNone.getDatasetClient().listDatasets(),
|
||||
ImmutableSet.of());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,50 @@
|
|||
/**
|
||||
* 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.joyent.sdc.v6_5.features;
|
||||
|
||||
import static org.testng.AssertJUnit.assertEquals;
|
||||
import static org.testng.Assert.assertNotNull;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import org.jclouds.joyent.sdc.v6_5.domain.Dataset;
|
||||
import org.jclouds.joyent.sdc.v6_5.internal.BaseSDCClientLiveTest;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
/**
|
||||
* @author Gerald Pereira
|
||||
*/
|
||||
@Test(groups = "live", testName = "DatasetClientLiveTest")
|
||||
public class DatasetClientLiveTest extends BaseSDCClientLiveTest {
|
||||
|
||||
public void testListDatasets() {
|
||||
Set<Dataset> datasets = sdcContext.getApi().getDatasetClient()
|
||||
.listDatasets();
|
||||
assertNotNull(datasets);
|
||||
assertTrue(datasets.size() > 0);
|
||||
}
|
||||
|
||||
public void testGetDataset() {
|
||||
final String id = "e4cd7b9e-4330-11e1-81cf-3bb50a972bda";
|
||||
Dataset dataset = sdcContext.getApi().getDatasetClient().getDataset(id);
|
||||
assertNotNull(dataset);
|
||||
assertEquals(dataset.getId(), id);
|
||||
}
|
||||
}
|
|
@ -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
|
||||
*
|
||||
* Unles 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 expres or implied. See the License for the
|
||||
* specific language governing permisions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.jclouds.joyent.sdc.v6_5.features;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.joyent.sdc.v6_5.SDCClient;
|
||||
import org.jclouds.joyent.sdc.v6_5.internal.BaseSDCClientExpectTest;
|
||||
import org.jclouds.joyent.sdc.v6_5.parse.ParseMachineListTest;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.collect.ImmutableMultimap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
/**
|
||||
* @author Gerald Pereira
|
||||
*/
|
||||
@Test(groups = "unit", testName = "MachineClientExpectTest")
|
||||
public class MachineClientExpectTest extends BaseSDCClientExpectTest {
|
||||
HttpRequest listMachines = HttpRequest.builder().method("GET").endpoint(
|
||||
URI.create("https://api.joyentcloud.com/my/machines")).headers(
|
||||
ImmutableMultimap.<String, String> builder().put("X-Api-Version",
|
||||
"~6.5").put("Accept", "application/json").put(
|
||||
"Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==")
|
||||
.build()).build();
|
||||
|
||||
public void testListMachinesWhenResponseIs2xx() {
|
||||
HttpResponse listMachinesResponse = HttpResponse.builder()
|
||||
.statusCode(200).payload(
|
||||
payloadFromResource("/machine_list.json")).build();
|
||||
|
||||
SDCClient clientWhenMachinesExists = requestSendsResponse(listMachines,
|
||||
listMachinesResponse);
|
||||
|
||||
assertEquals(
|
||||
clientWhenMachinesExists.getMachineClient().listMachines(),
|
||||
new ParseMachineListTest().expected());
|
||||
}
|
||||
|
||||
public void testListMachinesWhenResponseIs404() {
|
||||
HttpResponse listMachinesResponse = HttpResponse.builder().statusCode(
|
||||
404).build();
|
||||
|
||||
SDCClient listMachinesWhenNone = requestSendsResponse(listMachines,
|
||||
listMachinesResponse);
|
||||
|
||||
assertEquals(listMachinesWhenNone.getMachineClient().listMachines(),
|
||||
ImmutableSet.of());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,50 @@
|
|||
/**
|
||||
* 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.joyent.sdc.v6_5.features;
|
||||
|
||||
import static org.testng.Assert.assertNotNull;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import org.jclouds.joyent.sdc.v6_5.domain.Machine;
|
||||
import org.jclouds.joyent.sdc.v6_5.internal.BaseSDCClientLiveTest;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
/**
|
||||
* @author Gerald Pereira
|
||||
*/
|
||||
@Test(groups = "live", testName = "MachineClientLiveTest")
|
||||
public class MachineClientLiveTest extends BaseSDCClientLiveTest {
|
||||
|
||||
public void testListMachines() {
|
||||
Set<Machine> machines = sdcContext.getApi().getMachineClient()
|
||||
.listMachines();
|
||||
assertNotNull(machines);
|
||||
assertTrue(machines.size() > 0);
|
||||
}
|
||||
|
||||
public void testGetMachine() {
|
||||
final String id = "d73cb0b0-7d1f-44ef-8c40-e040eef0f726";
|
||||
Machine machine = sdcContext.getApi().getMachineClient().getMachine(id);
|
||||
assertNotNull(machine);
|
||||
assertEquals(machine.getId(), id);
|
||||
}
|
||||
}
|
|
@ -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
|
||||
*
|
||||
* Unles 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 expres or implied. See the License for the
|
||||
* specific language governing permisions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.jclouds.joyent.sdc.v6_5.features;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.joyent.sdc.v6_5.SDCClient;
|
||||
import org.jclouds.joyent.sdc.v6_5.internal.BaseSDCClientExpectTest;
|
||||
import org.jclouds.joyent.sdc.v6_5.parse.ParsePackageListTest;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.collect.ImmutableMultimap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
/**
|
||||
* @author Gerald Pereira
|
||||
*/
|
||||
@Test(groups = "unit", testName = "PackageClientExpectTest")
|
||||
public class PackageClientExpectTest extends BaseSDCClientExpectTest {
|
||||
HttpRequest listPackages = HttpRequest.builder().method("GET").endpoint(
|
||||
URI.create("https://api.joyentcloud.com/my/packages")).headers(
|
||||
ImmutableMultimap.<String, String> builder().put("X-Api-Version",
|
||||
"~6.5").put("Accept", "application/json").put(
|
||||
"Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==")
|
||||
.build()).build();
|
||||
|
||||
public void testListPackagesWhenResponseIs2xx() {
|
||||
HttpResponse listPackagesResponse = HttpResponse.builder()
|
||||
.statusCode(200).payload(
|
||||
payloadFromResource("/package_list.json")).build();
|
||||
|
||||
SDCClient clientWhenPackagesExists = requestSendsResponse(listPackages,
|
||||
listPackagesResponse);
|
||||
|
||||
assertEquals(
|
||||
clientWhenPackagesExists.getPackageClient().listPackages(),
|
||||
new ParsePackageListTest().expected());
|
||||
}
|
||||
|
||||
public void testListPackagesWhenResponseIs404() {
|
||||
HttpResponse listPackagesResponse = HttpResponse.builder().statusCode(
|
||||
404).build();
|
||||
|
||||
SDCClient listPackagesWhenNone = requestSendsResponse(listPackages,
|
||||
listPackagesResponse);
|
||||
|
||||
assertEquals(listPackagesWhenNone.getPackageClient().listPackages(),
|
||||
ImmutableSet.of());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,49 @@
|
|||
/**
|
||||
* 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.joyent.sdc.v6_5.features;
|
||||
|
||||
import static org.testng.AssertJUnit.assertEquals;
|
||||
import static org.testng.Assert.assertNotNull;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import org.jclouds.joyent.sdc.v6_5.internal.BaseSDCClientLiveTest;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
/**
|
||||
* @author Gerald Pereira
|
||||
*/
|
||||
@Test(groups = "live", testName = "PackageClientLiveTest")
|
||||
public class PackageClientLiveTest extends BaseSDCClientLiveTest {
|
||||
|
||||
public void testListPackages() {
|
||||
Set<org.jclouds.joyent.sdc.v6_5.domain.Package> packages = sdcContext.getApi().getPackageClient()
|
||||
.listPackages();
|
||||
assertNotNull(packages);
|
||||
assertTrue(packages.size() > 0);
|
||||
}
|
||||
|
||||
public void testGetPackage() {
|
||||
final String name = "Small 1GB";
|
||||
org.jclouds.joyent.sdc.v6_5.domain.Package packageSDC = sdcContext.getApi().getPackageClient().getPackage(name);
|
||||
assertNotNull(packageSDC);
|
||||
assertEquals(packageSDC.getName(), name);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,90 @@
|
|||
/**
|
||||
* 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.joyent.sdc.v6_5.parse;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
|
||||
import org.jclouds.date.internal.SimpleDateFormatDateService;
|
||||
import org.jclouds.joyent.sdc.v6_5.config.SDCParserModule;
|
||||
import org.jclouds.joyent.sdc.v6_5.domain.Dataset;
|
||||
import org.jclouds.joyent.sdc.v6_5.domain.Type;
|
||||
import org.jclouds.json.BaseSetParserTest;
|
||||
import org.jclouds.json.config.GsonModule;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
|
||||
/**
|
||||
* @author Gerald Pereira
|
||||
*/
|
||||
@Test(groups = "unit", testName = "ParseDatasetListTest")
|
||||
public class ParseDatasetListTest extends BaseSetParserTest<Dataset> {
|
||||
|
||||
@Override
|
||||
public String resource() {
|
||||
return "/dataset_list.json";
|
||||
}
|
||||
|
||||
@Override
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
public Set<Dataset> expected() {
|
||||
return ImmutableSet
|
||||
.of(
|
||||
Dataset
|
||||
.builder()
|
||||
.id("e4cd7b9e-4330-11e1-81cf-3bb50a972bda")
|
||||
.name("centos-6")
|
||||
.urn("sdc:sdc:centos-6:1.0.1")
|
||||
.type(Type.VIRTUALMACHINE)
|
||||
.version("1.0.1")
|
||||
.defaultDataset(false)
|
||||
.created(new SimpleDateFormatDateService().iso8601SecondsDateParse("2012-02-13T06:30:33+00:00"))
|
||||
.build(),
|
||||
|
||||
Dataset
|
||||
.builder()
|
||||
.id("e62c30b4-cdda-11e0-9dd4-af4d032032e3")
|
||||
.name("nodejs")
|
||||
.urn("sdc:sdc:nodejs:1.2.3")
|
||||
.type(Type.SMARTMACHINE)
|
||||
.version("1.2.3")
|
||||
.defaultDataset(false)
|
||||
.created(new SimpleDateFormatDateService().iso8601SecondsDateParse("2011-09-15T08:15:29+00:00"))
|
||||
.build()
|
||||
|
||||
);
|
||||
}
|
||||
|
||||
protected Injector injector() {
|
||||
return Guice.createInjector(new SDCParserModule(), new GsonModule() {
|
||||
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(DateAdapter.class).to(Iso8601DateAdapter.class);
|
||||
super.configure();
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
}
|
|
@ -0,0 +1,73 @@
|
|||
/**
|
||||
* 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.joyent.sdc.v6_5.parse;
|
||||
|
||||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
|
||||
import org.jclouds.date.internal.SimpleDateFormatDateService;
|
||||
import org.jclouds.joyent.sdc.v6_5.config.SDCParserModule;
|
||||
import org.jclouds.joyent.sdc.v6_5.domain.Dataset;
|
||||
import org.jclouds.joyent.sdc.v6_5.domain.Type;
|
||||
import org.jclouds.json.BaseItemParserTest;
|
||||
import org.jclouds.json.config.GsonModule;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
|
||||
/**
|
||||
* @author Gerald Pereira
|
||||
*/
|
||||
@Test(groups = "unit", testName = "ParseDatasetTest")
|
||||
public class ParseDatasetTest extends BaseItemParserTest<Dataset> {
|
||||
|
||||
@Override
|
||||
public String resource() {
|
||||
return "/dataset.json";
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
public Dataset expected() {
|
||||
return Dataset
|
||||
.builder()
|
||||
.id("e4cd7b9e-4330-11e1-81cf-3bb50a972bda")
|
||||
.name("centos-6")
|
||||
.urn("sdc:sdc:centos-6:1.0.1")
|
||||
.type(Type.VIRTUALMACHINE)
|
||||
.version("1.0.1")
|
||||
.defaultDataset(false)
|
||||
.created(new SimpleDateFormatDateService().iso8601SecondsDateParse("2012-02-13T06:30:33+00:00"))
|
||||
.build();
|
||||
}
|
||||
|
||||
protected Injector injector() {
|
||||
return Guice.createInjector(new SDCParserModule(), new GsonModule() {
|
||||
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(DateAdapter.class).to(Iso8601DateAdapter.class);
|
||||
super.configure();
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
}
|
|
@ -0,0 +1,120 @@
|
|||
/**
|
||||
* 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.joyent.sdc.v6_5.parse;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
|
||||
import org.jclouds.date.internal.SimpleDateFormatDateService;
|
||||
import org.jclouds.joyent.sdc.v6_5.config.SDCParserModule;
|
||||
import org.jclouds.joyent.sdc.v6_5.domain.Machine;
|
||||
import org.jclouds.joyent.sdc.v6_5.domain.Type;
|
||||
import org.jclouds.json.BaseSetParserTest;
|
||||
import org.jclouds.json.config.GsonModule;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
|
||||
/**
|
||||
* @author Gerald Pereira
|
||||
*/
|
||||
@Test(groups = "unit", testName = "ParseMachineListTest")
|
||||
public class ParseMachineListTest extends BaseSetParserTest<Machine> {
|
||||
|
||||
@Override
|
||||
public String resource() {
|
||||
return "/machine_list.json";
|
||||
}
|
||||
|
||||
@Override
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
public Set<Machine> expected() {
|
||||
return ImmutableSet
|
||||
.of(
|
||||
Machine
|
||||
.builder()
|
||||
.id("94eba336-ecb7-49f5-8a27-52f5e4dd57a1")
|
||||
.name("testJClouds")
|
||||
.type(Type.VIRTUALMACHINE)
|
||||
.state(Machine.State.RUNNING)
|
||||
.dataset("sdc:sdc:centos-5.7:1.2.1")
|
||||
.ips(
|
||||
ImmutableSet.<String> builder().add(
|
||||
"37.153.96.62").add(
|
||||
"10.224.0.63").build())
|
||||
.memorySizeMb(1024)
|
||||
.diskSizeGb(61440)
|
||||
.metadata(
|
||||
ImmutableMap
|
||||
.<String, String> builder()
|
||||
.put("root_authorized_keys",
|
||||
"ssh-rsa XXXXXX== test@xxxx.ovh.net\n")
|
||||
.build())
|
||||
.created(
|
||||
new SimpleDateFormatDateService()
|
||||
.iso8601SecondsDateParse("2012-05-09T13:32:46+00:00"))
|
||||
.updated(
|
||||
new SimpleDateFormatDateService()
|
||||
.iso8601SecondsDateParse("2012-05-11T09:00:33+00:00"))
|
||||
.build(),
|
||||
|
||||
Machine
|
||||
.builder()
|
||||
.id("d73cb0b0-7d1f-44ef-8c40-e040eef0f726")
|
||||
.name("testJClouds2")
|
||||
.type(Type.SMARTMACHINE)
|
||||
.state(Machine.State.RUNNING)
|
||||
.dataset("sdc:sdc:smartosplus:3.1.0")
|
||||
.ips(
|
||||
ImmutableSet.<String> builder().add(
|
||||
"37.153.96.56").add(
|
||||
"10.224.0.57").build())
|
||||
.memorySizeMb(1024)
|
||||
.diskSizeGb(61440)
|
||||
.metadata(
|
||||
ImmutableMap
|
||||
.<String, String> of())
|
||||
.created(
|
||||
new SimpleDateFormatDateService()
|
||||
.iso8601SecondsDateParse("2012-05-09T13:39:43+00:00"))
|
||||
.updated(
|
||||
new SimpleDateFormatDateService()
|
||||
.iso8601SecondsDateParse("2012-05-09T13:43:45+00:00"))
|
||||
.build()
|
||||
|
||||
);
|
||||
}
|
||||
|
||||
protected Injector injector() {
|
||||
return Guice.createInjector(new SDCParserModule(), new GsonModule() {
|
||||
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(DateAdapter.class).to(Iso8601DateAdapter.class);
|
||||
super.configure();
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
}
|
|
@ -0,0 +1,78 @@
|
|||
/**
|
||||
* 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.joyent.sdc.v6_5.parse;
|
||||
|
||||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
|
||||
import org.jclouds.date.internal.SimpleDateFormatDateService;
|
||||
import org.jclouds.joyent.sdc.v6_5.config.SDCParserModule;
|
||||
import org.jclouds.joyent.sdc.v6_5.domain.Machine;
|
||||
import org.jclouds.joyent.sdc.v6_5.domain.Type;
|
||||
import org.jclouds.json.BaseItemParserTest;
|
||||
import org.jclouds.json.config.GsonModule;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
|
||||
/**
|
||||
* @author Gerald Pereira
|
||||
*/
|
||||
@Test(groups = "unit", testName = "ParseMachineTest")
|
||||
public class ParseMachineTest extends BaseItemParserTest<Machine> {
|
||||
|
||||
@Override
|
||||
public String resource() {
|
||||
return "/machine.json";
|
||||
}
|
||||
|
||||
@Override
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
public Machine expected() {
|
||||
return Machine
|
||||
.builder()
|
||||
.id("94eba336-ecb7-49f5-8a27-52f5e4dd57a1")
|
||||
.name("testJClouds")
|
||||
.type(Type.VIRTUALMACHINE)
|
||||
.state(Machine.State.STOPPED)
|
||||
.dataset("sdc:sdc:centos-5.7:1.2.1")
|
||||
.ips(ImmutableSet. <String>builder().add("37.153.96.62").add("10.224.0.63").build())
|
||||
.memorySizeMb(1024)
|
||||
.diskSizeGb(61440)
|
||||
.metadata(ImmutableMap. <String,String>builder().put("root_authorized_keys","ssh-rsa XXXXXX== test@xxxx.ovh.net\n").build())
|
||||
.created(new SimpleDateFormatDateService().iso8601SecondsDateParse("2012-05-09T13:32:46+00:00"))
|
||||
.updated(new SimpleDateFormatDateService().iso8601SecondsDateParse("2012-05-11T08:44:53+00:00"))
|
||||
.build();
|
||||
}
|
||||
|
||||
protected Injector injector() {
|
||||
return Guice.createInjector(new SDCParserModule(), new GsonModule() {
|
||||
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(DateAdapter.class).to(Iso8601DateAdapter.class);
|
||||
super.configure();
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
}
|
|
@ -0,0 +1,84 @@
|
|||
/**
|
||||
* 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.joyent.sdc.v6_5.parse;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
|
||||
import org.jclouds.joyent.sdc.v6_5.config.SDCParserModule;
|
||||
import org.jclouds.joyent.sdc.v6_5.domain.Package;
|
||||
import org.jclouds.json.BaseSetParserTest;
|
||||
import org.jclouds.json.config.GsonModule;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
|
||||
/**
|
||||
* @author Gerald Pereira
|
||||
*/
|
||||
@Test(groups = "unit", testName = "ParsePackageListTest")
|
||||
public class ParsePackageListTest extends BaseSetParserTest<Package> {
|
||||
|
||||
@Override
|
||||
public String resource() {
|
||||
return "/package_list.json";
|
||||
}
|
||||
|
||||
@Override
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
public Set<Package> expected() {
|
||||
return ImmutableSet
|
||||
.of(
|
||||
org.jclouds.joyent.sdc.v6_5.domain.Package
|
||||
.builder()
|
||||
.name("Small 1GB")
|
||||
.memorySizeMb(1024)
|
||||
.diskSizeGb(30720)
|
||||
.swapSizeMb(2048)
|
||||
.isDefault(true)
|
||||
.build(),
|
||||
|
||||
org.jclouds.joyent.sdc.v6_5.domain.Package
|
||||
.builder()
|
||||
.name("Medium 2GB")
|
||||
.memorySizeMb(2048)
|
||||
.diskSizeGb(61440)
|
||||
.swapSizeMb(4096)
|
||||
.isDefault(false)
|
||||
.build()
|
||||
|
||||
);
|
||||
}
|
||||
|
||||
protected Injector injector() {
|
||||
return Guice.createInjector(new SDCParserModule(), new GsonModule() {
|
||||
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(DateAdapter.class).to(Iso8601DateAdapter.class);
|
||||
super.configure();
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
}
|
|
@ -0,0 +1,68 @@
|
|||
/**
|
||||
* 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.joyent.sdc.v6_5.parse;
|
||||
|
||||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
|
||||
import org.jclouds.joyent.sdc.v6_5.config.SDCParserModule;
|
||||
import org.jclouds.json.BaseItemParserTest;
|
||||
import org.jclouds.json.config.GsonModule;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
|
||||
/**
|
||||
* @author Gerald Pereira
|
||||
*/
|
||||
@Test(groups = "unit", testName = "ParsePackageTest")
|
||||
public class ParsePackageTest extends BaseItemParserTest<org.jclouds.joyent.sdc.v6_5.domain.Package> {
|
||||
|
||||
@Override
|
||||
public String resource() {
|
||||
return "/package.json";
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
public org.jclouds.joyent.sdc.v6_5.domain.Package expected() {
|
||||
return org.jclouds.joyent.sdc.v6_5.domain.Package
|
||||
.builder()
|
||||
.name("Small 1GB")
|
||||
.memorySizeMb(1024)
|
||||
.diskSizeGb(30720)
|
||||
.swapSizeMb(2048)
|
||||
.isDefault(true)
|
||||
.build();
|
||||
}
|
||||
|
||||
protected Injector injector() {
|
||||
return Guice.createInjector(new SDCParserModule(), new GsonModule() {
|
||||
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(DateAdapter.class).to(Iso8601DateAdapter.class);
|
||||
super.configure();
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
{"id":"e4cd7b9e-4330-11e1-81cf-3bb50a972bda","urn":"sdc:sdc:centos-6:1.0.1","name":"centos-6","os":"linux","type":"virtualmachine","description":"Centos 6 VM 1.0.1","default":false,"requirements":{},"version":"1.0.1","created":"2012-02-13T06:30:33+00:00"}
|
|
@ -0,0 +1 @@
|
|||
[{"id":"e4cd7b9e-4330-11e1-81cf-3bb50a972bda","urn":"sdc:sdc:centos-6:1.0.1","name":"centos-6","os":"linux","type":"virtualmachine","description":"Centos 6 VM 1.0.1","default":false,"requirements":{},"version":"1.0.1","created":"2012-02-13T06:30:33+00:00"},{"id":"e62c30b4-cdda-11e0-9dd4-af4d032032e3","urn":"sdc:sdc:nodejs:1.2.3","name":"nodejs","os":"smartos","type":"smartmachine","description":"Node.js git-deploy PaaS dataset","default":false,"requirements":{},"version":"1.2.3","created":"2011-09-15T08:15:29+00:00"}]
|
|
@ -0,0 +1 @@
|
|||
{"id":"94eba336-ecb7-49f5-8a27-52f5e4dd57a1","name":"testJClouds","type":"virtualmachine","state":"stopped","dataset":"sdc:sdc:centos-5.7:1.2.1","ips":["37.153.96.62","10.224.0.63"],"memory":1024,"disk":61440,"metadata":{"root_authorized_keys":"ssh-rsa XXXXXX== test@xxxx.ovh.net"},"created":"2012-05-09T13:32:46+00:00","updated":"2012-05-11T08:44:53+00:00"}
|
|
@ -0,0 +1 @@
|
|||
[{"id":"d73cb0b0-7d1f-44ef-8c40-e040eef0f726","name":"testJClouds2","type":"smartmachine","state":"running","dataset":"sdc:sdc:smartosplus:3.1.0","ips":["37.153.96.56","10.224.0.57"],"memory":1024,"disk":61440,"metadata":{},"created":"2012-05-09T13:39:43+00:00","updated":"2012-05-09T13:43:45+00:00"},{"id":"94eba336-ecb7-49f5-8a27-52f5e4dd57a1","name":"testJClouds","type":"virtualmachine","state":"running","dataset":"sdc:sdc:centos-5.7:1.2.1","ips":["37.153.96.62","10.224.0.63"],"memory":1024,"disk":61440,"metadata":{"root_authorized_keys":"ssh-rsa XXXXXX== test@xxxx.ovh.net\n"},"created":"2012-05-09T13:32:46+00:00","updated":"2012-05-11T09:00:33+00:00"}]
|
|
@ -0,0 +1 @@
|
|||
{"name":"Small 1GB","memory":1024,"disk":30720,"vcpus":1,"swap":2048,"default":true}
|
|
@ -0,0 +1 @@
|
|||
[{"name":"Small 1GB","memory":1024,"disk":30720,"vcpus":1,"swap":2048,"default":true},{"name":"Medium 2GB","memory":2048,"disk":61440,"vcpus":1,"swap":4096,"default":false}]
|
Loading…
Reference in New Issue