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;
}
use of com.microsoft.azuretools.sdkmanage.AzureManager in project azure-tools-for-java by Microsoft.
the class SettingsStep method prepare.
@Override
public JComponent prepare(WizardNavigationState wizardNavigationState) {
rootPanel.revalidate();
model.getCurrentNavigationState().NEXT.setEnabled(false);
try {
AzureManager azureManager = AuthMethodManager.getInstance().getAzureManager();
azure = azureManager.getAzure(model.getSubscription().getSubscriptionId());
} catch (Exception ex) {
DefaultLoader.getUIHelper().logError("An error occurred when trying to authenticate\n\n" + ex.getMessage(), ex);
}
fillResourceGroups();
retrieveStorageAccounts();
retrieveVirtualNetworks();
retrievePublicIpAddresses();
retrieveNetworkSecurityGroups();
retrieveAvailabilitySets();
return rootPanel;
}
use of com.microsoft.azuretools.sdkmanage.AzureManager in project azure-tools-for-java by Microsoft.
the class AzureDockerUtils method refreshDockerSubscriptions.
public static Map<String, AzureDockerSubscription> refreshDockerSubscriptions(AzureManager azureAuthManager) {
Map<String, AzureDockerSubscription> subsMap = new HashMap<>();
try {
if (DEBUG)
System.out.format("Get AzureDockerHostsManage subscription details: %s\n", new Date().toString());
SubscriptionManager subscriptionManager = azureAuthManager.getSubscriptionManager();
List<SubscriptionDetail> subscriptions = subscriptionManager.getSubscriptionDetails();
if (subscriptions != null) {
if (DEBUG)
System.out.format("Get AzureDockerHostsManage Docker subscription details: %s\n", new Date().toString());
Observable.from(subscriptions).flatMap(subscriptionDetail -> {
return Observable.create(new Observable.OnSubscribe<AzureDockerSubscription>() {
@Override
public void call(Subscriber<? super AzureDockerSubscription> dockerSubscriptionSubscriber) {
if (subscriptionDetail.isSelected()) {
AzureDockerSubscription dockerSubscription = new AzureDockerSubscription();
dockerSubscription.id = subscriptionDetail.getSubscriptionId();
try {
if (DEBUG)
System.out.format("\tGet AzureDockerHostsManage Docker subscription: %s at %s\n", dockerSubscription.id, new Date().toString());
dockerSubscription.tid = subscriptionDetail.getTenantId();
dockerSubscription.name = subscriptionDetail.getSubscriptionName();
dockerSubscription.azureClient = azureAuthManager.getAzure(dockerSubscription.id);
dockerSubscription.keyVaultClient = azureAuthManager.getKeyVaultClient(subscriptionDetail.getTenantId());
dockerSubscription.isSelected = true;
if (AzureDockerUtils.hasServicePrincipalAzureManager(azureAuthManager)) {
dockerSubscription.userId = null;
dockerSubscription.servicePrincipalId = azureAuthManager.getCurrentUserId();
} else {
dockerSubscription.userId = azureAuthManager.getCurrentUserId();
dockerSubscription.servicePrincipalId = null;
}
dockerSubscriptionSubscriber.onNext(dockerSubscription);
} catch (Exception e) {
e.printStackTrace();
DefaultLoader.getUIHelper().showError(e.getMessage(), "Error Loading Subscription Details for " + dockerSubscription.id);
}
}
dockerSubscriptionSubscriber.onCompleted();
}
}).subscribeOn(Schedulers.io());
}).subscribeOn(Schedulers.io()).toBlocking().subscribe(new Action1<AzureDockerSubscription>() {
@Override
public void call(AzureDockerSubscription dockerSubscription) {
subsMap.put(dockerSubscription.id, dockerSubscription);
}
});
}
if (DEBUG)
System.out.format("Get AzureDockerHostsManage locations: %s\n", new Date().toString());
List<Subscription> azureSubscriptionList = azureAuthManager.getSubscriptions();
for (Subscription subscription : azureSubscriptionList) {
AzureDockerSubscription dockerSubscription = subsMap.get(subscription.subscriptionId());
if (dockerSubscription != null) {
List<String> locations = subscription.listLocations().stream().sorted(Comparator.comparing(Location::displayName)).map(o -> o.name().toLowerCase()).collect(Collectors.toList());
dockerSubscription.locations = locations;
}
}
} catch (Exception e) {
e.printStackTrace();
DefaultLoader.getUIHelper().showError(e.getMessage(), "Error loading subscription details");
}
return subsMap;
}
Aggregations