Search in sources :

Example 1 with WebAppArtifact

use of com.microsoft.azure.toolkit.lib.appservice.model.WebAppArtifact in project azure-maven-plugins by microsoft.

the class ConfigParser method convertOneDeployResourceToArtifacts.

private static List<WebAppArtifact> convertOneDeployResourceToArtifacts(Resource resource) {
    final List<File> artifacts = MavenArtifactUtils.getArtifacts(resource);
    final String typeString = ((DeploymentResource) resource).getType();
    final DeployType type = DeployType.fromString(typeString);
    Objects.requireNonNull(type, () -> String.format("Unsupported resource type '%s', please change to one from this list: %s", typeString, DeployType.values().stream().map(Object::toString).map(StringUtils::lowerCase).collect(Collectors.joining(", "))));
    if (type.requireSingleFile() && artifacts.size() > 1) {
        throw new AzureToolkitRuntimeException(String.format("Multiple files are found for resource type('%s'), only one file is allowed.", type));
    }
    if (artifacts.isEmpty()) {
        Log.warn(String.format("Cannot find any files defined by resource(%s)", StringUtils.firstNonBlank(resource.toString())));
    }
    if (type.ignorePath() && StringUtils.isNotBlank(resource.getTargetPath())) {
        throw new AzureToolkitRuntimeException(String.format("'<targetPath>' is not allowed for deployable type('%s').", type));
    }
    if (StringUtils.isNotBlank(type.getFileExt())) {
        final String expectFileExtension = type.getFileExt();
        for (final File file : artifacts) {
            if (!StringUtils.equalsIgnoreCase(FilenameUtils.getExtension(file.getName()), expectFileExtension)) {
                throw new AzureToolkitRuntimeException(String.format("Wrong file '%s' Deployable type('%s'), expected file type '%s'", file, type, expectFileExtension));
            }
        }
    }
    return artifacts.stream().map(file -> WebAppArtifact.builder().file(file).deployType(type).path(getRemotePath(type, resource, file)).build()).collect(Collectors.toList());
}
Also used : DeployType(com.microsoft.azure.toolkit.lib.appservice.model.DeployType) AzureExecutionException(com.microsoft.azure.toolkit.lib.common.exception.AzureExecutionException) AppServiceConfig(com.microsoft.azure.toolkit.lib.appservice.config.AppServiceConfig) AbstractWebAppMojo(com.microsoft.azure.maven.webapp.AbstractWebAppMojo) PricingTier(com.microsoft.azure.toolkit.lib.appservice.model.PricingTier) ExpandableParameter(com.microsoft.azure.toolkit.lib.common.model.ExpandableParameter) StringUtils(org.apache.commons.lang3.StringUtils) Function(java.util.function.Function) CollectionUtils(org.apache.commons.collections4.CollectionUtils) Region(com.microsoft.azure.toolkit.lib.common.model.Region) Matcher(java.util.regex.Matcher) WebContainer(com.microsoft.azure.toolkit.lib.appservice.model.WebContainer) Nonnull(javax.annotation.Nonnull) MavenArtifactUtils(com.microsoft.azure.maven.utils.MavenArtifactUtils) 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) JavaVersion(com.microsoft.azure.toolkit.lib.appservice.model.JavaVersion) DeploymentResource(com.microsoft.azure.maven.model.DeploymentResource) WebAppArtifact(com.microsoft.azure.toolkit.lib.appservice.model.WebAppArtifact) Collectors(java.util.stream.Collectors) File(java.io.File) RuntimeConfig(com.microsoft.azure.toolkit.lib.appservice.config.RuntimeConfig) Deployment(com.microsoft.azure.maven.webapp.configuration.Deployment) Objects(java.util.Objects) MavenRuntimeConfig(com.microsoft.azure.maven.webapp.configuration.MavenRuntimeConfig) List(java.util.List) Resource(org.apache.maven.model.Resource) Paths(java.nio.file.Paths) DeploymentSlotConfig(com.microsoft.azure.maven.webapp.configuration.DeploymentSlotConfig) Optional(java.util.Optional) Log(com.microsoft.azure.toolkit.lib.common.logging.Log) DeployType(com.microsoft.azure.toolkit.lib.appservice.model.DeployType) OperatingSystem(com.microsoft.azure.toolkit.lib.appservice.model.OperatingSystem) Collections(java.util.Collections) WebAppConfiguration(com.microsoft.azure.maven.webapp.WebAppConfiguration) FilenameUtils(org.apache.commons.io.FilenameUtils) MavenDockerCredentialProvider(com.microsoft.azure.maven.MavenDockerCredentialProvider) DeploymentResource(com.microsoft.azure.maven.model.DeploymentResource) AzureToolkitRuntimeException(com.microsoft.azure.toolkit.lib.common.exception.AzureToolkitRuntimeException) File(java.io.File)

