Search in sources :

Example 1 with AzureToolkitRuntimeException

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

the class SignInCommandHandler method call.

private static <T> T call(Callable<T> loginCallable, String authMethod) {
    final Operation operation = TelemetryManager.createOperation(ACCOUNT, SIGNIN);
    final Map<String, String> properties = new HashMap<>();
    properties.put(SIGNIN_METHOD, authMethod);
    try {
        operation.start();
        operation.trackProperties(properties);
        operation.trackProperty(AZURE_ENVIRONMENT, Azure.az(AzureCloud.class).getName());
        return loginCallable.call();
    } catch (Exception e) {
        if (shouldNoticeErrorToUser(e)) {
            EventUtil.logError(operation, ErrorType.userError, e, properties, null);
        }
        throw new AzureToolkitRuntimeException(e.getMessage(), e);
    } finally {
        operation.complete();
    }
}
Also used : HashMap(java.util.HashMap) AzureToolkitRuntimeException(com.microsoft.azure.toolkit.lib.common.exception.AzureToolkitRuntimeException) Operation(com.microsoft.azuretools.telemetrywrapper.Operation) AzureOperation(com.microsoft.azure.toolkit.lib.common.operation.AzureOperation) AzureString(com.microsoft.azure.toolkit.lib.common.bundle.AzureString) AzureExecutionException(com.microsoft.azure.toolkit.lib.common.exception.AzureExecutionException) MsalClientException(com.microsoft.aad.msal4j.MsalClientException) CancellationException(java.util.concurrent.CancellationException) AzureToolkitRuntimeException(com.microsoft.azure.toolkit.lib.common.exception.AzureToolkitRuntimeException) ExecutionException(org.eclipse.core.commands.ExecutionException)

Example 2 with AzureToolkitRuntimeException

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

the class AzureWebAppMvpModel method deployArtifactsToWebApp.

@AzureOperation(name = "webapp|artifact.upload", params = { "file.getName()", "deployTarget.name()" }, type = AzureOperation.Type.SERVICE)
public void deployArtifactsToWebApp(@NotNull final IWebAppBase deployTarget, @NotNull final File file, boolean isDeployToRoot, @NotNull final IProgressIndicator progressIndicator) {
    if (!(deployTarget instanceof IWebApp || deployTarget instanceof IWebAppDeploymentSlot)) {
        final String error = "the deployment target is not a valid (deployment slot of) Web App";
        final String action = "select a valid Web App or deployment slot to deploy the artifact";
        throw new AzureToolkitRuntimeException(error, action);
    }
    // stop target app service
    String stopMessage = deployTarget instanceof IWebApp ? STOP_WEB_APP : STOP_DEPLOYMENT_SLOT;
    progressIndicator.setText(stopMessage);
    deployTarget.stop();
    final DeployType deployType = getDeployTypeByWebContainer(deployTarget.getRuntime().getWebContainer());
    // java se runtime will always deploy to root
    if (isDeployToRoot || Objects.equals(deployTarget.getRuntime().getWebContainer(), com.microsoft.azure.toolkit.lib.appservice.model.WebContainer.JAVA_SE)) {
        deployTarget.deploy(deployType, file);
    } else {
        final String webappPath = String.format("webapps/%s", FilenameUtils.getBaseName(file.getName()).replaceAll("#", StringUtils.EMPTY));
        deployTarget.deploy(deployType, file, webappPath);
    }
    String successMessage = deployTarget instanceof IWebApp ? DEPLOY_SUCCESS_WEB_APP : DEPLOY_SUCCESS_DEPLOYMENT_SLOT;
    progressIndicator.setText(successMessage);
    deployTarget.start();
}
Also used : DeployType(com.microsoft.azure.toolkit.lib.appservice.model.DeployType) IWebAppDeploymentSlot(com.microsoft.azure.toolkit.lib.appservice.service.IWebAppDeploymentSlot) AzureToolkitRuntimeException(com.microsoft.azure.toolkit.lib.common.exception.AzureToolkitRuntimeException) IWebApp(com.microsoft.azure.toolkit.lib.appservice.service.IWebApp) AzureOperation(com.microsoft.azure.toolkit.lib.common.operation.AzureOperation)

Example 3 with AzureToolkitRuntimeException

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

the class IntellijDatasourceService method getDataSourceRegistry.

