Search in sources :

Example 1 with AppServiceConfig

use of com.microsoft.azure.toolkit.lib.appservice.config.AppServiceConfig in project azure-maven-plugins by microsoft.

the class DeployMojo method createOrUpdateResource.

protected IFunctionAppBase<?> createOrUpdateResource(final FunctionAppConfig config) {
    IFunctionApp app = Azure.az(AzureAppService.class).functionApp(config.resourceGroup(), config.appName());
    final boolean newFunctionApp = !app.exists();
    AppServiceConfig defaultConfig = !newFunctionApp ? fromAppService(app, app.plan()) : buildDefaultConfig(config.subscriptionId(), config.resourceGroup(), config.appName());
    mergeAppServiceConfig(config, defaultConfig);
    if (!newFunctionApp && !config.disableAppInsights() && StringUtils.isEmpty(config.appInsightsKey())) {
        // fill ai key from existing app settings
        config.appInsightsKey(app.entity().getAppSettings().get(CreateOrUpdateFunctionAppTask.APPINSIGHTS_INSTRUMENTATION_KEY));
    }
    return new CreateOrUpdateFunctionAppTask(config).execute();
}
Also used : AppServiceConfig(com.microsoft.azure.toolkit.lib.appservice.config.AppServiceConfig) AppServiceConfigUtils.mergeAppServiceConfig(com.microsoft.azure.toolkit.lib.appservice.utils.AppServiceConfigUtils.mergeAppServiceConfig) AzureAppService(com.microsoft.azure.toolkit.lib.appservice.AzureAppService) CreateOrUpdateFunctionAppTask(com.microsoft.azure.toolkit.lib.appservice.task.CreateOrUpdateFunctionAppTask) IFunctionApp(com.microsoft.azure.toolkit.lib.appservice.service.IFunctionApp)

Example 2 with AppServiceConfig

use of com.microsoft.azure.toolkit.lib.appservice.config.AppServiceConfig in project azure-maven-plugins by microsoft.

the class AppServiceConfigUtils method buildDefaultFunctionConfig.

public static AppServiceConfig buildDefaultFunctionConfig(String subscriptionId, String resourceGroup, String appName, JavaVersion javaVersion) {
    final AppServiceConfig appServiceConfig = AppServiceConfig.buildDefaultFunctionConfig(resourceGroup, appName, javaVersion);
    final List<Region> regions = Azure.az(AzureAppService.class).listSupportedRegions(subscriptionId);
    // replace with first region when the default region is not present
    appServiceConfig.region(Utils.selectFirstOptionIfCurrentInvalid("region", regions, appServiceConfig.region()));
    return appServiceConfig;
}
Also used : AppServiceConfig(com.microsoft.azure.toolkit.lib.appservice.config.AppServiceConfig) AzureAppService(com.microsoft.azure.toolkit.lib.appservice.AzureAppService) Region(com.microsoft.azure.toolkit.lib.common.model.Region)

Example 3 with AppServiceConfig

use of com.microsoft.azure.toolkit.lib.appservice.config.AppServiceConfig in project azure-maven-plugins by microsoft.

the class AppServiceConfigUtils method fromAppService.

public static AppServiceConfig fromAppService(IAppService<?> appService, IAppServicePlan servicePlan) {
    AppServiceConfig config = new AppServiceConfig();
    config.appName(appService.name());
    config.resourceGroup(appService.entity().getResourceGroup());
    config.subscriptionId(Utils.getSubscriptionId(appService.id()));
    config.region(appService.entity().getRegion());
    config.pricingTier(servicePlan.entity().getPricingTier());
    RuntimeConfig runtimeConfig = new RuntimeConfig();
    if (AppServiceUtils.isDockerAppService(appService)) {
        runtimeConfig.os(OperatingSystem.DOCKER);
        final Map<String, String> settings = appService.entity().getAppSettings();
        final String imageSetting = settings.get(SETTING_DOCKER_IMAGE);
        if (StringUtils.isNotBlank(imageSetting)) {
            runtimeConfig.image(imageSetting);
        } else {
            runtimeConfig.image(appService.entity().getDockerImageName());
        }
        final String registryServerSetting = settings.get(SETTING_REGISTRY_SERVER);
        if (StringUtils.isNotBlank(registryServerSetting)) {
            runtimeConfig.registryUrl(registryServerSetting);
        }
    } else {
        runtimeConfig.os(appService.getRuntime().getOperatingSystem());
        runtimeConfig.webContainer(appService.getRuntime().getWebContainer());
        runtimeConfig.javaVersion(appService.getRuntime().getJavaVersion());
    }
    config.runtime(runtimeConfig);
    if (servicePlan.entity() != null) {
        config.pricingTier(servicePlan.entity().getPricingTier());
        config.servicePlanName(servicePlan.name());
        config.servicePlanResourceGroup(servicePlan.entity().getResourceGroup());
    }
    return config;
}
Also used : AppServiceConfig(com.microsoft.azure.toolkit.lib.appservice.config.AppServiceConfig) RuntimeConfig(com.microsoft.azure.toolkit.lib.appservice.config.RuntimeConfig)

