Search in sources :

Example 11 with Operation

use of com.microsoft.azuretools.telemetrywrapper.Operation 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 12 with Operation

use of com.microsoft.azuretools.telemetrywrapper.Operation in project azure-tools-for-java by Microsoft.

the class FunctionsModuleBuilder method setupRootModel.

@Override
public void setupRootModel(@NotNull final ModifiableRootModel rootModel) {
    final VirtualFile root = createAndGetContentEntry();
    rootModel.addContentEntry(root);
    // todo this should be moved to generic ModuleBuilder
    if (myJdk != null) {
        rootModel.setSdk(myJdk);
    } else {
        rootModel.inheritSdk();
    }
    final Project project = rootModel.getProject();
    runWhenInitialized(rootModel.getProject(), () -> {
        final Operation operation = TelemetryManager.createOperation(TelemetryConstants.FUNCTION, TelemetryConstants.CREATE_FUNCTION_PROJECT);
        try {
            operation.start();
            final String tool = wizardContext.getUserData(AzureFunctionsConstants.WIZARD_TOOL_KEY);
            final String groupId = wizardContext.getUserData(AzureFunctionsConstants.WIZARD_GROUPID_KEY);
            final String artifactId = wizardContext.getUserData(AzureFunctionsConstants.WIZARD_ARTIFACTID_KEY);
            final String version = wizardContext.getUserData(AzureFunctionsConstants.WIZARD_VERSION_KEY);
            final String packageName = wizardContext.getUserData(AzureFunctionsConstants.WIZARD_PACKAGE_NAME_KEY);
            final String[] triggers = wizardContext.getUserData(AzureFunctionsConstants.WIZARD_TRIGGERS_KEY);
            operation.trackProperty("tool", tool);
            operation.trackProperty(TelemetryConstants.TRIGGER_TYPE, StringUtils.join(triggers, ","));
            File tempProjectFolder = null;
            try {
                tempProjectFolder = AzureFunctionsUtils.createFunctionProjectToTempFolder(groupId, artifactId, version, tool);
                if (tempProjectFolder != null) {
                    if (tempProjectFolder.exists() && tempProjectFolder.isDirectory()) {
                        final File moduleFile = new File(getContentEntryPath());
                        final File srcFolder = Paths.get(tempProjectFolder.getAbsolutePath(), "src/main/java").toFile();
                        for (final String trigger : triggers) {
                            // class name like HttpTriggerFunction
                            final String className = trigger + "Function";
                            final String fileContent = AzureFunctionsUtils.generateFunctionClassByTrigger(trigger, packageName, className);
                            final File targetFile = Paths.get(srcFolder.getAbsolutePath(), String.format("%s/%s.java", packageName.replace('.', '/'), className)).toFile();
                            targetFile.getParentFile().mkdirs();
                            FileUtils.write(targetFile, fileContent, "utf-8");
                        }
                        FileUtils.copyDirectory(tempProjectFolder, moduleFile);
                        final VirtualFile vf = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(moduleFile);
                        RefreshQueue.getInstance().refresh(true, true, null, new VirtualFile[] { vf });
                        final VirtualFile pomFile = vf.findChild("pom.xml");
                        if (pomFile != null) {
                            final MavenProjectsManager mavenProjectsManager = MavenProjectsManager.getInstance(project);
                            mavenProjectsManager.addManagedFiles(Collections.singletonList(pomFile));
                        }
                    }
                }
            } catch (final Exception e) {
                PluginUtil.displayErrorDialogAndLog("Error", "Cannot create Azure Function Project in Java.", e);
                EventUtil.logError(operation, ErrorType.systemError, e, null, null);
            } finally {
                if (tempProjectFolder != null && tempProjectFolder.isDirectory()) {
                    try {
                        FileUtils.deleteDirectory(tempProjectFolder);
                    } catch (final IOException e) {
                    // ignore
                    }
                }
            }
        } finally {
            operation.complete();
        }
    });
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) MavenProjectsManager(org.jetbrains.idea.maven.project.MavenProjectsManager) Operation(com.microsoft.azuretools.telemetrywrapper.Operation) IOException(java.io.IOException) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) IOException(java.io.IOException)

Example 13 with Operation

use of com.microsoft.azuretools.telemetrywrapper.Operation in project azure-tools-for-java by Microsoft.

the class CreateSqlServerTask method execute.

