Search in sources :

Example 21 with AzureString

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

the class CreateStorageAccountAction method create.

@AzureOperation(name = "storage|account.create", params = { "config.getName()" }, type = AzureOperation.Type.ACTION)
public static void create(final StorageAccountConfig config) {
    final AzureString title = AzureOperationBundle.title("storage|account.create", config.getName());
    AzureTaskManager.getInstance().runInBackground(title, () -> createStorageAccount(config));
}
Also used : AzureString(com.microsoft.azure.toolkit.lib.common.bundle.AzureString) AzureOperation(com.microsoft.azure.toolkit.lib.common.operation.AzureOperation)

Example 22 with AzureString

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

the class CreateFunctionAppAction method createFunctionApp.

@AzureOperation(name = "function.create_detail", params = { "config.getName()" }, type = AzureOperation.Type.ACTION)
private Single<IFunctionApp> createFunctionApp(final FunctionAppConfig config) {
    final AzureString title = title("function.create_detail", config.getName());
    final IntellijAzureMessager actionMessenger = new IntellijAzureMessager() {

        @Override
        public boolean show(IAzureMessage raw) {
            if (raw.getType() != IAzureMessage.Type.INFO) {
                return super.show(raw);
            }
            return false;
        }
    };
    final AzureTask<IFunctionApp> task = new AzureTask<>(null, title, false, () -> {
        final Operation operation = TelemetryManager.createOperation(TelemetryConstants.FUNCTION, TelemetryConstants.CREATE_FUNCTION_APP);
        operation.trackProperties(config.getTelemetryProperties());
        try {
            AzureMessager.getContext().setMessager(actionMessenger);
            final ProgressIndicator indicator = ProgressManager.getInstance().getProgressIndicator();
            indicator.setIndeterminate(true);
            return functionAppService.createFunctionApp(config);
        } finally {
            operation.trackProperties(AzureTelemetry.getActionContext().getProperties());
            operation.complete();
        }
    });
    return AzureTaskManager.getInstance().runInModalAsObservable(task).toSingle().doOnSuccess(app -> {
        AzureMessager.getMessager().success(message("function.create.success.message", app.name()), message("function.create.success.title"));
        this.refreshAzureExplorer(app);
    });
}
Also used : ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) IAzureMessage(com.microsoft.azure.toolkit.lib.common.messager.IAzureMessage) IntellijAzureMessager(com.microsoft.azure.toolkit.intellij.common.messager.IntellijAzureMessager) AzureOperation(com.microsoft.azure.toolkit.lib.common.operation.AzureOperation) Operation(com.microsoft.azuretools.telemetrywrapper.Operation) IFunctionApp(com.microsoft.azure.toolkit.lib.appservice.service.IFunctionApp) AzureTask(com.microsoft.azure.toolkit.lib.common.task.AzureTask) AzureString(com.microsoft.azure.toolkit.lib.common.bundle.AzureString) AzureOperation(com.microsoft.azure.toolkit.lib.common.operation.AzureOperation)

Example 23 with AzureString

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

the class FunctionDeploymentState method listFunctions.

// todo: Move to toolkit lib as shared task
private List<FunctionEntity> listFunctions(final IFunctionApp functionApp) {
    final int[] count = { 0 };
    final IAzureMessager azureMessager = AzureMessager.getMessager();
    return Mono.fromCallable(() -> {
        final AzureString message = count[0]++ == 0 ? AzureString.fromString(SYNCING_TRIGGERS) : AzureString.format(SYNCING_TRIGGERS_WITH_RETRY, count[0], LIST_TRIGGERS_MAX_RETRY);
        azureMessager.info(message);
        return Optional.ofNullable(functionApp.listFunctions(true)).filter(CollectionUtils::isNotEmpty).orElseThrow(() -> new AzureToolkitRuntimeException(NO_TRIGGERS_FOUNDED));
    }).subscribeOn(Schedulers.boundedElastic()).retryWhen(Retry.fixedDelay(LIST_TRIGGERS_MAX_RETRY - 1, Duration.ofSeconds(LIST_TRIGGERS_RETRY_PERIOD_IN_SECONDS))).block();
}
Also used : IAzureMessager(com.microsoft.azure.toolkit.lib.common.messager.IAzureMessager) CollectionUtils(org.apache.commons.collections4.CollectionUtils) AzureToolkitRuntimeException(com.microsoft.azure.toolkit.lib.common.exception.AzureToolkitRuntimeException) AzureString(com.microsoft.azure.toolkit.lib.common.bundle.AzureString)

Example 24 with AzureString

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

the class OpenStorageExplorerAction method openStorageBrowser.

public static void openStorageBrowser(StorageAccount account) {
    final AzureString title = AzureString.format("storage|account.open_storage_explorer", account.name());
    AzureTaskManager.getInstance().runInBackground(new AzureTask<>(title, () -> {
        final String url = account.portalUrl() + "/storageExplorer";
        AzureActionManager.getInstance().getAction(ResourceCommonActionsContributor.OPEN_URL).handle(url);
    }));
}
Also used : AzureString(com.microsoft.azure.toolkit.lib.common.bundle.AzureString) AzureString(com.microsoft.azure.toolkit.lib.common.bundle.AzureString)

Example 25 with AzureString

use of com.microsoft.azure.toolkit.lib.common.bundle.AzureString 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)

Aggregations

AzureString (com.microsoft.azure.toolkit.lib.common.bundle.AzureString)46 AzureTask (com.microsoft.azure.toolkit.lib.common.task.AzureTask)36 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)21 Project (com.intellij.openapi.project.Project)7 AzureOperation (com.microsoft.azure.toolkit.lib.common.operation.AzureOperation)6 List (java.util.List)6 VirtualFile (com.intellij.openapi.vfs.VirtualFile)5 AzureOperationBundle (com.microsoft.azure.toolkit.lib.common.operation.AzureOperationBundle)5 AzureTaskManager (com.microsoft.azure.toolkit.lib.common.task.AzureTaskManager)5 AzureCmdException (com.microsoft.azuretools.azurecommons.helpers.AzureCmdException)5 EventUtil (com.microsoft.azuretools.telemetrywrapper.EventUtil)4 BlobFile (com.microsoft.tooling.msservices.model.storage.BlobFile)4 IOException (java.io.IOException)4 MessageType (com.intellij.openapi.ui.MessageType)3 LightVirtualFile (com.intellij.testFramework.LightVirtualFile)3 AzureAccount (com.microsoft.azure.toolkit.lib.auth.AzureAccount)3 AzureToolkitRuntimeException (com.microsoft.azure.toolkit.lib.common.exception.AzureToolkitRuntimeException)3 File (java.io.File)3 javax.swing (javax.swing)3 FileChooserDescriptorFactory (com.intellij.openapi.fileChooser.FileChooserDescriptorFactory)2