Search in sources :

Example 1 with IFunctionApp

use of com.microsoft.azure.toolkit.lib.appservice.service.IFunctionApp in project azure-tools-for-java by Microsoft.

the class FunctionAppService method createFunctionApp.

public IFunctionApp createFunctionApp(final FunctionAppConfig config) {
    AzureTelemetry.getActionContext().setProperty(CREATE_NEW_FUNCTION_APP, String.valueOf(true));
    final ResourceGroup resourceGroup = getOrCreateResourceGroup(config);
    final IAppServicePlan appServicePlan = getOrCreateAppServicePlan(config);
    AzureMessager.getMessager().info(String.format(CREATE_FUNCTION_APP, config.getName()));
    final Map<String, String> appSettings = getAppSettings(config);
    // get/create ai instances only if user didn't specify ai connection string in app settings
    AzureTelemetry.getActionContext().setProperty(DISABLE_APP_INSIGHTS, String.valueOf(config.getMonitorConfig().getApplicationInsightsConfig() == null));
    bindApplicationInsights(appSettings, config);
    final IFunctionApp result = Azure.az(AzureAppService.class).subscription(config.getSubscription()).functionApp(resourceGroup.getName(), config.getName()).create().withName(config.getName()).withResourceGroup(resourceGroup.getName()).withPlan(appServicePlan.id()).withRuntime(config.getRuntime()).withAppSettings(appSettings).withDiagnosticConfig(config.getMonitorConfig().getDiagnosticConfig()).commit();
    AzureMessager.getMessager().info(String.format(CREATE_FUNCTION_APP_DONE, result.name()));
    return result;
}
Also used : IAppServicePlan(com.microsoft.azure.toolkit.lib.appservice.service.IAppServicePlan) IFunctionApp(com.microsoft.azure.toolkit.lib.appservice.service.IFunctionApp) ResourceGroup(com.microsoft.azure.toolkit.lib.common.model.ResourceGroup)

Example 2 with IFunctionApp

use of com.microsoft.azure.toolkit.lib.appservice.service.IFunctionApp in project azure-tools-for-java by Microsoft.

the class CreateFunctionAppAction method createFunctionApp.

@AzureOperation(name = "function.create_detail", params = { "config.getName()" }, type = AzureOperation.Type.ACTION)
private Single<IFunctionApp> createFunctionApp(final FunctionAppConfig config) {
    final AzureString title = title("function.create_detail", config.getName());
    final IntellijAzureMessager actionMessenger = new IntellijAzureMessager() {

        @Override
        public boolean show(IAzureMessage raw) {
            if (raw.getType() != IAzureMessage.Type.INFO) {
                return super.show(raw);
            }
            return false;
        }
    };
    final AzureTask<IFunctionApp> task = new AzureTask<>(null, title, false, () -> {
        final Operation operation = TelemetryManager.createOperation(TelemetryConstants.FUNCTION, TelemetryConstants.CREATE_FUNCTION_APP);
        operation.trackProperties(config.getTelemetryProperties());
        try {
            AzureMessager.getContext().setMessager(actionMessenger);
            final ProgressIndicator indicator = ProgressManager.getInstance().getProgressIndicator();
            indicator.setIndeterminate(true);
            return functionAppService.createFunctionApp(config);
        } finally {
            operation.trackProperties(AzureTelemetry.getActionContext().getProperties());
            operation.complete();
        }
    });
    return AzureTaskManager.getInstance().runInModalAsObservable(task).toSingle().doOnSuccess(app -> {
        AzureMessager.getMessager().success(message("function.create.success.message", app.name()), message("function.create.success.title"));
        this.refreshAzureExplorer(app);
    });
}
Also used : ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) IAzureMessage(com.microsoft.azure.toolkit.lib.common.messager.IAzureMessage) IntellijAzureMessager(com.microsoft.azure.toolkit.intellij.common.messager.IntellijAzureMessager) AzureOperation(com.microsoft.azure.toolkit.lib.common.operation.AzureOperation) Operation(com.microsoft.azuretools.telemetrywrapper.Operation) IFunctionApp(com.microsoft.azure.toolkit.lib.appservice.service.IFunctionApp) AzureTask(com.microsoft.azure.toolkit.lib.common.task.AzureTask) AzureString(com.microsoft.azure.toolkit.lib.common.bundle.AzureString) AzureOperation(com.microsoft.azure.toolkit.lib.common.operation.AzureOperation)

