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/template/TemplateCategories.java b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/template/TemplateCategories.java new file mode 100644 index 0000000000..cad7f7c222 --- /dev/null +++ b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/template/TemplateCategories.java @@ -0,0 +1,108 @@ +/** + * 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.template; + +import com.google.common.collect.Sets; + +import javax.xml.bind.annotation.XmlElement; +import java.util.Collections; +import java.util.Set; + +import static com.google.common.base.Preconditions.checkNotNull; + +/** + * Wraps individual TemplateCategory elements. + * Needed because parsing is done with JAXB and it does not handle Generic collections + * + * @author Jason King + */ +public class TemplateCategories { + + @SuppressWarnings("unchecked") + public static Builder builder() { + return new Builder(); + } + + public Builder toBuilder() { + return new Builder().fromTemplateCategories(this); + } + + public static class Builder { + + private Set categories = Sets.newLinkedHashSet(); + + /** + * @see TemplateCategories#getTemplateCategories() + */ + public Builder categories(Set categories) { + this.categories = Sets.newLinkedHashSet(checkNotNull(categories, "categories")); + return this; + } + + public Builder addCategory(TemplateCategory category) { + categories.add(checkNotNull(category,"category")); + return this; + } + + public TemplateCategories build() { + return new TemplateCategories(categories); + } + + public Builder fromTemplateCategories(TemplateCategories in) { + return categories(in.getTemplateCategories()); + } + } + + private TemplateCategories() { + //For JAXB and builder use + } + + private TemplateCategories(Set categories) { + this.categories = Sets.newLinkedHashSet(categories); + } + + @XmlElement(name = "Category") + private Set categories = Sets.newLinkedHashSet(); + + public Set getTemplateCategories() { + return Collections.unmodifiableSet(categories); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + TemplateCategories that = (TemplateCategories) o; + + if (categories != null ? !categories.equals(that.categories) : that.categories != null) + return false; + + return true; + } + + @Override + public int hashCode() { + return categories != null ? categories.hashCode() : 0; + } + + public String toString() { + return "["+ categories.toString()+"]"; + } +} diff --git a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/template/TemplateCategory.java b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/template/TemplateCategory.java new file mode 100644 index 0000000000..f34c4a043c --- /dev/null +++ b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/template/TemplateCategory.java @@ -0,0 +1,124 @@ +/** + * 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.template; + +import com.google.common.collect.Sets; +import org.jclouds.javax.annotation.Nullable; + +import javax.xml.bind.annotation.XmlElement; +import java.util.Set; + +import static com.google.common.base.Preconditions.checkNotNull; + +/** + * + * @author Jason King + */ +public class TemplateCategory { + + @SuppressWarnings("unchecked") + public static Builder builder() { + return new Builder(); + } + + public Builder toBuilder() { + return new Builder().fromTemplateCategory(this); + } + + public static class Builder { + + private String name; + private Set operatingSystems = Sets.newLinkedHashSet(); + + /** + * @see TemplateCategory#getTemplateOperatingSystems + */ + public Builder templateOperatingSystems(Set operatingSystems) { + this.operatingSystems = Sets.newLinkedHashSet(checkNotNull(operatingSystems, "operatingSystems")); + return this; + } + + /** + * @see TemplateCategory#getName + */ + public Builder name(String name) { + this.name = name; + return this; + } + + public TemplateCategory build() { + return new TemplateCategory(name,operatingSystems); + } + + public Builder fromTemplateCategory(TemplateCategory in) { + return name(in.getName()).templateOperatingSystems(in.getTemplateOperatingSystems()); + } + } + + @XmlElement(name = "Name", required = false) + private String name; + + @XmlElement(name = "OperatingSystems", required = false) + private TemplateOperatingSystems operatingSystems = TemplateOperatingSystems.builder().build(); + + private TemplateCategory(@Nullable String name, Set operatingSystems) { + this.name = name; + this.operatingSystems = TemplateOperatingSystems.builder().operatingSystems(operatingSystems).build(); + } + + protected TemplateCategory() { + //For JAXB + } + + @Nullable + public String getName() { + return name; + } + + public Set getTemplateOperatingSystems() { + return operatingSystems.getTemplateOperatingSystems(); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + TemplateCategory that = (TemplateCategory) o; + + if (name != null ? !name.equals(that.name) : that.name != null) + return false; + if (operatingSystems != null ? !operatingSystems.equals(that.operatingSystems) : that.operatingSystems != null) + return false; + + return true; + } + + @Override + public int hashCode() { + int result = name != null ? name.hashCode() : 0; + result = 31 * result + (operatingSystems != null ? operatingSystems.hashCode() : 0); + return result; + } + + @Override + public String toString() { + return "[name="+name+", +operatingSystems="+operatingSystems+"]"; + } +} \ No newline at end of file diff --git a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/template/TemplateFamilies.java b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/template/TemplateFamilies.java new file mode 100644 index 0000000000..f03e85f16e --- /dev/null +++ b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/template/TemplateFamilies.java @@ -0,0 +1,108 @@ +/** + * 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.template; + +import com.google.common.collect.Sets; + +import javax.xml.bind.annotation.XmlElement; +import java.util.Collections; +import java.util.Set; + +import static com.google.common.base.Preconditions.checkNotNull; + +/** + * Wraps individual TemplateFamily elements. + * Needed because parsing is done with JAXB and it does not handle Generic collections + * + * @author Jason King + */ +public class TemplateFamilies { + + @SuppressWarnings("unchecked") + public static Builder builder() { + return new Builder(); + } + + public Builder toBuilder() { + return new Builder().fromTemplateFamilies(this); + } + + public static class Builder { + + private Set families = Sets.newLinkedHashSet(); + + /** + * @see TemplateFamilies#getTemplateFamilies() + */ + public Builder families(Set families) { + this.families = Sets.newLinkedHashSet(checkNotNull(families, "families")); + return this; + } + + public Builder addFamily(TemplateFamily family) { + families.add(checkNotNull(family,"family")); + return this; + } + + public TemplateFamilies build() { + return new TemplateFamilies(families); + } + + public Builder fromTemplateFamilies(TemplateFamilies in) { + return families(in.getTemplateFamilies()); + } + } + + private TemplateFamilies() { + //For JAXB and builder use + } + + private TemplateFamilies(Set families) { + this.families = Sets.newLinkedHashSet(families); + } + + @XmlElement(name = "Family") + private Set families = Sets.newLinkedHashSet(); + + public Set getTemplateFamilies() { + return Collections.unmodifiableSet(families); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + TemplateFamilies that = (TemplateFamilies) o; + + if (families != null ? !families.equals(that.families) : that.families != null) + return false; + + return true; + } + + @Override + public int hashCode() { + return families != null ? families.hashCode() : 0; + } + + public String toString() { + return "["+ families.toString()+"]"; + } +} diff --git a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/template/TemplateFamily.java b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/template/TemplateFamily.java new file mode 100644 index 0000000000..f1f0f52013 --- /dev/null +++ b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/template/TemplateFamily.java @@ -0,0 +1,124 @@ +/** + * 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.template; + +import com.google.common.collect.Sets; +import org.jclouds.javax.annotation.Nullable; + +import javax.xml.bind.annotation.XmlElement; +import java.util.Set; + +import static com.google.common.base.Preconditions.checkNotNull; + +/** + * + * @author Jason King + */ +public class TemplateFamily { + + @SuppressWarnings("unchecked") + public static Builder builder() { + return new Builder(); + } + + public Builder toBuilder() { + return new Builder().fromTemplateFamily(this); + } + + public static class Builder { + + private String name; + private Set categories = Sets.newLinkedHashSet(); + + /** + * @see TemplateFamily#getTemplateCategories + */ + public Builder templateCategories(Set categories) { + this.categories = Sets.newLinkedHashSet(checkNotNull(categories, "categories")); + return this; + } + + /** + * @see TemplateFamily#getName + */ + public Builder name(String name) { + this.name = name; + return this; + } + + public TemplateFamily build() { + return new TemplateFamily(name,categories); + } + + public Builder fromTemplateFamily(TemplateFamily in) { + return name(in.getName()).templateCategories(in.getTemplateCategories()); + } + } + + @XmlElement(name = "Name", required = false) + private String name; + + @XmlElement(name = "Categories", required = false) + private TemplateCategories categories = TemplateCategories.builder().build(); + + private TemplateFamily(@Nullable String name, Set categories) { + this.name = name; + this.categories = TemplateCategories.builder().categories(categories).build(); + } + + protected TemplateFamily() { + //For JAXB + } + + @Nullable + public String getName() { + return name; + } + + public Set getTemplateCategories() { + return categories.getTemplateCategories(); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + TemplateFamily that = (TemplateFamily) o; + + if (categories != null ? !categories.equals(that.categories) : that.categories != null) + return false; + if (name != null ? !name.equals(that.name) : that.name != null) + return false; + + return true; + } + + @Override + public int hashCode() { + int result = name != null ? name.hashCode() : 0; + result = 31 * result + (categories != null ? categories.hashCode() : 0); + return result; + } + + @Override + public String toString() { + return "[name="+name+", +categories="+categories+"]"; + } +} \ No newline at end of file diff --git a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/template/TemplateOperatingSystem.java b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/template/TemplateOperatingSystem.java new file mode 100644 index 0000000000..98d5640257 --- /dev/null +++ b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/template/TemplateOperatingSystem.java @@ -0,0 +1,124 @@ +/** + * 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.template; + +import com.google.common.collect.Sets; +import org.jclouds.javax.annotation.Nullable; + +import javax.xml.bind.annotation.XmlElement; +import java.util.Set; + +import static com.google.common.base.Preconditions.checkNotNull; + +/** + * + * @author Jason King + */ +public class TemplateOperatingSystem { + + @SuppressWarnings("unchecked") + public static Builder builder() { + return new Builder(); + } + + public Builder toBuilder() { + return new Builder().fromTemplateOperatingSystem(this); + } + + public static class Builder { + + private String name; + private Set templates = Sets.newLinkedHashSet(); + + /** + * @see TemplateOperatingSystem#getTemplates + */ + public Builder templates(Set templates) { + this.templates = Sets.newLinkedHashSet(checkNotNull(templates, "templates")); + return this; + } + + /** + * @see TemplateOperatingSystem#getName + */ + public Builder name(String name) { + this.name = name; + return this; + } + + public TemplateOperatingSystem build() { + return new TemplateOperatingSystem(name,templates); + } + + public Builder fromTemplateOperatingSystem(TemplateOperatingSystem in) { + return name(in.getName()).templates(in.getTemplates()); + } + } + + @XmlElement(name = "Name", required = false) + private String name; + + @XmlElement(name = "Templates", required = false) + private TemplateReferences templates = TemplateReferences.builder().build(); + + private TemplateOperatingSystem(@Nullable String name, Set templates) { + this.name = name; + this.templates = TemplateReferences.builder().templateReferences(checkNotNull(templates,"templates")).build(); + } + + private TemplateOperatingSystem() { + //For JAXB + } + + @Nullable + public String getName() { + return name; + } + + public Set getTemplates() { + return templates.getTemplateReferences(); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + TemplateOperatingSystem that = (TemplateOperatingSystem) o; + + if (name != null ? !name.equals(that.name) : that.name != null) + return false; + if (templates != null ? !templates.equals(that.templates) : that.templates != null) + return false; + + return true; + } + + @Override + public int hashCode() { + int result = name != null ? name.hashCode() : 0; + result = 31 * result + (templates != null ? templates.hashCode() : 0); + return result; + } + + @Override + public String toString() { + return "[name="+name+", +templates="+templates+"]"; + } +} \ No newline at end of file diff --git a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/template/TemplateOperatingSystems.java b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/template/TemplateOperatingSystems.java new file mode 100644 index 0000000000..0c62e80f9d --- /dev/null +++ b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/template/TemplateOperatingSystems.java @@ -0,0 +1,108 @@ +/** + * 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.template; + +import com.google.common.collect.Sets; + +import javax.xml.bind.annotation.XmlElement; +import java.util.Collections; +import java.util.Set; + +import static com.google.common.base.Preconditions.checkNotNull; + +/** + * Wraps individual TemplateOperatingSystem elements. + * Needed because parsing is done with JAXB and it does not handle Generic collections + * + * @author Jason King + */ +public class TemplateOperatingSystems { + + @SuppressWarnings("unchecked") + public static Builder builder() { + return new Builder(); + } + + public Builder toBuilder() { + return new Builder().fromTemplateOperatingSystems(this); + } + + public static class Builder { + + private Set operatingSystems = Sets.newLinkedHashSet(); + + /** + * @see TemplateOperatingSystems#getTemplateOperatingSystems() + */ + public Builder operatingSystems(Set operatingSystems) { + this.operatingSystems = Sets.newLinkedHashSet(checkNotNull(operatingSystems, "operatingSystems")); + return this; + } + + public Builder addOperatingSystem(TemplateOperatingSystem operatingSystem) { + operatingSystems.add(checkNotNull(operatingSystem,"operatingSystem")); + return this; + } + + public TemplateOperatingSystems build() { + return new TemplateOperatingSystems(operatingSystems); + } + + public Builder fromTemplateOperatingSystems(TemplateOperatingSystems in) { + return operatingSystems(in.getTemplateOperatingSystems()); + } + } + + private TemplateOperatingSystems() { + //For JAXB and builder use + } + + private TemplateOperatingSystems(Set operatingSystems) { + this.operatingSystems = Sets.newLinkedHashSet(operatingSystems); + } + + @XmlElement(name = "OperatingSystem") + private Set operatingSystems = Sets.newLinkedHashSet(); + + public Set getTemplateOperatingSystems() { + return Collections.unmodifiableSet(operatingSystems); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + TemplateOperatingSystems that = (TemplateOperatingSystems) o; + + if (operatingSystems != null ? !operatingSystems.equals(that.operatingSystems) : that.operatingSystems != null) + return false; + + return true; + } + + @Override + public int hashCode() { + return operatingSystems != null ? operatingSystems.hashCode() : 0; + } + + public String toString() { + return "["+ operatingSystems.toString()+"]"; + } +} diff --git a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/template/TemplateReference.java b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/template/TemplateReference.java new file mode 100644 index 0000000000..e670e01f72 --- /dev/null +++ b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/template/TemplateReference.java @@ -0,0 +1,30 @@ +/** + * 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.template; + +import org.jclouds.tmrk.enterprisecloud.domain.internal.BaseNamedResource; + +/** + * @author Jason King + */ +public class TemplateReference extends BaseNamedResource { + public TemplateReference() { + //For JAXB + } +} diff --git a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/template/TemplateReferences.java b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/template/TemplateReferences.java new file mode 100644 index 0000000000..8edfb17156 --- /dev/null +++ b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/template/TemplateReferences.java @@ -0,0 +1,108 @@ +/** + * 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.template; + +import com.google.common.collect.Sets; + +import javax.xml.bind.annotation.XmlElement; +import java.util.Collections; +import java.util.Set; + +import static com.google.common.base.Preconditions.checkNotNull; + +/** + * Wraps individual TemplateReference elements. + * Needed because parsing is done with JAXB and it does not handle Generic collections + * + * @author Jason King + */ +public class TemplateReferences { + + @SuppressWarnings("unchecked") + public static Builder builder() { + return new Builder(); + } + + public Builder toBuilder() { + return new Builder().fromTemplateReferences(this); + } + + public static class Builder { + + private Set templateReferences = Sets.newLinkedHashSet(); + + /** + * @see org.jclouds.tmrk.enterprisecloud.domain.template.TemplateReferences#getTemplateReferences() + */ + public Builder templateReferences(Set templateReferences) { + this.templateReferences = Sets.newLinkedHashSet(checkNotNull(templateReferences, "templateReferences")); + return this; + } + + public Builder addTemplateReference(TemplateReference templateReference) { + templateReferences.add(checkNotNull(templateReference,"templateReference")); + return this; + } + + public TemplateReferences build() { + return new TemplateReferences(templateReferences); + } + + public Builder fromTemplateReferences(TemplateReferences in) { + return templateReferences(in.getTemplateReferences()); + } + } + + private TemplateReferences() { + //For JAXB and builder use + } + + private TemplateReferences(Set templateReferences) { + this.templateReferences = Sets.newLinkedHashSet(templateReferences); + } + + @XmlElement(name = "Template") + private Set templateReferences = Sets.newLinkedHashSet(); + + public Set getTemplateReferences() { + return Collections.unmodifiableSet(templateReferences); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + TemplateReferences that = (TemplateReferences) o; + + if (templateReferences != null ? !templateReferences.equals(that.templateReferences) : that.templateReferences != null) + return false; + + return true; + } + + @Override + public int hashCode() { + return templateReferences != null ? templateReferences.hashCode() : 0; + } + + public String toString() { + return "["+ templateReferences.toString()+"]"; + } +} diff --git a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/template/Templates.java b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/template/Templates.java index f5ea7f90a9..4010116fd9 100644 --- a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/template/Templates.java +++ b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/template/Templates.java @@ -18,6 +18,7 @@ */ package org.jclouds.tmrk.enterprisecloud.domain.template; +import com.google.common.collect.Sets; import org.jclouds.tmrk.enterprisecloud.domain.Link; import org.jclouds.tmrk.enterprisecloud.domain.Links; import org.jclouds.tmrk.enterprisecloud.domain.internal.BaseResource; @@ -32,6 +33,7 @@ import java.util.Set; import static com.google.common.base.Preconditions.checkNotNull; /** + * Templates is more than a simple wrapper as it extends BaseResource. * * @author Jason King * @@ -54,7 +56,8 @@ public class Templates extends BaseResource { } public static class Builder extends BaseResource.Builder { - private Links links = Links.builder().build(); + private Links links = Links.builder().build(); + private Set families = Sets.newLinkedHashSet(); /** * @see Templates#getLinks @@ -64,13 +67,21 @@ public class Templates extends BaseResource { return this; } + /** + * @see Templates#getTemplateFamilies + */ + public Builder families(Set families) { + this.families =(checkNotNull(families,"families")); + return this; + } + @Override public Templates build() { - return new Templates(href, type, links); + return new Templates(href, type, links, families); } public Builder fromTemplates(Templates in) { - return fromResource(in).links(in.getLinks()); + return fromResource(in).links(in.getLinks()).families(in.getTemplateFamilies()); } /** @@ -107,15 +118,19 @@ public class Templates extends BaseResource { } - @XmlElement(name = "Links", required = true) + @XmlElement(name = "Links", required = false) private Links links = Links.builder().build(); - public Templates(URI href, String type, Links links ) { + @XmlElement(name = "Families", required = false) + private TemplateFamilies families; + + private Templates(URI href, String type, Links links, Set families) { super(href, type); this.links = checkNotNull(links, "links"); + this.families = TemplateFamilies.builder().families(families).build(); } - protected Templates() { + private Templates() { //For JAXB } @@ -123,8 +138,36 @@ public class Templates extends BaseResource { return Collections.unmodifiableSet(links.getLinks()); } + public Set getTemplateFamilies() { + return families.getTemplateFamilies(); + } + + @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; + + Templates templates = (Templates) o; + + if (families != null ? !families.equals(templates.families) : templates.families != null) + return false; + if (links != null ? !links.equals(templates.links) : templates.links != null) + return false; + + return true; + } + + @Override + public int hashCode() { + int result = super.hashCode(); + result = 31 * result + (links != null ? links.hashCode() : 0); + result = 31 * result + (families != null ? families.hashCode() : 0); + return result; + } + @Override public String string() { - return super.string()+", links="+links; + return super.string()+", links="+links+", families="+families; } } \ No newline at end of file diff --git a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/features/TemplateClient.java b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/features/TemplateClient.java index b52350c0b4..f683bc6fac 100644 --- a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/features/TemplateClient.java +++ b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/features/TemplateClient.java @@ -40,7 +40,7 @@ public interface TemplateClient { /** * The Get Templates call returns information regarding templates defined in a compute pool. - * Note that Templates are not a simple wrapper around template objects. + * Note that Templates are not a simple wrapper around template objects, so if not found returns null. * Once the desired template is located getTemplate must be called to retrieve all the attached information * @param uri compute pool identifier * @return the templates diff --git a/sandbox-providers/tmrk-enterprisecloud/src/test/java/org/jclouds/tmrk/enterprisecloud/features/TemplateClientLiveTest.java b/sandbox-providers/tmrk-enterprisecloud/src/test/java/org/jclouds/tmrk/enterprisecloud/features/TemplateClientLiveTest.java new file mode 100644 index 0000000000..762d6065ee --- /dev/null +++ b/sandbox-providers/tmrk-enterprisecloud/src/test/java/org/jclouds/tmrk/enterprisecloud/features/TemplateClientLiveTest.java @@ -0,0 +1,72 @@ +/** + * 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.features; + +import org.jclouds.tmrk.enterprisecloud.domain.template.*; +import org.testng.annotations.BeforeGroups; +import org.testng.annotations.Test; + +import java.net.URI; + +import static org.testng.Assert.*; + +/** + * Tests behavior of {@code TemplateClientLiveTest} + * TODO: don't hard-code uri's it should be possible to determine them but that means chaining the tests potentially. + * @author Jason King + */ +@Test(groups = "live", testName = "TemplateClientLiveTest") +public class TemplateClientLiveTest extends BaseTerremarkEnterpriseCloudClientLiveTest { + @BeforeGroups(groups = { "live" }) + public void setupClient() { + super.setupClient(); + client = context.getApi().getTemplateClient(); + } + + private TemplateClient client; + + public void testGetTemplates() throws Exception { + Templates templates = client.getTemplates(new URI("/cloudapi/ecloud/templates/computepools/89")); + for(TemplateFamily family: templates.getTemplateFamilies()) { + for(TemplateCategory category: family.getTemplateCategories()) { + for(TemplateOperatingSystem os: category.getTemplateOperatingSystems()) { + for(TemplateReference templateReference: os.getTemplates()) { + testTemplate(templateReference); + } + } + } + } + } + + private void testTemplate(TemplateReference templateReference) { + Template template = client.getTemplate(templateReference.getHref()); + assertNotNull(template); + assertNotNull(template.getDescription()); + } + + public void testGetTemplatesWhenMissing() throws Exception { + Templates templates = client.getTemplates(new URI("/cloudapi/ecloud/templates/computepools/-1")); + assertNull(templates); + } + + public void testGetTemplateWhenMissing() throws Exception { + Template template = client.getTemplate(new URI("/cloudapi/ecloud/templates/-1/computepools/89")); + assertNull(template); + } +} diff --git a/sandbox-providers/tmrk-enterprisecloud/src/test/java/org/jclouds/tmrk/enterprisecloud/xml/TemplatesJAXBParsingTest.java b/sandbox-providers/tmrk-enterprisecloud/src/test/java/org/jclouds/tmrk/enterprisecloud/xml/TemplatesJAXBParsingTest.java new file mode 100644 index 0000000000..d198bb26a3 --- /dev/null +++ b/sandbox-providers/tmrk-enterprisecloud/src/test/java/org/jclouds/tmrk/enterprisecloud/xml/TemplatesJAXBParsingTest.java @@ -0,0 +1,138 @@ +/** + * 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.xml; + +import com.google.common.base.Function; +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Iterables; +import com.google.inject.AbstractModule; +import com.google.inject.Module; +import com.google.inject.Provides; +import org.jclouds.crypto.Crypto; +import org.jclouds.http.HttpRequest; +import org.jclouds.http.HttpResponse; +import org.jclouds.http.functions.ParseSax; +import org.jclouds.http.functions.ParseXMLWithJAXB; +import org.jclouds.logging.config.NullLoggingModule; +import org.jclouds.rest.AuthorizationException; +import org.jclouds.rest.BaseRestClientTest; +import org.jclouds.rest.RestContextSpec; +import org.jclouds.rest.internal.RestAnnotationProcessor; +import org.jclouds.tmrk.enterprisecloud.domain.ConfigurationOptionRange; +import org.jclouds.tmrk.enterprisecloud.domain.CustomizationOption; +import org.jclouds.tmrk.enterprisecloud.domain.Link; +import org.jclouds.tmrk.enterprisecloud.domain.ResourceCapacityRange; +import org.jclouds.tmrk.enterprisecloud.domain.internal.ResourceCapacity; +import org.jclouds.tmrk.enterprisecloud.domain.software.OperatingSystem; +import org.jclouds.tmrk.enterprisecloud.domain.template.*; +import org.jclouds.tmrk.enterprisecloud.features.TemplateAsyncClient; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +import javax.inject.Named; +import java.io.InputStream; +import java.lang.reflect.Method; +import java.net.URI; +import java.net.URISyntaxException; +import java.util.Set; + +import static org.jclouds.io.Payloads.newInputStreamPayload; +import static org.jclouds.rest.RestContextFactory.contextSpec; +import static org.jclouds.rest.RestContextFactory.createContextBuilder; +import static org.testng.Assert.assertEquals; + +/** + * Tests behavior of JAXB parsing for Templates + * + * @author Jason King + */ +@Test(groups = "unit", testName = "TemplatesJAXBParsingTest") +public class TemplatesJAXBParsingTest extends BaseRestClientTest { + + @BeforeClass + void setupFactory() { + RestContextSpec contextSpec = contextSpec("test", "http://localhost:9999", "1", "", "userfoo", + "credentialFoo", String.class, Integer.class, + ImmutableSet.of(new MockModule(), new NullLoggingModule(), new AbstractModule() { + + @Override + protected void configure() { + } + + @SuppressWarnings("unused") + @Provides + @Named("exception") + Set exception() { + throw new AuthorizationException(); + } + + })); + + injector = createContextBuilder(contextSpec).buildInjector(); + parserFactory = injector.getInstance(ParseSax.Factory.class); + crypto = injector.getInstance(Crypto.class); + } + + public void testParseTemplates() throws Exception { + + Method method = TemplateAsyncClient.class.getMethod("getTemplates", URI.class); + HttpRequest request = factory(TemplateAsyncClient.class).createRequest(method,new URI("/1")); + assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); + + Function parser = (Function) RestAnnotationProcessor + .createResponseParser(parserFactory, injector, method, request); + + InputStream is = getClass().getResourceAsStream("/templates.xml"); + Templates templates = parser.apply(new HttpResponse(200, "ok", newInputStreamPayload(is))); + + assertLinks(templates.getLinks()); + assertFamilies(templates.getTemplateFamilies()); + } + + private void assertLinks(Set links) { + assertEquals(links.size(),1); + Link link = Iterables.getOnlyElement(links); + assertEquals(link.getName(),"Default Compute Pool"); + } + + private void assertFamilies(Set families) { + assertEquals(families.size(),1); + TemplateFamily family = Iterables.getOnlyElement(families); + assertEquals(family.getName(),"Standard Templates"); + assertCategories(family.getTemplateCategories()); + } + + private void assertCategories(Set categories) { + assertEquals(categories.size(),1); + TemplateCategory category = Iterables.getOnlyElement(categories); + assertEquals(category.getName(),"OS Only"); + assertOperatingSystems(category.getTemplateOperatingSystems()); + } + + private void assertOperatingSystems(Set operatingSystems) { + assertEquals(operatingSystems.size(),2); + TemplateOperatingSystem windows = Iterables.get(operatingSystems, 0); + assertEquals(windows.getName(),"Windows"); + assertEquals(windows.getTemplates().size(),4); + + TemplateOperatingSystem linux = Iterables.get(operatingSystems, 1); + assertEquals(linux.getName(),"Linux"); + assertEquals(linux.getTemplates().size(),2); + } +}