You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jclouds.apache.org by na...@apache.org on 2015/02/02 16:14:04 UTC

jclouds-labs git commit: JCLOUDS-664: Added DataVirtualHardDisk Representation With Tests

Repository: jclouds-labs
Updated Branches:
  refs/heads/master d56c8721f -> 80f5c8f76


JCLOUDS-664: Added DataVirtualHardDisk Representation With Tests

Minor Changes

Minor Changes

minor change


Project: http://git-wip-us.apache.org/repos/asf/jclouds-labs/repo
Commit: http://git-wip-us.apache.org/repos/asf/jclouds-labs/commit/80f5c8f7
Tree: http://git-wip-us.apache.org/repos/asf/jclouds-labs/tree/80f5c8f7
Diff: http://git-wip-us.apache.org/repos/asf/jclouds-labs/diff/80f5c8f7

Branch: refs/heads/master
Commit: 80f5c8f763f731437ba68986b7d9837900544334
Parents: d56c872
Author: hsbhathiya <hs...@gmail.com>
Authored: Thu Jan 22 19:01:35 2015 +0530
Committer: Ignasi Barrera <na...@apache.org>
Committed: Mon Feb 2 16:11:27 2015 +0100

----------------------------------------------------------------------
 .../domain/DataVirtualHardDisk.java             | 97 ++++++++++++++++++++
 .../xml/DataVirtualHardDiskHandler.java         | 91 ++++++++++++++++++
 .../xml/ListDataVirtualHardDisksHandler.java    | 66 +++++++++++++
 .../ListDataVirtualHardDisksHandlerTest.java    | 60 ++++++++++++
 .../src/test/resources/datavirtualharddisk.xml  | 18 ++++
 5 files changed, 332 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/80f5c8f7/azurecompute/src/main/java/org/jclouds/azurecompute/domain/DataVirtualHardDisk.java
----------------------------------------------------------------------
diff --git a/azurecompute/src/main/java/org/jclouds/azurecompute/domain/DataVirtualHardDisk.java b/azurecompute/src/main/java/org/jclouds/azurecompute/domain/DataVirtualHardDisk.java
new file mode 100644
index 0000000..05b39e2
--- /dev/null
+++ b/azurecompute/src/main/java/org/jclouds/azurecompute/domain/DataVirtualHardDisk.java
@@ -0,0 +1,97 @@
+/*
+ * 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.auto.value.AutoValue;
+import org.jclouds.javax.annotation.Nullable;
+
+import java.net.URI;
+
+/**
+ * @see <a href="https://msdn.microsoft.com/en-us/library/azure/jj157193.aspx#DataVirtualHardDisks" >api</a>
+ */
+
+@AutoValue
+public abstract class DataVirtualHardDisk {
+
+   public enum Caching {
+      READ_ONLY,
+      READ_WRITE,
+      NONE
+   }
+
+   /**
+    * Specifies the caching mode of the operating system disk.
+    * This setting impacts the consistency and performance of the disk.
+    * Possible values are:
+    * ReadOnly
+    * ReadWrite
+    * The default value is ReadWrite
+    */
+   @Nullable public abstract Caching hostCaching();
+
+   /**
+    * Required if an existing disk is being used to create a Virtual Machine.
+    * Specifies the name of a new or existing disk
+    */
+   @Nullable public abstract String diskName();
+
+   /**
+    * Specifies the Logical Unit Number (LUN) for the data disk. If the disk is the first disk that is added,
+    * this element is optional and the default value of 0 is used. If more than one disk is being added,
+    * this element is required.
+    * <p/>
+    * You can use Get Role to find the LUN numbers that are already being used.
+    * Valid LUN values are 0 through 31
+    */
+   @Nullable public abstract Integer lun();
+
+   /**
+    * Specifies the size, in GB, of an empty disk to be attached to the Virtual Machine.If the disk that is being added
+    * is already registered in the subscription, this element is ignored.If the disk and VHD is being created by Azure
+    * as it is added, this element defines the size of the new disk.
+    * <p/>
+    * The number of disks that can be added to a Virtual Machine is limited by the size of the machine.
+    * <p/>
+    * This element is used with the MediaLink element.
+    */
+   @Nullable public abstract Integer logicalDiskSizeInGB();
+
+   /**
+    * If the disk that is being added is already registered in the subscription or the VHD for the disk already exists
+    * in blob storage, this element is ignored. If a VHD file does not exist in blob storage, this element defines the
+    * location of the new VHD that is created when the new disk is added.
+    * Example:
+    * http://example.blob.core.windows.net/disks/mydatadisk.vhd
+    */
+   @Nullable public abstract URI mediaLink();
+
+   /**
+    * This property identifies the type of the storage account for the backing VHD.
+    * If the backing VHD is in an Provisioned Storage account, “Provisioned” is returned otherwise “Standard”
+    * is returned.
+    * <p/>
+    * This property is only returned with a version header of 2014-10-01 or newer
+    */
+   @Nullable public abstract String ioType();
+
+   public static DataVirtualHardDisk create(Caching hostCaching, String diskName,
+         Integer lun, Integer logicalDiskSizeInGB, URI mediaLink, String ioType) {
+      return new AutoValue_DataVirtualHardDisk(hostCaching, diskName, lun, logicalDiskSizeInGB,
+            mediaLink, ioType);
+   }
+}

