Search in sources :

Example 1 with FunctionAppBase

use of com.microsoft.azure.toolkit.lib.appservice.function.FunctionAppBase in project azure-gradle-plugins by microsoft.

the class DeployHandler method createOrUpdateFunctionApp.

@Nonnull
private FunctionAppBase<?, ?, ?> createOrUpdateFunctionApp() throws AzureExecutionException {
    final FunctionApp app = getFunctionApp();
    final FunctionAppConfig functionConfig = (FunctionAppConfig) new FunctionAppConfig().disableAppInsights(ctx.isDisableAppInsights()).appInsightsKey(ctx.getAppInsightsKey()).appInsightsInstance(ctx.getAppInsightsInstance()).subscriptionId(ctx.getOrCreateAzureAppServiceClient().getSubscriptionId()).resourceGroup(ctx.getResourceGroup()).appName(ctx.getAppName()).servicePlanName(ctx.getAppServicePlanName()).servicePlanResourceGroup(ctx.getAppServicePlanResourceGroup()).deploymentSlotName(// gradle function plugin doesn't support deploy slot now
    ctx.getDeploymentSlotName()).deploymentSlotConfigurationSource(ctx.getDeploymentSlotConfigurationSource()).pricingTier(getParsedPricingTier()).region(getParsedRegion()).runtime(getRuntimeConfig()).appSettings(ctx.getAppSettings());
    final boolean createFunctionApp = Optional.ofNullable(app).map(function -> !function.exists()).orElse(true);
    final AppServiceConfig defaultConfig = createFunctionApp ? buildDefaultConfig(functionConfig.subscriptionId(), functionConfig.resourceGroup(), functionConfig.appName()) : fromAppService(app, Objects.requireNonNull(app.getAppServicePlan()));
    mergeAppServiceConfig(functionConfig, defaultConfig);
    if (!createFunctionApp && !functionConfig.disableAppInsights() && StringUtils.isBlank(functionConfig.appInsightsKey())) {
        // fill ai key from existing app settings
        final String aiKey = Optional.ofNullable(app.getAppSettings()).map(map -> map.get(CreateOrUpdateFunctionAppTask.APPINSIGHTS_INSTRUMENTATION_KEY)).orElse(null);
        functionConfig.appInsightsKey(aiKey);
    }
    validateArtifactCompileVersion(functionConfig.runtime());
    return new CreateOrUpdateFunctionAppTask(functionConfig).execute();
}
Also used : Azure(com.microsoft.azure.toolkit.lib.Azure) AzureExecutionException(com.microsoft.azure.toolkit.lib.common.exception.AzureExecutionException) AppServiceConfigUtils.fromAppService(com.microsoft.azure.toolkit.lib.appservice.utils.AppServiceConfigUtils.fromAppService) AzureOperation(com.microsoft.azure.toolkit.lib.common.operation.AzureOperation) Retry(reactor.util.retry.Retry) AppServiceConfig(com.microsoft.azure.toolkit.lib.appservice.config.AppServiceConfig) PricingTier(com.microsoft.azure.toolkit.lib.appservice.model.PricingTier) StringUtils(org.apache.commons.lang3.StringUtils) CollectionUtils(org.apache.commons.collections4.CollectionUtils) Region(com.microsoft.azure.toolkit.lib.common.model.Region) AzureEnvironment(com.azure.core.management.AzureEnvironment) FunctionApp(com.microsoft.azure.toolkit.lib.appservice.function.FunctionApp) Utils(com.microsoft.azure.toolkit.lib.common.utils.Utils) AuthorizationLevel(com.microsoft.azure.functions.annotation.AuthorizationLevel) Duration(java.time.Duration) WebContainer(com.microsoft.azure.toolkit.lib.appservice.model.WebContainer) AzureString(com.microsoft.azure.toolkit.lib.common.bundle.AzureString) Schedulers(reactor.core.scheduler.Schedulers) AppServiceConfigUtils(com.microsoft.azure.toolkit.lib.appservice.utils.AppServiceConfigUtils) ComparableVersion(org.apache.maven.artifact.versioning.ComparableVersion) ManagementFactory(java.lang.management.ManagementFactory) Nonnull(javax.annotation.Nonnull) ZipUtil(org.zeroturnaround.zip.ZipUtil) FunctionAppBase(com.microsoft.azure.toolkit.lib.appservice.function.FunctionAppBase) AzureToolkitRuntimeException(com.microsoft.azure.toolkit.lib.common.exception.AzureToolkitRuntimeException) AzureMessager(com.microsoft.azure.toolkit.lib.common.messager.AzureMessager) Runtime(com.microsoft.azure.toolkit.lib.appservice.model.Runtime) CreateOrUpdateFunctionAppTask(com.microsoft.azure.toolkit.lib.appservice.task.CreateOrUpdateFunctionAppTask) JavaVersion(com.microsoft.azure.toolkit.lib.appservice.model.JavaVersion) Mono(reactor.core.publisher.Mono) Collectors(java.util.stream.Collectors) AppServiceConfigUtils.mergeAppServiceConfig(com.microsoft.azure.toolkit.lib.appservice.utils.AppServiceConfigUtils.mergeAppServiceConfig) FunctionDeployType(com.microsoft.azure.toolkit.lib.appservice.model.FunctionDeployType) File(java.io.File) RuntimeConfig(com.microsoft.azure.toolkit.lib.appservice.config.RuntimeConfig) Objects(java.util.Objects) GradleRuntimeConfig(com.microsoft.azure.gradle.configuration.GradleRuntimeConfig) List(java.util.List) TelemetryAgent(com.microsoft.azure.gradle.temeletry.TelemetryAgent) AzureAccount(com.microsoft.azure.toolkit.lib.auth.AzureAccount) GradleFunctionContext(com.microsoft.azure.plugin.functions.gradle.GradleFunctionContext) Optional(java.util.Optional) Preconditions(com.google.common.base.Preconditions) FunctionAppConfig(com.microsoft.azure.toolkit.lib.appservice.config.FunctionAppConfig) OperatingSystem(com.microsoft.azure.toolkit.lib.appservice.model.OperatingSystem) FunctionEntity(com.microsoft.azure.toolkit.lib.appservice.entity.FunctionEntity) FunctionAppConfig(com.microsoft.azure.toolkit.lib.appservice.config.FunctionAppConfig) AppServiceConfig(com.microsoft.azure.toolkit.lib.appservice.config.AppServiceConfig) AppServiceConfigUtils.mergeAppServiceConfig(com.microsoft.azure.toolkit.lib.appservice.utils.AppServiceConfigUtils.mergeAppServiceConfig) CreateOrUpdateFunctionAppTask(com.microsoft.azure.toolkit.lib.appservice.task.CreateOrUpdateFunctionAppTask) AzureString(com.microsoft.azure.toolkit.lib.common.bundle.AzureString) FunctionApp(com.microsoft.azure.toolkit.lib.appservice.function.FunctionApp) Nonnull(javax.annotation.Nonnull)

