Search in sources :

Example 6 with AzureOperation

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

the class AzureArtifactManager method getModuleFromAzureArtifact.

@Nullable
@AzureOperation(name = "common|artifact.get_module", params = { "azureArtifact.getName()" }, type = AzureOperation.Type.TASK)
public Module getModuleFromAzureArtifact(AzureArtifact azureArtifact) {
    if (azureArtifact == null || azureArtifact.getReferencedObject() == null) {
        return null;
    }
    switch(azureArtifact.getType()) {
        case Gradle:
            final String gradleModulePath = ((ExternalProjectPojo) azureArtifact.getReferencedObject()).getPath();
            final VirtualFile gradleVirtualFile = LocalFileSystem.getInstance().findFileByIoFile(new File(gradleModulePath));
            return ProjectFileIndex.getInstance(project).getModuleForFile(gradleVirtualFile);
        case Maven:
            return ProjectFileIndex.getInstance(project).getModuleForFile(((MavenProject) azureArtifact.getReferencedObject()).getFile());
        default:
            // IntelliJ artifact is bind to project, can not get the related module, same for File artifact
            return null;
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ExternalProjectPojo(com.intellij.openapi.externalSystem.model.project.ExternalProjectPojo) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(com.microsoft.azure.toolkit.intellij.common.AzureArtifactType.File) File(java.io.File) AzureOperation(com.microsoft.azure.toolkit.lib.common.operation.AzureOperation) Nullable(org.jetbrains.annotations.Nullable)

Example 7 with AzureOperation

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

the class CreateWebAppAction method deploy.

@AzureOperation(name = "webapp.deploy_artifact", params = { "webapp.name()" }, type = AzureOperation.Type.ACTION)
private void deploy(final IWebApp webapp, final Path application, final Project project) {
    final AzureString title = title("webapp.deploy_artifact", webapp.name());
    final AzureTask<Void> task = new AzureTask<>(null, title, false, () -> {
        ProgressManager.getInstance().getProgressIndicator().setIndeterminate(true);
        final RunProcessHandler processHandler = new RunProcessHandler();
        processHandler.addDefaultListener();
        final ConsoleView consoleView = TextConsoleBuilderFactory.getInstance().createBuilder(project).getConsole();
        processHandler.startNotify();
        consoleView.attachToProcess(processHandler);
        AzureWebAppMvpModel.getInstance().deployArtifactsToWebApp(webapp, application.toFile(), true, processHandler);
    });
    AzureTaskManager.getInstance().runInModalAsObservable(task).single().subscribe((none) -> {
        this.notifyDeploymentSuccess(webapp);
    });
// let root exception handler to show the error.
}
Also used : ConsoleView(com.intellij.execution.ui.ConsoleView) RunProcessHandler(com.microsoft.intellij.RunProcessHandler) 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 8 with AzureOperation

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

the class CreateWebAppAction method openDialog.

@AzureOperation(name = "webapp.open_creation_dialog", type = AzureOperation.Type.ACTION)
private void openDialog(final Project project, @Nullable final WebAppConfig data) {
    final WebAppCreationDialog dialog = new WebAppCreationDialog(project);
    if (Objects.nonNull(data)) {
        dialog.setData(data);
    }
    dialog.setOkActionListener((config) -> {
        dialog.close();
        this.createWebApp(config).subscribe(webapp -> {
            final Path artifact = config.getApplication();
            if (Objects.nonNull(artifact) && artifact.toFile().exists()) {
                AzureTaskManager.getInstance().runLater("deploy", () -> deploy(webapp, artifact, project));
            }
        }, (error) -> {
            final String title = String.format("Reopen dialog \"%s\"", dialog.getTitle());
            final Consumer<Object> act = t -> AzureTaskManager.getInstance().runLater("open dialog", () -> this.openDialog(project, config));
            final Action<?> action = new Action<>(act, new ActionView.Builder(title));
            AzureMessager.getMessager().error(error, null, action);
        });
    });
    dialog.show();
}
Also used : Path(java.nio.file.Path) AzureOperation(com.microsoft.azure.toolkit.lib.common.operation.AzureOperation) AzureBundle.message(com.microsoft.intellij.ui.messages.AzureBundle.message) AzureUIRefreshCore(com.microsoft.azuretools.utils.AzureUIRefreshCore) IWebApp(com.microsoft.azure.toolkit.lib.appservice.service.IWebApp) AzureTask(com.microsoft.azure.toolkit.lib.common.task.AzureTask) Single(rx.Single) AzureOperationBundle.title(com.microsoft.azure.toolkit.lib.common.operation.AzureOperationBundle.title) Project(com.intellij.openapi.project.Project) AzureString(com.microsoft.azure.toolkit.lib.common.bundle.AzureString) TextConsoleBuilderFactory(com.intellij.execution.filters.TextConsoleBuilderFactory) AzureWebAppMvpModel(com.microsoft.azuretools.core.mvp.model.webapp.AzureWebAppMvpModel) Path(java.nio.file.Path) Notifications(com.intellij.notification.Notifications) ProgressManager(com.intellij.openapi.progress.ProgressManager) WebAppConfig(com.microsoft.azure.toolkit.lib.webapp.WebAppConfig) AzureActionEnum(com.microsoft.tooling.msservices.serviceexplorer.AzureActionEnum) NodeActionListener(com.microsoft.tooling.msservices.serviceexplorer.NodeActionListener) WebAppModule(com.microsoft.tooling.msservices.serviceexplorer.azure.webapp.WebAppModule) WebAppCreationDialog(com.microsoft.azure.toolkit.intellij.webapp.WebAppCreationDialog) AzureMessager(com.microsoft.azure.toolkit.lib.common.messager.AzureMessager) Nullable(com.microsoft.azuretools.azurecommons.helpers.Nullable) AzureUIRefreshEvent(com.microsoft.azuretools.utils.AzureUIRefreshEvent) AzureSignInAction(com.microsoft.intellij.actions.AzureSignInAction) RunProcessHandler(com.microsoft.intellij.RunProcessHandler) NotificationType(com.intellij.notification.NotificationType) Objects(java.util.Objects) Consumer(java.util.function.Consumer) Notification(com.intellij.notification.Notification) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) WebAppService(com.microsoft.azure.toolkit.lib.webapp.WebAppService) ConsoleView(com.intellij.execution.ui.ConsoleView) ActionView(com.microsoft.azure.toolkit.lib.common.action.ActionView) Action(com.microsoft.azure.toolkit.lib.common.action.Action) NodeActionEvent(com.microsoft.tooling.msservices.serviceexplorer.NodeActionEvent) AzureTaskManager(com.microsoft.azure.toolkit.lib.common.task.AzureTaskManager) AzureSignInAction(com.microsoft.intellij.actions.AzureSignInAction) Action(com.microsoft.azure.toolkit.lib.common.action.Action) WebAppCreationDialog(com.microsoft.azure.toolkit.intellij.webapp.WebAppCreationDialog) ActionView(com.microsoft.azure.toolkit.lib.common.action.ActionView) AzureString(com.microsoft.azure.toolkit.lib.common.bundle.AzureString) AzureOperation(com.microsoft.azure.toolkit.lib.common.operation.AzureOperation)

Example 9 with AzureOperation

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

the class WebAppOnLinuxAction method onActionPerformed.

@Override
@AzureOperation(name = "docker.start.configuration", type = AzureOperation.Type.ACTION)
public boolean onActionPerformed(@NotNull AnActionEvent event, @Nullable Operation operation) {
    Module module = DataKeys.MODULE.getData(event.getDataContext());
    if (module == null) {
        return true;
    }
    AzureSignInAction.requireSignedIn(module.getProject(), () -> runConfiguration(module));
    return false;
}
Also used : Module(com.intellij.openapi.module.Module) AzureOperation(com.microsoft.azure.toolkit.lib.common.operation.AzureOperation)

Example 10 with AzureOperation

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

the class WebDeployAction method runConfiguration.

@SuppressWarnings("deprecation")
@AzureOperation(name = "webapp.deploy_module", params = { "module.getName()" }, type = AzureOperation.Type.ACTION)
private void runConfiguration(Module module) {
    Project project = module.getProject();
    final RunManagerEx manager = RunManagerEx.getInstanceEx(project);
    final ConfigurationFactory factory = configType.getWebAppConfigurationFactory();
    RunnerAndConfigurationSettings settings = manager.findConfigurationByName(String.format("%s: %s:%s", factory.getName(), project.getName(), module.getName()));
    if (settings == null) {
        settings = manager.createConfiguration(String.format("%s: %s:%s", factory.getName(), project.getName(), module.getName()), factory);
    }
    if (RunDialog.editConfiguration(project, settings, message("webapp.deploy.configuration.title"), DefaultRunExecutor.getRunExecutorInstance())) {
        List<BeforeRunTask> tasks = new ArrayList<>(manager.getBeforeRunTasks(settings.getConfiguration()));
        manager.addConfiguration(settings, false, tasks, false);
        manager.setSelectedConfiguration(settings);
        ProgramRunnerUtil.executeConfiguration(project, settings, DefaultRunExecutor.getRunExecutorInstance());
    }
}
Also used : BeforeRunTask(com.intellij.execution.BeforeRunTask) Project(com.intellij.openapi.project.Project) RunManagerEx(com.intellij.execution.RunManagerEx) ConfigurationFactory(com.intellij.execution.configurations.ConfigurationFactory) ArrayList(java.util.ArrayList) RunnerAndConfigurationSettings(com.intellij.execution.RunnerAndConfigurationSettings) AzureOperation(com.microsoft.azure.toolkit.lib.common.operation.AzureOperation)

Aggregations

AzureOperation (com.microsoft.azure.toolkit.lib.common.operation.AzureOperation)64 AzureString (com.microsoft.azure.toolkit.lib.common.bundle.AzureString)11 AzureToolkitRuntimeException (com.microsoft.azure.toolkit.lib.common.exception.AzureToolkitRuntimeException)11 IOException (java.io.IOException)10 Project (com.intellij.openapi.project.Project)9 ArrayList (java.util.ArrayList)9 AzureTask (com.microsoft.azure.toolkit.lib.common.task.AzureTask)8 Operation (com.microsoft.azuretools.telemetrywrapper.Operation)6 Path (java.nio.file.Path)6 Module (com.intellij.openapi.module.Module)5 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)5 VirtualFile (com.intellij.openapi.vfs.VirtualFile)5 IWebApp (com.microsoft.azure.toolkit.lib.appservice.service.IWebApp)5 Azure (com.microsoft.azure.management.Azure)4 IFunctionApp (com.microsoft.azure.toolkit.lib.appservice.service.IFunctionApp)4 AzureUIRefreshEvent (com.microsoft.azuretools.utils.AzureUIRefreshEvent)4 Action (com.microsoft.azure.toolkit.lib.common.action.Action)3 ResourceGroup (com.microsoft.azure.toolkit.lib.common.model.ResourceGroup)3 Subscription (com.microsoft.azure.toolkit.lib.common.model.Subscription)3 AzureTaskManager (com.microsoft.azure.toolkit.lib.common.task.AzureTaskManager)3