Example 2 with WebAppArtifact

use of com.microsoft.azure.toolkit.lib.appservice.model.WebAppArtifact in project azure-gradle-plugins by microsoft.

the class DeployTask method parseConfiguration.

private GradleWebAppConfig parseConfiguration() {
    final AzureWebappPluginExtension ctx = this.azureWebappExtension;
    GradleWebAppConfig config = new GradleWebAppConfig();
    config.subscriptionId(ctx.getSubscription());
    config.resourceGroup(ctx.getResourceGroup());
    config.appName(ctx.getAppName());
    config.pricingTier(ctx.getPricingTier());
    config.region(ctx.getRegion());
    config.runtime(ctx.getRuntime());
    config.appSettings(ctx.getAppSettings());
    config.servicePlanName(ctx.getAppServicePlanName());
    config.servicePlanResourceGroup(ctx.getAppServicePlanResourceGroup());
    config.deploymentSlotName(Optional.ofNullable(ctx.getDeploymentSlot()).map(GradleDeploymentSlotConfig::name).orElse(null));
    config.deploymentSlotConfigurationSource(Optional.ofNullable(ctx.getDeploymentSlot()).map(GradleDeploymentSlotConfig::configurationSource).orElse(null));
    if (StringUtils.isNotBlank(this.artifactFile)) {
        File file = new File(this.artifactFile);
        if (!file.exists()) {
            throw new AzureToolkitRuntimeException(String.format("artifact file(%s) cannot be found.", file.getAbsolutePath()));
        }
        final WebAppArtifact webAppArtifact = WebAppArtifact.builder().deployType(Utils.getDeployTypeByFileExtension(file)).file(file).build();
        config.webAppArtifacts(Collections.singletonList(webAppArtifact));
    }
    return config;
}
Also used : GradleDeploymentSlotConfig(com.microsoft.azure.gradle.configuration.GradleDeploymentSlotConfig) GradleWebAppConfig(com.microsoft.azure.gradle.configuration.GradleWebAppConfig) AzureToolkitRuntimeException(com.microsoft.azure.toolkit.lib.common.exception.AzureToolkitRuntimeException) File(java.io.File) WebAppArtifact(com.microsoft.azure.toolkit.lib.appservice.model.WebAppArtifact)

Aggregations

WebAppArtifact (com.microsoft.azure.toolkit.lib.appservice.model.WebAppArtifact)2 AzureToolkitRuntimeException (com.microsoft.azure.toolkit.lib.common.exception.AzureToolkitRuntimeException)2 File (java.io.File)2 GradleDeploymentSlotConfig (com.microsoft.azure.gradle.configuration.GradleDeploymentSlotConfig)1 GradleWebAppConfig (com.microsoft.azure.gradle.configuration.GradleWebAppConfig)1 MavenDockerCredentialProvider (com.microsoft.azure.maven.MavenDockerCredentialProvider)1 DeploymentResource (com.microsoft.azure.maven.model.DeploymentResource)1 MavenArtifactUtils (com.microsoft.azure.maven.utils.MavenArtifactUtils)1 AbstractWebAppMojo (com.microsoft.azure.maven.webapp.AbstractWebAppMojo)1 WebAppConfiguration (com.microsoft.azure.maven.webapp.WebAppConfiguration)1 Deployment (com.microsoft.azure.maven.webapp.configuration.Deployment)1 DeploymentSlotConfig (com.microsoft.azure.maven.webapp.configuration.DeploymentSlotConfig)1 MavenRuntimeConfig (com.microsoft.azure.maven.webapp.configuration.MavenRuntimeConfig)1 AppServiceConfig (com.microsoft.azure.toolkit.lib.appservice.config.AppServiceConfig)1 RuntimeConfig (com.microsoft.azure.toolkit.lib.appservice.config.RuntimeConfig)1 DeployType (com.microsoft.azure.toolkit.lib.appservice.model.DeployType)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