Skip to content

Commit

Permalink
Merge branch 'microsoft:develop' into java-projects-native-deployments
Browse files Browse the repository at this point in the history
  • Loading branch information
SandraAhlgrimm authored Jul 11, 2023
2 parents 083c718 + f08a0b4 commit 891656f
Show file tree
Hide file tree
Showing 131 changed files with 770 additions and 677 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ protected void validateParameters() {
}

private AppServiceConfig buildDefaultConfig(String subscriptionId, String resourceGroup, String appName) {
return AppServiceConfigUtils.buildDefaultFunctionConfig(subscriptionId, resourceGroup, appName, JavaVersion.JAVA_8);
return AppServiceConfigUtils.buildDefaultFunctionConfig(subscriptionId, resourceGroup, appName, JavaVersion.JAVA_17);
}

private void deployArtifact(final FunctionAppBase<?, ?, ?> target) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
<parent>
<artifactId>azure-toolkit-libs</artifactId>
<groupId>com.microsoft.azure</groupId>
<version>0.34.0-SNAPSHOT</version>
<version>0.35.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<groupId>com.microsoft.azure</groupId>
<artifactId>azure-toolkit-applicationinsights-lib</artifactId>
<version>0.34.0-SNAPSHOT</version>
<version>0.35.0-SNAPSHOT</version>
<build>
<plugins>
<plugin>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public String getConnectionString() {

@Nonnull
@Override
public String loadStatus(@Nonnull ApplicationInsightsComponent remote) {
protected String loadStatus(@Nonnull ApplicationInsightsComponent remote) {
return remote.provisioningState();
}
}
4 changes: 2 additions & 2 deletions azure-toolkit-libs/azure-toolkit-appservice-lib/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
<parent>
<artifactId>azure-toolkit-libs</artifactId>
<groupId>com.microsoft.azure</groupId>
<version>0.34.0-SNAPSHOT</version>
<version>0.35.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<groupId>com.microsoft.azure</groupId>
<artifactId>azure-toolkit-appservice-lib</artifactId>
<version>0.34.0-SNAPSHOT</version>
<version>0.35.0-SNAPSHOT</version>

<dependencies>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,18 +74,15 @@ protected AppServiceAppBase(@Nonnull T origin) {
this.kuduManager = origin.kuduManager;
}

@Nullable
@Override
protected WebSiteBase refreshRemoteFromAzure(@Nonnull WebSiteBase remote) {
return super.loadRemote();
}

@Nullable
public synchronized F getFullRemote() {
WebSiteBase remote = this.getRemote();
if (Objects.nonNull(remote) && !(remote instanceof WebAppBase)) {
this.invalidateCache();
remote = this.getRemote(true);
remote = this.getRemote();
}
if (!(remote instanceof WebAppBase)) {
return null;
}
//noinspection unchecked
return (F) remote;
Expand Down Expand Up @@ -215,7 +212,7 @@ public Runtime getRuntime() {

@Nonnull
@Override
public String loadStatus(@Nonnull WebSiteBase remote) {
protected String loadStatus(@Nonnull WebSiteBase remote) {
return remote.state();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.azure.core.management.exception.ManagementException;
import com.azure.resourcemanager.appservice.models.FunctionAppBasic;
import com.azure.resourcemanager.appservice.models.PlatformArchitecture;
import com.azure.resourcemanager.appservice.models.WebSiteBase;
import com.microsoft.azure.toolkit.lib.appservice.AppServiceServiceSubscription;
import com.microsoft.azure.toolkit.lib.appservice.entity.FunctionEntity;
import com.microsoft.azure.toolkit.lib.appservice.utils.AppServiceUtils;
Expand All @@ -34,6 +35,7 @@
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.concurrent.Callable;
import java.util.stream.Collectors;

import static com.microsoft.azure.toolkit.lib.appservice.function.core.AzureFunctionsAnnotationConstants.ANONYMOUS;
Expand Down Expand Up @@ -205,4 +207,11 @@ private List<FunctionEntity> trySyncListFunctions() {
}).subscribeOn(Schedulers.boundedElastic())
.retryWhen(Retry.fixedDelay(LIST_TRIGGERS_MAX_RETRY - 1, Duration.ofSeconds(LIST_TRIGGERS_RETRY_PERIOD_IN_SECONDS))).block();
}

@Nullable
@Override
protected WebSiteBase doModify(@Nonnull Callable<WebSiteBase> body, @Nullable String status) {
// override only to provide package visibility
return super.doModify(body, status);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@
import com.microsoft.azure.toolkit.lib.appservice.deploy.ZIPFunctionDeployHandler;
import com.microsoft.azure.toolkit.lib.appservice.file.AzureFunctionsAdminClient;
import com.microsoft.azure.toolkit.lib.appservice.file.IFileClient;
import com.microsoft.azure.toolkit.lib.appservice.model.*;
import com.microsoft.azure.toolkit.lib.appservice.model.DiagnosticConfig;
import com.microsoft.azure.toolkit.lib.appservice.model.FunctionDeployType;
import com.microsoft.azure.toolkit.lib.appservice.model.OperatingSystem;
import com.microsoft.azure.toolkit.lib.appservice.model.PricingTier;
import com.microsoft.azure.toolkit.lib.appservice.model.Runtime;
import com.microsoft.azure.toolkit.lib.appservice.plan.AppServicePlan;
import com.microsoft.azure.toolkit.lib.common.exception.AzureToolkitRuntimeException;
Expand All @@ -31,6 +34,7 @@
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Objects;
Expand Down Expand Up @@ -169,13 +173,16 @@ protected void updateAdditionalProperties(@Nullable WebSiteBase newRemote, @Null
}

private boolean getIsRemoteDebuggingEnabled() {
final F remote = Objects.requireNonNull(getFullRemote());
final Map<String, String> appSettings = Objects.requireNonNull(this.getAppSettings());
final F remote = getFullRemote();
if (Objects.isNull(remote)) {
return false;
}
final Map<String, String> appSettings = Optional.ofNullable(this.getAppSettings()).orElse(Collections.emptyMap());
// siteConfig for remote debug
final boolean configEnabled = remote.webSocketsEnabled() && remote.platformArchitecture() == PlatformArchitecture.X64;
// JAVA_OPTS
final boolean appSettingsEnabled = appSettings.containsKey(HTTP_PLATFORM_DEBUG_PORT) &&
StringUtils.equalsIgnoreCase(appSettings.get(JAVA_OPTS), getJavaOptsWithRemoteDebugEnabled(appSettings, appSettings.get(HTTP_PLATFORM_DEBUG_PORT)));
StringUtils.equalsIgnoreCase(appSettings.get(JAVA_OPTS), getJavaOptsWithRemoteDebugEnabled(appSettings, appSettings.get(HTTP_PLATFORM_DEBUG_PORT)));
return configEnabled && appSettingsEnabled;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,15 +123,14 @@ public FunctionDeploymentSlot createResourceInAzure() {
// todo: add unified error handling for reactor
final Consumer<Throwable> throwableConsumer = error -> messager.error(error);
final Context context = new Context("reactor.onErrorDropped.local", throwableConsumer);
FunctionDeploymentSlot slot = (FunctionDeploymentSlot) Objects.requireNonNull(this.doModify(() -> withCreate.create(context), Status.CREATING));
FunctionDeploymentSlot slot = withCreate.create(context);
final Runtime runtime = this.getRuntime();
// As we can not update runtime for deployment slot during creation, so call update resource here
final boolean isRuntimeModified = (Objects.nonNull(runtime) && !Objects.equals(runtime, getParent().getRuntime())) || Objects.nonNull(this.getDockerConfiguration());
this.ensureConfig().setAppSettings(null); // reset app settings
this.ensureConfig().setDiagnosticConfig(null); // reset diagnostic config
if (isRuntimeModified) {
final FunctionDeploymentSlot slotToUpdate = slot;
slot = (FunctionDeploymentSlot) Objects.requireNonNull(this.doModify(() -> updateResourceInAzure(slotToUpdate), Status.CREATING));
slot = updateResourceInAzure(slot);
}
if (isRemoteDebugEnabled() && CONFIGURATION_SOURCE_PARENT.equals(source)) {
// disable remote debugging when configuration source is parent, in case port conflicts
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
public class FunctionAppDraft extends FunctionApp implements AzResource.Draft<FunctionApp, WebSiteBase> {
private static final String CREATE_NEW_FUNCTION_APP = "isCreateNewFunctionApp";
public static final String FUNCTIONS_EXTENSION_VERSION = "FUNCTIONS_EXTENSION_VERSION";
public static final JavaVersion DEFAULT_JAVA_VERSION = JavaVersion.JAVA_8;
public static final JavaVersion DEFAULT_JAVA_VERSION = JavaVersion.JAVA_17;
public static final String UNSUPPORTED_OPERATING_SYSTEM = "Unsupported operating system %s";
public static final String CAN_NOT_UPDATE_EXISTING_APP_SERVICE_OS = "Can not update the operation system of an existing app";

Expand Down Expand Up @@ -127,8 +127,7 @@ public com.azure.resourcemanager.appservice.models.FunctionApp createResourceInA
}
final IAzureMessager messager = AzureMessager.getMessager();
messager.info(AzureString.format("Start creating Function App({0})...", name));
com.azure.resourcemanager.appservice.models.FunctionApp functionApp = (com.azure.resourcemanager.appservice.models.FunctionApp)
Objects.requireNonNull(this.doModify(() -> withCreate.create(), Status.CREATING));
com.azure.resourcemanager.appservice.models.FunctionApp functionApp = Objects.requireNonNull(withCreate.create());
messager.success(AzureString.format("Function App({0}) is successfully created", name));
return functionApp;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ protected AppServicePlan(@Nonnull com.azure.resourcemanager.appservice.models.Ap

@Nonnull
@Override
public String loadStatus(@Nonnull com.azure.resourcemanager.appservice.models.AppServicePlan plan) {
protected String loadStatus(@Nonnull com.azure.resourcemanager.appservice.models.AppServicePlan plan) {
return Optional.ofNullable(plan.innerModel()).map(AppServicePlanInner::provisioningState).map(ProvisioningState::toString).orElse(Status.UNKNOWN);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public com.azure.resourcemanager.appservice.models.AppServicePlan createResource

final IAzureMessager messager = AzureMessager.getMessager();
messager.info(AzureString.format("Start creating App Service plan ({0})...", name));
com.azure.resourcemanager.appservice.models.AppServicePlan plan = Objects.requireNonNull(this.doModify(() -> withCreate.create(), Status.CREATING));
com.azure.resourcemanager.appservice.models.AppServicePlan plan = Objects.requireNonNull(withCreate.create());
messager.success(AzureString.format("App Service plan ({0}) is successfully created", name));
return plan;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public class CreateOrUpdateFunctionAppTask extends AzureTask<FunctionAppBase<?,
private static final String FUNCTION_APP_NOT_EXIST_FOR_SLOT = "The Function App specified in pom.xml does not exist. " +
"Please make sure the Function App name is correct.";

public static final JavaVersion DEFAULT_FUNCTION_JAVA_VERSION = JavaVersion.JAVA_8;
public static final JavaVersion DEFAULT_FUNCTION_JAVA_VERSION = JavaVersion.JAVA_17;

private final FunctionAppConfig functionAppConfig;
private final List<AzureTask<?>> tasks = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package com.microsoft.azure.toolkit.lib.appservice.webapp;

import com.azure.resourcemanager.appservice.models.WebAppBasic;
import com.azure.resourcemanager.appservice.models.WebSiteBase;
import com.microsoft.azure.toolkit.lib.appservice.AppServiceServiceSubscription;
import com.microsoft.azure.toolkit.lib.common.bundle.AzureString;
import com.microsoft.azure.toolkit.lib.common.messager.AzureMessager;
Expand All @@ -17,9 +18,11 @@
import lombok.Getter;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.Callable;

@Getter
public class WebApp extends WebAppBase<WebApp, AppServiceServiceSubscription, com.azure.resourcemanager.appservice.models.WebApp>
Expand Down Expand Up @@ -72,4 +75,11 @@ public WebAppDeploymentSlotModule slots() {
public ServiceLinkerModule getServiceLinkerModule() {
return linkerModule;
}

@Nullable
@Override
protected WebSiteBase doModify(@Nonnull Callable<WebSiteBase> body, @Nullable String status) {
// override only to provide package visibility
return super.doModify(body, status);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -121,15 +121,14 @@ public DeploymentSlot createResourceInAzure() {
messager.info(AzureString.format("Start creating Web App deployment slot ({0})...", name));
// workaround to resolve slot creation exception could not be caught by azure operation
// todo: add unified error handling for reactor
final Consumer<Throwable> throwableConsumer = error -> messager.error(error);
final Consumer<Throwable> throwableConsumer = messager::error;
final Context context = new Context("reactor.onErrorDropped.local", throwableConsumer);
DeploymentSlot slot = (DeploymentSlot) Objects.requireNonNull(this.doModify(() -> withCreate.create(context), Status.CREATING));
DeploymentSlot slot = Objects.requireNonNull(withCreate.create(context));
final Runtime runtime = this.getRuntime();
// As we can not update runtime for deployment slot during creation, so call update resource here
final boolean isRuntimeModified = (Objects.nonNull(runtime) && !Objects.equals(runtime, getParent().getRuntime())) || Objects.nonNull(this.getDockerConfiguration());
if (isRuntimeModified) {
final DeploymentSlot slotToUpdate = slot;
slot = (DeploymentSlot) Objects.requireNonNull(this.doModify(() -> updateResourceInAzure(slotToUpdate), Status.CREATING));
slot = Objects.requireNonNull(updateResourceInAzure(slot));
}
messager.success(AzureString.format("Web App deployment slot ({0}) is successfully created", name));
return slot;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,7 @@ public com.azure.resourcemanager.appservice.models.WebApp createResourceInAzure(
}
final IAzureMessager messager = AzureMessager.getMessager();
messager.info(AzureString.format("Start creating Web App({0})...", name));
com.azure.resourcemanager.appservice.models.WebApp webApp = (com.azure.resourcemanager.appservice.models.WebApp)
Objects.requireNonNull(this.doModify(() -> withCreate.create(), Status.CREATING));
com.azure.resourcemanager.appservice.models.WebApp webApp = Objects.requireNonNull(withCreate.create());
messager.success(AzureString.format("Web App({0}) is successfully created", name));
return webApp;
}
Expand Down Expand Up @@ -147,7 +146,7 @@ public com.azure.resourcemanager.appservice.models.WebApp updateResourceInAzure(
settingsToAdd.entrySet().removeAll(oldAppSettings.entrySet());
}
final Set<String> settingsToRemove = Optional.ofNullable(this.ensureConfig().getAppSettingsToRemove())
.map(set -> set.stream().filter(key -> oldAppSettings.containsKey(key)).collect(Collectors.toSet()))
.map(set -> set.stream().filter(oldAppSettings::containsKey).collect(Collectors.toSet()))
.orElse(Collections.emptySet());
final DiagnosticConfig newDiagnosticConfig = this.ensureConfig().getDiagnosticConfig();
final Runtime newRuntime = this.ensureConfig().getRuntime();
Expand Down
4 changes: 2 additions & 2 deletions azure-toolkit-libs/azure-toolkit-auth-lib/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
<parent>
<artifactId>azure-toolkit-libs</artifactId>
<groupId>com.microsoft.azure</groupId>
<version>0.34.0-SNAPSHOT</version>
<version>0.35.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<groupId>com.microsoft.azure</groupId>
<artifactId>azure-toolkit-auth-lib</artifactId>
<version>0.34.0-SNAPSHOT</version>
<version>0.35.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>com.azure</groupId>
Expand Down
9 changes: 6 additions & 3 deletions azure-toolkit-libs/azure-toolkit-common-lib/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
<parent>
<artifactId>azure-toolkit-libs</artifactId>
<groupId>com.microsoft.azure</groupId>
<version>0.34.0-SNAPSHOT</version>
<version>0.35.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<groupId>com.microsoft.azure</groupId>
<artifactId>azure-toolkit-common-lib</artifactId>
<version>0.34.0-SNAPSHOT</version>
<version>0.35.0-SNAPSHOT</version>

<dependencies>
<dependency>
Expand Down Expand Up @@ -51,7 +51,10 @@
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>

<dependency>
<groupId>com.github.ben-manes.caffeine</groupId>
<artifactId>caffeine</artifactId>
</dependency>
<dependency>
<groupId>org.fusesource.jansi</groupId>
<artifactId>jansi</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,11 @@
@Accessors(chain = true)
public class Action<D> extends OperationBase implements Cloneable {
public static final String SOURCE = "ACTION_SOURCE";
public static final String PLACE = "place";
public static final String EMPTY_PLACE = "empty";
public static final String RESOURCE_TYPE = "resourceType";
public static final Id<Runnable> REQUIRE_AUTH = Id.of("common.requireAuth");
public static final Id<Object> AUTHENTICATE = Id.of("account.authenticate");
public static final Id<Object> AUTHENTICATE = Id.of("user/account.authenticate");
public static final Action.Id<Object> OPEN_AZURE_SETTINGS = Action.Id.of("user/common.open_azure_settings");
public static final Action.Id<Object> DISABLE_AUTH_CACHE = Action.Id.of("user/account.disable_auth_cache");

Expand Down Expand Up @@ -150,14 +152,14 @@ public void handle(D s, Object e) {

private void handle(D s, Object e, BiConsumer<D, Object> handler) {
final D source = Optional.ofNullable(this.source).orElse(s);
final OperationContext context = OperationContext.action();
context.setTelemetryProperties(this.getContext().getTelemetryProperties());
if (source instanceof AzResource) {
final AzResource resource = (AzResource) source;
final OperationContext context = OperationContext.action();
context.setTelemetryProperty("subscriptionId", resource.getSubscriptionId());
context.setTelemetryProperty("resourceType", resource.getFullResourceType());
} else if (source instanceof AzResourceModule) {
final AzResourceModule<?> resource = (AzResourceModule<?>) source;
final OperationContext context = OperationContext.action();
context.setTelemetryProperty("subscriptionId", resource.getSubscriptionId());
context.setTelemetryProperty("resourceType", resource.getFullResourceType());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,5 +101,13 @@ default Object restart() {
default Object deploy() {
return null;
}

default Object copy() {
return null;
}

default Object paste() {
return null;
}
}
}
Loading

0 comments on commit 891656f

Please sign in to comment.