Aggregations

AzureEnvironment (com.azure.core.management.AzureEnvironment)1 Preconditions (com.google.common.base.Preconditions)1 AuthorizationLevel (com.microsoft.azure.functions.annotation.AuthorizationLevel)1 GradleRuntimeConfig (com.microsoft.azure.gradle.configuration.GradleRuntimeConfig)1 TelemetryAgent (com.microsoft.azure.gradle.temeletry.TelemetryAgent)1 GradleFunctionContext (com.microsoft.azure.plugin.functions.gradle.GradleFunctionContext)1 Azure (com.microsoft.azure.toolkit.lib.Azure)1 AppServiceConfig (com.microsoft.azure.toolkit.lib.appservice.config.AppServiceConfig)1 FunctionAppConfig (com.microsoft.azure.toolkit.lib.appservice.config.FunctionAppConfig)1 RuntimeConfig (com.microsoft.azure.toolkit.lib.appservice.config.RuntimeConfig)1 FunctionEntity (com.microsoft.azure.toolkit.lib.appservice.entity.FunctionEntity)1 FunctionApp (com.microsoft.azure.toolkit.lib.appservice.function.FunctionApp)1 FunctionAppBase (com.microsoft.azure.toolkit.lib.appservice.function.FunctionAppBase)1 FunctionDeployType (com.microsoft.azure.toolkit.lib.appservice.model.FunctionDeployType)1 JavaVersion (com.microsoft.azure.toolkit.lib.appservice.model.JavaVersion)1 OperatingSystem (com.microsoft.azure.toolkit.lib.appservice.model.OperatingSystem)1 PricingTier (com.microsoft.azure.toolkit.lib.appservice.model.PricingTier)1 Runtime (com.microsoft.azure.toolkit.lib.appservice.model.Runtime)1 WebContainer (com.microsoft.azure.toolkit.lib.appservice.model.WebContainer)1 CreateOrUpdateFunctionAppTask (com.microsoft.azure.toolkit.lib.appservice.task.CreateOrUpdateFunctionAppTask)1