@AzureOperation(name = "sqlserver|server.create", params = { "config.getServerName()", "config.getSubscription().getName()" }, type = AzureOperation.Type.SERVICE)
public SqlServer execute() {
    final Operation operation = TelemetryManager.createOperation(ActionConstants.MySQL.CREATE);
    try {
        operation.start();
        final String subscriptionId = config.getSubscription().getId();
        EventUtil.logEvent(EventType.info, operation, Collections.singletonMap(TelemetryConstants.SUBSCRIPTIONID, subscriptionId));
        // create resource group if necessary.
        if (config.getResourceGroup() instanceof Draft) {
            ResourceGroup newResourceGroup = Azure.az(AzureGroup.class).subscription(subscriptionId).create(config.getResourceGroup().getName(), config.getRegion().getName());
            config.setResourceGroup(newResourceGroup);
        }
        // create sql server
        return Azure.az(AzureSqlServer.class).subscription(config.getSubscription().getId()).create(com.microsoft.azure.toolkit.lib.sqlserver.model.SqlServerConfig.builder().name(config.getServerName()).subscription(config.getSubscription()).resourceGroup(config.getResourceGroup()).region(config.getRegion()).administratorLoginName(config.getAdminUsername()).administratorLoginPassword(String.valueOf(config.getPassword())).enableAccessFromAzureServices(config.isAllowAccessFromAzureServices()).enableAccessFromLocalMachine(config.isAllowAccessFromLocalMachine()).build()).commit();
    } catch (final RuntimeException e) {
        EventUtil.logError(operation, ErrorType.systemError, e, null, null);
        throw e;
    } finally {
        operation.complete();
    }
}
Also used : Draft(com.microsoft.azure.toolkit.intellij.common.Draft) AzureSqlServer(com.microsoft.azure.toolkit.lib.sqlserver.AzureSqlServer) AzureOperation(com.microsoft.azure.toolkit.lib.common.operation.AzureOperation) Operation(com.microsoft.azuretools.telemetrywrapper.Operation) ResourceGroup(com.microsoft.azure.toolkit.lib.common.model.ResourceGroup) AzureOperation(com.microsoft.azure.toolkit.lib.common.operation.AzureOperation)

Example 14 with Operation

use of com.microsoft.azuretools.telemetrywrapper.Operation in project azure-tools-for-java by Microsoft.

the class DeploymentNodePresenter method onGetExportTemplateRes.

public void onGetExportTemplateRes(String template, File file) {
    Operation operation = TelemetryManager.createOperation(ARM, EXPORT_TEMPALTE_FILE);
    Observable.fromCallable(() -> {
        operation.start();
        IOUtils.write(template, new FileOutputStream(file), Charset.defaultCharset());
        return true;
    }).subscribe(res -> DefaultLoader.getIdeHelper().invokeLater(() -> {
        operation.complete();
        if (!isViewDetached()) {
            getMvpView().showExportTemplateResult(true, null);
        }
    }), ex -> {
        operation.complete();
        EventUtil.logError(operation, ErrorType.systemError, Exceptions.propagate(ex), null, null);
        if (!isViewDetached()) {
            getMvpView().showExportTemplateResult(false, ex);
        }
    });
}
Also used : FileOutputStream(java.io.FileOutputStream) Operation(com.microsoft.azuretools.telemetrywrapper.Operation)

Example 15 with Operation

use of com.microsoft.azuretools.telemetrywrapper.Operation in project azure-tools-for-java by Microsoft.

the class RedisExplorerPresenter method onGetKeyAndValue.

public void onGetKeyAndValue(int db, String key) {
    Operation operation = TelemetryManager.createOperation(TelemetryConstants.REDIS, TelemetryConstants.REDIS_GET);
    operation.start();
    Observable.fromCallable(() -> {
        boolean isExist = RedisExplorerMvpModel.getInstance().checkKeyExistance(sid, id, db, key);
        if (!isExist) {
            return null;
        } else {
            return getValueByKey(db, key);
        }
    }).subscribeOn(getSchedulerProvider().io()).subscribe(result -> {
        DefaultLoader.getIdeHelper().invokeLater(() -> {
            if (isViewDetached()) {
                return;
            }
            if (result == null) {
                getMvpView().getKeyFail();
                return;
            }
            getMvpView().updateKeyList();
            getMvpView().showContent(result);
            operation.complete();
        });
    }, e -> {
        EventUtil.logError(operation, ErrorType.userError, new Exception(e), null, null);
        operation.complete();
        errorHandler(CANNOT_GET_REDIS_INFO, (Exception) e);
    });
}
Also used : Operation(com.microsoft.azuretools.telemetrywrapper.Operation)

Aggregations

Operation (com.microsoft.azuretools.telemetrywrapper.Operation)29 AzureOperation (com.microsoft.azure.toolkit.lib.common.operation.AzureOperation)9 IOException (java.io.IOException)8 File (java.io.File)7 HashMap (java.util.HashMap)7 AzureString (com.microsoft.azure.toolkit.lib.common.bundle.AzureString)6 EventUtil (com.microsoft.azuretools.telemetrywrapper.EventUtil)6 AzureToolkitRuntimeException (com.microsoft.azure.toolkit.lib.common.exception.AzureToolkitRuntimeException)5 TelemetryConstants (com.microsoft.azuretools.telemetry.TelemetryConstants)5 ErrorType (com.microsoft.azuretools.telemetrywrapper.ErrorType)5 Map (java.util.Map)5 Project (com.intellij.openapi.project.Project)4 MsalClientException (com.microsoft.aad.msal4j.MsalClientException)4 TelemetryManager (com.microsoft.azuretools.telemetrywrapper.TelemetryManager)4 DefaultDockerClient (com.spotify.docker.client.DefaultDockerClient)4 Path (java.nio.file.Path)4 CancellationException (java.util.concurrent.CancellationException)4 DefaultExecutionResult (com.intellij.execution.DefaultExecutionResult)3 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)3 AzureTask (com.microsoft.azure.toolkit.lib.common.task.AzureTask)3