You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jclouds.apache.org by ad...@apache.org on 2014/10/20 21:55:51 UTC
[01/11] git commit: Fix osgi export.
Repository: jclouds-labs
Updated Branches:
refs/heads/master c005ff7d0 -> 20c397c7f
Fix osgi export.
Project: http://git-wip-us.apache.org/repos/asf/jclouds-labs/repo
Commit: http://git-wip-us.apache.org/repos/asf/jclouds-labs/commit/cd552012
Tree: http://git-wip-us.apache.org/repos/asf/jclouds-labs/tree/cd552012
Diff: http://git-wip-us.apache.org/repos/asf/jclouds-labs/diff/cd552012
Branch: refs/heads/master
Commit: cd552012f5b8da130f50e5b1a36417113373beb2
Parents: c005ff7
Author: Adrian Cole <ad...@gmail.com>
Authored: Thu Oct 16 09:01:10 2014 -0700
Committer: Adrian Cole <ac...@twitter.com>
Committed: Mon Oct 20 13:25:10 2014 -0400
----------------------------------------------------------------------
azurecompute/pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/cd552012/azurecompute/pom.xml
----------------------------------------------------------------------
diff --git a/azurecompute/pom.xml b/azurecompute/pom.xml
index bd4a90f..7cba08d 100644
--- a/azurecompute/pom.xml
+++ b/azurecompute/pom.xml
@@ -39,7 +39,7 @@
<test.azurecompute.build-version />
<test.azurecompute.identity>/path/to/cert.p12</test.azurecompute.identity>
<test.azurecompute.credential>password to cert</test.azurecompute.credential>
- <jclouds.osgi.export>org.jclouds.azure.management*;version="${project.version}"</jclouds.osgi.export>
+ <jclouds.osgi.export>org.jclouds.azurecompute*;version="${project.version}"</jclouds.osgi.export>
<jclouds.osgi.import>org.jclouds*;version="${project.version}",*</jclouds.osgi.import>
</properties>
[09/11] git commit: Fixed README bug.
Posted by ad...@apache.org.
Fixed README bug.
Project: http://git-wip-us.apache.org/repos/asf/jclouds-labs/repo
Commit: http://git-wip-us.apache.org/repos/asf/jclouds-labs/commit/ff9d3cee
Tree: http://git-wip-us.apache.org/repos/asf/jclouds-labs/tree/ff9d3cee
Diff: http://git-wip-us.apache.org/repos/asf/jclouds-labs/diff/ff9d3cee
Branch: refs/heads/master
Commit: ff9d3ceee792f727853b433bf45afbe5dea4312c
Parents: 14207a3
Author: Adrian Cole <ac...@twitter.com>
Authored: Sat Oct 18 10:04:48 2014 -0400
Committer: Adrian Cole <ac...@twitter.com>
Committed: Mon Oct 20 13:26:53 2014 -0400
----------------------------------------------------------------------
azurecompute/README.md | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/ff9d3cee/azurecompute/README.md
----------------------------------------------------------------------
diff --git a/azurecompute/README.md b/azurecompute/README.md
index 022abde..b1a9f61 100644
--- a/azurecompute/README.md
+++ b/azurecompute/README.md
@@ -12,7 +12,7 @@ openssl pkcs12 -export -out $HOME/.jclouds/azure.p12 -in $HOME/.jclouds/azure.pe
# create a cer file which you upload to the management console to authorize this certificate.
# https://manage.windowsazure.com/@ignasibarreragmail.onmicrosoft.com#Workspaces/AdminTasks/ListManagementCertificates
# note you need to press command+shift+. to display hidden directories in a open dialog in osx
-openssl x509 -inform pem -in $HOME/.jclouds/azure.p12 -outform der -out $HOME/.jclouds/azure.cer
+openssl x509 -inform pem -in $HOME/.jclouds/azure.pem -outform der -out $HOME/.jclouds/azure.cer
```
Once you do this, you will set the following to run the live tests.
@@ -20,4 +20,4 @@ Once you do this, you will set the following to run the live tests.
mvn -Plive -Dtest.jclouds.azurecompute.subscription-id=12345678-abcd-dcba-abdc-ba0987654321
-Dtest.azurecompute.credential=P12_EXPORT_PASSWORD
-Dtest.azurecompute.identity=$HOME/.jclouds/azure.p12
-```
\ No newline at end of file
+```
[07/11] git commit: Cleanup output-only Disk object.
Posted by ad...@apache.org.
Cleanup output-only Disk object.
Project: http://git-wip-us.apache.org/repos/asf/jclouds-labs/repo
Commit: http://git-wip-us.apache.org/repos/asf/jclouds-labs/commit/da40d636
Tree: http://git-wip-us.apache.org/repos/asf/jclouds-labs/tree/da40d636
Diff: http://git-wip-us.apache.org/repos/asf/jclouds-labs/diff/da40d636
Branch: refs/heads/master
Commit: da40d636bbfee47d07ef6ffefc9a22c3367dd45b
Parents: caf57cc
Author: Adrian Cole <ac...@twitter.com>
Authored: Sun Oct 19 10:34:30 2014 -0400
Committer: Adrian Cole <ac...@twitter.com>
Committed: Mon Oct 20 13:26:53 2014 -0400
----------------------------------------------------------------------
.../org/jclouds/azurecompute/domain/Disk.java | 446 +++++--------------
.../azurecompute/xml/AttachmentHandler.java | 36 +-
.../jclouds/azurecompute/xml/DiskHandler.java | 151 ++++---
.../azurecompute/xml/ListDisksHandler.java | 35 +-
.../azurecompute/features/DiskApiLiveTest.java | 74 ++-
.../azurecompute/features/DiskApiMockTest.java | 19 +-
.../azurecompute/parse/ListDisksTest.java | 71 ---
.../azurecompute/xml/ListDisksHandlerTest.java | 67 +++
azurecompute/src/test/resources/disks.xml | 6 +-
9 files changed, 332 insertions(+), 573 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/da40d636/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
index d257709..6590330 100644
--- a/azurecompute/src/main/java/org/jclouds/azurecompute/domain/Disk.java
+++ b/azurecompute/src/main/java/org/jclouds/azurecompute/domain/Disk.java
@@ -16,103 +16,56 @@
*/
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.Objects.equal;
+import static com.google.common.base.Objects.toStringHelper;
+import static com.google.common.base.Preconditions.checkNotNull;
+
import java.net.URI;
-import static com.google.common.base.Preconditions.checkNotNull;
+import org.jclouds.javax.annotation.Nullable;
+
+import com.google.common.base.Objects;
/**
- * disk in the image repository
+ * A 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 final class Disk {
+ public static final class Attachment {
+ /** The deployment in which the disk is being used. */
+ public String deployment() {
+ return deployment;
}
- public Builder toBuilder() {
- return builder().fromAttachment(this);
+ /** The hosted service in which the disk is being used. */
+ public String hostedService() {
+ return hostedService;
}
- 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);
- }
+ /** The virtual machine that the disk is attached to. */
+ public String virtualMachine() {
+ return virtualMachine;
}
- private final String hostedService;
- private final String deployment;
- private final String role;
+ public static Attachment create(String hostedService, String deployment, String virtualMachine) {
+ return new Attachment(hostedService, deployment, virtualMachine);
+ }
- private Attachment(String hostedService, String deployment, String role) {
+ // TODO: Remove from here down with @AutoValue.
+ private Attachment(String hostedService, String deployment, String virtualMachine) {
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;
+ this.virtualMachine = checkNotNull(virtualMachine, "virtualMachine");
}
- /**
- * The virtual machine that the disk is attached to.
- */
- public String getRole() {
- return role;
- }
+ private final String hostedService;
+ private final String deployment;
+ private final String virtualMachine;
@Override
public int hashCode() {
- return Objects.hashCode(hostedService, deployment, role);
+ return Objects.hashCode(hostedService, deployment, virtualMachine);
}
@Override
@@ -127,316 +80,157 @@ public class Disk {
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);
+ return equal(this.hostedService, other.hostedService) &&
+ equal(this.deployment, other.deployment) &&
+ equal(this.virtualMachine, other.virtualMachine);
}
@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);
+ return Objects.toStringHelper(this)
+ .add("hostedService", hostedService)
+ .add("deployment", deployment)
+ .add("virtualMachine", virtualMachine).toString();
}
- }
-
- 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() {
+ public String name() {
return name;
}
/**
- * The size, in GB, of the image.
+ * The geo-location of the disk in Windows Azure, if the disk is not
+ * associated with an affinity group. If a location has been specified, the AffinityGroup element
+ * is not returned.
*/
- public Optional<Integer> getLogicalSizeInGB() {
- return logicalSizeInGB;
+ @Nullable public String location() {
+ return location;
}
/**
- * The description for the image.
+ * The affinity group with which this disk is associated, if any. If the service is
+ * associated with an affinity group, the Location element is not returned.
*/
- public Optional<String> getDescription() {
- return description;
+ @Nullable public String affinityGroup() {
+ return affinityGroup;
}
- /**
- * 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;
+ @Nullable public String description() {
+ return description;
}
- /**
- * 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 operating system type of the OS image, or null if a data disk. */
+ @Nullable public OSType os() {
+ return os;
}
/**
- * The location of the blob in the blob store in which the media for the disk is located. The
+ * 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/mydisk.vhd
+ * http://example.blob.core.windows.net/disks/myimage.vhd
*/
- public Optional<URI> getMediaLink() {
+ @Nullable public URI mediaLink() {
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;
+ @Nullable public Integer logicalSizeInGB() {
+ return logicalSizeInGB;
}
/**
- * The description of the image.
+ * 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<String> getLabel() {
- return label;
+ @Nullable public Attachment attachedTo() {
+ return attachedTo;
}
/**
- * Returns whether this disk contains operation system. Only disks that have an operating system
- * installed can be mounted as an OS Drive.
+ * 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 boolean hasOperatingSystem() {
- return hasOperatingSystem;
+ @Nullable public String sourceImage() {
+ return sourceImage;
}
- /**
- * 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;
+ public static Disk create(String name, String location, String affinityGroup, String description,
+ OSType os, URI mediaLink, Integer logicalSizeInGB, Attachment attachedTo, String sourceImage) {
+ return new Disk(name, location, affinityGroup, description, os, mediaLink, logicalSizeInGB, attachedTo,
+ sourceImage);
}
- @Override
- public int hashCode() {
- return Objects.hashCode(name);
+ // TODO: Remove from here down with @AutoValue.
+ private Disk(String name, String location, String affinityGroup, String description, OSType os, URI mediaLink,
+ Integer logicalSizeInGB, Attachment attachedTo, String sourceImage) {
+ this.name = checkNotNull(name, "name");
+ this.location = location;
+ this.affinityGroup = affinityGroup;
+ this.description = description;
+ this.os = os;
+ this.mediaLink = mediaLink;
+ this.logicalSizeInGB = checkNotNull(logicalSizeInGB, "logicalSizeInGB of %s", name);
+ this.attachedTo = attachedTo;
+ this.sourceImage = sourceImage;
}
+ private final String name;
+ private final String location;
+ private final String affinityGroup;
+ private final String description;
+ private final OSType os;
+ private final URI mediaLink;
+ private final Integer logicalSizeInGB;
+ private final Attachment attachedTo;
+ private final String sourceImage;
+
@Override
- public boolean equals(Object obj) {
- if (this == obj) {
+ public boolean equals(Object object) {
+ if (this == object) {
return true;
}
- if (obj == null) {
+ if (object instanceof Disk) {
+ Disk that = Disk.class.cast(object);
+ return equal(name, that.name) &&
+ equal(location, that.location) &&
+ equal(affinityGroup, that.affinityGroup) &&
+ equal(description, that.description) &&
+ equal(os, that.os) &&
+ equal(mediaLink, that.mediaLink) &&
+ equal(logicalSizeInGB, that.logicalSizeInGB) &&
+ equal(attachedTo, that.attachedTo) &&
+ equal(sourceImage, that.sourceImage);
+ } else {
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();
+ public int hashCode() {
+ return Objects.hashCode(name, location, affinityGroup, description, os, mediaLink, logicalSizeInGB,
+ attachedTo, sourceImage);
}
- 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);
+ @Override
+ public String toString() {
+ return toStringHelper(this)
+ .add("name", name)
+ .add("location", location)
+ .add("affinityGroup", affinityGroup)
+ .add("description", description)
+ .add("os", os)
+ .add("mediaLink", mediaLink)
+ .add("logicalSizeInGB", logicalSizeInGB)
+ .add("attachedTo", attachedTo)
+ .add("sourceImage", sourceImage).toString();
}
-
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/da40d636/azurecompute/src/main/java/org/jclouds/azurecompute/xml/AttachmentHandler.java
----------------------------------------------------------------------
diff --git a/azurecompute/src/main/java/org/jclouds/azurecompute/xml/AttachmentHandler.java b/azurecompute/src/main/java/org/jclouds/azurecompute/xml/AttachmentHandler.java
index 648cf26..ccbe9c8 100644
--- a/azurecompute/src/main/java/org/jclouds/azurecompute/xml/AttachmentHandler.java
+++ b/azurecompute/src/main/java/org/jclouds/azurecompute/xml/AttachmentHandler.java
@@ -16,43 +16,39 @@
*/
package org.jclouds.azurecompute.xml;
+import static org.jclouds.util.SaxUtils.currentOrNull;
+
import org.jclouds.azurecompute.domain.Disk.Attachment;
import org.jclouds.http.functions.ParseSax;
-import org.jclouds.util.SaxUtils;
-import org.xml.sax.SAXException;
/**
* @see <a href="http://msdn.microsoft.com/en-us/library/jj157176" >api</a>
*/
-public class AttachmentHandler extends ParseSax.HandlerForGeneratedRequestWithResult<Attachment> {
+final class AttachmentHandler extends ParseSax.HandlerForGeneratedRequestWithResult<Attachment> {
+ private String hostedService;
+ private String deployment;
+ private String virtualMachine;
- private StringBuilder currentText = new StringBuilder();
- private Attachment.Builder builder = Attachment.builder();
+ private final StringBuilder currentText = new StringBuilder();
- @Override
- public Attachment getResult() {
- try {
- return builder.build();
- } finally {
- builder = Attachment.builder();
- }
+ @Override public Attachment getResult() {
+ Attachment result = Attachment.create(hostedService, deployment, virtualMachine);
+ hostedService = deployment = virtualMachine = null; // handler could be called in a loop.
+ return result;
}
- @Override
- public void endElement(String uri, String name, String qName) throws SAXException {
+ @Override public void endElement(String ignoredUri, String ignoredName, String qName) {
if (qName.equals("HostedServiceName")) {
- builder.hostedService(SaxUtils.currentOrNull(currentText));
+ hostedService = currentOrNull(currentText);
} else if (qName.equals("DeploymentName")) {
- builder.deployment(SaxUtils.currentOrNull(currentText));
+ deployment = currentOrNull(currentText);
} else if (qName.equals("RoleName")) {
- builder.role(SaxUtils.currentOrNull(currentText));
+ virtualMachine = currentOrNull(currentText);
}
currentText.setLength(0);
}
- @Override
- public void characters(char ch[], int start, int length) {
+ @Override public void characters(char ch[], int start, int length) {
currentText.append(ch, start, length);
}
-
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/da40d636/azurecompute/src/main/java/org/jclouds/azurecompute/xml/DiskHandler.java
----------------------------------------------------------------------
diff --git a/azurecompute/src/main/java/org/jclouds/azurecompute/xml/DiskHandler.java b/azurecompute/src/main/java/org/jclouds/azurecompute/xml/DiskHandler.java
index b592f95..0cc62c6 100644
--- a/azurecompute/src/main/java/org/jclouds/azurecompute/xml/DiskHandler.java
+++ b/azurecompute/src/main/java/org/jclouds/azurecompute/xml/DiskHandler.java
@@ -16,92 +16,97 @@
*/
package org.jclouds.azurecompute.xml;
+import static org.jclouds.util.SaxUtils.currentOrNull;
+
import java.net.URI;
-import javax.inject.Inject;
+
import org.jclouds.azurecompute.domain.Disk;
+import org.jclouds.azurecompute.domain.Disk.Attachment;
import org.jclouds.azurecompute.domain.OSType;
import org.jclouds.http.functions.ParseSax;
import org.xml.sax.Attributes;
-import org.xml.sax.SAXException;
-
-import static org.jclouds.util.SaxUtils.currentOrNull;
-import static org.jclouds.util.SaxUtils.equalsOrSuffix;
/**
* @see <a href="http://msdn.microsoft.com/en-us/library/jj157176" >api</a>
*/
-public class DiskHandler extends
- ParseSax.HandlerForGeneratedRequestWithResult<Disk> {
-
- private final AttachmentHandler attachmentHandler;
-
- @Inject
- private DiskHandler(AttachmentHandler attachmentHandler) {
- this.attachmentHandler = attachmentHandler;
- }
+final class DiskHandler extends ParseSax.HandlerForGeneratedRequestWithResult<Disk> {
+ private String name;
+ private String location;
+ private String affinityGroup;
+ private String description;
+ private OSType os;
+ private URI mediaLink;
+ private Integer logicalSizeInGB;
+ private Attachment attachedTo;
+ private String sourceImage;
- private StringBuilder currentText = new StringBuilder();
- private Disk.Builder builder = Disk.builder();
+ private boolean inAttachment;
+ private final AttachmentHandler attachmentHandler = new AttachmentHandler();
+ private final StringBuilder currentText = new StringBuilder();
- private boolean inAttachment;
+ @Override public Disk getResult() {
+ Disk result = Disk.create(name, location, affinityGroup, description, os, mediaLink, logicalSizeInGB,
+ attachedTo, sourceImage);
+ resetState(); // handler is called in a loop.
+ return result;
+ }
- @Override
- public Disk getResult() {
- try {
- return builder.build();
- } finally {
- builder = Disk.builder();
- }
- }
+ private void resetState() {
+ name = location = affinityGroup = description = sourceImage = null;
+ os = null;
+ mediaLink = null;
+ logicalSizeInGB = null;
+ attachedTo = null;
+ }
- @Override
- public void startElement(String uri, String localName, String qName,
- Attributes attributes) throws SAXException {
- if (equalsOrSuffix(qName, "AttachedTo")) {
- inAttachment = true;
- }
- }
+ @Override public void startElement(String uri, String localName, String qName, Attributes attributes) {
+ if (qName.equals("AttachedTo")) {
+ inAttachment = true;
+ }
+ }
- @Override
- public void endElement(String uri, String name, String qName)
- throws SAXException {
- if (equalsOrSuffix(qName, "AttachedTo")) {
- builder.attachedTo(attachmentHandler.getResult());
- inAttachment = false;
- } else if (inAttachment) {
- attachmentHandler.endElement(uri, name, qName);
- } else if (equalsOrSuffix(qName, "OS")) {
- builder.os(OSType.fromValue(currentOrNull(currentText)));
- } else if (equalsOrSuffix(qName, "Name")) {
- builder.name(currentOrNull(currentText));
- } else if (equalsOrSuffix(qName, "LogicalDiskSizeInGB")) {
- String gb = currentOrNull(currentText);
- if (gb != null)
- builder.logicalSizeInGB(Integer.parseInt(gb));
- } else if (equalsOrSuffix(qName, "Description")) {
- builder.description(currentOrNull(currentText));
- } else if (equalsOrSuffix(qName, "Location")) {
- builder.location(currentOrNull(currentText));
- } else if (equalsOrSuffix(qName, "AffinityGroup")) {
- builder.affinityGroup(currentOrNull(currentText));
- } else if (equalsOrSuffix(qName, "MediaLink")) {
- String link = currentOrNull(currentText);
- if (link != null)
- builder.mediaLink(URI.create(link));
- } else if (equalsOrSuffix(qName, "SourceImageName")) {
- builder.sourceImage(currentOrNull(currentText));
- } else if (equalsOrSuffix(qName, "Label")) {
- builder.label(currentOrNull(currentText));
- }
- currentText.setLength(0);
- }
+ @Override public void endElement(String ignoredUri, String ignoredName, String qName) {
+ if (qName.equals("AttachedTo")) {
+ attachedTo = attachmentHandler.getResult();
+ inAttachment = false;
+ } else if (inAttachment) {
+ attachmentHandler.endElement(ignoredUri, ignoredName, qName);
+ } else if (qName.equals("OS")) {
+ String osText = currentOrNull(currentText);
+ if (osText != null && osText.toUpperCase().equals("NULL")) {
+ os = null;
+ } else {
+ os = OSType.fromValue(currentOrNull(currentText));
+ }
+ } else if (qName.equals("Name")) {
+ name = currentOrNull(currentText);
+ } else if (qName.equals("LogicalDiskSizeInGB")) {
+ String gb = currentOrNull(currentText);
+ if (gb != null) {
+ logicalSizeInGB = Integer.parseInt(gb);
+ }
+ } else if (qName.equals("Description")) {
+ description = currentOrNull(currentText);
+ } else if (qName.equals("Location")) {
+ location = currentOrNull(currentText);
+ } else if (qName.equals("AffinityGroup")) {
+ affinityGroup = currentOrNull(currentText);
+ } else if (qName.equals("MediaLink")) {
+ String link = currentOrNull(currentText);
+ if (link != null) {
+ mediaLink = URI.create(link);
+ }
+ } else if (qName.equals("SourceImageName")) {
+ sourceImage = currentOrNull(currentText);
+ }
+ currentText.setLength(0);
+ }
- @Override
- public void characters(char ch[], int start, int length) {
- if (inAttachment) {
- attachmentHandler.characters(ch, start, length);
- } else {
- currentText.append(ch, start, length);
- }
- }
+ @Override public void characters(char ch[], int start, int length) {
+ if (inAttachment) {
+ attachmentHandler.characters(ch, start, length);
+ } else {
+ currentText.append(ch, start, length);
+ }
+ }
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/da40d636/azurecompute/src/main/java/org/jclouds/azurecompute/xml/ListDisksHandler.java
----------------------------------------------------------------------
diff --git a/azurecompute/src/main/java/org/jclouds/azurecompute/xml/ListDisksHandler.java b/azurecompute/src/main/java/org/jclouds/azurecompute/xml/ListDisksHandler.java
index fb6ea13..acdc7b5 100644
--- a/azurecompute/src/main/java/org/jclouds/azurecompute/xml/ListDisksHandler.java
+++ b/azurecompute/src/main/java/org/jclouds/azurecompute/xml/ListDisksHandler.java
@@ -16,37 +16,26 @@
*/
package org.jclouds.azurecompute.xml;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableList.Builder;
-import com.google.inject.Inject;
import java.util.List;
+
import org.jclouds.azurecompute.domain.Disk;
import org.jclouds.http.functions.ParseSax;
-import org.jclouds.util.SaxUtils;
import org.xml.sax.Attributes;
-import org.xml.sax.SAXException;
-
-public class ListDisksHandler extends ParseSax.HandlerForGeneratedRequestWithResult<List<Disk>> {
-
- private final DiskHandler diskHandler;
- private Builder<Disk> disks = ImmutableList.<Disk> builder();
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableList.Builder;
+public final class ListDisksHandler extends ParseSax.HandlerForGeneratedRequestWithResult<List<Disk>> {
private boolean inDisk;
+ private final DiskHandler diskHandler = new DiskHandler();
+ private final Builder<Disk> disks = ImmutableList.builder();
- @Inject
- public ListDisksHandler(final DiskHandler diskHandler) {
- this.diskHandler = diskHandler;
- }
-
- @Override
- public List<Disk> getResult() {
+ @Override public List<Disk> getResult() {
return disks.build();
}
- @Override
- public void startElement(String url, String name, String qName, Attributes attributes) throws SAXException {
- if (SaxUtils.equalsOrSuffix(qName, "Disk")) {
+ @Override public void startElement(String url, String name, String qName, Attributes attributes) {
+ if (qName.equals("Disk")) {
inDisk = true;
}
if (inDisk) {
@@ -54,8 +43,7 @@ public class ListDisksHandler extends ParseSax.HandlerForGeneratedRequestWithRes
}
}
- @Override
- public void endElement(String uri, String name, String qName) throws SAXException {
+ @Override public void endElement(String uri, String name, String qName) {
if (qName.equals("Disk")) {
inDisk = false;
disks.add(diskHandler.getResult());
@@ -64,8 +52,7 @@ public class ListDisksHandler extends ParseSax.HandlerForGeneratedRequestWithRes
}
}
- @Override
- public void characters(char ch[], int start, int length) {
+ @Override public void characters(char ch[], int start, int length) {
if (inDisk) {
diskHandler.characters(ch, start, length);
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/da40d636/azurecompute/src/test/java/org/jclouds/azurecompute/features/DiskApiLiveTest.java
----------------------------------------------------------------------
diff --git a/azurecompute/src/test/java/org/jclouds/azurecompute/features/DiskApiLiveTest.java b/azurecompute/src/test/java/org/jclouds/azurecompute/features/DiskApiLiveTest.java
index 478b1b3..53531de 100644
--- a/azurecompute/src/test/java/org/jclouds/azurecompute/features/DiskApiLiveTest.java
+++ b/azurecompute/src/test/java/org/jclouds/azurecompute/features/DiskApiLiveTest.java
@@ -16,9 +16,11 @@
*/
package org.jclouds.azurecompute.features;
-import com.google.common.base.Function;
-import com.google.common.collect.ImmutableSet;
-import java.util.List;
+import static com.google.common.collect.Iterables.transform;
+import static org.testng.Assert.assertNotEquals;
+import static org.testng.Assert.assertNull;
+import static org.testng.Assert.assertTrue;
+
import org.jclouds.azurecompute.domain.Disk;
import org.jclouds.azurecompute.domain.Image;
import org.jclouds.azurecompute.domain.Location;
@@ -27,10 +29,8 @@ import org.jclouds.azurecompute.internal.BaseAzureComputeApiLiveTest;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
-import static com.google.common.base.Preconditions.checkNotNull;
-import static com.google.common.collect.Iterables.transform;
-import static org.testng.Assert.assertNotEquals;
-import static org.testng.Assert.assertTrue;
+import com.google.common.base.Function;
+import com.google.common.collect.ImmutableSet;
@Test(groups = "live", testName = "DiskApiLiveTest")
public class DiskApiLiveTest extends BaseAzureComputeApiLiveTest {
@@ -44,73 +44,51 @@ public class DiskApiLiveTest extends BaseAzureComputeApiLiveTest {
locations = ImmutableSet.copyOf(transform(api.getLocationApi().list(),
new Function<Location, String>() {
- @Override
public String apply(Location in) {
return in.getName();
}
}));
images = ImmutableSet.copyOf(transform(api.getImageApi().list(), new Function<Image, String>() {
- @Override
public String apply(Image in) {
return in.name();
}
}));
}
- @Test
- protected void testList() {
- List<Disk> response = api().list();
-
- for (Disk disk : response) {
+ public void testList() {
+ for (Disk disk : api().list()) {
checkDisk(disk);
}
}
private void checkDisk(Disk disk) {
- checkNotNull(disk.getName(), "Name cannot be null for Disk %s", disk.getLabel());
- checkNotNull(disk.getOS(), "OS cannot be null for Disk: %s", disk);
- assertNotEquals(disk.getOS(), OSType.UNRECOGNIZED, "Status cannot be UNRECOGNIZED for Disk: " + disk);
+ assertNull(disk.name(), "Name cannot be null for: " + disk);
+ assertNull(disk.os(), "OS cannot be null for: " + disk);
+ assertNotEquals(disk.os(), OSType.UNRECOGNIZED, "Status cannot be UNRECOGNIZED for: " + disk);
- checkNotNull(disk.getAttachedTo(), "While AttachedTo can be null for Disk, its Optional wrapper cannot: %s", disk);
- if (disk.getAttachedTo().isPresent()) {
+ if (disk.attachedTo() != null) {
// TODO: verify you can lookup the role
}
- checkNotNull(disk.getLogicalSizeInGB(),
- "While LogicalSizeInGB can be null for Disk, its Optional wrapper cannot: %s", disk);
-
- if (disk.getLogicalSizeInGB().isPresent())
- assertTrue(disk.getLogicalSizeInGB().get() > 0, "LogicalSizeInGB should be positive, if set" + disk.toString());
-
- checkNotNull(disk.getMediaLink(), "While MediaLink can be null for Disk, its Optional wrapper cannot: %s", disk);
-
- if (disk.getMediaLink().isPresent())
- assertTrue(ImmutableSet.of("http", "https").contains(disk.getMediaLink().get().getScheme()),
- "MediaLink should be an http(s) url" + disk.toString());
-
- checkNotNull(disk.getLabel(), "While Label can be null for Disk, its Optional wrapper cannot: %s",
- disk);
+ if (disk.logicalSizeInGB() != null) {
+ assertTrue(disk.logicalSizeInGB() > 0, "LogicalSizeInGB should be positive, if set" + disk);
+ }
- checkNotNull(disk.getDescription(), "While Description can be null for Disk, its Optional wrapper cannot: %s",
- disk);
+ if (disk.mediaLink() != null) {
+ assertTrue(ImmutableSet.of("http", "https").contains(disk.mediaLink().getScheme()),
+ "MediaLink should be an http(s) url" + disk);
+ }
- checkNotNull(disk.getLocation(), "While Location can be null for Disk, its Optional wrapper cannot: %s", disk);
- if (disk.getLocation().isPresent()) {
- assertTrue(locations.contains(disk.getLocation().get()),
- "Location not in " + locations + " :" + disk.toString());
+ if (disk.location() != null) {
+ assertTrue(locations.contains(disk.location()), "Location not in " + locations + " :" + disk);
}
- checkNotNull(disk.getSourceImage(), "While SourceImage can be null for Disk, its Optional wrapper cannot: %s",
- disk);
- if (disk.getSourceImage().isPresent()) {
- assertTrue(images.contains(disk.getSourceImage().get()),
- "SourceImage not in " + images + " :" + disk.toString());
+ if (disk.sourceImage() != null) {
+ assertTrue(images.contains(disk.sourceImage()), "SourceImage not in " + images + " :" + disk);
}
- checkNotNull(disk.getAffinityGroup(),
- "While AffinityGroup can be null for Disk, its Optional wrapper cannot: %s", disk);
- if (disk.getAffinityGroup().isPresent()) {
- // TODO: list getAffinityGroups and check if there
+ if (disk.affinityGroup() != null) {
+ // TODO: list affinityGroups and check if there
}
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/da40d636/azurecompute/src/test/java/org/jclouds/azurecompute/features/DiskApiMockTest.java
----------------------------------------------------------------------
diff --git a/azurecompute/src/test/java/org/jclouds/azurecompute/features/DiskApiMockTest.java b/azurecompute/src/test/java/org/jclouds/azurecompute/features/DiskApiMockTest.java
index c6fab15..656428c 100644
--- a/azurecompute/src/test/java/org/jclouds/azurecompute/features/DiskApiMockTest.java
+++ b/azurecompute/src/test/java/org/jclouds/azurecompute/features/DiskApiMockTest.java
@@ -16,13 +16,16 @@
*/
package org.jclouds.azurecompute.features;
-import com.squareup.okhttp.mockwebserver.MockResponse;
-import com.squareup.okhttp.mockwebserver.MockWebServer;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertNull;
+import static org.testng.Assert.assertTrue;
+
import org.jclouds.azurecompute.internal.BaseAzureComputeApiMockTest;
-import org.jclouds.azurecompute.parse.ListDisksTest;
+import org.jclouds.azurecompute.xml.ListDisksHandlerTest;
import org.testng.annotations.Test;
-import static org.assertj.core.api.Assertions.assertThat;
+import com.squareup.okhttp.mockwebserver.MockResponse;
+import com.squareup.okhttp.mockwebserver.MockWebServer;
@Test(groups = "unit", testName = "DiskApiMockTest")
public class DiskApiMockTest extends BaseAzureComputeApiMockTest {
@@ -34,7 +37,7 @@ public class DiskApiMockTest extends BaseAzureComputeApiMockTest {
try {
DiskApi api = api(server.getUrl("/")).getDiskApi();
- assertThat(api.list()).containsExactlyElementsOf(ListDisksTest.expected());
+ assertEquals(api.list(), ListDisksHandlerTest.expected());
assertSent(server, "GET", "/services/disks");
} finally {
@@ -49,7 +52,7 @@ public class DiskApiMockTest extends BaseAzureComputeApiMockTest {
try {
DiskApi api = api(server.getUrl("/")).getDiskApi();
- assertThat(api.list()).isEmpty();
+ assertTrue(api.list().isEmpty());
assertSent(server, "GET", "/services/disks");
} finally {
@@ -64,7 +67,7 @@ public class DiskApiMockTest extends BaseAzureComputeApiMockTest {
try {
DiskApi api = api(server.getUrl("/")).getDiskApi();
- assertThat(api.delete("my-disk")).isEqualTo("request-1");
+ assertEquals(api.delete("my-disk"), "request-1");
assertSent(server, "DELETE", "/services/disks/my-disk");
} finally {
@@ -79,7 +82,7 @@ public class DiskApiMockTest extends BaseAzureComputeApiMockTest {
try {
DiskApi api = api(server.getUrl("/")).getDiskApi();
- assertThat(api.delete("my-disk")).isNull();
+ assertNull(api.delete("my-disk"));
assertSent(server, "DELETE", "/services/disks/my-disk");
} finally {
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/da40d636/azurecompute/src/test/java/org/jclouds/azurecompute/parse/ListDisksTest.java
----------------------------------------------------------------------
diff --git a/azurecompute/src/test/java/org/jclouds/azurecompute/parse/ListDisksTest.java b/azurecompute/src/test/java/org/jclouds/azurecompute/parse/ListDisksTest.java
deleted file mode 100644
index 390b007..0000000
--- a/azurecompute/src/test/java/org/jclouds/azurecompute/parse/ListDisksTest.java
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * 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.parse;
-
-import com.google.common.collect.ImmutableSet;
-import java.io.InputStream;
-import java.net.URI;
-import java.util.List;
-import java.util.Set;
-import org.jclouds.azurecompute.domain.Disk;
-import org.jclouds.azurecompute.domain.Disk.Attachment;
-import org.jclouds.azurecompute.domain.OSType;
-import org.jclouds.azurecompute.xml.ListDisksHandler;
-import org.jclouds.http.functions.BaseHandlerTest;
-import org.testng.annotations.Test;
-
-import static org.testng.Assert.assertEquals;
-
-@Test(groups = "unit", testName = "ListDisksTest")
-public class ListDisksTest extends BaseHandlerTest {
-
- public void test() {
- InputStream is = getClass().getResourceAsStream("/disks.xml");
-
- Set<Disk> expected = expected();
-
- ListDisksHandler handler = injector.getInstance(ListDisksHandler.class);
- List<Disk> result = factory.create(handler).parse(is);
-
- assertEquals(result.toString(), expected.toString());
-
- }
-
- public static Set<Disk> expected() {
-
- return ImmutableSet.<Disk>builder()
- .add(Disk.builder()
- .os(OSType.LINUX)
- .location("West Europe")
- .logicalSizeInGB(30)
- .mediaLink(URI.create("http://neotysbucket1.blob.core.windows.net/vhds/testimage2-testimage2-2012-08-17.vhd"))
- .name("testimage2-testimage2-0-20120817095145")
- .sourceImage("OpenLogic__OpenLogic-CentOS-62-20120531-en-us-30GB.vhd")
- .build())
- .add(Disk.builder()
- .attachedTo(Attachment.builder().deployment("neotysss").hostedService("neotysss").role("neotysss").build())
- .os(OSType.WINDOWS)
- .location("West Europe")
- .logicalSizeInGB(30)
- .mediaLink(URI.create("http://portalvhds0g7xhnq2x7t21.blob.core.windows.net/disks/neotysss/MSFT__Win2K8R2SP1-120612-1520-121206-01-en-us-30GB.vhd"))
- .name("neotysss-neotysss-0-20120824091357")
- .sourceImage("MSFT__Win2K8R2SP1-120612-1520-121206-01-en-us-30GB.vhd")
- .build())
- .build();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/da40d636/azurecompute/src/test/java/org/jclouds/azurecompute/xml/ListDisksHandlerTest.java
----------------------------------------------------------------------
diff --git a/azurecompute/src/test/java/org/jclouds/azurecompute/xml/ListDisksHandlerTest.java b/azurecompute/src/test/java/org/jclouds/azurecompute/xml/ListDisksHandlerTest.java
new file mode 100644
index 0000000..f263567
--- /dev/null
+++ b/azurecompute/src/test/java/org/jclouds/azurecompute/xml/ListDisksHandlerTest.java
@@ -0,0 +1,67 @@
+/*
+ * 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.xml;
+
+import static org.testng.Assert.assertEquals;
+
+import java.io.InputStream;
+import java.net.URI;
+import java.util.List;
+
+import org.jclouds.azurecompute.domain.Disk;
+import org.jclouds.azurecompute.domain.Disk.Attachment;
+import org.jclouds.azurecompute.domain.OSType;
+import org.jclouds.http.functions.BaseHandlerTest;
+import org.testng.annotations.Test;
+
+import com.google.common.collect.ImmutableList;
+
+@Test(groups = "unit", testName = "ListDisksHandlerTest")
+public class ListDisksHandlerTest extends BaseHandlerTest {
+
+ public void test() {
+ InputStream is = getClass().getResourceAsStream("/disks.xml");
+ List<Disk> result = factory.create(new ListDisksHandler()).parse(is);
+
+ assertEquals(result, expected());
+ }
+
+ public static List<Disk> expected() {
+ return ImmutableList.of( //
+ Disk.create( //
+ "testimage2-testimage2-0-20120817095145", // name
+ "West Europe", // location
+ null, // affinityGroup
+ null, //description
+ OSType.LINUX, // os
+ URI.create("http://blobs/vhds/testimage2-testimage2-2012-08-17.vhd"), // mediaLink
+ 30, // logicalSizeInGB
+ null, // attachedTo
+ "OpenLogic__OpenLogic-CentOS-62-20120531-en-us-30GB.vhd" // sourceImage
+ ), Disk.create( //
+ "neotysss-neotysss-0-20120824091357", // name
+ "West Europe", // location
+ null, // affinityGroup
+ null, //description
+ OSType.WINDOWS, // os
+ URI.create("http://blobs/disks/neotysss/MSFT__Win2K8R2SP1-ABCD-en-us-30GB.vhd"), // mediaLink
+ 30, // logicalSizeInGB
+ Attachment.create("neotysss", "neotysss", "neotysss"), // attachedTo
+ "MSFT__Win2K8R2SP1-ABCD-en-us-30GB.vhd" // sourceImage
+ ));
+ }
+}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/da40d636/azurecompute/src/test/resources/disks.xml
----------------------------------------------------------------------
diff --git a/azurecompute/src/test/resources/disks.xml b/azurecompute/src/test/resources/disks.xml
index afae399..2e9b453 100644
--- a/azurecompute/src/test/resources/disks.xml
+++ b/azurecompute/src/test/resources/disks.xml
@@ -3,7 +3,7 @@
<OS>Linux</OS>
<Location>West Europe</Location>
<LogicalDiskSizeInGB>30</LogicalDiskSizeInGB>
- <MediaLink>http://neotysbucket1.blob.core.windows.net/vhds/testimage2-testimage2-2012-08-17.vhd</MediaLink>
+ <MediaLink>http://blobs/vhds/testimage2-testimage2-2012-08-17.vhd</MediaLink>
<Name>testimage2-testimage2-0-20120817095145</Name>
<SourceImageName>OpenLogic__OpenLogic-CentOS-62-20120531-en-us-30GB.vhd</SourceImageName>
</Disk>
@@ -16,8 +16,8 @@
<OS>Windows</OS>
<Location>West Europe</Location>
<LogicalDiskSizeInGB>30</LogicalDiskSizeInGB>
- <MediaLink>http://portalvhds0g7xhnq2x7t21.blob.core.windows.net/disks/neotysss/MSFT__Win2K8R2SP1-120612-1520-121206-01-en-us-30GB.vhd</MediaLink>
+ <MediaLink>http://blobs/disks/neotysss/MSFT__Win2K8R2SP1-ABCD-en-us-30GB.vhd</MediaLink>
<Name>neotysss-neotysss-0-20120824091357</Name>
- <SourceImageName>MSFT__Win2K8R2SP1-120612-1520-121206-01-en-us-30GB.vhd</SourceImageName>
+ <SourceImageName>MSFT__Win2K8R2SP1-ABCD-en-us-30GB.vhd</SourceImageName>
</Disk>
</Disks>
[08/11] git commit: Cleanup output-only Error object.
Posted by ad...@apache.org.
Cleanup output-only Error object.
Project: http://git-wip-us.apache.org/repos/asf/jclouds-labs/repo
Commit: http://git-wip-us.apache.org/repos/asf/jclouds-labs/commit/caf57cc7
Tree: http://git-wip-us.apache.org/repos/asf/jclouds-labs/tree/caf57cc7
Diff: http://git-wip-us.apache.org/repos/asf/jclouds-labs/diff/caf57cc7
Branch: refs/heads/master
Commit: caf57cc754c5f35cbc264a93467ff9dd40816e05
Parents: 96ebc7f
Author: Adrian Cole <ac...@twitter.com>
Authored: Thu Oct 16 19:59:06 2014 -0700
Committer: Adrian Cole <ac...@twitter.com>
Committed: Mon Oct 20 13:26:53 2014 -0400
----------------------------------------------------------------------
.../org/jclouds/azurecompute/domain/Error.java | 202 +++----------------
.../jclouds/azurecompute/xml/ErrorHandler.java | 41 ++--
.../jclouds/azurecompute/parse/ErrorTest.java | 50 -----
.../azurecompute/parse/GetOperationTest.java | 14 +-
.../azurecompute/xml/ErrorHandlerTest.java | 42 ++++
5 files changed, 96 insertions(+), 253 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/caf57cc7/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
index e8947ab..1b529d0 100644
--- a/azurecompute/src/main/java/org/jclouds/azurecompute/domain/Error.java
+++ b/azurecompute/src/main/java/org/jclouds/azurecompute/domain/Error.java
@@ -16,225 +16,77 @@
*/
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.Objects.equal;
+import static com.google.common.base.Objects.toStringHelper;
import static com.google.common.base.Preconditions.checkNotNull;
+import com.google.common.base.Objects;
+
/**
- * 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 final 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();
+ /** Error code */
+ public Code getCode() {
+ return code;
}
- public Builder toBuilder() {
- return builder().fromError(this);
+ /** User message */
+ public String message() {
+ return message;
}
- 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);
- }
+ public static Error create(Code code, String message) {
+ return new Error(code, 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);
+ // TODO: Remove from here down with @AutoValue.
+ private Error(Code code, String message) {
+ this.code = checkNotNull(code, "code");
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;
- }
+ private final Code code;
+ private final String message;
@Override
public int hashCode() {
- return Objects.hashCode(rawCode, code, message);
+ return Objects.hashCode(code, message);
}
@Override
public boolean equals(Object obj) {
- if (this == obj)
+ if (this == obj) {
return true;
- if (obj == null)
+ }
+ if (obj == null) {
return false;
- if (getClass() != obj.getClass())
+ }
+ 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);
+ return equal(this.code, other.code) && equal(this.message, other.message);
}
@Override
public String toString() {
- return MoreObjects.toStringHelper(this).omitNullValues().add("code", rawCode).add("message", message).toString();
+ return toStringHelper(this).add("code", code).add("message", message).toString();
}
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/caf57cc7/azurecompute/src/main/java/org/jclouds/azurecompute/xml/ErrorHandler.java
----------------------------------------------------------------------
diff --git a/azurecompute/src/main/java/org/jclouds/azurecompute/xml/ErrorHandler.java b/azurecompute/src/main/java/org/jclouds/azurecompute/xml/ErrorHandler.java
index 3d7f2f4..001e856 100644
--- a/azurecompute/src/main/java/org/jclouds/azurecompute/xml/ErrorHandler.java
+++ b/azurecompute/src/main/java/org/jclouds/azurecompute/xml/ErrorHandler.java
@@ -16,43 +16,46 @@
*/
package org.jclouds.azurecompute.xml;
+import static com.google.common.base.CaseFormat.UPPER_CAMEL;
+import static com.google.common.base.CaseFormat.UPPER_UNDERSCORE;
+import static org.jclouds.util.SaxUtils.currentOrNull;
+
import org.jclouds.azurecompute.domain.Error;
import org.jclouds.azurecompute.domain.Error.Code;
import org.jclouds.http.functions.ParseSax;
-import org.jclouds.util.SaxUtils;
-import org.xml.sax.SAXException;
/**
* @see <a href="http://msdn.microsoft.com/en-us/library/ee460801" >api</a>
*/
-public class ErrorHandler extends ParseSax.HandlerForGeneratedRequestWithResult<Error> {
+public final class ErrorHandler extends ParseSax.HandlerForGeneratedRequestWithResult<Error> {
+ private Code code;
+ private String message;
private StringBuilder currentText = new StringBuilder();
- private Error.Builder builder = Error.builder();
- @Override
- public Error getResult() {
- try {
- return builder.build();
- } finally {
- builder = Error.builder();
- }
+ @Override public Error getResult() {
+ return Error.create(code, message);
}
- @Override
- public void endElement(String uri, String name, String qName) throws SAXException {
+ @Override public void endElement(String ignoredUri, String ignoredName, String qName) {
if (qName.equals("Code")) {
- String rawCode = SaxUtils.currentOrNull(currentText);
- builder.rawCode(rawCode);
- builder.code(Code.fromValue(rawCode));
+ String codeText = currentOrNull(currentText);
+ code = parseCode(codeText);
} else if (qName.equals("Message")) {
- builder.message(SaxUtils.currentOrNull(currentText));
+ message = currentOrNull(currentText);
}
currentText.setLength(0);
}
- @Override
- public void characters(char ch[], int start, int length) {
+ @Override public void characters(char ch[], int start, int length) {
currentText.append(ch, start, length);
}
+
+ private static Code parseCode(String code) {
+ try {
+ return Code.valueOf(UPPER_CAMEL.to(UPPER_UNDERSCORE, code));
+ } catch (IllegalArgumentException e) {
+ return Code.UNRECOGNIZED;
+ }
+ }
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/caf57cc7/azurecompute/src/test/java/org/jclouds/azurecompute/parse/ErrorTest.java
----------------------------------------------------------------------
diff --git a/azurecompute/src/test/java/org/jclouds/azurecompute/parse/ErrorTest.java b/azurecompute/src/test/java/org/jclouds/azurecompute/parse/ErrorTest.java
deleted file mode 100644
index 12d38c6..0000000
--- a/azurecompute/src/test/java/org/jclouds/azurecompute/parse/ErrorTest.java
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * 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.parse;
-
-import java.io.InputStream;
-import org.jclouds.azurecompute.domain.Error;
-import org.jclouds.azurecompute.domain.Error.Code;
-import org.jclouds.azurecompute.xml.ErrorHandler;
-import org.jclouds.http.functions.BaseHandlerTest;
-import org.testng.annotations.Test;
-
-import static org.testng.Assert.assertEquals;
-
-@Test(groups = "unit", testName = "ErrorTest")
-public class ErrorTest extends BaseHandlerTest {
-
- public void test() {
- InputStream is = getClass().getResourceAsStream("/error.xml");
-
- Error expected = expected();
-
- ErrorHandler handler = injector.getInstance(ErrorHandler.class);
- Error result = factory.create(handler).parse(is);
-
- assertEquals(result.toString(), expected.toString());
-
- }
-
- public Error expected() {
- return Error.builder()
- .rawCode("MissingOrInvalidRequiredQueryParameter")
- .code(Code.MISSING_OR_INVALID_REQUIRED_QUERY_PARAMETER)
- .message("A required query parameter was not specified for this request or was specified incorrectly.")
- .build();
- }
-}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/caf57cc7/azurecompute/src/test/java/org/jclouds/azurecompute/parse/GetOperationTest.java
----------------------------------------------------------------------
diff --git a/azurecompute/src/test/java/org/jclouds/azurecompute/parse/GetOperationTest.java b/azurecompute/src/test/java/org/jclouds/azurecompute/parse/GetOperationTest.java
index ecf7083..8e41f81 100644
--- a/azurecompute/src/test/java/org/jclouds/azurecompute/parse/GetOperationTest.java
+++ b/azurecompute/src/test/java/org/jclouds/azurecompute/parse/GetOperationTest.java
@@ -16,17 +16,17 @@
*/
package org.jclouds.azurecompute.parse;
+import static org.testng.Assert.assertEquals;
+
import java.io.InputStream;
-import org.jclouds.azurecompute.domain.Error;
-import org.jclouds.azurecompute.domain.Error.Code;
+
import org.jclouds.azurecompute.domain.Operation;
import org.jclouds.azurecompute.domain.Operation.Status;
+import org.jclouds.azurecompute.xml.ErrorHandlerTest;
import org.jclouds.azurecompute.xml.OperationHandler;
import org.jclouds.http.functions.BaseHandlerTest;
import org.testng.annotations.Test;
-import static org.testng.Assert.assertEquals;
-
@Test(groups = "unit", testName = "GetOperationTest")
public class GetOperationTest extends BaseHandlerTest {
@@ -47,11 +47,7 @@ public class GetOperationTest extends BaseHandlerTest {
.rawStatus("Failed")
.status(Status.FAILED)
.httpStatusCode(400)
- .error(Error.builder()
- .rawCode("MissingOrInvalidRequiredQueryParameter")
- .code(Code.MISSING_OR_INVALID_REQUIRED_QUERY_PARAMETER)
- .message("A required query parameter was not specified for this request or was specified incorrectly.")
- .build())
+ .error(ErrorHandlerTest.expected())
.build();
}
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/caf57cc7/azurecompute/src/test/java/org/jclouds/azurecompute/xml/ErrorHandlerTest.java
----------------------------------------------------------------------
diff --git a/azurecompute/src/test/java/org/jclouds/azurecompute/xml/ErrorHandlerTest.java b/azurecompute/src/test/java/org/jclouds/azurecompute/xml/ErrorHandlerTest.java
new file mode 100644
index 0000000..3c9a74b
--- /dev/null
+++ b/azurecompute/src/test/java/org/jclouds/azurecompute/xml/ErrorHandlerTest.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.xml;
+
+import static org.testng.Assert.assertEquals;
+
+import java.io.InputStream;
+
+import org.jclouds.azurecompute.domain.Error;
+import org.jclouds.azurecompute.domain.Error.Code;
+import org.jclouds.http.functions.BaseHandlerTest;
+import org.testng.annotations.Test;
+
+@Test(groups = "unit", testName = "ErrorHandlerTest")
+public class ErrorHandlerTest extends BaseHandlerTest {
+
+ public void test() {
+ InputStream is = getClass().getResourceAsStream("/error.xml");
+ Error result = factory.create(new ErrorHandler()).parse(is);
+
+ assertEquals(result, expected());
+ }
+
+ public static Error expected() {
+ return Error.create(Code.MISSING_OR_INVALID_REQUIRED_QUERY_PARAMETER,
+ "A required query parameter was not specified for this request or was specified incorrectly.");
+ }
+}
[04/11] git commit: Cleanup output-only Deployment object.
Posted by ad...@apache.org.
Cleanup output-only Deployment object.
Project: http://git-wip-us.apache.org/repos/asf/jclouds-labs/repo
Commit: http://git-wip-us.apache.org/repos/asf/jclouds-labs/commit/ece9a967
Tree: http://git-wip-us.apache.org/repos/asf/jclouds-labs/tree/ece9a967
Diff: http://git-wip-us.apache.org/repos/asf/jclouds-labs/diff/ece9a967
Branch: refs/heads/master
Commit: ece9a96716a6575a8881e585437e6d27f054a872
Parents: ff9d3ce
Author: Adrian Cole <ad...@gmail.com>
Authored: Thu Oct 16 09:01:39 2014 -0700
Committer: Adrian Cole <ac...@twitter.com>
Committed: Mon Oct 20 13:26:53 2014 -0400
----------------------------------------------------------------------
.../BindDeploymentParamsToXmlPayload.java | 11 +-
.../jclouds/azurecompute/domain/Deployment.java | 343 +++++++------------
.../azurecompute/domain/DeploymentParams.java | 2 +-
.../azurecompute/domain/DeploymentSlot.java | 42 ---
.../azurecompute/domain/DeploymentStatus.java | 43 ---
.../azurecompute/domain/InstanceStatus.java | 155 ---------
.../jclouds/azurecompute/domain/RoleSize.java | 23 +-
.../azurecompute/xml/DeploymentHandler.java | 172 ++++++----
.../features/DeploymentApiMockTest.java | 20 +-
.../azurecompute/parse/GetDeploymentTest.java | 62 ----
.../azurecompute/xml/DeploymentHandlerTest.java | 86 +++++
azurecompute/src/test/resources/deployment.xml | 126 +++----
12 files changed, 398 insertions(+), 687 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/ece9a967/azurecompute/src/main/java/org/jclouds/azurecompute/binders/BindDeploymentParamsToXmlPayload.java
----------------------------------------------------------------------
diff --git a/azurecompute/src/main/java/org/jclouds/azurecompute/binders/BindDeploymentParamsToXmlPayload.java b/azurecompute/src/main/java/org/jclouds/azurecompute/binders/BindDeploymentParamsToXmlPayload.java
index 1c127f1..22aa011 100644
--- a/azurecompute/src/main/java/org/jclouds/azurecompute/binders/BindDeploymentParamsToXmlPayload.java
+++ b/azurecompute/src/main/java/org/jclouds/azurecompute/binders/BindDeploymentParamsToXmlPayload.java
@@ -16,15 +16,20 @@
*/
package org.jclouds.azurecompute.binders;
-import com.google.common.base.Throwables;
-import com.jamesmurty.utils.XMLBuilder;
+import static com.google.common.base.CaseFormat.UPPER_CAMEL;
+import static com.google.common.base.CaseFormat.UPPER_UNDERSCORE;
+
import javax.inject.Singleton;
+
import org.jclouds.azurecompute.domain.DeploymentParams;
import org.jclouds.azurecompute.domain.InputEndpoint;
import org.jclouds.azurecompute.domain.OSType;
import org.jclouds.http.HttpRequest;
import org.jclouds.rest.Binder;
+import com.google.common.base.Throwables;
+import com.jamesmurty.utils.XMLBuilder;
+
@Singleton
public class BindDeploymentParamsToXmlPayload implements Binder {
@@ -95,7 +100,7 @@ public class BindDeploymentParamsToXmlPayload implements Binder {
.e("SourceImageName").t(params.getSourceImageName()).up()
.e("OS").t("Linux").up()
.up() //OSVirtualHardDisk
- .e("RoleSize").t(params.getSize().value()).up()
+ .e("RoleSize").t(UPPER_UNDERSCORE.to(UPPER_CAMEL, params.getSize().name())).up()
.up() //Role
.up(); //RoleList
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/ece9a967/azurecompute/src/main/java/org/jclouds/azurecompute/domain/Deployment.java
----------------------------------------------------------------------
diff --git a/azurecompute/src/main/java/org/jclouds/azurecompute/domain/Deployment.java b/azurecompute/src/main/java/org/jclouds/azurecompute/domain/Deployment.java
index 6bd179b..7a6986f 100644
--- a/azurecompute/src/main/java/org/jclouds/azurecompute/domain/Deployment.java
+++ b/azurecompute/src/main/java/org/jclouds/azurecompute/domain/Deployment.java
@@ -16,147 +16,73 @@
*/
package org.jclouds.azurecompute.domain;
-import java.net.URI;
+import static com.google.common.base.Objects.equal;
+import static com.google.common.base.Objects.toStringHelper;
+import static com.google.common.base.Preconditions.checkNotNull;
-public class Deployment {
+import org.jclouds.javax.annotation.Nullable;
- public static Builder builder() {
- return new Builder();
- }
-
- public static class Builder {
- private String deploymentName;
- private DeploymentSlot deploymentSlot;
- private DeploymentStatus deploymentStatus;
- private String deploymentLabel;
- private URI deploymentURL;
- private String roleName;
- private String instanceName;
- private InstanceStatus instanceStatus;
- private String instanceStateDetails;
- private String instanceErrorCode;
- private RoleSize instanceSize;
- private String privateIpAddress;
- private String publicIpAddress;
-
- public Builder deploymentName(final String deploymentName) {
- this.deploymentName = deploymentName;
- return this;
- }
-
- public Builder deploymentSlot(final DeploymentSlot deploymentSlot) {
- this.deploymentSlot = deploymentSlot;
- return this;
- }
-
- public Builder deploymentStatus(final DeploymentStatus deploymentStatus) {
- this.deploymentStatus = deploymentStatus;
- return this;
- }
+import com.google.common.base.Objects;
- public Builder deploymentLabel(final String deploymentLabel) {
- this.deploymentLabel = deploymentLabel;
- return this;
- }
-
- public Builder deploymentURL(final URI deploymentURL) {
- this.deploymentURL = deploymentURL;
- return this;
- }
-
- public Builder instanceSize(final RoleSize instanceSize) {
- this.instanceSize = instanceSize;
- return this;
- }
-
- public Builder instanceName(final String instanceName) {
- this.instanceName = instanceName;
- return this;
- }
+public final class Deployment {
- public Builder instanceStatus(final InstanceStatus instanceStatus) {
- this.instanceStatus = instanceStatus;
- return this;
- }
-
- public Builder instanceStateDetails(final String instanceStateDetails) {
- this.instanceStateDetails = instanceStateDetails;
- return this;
- }
-
- public Builder instanceErrorCode(final String instanceErrorCode) {
- this.instanceErrorCode = instanceErrorCode;
- return this;
- }
-
- public Builder privateIpAddress(final String privateIpAddress) {
- this.privateIpAddress = privateIpAddress;
- return this;
- }
-
- public Builder publicIpAddress(final String publicIpAddress) {
- this.publicIpAddress = publicIpAddress;
- return this;
- }
-
- public Builder roleName(final String roleName) {
- this.roleName = roleName;
- return this;
- }
+ public enum Slot {
+ PRODUCTION, STAGING,
+ UNRECOGNIZED;
+ }
- public Deployment build() {
- return new Deployment(deploymentName, deploymentSlot, deploymentStatus, deploymentLabel, deploymentURL,
- roleName, instanceName, instanceStatus, instanceStateDetails, instanceErrorCode, instanceSize,
- privateIpAddress, publicIpAddress);
- }
+ public enum Status {
+ RUNNING, SUSPENDED, RUNNING_TRANSITIONING, SUSPENDED_TRANSITIONING, STARTING, SUSPENDING, DEPLOYING, DELETING,
+ UNRECOGNIZED;
+ }
+ public enum InstanceStatus {
+ CREATING_VM, STARTING_VM, CREATING_ROLE, STARTING_ROLE, READY_ROLE, BUSY_ROLE, STOPPING_ROLE, STOPPING_VM,
+ DELETING_VM, STOPPED_VM, RESTARTING_ROLE, CYCLING_ROLE, FAILED_STARTING_ROLE, FAILED_STARTING_VM, UNRESPONSIVE_ROLE,
+ STOPPED_DEALLOCATED, PREPARING,
+ /** Unknown to Azure. */
+ UNKNOWN,
+ /** Not parsable into one of the above. */
+ UNRECOGNIZED,
}
- /**
- * The user-supplied name for this deployment.
- */
- private final String deploymentName;
+ /** The user-supplied name for this deployment. */
+ public String name() {
+ return name;
+ }
- /**
- * The environment to which the hosted service is deployed, either staging
- * or production.
- */
- private final DeploymentSlot deploymentSlot;
+ /** The environment to which the hosted service is deployed. */
+ public Slot slot() {
+ return slot;
+ }
- /**
- * The status of the deployment.
- */
- private final DeploymentStatus deploymentStatus;
+ public Status status() {
+ return status;
+ }
/**
* The user-supplied name of the deployment returned as a base-64 encoded
* string. This name can be used identify the deployment for your tracking
* purposes.
*/
- private final String deploymentLabel;
-
- /**
- * The URL 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
- */
- private final URI deploymentURL;
+ public String label() {
+ return label;
+ }
- /**
- * Specifies the name for the virtual machine. The name must be unique
- * within Windows Azure.
- */
- private final String roleName;
+ /** Specifies the name for the virtual machine. The name must be unique within Windows Azure. */
+ public String virtualMachineName() {
+ return virtualMachineName;
+ }
- /**
- * The name of the specific role instance (if any).
- */
- private final String instanceName;
+ /** The name of the specific role instance (if any). */
+ @Nullable public String instanceName() {
+ return instanceName;
+ }
- /**
- * The current status of this instance.
- */
- private final InstanceStatus instanceStatus;
+ /** The current status of this instance. */
+ public InstanceStatus instanceStatus() {
+ return instanceStatus;
+ }
/**
* The instance state is returned as an English human-readable string that,
@@ -166,7 +92,9 @@ public class Deployment {
* For example, when the instance is first being initialized a
* "Preparing Windows for first use." could be returned.
*/
- private final String instanceStateDetails;
+ @Nullable public String instanceStateDetails() {
+ return instanceStateDetails;
+ }
/**
* Error code of the latest role or VM start
@@ -187,123 +115,102 @@ public class Deployment {
* For web and worker roles this field returns an error code that can be provided to Windows Azure support to assist
* in resolution of errors. Typically this field will be empty.
*/
- private final String instanceErrorCode;
-
- /**
- * The size of the role instance
- */
- private final RoleSize instanceSize;
- private final String privateIpAddress;
- private final String publicIpAddress;
-
- public Deployment(String deploymentName, DeploymentSlot deploymentSlot, DeploymentStatus deploymentStatus,
- String deploymentLabel, URI deploymentURL, String roleName, String instanceName, InstanceStatus instanceStatus,
- String instanceStateDetails, String instanceErrorCode, RoleSize instanceSize, String privateIpAddress,
- String publicIpAddress) {
- this.deploymentName = deploymentName;
- this.deploymentSlot = deploymentSlot;
- this.deploymentStatus = deploymentStatus;
- this.deploymentLabel = deploymentLabel;
- this.deploymentURL = deploymentURL;
- this.roleName = roleName;
- this.instanceName = instanceName;
- this.instanceStatus = instanceStatus;
- this.instanceStateDetails = instanceStateDetails;
- this.instanceErrorCode = instanceErrorCode;
- this.instanceSize = instanceSize;
- this.privateIpAddress = privateIpAddress;
- this.publicIpAddress = publicIpAddress;
- }
-
- public String getDeploymentName() {
- return deploymentName;
- }
-
- public DeploymentSlot getDeploymentSlot() {
- return deploymentSlot;
- }
-
- public DeploymentStatus getDeploymentStatus() {
- return deploymentStatus;
- }
-
- public String getDeploymentLabel() {
- return deploymentLabel;
- }
-
- public URI getDeploymentURL() {
- return deploymentURL;
- }
-
- public String getRoleName() {
- return roleName;
- }
-
- public String getInstanceName() {
- return instanceName;
- }
-
- public InstanceStatus getInstanceStatus() {
- return instanceStatus;
- }
-
- public String getInstanceStateDetails() {
- return instanceStateDetails;
- }
-
- public String getInstanceErrorCode() {
+ @Nullable public String instanceErrorCode() {
return instanceErrorCode;
}
- public RoleSize getInstanceSize() {
+ public RoleSize instanceSize() {
return instanceSize;
}
- public String getPrivateIpAddress() {
+ public String privateIpAddress() {
return privateIpAddress;
}
- public String getPublicIpAddress() {
+ public String publicIpAddress() {
return publicIpAddress;
}
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result + ((deploymentName == null) ? 0 : deploymentName.hashCode());
- return result;
+ public static Deployment create(String name, Slot slot, Status status, String label, String virtualMachineName,
+ String instanceName, InstanceStatus instanceStatus, String instanceStateDetails, String instanceErrorCode,
+ RoleSize instanceSize, String privateIpAddress, String publicIpAddress) {
+ return new Deployment(name, slot, status, label, virtualMachineName, instanceName, instanceStatus, instanceStateDetails,
+ instanceErrorCode, instanceSize, privateIpAddress, publicIpAddress);
}
+ // TODO: Remove from here down with @AutoValue.
+ private Deployment(String name, Slot slot, Status status, String label, String virtualMachineName, String instanceName,
+ InstanceStatus instanceStatus, String instanceStateDetails, String instanceErrorCode, RoleSize instanceSize,
+ String privateIpAddress, String publicIpAddress) {
+ this.name = checkNotNull(name, "name");
+ this.slot = checkNotNull(slot, "slot");
+ this.status = checkNotNull(status, "status");
+ this.label = checkNotNull(label, "label");
+ this.virtualMachineName = checkNotNull(virtualMachineName, "virtualMachineName");
+ this.instanceName = instanceName;
+ this.instanceStatus = checkNotNull(instanceStatus, "instanceStatus");
+ this.instanceStateDetails = instanceStateDetails;
+ this.instanceErrorCode = instanceErrorCode;
+ this.instanceSize = checkNotNull(instanceSize, "instanceSize");
+ this.privateIpAddress = checkNotNull(privateIpAddress, "privateIpAddress");
+ this.publicIpAddress = checkNotNull(publicIpAddress, "publicIpAddress");
+ }
+
+ private final String name;
+ private final Slot slot;
+ private final Status status;
+ private final String label;
+ private final String virtualMachineName;
+ private final String instanceName;
+ private final InstanceStatus instanceStatus;
+ private final String instanceStateDetails;
+ private final String instanceErrorCode;
+ private final RoleSize instanceSize;
+ private final String privateIpAddress;
+ private final String publicIpAddress;
+
@Override
- public boolean equals(Object obj) {
- if (this == obj) {
+ public boolean equals(Object object) {
+ if (this == object) {
return true;
}
- if (obj == null) {
- return false;
- }
- if (getClass() != obj.getClass()) {
- return false;
- }
- Deployment other = (Deployment) obj;
- if (deploymentName == null) {
- if (other.deploymentName != null) {
- return false;
- }
- } else if (!deploymentName.equals(other.deploymentName)) {
+ if (object instanceof Deployment) {
+ Deployment that = Deployment.class.cast(object);
+ return equal(name, that.name)
+ && equal(slot, that.slot)
+ && equal(label, that.label)
+ && equal(virtualMachineName, that.virtualMachineName)
+ && equal(instanceName, that.instanceName)
+ && equal(instanceStatus, that.instanceStatus)
+ && equal(instanceStateDetails, that.instanceStateDetails)
+ && equal(instanceErrorCode, that.instanceErrorCode)
+ && equal(instanceSize, that.instanceSize)
+ && equal(privateIpAddress, that.privateIpAddress)
+ && equal(publicIpAddress, that.publicIpAddress);
+ } else {
return false;
}
- return true;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hashCode(name, slot, label, virtualMachineName, instanceName, instanceStatus, instanceStateDetails,
+ instanceErrorCode, instanceSize, privateIpAddress, publicIpAddress);
}
@Override
public String toString() {
- return "Deployment [deploymentName=" + deploymentName + ", deploymentSlot=" + deploymentSlot
- + ", deploymentStatus=" + deploymentStatus + ", deploymentLabel=" + deploymentLabel + ", deploymentURL="
- + deploymentURL + ", roleName=" + roleName + ", instanceName=" + instanceName + ", instanceStatus="
- + instanceStatus + ", instanceStateDetails=" + instanceStateDetails + ", instanceErrorCode="
- + instanceErrorCode + ", instanceSize=" + instanceSize + ", privateIpAddress=" + privateIpAddress
- + ", publicIpAddress=" + publicIpAddress + "]";
+ return toStringHelper(this)
+ .add("name", name)
+ .add("slot", slot)
+ .add("label", label)
+ .add("virtualMachineName", virtualMachineName)
+ .add("instanceName", instanceName)
+ .add("instanceStatus", instanceStatus)
+ .add("instanceStateDetails", instanceStateDetails)
+ .add("instanceErrorCode", instanceErrorCode)
+ .add("instanceSize", instanceSize)
+ .add("privateIpAddress", privateIpAddress)
+ .add("publicIpAddress", publicIpAddress).toString();
}
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/ece9a967/azurecompute/src/main/java/org/jclouds/azurecompute/domain/DeploymentParams.java
----------------------------------------------------------------------
diff --git a/azurecompute/src/main/java/org/jclouds/azurecompute/domain/DeploymentParams.java b/azurecompute/src/main/java/org/jclouds/azurecompute/domain/DeploymentParams.java
index 9ee4423..54325ae 100644
--- a/azurecompute/src/main/java/org/jclouds/azurecompute/domain/DeploymentParams.java
+++ b/azurecompute/src/main/java/org/jclouds/azurecompute/domain/DeploymentParams.java
@@ -94,7 +94,7 @@ public class DeploymentParams {
}
public Builder fromDeploymentParams(DeploymentParams in) {
- // TODO Since the roleName should be unique, is it a good idea to copy it ?
+ // TODO Since the virtualMachineName should be unique, is it a good idea to copy it ?
return this.name(in.getName()).sourceImageName(in.getSourceImageName()).username(in.getUsername())
.password(in.getPassword()).size(in.getSize());
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/ece9a967/azurecompute/src/main/java/org/jclouds/azurecompute/domain/DeploymentSlot.java
----------------------------------------------------------------------
diff --git a/azurecompute/src/main/java/org/jclouds/azurecompute/domain/DeploymentSlot.java b/azurecompute/src/main/java/org/jclouds/azurecompute/domain/DeploymentSlot.java
deleted file mode 100644
index 2e76b88..0000000
--- a/azurecompute/src/main/java/org/jclouds/azurecompute/domain/DeploymentSlot.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * 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 DeploymentSlot {
- PRODUCTION, STAGING;
-
- public String value() {
- return CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, name());
- }
-
- @Override
- public String toString() {
- return value();
- }
-
- public static DeploymentSlot 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/ece9a967/azurecompute/src/main/java/org/jclouds/azurecompute/domain/DeploymentStatus.java
----------------------------------------------------------------------
diff --git a/azurecompute/src/main/java/org/jclouds/azurecompute/domain/DeploymentStatus.java b/azurecompute/src/main/java/org/jclouds/azurecompute/domain/DeploymentStatus.java
deleted file mode 100644
index eb34aa5..0000000
--- a/azurecompute/src/main/java/org/jclouds/azurecompute/domain/DeploymentStatus.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * 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 DeploymentStatus {
- RUNNING, SUSPENDED, RUNNING_TRANSITIONING, SUSPENDED_TRANSITIONING, STARTING, SUSPENDING, DEPLOYING, DELETING;
-
- public String value() {
- return CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, name());
- }
-
- @Override
- public String toString() {
- return value();
- }
-
- public static DeploymentStatus 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/ece9a967/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
deleted file mode 100644
index 51b5d24..0000000
--- a/azurecompute/src/main/java/org/jclouds/azurecompute/domain/InstanceStatus.java
+++ /dev/null
@@ -1,155 +0,0 @@
-/*
- * 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/ece9a967/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
index 6839091..5e2aa8b 100644
--- a/azurecompute/src/main/java/org/jclouds/azurecompute/domain/RoleSize.java
+++ b/azurecompute/src/main/java/org/jclouds/azurecompute/domain/RoleSize.java
@@ -16,27 +16,6 @@
*/
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;
- }
- }
+ EXTRA_SMALL, SMALL, MEDIUM, LARGE, EXTRA_LARGE, UNRECOGNIZED;
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/ece9a967/azurecompute/src/main/java/org/jclouds/azurecompute/xml/DeploymentHandler.java
----------------------------------------------------------------------
diff --git a/azurecompute/src/main/java/org/jclouds/azurecompute/xml/DeploymentHandler.java b/azurecompute/src/main/java/org/jclouds/azurecompute/xml/DeploymentHandler.java
index 8d92c72..50e8294 100644
--- a/azurecompute/src/main/java/org/jclouds/azurecompute/xml/DeploymentHandler.java
+++ b/azurecompute/src/main/java/org/jclouds/azurecompute/xml/DeploymentHandler.java
@@ -16,100 +16,130 @@
*/
package org.jclouds.azurecompute.xml;
-import com.google.common.collect.Lists;
-import java.net.URI;
-import java.util.List;
+import static com.google.common.base.CaseFormat.UPPER_CAMEL;
+import static com.google.common.base.CaseFormat.UPPER_UNDERSCORE;
+import static com.google.common.base.Charsets.UTF_8;
+import static com.google.common.io.BaseEncoding.base64;
+import static org.jclouds.util.SaxUtils.currentOrNull;
+
import org.jclouds.azurecompute.domain.Deployment;
-import org.jclouds.azurecompute.domain.DeploymentSlot;
-import org.jclouds.azurecompute.domain.DeploymentStatus;
-import org.jclouds.azurecompute.domain.InstanceStatus;
+import org.jclouds.azurecompute.domain.Deployment.InstanceStatus;
+import org.jclouds.azurecompute.domain.Deployment.Slot;
+import org.jclouds.azurecompute.domain.Deployment.Status;
import org.jclouds.azurecompute.domain.RoleSize;
import org.jclouds.http.functions.ParseSax;
import org.xml.sax.Attributes;
-import org.xml.sax.SAXException;
-import static com.google.common.base.Charsets.UTF_8;
-import static com.google.common.io.BaseEncoding.base64;
-import static org.jclouds.util.SaxUtils.currentOrNull;
-import static org.jclouds.util.SaxUtils.equalsOrSuffix;
+import com.google.common.annotations.VisibleForTesting;
/**
- * @see <a href="http://msdn.microsoft.com/en-us/library/ee460804" >api</a>
+ * @see <a href="http://msdn.microsoft.com/en-us/library/ee460804" >Response body description</a>.
*/
-public class DeploymentHandler extends ParseSax.HandlerForGeneratedRequestWithResult<Deployment> {
+public final class DeploymentHandler extends ParseSax.HandlerForGeneratedRequestWithResult<Deployment> {
+ private String name;
+ private Slot slot;
+ private Status status;
+ private String label;
+ private String virtualMachineName;
+ private String instanceName;
+ private InstanceStatus instanceStatus;
+ private String instanceStateDetails;
+ private String instanceErrorCode;
+ private RoleSize instanceSize;
+ private String privateIpAddress;
+ private String publicIpAddress;
- private List<String> elements = Lists.newArrayList();
- private StringBuilder currentText = new StringBuilder();
- private Deployment.Builder builder = Deployment.builder();
+ private int depth;
+ private final StringBuilder currentText = new StringBuilder();
- @Override
- public Deployment getResult() {
- try {
- return builder.build();
- } finally {
- builder = Deployment.builder();
- }
+ @Override public Deployment getResult() { // Fields don't need to be reset as this isn't used in a loop.
+ return Deployment.create(name, slot, status, label, virtualMachineName, instanceName, instanceStatus, //
+ instanceStateDetails, instanceErrorCode, instanceSize, privateIpAddress, publicIpAddress);
}
- @Override
- public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
- elements.add(qName);
+ @Override public void startElement(String url, String name, String qName, Attributes attributes) {
+ depth++;
}
- @Override
- public void endElement(String uri, String name, String qName) throws SAXException {
- if (equalsOrSuffix(qName, "Name") && "Deployment".equals(elements.get(elements.size() - 2))) {
- builder.deploymentName(currentOrNull(currentText));
- } else if (equalsOrSuffix(qName, "DeploymentSlot")) {
- final String dpltSlot = currentOrNull(currentText);
- if (dpltSlot != null) {
- builder.deploymentSlot(DeploymentSlot.fromValue(dpltSlot));
+ @Override public void endElement(String ignoredUri, String ignoredName, String qName) {
+ if (qName.equals("Name") && depth == 2) {
+ name = currentOrNull(currentText);
+ } else if (qName.equals("DeploymentSlot")) {
+ String slotText = currentOrNull(currentText);
+ if (slotText != null) {
+ slot = parseSlot(slotText);
}
- } else if (equalsOrSuffix(qName, "Status")) {
- String deploymentStatus = currentOrNull(currentText);
- if (deploymentStatus != null) {
- builder.deploymentStatus(DeploymentStatus.fromValue(deploymentStatus));
+ } else if (qName.equals("Status")) {
+ String statusText = currentOrNull(currentText);
+ if (statusText != null) {
+ status = parseStatus(statusText);
}
- } else if (equalsOrSuffix(qName, "Label")) {
- String label = currentOrNull(currentText);
- if (label != null) {
- builder.deploymentLabel(new String(base64().decode(label), UTF_8));
+ } else if (qName.equals("Label")) {
+ String labelText = currentOrNull(currentText);
+ if (labelText != null) {
+ label = new String(base64().decode(labelText), UTF_8);
}
- } else if (equalsOrSuffix(qName, "Url")) {
- final String url = currentOrNull(currentText);
- if (url != null) {
- builder.deploymentURL(URI.create(url));
+ } else if (qName.equals("RoleName")) {
+ virtualMachineName = currentOrNull(currentText);
+ } else if (qName.equals("InstanceName")) {
+ instanceName = currentOrNull(currentText);
+ } else if (qName.equals("InstanceStatus")) {
+ String instanceStatusText = currentOrNull(currentText);
+ if (instanceStatusText != null) {
+ instanceStatus = parseInstanceStatus(instanceStatusText);
}
- } else if (equalsOrSuffix(qName, "RoleName")) {
- builder.roleName(currentOrNull(currentText));
- } else if (equalsOrSuffix(qName, "InstanceName")) {
- builder.instanceName(currentOrNull(currentText));
- } else if (equalsOrSuffix(qName, "InstanceStatus")) {
- String instanceStatus = currentOrNull(currentText);
- if (instanceStatus != null) {
- builder.instanceStatus(InstanceStatus.fromValue(instanceStatus));
+ } else if (qName.equals("InstanceStateDetails")) {
+ instanceStateDetails = currentOrNull(currentText);
+ } else if (qName.equals("InstanceErrorCode")) {
+ instanceErrorCode = currentOrNull(currentText);
+ } else if (qName.equals("InstanceSize")) {
+ String instanceSizeText = currentOrNull(currentText);
+ if (instanceSizeText != null) {
+ instanceSize = parseRoleSize(instanceSizeText);
}
- } else if (equalsOrSuffix(qName, "InstanceStateDetails")) {
- builder.instanceStateDetails(currentOrNull(currentText));
- } else if (equalsOrSuffix(qName, "InstanceErrorCode")) {
- builder.instanceErrorCode(currentOrNull(currentText));
- } else if (equalsOrSuffix(qName, "InstanceSize")) {
- String instanceSize = currentOrNull(currentText);
- if (instanceSize != null) {
- builder.instanceSize(RoleSize.fromValue(instanceSize));
- }
- } else if (equalsOrSuffix(qName, "IpAddress")) {
- builder.privateIpAddress(currentOrNull(currentText));
- } else if (equalsOrSuffix(qName, "Vip")) {
- builder.publicIpAddress(currentOrNull(currentText));
+ } else if (qName.equals("IpAddress")) {
+ privateIpAddress = currentOrNull(currentText);
+ } else if (qName.equals("Vip")) {
+ publicIpAddress = currentOrNull(currentText);
}
-
currentText.setLength(0);
- elements.remove(elements.size() - 1);
+ depth--;
}
- @Override
- public void characters(char ch[], int start, int length) {
+ @Override public void characters(char ch[], int start, int length) {
currentText.append(ch, start, length);
}
+
+ private static Status parseStatus(String status) {
+ try {
+ return Status.valueOf(UPPER_CAMEL.to(UPPER_UNDERSCORE, status));
+ } catch (IllegalArgumentException e) {
+ return Status.UNRECOGNIZED;
+ }
+ }
+
+ private static Slot parseSlot(String slot) {
+ try {
+ return Slot.valueOf(UPPER_CAMEL.to(UPPER_UNDERSCORE, slot));
+ } catch (IllegalArgumentException e) {
+ return Slot.UNRECOGNIZED;
+ }
+ }
+
+ @VisibleForTesting static InstanceStatus parseInstanceStatus(String instanceStatus) {
+ try {
+ // Azure isn't exactly upper-camel, as some states end in VM, not Vm.
+ return InstanceStatus.valueOf(UPPER_CAMEL.to(UPPER_UNDERSCORE, instanceStatus).replace("V_M", "VM"));
+ } catch (IllegalArgumentException e) {
+ return InstanceStatus.UNRECOGNIZED;
+ }
+ }
+
+ private static RoleSize parseRoleSize(String roleSize) {
+ try {
+ return RoleSize.valueOf(UPPER_CAMEL.to(UPPER_UNDERSCORE, roleSize));
+ } catch (IllegalArgumentException e) {
+ return RoleSize.UNRECOGNIZED;
+ }
+ }
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/ece9a967/azurecompute/src/test/java/org/jclouds/azurecompute/features/DeploymentApiMockTest.java
----------------------------------------------------------------------
diff --git a/azurecompute/src/test/java/org/jclouds/azurecompute/features/DeploymentApiMockTest.java b/azurecompute/src/test/java/org/jclouds/azurecompute/features/DeploymentApiMockTest.java
index e0bd956..90f34a9 100644
--- a/azurecompute/src/test/java/org/jclouds/azurecompute/features/DeploymentApiMockTest.java
+++ b/azurecompute/src/test/java/org/jclouds/azurecompute/features/DeploymentApiMockTest.java
@@ -16,16 +16,18 @@
*/
package org.jclouds.azurecompute.features;
-import com.squareup.okhttp.mockwebserver.MockResponse;
-import com.squareup.okhttp.mockwebserver.MockWebServer;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertNull;
+
import org.jclouds.azurecompute.domain.DeploymentParams;
import org.jclouds.azurecompute.domain.OSType;
import org.jclouds.azurecompute.domain.RoleSize;
import org.jclouds.azurecompute.internal.BaseAzureComputeApiMockTest;
-import org.jclouds.azurecompute.parse.GetDeploymentTest;
+import org.jclouds.azurecompute.xml.DeploymentHandlerTest;
import org.testng.annotations.Test;
-import static org.assertj.core.api.Assertions.assertThat;
+import com.squareup.okhttp.mockwebserver.MockResponse;
+import com.squareup.okhttp.mockwebserver.MockWebServer;
@Test(groups = "unit", testName = "DeploymentApiMockTest")
public class DeploymentApiMockTest extends BaseAzureComputeApiMockTest {
@@ -42,7 +44,7 @@ public class DeploymentApiMockTest extends BaseAzureComputeApiMockTest {
.sourceImageName("OpenLogic__OpenLogic-CentOS-62-20120531-en-us-30GB.vhd")
.storageAccount("portalvhds0g7xhnq2x7t21").build();
- assertThat(api.create(params)).isEqualTo("request-1");
+ assertEquals(api.create(params), "request-1");
assertSent(server, "POST", "/services/hostedservices/myservice/deployments", "/deploymentparams.xml");
} finally {
@@ -57,7 +59,7 @@ public class DeploymentApiMockTest extends BaseAzureComputeApiMockTest {
try {
DeploymentApi api = api(server.getUrl("/")).getDeploymentApiForService("myservice");
- assertThat(api.get("mydeployment")).isEqualTo(GetDeploymentTest.expected());
+ assertEquals(api.get("mydeployment"), DeploymentHandlerTest.expected());
assertSent(server, "GET", "/services/hostedservices/myservice/deployments/mydeployment");
} finally {
@@ -72,7 +74,7 @@ public class DeploymentApiMockTest extends BaseAzureComputeApiMockTest {
try {
DeploymentApi api = api(server.getUrl("/")).getDeploymentApiForService("myservice");
- assertThat(api.get("mydeployment")).isNull();
+ assertNull(api.get("mydeployment"));
assertSent(server, "GET", "/services/hostedservices/myservice/deployments/mydeployment");
} finally {
@@ -87,7 +89,7 @@ public class DeploymentApiMockTest extends BaseAzureComputeApiMockTest {
try {
DeploymentApi api = api(server.getUrl("/")).getDeploymentApiForService("myservice");
- assertThat(api.delete("mydeployment")).isEqualTo("request-1");
+ assertEquals(api.delete("mydeployment"), "request-1");
assertSent(server, "DELETE", "/services/hostedservices/myservice/deployments/mydeployment");
} finally {
@@ -102,7 +104,7 @@ public class DeploymentApiMockTest extends BaseAzureComputeApiMockTest {
try {
DeploymentApi api = api(server.getUrl("/")).getDeploymentApiForService("myservice");
- assertThat(api.delete("mydeployment")).isNull();
+ assertNull(api.delete("mydeployment"));
assertSent(server, "DELETE", "/services/hostedservices/myservice/deployments/mydeployment");
} finally {
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/ece9a967/azurecompute/src/test/java/org/jclouds/azurecompute/parse/GetDeploymentTest.java
----------------------------------------------------------------------
diff --git a/azurecompute/src/test/java/org/jclouds/azurecompute/parse/GetDeploymentTest.java b/azurecompute/src/test/java/org/jclouds/azurecompute/parse/GetDeploymentTest.java
deleted file mode 100644
index 76bad81..0000000
--- a/azurecompute/src/test/java/org/jclouds/azurecompute/parse/GetDeploymentTest.java
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * 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.parse;
-
-import java.io.InputStream;
-import java.net.URI;
-import org.jclouds.azurecompute.domain.Deployment;
-import org.jclouds.azurecompute.domain.DeploymentSlot;
-import org.jclouds.azurecompute.domain.DeploymentStatus;
-import org.jclouds.azurecompute.domain.InstanceStatus;
-import org.jclouds.azurecompute.domain.RoleSize;
-import org.jclouds.azurecompute.xml.DeploymentHandler;
-import org.jclouds.http.functions.BaseHandlerTest;
-import org.testng.annotations.Test;
-
-import static org.testng.Assert.assertEquals;
-
-@Test(groups = "unit", testName = "GetDeploymentTest")
-public class GetDeploymentTest extends BaseHandlerTest {
-
- public void test() {
- InputStream is = getClass().getResourceAsStream("/deployment.xml");
-
- Deployment expected = expected();
-
- DeploymentHandler handler = injector.getInstance(DeploymentHandler.class);
- Deployment result = factory.create(handler).parse(is);
-
- assertEquals(result.toString(), expected.toString());
- }
-
- public static Deployment expected() {
- return Deployment.builder()
- .deploymentName("neotysss")
- .deploymentSlot(DeploymentSlot.PRODUCTION)
- .deploymentStatus(DeploymentStatus.RUNNING)
- .deploymentLabel("neotysss")
- .deploymentURL(URI.create("http://neotysss.cloudapp.net/"))
- .roleName("neotysss")
- .instanceName("neotysss")
- .instanceStatus(InstanceStatus.READY_ROLE)
- .instanceSize(RoleSize.MEDIUM)
- .privateIpAddress("10.59.244.162")
- .publicIpAddress("168.63.27.148")
- .build();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/ece9a967/azurecompute/src/test/java/org/jclouds/azurecompute/xml/DeploymentHandlerTest.java
----------------------------------------------------------------------
diff --git a/azurecompute/src/test/java/org/jclouds/azurecompute/xml/DeploymentHandlerTest.java b/azurecompute/src/test/java/org/jclouds/azurecompute/xml/DeploymentHandlerTest.java
new file mode 100644
index 0000000..d622b42
--- /dev/null
+++ b/azurecompute/src/test/java/org/jclouds/azurecompute/xml/DeploymentHandlerTest.java
@@ -0,0 +1,86 @@
+/*
+ * 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.xml;
+
+import static org.jclouds.azurecompute.xml.DeploymentHandler.parseInstanceStatus;
+import static org.testng.Assert.assertEquals;
+
+import java.io.InputStream;
+
+import org.jclouds.azurecompute.domain.Deployment;
+import org.jclouds.azurecompute.domain.Deployment.InstanceStatus;
+import org.jclouds.azurecompute.domain.Deployment.Slot;
+import org.jclouds.azurecompute.domain.Deployment.Status;
+import org.jclouds.azurecompute.domain.RoleSize;
+import org.jclouds.http.functions.BaseHandlerTest;
+import org.testng.annotations.Test;
+
+@Test(groups = "unit", testName = "DeploymentHandlerTest")
+public class DeploymentHandlerTest extends BaseHandlerTest {
+
+ /**
+ * Covers values listed <a href="http://msdn.microsoft.com/en-us/library/azure/ee460804.aspx#RoleInstanceList">here</a>.
+ */
+ public void parseInstanceStatus_Recognized() {
+ assertEquals(parseInstanceStatus("Unknown"), InstanceStatus.UNKNOWN);
+ assertEquals(parseInstanceStatus("CreatingVM"), InstanceStatus.CREATING_VM);
+ assertEquals(parseInstanceStatus("StartingVM"), InstanceStatus.STARTING_VM);
+ assertEquals(parseInstanceStatus("CreatingRole"), InstanceStatus.CREATING_ROLE);
+ assertEquals(parseInstanceStatus("StartingRole"), InstanceStatus.STARTING_ROLE);
+ assertEquals(parseInstanceStatus("ReadyRole"), InstanceStatus.READY_ROLE);
+ assertEquals(parseInstanceStatus("BusyRole"), InstanceStatus.BUSY_ROLE);
+ assertEquals(parseInstanceStatus("StoppingRole"), InstanceStatus.STOPPING_ROLE);
+ assertEquals(parseInstanceStatus("StoppingVM"), InstanceStatus.STOPPING_VM);
+ assertEquals(parseInstanceStatus("DeletingVM"), InstanceStatus.DELETING_VM);
+ assertEquals(parseInstanceStatus("StoppedVM"), InstanceStatus.STOPPED_VM);
+ assertEquals(parseInstanceStatus("RestartingRole"), InstanceStatus.RESTARTING_ROLE);
+ assertEquals(parseInstanceStatus("CyclingRole"), InstanceStatus.CYCLING_ROLE);
+ assertEquals(parseInstanceStatus("FailedStartingRole"), InstanceStatus.FAILED_STARTING_ROLE);
+ assertEquals(parseInstanceStatus("FailedStartingVM"), InstanceStatus.FAILED_STARTING_VM);
+ assertEquals(parseInstanceStatus("UnresponsiveRole"), InstanceStatus.UNRESPONSIVE_ROLE);
+ assertEquals(parseInstanceStatus("StoppedDeallocated"), InstanceStatus.STOPPED_DEALLOCATED);
+ assertEquals(parseInstanceStatus("Preparing"), InstanceStatus.PREPARING);
+ }
+
+ public void parseInstanceStatus_Unrecognized() {
+ assertEquals(parseInstanceStatus("FooAddedToday"), InstanceStatus.UNRECOGNIZED);
+ }
+
+ public void test() {
+ InputStream is = getClass().getResourceAsStream("/deployment.xml");
+ Deployment result = factory.create(new DeploymentHandler()).parse(is);
+
+ assertEquals(result, expected());
+ }
+
+ public static Deployment expected() {
+ return Deployment.create( //
+ "deployment_name", // name
+ Slot.PRODUCTION, // slot
+ Status.RUNNING, // status
+ "neotysss", // label
+ "role_name_from_role_list", // virtualMachineName
+ "instance_name", // instanceName
+ InstanceStatus.READY_ROLE, // instanceStatus
+ null, // instanceStateDetails
+ null, // instanceErrorCode
+ RoleSize.MEDIUM, // instanceSize
+ "10.59.244.162", // privateIpAddress
+ "168.63.27.148" // publicIpAddress
+ );
+ }
+}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/ece9a967/azurecompute/src/test/resources/deployment.xml
----------------------------------------------------------------------
diff --git a/azurecompute/src/test/resources/deployment.xml b/azurecompute/src/test/resources/deployment.xml
index c44fc7a..b3029d6 100644
--- a/azurecompute/src/test/resources/deployment.xml
+++ b/azurecompute/src/test/resources/deployment.xml
@@ -1,70 +1,74 @@
<Deployment xmlns="http://schemas.microsoft.com/windowsazure" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
- <Name>neotysss</Name>
- <DeploymentSlot>Production</DeploymentSlot>
- <PrivateID>05aa8ec5d8ee4215894431c7db401b31</PrivateID>
- <Status>Running</Status>
- <Label>bmVvdHlzc3M=</Label>
- <Url>http://neotysss.cloudapp.net/</Url>
- <Configuration>PFNlcnZpY2VDb25maWd1cmF0aW9uIHhtbG5zOnhzaT0iaHR0cDovL3d3dy53My5vcmcvMjAwMS9YTUxTY2hlbWEtaW5zdGFuY2UiIHhtbG5zOnhzZD0iaHR0cDovL3d3dy53My5vcmcvMjAwMS9YTUxTY2hlbWEiIHhtbG5zPSJodHRwOi8vc2NoZW1hcy5taWNyb3NvZnQuY29tL1NlcnZpY2VIb3N0aW5nLzIwMDgvMTAvU2VydmljZUNvbmZpZ3VyYXRpb24iPg0KICA8Um9sZSBuYW1lPSJuZW90eXNzcyI+DQogICAgPEluc3RhbmNlcyBjb3VudD0iMSIgLz4NCiAgPC9Sb2xlPg0KPC9TZXJ2aWNlQ29uZmlndXJhdGlvbj4=</Configuration>
- <RoleInstanceList>
- <RoleInstance>
- <RoleName>neotysss</RoleName>
- <InstanceName>neotysss</InstanceName>
- <InstanceStatus>ReadyRole</InstanceStatus>
- <InstanceUpgradeDomain>0</InstanceUpgradeDomain>
- <InstanceFaultDomain>0</InstanceFaultDomain>
- <InstanceSize>Medium</InstanceSize>
- <InstanceStateDetails/>
- <IpAddress>10.59.244.162</IpAddress>
- <InstanceEndpoints>
+ <Name>deployment_name</Name>
+ <DeploymentSlot>Production</DeploymentSlot>
+ <PrivateID>05aa8ec5d8ee4215894431c7db401b31</PrivateID>
+ <Status>Running</Status>
+ <Label>bmVvdHlzc3M=</Label>
+ <Url>http://neotysss.cloudapp.net/</Url>
+ <Configuration>
+ PFNlcnZpY2VDb25maWd1cmF0aW9uIHhtbG5zOnhzaT0iaHR0cDovL3d3dy53My5vcmcvMjAwMS9YTUxTY2hlbWEtaW5zdGFuY2UiIHhtbG5zOnhzZD0iaHR0cDovL3d3dy53My5vcmcvMjAwMS9YTUxTY2hlbWEiIHhtbG5zPSJodHRwOi8vc2NoZW1hcy5taWNyb3NvZnQuY29tL1NlcnZpY2VIb3N0aW5nLzIwMDgvMTAvU2VydmljZUNvbmZpZ3VyYXRpb24iPg0KICA8Um9sZSBuYW1lPSJuZW90eXNzcyI+DQogICAgPEluc3RhbmNlcyBjb3VudD0iMSIgLz4NCiAgPC9Sb2xlPg0KPC9TZXJ2aWNlQ29uZmlndXJhdGlvbj4=
+ </Configuration>
+ <RoleInstanceList>
+ <RoleInstance>
+ <RoleName>role_name_from_instance</RoleName>
+ <InstanceName>instance_name</InstanceName>
+ <InstanceStatus>ReadyRole</InstanceStatus>
+ <InstanceUpgradeDomain>0</InstanceUpgradeDomain>
+ <InstanceFaultDomain>0</InstanceFaultDomain>
+ <InstanceSize>Medium</InstanceSize>
+ <InstanceStateDetails/>
+ <IpAddress>10.59.244.162</IpAddress>
+ <InstanceEndpoints>
<InstanceEndpoint>
- <Name>SSH</Name>
- <Vip>168.63.27.148</Vip>
- <PublicPort>22</PublicPort>
- <LocalPort>22</LocalPort>
- <Protocol>tcp</Protocol>
+ <Name>SSH</Name>
+ <Vip>168.63.27.148</Vip>
+ <PublicPort>22</PublicPort>
+ <LocalPort>22</LocalPort>
+ <Protocol>tcp</Protocol>
</InstanceEndpoint>
- </InstanceEndpoints>
- <PowerState>Started</PowerState>
- <HostName>neotys</HostName>
+ </InstanceEndpoints>
+ <PowerState>Started</PowerState>
+ <HostName>host_name</HostName>
</RoleInstance>
- </RoleInstanceList>
- <UpgradeDomainCount>1</UpgradeDomainCount>
- <RoleList>
- <Role i:type="PersistentVMRole">
- <RoleName>neotysss</RoleName>
- <OsVersion/>
- <RoleType>PersistentVMRole</RoleType>
- <ConfigurationSets>
+ </RoleInstanceList>
+ <UpgradeDomainCount>1</UpgradeDomainCount>
+ <RoleList>
+ <Role i:type="PersistentVMRole">
+ <RoleName>role_name_from_role_list</RoleName>
+ <OsVersion/>
+ <RoleType>PersistentVMRole</RoleType>
+ <ConfigurationSets>
<ConfigurationSet i:type="NetworkConfigurationSet">
- <ConfigurationSetType>NetworkConfiguration</ConfigurationSetType>
- <InputEndpoints>
+ <ConfigurationSetType>NetworkConfiguration</ConfigurationSetType>
+ <InputEndpoints>
<InputEndpoint>
- <LocalPort>22</LocalPort>
- <Name>SSH</Name>
- <Port>22</Port>
- <Protocol>tcp</Protocol>
- <Vip>168.63.27.148</Vip>
+ <LocalPort>22</LocalPort>
+ <Name>SSH</Name>
+ <Port>22</Port>
+ <Protocol>tcp</Protocol>
+ <Vip>168.63.27.148</Vip>
</InputEndpoint>
- </InputEndpoints>
- <SubnetNames/>
+ </InputEndpoints>
+ <SubnetNames/>
</ConfigurationSet>
- </ConfigurationSets>
- <DataVirtualHardDisks/>
- <OSVirtualHardDisk>
- <HostCaching>ReadWrite</HostCaching>
- <DiskName>neotysss-neotysss-0-20120824091357</DiskName>
- <MediaLink>http://portalvhds0g7xhnq2x7t21.blob.core.windows.net/disks/neotysss/MSFT__Win2K8R2SP1-120612-1520-121206-01-en-us-30GB.vhd</MediaLink>
- <SourceImageName>MSFT__Win2K8R2SP1-120612-1520-121206-01-en-us-30GB.vhd</SourceImageName>
- <OS>Windows</OS>
- </OSVirtualHardDisk>
- <RoleSize>Medium</RoleSize>
+ </ConfigurationSets>
+ <DataVirtualHardDisks/>
+ <OSVirtualHardDisk>
+ <HostCaching>ReadWrite</HostCaching>
+ <DiskName>neotysss-neotysss-0-20120824091357</DiskName>
+ <MediaLink>
+ http://portalvhds0g7xhnq2x7t21.blob.core.windows.net/disks/neotysss/MSFT__Win2K8R2SP1-120612-1520-121206-01-en-us-30GB.vhd
+ </MediaLink>
+ <SourceImageName>MSFT__Win2K8R2SP1-120612-1520-121206-01-en-us-30GB.vhd</SourceImageName>
+ <OS>Windows</OS>
+ </OSVirtualHardDisk>
+ <RoleSize>Medium</RoleSize>
</Role>
- </RoleList>
- <SdkVersion/>
- <Locked>false</Locked>
- <RollbackAllowed>false</RollbackAllowed>
- <CreatedTime>2012-08-24T09:13:53Z</CreatedTime>
- <LastModifiedTime>2012-08-27T08:55:13Z</LastModifiedTime>
- <ExtendedProperties/>
-</Deployment>
\ No newline at end of file
+ </RoleList>
+ <SdkVersion/>
+ <Locked>false</Locked>
+ <RollbackAllowed>false</RollbackAllowed>
+ <CreatedTime>2012-08-24T09:13:53Z</CreatedTime>
+ <LastModifiedTime>2012-08-27T08:55:13Z</LastModifiedTime>
+ <ExtendedProperties/>
+</Deployment>
[02/11] Cleanup output-only HostedService object.
Posted by ad...@apache.org.
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/de2f415a/azurecompute/src/test/resources/hostedservice.xml
----------------------------------------------------------------------
diff --git a/azurecompute/src/test/resources/hostedservice.xml b/azurecompute/src/test/resources/hostedservice.xml
index 625aeb3..bdece1b 100644
--- a/azurecompute/src/test/resources/hostedservice.xml
+++ b/azurecompute/src/test/resources/hostedservice.xml
@@ -1,10 +1,13 @@
<HostedService xmlns="http://schemas.microsoft.com/windowsazure">
- <Url>https://management.core.windows.net/eb0347c3-68d4-4550-9b39-5e7e0f92f7db/services/hostedservices/neotys</Url>
+ <Url>https://api/services/hostedservices/neotys</Url>
<ServiceName>neotys</ServiceName>
<HostedServiceProperties>
- <Description>Implicitly created hosted service2012-08-06 14:55
- </Description>
+ <Description>Implicitly created hosted service2012-08-06 14:55</Description>
<Location>West Europe</Location>
<Label>bmVvdHlz</Label>
+ <Status>Created</Status>
+ <DateCreated>2012-08-06T14:55:17Z</DateCreated>
+ <DateLastModified>2012-08-06T15:50:34Z</DateLastModified>
+ <ExtendedProperties />
</HostedServiceProperties>
</HostedService>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/de2f415a/azurecompute/src/test/resources/hostedservice_details.xml
----------------------------------------------------------------------
diff --git a/azurecompute/src/test/resources/hostedservice_details.xml b/azurecompute/src/test/resources/hostedservice_details.xml
deleted file mode 100644
index d730cc7..0000000
--- a/azurecompute/src/test/resources/hostedservice_details.xml
+++ /dev/null
@@ -1,13 +0,0 @@
-<HostedService xmlns="http://schemas.microsoft.com/windowsazure">
- <Url>https://management.core.windows.net/eb0347c3-68d4-4550-9b39-5e7e0f92f7db/services/hostedservices/neotys</Url>
- <ServiceName>neotys</ServiceName>
- <HostedServiceProperties>
- <Description>Implicitly created hosted service2012-08-06 14:55</Description>
- <Location>West Europe</Location>
- <Label>bmVvdHlz</Label>
- <Status>Created</Status>
- <DateCreated>2012-08-06T14:55:17Z</DateCreated>
- <DateLastModified>2012-08-06T15:50:34Z</DateLastModified>
- <ExtendedProperties />
- </HostedServiceProperties>
-</HostedService>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/de2f415a/azurecompute/src/test/resources/hostedservices.xml
----------------------------------------------------------------------
diff --git a/azurecompute/src/test/resources/hostedservices.xml b/azurecompute/src/test/resources/hostedservices.xml
index 66b7589..3cee89b 100644
--- a/azurecompute/src/test/resources/hostedservices.xml
+++ b/azurecompute/src/test/resources/hostedservices.xml
@@ -1,10 +1,10 @@
<HostedServices xmlns="http://schemas.microsoft.com/windowsazure"
xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<HostedService>
- <Url>https://management.core.windows.net/eb0347c3-68d4-4550-9b39-5e7e0f92f7db/services/hostedservices/neotys</Url>
+ <Url>https://api/services/hostedservices/neotys</Url>
<ServiceName>neotys</ServiceName>
<HostedServiceProperties>
- <Description>Implicitly created hosted service2012-08-06 14:55</Description>
+ <Description>Implicitly created hosted service2012-08-06 14:55</Description>
<Location>West Europe</Location>
<Label>bmVvdHlz</Label>
<Status>Created</Status>
@@ -14,7 +14,7 @@
</HostedServiceProperties>
</HostedService>
<HostedService>
- <Url>https://management.core.windows.net/eb0347c3-68d4-4550-9b39-5e7e0f92f7db/services/hostedservices/neotys3</Url>
+ <Url>https://api/services/hostedservices/neotys3</Url>
<ServiceName>neotys3</ServiceName>
<HostedServiceProperties>
<Description i:nil="true" />
[10/11] git commit: Cleanup output-only Location object.
Posted by ad...@apache.org.
Cleanup output-only Location object.
Project: http://git-wip-us.apache.org/repos/asf/jclouds-labs/repo
Commit: http://git-wip-us.apache.org/repos/asf/jclouds-labs/commit/f4af63fb
Tree: http://git-wip-us.apache.org/repos/asf/jclouds-labs/tree/f4af63fb
Diff: http://git-wip-us.apache.org/repos/asf/jclouds-labs/diff/f4af63fb
Branch: refs/heads/master
Commit: f4af63fb433a0b52cfc035aec89decdba764fd16
Parents: da40d63
Author: Adrian Cole <ac...@twitter.com>
Authored: Mon Oct 20 08:45:21 2014 -0400
Committer: Adrian Cole <ac...@twitter.com>
Committed: Mon Oct 20 13:26:54 2014 -0400
----------------------------------------------------------------------
.../jclouds/azurecompute/domain/Location.java | 140 ++++++-------------
.../azurecompute/xml/ListLocationsHandler.java | 35 ++---
.../azurecompute/xml/LocationHandler.java | 41 +++---
.../azurecompute/features/DiskApiLiveTest.java | 2 +-
.../features/HostedServiceApiLiveTest.java | 2 +-
.../azurecompute/features/ImageApiLiveTest.java | 2 +-
.../features/LocationApiLiveTest.java | 34 ++---
.../features/LocationApiMockTest.java | 4 +-
.../azurecompute/parse/ListLocationsTest.java | 79 -----------
.../xml/ListLocationsHandlerTest.java | 52 +++++++
10 files changed, 141 insertions(+), 250 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/f4af63fb/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
index 2b51a58..0949d46 100644
--- a/azurecompute/src/main/java/org/jclouds/azurecompute/domain/Location.java
+++ b/azurecompute/src/main/java/org/jclouds/azurecompute/domain/Location.java
@@ -16,135 +16,73 @@
*/
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.Objects.equal;
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();
+import java.util.List;
- /**
- * @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;
- }
+import com.google.common.base.Objects;
- public Location build() {
- return new Location(name, displayName, availableServices.build());
- }
+/** A data center location that is valid for your subscription. */
+public final class Location {
- public Builder fromLocation(Location in) {
- return this.name(in.getName()).displayName(in.getDisplayName()).availableServices(in.getAvailableServices());
- }
+ /** The name of the data center location. Ex. {@code West Europe}. */
+ public String name() {
+ return name;
}
- 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 localized name of the data center location. */
+ public String displayName() {
+ return displayName;
}
- /**
- *
- * The name of a data center location that is valid for your subscription. For example:
- * {@code West Europe}
- */
- public String getName() {
- return name;
+ /** Indicates the services available at this location. Ex. {@code Compute}. */
+ public List<String> availableServices() {
+ return availableServices;
}
- /**
- * The localized name of data center location.
- */
- public String getDisplayName() {
- return displayName;
+ public static Location create(String name, String displayName, List<String> availableServices) {
+ return new Location(name, displayName, availableServices);
}
- /**
- * 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;
+ // TODO: Remove from here down with @AutoValue.
+ private Location(String name, String displayName, List<String> availableServices) {
+ this.name = checkNotNull(name, "name");
+ this.displayName = checkNotNull(displayName, "displayName");
+ this.availableServices = checkNotNull(availableServices, "availableServices");
}
+ private final String name;
+ private final String displayName;
+ private final List<String> availableServices;
+
@Override
public int hashCode() {
- return Objects.hashCode(name);
+ return Objects.hashCode(name, displayName, availableServices);
}
@Override
public boolean equals(Object obj) {
- if (this == obj)
+ if (this == obj) {
return true;
- if (obj == null)
+ }
+ if (obj == null) {
return false;
- if (getClass() != obj.getClass())
+ }
+ if (getClass() != obj.getClass()) {
return false;
+ }
Location other = (Location) obj;
- return Objects.equal(this.name, other.name);
+ return equal(this.name, other.name) &&
+ equal(this.displayName, other.displayName) &&
+ equal(this.availableServices, other.availableServices);
}
@Override
public String toString() {
- return MoreObjects.toStringHelper(this).omitNullValues().add("name", name).add("displayName", displayName)
- .add("availableServices", availableServices).toString();
+ return Objects.toStringHelper(this)
+ .add("name", name)
+ .add("displayName", displayName)
+ .add("availableServices", availableServices).toString();
}
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/f4af63fb/azurecompute/src/main/java/org/jclouds/azurecompute/xml/ListLocationsHandler.java
----------------------------------------------------------------------
diff --git a/azurecompute/src/main/java/org/jclouds/azurecompute/xml/ListLocationsHandler.java b/azurecompute/src/main/java/org/jclouds/azurecompute/xml/ListLocationsHandler.java
index f257a6a..dc05df5 100644
--- a/azurecompute/src/main/java/org/jclouds/azurecompute/xml/ListLocationsHandler.java
+++ b/azurecompute/src/main/java/org/jclouds/azurecompute/xml/ListLocationsHandler.java
@@ -16,46 +16,31 @@
*/
package org.jclouds.azurecompute.xml;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableList.Builder;
-import com.google.inject.Inject;
import java.util.List;
+
import org.jclouds.azurecompute.domain.Location;
import org.jclouds.http.functions.ParseSax;
-import org.jclouds.util.SaxUtils;
import org.xml.sax.Attributes;
-import org.xml.sax.SAXException;
-
-public class ListLocationsHandler extends ParseSax.HandlerForGeneratedRequestWithResult<List<Location>> {
- private final LocationHandler locationHandler;
-
- private Builder<Location> locations = ImmutableList.<Location> builder();
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableList.Builder;
+public final class ListLocationsHandler extends ParseSax.HandlerForGeneratedRequestWithResult<List<Location>> {
private boolean inLocation;
+ private final LocationHandler locationHandler = new LocationHandler();
+ private final Builder<Location> locations = ImmutableList.builder();
- @Inject
- public ListLocationsHandler(LocationHandler locationHandler) {
- this.locationHandler = locationHandler;
- }
-
- @Override
- public List<Location> getResult() {
+ @Override public List<Location> getResult() {
return locations.build();
}
- @Override
- public void startElement(String url, String name, String qName, Attributes attributes) throws SAXException {
- if (SaxUtils.equalsOrSuffix(qName, "Location")) {
+ @Override public void startElement(String url, String name, String qName, Attributes attributes) {
+ if (qName.equals("Location")) {
inLocation = true;
}
- if (inLocation) {
- locationHandler.startElement(url, name, qName, attributes);
- }
}
- @Override
- public void endElement(String uri, String name, String qName) throws SAXException {
+ @Override public void endElement(String uri, String name, String qName) {
if (qName.equals("Location")) {
inLocation = false;
locations.add(locationHandler.getResult());
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/f4af63fb/azurecompute/src/main/java/org/jclouds/azurecompute/xml/LocationHandler.java
----------------------------------------------------------------------
diff --git a/azurecompute/src/main/java/org/jclouds/azurecompute/xml/LocationHandler.java b/azurecompute/src/main/java/org/jclouds/azurecompute/xml/LocationHandler.java
index 01d2b9e..a16505a 100644
--- a/azurecompute/src/main/java/org/jclouds/azurecompute/xml/LocationHandler.java
+++ b/azurecompute/src/main/java/org/jclouds/azurecompute/xml/LocationHandler.java
@@ -16,42 +16,45 @@
*/
package org.jclouds.azurecompute.xml;
+import static org.jclouds.util.SaxUtils.currentOrNull;
+
+import java.util.List;
+
import org.jclouds.azurecompute.domain.Location;
import org.jclouds.http.functions.ParseSax;
-import org.jclouds.util.SaxUtils;
-import org.xml.sax.SAXException;
+
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.Lists;
/**
* @see <a href="http://msdn.microsoft.com/en-us/library/gg441293" >api</a>
*/
-public class LocationHandler extends ParseSax.HandlerForGeneratedRequestWithResult<Location> {
+final class LocationHandler extends ParseSax.HandlerForGeneratedRequestWithResult<Location> {
+ private String name;
+ private String displayName;
+ private final List<String> availableServices = Lists.newArrayList();
- private StringBuilder currentText = new StringBuilder();
- private Location.Builder builder = Location.builder();
+ private final StringBuilder currentText = new StringBuilder();
- @Override
- public Location getResult() {
- try {
- return builder.build();
- } finally {
- builder = Location.builder();
- }
+ @Override public Location getResult() {
+ Location result = Location.create(name, displayName, ImmutableList.copyOf(availableServices));
+ name = displayName = null; // handler is called in a loop.
+ availableServices.clear();
+ return result;
}
- @Override
- public void endElement(String uri, String name, String qName) throws SAXException {
+ @Override public void endElement(String ignoredUri, String ignoredName, String qName) {
if (qName.equals("Name")) {
- builder.name(SaxUtils.currentOrNull(currentText));
+ name = currentOrNull(currentText);
} else if (qName.equals("DisplayName")) {
- builder.displayName(SaxUtils.currentOrNull(currentText));
+ displayName = currentOrNull(currentText);
} else if (qName.equals("AvailableService")) {
- builder.addAvailableService(SaxUtils.currentOrNull(currentText));
+ availableServices.add(currentOrNull(currentText));
}
currentText.setLength(0);
}
- @Override
- public void characters(char ch[], int start, int length) {
+ @Override public void characters(char ch[], int start, int length) {
currentText.append(ch, start, length);
}
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/f4af63fb/azurecompute/src/test/java/org/jclouds/azurecompute/features/DiskApiLiveTest.java
----------------------------------------------------------------------
diff --git a/azurecompute/src/test/java/org/jclouds/azurecompute/features/DiskApiLiveTest.java b/azurecompute/src/test/java/org/jclouds/azurecompute/features/DiskApiLiveTest.java
index 53531de..4e8caba 100644
--- a/azurecompute/src/test/java/org/jclouds/azurecompute/features/DiskApiLiveTest.java
+++ b/azurecompute/src/test/java/org/jclouds/azurecompute/features/DiskApiLiveTest.java
@@ -45,7 +45,7 @@ public class DiskApiLiveTest extends BaseAzureComputeApiLiveTest {
locations = ImmutableSet.copyOf(transform(api.getLocationApi().list(),
new Function<Location, String>() {
public String apply(Location in) {
- return in.getName();
+ return in.name();
}
}));
images = ImmutableSet.copyOf(transform(api.getImageApi().list(), new Function<Image, String>() {
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/f4af63fb/azurecompute/src/test/java/org/jclouds/azurecompute/features/HostedServiceApiLiveTest.java
----------------------------------------------------------------------
diff --git a/azurecompute/src/test/java/org/jclouds/azurecompute/features/HostedServiceApiLiveTest.java b/azurecompute/src/test/java/org/jclouds/azurecompute/features/HostedServiceApiLiveTest.java
index da816d3..eb0eec8 100644
--- a/azurecompute/src/test/java/org/jclouds/azurecompute/features/HostedServiceApiLiveTest.java
+++ b/azurecompute/src/test/java/org/jclouds/azurecompute/features/HostedServiceApiLiveTest.java
@@ -54,7 +54,7 @@ public class HostedServiceApiLiveTest extends BaseAzureComputeApiLiveTest {
public void setup() {
super.setup();
// TODO: filter locations on those who have compute
- location = Iterables.get(api.getLocationApi().list(), 0).getName();
+ location = Iterables.get(api.getLocationApi().list(), 0).name();
operationSucceeded = retry(new Predicate<String>() {
public boolean apply(String input) {
return api.getOperationApi().get(input).getStatus() == Operation.Status.SUCCEEDED;
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/f4af63fb/azurecompute/src/test/java/org/jclouds/azurecompute/features/ImageApiLiveTest.java
----------------------------------------------------------------------
diff --git a/azurecompute/src/test/java/org/jclouds/azurecompute/features/ImageApiLiveTest.java b/azurecompute/src/test/java/org/jclouds/azurecompute/features/ImageApiLiveTest.java
index 2b1aaf0..71d4deb 100644
--- a/azurecompute/src/test/java/org/jclouds/azurecompute/features/ImageApiLiveTest.java
+++ b/azurecompute/src/test/java/org/jclouds/azurecompute/features/ImageApiLiveTest.java
@@ -43,7 +43,7 @@ public class ImageApiLiveTest extends BaseAzureComputeApiLiveTest {
locations = ImmutableSet.copyOf(transform(api.getLocationApi().list(), new Function<Location, String>() {
public String apply(Location in) {
- return in.getName();
+ return in.name();
}
}));
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/f4af63fb/azurecompute/src/test/java/org/jclouds/azurecompute/features/LocationApiLiveTest.java
----------------------------------------------------------------------
diff --git a/azurecompute/src/test/java/org/jclouds/azurecompute/features/LocationApiLiveTest.java b/azurecompute/src/test/java/org/jclouds/azurecompute/features/LocationApiLiveTest.java
index 455ef11..d270442 100644
--- a/azurecompute/src/test/java/org/jclouds/azurecompute/features/LocationApiLiveTest.java
+++ b/azurecompute/src/test/java/org/jclouds/azurecompute/features/LocationApiLiveTest.java
@@ -16,42 +16,34 @@
*/
package org.jclouds.azurecompute.features;
-import com.google.common.base.Predicate;
-import com.google.common.base.Predicates;
-import com.google.common.collect.Iterables;
+import static org.testng.Assert.assertNotNull;
+import static org.testng.Assert.assertTrue;
+
import java.util.Arrays;
import java.util.List;
+
import org.jclouds.azurecompute.domain.Location;
import org.jclouds.azurecompute.internal.BaseAzureComputeApiLiveTest;
import org.testng.annotations.Test;
-import static com.google.common.base.Preconditions.checkNotNull;
-import static com.google.common.base.Preconditions.checkState;
-
@Test(groups = "live", testName = "LocationApiLiveTest")
public class LocationApiLiveTest extends BaseAzureComputeApiLiveTest {
- @Test
- protected void testList() {
- List<Location> response = api().list();
+ private static final List<String> KNOWN_SERVICES = Arrays
+ .asList("Compute", "Storage", "PersistentVMRole", "HighMemory");
- for (Location location : response) {
+ @Test public void testList() {
+ for (Location location : api().list()) {
checkLocation(location);
}
-
}
- private Predicate<String> knownServices = Predicates
- .in(Arrays.asList("Compute", "Storage", "PersistentVMRole", "HighMemory"));
-
private void checkLocation(Location location) {
- checkNotNull(location.getName(), "Name cannot be null for a Location.");
- checkNotNull(location.getDisplayName(), "DisplayName cannot be null for Location %s", location.getName());
- checkNotNull(location.getAvailableServices(), "AvailableServices cannot be null for Location %s",
- location.getName());
- checkState(Iterables.all(location.getAvailableServices(), knownServices),
- "AvailableServices in Location %s didn't match %s: %s", location.getName(), knownServices,
- location.getAvailableServices());
+ assertNotNull(location.name(), "Name cannot be null for a Location.");
+ assertNotNull(location.displayName(), "DisplayName cannot be null for: " + location);
+ assertNotNull(location.availableServices(), "AvailableServices cannot be null for: " + location.name());
+ assertTrue(KNOWN_SERVICES.containsAll(location.availableServices()),
+ "AvailableServices in " + location + " didn't match: " + KNOWN_SERVICES);
}
private LocationApi api() {
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/f4af63fb/azurecompute/src/test/java/org/jclouds/azurecompute/features/LocationApiMockTest.java
----------------------------------------------------------------------
diff --git a/azurecompute/src/test/java/org/jclouds/azurecompute/features/LocationApiMockTest.java b/azurecompute/src/test/java/org/jclouds/azurecompute/features/LocationApiMockTest.java
index 695b54d..b476ed1 100644
--- a/azurecompute/src/test/java/org/jclouds/azurecompute/features/LocationApiMockTest.java
+++ b/azurecompute/src/test/java/org/jclouds/azurecompute/features/LocationApiMockTest.java
@@ -19,7 +19,7 @@ package org.jclouds.azurecompute.features;
import com.squareup.okhttp.mockwebserver.MockResponse;
import com.squareup.okhttp.mockwebserver.MockWebServer;
import org.jclouds.azurecompute.internal.BaseAzureComputeApiMockTest;
-import org.jclouds.azurecompute.parse.ListLocationsTest;
+import org.jclouds.azurecompute.xml.ListLocationsHandlerTest;
import org.testng.annotations.Test;
import static org.assertj.core.api.Assertions.assertThat;
@@ -34,7 +34,7 @@ public class LocationApiMockTest extends BaseAzureComputeApiMockTest {
try {
LocationApi api = api(server.getUrl("/")).getLocationApi();
- assertThat(api.list()).containsExactlyElementsOf(ListLocationsTest.expected());
+ assertThat(api.list()).containsExactlyElementsOf(ListLocationsHandlerTest.expected());
assertSent(server, "GET", "/locations");
} finally {
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/f4af63fb/azurecompute/src/test/java/org/jclouds/azurecompute/parse/ListLocationsTest.java
----------------------------------------------------------------------
diff --git a/azurecompute/src/test/java/org/jclouds/azurecompute/parse/ListLocationsTest.java b/azurecompute/src/test/java/org/jclouds/azurecompute/parse/ListLocationsTest.java
deleted file mode 100644
index 5ec96b1..0000000
--- a/azurecompute/src/test/java/org/jclouds/azurecompute/parse/ListLocationsTest.java
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- * 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.parse;
-
-import com.google.common.collect.ImmutableList;
-import java.io.InputStream;
-import java.util.List;
-import org.jclouds.azurecompute.domain.Location;
-import org.jclouds.azurecompute.xml.ListLocationsHandler;
-import org.jclouds.http.functions.BaseHandlerTest;
-import org.testng.annotations.Test;
-
-import static org.testng.Assert.assertEquals;
-
-@Test(groups = "unit", testName = "LocationsTest")
-public class ListLocationsTest extends BaseHandlerTest {
-
- public void test() {
- InputStream is = getClass().getResourceAsStream("/locations.xml");
-
- List<Location> expected = expected();
-
- ListLocationsHandler handler = injector.getInstance(ListLocationsHandler.class);
- List<Location> result = factory.create(handler).parse(is);
-
- assertEquals(result.toString(), expected.toString());
-
- }
-
- public static List<Location> expected() {
- List<String> availableServices = ImmutableList.of("Compute", "Storage", "PersistentVMRole");
- return ImmutableList.<Location>builder()
- .add(Location.builder()
- .name("West US")
- .displayName("West US")
- .availableServices(availableServices)
- .build())
- .add(Location.builder()
- .name("East US")
- .displayName("East US")
- .availableServices(availableServices)
- .build())
- .add(Location.builder()
- .name("East Asia")
- .displayName("East Asia")
- .availableServices(availableServices)
- .build())
- .add(Location.builder()
- .name("Southeast Asia")
- .displayName("Southeast Asia")
- .availableServices(availableServices)
- .build())
- .add(Location.builder()
- .name("North Europe")
- .displayName("North Europe")
- .availableServices(availableServices)
- .build())
- .add(Location.builder()
- .name("West Europe")
- .displayName("West Europe")
- .availableServices(availableServices)
- .build()).build();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/f4af63fb/azurecompute/src/test/java/org/jclouds/azurecompute/xml/ListLocationsHandlerTest.java
----------------------------------------------------------------------
diff --git a/azurecompute/src/test/java/org/jclouds/azurecompute/xml/ListLocationsHandlerTest.java b/azurecompute/src/test/java/org/jclouds/azurecompute/xml/ListLocationsHandlerTest.java
new file mode 100644
index 0000000..599d307
--- /dev/null
+++ b/azurecompute/src/test/java/org/jclouds/azurecompute/xml/ListLocationsHandlerTest.java
@@ -0,0 +1,52 @@
+/*
+ * 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.xml;
+
+import static org.testng.Assert.assertEquals;
+
+import java.io.InputStream;
+import java.util.List;
+
+import org.jclouds.azurecompute.domain.Location;
+import org.jclouds.http.functions.BaseHandlerTest;
+import org.testng.annotations.Test;
+
+import com.google.common.collect.ImmutableList;
+
+@Test(groups = "unit", testName = "ListLocationsHandlerTest")
+public class ListLocationsHandlerTest extends BaseHandlerTest {
+
+ public void test() {
+ InputStream is = getClass().getResourceAsStream("/locations.xml");
+ List<Location> result = factory.create(new ListLocationsHandler()).parse(is);
+
+ assertEquals(result, expected());
+ }
+
+ public static List<Location> expected() {
+ List<String> availableServices = ImmutableList.of("Compute", "Storage", "PersistentVMRole");
+ return ImmutableList.of( //
+ Location.create("West US", "West US", availableServices), //
+ Location.create("East US", "East US", availableServices), //
+ Location.create("East Asia", "East Asia", availableServices), //
+ Location.create("Southeast Asia", "Southeast Asia", availableServices), //
+ Location.create("North Europe", "North Europe", availableServices), //
+ Location.create("West Europe", "West Europe", availableServices) //
+ );
+ }
+
+}
[05/11] git commit: Cleanup output-only Image object.
Posted by ad...@apache.org.
Cleanup output-only Image object.
Project: http://git-wip-us.apache.org/repos/asf/jclouds-labs/repo
Commit: http://git-wip-us.apache.org/repos/asf/jclouds-labs/commit/96ebc7f6
Tree: http://git-wip-us.apache.org/repos/asf/jclouds-labs/tree/96ebc7f6
Diff: http://git-wip-us.apache.org/repos/asf/jclouds-labs/diff/96ebc7f6
Branch: refs/heads/master
Commit: 96ebc7f6f64f2b8156486b9c2c42b46c808f541a
Parents: de2f415
Author: Adrian Cole <ac...@twitter.com>
Authored: Thu Oct 16 19:49:17 2014 -0700
Committer: Adrian Cole <ac...@twitter.com>
Committed: Mon Oct 20 13:26:53 2014 -0400
----------------------------------------------------------------------
.../org/jclouds/azurecompute/domain/Image.java | 312 ++++++-------------
.../org/jclouds/azurecompute/domain/OSType.java | 10 +-
.../jclouds/azurecompute/xml/ImageHandler.java | 102 +++---
.../azurecompute/xml/ListImagesHandler.java | 38 +--
.../azurecompute/features/DiskApiLiveTest.java | 2 +-
.../azurecompute/features/ImageApiLiveTest.java | 88 ++----
.../azurecompute/features/ImageApiMockTest.java | 24 +-
.../azurecompute/parse/ListImagesTest.java | 117 -------
.../azurecompute/xml/ListImagesHandlerTest.java | 156 ++++++++++
9 files changed, 377 insertions(+), 472 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/96ebc7f6/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
index 0bde175..8a1e373 100644
--- a/azurecompute/src/main/java/org/jclouds/azurecompute/domain/Image.java
+++ b/azurecompute/src/main/java/org/jclouds/azurecompute/domain/Image.java
@@ -16,198 +16,54 @@
*/
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 static com.google.common.base.Objects.equal;
+import static com.google.common.base.Objects.toStringHelper;
+import static com.google.common.base.Preconditions.checkNotNull;
+
import java.net.URI;
import java.util.List;
-import static com.google.common.base.Preconditions.checkNotNull;
+import org.jclouds.javax.annotation.Nullable;
+
+import com.google.common.base.Objects;
/**
- * OS images from the image repository
+ * OS image 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;
- }
+public final class Image {
- /**
- * @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);
+ public String name() {
+ return name;
}
/**
- * The operating system type of the OS image.
+ * The geo-location of the image in Windows Azure, if the image is not
+ * associated with an affinity group. If a location has been specified, the AffinityGroup element
+ * is not returned.
*/
- public OSType getOS() {
- return os;
+ @Nullable public String location() {
+ return location;
}
/**
- * 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
+ * The affinity group with which this image is associated, if any. If the service is
+ * associated with an affinity group, the Location element is not returned.
*/
- public String getName() {
- return name;
+ @Nullable public String affinityGroup() {
+ return affinityGroup;
}
/**
- * The size, in GB, of the image.
+ * The name can be up to 100 characters in length. The name can be used identify the storage account for your
+ * tracking purposes.
*/
- public Optional<Integer> getLogicalSizeInGB() {
- return logicalSizeInGB;
+ public String label() {
+ return label;
}
- /**
- * The description for the image.
- */
- public Optional<String> getDescription() {
+ @Nullable public String description() {
return description;
}
@@ -215,26 +71,13 @@ public class Image {
* 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() {
+ @Nullable public String category() {
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 operating system type of the OS image. */
+ public OSType os() {
+ return os;
}
/**
@@ -246,53 +89,92 @@ public class Image {
*
* http://example.blob.core.windows.net/disks/myimage.vhd
*/
- public Optional<URI> getMediaLink() {
+ @Nullable public URI mediaLink() {
return mediaLink;
}
- /**
- * The eulas for the image, if available.
- */
+ public int logicalSizeInGB() {
+ return logicalSizeInGB;
+ }
+
+ /** The eulas for the image, if available. */
// Not URI as some providers put non-uri data in, such as riverbed.
- public List<String> getEula() {
+ public List<String> eula() {
return eula;
}
- /**
- * The description of the image.
- */
- public String getLabel() {
- return label;
+ public static Image create(String name, String location, String affinityGroup, String label, String description,
+ String category, OSType os, URI mediaLink, int logicalSizeInGB, List<String> eula) {
+ return new Image(name, location, affinityGroup, label, description, category, os, mediaLink, logicalSizeInGB,
+ eula);
}
- @Override
- public int hashCode() {
- return Objects.hashCode(name);
+ // TODO: Remove from here down with @AutoValue.
+ private Image(String name, String location, String affinityGroup, String label, String description, String category,
+ OSType os, URI mediaLink, int logicalSizeInGB, List<String> eula) {
+ this.name = checkNotNull(name, "name");
+ this.location = location;
+ this.affinityGroup = affinityGroup;
+ this.label = checkNotNull(label, "label");
+ this.description = description;
+ this.category = category;
+ this.os = checkNotNull(os, "os");
+ this.mediaLink = mediaLink;
+ this.logicalSizeInGB = logicalSizeInGB;
+ this.eula = checkNotNull(eula, "eula");
}
+ private final String name;
+ private final String location;
+ private final String affinityGroup;
+ private final String label;
+ private final String category;
+ private final String description;
+ private final OSType os;
+ private final URI mediaLink;
+ private final int logicalSizeInGB;
+ private final List<String> eula;
+
@Override
- public boolean equals(Object obj) {
- if (this == obj)
+ public boolean equals(Object object) {
+ if (this == object) {
return true;
- if (obj == null)
- return false;
- if (getClass() != obj.getClass())
+ }
+ if (object instanceof Image) {
+ Image that = Image.class.cast(object);
+ return equal(name, that.name)
+ && equal(location, that.location)
+ && equal(affinityGroup, that.affinityGroup)
+ && equal(label, that.label)
+ && equal(description, that.description)
+ && equal(category, that.category)
+ && equal(os, that.os)
+ && equal(mediaLink, that.mediaLink)
+ && equal(logicalSizeInGB, that.logicalSizeInGB)
+ && equal(eula, that.eula);
+ } else {
return false;
- Image other = (Image) obj;
- return Objects.equal(this.name, other.name);
+ }
}
@Override
- public String toString() {
- return string().toString();
+ public int hashCode() {
+ return Objects.hashCode(name, location, affinityGroup, label, description, category, os, mediaLink,
+ logicalSizeInGB, eula);
}
- 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);
+ @Override
+ public String toString() {
+ return toStringHelper(this)
+ .add("name", name)
+ .add("location", location)
+ .add("affinityGroup", affinityGroup)
+ .add("label", label)
+ .add("description", description)
+ .add("category", category)
+ .add("os", os)
+ .add("mediaLink", mediaLink)
+ .add("logicalSizeInGB", logicalSizeInGB)
+ .add("eula", eula).toString();
}
-
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/96ebc7f6/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
index fd85bde..c81b590 100644
--- a/azurecompute/src/main/java/org/jclouds/azurecompute/domain/OSType.java
+++ b/azurecompute/src/main/java/org/jclouds/azurecompute/domain/OSType.java
@@ -16,20 +16,18 @@
*/
package org.jclouds.azurecompute.domain;
-import com.google.common.base.CaseFormat;
-
+import static com.google.common.base.CaseFormat.UPPER_CAMEL;
+import static com.google.common.base.CaseFormat.UPPER_UNDERSCORE;
import static com.google.common.base.Preconditions.checkNotNull;
public enum OSType {
LINUX,
-
WINDOWS,
-
UNRECOGNIZED;
public String value() {
- return CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, name());
+ return UPPER_UNDERSCORE.to(UPPER_CAMEL, name());
}
@Override
@@ -39,7 +37,7 @@ public enum OSType {
public static OSType fromValue(String type) {
try {
- return valueOf(CaseFormat.UPPER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE, checkNotNull(type, "type")));
+ return valueOf(UPPER_CAMEL.to(UPPER_UNDERSCORE, checkNotNull(type, "type")));
} catch (IllegalArgumentException e) {
return UNRECOGNIZED;
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/96ebc7f6/azurecompute/src/main/java/org/jclouds/azurecompute/xml/ImageHandler.java
----------------------------------------------------------------------
diff --git a/azurecompute/src/main/java/org/jclouds/azurecompute/xml/ImageHandler.java b/azurecompute/src/main/java/org/jclouds/azurecompute/xml/ImageHandler.java
index 08adfea..c53888d 100644
--- a/azurecompute/src/main/java/org/jclouds/azurecompute/xml/ImageHandler.java
+++ b/azurecompute/src/main/java/org/jclouds/azurecompute/xml/ImageHandler.java
@@ -16,73 +16,91 @@
*/
package org.jclouds.azurecompute.xml;
-import com.google.common.base.Splitter;
-import com.google.common.base.Strings;
+import static com.google.common.base.Strings.emptyToNull;
+import static org.jclouds.util.SaxUtils.currentOrNull;
+
import java.net.URI;
+import java.util.List;
+
import org.jclouds.azurecompute.domain.Image;
import org.jclouds.azurecompute.domain.OSType;
import org.jclouds.http.functions.ParseSax;
-import org.xml.sax.SAXException;
-import static org.jclouds.util.SaxUtils.currentOrNull;
-import static org.jclouds.util.SaxUtils.equalsOrSuffix;
+import com.google.common.base.Splitter;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.Lists;
/**
* @see <a href="http://msdn.microsoft.com/en-us/library/jj157191" >api</a>
*/
-public class ImageHandler extends ParseSax.HandlerForGeneratedRequestWithResult<Image> {
+final class ImageHandler extends ParseSax.HandlerForGeneratedRequestWithResult<Image> {
+ private String name;
+ private String location;
+ private String affinityGroup;
+ private String label;
+ private String category;
+ private String description;
+ private OSType os;
+ private URI mediaLink;
+ private Integer logicalSizeInGB;
+ private final List<String> eula = Lists.newArrayList();
- private StringBuilder currentText = new StringBuilder();
- private Image.Builder builder = Image.builder();
+ private final StringBuilder currentText = new StringBuilder();
- @Override
- public Image getResult() {
- try {
- return builder.build();
- } finally {
- builder = Image.builder();
- }
+ @Override public Image getResult() {
+ Image result = Image.create(name, location, affinityGroup, label, description, category, os, mediaLink,
+ logicalSizeInGB, ImmutableList.copyOf(eula));
+ resetState(); // handler is called in a loop.
+ return result;
+ }
+
+ private void resetState() {
+ name = location = affinityGroup = label = description = category = null;
+ os = null;
+ mediaLink = null;
+ logicalSizeInGB = null;
+ eula.clear();
}
- @Override
- public void endElement(String uri, String name, String qName) throws SAXException {
- if (equalsOrSuffix(qName, "OS")) {
- builder.os(OSType.fromValue(currentOrNull(currentText)));
- } else if (equalsOrSuffix(qName, "Name")) {
- builder.name(currentOrNull(currentText));
- } else if (equalsOrSuffix(qName, "LogicalSizeInGB")) {
+ @Override public void endElement(String ignoredUri, String ignoredName, String qName) {
+ if (qName.equals("OS")) {
+ os = OSType.fromValue(currentOrNull(currentText));
+ } else if (qName.equals("Name")) {
+ name = currentOrNull(currentText);
+ } else if (qName.equals("LogicalSizeInGB")) {
String gb = currentOrNull(currentText);
- if (gb != null)
- builder.logicalSizeInGB(Integer.parseInt(gb));
- } else if (equalsOrSuffix(qName, "Description")) {
- builder.description(currentOrNull(currentText));
- } else if (equalsOrSuffix(qName, "Category")) {
- builder.category(currentOrNull(currentText));
- } else if (equalsOrSuffix(qName, "Location")) {
- builder.location(currentOrNull(currentText));
- } else if (equalsOrSuffix(qName, "AffinityGroup")) {
- builder.affinityGroup(currentOrNull(currentText));
- } else if (equalsOrSuffix(qName, "MediaLink")) {
+ if (gb != null) {
+ logicalSizeInGB = Integer.parseInt(gb);
+ }
+ } else if (qName.equals("Description")) {
+ description = currentOrNull(currentText);
+ } else if (qName.equals("Category")) {
+ category = currentOrNull(currentText);
+ } else if (qName.equals("Location")) {
+ location = currentOrNull(currentText);
+ } else if (qName.equals("AffinityGroup")) {
+ affinityGroup = currentOrNull(currentText);
+ } else if (qName.equals("MediaLink")) {
String link = currentOrNull(currentText);
- if (link != null)
- builder.mediaLink(URI.create(link));
- } else if (equalsOrSuffix(qName, "Eula")) {
+ if (link != null) {
+ mediaLink = URI.create(link);
+ }
+ } else if (qName.equals("Eula")) {
String eulaField = currentOrNull(currentText);
if (eulaField != null) {
for (String eula : Splitter.on(';').split(eulaField)) {
- if ((eula = Strings.emptyToNull(eula.trim())) != null) { // Dirty data in RightScale eula field.
- builder.eula(eula);
+ if ((eula = emptyToNull(eula.trim())) != null) { // Dirty data in RightScale eula field.
+ this.eula.add(eula);
}
}
}
- } else if (equalsOrSuffix(qName, "Label")) {
- builder.label(currentOrNull(currentText));
+ } else if (qName.equals("Label")) {
+ label = currentOrNull(currentText);
}
currentText.setLength(0);
}
- @Override
- public void characters(char ch[], int start, int length) {
+ @Override public void characters(char ch[], int start, int length) {
currentText.append(ch, start, length);
}
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/96ebc7f6/azurecompute/src/main/java/org/jclouds/azurecompute/xml/ListImagesHandler.java
----------------------------------------------------------------------
diff --git a/azurecompute/src/main/java/org/jclouds/azurecompute/xml/ListImagesHandler.java b/azurecompute/src/main/java/org/jclouds/azurecompute/xml/ListImagesHandler.java
index beae350..f220f8c 100644
--- a/azurecompute/src/main/java/org/jclouds/azurecompute/xml/ListImagesHandler.java
+++ b/azurecompute/src/main/java/org/jclouds/azurecompute/xml/ListImagesHandler.java
@@ -16,58 +16,46 @@
*/
package org.jclouds.azurecompute.xml;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableList.Builder;
-import com.google.inject.Inject;
import java.util.List;
+
import org.jclouds.azurecompute.domain.Image;
import org.jclouds.http.functions.ParseSax;
-import org.jclouds.util.SaxUtils;
import org.xml.sax.Attributes;
-import org.xml.sax.SAXException;
-public class ListImagesHandler extends ParseSax.HandlerForGeneratedRequestWithResult<List<Image>> {
-
- private final ImageHandler locationHandler;
-
- private Builder<Image> locations = ImmutableList.<Image> builder();
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableList.Builder;
+public final class ListImagesHandler extends ParseSax.HandlerForGeneratedRequestWithResult<List<Image>> {
private boolean inOSImage;
-
- @Inject
- public ListImagesHandler(ImageHandler locationHandler) {
- this.locationHandler = locationHandler;
- }
+ private final ImageHandler imageHandler = new ImageHandler();
+ private final Builder<Image> images = ImmutableList.builder();
@Override
public List<Image> getResult() {
- return locations.build();
+ return images.build();
}
@Override
- public void startElement(String url, String name, String qName, Attributes attributes) throws SAXException {
- if (SaxUtils.equalsOrSuffix(qName, "OSImage")) {
+ public void startElement(String url, String name, String qName, Attributes attributes) {
+ if (qName.equals("OSImage")) {
inOSImage = true;
}
- if (inOSImage) {
- locationHandler.startElement(url, name, qName, attributes);
- }
}
@Override
- public void endElement(String uri, String name, String qName) throws SAXException {
+ public void endElement(String uri, String name, String qName) {
if (qName.equals("OSImage")) {
inOSImage = false;
- locations.add(locationHandler.getResult());
+ images.add(imageHandler.getResult());
} else if (inOSImage) {
- locationHandler.endElement(uri, name, qName);
+ imageHandler.endElement(uri, name, qName);
}
}
@Override
public void characters(char ch[], int start, int length) {
if (inOSImage) {
- locationHandler.characters(ch, start, length);
+ imageHandler.characters(ch, start, length);
}
}
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/96ebc7f6/azurecompute/src/test/java/org/jclouds/azurecompute/features/DiskApiLiveTest.java
----------------------------------------------------------------------
diff --git a/azurecompute/src/test/java/org/jclouds/azurecompute/features/DiskApiLiveTest.java b/azurecompute/src/test/java/org/jclouds/azurecompute/features/DiskApiLiveTest.java
index eb16847..478b1b3 100644
--- a/azurecompute/src/test/java/org/jclouds/azurecompute/features/DiskApiLiveTest.java
+++ b/azurecompute/src/test/java/org/jclouds/azurecompute/features/DiskApiLiveTest.java
@@ -52,7 +52,7 @@ public class DiskApiLiveTest extends BaseAzureComputeApiLiveTest {
images = ImmutableSet.copyOf(transform(api.getImageApi().list(), new Function<Image, String>() {
@Override
public String apply(Image in) {
- return in.getName();
+ return in.name();
}
}));
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/96ebc7f6/azurecompute/src/test/java/org/jclouds/azurecompute/features/ImageApiLiveTest.java
----------------------------------------------------------------------
diff --git a/azurecompute/src/test/java/org/jclouds/azurecompute/features/ImageApiLiveTest.java b/azurecompute/src/test/java/org/jclouds/azurecompute/features/ImageApiLiveTest.java
index 3507147..2b1aaf0 100644
--- a/azurecompute/src/test/java/org/jclouds/azurecompute/features/ImageApiLiveTest.java
+++ b/azurecompute/src/test/java/org/jclouds/azurecompute/features/ImageApiLiveTest.java
@@ -16,9 +16,12 @@
*/
package org.jclouds.azurecompute.features;
-import com.google.common.base.Function;
-import com.google.common.collect.ImmutableSet;
-import java.util.List;
+import static com.google.common.collect.Iterables.transform;
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertNotEquals;
+import static org.testng.Assert.assertNotNull;
+import static org.testng.Assert.assertTrue;
+
import org.jclouds.azurecompute.domain.Image;
import org.jclouds.azurecompute.domain.Location;
import org.jclouds.azurecompute.domain.OSType;
@@ -26,11 +29,8 @@ import org.jclouds.azurecompute.internal.BaseAzureComputeApiLiveTest;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
-import static com.google.common.base.Preconditions.checkNotNull;
-import static com.google.common.collect.Iterables.transform;
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.testng.Assert.assertNotEquals;
-import static org.testng.Assert.assertTrue;
+import com.google.common.base.Function;
+import com.google.common.collect.ImmutableSet;
@Test(groups = "live", testName = "ImageApiLiveTest")
public class ImageApiLiveTest extends BaseAzureComputeApiLiveTest {
@@ -41,65 +41,41 @@ public class ImageApiLiveTest extends BaseAzureComputeApiLiveTest {
public void setup() {
super.setup();
- locations = ImmutableSet.copyOf(transform(api.getLocationApi().list(),
- new Function<Location, String>() {
- @Override
- public String apply(Location in) {
- return in.getName();
- }
- }));
+ locations = ImmutableSet.copyOf(transform(api.getLocationApi().list(), new Function<Location, String>() {
+ public String apply(Location in) {
+ return in.getName();
+ }
+ }));
}
- @Test
- protected void testList() {
- List<Image> response = api().list();
-
- for (Image image : response) {
+ public void testList() {
+ for (Image image : api().list()) {
checkOSImage(image);
}
}
private void checkOSImage(Image image) {
- checkNotNull(image.getLabel(), "Label cannot be null for OSImage %s", image);
- checkNotNull(image.getName(), "Name cannot be null for OSImage %s", image.getLabel());
- checkNotNull(image.getOS(), "OS cannot be null for OSImage: %s", image);
- assertNotEquals(image.getOS(), OSType.UNRECOGNIZED, "Status cannot be UNRECOGNIZED for OSImage: " + image);
-
- checkNotNull(image.getCategory(), "While Category can be null for OSImage, its Optional wrapper cannot: %s",
- image);
- if (image.getCategory().isPresent())
- assertNotEquals("", image.getCategory().get().trim(), "Invalid Category: " + image.toString());
-
- checkNotNull(image.getLogicalSizeInGB(),
- "While LogicalSizeInGB can be null for OSImage, its Optional wrapper cannot: %s", image);
-
- if (image.getLogicalSizeInGB().isPresent())
- assertTrue(image.getLogicalSizeInGB().get() > 0,
- "LogicalSizeInGB should be positive, if set" + image.toString());
-
- checkNotNull(image.getMediaLink(), "While MediaLink can be null for OSImage, its Optional wrapper cannot: %s",
- image);
-
- if (image.getMediaLink().isPresent())
- assertTrue(ImmutableSet.of("http", "https").contains(image.getMediaLink().get().getScheme()),
- "MediaLink should be an http(s) url" + image.toString());
-
- checkNotNull(image.getDescription(),
- "While Description can be null for OSImage, its Optional wrapper cannot: %s", image);
+ assertNotNull(image.label(), "Label cannot be null for " + image);
+ assertNotNull(image.name(), "Name cannot be null for " + image);
+ assertNotNull(image.os(), "OS cannot be null for " + image);
+ assertNotEquals(image.os(), OSType.UNRECOGNIZED, "Status cannot be UNRECOGNIZED for " + image);
+ assertTrue(image.logicalSizeInGB() > 0, "LogicalSizeInGB should be positive, if set" + image);
+
+ if (image.category() != null) {
+ assertNotEquals("", image.category().trim(), "Invalid Category for " + image);
+ }
- checkNotNull(image.getLocation(), "While Location can be null for OSImage, its Optional wrapper cannot: %s",
- image);
- if (image.getLocation().isPresent()) {
- assertTrue(locations.contains(image.getLocation().get()),
- "Location not in " + locations + " :" + image.toString());
+ if (image.mediaLink() != null) {
+ assertTrue(ImmutableSet.of("http", "https").contains(image.mediaLink().getScheme()),
+ "MediaLink should be an http(s) url" + image);
+ }
+ if (image.location() != null) {
+ assertTrue(locations.contains(image.location()), "Location not in " + locations + " :" + image);
}
// Ex. Dirty data in RightScale eula field comes out as an empty string.
- assertThat(image.getEula()).isNotNull().doesNotContain("");
-
- checkNotNull(image.getAffinityGroup(),
- "While AffinityGroup can be null for OSImage, its Optional wrapper cannot: %s", image);
- if (image.getAffinityGroup().isPresent()) {
+ assertFalse(image.eula().contains(""));
+ if (image.affinityGroup() != null) {
// TODO: list getAffinityGroups and check if there
}
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/96ebc7f6/azurecompute/src/test/java/org/jclouds/azurecompute/features/ImageApiMockTest.java
----------------------------------------------------------------------
diff --git a/azurecompute/src/test/java/org/jclouds/azurecompute/features/ImageApiMockTest.java b/azurecompute/src/test/java/org/jclouds/azurecompute/features/ImageApiMockTest.java
index 6c7b5c4..be3d9d7 100644
--- a/azurecompute/src/test/java/org/jclouds/azurecompute/features/ImageApiMockTest.java
+++ b/azurecompute/src/test/java/org/jclouds/azurecompute/features/ImageApiMockTest.java
@@ -16,16 +16,20 @@
*/
package org.jclouds.azurecompute.features;
-import com.squareup.okhttp.mockwebserver.MockResponse;
-import com.squareup.okhttp.mockwebserver.MockWebServer;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertNull;
+import static org.testng.Assert.assertTrue;
+
import java.net.URI;
+
import org.jclouds.azurecompute.domain.ImageParams;
import org.jclouds.azurecompute.domain.OSType;
import org.jclouds.azurecompute.internal.BaseAzureComputeApiMockTest;
-import org.jclouds.azurecompute.parse.ListImagesTest;
+import org.jclouds.azurecompute.xml.ListImagesHandlerTest;
import org.testng.annotations.Test;
-import static org.assertj.core.api.Assertions.assertThat;
+import com.squareup.okhttp.mockwebserver.MockResponse;
+import com.squareup.okhttp.mockwebserver.MockWebServer;
@Test(groups = "unit", testName = "ImageApiMockTest")
public class ImageApiMockTest extends BaseAzureComputeApiMockTest {
@@ -37,7 +41,7 @@ public class ImageApiMockTest extends BaseAzureComputeApiMockTest {
try {
ImageApi api = api(server.getUrl("/")).getImageApi();
- assertThat(api.list()).containsExactlyElementsOf(ListImagesTest.expected());
+ assertEquals(api.list(), ListImagesHandlerTest.expected());
assertSent(server, "GET", "/services/images");
} finally {
@@ -52,7 +56,7 @@ public class ImageApiMockTest extends BaseAzureComputeApiMockTest {
try {
ImageApi api = api(server.getUrl("/")).getImageApi();
- assertThat(api.list()).isEmpty();
+ assertTrue(api.list().isEmpty());
assertSent(server, "GET", "/services/images");
} finally {
@@ -70,7 +74,7 @@ public class ImageApiMockTest extends BaseAzureComputeApiMockTest {
ImageParams params = ImageParams.builder().name("myimage").label("foo").os(OSType.LINUX)
.mediaLink(URI.create("http://example.blob.core.windows.net/disks/mydisk.vhd")).build();
- assertThat(api.add(params)).isEqualTo("request-1");
+ assertEquals(api.add(params), "request-1");
assertSent(server, "POST", "/services/images", "/imageparams.xml");
} finally {
@@ -88,7 +92,7 @@ public class ImageApiMockTest extends BaseAzureComputeApiMockTest {
ImageParams params = ImageParams.builder().name("myimage").label("foo").os(OSType.LINUX)
.mediaLink(URI.create("http://example.blob.core.windows.net/disks/mydisk.vhd")).build();
- assertThat(api.update(params)).isEqualTo("request-1");
+ assertEquals(api.update(params), "request-1");
assertSent(server, "PUT", "/services/images/myimage", "/imageparams.xml");
} finally {
@@ -103,7 +107,7 @@ public class ImageApiMockTest extends BaseAzureComputeApiMockTest {
try {
ImageApi api = api(server.getUrl("/")).getImageApi();
- assertThat(api.delete("myimage")).isEqualTo("request-1");
+ assertEquals(api.delete("myimage"), "request-1");
assertSent(server, "DELETE", "/services/images/myimage");
} finally {
@@ -118,7 +122,7 @@ public class ImageApiMockTest extends BaseAzureComputeApiMockTest {
try {
ImageApi api = api(server.getUrl("/")).getImageApi();
- assertThat(api.delete("myimage")).isNull();
+ assertNull(api.delete("myimage"));
assertSent(server, "DELETE", "/services/images/myimage");
} finally {
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/96ebc7f6/azurecompute/src/test/java/org/jclouds/azurecompute/parse/ListImagesTest.java
----------------------------------------------------------------------
diff --git a/azurecompute/src/test/java/org/jclouds/azurecompute/parse/ListImagesTest.java b/azurecompute/src/test/java/org/jclouds/azurecompute/parse/ListImagesTest.java
deleted file mode 100644
index d9e19b3..0000000
--- a/azurecompute/src/test/java/org/jclouds/azurecompute/parse/ListImagesTest.java
+++ /dev/null
@@ -1,117 +0,0 @@
-/*
- * 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.parse;
-
-import com.google.common.collect.ImmutableList;
-import java.io.InputStream;
-import java.util.List;
-import org.jclouds.azurecompute.domain.Image;
-import org.jclouds.azurecompute.domain.OSType;
-import org.jclouds.azurecompute.xml.ListImagesHandler;
-import org.jclouds.http.functions.BaseHandlerTest;
-import org.testng.annotations.Test;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-@Test(groups = "unit", testName = "ListOSImagesTest")
-public class ListImagesTest extends BaseHandlerTest {
-
- public void test() {
- InputStream is = getClass().getResourceAsStream("/images.xml");
-
- ListImagesHandler handler = injector.getInstance(ListImagesHandler.class);
- List<Image> result = factory.create(handler).parse(is);
-
- assertThat(result).usingFieldByFieldElementComparator().containsExactlyElementsOf(expected());
- }
-
- public static List<Image> expected() {
- return ImmutableList.<Image>builder()
- .add(Image.builder()
- .category("Canonical")
- .label("Ubuntu Server 12.04 LTS")
- .logicalSizeInGB(30)
- .name("CANONICAL__Canonical-Ubuntu-12-04-amd64-server-20120528.1.3-en-us-30GB.vhd")
- .os(OSType.LINUX)
- .eula("http://www.ubuntu.com/project/about-ubuntu/licensing")
- .description("Ubuntu Server 12.04 LTS amd64 20120528 Cloud Image").build())
- .add(Image.builder()
- .category("Microsoft")
- .label("Windows Server 2008 R2 SP1, June 2012")
- .logicalSizeInGB(30)
- .name("MSFT__Win2K8R2SP1-120612-1520-121206-01-en-us-30GB.vhd")
- .os(OSType.WINDOWS)
- .description("Windows Server 2008 R2 is a multi-purpose server.").build())
- .add(Image.builder()
- .category("Microsoft")
- .label("Microsoft SQL Server 2012 Evaluation Edition")
- .logicalSizeInGB(30)
- .name("MSFT__Sql-Server-11EVAL-11.0.2215.0-05152012-en-us-30GB.vhd")
- .os(OSType.WINDOWS)
- .eula("http://go.microsoft.com/fwlink/?LinkID=251820") // NOTE multiple eula.
- .eula("http://go.microsoft.com/fwlink/?LinkID=131004")
- .description("SQL Server 2012 Evaluation Edition (64-bit).").build())
- .add(Image.builder()
- .category("Microsoft")
- .label("Windows Server 2012 Release Candidate, July 2012")
- .logicalSizeInGB(30)
- .name("MSFT__Win2K12RC-Datacenter-201207.02-en.us-30GB.vhd")
- .os(OSType.WINDOWS)
- .description("Windows Server 2012 incorporates Microsoft's experience building.").build())
- .add(Image.builder()
- .category("Microsoft")
- .label("Windows Server 2008 R2 SP1, July 2012")
- .logicalSizeInGB(30)
- .name("MSFT__Win2K8R2SP1-Datacenter-201207.01-en.us-30GB.vhd")
- .os(OSType.WINDOWS)
- .description("Windows Server 2008 R2 is a multi-purpose server.")
- .build())
- .add(Image.builder()
- .category("OpenLogic")
- .label("OpenLogic CentOS 6.2")
- .logicalSizeInGB(30)
- .name("OpenLogic__OpenLogic-CentOS-62-20120531-en-us-30GB.vhd")
- .os(OSType.LINUX)
- .eula("http://www.openlogic.com/azure/service-agreement/")
- .description("This distribution of Linux is based on CentOS.").build())
- .add(Image.builder()
- .category("SUSE")
- .label("openSUSE 12.1")
- .logicalSizeInGB(30)
- .name("SUSE__openSUSE-12-1-20120603-en-us-30GB.vhd")
- .os(OSType.LINUX)
- .eula("http://opensuse.org/")
- .description("openSUSE is a free and Linux-based operating system!")
- .build())
- .add(Image.builder()
- .category("SUSE")
- .label("SUSE Linux Enterprise Server")
- .logicalSizeInGB(30)
- .name("SUSE__SUSE-Linux-Enterprise-Server-11SP2-20120601-en-us-30GB.vhd")
- .os(OSType.LINUX)
- .eula("http://www.novell.com/licensing/eula/")
- .description("SUSE Linux Enterprise Server is a highly reliable value.").build())
- .add(Image.builder()
- .category("RightScale with Linux")
- .label("RightImage-CentOS-6.4-x64-v13.4")
- .logicalSizeInGB(10)
- .name("0b11de9248dd4d87b18621318e037d37__RightImage-CentOS-6.4-x64-v13.4")
- .os(OSType.LINUX) // No EULA, as RightScale stuffed ';' into the field.
- .build()).build();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/96ebc7f6/azurecompute/src/test/java/org/jclouds/azurecompute/xml/ListImagesHandlerTest.java
----------------------------------------------------------------------
diff --git a/azurecompute/src/test/java/org/jclouds/azurecompute/xml/ListImagesHandlerTest.java b/azurecompute/src/test/java/org/jclouds/azurecompute/xml/ListImagesHandlerTest.java
new file mode 100644
index 0000000..823a6e2
--- /dev/null
+++ b/azurecompute/src/test/java/org/jclouds/azurecompute/xml/ListImagesHandlerTest.java
@@ -0,0 +1,156 @@
+/*
+ * 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.xml;
+
+import static org.testng.Assert.assertEquals;
+
+import java.io.InputStream;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+import org.jclouds.azurecompute.domain.Image;
+import org.jclouds.azurecompute.domain.OSType;
+import org.jclouds.http.functions.BaseHandlerTest;
+import org.testng.annotations.Test;
+
+import com.google.common.collect.ImmutableList;
+
+@Test(groups = "unit", testName = "ListImagesHandlerTest")
+public class ListImagesHandlerTest extends BaseHandlerTest {
+
+ public void test() {
+ InputStream is = getClass().getResourceAsStream("/images.xml");
+ List<Image> result = factory.create(new ListImagesHandler()).parse(is);
+
+ assertEquals(result, expected());
+ }
+
+ public static List<Image> expected() {
+ return ImmutableList.of( //
+ Image.create( //
+ "CANONICAL__Canonical-Ubuntu-12-04-amd64-server-20120528.1.3-en-us-30GB.vhd", // name
+ null, // location
+ null, // affinityGroup
+ "Ubuntu Server 12.04 LTS", // label
+ "Ubuntu Server 12.04 LTS amd64 20120528 Cloud Image", //description
+ "Canonical", // category
+ OSType.LINUX, // os
+ null, // mediaLink
+ 30, // logicalSizeInGB
+ Arrays.asList("http://www.ubuntu.com/project/about-ubuntu/licensing") // eula
+ ),
+ Image.create( //
+ "MSFT__Win2K8R2SP1-120612-1520-121206-01-en-us-30GB.vhd", // name
+ null, // location
+ null, // affinityGroup
+ "Windows Server 2008 R2 SP1, June 2012", // label
+ "Windows Server 2008 R2 is a multi-purpose server.", //description
+ "Microsoft", // category
+ OSType.WINDOWS, // os
+ null, // mediaLink
+ 30, // logicalSizeInGB
+ Collections.<String>emptyList() // eula
+ ),
+ Image.create( //
+ "MSFT__Sql-Server-11EVAL-11.0.2215.0-05152012-en-us-30GB.vhd", // name
+ null, // location
+ null, // affinityGroup
+ "Microsoft SQL Server 2012 Evaluation Edition", // label
+ "SQL Server 2012 Evaluation Edition (64-bit).", //description
+ "Microsoft", // category
+ OSType.WINDOWS, // os
+ null, // mediaLink
+ 30, // logicalSizeInGB
+ Arrays.asList("http://go.microsoft.com/fwlink/?LinkID=251820",
+ "http://go.microsoft.com/fwlink/?LinkID=131004") // eula
+ ),
+ Image.create( //
+ "MSFT__Win2K12RC-Datacenter-201207.02-en.us-30GB.vhd", // name
+ null, // location
+ null, // affinityGroup
+ "Windows Server 2012 Release Candidate, July 2012", // label
+ "Windows Server 2012 incorporates Microsoft's experience building.", //description
+ "Microsoft", // category
+ OSType.WINDOWS, // os
+ null, // mediaLink
+ 30, // logicalSizeInGB
+ Collections.<String>emptyList() // eula
+ ),
+ Image.create( //
+ "MSFT__Win2K8R2SP1-Datacenter-201207.01-en.us-30GB.vhd", // name
+ null, // location
+ null, // affinityGroup
+ "Windows Server 2008 R2 SP1, July 2012", // label
+ "Windows Server 2008 R2 is a multi-purpose server.", //description
+ "Microsoft", // category
+ OSType.WINDOWS, // os
+ null, // mediaLink
+ 30, // logicalSizeInGB
+ Collections.<String>emptyList() // eula
+ ),
+ Image.create( //
+ "OpenLogic__OpenLogic-CentOS-62-20120531-en-us-30GB.vhd", // name
+ null, // location
+ null, // affinityGroup
+ "OpenLogic CentOS 6.2", // label
+ "This distribution of Linux is based on CentOS.", //description
+ "OpenLogic", // category
+ OSType.LINUX, // os
+ null, // mediaLink
+ 30, // logicalSizeInGB
+ Arrays.asList("http://www.openlogic.com/azure/service-agreement/") // eula
+ ),
+ Image.create( //
+ "SUSE__openSUSE-12-1-20120603-en-us-30GB.vhd", // name
+ null, // location
+ null, // affinityGroup
+ "openSUSE 12.1", // label
+ "openSUSE is a free and Linux-based operating system!", //description
+ "SUSE", // category
+ OSType.LINUX, // os
+ null, // mediaLink
+ 30, // logicalSizeInGB
+ Arrays.asList("http://opensuse.org/") // eula
+ ),
+ Image.create( //
+ "SUSE__SUSE-Linux-Enterprise-Server-11SP2-20120601-en-us-30GB.vhd", // name
+ null, // location
+ null, // affinityGroup
+ "SUSE Linux Enterprise Server", // label
+ "SUSE Linux Enterprise Server is a highly reliable value.", //description
+ "SUSE", // category
+ OSType.LINUX, // os
+ null, // mediaLink
+ 30, // logicalSizeInGB
+ Arrays.asList("http://www.novell.com/licensing/eula/") // eula
+ ),
+ Image.create( //
+ "0b11de9248dd4d87b18621318e037d37__RightImage-CentOS-6.4-x64-v13.4", // name
+ null, // location
+ null, // affinityGroup
+ "RightImage-CentOS-6.4-x64-v13.4", // label
+ null, //description
+ "RightScale with Linux", // category
+ OSType.LINUX, // os
+ null, // mediaLink
+ 10, // logicalSizeInGB
+ Collections.<String>emptyList() // No EULA, as RightScale stuffed ';' into the field.
+ )
+ );
+ }
+}
[03/11] git commit: Cleanup output-only HostedService object.
Posted by ad...@apache.org.
Cleanup output-only HostedService object.
Project: http://git-wip-us.apache.org/repos/asf/jclouds-labs/repo
Commit: http://git-wip-us.apache.org/repos/asf/jclouds-labs/commit/de2f415a
Tree: http://git-wip-us.apache.org/repos/asf/jclouds-labs/tree/de2f415a
Diff: http://git-wip-us.apache.org/repos/asf/jclouds-labs/diff/de2f415a
Branch: refs/heads/master
Commit: de2f415a2dd395c00eb8cc6a22026c300d93ebf4
Parents: ece9a96
Author: Adrian Cole <ac...@twitter.com>
Authored: Thu Oct 16 18:54:55 2014 -0700
Committer: Adrian Cole <ac...@twitter.com>
Committed: Mon Oct 20 13:26:53 2014 -0400
----------------------------------------------------------------------
.../domain/DetailedHostedServiceProperties.java | 173 -------------
.../azurecompute/domain/HostedService.java | 242 +++++++++----------
.../domain/HostedServiceProperties.java | 170 -------------
.../HostedServiceWithDetailedProperties.java | 63 -----
.../azurecompute/features/HostedServiceApi.java | 40 ++-
.../DetailedHostedServicePropertiesHandler.java | 73 ------
.../azurecompute/xml/HostedServiceHandler.java | 126 ++++++----
.../xml/HostedServicePropertiesHandler.java | 64 -----
...tedServiceWithDetailedPropertiesHandler.java | 42 ----
.../xml/ListHostedServicesHandler.java | 43 ++--
.../features/HostedServiceApiLiveTest.java | 99 +++-----
.../features/HostedServiceApiMockTest.java | 74 ++----
.../parse/GetHostedServiceDetailsTest.java | 65 -----
.../parse/GetHostedServiceTest.java | 55 -----
.../parse/ListHostedServicesTest.java | 79 ------
.../xml/HostedServiceHandlerTest.java | 55 +++++
.../xml/ListHostedServicesHandlerTest.java | 71 ++++++
.../src/test/resources/hostedservice.xml | 9 +-
.../test/resources/hostedservice_details.xml | 13 -
.../src/test/resources/hostedservices.xml | 6 +-
20 files changed, 424 insertions(+), 1138 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/de2f415a/azurecompute/src/main/java/org/jclouds/azurecompute/domain/DetailedHostedServiceProperties.java
----------------------------------------------------------------------
diff --git a/azurecompute/src/main/java/org/jclouds/azurecompute/domain/DetailedHostedServiceProperties.java b/azurecompute/src/main/java/org/jclouds/azurecompute/domain/DetailedHostedServiceProperties.java
deleted file mode 100644
index f954fd0..0000000
--- a/azurecompute/src/main/java/org/jclouds/azurecompute/domain/DetailedHostedServiceProperties.java
+++ /dev/null
@@ -1,173 +0,0 @@
-/*
- * 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.ToStringHelper;
-import com.google.common.base.Optional;
-import com.google.common.collect.ImmutableMap;
-import java.util.Date;
-import java.util.Map;
-import org.jclouds.azurecompute.domain.HostedService.Status;
-
-import static com.google.common.base.Preconditions.checkNotNull;
-
-public class DetailedHostedServiceProperties extends HostedServiceProperties {
- public static Builder builder() {
- return new Builder();
- }
-
- public Builder toBuilder() {
- return new Builder().fromDetailedHostedServiceProperties(this);
- }
-
- public static class Builder extends HostedServiceProperties.Builder<Builder> {
-
- protected String rawStatus;
- protected Status status;
- protected Date created;
- protected Date lastModified;
- protected ImmutableMap.Builder<String, String> extendedProperties = ImmutableMap.<String, String>builder();
-
- /**
- * @see DetailedHostedServiceProperties#getRawStatus()
- */
- public Builder rawStatus(String rawStatus) {
- this.rawStatus = rawStatus;
- return this;
- }
-
- /**
- * @see DetailedHostedServiceProperties#getStatus()
- */
- public Builder status(Status status) {
- this.status = status;
- return this;
- }
-
- /**
- * @see DetailedHostedServiceProperties#getCreated()
- */
- public Builder created(Date created) {
- this.created = created;
- return this;
- }
-
- /**
- * @see DetailedHostedServiceProperties#getLastModified()
- */
- public Builder lastModified(Date lastModified) {
- this.lastModified = lastModified;
- return this;
- }
-
- /**
- * @see DetailedHostedServiceProperties#getExtendedProperties()
- */
- public Builder extendedProperties(Map<String, String> extendedProperties) {
- this.extendedProperties.putAll(checkNotNull(extendedProperties, "extendedProperties"));
- return this;
- }
-
- /**
- * @see DetailedHostedServiceProperties#getExtendedProperties()
- */
- public Builder addExtendedProperty(String name, String value) {
- this.extendedProperties.put(checkNotNull(name, "name"), checkNotNull(value, "value"));
- return this;
- }
-
- @Override protected Builder self() {
- return this;
- }
-
- public DetailedHostedServiceProperties build() {
- return new DetailedHostedServiceProperties(description, location, affinityGroup, label, rawStatus, status,
- created, lastModified, extendedProperties.build());
- }
-
- public Builder fromDetailedHostedServiceProperties(DetailedHostedServiceProperties in) {
- return fromHostedServiceProperties(in).rawStatus(in.getRawStatus()).status(in.getStatus())
- .created(in.getCreated()).lastModified(in.getLastModified())
- .extendedProperties(in.getExtendedProperties());
- }
- }
-
- protected final String rawStatus;
- protected final Status status;
- protected final Date created;
- protected final Date lastModified;
- protected final Map<String, String> extendedProperties;
-
- protected DetailedHostedServiceProperties(Optional<String> description, Optional<String> location,
- Optional<String> affinityGroup, String label, String rawStatus, Status status, Date created, Date lastModified,
- Map<String, String> extendedProperties) {
- super(description, location, affinityGroup, label);
- this.rawStatus = checkNotNull(rawStatus, "rawStatus of %s", description);
- this.status = checkNotNull(status, "status of %s", description);
- this.created = checkNotNull(created, "created of %s", description);
- this.lastModified = checkNotNull(lastModified, "lastModified of %s", description);
- this.extendedProperties = ImmutableMap
- .copyOf(checkNotNull(extendedProperties, "extendedProperties of %s", description));
- }
-
- /**
- * The status of the hosted service.
- */
- public Status getStatus() {
- return status;
- }
-
- /**
- * The status of the hosted service unparsed.
- */
- public String getRawStatus() {
- return rawStatus;
- }
-
- /**
- * The date that the hosted service was created.
- */
- public Date getCreated() {
- return created;
- }
-
- /**
- * The date that the hosted service was last updated.
- */
- public Date getLastModified() {
- return lastModified;
- }
-
- /**
- * Represents the name of an extended hosted service property. Each extended property must have
- * both a defined name and value. You can have a maximum of 50 extended property name/value
- * pairs.
- *
- * The maximum length of the Name element is 64 characters, only alphanumeric characters and
- * underscores are valid in the Name, and the name must start with a letter. Each extended
- * property value has a maximum length of 255 characters.
- */
- public Map<String, String> getExtendedProperties() {
- return extendedProperties;
- }
-
- @Override
- public ToStringHelper string() {
- return super.string().add("status", rawStatus).add("created", created).add("lastModified", lastModified)
- .add("extendedProperties", extendedProperties);
- }
-}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/de2f415a/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
index f1e0584..6ef400b 100644
--- a/azurecompute/src/main/java/org/jclouds/azurecompute/domain/HostedService.java
+++ b/azurecompute/src/main/java/org/jclouds/azurecompute/domain/HostedService.java
@@ -16,169 +16,163 @@
*/
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.Objects.equal;
+import static com.google.common.base.Objects.toStringHelper;
import static com.google.common.base.Preconditions.checkNotNull;
+import java.util.Date;
+import java.util.Map;
+
+import org.jclouds.javax.annotation.Nullable;
+
+import com.google.common.base.Objects;
+
/**
- * System properties for the specified hosted service
+ * 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 HostedService {
- public static enum Status {
-
- CREATING,
-
- CREATED,
-
- DELETING,
-
- DELETED,
-
- CHANGING,
-
- RESOLVING_DNS,
-
+public final class HostedService {
+ public 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();
+ /**
+ * The name of the hosted service. This name is the DNS prefix name and can be used to access the
+ * hosted service.
+ *
+ * <p/>For example, if the service name is MyService you could access the access the service by
+ * calling: http://MyService.cloudapp.net
+ */
+ public String name() {
+ return name;
}
- public Builder<?> toBuilder() {
- return new ConcreteBuilder().fromHostedService(this);
+ /**
+ * 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.
+ */
+ @Nullable public String location() {
+ return location;
}
- 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);
- }
+ /**
+ * 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.
+ */
+ @Nullable public String affinityGroup() {
+ return affinityGroup;
+ }
- public T fromHostedService(HostedService in) {
- return this.url(in.getUrl()).name(in.getName()).properties(in.getProperties());
- }
+ /**
+ * 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 label() {
+ return label;
}
- private static class ConcreteBuilder extends Builder<ConcreteBuilder> {
- @Override
- protected ConcreteBuilder self() {
- return this;
- }
+ @Nullable public String description() {
+ return description;
}
- protected final URI url;
- protected final String name;
- protected final HostedServiceProperties properties;
+ public Status status() {
+ return status;
+ }
- protected HostedService(URI url, String name, HostedServiceProperties properties) {
- this.url = checkNotNull(url, "url");
- this.name = checkNotNull(name, "name");
- this.properties = checkNotNull(properties, "properties");
+ public Date created() {
+ return created;
}
- /**
- * The Service Management API request URI used to perform Get Hosted Service Properties requests
- * against the hosted service.
- */
- public URI getUrl() {
- return url;
+ public Date lastModified() {
+ return lastModified;
}
/**
- * The name of the hosted service. This name is the DNS prefix name and can be used to access the
- * hosted service.
+ * Represents the name of an extended hosted service property. Each extended property must have
+ * both a defined name and value. You can have a maximum of 50 extended property name/value
+ * pairs.
*
- * For example, if the service name is MyService you could access the access the service by
- * calling: http://MyService.cloudapp.net
+ * <p/>The maximum length of the Name element is 64 characters, only alphanumeric characters and
+ * underscores are valid in the Name, and the name must start with a letter. Each extended
+ * property value has a maximum length of 255 characters.
*/
- public String getName() {
- return name;
+ public Map<String, String> extendedProperties() {
+ return extendedProperties;
}
- /**
- * Provides the url of the database properties to be used for this DB HostedService.
- */
- public HostedServiceProperties getProperties() {
- return properties;
+ public static HostedService create(String name, String location, String affinityGroup, String label,
+ String description, Status status, Date created, Date lastModified, Map<String, String> extendedProperties) {
+ return new HostedService(name, location, affinityGroup, label, description, status, created, lastModified,
+ extendedProperties);
}
- @Override
- public int hashCode() {
- return Objects.hashCode(url);
+ // TODO: Remove from here down with @AutoValue.
+ private HostedService(String name, String location, String affinityGroup, String label, String description,
+ Status status, Date created, Date lastModified, Map<String, String> extendedProperties) {
+ this.name = checkNotNull(name, "name");
+ this.location = location;
+ this.affinityGroup = affinityGroup;
+ this.label = checkNotNull(label, "label");
+ this.description = description;
+ this.status = checkNotNull(status, "status");
+ this.created = checkNotNull(created, "created");
+ this.lastModified = checkNotNull(lastModified, "lastModified");
+ this.extendedProperties = checkNotNull(extendedProperties, "extendedProperties");
}
+ private final String name;
+ private final String location;
+ private final String affinityGroup;
+ private final String label;
+ private final String description;
+ private final Status status;
+ private final Date created;
+ private final Date lastModified;
+ private final Map<String, String> extendedProperties;
+
@Override
- public boolean equals(Object obj) {
- if (this == obj)
+ public boolean equals(Object object) {
+ if (this == object) {
return true;
- if (obj == null)
- return false;
- if (getClass() != obj.getClass())
+ }
+ if (object instanceof HostedService) {
+ HostedService that = HostedService.class.cast(object);
+ return equal(name, that.name)
+ && equal(location, that.location)
+ && equal(affinityGroup, that.affinityGroup)
+ && equal(label, that.label)
+ && equal(description, that.description)
+ && equal(status, that.status)
+ && equal(created, that.created)
+ && equal(lastModified, that.lastModified)
+ && equal(extendedProperties, that.extendedProperties);
+ } else {
return false;
- HostedService other = (HostedService) obj;
- return Objects.equal(this.url, other.url);
+ }
}
@Override
- public String toString() {
- return string().toString();
+ public int hashCode() {
+ return Objects.hashCode(name, location, affinityGroup, label, description, status, created, lastModified,
+ extendedProperties);
}
- protected ToStringHelper string() {
- return MoreObjects.toStringHelper(this).omitNullValues().add("url", url).add("name", name)
- .add("properties", properties);
+ @Override
+ public String toString() {
+ return toStringHelper(this)
+ .add("name", name)
+ .add("location", location)
+ .add("affinityGroup", affinityGroup)
+ .add("label", label)
+ .add("description", description)
+ .add("status", status)
+ .add("created", created)
+ .add("lastModified", lastModified)
+ .add("extendedProperties", extendedProperties).toString();
}
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/de2f415a/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
deleted file mode 100644
index 4793785..0000000
--- a/azurecompute/src/main/java/org/jclouds/azurecompute/domain/HostedServiceProperties.java
+++ /dev/null
@@ -1,170 +0,0 @@
-/*
- * 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/de2f415a/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
deleted file mode 100644
index 66c6640..0000000
--- a/azurecompute/src/main/java/org/jclouds/azurecompute/domain/HostedServiceWithDetailedProperties.java
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * 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/de2f415a/azurecompute/src/main/java/org/jclouds/azurecompute/features/HostedServiceApi.java
----------------------------------------------------------------------
diff --git a/azurecompute/src/main/java/org/jclouds/azurecompute/features/HostedServiceApi.java b/azurecompute/src/main/java/org/jclouds/azurecompute/features/HostedServiceApi.java
index 9e6b9a2..bdfeda6 100644
--- a/azurecompute/src/main/java/org/jclouds/azurecompute/features/HostedServiceApi.java
+++ b/azurecompute/src/main/java/org/jclouds/azurecompute/features/HostedServiceApi.java
@@ -16,7 +16,12 @@
*/
package org.jclouds.azurecompute.features;
+import static javax.ws.rs.core.MediaType.APPLICATION_XML;
+import static org.jclouds.Fallbacks.EmptyListOnNotFoundOr404;
+import static org.jclouds.Fallbacks.NullOnNotFoundOr404;
+
import java.util.List;
+
import javax.inject.Named;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
@@ -25,15 +30,14 @@ 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.BindCreateHostedServiceToXmlPayload;
import org.jclouds.azurecompute.domain.HostedService;
-import org.jclouds.azurecompute.domain.HostedServiceWithDetailedProperties;
import org.jclouds.azurecompute.functions.ParseRequestIdHeader;
import org.jclouds.azurecompute.options.CreateHostedServiceOptions;
import org.jclouds.azurecompute.xml.HostedServiceHandler;
-import org.jclouds.azurecompute.xml.HostedServiceWithDetailedPropertiesHandler;
import org.jclouds.azurecompute.xml.ListHostedServicesHandler;
+import org.jclouds.javax.annotation.Nullable;
import org.jclouds.rest.annotations.Fallback;
import org.jclouds.rest.annotations.Headers;
import org.jclouds.rest.annotations.MapBinder;
@@ -42,9 +46,6 @@ import org.jclouds.rest.annotations.QueryParams;
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 hosted services beneath your
* subscription.
@@ -53,7 +54,7 @@ import static org.jclouds.Fallbacks.NullOnNotFoundOr404;
*/
@Path("/services/hostedservices")
@Headers(keys = "x-ms-version", values = "{jclouds.api-version}")
-@Consumes(MediaType.APPLICATION_XML)
+@Consumes(APPLICATION_XML)
public interface HostedServiceApi {
/**
@@ -64,9 +65,10 @@ public interface HostedServiceApi {
*/
@Named("ListHostedServices")
@GET
+ @QueryParams(keys = "embed-detail", values = "true")
@XMLResponseParser(ListHostedServicesHandler.class)
@Fallback(EmptyListOnNotFoundOr404.class)
- List<HostedServiceWithDetailedProperties> list();
+ List<HostedService> list();
/**
* The Create Hosted Service operation creates a new hosted service in Windows Azure.
@@ -88,7 +90,7 @@ public interface HostedServiceApi {
@Named("CreateHostedService")
@POST
@MapBinder(BindCreateHostedServiceToXmlPayload.class)
- @Produces(MediaType.APPLICATION_XML)
+ @Produces(APPLICATION_XML)
@ResponseParser(ParseRequestIdHeader.class)
String createServiceWithLabelInLocation(@PayloadParam("name") String name,
@PayloadParam("label") String label, @PayloadParam("location") String location);
@@ -103,7 +105,7 @@ public interface HostedServiceApi {
@Named("CreateHostedService")
@POST
@MapBinder(BindCreateHostedServiceToXmlPayload.class)
- @Produces(MediaType.APPLICATION_XML)
+ @Produces(APPLICATION_XML)
@ResponseParser(ParseRequestIdHeader.class)
String createServiceWithLabelInLocation(@PayloadParam("name") String name,
@PayloadParam("label") String label, @PayloadParam("location") String location,
@@ -121,24 +123,10 @@ public interface HostedServiceApi {
@Named("GetHostedServiceProperties")
@GET
@Path("/{name}")
- @XMLResponseParser(HostedServiceHandler.class)
- @Fallback(NullOnNotFoundOr404.class)
- HostedService get(@PathParam("name") String name);
-
- /**
- * like {@link #get(String)}, except additional data such as status and deployment information is
- * returned.
- *
- * @param name
- * the unique DNS Prefix value in the Windows Azure Management Portal
- */
- @Named("GetHostedServiceProperties")
- @GET
- @Path("/{name}")
@QueryParams(keys = "embed-detail", values = "true")
- @XMLResponseParser(HostedServiceWithDetailedPropertiesHandler.class)
+ @XMLResponseParser(HostedServiceHandler.class)
@Fallback(NullOnNotFoundOr404.class)
- HostedServiceWithDetailedProperties getDetails(@PathParam("name") String name);
+ @Nullable HostedService get(@PathParam("name") String name);
/**
* The Delete Hosted Service operation deletes the specified hosted service from Windows Azure.
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/de2f415a/azurecompute/src/main/java/org/jclouds/azurecompute/xml/DetailedHostedServicePropertiesHandler.java
----------------------------------------------------------------------
diff --git a/azurecompute/src/main/java/org/jclouds/azurecompute/xml/DetailedHostedServicePropertiesHandler.java b/azurecompute/src/main/java/org/jclouds/azurecompute/xml/DetailedHostedServicePropertiesHandler.java
deleted file mode 100644
index 2986d7d..0000000
--- a/azurecompute/src/main/java/org/jclouds/azurecompute/xml/DetailedHostedServicePropertiesHandler.java
+++ /dev/null
@@ -1,73 +0,0 @@
-/*
- * 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.xml;
-
-import javax.inject.Inject;
-import org.jclouds.azurecompute.domain.DetailedHostedServiceProperties;
-import org.jclouds.azurecompute.domain.HostedService.Status;
-import org.jclouds.date.DateService;
-import org.xml.sax.SAXException;
-
-import static org.jclouds.util.SaxUtils.currentOrNull;
-import static org.jclouds.util.SaxUtils.equalsOrSuffix;
-
-/**
- * @see <a href="http://msdn.microsoft.com/en-us/library/gg441293" >api</a>
- */
-public class DetailedHostedServicePropertiesHandler extends HostedServicePropertiesHandler {
-
- private final DateService dateService;
-
- @Inject
- private DetailedHostedServicePropertiesHandler(DateService dateService) {
- this.dateService = dateService;
- }
-
- private DetailedHostedServiceProperties.Builder builder = DetailedHostedServiceProperties.builder();
-
- private String name;
-
- @Override
- public DetailedHostedServiceProperties getResult() {
- try {
- return builder.fromHostedServiceProperties(super.getResult()).build();
- } finally {
- builder = DetailedHostedServiceProperties.builder();
- }
- }
-
- @Override
- public void endElement(String uri, String name, String qName) throws SAXException {
- if (equalsOrSuffix(qName, "DateCreated")) {
- builder.created(dateService.iso8601SecondsDateParse(currentOrNull(currentText)));
- } else if (equalsOrSuffix(qName, "DateLastModified")) {
- builder.lastModified(dateService.iso8601SecondsDateParse(currentOrNull(currentText)));
- } else if (equalsOrSuffix(qName, "Status")) {
- String rawStatus = currentOrNull(currentText);
- builder.rawStatus(rawStatus);
- builder.status(Status.fromValue(rawStatus));
- } else if (equalsOrSuffix(qName, "Name")) {
- this.name = currentOrNull(currentText);
- } else if (equalsOrSuffix(qName, "Value")) {
- builder.addExtendedProperty(this.name, currentOrNull(currentText));
- this.name = null;
- } else {
- super.endElement(uri, name, qName);
- }
- currentText.setLength(0);
- }
-}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/de2f415a/azurecompute/src/main/java/org/jclouds/azurecompute/xml/HostedServiceHandler.java
----------------------------------------------------------------------
diff --git a/azurecompute/src/main/java/org/jclouds/azurecompute/xml/HostedServiceHandler.java b/azurecompute/src/main/java/org/jclouds/azurecompute/xml/HostedServiceHandler.java
index 2962c42..6bbe403 100644
--- a/azurecompute/src/main/java/org/jclouds/azurecompute/xml/HostedServiceHandler.java
+++ b/azurecompute/src/main/java/org/jclouds/azurecompute/xml/HostedServiceHandler.java
@@ -16,78 +16,112 @@
*/
package org.jclouds.azurecompute.xml;
-import java.net.URI;
+import static com.google.common.base.CaseFormat.UPPER_CAMEL;
+import static com.google.common.base.CaseFormat.UPPER_UNDERSCORE;
+import static com.google.common.base.Charsets.UTF_8;
+import static com.google.common.io.BaseEncoding.base64;
+import static org.jclouds.util.SaxUtils.currentOrNull;
+
+import java.util.Date;
+import java.util.Map;
+
import javax.inject.Inject;
+
import org.jclouds.azurecompute.domain.HostedService;
-import org.jclouds.azurecompute.domain.HostedService.Builder;
+import org.jclouds.date.DateService;
import org.jclouds.http.functions.ParseSax;
import org.xml.sax.Attributes;
-import org.xml.sax.SAXException;
-import static org.jclouds.util.SaxUtils.currentOrNull;
-import static org.jclouds.util.SaxUtils.equalsOrSuffix;
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.Maps;
/**
- * @see <a href="http://msdn.microsoft.com/en-us/library/gg441293" >api</a>
+ * @see <a href="http://msdn.microsoft.com/en-us/library/gg441293" >Response body description</a>
*/
-public class HostedServiceHandler extends ParseSax.HandlerForGeneratedRequestWithResult<HostedService> {
-
- private final HostedServicePropertiesHandler hostedServicePropertiesHandler;
-
- @Inject protected HostedServiceHandler(HostedServicePropertiesHandler hostedServicePropertiesHandler) {
- this.hostedServicePropertiesHandler = hostedServicePropertiesHandler;
- }
+public final class HostedServiceHandler extends ParseSax.HandlerForGeneratedRequestWithResult<HostedService> {
+ private String name;
+ private String location;
+ private String affinityGroup;
+ private String label;
+ private String description;
+ private HostedService.Status status;
+ private Date created;
+ private Date lastModified;
+ private Map<String, String> extendedProperties = Maps.newLinkedHashMap();
+ private boolean inHostedServiceProperties;
+ private String propertyName;
private StringBuilder currentText = new StringBuilder();
- protected HostedService.Builder<?> builder = builder();
+ private final DateService dateService;
- protected Builder<?> builder() {
- return HostedService.builder();
+ @Inject HostedServiceHandler(DateService dateService) {
+ this.dateService = dateService;
}
- private boolean inHostedServiceProperties;
+ @Override public HostedService getResult() {
+ HostedService result = HostedService.create(name, location, affinityGroup, label, description, status, created, //
+ lastModified, ImmutableMap.copyOf(extendedProperties));
+ resetState(); // handler is called in a loop.
+ return result;
+ }
- @Override
- public HostedService getResult() {
- try {
- return builder.build();
- } finally {
- builder = builder();
- }
+ private void resetState() {
+ name = description = location = affinityGroup = label = null;
+ status = null;
+ created = lastModified = null;
+ extendedProperties.clear();
+ inHostedServiceProperties = false;
+ propertyName = null;
}
- @Override
- public void startElement(String url, String name, String qName, Attributes attributes) throws SAXException {
- if (equalsOrSuffix(qName, "HostedServiceProperties")) {
+ @Override public void startElement(String ignoredUri, String ignoredLocalName, String qName, Attributes ignoredAttributes) {
+ if (qName.equals("HostedServiceProperties")) {
inHostedServiceProperties = true;
}
- if (inHostedServiceProperties) {
- hostedServicePropertiesHandler.startElement(url, name, qName, attributes);
- }
}
- @Override
- public void endElement(String uri, String name, String qName) throws SAXException {
-
- if (equalsOrSuffix(qName, "HostedServiceProperties")) {
- builder.properties(hostedServicePropertiesHandler.getResult());
+ @Override public void endElement(String ignoredUri, String ignoredName, String qName) {
+ if (qName.equals("HostedServiceProperties")) {
inHostedServiceProperties = false;
} else if (inHostedServiceProperties) {
- hostedServicePropertiesHandler.endElement(uri, name, qName);
- } else if (equalsOrSuffix(qName, "Url")) {
- builder.url(URI.create(currentOrNull(currentText)));
- } else if (equalsOrSuffix(qName, "ServiceName")) {
- builder.name(currentOrNull(currentText));
+ if (qName.equals("DateCreated")) {
+ created = dateService.iso8601SecondsDateParse(currentOrNull(currentText));
+ } else if (qName.equals("DateLastModified")) {
+ lastModified = dateService.iso8601SecondsDateParse(currentOrNull(currentText));
+ } else if (qName.equals("Status")) {
+ String statusText = currentOrNull(currentText);
+ if (statusText != null) {
+ status = status(statusText);
+ }
+ } else if (qName.equals("Name")) {
+ propertyName = currentOrNull(currentText);
+ } else if (qName.equals("Value")) {
+ extendedProperties.put(propertyName, currentOrNull(currentText));
+ propertyName = null;
+ } else if (qName.equals("Description")) {
+ description = currentOrNull(currentText);
+ } else if (qName.equals("Location")) {
+ location = currentOrNull(currentText);
+ } else if (qName.equals("AffinityGroup")) {
+ affinityGroup = currentOrNull(currentText);
+ } else if (qName.equals("Label")) {
+ label = new String(base64().decode(currentOrNull(currentText)), UTF_8);
+ }
+ } else if (qName.equals("ServiceName")) {
+ name = currentOrNull(currentText);
}
currentText.setLength(0);
}
- @Override
- public void characters(char ch[], int start, int length) {
- if (inHostedServiceProperties) {
- hostedServicePropertiesHandler.characters(ch, start, length);
- } else {
- currentText.append(ch, start, length);
+ @Override public void characters(char ch[], int start, int length) {
+ currentText.append(ch, start, length);
+ }
+
+ private static HostedService.Status status(String status) {
+ try {
+ return HostedService.Status.valueOf(UPPER_CAMEL.to(UPPER_UNDERSCORE, status));
+ } catch (IllegalArgumentException e) {
+ return HostedService.Status.UNRECOGNIZED;
}
}
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/de2f415a/azurecompute/src/main/java/org/jclouds/azurecompute/xml/HostedServicePropertiesHandler.java
----------------------------------------------------------------------
diff --git a/azurecompute/src/main/java/org/jclouds/azurecompute/xml/HostedServicePropertiesHandler.java b/azurecompute/src/main/java/org/jclouds/azurecompute/xml/HostedServicePropertiesHandler.java
deleted file mode 100644
index 835ce3a..0000000
--- a/azurecompute/src/main/java/org/jclouds/azurecompute/xml/HostedServicePropertiesHandler.java
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * 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.xml;
-
-import org.jclouds.azurecompute.domain.HostedServiceProperties;
-import org.jclouds.http.functions.ParseSax;
-import org.xml.sax.SAXException;
-
-import static com.google.common.base.Charsets.UTF_8;
-import static com.google.common.io.BaseEncoding.base64;
-import static org.jclouds.util.SaxUtils.currentOrNull;
-import static org.jclouds.util.SaxUtils.equalsOrSuffix;
-
-/**
- * @see <a href="http://msdn.microsoft.com/en-us/library/gg441293" >api</a>
- */
-public class HostedServicePropertiesHandler extends
- ParseSax.HandlerForGeneratedRequestWithResult<HostedServiceProperties> {
-
- protected StringBuilder currentText = new StringBuilder();
- private HostedServiceProperties.Builder<?> builder = HostedServiceProperties.builder();
-
- @Override
- public HostedServiceProperties getResult() {
- try {
- return builder.build();
- } finally {
- builder = HostedServiceProperties.builder();
- }
- }
-
- @Override
- public void endElement(String uri, String name, String qName) throws SAXException {
- if (equalsOrSuffix(qName, "Description")) {
- builder.description(currentOrNull(currentText));
- } else if (equalsOrSuffix(qName, "Location")) {
- builder.location(currentOrNull(currentText));
- } else if (equalsOrSuffix(qName, "AffinityGroup")) {
- builder.affinityGroup(currentOrNull(currentText));
- } else if (equalsOrSuffix(qName, "Label")) {
- builder.label(new String(base64().decode(currentOrNull(currentText)), UTF_8));
- }
- currentText.setLength(0);
- }
-
- @Override
- public void characters(char ch[], int start, int length) {
- currentText.append(ch, start, length);
- }
-}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/de2f415a/azurecompute/src/main/java/org/jclouds/azurecompute/xml/HostedServiceWithDetailedPropertiesHandler.java
----------------------------------------------------------------------
diff --git a/azurecompute/src/main/java/org/jclouds/azurecompute/xml/HostedServiceWithDetailedPropertiesHandler.java b/azurecompute/src/main/java/org/jclouds/azurecompute/xml/HostedServiceWithDetailedPropertiesHandler.java
deleted file mode 100644
index 69193b1..0000000
--- a/azurecompute/src/main/java/org/jclouds/azurecompute/xml/HostedServiceWithDetailedPropertiesHandler.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * 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.xml;
-
-import javax.inject.Inject;
-import org.jclouds.azurecompute.domain.HostedServiceWithDetailedProperties;
-
-public class HostedServiceWithDetailedPropertiesHandler extends HostedServiceHandler {
-
- @Inject protected HostedServiceWithDetailedPropertiesHandler(
- DetailedHostedServicePropertiesHandler hostedServicePropertiesHandler) {
- super(hostedServicePropertiesHandler);
- }
-
- @Override
- protected HostedServiceWithDetailedProperties.Builder builder() {
- return HostedServiceWithDetailedProperties.builder();
- }
-
- @Override
- public HostedServiceWithDetailedProperties getResult() {
- try {
- return HostedServiceWithDetailedProperties.class.cast(builder.build());
- } finally {
- builder = builder();
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/de2f415a/azurecompute/src/main/java/org/jclouds/azurecompute/xml/ListHostedServicesHandler.java
----------------------------------------------------------------------
diff --git a/azurecompute/src/main/java/org/jclouds/azurecompute/xml/ListHostedServicesHandler.java b/azurecompute/src/main/java/org/jclouds/azurecompute/xml/ListHostedServicesHandler.java
index 875e787..15bb5b2 100644
--- a/azurecompute/src/main/java/org/jclouds/azurecompute/xml/ListHostedServicesHandler.java
+++ b/azurecompute/src/main/java/org/jclouds/azurecompute/xml/ListHostedServicesHandler.java
@@ -16,42 +16,35 @@
*/
package org.jclouds.azurecompute.xml;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableList.Builder;
-import com.google.inject.Inject;
import java.util.List;
-import org.jclouds.azurecompute.domain.HostedServiceWithDetailedProperties;
+
+import javax.inject.Inject;
+
+import org.jclouds.azurecompute.domain.HostedService;
import org.jclouds.http.functions.ParseSax;
-import org.jclouds.util.SaxUtils;
import org.xml.sax.Attributes;
-import org.xml.sax.SAXException;
+
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableList.Builder;
/**
- * @see <a href="http://msdn.microsoft.com/en-us/library/ee460781">doc</a>
+ * @see <a href="http://msdn.microsoft.com/en-us/library/ee460781">Response body description</a>
*/
-public class ListHostedServicesHandler extends
- ParseSax.HandlerForGeneratedRequestWithResult<List<HostedServiceWithDetailedProperties>> {
-
- private final HostedServiceWithDetailedPropertiesHandler hostedServiceHandler;
-
- private Builder<HostedServiceWithDetailedProperties> hostedServices = ImmutableList
- .<HostedServiceWithDetailedProperties> builder();
-
+public final class ListHostedServicesHandler extends ParseSax.HandlerForGeneratedRequestWithResult<List<HostedService>> {
private boolean inHostedService;
+ private final HostedServiceHandler hostedServiceHandler;
+ private final Builder<HostedService> hostedServices = ImmutableList.builder();
- @Inject
- public ListHostedServicesHandler(HostedServiceWithDetailedPropertiesHandler hostedServiceHandler) {
+ @Inject ListHostedServicesHandler(HostedServiceHandler hostedServiceHandler) {
this.hostedServiceHandler = hostedServiceHandler;
}
- @Override
- public List<HostedServiceWithDetailedProperties> getResult() {
+ @Override public List<HostedService> getResult() {
return hostedServices.build();
}
- @Override
- public void startElement(String url, String name, String qName, Attributes attributes) throws SAXException {
- if (SaxUtils.equalsOrSuffix(qName, "HostedService")) {
+ @Override public void startElement(String url, String name, String qName, Attributes attributes) {
+ if (qName.equals("HostedService")) {
inHostedService = true;
}
if (inHostedService) {
@@ -59,8 +52,7 @@ public class ListHostedServicesHandler extends
}
}
- @Override
- public void endElement(String uri, String name, String qName) throws SAXException {
+ @Override public void endElement(String uri, String name, String qName) {
if (qName.equals("HostedService")) {
inHostedService = false;
hostedServices.add(hostedServiceHandler.getResult());
@@ -69,8 +61,7 @@ public class ListHostedServicesHandler extends
}
}
- @Override
- public void characters(char ch[], int start, int length) {
+ @Override public void characters(char ch[], int start, int length) {
if (inHostedService) {
hostedServiceHandler.characters(ch, start, length);
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/de2f415a/azurecompute/src/test/java/org/jclouds/azurecompute/features/HostedServiceApiLiveTest.java
----------------------------------------------------------------------
diff --git a/azurecompute/src/test/java/org/jclouds/azurecompute/features/HostedServiceApiLiveTest.java b/azurecompute/src/test/java/org/jclouds/azurecompute/features/HostedServiceApiLiveTest.java
index 558689f..da816d3 100644
--- a/azurecompute/src/test/java/org/jclouds/azurecompute/features/HostedServiceApiLiveTest.java
+++ b/azurecompute/src/test/java/org/jclouds/azurecompute/features/HostedServiceApiLiveTest.java
@@ -16,37 +16,36 @@
*/
package org.jclouds.azurecompute.features;
-import com.google.common.base.Predicate;
-import com.google.common.collect.Iterables;
+import static java.util.concurrent.TimeUnit.SECONDS;
+import static org.jclouds.azurecompute.domain.HostedService.Status.UNRECOGNIZED;
+import static org.jclouds.util.Predicates2.retry;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertNotEquals;
+import static org.testng.Assert.assertNotNull;
+import static org.testng.Assert.assertTrue;
+
import java.util.List;
import java.util.logging.Logger;
-import org.jclouds.azurecompute.domain.DetailedHostedServiceProperties;
+
import org.jclouds.azurecompute.domain.HostedService;
import org.jclouds.azurecompute.domain.HostedService.Status;
-import org.jclouds.azurecompute.domain.HostedServiceWithDetailedProperties;
import org.jclouds.azurecompute.domain.Operation;
import org.jclouds.azurecompute.internal.BaseAzureComputeApiLiveTest;
-import org.testng.Assert;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
-import static com.google.common.base.Preconditions.checkNotNull;
-import static com.google.common.base.Preconditions.checkState;
-import static java.util.concurrent.TimeUnit.SECONDS;
-import static org.jclouds.util.Predicates2.retry;
-import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertNotEquals;
-import static org.testng.Assert.assertTrue;
+import com.google.common.base.Predicate;
+import com.google.common.collect.Iterables;
@Test(groups = "live", testName = "HostedServiceApiLiveTest")
public class HostedServiceApiLiveTest extends BaseAzureComputeApiLiveTest {
public static final String HOSTED_SERVICE = (System.getProperty("user.name") + "-jclouds-hostedService")
- .toLowerCase();
+ .toLowerCase();
private Predicate<String> operationSucceeded;
- private Predicate<HostedServiceWithDetailedProperties> hostedServiceCreated;
+ private Predicate<HostedService> hostedServiceCreated;
private Predicate<HostedService> hostedServiceGone;
private String location;
@@ -61,19 +60,19 @@ public class HostedServiceApiLiveTest extends BaseAzureComputeApiLiveTest {
return api.getOperationApi().get(input).getStatus() == Operation.Status.SUCCEEDED;
}
}, 600, 5, 5, SECONDS);
- hostedServiceCreated = retry(new Predicate<HostedServiceWithDetailedProperties>() {
- public boolean apply(HostedServiceWithDetailedProperties input) {
- return api().getDetails(input.getName()).getProperties().getStatus() == Status.CREATED;
+ hostedServiceCreated = retry(new Predicate<HostedService>() {
+ public boolean apply(HostedService input) {
+ return api().get(input.name()).status() == Status.CREATED;
}
}, 600, 5, 5, SECONDS);
hostedServiceGone = retry(new Predicate<HostedService>() {
public boolean apply(HostedService input) {
- return api().get(input.getName()) == null;
+ return api().get(input.name()) == null;
}
}, 600, 5, 5, SECONDS);
}
- private HostedServiceWithDetailedProperties hostedService;
+ private HostedService hostedService;
public void testCreateHostedService() {
@@ -81,22 +80,22 @@ public class HostedServiceApiLiveTest extends BaseAzureComputeApiLiveTest {
assertTrue(operationSucceeded.apply(requestId), requestId);
Logger.getAnonymousLogger().info("operation succeeded: " + requestId);
- hostedService = api().getDetails(HOSTED_SERVICE);
+ hostedService = api().get(HOSTED_SERVICE);
Logger.getAnonymousLogger().info("created hostedService: " + hostedService);
- assertEquals(hostedService.getName(), HOSTED_SERVICE);
+ assertEquals(hostedService.name(), HOSTED_SERVICE);
checkHostedService(hostedService);
assertTrue(hostedServiceCreated.apply(hostedService), hostedService.toString());
- hostedService = api().getDetails(hostedService.getName());
+ hostedService = api().get(hostedService.name());
Logger.getAnonymousLogger().info("hostedService available: " + hostedService);
}
@Test(dependsOnMethods = "testCreateHostedService")
public void testDeleteHostedService() {
- String requestId = api().delete(hostedService.getName());
+ String requestId = api().delete(hostedService.name());
assertTrue(operationSucceeded.apply(requestId), requestId);
Logger.getAnonymousLogger().info("operation succeeded: " + requestId);
@@ -104,62 +103,40 @@ public class HostedServiceApiLiveTest extends BaseAzureComputeApiLiveTest {
Logger.getAnonymousLogger().info("hostedService deleted: " + hostedService);
}
- @Override
- @AfterClass(groups = "live")
+ @Override @AfterClass(groups = "live")
protected void tearDown() {
String requestId = api().delete(HOSTED_SERVICE);
- if (requestId != null)
+ if (requestId != null) {
operationSucceeded.apply(requestId);
+ }
super.tearDown();
}
@Test
protected void testList() {
- List<HostedServiceWithDetailedProperties> response = api().list();
+ List<HostedService> response = api().list();
- for (HostedServiceWithDetailedProperties hostedService : response) {
+ for (HostedService hostedService : api().list()) {
checkHostedService(hostedService);
}
if (response.size() > 0) {
HostedService hostedService = response.iterator().next();
- Assert.assertEquals(api().getDetails(hostedService.getName()), hostedService);
+ assertEquals(api().get(hostedService.name()), hostedService);
}
}
- private void checkHostedService(HostedServiceWithDetailedProperties hostedService) {
- checkNotNull(hostedService.getUrl(), "Url cannot be null for a HostedService.");
- checkNotNull(hostedService.getName(), "ServiceName cannot be null for HostedService %s", hostedService.getUrl());
- checkNotNull(hostedService.getProperties(), "Properties cannot be null for HostedService %s",
- hostedService.getUrl());
- checkProperties(hostedService.getProperties());
- }
-
- private void checkProperties(DetailedHostedServiceProperties hostedService) {
- checkNotNull(hostedService.getDescription(),
- "While Description can be null for DetailedHostedServiceProperties, its Optional wrapper cannot: %s",
- hostedService);
- checkNotNull(hostedService.getLocation(),
- "While Location can be null for DetailedHostedServiceProperties, its Optional wrapper cannot: %s",
- hostedService);
- checkNotNull(hostedService.getAffinityGroup(),
- "While AffinityGroup can be null for DetailedHostedServiceProperties, its Optional wrapper cannot: %s",
- hostedService);
- checkState(hostedService.getLocation().isPresent() || hostedService.getAffinityGroup().isPresent(),
- "Location or AffinityGroup must be present for DetailedHostedServiceProperties: %s", hostedService);
- checkNotNull(hostedService.getLabel(), "Label cannot be null for HostedService %s", hostedService);
-
- checkNotNull(hostedService.getStatus(), "Status cannot be null for DetailedHostedServiceProperties: %s",
- hostedService);
- assertNotEquals(hostedService.getStatus(), Status.UNRECOGNIZED,
- "Status cannot be UNRECOGNIZED for DetailedHostedServiceProperties: " + hostedService);
- checkNotNull(hostedService.getCreated(), "Created cannot be null for DetailedHostedServiceProperties %s",
- hostedService);
- checkNotNull(hostedService.getLastModified(),
- "LastModified cannot be null for DetailedHostedServiceProperties %s", hostedService);
- checkNotNull(hostedService.getExtendedProperties(),
- "ExtendedProperties cannot be null for DetailedHostedServiceProperties %s", hostedService);
+ private void checkHostedService(HostedService hostedService) {
+ assertNotNull(hostedService.name(), "ServiceName cannot be null for " + hostedService);
+ assertTrue(hostedService.location() != null || hostedService.affinityGroup() != null,
+ "Location or AffinityGroup must be present for " + hostedService);
+ assertNotNull(hostedService.label(), "Label cannot be null for " + hostedService);
+ assertNotNull(hostedService.status(), "Status cannot be null for " + hostedService);
+ assertNotEquals(hostedService.status(), UNRECOGNIZED, "Status cannot be UNRECOGNIZED for " + hostedService);
+ assertNotNull(hostedService.created(), "Created cannot be null for " + hostedService);
+ assertNotNull(hostedService.lastModified(), "LastModified cannot be null for " + hostedService);
+ assertNotNull(hostedService.extendedProperties(), "ExtendedProperties cannot be null for " + hostedService);
}
private HostedServiceApi api() {
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/de2f415a/azurecompute/src/test/java/org/jclouds/azurecompute/features/HostedServiceApiMockTest.java
----------------------------------------------------------------------
diff --git a/azurecompute/src/test/java/org/jclouds/azurecompute/features/HostedServiceApiMockTest.java b/azurecompute/src/test/java/org/jclouds/azurecompute/features/HostedServiceApiMockTest.java
index a2a4aaf..1ac320d 100644
--- a/azurecompute/src/test/java/org/jclouds/azurecompute/features/HostedServiceApiMockTest.java
+++ b/azurecompute/src/test/java/org/jclouds/azurecompute/features/HostedServiceApiMockTest.java
@@ -16,17 +16,19 @@
*/
package org.jclouds.azurecompute.features;
-import com.google.common.collect.ImmutableMap;
-import com.squareup.okhttp.mockwebserver.MockResponse;
-import com.squareup.okhttp.mockwebserver.MockWebServer;
+import static org.jclouds.azurecompute.options.CreateHostedServiceOptions.Builder.description;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertNull;
+import static org.testng.Assert.assertTrue;
+
import org.jclouds.azurecompute.internal.BaseAzureComputeApiMockTest;
-import org.jclouds.azurecompute.parse.GetHostedServiceDetailsTest;
-import org.jclouds.azurecompute.parse.GetHostedServiceTest;
-import org.jclouds.azurecompute.parse.ListHostedServicesTest;
+import org.jclouds.azurecompute.xml.HostedServiceHandlerTest;
+import org.jclouds.azurecompute.xml.ListHostedServicesHandlerTest;
import org.testng.annotations.Test;
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.jclouds.azurecompute.options.CreateHostedServiceOptions.Builder.description;
+import com.google.common.collect.ImmutableMap;
+import com.squareup.okhttp.mockwebserver.MockResponse;
+import com.squareup.okhttp.mockwebserver.MockWebServer;
@Test(groups = "unit", testName = "HostedServiceApiMockTest")
public class HostedServiceApiMockTest extends BaseAzureComputeApiMockTest {
@@ -38,9 +40,9 @@ public class HostedServiceApiMockTest extends BaseAzureComputeApiMockTest {
try {
HostedServiceApi api = api(server.getUrl("/")).getHostedServiceApi();
- assertThat(api.list()).containsExactlyElementsOf(ListHostedServicesTest.expected());
+ assertEquals(api.list(), ListHostedServicesHandlerTest.expected());
- assertSent(server, "GET", "/services/hostedservices");
+ assertSent(server, "GET", "/services/hostedservices?embed-detail=true");
} finally {
server.shutdown();
}
@@ -53,9 +55,9 @@ public class HostedServiceApiMockTest extends BaseAzureComputeApiMockTest {
try {
HostedServiceApi api = api(server.getUrl("/")).getHostedServiceApi();
- assertThat(api.list()).isEmpty();
+ assertTrue(api.list().isEmpty());
- assertSent(server, "GET", "/services/hostedservices");
+ assertSent(server, "GET", "/services/hostedservices?embed-detail=true");
} finally {
server.shutdown();
}
@@ -68,37 +70,7 @@ public class HostedServiceApiMockTest extends BaseAzureComputeApiMockTest {
try {
HostedServiceApi api = api(server.getUrl("/")).getHostedServiceApi();
- assertThat(api.get("myservice")).isEqualTo(GetHostedServiceTest.expected());
-
- assertSent(server, "GET", "/services/hostedservices/myservice");
- } finally {
- server.shutdown();
- }
- }
-
- public void getWhenNotFound() throws Exception {
- MockWebServer server = mockAzureManagementServer();
- server.enqueue(new MockResponse().setResponseCode(404));
-
- try {
- HostedServiceApi api = api(server.getUrl("/")).getHostedServiceApi();
-
- assertThat(api.get("myservice")).isNull();
-
- assertSent(server, "GET", "/services/hostedservices/myservice");
- } finally {
- server.shutdown();
- }
- }
-
- public void getDetailsWhenFound() throws Exception {
- MockWebServer server = mockAzureManagementServer();
- server.enqueue(xmlResponse("/hostedservice_details.xml"));
-
- try {
- HostedServiceApi api = api(server.getUrl("/")).getHostedServiceApi();
-
- assertThat(api.getDetails("myservice")).isEqualTo(GetHostedServiceDetailsTest.expected());
+ assertEquals(api.get("myservice"), HostedServiceHandlerTest.expected());
assertSent(server, "GET", "/services/hostedservices/myservice?embed-detail=true");
} finally {
@@ -106,14 +78,14 @@ public class HostedServiceApiMockTest extends BaseAzureComputeApiMockTest {
}
}
- public void getDetailsWhenNotFound() throws Exception {
+ public void getWhenNotFound() throws Exception {
MockWebServer server = mockAzureManagementServer();
server.enqueue(new MockResponse().setResponseCode(404));
try {
HostedServiceApi api = api(server.getUrl("/")).getHostedServiceApi();
- assertThat(api.getDetails("myservice")).isNull();
+ assertNull(api.get("myservice"));
assertSent(server, "GET", "/services/hostedservices/myservice?embed-detail=true");
} finally {
@@ -128,8 +100,7 @@ public class HostedServiceApiMockTest extends BaseAzureComputeApiMockTest {
try {
HostedServiceApi api = api(server.getUrl("/")).getHostedServiceApi();
- assertThat(api.createServiceWithLabelInLocation("myservice", "service mine", "West US"))
- .isEqualTo("request-1");
+ assertEquals(api.createServiceWithLabelInLocation("myservice", "service mine", "West US"), "request-1");
assertSent(server, "POST", "/services/hostedservices", "/create_hostedservice_location.xml");
} finally {
@@ -144,9 +115,8 @@ public class HostedServiceApiMockTest extends BaseAzureComputeApiMockTest {
try {
HostedServiceApi api = api(server.getUrl("/")).getHostedServiceApi();
- assertThat(api.createServiceWithLabelInLocation("myservice", "service mine", "West US",
- description("my description").extendedProperties(ImmutableMap.of("Role", "Production"))))
- .isEqualTo("request-1");
+ assertEquals(api.createServiceWithLabelInLocation("myservice", "service mine", "West US",
+ description("my description").extendedProperties(ImmutableMap.of("Role", "Production"))), "request-1");
assertSent(server, "POST", "/services/hostedservices", "/create_hostedservice_location_options.xml");
} finally {
@@ -161,7 +131,7 @@ public class HostedServiceApiMockTest extends BaseAzureComputeApiMockTest {
try {
HostedServiceApi api = api(server.getUrl("/")).getHostedServiceApi();
- assertThat(api.delete("myservice")).isEqualTo("request-1");
+ assertEquals(api.delete("myservice"), "request-1");
assertSent(server, "DELETE", "/services/hostedservices/myservice");
} finally {
@@ -176,7 +146,7 @@ public class HostedServiceApiMockTest extends BaseAzureComputeApiMockTest {
try {
HostedServiceApi api = api(server.getUrl("/")).getHostedServiceApi();
- assertThat(api.delete("myservice")).isNull();
+ assertNull(api.delete("myservice"));
assertSent(server, "DELETE", "/services/hostedservices/myservice");
} finally {
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/de2f415a/azurecompute/src/test/java/org/jclouds/azurecompute/parse/GetHostedServiceDetailsTest.java
----------------------------------------------------------------------
diff --git a/azurecompute/src/test/java/org/jclouds/azurecompute/parse/GetHostedServiceDetailsTest.java b/azurecompute/src/test/java/org/jclouds/azurecompute/parse/GetHostedServiceDetailsTest.java
deleted file mode 100644
index 8a71f50..0000000
--- a/azurecompute/src/test/java/org/jclouds/azurecompute/parse/GetHostedServiceDetailsTest.java
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * 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.parse;
-
-import java.io.InputStream;
-import java.net.URI;
-import org.jclouds.azurecompute.domain.DetailedHostedServiceProperties;
-import org.jclouds.azurecompute.domain.HostedService;
-import org.jclouds.azurecompute.domain.HostedService.Status;
-import org.jclouds.azurecompute.domain.HostedServiceWithDetailedProperties;
-import org.jclouds.azurecompute.xml.HostedServiceWithDetailedPropertiesHandler;
-import org.jclouds.date.DateService;
-import org.jclouds.date.internal.SimpleDateFormatDateService;
-import org.jclouds.http.functions.BaseHandlerTest;
-import org.testng.annotations.Test;
-
-import static org.testng.Assert.assertEquals;
-
-@Test(groups = "unit", testName = "DetailedHostedServiceProperties")
-public class GetHostedServiceDetailsTest extends BaseHandlerTest {
-
- public void test() {
- InputStream is = getClass().getResourceAsStream("/hostedservice_details.xml");
-
- HostedService expected = expected();
-
- HostedServiceWithDetailedPropertiesHandler handler = injector.getInstance(HostedServiceWithDetailedPropertiesHandler.class);
- HostedServiceWithDetailedProperties result = HostedServiceWithDetailedProperties.class.cast(factory.create(handler).parse(is));
-
- assertEquals(result.toString(), expected.toString());
-
- }
-
- private static final DateService dateService = new SimpleDateFormatDateService();
-
- public static HostedServiceWithDetailedProperties expected() {
- return HostedServiceWithDetailedProperties.builder()
- .url(URI.create("https://management.core.windows.net/eb0347c3-68d4-4550-9b39-5e7e0f92f7db/services/hostedservices/neotys"))
- .name("neotys")
- .properties(DetailedHostedServiceProperties.builder()
- .description("Implicitly created hosted service2012-08-06 14:55")
- .location("West Europe")
- .label("neotys")
- .rawStatus("Created")
- .status(Status.CREATED)
- .created(dateService.iso8601SecondsDateParse("2012-08-06T14:55:17Z"))
- .lastModified(dateService.iso8601SecondsDateParse("2012-08-06T15:50:34Z"))
- .build())
- .build();
- }
-}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/de2f415a/azurecompute/src/test/java/org/jclouds/azurecompute/parse/GetHostedServiceTest.java
----------------------------------------------------------------------
diff --git a/azurecompute/src/test/java/org/jclouds/azurecompute/parse/GetHostedServiceTest.java b/azurecompute/src/test/java/org/jclouds/azurecompute/parse/GetHostedServiceTest.java
deleted file mode 100644
index b5ccd31..0000000
--- a/azurecompute/src/test/java/org/jclouds/azurecompute/parse/GetHostedServiceTest.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * 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.parse;
-
-import java.io.InputStream;
-import java.net.URI;
-import org.jclouds.azurecompute.domain.HostedService;
-import org.jclouds.azurecompute.domain.HostedServiceProperties;
-import org.jclouds.azurecompute.xml.HostedServiceHandler;
-import org.jclouds.http.functions.BaseHandlerTest;
-import org.testng.annotations.Test;
-
-import static org.testng.Assert.assertEquals;
-
-@Test(groups = "unit", testName = "GetHostedServiceTest")
-public class GetHostedServiceTest extends BaseHandlerTest {
-
- public void test() {
- InputStream is = getClass().getResourceAsStream("/hostedservice.xml");
-
- HostedService expected = expected();
-
- HostedServiceHandler handler = injector.getInstance(HostedServiceHandler.class);
- HostedService result = factory.create(handler).parse(is);
-
- assertEquals(result.toString(), expected.toString());
-
- }
-
- public static HostedService expected() {
- return HostedService.builder()
- .url(URI.create("https://management.core.windows.net/eb0347c3-68d4-4550-9b39-5e7e0f92f7db/services/hostedservices/neotys"))
- .name("neotys")
- .properties(HostedServiceProperties.builder()
- .description("Implicitly created hosted service2012-08-06 14:55")
- .location("West Europe")
- .label("neotys")
- .build())
- .build();
- }
-}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/de2f415a/azurecompute/src/test/java/org/jclouds/azurecompute/parse/ListHostedServicesTest.java
----------------------------------------------------------------------
diff --git a/azurecompute/src/test/java/org/jclouds/azurecompute/parse/ListHostedServicesTest.java b/azurecompute/src/test/java/org/jclouds/azurecompute/parse/ListHostedServicesTest.java
deleted file mode 100644
index 3eaf136..0000000
--- a/azurecompute/src/test/java/org/jclouds/azurecompute/parse/ListHostedServicesTest.java
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- * 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.parse;
-
-import com.google.common.collect.ImmutableList;
-import java.io.InputStream;
-import java.net.URI;
-import java.util.List;
-import org.jclouds.azurecompute.domain.DetailedHostedServiceProperties;
-import org.jclouds.azurecompute.domain.HostedService.Status;
-import org.jclouds.azurecompute.domain.HostedServiceWithDetailedProperties;
-import org.jclouds.azurecompute.xml.ListHostedServicesHandler;
-import org.jclouds.date.DateService;
-import org.jclouds.date.internal.SimpleDateFormatDateService;
-import org.jclouds.http.functions.BaseHandlerTest;
-import org.testng.annotations.Test;
-
-import static org.testng.Assert.assertEquals;
-
-@Test(groups = "unit", testName = "ListHostedServicesTest")
-public class ListHostedServicesTest extends BaseHandlerTest {
-
- public void test() {
- InputStream is = getClass().getResourceAsStream("/hostedservices.xml");
-
- List<HostedServiceWithDetailedProperties> expected = expected();
-
- ListHostedServicesHandler handler = injector.getInstance(ListHostedServicesHandler.class);
- List<HostedServiceWithDetailedProperties> result = factory.create(handler).parse(is);
-
- assertEquals(result.toString(), expected.toString());
-
- }
-
- private static final DateService dateService = new SimpleDateFormatDateService();
-
- public static List<HostedServiceWithDetailedProperties> expected() {
- return ImmutableList.<HostedServiceWithDetailedProperties>builder()
- .add(HostedServiceWithDetailedProperties.builder()
- .url(URI.create("https://management.core.windows.net/eb0347c3-68d4-4550-9b39-5e7e0f92f7db/services/hostedservices/neotys"))
- .name("neotys")
- .properties(DetailedHostedServiceProperties.builder()
- .description("Implicitly created hosted service2012-08-06 14:55")
- .location("West Europe")
- .label("neotys")
- .rawStatus("Created")
- .status(Status.CREATED)
- .created(dateService.iso8601SecondsDateParse("2012-08-06T14:55:17Z"))
- .lastModified(dateService.iso8601SecondsDateParse("2012-08-06T15:50:34Z"))
- .build())
- .build())
- .add(HostedServiceWithDetailedProperties.builder()
- .url(URI.create("https://management.core.windows.net/eb0347c3-68d4-4550-9b39-5e7e0f92f7db/services/hostedservices/neotys3"))
- .name("neotys3")
- .properties(DetailedHostedServiceProperties.builder()
- .location("West Europe")
- .label("neotys3")
- .rawStatus("Created")
- .status(Status.CREATED)
- .created(dateService.iso8601SecondsDateParse("2012-08-07T09:00:02Z"))
- .lastModified(dateService.iso8601SecondsDateParse("2012-08-07T09:00:02Z"))
- .build())
- .build()).build();
- }
-}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/de2f415a/azurecompute/src/test/java/org/jclouds/azurecompute/xml/HostedServiceHandlerTest.java
----------------------------------------------------------------------
diff --git a/azurecompute/src/test/java/org/jclouds/azurecompute/xml/HostedServiceHandlerTest.java b/azurecompute/src/test/java/org/jclouds/azurecompute/xml/HostedServiceHandlerTest.java
new file mode 100644
index 0000000..aefdca4
--- /dev/null
+++ b/azurecompute/src/test/java/org/jclouds/azurecompute/xml/HostedServiceHandlerTest.java
@@ -0,0 +1,55 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jclouds.azurecompute.xml;
+
+import static org.testng.Assert.assertEquals;
+
+import java.io.InputStream;
+import java.util.Collections;
+
+import org.jclouds.azurecompute.domain.HostedService;
+import org.jclouds.azurecompute.domain.HostedService.Status;
+import org.jclouds.date.DateService;
+import org.jclouds.date.internal.SimpleDateFormatDateService;
+import org.jclouds.http.functions.BaseHandlerTest;
+import org.testng.annotations.Test;
+
+@Test(groups = "unit", testName = "HostedServiceHandlerTest")
+public class HostedServiceHandlerTest extends BaseHandlerTest {
+ private static final DateService DATE_SERVICE = new SimpleDateFormatDateService();
+
+ public void test() {
+ InputStream is = getClass().getResourceAsStream("/hostedservice.xml");
+ HostedService result = factory.create(new HostedServiceHandler(DATE_SERVICE)).parse(is);
+
+ assertEquals(result, expected());
+ }
+
+ public static HostedService expected() {
+ return HostedService.create( //
+ "neotys", // name
+ "West Europe", // location
+ null, // affinityGroup
+ "neotys", // label
+ "Implicitly created hosted service2012-08-06 14:55", // description
+ Status.CREATED, // status
+ DATE_SERVICE.iso8601SecondsDateParse("2012-08-06T14:55:17Z"), // created
+ DATE_SERVICE.iso8601SecondsDateParse("2012-08-06T15:50:34Z"), // lastModified
+ Collections.<String, String>emptyMap() // extendedProperties
+ );
+ }
+}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/de2f415a/azurecompute/src/test/java/org/jclouds/azurecompute/xml/ListHostedServicesHandlerTest.java
----------------------------------------------------------------------
diff --git a/azurecompute/src/test/java/org/jclouds/azurecompute/xml/ListHostedServicesHandlerTest.java b/azurecompute/src/test/java/org/jclouds/azurecompute/xml/ListHostedServicesHandlerTest.java
new file mode 100644
index 0000000..f40f3c9
--- /dev/null
+++ b/azurecompute/src/test/java/org/jclouds/azurecompute/xml/ListHostedServicesHandlerTest.java
@@ -0,0 +1,71 @@
+/*
+ * 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.xml;
+
+import static org.testng.Assert.assertEquals;
+
+import java.io.InputStream;
+import java.util.Collections;
+import java.util.List;
+
+import org.jclouds.azurecompute.domain.HostedService;
+import org.jclouds.azurecompute.domain.HostedService.Status;
+import org.jclouds.date.DateService;
+import org.jclouds.date.internal.SimpleDateFormatDateService;
+import org.jclouds.http.functions.BaseHandlerTest;
+import org.testng.annotations.Test;
+
+import com.google.common.collect.ImmutableList;
+
+@Test(groups = "unit", testName = "ListHostedServicesHandlerTest")
+public class ListHostedServicesHandlerTest extends BaseHandlerTest {
+ private static final DateService DATE_SERVICE = new SimpleDateFormatDateService();
+
+ public void test() {
+ InputStream is = getClass().getResourceAsStream("/hostedservices.xml");
+ ListHostedServicesHandler handler = new ListHostedServicesHandler(new HostedServiceHandler(DATE_SERVICE));
+ List<HostedService> result = factory.create(handler).parse(is);
+
+ assertEquals(result, expected());
+ }
+
+ public static List<HostedService> expected() {
+ return ImmutableList.of( //
+ HostedService.create( //
+ "neotys", // name
+ "West Europe", // location
+ null, // affinityGroup
+ "neotys", // label
+ "Implicitly created hosted service2012-08-06 14:55", // description
+ Status.CREATED, // status
+ DATE_SERVICE.iso8601SecondsDateParse("2012-08-06T14:55:17Z"), // created
+ DATE_SERVICE.iso8601SecondsDateParse("2012-08-06T15:50:34Z"), // lastModified
+ Collections.<String, String>emptyMap() // extendedProperties
+ ), //
+ HostedService.create( //
+ "neotys3", // name
+ "West Europe", // location
+ null, // affinityGroup
+ "neotys3", // label
+ null, // description
+ Status.CREATED, // status
+ DATE_SERVICE.iso8601SecondsDateParse("2012-08-07T09:00:02Z"), // created
+ DATE_SERVICE.iso8601SecondsDateParse("2012-08-07T09:00:02Z"), // lastModified
+ Collections.<String, String>emptyMap() // extendedProperties
+ ));
+ }
+}
[11/11] git commit: Cleanup output-only Operation object.
Posted by ad...@apache.org.
Cleanup output-only Operation object.
Project: http://git-wip-us.apache.org/repos/asf/jclouds-labs/repo
Commit: http://git-wip-us.apache.org/repos/asf/jclouds-labs/commit/20c397c7
Tree: http://git-wip-us.apache.org/repos/asf/jclouds-labs/tree/20c397c7
Diff: http://git-wip-us.apache.org/repos/asf/jclouds-labs/diff/20c397c7
Branch: refs/heads/master
Commit: 20c397c7fbf82eeee41590821689f6eedcb49ac0
Parents: f4af63f
Author: Adrian Cole <ac...@twitter.com>
Authored: Mon Oct 20 09:59:13 2014 -0400
Committer: Adrian Cole <ac...@twitter.com>
Committed: Mon Oct 20 13:26:54 2014 -0400
----------------------------------------------------------------------
.../jclouds/azurecompute/domain/Operation.java | 180 +++++--------------
.../azurecompute/xml/OperationHandler.java | 81 ++++-----
.../features/HostedServiceApiLiveTest.java | 2 +-
.../features/OperationApiMockTest.java | 14 +-
.../azurecompute/parse/GetOperationTest.java | 53 ------
.../azurecompute/xml/OperationHandlerTest.java | 41 +++++
6 files changed, 124 insertions(+), 247 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/20c397c7/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
index eb336f4..0c0b02a 100644
--- a/azurecompute/src/main/java/org/jclouds/azurecompute/domain/Operation.java
+++ b/azurecompute/src/main/java/org/jclouds/azurecompute/domain/Operation.java
@@ -16,168 +16,62 @@
*/
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.Objects.equal;
import static com.google.common.base.Preconditions.checkNotNull;
+import org.jclouds.javax.annotation.Nullable;
+
+import com.google.common.base.Objects;
+
/**
*
- * Determines whether the operation has succeeded, failed, or is still in progress.
+ * Determines whether the asynchronous 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,
-
+public final class Operation {
+ public 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());
- }
+ public String id() {
+ return id;
}
- 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);
+ public Status status() {
+ return status;
}
- /**
- * The request ID of the asynchronous request.
- */
- public String getId() {
- return id;
+ @Nullable public Integer httpStatusCode() {
+ return httpStatusCode;
}
- /**
- * The status of the asynchronous request.
- */
- public Status getStatus() {
- return status;
+ /** Present when the operation {@link Status#FAILED failed}. */
+ @Nullable public Error error() {
+ return error;
}
- /**
- * The status of the asynchronous request, unparsed
- */
- public String getRawStatus() {
- return rawStatus;
+ public static Operation create(String id, Status status, Integer httpStatusCode, Error error) {
+ return new Operation(id, status, httpStatusCode, error);
}
- /**
- * The HTTP status code for the asynchronous request.
- */
- public Optional<Integer> getHttpStatusCode() {
- return httpStatusCode;
+ // TODO: Remove from here down with @AutoValue.
+ private Operation(String id, Status status, Integer httpStatusCode, Error error) {
+ this.id = checkNotNull(id, "id");
+ this.status = checkNotNull(status, "status");
+ this.httpStatusCode = httpStatusCode;
+ this.error = error;
}
- /**
- * The management service error returned if the asynchronous request failed.
- */
- public Optional<Error> getError() {
- return error;
- }
+ private final String id;
+ private final Status status;
+ private final Integer httpStatusCode;
+ private final Error error;
@Override
public int hashCode() {
- return Objects.hashCode(id);
+ return Objects.hashCode(id, status, httpStatusCode, error);
}
@Override
@@ -189,12 +83,18 @@ public class Operation {
if (getClass() != obj.getClass())
return false;
Operation other = (Operation) obj;
- return Objects.equal(this.id, other.id);
+ return equal(this.id, other.id) &&
+ equal(this.status, other.status) &&
+ equal(this.httpStatusCode, other.httpStatusCode) &&
+ equal(this.error, other.error);
}
@Override
public String toString() {
- return MoreObjects.toStringHelper(this).omitNullValues().add("id", id).add("status", rawStatus)
- .add("httpStatusCode", httpStatusCode).add("error", error.orNull()).toString();
+ return Objects.toStringHelper(this)
+ .add("id", id)
+ .add("status", status)
+ .add("httpStatusCode", httpStatusCode)
+ .add("error", error).toString();
}
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/20c397c7/azurecompute/src/main/java/org/jclouds/azurecompute/xml/OperationHandler.java
----------------------------------------------------------------------
diff --git a/azurecompute/src/main/java/org/jclouds/azurecompute/xml/OperationHandler.java b/azurecompute/src/main/java/org/jclouds/azurecompute/xml/OperationHandler.java
index e0a6912..e417be1 100644
--- a/azurecompute/src/main/java/org/jclouds/azurecompute/xml/OperationHandler.java
+++ b/azurecompute/src/main/java/org/jclouds/azurecompute/xml/OperationHandler.java
@@ -16,82 +16,69 @@
*/
package org.jclouds.azurecompute.xml;
-import javax.inject.Inject;
+import static com.google.common.base.CaseFormat.UPPER_CAMEL;
+import static com.google.common.base.CaseFormat.UPPER_UNDERSCORE;
+import static org.jclouds.util.SaxUtils.currentOrNull;
+
+import org.jclouds.azurecompute.domain.Error;
import org.jclouds.azurecompute.domain.Operation;
-import org.jclouds.azurecompute.domain.Operation.Builder;
import org.jclouds.azurecompute.domain.Operation.Status;
import org.jclouds.http.functions.ParseSax;
import org.xml.sax.Attributes;
-import org.xml.sax.SAXException;
-
-import static org.jclouds.util.SaxUtils.currentOrNull;
-import static org.jclouds.util.SaxUtils.equalsOrSuffix;
/**
* @see <a href="http://msdn.microsoft.com/en-us/library/ee460783" >api</a>
*/
-public class OperationHandler extends ParseSax.HandlerForGeneratedRequestWithResult<Operation> {
-
- private final ErrorHandler errorHandler;
-
- @Inject
- private OperationHandler(ErrorHandler errorHandler) {
- this.errorHandler = errorHandler;
- }
-
- private StringBuilder currentText = new StringBuilder();
- private Operation.Builder builder = builder();
-
- private Builder builder() {
- return Operation.builder();
- }
+public final class OperationHandler extends ParseSax.HandlerForGeneratedRequestWithResult<Operation> {
+ private String id;
+ private Status status;
+ private Integer httpStatusCode;
+ private Error error;
private boolean inError;
+ private final ErrorHandler errorHandler = new ErrorHandler();
+ private final StringBuilder currentText = new StringBuilder();
- @Override
- public Operation getResult() {
- try {
- return builder.build();
- } finally {
- builder = builder();
- }
+ @Override public Operation getResult() {
+ return Operation.create(id, status, httpStatusCode, error);
}
- @Override
- public void startElement(String url, String name, String qName, Attributes attributes) throws SAXException {
- if (equalsOrSuffix(qName, "Error")) {
+ @Override public void startElement(String url, String name, String qName, Attributes attributes) {
+ if (qName.equals("Error")) {
inError = true;
}
- if (inError) {
- errorHandler.startElement(url, name, qName, attributes);
- }
}
- @Override
- public void endElement(String uri, String name, String qName) throws SAXException {
- if (equalsOrSuffix(qName, "Error")) {
- builder.error(errorHandler.getResult());
+ @Override public void endElement(String uri, String name, String qName) {
+ if (qName.equals("Error")) {
+ error = errorHandler.getResult();
inError = false;
} else if (inError) {
errorHandler.endElement(uri, name, qName);
- } else if (equalsOrSuffix(qName, "ID")) {
- builder.id(currentOrNull(currentText));
+ } else if (qName.equals("ID")) {
+ id = currentOrNull(currentText);
} else if (qName.equals("Status")) {
- String rawStatus = currentOrNull(currentText);
- builder.rawStatus(rawStatus);
- builder.status(Status.fromValue(rawStatus));
- } else if (equalsOrSuffix(qName, "HttpStatusCode")) {
- builder.httpStatusCode(Integer.parseInt(currentOrNull(currentText)));
+ String statusText = currentOrNull(currentText);
+ status = parseStatus(statusText);
+ } else if (qName.equals("HttpStatusCode")) {
+ httpStatusCode = Integer.parseInt(currentOrNull(currentText));
}
currentText.setLength(0);
}
- @Override
- public void characters(char ch[], int start, int length) {
+ @Override public void characters(char ch[], int start, int length) {
if (inError) {
errorHandler.characters(ch, start, length);
} else {
currentText.append(ch, start, length);
}
}
+
+ private static Status parseStatus(String status) {
+ try {
+ return Status.valueOf(UPPER_CAMEL.to(UPPER_UNDERSCORE, status));
+ } catch (IllegalArgumentException e) {
+ return Status.UNRECOGNIZED;
+ }
+ }
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/20c397c7/azurecompute/src/test/java/org/jclouds/azurecompute/features/HostedServiceApiLiveTest.java
----------------------------------------------------------------------
diff --git a/azurecompute/src/test/java/org/jclouds/azurecompute/features/HostedServiceApiLiveTest.java b/azurecompute/src/test/java/org/jclouds/azurecompute/features/HostedServiceApiLiveTest.java
index eb0eec8..894c0de 100644
--- a/azurecompute/src/test/java/org/jclouds/azurecompute/features/HostedServiceApiLiveTest.java
+++ b/azurecompute/src/test/java/org/jclouds/azurecompute/features/HostedServiceApiLiveTest.java
@@ -57,7 +57,7 @@ public class HostedServiceApiLiveTest extends BaseAzureComputeApiLiveTest {
location = Iterables.get(api.getLocationApi().list(), 0).name();
operationSucceeded = retry(new Predicate<String>() {
public boolean apply(String input) {
- return api.getOperationApi().get(input).getStatus() == Operation.Status.SUCCEEDED;
+ return api.getOperationApi().get(input).status() == Operation.Status.SUCCEEDED;
}
}, 600, 5, 5, SECONDS);
hostedServiceCreated = retry(new Predicate<HostedService>() {
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/20c397c7/azurecompute/src/test/java/org/jclouds/azurecompute/features/OperationApiMockTest.java
----------------------------------------------------------------------
diff --git a/azurecompute/src/test/java/org/jclouds/azurecompute/features/OperationApiMockTest.java b/azurecompute/src/test/java/org/jclouds/azurecompute/features/OperationApiMockTest.java
index 2298bc0..dae2053 100644
--- a/azurecompute/src/test/java/org/jclouds/azurecompute/features/OperationApiMockTest.java
+++ b/azurecompute/src/test/java/org/jclouds/azurecompute/features/OperationApiMockTest.java
@@ -16,13 +16,15 @@
*/
package org.jclouds.azurecompute.features;
-import com.squareup.okhttp.mockwebserver.MockResponse;
-import com.squareup.okhttp.mockwebserver.MockWebServer;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertNull;
+
import org.jclouds.azurecompute.internal.BaseAzureComputeApiMockTest;
-import org.jclouds.azurecompute.parse.GetOperationTest;
+import org.jclouds.azurecompute.xml.OperationHandlerTest;
import org.testng.annotations.Test;
-import static org.assertj.core.api.Assertions.assertThat;
+import com.squareup.okhttp.mockwebserver.MockResponse;
+import com.squareup.okhttp.mockwebserver.MockWebServer;
@Test(groups = "unit", testName = "OperationApiMockTest")
public class OperationApiMockTest extends BaseAzureComputeApiMockTest {
@@ -34,7 +36,7 @@ public class OperationApiMockTest extends BaseAzureComputeApiMockTest {
try {
OperationApi api = api(server.getUrl("/")).getOperationApi();
- assertThat(api.get("request-id")).isEqualTo(GetOperationTest.expected());
+ assertEquals(api.get("request-id"), OperationHandlerTest.expected());
assertSent(server, "GET", "/operations/request-id");
} finally {
@@ -49,7 +51,7 @@ public class OperationApiMockTest extends BaseAzureComputeApiMockTest {
try {
OperationApi api = api(server.getUrl("/")).getOperationApi();
- assertThat(api.get("request-id")).isNull();
+ assertNull(api.get("request-id"));
assertSent(server, "GET", "/operations/request-id");
} finally {
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/20c397c7/azurecompute/src/test/java/org/jclouds/azurecompute/parse/GetOperationTest.java
----------------------------------------------------------------------
diff --git a/azurecompute/src/test/java/org/jclouds/azurecompute/parse/GetOperationTest.java b/azurecompute/src/test/java/org/jclouds/azurecompute/parse/GetOperationTest.java
deleted file mode 100644
index 8e41f81..0000000
--- a/azurecompute/src/test/java/org/jclouds/azurecompute/parse/GetOperationTest.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * 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.parse;
-
-import static org.testng.Assert.assertEquals;
-
-import java.io.InputStream;
-
-import org.jclouds.azurecompute.domain.Operation;
-import org.jclouds.azurecompute.domain.Operation.Status;
-import org.jclouds.azurecompute.xml.ErrorHandlerTest;
-import org.jclouds.azurecompute.xml.OperationHandler;
-import org.jclouds.http.functions.BaseHandlerTest;
-import org.testng.annotations.Test;
-
-@Test(groups = "unit", testName = "GetOperationTest")
-public class GetOperationTest extends BaseHandlerTest {
-
- public void test() {
- InputStream is = getClass().getResourceAsStream("/operation.xml");
-
- Operation expected = expected();
-
- OperationHandler handler = injector.getInstance(OperationHandler.class);
- Operation result = factory.create(handler).parse(is);
-
- assertEquals(result.toString(), expected.toString());
- }
-
- public static Operation expected() {
- return Operation.builder()
- .id("request-id")
- .rawStatus("Failed")
- .status(Status.FAILED)
- .httpStatusCode(400)
- .error(ErrorHandlerTest.expected())
- .build();
- }
-}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/20c397c7/azurecompute/src/test/java/org/jclouds/azurecompute/xml/OperationHandlerTest.java
----------------------------------------------------------------------
diff --git a/azurecompute/src/test/java/org/jclouds/azurecompute/xml/OperationHandlerTest.java b/azurecompute/src/test/java/org/jclouds/azurecompute/xml/OperationHandlerTest.java
new file mode 100644
index 0000000..635c5df
--- /dev/null
+++ b/azurecompute/src/test/java/org/jclouds/azurecompute/xml/OperationHandlerTest.java
@@ -0,0 +1,41 @@
+/*
+ * 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.xml;
+
+import static org.testng.Assert.assertEquals;
+
+import java.io.InputStream;
+
+import org.jclouds.azurecompute.domain.Operation;
+import org.jclouds.azurecompute.domain.Operation.Status;
+import org.jclouds.http.functions.BaseHandlerTest;
+import org.testng.annotations.Test;
+
+@Test(groups = "unit", testName = "OperationHandlerTest")
+public class OperationHandlerTest extends BaseHandlerTest {
+
+ public void test() {
+ InputStream is = getClass().getResourceAsStream("/operation.xml");
+ Operation result = factory.create(new OperationHandler()).parse(is);
+
+ assertEquals(result, expected());
+ }
+
+ public static Operation expected() {
+ return Operation.create("request-id", Status.FAILED, 400, ErrorHandlerTest.expected());
+ }
+}
[06/11] git commit: Removed unused JAXB annotations.
Posted by ad...@apache.org.
Removed unused JAXB annotations.
Project: http://git-wip-us.apache.org/repos/asf/jclouds-labs/repo
Commit: http://git-wip-us.apache.org/repos/asf/jclouds-labs/commit/14207a33
Tree: http://git-wip-us.apache.org/repos/asf/jclouds-labs/tree/14207a33
Diff: http://git-wip-us.apache.org/repos/asf/jclouds-labs/diff/14207a33
Branch: refs/heads/master
Commit: 14207a33cf4c8a1d9a32615bdf0c762b7406d910
Parents: cd55201
Author: Adrian Cole <ac...@twitter.com>
Authored: Thu Oct 16 19:01:17 2014 -0700
Committer: Adrian Cole <ac...@twitter.com>
Committed: Mon Oct 20 13:26:53 2014 -0400
----------------------------------------------------------------------
.../binders/BindDeploymentParamsToXmlPayload.java | 2 +-
.../main/java/org/jclouds/azurecompute/domain/Protocol.java | 8 --------
2 files changed, 1 insertion(+), 9 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/14207a33/azurecompute/src/main/java/org/jclouds/azurecompute/binders/BindDeploymentParamsToXmlPayload.java
----------------------------------------------------------------------
diff --git a/azurecompute/src/main/java/org/jclouds/azurecompute/binders/BindDeploymentParamsToXmlPayload.java b/azurecompute/src/main/java/org/jclouds/azurecompute/binders/BindDeploymentParamsToXmlPayload.java
index 5c50740..1c127f1 100644
--- a/azurecompute/src/main/java/org/jclouds/azurecompute/binders/BindDeploymentParamsToXmlPayload.java
+++ b/azurecompute/src/main/java/org/jclouds/azurecompute/binders/BindDeploymentParamsToXmlPayload.java
@@ -79,7 +79,7 @@ public class BindDeploymentParamsToXmlPayload implements Binder {
inputBuilder.e("LocalPort").t(endpoint.getLocalPort().toString()).up()
.e("Name").t(endpoint.getName()).up()
.e("Port").t(endpoint.getExternalPort().toString()).up()
- .e("Protocol").t(endpoint.getProtocol().name()).up()
+ .e("Protocol").t(endpoint.getProtocol().name().toLowerCase()).up()
.up(); //InputEndpoint
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/14207a33/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
index add7ee0..2e3d245 100644
--- a/azurecompute/src/main/java/org/jclouds/azurecompute/domain/Protocol.java
+++ b/azurecompute/src/main/java/org/jclouds/azurecompute/domain/Protocol.java
@@ -16,16 +16,8 @@
*/
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
}