You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jclouds.apache.org by na...@apache.org on 2013/09/19 00:09:31 UTC
[4/8] JCLOUDS-236: Add CloudSigma v2 API and Providers
http://git-wip-us.apache.org/repos/asf/incubator-jclouds-labs/blob/14619a17/cloudsigma2/src/main/java/org/jclouds/cloudsigma2/domain/Subscription.java
----------------------------------------------------------------------
diff --git a/cloudsigma2/src/main/java/org/jclouds/cloudsigma2/domain/Subscription.java b/cloudsigma2/src/main/java/org/jclouds/cloudsigma2/domain/Subscription.java
new file mode 100644
index 0000000..c63898a
--- /dev/null
+++ b/cloudsigma2/src/main/java/org/jclouds/cloudsigma2/domain/Subscription.java
@@ -0,0 +1,464 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF 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.cloudsigma2.domain;
+
+import com.google.common.collect.ImmutableList;
+
+import javax.inject.Named;
+import java.beans.ConstructorProperties;
+import java.net.URI;
+import java.util.Date;
+import java.util.List;
+
+/**
+ * @author Vladimir Shevchenko
+ */
+public class Subscription {
+
+ public static class Builder{
+ private String amount;
+ private boolean isAutoRenewEnabled;
+ private List<URI> descendants;
+ private double discountAmount;
+ private double discountPercent;
+ private Date endTime;
+ private String id;
+ private Date lastNotification;
+ private String period;
+ private double price;
+ private String remaining;
+ private SubscriptionResource resource;
+ private URI resourceUri;
+ private Date startTime;
+ private String status;
+ private String subscribedObject;
+ private String uuid;
+
+ /**
+ * @param amount
+ * @return Subscription Binder
+ */
+ public Builder amount(String amount){
+ this.amount = amount;
+ return this;
+ }
+
+ /**
+ * @param isAutoRenewEnabled States if the subscription will auto renew on expire
+ * @return Subscription Binder
+ */
+ public Builder isAutoRenewEnabled(boolean isAutoRenewEnabled){
+ this.isAutoRenewEnabled = isAutoRenewEnabled;
+ return this;
+ }
+
+ /**
+ * @param descendants Subscriptions that have been extended from the current one
+ * @return Subscription Binder
+ */
+ public Builder descendants(List<URI> descendants){
+ this.descendants = ImmutableList.copyOf(descendants);
+ return this;
+ }
+
+ /**
+ * @param discountAmount Amount of discount
+ * @return Subscription Binder
+ */
+ public Builder discountAmount(double discountAmount){
+ this.discountAmount = discountAmount;
+ return this;
+ }
+
+ /**
+ * @param discountPercent Percent of discount
+ * @return Subscription Binder
+ */
+ public Builder discountPercent(double discountPercent){
+ this.discountPercent = discountPercent;
+ return this;
+ }
+
+ /**
+ * @param endTime End time of subscription
+ * @return Subscription Binder
+ */
+ public Builder endTime(Date endTime){
+ this.endTime = endTime;
+ return this;
+ }
+
+ /**
+ * @param id unique id
+ * @return Subscription Binder
+ */
+ public Builder id(String id){
+ this.id = id;
+ return this;
+ }
+
+ /**
+ * @param lastNotification A date & time of last notification
+ * @return Subscription Binder
+ */
+ public Builder lastNotification(Date lastNotification){
+ this.lastNotification = lastNotification;
+ return this;
+ }
+
+ /**
+ * @param period Duration of the subscription
+ * @return Subscription Binder
+ */
+ public Builder period(String period){
+ this.period = period;
+ return this;
+ }
+
+ /**
+ * @param price Subscription price
+ * @return Subscription Binder
+ */
+ public Builder price(double price){
+ this.price = price;
+ return this;
+ }
+
+ /**
+ * @param remaining Amount remaining
+ * @return Subscription Binder
+ */
+ public Builder remaining(String remaining){
+ this.remaining = remaining;
+ return this;
+ }
+
+ /**
+ * @param resource Name of resource associated with the subscription
+ * @return Subscription Binder
+ */
+ public Builder resource(SubscriptionResource resource){
+ this.resource = resource;
+ return this;
+ }
+
+ /**
+ * @param resourceUri Resource URI
+ * @return Subscription Binder
+ */
+ public Builder resourceUri(URI resourceUri){
+ this.resourceUri = resourceUri;
+ return this;
+ }
+
+ /**
+ * @param startTime Start time of subscription
+ * @return Subscription Binder
+ */
+ public Builder startTime(Date startTime){
+ this.startTime = startTime;
+ return this;
+ }
+
+ /**
+ * @param status Status of the subscription
+ * @return Subscription Binder
+ */
+ public Builder status(String status){
+ this.status = status;
+ return this;
+ }
+
+ /**
+ * @param subscribedObject Subscribed object - the target of this subscription, if applicable
+ * @return Subscription Binder
+ */
+ public Builder subscribedObject(String subscribedObject){
+ this.subscribedObject = subscribedObject;
+ return this;
+ }
+
+ /**
+ * @param uuid Subscription uuid
+ * @return Subscription Binder
+ */
+ public Builder uuid(String uuid){
+ this.uuid = uuid;
+ return this;
+ }
+
+ public Subscription build(){
+ return new Subscription(amount, isAutoRenewEnabled, descendants, discountAmount, discountPercent, endTime
+ , id, lastNotification, period, price, remaining, resource, resourceUri, startTime, status
+ , subscribedObject, uuid);
+ }
+ }
+
+ private final String amount;
+ @Named("auto_renew")
+ private final boolean isAutoRenewEnabled;
+ private final List<URI> descendants;
+ @Named("discount_amount")
+ private final double discountAmount;
+ @Named("discount_percent")
+ private final double discountPercent;
+ @Named("end_time")
+ private final Date endTime;
+ private final String id;
+ @Named("last_notification")
+ private final Date lastNotification;
+ private final String period;
+ private final double price;
+ private final String remaining;
+ private final SubscriptionResource resource;
+ @Named("resource_uri")
+ private final URI resourceUri;
+ @Named("start_time")
+ private final Date startTime;
+ private final String status;
+ @Named("subscribed_object")
+ private final String subscribedObject;
+ private final String uuid;
+
+ @ConstructorProperties({
+ "amount", "auto_renew", "descendants", "discount_amount"
+ , "discount_percent", "end_time", "id", "last_notification", "period", "price"
+ , "remaining", "resource", "resource_uri", "start_time", "status"
+ , "subscribed_object", "uuid"
+ })
+ public Subscription(String amount, boolean autoRenewEnabled, List<URI> descendants, double discountAmount
+ , double discountPercent, Date endTime, String id, Date lastNotification, String period, double price
+ , String remaining, SubscriptionResource resource, URI resourceUri, Date startTime, String status
+ , String subscribedObject, String uuid) {
+ this.amount = amount;
+ isAutoRenewEnabled = autoRenewEnabled;
+ this.descendants = descendants;
+ this.discountAmount = discountAmount;
+ this.discountPercent = discountPercent;
+ this.endTime = endTime;
+ this.id = id;
+ this.lastNotification = lastNotification;
+ this.period = period;
+ this.price = price;
+ this.remaining = remaining;
+ this.resource = resource;
+ this.resourceUri = resourceUri;
+ this.startTime = startTime;
+ this.status = status;
+ this.subscribedObject = subscribedObject;
+ this.uuid = uuid;
+ }
+
+ /**
+ * @return Subscription amount
+ */
+ public String getAmount() {
+ return amount;
+ }
+
+ /**
+ * @return States if the subscription will auto renew on expire
+ */
+ public boolean isAutoRenewEnabled() {
+ return isAutoRenewEnabled;
+ }
+
+ /**
+ * @return Subscriptions that have been extended from the current one
+ */
+ public List<URI> getDescendants() {
+ return descendants;
+ }
+
+ /**
+ * @return Amount of discount
+ */
+ public double getDiscountAmount() {
+ return discountAmount;
+ }
+
+ /**
+ * @return Percent of discount
+ */
+ public double getDiscountPercent() {
+ return discountPercent;
+ }
+
+ /**
+ * @return End time of subscription
+ */
+ public Date getEndTime() {
+ return endTime;
+ }
+
+ /**
+ * @return "Unicode id
+ */
+ public String getId() {
+ return id;
+ }
+
+ /**
+ * @return A date & time of last notification
+ */
+ public Date getLastNotification() {
+ return lastNotification;
+ }
+
+ /**
+ * @return Duration of the subscription
+ */
+ public String getPeriod() {
+ return period;
+ }
+
+ /**
+ * @return Subscription price
+ */
+ public double getPrice() {
+ return price;
+ }
+
+ /**
+ * @return Amount remaining
+ */
+ public String getRemaining() {
+ return remaining;
+ }
+
+ /**
+ * @return Name of resource associated with the subscription
+ */
+ public SubscriptionResource getResource() {
+ return resource;
+ }
+
+ /**
+ * @return resource uri
+ */
+ public URI getResourceUri() {
+ return resourceUri;
+ }
+
+ /**
+ * @return Start time of subscription
+ */
+ public Date getStartTime() {
+ return startTime;
+ }
+
+ /**
+ * @return "Status of the subscription
+ */
+ public String getStatus() {
+ return status;
+ }
+
+ /**
+ * @return Subscribed object - the target of this subscription, if applicable
+ */
+ public String getSubscribedObject() {
+ return subscribedObject;
+ }
+
+ /**
+ * @return subscription uuid
+ */
+ public String getUuid() {
+ return uuid;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (!(o instanceof Subscription)) return false;
+
+ Subscription that = (Subscription) o;
+
+ if (Double.compare(that.discountAmount, discountAmount) != 0) return false;
+ if (Double.compare(that.discountPercent, discountPercent) != 0) return false;
+ if (isAutoRenewEnabled != that.isAutoRenewEnabled) return false;
+ if (Double.compare(that.price, price) != 0) return false;
+ if (amount != null ? !amount.equals(that.amount) : that.amount != null) return false;
+ if (descendants != null ? !descendants.equals(that.descendants) : that.descendants != null) return false;
+ if (endTime != null ? !endTime.equals(that.endTime) : that.endTime != null) return false;
+ if (id != null ? !id.equals(that.id) : that.id != null) return false;
+ if (lastNotification != null ? !lastNotification.equals(that.lastNotification) : that.lastNotification != null)
+ return false;
+ if (period != null ? !period.equals(that.period) : that.period != null) return false;
+ if (remaining != null ? !remaining.equals(that.remaining) : that.remaining != null) return false;
+ if (resource != null ? !resource.equals(that.resource) : that.resource != null) return false;
+ if (resourceUri != null ? !resourceUri.equals(that.resourceUri) : that.resourceUri != null) return false;
+ if (startTime != null ? !startTime.equals(that.startTime) : that.startTime != null) return false;
+ if (status != null ? !status.equals(that.status) : that.status != null) return false;
+ if (subscribedObject != null ? !subscribedObject.equals(that.subscribedObject) : that.subscribedObject != null)
+ return false;
+ if (uuid != null ? !uuid.equals(that.uuid) : that.uuid != null) return false;
+
+ return true;
+ }
+
+ @Override
+ public int hashCode() {
+ int result;
+ long temp;
+ result = amount != null ? amount.hashCode() : 0;
+ result = 31 * result + (isAutoRenewEnabled ? 1 : 0);
+ result = 31 * result + (descendants != null ? descendants.hashCode() : 0);
+ temp = Double.doubleToLongBits(discountAmount);
+ result = 31 * result + (int) (temp ^ (temp >>> 32));
+ temp = Double.doubleToLongBits(discountPercent);
+ result = 31 * result + (int) (temp ^ (temp >>> 32));
+ result = 31 * result + (endTime != null ? endTime.hashCode() : 0);
+ result = 31 * result + (id != null ? id.hashCode() : 0);
+ result = 31 * result + (lastNotification != null ? lastNotification.hashCode() : 0);
+ result = 31 * result + (period != null ? period.hashCode() : 0);
+ temp = Double.doubleToLongBits(price);
+ result = 31 * result + (int) (temp ^ (temp >>> 32));
+ result = 31 * result + (remaining != null ? remaining.hashCode() : 0);
+ result = 31 * result + (resource != null ? resource.hashCode() : 0);
+ result = 31 * result + (resourceUri != null ? resourceUri.hashCode() : 0);
+ result = 31 * result + (startTime != null ? startTime.hashCode() : 0);
+ result = 31 * result + (status != null ? status.hashCode() : 0);
+ result = 31 * result + (subscribedObject != null ? subscribedObject.hashCode() : 0);
+ result = 31 * result + (uuid != null ? uuid.hashCode() : 0);
+ return result;
+ }
+
+ @Override
+ public String toString() {
+ return "[" +
+ "amount='" + amount + '\'' +
+ ", isAutoRenewEnabled=" + isAutoRenewEnabled +
+ ", descendants=" + descendants +
+ ", discountAmount=" + discountAmount +
+ ", discountPercent=" + discountPercent +
+ ", endTime=" + endTime +
+ ", id='" + id + '\'' +
+ ", lastNotification=" + lastNotification +
+ ", period='" + period + '\'' +
+ ", price=" + price +
+ ", remaining='" + remaining + '\'' +
+ ", resource='" + resource + '\'' +
+ ", resourceUri=" + resourceUri +
+ ", startTime=" + startTime +
+ ", status='" + status + '\'' +
+ ", subscribedObject='" + subscribedObject + '\'' +
+ ", uuid='" + uuid + '\'' +
+ "]";
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-jclouds-labs/blob/14619a17/cloudsigma2/src/main/java/org/jclouds/cloudsigma2/domain/SubscriptionResource.java
----------------------------------------------------------------------
diff --git a/cloudsigma2/src/main/java/org/jclouds/cloudsigma2/domain/SubscriptionResource.java b/cloudsigma2/src/main/java/org/jclouds/cloudsigma2/domain/SubscriptionResource.java
new file mode 100644
index 0000000..9713bc1
--- /dev/null
+++ b/cloudsigma2/src/main/java/org/jclouds/cloudsigma2/domain/SubscriptionResource.java
@@ -0,0 +1,42 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF 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.cloudsigma2.domain;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+/**
+ * @author Vladimir Shevchenko
+ */
+public enum SubscriptionResource {
+ DSSD, CPU, MEM, TX, IP, VLAN;
+ public String value() {
+ return name().toLowerCase();
+ }
+
+ @Override
+ public String toString() {
+ return value();
+ }
+
+ public static SubscriptionResource fromValue(String status) {
+ try {
+ return valueOf(checkNotNull(status, "status").toUpperCase());
+ } catch (IllegalArgumentException e) {
+ return null;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-jclouds-labs/blob/14619a17/cloudsigma2/src/main/java/org/jclouds/cloudsigma2/domain/Tag.java
----------------------------------------------------------------------
diff --git a/cloudsigma2/src/main/java/org/jclouds/cloudsigma2/domain/Tag.java b/cloudsigma2/src/main/java/org/jclouds/cloudsigma2/domain/Tag.java
new file mode 100644
index 0000000..f6f8ef1
--- /dev/null
+++ b/cloudsigma2/src/main/java/org/jclouds/cloudsigma2/domain/Tag.java
@@ -0,0 +1,148 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF 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.cloudsigma2.domain;
+
+import com.google.common.collect.ImmutableList;
+
+import java.beans.ConstructorProperties;
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @author Vladimir Shevchenko
+ */
+public class Tag extends Item{
+
+ public static class Builder extends Item.Builder{
+ private Map<String, String> meta;
+ private Owner owner;
+ private List<TagResource> resources;
+
+ public Builder meta(Map<String, String> meta) {
+ this.meta = meta;
+ return this;
+ }
+
+ public Builder owner(Owner owner) {
+ this.owner = owner;
+ return this;
+ }
+
+ public Builder resources(List<TagResource> resources) {
+ this.resources = ImmutableList.copyOf(resources);
+ return this;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Builder uuid(String uuid) {
+ return Builder.class.cast(super.uuid(uuid));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Builder name(String name) {
+ return Builder.class.cast(super.name(name));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Builder resourceUri(URI resourceUri) {
+ return Builder.class.cast(super.resourceUri(resourceUri));
+ }
+
+ public Tag build(){
+ return new Tag(uuid, name, resourceUri, meta, owner, resources);
+ }
+ }
+
+ private final Map<String, String> meta;
+ private final Owner owner;
+ private final List<TagResource> resources;
+
+ @ConstructorProperties({
+ "uuid", "name", "resource_uri", "meta", "owner", "resources"
+ })
+ public Tag(String uuid, String name, URI resourceUri, Map<String, String> meta, Owner owner, List<TagResource> resources) {
+ super(uuid, name, resourceUri);
+ this.meta = meta;
+ this.owner = owner;
+ this.resources = resources == null ? new ArrayList<TagResource>() : resources;
+ }
+
+ /**
+ *
+ * @return tag meta data
+ */
+ public Map<String, String> getMeta() {
+ return meta;
+ }
+
+ /**
+ *
+ * @return tag owner
+ */
+ public Owner getOwner() {
+ return owner;
+ }
+
+ /**
+ *
+ * @return tag's resource list
+ */
+ public List<TagResource> getResources() {
+ return resources;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (!(o instanceof Tag)) return false;
+ if (!super.equals(o)) return false;
+
+ Tag tag = (Tag) o;
+
+ if (meta != null ? !meta.equals(tag.meta) : tag.meta != null) return false;
+ if (owner != null ? !owner.equals(tag.owner) : tag.owner != null) return false;
+ if (resources != null ? !resources.equals(tag.resources) : tag.resources != null) return false;
+
+ return true;
+ }
+
+ @Override
+ public int hashCode() {
+ int result = super.hashCode();
+ result = 31 * result + (meta != null ? meta.hashCode() : 0);
+ result = 31 * result + (owner != null ? owner.hashCode() : 0);
+ result = 31 * result + (resources != null ? resources.hashCode() : 0);
+ return result;
+ }
+
+ @Override
+ public String toString() {
+ return "[uuid=" + uuid + ", name=" + name + ", resourceUri=" + resourceUri
+ + ", meta=" + meta + ", owner=" + owner + ", resources=" + resources + "]";
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-jclouds-labs/blob/14619a17/cloudsigma2/src/main/java/org/jclouds/cloudsigma2/domain/TagResource.java
----------------------------------------------------------------------
diff --git a/cloudsigma2/src/main/java/org/jclouds/cloudsigma2/domain/TagResource.java b/cloudsigma2/src/main/java/org/jclouds/cloudsigma2/domain/TagResource.java
new file mode 100644
index 0000000..01f0821
--- /dev/null
+++ b/cloudsigma2/src/main/java/org/jclouds/cloudsigma2/domain/TagResource.java
@@ -0,0 +1,157 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF 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.cloudsigma2.domain;
+
+import javax.inject.Named;
+import java.beans.ConstructorProperties;
+import java.net.URI;
+
+/**
+ * @author Vladimir Shevchenko
+ */
+public class TagResource {
+
+ public static class Builder{
+ private Owner owner;
+ private URI resourceUri;
+ private String uuid;
+ private TagResourceType resourceType;
+
+ public Builder uuid(String uuid) {
+ this.uuid = uuid;
+ return this;
+ }
+
+ public Builder resourceUri(URI resourceUri) {
+ this.resourceUri = resourceUri;
+ return this;
+ }
+
+ public Builder owner(Owner owner) {
+ this.owner = owner;
+ return this;
+ }
+
+ public Builder resourceType(TagResourceType resourceType) {
+ this.resourceType = resourceType;
+ return this;
+ }
+
+ public TagResource build() {
+ return new TagResource(uuid, resourceType, owner, resourceUri);
+ }
+ }
+
+ private final Owner owner;
+ @Named("resource_uri")
+ private final URI resourceUri;
+ private final String uuid;
+ @Named("resource_type")
+ private final TagResourceType resourceType;
+
+ @ConstructorProperties({
+ "uuid", "resource_type", "owner", "resource_uri"
+ })
+ public TagResource(String uuid, TagResourceType resourceType, Owner owner, URI resourceUri) {
+ this.owner = owner;
+ this.resourceUri = resourceUri;
+ this.uuid = uuid;
+ this.resourceType = resourceType;
+ }
+
+ /**
+ *
+ * @return resource owner
+ */
+ public Owner getOwner() {
+ return owner;
+ }
+
+ /**
+ *
+ * @return resource type
+ */
+ public TagResourceType getResourceType() {
+ return resourceType;
+ }
+
+ /**
+ *
+ * @return resource uri
+ */
+ public URI getResourceUri() {
+ return resourceUri;
+ }
+
+ /**
+ *
+ * @return resource uuid
+ */
+ public String getUuid() {
+ return uuid;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ TagResource other = (TagResource) obj;
+ if (owner == null) {
+ if (other.owner != null)
+ return false;
+ } else if (!owner.equals(other.owner))
+ return false;
+ if (uuid == null) {
+ if (other.uuid != null)
+ return false;
+ } else if (!uuid.equals(other.uuid))
+ return false;
+ if (resourceUri == null) {
+ if (other.resourceUri != null)
+ return false;
+ } else if (!resourceUri.equals(other.resourceUri))
+ return false;
+ if (resourceType == null) {
+ if (other.resourceType != null)
+ return false;
+ } else if (!resourceType.equals(other.resourceType))
+ return false;
+
+ return true;
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((uuid == null) ? 0 : uuid.hashCode());
+ result = prime * result + ((owner == null) ? 0 : owner.hashCode());
+ result = prime * result + ((resourceUri == null) ? 0 : resourceUri.hashCode());
+ result = prime * result + ((resourceType == null) ? 0 : resourceType.hashCode());
+ return result;
+ }
+
+ @Override
+ public String toString() {
+ return "[uuid=" + uuid + ", owner=" + owner
+ + ", resourceUri=" + resourceUri + ", resourceType=" + resourceType + "]";
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-jclouds-labs/blob/14619a17/cloudsigma2/src/main/java/org/jclouds/cloudsigma2/domain/TagResourceType.java
----------------------------------------------------------------------
diff --git a/cloudsigma2/src/main/java/org/jclouds/cloudsigma2/domain/TagResourceType.java b/cloudsigma2/src/main/java/org/jclouds/cloudsigma2/domain/TagResourceType.java
new file mode 100644
index 0000000..57d1196
--- /dev/null
+++ b/cloudsigma2/src/main/java/org/jclouds/cloudsigma2/domain/TagResourceType.java
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF 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.cloudsigma2.domain;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+/**
+ * @author Vladimir Shevchenko
+ */
+public enum TagResourceType {
+ VLANS, DRIVES, SERVERS, IPS, UNRECOGNIZED;
+
+ public String value() {
+ return name().toLowerCase();
+ }
+
+ @Override
+ public String toString() {
+ return value();
+ }
+
+ public static TagResourceType fromValue(String type) {
+ try {
+ return valueOf(checkNotNull(type, "type").toUpperCase());
+ } catch (IllegalArgumentException e) {
+ return UNRECOGNIZED;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-jclouds-labs/blob/14619a17/cloudsigma2/src/main/java/org/jclouds/cloudsigma2/domain/Transaction.java
----------------------------------------------------------------------
diff --git a/cloudsigma2/src/main/java/org/jclouds/cloudsigma2/domain/Transaction.java b/cloudsigma2/src/main/java/org/jclouds/cloudsigma2/domain/Transaction.java
new file mode 100644
index 0000000..756646c
--- /dev/null
+++ b/cloudsigma2/src/main/java/org/jclouds/cloudsigma2/domain/Transaction.java
@@ -0,0 +1,193 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF 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.cloudsigma2.domain;
+
+import javax.inject.Named;
+import java.beans.ConstructorProperties;
+import java.util.Date;
+
+/**
+ * @author Vladimir Shevchenko
+ */
+public class Transaction {
+
+ public static class Builder{
+ private double amount;
+ private long billingCycle;
+ private double end;
+ private String id;
+ private double initial;
+ private String reason;
+ private Date time;
+
+ public Builder amount(double amount){
+ this.amount = amount;
+ return this;
+ }
+
+ public Builder billingCycle(long billingCycle){
+ this.billingCycle = billingCycle;
+ return this;
+ }
+
+ public Builder end(double end){
+ this.end = end;
+ return this;
+ }
+ public Builder id(String id){
+ this.id = id;
+ return this;
+ }
+ public Builder initial(double initial){
+ this.initial = initial;
+ return this;
+ }
+
+ public Builder reason(String reason){
+ this.reason = reason;
+ return this;
+ }
+
+ public Builder time(Date time){
+ this.time = time;
+ return this;
+ }
+
+ public Transaction build(){
+ return new Transaction(amount, billingCycle, end, id, initial, reason, time);
+ }
+ }
+
+ private final double amount;
+ @Named("billing_cycle")
+ private final long billingCycle;
+ private final double end;
+ private final String id;
+ private final double initial;
+ private final String reason;
+ private final Date time;
+
+ @ConstructorProperties({
+ "amount", "billing_cycle", "end", "id", "initial", "reason", "time"
+ })
+ public Transaction(double amount, long billingCycle, double end, String id, double initial, String reason, Date time) {
+ this.amount = amount;
+ this.billingCycle = billingCycle;
+ this.end = end;
+ this.id = id;
+ this.initial = initial;
+ this.reason = reason;
+ this.time = time;
+ }
+
+ /**
+ * @return Amount of the operation, positive for debits, negative for credits
+ */
+ public double getAmount() {
+ return amount;
+ }
+
+ /**
+ * @return Billing cycle that generated this charge
+ */
+ public long getBillingCycle() {
+ return billingCycle;
+ }
+
+ /**
+ * @return Amount of money after the operation
+ */
+ public double getEnd() {
+ return end;
+ }
+
+ /**
+ * @return Unique id
+ */
+ public String getId() {
+ return id;
+ }
+
+ /**
+ * @return Amount of money before the operation
+ */
+ public double getInitial() {
+ return initial;
+ }
+
+ /**
+ * @return Description of the operation
+ */
+ public String getReason() {
+ return reason;
+ }
+
+ /**
+ * @return date & time
+ */
+ public Date getTime() {
+ return time;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (!(o instanceof Transaction)) return false;
+
+ Transaction that = (Transaction) o;
+
+ if (Double.compare(that.amount, amount) != 0) return false;
+ if (billingCycle != that.billingCycle) return false;
+ if (Double.compare(that.end, end) != 0) return false;
+ if (Double.compare(that.initial, initial) != 0) return false;
+ if (id != null ? !id.equals(that.id) : that.id != null) return false;
+ if (reason != null ? !reason.equals(that.reason) : that.reason != null) return false;
+ if (time != null ? !time.equals(that.time) : that.time != null) return false;
+
+ return true;
+ }
+
+ @Override
+ public int hashCode() {
+ int result;
+ long temp;
+ temp = Double.doubleToLongBits(amount);
+ result = (int) (temp ^ (temp >>> 32));
+ result = 31 * result + (int) (billingCycle ^ (billingCycle >>> 32));
+ temp = Double.doubleToLongBits(end);
+ result = 31 * result + (int) (temp ^ (temp >>> 32));
+ result = 31 * result + (id != null ? id.hashCode() : 0);
+ temp = Double.doubleToLongBits(initial);
+ result = 31 * result + (int) (temp ^ (temp >>> 32));
+ result = 31 * result + (reason != null ? reason.hashCode() : 0);
+ result = 31 * result + (time != null ? time.hashCode() : 0);
+ return result;
+ }
+
+ @Override
+ public String toString() {
+ return "[" +
+ "amount=" + amount +
+ ", billingCycle=" + billingCycle +
+ ", end=" + end +
+ ", id='" + id + '\'' +
+ ", initial=" + initial +
+ ", reason='" + reason + '\'' +
+ ", time=" + time +
+ "]";
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-jclouds-labs/blob/14619a17/cloudsigma2/src/main/java/org/jclouds/cloudsigma2/domain/Usage.java
----------------------------------------------------------------------
diff --git a/cloudsigma2/src/main/java/org/jclouds/cloudsigma2/domain/Usage.java b/cloudsigma2/src/main/java/org/jclouds/cloudsigma2/domain/Usage.java
new file mode 100644
index 0000000..15d9b2b
--- /dev/null
+++ b/cloudsigma2/src/main/java/org/jclouds/cloudsigma2/domain/Usage.java
@@ -0,0 +1,107 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF 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.cloudsigma2.domain;
+
+import java.beans.ConstructorProperties;
+import java.math.BigInteger;
+
+/**
+ * @author Vladimir Shevchenko
+ */
+public class Usage {
+
+ public static class Builder{
+ private BigInteger burst;
+ private BigInteger subscribed;
+ private BigInteger using;
+
+ public Builder subscribed(BigInteger subscribed) {
+ this.subscribed = subscribed;
+ return this;
+ }
+
+ public Builder burst(BigInteger burst) {
+ this.burst = burst;
+ return this;
+ }
+
+ public Builder using(BigInteger using) {
+ this.using = using;
+ return this;
+ }
+
+ public Usage build(){
+ return new Usage(burst, subscribed, using);
+ }
+ }
+
+ private final BigInteger burst;
+ private final BigInteger subscribed;
+ private final BigInteger using;
+
+ @ConstructorProperties({
+ "burst", "subscribed", "using"
+ })
+ public Usage(BigInteger burst, BigInteger subscribed, BigInteger using) {
+ this.burst = burst;
+ this.subscribed = subscribed;
+ this.using = using;
+ }
+
+ public BigInteger getUsing() {
+ return using;
+ }
+
+ public BigInteger getBurst() {
+ return burst;
+ }
+
+ public BigInteger getSubscribed() {
+ return subscribed;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (!(o instanceof Usage)) return false;
+
+ Usage usage = (Usage) o;
+
+ if (burst != null ? !burst.equals(usage.burst) : usage.burst != null) return false;
+ if (subscribed != null ? !subscribed.equals(usage.subscribed) : usage.subscribed != null) return false;
+ if (using != null ? !using.equals(usage.using) : usage.using != null) return false;
+
+ return true;
+ }
+
+ @Override
+ public int hashCode() {
+ int result = burst != null ? burst.hashCode() : 0;
+ result = 31 * result + (subscribed != null ? subscribed.hashCode() : 0);
+ result = 31 * result + (using != null ? using.hashCode() : 0);
+ return result;
+ }
+
+ @Override
+ public String toString() {
+ return "[" +
+ "burst=" + burst +
+ ", subscribed=" + subscribed +
+ ", using=" + using +
+ "]";
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-jclouds-labs/blob/14619a17/cloudsigma2/src/main/java/org/jclouds/cloudsigma2/domain/VLANInfo.java
----------------------------------------------------------------------
diff --git a/cloudsigma2/src/main/java/org/jclouds/cloudsigma2/domain/VLANInfo.java b/cloudsigma2/src/main/java/org/jclouds/cloudsigma2/domain/VLANInfo.java
new file mode 100644
index 0000000..418937f
--- /dev/null
+++ b/cloudsigma2/src/main/java/org/jclouds/cloudsigma2/domain/VLANInfo.java
@@ -0,0 +1,248 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF 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.cloudsigma2.domain;
+
+import com.google.common.collect.ImmutableList;
+import org.jclouds.javax.annotation.Nullable;
+
+import javax.inject.Named;
+import java.beans.ConstructorProperties;
+import java.net.URI;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @author Vladimir Shevchenko
+ */
+public class VLANInfo {
+ public static class Builder {
+ private Map<String, String> meta;
+ private String uuid;
+ private Owner owner;
+ private URI resourceUri;
+ private List<Server> servers;
+ private Subscription subscription;
+ private List<Tag> tags;
+
+ /**
+ * @param uuid VLAN UUID
+ * @return VLANInfo Builder
+ */
+ public Builder uuid(String uuid) {
+ this.uuid = uuid;
+ return this;
+ }
+
+ /**
+ * @param owner VLAN owner
+ * @return VLANInfo Builder
+ */
+ public Builder owner(Owner owner) {
+ this.owner = owner;
+ return this;
+ }
+
+ /**
+ * @param meta User defined meta information
+ * @return VLANInfo Builder
+ */
+ public Builder meta(Map<String, String> meta) {
+ this.meta = meta;
+ return this;
+ }
+
+ /**
+ * @param resourceUri Resource URI
+ * @return VLANInfo Builder
+ */
+ public Builder resourceUri(URI resourceUri) {
+ this.resourceUri = resourceUri;
+ return this;
+ }
+
+ /**
+ * @param servers Servers in this VLAN
+ * @return VLANInfo Builder
+ */
+ public Builder servers(List<Server> servers) {
+ this.servers = ImmutableList.copyOf(servers);
+ return this;
+ }
+
+ /**
+ * @param subscription Subscription related to this VLAN
+ * @return VLANInfo Builder
+ */
+ public Builder subscription(Subscription subscription) {
+ this.subscription = subscription;
+ return this;
+ }
+
+ /**
+ * @param tags Tags added to this VLAN
+ * @return VLANInfo Builder
+ */
+ public Builder tags(List<Tag> tags) {
+ this.tags = ImmutableList.copyOf(tags);
+ return this;
+ }
+
+ public VLANInfo build() {
+ return new VLANInfo(meta, uuid, owner, resourceUri, servers, subscription, tags);
+ }
+ }
+
+ private final Map<String, String> meta;
+ private final String uuid;
+ private final Owner owner;
+ @Named("resource_uri")
+ private final URI resourceUri;
+ private final List<Server> servers;
+ private final Subscription subscription;
+ private final List<Tag> tags;
+
+ @ConstructorProperties({
+ "meta", "uuid", "owner", "resource_uri", "servers", "subscription", "tags"
+ })
+ public VLANInfo(Map<String, String> meta, String uuid, Owner owner, URI resourceUri, List<Server> servers
+ , Subscription subscription, List<Tag> tags) {
+ this.meta = meta;
+ this.uuid = uuid;
+ this.owner = owner;
+ this.resourceUri = resourceUri;
+ this.servers = servers;
+ this.subscription = subscription;
+ this.tags = tags;
+ }
+
+ /**
+ * @return VLAN UUID
+ */
+ @Nullable
+ public String getUuid() {
+ return uuid;
+ }
+
+ /**
+ * @return VLAN owner
+ */
+ public Owner getOwner() {
+ return owner;
+ }
+
+ /**
+ * @return User defined meta information
+ */
+ public Map<String, String> getMeta() {
+ return meta;
+ }
+
+ /**
+ * @return Resource URI
+ */
+ public URI getResourceUri() {
+ return resourceUri;
+ }
+
+ /**
+ * @return Servers in this VLAN
+ */
+ public List<Server> getServers() {
+ return servers;
+ }
+
+ /**
+ * @return Subscription related to this VLAN
+ */
+ public Subscription getSubscription() {
+ return subscription;
+ }
+
+ /**
+ * @return Tags added to this VLAN
+ */
+ public List<Tag> getTags() {
+ return tags;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (!(o instanceof VLANInfo)) return false;
+
+ VLANInfo vlanInfo = (VLANInfo) o;
+
+ if (meta != null ? !meta.equals(vlanInfo.meta) : vlanInfo.meta != null) return false;
+ if (owner != null ? !owner.equals(vlanInfo.owner) : vlanInfo.owner != null) return false;
+ if (resourceUri != null ? !resourceUri.equals(vlanInfo.resourceUri) : vlanInfo.resourceUri != null)
+ return false;
+ if (servers != null ? !servers.equals(vlanInfo.servers) : vlanInfo.servers != null) return false;
+ if (subscription != null ? !subscription.equals(vlanInfo.subscription) : vlanInfo.subscription != null)
+ return false;
+ if (tags != null ? !tags.equals(vlanInfo.tags) : vlanInfo.tags != null) return false;
+ if (uuid != null ? !uuid.equals(vlanInfo.uuid) : vlanInfo.uuid != null) return false;
+
+ return true;
+ }
+
+ @Override
+ public int hashCode() {
+ int result = meta != null ? meta.hashCode() : 0;
+ result = 31 * result + (uuid != null ? uuid.hashCode() : 0);
+ result = 31 * result + (owner != null ? owner.hashCode() : 0);
+ result = 31 * result + (resourceUri != null ? resourceUri.hashCode() : 0);
+ result = 31 * result + (servers != null ? servers.hashCode() : 0);
+ result = 31 * result + (subscription != null ? subscription.hashCode() : 0);
+ result = 31 * result + (tags != null ? tags.hashCode() : 0);
+ return result;
+ }
+
+ @Override
+ public String toString() {
+ return "[" +
+ "meta=" + meta +
+ ", uuid='" + uuid + '\'' +
+ ", owner=" + owner +
+ ", resourceUri=" + resourceUri +
+ ", servers=" + servers +
+ ", subscription=" + subscription +
+ ", tags=" + tags +
+ "]";
+ }
+
+ /**
+ * Creates VLAN NIC
+ *
+ * @param firewallPolicy
+ * @return server's NIC
+ */
+ public NIC toNIC(FirewallPolicy firewallPolicy){
+ return new NIC.Builder()
+ .vlan(new Builder().uuid(this.uuid).build())
+ .firewallPolicy(firewallPolicy)
+ .build();
+ }
+
+ /**
+ * Creates VLAN NIC
+ *
+ * @return server's NIC
+ */
+ public NIC toNIC(){
+ return toNIC(null);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-jclouds-labs/blob/14619a17/cloudsigma2/src/main/java/org/jclouds/cloudsigma2/functions/CreateSubscriptionRequestToJson.java
----------------------------------------------------------------------
diff --git a/cloudsigma2/src/main/java/org/jclouds/cloudsigma2/functions/CreateSubscriptionRequestToJson.java b/cloudsigma2/src/main/java/org/jclouds/cloudsigma2/functions/CreateSubscriptionRequestToJson.java
new file mode 100644
index 0000000..c26a8a7
--- /dev/null
+++ b/cloudsigma2/src/main/java/org/jclouds/cloudsigma2/functions/CreateSubscriptionRequestToJson.java
@@ -0,0 +1,53 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF 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.cloudsigma2.functions;
+
+import com.google.common.base.Function;
+import com.google.gson.JsonObject;
+import org.jclouds.cloudsigma2.domain.CreateSubscriptionRequest;
+import org.jclouds.javax.annotation.Nullable;
+
+import javax.inject.Singleton;
+
+/**
+ * @author Vladimir Shevchenko
+ */
+@Singleton
+public class CreateSubscriptionRequestToJson implements Function<CreateSubscriptionRequest, JsonObject> {
+ @Override
+ public JsonObject apply(@Nullable CreateSubscriptionRequest input) {
+ if(input == null){
+ return null;
+ }
+
+ JsonObject createSubscriptionObject = new JsonObject();
+
+ if(input.getAmount() != null){
+ createSubscriptionObject.addProperty("amount", input.getAmount());
+ }
+
+ if(input.getPeriod() != null){
+ createSubscriptionObject.addProperty("period", input.getPeriod());
+ }
+
+ if(input.getResource() != null){
+ createSubscriptionObject.addProperty("resource", input.getResource().value());
+ }
+
+ return createSubscriptionObject;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-jclouds-labs/blob/14619a17/cloudsigma2/src/main/java/org/jclouds/cloudsigma2/functions/DriveToJson.java
----------------------------------------------------------------------
diff --git a/cloudsigma2/src/main/java/org/jclouds/cloudsigma2/functions/DriveToJson.java b/cloudsigma2/src/main/java/org/jclouds/cloudsigma2/functions/DriveToJson.java
new file mode 100644
index 0000000..710d606
--- /dev/null
+++ b/cloudsigma2/src/main/java/org/jclouds/cloudsigma2/functions/DriveToJson.java
@@ -0,0 +1,63 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF 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.cloudsigma2.functions;
+
+import com.google.common.base.Function;
+import com.google.gson.Gson;
+import com.google.gson.JsonObject;
+import com.google.gson.JsonParser;
+import org.jclouds.cloudsigma2.domain.DriveInfo;
+
+import javax.inject.Singleton;
+
+/**
+ * @author Vladimir Shevchenko
+ */
+@Singleton
+public class DriveToJson implements Function<DriveInfo, JsonObject> {
+ @Override
+ public JsonObject apply(DriveInfo input) {
+ JsonObject driveObject = new JsonObject();
+
+ if(input.getName() != null){
+ driveObject.addProperty("name", input.getName());
+ }
+
+ if(input.getSize() != null){
+ driveObject.addProperty("size", "" + input.getSize().toString());
+ }
+
+ if(input.getMedia() != null){
+ driveObject.addProperty("media", input.getMedia().toString());
+ }
+
+ if(input.getAffinities() != null){
+ driveObject.add("affinities", new JsonParser().parse(new Gson().toJson(input.getAffinities())));
+ }
+
+ if(input.getMeta() != null){
+ driveObject.add("meta", new JsonParser().parse(new Gson().toJson(input.getMeta())));
+ }
+
+ if(input.getTags() != null){
+ driveObject.add("tags", new JsonParser().parse(new Gson().toJson(input.getTags())));
+ }
+
+ driveObject.addProperty("allow_multimount", input.isAllowMultimount());
+ return driveObject;
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-jclouds-labs/blob/14619a17/cloudsigma2/src/main/java/org/jclouds/cloudsigma2/functions/FirewallPolicyToJson.java
----------------------------------------------------------------------
diff --git a/cloudsigma2/src/main/java/org/jclouds/cloudsigma2/functions/FirewallPolicyToJson.java b/cloudsigma2/src/main/java/org/jclouds/cloudsigma2/functions/FirewallPolicyToJson.java
new file mode 100644
index 0000000..41b00af
--- /dev/null
+++ b/cloudsigma2/src/main/java/org/jclouds/cloudsigma2/functions/FirewallPolicyToJson.java
@@ -0,0 +1,92 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF 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.cloudsigma2.functions;
+
+import com.google.common.base.Function;
+import com.google.gson.Gson;
+import com.google.gson.JsonArray;
+import com.google.gson.JsonObject;
+import com.google.gson.JsonParser;
+import org.jclouds.cloudsigma2.domain.FirewallPolicy;
+import org.jclouds.cloudsigma2.domain.FirewallRule;
+import org.jclouds.javax.annotation.Nullable;
+
+import javax.inject.Singleton;
+
+/**
+ * @author Vladimir Shevchenko
+ */
+@Singleton
+public class FirewallPolicyToJson implements Function<FirewallPolicy, JsonObject> {
+ @Override
+ public JsonObject apply(@Nullable FirewallPolicy input) {
+ JsonObject firewallObject = new JsonObject();
+
+ if(input.getName() != null){
+ firewallObject.addProperty("name", input.getName());
+ }
+
+ if(input.getMeta() != null){
+ firewallObject.add("meta", new JsonParser().parse(new Gson().toJson(input.getMeta())));
+ }
+
+ if(input.getRules() != null){
+ JsonArray rulesArray = new JsonArray();
+
+ for(FirewallRule rule : input.getRules()){
+ JsonObject ruleObject = new JsonObject();
+
+ if(rule.getAction() != null){
+ ruleObject.addProperty("action", rule.getAction().value());
+ }
+
+ if(rule.getComment() != null){
+ ruleObject.addProperty("comment", rule.getComment());
+ }
+
+ if(rule.getDirection() != null){
+ ruleObject.addProperty("direction", rule.getDirection().value());
+ }
+
+ if(rule.getDestinationIp() != null){
+ ruleObject.addProperty("dst_ip", rule.getDestinationIp());
+ }
+
+ if(rule.getDestinationPort() != null){
+ ruleObject.addProperty("dst_port", rule.getDestinationPort());
+ }
+
+ if(rule.getIpProtocol() != null){
+ ruleObject.addProperty("ip_proto", rule.getIpProtocol().toString());
+ }
+
+ if(rule.getSourceIp() != null){
+ ruleObject.addProperty("src_ip", rule.getSourceIp());
+ }
+
+ if(rule.getSourcePort() != null){
+ ruleObject.addProperty("src_port", rule.getSourcePort());
+ }
+
+ rulesArray.add(ruleObject);
+ }
+
+ firewallObject.add("rules", rulesArray);
+ }
+ return firewallObject;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-jclouds-labs/blob/14619a17/cloudsigma2/src/main/java/org/jclouds/cloudsigma2/functions/IPInfoToJson.java
----------------------------------------------------------------------
diff --git a/cloudsigma2/src/main/java/org/jclouds/cloudsigma2/functions/IPInfoToJson.java b/cloudsigma2/src/main/java/org/jclouds/cloudsigma2/functions/IPInfoToJson.java
new file mode 100644
index 0000000..34507e4
--- /dev/null
+++ b/cloudsigma2/src/main/java/org/jclouds/cloudsigma2/functions/IPInfoToJson.java
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF 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.cloudsigma2.functions;
+
+import com.google.common.base.Function;
+import com.google.gson.Gson;
+import com.google.gson.JsonObject;
+import com.google.gson.JsonParser;
+import org.jclouds.cloudsigma2.domain.IPInfo;
+import org.jclouds.javax.annotation.Nullable;
+
+import javax.inject.Singleton;
+
+/**
+ * @author Vladimir Shevchenko
+ */
+@Singleton
+public class IPInfoToJson implements Function<IPInfo, JsonObject>{
+ @Override
+ public JsonObject apply(@Nullable IPInfo input) {
+ if(input == null){
+ return null;
+ }
+
+ JsonObject ipObject = new JsonObject();
+
+ if(input.getMeta() != null){
+ ipObject.add("meta", new JsonParser().parse(new Gson().toJson(input.getMeta())));
+ }
+
+ return ipObject;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-jclouds-labs/blob/14619a17/cloudsigma2/src/main/java/org/jclouds/cloudsigma2/functions/LibraryDriveToJson.java
----------------------------------------------------------------------
diff --git a/cloudsigma2/src/main/java/org/jclouds/cloudsigma2/functions/LibraryDriveToJson.java b/cloudsigma2/src/main/java/org/jclouds/cloudsigma2/functions/LibraryDriveToJson.java
new file mode 100644
index 0000000..88f235a
--- /dev/null
+++ b/cloudsigma2/src/main/java/org/jclouds/cloudsigma2/functions/LibraryDriveToJson.java
@@ -0,0 +1,55 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF 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.cloudsigma2.functions;
+
+import com.google.common.base.Function;
+import com.google.gson.JsonObject;
+import org.jclouds.cloudsigma2.domain.LibraryDrive;
+import org.jclouds.javax.annotation.Nullable;
+
+import javax.inject.Inject;
+import javax.inject.Singleton;
+
+/**
+ * @author Vladimir Shevchenko
+ */
+@Singleton
+public class LibraryDriveToJson implements Function<LibraryDrive, JsonObject> {
+
+ private final DriveToJson infoJsonObjectFunction;
+
+ @Inject
+ public LibraryDriveToJson(DriveToJson infoJsonObjectFunction) {
+ this.infoJsonObjectFunction = infoJsonObjectFunction;
+ }
+
+ @Override
+ public JsonObject apply(@Nullable LibraryDrive input) {
+ JsonObject libraryDriveObject = infoJsonObjectFunction.apply(input);
+
+ if(libraryDriveObject == null){
+ libraryDriveObject = new JsonObject();
+ }
+
+ libraryDriveObject.addProperty("favourite", input.isFavorite());
+
+ if(input.getDescription() != null){
+ libraryDriveObject.addProperty("description", input.getDescription());
+ }
+ return libraryDriveObject;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-jclouds-labs/blob/14619a17/cloudsigma2/src/main/java/org/jclouds/cloudsigma2/functions/ProfileInfoToJson.java
----------------------------------------------------------------------
diff --git a/cloudsigma2/src/main/java/org/jclouds/cloudsigma2/functions/ProfileInfoToJson.java b/cloudsigma2/src/main/java/org/jclouds/cloudsigma2/functions/ProfileInfoToJson.java
new file mode 100644
index 0000000..c42911a
--- /dev/null
+++ b/cloudsigma2/src/main/java/org/jclouds/cloudsigma2/functions/ProfileInfoToJson.java
@@ -0,0 +1,99 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF 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.cloudsigma2.functions;
+
+import com.google.common.base.Function;
+import com.google.gson.Gson;
+import com.google.gson.JsonObject;
+import com.google.gson.JsonParser;
+import org.jclouds.cloudsigma2.domain.ProfileInfo;
+import org.jclouds.javax.annotation.Nullable;
+
+import javax.inject.Singleton;
+
+/**
+ * @author Vladimir Shevchenko
+ */
+@Singleton
+public class ProfileInfoToJson implements Function<ProfileInfo, JsonObject>{
+ @Override
+ public JsonObject apply(@Nullable ProfileInfo input) {
+ if(input == null){
+ return null;
+ }
+
+ JsonObject profileJson = new JsonObject();
+
+ if(input.getAddress() != null){
+ profileJson.addProperty("address", input.getAddress());
+ }
+
+ if(input.getBankReference() != null){
+ profileJson.addProperty("bank_reference", input.getBankReference());
+ }
+
+ if(input.getCompany() != null){
+ profileJson.addProperty("company", input.getCompany());
+ }
+
+ if(input.getCountry() != null){
+ profileJson.addProperty("country", input.getCountry());
+ }
+
+ if(input.getEmail() != null){
+ profileJson.addProperty("email", input.getEmail());
+ }
+
+ if(input.getFirstName() != null){
+ profileJson.addProperty("first_name", input.getFirstName());
+ }
+
+ if(input.getLastName() != null){
+ profileJson.addProperty("last_name", input.getLastName());
+ }
+
+ if(input.getMeta() != null){
+ profileJson.add("meta", new JsonParser().parse(new Gson().toJson(input.getMeta())));
+ }
+
+ if(input.getMyNotes() != null){
+ profileJson.addProperty("my_notes", input.getMyNotes());
+ }
+
+ if(input.getNickname() != null){
+ profileJson.addProperty("nickname", input.getNickname());
+ }
+
+ if(input.getPhone() != null){
+ profileJson.addProperty("phone", input.getPhone());
+ }
+
+ if(input.getPostcode() != null){
+ profileJson.addProperty("postcode", input.getPostcode());
+ }
+
+ if(input.getTitle() != null){
+ profileJson.addProperty("title", input.getTitle());
+ }
+
+ if(input.getTown() != null){
+ profileJson.addProperty("town", input.getTown());
+ }
+
+ return profileJson;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-jclouds-labs/blob/14619a17/cloudsigma2/src/main/java/org/jclouds/cloudsigma2/functions/ServerInfoToJson.java
----------------------------------------------------------------------
diff --git a/cloudsigma2/src/main/java/org/jclouds/cloudsigma2/functions/ServerInfoToJson.java b/cloudsigma2/src/main/java/org/jclouds/cloudsigma2/functions/ServerInfoToJson.java
new file mode 100644
index 0000000..c086326
--- /dev/null
+++ b/cloudsigma2/src/main/java/org/jclouds/cloudsigma2/functions/ServerInfoToJson.java
@@ -0,0 +1,145 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF 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.cloudsigma2.functions;
+
+import com.google.common.base.Function;
+import com.google.gson.Gson;
+import com.google.gson.JsonArray;
+import com.google.gson.JsonObject;
+import com.google.gson.JsonParser;
+import org.jclouds.cloudsigma2.domain.IPConfiguration;
+import org.jclouds.cloudsigma2.domain.NIC;
+import org.jclouds.cloudsigma2.domain.ServerDrive;
+import org.jclouds.cloudsigma2.domain.ServerInfo;
+
+import javax.inject.Singleton;
+
+/**
+ * @author Vladimir Shevchenko
+ */
+@Singleton
+public class ServerInfoToJson implements Function<ServerInfo, JsonObject> {
+ @Override
+ public JsonObject apply(ServerInfo input) {
+ JsonObject serverObject = new JsonObject();
+
+ if(input.getName() != null){
+ serverObject.addProperty("name", input.getName());
+ }
+
+ if(input.getCpu() > 0){
+ serverObject.addProperty("cpu", input.getCpu());
+ }
+
+ if(input.getMemory() != null){
+ serverObject.addProperty("mem", input.getMemory().toString());
+ }
+
+ if(input.getMeta() != null){
+ serverObject.add("meta", new JsonParser().parse(new Gson().toJson(input.getMeta())));
+ }
+
+ if(input.getRequirements() != null){
+ serverObject.add("requirements", new JsonParser().parse(new Gson().toJson(input.getRequirements())));
+ }
+
+ if(input.getTags() != null){
+ serverObject.add("tags", new JsonParser().parse(new Gson().toJson(input.getTags())));
+ }
+
+ if(input.getVncPassword() != null){
+ serverObject.addProperty("vnc_password", input.getVncPassword());
+ }
+
+ if(input.getNics() != null){
+ JsonArray nics = new JsonArray();
+
+ for(NIC nic : input.getNics()){
+ JsonObject nicObject = new JsonObject();
+
+ if(nic.getFirewallPolicy() != null){
+ nicObject.addProperty("firewall_policy", nic.getFirewallPolicy().getUuid());
+ }
+
+ if(nic.getVlan() != null){
+ nicObject.addProperty("vlan", nic.getVlan().getUuid());
+ } else if(nic.getIpV4Configuration() != null){
+ nicObject.add("ip_v4_conf", ipConfigurationToJsonObject(nic.getIpV4Configuration()));
+
+ if(nic.getModel() != null){
+ nicObject.addProperty("model", nic.getModel().value());
+ }
+ if(nic.getMac() != null){
+ nicObject.addProperty("mac", nic.getMac());
+ }
+ } else if(nic.getIpV6Configuration() != null){
+ nicObject.add("ip_v6_conf", ipConfigurationToJsonObject(nic.getIpV6Configuration()));
+
+ if(nic.getModel() != null){
+ nicObject.addProperty("model", nic.getModel().value());
+ }
+ if(nic.getMac() != null){
+ nicObject.addProperty("mac", nic.getMac());
+ }
+ }
+
+ nics.add(nicObject);
+ }
+
+ serverObject.add("nics", nics);
+ }
+
+ if(input.getDrives() != null){
+ JsonArray serverDrives = new JsonArray();
+
+ for(ServerDrive serverDrive : input.getDrives()){
+ JsonObject driveObject = new JsonObject();
+ driveObject.addProperty("boot_order", serverDrive.getBootOrder());
+
+ if(serverDrive.getDeviceChannel() != null){
+ driveObject.addProperty("dev_channel", serverDrive.getDeviceChannel());
+ }
+
+ if(serverDrive.getDeviceEmulationType() != null){
+ driveObject.addProperty("device", serverDrive.getDeviceEmulationType().value());
+ }
+
+ if(serverDrive.getDriveUuid() != null){
+ driveObject.addProperty("drive", serverDrive.getDriveUuid());
+ } else if(serverDrive.getDrive() != null){
+ driveObject.addProperty("drive", serverDrive.getDrive().getUuid());
+ }
+
+ serverDrives.add(driveObject);
+ }
+ serverObject.add("drives", serverDrives);
+ }
+
+ return serverObject;
+ }
+
+ private JsonObject ipConfigurationToJsonObject(IPConfiguration ipConfiguration){
+ JsonObject ipConfObject = new JsonObject();
+ if(ipConfiguration.getConfigurationType() != null){
+ ipConfObject.addProperty("conf", ipConfiguration.getConfigurationType().value());
+ }
+ if(ipConfiguration.getIp() != null){
+ ipConfObject.addProperty("ip", ipConfiguration.getIp().getUuid());
+ }
+ return ipConfObject;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-jclouds-labs/blob/14619a17/cloudsigma2/src/main/java/org/jclouds/cloudsigma2/functions/TagToJson.java
----------------------------------------------------------------------
diff --git a/cloudsigma2/src/main/java/org/jclouds/cloudsigma2/functions/TagToJson.java b/cloudsigma2/src/main/java/org/jclouds/cloudsigma2/functions/TagToJson.java
new file mode 100644
index 0000000..6beb728
--- /dev/null
+++ b/cloudsigma2/src/main/java/org/jclouds/cloudsigma2/functions/TagToJson.java
@@ -0,0 +1,60 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF 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.cloudsigma2.functions;
+
+import com.google.common.base.Function;
+import com.google.gson.Gson;
+import com.google.gson.JsonArray;
+import com.google.gson.JsonObject;
+import com.google.gson.JsonParser;
+import com.google.gson.JsonPrimitive;
+import org.jclouds.cloudsigma2.domain.Tag;
+import org.jclouds.cloudsigma2.domain.TagResource;
+import org.jclouds.javax.annotation.Nullable;
+
+import javax.inject.Singleton;
+
+/**
+ * @author Vladimir Shevchenko
+ */
+@Singleton
+public class TagToJson implements Function<Tag, JsonObject> {
+ @Override
+ public JsonObject apply(@Nullable Tag input) {
+ JsonObject jsonTag = new JsonObject();
+
+ if(input.getName() != null){
+ jsonTag.addProperty("name", input.getName());
+ }
+
+ if(input.getMeta() != null){
+ jsonTag.add("meta", new JsonParser().parse(new Gson().toJson(input.getMeta())));
+ }
+
+ if(input.getResources() != null && input.getResources().size() != 0){
+ JsonArray uuidsArray = new JsonArray();
+
+ for(TagResource tagResource : input.getResources()){
+ uuidsArray.add(new JsonPrimitive(tagResource.getUuid()));
+ }
+
+ jsonTag.add("resources", uuidsArray);
+ }
+
+ return jsonTag;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-jclouds-labs/blob/14619a17/cloudsigma2/src/main/java/org/jclouds/cloudsigma2/functions/VLANInfoToJson.java
----------------------------------------------------------------------
diff --git a/cloudsigma2/src/main/java/org/jclouds/cloudsigma2/functions/VLANInfoToJson.java b/cloudsigma2/src/main/java/org/jclouds/cloudsigma2/functions/VLANInfoToJson.java
new file mode 100644
index 0000000..60d3d31
--- /dev/null
+++ b/cloudsigma2/src/main/java/org/jclouds/cloudsigma2/functions/VLANInfoToJson.java
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF 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.cloudsigma2.functions;
+
+import com.google.common.base.Function;
+import com.google.gson.Gson;
+import com.google.gson.JsonObject;
+import com.google.gson.JsonParser;
+import com.google.inject.Singleton;
+import org.jclouds.cloudsigma2.domain.VLANInfo;
+import org.jclouds.javax.annotation.Nullable;
+
+/**
+ * @author Vladimir Shevchenko
+ */
+@Singleton
+public class VLANInfoToJson implements Function<VLANInfo, JsonObject> {
+
+ @Override
+ public JsonObject apply(@Nullable VLANInfo input) {
+ if(input == null){
+ return null;
+ }
+
+ JsonObject vlanObject = new JsonObject();
+
+ if(input.getMeta() != null){
+ vlanObject.add("meta", new JsonParser().parse(new Gson().toJson(input.getMeta())));
+ }
+
+ return vlanObject;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-jclouds-labs/blob/14619a17/cloudsigma2/src/main/java/org/jclouds/cloudsigma2/handlers/CloudSigmaErrorHandler.java
----------------------------------------------------------------------
diff --git a/cloudsigma2/src/main/java/org/jclouds/cloudsigma2/handlers/CloudSigmaErrorHandler.java b/cloudsigma2/src/main/java/org/jclouds/cloudsigma2/handlers/CloudSigmaErrorHandler.java
new file mode 100644
index 0000000..50b7f62
--- /dev/null
+++ b/cloudsigma2/src/main/java/org/jclouds/cloudsigma2/handlers/CloudSigmaErrorHandler.java
@@ -0,0 +1,106 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF 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.cloudsigma2.handlers;
+
+import com.google.common.base.Throwables;
+import com.google.common.io.Closeables;
+import org.jclouds.http.HttpCommand;
+import org.jclouds.http.HttpErrorHandler;
+import org.jclouds.http.HttpResponse;
+import org.jclouds.http.HttpResponseException;
+import org.jclouds.logging.Logger;
+import org.jclouds.rest.AuthorizationException;
+import org.jclouds.rest.ResourceNotFoundException;
+import org.jclouds.util.Strings2;
+
+import javax.annotation.Resource;
+import javax.inject.Singleton;
+import java.io.IOException;
+
+/**
+ * This will parse and set an appropriate exception on the command object.
+ *
+ * <p/>
+ * Errors are returned with an appropriate HTTP status code, an X-Elastic- Error header specifying
+ * the error type, and a text description in the HTTP body.
+ *
+ * @author Vladimir Shevchenko
+ *
+ */
+@Singleton
+public class CloudSigmaErrorHandler implements HttpErrorHandler {
+ @Resource
+ protected Logger logger = Logger.NULL;
+
+ public void handleError(HttpCommand command, HttpResponse response) {
+ // it is important to always read fully and close streams
+ String message = parseMessage(response);
+ Exception exception = message != null ? new HttpResponseException(command, response, message)
+ : new HttpResponseException(command, response);
+ try {
+ message = message != null ? message : String.format("%s -> %s", command.getCurrentRequest().getRequestLine(),
+ response.getStatusLine());
+ switch (response.getStatusCode()) {
+ case 400:
+ if ((command.getCurrentRequest().getEndpoint().getPath().endsWith("/info"))
+ || (message != null && message.indexOf("could not be found") != -1))
+ exception = new ResourceNotFoundException(message, exception);
+ else if (message != null && message.indexOf("currently in use") != -1)
+ exception = new IllegalStateException(message, exception);
+ else
+ exception = new IllegalArgumentException(message, exception);
+ break;
+ case 401:
+ exception = new AuthorizationException(message, exception);
+ break;
+ case 402:
+ exception = new IllegalStateException(message, exception);
+ break;
+ case 404:
+ if (!command.getCurrentRequest().getMethod().equals("DELETE")) {
+ exception = new ResourceNotFoundException(message, exception);
+ }
+ break;
+ case 405:
+ exception = new IllegalArgumentException(message, exception);
+ break;
+ case 409:
+ exception = new IllegalStateException(message, exception);
+ break;
+ }
+ } finally {
+ Closeables.closeQuietly(response.getPayload());
+ command.setException(exception);
+ }
+ }
+
+ public String parseMessage(HttpResponse response) {
+ if (response.getPayload() == null)
+ return null;
+ try {
+ return Strings2.toString(response.getPayload());
+ } catch (IOException e) {
+ throw Throwables.propagate(e);
+ } finally {
+ try {
+ response.getPayload().getInput().close();
+ } catch (IOException e) {
+ throw Throwables.propagate(e);
+ }
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-jclouds-labs/blob/14619a17/cloudsigma2/src/main/resources/META-INF/services/org.jclouds.apis.ApiMetadata
----------------------------------------------------------------------
diff --git a/cloudsigma2/src/main/resources/META-INF/services/org.jclouds.apis.ApiMetadata b/cloudsigma2/src/main/resources/META-INF/services/org.jclouds.apis.ApiMetadata
new file mode 100644
index 0000000..b6f3d71
--- /dev/null
+++ b/cloudsigma2/src/main/resources/META-INF/services/org.jclouds.apis.ApiMetadata
@@ -0,0 +1 @@
+org.jclouds.cloudsigma2.CloudSigma2ApiMetadata
\ No newline at end of file