use of com.microsoft.azure.toolkit.lib.common.task.AzureTask in project azure-tools-for-java by Microsoft.
the class MachineSettingsStep method prepare.
@Override
public JComponent prepare(WizardNavigationState wizardNavigationState) {
rootPanel.revalidate();
boolean isLinux;
try {
AzureManager azureManager = AuthMethodManager.getInstance().getAzureManager();
azure = azureManager.getAzure(model.getSubscription().getId());
} catch (Exception ex) {
DefaultLoader.getUIHelper().logError("An error occurred when trying to authenticate\n\n" + ex.getMessage(), ex);
}
if (model.isKnownMachineImage()) {
isLinux = model.getKnownMachineImage() instanceof KnownLinuxVirtualMachineImage;
} else {
isLinux = model.getVirtualMachineImage().osDiskImage().operatingSystem() == OperatingSystemTypes.LINUX;
}
if (isLinux) {
certificateCheckBox.setEnabled(true);
passwordCheckBox.setEnabled(true);
certificateCheckBox.setSelected(false);
passwordCheckBox.setSelected(true);
} else {
certificateCheckBox.setSelected(false);
passwordCheckBox.setSelected(true);
certificateCheckBox.setEnabled(false);
passwordCheckBox.setEnabled(false);
}
validateEmptyFields();
if (model.getRegion() != null && (vmSizeComboBox.getItemCount() == 0 || vmSizeComboBox.getItemAt(0).contains("<Loading...>"))) {
vmSizeComboBox.setModel(new DefaultComboBoxModel(new String[] { "<Loading...>" }));
final AzureString title = AzureOperationBundle.title("vm.list_sizes.region", model.getRegion().getName());
AzureTaskManager.getInstance().runInBackground(new AzureTask(project, title, false, () -> {
final ProgressIndicator progressIndicator = ProgressManager.getInstance().getProgressIndicator();
progressIndicator.setIndeterminate(true);
PagedList<com.microsoft.azure.management.compute.VirtualMachineSize> sizes = azure.virtualMachines().sizes().listByRegion(model.getRegion().getName());
sizes.sort((t0, t1) -> {
if (t0.name().contains("Basic") && t1.name().contains("Basic")) {
return t0.name().compareTo(t1.name());
} else if (t0.name().contains("Basic")) {
return -1;
} else if (t1.name().contains("Basic")) {
return 1;
}
int coreCompare = Integer.valueOf(t0.numberOfCores()).compareTo(t1.numberOfCores());
if (coreCompare == 0) {
return Integer.valueOf(t0.memoryInMB()).compareTo(t1.memoryInMB());
} else {
return coreCompare;
}
});
AzureTaskManager.getInstance().runAndWait(() -> {
vmSizeComboBox.setModel(new DefaultComboBoxModel<>(sizes.stream().map(VirtualMachineSize::name).toArray(String[]::new)));
selectDefaultSize();
}, AzureTask.Modality.ANY);
}));
} else {
selectDefaultSize();
}
return rootPanel;
}
use of com.microsoft.azure.toolkit.lib.common.task.AzureTask in project azure-tools-for-java by Microsoft.
the class SelectImageStep method fillPublishers.
private void fillPublishers() {
if (customImageBtn.isSelected()) {
disableNext();
final AzureString title = AzureOperationBundle.title("vm|publisher.list");
AzureTaskManager.getInstance().runInBackground(new AzureTask(project, title, false, () -> {
final ProgressIndicator progressIndicator = ProgressManager.getInstance().getProgressIndicator();
progressIndicator.setIndeterminate(true);
final Object selectedItem = regionComboBox.getSelectedItem();
final Region location = selectedItem instanceof Region ? (Region) selectedItem : null;
if (location == null) {
return;
}
clearSelection(publisherComboBox, offerComboBox, skuComboBox, imageLabelList);
RxJavaUtils.unsubscribeSubscription(fillPublisherSubscription);
fillPublisherSubscription = Observable.fromCallable(() -> azure.virtualMachineImages().publishers().listByRegion(location.getName())).subscribeOn(Schedulers.io()).subscribe(publisherList -> DefaultLoader.getIdeHelper().invokeLater(() -> {
publisherComboBox.setModel(new DefaultComboBoxModel(publisherList.toArray()));
fillOffers();
}), error -> {
final String msg = String.format(ERROR_MESSAGE_LIST_PUBLISHER, String.format(message("webappExpMsg"), error.getMessage()));
handleError(msg, error);
});
}));
}
}
use of com.microsoft.azure.toolkit.lib.common.task.AzureTask in project azure-tools-for-java by Microsoft.
the class SelectImageStep method fillSkus.
private void fillSkus() {
disableNext();
if (offerComboBox.getItemCount() > 0) {
final VirtualMachineOffer offer = (VirtualMachineOffer) offerComboBox.getSelectedItem();
final AzureString title = AzureOperationBundle.title("vm|sku.list", offer.name());
AzureTaskManager.getInstance().runInBackground(new AzureTask(project, title, false, () -> {
final ProgressIndicator progressIndicator = ProgressManager.getInstance().getProgressIndicator();
progressIndicator.setIndeterminate(true);
RxJavaUtils.unsubscribeSubscription(fillSkuSubscription);
clearSelection(skuComboBox, imageLabelList);
fillSkuSubscription = Observable.fromCallable(() -> offer.skus().list()).subscribeOn(Schedulers.io()).subscribe(skuList -> DefaultLoader.getIdeHelper().invokeLater(() -> {
skuComboBox.setModel(new DefaultComboBoxModel(skuList.toArray()));
fillImages();
}), error -> {
String msg = String.format(ERROR_MESSAGE_FILL_SKUS, String.format(message("webappExpMsg"), error.getMessage()));
handleError(msg, error);
});
}));
} else {
skuComboBox.removeAllItems();
imageLabelList.setListData(new Object[] {});
}
}
Aggregations