use of com.microsoft.azuretools.sdkmanage.AzureManager in project azure-tools-for-java by Microsoft.
the class SubscriptionStep method loadSubscriptions.
private void loadSubscriptions() {
try {
AzureManager azureManager = AuthMethodManager.getInstance().getAzureManager();
// not signed in
if (azureManager == null) {
return;
}
/*
* if (manager.authenticated()) { String upn =
* manager.getUserInfo().getUniqueName();
* userInfoLabel.setText("Signed in as: " + (upn.contains("#") ?
* upn.split("#")[1] : upn)); } else { userInfoLabel.setText(""); }
*/
SubscriptionManager subscriptionManager = azureManager.getSubscriptionManager();
List<SubscriptionDetail> subscriptionDetails = subscriptionManager.getSubscriptionDetails();
for (SubscriptionDetail subscription : subscriptionDetails) {
if (subscription.isSelected()) {
subscriptionComboBox.add(subscription.getSubscriptionName());
subscriptionComboBox.setData(subscription.getSubscriptionName(), subscription);
}
}
if (!subscriptionDetails.isEmpty()) {
subscriptionComboBox.select(0);
wizard.setSubscription((SubscriptionDetail) subscriptionComboBox.getData(subscriptionComboBox.getText()));
}
setPageComplete(!subscriptionDetails.isEmpty());
} catch (Exception ex) {
DefaultLoader.getUIHelper().logError("An error occurred when trying to load Subscriptions\n\n" + ex.getMessage(), ex);
}
}
use of com.microsoft.azuretools.sdkmanage.AzureManager in project azure-tools-for-java by Microsoft.
the class SDKJarsFilter method setData.
private void setData() {
try {
AzureManager azureManager = AuthMethodManager.getInstance().getAzureManager();
// not signed in
if (azureManager == null) {
return;
}
List<SubscriptionDetail> subList = azureManager.getSubscriptionManager().getSubscriptionDetails();
if (subList.size() > 0 && !ApplicationInsightsPreferences.isLoaded()) {
// if (manager.authenticated()) {
// authenticated using AD. Proceed for updating application insights registry.
ApplicationInsightsResourceRegistryEclipse.updateApplicationInsightsResourceRegistry(subList);
// } else {
// imported publish settings file. just show manually added list from preferences
// Neither clear subscription list nor show sign in dialog as user may just want to add key manually.
// ApplicationInsightsResourceRegistryEclipse.keeepManuallyAddedList();
// }
}
} catch (Exception ex) {
Activator.getDefault().log(ex.getMessage(), ex);
}
comboInstrumentationKey.removeAll();
String[] array = ApplicationInsightsResourceRegistry.getResourcesNamesToDisplay();
if (array.length > 0) {
comboInstrumentationKey.setItems(array);
comboInstrumentationKey.setText(array[0]);
}
}
use of com.microsoft.azuretools.sdkmanage.AzureManager in project azure-tools-for-java by Microsoft.
the class CreateArmStorageAccountForm method createStorageAccount.
private boolean createStorageAccount() {
try {
boolean isNewResourceGroup = createNewRadioButton.isSelected();
final String resourceGroupName = isNewResourceGroup ? resourceGrpField.getText() : resourceGrpCombo.getSelectedItem().toString();
AzureSDKManager.createStorageAccount(((SubscriptionDetail) subscriptionComboBox.getSelectedItem()).getSubscriptionId(), nameTextField.getText(), ((Location) regionComboBox.getSelectedItem()).name(), isNewResourceGroup, resourceGroupName, (Kind) accoountKindCombo.getSelectedItem(), (AccessTier) accessTeirComboBox.getSelectedItem(), (Boolean) encriptonComboBox.getSelectedItem(), replicationComboBox.getSelectedItem().toString());
// update resource groups cache if new resource group was created when creating storage account
if (createNewRadioButton.isSelected()) {
AzureManager azureManager = AuthMethodManager.getInstance().getAzureManager();
// not signed in; does not matter what we return as storage account already created
if (azureManager == null) {
return true;
}
SubscriptionDetail subscriptionDetail = (SubscriptionDetail) subscriptionComboBox.getSelectedItem();
ResourceGroup rg = azureManager.getAzure(subscriptionDetail.getSubscriptionId()).resourceGroups().getByName(resourceGroupName);
AzureModelController.addNewResourceGroup(subscriptionDetail, rg);
}
DefaultLoader.getIdeHelper().invokeLater(new Runnable() {
@Override
public void run() {
if (onCreate != null) {
onCreate.run();
}
}
});
return true;
} catch (Exception e) {
String msg = "An error occurred while attempting to create the specified storage account in subscription " + ((SubscriptionDetail) subscriptionComboBox.getSelectedItem()).getSubscriptionId() + ".\n" + String.format(message("webappExpMsg"), e.getMessage());
DefaultLoader.getIdeHelper().invokeAndWait(() -> DefaultLoader.getUIHelper().showException(msg, e, message("errTtl"), false, true));
AzurePlugin.log(msg, e);
}
return false;
}
use of com.microsoft.azuretools.sdkmanage.AzureManager in project azure-tools-for-java by Microsoft.
the class CreateArmStorageAccountForm method fillFields.
public void fillFields(final SubscriptionDetail subscription, Location region) {
if (subscription == null) {
// loadRegions();
accoountKindCombo.setModel(new DefaultComboBoxModel(Kind.values()));
accoountKindCombo.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
if (e.getStateChange() == ItemEvent.SELECTED) {
fillPerformanceComboBox();
fillReplicationTypes();
boolean isBlobKind = e.getItem().equals(Kind.BLOB_STORAGE);
accessTeirComboBox.setVisible(isBlobKind);
accessTierLabel.setVisible(isBlobKind);
}
}
});
accessTeirComboBox.setModel(new DefaultComboBoxModel(AccessTier.values()));
subscriptionComboBox.setEnabled(true);
try {
AzureManager azureManager = AuthMethodManager.getInstance().getAzureManager();
// not signed in
if (azureManager == null) {
return;
}
SubscriptionManager subscriptionManager = azureManager.getSubscriptionManager();
List<SubscriptionDetail> subscriptionDetails = subscriptionManager.getSubscriptionDetails();
List<SubscriptionDetail> selectedSubscriptions = subscriptionDetails.stream().filter(SubscriptionDetail::isSelected).collect(Collectors.toList());
subscriptionComboBox.setModel(new DefaultComboBoxModel<>(selectedSubscriptions.toArray(new SubscriptionDetail[selectedSubscriptions.size()])));
if (selectedSubscriptions.size() > 0) {
loadRegions();
}
} catch (Exception ex) {
DefaultLoader.getUIHelper().logError("An error occurred when trying to load Subscriptions\n\n" + ex.getMessage(), ex);
}
subscriptionComboBox.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent itemEvent) {
loadRegions();
}
});
} else {
// if you create SA while creating VM
this.subscription = subscription;
subscriptionComboBox.addItem(subscription);
// only General purpose accounts supported for VMs
accoountKindCombo.addItem(Kind.STORAGE);
accoountKindCombo.setEnabled(false);
// Access tier is not available for General purpose accounts
accessTeirComboBox.setVisible(false);
accessTierLabel.setVisible(false);
regionComboBox.addItem(region);
regionComboBox.setEnabled(false);
loadGroups();
}
//performanceComboBox.setModel(new DefaultComboBoxModel(SkuTier.values()));
fillPerformanceComboBox();
performanceComboBox.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
if (e.getStateChange() == ItemEvent.SELECTED) {
fillReplicationTypes();
}
}
});
replicationComboBox.setRenderer(new ListCellRendererWrapper<ReplicationTypes>() {
@Override
public void customize(JList jList, ReplicationTypes replicationTypes, int i, boolean b, boolean b1) {
if (replicationTypes != null) {
setText(replicationTypes.getDescription());
}
}
});
fillReplicationTypes();
}
use of com.microsoft.azuretools.sdkmanage.AzureManager 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(((VMWizardModel) model).getSubscription().getSubscriptionId());
} 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().equals(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 (vmSizeComboBox.getItemCount() == 0) {
vmSizeComboBox.setModel(new DefaultComboBoxModel(new String[] { "<Loading...>" }));
ProgressManager.getInstance().run(new Task.Backgroundable(project, "Loading VM sizes...", false) {
@Override
public void run(@NotNull ProgressIndicator progressIndicator) {
progressIndicator.setIndeterminate(true);
PagedList<com.microsoft.azure.management.compute.VirtualMachineSize> sizes = azure.virtualMachines().sizes().listByRegion(model.getRegion().name());
Collections.sort(sizes, new Comparator<VirtualMachineSize>() {
@Override
public int compare(VirtualMachineSize t0, VirtualMachineSize 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;
}
}
});
ApplicationManager.getApplication().invokeAndWait(new Runnable() {
@Override
public void run() {
vmSizeComboBox.setModel(new DefaultComboBoxModel<>(sizes.stream().map(VirtualMachineSize::name).toArray(String[]::new)));
selectDefaultSize();
}
}, ModalityState.any());
}
});
} else {
selectDefaultSize();
}
return rootPanel;
}
Aggregations