Search in sources :

Example 51 with AzureOperation

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

the class Node method openResourcesInPortal.

@AzureOperation(name = "common.open_portal", params = { "nameFromResourceId(resourceId)" }, type = AzureOperation.Type.ACTION)
public void openResourcesInPortal(String subscriptionId, String resourceId) {
    final AzureManager azureManager = AuthMethodManager.getInstance().getAzureManager();
    // not signed in
    if (azureManager == null) {
        return;
    }
    final String portalUrl = azureManager.getPortalUrl();
    Subscription subscription = Azure.az(AzureAccount.class).account().getSubscription(subscriptionId);
    final String url = portalUrl + REST_SEGMENT_JOB_MANAGEMENT_TENANTID + subscription.getTenantId() + REST_SEGMENT_JOB_MANAGEMENT_RESOURCE + resourceId;
    DefaultLoader.getIdeHelper().openLinkInBrowser(url);
}
Also used : AzureManager(com.microsoft.azuretools.sdkmanage.AzureManager) Subscription(com.microsoft.azure.toolkit.lib.common.model.Subscription) AzureOperation(com.microsoft.azure.toolkit.lib.common.operation.AzureOperation)

Example 52 with AzureOperation

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

the class IDEHelperImpl method openAppServiceFile.

@AzureOperation(name = "appservice|file.open", params = { "target.getName()" }, type = AzureOperation.Type.SERVICE)
@SneakyThrows
public void openAppServiceFile(AppServiceFile target, Object context) {
    final IAppService appService = target.getApp();
    final FileEditorManager fileEditorManager = FileEditorManager.getInstance((Project) context);
    final VirtualFile virtualFile = getOrCreateVirtualFile(target, fileEditorManager);
    final OutputStream output = virtualFile.getOutputStream(null);
    final AzureString title = AzureOperationBundle.title("appservice|file.open", virtualFile.getName());
    final AzureTask<Void> task = new AzureTask<>(null, title, false, () -> {
        final ProgressIndicator indicator = ProgressManager.getInstance().getProgressIndicator();
        indicator.setIndeterminate(true);
        indicator.setText2("Checking file existence");
        final AppServiceFile file = appService.getFileByPath(target.getPath());
        if (file == null) {
            final String failureFileDeleted = String.format("Target file (%s) has been deleted", target.getName());
            UIUtil.invokeLaterIfNeeded(() -> Messages.showWarningDialog(failureFileDeleted, "Open File"));
            return;
        }
        indicator.setText2("Loading file content");
        final String failure = String.format("Can not open file (%s). Try downloading it first and open it manually.", virtualFile.getName());
        appService.getFileContent(file.getPath()).doOnComplete(() -> AzureTaskManager.getInstance().runLater(() -> {
            final Consumer<String> contentSaver = content -> saveFileToAzure(target, content, fileEditorManager.getProject());
            if (!openFileInEditor(contentSaver, virtualFile, fileEditorManager)) {
                Messages.showWarningDialog(failure, "Open File");
            }
        }, AzureTask.Modality.NONE)).doAfterTerminate(() -> IOUtils.closeQuietly(output, null)).subscribe(bytes -> {
            try {
                if (bytes != null) {
                    output.write(bytes.array(), 0, bytes.limit());
                }
            } catch (final IOException e) {
                final String error = "failed to load data into editor";
                final String action = "try later or downloading it first";
                throw new AzureToolkitRuntimeException(error, e, action);
            }
        }, IDEHelperImpl::onRxException);
    });
    AzureTaskManager.getInstance().runInModal(task);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) LightVirtualFile(com.intellij.testFramework.LightVirtualFile) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) AzureToolkitRuntimeException(com.microsoft.azure.toolkit.lib.common.exception.AzureToolkitRuntimeException) AzureString(com.microsoft.azure.toolkit.lib.common.bundle.AzureString) InterruptedIOException(java.io.InterruptedIOException) IOException(java.io.IOException) AzureString(com.microsoft.azure.toolkit.lib.common.bundle.AzureString) IAppService(com.microsoft.azure.toolkit.lib.appservice.service.IAppService) FileEditorManager(com.intellij.openapi.fileEditor.FileEditorManager) Consumer(com.intellij.util.Consumer) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) AzureTask(com.microsoft.azure.toolkit.lib.common.task.AzureTask) AppServiceFile(com.microsoft.azure.toolkit.lib.appservice.model.AppServiceFile) AzureOperation(com.microsoft.azure.toolkit.lib.common.operation.AzureOperation) SneakyThrows(lombok.SneakyThrows)

Example 53 with AzureOperation

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

the class WhatsNewAction method actionPerformed.

@Override
@AzureOperation(name = "common.load_whatsnew", type = AzureOperation.Type.ACTION)
public void actionPerformed(@Nonnull final AnActionEvent event) {
    final boolean manually = !"AzurePluginStartupActivity".equals(event.getPlace());
    final String content = getWhatsNewContent();
    final DefaultArtifactVersion currentVersion = getVersion(content);
    final DefaultArtifactVersion lastVersion = getLastVersion();
    if (manually || compare(currentVersion, lastVersion)) {
        saveVersion(currentVersion);
        doShow(content, currentVersion, manually, Objects.requireNonNull(event.getProject()));
    }
}
Also used : DefaultArtifactVersion(org.apache.maven.artifact.versioning.DefaultArtifactVersion) AzureOperation(com.microsoft.azure.toolkit.lib.common.operation.AzureOperation)

Example 54 with AzureOperation

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

the class AzureExplorerOpenAction method onActionPerformed.

@Override
@AzureOperation(name = "common|explorer.open", type = AzureOperation.Type.ACTION)
public boolean onActionPerformed(@NotNull AnActionEvent event, @Nullable Operation operation) {
    Project project = DataKeys.PROJECT.getData(event.getDataContext());
    ToolWindowManager.getInstance(project).getToolWindow(ServerExplorerToolWindowFactory.EXPLORER_WINDOW).activate(null);
    return true;
}
Also used : Project(com.intellij.openapi.project.Project) AzureOperation(com.microsoft.azure.toolkit.lib.common.operation.AzureOperation)

Example 55 with AzureOperation

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

the class WebAppService method createWebApp.

@AzureOperation(name = "webapp.create_detail", params = { "config.getName()" }, type = AzureOperation.Type.SERVICE)
public IWebApp createWebApp(final WebAppConfig config) {
    final WebAppSettingModel settings = convertConfig2Settings(config);
    settings.setCreatingNew(true);
    final Map<String, String> properties = settings.getTelemetryProperties(null);
    final Operation operation = TelemetryManager.createOperation(WEBAPP, CREATE_WEBAPP);
    try {
        operation.start();
        operation.trackProperties(properties);
        return AzureWebAppMvpModel.getInstance().createWebAppFromSettingModel(settings);
    } catch (final RuntimeException e) {
        EventUtil.logError(operation, ErrorType.userError, e, properties, null);
        throw e;
    } finally {
        operation.complete();
    }
}
Also used : AzureOperation(com.microsoft.azure.toolkit.lib.common.operation.AzureOperation) Operation(com.microsoft.azuretools.telemetrywrapper.Operation) WebAppSettingModel(com.microsoft.azuretools.core.mvp.model.webapp.WebAppSettingModel) 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