Skip to content

Commit

Permalink
Merge pull request #3 from Azure/dev
Browse files Browse the repository at this point in the history
pull from dev to my fork branch
  • Loading branch information
xuezhai committed Jun 5, 2014
2 parents 48a5aba + 902c62b commit 9dd83bb
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,14 @@
package com.microsoft.windowsazure.management.compute;

import java.io.*;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.security.InvalidKeyException;
import java.util.ArrayList;
import java.util.Random;

import javax.xml.parsers.ParserConfigurationException;

import org.apache.http.impl.client.DefaultHttpRequestRetryHandler;
import org.junit.Assert;
import org.xml.sax.SAXException;

import com.microsoft.windowsazure.core.OperationResponse;
import com.microsoft.windowsazure.core.pipeline.apache.ApacheConfigurationProperties;
import com.microsoft.windowsazure.core.utils.KeyStoreType;
Expand All @@ -41,12 +36,8 @@
import com.microsoft.windowsazure.management.storage.StorageManagementService;
import com.microsoft.windowsazure.management.storage.models.StorageAccountCreateParameters;
import com.microsoft.windowsazure.management.storage.models.StorageAccountGetKeysResponse;
import com.microsoft.windowsazure.management.storage.models.StorageAccountGetResponse;
import com.microsoft.windowsazure.storage.CloudStorageAccount;
import com.microsoft.windowsazure.storage.StorageException;
import com.microsoft.windowsazure.storage.blob.CloudBlobClient;
import com.microsoft.windowsazure.storage.blob.CloudBlobContainer;
import com.microsoft.windowsazure.storage.blob.CloudPageBlob;
import com.microsoft.windowsazure.storage.blob.*;
import com.microsoft.windowsazure.*;

Expand Down Expand Up @@ -205,10 +196,11 @@ protected static void cleanBlob(String storageAccountName, String storageContain
try {
blobClient = createBlobClient(storageAccountName, storageAccountKey);
} catch (InvalidKeyException e) {
e.printStackTrace();
} catch (URISyntaxException e) {
e.printStackTrace();
}

// Retrieve reference to a previously created container
if (blobClient != null)
{
CloudBlobContainer container = null;
Expand All @@ -217,39 +209,43 @@ protected static void cleanBlob(String storageAccountName, String storageContain
} catch (URISyntaxException e) {
} catch (StorageException e) {
}

try {
container.breakLease(300);
container.breakLease(0);
} catch (StorageException e) {
}

try {
container.delete();
} catch (StorageException e) {
}

try {
while (container.exists())
{
Thread.sleep(1000);
}
} catch (StorageException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}

}
}