Example 3 with IFunctionApp

use of com.microsoft.azure.toolkit.lib.appservice.service.IFunctionApp in project azure-tools-for-java by Microsoft.

the class DeployFunctionAppAction method getRunConfigurationSettings.

private RunnerAndConfigurationSettings getRunConfigurationSettings(RunManagerEx manager) {
    final ConfigurationFactory factory = new FunctionDeploymentConfigurationFactory(functionType);
    final String runConfigurationName = String.format("%s: %s:%s", factory.getName(), project.getName(), functionNode.getName());
    RunnerAndConfigurationSettings settings = manager.findConfigurationByName(runConfigurationName);
    if (settings == null) {
        settings = manager.createConfiguration(runConfigurationName, factory);
    }
    final RunConfiguration runConfiguration = settings.getConfiguration();
    if (runConfiguration instanceof FunctionDeployConfiguration) {
        final IFunctionApp functionApp = Azure.az(AzureAppService.class).functionApp(functionNode.getId());
        final FunctionAppConfig config = FunctionAppService.getInstance().getFunctionAppConfigFromExistingFunction(functionApp);
        ((FunctionDeployConfiguration) runConfiguration).saveConfig(config);
    }
    return settings;
}
Also used : RunConfiguration(com.intellij.execution.configurations.RunConfiguration) FunctionAppConfig(com.microsoft.azure.toolkit.lib.function.FunctionAppConfig) AzureAppService(com.microsoft.azure.toolkit.lib.appservice.AzureAppService) ConfigurationFactory(com.intellij.execution.configurations.ConfigurationFactory) FunctionDeploymentConfigurationFactory(com.microsoft.azure.toolkit.intellij.function.runner.deploy.FunctionDeploymentConfigurationFactory) RunnerAndConfigurationSettings(com.intellij.execution.RunnerAndConfigurationSettings) FunctionDeployConfiguration(com.microsoft.azure.toolkit.intellij.function.runner.deploy.FunctionDeployConfiguration) IFunctionApp(com.microsoft.azure.toolkit.lib.appservice.service.IFunctionApp) FunctionDeploymentConfigurationFactory(com.microsoft.azure.toolkit.intellij.function.runner.deploy.FunctionDeploymentConfigurationFactory)

Example 4 with IFunctionApp

use of com.microsoft.azure.toolkit.lib.appservice.service.IFunctionApp in project azure-tools-for-java by Microsoft.

the class FunctionDeploymentState method createFunctionApp.

private IFunctionApp createFunctionApp(@NotNull RunProcessHandler processHandler) {
    IFunctionApp functionApp = Azure.az(AzureAppService.class).subscription(functionDeployConfiguration.getSubscriptionId()).functionApp(functionDeployConfiguration.getConfig().getResourceGroup().getName(), functionDeployConfiguration.getAppName());
    if (functionApp.exists()) {
        return functionApp;
    }
    processHandler.setText(message("function.create.hint.creating", functionDeployConfiguration.getAppName()));
    // Load app settings from security storage
    final FunctionAppConfig config = deployModel.getFunctionAppConfig();
    config.setAppSettings(FunctionUtils.loadAppSettingsFromSecurityStorage(functionDeployConfiguration.getAppSettingsKey()));
    // create function app
    functionApp = FunctionAppService.getInstance().createFunctionApp(config);
    // update run configuration
    functionDeployConfiguration.setFunctionId(functionApp.id());
    // Notify explorer refresh
    AzureUIRefreshCore.execute(new AzureUIRefreshEvent(AzureUIRefreshEvent.EventType.REFRESH, functionApp));
    processHandler.setText(message("function.create.hint.created", functionDeployConfiguration.getAppName()));
    return functionApp;
}
Also used : FunctionAppConfig(com.microsoft.azure.toolkit.lib.function.FunctionAppConfig) IFunctionApp(com.microsoft.azure.toolkit.lib.appservice.service.IFunctionApp) AzureUIRefreshEvent(com.microsoft.azuretools.utils.AzureUIRefreshEvent)

