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();
}
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;
}
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;
}
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();
}
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();
}
Aggregations