use of com.microsoft.azure.toolkit.lib.common.bundle.AzureString in project azure-tools-for-java by Microsoft.
the class SpringCloudStreamingLogAction method startLogStreaming.
public static void startLogStreaming(@Nonnull SpringCloudApp app, @Nullable Project project) {
final IAzureMessager messager = AzureMessager.getMessager();
final AzureString title = AzureOperationBundle.title("springcloud|log_stream.open", app.name());
AzureTaskManager.getInstance().runInBackground(new AzureTask<>(project, title, false, () -> {
try {
final SpringCloudDeployment deployment = app.activeDeployment();
if (deployment == null || !deployment.exists()) {
messager.warning(NO_ACTIVE_DEPLOYMENT, FAILED_TO_START_LOG_STREAMING);
return;
}
final List<SpringCloudDeploymentInstanceEntity> instances = deployment.entity().getInstances();
if (CollectionUtils.isEmpty(instances)) {
messager.warning(NO_AVAILABLE_INSTANCES, FAILED_TO_START_LOG_STREAMING);
} else {
showLogStreamingDialog(instances, app, project);
}
} catch (final Exception e) {
final String errorMessage = StringUtils.isEmpty(e.getMessage()) ? FAILED_TO_LIST_INSTANCES : String.format(FAILED_TO_LIST_INSTANCES_WITH_MESSAGE, e.getMessage());
messager.error(errorMessage, FAILED_TO_START_LOG_STREAMING);
}
}));
}
use of com.microsoft.azure.toolkit.lib.common.bundle.AzureString in project azure-tools-for-java by Microsoft.
the class SpringCloudStreamingLogConsoleView method shutdown.
public void shutdown() {
synchronized (this) {
if (getStatus() != ConsoleViewStatus.ACTIVE && getStatus() != ConsoleViewStatus.STARTING) {
return;
}
setStatus(ConsoleViewStatus.STOPPING);
}
final AzureString title = AzureOperationBundle.title("springcloud|log_stream.close", resourceName);
AzureTaskManager.getInstance().runInBackground(new AzureTask<>(getProject(), title, false, () -> {
try {
if (logInputStream != null) {
logInputStream.close();
}
if (executorService != null) {
ThreadPoolUtils.stop(executorService, 100, TimeUnit.MICROSECONDS);
}
} catch (final IOException e) {
// swallow io exception when close
} finally {
setStatus(ConsoleViewStatus.STOPPED);
}
}));
}
use of com.microsoft.azure.toolkit.lib.common.bundle.AzureString in project azure-tools-for-java by Microsoft.
the class SignInCommandHandler method loginNonDeviceCodeSingle.
private static Single<AuthMethodDetails> loginNonDeviceCodeSingle(AuthConfiguration auth) {
final AzureString title = AzureOperationBundle.title("account.sign_in");
final AzureTask<AuthMethodDetails> task = new AzureTask<>(null, title, true, () -> doLogin(AzureTaskContext.current().getTask().getMonitor(), auth));
return AzureTaskManager.getInstance().runInBackgroundAsObservable(task).toSingle();
}
use of com.microsoft.azure.toolkit.lib.common.bundle.AzureString 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);
}
use of com.microsoft.azure.toolkit.lib.common.bundle.AzureString in project azure-tools-for-java by Microsoft.
the class BlobExplorerFileEditor method downloadSelectedFile.
private void downloadSelectedFile(final File targetFile, final boolean open) {
final BlobFile fileSelection = getFileSelection();
if (fileSelection != null) {
final AzureString title = AzureOperationBundle.title("blob.download", targetFile, blobContainer.getName());
AzureTaskManager.getInstance().runInBackground(new AzureTask(project, title, false, () -> {
final ProgressIndicator progressIndicator = ProgressManager.getInstance().getProgressIndicator();
try {
progressIndicator.setIndeterminate(false);
if (!targetFile.exists()) {
if (!targetFile.createNewFile()) {
throw new IOException("File not created");
}
}
final BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(new FileOutputStream(targetFile), 65536) {
private long runningCount = 0;
@Override
public synchronized void write(@NotNull byte[] bytes, int i, int i1) throws IOException {
super.write(bytes, i, i1);
runningCount += i1;
double progress = (double) runningCount / fileSelection.getSize();
progressIndicator.setFraction(progress);
progressIndicator.setText2(String.format("%s%% downloaded", (int) (progress * 100)));
}
};
try {
Future<?> future = ApplicationManager.getApplication().executeOnPooledThread(new Runnable() {
@Override
public void run() {
try {
StorageClientSDKManager.getManager().downloadBlobFileContent(connectionString, fileSelection, bufferedOutputStream);
if (open && targetFile.exists()) {
Desktop.getDesktop().open(targetFile);
}
} catch (AzureCmdException e) {
Throwable connectionFault = e.getCause().getCause();
progressIndicator.setText("Error downloading Blob");
progressIndicator.setText2((connectionFault instanceof SocketTimeoutException) ? "Connection timed out" : connectionFault.getMessage());
} catch (IOException ex) {
try {
final Process p;
Runtime runtime = Runtime.getRuntime();
p = runtime.exec(new String[] { "open", "-R", targetFile.getName() }, null, targetFile.getParentFile());
InputStream errorStream = p.getErrorStream();
String errResponse = new String(IOUtils.readFully(errorStream, -1));
if (p.waitFor() != 0) {
throw new Exception(errResponse);
}
} catch (Exception e) {
progressIndicator.setText("Error openning file");
progressIndicator.setText2(ex.getMessage());
}
}
}
});
while (!future.isDone()) {
progressIndicator.checkCanceled();
if (progressIndicator.isCanceled()) {
future.cancel(true);
}
}
} finally {
bufferedOutputStream.close();
}
} catch (IOException e) {
PluginUtil.displayErrorDialogAndLog(message("errTtl"), "An error occurred while attempting to download Blob.", e);
}
}));
}
}
Aggregations