http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/80f5c8f7/azurecompute/src/main/java/org/jclouds/azurecompute/xml/DataVirtualHardDiskHandler.java
----------------------------------------------------------------------
diff --git a/azurecompute/src/main/java/org/jclouds/azurecompute/xml/DataVirtualHardDiskHandler.java b/azurecompute/src/main/java/org/jclouds/azurecompute/xml/DataVirtualHardDiskHandler.java
new file mode 100644
index 0000000..97452de
--- /dev/null
+++ b/azurecompute/src/main/java/org/jclouds/azurecompute/xml/DataVirtualHardDiskHandler.java
@@ -0,0 +1,91 @@
+/*
+ * 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.DataVirtualHardDisk;
+import org.jclouds.http.functions.ParseSax;
+
+import static com.google.common.base.CaseFormat.UPPER_CAMEL;
+import static com.google.common.base.CaseFormat.UPPER_UNDERSCORE;
+
+import java.net.URI;
+
+import static org.jclouds.util.SaxUtils.currentOrNull;
+
+/**
+ * @see <a href="https://msdn.microsoft.com/en-us/library/azure/jj157193.aspx#DataVirtualHardDisks" >api</a>
+ */
+final class DataVirtualHardDiskHandler extends ParseSax.HandlerForGeneratedRequestWithResult<DataVirtualHardDisk> {
+
+   private DataVirtualHardDisk.Caching hostCaching;
+   private String diskName;
+   private Integer lun;
+   private Integer logicalDiskSizeInGB;
+   private URI mediaLink;
+   private String ioType;
+
+   private final StringBuilder currentText = new StringBuilder();
+
+   @Override
+   public DataVirtualHardDisk getResult() {
+      DataVirtualHardDisk result = DataVirtualHardDisk
+            .create(hostCaching, diskName, lun, logicalDiskSizeInGB, mediaLink, ioType);
+      return result;
+   }
+
+   @Override public void endElement(String ignoredUri, String ignoredName, String qName) {
+
+      if (qName.equals("HostCaching")) {
+         String hostCachingText = currentOrNull(currentText);
+         if (hostCachingText != null) {
+            hostCaching = parseHostCache(hostCachingText);
+         }
+      } else if (qName.equals("DiskName")) {
+         diskName = currentOrNull(currentText);
+      } else if (qName.equals("Lun")) {
+         String lunText = currentOrNull(currentText);
+         if (lunText != null) {
+            lun = Integer.parseInt(lunText);
+         }
+      } else if (qName.equals("LogicalDiskSizeInGB")) {
+         String gb = currentOrNull(currentText);
+         if (gb != null) {
+            logicalDiskSizeInGB = Integer.parseInt(gb);
+         }
+      } else if (qName.equals("MediaLink")) {
+         String link = currentOrNull(currentText);
+         if (link != null) {
+            mediaLink = URI.create(link);
+         }
+      } else if (qName.equals("IOType")) {
+         ioType = currentOrNull(currentText);
+      }
+      currentText.setLength(0);
+   }
+
+   private static DataVirtualHardDisk.Caching parseHostCache(String hostCaching) {
+      try {
+         return DataVirtualHardDisk.Caching.valueOf(UPPER_CAMEL.to(UPPER_UNDERSCORE, hostCaching));
+      } catch (IllegalArgumentException e) {
+         return DataVirtualHardDisk.Caching.NONE;
+      }
+   }
+
+   @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/80f5c8f7/azurecompute/src/main/java/org/jclouds/azurecompute/xml/ListDataVirtualHardDisksHandler.java
----------------------------------------------------------------------
diff --git a/azurecompute/src/main/java/org/jclouds/azurecompute/xml/ListDataVirtualHardDisksHandler.java b/azurecompute/src/main/java/org/jclouds/azurecompute/xml/ListDataVirtualHardDisksHandler.java
new file mode 100644
index 0000000..47a1b20
--- /dev/null
+++ b/azurecompute/src/main/java/org/jclouds/azurecompute/xml/ListDataVirtualHardDisksHandler.java
@@ -0,0 +1,66 @@
+/*
+ * 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 com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableList.Builder;
+import com.google.inject.Inject;
+import org.jclouds.azurecompute.domain.DataVirtualHardDisk;
+import org.jclouds.http.functions.ParseSax;
+import org.xml.sax.Attributes;
+
+import java.util.List;
+
+public final class ListDataVirtualHardDisksHandler
+      extends ParseSax.HandlerForGeneratedRequestWithResult<List<DataVirtualHardDisk>> {
+   private boolean inDataVHD;
+   private final DataVirtualHardDiskHandler dataVirtualHardDiskHandler;
+   private final Builder<DataVirtualHardDisk> VHDs = ImmutableList.builder();
+
+   @Inject ListDataVirtualHardDisksHandler(DataVirtualHardDiskHandler dataVirtualHardDiskHandler) {
+      this.dataVirtualHardDiskHandler = dataVirtualHardDiskHandler;
+   }
+
+   @Override
+   public List<DataVirtualHardDisk> getResult() {
+      return VHDs.build();
+   }
+
+   @Override
+   public void startElement(String url, String name, String qName, Attributes attributes) {
+      if (qName.equals("DataVirtualHardDisk")) {
+         inDataVHD = true;
+      }
+   }
+
+   @Override
+   public void endElement(String uri, String name, String qName) {
+      if (qName.equals("DataVirtualHardDisk")) {
+         inDataVHD = false;
+         VHDs.add(dataVirtualHardDiskHandler.getResult());
+      } else if (inDataVHD) {
+         dataVirtualHardDiskHandler.endElement(uri, name, qName);
+      }
+   }
+
+   @Override
+   public void characters(char ch[], int start, int length) {
+      if (inDataVHD) {
+         dataVirtualHardDiskHandler.characters(ch, start, length);
+      }
+   }
+}

http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/80f5c8f7/azurecompute/src/test/java/org/jclouds/azurecompute/xml/ListDataVirtualHardDisksHandlerTest.java
----------------------------------------------------------------------
diff --git a/azurecompute/src/test/java/org/jclouds/azurecompute/xml/ListDataVirtualHardDisksHandlerTest.java b/azurecompute/src/test/java/org/jclouds/azurecompute/xml/ListDataVirtualHardDisksHandlerTest.java
new file mode 100644
index 0000000..1b54185
--- /dev/null
+++ b/azurecompute/src/test/java/org/jclouds/azurecompute/xml/ListDataVirtualHardDisksHandlerTest.java
@@ -0,0 +1,60 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jclouds.azurecompute.xml;
+
+import com.google.common.collect.ImmutableList;
+import org.jclouds.azurecompute.domain.DataVirtualHardDisk;
+import org.jclouds.http.functions.BaseHandlerTest;
+import org.testng.annotations.Test;
+
+import java.io.InputStream;
+import java.net.URI;
+import java.util.List;
+
+import static org.testng.Assert.assertEquals;
+
+@Test(groups = "unit", testName = "ListDataVirtualHardDiskHandlerTest")
+public class ListDataVirtualHardDisksHandlerTest extends BaseHandlerTest {
+
+   public void test() {
+      InputStream is = getClass().getResourceAsStream("/datavirtualharddisk.xml");
+      List<DataVirtualHardDisk> result = factory
+            .create(new ListDataVirtualHardDisksHandler(new DataVirtualHardDiskHandler())).parse(is);
+      assertEquals(result, expected());
+   }
+
+   public static List<DataVirtualHardDisk> expected() {
+      return ImmutableList.of(
+            DataVirtualHardDisk.create(
+                  DataVirtualHardDisk.Caching.READ_ONLY,
+                  "testimage1-testimage1-0-20120817095145",
+                  10,
+                  30,
+                  URI.create("http://blobs/disks/neotysss/MSFT__Win2K8R2SP1-ABCD-en-us-30GB.vhd"),
+                  "Standard"
+            ),
+            DataVirtualHardDisk.create(
+                  DataVirtualHardDisk.Caching.READ_WRITE,
+                  "testimage2-testimage2-0-20120817095145",
+                  10,
+                  30,
+                  URI.create("http://blobs/disks/neotysss/MSFT__Win2K8R2SP1-ABCD-en-us-30GB.vhd"),
+                  "Standard"
+            )
+      );
+   }
+}

http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/80f5c8f7/azurecompute/src/test/resources/datavirtualharddisk.xml
----------------------------------------------------------------------
diff --git a/azurecompute/src/test/resources/datavirtualharddisk.xml b/azurecompute/src/test/resources/datavirtualharddisk.xml
new file mode 100644
index 0000000..c4bff06
--- /dev/null
+++ b/azurecompute/src/test/resources/datavirtualharddisk.xml
@@ -0,0 +1,18 @@
+<DataVirtualHardDisks xmlns="http://schemas.microsoft.com/windowsazure">
+    <DataVirtualHardDisk>
+        <HostCaching>ReadOnly</HostCaching>
+        <DiskName>testimage1-testimage1-0-20120817095145</DiskName>
+        <Lun>10</Lun>
+        <LogicalDiskSizeInGB>30</LogicalDiskSizeInGB>
+        <MediaLink>http://blobs/disks/neotysss/MSFT__Win2K8R2SP1-ABCD-en-us-30GB.vhd</MediaLink>
+        <IOType>Standard</IOType>
+    </DataVirtualHardDisk>
+    <DataVirtualHardDisk>
+        <HostCaching>ReadWrite</HostCaching>
+        <DiskName>testimage2-testimage2-0-20120817095145</DiskName>
+        <Lun>10</Lun>
+        <LogicalDiskSizeInGB>30</LogicalDiskSizeInGB>
+        <MediaLink>http://blobs/disks/neotysss/MSFT__Win2K8R2SP1-ABCD-en-us-30GB.vhd</MediaLink>
+        <IOType>Standard</IOType>
+    </DataVirtualHardDisk>
+</DataVirtualHardDisks>