http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/9caaa469/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/features/DeploymentApi.java ---------------------------------------------------------------------- diff --git a/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/features/DeploymentApi.java b/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/features/DeploymentApi.java index 8d446a5..1ff43de 100644 --- a/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/features/DeploymentApi.java +++ b/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/features/DeploymentApi.java @@ -60,11 +60,11 @@ public interface DeploymentApi { */ @Named("deployment:create") @Path("/{deploymentname}") - @Payload("{properties}") + @Payload("{template}") @PUT @Produces(MediaType.APPLICATION_JSON) Deployment create(@PathParam("deploymentname") String deploymentname, - @PayloadParam("properties") String properties); + @PayloadParam("template") String template); /** * Get Deployment Information returns information about the specified deployment. @@ -80,11 +80,11 @@ public interface DeploymentApi { */ @Named("deployment:validate") @Path("/{deploymentname}/validate") - @Payload("{properties}") + @Payload("{template}") @POST @Produces(MediaType.APPLICATION_JSON) Deployment validate(@PathParam("deploymentname") String deploymentname, - @PayloadParam("properties") String properties); + @PayloadParam("template") String template); /** * List all deployments in a resource group
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/9caaa469/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/features/DiskApi.java ---------------------------------------------------------------------- diff --git a/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/features/DiskApi.java b/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/features/DiskApi.java index 0797dbd..10e9ac6 100644 --- a/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/features/DiskApi.java +++ b/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/features/DiskApi.java @@ -26,7 +26,6 @@ import javax.ws.rs.GET; import javax.ws.rs.PUT; import javax.ws.rs.Path; import javax.ws.rs.PathParam; -import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; import org.jclouds.Fallbacks.EmptyListOnNotFoundOr404; @@ -38,7 +37,6 @@ import org.jclouds.azurecompute.arm.functions.URIParser; import org.jclouds.oauth.v2.filters.OAuthFilter; import org.jclouds.rest.annotations.Fallback; import org.jclouds.rest.annotations.MapBinder; -import org.jclouds.rest.annotations.Payload; import org.jclouds.rest.annotations.PayloadParam; import org.jclouds.rest.annotations.RequestFilters; import org.jclouds.rest.annotations.ResponseParser; @@ -58,10 +56,8 @@ public interface DiskApi { @Named("disk:create_or_update") @PUT - @Payload("%7B\"location\":\"{location}\",\"properties\":{properties}%7D") @MapBinder(BindToJsonPayload.class) @Path("/{diskName}") - @Produces(MediaType.APPLICATION_JSON) Disk createOrUpdate(@PathParam("diskName") String diskName, @PayloadParam("location") String location, @PayloadParam("properties") DiskProperties properties); http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/9caaa469/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/features/ImageApi.java ---------------------------------------------------------------------- diff --git a/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/features/ImageApi.java b/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/features/ImageApi.java index c97b0ac..96caa40 100644 --- a/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/features/ImageApi.java +++ b/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/features/ImageApi.java @@ -26,7 +26,6 @@ import javax.ws.rs.GET; import javax.ws.rs.PUT; import javax.ws.rs.Path; import javax.ws.rs.PathParam; -import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; import org.jclouds.Fallbacks.EmptyListOnNotFoundOr404; @@ -38,7 +37,6 @@ import org.jclouds.azurecompute.arm.functions.URIParser; import org.jclouds.oauth.v2.filters.OAuthFilter; import org.jclouds.rest.annotations.Fallback; import org.jclouds.rest.annotations.MapBinder; -import org.jclouds.rest.annotations.Payload; import org.jclouds.rest.annotations.PayloadParam; import org.jclouds.rest.annotations.RequestFilters; import org.jclouds.rest.annotations.ResponseParser; @@ -58,10 +56,8 @@ public interface ImageApi { @Named("image:create_or_update") @PUT - @Payload("%7B\"location\":\"{location}\",\"properties\":{properties}%7D") @MapBinder(BindToJsonPayload.class) @Path("/{imageName}") - @Produces(MediaType.APPLICATION_JSON) Image createOrUpdate(@PathParam("imageName") String imageName, @PayloadParam("location") String location, @PayloadParam("properties") ImageProperties properties); http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/9caaa469/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/features/JobApi.java ---------------------------------------------------------------------- diff --git a/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/features/JobApi.java b/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/features/JobApi.java index 3c3bab9..5a01e90 100644 --- a/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/features/JobApi.java +++ b/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/features/JobApi.java @@ -40,7 +40,8 @@ import org.jclouds.rest.annotations.SelectJson; @RequestFilters(OAuthFilter.class) @Consumes(MediaType.APPLICATION_JSON) -public interface JobApi extends Closeable{ +public interface JobApi extends Closeable { + @GET @ResponseParser(ParseJobStatus.class) JobStatus jobStatus(@EndpointParam URI jobURI); http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/9caaa469/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/features/LoadBalancerApi.java ---------------------------------------------------------------------- diff --git a/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/features/LoadBalancerApi.java b/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/features/LoadBalancerApi.java index f0ea900..f9805c0 100644 --- a/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/features/LoadBalancerApi.java +++ b/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/features/LoadBalancerApi.java @@ -27,7 +27,6 @@ import javax.ws.rs.GET; import javax.ws.rs.PUT; import javax.ws.rs.Path; import javax.ws.rs.PathParam; -import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; import org.jclouds.Fallbacks.EmptyListOnNotFoundOr404; @@ -67,7 +66,6 @@ public interface LoadBalancerApi { @Path("/{loadbalancername}") @PUT @MapBinder(BindToJsonPayload.class) - @Produces(MediaType.APPLICATION_JSON) LoadBalancer createOrUpdate(@PathParam("loadbalancername") String lbName, @PayloadParam("location") String location, @Nullable @PayloadParam("tags") Map<String, String> tags, @PayloadParam("properties") LoadBalancerProperties properties); http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/9caaa469/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/features/NetworkSecurityGroupApi.java ---------------------------------------------------------------------- diff --git a/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/features/NetworkSecurityGroupApi.java b/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/features/NetworkSecurityGroupApi.java index ba4c2cd..41c0c85 100644 --- a/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/features/NetworkSecurityGroupApi.java +++ b/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/features/NetworkSecurityGroupApi.java @@ -27,7 +27,6 @@ import javax.ws.rs.GET; import javax.ws.rs.PUT; import javax.ws.rs.Path; import javax.ws.rs.PathParam; -import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; import org.jclouds.Fallbacks.EmptyListOnNotFoundOr404; @@ -68,7 +67,6 @@ public interface NetworkSecurityGroupApi { @Path("/{networksecuritygroupname}") @PUT @MapBinder(BindToJsonPayload.class) - @Produces(MediaType.APPLICATION_JSON) NetworkSecurityGroup createOrUpdate(@PathParam("networksecuritygroupname") String nsgName, @PayloadParam("location") String location, @Nullable @PayloadParam("tags") Map<String, String> tags, @PayloadParam("properties") NetworkSecurityGroupProperties properties); http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/9caaa469/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/features/NetworkSecurityRuleApi.java ---------------------------------------------------------------------- diff --git a/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/features/NetworkSecurityRuleApi.java b/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/features/NetworkSecurityRuleApi.java index 8def4e3..7404234 100644 --- a/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/features/NetworkSecurityRuleApi.java +++ b/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/features/NetworkSecurityRuleApi.java @@ -26,7 +26,6 @@ import javax.ws.rs.GET; import javax.ws.rs.PUT; import javax.ws.rs.Path; import javax.ws.rs.PathParam; -import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; import org.jclouds.Fallbacks.EmptyListOnNotFoundOr404; @@ -48,11 +47,11 @@ import org.jclouds.rest.binders.BindToJsonPayload; @RequestFilters({ OAuthFilter.class, ApiVersionFilter.class }) @Consumes(MediaType.APPLICATION_JSON) public interface NetworkSecurityRuleApi { + @Named("networksecurityrule:createOrUpdate") @Path("/securityRules/{networksecurityrulename}") @PUT @MapBinder(BindToJsonPayload.class) - @Produces(MediaType.APPLICATION_JSON) NetworkSecurityRule createOrUpdate(@PathParam("networksecurityrulename") String ruleName, @PayloadParam("properties") NetworkSecurityRuleProperties properties); http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/9caaa469/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/features/ResourceGroupApi.java ---------------------------------------------------------------------- diff --git a/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/features/ResourceGroupApi.java b/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/features/ResourceGroupApi.java index 2c6a8b3..7c51621 100644 --- a/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/features/ResourceGroupApi.java +++ b/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/features/ResourceGroupApi.java @@ -28,7 +28,6 @@ import javax.ws.rs.GET; import javax.ws.rs.PUT; import javax.ws.rs.Path; import javax.ws.rs.PathParam; -import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; import org.jclouds.Fallbacks.EmptyListOnNotFoundOr404; @@ -67,7 +66,6 @@ public interface ResourceGroupApi extends Closeable{ @Named("resourcegroup:create") @PUT @Path("/{name}") - @Produces(MediaType.APPLICATION_JSON) @MapBinder(BindToJsonPayload.class) ResourceGroup create(@PathParam("name") String name, @PayloadParam("location") String location, @Nullable @PayloadParam("tags") Map<String, String> tags); @@ -87,7 +85,6 @@ public interface ResourceGroupApi extends Closeable{ @Named("resourcegroup:update") @PATCH - @Produces(MediaType.APPLICATION_JSON) @Path("/{name}") @MapBinder(BindToJsonPayload.class) ResourceGroup update(@PathParam("name") String name, @Nullable @PayloadParam("tags") Map<String, String> tags); http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/9caaa469/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/features/ResourceProviderApi.java ---------------------------------------------------------------------- diff --git a/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/features/ResourceProviderApi.java b/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/features/ResourceProviderApi.java index a25e2a5..56dd0d4 100644 --- a/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/features/ResourceProviderApi.java +++ b/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/features/ResourceProviderApi.java @@ -16,7 +16,6 @@ */ package org.jclouds.azurecompute.arm.features; - import java.io.Closeable; import java.util.List; http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/9caaa469/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/features/StorageAccountApi.java ---------------------------------------------------------------------- diff --git a/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/features/StorageAccountApi.java b/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/features/StorageAccountApi.java index 5d2e06c..0c9399c 100644 --- a/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/features/StorageAccountApi.java +++ b/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/features/StorageAccountApi.java @@ -79,9 +79,7 @@ public interface StorageAccountApi { * PUT */ @Named("storageaccount:create") - @Payload("%7B\"location\":\"{location}\",\"tags\":{tags},\"properties\":{properties}%7D") @Path("/resourcegroups/{resourceGroup}/providers/Microsoft.Storage/storageAccounts/{storageAccountName}") - @Produces(MediaType.APPLICATION_JSON) @ResponseParser(URIParser.class) @MapBinder(BindToJsonPayload.class) @PUT @@ -120,7 +118,6 @@ public interface StorageAccountApi { @Named("storageaccountkey:get") @POST @Path("/resourcegroups/{resourceGroup}/providers/Microsoft.Storage/storageAccounts/{storageAccountName}/listKeys") - @Produces(MediaType.APPLICATION_JSON) @Fallback(Fallbacks.NullOnNotFoundOr404.class) StorageServiceKeys getKeys(@PathParam("storageAccountName") String storageAccountName); @@ -143,10 +140,8 @@ public interface StorageAccountApi { */ @Named("storageaccount:update") @PATCH - @Payload("%7B\"tags\":{tags},\"properties\":{properties}%7D") @MapBinder(BindToJsonPayload.class) @Path("/resourcegroups/{resourceGroup}/providers/Microsoft.Storage/storageAccounts/{storageAccountName}") - @Produces(MediaType.APPLICATION_JSON) StorageServiceUpdateParams update( @PathParam("storageAccountName") String storageAccountName, @Nullable @PayloadParam("tags") Map<String, String> tags, http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/9caaa469/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/features/VirtualMachineApi.java ---------------------------------------------------------------------- diff --git a/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/features/VirtualMachineApi.java b/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/features/VirtualMachineApi.java index c87390e..39ed860 100644 --- a/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/features/VirtualMachineApi.java +++ b/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/features/VirtualMachineApi.java @@ -77,11 +77,9 @@ public interface VirtualMachineApi { @Named("CreateOrUpdateVirtualMachine") @PUT - @Payload("%7B\"location\":\"{location}\",\"tags\":{tags},\"properties\":{properties},\"plan\":{plan}%7D") @MapBinder(BindToJsonPayload.class) @Path("/{vmname}") @QueryParams(keys = "validating", values = "false") - @Produces(MediaType.APPLICATION_JSON) VirtualMachine createOrUpdate(@PathParam("vmname") String vmname, @PayloadParam("location") String location, @PayloadParam("properties") VirtualMachineProperties properties, @@ -130,10 +128,10 @@ public interface VirtualMachineApi { @Named("capture") @POST @Payload("%7B\"vhdPrefix\":\"{vhdPrefix}\",\"destinationContainerName\":\"{destinationContainerName}\",\"overwriteVhds\":\"true\"%7D") - @MapBinder(BindToJsonPayload.class) @Path("/{name}/capture") @ResponseParser(URIParser.class) @Fallback(Fallbacks.NullOnNotFoundOr404.class) + @Produces(MediaType.APPLICATION_JSON) URI capture(@PathParam("name") String name, @PayloadParam("vhdPrefix") String vhdPrefix, @PayloadParam("destinationContainerName") String destinationContainerName); http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/9caaa469/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/functions/StorageProfileToStorageAccountName.java ---------------------------------------------------------------------- diff --git a/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/functions/StorageProfileToStorageAccountName.java b/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/functions/StorageProfileToStorageAccountName.java deleted file mode 100644 index f624886..0000000 --- a/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/functions/StorageProfileToStorageAccountName.java +++ /dev/null @@ -1,38 +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.arm.functions; - -import java.net.URI; - -import org.jclouds.azurecompute.arm.domain.StorageProfile; - -import com.google.common.base.Function; -import com.google.common.base.Splitter; -import com.google.common.collect.Iterables; - -/** - * Returns the storage account name for a given storage profile. - */ -public class StorageProfileToStorageAccountName implements Function<StorageProfile, String> { - - @Override - public String apply(StorageProfile input) { - String storageAccountNameURI = input.osDisk().vhd().uri(); - return Iterables.get(Splitter.on(".").split(URI.create(storageAccountNameURI).getHost()), 0); - } - -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/9caaa469/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/util/BlobHelper.java ---------------------------------------------------------------------- diff --git a/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/util/BlobHelper.java b/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/util/BlobHelper.java deleted file mode 100644 index b42ea5e..0000000 --- a/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/util/BlobHelper.java +++ /dev/null @@ -1,83 +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.arm.util; - -import static org.jclouds.util.Closeables2.closeQuietly; - -import java.io.Closeable; -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; - -import org.jclouds.ContextBuilder; -import org.jclouds.azureblob.AzureBlobClient; -import org.jclouds.azureblob.domain.BlobProperties; -import org.jclouds.azureblob.domain.ContainerProperties; -import org.jclouds.azureblob.domain.ListBlobsResponse; -import org.jclouds.azurecompute.arm.domain.VMImage; - -public class BlobHelper implements Closeable { - - private final String storageAccount; - private final AzureBlobClient azureBlob; - - public BlobHelper(String storageAccount, String key) { - this.storageAccount = storageAccount; - this.azureBlob = ContextBuilder.newBuilder("azureblob").credentials(storageAccount, key) - .buildApi(AzureBlobClient.class); - } - - @Override - public void close() throws IOException { - closeQuietly(azureBlob); - } - - public void deleteContainerIfExists(String containerName) { - azureBlob.deleteContainer(containerName); - } - - public boolean hasContainers() { - return !azureBlob.listContainers().isEmpty(); - } - - public boolean customImageExists() { - return azureBlob.containerExists("system"); - } - - public List<VMImage> getImages(String containerName, String group, String offer, String location) { - List<VMImage> list = new ArrayList<VMImage>(); - - ContainerProperties systemContainer = azureBlob.getContainerProperties("system"); - if (systemContainer != null) { - ListBlobsResponse blobList = azureBlob.listBlobs(systemContainer.getName()); - for (BlobProperties blob : blobList) { - String name = blob.getName(); - - if (name.contains("-osDisk")) { - String imageName = name.substring(name.lastIndexOf('/') + 1, name.indexOf("-osDisk")); - String imageUrl = blob.getUrl().toString(); - - list.add(VMImage.customImage().group(group).storage(storageAccount).vhd1(imageUrl).name(imageName) - .offer(offer).location(location).build()); - } - } - } - - return list; - } - -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/9caaa469/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/util/VMImages.java ---------------------------------------------------------------------- diff --git a/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/util/VMImages.java b/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/util/VMImages.java index d5b6394..a5944ec 100644 --- a/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/util/VMImages.java +++ b/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/util/VMImages.java @@ -21,7 +21,7 @@ import static com.google.common.base.Preconditions.checkNotNull; public class VMImages { public static boolean isCustom(String imageId) { - return checkNotNull(imageId, "id").split("/").length == 5; + return checkNotNull(imageId, "id").split("/").length == 2; } } http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/9caaa469/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/compute/AzureComputeServiceLiveTest.java ---------------------------------------------------------------------- diff --git a/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/compute/AzureComputeServiceLiveTest.java b/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/compute/AzureComputeServiceLiveTest.java index 9c2427c..7c5c97f 100644 --- a/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/compute/AzureComputeServiceLiveTest.java +++ b/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/compute/AzureComputeServiceLiveTest.java @@ -16,8 +16,11 @@ */ package org.jclouds.azurecompute.arm.compute; +import static org.jclouds.azurecompute.arm.config.AzureComputeProperties.TIMEOUT_RESOURCE_DELETED; import static org.jclouds.compute.options.TemplateOptions.Builder.authorizePublicKey; +import static org.testng.Assert.assertTrue; +import java.net.URI; import java.util.Properties; import org.jclouds.azurecompute.arm.AzureComputeApi; @@ -38,10 +41,12 @@ import org.jclouds.sshj.config.SshjSshClientModule; import org.testng.annotations.AfterClass; import org.testng.annotations.Test; +import com.google.common.base.Predicate; import com.google.common.cache.LoadingCache; import com.google.inject.Key; import com.google.inject.Module; import com.google.inject.TypeLiteral; +import com.google.inject.name.Names; /** * Live tests for the {@link org.jclouds.compute.ComputeService} integration. @@ -50,6 +55,7 @@ import com.google.inject.TypeLiteral; public class AzureComputeServiceLiveTest extends BaseComputeServiceLiveTest { private LoadingCache<String, ResourceGroup> resourceGroupMap; + private Predicate<URI> resourceDeleted; public AzureComputeServiceLiveTest() { provider = "azurecompute-arm"; @@ -61,6 +67,8 @@ public class AzureComputeServiceLiveTest extends BaseComputeServiceLiveTest { resourceGroupMap = context.utils().injector() .getInstance(Key.get(new TypeLiteral<LoadingCache<String, ResourceGroup>>() { })); + resourceDeleted = context.utils().injector().getInstance(Key.get(new TypeLiteral<Predicate<URI>>() { + }, Names.named(TIMEOUT_RESOURCE_DELETED))); } @Override @@ -71,7 +79,11 @@ public class AzureComputeServiceLiveTest extends BaseComputeServiceLiveTest { ResourceGroup rg = resourceGroupMap.getIfPresent(template.getLocation().getId()); if (rg != null) { AzureComputeApi api = view.unwrapApi(AzureComputeApi.class); - api.getResourceGroupApi().delete(rg.name()); + URI uri = api.getResourceGroupApi().delete(rg.name()); + if (uri != null) { + assertTrue(resourceDeleted.apply(uri), + String.format("Resource %s was not terminated in the configured timeout", uri)); + } } } } finally { @@ -97,7 +109,7 @@ public class AzureComputeServiceLiveTest extends BaseComputeServiceLiveTest { @Override protected Properties setupProperties() { Properties properties = super.setupProperties(); - AzureLiveTestUtils.defaultProperties(properties); + AzureLiveTestUtils.defaultProperties(properties, getClass().getSimpleName().toLowerCase()); setIfTestSystemPropertyPresent(properties, "oauth.endpoint"); return properties; } http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/9caaa469/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/compute/AzureTemplateBuilderLiveTest.java ---------------------------------------------------------------------- diff --git a/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/compute/AzureTemplateBuilderLiveTest.java b/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/compute/AzureTemplateBuilderLiveTest.java index 56200c4..d4cbdb0 100644 --- a/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/compute/AzureTemplateBuilderLiveTest.java +++ b/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/compute/AzureTemplateBuilderLiveTest.java @@ -56,7 +56,7 @@ public class AzureTemplateBuilderLiveTest extends BaseTemplateBuilderLiveTest { @Override protected Properties setupProperties() { Properties properties = super.setupProperties(); - AzureLiveTestUtils.defaultProperties(properties); + AzureLiveTestUtils.defaultProperties(properties, getClass().getSimpleName().toLowerCase()); setIfTestSystemPropertyPresent(properties, "oauth.endpoint"); return properties; } @@ -65,8 +65,8 @@ public class AzureTemplateBuilderLiveTest extends BaseTemplateBuilderLiveTest { @Test public void testDefaultTemplateBuilder() throws IOException { Template defaultTemplate = view.getComputeService().templateBuilder().build(); - assertTrue(defaultTemplate.getImage().getOperatingSystem().getVersion().matches("1[45]\\.[01][04]\\.[0-9]-LTS"), - "Version mismatch, expected dd.dd.d-LTS, found: " + assertTrue(defaultTemplate.getImage().getOperatingSystem().getVersion().matches("1[456]\\.[01][04](\\.[0-9])?-LTS"), + "Version mismatch, expected dd.dd(.d)?-LTS, found: " + defaultTemplate.getImage().getOperatingSystem().getVersion()); assertEquals(defaultTemplate.getImage().getOperatingSystem().is64Bit(), true); assertEquals(defaultTemplate.getImage().getOperatingSystem().getFamily(), OsFamily.UBUNTU); http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/9caaa469/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/compute/extensions/AzureComputeImageExtensionLiveTest.java ---------------------------------------------------------------------- diff --git a/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/compute/extensions/AzureComputeImageExtensionLiveTest.java b/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/compute/extensions/AzureComputeImageExtensionLiveTest.java index a6d19fa..d708723 100644 --- a/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/compute/extensions/AzureComputeImageExtensionLiveTest.java +++ b/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/compute/extensions/AzureComputeImageExtensionLiveTest.java @@ -17,7 +17,12 @@ package org.jclouds.azurecompute.arm.compute.extensions; import static org.jclouds.compute.options.TemplateOptions.Builder.authorizePublicKey; +import static org.jclouds.azurecompute.arm.config.AzureComputeProperties.TIMEOUT_RESOURCE_DELETED; +import static org.jclouds.compute.options.RunScriptOptions.Builder.wrapInInitScript; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertTrue; +import java.net.URI; import java.util.Map; import java.util.Properties; @@ -26,18 +31,23 @@ import org.jclouds.azurecompute.arm.AzureComputeProviderMetadata; import org.jclouds.azurecompute.arm.domain.ResourceGroup; import org.jclouds.azurecompute.arm.internal.AzureLiveTestUtils; import org.jclouds.compute.ComputeTestUtils; +import org.jclouds.compute.domain.ExecResponse; +import org.jclouds.compute.domain.NodeMetadata; import org.jclouds.compute.domain.TemplateBuilder; import org.jclouds.compute.extensions.internal.BaseImageExtensionLiveTest; import org.jclouds.domain.Location; import org.jclouds.providers.ProviderMetadata; import org.jclouds.sshj.config.SshjSshClientModule; import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; +import com.google.common.base.Predicate; import com.google.common.cache.LoadingCache; import com.google.inject.Key; import com.google.inject.Module; import com.google.inject.TypeLiteral; +import com.google.inject.name.Names; /** * Live tests for the {@link org.jclouds.compute.extensions.ImageExtension} @@ -45,32 +55,34 @@ import com.google.inject.TypeLiteral; */ @Test(groups = "live", singleThreaded = true, testName = "AzureComputeImageExtensionLiveTest") public class AzureComputeImageExtensionLiveTest extends BaseImageExtensionLiveTest { - - public static final String NAME_PREFIX = "%s"; - - private LoadingCache<String, ResourceGroup> resourceGroupMap; + private LoadingCache<String, ResourceGroup> resourceGroupMap; + private Predicate<URI> resourceDeleted; + private ResourceGroup testResourceGroup; + public AzureComputeImageExtensionLiveTest() { provider = "azurecompute-arm"; } - - @Override - public void initializeContext() { - super.initializeContext(); + + @BeforeClass(groups = { "integration", "live" }) + public void setupContext() { + super.setupContext(); resourceGroupMap = context.utils().injector() .getInstance(Key.get(new TypeLiteral<LoadingCache<String, ResourceGroup>>() { })); + resourceDeleted = context.utils().injector().getInstance(Key.get(new TypeLiteral<Predicate<URI>>() { + }, Names.named(TIMEOUT_RESOURCE_DELETED))); + createResourceGroup(); } - + + @AfterClass(groups = { "integration", "live" }) @Override - @AfterClass(groups = "live", alwaysRun = true) protected void tearDownContext() { try { - Location location = getNodeTemplate().build().getLocation(); - ResourceGroup rg = resourceGroupMap.getIfPresent(location.getId()); - if (rg != null) { - AzureComputeApi api = view.unwrapApi(AzureComputeApi.class); - api.getResourceGroupApi().delete(rg.name()); + URI uri = view.unwrapApi(AzureComputeApi.class).getResourceGroupApi().delete(testResourceGroup.name()); + if (uri != null) { + assertTrue(resourceDeleted.apply(uri), + String.format("Resource %s was not terminated in the configured timeout", uri)); } } finally { super.tearDownContext(); @@ -78,6 +90,17 @@ public class AzureComputeImageExtensionLiveTest extends BaseImageExtensionLiveTe } @Override + protected void prepareNodeBeforeCreatingImage(NodeMetadata node) { + // Don't wrap in the init-script, since the comand will clear the user + // config, and jclouds won't be able to execute more than one command + // (won't be able to poll for the execution status of the command when + // running with the init-script) + ExecResponse result = view.getComputeService().runScriptOnNode(node.getId(), "waagent -deprovision+user -force", + wrapInInitScript(false)); + assertEquals(result.getExitStatus(), 0); + } + + @Override protected Module getSshModule() { return new SshjSshClientModule(); } @@ -85,7 +108,7 @@ public class AzureComputeImageExtensionLiveTest extends BaseImageExtensionLiveTe @Override protected Properties setupProperties() { Properties properties = super.setupProperties(); - AzureLiveTestUtils.defaultProperties(properties); + AzureLiveTestUtils.defaultProperties(properties, getClass().getSimpleName().toLowerCase()); setIfTestSystemPropertyPresent(properties, "oauth.endpoint"); return properties; } @@ -99,9 +122,11 @@ public class AzureComputeImageExtensionLiveTest extends BaseImageExtensionLiveTe public TemplateBuilder getNodeTemplate() { Map<String, String> keyPair = ComputeTestUtils.setupKeyPair(); return super.getNodeTemplate().options( - authorizePublicKey(keyPair.get("public")) - .overrideLoginPrivateKey(keyPair.get("private"))); + authorizePublicKey(keyPair.get("public")).overrideLoginPrivateKey(keyPair.get("private"))); } - + private void createResourceGroup() { + Location location = getNodeTemplate().build().getLocation(); + testResourceGroup = resourceGroupMap.getUnchecked(location.getId()); + } } http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/9caaa469/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/compute/extensions/AzureComputeSecurityGroupExtensionLiveTest.java ---------------------------------------------------------------------- diff --git a/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/compute/extensions/AzureComputeSecurityGroupExtensionLiveTest.java b/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/compute/extensions/AzureComputeSecurityGroupExtensionLiveTest.java index 9296d69..e00880b 100644 --- a/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/compute/extensions/AzureComputeSecurityGroupExtensionLiveTest.java +++ b/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/compute/extensions/AzureComputeSecurityGroupExtensionLiveTest.java @@ -18,6 +18,7 @@ package org.jclouds.azurecompute.arm.compute.extensions; import static com.google.common.collect.Iterables.get; import static com.google.common.collect.Iterables.getOnlyElement; +import static org.jclouds.azurecompute.arm.config.AzureComputeProperties.TIMEOUT_RESOURCE_DELETED; import static org.jclouds.compute.options.TemplateOptions.Builder.inboundPorts; import static org.jclouds.compute.options.TemplateOptions.Builder.securityGroups; import static org.jclouds.compute.predicates.NodePredicates.inGroup; @@ -26,6 +27,7 @@ import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertNotNull; import static org.testng.Assert.assertTrue; +import java.net.URI; import java.util.Properties; import java.util.Set; import java.util.concurrent.ExecutionException; @@ -49,9 +51,11 @@ import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import com.google.common.base.Optional; +import com.google.common.base.Predicate; import com.google.common.cache.LoadingCache; import com.google.inject.Key; import com.google.inject.TypeLiteral; +import com.google.inject.name.Names; /** * Live test for AzureCompute @@ -61,6 +65,7 @@ import com.google.inject.TypeLiteral; public class AzureComputeSecurityGroupExtensionLiveTest extends BaseSecurityGroupExtensionLiveTest { private LoadingCache<String, ResourceGroup> resourceGroupMap; + private Predicate<URI> resourceDeleted; private ResourceGroup testResourceGroup; public AzureComputeSecurityGroupExtensionLiveTest() { @@ -73,6 +78,8 @@ public class AzureComputeSecurityGroupExtensionLiveTest extends BaseSecurityGrou resourceGroupMap = context.utils().injector() .getInstance(Key.get(new TypeLiteral<LoadingCache<String, ResourceGroup>>() { })); + resourceDeleted = context.utils().injector().getInstance(Key.get(new TypeLiteral<Predicate<URI>>() { + }, Names.named(TIMEOUT_RESOURCE_DELETED))); createResourceGroup(); } @@ -134,7 +141,11 @@ public class AzureComputeSecurityGroupExtensionLiveTest extends BaseSecurityGrou @Override protected void tearDownContext() { try { - view.unwrapApi(AzureComputeApi.class).getResourceGroupApi().delete(testResourceGroup.name()); + URI uri = view.unwrapApi(AzureComputeApi.class).getResourceGroupApi().delete(testResourceGroup.name()); + if (uri != null) { + assertTrue(resourceDeleted.apply(uri), + String.format("Resource %s was not terminated in the configured timeout", uri)); + } } finally { super.tearDownContext(); } @@ -143,7 +154,7 @@ public class AzureComputeSecurityGroupExtensionLiveTest extends BaseSecurityGrou @Override protected Properties setupProperties() { Properties properties = super.setupProperties(); - AzureLiveTestUtils.defaultProperties(properties); + AzureLiveTestUtils.defaultProperties(properties, "sgelivetest"); setIfTestSystemPropertyPresent(properties, "oauth.endpoint"); return properties; } http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/9caaa469/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/AvailabilitySetApiLiveTest.java ---------------------------------------------------------------------- diff --git a/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/AvailabilitySetApiLiveTest.java b/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/AvailabilitySetApiLiveTest.java index 6e9e1e7..2b9e30a 100644 --- a/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/AvailabilitySetApiLiveTest.java +++ b/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/AvailabilitySetApiLiveTest.java @@ -17,6 +17,7 @@ package org.jclouds.azurecompute.arm.features; import static com.google.common.collect.Iterables.any; +import static org.jclouds.azurecompute.arm.domain.AvailabilitySet.AvailabilitySetType.MANAGED; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertNotNull; import static org.testng.Assert.assertNull; @@ -27,6 +28,7 @@ import java.util.UUID; import org.jclouds.azurecompute.arm.domain.AvailabilitySet; import org.jclouds.azurecompute.arm.domain.AvailabilitySet.AvailabilitySetProperties; +import org.jclouds.azurecompute.arm.domain.AvailabilitySet.SKU; import org.jclouds.azurecompute.arm.internal.BaseAzureComputeApiLiveTest; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; @@ -56,10 +58,13 @@ public class AvailabilitySetApiLiveTest extends BaseAzureComputeApiLiveTest { public void createAvailabilitySet() { AvailabilitySetProperties props = AvailabilitySetProperties.builder().platformUpdateDomainCount(2) .platformFaultDomainCount(3).build(); - AvailabilitySet as = api().createOrUpdate(asName, LOCATION, null, props); + AvailabilitySet as = api().createOrUpdate(asName, SKU.create(MANAGED), LOCATION, null, props); assertNotNull(as); assertEquals(as.name(), asName); + + assertNotNull(as.sku()); + assertEquals(as.sku().type(), MANAGED); } @Test(dependsOnMethods = "createAvailabilitySet") @@ -80,7 +85,7 @@ public class AvailabilitySetApiLiveTest extends BaseAzureComputeApiLiveTest { @Test(dependsOnMethods = "createAvailabilitySet") public void updateAvailabilitySet() { AvailabilitySet as = api().get(asName); - as = api().createOrUpdate(asName, LOCATION, ImmutableMap.of("foo", "bar"), as.properties()); + as = api().createOrUpdate(asName, SKU.create(MANAGED), LOCATION, ImmutableMap.of("foo", "bar"), as.properties()); assertNotNull(as); assertTrue(as.tags().containsKey("foo")); http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/9caaa469/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/AvailabilitySetApiMockTest.java ---------------------------------------------------------------------- diff --git a/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/AvailabilitySetApiMockTest.java b/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/AvailabilitySetApiMockTest.java index db9a7ed..430c32f 100644 --- a/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/AvailabilitySetApiMockTest.java +++ b/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/AvailabilitySetApiMockTest.java @@ -17,6 +17,7 @@ package org.jclouds.azurecompute.arm.features; import static com.google.common.collect.Iterables.isEmpty; +import static org.jclouds.azurecompute.arm.domain.AvailabilitySet.AvailabilitySetType.MANAGED; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertNotNull; import static org.testng.Assert.assertNull; @@ -27,6 +28,7 @@ import java.util.List; import org.jclouds.azurecompute.arm.domain.AvailabilitySet; import org.jclouds.azurecompute.arm.domain.AvailabilitySet.AvailabilitySetProperties; +import org.jclouds.azurecompute.arm.domain.AvailabilitySet.SKU; import org.jclouds.azurecompute.arm.internal.BaseAzureComputeApiMockTest; import org.testng.annotations.Test; @@ -36,7 +38,7 @@ public class AvailabilitySetApiMockTest extends BaseAzureComputeApiMockTest { private final String subscriptionid = "SUBSCRIPTIONID"; private final String resourcegroup = "myresourcegroup"; private final String asName = "myas"; - private final String apiVersion = "api-version=2016-03-30"; + private final String apiVersion = "api-version=2016-04-30-preview"; public void createAvailabilitySet() throws InterruptedException { @@ -46,12 +48,12 @@ public class AvailabilitySetApiMockTest extends BaseAzureComputeApiMockTest { AvailabilitySetProperties props = AvailabilitySetProperties.builder().platformUpdateDomainCount(2) .platformFaultDomainCount(3).build(); - AvailabilitySet as = asApi.createOrUpdate(asName, "westeurope", null, props); + AvailabilitySet as = asApi.createOrUpdate(asName, SKU.create(MANAGED), "westeurope", null, props); String path = String.format( "/subscriptions/%s/resourcegroups/%s/providers/Microsoft.Compute/availabilitySets/%s?%s", subscriptionid, resourcegroup, asName, apiVersion); - String json = "{\"location\":\"westeurope\",\"properties\":{\"platformUpdateDomainCount\":2,\"platformFaultDomainCount\":3}}"; + String json = "{\"location\":\"westeurope\",\"properties\":{\"platformUpdateDomainCount\":2,\"platformFaultDomainCount\":3},\"sku\":{\"name\":\"Aligned\"}}"; assertSent(server, "PUT", path, json); assertEquals(as.name(), asName); http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/9caaa469/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/DeploymentApiLiveTest.java ---------------------------------------------------------------------- diff --git a/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/DeploymentApiLiveTest.java b/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/DeploymentApiLiveTest.java index b485dc2..0b9ab05 100644 --- a/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/DeploymentApiLiveTest.java +++ b/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/DeploymentApiLiveTest.java @@ -23,11 +23,8 @@ import static org.testng.Assert.assertTrue; import java.net.URI; import java.util.List; -import org.jclouds.azurecompute.arm.compute.options.AzureTemplateOptions; import org.jclouds.azurecompute.arm.domain.Deployment; import org.jclouds.azurecompute.arm.domain.Deployment.ProvisioningState; -import org.jclouds.azurecompute.arm.domain.Subnet; -import org.jclouds.azurecompute.arm.domain.VirtualNetwork; import org.jclouds.azurecompute.arm.internal.BaseAzureComputeApiLiveTest; import org.jclouds.util.Predicates2; import org.testng.Assert; @@ -37,12 +34,10 @@ import org.testng.annotations.Test; import com.google.common.base.Predicate; import com.google.common.net.UrlEscapers; -@Test(testName = "DeploymentApiLiveTest", singleThreaded = true) +@Test(groups = "live", testName = "DeploymentApiLiveTest", singleThreaded = true) public class DeploymentApiLiveTest extends BaseAzureComputeApiLiveTest { private String deploymentName; - private String subnetId; - private String properties; private String badProperties; @@ -52,7 +47,6 @@ public class DeploymentApiLiveTest extends BaseAzureComputeApiLiveTest { super.setup(); createTestResourceGroup(); deploymentName = "jc" + System.currentTimeMillis(); - String virtualNetworkName = String.format("vn-%s-%s", this.getClass().getSimpleName().toLowerCase(), System.getProperty("user.name")); String storageAccountName = String.format("st%s%s", System.getProperty("user.name"), RAND); String rawtemplate = "{\"$schema\":\"https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#\",\"contentVersion\":\"1.0.0.0\",\"parameters\":{\"newStorageAccountName\":{\"type\":\"string\",\"metadata\":{\"description\":\"Name of the Storage Account\"}},\"storageAccountType\":{\"type\":\"string\",\"defaultValue\":\"Standard_LRS\",\"allowedValues\":[\"Standard_LRS\",\"Standard_GRS\",\"Standard_ZRS\"],\"metadata\":{\"description\":\"Storage Account type\"}},\"location\":{\"type\":\"string\",\"allowedValues\":[\"East US\",\"West US\",\"West Europe\",\"East Asia\",\"Southeast Asia\"],\"metadata\":{\"description\":\"Location of storage account\"}}},\"resources\":[{\"type\":\"Microsoft.Storage/storageAccounts\",\"name\":\"[parameters('newStorageAccountName')]\",\"apiVersion\":\"2015-05-01-preview\",\"location\":\"[parameters('location')]\",\"properties\":{\"accountType\":\"[parameters('storageAccountType')]\"}}]}"; @@ -61,17 +55,6 @@ public class DeploymentApiLiveTest extends BaseAzureComputeApiLiveTest { properties = getPutBody(rawtemplate, "Incremental", rawparameters); badProperties = getPutBody(rawtemplate, "Incremental", rawbadParameters); - - //Subnets belong to a virtual network so that needs to be created first - VirtualNetwork vn = createDefaultVirtualNetwork(resourceGroupName, virtualNetworkName, "10.3.0.0/16", LOCATION); - assertNotNull(vn); - - //Subnet needs to be up & running before NIC can be created - String subnetName = String.format("s-%s-%s", this.getClass().getSimpleName().toLowerCase(), System.getProperty("user.name")); - Subnet subnet = createDefaultSubnet(resourceGroupName, subnetName, virtualNetworkName, "10.3.0.0/23"); - assertNotNull(subnet); - assertNotNull(subnet.id()); - subnetId = subnet.id(); } private String getPutBody(String template, String mode, String parameters) { @@ -104,48 +87,10 @@ public class DeploymentApiLiveTest extends BaseAzureComputeApiLiveTest { } assertNotNull(deploymentValid); } - @Test + + @Test(dependsOnMethods = "testValidate") public void testCreate() { - String rsakey = new String("ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAQEAmfk/QSF0pvnrpdz+Ah2KulGruKU+8FFBdlw938MpOysRdmp7uwpH6Z7+5VNGNdxFIAyc/W3UaZXF9hTsU8+78TlwkZpsr2mzU+ycu37XLAQ8Uv7hjsAN0DkKKPrZ9lgUUfZVKV/8E/JIAs03gIbL6zO3y7eYJQ5fNeZb+nji7tQT+YLpGq/FDegvraPKVMQbCSCZhsHyWhdPLyFlu9/30npZ0ahYOPI/KyZxFDtM/pHp88+ZAk9Icq5owaLRWcJQqrBGWqjbZnHtjdDqvHZ+C0wPhdJZPyfkHOrSYTwSQBXfX4JLRRCz3J1jf62MbQWT1o6Y4JEs1ZP1Skxu6zR96Q== mocktest"); - - AzureTemplateOptions options = new AzureTemplateOptions(); - options.authorizePublicKey(rsakey); - options.subnetId(subnetId); - - String deploymentTemplate = "{\n" + - " \"id\": \"/subscriptions/04f7ec88-8e28-41ed-8537-5e17766001f5/resourceGroups/jims216group/providers/Microsoft.Resources/deployments/jcdep1458344383064\",\n" + - " \"name\": \"jcdep1458344383064\",\n" + - " \"properties\": {\n" + - " \"parameters\": {\n" + - " \"newStorageAccountName\": {\n" + - " \"type\": \"String\",\n" + - " \"value\": \"jcres1458344383064\"\n" + - " },\n" + - " \"storageAccountType\": {\n" + - " \"type\": \"String\",\n" + - " \"value\": \"Standard_LRS\"\n" + - " },\n" + - " \"location\": {\n" + - " \"type\": \"String\",\n" + - " \"value\": \"West US\"\n" + - " }\n" + - " },\n" + - " \"mode\": \"Incremental\",\n" + - " \"provisioningState\": \"Accepted\",\n" + - " \"timestamp\": \"2016-03-18T23:39:47.3048037Z\",\n" + - " \"duration\": \"PT2.4433028S\",\n" + - " \"correlationId\": \"8dee9711-8632-4948-9fe6-368bb75e6438\",\n" + - " \"providers\": [{\n" + - " \"namespace\": \"Microsoft.Storage\",\n" + - " \"resourceTypes\": [{\n" + - " \"resourceType\": \"storageAccounts\",\n" + - " \"locations\": [\"westus\"]\n" + - " }]\n" + - " }],\n" + - " \"dependencies\": []\n" + - " }\n" + - "}"; - deploymentTemplate = UrlEscapers.urlFormParameterEscaper().escape(deploymentTemplate); + String deploymentTemplate = UrlEscapers.urlFormParameterEscaper().escape(properties); Deployment deploymentValid = api().validate(deploymentName, deploymentTemplate); assertNotNull(deploymentValid); http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/9caaa469/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/DiskApiLiveTest.java ---------------------------------------------------------------------- diff --git a/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/DiskApiLiveTest.java b/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/DiskApiLiveTest.java index becfccd..f5af885 100644 --- a/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/DiskApiLiveTest.java +++ b/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/DiskApiLiveTest.java @@ -36,10 +36,10 @@ import static org.testng.Assert.assertNotNull; import static org.testng.Assert.assertNull; import static org.testng.Assert.assertTrue; -@Test(groups = "live", singleThreaded = true) +@Test(groups = "live", testName = "DiskApiLiveTest", singleThreaded = true) public class DiskApiLiveTest extends BaseAzureComputeApiLiveTest { - public static final String JCLOUDS_IMAGE_PREFIX = "jclouds-"; + public static final String JCLOUDS_DISK_PREFIX = "jclouds-"; private String diskName; @BeforeClass @@ -47,12 +47,12 @@ public class DiskApiLiveTest extends BaseAzureComputeApiLiveTest { public void setup() { super.setup(); createTestResourceGroup(); - diskName = JCLOUDS_IMAGE_PREFIX + RAND; + diskName = JCLOUDS_DISK_PREFIX + RAND; } @Test public void deleteDiskResourceDoesNotExist() { - assertNull(api().delete(JCLOUDS_IMAGE_PREFIX + UUID.randomUUID())); + assertNull(api().delete(JCLOUDS_DISK_PREFIX + UUID.randomUUID())); } @Test http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/9caaa469/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/ImageApiLiveTest.java ---------------------------------------------------------------------- diff --git a/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/ImageApiLiveTest.java b/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/ImageApiLiveTest.java index 038fc31..d976258 100644 --- a/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/ImageApiLiveTest.java +++ b/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/ImageApiLiveTest.java @@ -16,90 +16,154 @@ */ package org.jclouds.azurecompute.arm.features; +import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.collect.Iterables.any; +import static com.google.common.collect.Iterables.getOnlyElement; +import static org.jclouds.azurecompute.arm.config.AzureComputeProperties.TIMEOUT_RESOURCE_DELETED; +import static org.jclouds.compute.predicates.NodePredicates.inGroup; +import static org.testng.Assert.assertNotNull; +import static org.testng.Assert.assertNull; +import static org.testng.Assert.assertTrue; + import java.net.URI; -import java.util.Collections; -import java.util.List; -import java.util.UUID; +import java.util.Properties; +import org.jclouds.azurecompute.arm.AzureComputeApi; +import org.jclouds.azurecompute.arm.domain.IdReference; import org.jclouds.azurecompute.arm.domain.Image; import org.jclouds.azurecompute.arm.domain.ImageProperties; -import org.jclouds.azurecompute.arm.domain.Provisionable; -import org.jclouds.azurecompute.arm.domain.VirtualMachine; -import org.jclouds.azurecompute.arm.domain.VirtualMachineProperties; -import org.jclouds.azurecompute.arm.internal.BaseAzureComputeApiLiveTest; +import org.jclouds.azurecompute.arm.domain.ResourceGroup; +import org.jclouds.azurecompute.arm.internal.AzureLiveTestUtils; +import org.jclouds.compute.RunNodesException; +import org.jclouds.compute.domain.NodeMetadata; +import org.jclouds.compute.internal.BaseComputeServiceContextLiveTest; +import org.jclouds.domain.Location; +import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; -import com.google.common.base.Supplier; +import com.google.common.base.Predicate; +import com.google.common.cache.LoadingCache; +import com.google.inject.Key; +import com.google.inject.TypeLiteral; +import com.google.inject.name.Names; -import static org.testng.Assert.assertNotNull; -import static org.testng.Assert.assertNull; -import static org.testng.Assert.assertTrue; +// We extend the BaseComputeServiceContextLiveTest to create nodes using the abstraction, which is much easier +@Test(groups = "live", singleThreaded = true, testName = "ImageApiLiveTest") +public class ImageApiLiveTest extends BaseComputeServiceContextLiveTest { + + private static final String imageName = "imageFromRest"; -@Test(groups = "live", singleThreaded = true) -public class ImageApiLiveTest extends BaseAzureComputeApiLiveTest { + private LoadingCache<String, ResourceGroup> resourceGroupMap; + private Predicate<URI> resourceDeleted; + private AzureComputeApi api; + + private String resourceGroupName; + private String location; + private ImageApi imageApi; + private Image image; + + private String group; + + public ImageApiLiveTest() { + provider = "azurecompute-arm"; + group = getClass().getSimpleName().toLowerCase(); + } + + @Override + protected Properties setupProperties() { + Properties properties = super.setupProperties(); + AzureLiveTestUtils.defaultProperties(properties, getClass().getSimpleName().toLowerCase()); + checkNotNull(setIfTestSystemPropertyPresent(properties, "oauth.endpoint"), "test.oauth.endpoint"); + return properties; + } - public static final String JCLOUDS_VM_IMAGE_PREFIX = "jclouds-vm-image-"; - private String imageName; - private VirtualMachine virtualMachine; + @Override + protected void initializeContext() { + super.initializeContext(); + resourceDeleted = context.utils().injector().getInstance(Key.get(new TypeLiteral<Predicate<URI>>() { + }, Names.named(TIMEOUT_RESOURCE_DELETED))); + resourceGroupMap = context.utils().injector() + .getInstance(Key.get(new TypeLiteral<LoadingCache<String, ResourceGroup>>() { + })); + api = view.unwrapApi(AzureComputeApi.class); + } + @Override @BeforeClass + public void setupContext() { + super.setupContext(); + // Use the resource name conventions used in the abstraction + ResourceGroup resourceGroup = createResourceGroup(); + resourceGroupName = resourceGroup.name(); + location = resourceGroup.location(); + imageApi = api.getVirtualMachineImageApi(resourceGroupName); + } + @Override - public void setup() { - super.setup(); - createTestResourceGroup(); - imageName = JCLOUDS_VM_IMAGE_PREFIX + RAND; - String vmName = "jclouds-vm-" + RAND; - - virtualMachine = api.getVirtualMachineApi(resourceGroupName).createOrUpdate(vmName, LOCATION, VirtualMachineProperties.builder().build(), - Collections.<String, String> emptyMap(), null); + @AfterClass(alwaysRun = true) + protected void tearDownContext() { + try { + view.getComputeService().destroyNodesMatching(inGroup(group)); + } finally { + try { + URI uri = api.getResourceGroupApi().delete(resourceGroupName); + assertResourceDeleted(uri); + } finally { + super.tearDownContext(); + } + } } @Test - public void deleteImageResourceDoesNotExist() { - assertNull(api().delete(JCLOUDS_VM_IMAGE_PREFIX + UUID.randomUUID())); + public void testDeleteImageDoesNotExist() { + assertNull(imageApi.delete("notAnImage")); } @Test - public void CreateVirtualMachineImageFromExistingVM() { - String id = String.format("/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Compute/virtualMachines/myVM", getSubscriptionId(), resourceGroupName); - ImageProperties properties = ImageProperties.builder() - .sourceVirtualMachine(ImageProperties.SourceVirtualMachine.create(id)) - .build(); - Image image = api().createOrUpdate(imageName, LOCATION, properties); - assertTrue(waitUntilAvailable(imageName), "creation operation did not complete in the configured timeout"); - assertTrue(id.equals(image.properties().sourceVirtualMachine().id())); - } + public void testCreateImage() throws RunNodesException { + NodeMetadata node = getOnlyElement(view.getComputeService().createNodesInGroup(group, 1)); + IdReference vmIdRef = IdReference.create(node.getProviderId()); + view.getComputeService().suspendNode(node.getId()); + + api.getVirtualMachineApi(resourceGroupName).generalize(node.getName()); - @Test(dependsOnMethods = "CreateVirtualMachineImageFromExistingVM") - public void getImage() { - Image image = api().get(imageName); + image = imageApi.createOrUpdate(imageName, location, ImageProperties.builder() + .sourceVirtualMachine(vmIdRef).build()); assertNotNull(image); } - @Test(dependsOnMethods = "CreateVirtualMachineImageFromExistingVM") - public void listImages() { - List<Image> images = api().list(); - assertTrue(images.size() > 0); + @Test(dependsOnMethods = "testCreateImage") + public void testListImages() { + // Check that the image we've just created exists + assertTrue(any(imageApi.list(), new Predicate<Image>() { + @Override + public boolean apply(Image input) { + return image.name().equals(input.name()); + } + })); + } + + @Test(dependsOnMethods = "testCreateImage") + public void testGetImage() { + assertNotNull(imageApi.get(imageName)); } - @Test(dependsOnMethods = {"listImages", "getImage"}, alwaysRun = true) + @Test(dependsOnMethods = { "testCreateImage", "testListImages", "testGetImage" }, alwaysRun = true) public void deleteImage() { - URI uri = api().delete(imageName); - assertNotNull(uri); + assertResourceDeleted(imageApi.delete(imageName)); } - private ImageApi api() { - return api.getVirtualMachineImageApi(resourceGroupName); + private void assertResourceDeleted(final URI uri) { + if (uri != null) { + assertTrue(resourceDeleted.apply(uri), + String.format("Resource %s was not deleted in the configured timeout", uri)); + } } - - private boolean waitUntilAvailable(final String name) { - return resourceAvailable.apply(new Supplier<Provisionable>() { - @Override public Provisionable get() { - Image image = api().get(name); - return image == null ? null : image.properties(); - } - }); + + private ResourceGroup createResourceGroup() { + Location location = view.getComputeService().templateBuilder().build().getLocation(); + return resourceGroupMap.getUnchecked(location.getId()); } -} +} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/9caaa469/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/ImageApiMockTest.java ---------------------------------------------------------------------- diff --git a/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/ImageApiMockTest.java b/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/ImageApiMockTest.java new file mode 100644 index 0000000..cec0483 --- /dev/null +++ b/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/ImageApiMockTest.java @@ -0,0 +1,155 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jclouds.azurecompute.arm.features; + +import static com.google.common.collect.Iterables.isEmpty; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotNull; +import static org.testng.Assert.assertNull; +import static org.testng.Assert.assertTrue; + +import java.net.URI; +import java.util.List; + +import org.jclouds.azurecompute.arm.domain.DataDisk; +import org.jclouds.azurecompute.arm.domain.IdReference; +import org.jclouds.azurecompute.arm.domain.Image; +import org.jclouds.azurecompute.arm.domain.ImageProperties; +import org.jclouds.azurecompute.arm.domain.OSDisk; +import org.jclouds.azurecompute.arm.domain.StorageProfile; +import org.jclouds.azurecompute.arm.internal.BaseAzureComputeApiMockTest; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableList; + +@Test(groups = "unit", testName = "ImageApiMockTest", singleThreaded = true) +public class ImageApiMockTest extends BaseAzureComputeApiMockTest { + private static final String subscriptionid = "SUBSCRIPTIONID"; + private static final String resourcegroup = "myresourcegroup"; + private static final String apiVersion = "api-version=2016-04-30-preview"; + private static final String imageName = "testVirtualMachineImage"; + private static final String location = "canadaeast"; + + private static final String PATH = String + .format("/subscriptions/%s/resourcegroups/%s/providers/Microsoft.Compute/images/%s?%s", subscriptionid, + resourcegroup, imageName, apiVersion); + + public void createVirtualMachineImage() throws InterruptedException { + server.enqueue(jsonResponse("/virtualmachineimagecreate.json")); + + ImageApi imageApi = api.getVirtualMachineImageApi(resourcegroup); + Image result = imageApi.createOrUpdate(imageName, location, newVirtualMachineImage().properties()); + + assertSent(server, "PUT", PATH, "{\"location\":\"" + location + "\"," + + "\"properties\":{\"sourceVirtualMachine\":{\"id\":\"vmId\"}," + + "\"storageProfile\":{\"osDisk\":{\"osType\":\"Linux\",\"name\":\"Ubuntu\"},\"dataDisks\":[]}," + + "\"provisioningState\":\"Succeeded\"}}"); + + assertEquals(result.name(), imageName); + assertEquals(result.location(), location); + } + + public void getVirtualMachineImage() throws InterruptedException { + server.enqueue(jsonResponse("/virtualmachineimageget.json")); + + ImageApi imageApi = api.getVirtualMachineImageApi(resourcegroup); + Image result = imageApi.get(imageName); + + assertSent(server, "GET", PATH); + + assertEquals(result.name(), imageName); + assertEquals(result.location(), location); + assertNotNull(result.properties().sourceVirtualMachine()); + assertNotNull(result.properties().storageProfile()); + } + + public void getVirtualMachineImageReturns404() throws InterruptedException { + server.enqueue(response404()); + + final ImageApi imageApi = api.getVirtualMachineImageApi(resourcegroup); + Image result = imageApi.get(imageName); + + assertSent(server, "GET", PATH); + + assertNull(result); + } + + public void listVirtualMachineImages() throws InterruptedException { + server.enqueue(jsonResponse("/virtualmachineimagelist.json")); + + final ImageApi imageApi = api.getVirtualMachineImageApi(resourcegroup); + List<Image> result = imageApi.list(); + + assertSent(server, "GET", String + .format("/subscriptions/%s/resourcegroups/%s/providers/Microsoft.Compute/images?%s", subscriptionid, + resourcegroup, apiVersion)); + + assertNotNull(result); + assertTrue(result.size() > 0); + } + + public void listVirtualMachineImagesReturns404() throws InterruptedException { + server.enqueue(response404()); + + final ImageApi imageApi = api.getVirtualMachineImageApi(resourcegroup); + List<Image> result = imageApi.list(); + + assertSent(server, "GET", String + .format("/subscriptions/%s/resourcegroups/%s/providers/Microsoft.Compute/images?%s", subscriptionid, + resourcegroup, apiVersion)); + + assertTrue(isEmpty(result)); + } + + public void deleteVirtualMachineImage() throws InterruptedException { + server.enqueue(response202WithHeader()); + + final ImageApi imageApi = api.getVirtualMachineImageApi(resourcegroup); + URI uri = imageApi.delete(imageName); + + assertSent(server, "DELETE", PATH); + + assertNotNull(uri); + assertTrue(uri.toString().contains("api-version")); + assertTrue(uri.toString().contains("operationresults")); + } + + public void deleteVirtualMachineImageDoesNotExist() throws InterruptedException { + server.enqueue(response404()); + + final ImageApi imageApi = api.getVirtualMachineImageApi(resourcegroup); + URI uri = imageApi.delete(imageName); + assertNull(uri); + + assertSent(server, "DELETE", PATH); + } + + private Image newVirtualMachineImage() { + return Image + .builder() + .name(imageName) + .location(location) + .properties( + ImageProperties + .builder() + .sourceVirtualMachine(IdReference.create("vmId")) + .storageProfile( + StorageProfile.create(null, OSDisk.builder().osType("Linux").name("Ubuntu").build(), + ImmutableList.<DataDisk> of())).provisioningState("Succeeded").build()).build(); + + } +} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/9caaa469/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/LoadBalancerApiLiveTest.java ---------------------------------------------------------------------- diff --git a/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/LoadBalancerApiLiveTest.java b/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/LoadBalancerApiLiveTest.java index 69014a5..5799093 100644 --- a/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/LoadBalancerApiLiveTest.java +++ b/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/LoadBalancerApiLiveTest.java @@ -116,7 +116,7 @@ public class LoadBalancerApiLiveTest extends BaseComputeServiceContextLiveTest { @Override protected Properties setupProperties() { Properties properties = super.setupProperties(); - AzureLiveTestUtils.defaultProperties(properties); + AzureLiveTestUtils.defaultProperties(properties, getClass().getSimpleName().toLowerCase()); checkNotNull(setIfTestSystemPropertyPresent(properties, "oauth.endpoint"), "test.oauth.endpoint"); return properties; } @@ -356,7 +356,7 @@ public class LoadBalancerApiLiveTest extends BaseComputeServiceContextLiveTest { // set AvailabilitySetProperties props = AvailabilitySetProperties.builder().platformUpdateDomainCount(count) .platformFaultDomainCount(count).build(); - AvailabilitySet as = AvailabilitySet.builder().name(group).properties(props).build(); + AvailabilitySet as = AvailabilitySet.managed().name(group).properties(props).build(); Set<? extends NodeMetadata> nodes = view.getComputeService() .createNodesInGroup(group, count, availabilitySet(as)); http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/9caaa469/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/VirtualMachineApiLiveTest.java ---------------------------------------------------------------------- diff --git a/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/VirtualMachineApiLiveTest.java b/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/VirtualMachineApiLiveTest.java index ccf1e70..cecdc01 100644 --- a/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/VirtualMachineApiLiveTest.java +++ b/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/VirtualMachineApiLiveTest.java @@ -16,6 +16,12 @@ */ package org.jclouds.azurecompute.arm.features; +import static org.assertj.core.api.Assertions.assertThat; +import static org.jclouds.util.Predicates2.retry; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotNull; +import static org.testng.Assert.assertTrue; + import java.net.URI; import java.util.ArrayList; import java.util.Arrays; @@ -24,7 +30,6 @@ import java.util.List; import java.util.Map; import org.jclouds.azurecompute.arm.domain.DataDisk; -import org.jclouds.azurecompute.arm.domain.DiagnosticsProfile; import org.jclouds.azurecompute.arm.domain.HardwareProfile; import org.jclouds.azurecompute.arm.domain.IdReference; import org.jclouds.azurecompute.arm.domain.ImageReference; @@ -37,6 +42,7 @@ import org.jclouds.azurecompute.arm.domain.NetworkProfile; import org.jclouds.azurecompute.arm.domain.OSDisk; import org.jclouds.azurecompute.arm.domain.OSProfile; import org.jclouds.azurecompute.arm.domain.ResourceDefinition; +import org.jclouds.azurecompute.arm.domain.StorageAccountType; import org.jclouds.azurecompute.arm.domain.StorageProfile; import org.jclouds.azurecompute.arm.domain.StorageService; import org.jclouds.azurecompute.arm.domain.Subnet; @@ -45,8 +51,8 @@ import org.jclouds.azurecompute.arm.domain.VirtualMachine; import org.jclouds.azurecompute.arm.domain.VirtualMachineInstance; import org.jclouds.azurecompute.arm.domain.VirtualMachineInstance.PowerState; import org.jclouds.azurecompute.arm.domain.VirtualMachineProperties; +import org.jclouds.azurecompute.arm.functions.ParseJobStatus; import org.jclouds.azurecompute.arm.internal.BaseAzureComputeApiLiveTest; -import org.testng.Assert; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; @@ -55,20 +61,12 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Iterables; -import static org.assertj.core.api.Assertions.assertThat; -import static org.jclouds.util.Predicates2.retry; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertNotNull; -import static org.testng.Assert.assertTrue; - @Test(groups = "live", testName = "VirtualMachineApiLiveTest") public class VirtualMachineApiLiveTest extends BaseAzureComputeApiLiveTest { private String subscriptionid; - private String storageServiceName; private String vmName; private String nicName; - private StorageService storageService; private String virtualNetworkName; private String subnetId; @@ -81,9 +79,6 @@ public class VirtualMachineApiLiveTest extends BaseAzureComputeApiLiveTest { createTestResourceGroup(); virtualNetworkName = String.format("vn-%s-%s", this.getClass().getSimpleName().toLowerCase(), System.getProperty("user.name")); - storageServiceName = String.format("st%s%s", System.getProperty("user.name"), RAND); - storageService = createStorageService(resourceGroupName, storageServiceName, LOCATION); - // Subnets belong to a virtual network so that needs to be created first assertNotNull(createDefaultVirtualNetwork(resourceGroupName, virtualNetworkName, "10.2.0.0/16", LOCATION)); @@ -103,25 +98,10 @@ public class VirtualMachineApiLiveTest extends BaseAzureComputeApiLiveTest { @Test public void testCreate() { - String blob = storageService.storageServiceProperties().primaryEndpoints().get("blob"); - - VirtualMachine vm = api().createOrUpdate(vmName, LOCATION, getProperties(blob, nicName), + VirtualMachine vm = api().createOrUpdate(vmName, LOCATION, getProperties(nicName, null), Collections.<String, String> emptyMap(), null); assertTrue(!vm.name().isEmpty()); - - //Poll until resource is ready to be used - boolean jobDone = retry(new Predicate<String>() { - @Override - public boolean apply(String name) { - return !api().get(name).properties().provisioningState().equals(VirtualMachineProperties.ProvisioningState.CREATING); - } - }, 60 * 20 * 1000).apply(vmName); - assertTrue(jobDone, "createOrUpdate operation did not complete in the configured timeout"); - - VirtualMachineProperties.ProvisioningState status = api().get(vmName).properties().provisioningState(); - // Cannot be creating anymore. Should be succeeded or running but not failed. - assertThat(status).isNotEqualTo(VirtualMachineProperties.ProvisioningState.CREATING); - assertThat(status).isNotEqualTo(VirtualMachineProperties.ProvisioningState.FAILED); + waitUntilReady(vmName); } @Test(dependsOnMethods = "testCreate") @@ -139,7 +119,7 @@ public class VirtualMachineApiLiveTest extends BaseAzureComputeApiLiveTest { @Test(dependsOnMethods = "testGet") public void testStart() { api().start(vmName); - assertTrue(stateReached(PowerState.RUNNING), "start operation did not complete in the configured timeout"); + assertTrue(stateReached(vmName, PowerState.RUNNING), "start operation did not complete in the configured timeout"); } @Test(dependsOnMethods = "testStart") @@ -147,15 +127,12 @@ public class VirtualMachineApiLiveTest extends BaseAzureComputeApiLiveTest { VirtualMachine vm = api().get(vmName); VirtualMachineProperties oldProperties = vm.properties(); StorageProfile oldStorageProfile = oldProperties.storageProfile(); - - String blob = storageService.storageServiceProperties().primaryEndpoints().get("blob"); - VHD vhd = VHD.create(blob + "vhds/" + vmName + "new-data-disk.vhd"); + DataDisk newDataDisk = DataDisk.builder() .name(vmName + "new-data-disk") .diskSizeGB("1") .lun(1) .createOption(DataDisk.DiskCreateOptionTypes.EMPTY) - .vhd(vhd) .build(); List<DataDisk> oldDataDisks = oldStorageProfile.dataDisks(); assertEquals(oldDataDisks.size(), 1); @@ -173,15 +150,15 @@ public class VirtualMachineApiLiveTest extends BaseAzureComputeApiLiveTest { @Test(dependsOnMethods = "testUpdate") public void testStop() { api().stop(vmName); - assertTrue(stateReached(PowerState.STOPPED), "stop operation did not complete in the configured timeout"); + assertTrue(stateReached(vmName, PowerState.STOPPED), "stop operation did not complete in the configured timeout"); } @Test(dependsOnMethods = "testStop") public void testRestart() { api().start(vmName); - assertTrue(stateReached(PowerState.RUNNING), "start operation did not complete in the configured timeout"); + assertTrue(stateReached(vmName, PowerState.RUNNING), "start operation did not complete in the configured timeout"); api().restart(vmName); - assertTrue(stateReached(PowerState.RUNNING), "restart operation did not complete in the configured timeout"); + assertTrue(stateReached(vmName, PowerState.RUNNING), "restart operation did not complete in the configured timeout"); } @Test(dependsOnMethods = "testCreate") @@ -201,15 +178,31 @@ public class VirtualMachineApiLiveTest extends BaseAzureComputeApiLiveTest { @Test(dependsOnMethods = "testRestart") public void testGeneralize() throws IllegalStateException { api().stop(vmName); - assertTrue(stateReached(PowerState.STOPPED), "restart operation did not complete in the configured timeout"); + assertTrue(stateReached(vmName, PowerState.STOPPED), "restart operation did not complete in the configured timeout"); api().generalize(vmName); } @SuppressWarnings("unchecked") - @Test(dependsOnMethods = "testGeneralize") + @Test public void testCapture() throws IllegalStateException { - URI uri = api().capture(vmName, vmName, vmName); - if (uri == null) Assert.fail(); + // Capture is only allowed for Blob based VMs, so let's create one VM for this test + NetworkInterfaceCard nic = createNetworkInterfaceCard(resourceGroupName, "capture-nic-" + RAND, LOCATION, "ipConfig-" + RAND); + StorageService storageService = createStorageService(resourceGroupName, "capture" + RAND, LOCATION); + String blob = storageService.storageServiceProperties().primaryEndpoints().get("blob"); + + String captureVmName = "capture-" + RAND; + api().createOrUpdate(captureVmName, LOCATION, getProperties(nic.name(), blob), + Collections.<String, String> emptyMap(), null); + waitUntilReady(captureVmName); + + api().stop(captureVmName); + assertTrue(stateReached(captureVmName, PowerState.STOPPED), + "restart operation did not complete in the configured timeout"); + api().generalize(captureVmName); + + URI uri = api().capture(captureVmName, captureVmName, captureVmName); + assertNotNull(uri); + if (imageAvailablePredicate.apply(uri)) { List<ResourceDefinition> definitions = api.getJobApi().captureStatus(uri); if (definitions != null) { @@ -219,18 +212,13 @@ public class VirtualMachineApiLiveTest extends BaseAzureComputeApiLiveTest { Map<String, String> properties2 = (Map<String, String>) storageObject; Object osDiskObject = properties2.get("osDisk"); Map<String, String> osProperties = (Map<String, String>) osDiskObject; - Object dataDisksObject = properties2.get("dataDisks"); - List<Object> dataProperties = (List<Object>) dataDisksObject; - Map<String, String> datadiskObject = (Map<String, String>) dataProperties.get(0); - assertNotNull(osProperties.get("name")); - assertNotNull(datadiskObject.get("name")); } } } } - @Test(dependsOnMethods = "testCapture", alwaysRun = true) + @Test(dependsOnMethods = "testGeneralize", alwaysRun = true) public void testDelete() throws Exception { URI uri = api().delete(vmName); assertResourceDeleted(uri); @@ -240,22 +228,28 @@ public class VirtualMachineApiLiveTest extends BaseAzureComputeApiLiveTest { return api.getVirtualMachineApi(resourceGroupName); } - private VirtualMachineProperties getProperties(String blob, String nic) { + private VirtualMachineProperties getProperties(String nic, String blob) { HardwareProfile hwProf = HardwareProfile.create("Standard_D1"); ImageReference imgRef = ImageReference.builder().publisher("MicrosoftWindowsServerEssentials") .offer("WindowsServerEssentials").sku("WindowsServerEssentials").version("latest").build(); - DataDisk dataDisk = DataDisk.builder().name("data").diskSizeGB("100").lun(0).createOption(DataDisk.DiskCreateOptionTypes.EMPTY).build(); - List<DataDisk> dataDisks = new ArrayList<DataDisk>(); - dataDisks.add(dataDisk); - - OSDisk osDisk = OSDisk.builder() + + DataDisk.Builder dataDisk = DataDisk.builder().name("data").diskSizeGB("100").lun(0).createOption(DataDisk.DiskCreateOptionTypes.EMPTY); + + OSDisk.Builder osDisk = OSDisk.builder() + .name("os") .osType("Windows") .caching(DataDisk.CachingTypes.READ_WRITE.toString()) - .createOption("FromImage") - .managedDiskParameters(ManagedDiskParameters.create(null, ManagedDiskParameters.StorageAccountTypes.STANDARD_LRS.toString())) - .build(); - StorageProfile storageProfile = StorageProfile.create(imgRef, osDisk, dataDisks); + .createOption("FromImage"); + + if (blob == null) { + osDisk.managedDiskParameters(ManagedDiskParameters.create(null, StorageAccountType.STANDARD_LRS.toString())); + } else { + osDisk.vhd(VHD.create(blob + "vhds/" + vmName + ".vhd")); + dataDisk.vhd(VHD.create(blob + "vhds/" + vmName + "data.vhd")); + } + + StorageProfile storageProfile = StorageProfile.create(imgRef, osDisk.build(), ImmutableList.of(dataDisk.build())); OSProfile.WindowsConfiguration windowsConfig = OSProfile.WindowsConfiguration.create(false, null, null, true, null); OSProfile osProfile = OSProfile.create(vmName, "azureuser", "RFe3&432dg", null, null, windowsConfig); @@ -267,15 +261,12 @@ public class VirtualMachineApiLiveTest extends BaseAzureComputeApiLiveTest { new ArrayList<IdReference>(); networkInterfaces.add(networkInterface); NetworkProfile networkProfile = NetworkProfile.create(networkInterfaces); - DiagnosticsProfile.BootDiagnostics bootDiagnostics = - DiagnosticsProfile.BootDiagnostics.create(true, blob); - DiagnosticsProfile diagnosticsProfile = DiagnosticsProfile.create(bootDiagnostics); VirtualMachineProperties properties = VirtualMachineProperties.create(null, - null, null, hwProf, storageProfile, osProfile, networkProfile, diagnosticsProfile, VirtualMachineProperties.ProvisioningState.CREATING); + null, null, hwProf, storageProfile, osProfile, networkProfile, null, VirtualMachineProperties.ProvisioningState.CREATING); return properties; } - protected NetworkInterfaceCard createNetworkInterfaceCard(final String resourceGroupName, String networkInterfaceCardName, String locationName, String ipConfigurationName) { + private NetworkInterfaceCard createNetworkInterfaceCard(final String resourceGroupName, String networkInterfaceCardName, String locationName, String ipConfigurationName) { //Create properties object final NetworkInterfaceCardProperties networkInterfaceCardProperties = NetworkInterfaceCardProperties .builder() @@ -286,12 +277,46 @@ public class VirtualMachineApiLiveTest extends BaseAzureComputeApiLiveTest { final Map<String, String> tags = ImmutableMap.of("jclouds", "livetest"); return api.getNetworkInterfaceCardApi(resourceGroupName).createOrUpdate(networkInterfaceCardName, locationName, networkInterfaceCardProperties, tags); } + + private StorageService createStorageService(final String resourceGroupName, final String storageServiceName, + final String location) { + URI uri = api.getStorageAccountApi(resourceGroupName).create(storageServiceName, location, + ImmutableMap.of("property_name", "property_value"), + ImmutableMap.of("accountType", StorageService.AccountType.Standard_LRS.toString())); + if (uri != null) { + assertTrue(uri.toString().contains("api-version")); + + boolean jobDone = retry(new Predicate<URI>() { + @Override + public boolean apply(final URI uri) { + return ParseJobStatus.JobStatus.DONE == api.getJobApi().jobStatus(uri); + } + }, 60 * 1 * 1000 /* 1 minute timeout */).apply(uri); + assertTrue(jobDone, "create operation did not complete in the configured timeout"); + } + return api.getStorageAccountApi(resourceGroupName).get(storageServiceName); + } private boolean waitForState(String name, final PowerState state) { return api().getInstanceDetails(name).powerState().equals(state); } + + private void waitUntilReady(String vmName) { + boolean ready = retry(new Predicate<String>() { + @Override + public boolean apply(String name) { + return !api().get(name).properties().provisioningState().equals(VirtualMachineProperties.ProvisioningState.CREATING); + } + }, 60 * 20 * 1000).apply(vmName); + assertTrue(ready, "createOrUpdate operation did not complete in the configured timeout"); + + VirtualMachineProperties.ProvisioningState status = api().get(vmName).properties().provisioningState(); + // Cannot be creating anymore. Should be succeeded or running but not failed. + assertThat(status).isNotEqualTo(VirtualMachineProperties.ProvisioningState.CREATING); + assertThat(status).isNotEqualTo(VirtualMachineProperties.ProvisioningState.FAILED); + } - private boolean stateReached(final PowerState state) { + private boolean stateReached(String vmName, final PowerState state) { return retry(new Predicate<String>() { @Override public boolean apply(String name) {
