Search in sources :

Example 16 with AzureOperation

use of com.microsoft.azure.toolkit.lib.common.operation.AzureOperation 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 17 with AzureOperation

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

the class CreateFunctionAppAction method openDialog.

@AzureOperation(name = "function.open_creation_dialog", type = AzureOperation.Type.ACTION)
private void openDialog(final Project project, @Nullable final FunctionAppConfig data) {
    final FunctionAppCreationDialog dialog = new FunctionAppCreationDialog(project);
    if (Objects.nonNull(data)) {
        dialog.setData(data);
    }
    dialog.setOkActionListener((config) -> {
        dialog.close();
        this.createFunctionApp(config).subscribe(functionApp -> {
        }, (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 : FunctionAppCreationDialog(com.microsoft.azure.toolkit.intellij.function.FunctionAppCreationDialog) AzureOperation(com.microsoft.azure.toolkit.lib.common.operation.AzureOperation) AzureBundle.message(com.microsoft.intellij.ui.messages.AzureBundle.message) AzureUIRefreshCore(com.microsoft.azuretools.utils.AzureUIRefreshCore) IntellijAzureMessager(com.microsoft.azure.toolkit.intellij.common.messager.IntellijAzureMessager) 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) FunctionAppService(com.microsoft.azure.toolkit.lib.function.FunctionAppService) ProgressManager(com.intellij.openapi.progress.ProgressManager) AzureActionEnum(com.microsoft.tooling.msservices.serviceexplorer.AzureActionEnum) NodeActionListener(com.microsoft.tooling.msservices.serviceexplorer.NodeActionListener) AzureMessager(com.microsoft.azure.toolkit.lib.common.messager.AzureMessager) Nullable(com.microsoft.azuretools.azurecommons.helpers.Nullable) IAzureMessage(com.microsoft.azure.toolkit.lib.common.messager.IAzureMessage) AzureUIRefreshEvent(com.microsoft.azuretools.utils.AzureUIRefreshEvent) Operation(com.microsoft.azuretools.telemetrywrapper.Operation) AzureSignInAction(com.microsoft.intellij.actions.AzureSignInAction) Name(com.microsoft.tooling.msservices.helpers.Name) FunctionAppConfig(com.microsoft.azure.toolkit.lib.function.FunctionAppConfig) AzureTelemetry(com.microsoft.azure.toolkit.lib.common.telemetry.AzureTelemetry) Objects(java.util.Objects) Consumer(java.util.function.Consumer) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) FunctionModule(com.microsoft.tooling.msservices.serviceexplorer.azure.function.FunctionModule) ActionView(com.microsoft.azure.toolkit.lib.common.action.ActionView) TelemetryConstants(com.microsoft.azuretools.telemetry.TelemetryConstants) IFunctionApp(com.microsoft.azure.toolkit.lib.appservice.service.IFunctionApp) Action(com.microsoft.azure.toolkit.lib.common.action.Action) TelemetryManager(com.microsoft.azuretools.telemetrywrapper.TelemetryManager) 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) ActionView(com.microsoft.azure.toolkit.lib.common.action.ActionView) AzureString(com.microsoft.azure.toolkit.lib.common.bundle.AzureString) FunctionAppCreationDialog(com.microsoft.azure.toolkit.intellij.function.FunctionAppCreationDialog) AzureOperation(com.microsoft.azure.toolkit.lib.common.operation.AzureOperation)

Example 18 with AzureOperation

use of com.microsoft.azure.toolkit.lib.common.operation.AzureOperation 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 19 with AzureOperation

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

the class FunctionUtils method prepareStagingFolder.

@AzureOperation(name = "function.prepare_staging_folder", type = AzureOperation.Type.TASK)
public static Map<String, FunctionConfiguration> prepareStagingFolder(Path stagingFolder, Path hostJson, Module module, PsiMethod[] methods) throws AzureExecutionException, IOException {
    final Map<String, FunctionConfiguration> configMap = generateConfigurations(methods);
    if (stagingFolder.toFile().isDirectory()) {
        FileUtils.cleanDirectory(stagingFolder.toFile());
    }
    final Path jarFile = JarUtils.buildJarFileToStagingPath(stagingFolder.toString(), module);
    final String scriptFilePath = "../" + jarFile.getFileName().toString();
    configMap.values().forEach(config -> config.setScriptFile(scriptFilePath));
    for (final Map.Entry<String, FunctionConfiguration> config : configMap.entrySet()) {
        if (StringUtils.isNotBlank(config.getKey())) {
            final File functionJsonFile = Paths.get(stagingFolder.toString(), config.getKey(), FUNCTION_JSON).toFile();
            writeFunctionJsonFile(functionJsonFile, config.getValue());
        }
    }
    final File hostJsonFile = new File(stagingFolder.toFile(), "host.json");
    copyFilesWithDefaultContent(hostJson, hostJsonFile, DEFAULT_HOST_JSON);
    final List<File> jarFiles = new ArrayList<>();
    OrderEnumerator.orderEntries(module).productionOnly().forEachLibrary(lib -> {
        if (StringUtils.isNotEmpty(lib.getName()) && ArrayUtils.contains(lib.getName().split("\\:"), FUNCTION_JAVA_LIBRARY_ARTIFACT_ID)) {
            return true;
        }
        if (lib != null) {
            for (final VirtualFile virtualFile : lib.getFiles(OrderRootType.CLASSES)) {
                final File file = new File(stripExtraCharacters(virtualFile.getPath()));
                if (file.exists()) {
                    jarFiles.add(file);
                }
            }
        }
        return true;
    });
    final File libFolder = new File(stagingFolder.toFile(), "lib");
    for (final File file : jarFiles) {
        FileUtils.copyFileToDirectory(file, libFolder);
    }
    return configMap;
}
Also used : Path(java.nio.file.Path) VirtualFile(com.intellij.openapi.vfs.VirtualFile) FunctionConfiguration(com.microsoft.azure.toolkit.lib.legacy.function.configurations.FunctionConfiguration) ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) AzureOperation(com.microsoft.azure.toolkit.lib.common.operation.AzureOperation)

Example 20 with AzureOperation

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

the class FunctionRunState method launchDebugger.

@AzureOperation(name = "function.launch_debugger", type = AzureOperation.Type.TASK)
private void launchDebugger(final Project project, int debugPort) {
    final Runnable runnable = () -> {
        final RunManagerImpl manager = new RunManagerImpl(project);
        final ConfigurationFactory configFactory = RemoteConfigurationType.getInstance().getConfigurationFactories()[0];
        final RemoteConfiguration remoteConfig = new RemoteConfiguration(project, configFactory);
        remoteConfig.PORT = String.valueOf(debugPort);
        remoteConfig.HOST = "localhost";
        remoteConfig.USE_SOCKET_TRANSPORT = true;
        remoteConfig.SERVER_MODE = false;
        remoteConfig.setName("azure functions");
        final RunnerAndConfigurationSettings configuration = new RunnerAndConfigurationSettingsImpl(manager, remoteConfig, false);
        manager.setTemporaryConfiguration(configuration);
        ExecutionUtil.runConfiguration(configuration, ExecutorRegistry.getInstance().getExecutorById(ToolWindowId.DEBUG));
    };
    AzureTaskManager.getInstance().runAndWait(runnable, AzureTask.Modality.ANY);
}
Also used : RemoteConfiguration(com.intellij.execution.remote.RemoteConfiguration) ConfigurationFactory(com.intellij.execution.configurations.ConfigurationFactory) RunnerAndConfigurationSettings(com.intellij.execution.RunnerAndConfigurationSettings) RunnerAndConfigurationSettingsImpl(com.intellij.execution.impl.RunnerAndConfigurationSettingsImpl) RunManagerImpl(com.intellij.execution.impl.RunManagerImpl) 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