use of com.microsoft.azure.toolkit.lib.common.task.AzureTask in project azure-tools-for-java by Microsoft.
the class ResourceTemplateView method updateDeployment.
private void updateDeployment() {
String oldTemplate = this.originTemplate;
String oldParameters = this.originParameters;
final AzureString title = AzureOperationBundle.title("arm|deployment.update", node.getDeployment().name());
AzureTaskManager.getInstance().runInBackground(new AzureTask(project, title, false, () -> {
EventUtil.executeWithLog(ARM, UPDATE_DEPLOYMENT_SHORTCUT, (operation -> {
ResourceTemplateView.this.originTemplate = getTemplate();
ResourceTemplateView.this.originParameters = getParameters();
node.getDeployment().update().withTemplate(ResourceTemplateView.this.originTemplate).withParameters(ResourceTemplateView.this.originParameters).withMode(DeploymentMode.INCREMENTAL).apply();
UIUtils.showNotification(project, NOTIFY_UPDATE_DEPLOYMENT_SUCCESS, MessageType.INFO);
}), (e) -> {
// Fall back the origin value when update fail.
ResourceTemplateView.this.originTemplate = oldTemplate;
ResourceTemplateView.this.originParameters = oldParameters;
UIUtils.showNotification(project, NOTIFY_UPDATE_DEPLOYMENT_FAIL + ", " + e.getMessage(), MessageType.ERROR);
});
}));
}
use of com.microsoft.azure.toolkit.lib.common.task.AzureTask in project azure-tools-for-java by Microsoft.
the class UpdateDeploymentForm method doOKAction.
@Override
protected void doOKAction() {
String deploymentName = deploymentNode.getDeployment().name();
final AzureString title = AzureOperationBundle.title("arm|deployment.update", deploymentName);
AzureTaskManager.getInstance().runInBackground(new AzureTask(project, title, false, () -> {
EventUtil.executeWithLog(TelemetryConstants.ARM, TelemetryConstants.UPDATE_DEPLOYMENT, (operation -> {
Deployment.Update update = deploymentNode.getDeployment().update();
String templatePath = templateTextField.getText();
update = update.withTemplate(IOUtils.toString(new FileReader(templatePath)));
String parametersPath = parametersTextField.getText();
if (!StringUtils.isEmpty(parametersPath)) {
String parameters = IOUtils.toString(new FileReader(parametersPath));
update = update.withParameters(DeploymentUtils.parseParameters(parameters));
}
update.withMode(DeploymentMode.INCREMENTAL).apply();
UIUtils.showNotification(statusBar, NOTIFY_UPDATE_DEPLOYMENT_SUCCESS, MessageType.INFO);
}), (e) -> {
UIUtils.showNotification(statusBar, NOTIFY_UPDATE_DEPLOYMENT_FAIL + ", " + e.getMessage(), MessageType.ERROR);
});
}));
close(OK_EXIT_CODE, true);
}
use of com.microsoft.azure.toolkit.lib.common.task.AzureTask in project azure-tools-for-java by Microsoft.
the class AppServiceFileNode method onNodeDblClicked.
@Override
public void onNodeDblClicked(Object context) {
if (this.file.getType() == AppServiceFile.Type.DIRECTORY) {
return;
} else if (this.file.getSize() > SIZE_20MB) {
DefaultLoader.getUIHelper().showError("File is too large, please download it first", "File is Too Large");
return;
}
final Runnable runnable = () -> open(context);
final AzureString title = AzureOperationBundle.title("appservice|file.get_content", file.getName(), file.getApp().name());
AzureTaskManager.getInstance().runInBackground(new AzureTask(this.getProject(), title, false, runnable));
}
use of com.microsoft.azure.toolkit.lib.common.task.AzureTask 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.task.AzureTask 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);
}
Aggregations