diff --git a/sdk/resourcemanager/azure-resourcemanager-appservice/CHANGELOG.md b/sdk/resourcemanager/azure-resourcemanager-appservice/CHANGELOG.md index cbdafd04c20a..7751255bcfd9 100644 --- a/sdk/resourcemanager/azure-resourcemanager-appservice/CHANGELOG.md +++ b/sdk/resourcemanager/azure-resourcemanager-appservice/CHANGELOG.md @@ -2,6 +2,7 @@ ## 2.1.0-beta.1 (Unreleased) +- Supported OneDeploy feature ## 2.0.0 (2020-10-19) diff --git a/sdk/resourcemanager/azure-resourcemanager-appservice/src/main/java/com/azure/resourcemanager/appservice/implementation/DeploymentSlotImpl.java b/sdk/resourcemanager/azure-resourcemanager-appservice/src/main/java/com/azure/resourcemanager/appservice/implementation/DeploymentSlotImpl.java index 8d0b26b13dd7..ad82bb6ac690 100644 --- a/sdk/resourcemanager/azure-resourcemanager-appservice/src/main/java/com/azure/resourcemanager/appservice/implementation/DeploymentSlotImpl.java +++ b/sdk/resourcemanager/azure-resourcemanager-appservice/src/main/java/com/azure/resourcemanager/appservice/implementation/DeploymentSlotImpl.java @@ -3,6 +3,8 @@ package com.azure.resourcemanager.appservice.implementation; +import com.azure.resourcemanager.appservice.models.DeployOptions; +import com.azure.resourcemanager.appservice.models.DeployType; import com.azure.resourcemanager.appservice.models.DeploymentSlot; import com.azure.resourcemanager.appservice.models.DeploymentSlotBase; import com.azure.resourcemanager.appservice.models.WebApp; @@ -12,6 +14,7 @@ import java.io.File; import java.io.IOException; import java.io.InputStream; +import java.util.Objects; import reactor.core.publisher.Mono; @@ -113,4 +116,60 @@ public Mono zipDeployAsync(File zipFile) { return Mono.error(e); } } + + @Override + public void deploy(DeployType type, File file) { + deployAsync(type, file).block(); + } + + @Override + public Mono deployAsync(DeployType type, File file) { + return deployAsync(type, file, new DeployOptions()); + } + + @Override + public void deploy(DeployType type, File file, DeployOptions deployOptions) { + deployAsync(type, file, deployOptions).block(); + } + + @Override + public Mono deployAsync(DeployType type, File file, DeployOptions deployOptions) { + Objects.requireNonNull(type); + Objects.requireNonNull(file); + if (deployOptions == null) { + deployOptions = new DeployOptions(); + } + try { + return kuduClient.deployAsync(type, file, + deployOptions.path(), deployOptions.restartSite(), deployOptions.cleanDeployment()); + } catch (IOException e) { + return Mono.error(e); + } + } + + @Override + public void deploy(DeployType type, InputStream file, long length) { + deployAsync(type, file, length).block(); + } + + @Override + public Mono deployAsync(DeployType type, InputStream file, long length) { + return deployAsync(type, file, length, new DeployOptions()); + } + + @Override + public void deploy(DeployType type, InputStream file, long length, DeployOptions deployOptions) { + deployAsync(type, file, length, deployOptions).block(); + } + + @Override + public Mono deployAsync(DeployType type, InputStream file, long length, DeployOptions deployOptions) { + Objects.requireNonNull(type); + Objects.requireNonNull(file); + if (deployOptions == null) { + deployOptions = new DeployOptions(); + } + return kuduClient.deployAsync(type, file, length, + deployOptions.path(), deployOptions.restartSite(), deployOptions.cleanDeployment()); + } } diff --git a/sdk/resourcemanager/azure-resourcemanager-appservice/src/main/java/com/azure/resourcemanager/appservice/implementation/KuduClient.java b/sdk/resourcemanager/azure-resourcemanager-appservice/src/main/java/com/azure/resourcemanager/appservice/implementation/KuduClient.java index 11d925f16171..1689de1ffde6 100644 --- a/sdk/resourcemanager/azure-resourcemanager-appservice/src/main/java/com/azure/resourcemanager/appservice/implementation/KuduClient.java +++ b/sdk/resourcemanager/azure-resourcemanager-appservice/src/main/java/com/azure/resourcemanager/appservice/implementation/KuduClient.java @@ -17,21 +17,21 @@ import com.azure.core.http.policy.HttpPipelinePolicy; import com.azure.core.http.rest.RestProxy; import com.azure.core.http.rest.StreamResponse; -import com.azure.core.management.exception.ManagementException; import com.azure.core.management.serializer.SerializerFactory; import com.azure.core.util.FluxUtil; import com.azure.core.util.logging.ClientLogger; +import com.azure.resourcemanager.appservice.models.DeployType; import com.azure.resourcemanager.appservice.models.KuduAuthenticationPolicy; import com.azure.resourcemanager.appservice.models.WebAppBase; import com.azure.resourcemanager.resources.fluentcore.policy.AuthenticationPolicy; import com.azure.resourcemanager.resources.fluentcore.policy.AuxiliaryAuthenticationPolicy; import com.azure.resourcemanager.resources.fluentcore.policy.ProviderRegistrationPolicy; -import com.fasterxml.jackson.core.JsonParseException; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.IOException; import java.io.InputStream; +import java.net.SocketTimeoutException; import java.nio.ByteBuffer; import java.nio.channels.AsynchronousFileChannel; import java.nio.charset.StandardCharsets; @@ -40,6 +40,7 @@ import java.util.ArrayList; import java.util.List; import java.util.Locale; +import java.util.concurrent.TimeoutException; import reactor.core.Exceptions; import reactor.core.publisher.Flux; @@ -87,38 +88,18 @@ class KuduClient { @Host("{$host}") @ServiceInterface(name = "KuduService") private interface KuduService { - @Headers({ - "x-ms-logging-context: com.microsoft.azure.management.appservice.WebApps streamApplicationLogs", - "x-ms-body-logging: false" - }) @Get("api/logstream/application") Mono streamApplicationLogs(@HostParam("$host") String host); - @Headers({ - "x-ms-logging-context: com.microsoft.azure.management.appservice.WebApps streamHttpLogs", - "x-ms-body-logging: false" - }) @Get("api/logstream/http") Mono streamHttpLogs(@HostParam("$host") String host); - @Headers({ - "x-ms-logging-context: com.microsoft.azure.management.appservice.WebApps streamTraceLogs", - "x-ms-body-logging: false" - }) @Get("api/logstream/kudu/trace") Mono streamTraceLogs(@HostParam("$host") String host); - @Headers({ - "x-ms-logging-context: com.microsoft.azure.management.appservice.WebApps streamDeploymentLogs", - "x-ms-body-logging: false" - }) @Get("api/logstream/kudu/deployment") Mono streamDeploymentLogs(@HostParam("$host") String host); - @Headers({ - "x-ms-logging-context: com.microsoft.azure.management.appservice.WebApps streamAllLogs", - "x-ms-body-logging: false" - }) @Get("api/logstream") Mono streamAllLogs(@HostParam("$host") String host); @@ -133,11 +114,7 @@ private interface KuduService { // @BodyParam("application/octet-stream") byte[] warFile, // @QueryParam("name") String appName); - @Headers({ - "Content-Type: application/octet-stream", - "x-ms-logging-context: com.microsoft.azure.management.appservice.WebApps warDeploy", - "x-ms-body-logging: false" - }) + @Headers({"Content-Type: application/octet-stream"}) @Post("api/wardeploy") Mono warDeploy( @HostParam("$host") String host, @@ -155,16 +132,22 @@ Mono warDeploy( // @HostParam("$host") String host, // @BodyParam("application/octet-stream") byte[] zipFile); - @Headers({ - "Content-Type: application/octet-stream", - "x-ms-logging-context: com.microsoft.azure.management.appservice.WebApps zipDeploy", - "x-ms-body-logging: false" - }) + @Headers({"Content-Type: application/octet-stream"}) @Post("api/zipdeploy") Mono zipDeploy( @HostParam("$host") String host, @BodyParam("application/octet-stream") Flux zipFile, @HeaderParam("content-length") long size); + + @Headers({"Content-Type: application/octet-stream"}) + @Post("api/publish") + Mono deploy(@HostParam("$host") String host, + @BodyParam("application/octet-stream") Flux file, + @HeaderParam("content-length") long size, + @QueryParam("type") DeployType type, + @QueryParam("path") String path, + @QueryParam("restart") Boolean restart, + @QueryParam("clean") Boolean clean); } Flux streamApplicationLogsAsync() { @@ -266,19 +249,19 @@ private static int findByte(ByteBuffer byteBuffer, byte b) { Mono warDeployAsync(InputStream warFile, long length, String appName) { Flux flux = FluxUtil.toFluxByteBuffer(warFile); - return withRetry(service.warDeploy(host, flux, length, appName)); + return retryOnError(service.warDeploy(host, flux, length, appName)); } Mono warDeployAsync(File warFile, String appName) throws IOException { AsynchronousFileChannel fileChannel = AsynchronousFileChannel.open(warFile.toPath(), StandardOpenOption.READ); - return withRetry(service.warDeploy(host, FluxUtil.readFile(fileChannel), fileChannel.size(), appName) + return retryOnError(service.warDeploy(host, FluxUtil.readFile(fileChannel), fileChannel.size(), appName)) .doFinally(ignored -> { try { fileChannel.close(); } catch (IOException e) { logger.logThrowableAsError(e); } - })); + }); } // Mono zipDeployAsync(InputStream zipFile) { @@ -292,19 +275,41 @@ Mono warDeployAsync(File warFile, String appName) throws IOException { Mono zipDeployAsync(InputStream zipFile, long length) { Flux flux = FluxUtil.toFluxByteBuffer(zipFile); - return withRetry(service.zipDeploy(host, flux, length)); + return retryOnError(service.zipDeploy(host, flux, length)); } Mono zipDeployAsync(File zipFile) throws IOException { AsynchronousFileChannel fileChannel = AsynchronousFileChannel.open(zipFile.toPath(), StandardOpenOption.READ); - return withRetry(service.zipDeploy(host, FluxUtil.readFile(fileChannel), fileChannel.size()) + return retryOnError(service.zipDeploy(host, FluxUtil.readFile(fileChannel), fileChannel.size())) + .doFinally(ignored -> { + try { + fileChannel.close(); + } catch (IOException e) { + logger.logThrowableAsError(e); + } + }); + } + + Mono deployAsync(DeployType type, + InputStream file, long length, + String path, Boolean restart, Boolean clean) { + Flux flux = FluxUtil.toFluxByteBuffer(file); + return retryOnError(service.deploy(host, flux, length, type, path, restart, clean)); + } + + Mono deployAsync(DeployType type, + File file, + String path, Boolean restart, Boolean clean) throws IOException { + AsynchronousFileChannel fileChannel = AsynchronousFileChannel.open(file.toPath(), StandardOpenOption.READ); + return retryOnError(service.deploy(host, FluxUtil.readFile(fileChannel), fileChannel.size(), + type, path, restart, clean)) .doFinally(ignored -> { try { fileChannel.close(); } catch (IOException e) { logger.logThrowableAsError(e); } - })); + }); } // private InputStreamFlux fluxFromInputStream(InputStream inputStream) { @@ -338,26 +343,23 @@ Mono zipDeployAsync(File zipFile) throws IOException { // private long size; // } - private Mono withRetry(Mono observable) { + private Mono retryOnError(Mono observable) { + final int retryCount = 5 + 1; // retryCount is 5, last 1 is guard return observable .retryWhen(Retry.withThrowable( flux -> flux .zipWith( - Flux.range(1, 6), - (Throwable throwable, Integer integer) -> { - if (throwable instanceof ManagementException - && ((ManagementException) throwable).getResponse().getStatusCode() == 502 - || throwable instanceof JsonParseException -// || throwable instanceof TimeoutException -// || throwable instanceof SocketTimeoutException - ) { - return integer; + Flux.range(1, retryCount), + (Throwable throwable, Integer count) -> { + if (count < retryCount + && (throwable instanceof TimeoutException + || throwable instanceof SocketTimeoutException)) { + return count; } else { throw logger.logExceptionAsError(Exceptions.propagate(throwable)); } }) .flatMap(i -> Mono.delay(Duration.ofSeconds(((long) i) * 10))))); } - } diff --git a/sdk/resourcemanager/azure-resourcemanager-appservice/src/main/java/com/azure/resourcemanager/appservice/implementation/WebAppImpl.java b/sdk/resourcemanager/azure-resourcemanager-appservice/src/main/java/com/azure/resourcemanager/appservice/implementation/WebAppImpl.java index 81b2cf9267aa..feab1b1619fd 100644 --- a/sdk/resourcemanager/azure-resourcemanager-appservice/src/main/java/com/azure/resourcemanager/appservice/implementation/WebAppImpl.java +++ b/sdk/resourcemanager/azure-resourcemanager-appservice/src/main/java/com/azure/resourcemanager/appservice/implementation/WebAppImpl.java @@ -5,6 +5,8 @@ import com.azure.resourcemanager.appservice.AppServiceManager; import com.azure.resourcemanager.appservice.models.AppServicePlan; +import com.azure.resourcemanager.appservice.models.DeployOptions; +import com.azure.resourcemanager.appservice.models.DeployType; import com.azure.resourcemanager.appservice.models.DeploymentSlots; import com.azure.resourcemanager.appservice.models.OperatingSystem; import com.azure.resourcemanager.appservice.models.PricingTier; @@ -21,6 +23,8 @@ import java.io.IOException; import java.io.InputStream; import java.util.HashMap; +import java.util.Objects; + import reactor.core.publisher.Mono; /** The implementation for WebApp. */ @@ -278,4 +282,60 @@ Mono listMetadata() { Mono updateMetadata(StringDictionaryInner inner) { return this.manager().serviceClient().getWebApps().updateMetadataAsync(resourceGroupName(), name(), inner); } + + @Override + public void deploy(DeployType type, File file) { + deployAsync(type, file).block(); + } + + @Override + public Mono deployAsync(DeployType type, File file) { + return deployAsync(type, file, new DeployOptions()); + } + + @Override + public void deploy(DeployType type, File file, DeployOptions deployOptions) { + deployAsync(type, file, deployOptions).block(); + } + + @Override + public Mono deployAsync(DeployType type, File file, DeployOptions deployOptions) { + Objects.requireNonNull(type); + Objects.requireNonNull(file); + if (deployOptions == null) { + deployOptions = new DeployOptions(); + } + try { + return kuduClient.deployAsync(type, file, + deployOptions.path(), deployOptions.restartSite(), deployOptions.cleanDeployment()); + } catch (IOException e) { + return Mono.error(e); + } + } + + @Override + public void deploy(DeployType type, InputStream file, long length) { + deployAsync(type, file, length).block(); + } + + @Override + public Mono deployAsync(DeployType type, InputStream file, long length) { + return deployAsync(type, file, length, new DeployOptions()); + } + + @Override + public void deploy(DeployType type, InputStream file, long length, DeployOptions deployOptions) { + deployAsync(type, file, length, deployOptions).block(); + } + + @Override + public Mono deployAsync(DeployType type, InputStream file, long length, DeployOptions deployOptions) { + Objects.requireNonNull(type); + Objects.requireNonNull(file); + if (deployOptions == null) { + deployOptions = new DeployOptions(); + } + return kuduClient.deployAsync(type, file, length, + deployOptions.path(), deployOptions.restartSite(), deployOptions.cleanDeployment()); + } } diff --git a/sdk/resourcemanager/azure-resourcemanager-appservice/src/main/java/com/azure/resourcemanager/appservice/models/DeployOptions.java b/sdk/resourcemanager/azure-resourcemanager-appservice/src/main/java/com/azure/resourcemanager/appservice/models/DeployOptions.java new file mode 100644 index 000000000000..f4c3bc983753 --- /dev/null +++ b/sdk/resourcemanager/azure-resourcemanager-appservice/src/main/java/com/azure/resourcemanager/appservice/models/DeployOptions.java @@ -0,0 +1,75 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package com.azure.resourcemanager.appservice.models; + +/** + * The options for OneDeploy. + */ +public class DeployOptions { + + private String path; + private Boolean restartSite; + private Boolean cleanDeployment; + + /** + * @return the path for deploy + */ + public String path() { + return path; + } + + /** + * Specifies the path for deploy. Some some deploy type, path is required. + * + * @param path the path for deploy + * @return the DeployOptions object + */ + public DeployOptions withPath(String path) { + this.path = path; + return this; + } + + /** + * @return whether to restart site after deployment + */ + public Boolean restartSite() { + return restartSite; + } + + /** + * Specifies whether to restart site after deployment. + * + * By default, any OneDeploy call will restart the site. This behavior can be altered by this option. + * + * @param restartSite whether to restart side after deployment + * @return the DeployOptions object + */ + public DeployOptions withRestartSite(Boolean restartSite) { + this.restartSite = restartSite; + return this; + } + + /** + * @return whether to perform clean deployment + */ + public Boolean cleanDeployment() { + return cleanDeployment; + } + + /** + * Specifies whether to perform clean deployment. + * + * By default {@code type=zip} and {@code type=war&path=webapps/} performs clean deployment. + * All other types of artifacts will be deployed incrementally. + * The default behavior for any artifact type can be changed by this option. + * A clean deployment nukes the default directory associated with the type of artifact being deployed. + * + * @param cleanDeployment whether to perform clean deployment + * @return the DeployOptions object + */ + public DeployOptions withCleanDeployment(Boolean cleanDeployment) { + this.cleanDeployment = cleanDeployment; + return this; + } +} diff --git a/sdk/resourcemanager/azure-resourcemanager-appservice/src/main/java/com/azure/resourcemanager/appservice/models/DeployType.java b/sdk/resourcemanager/azure-resourcemanager-appservice/src/main/java/com/azure/resourcemanager/appservice/models/DeployType.java new file mode 100644 index 000000000000..71318aad4db0 --- /dev/null +++ b/sdk/resourcemanager/azure-resourcemanager-appservice/src/main/java/com/azure/resourcemanager/appservice/models/DeployType.java @@ -0,0 +1,72 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package com.azure.resourcemanager.appservice.models; + +import com.azure.core.util.ExpandableStringEnum; +import com.fasterxml.jackson.annotation.JsonCreator; + +import java.util.Collection; + +/** + * OneDeploy type. + */ +public class DeployType extends ExpandableStringEnum { + + /** + * Deploy the war file to {@code /home/site/wwwroot/app.war}. + * + * If {@code DeployOptions.path} is provided, {@code path=webapps/} will behave exactly like wardeploy by + * unzipping app to {@code /home/site/wwwroot/webapps/}. + */ + public static final DeployType WAR = fromString("war"); + + /** + * Deploy the jar file to {@code /home/site/wwwroot/app.jar}. + */ + public static final DeployType JAR = fromString("jar"); + + /** + * Deploy the ear file to {@code /home/site/wwwroot/app.ear}. + */ + public static final DeployType EAR = fromString("ear"); + + /** + * Deploy the jar to {@code /home/site/libs}. {@code DeployOptions.path} parameter needs to be specified. + */ + public static final DeployType JAR_LIB = fromString("lib"); + + /** + * Deploy the static file to {@code /home/site/wwwroot/}. + * {@code DeployOptions.path} parameter needs to be specified. + */ + public static final DeployType STATIC = fromString("static"); + + /** + * Deploy the script as startup.sh (Linux) or startup.cmd (Windows) to {@code /home/site/scripts/}. + * {@code DeployOptions.path} parameter is not supported. + */ + public static final DeployType SCRIPT_STARTUP = fromString("startup"); + + /** + * unzip the zip to {@code /home/site/wwwroot}. {@code DeployOptions.path} parameter is optional. + */ + public static final DeployType ZIP = fromString("zip"); + + /** + * Creates or finds a DeployType from its string representation. + * @param name a name to look for + * @return the corresponding DeployType + */ + @JsonCreator + public static DeployType fromString(String name) { + return fromString(name, DeployType.class); + } + + /** + * @return known DeployType type values + */ + public static Collection values() { + return values(DeployType.class); + } +} diff --git a/sdk/resourcemanager/azure-resourcemanager-appservice/src/main/java/com/azure/resourcemanager/appservice/models/DeploymentSlot.java b/sdk/resourcemanager/azure-resourcemanager-appservice/src/main/java/com/azure/resourcemanager/appservice/models/DeploymentSlot.java index d2ff013ac38e..1e522cc6c7ff 100644 --- a/sdk/resourcemanager/azure-resourcemanager-appservice/src/main/java/com/azure/resourcemanager/appservice/models/DeploymentSlot.java +++ b/sdk/resourcemanager/azure-resourcemanager-appservice/src/main/java/com/azure/resourcemanager/appservice/models/DeploymentSlot.java @@ -19,6 +19,7 @@ public interface DeploymentSlot extends IndependentChildResource, WebDeploymentSlotBasic, + SupportsOneDeploy, DeploymentSlotBase, Updatable>, HasParent { diff --git a/sdk/resourcemanager/azure-resourcemanager-appservice/src/main/java/com/azure/resourcemanager/appservice/models/SupportsOneDeploy.java b/sdk/resourcemanager/azure-resourcemanager-appservice/src/main/java/com/azure/resourcemanager/appservice/models/SupportsOneDeploy.java new file mode 100644 index 000000000000..1c00dc7459d6 --- /dev/null +++ b/sdk/resourcemanager/azure-resourcemanager-appservice/src/main/java/com/azure/resourcemanager/appservice/models/SupportsOneDeploy.java @@ -0,0 +1,91 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package com.azure.resourcemanager.appservice.models; + +import reactor.core.publisher.Mono; + +import java.io.File; +import java.io.InputStream; + +/** + * Provides access to OneDeploy. + */ +public interface SupportsOneDeploy { + + /** + * Deploy a file to Azure site. + * + * @param type the deploy type + * @param file the file to upload + */ + void deploy(DeployType type, File file); + + /** + * Deploy a file to Azure site. + * + * @param type the deploy type + * @param file the file to upload + * @return the completable of the operation + */ + Mono deployAsync(DeployType type, File file); + + /** + * Deploy a file to Azure site. + * + * @param type the deploy type + * @param file the file to upload + * @param deployOptions the deploy options + */ + void deploy(DeployType type, File file, DeployOptions deployOptions); + + /** + * Deploy a file to Azure site. + * + * @param type the deploy type + * @param file the file to upload + * @param deployOptions the deploy options + * @return the completable of the operation + */ + Mono deployAsync(DeployType type, File file, DeployOptions deployOptions); + + /** + * Deploy a file to Azure site. + * + * @param type the deploy type + * @param file the file to upload + * @param length the length of the file + */ + void deploy(DeployType type, InputStream file, long length); + + /** + * Deploy a file to Azure site. + * + * @param type the deploy type + * @param file the file to upload + * @param length the length of the file + * @return the completable of the operation + */ + Mono deployAsync(DeployType type, InputStream file, long length); + + /** + * Deploy a file to Azure site. + * + * @param type the deploy type + * @param file the file to upload + * @param length the length of the file + * @param deployOptions the deploy options + */ + void deploy(DeployType type, InputStream file, long length, DeployOptions deployOptions); + + /** + * Deploy a file to Azure site. + * + * @param type the deploy type + * @param file the file to upload + * @param length the length of the file + * @param deployOptions the deploy options + * @return the completable of the operation + */ + Mono deployAsync(DeployType type, InputStream file, long length, DeployOptions deployOptions); +} diff --git a/sdk/resourcemanager/azure-resourcemanager-appservice/src/main/java/com/azure/resourcemanager/appservice/models/WebApp.java b/sdk/resourcemanager/azure-resourcemanager-appservice/src/main/java/com/azure/resourcemanager/appservice/models/WebApp.java index 88ce8a6ac832..7f6f34b575be 100644 --- a/sdk/resourcemanager/azure-resourcemanager-appservice/src/main/java/com/azure/resourcemanager/appservice/models/WebApp.java +++ b/sdk/resourcemanager/azure-resourcemanager-appservice/src/main/java/com/azure/resourcemanager/appservice/models/WebApp.java @@ -15,7 +15,7 @@ /** An immutable client-side representation of an Azure Web App. */ @Fluent -public interface WebApp extends WebAppBasic, WebAppBase, Updatable { +public interface WebApp extends WebAppBasic, SupportsOneDeploy, WebAppBase, Updatable { /** @return the entry point to deployment slot management API under the web app */ DeploymentSlots deploymentSlots(); diff --git a/sdk/resourcemanager/azure-resourcemanager-appservice/src/test/java/com/azure/resourcemanager/appservice/OneDeployTests.java b/sdk/resourcemanager/azure-resourcemanager-appservice/src/test/java/com/azure/resourcemanager/appservice/OneDeployTests.java new file mode 100644 index 000000000000..b87bc155ddc1 --- /dev/null +++ b/sdk/resourcemanager/azure-resourcemanager-appservice/src/test/java/com/azure/resourcemanager/appservice/OneDeployTests.java @@ -0,0 +1,47 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package com.azure.resourcemanager.appservice; + +import com.azure.core.management.Region; +import com.azure.core.test.annotation.DoNotRecord; +import com.azure.resourcemanager.appservice.models.DeployType; +import com.azure.resourcemanager.appservice.models.JavaVersion; +import com.azure.resourcemanager.appservice.models.PricingTier; +import com.azure.resourcemanager.appservice.models.WebApp; +import com.azure.resourcemanager.appservice.models.WebContainer; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +import java.io.File; + +public class OneDeployTests extends AppServiceTest { + + @Test + @DoNotRecord + public void canDeployZip() throws Exception { + if (skipInPlayback()) { + return; + } + + String webAppName1 = generateRandomResourceName("webapp", 10); + + WebApp webApp1 = + appServiceManager + .webApps() + .define(webAppName1) + .withRegion(Region.US_CENTRAL) + .withNewResourceGroup(rgName) + .withNewWindowsPlan(PricingTier.BASIC_B1) + .withJavaVersion(JavaVersion.JAVA_8_NEWEST) + .withWebContainer(WebContainer.TOMCAT_8_5_NEWEST) + .withHttpsOnly(true) + .create(); + + File zipFile = new File(OneDeployTests.class.getResource("/webapps.zip").getPath()); + webApp1.deploy(DeployType.ZIP, zipFile); + + String response = curl("https://" + webAppName1 + ".azurewebsites.net/" + "helloworld/").getValue(); + Assertions.assertTrue(response.contains("Hello")); + } +}