http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/6ab58bd2/azurecompute/src/main/java/org/jclouds/azurecompute/domain/Disk.java ---------------------------------------------------------------------- diff --git a/azurecompute/src/main/java/org/jclouds/azurecompute/domain/Disk.java b/azurecompute/src/main/java/org/jclouds/azurecompute/domain/Disk.java new file mode 100644 index 0000000..d257709 --- /dev/null +++ b/azurecompute/src/main/java/org/jclouds/azurecompute/domain/Disk.java @@ -0,0 +1,442 @@ +/* + * 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.azurecompute.domain; + +import com.google.common.base.MoreObjects; +import com.google.common.base.MoreObjects.ToStringHelper; +import com.google.common.base.Objects; +import com.google.common.base.Optional; +import java.net.URI; + +import static com.google.common.base.Preconditions.checkNotNull; + +/** + * disk in the image repository + * + * @see <a href="http://msdn.microsoft.com/en-us/library/jj157176" >api</a> + */ +public class Disk { + public static class Attachment { + + public static Builder builder() { + return new Builder(); + } + + public Builder toBuilder() { + return builder().fromAttachment(this); + } + + public static class Builder { + + private String hostedService; + private String deployment; + private String role; + + /** + * @see Attachment#getHostedService() + */ + public Builder hostedService(String hostedService) { + this.hostedService = hostedService; + return this; + } + + /** + * @see Attachment#getDeployment() + */ + public Builder deployment(String deployment) { + this.deployment = deployment; + return this; + } + + /** + * @see Attachment#getRole() + */ + public Builder role(String role) { + this.role = role; + return this; + } + + public Attachment build() { + return new Attachment(hostedService, deployment, role); + } + + public Builder fromAttachment(Attachment in) { + return this.hostedService(in.hostedService).deployment(in.deployment).role(in.role); + } + } + + private final String hostedService; + private final String deployment; + private final String role; + + private Attachment(String hostedService, String deployment, String role) { + this.hostedService = checkNotNull(hostedService, "hostedService"); + this.deployment = checkNotNull(deployment, "deployment"); + this.role = checkNotNull(role, "role"); + } + + /** + * The deployment in which the disk is being used. + */ + public String getDeployment() { + return deployment; + } + + /** + * The hosted service in which the disk is being used. + */ + public String getHostedService() { + return hostedService; + } + + /** + * The virtual machine that the disk is attached to. + */ + public String getRole() { + return role; + } + + @Override + public int hashCode() { + return Objects.hashCode(hostedService, deployment, role); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + Attachment other = (Attachment) obj; + return Objects.equal(this.hostedService, other.hostedService) && Objects + .equal(this.deployment, other.deployment) && Objects.equal(this.role, other.role); + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this).omitNullValues().add("deployment", hostedService).add("role", role) + .toString(); + } + + } + + public static Builder builder() { + return new Builder(); + } + + public Builder toBuilder() { + return new Builder().fromHostedService(this); + } + + public static class Builder { + + private Optional<Attachment> attachedTo = Optional.absent(); + private OSType os; + private String name; + private Optional<Integer> logicalSizeInGB = Optional.absent(); + private Optional<String> description = Optional.absent(); + private Optional<String> location = Optional.absent(); + private Optional<String> affinityGroup = Optional.absent(); + private Optional<URI> mediaLink = Optional.absent(); + private Optional<String> sourceImage = Optional.absent(); + private Optional<String> label = Optional.absent(); + private boolean hasOperatingSystem; + private boolean isCorrupted; + + /** + * @see Disk#getAttachedTo() + */ + public Builder attachedTo(Attachment attachedTo) { + this.attachedTo = Optional.fromNullable(attachedTo); + return this; + } + + /** + * @see Disk#getOS() + */ + public Builder os(OSType os) { + this.os = os; + return this; + } + + /** + * @see Disk#getName() + */ + public Builder name(String name) { + this.name = name; + return this; + } + + /** + * @see Disk#getDescription() + */ + public Builder description(String description) { + this.description = Optional.fromNullable(description); + return this; + } + + /** + * @see Disk#getLogicalSizeInGB() + */ + public Builder logicalSizeInGB(Integer logicalSizeInGB) { + this.logicalSizeInGB = Optional.fromNullable(logicalSizeInGB); + return this; + } + + /** + * @see Disk#getLocation() + */ + public Builder location(String location) { + this.location = Optional.fromNullable(location); + return this; + } + + /** + * @see Disk#getAffinityGroup() + */ + public Builder affinityGroup(String affinityGroup) { + this.affinityGroup = Optional.fromNullable(affinityGroup); + return this; + } + + /** + * @see Disk#getMediaLink() + */ + public Builder mediaLink(URI mediaLink) { + this.mediaLink = Optional.fromNullable(mediaLink); + return this; + } + + /** + * @see Disk#getSourceImage() + */ + public Builder sourceImage(String sourceImage) { + this.sourceImage = Optional.fromNullable(sourceImage); + return this; + } + + /** + * @see Disk#getLabel() + */ + public Builder label(String label) { + this.label = Optional.fromNullable(label); + return this; + } + + /** + * @see Disk#hasOperatingSystem() + */ + public Builder hasOperatingSystem(boolean hasOperatingSystem) { + this.hasOperatingSystem = hasOperatingSystem; + return this; + } + + /** + * @see Disk#isCorrupted() + */ + public Builder isCorrupted(boolean isCorrupted) { + this.isCorrupted = isCorrupted; + return this; + } + + public Disk build() { + return new Disk(attachedTo, os, name, logicalSizeInGB, description, location, affinityGroup, mediaLink, + sourceImage, label, hasOperatingSystem, isCorrupted); + } + + public Builder fromHostedService(Disk in) { + return this.attachedTo(in.attachedTo.orNull()).os(in.getOS()).name(in.getName()) + .logicalSizeInGB(in.getLogicalSizeInGB().orNull()).description(in.getDescription().orNull()) + .location(in.getLocation().orNull()).affinityGroup(in.getAffinityGroup().orNull()) + .mediaLink(in.getMediaLink().orNull()).sourceImage(in.getSourceImage().orNull()) + .label(in.getLabel().orNull()).hasOperatingSystem(in.hasOperatingSystem).isCorrupted(in.isCorrupted); + } + } + + private final Optional<Attachment> attachedTo; + private final OSType os; + private final String name; + private final Optional<Integer> logicalSizeInGB; + private final Optional<String> description; + private final Optional<String> location; + private final Optional<String> affinityGroup; + private final Optional<URI> mediaLink; + private final Optional<String> sourceImage; + private final Optional<String> label; + private final boolean hasOperatingSystem; + private final boolean isCorrupted; + + private Disk(Optional<Attachment> attachedTo, OSType os, String name, Optional<Integer> logicalSizeInGB, + Optional<String> description, Optional<String> location, Optional<String> affinityGroup, + Optional<URI> mediaLink, Optional<String> sourceImage, Optional<String> label, boolean hasOperatingSystem, + boolean isCorrupted) { + this.name = checkNotNull(name, "name"); + this.attachedTo = checkNotNull(attachedTo, "attachedTo for %s", name); + this.logicalSizeInGB = checkNotNull(logicalSizeInGB, "logicalSizeInGB for %s", name); + this.description = checkNotNull(description, "description for %s", name); + this.os = checkNotNull(os, "os for %s", name); + this.location = checkNotNull(location, "location for %s", name); + this.affinityGroup = checkNotNull(affinityGroup, "affinityGroup for %s", name); + this.mediaLink = checkNotNull(mediaLink, "mediaLink for %s", name); + this.sourceImage = checkNotNull(sourceImage, "sourceImage for %s", name); + this.label = checkNotNull(label, "label for %s", name); + this.hasOperatingSystem = hasOperatingSystem; + this.isCorrupted = isCorrupted; + } + + /** + * Contains properties that specify a virtual machine that currently using the disk. A disk + * cannot be deleted as long as it is attached to a virtual machine. + */ + public Optional<Attachment> getAttachedTo() { + return attachedTo; + } + + /** + * The operating system type of the OS image. + */ + public OSType getOS() { + return os; + } + + /** + * The name of the disk. This is the name that is used when creating one or more virtual machines + * using the disk. + */ + public String getName() { + return name; + } + + /** + * The size, in GB, of the image. + */ + public Optional<Integer> getLogicalSizeInGB() { + return logicalSizeInGB; + } + + /** + * The description for the image. + */ + public Optional<String> getDescription() { + return description; + } + + /** + * The geo-location in which this media is located. The Location value is derived from storage + * account that contains the blob in which the media is located. If the storage account belongs + * to an affinity group the value is absent. + */ + public Optional<String> getLocation() { + return location; + } + + /** + * The affinity in which the media is located. The AffinityGroup value is derived from storage + * account that contains the blob in which the media is located. If the storage account does not + * belong to an affinity group the value is absent. + */ + public Optional<String> getAffinityGroup() { + return affinityGroup; + } + + /** + * The location of the blob in the blob store in which the media for the disk is located. The + * blob location belongs to a storage account in the subscription specified by the + * <subscription-id> value in the operation call. + * + * Example: + * + * http://example.blob.core.windows.net/disks/mydisk.vhd + */ + public Optional<URI> getMediaLink() { + return mediaLink; + } + + /** + * The name of the OS Image from which the disk was created. This property is populated + * automatically when a disk is created from an OS image by calling the Add Role, Create + * Deployment, or Provision Disk operations. + */ + public Optional<String> getSourceImage() { + return sourceImage; + } + + /** + * The description of the image. + */ + public Optional<String> getLabel() { + return label; + } + + /** + * Returns whether this disk contains operation system. Only disks that have an operating system + * installed can be mounted as an OS Drive. + */ + public boolean hasOperatingSystem() { + return hasOperatingSystem; + } + + /** + * Returns whether there is a consistency failure detected with this disk. If a disk fails the + * consistency check, you delete any virtual machines using it, delete the disk, and inspect the + * blob media to see if the content is intact. You can then reregister the media in the blob as a + * disk. + */ + public boolean isCorrupted() { + return isCorrupted; + } + + @Override + public int hashCode() { + return Objects.hashCode(name); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + Disk other = (Disk) obj; + return Objects.equal(this.name, other.name); + } + + @Override + public String toString() { + return string().toString(); + } + + private ToStringHelper string() { + return MoreObjects.toStringHelper(this).omitNullValues().add("os", os).add("name", name) + .add("attachedTo", attachedTo.orNull()).add("logicalSizeInGB", logicalSizeInGB.orNull()) + .add("description", description).add("location", location.orNull()) + .add("affinityGroup", affinityGroup.orNull()).add("mediaLink", mediaLink.orNull()) + .add("sourceImage", sourceImage.orNull()).add("label", label.orNull()) + .add("hasOperatingSystem", hasOperatingSystem).add("isCorrupted", isCorrupted); + } + +}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/6ab58bd2/azurecompute/src/main/java/org/jclouds/azurecompute/domain/Error.java ---------------------------------------------------------------------- diff --git a/azurecompute/src/main/java/org/jclouds/azurecompute/domain/Error.java b/azurecompute/src/main/java/org/jclouds/azurecompute/domain/Error.java new file mode 100644 index 0000000..e8947ab --- /dev/null +++ b/azurecompute/src/main/java/org/jclouds/azurecompute/domain/Error.java @@ -0,0 +1,240 @@ +/* + * 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.azurecompute.domain; + +import com.google.common.base.CaseFormat; +import com.google.common.base.MoreObjects; +import com.google.common.base.Objects; + +import static com.google.common.base.Preconditions.checkNotNull; + +/** + * additional error information that is defined by the management service. Th + * + * @see <a href="http://msdn.microsoft.com/en-us/library/ee460801" >api</a> + */ +public class Error { + + public static enum Code { + + /** + * Bad Request (400) + * + * The versioning header is not specified or was specified incorrectly. + */ + MISSING_OR_INCORRECT_VERSION_HEADER, + + /** + * Bad Request (400) + * + * The request bodyâs XML was invalid or not correctly specified. + */ + INVALID_XML_REQUEST, + + /** + * Bad Request (400) + * + * A required query parameter was not specified for this request or was specified incorrectly. + */ + MISSING_OR_INVALID_REQUIRED_QUERY_PARAMETER, + + /** + * Bad Request (400) + * + * The HTTP verb specified was not recognized by the server or isnât valid for this resource. + */ + INVALID_HTTP_VERB, + + /** + * Forbidden (403) + * + * The server failed to authenticate the request. Verify that the certificate is valid and is + * associated with this subscription. + */ + AUTHENTICATION_FAILED, + + /** + * Not Found (404) + * + * The specified resource does not exist. + */ + RESOURCE_NOT_FOUND, + + /** + * Internal Server Error (500) + * + * The server encountered an internal error. Please retry the request. + */ + INTERNAL_ERROR, + + /** + * Internal Server Error (500) + * + * The operation could not be completed within the permitted time. + */ + OPERATION_TIMED_OUT, + + /** + * Service Unavailable (503) + * + * The server (or an internal component) is currently unavailable to receive requests. Please + * retry your request + */ + SERVER_BUSY, + + /** + * Forbidden (403) + * + * The subscription is in a disabled state. + */ + SUBSCRIPTION_DISABLED, + + /** + * Bad Request (400) + * + * A parameter was incorrect. + */ + BAD_REQUEST, + + /** + * Conflict (409) + * + * A conflict occurred to prevent the operation from completing. + */ + CONFLICT_ERROR, + + UNRECOGNIZED; + + public String value() { + return CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, name()); + } + + @Override + public String toString() { + return value(); + } + + public static Code fromValue(String code) { + try { + return valueOf(CaseFormat.UPPER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE, checkNotNull(code, "code"))); + } catch (IllegalArgumentException e) { + return UNRECOGNIZED; + } + } + } + + public static Builder builder() { + return new Builder(); + } + + public Builder toBuilder() { + return builder().fromError(this); + } + + public static class Builder { + + private String rawCode; + private Code code; + private String message; + + /** + * @see Error#getRawCode() + */ + public Builder rawCode(String rawCode) { + this.rawCode = rawCode; + return this; + } + + /** + * @see Error#getCode() + */ + public Builder code(Code code) { + this.code = code; + return this; + } + + /** + * @see Error#getMessage() + */ + public Builder message(String message) { + this.message = message; + return this; + } + + public Error build() { + return new Error(rawCode, code, message); + } + + public Builder fromError(Error in) { + return this.rawCode(in.rawCode).code(in.code).message(in.message); + } + } + + private final String rawCode; + private final Code code; + private final String message; + + protected Error(String rawCode, Code code, String message) { + this.rawCode = checkNotNull(rawCode, "rawCode for %s", message); + this.code = checkNotNull(code, "code for %s", message); + this.message = checkNotNull(message, "message"); + } + + /** + * Error code + */ + public Code getCode() { + return code; + } + + /** + * Error code, unparsed + */ + public String getRawCode() { + return rawCode; + } + + /** + * User message + */ + public String getMessage() { + return message; + } + + @Override + public int hashCode() { + return Objects.hashCode(rawCode, code, message); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + Error other = (Error) obj; + return Objects.equal(this.rawCode, other.rawCode) && Objects.equal(this.code, other.code) + && Objects.equal(this.message, other.message); + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this).omitNullValues().add("code", rawCode).add("message", message).toString(); + } +} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/6ab58bd2/azurecompute/src/main/java/org/jclouds/azurecompute/domain/HostedService.java ---------------------------------------------------------------------- diff --git a/azurecompute/src/main/java/org/jclouds/azurecompute/domain/HostedService.java b/azurecompute/src/main/java/org/jclouds/azurecompute/domain/HostedService.java new file mode 100644 index 0000000..f1e0584 --- /dev/null +++ b/azurecompute/src/main/java/org/jclouds/azurecompute/domain/HostedService.java @@ -0,0 +1,184 @@ +/* + * 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.azurecompute.domain; + +import com.google.common.base.CaseFormat; +import com.google.common.base.MoreObjects; +import com.google.common.base.MoreObjects.ToStringHelper; +import com.google.common.base.Objects; +import java.net.URI; + +import static com.google.common.base.Preconditions.checkNotNull; + +/** + * System properties for the specified hosted service + * + * @see <a href="http://msdn.microsoft.com/en-us/library/gg441293" >api</a> + */ +public class HostedService { + public static enum Status { + + CREATING, + + CREATED, + + DELETING, + + DELETED, + + CHANGING, + + RESOLVING_DNS, + + UNRECOGNIZED; + + public String value() { + return CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, name()); + } + + @Override + public String toString() { + return value(); + } + + public static Status fromValue(String status) { + try { + return valueOf(CaseFormat.UPPER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE, checkNotNull(status, "status"))); + } catch (IllegalArgumentException e) { + return UNRECOGNIZED; + } + } + } + + public static Builder<?> builder() { + return new ConcreteBuilder(); + } + + public Builder<?> toBuilder() { + return new ConcreteBuilder().fromHostedService(this); + } + + public abstract static class Builder<T extends Builder<T>> { + protected abstract T self(); + + protected URI url; + protected String name; + protected HostedServiceProperties properties; + + /** + * @see HostedService#getUrl() + */ + public T url(URI url) { + this.url = url; + return self(); + } + + /** + * @see HostedService#getName() + */ + public T name(String name) { + this.name = name; + return self(); + } + + /** + * @see HostedService#getProperties() + */ + public T properties(HostedServiceProperties properties) { + this.properties = properties; + return self(); + } + + public HostedService build() { + return new HostedService(url, name, properties); + } + + public T fromHostedService(HostedService in) { + return this.url(in.getUrl()).name(in.getName()).properties(in.getProperties()); + } + } + + private static class ConcreteBuilder extends Builder<ConcreteBuilder> { + @Override + protected ConcreteBuilder self() { + return this; + } + } + + protected final URI url; + protected final String name; + protected final HostedServiceProperties properties; + + protected HostedService(URI url, String name, HostedServiceProperties properties) { + this.url = checkNotNull(url, "url"); + this.name = checkNotNull(name, "name"); + this.properties = checkNotNull(properties, "properties"); + } + + /** + * The Service Management API request URI used to perform Get Hosted Service Properties requests + * against the hosted service. + */ + public URI getUrl() { + return url; + } + + /** + * The name of the hosted service. This name is the DNS prefix name and can be used to access the + * hosted service. + * + * For example, if the service name is MyService you could access the access the service by + * calling: http://MyService.cloudapp.net + */ + public String getName() { + return name; + } + + /** + * Provides the url of the database properties to be used for this DB HostedService. + */ + public HostedServiceProperties getProperties() { + return properties; + } + + @Override + public int hashCode() { + return Objects.hashCode(url); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + HostedService other = (HostedService) obj; + return Objects.equal(this.url, other.url); + } + + @Override + public String toString() { + return string().toString(); + } + + protected ToStringHelper string() { + return MoreObjects.toStringHelper(this).omitNullValues().add("url", url).add("name", name) + .add("properties", properties); + } +} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/6ab58bd2/azurecompute/src/main/java/org/jclouds/azurecompute/domain/HostedServiceProperties.java ---------------------------------------------------------------------- diff --git a/azurecompute/src/main/java/org/jclouds/azurecompute/domain/HostedServiceProperties.java b/azurecompute/src/main/java/org/jclouds/azurecompute/domain/HostedServiceProperties.java new file mode 100644 index 0000000..4793785 --- /dev/null +++ b/azurecompute/src/main/java/org/jclouds/azurecompute/domain/HostedServiceProperties.java @@ -0,0 +1,170 @@ +/* + * 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.azurecompute.domain; + +import com.google.common.base.MoreObjects; +import com.google.common.base.MoreObjects.ToStringHelper; +import com.google.common.base.Objects; +import com.google.common.base.Optional; + +import static com.google.common.base.Preconditions.checkNotNull; + +/** + * System properties for the specified hosted service. These properties include the service name and + * service type; the name of the affinity group to which the service belongs, or its location if it + * is not part of an affinity group. + * + * @see <a href="http://msdn.microsoft.com/en-us/library/gg441293" >api</a> + */ +public class HostedServiceProperties { + public static Builder<?> builder() { + return new ConcreteBuilder(); + } + + public Builder<?> toBuilder() { + return new ConcreteBuilder().fromHostedServiceProperties(this); + } + + public abstract static class Builder<T extends Builder<T>> { + protected abstract T self(); + + protected Optional<String> description = Optional.absent(); + protected Optional<String> location = Optional.absent(); + protected Optional<String> affinityGroup = Optional.absent(); + protected String label; + + /** + * @see HostedServiceProperties#getDescription() + */ + public T description(String description) { + this.description = Optional.fromNullable(description); + return self(); + } + + /** + * @see HostedServiceProperties#getLocation() + */ + public T location(String location) { + this.location = Optional.fromNullable(location); + return self(); + } + + /** + * @see HostedServiceProperties#getAffinityGroup() + */ + public T affinityGroup(String affinityGroup) { + this.affinityGroup = Optional.fromNullable(affinityGroup); + return self(); + } + + /** + * @see HostedServiceProperties#getLabel() + */ + public T label(String label) { + this.label = label; + return self(); + } + + public HostedServiceProperties build() { + return new HostedServiceProperties(description, location, affinityGroup, label); + } + + public T fromHostedServiceProperties(HostedServiceProperties in) { + return this.description(in.getDescription().orNull()).location(in.getLocation().orNull()) + .affinityGroup(in.getAffinityGroup().orNull()).label(in.getLabel()); + } + } + + private static class ConcreteBuilder extends Builder<ConcreteBuilder> { + @Override + protected ConcreteBuilder self() { + return this; + } + } + + protected final Optional<String> description; + protected final Optional<String> location; + protected final Optional<String> affinityGroup; + protected final String label; + + protected HostedServiceProperties(Optional<String> description, Optional<String> location, + Optional<String> affinityGroup, String label) { + this.description = checkNotNull(description, "description"); + this.location = checkNotNull(location, "location"); + this.affinityGroup = checkNotNull(affinityGroup, "affinityGroup"); + this.label = checkNotNull(label, "label"); + } + + /** + * The description for the hosted service.. + */ + public Optional<String> getDescription() { + return description; + } + + /** + * The geo-location of the hosted service in Windows Azure, if the hosted service is not + * associated with an affinity group. If a location has been specified, the AffinityGroup element + * is not returned. + */ + public Optional<String> getLocation() { + return location; + } + + /** + * The affinity group with which this hosted service is associated, if any. If the service is + * associated with an affinity group, the Location element is not returned. + */ + public Optional<String> getAffinityGroup() { + return affinityGroup; + } + + /** + * The name can be up to 100 characters in length. The name can be used identify the storage account for your tracking purposes. + */ + public String getLabel() { + return label; + } + + @Override + public int hashCode() { + return Objects.hashCode(description, location, affinityGroup, label); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + HostedServiceProperties other = (HostedServiceProperties) obj; + return Objects.equal(this.description, other.description) && Objects.equal(this.location, other.location) + && Objects.equal(this.affinityGroup, other.affinityGroup) && Objects.equal(this.label, other.label); + } + + @Override + public String toString() { + return string().toString(); + } + + protected ToStringHelper string() { + return MoreObjects.toStringHelper(this).omitNullValues().add("description", description.orNull()) + .add("location", location.orNull()).add("affinityGroup", affinityGroup.orNull()).add("label", label); + } +} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/6ab58bd2/azurecompute/src/main/java/org/jclouds/azurecompute/domain/HostedServiceWithDetailedProperties.java ---------------------------------------------------------------------- diff --git a/azurecompute/src/main/java/org/jclouds/azurecompute/domain/HostedServiceWithDetailedProperties.java b/azurecompute/src/main/java/org/jclouds/azurecompute/domain/HostedServiceWithDetailedProperties.java new file mode 100644 index 0000000..66c6640 --- /dev/null +++ b/azurecompute/src/main/java/org/jclouds/azurecompute/domain/HostedServiceWithDetailedProperties.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.azurecompute.domain; + +import java.net.URI; + +public class HostedServiceWithDetailedProperties extends HostedService { + + public static Builder builder() { + return new Builder(); + } + + public Builder toBuilder() { + return new Builder().fromHostedServiceWithDetailedProperties(this); + } + + public static class Builder extends HostedService.Builder<Builder> { + + @Override + public Builder properties(HostedServiceProperties properties) { + this.properties = DetailedHostedServiceProperties.class.cast(properties); + return this; + } + + public HostedServiceWithDetailedProperties build() { + return new HostedServiceWithDetailedProperties(url, name, + DetailedHostedServiceProperties.class.cast(properties)); + } + + public Builder fromHostedServiceWithDetailedProperties(HostedServiceWithDetailedProperties in) { + return fromHostedService(in); + } + + @Override protected Builder self() { + return this; + } + } + + protected HostedServiceWithDetailedProperties(URI url, String serviceName, + DetailedHostedServiceProperties properties) { + super(url, serviceName, properties); + } + + @Override + public DetailedHostedServiceProperties getProperties() { + return DetailedHostedServiceProperties.class.cast(properties); + } + +} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/6ab58bd2/azurecompute/src/main/java/org/jclouds/azurecompute/domain/Image.java ---------------------------------------------------------------------- diff --git a/azurecompute/src/main/java/org/jclouds/azurecompute/domain/Image.java b/azurecompute/src/main/java/org/jclouds/azurecompute/domain/Image.java new file mode 100644 index 0000000..0bde175 --- /dev/null +++ b/azurecompute/src/main/java/org/jclouds/azurecompute/domain/Image.java @@ -0,0 +1,298 @@ +/* + * 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.azurecompute.domain; + +import com.google.common.base.MoreObjects; +import com.google.common.base.MoreObjects.ToStringHelper; +import com.google.common.base.Objects; +import com.google.common.base.Optional; +import com.google.common.collect.ImmutableList; +import java.net.URI; +import java.util.List; + +import static com.google.common.base.Preconditions.checkNotNull; + +/** + * OS images from the image repository + * + * @see <a href="http://msdn.microsoft.com/en-us/library/jj157191" >api</a> + */ +public class Image { + public static Builder builder() { + return new Builder(); + } + + public Builder toBuilder() { + return new Builder().fromOSImage(this); + } + + public static class Builder { + private OSType os; + private String name; + private Optional<Integer> logicalSizeInGB = Optional.absent(); + private Optional<String> description = Optional.absent(); + private Optional<String> category = Optional.absent(); + private Optional<String> location = Optional.absent(); + private Optional<String> affinityGroup = Optional.absent(); + private Optional<URI> mediaLink = Optional.absent(); + private ImmutableList.Builder<String> eula = ImmutableList.builder(); + private String label; + + /** + * @see Image#getOS() + */ + public Builder os(OSType os) { + this.os = os; + return this; + } + + /** + * @see Image#getName() + */ + public Builder name(String name) { + this.name = name; + return this; + } + + /** + * @see Image#getDescription() + */ + public Builder description(String description) { + this.description = Optional.fromNullable(description); + return this; + } + + /** + * @see Image#getLogicalSizeInGB() + */ + public Builder logicalSizeInGB(Integer logicalSizeInGB) { + this.logicalSizeInGB = Optional.fromNullable(logicalSizeInGB); + return this; + } + + /** + * @see Image#getCategory() + */ + public Builder category(String category) { + this.category = Optional.fromNullable(category); + return this; + } + + /** + * @see Image#getLocation() + */ + public Builder location(String location) { + this.location = Optional.fromNullable(location); + return this; + } + + /** + * @see Image#getAffinityGroup() + */ + public Builder affinityGroup(String affinityGroup) { + this.affinityGroup = Optional.fromNullable(affinityGroup); + return this; + } + + /** + * @see Image#getMediaLink() + */ + public Builder mediaLink(URI mediaLink) { + this.mediaLink = Optional.fromNullable(mediaLink); + return this; + } + + /** + * @see Image#getEula() + */ + public Builder eula(Iterable<String> eula) { + this.eula.addAll(eula); + return this; + } + + /** + * @see Image#getEula() + */ + public Builder eula(String eula) { + this.eula.add(eula); + return this; + } + + /** + * @see Image#getLabel() + */ + public Builder label(String label) { + this.label = label; + return this; + } + + public Image build() { + return new Image(os, name, logicalSizeInGB, description, category, location, affinityGroup, mediaLink, + eula.build(), label); + } + + public Builder fromOSImage(Image in) { + return this.os(in.getOS()).name(in.getName()).logicalSizeInGB(in.getLogicalSizeInGB().orNull()) + .description(in.getDescription().orNull()).category(in.getCategory().orNull()) + .location(in.getLocation().orNull()).affinityGroup(in.getAffinityGroup().orNull()) + .mediaLink(in.getMediaLink().orNull()).eula(in.getEula()).label(in.getLabel()); + } + } + + private final OSType os; + private final String name; + private final Optional<Integer> logicalSizeInGB; + private final Optional<String> description; + private final Optional<String> category; + private final Optional<String> location; + private final Optional<String> affinityGroup; + private final Optional<URI> mediaLink; + private final List<String> eula; + private final String label; + + private Image(OSType os, String name, Optional<Integer> logicalSizeInGB, Optional<String> description, + Optional<String> category, Optional<String> location, Optional<String> affinityGroup, Optional<URI> mediaLink, + List<String> eula, String label) { + this.name = checkNotNull(name, "name"); + this.logicalSizeInGB = checkNotNull(logicalSizeInGB, "logicalSizeInGB for %s", name); + this.description = checkNotNull(description, "description for %s", name); + this.os = checkNotNull(os, "os for %s", name); + this.category = checkNotNull(category, "category for %s", name); + this.location = checkNotNull(location, "location for %s", name); + this.affinityGroup = checkNotNull(affinityGroup, "affinityGroup for %s", name); + this.mediaLink = checkNotNull(mediaLink, "mediaLink for %s", name); + this.eula = checkNotNull(eula, "eula for %s", name); + this.label = checkNotNull(label, "label for %s", name); + } + + /** + * The operating system type of the OS image. + */ + public OSType getOS() { + return os; + } + + /** + * The name of the hosted service. This name is the DNS prefix name and can be used to access the + * hosted service. + * + * For example, if the service name is MyService you could access the access the service by + * calling: http://MyService.cloudapp.net + */ + public String getName() { + return name; + } + + /** + * The size, in GB, of the image. + */ + public Optional<Integer> getLogicalSizeInGB() { + return logicalSizeInGB; + } + + /** + * The description for the image. + */ + public Optional<String> getDescription() { + return description; + } + + /** + * The repository classification of image. All user images have the category "User", but + * categories for other images could be, for example "Canonical" + */ + public Optional<String> getCategory() { + return category; + } + + /** + * The geo-location in which this media is located. The Location value is derived from storage + * account that contains the blob in which the media is located. If the storage account belongs + * to an affinity group the value is absent. + */ + public Optional<String> getLocation() { + return location; + } + + /** + * The affinity in which the media is located. The AffinityGroup value is derived from storage + * account that contains the blob in which the media is located. If the storage account does not + * belong to an affinity group the value is absent. + */ + public Optional<String> getAffinityGroup() { + return affinityGroup; + } + + /** + * The location of the blob in the blob store in which the media for the image is located. The + * blob location belongs to a storage account in the subscription specified by the + * <subscription-id> value in the operation call. + * + * Example: + * + * http://example.blob.core.windows.net/disks/myimage.vhd + */ + public Optional<URI> getMediaLink() { + return mediaLink; + } + + /** + * The eulas for the image, if available. + */ + // Not URI as some providers put non-uri data in, such as riverbed. + public List<String> getEula() { + return eula; + } + + /** + * The description of the image. + */ + public String getLabel() { + return label; + } + + @Override + public int hashCode() { + return Objects.hashCode(name); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + Image other = (Image) obj; + return Objects.equal(this.name, other.name); + } + + @Override + public String toString() { + return string().toString(); + } + + private ToStringHelper string() { + return MoreObjects.toStringHelper(this).omitNullValues().add("os", os).add("name", name) + .add("logicalSizeInGB", logicalSizeInGB.orNull()).add("description", description) + .add("category", category.orNull()).add("location", location.orNull()) + .add("affinityGroup", affinityGroup.orNull()).add("mediaLink", mediaLink.orNull()) + .add("eula", eula).add("label", label); + } + +} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/6ab58bd2/azurecompute/src/main/java/org/jclouds/azurecompute/domain/ImageParams.java ---------------------------------------------------------------------- diff --git a/azurecompute/src/main/java/org/jclouds/azurecompute/domain/ImageParams.java b/azurecompute/src/main/java/org/jclouds/azurecompute/domain/ImageParams.java new file mode 100644 index 0000000..3de38a5 --- /dev/null +++ b/azurecompute/src/main/java/org/jclouds/azurecompute/domain/ImageParams.java @@ -0,0 +1,165 @@ +/* + * 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.azurecompute.domain; + +import com.google.common.base.MoreObjects; +import com.google.common.base.MoreObjects.ToStringHelper; +import com.google.common.base.Objects; +import java.net.URI; + +import static com.google.common.base.Preconditions.checkNotNull; + +/** + * The Add OS Image operation adds an OS image that is currently stored in a storage account in your + * subscription to the image repository. + * + * @see <a href="http://msdn.microsoft.com/en-us/library/jj157191" >api</a> + */ +public class ImageParams { + + public static Builder builder() { + return new Builder(); + } + + public Builder toBuilder() { + return builder().fromImageParams(this); + } + + public static class Builder { + private String label; + private URI mediaLink; + private OSType os; + private String name; + + /** + * @see ImageParams#getLabel() + */ + public Builder label(String label) { + this.label = label; + return this; + } + + /** + * @see ImageParams#getMediaLink() + */ + public Builder mediaLink(URI mediaLink) { + this.mediaLink = mediaLink; + return this; + } + + /** + * @see ImageParams#getName() + */ + public Builder name(String name) { + this.name = name; + return this; + } + + /** + * @see ImageParams#getOS() + */ + public Builder os(OSType os) { + this.os = os; + return this; + } + + public ImageParams build() { + return new ImageParams(label, mediaLink, name, os); + } + + public Builder fromImageParams(ImageParams in) { + return this.label(in.getLabel()).mediaLink(in.getMediaLink()).name(in.getName()).os(in.getOS()); + } + } + + private final String label; + private final URI mediaLink; + private final String name; + private final OSType os; + + private ImageParams(String label, URI mediaLink, String name, OSType os) { + this.label = checkNotNull(label, "label"); + this.name = checkNotNull(name, "name for %s", label); + this.mediaLink = checkNotNull(mediaLink, "mediaLink for %s", label); + this.os = checkNotNull(os, "os for %s", label); + } + + /** + * The operating system type of the OS image. + */ + public OSType getOS() { + return os; + } + + /** + * The name of the hosted service. This name is the DNS prefix name and can be used to access the + * hosted service. + * + * For example, if the service name is MyService you could access the access the service by + * calling: http://MyService.cloudapp.net + */ + public String getName() { + return name; + } + + /** + * The location of the blob in the blob store in which the media for the image is located. The + * blob location belongs to a storage account in the subscription specified by the + * <subscription-id> value in the operation call. + * + * Example: + * + * http://example.blob.core.windows.net/disks/myimage.vhd + */ + public URI getMediaLink() { + return mediaLink; + } + + /** + * The description of the image. + */ + public String getLabel() { + return label; + } + + @Override + public int hashCode() { + return Objects.hashCode(name); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + ImageParams other = (ImageParams) obj; + return Objects.equal(this.name, other.name); + } + + @Override + public String toString() { + return string().toString(); + } + + private ToStringHelper string() { + return MoreObjects.toStringHelper(this).add("label", label).add("mediaLink", mediaLink).add("name", name) + .add("os", os); + } +} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/6ab58bd2/azurecompute/src/main/java/org/jclouds/azurecompute/domain/InputEndpoint.java ---------------------------------------------------------------------- diff --git a/azurecompute/src/main/java/org/jclouds/azurecompute/domain/InputEndpoint.java b/azurecompute/src/main/java/org/jclouds/azurecompute/domain/InputEndpoint.java new file mode 100644 index 0000000..a06c0f5 --- /dev/null +++ b/azurecompute/src/main/java/org/jclouds/azurecompute/domain/InputEndpoint.java @@ -0,0 +1,137 @@ +/* + * 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.azurecompute.domain; + +public class InputEndpoint { + + public static Builder builder() { + return new Builder(); + } + + public static class Builder { + private Integer localPort; + private Integer externalPort; + private String name; + private Protocol protocol; + + public Builder localPort(Integer localPort) { + this.localPort = localPort; + return this; + } + + public Builder externalPort(Integer externalPort) { + this.externalPort = externalPort; + return this; + } + + public Builder name(String name) { + this.name = name; + return this; + } + + public Builder protocol(Protocol protocol) { + this.protocol = protocol; + return this; + } + + public InputEndpoint build(){ + return new InputEndpoint(localPort, externalPort, name, protocol); + } + + } + + private final Integer localPort; + private final Integer externalPort; + private final String name; + private final Protocol protocol; + + public InputEndpoint(Integer localPort, Integer externalPort, String name, + Protocol protocol) { + super(); + this.localPort = localPort; + this.externalPort = externalPort; + this.name = name; + this.protocol = protocol; + } + + public Integer getLocalPort() { + return localPort; + } + + public Integer getExternalPort() { + return externalPort; + } + + public String getName() { + return name; + } + + public Protocol getProtocol() { + return protocol; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + + ((externalPort == null) ? 0 : externalPort.hashCode()); + result = prime * result + + ((localPort == null) ? 0 : localPort.hashCode()); + result = prime * result + ((name == null) ? 0 : name.hashCode()); + result = prime * result + + ((protocol == null) ? 0 : protocol.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + InputEndpoint other = (InputEndpoint) obj; + if (externalPort == null) { + if (other.externalPort != null) + return false; + } else if (!externalPort.equals(other.externalPort)) + return false; + if (localPort == null) { + if (other.localPort != null) + return false; + } else if (!localPort.equals(other.localPort)) + return false; + if (name == null) { + if (other.name != null) + return false; + } else if (!name.equals(other.name)) + return false; + if (protocol != other.protocol) + return false; + return true; + } + + @Override + public String toString() { + return "InputEndPoint [localPort=" + localPort + ", externalPort=" + + externalPort + ", name=" + name + ", protocol=" + protocol + + "]"; + } + +} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/6ab58bd2/azurecompute/src/main/java/org/jclouds/azurecompute/domain/InstanceStatus.java ---------------------------------------------------------------------- diff --git a/azurecompute/src/main/java/org/jclouds/azurecompute/domain/InstanceStatus.java b/azurecompute/src/main/java/org/jclouds/azurecompute/domain/InstanceStatus.java new file mode 100644 index 0000000..51b5d24 --- /dev/null +++ b/azurecompute/src/main/java/org/jclouds/azurecompute/domain/InstanceStatus.java @@ -0,0 +1,155 @@ +/* + * 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.azurecompute.domain; + +import com.google.common.base.CaseFormat; + +import static com.google.common.base.Preconditions.checkNotNull; + +public enum InstanceStatus { + + /** + * The role state is currently unknown. The state should automatically be + * resolved once the role state is detected, so no action is required. + */ + ROLE_STATE_UNKNOWN, + + /** + * The host agent is currently creating resources for the Virtual Machine + * (VM). + */ + CREATING_V_M, + + /** + * The host agent is starting the Virtual Machine. + */ + STARTING_V_M, + + /** + * Windows Azure is creating resources for the role. + */ + CREATING_ROLE, + + /** + * Windows Azure is starting the role. + */ + STARTING_ROLE, + + /** + * The role instance has started and is ready to be used. + */ + READY_ROLE, + + /** + * The role instance is unavailable for requests. This state is usually + * generated while the role is being created or stopped. + */ + BUSY_ROLE, + + /** + * Windows Azure is stopping the role. + */ + STOPPING_ROLE, + + /** + * The host agent is stopping the Virtual Machine. This status also + * indicates that the role has already been stopped. + */ + STOPPING_V_M, + + /** + * The Virtual Machine is being deleted by the host agent. + */ + DELETING_V_M, + + /** + * The Virtual Machine is not running. This is the final state of the + * shutdown process, and no other status messages should be received after + * StoppedVM. + */ + STOPPED_V_M, + + /** + * The role has unexpectedly stopped or has failed to start. This status + * indicates that there is a problem with the role that is causing it to + * crash or preventing it from starting, and must be corrected before the + * role can be started. The InstanceStateDetails and InstanceErrorCode + * fields can hold information about the role error that caused this state, + * which may be useful for identifying and debugging the problem. + */ + RESTARTING_ROLE, + + /** + * The role has continually crashed after being started by Windows Azure. + * This status indicates that there is a problem with the role that prevents + * it from starting, and may be generated after the StartingRole even + * ReadyRole statuses are received. The problem in the role must be found + * and corrected before the role can be started. The InstanceStateDetails + * and InstanceErrorCode fields can hold information about the role error + * that caused this state, which may be useful for identifying and debugging + * the problem. + */ + CYCLING_ROLE, + + /** + * The role has continually failed to start. This status indicates that + * there is a problem with the role that prevents it from starting, and may + * be generated after the process returns StartingRole. The problem in the + * role must be found and corrected before the role can be started. The + * InstanceStateDetails and InstanceErrorCode fields can hold information + * about the role error that caused this state, which may be useful for + * identifying and debugging the problem. + */ + FAILED_STARTING_ROLE, + + /** + * A Windows Azure or container error is preventing the Virtual Machine from + * starting. This status is generated by Windows Azure, and does not + * indicate an error with the role. It may be generated after the + * StartingRole state. + */ + FAILED_STARTING_V_M, + + /** + * The role has timed out before receiving a status message and is not + * responding to requests. + */ + UNRESPONSIVE_ROLE, + + /** + * UNDOCUMENTED BY AZURE + */ + PROVISIONING; + + public String value() { + return CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, name()); + } + + @Override + public String toString() { + return value(); + } + + public static InstanceStatus fromValue(String type) { + try { + return valueOf(CaseFormat.UPPER_CAMEL.to( + CaseFormat.UPPER_UNDERSCORE, checkNotNull(type, "type"))); + } catch (IllegalArgumentException e) { + return ROLE_STATE_UNKNOWN; + } + } +} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/6ab58bd2/azurecompute/src/main/java/org/jclouds/azurecompute/domain/Location.java ---------------------------------------------------------------------- diff --git a/azurecompute/src/main/java/org/jclouds/azurecompute/domain/Location.java b/azurecompute/src/main/java/org/jclouds/azurecompute/domain/Location.java new file mode 100644 index 0000000..2b51a58 --- /dev/null +++ b/azurecompute/src/main/java/org/jclouds/azurecompute/domain/Location.java @@ -0,0 +1,150 @@ +/* + * 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.azurecompute.domain; + +import com.google.common.base.MoreObjects; +import com.google.common.base.Objects; +import com.google.common.collect.ImmutableSet; +import java.util.Set; + +import static com.google.common.base.Preconditions.checkNotNull; + +/** + * + * A geographical region in which a service or storage account will be hosted. + * + * @see <a href="http://msdn.microsoft.com/en-us/library/gg441293" >api</a> + */ +public class Location { + public static Builder builder() { + return new Builder(); + } + + public Builder toBuilder() { + return builder().fromLocation(this); + } + + public static class Builder { + + private String name; + private String displayName; + private ImmutableSet.Builder<String> availableServices = ImmutableSet.<String> builder(); + + /** + * @see Location#getName() + */ + public Builder name(String name) { + this.name = name; + return this; + } + + /** + * @see Location#getDisplayName() + */ + public Builder displayName(String displayName) { + this.displayName = displayName; + return this; + } + + /** + * @see Location#getAvailableServices() + */ + public Builder addAvailableService(String availableService) { + this.availableServices.add(checkNotNull(availableService, "availableService")); + return this; + } + + /** + * @see Location#getAvailableServices() + */ + public Builder availableServices(Iterable<String> availableServices) { + this.availableServices = ImmutableSet.<String> builder().addAll( + checkNotNull(availableServices, "availableServices")); + return this; + } + + public Location build() { + return new Location(name, displayName, availableServices.build()); + } + + public Builder fromLocation(Location in) { + return this.name(in.getName()).displayName(in.getDisplayName()).availableServices(in.getAvailableServices()); + } + } + + private final String name; + private final String displayName; + private final Set<String> availableServices; + + protected Location(String name, String displayName, Iterable<String> availableServices) { + this.name = checkNotNull(name, "name"); + this.displayName = checkNotNull(displayName, "displayName for %s", name); + this.availableServices = ImmutableSet.copyOf(checkNotNull(availableServices, "availableServices for %s", name)); + } + + /** + * + * The name of a data center location that is valid for your subscription. For example: + * {@code West Europe} + */ + public String getName() { + return name; + } + + /** + * The localized name of data center location. + */ + public String getDisplayName() { + return displayName; + } + + /** + * Indicates the services available at a location. + * + * Returned values are none, one, or both of the values listed below. + * + * Compute + * + * Storage + */ + public Set<String> getAvailableServices() { + return availableServices; + } + + @Override + public int hashCode() { + return Objects.hashCode(name); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + Location other = (Location) obj; + return Objects.equal(this.name, other.name); + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this).omitNullValues().add("name", name).add("displayName", displayName) + .add("availableServices", availableServices).toString(); + } +} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/6ab58bd2/azurecompute/src/main/java/org/jclouds/azurecompute/domain/OSType.java ---------------------------------------------------------------------- diff --git a/azurecompute/src/main/java/org/jclouds/azurecompute/domain/OSType.java b/azurecompute/src/main/java/org/jclouds/azurecompute/domain/OSType.java new file mode 100644 index 0000000..fd85bde --- /dev/null +++ b/azurecompute/src/main/java/org/jclouds/azurecompute/domain/OSType.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.azurecompute.domain; + +import com.google.common.base.CaseFormat; + +import static com.google.common.base.Preconditions.checkNotNull; + +public enum OSType { + + LINUX, + + WINDOWS, + + UNRECOGNIZED; + + public String value() { + return CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, name()); + } + + @Override + public String toString() { + return value(); + } + + public static OSType fromValue(String type) { + try { + return valueOf(CaseFormat.UPPER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE, checkNotNull(type, "type"))); + } catch (IllegalArgumentException e) { + return UNRECOGNIZED; + } + } +} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/6ab58bd2/azurecompute/src/main/java/org/jclouds/azurecompute/domain/Operation.java ---------------------------------------------------------------------- diff --git a/azurecompute/src/main/java/org/jclouds/azurecompute/domain/Operation.java b/azurecompute/src/main/java/org/jclouds/azurecompute/domain/Operation.java new file mode 100644 index 0000000..eb336f4 --- /dev/null +++ b/azurecompute/src/main/java/org/jclouds/azurecompute/domain/Operation.java @@ -0,0 +1,200 @@ +/* + * 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.azurecompute.domain; + +import com.google.common.base.CaseFormat; +import com.google.common.base.MoreObjects; +import com.google.common.base.Objects; +import com.google.common.base.Optional; + +import static com.google.common.base.Preconditions.checkNotNull; + +/** + * + * Determines whether the operation has succeeded, failed, or is still in progress. + * + * @see <a href="http://msdn.microsoft.com/en-us/library/ee460783" >api</a> + */ +public class Operation { + + public static enum Status { + + IN_PROGRESS, + + SUCCEEDED, + + FAILED, + + UNRECOGNIZED; + + public String value() { + return CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, name()); + } + + @Override + public String toString() { + return value(); + } + + public static Status fromValue(String status) { + try { + return valueOf(CaseFormat.UPPER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE, checkNotNull(status, "status"))); + } catch (IllegalArgumentException e) { + return UNRECOGNIZED; + } + } + } + + public static Builder builder() { + return new Builder(); + } + + public Builder toBuilder() { + return builder().fromOperation(this); + } + + public static class Builder { + + private String id; + private String rawStatus; + private Status status; + // When the operation is in progress, no status code is returned + private Optional<Integer> httpStatusCode = Optional.absent(); + private Optional<Error> error = Optional.absent(); + + /** + * @see Operation#getId() + */ + public Builder id(String id) { + this.id = id; + return this; + } + + /** + * @see Operation#getRawStatus() + */ + public Builder rawStatus(String rawStatus) { + this.rawStatus = rawStatus; + return this; + } + + /** + * @see Operation#getStatus() + */ + public Builder status(Status status) { + this.status = status; + return this; + } + + /** + * @see Operation#getHttpStatusCode() + */ + public Builder httpStatusCode(Integer httpStatusCode) { + this.httpStatusCode = Optional.fromNullable(httpStatusCode); + return this; + } + + /** + * @see Operation#getError() + */ + public Builder error(Error error) { + this.error = Optional.fromNullable(error); + return this; + } + + public Operation build() { + return new Operation(id, rawStatus, status, httpStatusCode, error); + } + + public Builder fromOperation(Operation in) { + return this.id(in.id).rawStatus(in.rawStatus).status(in.status).httpStatusCode(in.httpStatusCode.orNull()) + .error(in.error.orNull()); + } + } + + private final String id; + private final String rawStatus; + private final Status status; + private final Optional<Integer> httpStatusCode; + private final Optional<Error> error; + + protected Operation(String id, String rawStatus, Status status, Optional<Integer> httpStatusCode, Optional<Error> error) { + this.id = checkNotNull(id, "id"); + this.rawStatus = checkNotNull(rawStatus, "rawStatus for %s", id); + this.status = checkNotNull(status, "status for %s", id); + this.httpStatusCode = checkNotNull(httpStatusCode, "httpStatusCode for %s", id); + this.error = checkNotNull(error, "error for %s", id); + } + + /** + * The request ID of the asynchronous request. + */ + public String getId() { + return id; + } + + /** + * The status of the asynchronous request. + */ + public Status getStatus() { + return status; + } + + /** + * The status of the asynchronous request, unparsed + */ + public String getRawStatus() { + return rawStatus; + } + + /** + * The HTTP status code for the asynchronous request. + */ + public Optional<Integer> getHttpStatusCode() { + return httpStatusCode; + } + + /** + * The management service error returned if the asynchronous request failed. + */ + public Optional<Error> getError() { + return error; + } + + @Override + public int hashCode() { + return Objects.hashCode(id); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + Operation other = (Operation) obj; + return Objects.equal(this.id, other.id); + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this).omitNullValues().add("id", id).add("status", rawStatus) + .add("httpStatusCode", httpStatusCode).add("error", error.orNull()).toString(); + } +} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/6ab58bd2/azurecompute/src/main/java/org/jclouds/azurecompute/domain/Protocol.java ---------------------------------------------------------------------- diff --git a/azurecompute/src/main/java/org/jclouds/azurecompute/domain/Protocol.java b/azurecompute/src/main/java/org/jclouds/azurecompute/domain/Protocol.java new file mode 100644 index 0000000..add7ee0 --- /dev/null +++ b/azurecompute/src/main/java/org/jclouds/azurecompute/domain/Protocol.java @@ -0,0 +1,31 @@ +/* + * 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.azurecompute.domain; + +import javax.xml.bind.annotation.XmlEnum; +import javax.xml.bind.annotation.XmlEnumValue; +import javax.xml.bind.annotation.XmlType; + +@XmlType(name = "Protocol") @XmlEnum +public enum Protocol { + @XmlEnumValue("tcp") + TCP, + @XmlEnumValue("http") + HTTP, + @XmlEnumValue("udp") + UDP +} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/6ab58bd2/azurecompute/src/main/java/org/jclouds/azurecompute/domain/RoleSize.java ---------------------------------------------------------------------- diff --git a/azurecompute/src/main/java/org/jclouds/azurecompute/domain/RoleSize.java b/azurecompute/src/main/java/org/jclouds/azurecompute/domain/RoleSize.java new file mode 100644 index 0000000..6839091 --- /dev/null +++ b/azurecompute/src/main/java/org/jclouds/azurecompute/domain/RoleSize.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.azurecompute.domain; + +import com.google.common.base.CaseFormat; + +import static com.google.common.base.Preconditions.checkNotNull; + +public enum RoleSize { + EXTRA_SMALL, SMALL, MEDIUM, LARGE, EXTRA_LARGE; + + public String value() { + return CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, name()); + } + + @Override + public String toString() { + return value(); + } + + public static RoleSize fromValue(String type) { + try { + return valueOf(CaseFormat.UPPER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE, checkNotNull(type, "type"))); + } catch (IllegalArgumentException e) { + return null; + } + } +} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/6ab58bd2/azurecompute/src/main/java/org/jclouds/azurecompute/features/DeploymentApi.java ---------------------------------------------------------------------- diff --git a/azurecompute/src/main/java/org/jclouds/azurecompute/features/DeploymentApi.java b/azurecompute/src/main/java/org/jclouds/azurecompute/features/DeploymentApi.java new file mode 100644 index 0000000..ada88ac --- /dev/null +++ b/azurecompute/src/main/java/org/jclouds/azurecompute/features/DeploymentApi.java @@ -0,0 +1,80 @@ +/* + * 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.azurecompute.features; + +import javax.inject.Named; +import javax.ws.rs.Consumes; +import javax.ws.rs.DELETE; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; +import org.jclouds.azurecompute.binders.BindDeploymentParamsToXmlPayload; +import org.jclouds.azurecompute.domain.Deployment; +import org.jclouds.azurecompute.domain.DeploymentParams; +import org.jclouds.azurecompute.functions.ParseRequestIdHeader; +import org.jclouds.azurecompute.xml.DeploymentHandler; +import org.jclouds.rest.annotations.BinderParam; +import org.jclouds.rest.annotations.Fallback; +import org.jclouds.rest.annotations.Headers; +import org.jclouds.rest.annotations.ResponseParser; +import org.jclouds.rest.annotations.XMLResponseParser; + +import static org.jclouds.Fallbacks.NullOnNotFoundOr404; + +@Path("/services/hostedservices/{serviceName}/deployments") +@Headers(keys = "x-ms-version", values = "{jclouds.api-version}") +@Consumes(MediaType.APPLICATION_XML) +public interface DeploymentApi { + + /** + * The Get Deployment operation returns the specified deployment from Windows Azure. + * + * @param name + * the unique DNS Prefix value in the Windows Azure Management Portal + */ + @Named("GetDeployment") + @GET + @Path("/{name}") + @XMLResponseParser(DeploymentHandler.class) + @Fallback(NullOnNotFoundOr404.class) + Deployment get(@PathParam("name") String name); + + /** + * http://msdn.microsoft.com/en-us/library/jj157194 + */ + @Named("CreateVirtualMachineDeployment") + @POST + @Produces(MediaType.APPLICATION_XML) + @ResponseParser(ParseRequestIdHeader.class) + String create(@BinderParam(BindDeploymentParamsToXmlPayload.class) DeploymentParams deploymentParams); + + /** + * The Delete Deployment operation deletes the specified deployment from Windows Azure. + * + * @param name + * the unique DNS Prefix value in the Windows Azure Management Portal + */ + @Named("DeleteDeployment") + @DELETE + @Path("/{name}") + @Fallback(NullOnNotFoundOr404.class) + @ResponseParser(ParseRequestIdHeader.class) + String delete(@PathParam("name") String name); +} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/6ab58bd2/azurecompute/src/main/java/org/jclouds/azurecompute/features/DiskApi.java ---------------------------------------------------------------------- diff --git a/azurecompute/src/main/java/org/jclouds/azurecompute/features/DiskApi.java b/azurecompute/src/main/java/org/jclouds/azurecompute/features/DiskApi.java new file mode 100644 index 0000000..1d43707 --- /dev/null +++ b/azurecompute/src/main/java/org/jclouds/azurecompute/features/DiskApi.java @@ -0,0 +1,69 @@ +/* + * 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.azurecompute.features; + +import java.util.List; +import javax.inject.Named; +import javax.ws.rs.Consumes; +import javax.ws.rs.DELETE; +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.core.MediaType; +import org.jclouds.azurecompute.domain.Disk; +import org.jclouds.azurecompute.functions.ParseRequestIdHeader; +import org.jclouds.azurecompute.xml.ListDisksHandler; +import org.jclouds.rest.annotations.Fallback; +import org.jclouds.rest.annotations.Headers; +import org.jclouds.rest.annotations.ResponseParser; +import org.jclouds.rest.annotations.XMLResponseParser; + +import static org.jclouds.Fallbacks.EmptyListOnNotFoundOr404; +import static org.jclouds.Fallbacks.NullOnNotFoundOr404; + +/** + * The Service Management API includes operations for managing the disks in your subscription. + * + * @see <a href="http://msdn.microsoft.com/en-us/library/jj157188">docs</a> + */ +@Path("/services/disks") +@Headers(keys = "x-ms-version", values = "{jclouds.api-version}") +@Consumes(MediaType.APPLICATION_XML) +public interface DiskApi { + + /** + * The List Disks operation retrieves a list of the disks in your image repository. + */ + @Named("ListDisks") + @GET + @XMLResponseParser(ListDisksHandler.class) + @Fallback(EmptyListOnNotFoundOr404.class) + List<Disk> list(); + + /** + * The Delete Disk operation deletes the specified data or operating system disk from your image + * repository. + * + * @return request id or null, if not found + */ + @Named("DeleteDisk") + @DELETE + @Path("/{diskName}") + @Fallback(NullOnNotFoundOr404.class) + @ResponseParser(ParseRequestIdHeader.class) + String delete(@PathParam("diskName") String diskName); +}