protected static void cleanStorageAccount(String storageAccountName) {
StorageAccountGetResponse storageAccountGetResponse = null;
OperationResponse operationResponse = null;
try {
storageAccountGetResponse = storageManagementClient.getStorageAccountsOperations().get(storageAccountName);
} catch (ServiceException e) {
operationResponse = storageManagementClient.getStorageAccountsOperations().delete(storageAccountName);
} catch (IOException e) {
} catch (ParserConfigurationException e) {
} catch (SAXException e) {
} catch (URISyntaxException e) {
e.printStackTrace();
} catch (ServiceException e) {
e.printStackTrace();
}

if ((storageAccountGetResponse != null) && (storageAccountGetResponse.getStorageAccount().getName().contains(storageAccountName))) {
OperationResponse operationResponse = null;
try {
operationResponse = storageManagementClient.getStorageAccountsOperations().delete(storageAccountName);
} catch (IOException e) {
} catch (ServiceException e) {
}
if (operationResponse != null) {
Assert.assertEquals(200, operationResponse.getStatusCode());
}

if (operationResponse != null) {
Assert.assertEquals(200, operationResponse.getStatusCode());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class VirtualMachineDiskOperationsTests extends ComputeManagementIntegrat
static int random = (int)(Math.random()* 100);
public static String virtualMachineDiskName = testVMPrefix + "Disk" + random;

static String storageAccountName = testStoragePrefix + randomString(10);
static String storageAccountName = testStoragePrefix + "vmd" +randomString(7);
static String storageContainer = "disk-store";

static String vhdfileName = "oneGBFixedWS2008R2.vhd";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class VirtualMachineOSImagesOperationsTests extends ComputeManagementInte
static int random = (int)(Math.random()* 100);
static String virtualMachineOSImageName = testVMPrefix + "OSImage" + random;

static String storageAccountName = testStoragePrefix + randomString(10);
static String storageAccountName = testStoragePrefix + "vmo" + randomString(7);
static String storageContainer = "image-store";

static String vhdfileName = "oneGBFixedWS2008R2.vhd";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.security.InvalidKeyException;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.concurrent.ExecutionException;
Expand All @@ -27,13 +26,10 @@
import javax.xml.transform.TransformerException;

import com.microsoft.windowsazure.core.OperationResponse;
import com.microsoft.windowsazure.core.OperationStatus;
import com.microsoft.windowsazure.core.OperationStatusResponse;
import com.microsoft.windowsazure.exception.ServiceException;
import com.microsoft.windowsazure.management.models.*;
import com.microsoft.windowsazure.management.compute.models.*;
import com.microsoft.windowsazure.management.storage.models.*;
import com.microsoft.windowsazure.storage.*;
import com.microsoft.windowsazure.storage.blob.*;

import org.junit.AfterClass;
import org.junit.Assert;
Expand All @@ -47,7 +43,6 @@ public class VirtualMachineOperationsTests extends ComputeManagementIntegrationT
//lower case only for storage account name, this is existed storage account with vhd-store container,
//need to create your own storage account and create container there to store VM images
private static String storageAccountName;
private static String storageAccountKey = "";
private static String storageContainer = "vhd-store";
private static String hostedServiceName;
private static String deploymentName = testVMPrefix + "deploy1";
Expand All @@ -60,7 +55,7 @@ public class VirtualMachineOperationsTests extends ComputeManagementIntegrationT

@BeforeClass
public static void setup() throws Exception {
storageAccountName = testStoragePrefix + randomString(10);
storageAccountName = testStoragePrefix + "vmo" + randomString(7);
hostedServiceName = testHostedServicePrefix + randomString(10);

//create storage service for storage account creation
Expand All @@ -81,9 +76,9 @@ public static void setup() throws Exception {
}

@AfterClass
public static void cleanup() {
cleanDeployment();
public static void cleanup() {
cleanHostedService();
cleanDeployment();
cleanBlob(storageAccountName, storageContainer);
cleanStorageAccount(storageAccountName);
}
Expand Down Expand Up @@ -418,7 +413,10 @@ private static void cleanHostedService() {
}
if (operationStatusResponse != null) {
Assert.assertEquals(200, operationStatusResponse.getStatusCode());
waitOperationToComplete(operationStatusResponse.getRequestId(), 20, 60);
}


}
}

Expand All @@ -445,6 +443,45 @@ private static void cleanDeployment() {
if (operationStatusResponse != null) {
Assert.assertEquals(200, operationStatusResponse.getStatusCode());
}
waitOperationToComplete(operationStatusResponse.getRequestId(), 20, 60);
}

try {
Thread.sleep(3*60*1000);
} catch (InterruptedException e) {
}
}

private static void waitOperationToComplete(String requestId, long waitTimeBetweenTriesInSeconds, int maximumNumberOfTries) {
boolean operationCompleted = false;
int tryCount =0;
while ((!operationCompleted)&&(tryCount<maximumNumberOfTries))
{
OperationStatusResponse operationStatus = null;
try {
operationStatus = computeManagementClient.getOperationStatus(requestId);
} catch (IOException e) {
e.printStackTrace();
} catch (ServiceException e) {
e.printStackTrace();
} catch (ParserConfigurationException e) {
e.printStackTrace();
} catch (SAXException e) {
e.printStackTrace();
}

if ((operationStatus.getStatus() == OperationStatus.Failed) || (operationStatus.getStatus() == OperationStatus.Succeeded))
{
operationCompleted = true;
}else{
try {
Thread.sleep(waitTimeBetweenTriesInSeconds * 1000);
tryCount ++;
} catch (InterruptedException e) {
e.printStackTrace();
}
}

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ public void listSubscriptionsSuccess() throws Exception {

Assert.assertEquals(200, subscriptionListOperationsResponse.getStatusCode());
Assert.assertNotNull(subscriptionListOperationsResponse.getRequestId());
Assert.assertEquals(50, subscriptionListOperationsResponse.getSubscriptionOperations().size());
}
}

0 comments on commit 9dd83bb

Please sign in to comment.