Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/endgame-202310' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
wangmingliang-ms committed Nov 7, 2023
2 parents 36fa11f + 5fa6685 commit 5a9cef2
Show file tree
Hide file tree
Showing 95 changed files with 1,184 additions and 1,114 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
All notable changes to "Azure Toolkit for IntelliJ IDEA" will be documented in this file.

- [Change Log](#change-log)
- [3.82.0](#3820)
- [3.81.0](#3810)
- [3.80.0](#3800)
- [3.79.1](#3791)
Expand Down Expand Up @@ -103,6 +104,15 @@ All notable changes to "Azure Toolkit for IntelliJ IDEA" will be documented in t
- [3.0.7](#307)
- [3.0.6](#306)

## 3.82.0
### Added
- Code assistance of Azure resources for Spring and Azure Functions.
- Azure Functions flex consumption tier support.

### Fixed
- [#7907](https://github.com/microsoft/azure-tools-for-java/issues/7907): Uncaught Exception Operator called default onErrorDropped java.lang.InterruptedException.
- other known issues.

## 3.81.1
### Fixed
- [#7897](https://github.com/microsoft/azure-tools-for-java/issues/7897): Uncaught Exception: Error was received while reading the incoming data. The connection will be closed.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ protected PsiElement[] invokeDialog(Project project, PsiDirectory psiDirectory)
final String newName = packageName.replace('.', '/');
operation.trackProperty(TelemetryConstants.TRIGGER_TYPE, triggerType);

final String functionClassContent = bindingTemplate.generateContent(parameters);
final String functionClassContent = bindingTemplate.generateContent(parameters).replaceAll("\\r", "");
if (StringUtils.isNotEmpty(functionClassContent)) {
AzureTaskManager.getInstance().write(() -> {
final CreateFileAction.MkDirs mkDirs = ApplicationManager.getApplication().runWriteAction(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,7 @@
import java.io.InputStream;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.*;
import java.util.concurrent.Callable;
import java.util.function.Consumer;
import java.util.regex.Matcher;
Expand Down Expand Up @@ -255,11 +249,16 @@ private int runFunctionCli(RunProcessHandler processHandler, File stagingFolder)
}
});
// Pending for function cli
final int result = process.waitFor();
if (result != 0) {
throw new AzureToolkitRuntimeException(error[0]);
try {
final int result = process.waitFor();
if (result != 0) {
throw new AzureToolkitRuntimeException(error[0]);
}
return result;
} catch (final InterruptedException i) {
// swallow interrupted exception which is caused by user stop
return 0;
}
return result;
}

private boolean isFuncInitialized(String input) {
Expand Down Expand Up @@ -348,21 +347,26 @@ private void prepareStagingFolder(File stagingFolder,
final String error = String.format("failed prepare staging folder[%s]", folder);
throw new AzureToolkitRuntimeException(error, e);
}
if (installProcess != null) {
readInputStreamByLines(installProcess.getErrorStream(), inputLine -> {
if (processHandler.isProcessRunning()) {
processHandler.println(inputLine, ProcessOutputTypes.STDERR);
}
});
readInputStreamByLines(installProcess.getInputStream(), inputLine -> {
if (processHandler.isProcessRunning()) {
processHandler.setText(inputLine);
}
});
if (Objects.isNull(installProcess)) {
return;
}
readInputStreamByLines(installProcess.getErrorStream(), inputLine -> {
if (processHandler.isProcessRunning()) {
processHandler.println(inputLine, ProcessOutputTypes.STDERR);
}
});
readInputStreamByLines(installProcess.getInputStream(), inputLine -> {
if (processHandler.isProcessRunning()) {
processHandler.setText(inputLine);
}
});
try {
final int exitCode = installProcess.waitFor();
if (exitCode != 0) {
throw new AzureExecutionException(message("function.run.error.installFuncFailed"));
}
} catch (final InterruptedException e) {
// swallow interrupted exception which is caused by user cancel
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@
import com.intellij.openapi.module.Module;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.ComboBox;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.vfs.LocalFileSystem;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.packaging.artifacts.Artifact;
import com.intellij.ui.ListCellRendererWrapper;
import com.intellij.ui.SimpleListCellRenderer;
import com.microsoft.azure.toolkit.intellij.common.AzureFormInputComponent;
import com.microsoft.azure.toolkit.intellij.common.AzureTextInput;
import com.microsoft.azure.toolkit.intellij.function.components.ModuleFileComboBox;
Expand All @@ -37,12 +38,7 @@
import java.awt.event.ItemEvent;
import java.io.File;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.Collections;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.UUID;
import java.util.*;

import static com.microsoft.azure.toolkit.intellij.common.AzureBundle.message;

Expand Down Expand Up @@ -72,7 +68,7 @@ public FunctionRunPanel(@NotNull Project project, FunctionRunConfiguration funct
}

private void init() {
cbFunctionModule.setRenderer(new ListCellRendererWrapper<>() {
cbFunctionModule.setRenderer(new SimpleListCellRenderer<>() {
@Override
public void customize(JList list, Module module, int i, boolean b, boolean b1) {
if (module != null) {
Expand All @@ -97,6 +93,9 @@ private void onSelectModule(ItemEvent itemEvent) {
functionRunConfiguration.saveModule((Module) module);
final DataContext context = DataManager.getInstance().getDataContext(pnlMain);
final ConfigurationSettingsEditorWrapper editor = ConfigurationSettingsEditorWrapper.CONFIGURATION_EDITOR_KEY.getData(context);
if (Objects.isNull(editor)) {
return;
}
BuildArtifactBeforeRunTaskUtils.updateConnectorBeforeRunTask(this.functionRunConfiguration, editor);
} else {
cbHostJson.setModule(null);
Expand Down Expand Up @@ -124,6 +123,13 @@ protected void resetFromConfig(@NotNull FunctionRunConfiguration configuration)
final Map<String, String> appSettings = FunctionUtils.loadAppSettingsFromSecurityStorage(appSettingsKey);
if (MapUtils.isNotEmpty(appSettings)) {
appSettingsTable.setAppSettings(appSettings);
} else {
final String localSettingsPath = configuration.getDefaultLocalSettingsJsonPath(configuration.getModule());

if (StringUtils.isNotBlank(localSettingsPath) && FileUtil.exists(localSettingsPath)) {
appSettingsTable.setLocalSettingPath(localSettingsPath);
appSettingsTable.loadLocalSetting();
}
}
}
// In case `FUNCTIONS_WORKER_RUNTIME` or `AZURE_WEB_JOB_STORAGE_KEY` was missed in configuration
Expand Down Expand Up @@ -192,7 +198,7 @@ private void createUIComponents() {
appSettingsTable = new FunctionAppSettingsTable(localSettingPath);
appSettingsTable.setProject(project);
pnlAppSettings = FunctionAppSettingsTableUtils.createAppSettingPanel(appSettingsTable);
appSettingsTable.loadLocalSetting();
// appSettingsTable.loadLocalSetting();

cbHostJson = new ModuleFileComboBox(project, "host.json");
cbHostJson.setRequired(true);
Expand All @@ -214,6 +220,7 @@ private void selectModule(final Module target) {
}
for (int i = 0; i < cbFunctionModule.getItemCount(); i++) {
final Module module = cbFunctionModule.getItemAt(i);
//noinspection UnstableApiUsage
if (Paths.get(module.getModuleFilePath()).equals(Paths.get(target.getModuleFilePath()))) {
cbFunctionModule.setSelectedIndex(i);
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.intellij.ui.popup.list.GroupedItemsListRenderer;
import com.microsoft.azure.toolkit.intellij.common.AzureComboBox;
import com.microsoft.azure.toolkit.lib.appservice.model.Runtime;
import com.microsoft.azure.toolkit.lib.appservice.model.WebContainer;
import com.microsoft.azure.toolkit.lib.legacy.webapp.WebAppService;

import javax.annotation.Nonnull;
Expand Down Expand Up @@ -62,7 +63,11 @@ protected boolean hasSeparator(Runtime value, int index) {
}

private String getSeparatorCaption(Runtime item) {
return item.isDocker() ? "Docker" : String.format("%s & %s", item.getOperatingSystem().toString(), item.getJavaVersion().toString());
if (item.isDocker()) {
return "Docker";
}
return Objects.equals(item.getWebContainer(), WebContainer.JAVA_OFF) ? item.getOperatingSystem().toString() :
String.format("%s & %s", item.getOperatingSystem().toString(), item.getJavaVersion().toString());
}

class RuntimeItemDescriptor extends ListItemDescriptorAdapter<Runtime> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.intellij.ui.components.fields.ExtendableTextComponent;
import com.microsoft.azure.toolkit.intellij.common.AzureComboBox;
import com.microsoft.azure.toolkit.lib.appservice.model.PricingTier;
import org.apache.commons.lang3.StringUtils;

import javax.annotation.Nonnull;
import java.util.Collections;
Expand Down Expand Up @@ -38,8 +39,9 @@ protected String getItemText(final Object item) {
return EMPTY_ITEM;
}
final PricingTier pricingTier = (PricingTier) item;
return Objects.equals(pricingTier, PricingTier.CONSUMPTION) ?
message("appService.pricingTier.consumption") : pricingTier.getTier() + "_" + pricingTier.getSize();
// todo: move display name method to toolkit lib to share among azure tooling
return pricingTier.isConsumption() || pricingTier.isFlexConsumption() ? pricingTier.toString() :
String.format("%s %s", StringUtils.capitalize(pricingTier.getTier()), StringUtils.upperCase(pricingTier.getSize()));
}

@Nonnull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import com.microsoft.azure.toolkit.lib.appservice.function.AzureFunctions;
import com.microsoft.azure.toolkit.lib.appservice.function.FunctionApp;
import com.microsoft.azure.toolkit.lib.appservice.function.FunctionAppBase;
import com.microsoft.azure.toolkit.lib.appservice.model.FlexConsumptionConfiguration;
import com.microsoft.azure.toolkit.lib.appservice.model.Runtime;
import com.microsoft.azure.toolkit.lib.appservice.task.CreateOrUpdateFunctionAppTask;
import com.microsoft.azure.toolkit.lib.appservice.task.DeployFunctionAppTask;
Expand Down Expand Up @@ -45,6 +46,7 @@ public FunctionAppConfig getFunctionAppConfigFromExistingFunction(@Nonnull final
.diagnosticConfig(functionApp.getDiagnosticConfig())
.applicationInsightsConfig(ApplicationInsightsConfig.builder().instrumentationKey(applicationInsightsKey).build())
.build();
final FlexConsumptionConfiguration flexConsumptionConfiguration = functionApp.getFlexConsumptionConfiguration();
return FunctionAppConfig.builder()
.resourceId(functionApp.getId())
.name(functionApp.getName())
Expand All @@ -54,6 +56,7 @@ public FunctionAppConfig getFunctionAppConfigFromExistingFunction(@Nonnull final
.subscription(functionApp.getSubscription())
.appSettings(functionApp.getAppSettings())
.monitorConfig(monitorConfig)
.flexConsumptionConfiguration(flexConsumptionConfiguration)
.servicePlan(AppServicePlanConfig.fromResource(functionApp.getAppServicePlan())).build();
}

Expand Down Expand Up @@ -91,6 +94,8 @@ private com.microsoft.azure.toolkit.lib.appservice.config.FunctionAppConfig conv
result.deploymentSlotConfigurationSource(slot.getConfigurationSource());
});
Optional.ofNullable(config.getMonitorConfig()).map(MonitorConfig::getDiagnosticConfig).ifPresent(result::diagnosticConfig);
// currently ide did not support set flex consumption options, so use default values
Optional.ofNullable(config.getFlexConsumptionConfiguration()).ifPresent(result::flexConsumptionConfiguration);
return result;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*/

package com.microsoft.azure.toolkit.intellij.cosmos.code.function;

import com.intellij.openapi.util.TextRange;
import com.intellij.psi.*;
import com.intellij.util.ProcessingContext;
import com.microsoft.azure.toolkit.intellij.connector.Connection;
import com.microsoft.azure.toolkit.intellij.connector.code.function.FunctionAnnotationResourceReference;
import com.microsoft.azure.toolkit.lib.common.model.AzResource;
import com.microsoft.azure.toolkit.lib.cosmos.sql.SqlDatabase;
import org.apache.commons.lang.StringUtils;

import javax.annotation.Nonnull;
import java.util.Optional;
import java.util.function.BiFunction;

import static com.intellij.patterns.PsiJavaPatterns.psiElement;
import static com.microsoft.azure.toolkit.intellij.cosmos.code.function.CosmosDBContainerNameCompletionProvider.COSMOS_CONTAINER_NAME_PAIR_PATTERN;
import static com.microsoft.azure.toolkit.intellij.cosmos.code.function.CosmosDBDatabaseNameCompletionProvider.COSMOS_DATABASE_NAME_PAIR_PATTERN;

public class AzureCosmosDBResourceReferenceContributor extends PsiReferenceContributor {
@Override
public void registerReferenceProviders(@Nonnull PsiReferenceRegistrar registrar) {
registrar.registerReferenceProvider(psiElement(PsiLiteralExpression.class).withParent(COSMOS_DATABASE_NAME_PAIR_PATTERN), new PsiReferenceProvider() {
@Override
public PsiReference[] getReferencesByElement(@Nonnull PsiElement element, @Nonnull ProcessingContext context) {
final PsiLiteralExpression literal = (PsiLiteralExpression) element;
final String value = literal.getValue() instanceof String ? (String) literal.getValue() : StringUtils.EMPTY;
if (StringUtils.isNotBlank(value)) {
final TextRange range = new TextRange(1, value.length() + 1);
return new PsiReference[]{new FunctionAnnotationResourceReference(element, range,
(ann, con) -> CosmosDBDatabaseNameCompletionProvider.getConnectedDatabase(ann))};
}
return PsiReference.EMPTY_ARRAY;
}
});
registrar.registerReferenceProvider(psiElement(PsiLiteralExpression.class).withParent(COSMOS_CONTAINER_NAME_PAIR_PATTERN), new PsiReferenceProvider() {
@Override
public PsiReference[] getReferencesByElement(@Nonnull PsiElement element, @Nonnull ProcessingContext context) {
final PsiLiteralExpression literal = (PsiLiteralExpression) element;
final String value = literal.getValue() instanceof String ? (String) literal.getValue() : StringUtils.EMPTY;
final BiFunction<PsiAnnotation, Connection<?, ?>, AzResource> function = (annotation, connection) -> {
final SqlDatabase database = CosmosDBDatabaseNameCompletionProvider.getConnectedDatabase(annotation);
return Optional.ofNullable(database).map(d -> d.containers().get(value, database.getResourceGroupName())).orElse(null);
};
if (StringUtils.isNotBlank(value)) {
final TextRange range = new TextRange(1, value.length() + 1);
return new PsiReference[]{new FunctionAnnotationResourceReference(element, range, function)};
}
return PsiReference.EMPTY_ARRAY;
}
});
}
}
Loading

0 comments on commit 5a9cef2

Please sign in to comment.