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();
}
}
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();
}
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);
}
}
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));
}
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);
}
Aggregations