Example 4 with AppServiceConfig

use of com.microsoft.azure.toolkit.lib.appservice.config.AppServiceConfig 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)

Example 5 with AppServiceConfig

use of com.microsoft.azure.toolkit.lib.appservice.config.AppServiceConfig in project azure-gradle-plugins by microsoft.

the class DeployTask method createOrUpdateWebapp.

private WebAppBase<?, ?, ?> createOrUpdateWebapp(GradleWebAppConfig config) {
    final AppServiceConfig appServiceConfig = convert(config);
    final WebApp app = Azure.az(AzureWebApp.class).webApps(appServiceConfig.subscriptionId()).get(appServiceConfig.resourceGroup(), appServiceConfig.appName());
    boolean skipCreate = BooleanUtils.toBoolean(System.getProperty("azure.resource.create.skip", "false"));
    final AppServiceConfig defaultConfig = app != null && app.exists() ? fromAppService(app, Objects.requireNonNull(app.getAppServicePlan())) : buildDefaultConfig(appServiceConfig.subscriptionId(), appServiceConfig.resourceGroup(), appServiceConfig.appName());
    mergeAppServiceConfig(appServiceConfig, defaultConfig);
    if (appServiceConfig.pricingTier() == null) {
        appServiceConfig.pricingTier(StringUtils.containsIgnoreCase(Objects.toString(appServiceConfig.runtime().webContainer()), "jboss") ? PricingTier.PREMIUM_P1V3 : PricingTier.PREMIUM_P1V2);
    }
    CreateOrUpdateWebAppTask task = new CreateOrUpdateWebAppTask(appServiceConfig);
    task.setSkipCreateAzureResource(skipCreate);
    return task.execute();
}
Also used : CreateOrUpdateWebAppTask(com.microsoft.azure.toolkit.lib.appservice.task.CreateOrUpdateWebAppTask) AppServiceConfig(com.microsoft.azure.toolkit.lib.appservice.config.AppServiceConfig) AppServiceConfigUtils.mergeAppServiceConfig(com.microsoft.azure.toolkit.lib.appservice.utils.AppServiceConfigUtils.mergeAppServiceConfig) WebApp(com.microsoft.azure.toolkit.lib.appservice.webapp.WebApp) AzureWebApp(com.microsoft.azure.toolkit.lib.appservice.webapp.AzureWebApp)

Aggregations

AppServiceConfig (com.microsoft.azure.toolkit.lib.appservice.config.AppServiceConfig)8 AzureAppService (com.microsoft.azure.toolkit.lib.appservice.AzureAppService)4 AppServiceConfigUtils.mergeAppServiceConfig (com.microsoft.azure.toolkit.lib.appservice.utils.AppServiceConfigUtils.mergeAppServiceConfig)4 Region (com.microsoft.azure.toolkit.lib.common.model.Region)3 RuntimeConfig (com.microsoft.azure.toolkit.lib.appservice.config.RuntimeConfig)2 CreateOrUpdateFunctionAppTask (com.microsoft.azure.toolkit.lib.appservice.task.CreateOrUpdateFunctionAppTask)2 CreateOrUpdateWebAppTask (com.microsoft.azure.toolkit.lib.appservice.task.CreateOrUpdateWebAppTask)2 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 DeploymentSlotConfig (com.microsoft.azure.maven.webapp.configuration.DeploymentSlotConfig)1 GradleFunctionContext (com.microsoft.azure.plugin.functions.gradle.GradleFunctionContext)1 Azure (com.microsoft.azure.toolkit.lib.Azure)1 FunctionAppConfig (com.microsoft.azure.toolkit.lib.appservice.config.FunctionAppConfig)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