private Object getDataSourceRegistry(Project project, DatasourceProperties properties) {
    try {
        Class[] parameterTypes = { Project.class };
        Class dataSourceRegistryClazz = Class.forName("com.intellij.database.autoconfig.DataSourceRegistry");
        Constructor constructor = dataSourceRegistryClazz.getConstructor(parameterTypes);
        return constructor.newInstance(project);
    } catch (ClassNotFoundException | NoSuchMethodException | InstantiationException | IllegalAccessException | InvocationTargetException e) {
        throw new AzureToolkitRuntimeException(String.format(ERROR_MESSAGE_PATTERN, properties.getName()), ERROR_ACTION);
    }
}
Also used : Constructor(java.lang.reflect.Constructor) AzureToolkitRuntimeException(com.microsoft.azure.toolkit.lib.common.exception.AzureToolkitRuntimeException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 4 with AzureToolkitRuntimeException

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

the class SSHIntoWebAppAction method actionPerformed.

@Override
protected void actionPerformed(NodeActionEvent nodeActionEvent) throws AzureCmdException {
    logger.info(message("webapp.ssh.hint.startSSH", webAppName));
    // ssh to connect to remote web app container.
    final AzureString title = title("webapp|ssh.connect", webAppName);
    AzureTaskManager.getInstance().runInBackground(new AzureTask(project, title, false, () -> {
        final TunnelProxy proxy = new TunnelProxy(webApp);
        int localPort;
        try {
            localPort = proxy.start();
        } catch (IOException e) {
            try {
                proxy.close();
            } catch (Throwable ex) {
            // ignore
            }
            throw new AzureToolkitRuntimeException(message("webapp.ssh.error.message"));
        }
        final int finalLocalPort = localPort;
        // ssh to local proxy and open terminal.
        AzureTaskManager.getInstance().runAndWait(() -> {
            // create a new terminal tab.
            TerminalView terminalView = TerminalView.getInstance(project);
            ShellTerminalWidget shellTerminalWidget = terminalView.createLocalShellWidget(null, String.format(WEBAPP_TERMINAL_TABLE_NAME, webAppName));
            final AzureString messageTitle = title("webapp|ssh.open", webAppName);
            AzureTaskManager.getInstance().runInBackground(new AzureTask(project, messageTitle, false, () -> {
                // create connection to the local proxy.
                final SSHTerminalManager.CreateRemoteConnectionInfo info = new SSHTerminalManager.CreateRemoteConnectionInfo();
                info.setUsername(TunnelProxy.DEFAULT_SSH_USERNAME);
                info.setPassword(TunnelProxy.DEFAULT_SSH_PASSWORD);
                info.setPort(finalLocalPort);
                SSHTerminalManager.INSTANCE.openConnectionInTerminal(shellTerminalWidget, info);
            }));
        }, AzureTask.Modality.ANY);
    }));
    logger.info(message("webapp.ssh.hint.SSHDone", webAppName));
}
Also used : TerminalView(org.jetbrains.plugins.terminal.TerminalView) TunnelProxy(com.microsoft.azure.toolkit.lib.appservice.TunnelProxy) AzureToolkitRuntimeException(com.microsoft.azure.toolkit.lib.common.exception.AzureToolkitRuntimeException) ShellTerminalWidget(org.jetbrains.plugins.terminal.ShellTerminalWidget) IOException(java.io.IOException) AzureTask(com.microsoft.azure.toolkit.lib.common.task.AzureTask) AzureString(com.microsoft.azure.toolkit.lib.common.bundle.AzureString)

Example 5 with AzureToolkitRuntimeException

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

the class IDEHelperImpl method saveAppServiceFile.

@SneakyThrows
@Override
public void saveAppServiceFile(@NotNull AppServiceFile file, @NotNull Object context, @Nullable File dest) {
    final File destFile = Objects.isNull(dest) ? DefaultLoader.getUIHelper().showFileSaver("Download", file.getName()) : dest;
    if (Objects.isNull(destFile)) {
        return;
    }
    final OutputStream output = new FileOutputStream(destFile);
    final Project project = (Project) context;
    final AzureString title = AzureOperationBundle.title("appservice|file.download", file.getName());
    final AzureTask<Void> task = new AzureTask<>(project, title, false, () -> {
        ProgressManager.getInstance().getProgressIndicator().setIndeterminate(true);
        file.getApp().getFileContent(file.getPath()).doOnComplete(() -> notifyDownloadSuccess(file.getName(), destFile, ((Project) context))).doOnTerminate(() -> 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 write data into local file";
                final String action = "try later";
                throw new AzureToolkitRuntimeException(error, e, action);
            }
        }, IDEHelperImpl::onRxException);
    });
    AzureTaskManager.getInstance().runInModal(task);
}
Also used : Project(com.intellij.openapi.project.Project) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) AzureToolkitRuntimeException(com.microsoft.azure.toolkit.lib.common.exception.AzureToolkitRuntimeException) InterruptedIOException(java.io.InterruptedIOException) IOException(java.io.IOException) AzureString(com.microsoft.azure.toolkit.lib.common.bundle.AzureString) AzureTask(com.microsoft.azure.toolkit.lib.common.task.AzureTask) VirtualFile(com.intellij.openapi.vfs.VirtualFile) LightVirtualFile(com.intellij.testFramework.LightVirtualFile) AppServiceFile(com.microsoft.azure.toolkit.lib.appservice.model.AppServiceFile) File(java.io.File) AzureString(com.microsoft.azure.toolkit.lib.common.bundle.AzureString) SneakyThrows(lombok.SneakyThrows)

Aggregations

AzureToolkitRuntimeException (com.microsoft.azure.toolkit.lib.common.exception.AzureToolkitRuntimeException)29 AzureOperation (com.microsoft.azure.toolkit.lib.common.operation.AzureOperation)13 IOException (java.io.IOException)13 AzureString (com.microsoft.azure.toolkit.lib.common.bundle.AzureString)9 File (java.io.File)5 AzureExecutionException (com.microsoft.azure.toolkit.lib.common.exception.AzureExecutionException)4 AzureTask (com.microsoft.azure.toolkit.lib.common.task.AzureTask)4 InvocationTargetException (java.lang.reflect.InvocationTargetException)4 HashMap (java.util.HashMap)4 VirtualFile (com.intellij.openapi.vfs.VirtualFile)3 Operation (com.microsoft.azuretools.telemetrywrapper.Operation)3 Path (java.nio.file.Path)3 PsiMethod (com.intellij.psi.PsiMethod)2 LightVirtualFile (com.intellij.testFramework.LightVirtualFile)2 MsalClientException (com.microsoft.aad.msal4j.MsalClientException)2 AuthorizationLevel (com.microsoft.azure.functions.annotation.AuthorizationLevel)2 AppServiceFile (com.microsoft.azure.toolkit.lib.appservice.model.AppServiceFile)2 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 DeserializationFeature (com.fasterxml.jackson.databind.DeserializationFeature)1