Search in sources :

Example 1 with AzureExecutionException

use of com.microsoft.azure.toolkit.lib.common.exception.AzureExecutionException in project azure-tools-for-java by Microsoft.

the class AzureLoginHelper method ensureAzureSubsAvailable.

public static void ensureAzureSubsAvailable() throws AzureExecutionException {
    if (!AuthMethodManager.getInstance().isSignedIn()) {
        throw new AzureExecutionException(NEED_SIGN_IN);
    }
    IdentityAzureManager azureManager = IdentityAzureManager.getInstance();
    final List<Subscription> subscriptions = azureManager.getSubscriptions();
    if (CollectionUtils.isEmpty(subscriptions)) {
        throw new AzureExecutionException(NO_SUBSCRIPTION);
    }
    final List<Subscription> selectedSubscriptions = azureManager.getSelectedSubscriptions();
    if (CollectionUtils.isEmpty(selectedSubscriptions)) {
        throw new AzureExecutionException(MUST_SELECT_SUBSCRIPTION);
    }
}
Also used : IdentityAzureManager(com.microsoft.azuretools.sdkmanage.IdentityAzureManager) AzureExecutionException(com.microsoft.azure.toolkit.lib.common.exception.AzureExecutionException) Subscription(com.microsoft.azure.toolkit.lib.common.model.Subscription)

Example 2 with AzureExecutionException

use of com.microsoft.azure.toolkit.lib.common.exception.AzureExecutionException in project azure-tools-for-java by Microsoft.

the class FunctionDeploymentState method prepareStagingFolder.

@AzureOperation(name = "function.prepare_staging_folder_detail", params = { "stagingFolder.getName()", "this.deployModel.getFunctionAppConfig().getName()" }, type = AzureOperation.Type.TASK)
private void prepareStagingFolder(File stagingFolder, RunProcessHandler processHandler, @NotNull final Operation operation) {
    AzureTaskManager.getInstance().read(() -> {
        final Path hostJsonPath = FunctionUtils.getDefaultHostJson(project);
        final PsiMethod[] methods = FunctionUtils.findFunctionsByAnnotation(functionDeployConfiguration.getModule());
        final Path folder = stagingFolder.toPath();
        try {
            final Map<String, FunctionConfiguration> configMap = FunctionUtils.prepareStagingFolder(folder, hostJsonPath, functionDeployConfiguration.getModule(), methods);
            operation.trackProperty(TelemetryConstants.TRIGGER_TYPE, StringUtils.join(FunctionUtils.getFunctionBindingList(configMap), ","));
        } catch (final AzureExecutionException | IOException e) {
            final String error = String.format("failed prepare staging folder[%s]", folder);
            throw new AzureToolkitRuntimeException(error, e);
        }
    });
}
Also used : Path(java.nio.file.Path) PsiMethod(com.intellij.psi.PsiMethod) AzureExecutionException(com.microsoft.azure.toolkit.lib.common.exception.AzureExecutionException) FunctionConfiguration(com.microsoft.azure.toolkit.lib.legacy.function.configurations.FunctionConfiguration) AzureToolkitRuntimeException(com.microsoft.azure.toolkit.lib.common.exception.AzureToolkitRuntimeException) AzureString(com.microsoft.azure.toolkit.lib.common.bundle.AzureString) IOException(java.io.IOException) AzureOperation(com.microsoft.azure.toolkit.lib.common.operation.AzureOperation)

Example 3 with AzureExecutionException

use of com.microsoft.azure.toolkit.lib.common.exception.AzureExecutionException in project azure-tools-for-java by Microsoft.

the class AnnotationHelper method getEnumConstantString.

private static String getEnumConstantString(PsiAnnotationMemberValue value) throws AzureExecutionException {
    if (value instanceof PsiReferenceExpression) {
        final PsiReferenceExpression referenceExpression = (PsiReferenceExpression) value;
        final Object resolved = referenceExpression.resolve();
        if (resolved instanceof PsiEnumConstant) {
            final PsiEnumConstant enumConstant = (PsiEnumConstant) resolved;
            final PsiClass enumClass = enumConstant.getContainingClass();
            if (enumClass != null) {
                try {
                    return getEnumFieldString(enumClass.getQualifiedName(), enumConstant.getName());
                } catch (ClassNotFoundException | IllegalAccessException e) {
                    throw new AzureExecutionException(e.getMessage(), e);
                }
            } else {
                return enumConstant.getName();
            }
        }
    }
    return null;
}
Also used : AzureExecutionException(com.microsoft.azure.toolkit.lib.common.exception.AzureExecutionException)

Example 4 with AzureExecutionException

use of com.microsoft.azure.toolkit.lib.common.exception.AzureExecutionException in project azure-tools-for-java by Microsoft.

