use of com.microsoft.azure.toolkit.lib.common.task.AzureTask in project azure-tools-for-java by Microsoft.
the class CreateDeploymentForm method doOKAction.
@Override
protected void doOKAction() {
deploymentName = deploymentNameTextField.getText();
final AzureString title = AzureOperationBundle.title("arm|deployment.deploy", deploymentName);
AzureTaskManager.getInstance().runInBackground(new AzureTask(project, title, false, () -> {
EventUtil.executeWithLog(TelemetryConstants.ARM, TelemetryConstants.CREATE_DEPLOYMENT, (operation -> {
Subscription subs = (Subscription) subscriptionCb.getSelectedItem();
com.microsoft.azure.management.Azure azure = AuthMethodManager.getInstance().getAzureClient(subs.getId());
WithTemplate template;
if (createNewRgButton.isSelected()) {
rgName = rgNameTextFiled.getText();
final Region region = (Region) regionCb.getSelectedItem();
template = azure.deployments().define(deploymentName).withNewResourceGroup(rgNameTextFiled.getText(), com.microsoft.azure.management.resources.fluentcore.arm.Region.fromName(region.getName()));
} else {
ResourceGroup rg = (ResourceGroup) rgNameCb.getSelectedItem();
List<ResourceEx<Deployment>> deployments = AzureMvpModel.getInstance().getDeploymentByRgName(subs.getId(), rg.getName());
boolean isExist = deployments.parallelStream().anyMatch(deployment -> deployment.getResource().name().equals(deploymentName));
if (isExist) {
throw new RuntimeException(DUPLICATED_DEPLOYMENT_NAME);
}
rgName = rg.getName();
template = azure.deployments().define(deploymentName).withExistingResourceGroup(rg.getName());
}
String fileText = templateTextField.getText();
String content = IOUtils.toString(new FileReader(fileText));
String parametersPath = parametersTextField.getText();
String parameters = StringUtils.isEmpty(parametersPath) ? "{}" : IOUtils.toString(new FileReader(parametersPath));
parameters = DeploymentUtils.parseParameters(parameters);
template.withTemplate(content).withParameters(parameters).withMode(DeploymentMode.INCREMENTAL).create();
UIUtils.showNotification(statusBar, NOTIFY_CREATE_DEPLOYMENT_SUCCESS, MessageType.INFO);
updateUI();
}), (ex) -> {
UIUtils.showNotification(statusBar, NOTIFY_CREATE_DEPLOYMENT_FAIL + ", " + ex.getMessage(), MessageType.ERROR);
updateUI();
});
}));
close(DialogWrapper.OK_EXIT_CODE, true);
}
use of com.microsoft.azure.toolkit.lib.common.task.AzureTask 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.task.AzureTask in project azure-tools-for-java by Microsoft.
the class StartStreamingLogsAction method actionPerformed.
@Override
protected void actionPerformed(NodeActionEvent nodeActionEvent) throws AzureCmdException {
final AzureString title = AzureOperationBundle.title("appservice|log_stream.start", ResourceUtils.nameFromResourceId(resourceId));
AzureTaskManager.getInstance().runInBackground(new AzureTask(project, title, false, () -> {
switch(operation) {
case START_STREAMING_LOG_FUNCTION_APP:
AppServiceStreamingLogManager.INSTANCE.showFunctionStreamingLog(project, resourceId);
break;
case START_STREAMING_LOG_WEBAPP:
AppServiceStreamingLogManager.INSTANCE.showWebAppStreamingLog(project, resourceId);
break;
case START_STREAMING_LOG_WEBAPP_SLOT:
AppServiceStreamingLogManager.INSTANCE.showWebAppDeploymentSlotStreamingLog(project, resourceId);
break;
default:
DefaultLoader.getUIHelper().showError("Unsupported operation", "Unsupported operation");
break;
}
}));
}
use of com.microsoft.azure.toolkit.lib.common.task.AzureTask in project azure-tools-for-java by Microsoft.
the class ApplicationInsightsNewDialog method doOKAction.
@Override
protected void doOKAction() {
final boolean grpNotSelected = Objects.isNull(comboGrp.getSelectedItem()) || ((String) comboGrp.getSelectedItem()).isEmpty();
final boolean regNotSelected = Objects.isNull(comboReg.getSelectedItem()) || ((String) comboReg.getSelectedItem()).isEmpty();
final boolean subNotSelected = comboSub.getSelectedItem() == null;
if (txtName.getText().trim().isEmpty() || subNotSelected || (grpNotSelected && useExistingBtn.isSelected()) || (textGrp.getText().isEmpty() && createNewBtn.isSelected()) || regNotSelected) {
if (subNotSelected || comboSub.getItemCount() <= 0) {
PluginUtil.displayErrorDialog(message("aiErrTtl"), message("noSubErrMsg"));
} else if (grpNotSelected || comboGrp.getItemCount() <= 0) {
PluginUtil.displayErrorDialog(message("aiErrTtl"), message("noResGrpErrMsg"));
} else {
PluginUtil.displayErrorDialog(message("aiErrTtl"), message("nameEmptyMsg"));
}
} else {
boolean isNewGroup = createNewBtn.isSelected();
String resourceGroup = isNewGroup ? textGrp.getText() : (String) comboGrp.getSelectedItem();
final AzureString title = AzureOperationBundle.title("ai.create.rg", txtName.getText(), resourceGroup);
AzureTaskManager.getInstance().runInBackground(new AzureTask(null, title, false, () -> {
try {
ApplicationInsightsComponent resource = AzureSDKManager.createInsightsResource(currentSub, resourceGroup, isNewGroup, txtName.getText(), (String) comboReg.getSelectedItem());
resourceToAdd = new ApplicationInsightsResource(resource, currentSub, true);
if (onCreate != null) {
onCreate.run();
}
} catch (Exception ex) {
PluginUtil.displayErrorDialogInAWTAndLog(message("aiErrTtl"), message("resCreateErrMsg"), ex);
}
}));
super.doOKAction();
}
}
use of com.microsoft.azure.toolkit.lib.common.task.AzureTask 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