Search in sources :

Example 1 with AzureAuthFailureException

use of com.microsoft.azure.maven.auth.AzureAuthFailureException in project azure-maven-plugins by microsoft.

the class ConfigMojo method config.

protected void config(WebAppConfiguration configuration) throws MojoFailureException, AzureExecutionException, IOException, IllegalAccessException {
    WebAppConfiguration result;
    do {
        if (configuration == null || !isProjectConfigured()) {
            try {
                result = chooseExistingWebappForConfiguration();
                if (result == null) {
                    result = initConfig();
                }
            } catch (AzureAuthFailureException e) {
                throw new AzureExecutionException(String.format("Cannot get Web App list due to error: %s.", e.getMessage()), e);
            }
        } else {
            result = updateConfiguration(configuration.toBuilder().build());
        }
    } while (!confirmConfiguration(result));
    Log.info(SAVING_TO_POM);
    pomHandler.updatePluginConfiguration(result, configuration);
}
Also used : AzureAuthFailureException(com.microsoft.azure.maven.auth.AzureAuthFailureException) AzureExecutionException(com.microsoft.azure.toolkit.lib.common.exception.AzureExecutionException)

Example 2 with AzureAuthFailureException

use of com.microsoft.azure.maven.auth.AzureAuthFailureException in project azure-maven-plugins by microsoft.

the class ConfigMojo method chooseExistingWebappForConfiguration.

private WebAppConfiguration chooseExistingWebappForConfiguration() throws AzureAuthFailureException {
    try {
        final AzureAppService az = getOrCreateAzureAppServiceClient();
        if (Objects.isNull(az)) {
            return null;
        }
        // get user selected sub id to persistent it in pom.xml
        this.subscriptionId = az.getDefaultSubscription().getId();
        // load configuration to detecting java or docker
        Log.info(LONG_LOADING_HINT);
        final List<WebAppOption> webAppOptionList = az.webapps().stream().map(WebAppOption::new).sorted().collect(Collectors.toList());
        // check empty: first time
        if (webAppOptionList.isEmpty()) {
            Log.warn(NO_JAVA_WEB_APPS);
            return null;
        }
        final boolean isContainer = !Utils.isJarPackagingProject(this.project.getPackaging());
        final boolean isDockerOnly = Utils.isPomPackagingProject(this.project.getPackaging());
        final List<WebAppOption> javaOrDockerWebapps = webAppOptionList.stream().filter(app -> app.isJavaWebApp() || app.isDockerWebapp()).filter(app -> checkWebAppVisible(isContainer, isDockerOnly, app.isJavaSE(), app.isDockerWebapp())).sorted().collect(Collectors.toList());
        final TextIO textIO = TextIoFactory.getTextIO();
        final WebAppOption selectedApp = selectAzureWebApp(textIO, javaOrDockerWebapps, getWebAppTypeByPackaging(this.project.getPackaging()), az.getDefaultSubscription());
        if (selectedApp == null || selectedApp.isCreateNew()) {
            return null;
        }
        final IWebApp webapp = az.webapp(selectedApp.getId());
        final WebAppConfiguration.WebAppConfigurationBuilder<?, ?> builder = WebAppConfiguration.builder();
        if (!AppServiceUtils.isDockerAppService(webapp)) {
            builder.resources(Deployment.getDefaultDeploymentConfiguration(getProject().getPackaging()).getResources());
        }
        return getConfigurationFromExisting(webapp, builder);
    } catch (AzureToolkitAuthenticationException ex) {
        // if is valid for config goal to have error in authentication
        getLog().warn(String.format("Cannot authenticate due to error: %s, select existing webapp is skipped.", ex.getMessage()));
        return null;
    }
}
Also used : Azure(com.microsoft.azure.toolkit.lib.Azure) AzureExecutionException(com.microsoft.azure.toolkit.lib.common.exception.AzureExecutionException) Arrays(java.util.Arrays) TextIO(org.beryx.textio.TextIO) AppServiceConfig(com.microsoft.azure.toolkit.lib.appservice.config.AppServiceConfig) Utils.findStringInCollectionIgnoreCase(com.microsoft.azure.maven.webapp.utils.Utils.findStringInCollectionIgnoreCase) StringUtils(org.apache.commons.lang3.StringUtils) MavenConfigUtils(com.microsoft.azure.maven.utils.MavenConfigUtils) WebAppPomHandler(com.microsoft.azure.maven.webapp.handlers.WebAppPomHandler) MavenPluginQueryer(com.microsoft.azure.maven.queryer.MavenPluginQueryer) Map(java.util.Map) WebContainer(com.microsoft.azure.toolkit.lib.appservice.model.WebContainer) SchemaVersion(com.microsoft.azure.maven.webapp.configuration.SchemaVersion) AppServiceUtils(com.microsoft.azure.toolkit.lib.legacy.appservice.AppServiceUtils) Runtime(com.microsoft.azure.toolkit.lib.appservice.model.Runtime) JavaVersion(com.microsoft.azure.toolkit.lib.appservice.model.JavaVersion) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) AzureAuthFailureException(com.microsoft.azure.maven.auth.AzureAuthFailureException) AzureToolkitAuthenticationException(com.microsoft.azure.toolkit.lib.auth.exception.AzureToolkitAuthenticationException) List(java.util.List) Stream(java.util.stream.Stream) TextUtils(com.microsoft.azure.toolkit.lib.common.utils.TextUtils) OperatingSystem(com.microsoft.azure.toolkit.lib.appservice.model.OperatingSystem) AppServiceConfigUtils.fromAppService(com.microsoft.azure.toolkit.lib.appservice.utils.AppServiceConfigUtils.fromAppService) QueryFactory(com.microsoft.azure.maven.queryer.QueryFactory) PricingTier(com.microsoft.azure.toolkit.lib.appservice.model.PricingTier) Xpp3Dom(org.codehaus.plexus.util.xml.Xpp3Dom) IWebApp(com.microsoft.azure.toolkit.lib.appservice.service.IWebApp) ArrayList(java.util.ArrayList) Region(com.microsoft.azure.toolkit.lib.common.model.Region) Mojo(org.apache.maven.plugins.annotations.Mojo) DocumentException(org.dom4j.DocumentException) WebAppOption(com.microsoft.azure.maven.webapp.models.WebAppOption) Utils(com.microsoft.azure.toolkit.lib.common.utils.Utils) ObjectUtils(org.apache.commons.lang3.ObjectUtils) TextIoFactory(org.beryx.textio.TextIoFactory) Nonnull(javax.annotation.Nonnull) Subscription(com.microsoft.azure.toolkit.lib.common.model.Subscription) AzureAppService(com.microsoft.azure.toolkit.lib.appservice.AzureAppService) AzureToolkitRuntimeException(com.microsoft.azure.toolkit.lib.common.exception.AzureToolkitRuntimeException) AzureMessager(com.microsoft.azure.toolkit.lib.common.messager.AzureMessager) DeploymentSlotSetting(com.microsoft.azure.toolkit.lib.legacy.appservice.DeploymentSlotSetting) IOException(java.io.IOException) MojoFailureException(org.apache.maven.plugin.MojoFailureException) Deployment(com.microsoft.azure.maven.webapp.configuration.Deployment) Log(com.microsoft.azure.toolkit.lib.common.logging.Log) CustomTextIoStringListReader(com.microsoft.azure.maven.utils.CustomTextIoStringListReader) Collections(java.util.Collections) AzureAppService(com.microsoft.azure.toolkit.lib.appservice.AzureAppService) WebAppOption(com.microsoft.azure.maven.webapp.models.WebAppOption) TextIO(org.beryx.textio.TextIO) AzureToolkitAuthenticationException(com.microsoft.azure.toolkit.lib.auth.exception.AzureToolkitAuthenticationException) IWebApp(com.microsoft.azure.toolkit.lib.appservice.service.IWebApp)