Example 5 with IFunctionApp

use of com.microsoft.azure.toolkit.lib.appservice.service.IFunctionApp in project azure-tools-for-java by Microsoft.

the class FunctionAppPropertyView method createPresenter.

@Override
protected WebAppBasePropertyViewPresenter createPresenter() {
    return new WebAppBasePropertyViewPresenter() {

        @Override
        protected IFunctionApp getWebAppBase(String subscriptionId, String functionAppId, String name) {
            return Azure.az(AzureAppService.class).subscription(subscriptionId).functionApp(functionAppId);
        }

        @Override
        protected void updateAppSettings(String subscriptionId, String functionAppId, String name, Map toUpdate, Set toRemove) {
            final IFunctionApp functionApp = getWebAppBase(subscriptionId, functionAppId, name);
            final IAppServiceUpdater appServiceUpdater = functionApp.update();
            appServiceUpdater.withAppSettings(toUpdate);
            toRemove.forEach(key -> appServiceUpdater.withoutAppSettings((String) key));
            appServiceUpdater.commit();
        }
    };
}
Also used : Set(java.util.Set) IAppServiceUpdater(com.microsoft.azure.toolkit.lib.appservice.service.IAppServiceUpdater) IFunctionApp(com.microsoft.azure.toolkit.lib.appservice.service.IFunctionApp) Map(java.util.Map) WebAppBasePropertyViewPresenter(com.microsoft.tooling.msservices.serviceexplorer.azure.webapp.base.WebAppBasePropertyViewPresenter)

Aggregations

IFunctionApp (com.microsoft.azure.toolkit.lib.appservice.service.IFunctionApp)6 AzureAppService (com.microsoft.azure.toolkit.lib.appservice.AzureAppService)2 AzureOperation (com.microsoft.azure.toolkit.lib.common.operation.AzureOperation)2 FunctionAppConfig (com.microsoft.azure.toolkit.lib.function.FunctionAppConfig)2 RunnerAndConfigurationSettings (com.intellij.execution.RunnerAndConfigurationSettings)1 ConfigurationFactory (com.intellij.execution.configurations.ConfigurationFactory)1 RunConfiguration (com.intellij.execution.configurations.RunConfiguration)1 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)1 IntellijAzureMessager (com.microsoft.azure.toolkit.intellij.common.messager.IntellijAzureMessager)1 FunctionDeployConfiguration (com.microsoft.azure.toolkit.intellij.function.runner.deploy.FunctionDeployConfiguration)1 FunctionDeploymentConfigurationFactory (com.microsoft.azure.toolkit.intellij.function.runner.deploy.FunctionDeploymentConfigurationFactory)1 IAppServicePlan (com.microsoft.azure.toolkit.lib.appservice.service.IAppServicePlan)1 IAppServiceUpdater (com.microsoft.azure.toolkit.lib.appservice.service.IAppServiceUpdater)1 AzureString (com.microsoft.azure.toolkit.lib.common.bundle.AzureString)1 IAzureMessage (com.microsoft.azure.toolkit.lib.common.messager.IAzureMessage)1 ResourceGroup (com.microsoft.azure.toolkit.lib.common.model.ResourceGroup)1 AzureTask (com.microsoft.azure.toolkit.lib.common.task.AzureTask)1 Operation (com.microsoft.azuretools.telemetrywrapper.Operation)1 AzureUIRefreshEvent (com.microsoft.azuretools.utils.AzureUIRefreshEvent)1 WebAppBasePropertyViewPresenter (com.microsoft.tooling.msservices.serviceexplorer.azure.webapp.base.WebAppBasePropertyViewPresenter)1