Skip to content

Commit 8d9145b

Browse files
authored
Merge pull request #5434 from microsoft/fix-function
Fix issues for function deployment
2 parents 43917bb + e2ce2f2 commit 8d9145b

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

PluginsAndFeatures/azure-toolkit-for-intellij/src/com/microsoft/azure/toolkit/intellij/function/runner/deploy/FunctionDeploymentState.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import com.microsoft.intellij.RunProcessHandler;
3434
import lombok.RequiredArgsConstructor;
3535
import org.apache.commons.collections4.CollectionUtils;
36+
import org.apache.commons.collections4.MapUtils;
3637
import org.apache.commons.lang.StringUtils;
3738
import org.jetbrains.annotations.NotNull;
3839
import org.jetbrains.annotations.Nullable;
@@ -48,6 +49,7 @@
4849
import java.time.Duration;
4950
import java.util.List;
5051
import java.util.Map;
52+
import java.util.Optional;
5153
import java.util.stream.Collectors;
5254

5355
import static com.microsoft.intellij.ui.messages.AzureBundle.message;
@@ -64,6 +66,7 @@ public class FunctionDeploymentState extends AzureRunProfileState<IFunctionApp>
6466
"because they are non-anonymous. To access the non-anonymous triggers, please refer https://aka.ms/azure-functions-key.";
6567
private static final String FAILED_TO_LIST_TRIGGERS = "Deployment succeeded, but failed to list http trigger urls.";
6668
private static final String SYNCING_TRIGGERS_AND_FETCH_FUNCTION_INFORMATION = "Syncing triggers and fetching function information...";
69+
private static final String NO_TRIGGERS_FOUNDED = "No triggers found in deployed function app";
6770

6871
private final FunctionDeployConfiguration functionDeployConfiguration;
6972
private final FunctionDeployModel deployModel;
@@ -90,6 +93,7 @@ public IFunctionApp executeSteps(@NotNull RunProcessHandler processHandler, @Not
9093
} else {
9194
functionApp = Azure.az(AzureAppService.class).subscription(functionDeployConfiguration.getSubscriptionId())
9295
.functionApp(functionDeployConfiguration.getFunctionId());
96+
updateApplicationSettings(functionApp);
9397
}
9498
stagingFolder = FunctionUtils.getTempStagingFolder();
9599
prepareStagingFolder(stagingFolder, processHandler, operation);
@@ -122,6 +126,16 @@ private IFunctionApp createFunctionApp(@NotNull RunProcessHandler processHandler
122126
return functionApp;
123127
}
124128

129+
private void updateApplicationSettings(IFunctionApp deployTarget) {
130+
final Map<String, String> applicationSettings = FunctionUtils.loadAppSettingsFromSecurityStorage(functionDeployConfiguration.getAppSettingsKey());
131+
if (MapUtils.isEmpty(applicationSettings)) {
132+
return;
133+
}
134+
AzureMessager.getMessager().info("Updating application settings...");
135+
deployTarget.update().withAppSettings(applicationSettings).commit();
136+
AzureMessager.getMessager().info("Update application settings successfully.");
137+
}
138+
125139
@AzureOperation(
126140
name = "function.prepare_staging_folder_detail",
127141
params = {"stagingFolder.getName()", "this.deployModel.getAppName()"},
@@ -229,7 +243,9 @@ private List<FunctionEntity> listFunctions(final IFunctionApp functionApp) {
229243
AzureMessager.getMessager().info(SYNCING_TRIGGERS_AND_FETCH_FUNCTION_INFORMATION);
230244
return Mono.fromCallable(() -> {
231245
functionApp.syncTriggers();
232-
return functionApp.listFunctions(true);
246+
return Optional.ofNullable(functionApp.listFunctions(true))
247+
.filter(CollectionUtils::isNotEmpty)
248+
.orElseThrow(() -> new AzureToolkitRuntimeException(NO_TRIGGERS_FOUNDED));
233249
}).retryWhen(Retry.withThrowable(flux ->
234250
flux.zipWith(Flux.range(1, LIST_TRIGGERS_MAX_RETRY + 1), (throwable, count) -> {
235251
if (count < LIST_TRIGGERS_MAX_RETRY) {

0 commit comments

Comments
 (0)