Search in sources :

Example 1 with GradleRuntimeConfig

use of com.microsoft.azure.gradle.configuration.GradleRuntimeConfig in project azure-gradle-plugins by microsoft.

the class DeployHandler method validateParameters.

protected void validateParameters() {
    // app name
    final String appName = ctx.getAppName();
    if (StringUtils.isBlank(appName)) {
        throw new AzureToolkitRuntimeException(EMPTY_APP_NAME);
    }
    if (appName.startsWith("-") || !appName.matches(APP_NAME_PATTERN)) {
        throw new AzureToolkitRuntimeException(INVALID_APP_NAME);
    }
    final String resourceGroup = ctx.getResourceGroup();
    // resource group
    if (StringUtils.isBlank(resourceGroup)) {
        throw new AzureToolkitRuntimeException(EMPTY_RESOURCE_GROUP);
    }
    if (resourceGroup.endsWith(".") || !resourceGroup.matches(RESOURCE_GROUP_PATTERN)) {
        throw new AzureToolkitRuntimeException(INVALID_RESOURCE_GROUP_NAME);
    }
    final String appServicePlanName = ctx.getAppServicePlanName();
    // asp name & resource group
    if (StringUtils.isNotEmpty(appServicePlanName) && !appServicePlanName.matches(APP_SERVICE_PLAN_NAME_PATTERN)) {
        throw new AzureToolkitRuntimeException(String.format(INVALID_SERVICE_PLAN_NAME, APP_SERVICE_PLAN_NAME_PATTERN));
    }
    final String appServicePlanResourceGroup = ctx.getAppServicePlanResourceGroup();
    if (StringUtils.isNotEmpty(appServicePlanResourceGroup) && (appServicePlanResourceGroup.endsWith(".") || !appServicePlanResourceGroup.matches(RESOURCE_GROUP_PATTERN))) {
        throw new AzureToolkitRuntimeException(INVALID_SERVICE_PLAN_RESOURCE_GROUP_NAME);
    }
    final String region = ctx.getRegion();
    if (StringUtils.isNotEmpty(region) && Region.fromName(region).isExpandedValue()) {
        // allow arbitrary region since the region can be changed
        AzureMessager.getMessager().warning(AzureString.format(EXPANDABLE_REGION_WARNING, region));
    }
    final GradleRuntimeConfig runtime = ctx.getRuntime();
    if (runtime != null) {
        // os
        if (StringUtils.isNotEmpty(runtime.os()) && OperatingSystem.fromString(runtime.os()) == null) {
            throw new AzureToolkitRuntimeException(INVALID_OS);
        }
        // java version
        if (StringUtils.isNotEmpty(runtime.javaVersion()) && JavaVersion.fromString(runtime.javaVersion()).isExpandedValue()) {
            AzureMessager.getMessager().warning(AzureString.format(EXPANDABLE_JAVA_VERSION_WARNING, runtime.javaVersion()));
        }
    }
    final String pricingTier = ctx.getPricingTier();
    // pricing tier
    if (StringUtils.isNotEmpty(pricingTier) && PricingTier.fromString(pricingTier) == null) {
        throw new AzureToolkitRuntimeException(String.format(EXPANDABLE_PRICING_TIER_WARNING, pricingTier));
    }
    validateApplicationInsightsConfiguration();
}
Also used : GradleRuntimeConfig(com.microsoft.azure.gradle.configuration.GradleRuntimeConfig) AzureToolkitRuntimeException(com.microsoft.azure.toolkit.lib.common.exception.AzureToolkitRuntimeException) AzureString(com.microsoft.azure.toolkit.lib.common.bundle.AzureString)

Example 2 with GradleRuntimeConfig

use of com.microsoft.azure.gradle.configuration.GradleRuntimeConfig in project azure-gradle-plugins by microsoft.

the class DeployHandler method getRuntimeConfig.

private RuntimeConfig getRuntimeConfig() {
    final GradleRuntimeConfig runtime = ctx.getRuntime();
    if (runtime == null) {
        return null;
    }
    final OperatingSystem os = Optional.ofNullable(runtime.os()).map(OperatingSystem::fromString).orElse(null);
    final JavaVersion javaVersion = Optional.ofNullable(runtime.javaVersion()).map(JavaVersion::fromString).orElse(null);
    return new RuntimeConfig().os(os).javaVersion(javaVersion).webContainer(WebContainer.JAVA_OFF).image(runtime.image()).registryUrl(runtime.registryUrl()).username(runtime.username()).password(runtime.password());
}
Also used : OperatingSystem(com.microsoft.azure.toolkit.lib.appservice.model.OperatingSystem) GradleRuntimeConfig(com.microsoft.azure.gradle.configuration.GradleRuntimeConfig) RuntimeConfig(com.microsoft.azure.toolkit.lib.appservice.config.RuntimeConfig) GradleRuntimeConfig(com.microsoft.azure.gradle.configuration.GradleRuntimeConfig) JavaVersion(com.microsoft.azure.toolkit.lib.appservice.model.JavaVersion)