the class AddDependencyAction method onActionPerformed.

@Override
public boolean onActionPerformed(@NotNull AnActionEvent event, @Nullable Operation operation) {
    final Module module = event.getData(LangDataKeys.MODULE);
    final Project project = module.getProject();
    final MavenProjectsManager projectsManager = MavenProjectsManager.getInstance(project);
    final MavenProject mavenProject = projectsManager.findProject(module);
    if (mavenProject == null) {
        PluginUtil.showErrorNotificationProject(project, "Error", String.format("Project '%s' is not a maven project.", project.getName()));
        return true;
    }
    final AzureString title = AzureOperationBundle.title("springcloud.update_dependency", project.getName());
    AzureTaskManager.getInstance().runInBackground(new AzureTask(project, title, true, () -> {
        ProgressIndicator progressIndicator = ProgressManager.getInstance().getProgressIndicator();
        progressIndicator.setText("Syncing maven project " + project.getName());
        final SettableFuture<Boolean> isDirty = SettableFuture.create();
        AzureTaskManager.getInstance().runAndWait(() -> {
            ProjectNotificationAware notificationAware = ProjectNotificationAware.getInstance(project);
            isDirty.set(notificationAware.isNotificationVisible());
            if (notificationAware.isNotificationVisible()) {
                ExternalSystemProjectTracker projectTracker = ExternalSystemProjectTracker.getInstance(project);
                projectTracker.scheduleProjectRefresh();
            }
        });
        try {
            if (isDirty.get().booleanValue()) {
                projectsManager.forceUpdateProjects(Collections.singletonList(mavenProject)).get();
            }
        } catch (InterruptedException | ExecutionException e) {
            PluginUtil.showErrorNotification("Error", "Failed to update project due to error: " + e.getMessage());
            return;
        }
        try {
            progressIndicator.setText("Check existing dependencies");
            final String evaluateEffectivePom = MavenUtils.evaluateEffectivePom(project, mavenProject);
            ProgressManager.checkCanceled();
            if (StringUtils.isEmpty(evaluateEffectivePom)) {
                PluginUtil.showErrorNotificationProject(project, "Error", "Failed to evaluate effective pom.");
                return;
            }
            final String springBootVer = getMavenLibraryVersion(mavenProject, SPRING_BOOT_GROUP_ID, "spring-boot-autoconfigure");
            if (StringUtils.isEmpty(springBootVer)) {
                throw new AzureExecutionException(String.format("Module %s is not a spring-boot application.", module.getName()));
            }
            progressIndicator.setText("Get latest versions ...");
            SpringCloudDependencyManager dependencyManager = new SpringCloudDependencyManager(evaluateEffectivePom);
            Map<String, DependencyArtifact> versionMaps = dependencyManager.getDependencyVersions();
            Map<String, DependencyArtifact> managerDependencyVersionsMaps = dependencyManager.getDependencyManagementVersions();
            // given the spring-cloud-commons is greater or equal to 2.2.5.RELEASE, we should not add spring-cloud-starter-azure-spring-cloud-client
            // because the code is already merged into spring repo: https://github.com/spring-cloud/spring-cloud-commons/pull/803
            boolean noAzureSpringCloudClientDependency = shouldNotAddAzureSpringCloudClientDependency(versionMaps) || shouldNotAddAzureSpringCloudClientDependency(managerDependencyVersionsMaps);
            ProgressManager.checkCanceled();
            final List<DependencyArtifact> versionChanges = calculateVersionChanges(springBootVer, noAzureSpringCloudClientDependency, versionMaps);
            if (versionChanges.isEmpty()) {
                PluginUtil.showInfoNotificationProject(project, "Your project is update-to-date.", "No updates are needed.");
                return;
            }
            progressIndicator.setText("Applying versions ...");
            final File pomFile = new File(mavenProject.getFile().getCanonicalPath());
            ProgressManager.checkCanceled();
            if (applyVersionChanges(dependencyManager, pomFile, springBootVer, managerDependencyVersionsMaps, versionChanges)) {
                noticeUserVersionChanges(project, pomFile, versionChanges);
            } else {
                PluginUtil.showInfoNotificationProject(project, "Your project is update-to-date.", "No updates are needed.");
            }
        } catch (DocumentException | IOException | AzureExecutionException | MavenProcessCanceledException e) {
            PluginUtil.showErrorNotification("Error", "Failed to update Azure Spring Cloud dependencies due to error: " + e.getMessage());
        }
    }));
    return false;
}
Also used : SettableFuture(com.google.common.util.concurrent.SettableFuture) MavenProjectsManager(org.jetbrains.idea.maven.project.MavenProjectsManager) AzureString(com.microsoft.azure.toolkit.lib.common.bundle.AzureString) AzureString(com.microsoft.azure.toolkit.lib.common.bundle.AzureString) Project(com.intellij.openapi.project.Project) MavenProject(org.jetbrains.idea.maven.project.MavenProject) ProjectNotificationAware(com.intellij.openapi.externalSystem.autoimport.ProjectNotificationAware) MavenProject(org.jetbrains.idea.maven.project.MavenProject) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) AzureExecutionException(com.microsoft.azure.toolkit.lib.common.exception.AzureExecutionException) ExternalSystemProjectTracker(com.intellij.openapi.externalSystem.autoimport.ExternalSystemProjectTracker) ArrayList(java.util.ArrayList) List(java.util.List) Module(com.intellij.openapi.module.Module) AzureTask(com.microsoft.azure.toolkit.lib.common.task.AzureTask) Map(java.util.Map) VirtualFile(com.intellij.openapi.vfs.VirtualFile) PsiFile(com.intellij.psi.PsiFile) File(java.io.File)