Aggregations

AzureAuthFailureException (com.microsoft.azure.maven.auth.AzureAuthFailureException)2 AzureExecutionException (com.microsoft.azure.toolkit.lib.common.exception.AzureExecutionException)2 MavenPluginQueryer (com.microsoft.azure.maven.queryer.MavenPluginQueryer)1 QueryFactory (com.microsoft.azure.maven.queryer.QueryFactory)1 CustomTextIoStringListReader (com.microsoft.azure.maven.utils.CustomTextIoStringListReader)1 MavenConfigUtils (com.microsoft.azure.maven.utils.MavenConfigUtils)1 Deployment (com.microsoft.azure.maven.webapp.configuration.Deployment)1 SchemaVersion (com.microsoft.azure.maven.webapp.configuration.SchemaVersion)1 WebAppPomHandler (com.microsoft.azure.maven.webapp.handlers.WebAppPomHandler)1 WebAppOption (com.microsoft.azure.maven.webapp.models.WebAppOption)1 Utils.findStringInCollectionIgnoreCase (com.microsoft.azure.maven.webapp.utils.Utils.findStringInCollectionIgnoreCase)1 Azure (com.microsoft.azure.toolkit.lib.Azure)1 AzureAppService (com.microsoft.azure.toolkit.lib.appservice.AzureAppService)1 AppServiceConfig (com.microsoft.azure.toolkit.lib.appservice.config.AppServiceConfig)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 IWebApp (com.microsoft.azure.toolkit.lib.appservice.service.IWebApp)1