Example 3 with GradleRuntimeConfig

use of com.microsoft.azure.gradle.configuration.GradleRuntimeConfig in project azure-gradle-plugins by microsoft.

the class AzureWebappPluginExtension method getTelemetryProperties.

public Map<String, String> getTelemetryProperties() {
    final Map<String, String> result = new HashMap<>();
    final GradleRuntimeConfig runtime = getRuntime();
    final String os = java.util.Optional.ofNullable(runtime).map(GradleRuntimeConfig::os).orElse(null);
    result.put(OS_KEY, os);
    result.put(JAVA_VERSION_KEY, java.util.Optional.ofNullable(runtime).map(GradleRuntimeConfig::javaVersion).orElse(null));
    result.put(JAVA_WEB_CONTAINER_KEY, java.util.Optional.ofNullable(runtime).map(GradleRuntimeConfig::webContainer).orElse(null));
    result.put(PRICING_TIER_KEY, pricingTier);
    result.put(REGION_KEY, region);
    if (runtime != null && StringUtils.equalsIgnoreCase(os, OperatingSystem.DOCKER.getValue())) {
        final boolean isCustomRegistry = StringUtils.isNotEmpty(runtime.registryUrl());
        final DockerImageType imageType;
        if (isCustomRegistry) {
            imageType = StringUtils.isEmpty(runtime.password()) ? DockerImageType.PRIVATE_REGISTRY : DockerImageType.UNKNOWN;
        } else {
            imageType = StringUtils.isEmpty(runtime.password()) ? DockerImageType.PRIVATE_DOCKER_HUB : DockerImageType.PUBLIC_DOCKER_HUB;
        }
        result.put(DOCKER_IMAGE_TYPE_KEY, imageType.name());
    } else {
        result.put(DOCKER_IMAGE_TYPE_KEY, DockerImageType.NONE.toString());
    }
    final boolean isDeployToSlot = java.util.Optional.ofNullable(getDeploymentSlot()).map(GradleDeploymentSlotConfig::name).map(StringUtils::isNotEmpty).orElse(false);
    result.put(DEPLOY_TO_SLOT_KEY, String.valueOf(isDeployToSlot));
    result.put(SKIP_CREATE_RESOURCE_KEY, System.getProperty("azure.resource.create.skip", "false"));
    return result;
}
Also used : GradleRuntimeConfig(com.microsoft.azure.gradle.configuration.GradleRuntimeConfig) DockerImageType(com.microsoft.azure.toolkit.lib.legacy.appservice.DockerImageType) GradleDeploymentSlotConfig(com.microsoft.azure.gradle.configuration.GradleDeploymentSlotConfig) HashMap(java.util.HashMap)

Example 4 with GradleRuntimeConfig

use of com.microsoft.azure.gradle.configuration.GradleRuntimeConfig in project azure-gradle-plugins by microsoft.

the class AzureWebappPluginExtension method setRuntime.

public void setRuntime(Closure closure) {
    runtime = new GradleRuntimeConfig();
    project.configure(runtime, closure);
}
Also used : GradleRuntimeConfig(com.microsoft.azure.gradle.configuration.GradleRuntimeConfig)

Example 5 with GradleRuntimeConfig

use of com.microsoft.azure.gradle.configuration.GradleRuntimeConfig in project azure-gradle-plugins by microsoft.

the class AzureFunctionsExtension method setRuntime.

public void setRuntime(Closure closure) {
    runtime = new GradleRuntimeConfig();
    project.configure(runtime, closure);
}
Also used : GradleRuntimeConfig(com.microsoft.azure.gradle.configuration.GradleRuntimeConfig)

Aggregations

GradleRuntimeConfig (com.microsoft.azure.gradle.configuration.GradleRuntimeConfig)6 HashMap (java.util.HashMap)2 GradleDeploymentSlotConfig (com.microsoft.azure.gradle.configuration.GradleDeploymentSlotConfig)1 RuntimeConfig (com.microsoft.azure.toolkit.lib.appservice.config.RuntimeConfig)1 JavaVersion (com.microsoft.azure.toolkit.lib.appservice.model.JavaVersion)1 OperatingSystem (com.microsoft.azure.toolkit.lib.appservice.model.OperatingSystem)1 AzureString (com.microsoft.azure.toolkit.lib.common.bundle.AzureString)1 AzureToolkitRuntimeException (com.microsoft.azure.toolkit.lib.common.exception.AzureToolkitRuntimeException)1 DockerImageType (com.microsoft.azure.toolkit.lib.legacy.appservice.DockerImageType)1