Example 5 with AzureExecutionException

use of com.microsoft.azure.toolkit.lib.common.exception.AzureExecutionException in project azure-tools-for-java by Microsoft.

the class SpringCloudDependencyManager method getCompatibleVersions.

public static List<DependencyArtifact> getCompatibleVersions(List<DependencyArtifact> dependencies, String springBootVersionStr) throws AzureExecutionException, IOException, DocumentException {
    List<DependencyArtifact> res = new ArrayList<>();
    DefaultArtifactVersion springBootVersion = new DefaultArtifactVersion(springBootVersionStr);
    for (DependencyArtifact dependency : dependencies) {
        if (StringUtils.isNotEmpty(dependency.getCurrentVersion()) && isCompatibleVersion(dependency.getCurrentVersion(), springBootVersionStr)) {
            continue;
        }
        List<String> latestVersions = getMavenCentralVersions(dependency.getGroupId(), dependency.getArtifactId());
        String targetVersionText = getCompatibleVersionWithBootVersion(latestVersions, springBootVersion);
        if (StringUtils.isEmpty(targetVersionText)) {
            if (isGreaterOrEqualVersion(springBootVersionStr, LATEST_SPRING_BOOT_RELEASE) && !latestVersions.isEmpty()) {
                // to handle the ege case: spring-cloud-starter-config 2.2.5.RELEASE supports spring boot 2.3.0
                // here for newest spring boot versions, use the latest versions
                targetVersionText = latestVersions.get(latestVersions.size() - 1);
            } else {
                throw new AzureExecutionException(String.format("Cannot get compatible version for %s:%s with Spring Boot with version %s", dependency.getGroupId(), dependency.getArtifactId(), springBootVersionStr));
            }
        }
        dependency.setCompatibleVersion(targetVersionText);
        if (!StringUtils.equals(dependency.getCurrentVersion(), targetVersionText)) {
            res.add(dependency);
        }
    }
    return res;
}
Also used : DependencyArtifact(com.microsoft.azure.toolkit.intellij.springcloud.dependency.DependencyArtifact) AzureExecutionException(com.microsoft.azure.toolkit.lib.common.exception.AzureExecutionException) DefaultArtifactVersion(org.apache.maven.artifact.versioning.DefaultArtifactVersion)

Aggregations

AzureExecutionException (com.microsoft.azure.toolkit.lib.common.exception.AzureExecutionException)9 AzureToolkitRuntimeException (com.microsoft.azure.toolkit.lib.common.exception.AzureToolkitRuntimeException)3 IOException (java.io.IOException)3 PsiFile (com.intellij.psi.PsiFile)2 PsiMethod (com.intellij.psi.PsiMethod)2 AzureString (com.microsoft.azure.toolkit.lib.common.bundle.AzureString)2 Subscription (com.microsoft.azure.toolkit.lib.common.model.Subscription)2 AzureOperation (com.microsoft.azure.toolkit.lib.common.operation.AzureOperation)2 FunctionConfiguration (com.microsoft.azure.toolkit.lib.legacy.function.configurations.FunctionConfiguration)2 IdentityAzureManager (com.microsoft.azuretools.sdkmanage.IdentityAzureManager)2 File (java.io.File)2 Path (java.nio.file.Path)2 ArrayList (java.util.ArrayList)2 SettableFuture (com.google.common.util.concurrent.SettableFuture)1 CreateFileAction (com.intellij.ide.actions.CreateFileAction)1 ExternalSystemProjectTracker (com.intellij.openapi.externalSystem.autoimport.ExternalSystemProjectTracker)1 ProjectNotificationAware (com.intellij.openapi.externalSystem.autoimport.ProjectNotificationAware)1 Module (com.intellij.openapi.module.Module)1 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)1 Project (com.intellij.openapi.project.Project)1