Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mgmt, appservice onedeploy #16957

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## 2.0.0-beta.6 (Unreleased)

- Supported OneDeploy feature
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe not the appplatform


## 2.0.0-beta.5 (2020-10-19)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -113,4 +116,60 @@ public Mono<Void> zipDeployAsync(File zipFile) {
return Mono.error(e);
}
}

@Override
public void deploy(DeployType type, File file) {
deployAsync(type, file).block();
}

@Override
public Mono<Void> 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<Void> 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<Void> 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<Void> 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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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<StreamResponse> 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<StreamResponse> 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<StreamResponse> 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<StreamResponse> 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<StreamResponse> streamAllLogs(@HostParam("$host") String host);

Expand All @@ -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<Void> warDeploy(
@HostParam("$host") String host,
Expand All @@ -155,16 +132,22 @@ Mono<Void> 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<Void> zipDeploy(
@HostParam("$host") String host,
@BodyParam("application/octet-stream") Flux<ByteBuffer> zipFile,
@HeaderParam("content-length") long size);

@Headers({"Content-Type: application/octet-stream"})
@Post("api/publish")
Mono<Void> deploy(@HostParam("$host") String host,
@BodyParam("application/octet-stream") Flux<ByteBuffer> file,
@HeaderParam("content-length") long size,
@QueryParam("type") DeployType type,
@QueryParam("path") String path,
@QueryParam("restart") Boolean restart,
@QueryParam("clean") Boolean clean);
}

Flux<String> streamApplicationLogsAsync() {
Expand Down Expand Up @@ -266,19 +249,19 @@ private static int findByte(ByteBuffer byteBuffer, byte b) {

Mono<Void> warDeployAsync(InputStream warFile, long length, String appName) {
Flux<ByteBuffer> flux = FluxUtil.toFluxByteBuffer(warFile);
return withRetry(service.warDeploy(host, flux, length, appName));
return retryOnError(service.warDeploy(host, flux, length, appName));
}

Mono<Void> 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<Void> zipDeployAsync(InputStream zipFile) {
Expand All @@ -292,19 +275,41 @@ Mono<Void> warDeployAsync(File warFile, String appName) throws IOException {

Mono<Void> zipDeployAsync(InputStream zipFile, long length) {
Flux<ByteBuffer> flux = FluxUtil.toFluxByteBuffer(zipFile);
return withRetry(service.zipDeploy(host, flux, length));
return retryOnError(service.zipDeploy(host, flux, length));
}

Mono<Void> 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<Void> deployAsync(DeployType type,
InputStream file, long length,
String path, Boolean restart, Boolean clean) {
Flux<ByteBuffer> flux = FluxUtil.toFluxByteBuffer(file);
return retryOnError(service.deploy(host, flux, length, type, path, restart, clean));
}

Mono<Void> 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) {
Expand Down Expand Up @@ -338,26 +343,23 @@ Mono<Void> zipDeployAsync(File zipFile) throws IOException {
// private long size;
// }

private Mono<Void> withRetry(Mono<Void> observable) {
private <T> Mono<T> retryOnError(Mono<T> 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)))));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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. */
Expand Down Expand Up @@ -278,4 +282,60 @@ Mono<StringDictionaryInner> listMetadata() {
Mono<StringDictionaryInner> 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<Void> 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<Void> 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<Void> 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<Void> 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());
}
}
Loading