diff --git a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/TerremarkEnterpriseCloudAsyncClient.java b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/TerremarkEnterpriseCloudAsyncClient.java index ffb9417a55..dbcb6469b6 100644 --- a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/TerremarkEnterpriseCloudAsyncClient.java +++ b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/TerremarkEnterpriseCloudAsyncClient.java @@ -20,6 +20,7 @@ package org.jclouds.tmrk.enterprisecloud; import org.jclouds.rest.annotations.Delegate; import org.jclouds.tmrk.enterprisecloud.features.TaskAsyncClient; +import org.jclouds.tmrk.enterprisecloud.features.TemplateAsyncClient; import org.jclouds.tmrk.enterprisecloud.features.VirtualMachineAsyncClient; /** @@ -45,4 +46,10 @@ public interface TerremarkEnterpriseCloudAsyncClient { */ @Delegate VirtualMachineAsyncClient getVirtualMachineClient(); + + /** + * Provides asynchronous access to Template features. + */ + @Delegate + TemplateAsyncClient getTemplateClient(); } diff --git a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/TerremarkEnterpriseCloudClient.java b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/TerremarkEnterpriseCloudClient.java index eab698ac66..a787096bf7 100644 --- a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/TerremarkEnterpriseCloudClient.java +++ b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/TerremarkEnterpriseCloudClient.java @@ -23,6 +23,7 @@ import java.util.concurrent.TimeUnit; import org.jclouds.concurrent.Timeout; import org.jclouds.rest.annotations.Delegate; import org.jclouds.tmrk.enterprisecloud.features.TaskClient; +import org.jclouds.tmrk.enterprisecloud.features.TemplateClient; import org.jclouds.tmrk.enterprisecloud.features.VirtualMachineClient; /** @@ -49,4 +50,10 @@ public interface TerremarkEnterpriseCloudClient { */ @Delegate VirtualMachineClient getVirtualMachineClient(); + + /** + * Provides synchronous access to Template features. + */ + @Delegate + TemplateClient getTemplateClient(); } diff --git a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/config/TerremarkEnterpriseCloudRestClientModule.java b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/config/TerremarkEnterpriseCloudRestClientModule.java index 92e73f0227..4d3befe166 100644 --- a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/config/TerremarkEnterpriseCloudRestClientModule.java +++ b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/config/TerremarkEnterpriseCloudRestClientModule.java @@ -31,10 +31,7 @@ import org.jclouds.rest.ConfiguresRestClient; import org.jclouds.rest.config.RestClientModule; import org.jclouds.tmrk.enterprisecloud.TerremarkEnterpriseCloudAsyncClient; import org.jclouds.tmrk.enterprisecloud.TerremarkEnterpriseCloudClient; -import org.jclouds.tmrk.enterprisecloud.features.TaskAsyncClient; -import org.jclouds.tmrk.enterprisecloud.features.TaskClient; -import org.jclouds.tmrk.enterprisecloud.features.VirtualMachineAsyncClient; -import org.jclouds.tmrk.enterprisecloud.features.VirtualMachineClient; +import org.jclouds.tmrk.enterprisecloud.features.*; import org.jclouds.tmrk.enterprisecloud.handlers.TerremarkEnterpriseCloudErrorHandler; import com.google.common.collect.ImmutableMap; @@ -52,6 +49,7 @@ public class TerremarkEnterpriseCloudRestClientModule extends public static final Map, Class> DELEGATE_MAP = ImmutableMap., Class> builder() .put(TaskClient.class, TaskAsyncClient.class) .put(VirtualMachineClient.class, VirtualMachineAsyncClient.class) + .put(TemplateClient.class, TemplateAsyncClient.class) .build(); public TerremarkEnterpriseCloudRestClientModule() { diff --git a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/Action.java b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/Action.java index 7184016f44..0e7defe390 100644 --- a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/Action.java +++ b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/Action.java @@ -119,8 +119,8 @@ public class Action extends BaseNamedResource { * {@inheritDoc} */ @Override - public Builder fromResource(BaseResource in) { - return Builder.class.cast(super.fromResource(in)); + public Builder fromBaseResource(BaseResource in) { + return Builder.class.cast(super.fromBaseResource(in)); } /** @@ -171,14 +171,15 @@ public class Action extends BaseNamedResource { @XmlAttribute protected ActionDisabled actionDisabled; - public Action(URI href, String type, String name, @Nullable ActionDisabled actionDisabled) { + private Action(URI href, String type, String name, @Nullable ActionDisabled actionDisabled) { super(href, type, name); this.actionDisabled = actionDisabled; } - protected Action() { + private Action() { //For JAXB } + /** * The attribute actionDisabled appears only when the example has an action * disabled for business rules. diff --git a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/Group.java b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/Group.java deleted file mode 100644 index a8428e47f1..0000000000 --- a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/Group.java +++ /dev/null @@ -1,31 +0,0 @@ -/** - * 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.tmrk.enterprisecloud.domain; - -import org.jclouds.tmrk.enterprisecloud.domain.internal.BaseNamedResource; - -/** - * @author Jason King - */ -public class Group extends BaseNamedResource { - - public Group() { - //For JAXB - } -} diff --git a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/Layout.java b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/Layout.java index aea017a226..58405d36c0 100644 --- a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/Layout.java +++ b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/Layout.java @@ -34,12 +34,12 @@ import javax.xml.bind.annotation.XmlElement; */ public class Layout { @XmlElement(name = "Group") - private Group group; + private NamedResource group; @XmlElement(name = "Row") - private Row row; + private NamedResource row; - public Layout(@Nullable Group group, @Nullable Row row) { + public Layout(@Nullable NamedResource group, @Nullable NamedResource row) { this.group = group; this.row = row; } @@ -48,11 +48,11 @@ public class Layout { //For JAXB } - public Group getGroup() { + public NamedResource getGroup() { return group; } - public Row getRow() { + public NamedResource getRow() { return row; } diff --git a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/Link.java b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/Link.java index c4a6e4b5af..f9a47b4037 100644 --- a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/Link.java +++ b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/Link.java @@ -18,6 +18,7 @@ */ package org.jclouds.tmrk.enterprisecloud.domain; +import com.google.common.collect.Sets; import org.jclouds.tmrk.enterprisecloud.domain.internal.BaseNamedResource; import org.jclouds.tmrk.enterprisecloud.domain.internal.BaseResource; @@ -26,6 +27,7 @@ import javax.xml.bind.annotation.XmlEnum; import javax.xml.bind.annotation.XmlEnumValue; import java.net.URI; import java.util.Map; +import java.util.Set; import static com.google.common.base.Preconditions.checkNotNull; @@ -134,8 +136,8 @@ public class Link extends BaseNamedResource { * {@inheritDoc} */ @Override - public Builder fromResource(BaseResource in) { - return Builder.class.cast(super.fromResource(in)); + public Builder fromBaseResource(BaseResource in) { + return Builder.class.cast(super.fromBaseResource(in)); } /** @@ -185,12 +187,12 @@ public class Link extends BaseNamedResource { @XmlAttribute protected Relationship rel; - public Link(URI href, String type, String name, Relationship rel) { + private Link(URI href, String type, String name, Relationship rel) { super(href, type, name); this.rel = checkNotNull(rel, "rel"); } - protected Link() { + private Link() { //For JAXB } diff --git a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/NamedResource.java b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/NamedResource.java index b9b3a3a44d..1365f5fb67 100644 --- a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/NamedResource.java +++ b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/NamedResource.java @@ -20,6 +20,7 @@ package org.jclouds.tmrk.enterprisecloud.domain; import java.net.URI; import java.util.Map; +import java.util.Set; import org.jclouds.tmrk.enterprisecloud.domain.internal.BaseNamedResource; import org.jclouds.tmrk.enterprisecloud.domain.internal.BaseResource; @@ -58,8 +59,8 @@ public class NamedResource extends BaseNamedResource { * {@inheritDoc} */ @Override - public Builder fromResource(BaseResource in) { - return Builder.class.cast(super.fromResource(in)); + public Builder fromBaseResource(BaseResource in) { + return Builder.class.cast(super.fromBaseResource(in)); } /** @@ -104,7 +105,7 @@ public class NamedResource extends BaseNamedResource { } - public NamedResource(URI href, String type, String name) { + private NamedResource(URI href, String type, String name) { super(href, type, name); } diff --git a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/Row.java b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/Row.java deleted file mode 100644 index fe4e133dc0..0000000000 --- a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/Row.java +++ /dev/null @@ -1,30 +0,0 @@ -/** - * 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.tmrk.enterprisecloud.domain; - -import org.jclouds.tmrk.enterprisecloud.domain.internal.BaseNamedResource; - -/** - * @author Jason King - */ -public class Row extends BaseNamedResource { - public Row() { - //For JAXB - } -} diff --git a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/Task.java b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/Task.java index ce5fd5db7b..3cced5ef2f 100644 --- a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/Task.java +++ b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/Task.java @@ -18,21 +18,22 @@ */ package org.jclouds.tmrk.enterprisecloud.domain; -import static com.google.common.base.CaseFormat.UPPER_CAMEL; -import static com.google.common.base.CaseFormat.UPPER_UNDERSCORE; -import static com.google.common.base.Preconditions.checkNotNull; - -import java.net.URI; -import java.util.Date; -import java.util.Map; - import org.jclouds.javax.annotation.Nullable; import org.jclouds.tmrk.enterprisecloud.domain.internal.BaseResource; +import org.jclouds.tmrk.enterprisecloud.domain.internal.Resource; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlEnum; import javax.xml.bind.annotation.XmlEnumValue; import javax.xml.bind.annotation.XmlRootElement; +import java.net.URI; +import java.util.Date; +import java.util.Map; +import java.util.Set; + +import static com.google.common.base.CaseFormat.UPPER_CAMEL; +import static com.google.common.base.CaseFormat.UPPER_UNDERSCORE; +import static com.google.common.base.Preconditions.checkNotNull; /** * @@ -40,7 +41,7 @@ import javax.xml.bind.annotation.XmlRootElement; * */ @XmlRootElement(name = "Task") -public class Task extends BaseResource { +public class Task extends Resource { @XmlEnum public static enum Status { /** @@ -109,7 +110,7 @@ public class Task extends BaseResource { return new Builder().fromTask(this); } - public static class Builder extends BaseResource.Builder { + public static class Builder extends Resource.Builder { //TODO There are additional fields protected String operation; protected Status status; @@ -186,8 +187,8 @@ public class Task extends BaseResource { @Override public Task build() { - return new Task(href, type, operation, status, impactedItem, startTime, completedTime, notes, errorMessage, - initiatedBy); + return new Task(href, type, name, links, + actions, operation, status, impactedItem, startTime, completedTime, notes, errorMessage, initiatedBy); } public Builder fromTask(Task in) { @@ -200,7 +201,15 @@ public class Task extends BaseResource { * {@inheritDoc} */ @Override - public Builder fromResource(BaseResource in) { + public Builder fromBaseResource(BaseResource in) { + return Builder.class.cast(super.fromBaseResource(in)); + } + + /** + * {@inheritDoc} + */ + @Override + public Builder fromResource(Resource in) { return Builder.class.cast(super.fromResource(in)); } @@ -220,6 +229,30 @@ public class Task extends BaseResource { return Builder.class.cast(super.href(href)); } + /** + * {@inheritDoc} + */ + @Override + public Builder name(String name) { + return Builder.class.cast(super.name(name)); + } + + /** + * {@inheritDoc} + */ + @Override + public Builder links(Set links) { + return Builder.class.cast(super.links(links)); + } + + /** + * {@inheritDoc} + */ + @Override + public Builder actions(Set actions) { + return Builder.class.cast(super.actions(actions)); + } + /** * {@inheritDoc} */ @@ -254,9 +287,9 @@ public class Task extends BaseResource { @XmlElement(name = "InitiatedBy", required = true) protected NamedResource initiatedBy; - public Task(URI href, String type, String operation, Status status, NamedResource impactedItem, Date startTime, + private Task(URI href, String type, String name, Set links, Set actions, String operation, Status status, NamedResource impactedItem, Date startTime, @Nullable Date completedTime, @Nullable String notes, @Nullable String errorMessage, NamedResource initiatedBy) { - super(href, type); + super(href, type, name, links, actions); this.operation = checkNotNull(operation, "operation"); this.status = checkNotNull(status, "status"); this.impactedItem = checkNotNull(impactedItem, "impactedItem"); @@ -267,7 +300,7 @@ public class Task extends BaseResource { this.initiatedBy = checkNotNull(initiatedBy, "initiatedBy"); } - protected Task() { + private Task() { //For JAXB } diff --git a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/hardware/HardwareConfiguration.java b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/hardware/HardwareConfiguration.java index c994bef5ad..cf5dc767cd 100644 --- a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/hardware/HardwareConfiguration.java +++ b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/hardware/HardwareConfiguration.java @@ -22,8 +22,9 @@ import com.google.common.collect.ImmutableSet; import com.google.common.collect.Sets; import org.jclouds.javax.annotation.Nullable; import org.jclouds.tmrk.enterprisecloud.domain.Action; -import org.jclouds.tmrk.enterprisecloud.domain.Actions; +import org.jclouds.tmrk.enterprisecloud.domain.Link; import org.jclouds.tmrk.enterprisecloud.domain.internal.BaseResource; +import org.jclouds.tmrk.enterprisecloud.domain.internal.Resource; import org.jclouds.tmrk.enterprisecloud.domain.internal.ResourceCapacity; import org.jclouds.tmrk.enterprisecloud.domain.network.Nics; import org.jclouds.tmrk.enterprisecloud.domain.network.VirtualNic; @@ -42,7 +43,7 @@ import static com.google.common.base.Preconditions.checkNotNull; * @author Jason King */ @XmlRootElement(name = "HardwareConfiguration") -public class HardwareConfiguration extends BaseResource { +public class HardwareConfiguration extends Resource { @SuppressWarnings("unchecked") public static Builder builder() { @@ -57,23 +58,13 @@ public class HardwareConfiguration extends BaseResource { return new Builder().fromHardwareConfiguration(this); } - public static class Builder extends BaseResource.Builder { + public static class Builder extends Resource.Builder { - // TODO Links - private Set actions = Sets.newLinkedHashSet(); private int processorCount; private ResourceCapacity memory; private Set virtualDisks = Sets.newLinkedHashSet(); private Set virtualNics = Sets.newLinkedHashSet(); - /** - * @see HardwareConfiguration#getActions - */ - public Builder actions(Set actions) { - this.actions = ImmutableSet. copyOf(checkNotNull(actions, "actions")); - return this; - } - /** * @see HardwareConfiguration#getProcessorCount */ @@ -109,14 +100,22 @@ public class HardwareConfiguration extends BaseResource { @Override public HardwareConfiguration build() { - return new HardwareConfiguration(actions, processorCount, memory, virtualDisks, virtualNics); + return new HardwareConfiguration(processorCount, memory, virtualDisks, virtualNics); } /** * {@inheritDoc} */ @Override - public Builder fromResource(BaseResource in) { + public Builder fromBaseResource(BaseResource in) { + return Builder.class.cast(super.fromBaseResource(in)); + } + + /** + * {@inheritDoc} + */ + @Override + public Builder fromResource(Resource in) { return Builder.class.cast(super.fromResource(in)); } @@ -136,6 +135,30 @@ public class HardwareConfiguration extends BaseResource { return Builder.class.cast(super.href(href)); } + /** + * {@inheritDoc} + */ + @Override + public Builder name(String name) { + return Builder.class.cast(super.name(name)); + } + + /** + * {@inheritDoc} + */ + @Override + public Builder links(Set links) { + return Builder.class.cast(super.links(links)); + } + + /** + * {@inheritDoc} + */ + @Override + public Builder actions(Set actions) { + return Builder.class.cast(super.actions(actions)); + } + /** * {@inheritDoc} */ @@ -145,17 +168,13 @@ public class HardwareConfiguration extends BaseResource { } public Builder fromHardwareConfiguration(HardwareConfiguration in) { - return fromResource(in).actions(in.getActions()) - .processorCount(in.getProcessorCount()) + return fromResource(in).processorCount(in.getProcessorCount()) .memory(in.getMemory()) .disks(in.getVirtualDisks()) .nics(in.getVirtualNics()); } } - @XmlElement(name = "Actions", required = false) - private Actions actions = Actions.builder().build(); - @XmlElement(name = "ProcessorCount", required = true) private int processorCount; @@ -168,22 +187,17 @@ public class HardwareConfiguration extends BaseResource { @XmlElement(name = "Nics", required = false) private Nics virtualNics = Nics.builder().build(); - public HardwareConfiguration(Set actions, int processorCount, @Nullable ResourceCapacity memory, Set virtualDisks, Set virtualNics) { - this.actions = Actions.builder().actions(checkNotNull(actions, "actions")).build(); + private HardwareConfiguration(int processorCount, @Nullable ResourceCapacity memory, Set virtualDisks, Set virtualNics) { this.virtualDisks = Disks.builder().disks(checkNotNull(virtualDisks,"virtualDisks")).build(); this.virtualNics = Nics.builder().nics(checkNotNull(virtualNics, "virtualNics")).build(); this.processorCount = processorCount; this.memory = memory; } - protected HardwareConfiguration() { + private HardwareConfiguration() { //For JAXB } - public Set getActions() { - return Collections.unmodifiableSet(actions.getActions()); - } - public int getProcessorCount() { return processorCount; } @@ -209,7 +223,6 @@ public class HardwareConfiguration extends BaseResource { HardwareConfiguration that = (HardwareConfiguration) o; if (processorCount != that.processorCount) return false; - if (!actions.equals(that.actions)) return false; if (!virtualDisks.equals(that.virtualDisks)) return false; if (memory != null ? !memory.equals(that.memory) : that.memory != null) return false; @@ -221,7 +234,6 @@ public class HardwareConfiguration extends BaseResource { @Override public int hashCode() { int result = super.hashCode(); - result = 31 * result + actions.hashCode(); result = 31 * result + processorCount; result = 31 * result + (memory != null ? memory.hashCode() : 0); result = 31 * result + virtualDisks.hashCode(); @@ -231,7 +243,7 @@ public class HardwareConfiguration extends BaseResource { @Override public String string() { - return super.string()+", actions="+actions+", processorCount="+processorCount+ + return super.string()+", processorCount="+processorCount+ ", memory="+memory+", disks="+ virtualDisks +", nics="+ virtualNics; } } diff --git a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/internal/BaseNamedResource.java b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/internal/BaseNamedResource.java index b93928501f..fa302f8e22 100644 --- a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/internal/BaseNamedResource.java +++ b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/internal/BaseNamedResource.java @@ -19,12 +19,11 @@ package org.jclouds.tmrk.enterprisecloud.domain.internal; import javax.xml.bind.annotation.XmlAttribute; - -import static com.google.common.base.Preconditions.checkNotNull; - import java.net.URI; import java.util.Map; +import static com.google.common.base.Preconditions.checkNotNull; + /** * Location of a Rest resource * @@ -62,12 +61,12 @@ public class BaseNamedResource> extends BaseResou */ @SuppressWarnings("unchecked") @Override - public Builder fromResource(BaseResource in) { - return Builder.class.cast(super.fromResource(in)); + public Builder fromBaseResource(BaseResource in) { + return Builder.class.cast(super.fromBaseResource(in)); } public Builder fromNamedResource(BaseNamedResource in) { - return fromResource(in).name(in.getName()); + return fromBaseResource(in).name(in.getName()); } /** @@ -82,7 +81,7 @@ public class BaseNamedResource> extends BaseResou @XmlAttribute protected String name; - public BaseNamedResource(URI href, String type, String name) { + protected BaseNamedResource(URI href, String type, String name) { super(href, type); this.name = checkNotNull(name, "name"); } diff --git a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/internal/BaseResource.java b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/internal/BaseResource.java index 73d46f998b..8d29c8cb11 100644 --- a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/internal/BaseResource.java +++ b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/internal/BaseResource.java @@ -19,12 +19,11 @@ package org.jclouds.tmrk.enterprisecloud.domain.internal; import javax.xml.bind.annotation.XmlAttribute; - -import static com.google.common.base.Preconditions.checkNotNull; - import java.net.URI; import java.util.Map; +import static com.google.common.base.Preconditions.checkNotNull; + /** * Location of a Rest resource * @@ -38,7 +37,7 @@ public class BaseResource> { } public Builder toBuilder() { - return new Builder().fromResource(this); + return new Builder().fromBaseResource(this); } public static class Builder> { @@ -66,11 +65,11 @@ public class BaseResource> { return new BaseResource(href, type); } - public Builder fromResource(BaseResource in) { + protected Builder fromBaseResource(BaseResource in) { return type(in.getType()).href(in.getHref()); } - public Builder fromAttributes(Map attributes) { + protected Builder fromAttributes(Map attributes) { return href(URI.create(attributes.get("href"))).type(attributes.get("type")); } @@ -82,7 +81,7 @@ public class BaseResource> { @XmlAttribute protected URI href; - public BaseResource(URI href, String type) { + protected BaseResource(URI href, String type) { this.type = checkNotNull(type, "type"); this.href = checkNotNull(href, "href"); } @@ -108,34 +107,25 @@ public class BaseResource> { } @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((href == null) ? 0 : href.hashCode()); - result = prime * result + ((type == null) ? 0 : type.hashCode()); - return result; + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + BaseResource that = (BaseResource) o; + + if (href != null ? !href.equals(that.href) : that.href != null) + return false; + if (type != null ? !type.equals(that.type) : that.type != null) + return false; + + return true; } @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - BaseResource other = (BaseResource) obj; - if (href == null) { - if (other.href != null) - return false; - } else if (!href.equals(other.href)) - return false; - if (type == null) { - if (other.type != null) - return false; - } else if (!type.equals(other.type)) - return false; - return true; + public int hashCode() { + int result = type != null ? type.hashCode() : 0; + result = 31 * result + (href != null ? href.hashCode() : 0); + return result; } @Override diff --git a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/internal/Resource.java b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/internal/Resource.java new file mode 100644 index 0000000000..c0e4f84670 --- /dev/null +++ b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/internal/Resource.java @@ -0,0 +1,173 @@ +/** + * 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.tmrk.enterprisecloud.domain.internal; + +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Sets; +import org.jclouds.javax.annotation.Nullable; +import org.jclouds.tmrk.enterprisecloud.domain.Action; +import org.jclouds.tmrk.enterprisecloud.domain.Actions; +import org.jclouds.tmrk.enterprisecloud.domain.Link; +import org.jclouds.tmrk.enterprisecloud.domain.Links; + +import javax.xml.bind.annotation.XmlAttribute; +import javax.xml.bind.annotation.XmlElement; +import java.net.URI; +import java.util.Collections; +import java.util.Map; +import java.util.Set; + +import static com.google.common.base.Preconditions.checkNotNull; + +/** + * Base Resource class. + * has Links and Actions and name (plus href and type are inherited) + * + * @author Jason King + * + */ +public class Resource> extends BaseResource { + + public static > Builder builder() { + return new Builder(); + } + + public Builder toBuilder() { + return new Builder().fromResource(this); + } + + public static class Builder> extends BaseResource.Builder { + + protected Set links = Sets.newLinkedHashSet(); + protected Set actions = Sets.newLinkedHashSet(); + protected String name; + + /** + * @see Resource#getLinks + */ + public Builder links(Set links) { + this.links = ImmutableSet. copyOf(checkNotNull(links, "links")); + return this; + } + + /** + * @see Resource#getActions + */ + public Builder actions(Set actions) { + this.actions = ImmutableSet. copyOf(checkNotNull(actions, "actions")); + return this; + } + + /** + * @see Resource#getActions + */ + public Builder name(String name) { + this.name = checkNotNull(name, "name"); + return this; + } + + public Resource build() { + return new Resource(href, type, name, links, actions); + } + + /** + * {@inheritDoc} + */ + public Builder fromBaseResource(BaseResource in) { + return Builder.class.cast(super.fromBaseResource(in)); + } + + public Builder fromResource(Resource in) { + return fromBaseResource(in).links(in.getLinks()) + .actions(in.getActions()).name(in.getName()); + } + + /** + * {@inheritDoc} + */ + @SuppressWarnings("unchecked") + public Builder fromAttributes(Map attributes) { + return Builder.class.cast(super.fromAttributes(attributes)); + } + } + + @XmlElement(name = "Links", required = false) + protected Links links = Links.builder().build(); + + @XmlElement(name = "Actions", required = false) + protected Actions actions = Actions.builder().build(); + + @XmlAttribute(required = false) + protected String name; + + protected Resource(URI href, String type, @Nullable String name, Set links, Set actions) { + super(href, type); + this.name = name; + this.links = Links.builder().links(checkNotNull(links,"links")).build(); + this.actions = Actions.builder().actions(checkNotNull(actions, "actions")).build(); + } + + protected Resource() { + //For JAXB + } + + public Set getLinks() { + return Collections.unmodifiableSet(links.getLinks()); + } + + public Set getActions() { + return Collections.unmodifiableSet(actions.getActions()); + } + + public String getName() { + return name; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + if (!super.equals(o)) return false; + + Resource resource = (Resource) o; + + if (actions != null ? !actions.equals(resource.actions) : resource.actions != null) + return false; + if (links != null ? !links.equals(resource.links) : resource.links != null) + return false; + if (name != null ? !name.equals(resource.name) : resource.name != null) + return false; + + return true; + } + + @Override + public int hashCode() { + int result = super.hashCode(); + result = 31 * result + (links != null ? links.hashCode() : 0); + result = 31 * result + (actions != null ? actions.hashCode() : 0); + result = 31 * result + (name != null ? name.hashCode() : 0); + return result; + } + + @Override + public String string() { + return super.string()+", name="+name+", links="+links+", actions="+actions; + } +} \ No newline at end of file diff --git a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/network/AssignedIpAddresses.java b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/network/AssignedIpAddresses.java index 52f880eeed..83c3f4a9d3 100644 --- a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/network/AssignedIpAddresses.java +++ b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/network/AssignedIpAddresses.java @@ -18,8 +18,10 @@ */ package org.jclouds.tmrk.enterprisecloud.domain.network; +import com.google.common.collect.Sets; import org.jclouds.tmrk.enterprisecloud.domain.Actions; -import org.jclouds.tmrk.enterprisecloud.domain.internal.BaseResource; +import org.jclouds.tmrk.enterprisecloud.domain.Link; +import org.jclouds.tmrk.enterprisecloud.domain.internal.Resource; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; @@ -32,19 +34,13 @@ import static com.google.common.base.Preconditions.checkNotNull; * @author Jason King */ @XmlRootElement(name="AssignedIpAddresses") -public class AssignedIpAddresses extends BaseResource { - - //TODO links - - @XmlElement(name = "Actions", required = true) - private Actions actions = Actions.builder().build(); +public class AssignedIpAddresses extends Resource { @XmlElement(name = "Networks", required = true) private DeviceNetworks networks = new DeviceNetworks(); - public AssignedIpAddresses(URI href, String type, Actions actions, DeviceNetworks networks) { - super(href, type); - checkNotNull(actions,"actions"); + public AssignedIpAddresses(URI href, String type, String name, Actions actions, DeviceNetworks networks) { + super(href, type, name, Sets.newIdentityHashSet(), actions.getActions()); checkNotNull(networks,"networks"); } @@ -52,10 +48,6 @@ public class AssignedIpAddresses extends BaseResource { //For JAXB } - public Actions getActions() { - return actions; - } - public DeviceNetworks getNetworks() { return networks; } @@ -68,7 +60,6 @@ public class AssignedIpAddresses extends BaseResource { AssignedIpAddresses that = (AssignedIpAddresses) o; - if (!actions.equals(that.actions)) return false; if (!networks.equals(that.networks)) return false; return true; @@ -77,14 +68,13 @@ public class AssignedIpAddresses extends BaseResource { @Override public int hashCode() { int result = super.hashCode(); - result = 31 * result + actions.hashCode(); result = 31 * result + networks.hashCode(); return result; } @Override public String string() { - return super.string()+", actions="+actions+", networks="+networks; + return super.string()+", networks="+networks; } } \ No newline at end of file diff --git a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/network/DeviceNetwork.java b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/network/DeviceNetwork.java index d2e18a4fd6..97f2b74dff 100644 --- a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/network/DeviceNetwork.java +++ b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/network/DeviceNetwork.java @@ -18,7 +18,7 @@ */ package org.jclouds.tmrk.enterprisecloud.domain.network; -import org.jclouds.tmrk.enterprisecloud.domain.internal.BaseNamedResource; +import org.jclouds.tmrk.enterprisecloud.domain.internal.Resource; import javax.xml.bind.annotation.XmlElement; @@ -27,12 +27,14 @@ import javax.xml.bind.annotation.XmlElement; * * @author Jason King */ -public class DeviceNetwork extends BaseNamedResource { +public class DeviceNetwork extends Resource { + + //TODO: Builder @XmlElement(name = "IpAddresses") private DeviceIps ipAddresses = new DeviceIps(); - protected DeviceNetwork() { + private DeviceNetwork() { //For JAXB } diff --git a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/network/NetworkReference.java b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/network/NetworkReference.java index 57ab774346..5102392b49 100644 --- a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/network/NetworkReference.java +++ b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/network/NetworkReference.java @@ -19,6 +19,8 @@ package org.jclouds.tmrk.enterprisecloud.domain.network; import org.jclouds.javax.annotation.Nullable; +import org.jclouds.tmrk.enterprisecloud.domain.Action; +import org.jclouds.tmrk.enterprisecloud.domain.Link; import org.jclouds.tmrk.enterprisecloud.domain.internal.BaseNamedResource; import org.jclouds.tmrk.enterprisecloud.domain.internal.BaseResource; @@ -26,6 +28,8 @@ import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlEnum; import javax.xml.bind.annotation.XmlEnumValue; import java.net.URI; +import java.util.Map; +import java.util.Set; import static com.google.common.base.CaseFormat.LOWER_CAMEL; import static com.google.common.base.CaseFormat.UPPER_UNDERSCORE; @@ -93,8 +97,8 @@ public class NetworkReference extends BaseNamedResource { * {@inheritDoc} */ @Override - public Builder fromResource(BaseResource in) { - return Builder.class.cast(super.fromResource(in)); + public Builder fromBaseResource(BaseResource in) { + return Builder.class.cast(super.fromBaseResource(in)); } /** @@ -128,17 +132,25 @@ public class NetworkReference extends BaseNamedResource { public Builder type(String type) { return Builder.class.cast(super.type(type)); } + + /** + * {@inheritDoc} + */ + @Override + public Builder fromAttributes(Map attributes) { + return Builder.class.cast(super.fromAttributes(attributes)); + } } @XmlElement(name = "NetworkType") private NetworkType networkType; - public NetworkReference(URI href, String type, String name,@Nullable NetworkType networkType) { + private NetworkReference(URI href, String type, String name,@Nullable NetworkType networkType) { super(href, type, name); this.networkType = networkType; } - protected NetworkReference() { + private NetworkReference() { //For JAXB } diff --git a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/software/OperatingSystem.java b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/software/OperatingSystem.java index 8d559faef7..705308236e 100644 --- a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/software/OperatingSystem.java +++ b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/software/OperatingSystem.java @@ -18,18 +18,21 @@ */ package org.jclouds.tmrk.enterprisecloud.domain.software; -import org.jclouds.tmrk.enterprisecloud.domain.internal.BaseNamedResource; +import org.jclouds.tmrk.enterprisecloud.domain.Action; +import org.jclouds.tmrk.enterprisecloud.domain.Link; import org.jclouds.tmrk.enterprisecloud.domain.internal.BaseResource; +import org.jclouds.tmrk.enterprisecloud.domain.internal.Resource; import java.net.URI; import java.util.Map; +import java.util.Set; /** * * @author Jason King * */ -public class OperatingSystem extends BaseNamedResource { +public class OperatingSystem extends Resource { //TODO There are other fields @@ -43,24 +46,24 @@ public class OperatingSystem extends BaseNamedResource { */ @Override public Builder toBuilder() { - return new Builder().fromNamedResource(this); + return new Builder().fromOperatingSystem(this); } - public static class Builder extends BaseNamedResource.Builder { + public static class Builder extends Resource.Builder { /** * {@inheritDoc} */ @Override public OperatingSystem build() { - return new OperatingSystem(href, type, name); + return new OperatingSystem(href, type, links, actions, name); } /** * {@inheritDoc} */ @Override - public Builder fromResource(BaseResource in) { + public Builder fromResource(Resource in) { return Builder.class.cast(super.fromResource(in)); } @@ -68,8 +71,12 @@ public class OperatingSystem extends BaseNamedResource { * {@inheritDoc} */ @Override - public Builder fromNamedResource(BaseNamedResource in) { - return Builder.class.cast(super.fromNamedResource(in)); + public Builder fromBaseResource(BaseResource in) { + return Builder.class.cast(super.fromBaseResource(in)); + } + + public Builder fromOperatingSystem(OperatingSystem in) { + return fromResource(in); } /** @@ -96,6 +103,22 @@ public class OperatingSystem extends BaseNamedResource { return Builder.class.cast(super.type(type)); } + /** + * {@inheritDoc} + */ + @Override + public Builder links(Set links) { + return Builder.class.cast(super.links(links)); + } + + /** + * {@inheritDoc} + */ + @Override + public Builder actions(Set actions) { + return Builder.class.cast(super.actions(actions)); + } + /** * {@inheritDoc} */ @@ -106,11 +129,11 @@ public class OperatingSystem extends BaseNamedResource { } - public OperatingSystem(URI href, String type, String name) { - super(href, type, name); + private OperatingSystem(URI href, String type, Set links, Set actions, String name) { + super(href, type, name, links, actions); } - protected OperatingSystem() { + private OperatingSystem() { //For JAXB } } \ No newline at end of file diff --git a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/template/Template.java b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/template/Template.java index 643b7122c4..88ecc31314 100644 --- a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/template/Template.java +++ b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/template/Template.java @@ -19,17 +19,16 @@ package org.jclouds.tmrk.enterprisecloud.domain.template; import org.jclouds.javax.annotation.Nullable; -import org.jclouds.tmrk.enterprisecloud.domain.ConfigurationOptionRange; -import org.jclouds.tmrk.enterprisecloud.domain.CustomizationOption; -import org.jclouds.tmrk.enterprisecloud.domain.Links; -import org.jclouds.tmrk.enterprisecloud.domain.ResourceCapacityRange; -import org.jclouds.tmrk.enterprisecloud.domain.internal.BaseNamedResource; +import org.jclouds.tmrk.enterprisecloud.domain.*; import org.jclouds.tmrk.enterprisecloud.domain.internal.BaseResource; +import org.jclouds.tmrk.enterprisecloud.domain.internal.Resource; import org.jclouds.tmrk.enterprisecloud.domain.software.OperatingSystem; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; import java.net.URI; +import java.util.Map; +import java.util.Set; /** * @@ -37,7 +36,7 @@ import java.net.URI; * */ @XmlRootElement(name = "Template") -public class Template extends BaseNamedResource