use of com.microsoft.azuretools.authmanage.models.SubscriptionDetail in project azure-tools-for-java by Microsoft.
the class WebAppDeployDialog method doFillTable.
private void doFillTable() {
Map<SubscriptionDetail, List<ResourceGroup>> srgMap = AzureModel.getInstance().getSubscriptionToResourceGroupMap();
Map<ResourceGroup, List<WebApp>> rgwaMap = AzureModel.getInstance().getResourceGroupToWebAppMap();
Map<ResourceGroup, List<AppServicePlan>> rgaspMap = AzureModel.getInstance().getResourceGroupToAppServicePlanMap();
if (srgMap == null)
throw new NullPointerException("srgMap is null");
if (rgwaMap == null)
throw new NullPointerException("rgwaMap is null");
if (rgaspMap == null)
throw new NullPointerException("rgaspMap is null");
cleanTable();
DefaultTableModel tableModel = (DefaultTableModel) table.getModel();
for (SubscriptionDetail sd : srgMap.keySet()) {
if (!sd.isSelected())
continue;
Map<String, WebAppUtils.AspDetails> aspMap = new HashMap<>();
try {
for (ResourceGroup rg : srgMap.get(sd)) {
for (AppServicePlan asp : rgaspMap.get(rg)) {
aspMap.put(asp.id(), new WebAppUtils.AspDetails(asp, rg));
}
}
} catch (NullPointerException npe) {
LOGGER.error("NPE while initializing App Service Plan map", npe);
}
for (ResourceGroup rg : srgMap.get(sd)) {
for (WebApp wa : rgwaMap.get(rg)) {
if (wa.javaVersion() != JavaVersion.OFF) {
tableModel.addRow(new String[] { wa.name(), wa.javaVersion().toString(), wa.javaContainer() + " " + wa.javaContainerVersion(), wa.resourceGroupName() });
} else {
tableModel.addRow(new String[] { wa.name(), "Off", "N/A", wa.resourceGroupName() });
}
WebAppDetails webAppDetails = new WebAppDetails();
webAppDetails.webApp = wa;
webAppDetails.subscriptionDetail = sd;
webAppDetails.resourceGroup = rg;
webAppDetails.appServicePlan = aspMap.get(wa.appServicePlanId()).getAsp();
webAppDetails.appServicePlanResourceGroup = aspMap.get(wa.appServicePlanId()).getRg();
webAppWebAppDetailsMap.put(wa.name(), webAppDetails);
}
}
}
table.setModel(tableModel);
if (tableModel.getRowCount() > 0)
tableModel.fireTableDataChanged();
}
use of com.microsoft.azuretools.authmanage.models.SubscriptionDetail in project azure-tools-for-java by Microsoft.
the class SrvPriSettingsDialog method setSubscriptions.
private void setSubscriptions() {
for (SubscriptionDetail sd : sdl) {
model.addRow(new Object[] { sd.isSelected(), sd.getSubscriptionName(), sd.getSubscriptionId() });
model.fireTableDataChanged();
}
}
use of com.microsoft.azuretools.authmanage.models.SubscriptionDetail in project azure-tools-for-java by Microsoft.
the class AzureModelController method updateSubscriptionMaps.
public static synchronized void updateSubscriptionMaps(IProgressIndicator progressIndicator) throws IOException, CanceledByUserException, AuthException {
AzureManager azureManager = AuthMethodManager.getInstance().getAzureManager();
// not signed in
if (azureManager == null) {
return;
}
if (progressIndicator != null && progressIndicator.isCanceled()) {
clearAll();
throw new CanceledByUserException();
}
AzureModel azureModel = AzureModel.getInstance();
// to get regions we nees subscription objects
if (progressIndicator != null)
progressIndicator.setText("Reading subscription list...");
List<Subscription> sl = azureManager.getSubscriptions();
// convert to map to easier find by sid
Map<String, Subscription> sidToSubscriptionMap = azureModel.createSidToSubscriptionMap();
for (Subscription s : sl) {
sidToSubscriptionMap.put(s.subscriptionId(), s);
}
azureModel.setSidToSubscriptionMap(sidToSubscriptionMap);
Map<SubscriptionDetail, List<Location>> sdlocMap = azureModel.createSubscriptionToRegionMap();
Map<SubscriptionDetail, List<ResourceGroup>> sdrgMap = azureModel.createSubscriptionToResourceGroupMap();
SubscriptionManager subscriptionManager = azureManager.getSubscriptionManager();
subscriptionManager.addListener(subscriptionSelectionListener);
List<SubscriptionDetail> sdl = subscriptionManager.getSubscriptionDetails();
for (SubscriptionDetail sd : sdl) {
if (!sd.isSelected())
continue;
if (progressIndicator != null && progressIndicator.isCanceled()) {
clearAll();
throw new CanceledByUserException();
}
System.out.println("sn : " + sd.getSubscriptionName());
if (progressIndicator != null)
progressIndicator.setText("Reading subscription '" + sd.getSubscriptionName() + "'");
Azure azure = azureManager.getAzure(sd.getSubscriptionId());
List<ResourceGroup> rgList = azure.resourceGroups().list();
sdrgMap.put(sd, rgList);
List<Location> locl = sidToSubscriptionMap.get(sd.getSubscriptionId()).listLocations();
Collections.sort(locl, new Comparator<Location>() {
@Override
public int compare(Location lhs, Location rhs) {
return lhs.displayName().compareTo(rhs.displayName());
}
});
sdlocMap.put(sd, locl);
}
azureModel.setSubscriptionToResourceGroupMap(sdrgMap);
azureModel.setSubscriptionToLocationMap(sdlocMap);
}
use of com.microsoft.azuretools.authmanage.models.SubscriptionDetail in project azure-tools-for-java by Microsoft.
the class AzureModelController method subscriptionSelectionChanged.
private static synchronized void subscriptionSelectionChanged(IProgressIndicator progressIndicator) throws IOException, AuthException {
System.out.println("AzureModelController.subscriptionSelectionChanged: starting");
AzureManager azureManager = AuthMethodManager.getInstance().getAzureManager();
// not signed in
if (azureManager == null) {
System.out.println("AzureModelController.subscriptionSelectionChanged: azureManager == null -> return");
return;
}
SubscriptionManager subscriptionManager = azureManager.getSubscriptionManager();
AzureModel azureModel = AzureModel.getInstance();
Map<SubscriptionDetail, List<ResourceGroup>> srgMap = azureModel.getSubscriptionToResourceGroupMap();
if (srgMap == null) {
System.out.println("AzureModelController.subscriptionSelectionChanged: srgMap == null -> return");
return;
}
Map<String, Subscription> sidToSubscriptionMap = azureModel.getSidToSubscriptionMap();
if (sidToSubscriptionMap == null) {
System.out.println("AzureModelController.subscriptionSelectionChanged: sidToSubscriptionMap == null -> return");
return;
}
Map<ResourceGroup, List<WebApp>> rgwaMap = azureModel.getResourceGroupToWebAppMap();
Map<ResourceGroup, List<AppServicePlan>> rgspMap = azureModel.getResourceGroupToAppServicePlanMap();
System.out.println("AzureModelController.subscriptionSelectionChanged: getting subscription details...");
List<SubscriptionDetail> sdl = subscriptionManager.getSubscriptionDetails();
if (sdl == null) {
System.out.println("AzureModelController.subscriptionSelectionChanged: sdl == null -> return");
return;
}
for (SubscriptionDetail sd : sdl) {
if (!srgMap.containsKey(sd)) {
if (!sd.isSelected())
continue;
if (progressIndicator != null && progressIndicator.isCanceled()) {
progressIndicator.setText("Cancelling...");
clearAll();
return;
// FIXME: throw exception?
}
Azure azure = azureManager.getAzure(sd.getSubscriptionId());
// subscription locations
List<Subscription> sl = azureManager.getSubscriptions();
System.out.println("Updating subscription locations");
Subscription subscription = sidToSubscriptionMap.get(sd.getSubscriptionId());
if (progressIndicator != null)
progressIndicator.setText(String.format("Updating subscription '%s' locations...", subscription.displayName()));
List<Location> locl = subscription.listLocations();
Collections.sort(locl, new Comparator<Location>() {
@Override
public int compare(Location lhs, Location rhs) {
return lhs.displayName().compareTo(rhs.displayName());
}
});
Map<SubscriptionDetail, List<Location>> sdlocMap = azureModel.getSubscriptionToLocationMap();
sdlocMap.put(sd, locl);
// resource group maps
List<ResourceGroup> rgList = azure.resourceGroups().list();
srgMap.put(sd, rgList);
updateResGrDependency(azure, rgList, progressIndicator, rgwaMap, rgspMap);
} else {
// find and modify the key
for (SubscriptionDetail sdk : srgMap.keySet()) {
if (sdk.equals(sd)) {
sdk.setSelected(sd.isSelected());
}
}
}
}
}
use of com.microsoft.azuretools.authmanage.models.SubscriptionDetail in project azure-tools-for-java by Microsoft.
the class SubscriptionStep method createSubscriptionCombo.
private void createSubscriptionCombo(Composite container) {
Composite composite = new Composite(container, SWT.NONE);
GridLayout gridLayout = new GridLayout();
gridLayout.numColumns = 1;
GridData gridData = new GridData();
gridData.horizontalAlignment = SWT.FILL;
gridData.verticalAlignment = GridData.BEGINNING;
gridData.grabExcessHorizontalSpace = true;
composite.setLayout(gridLayout);
composite.setLayoutData(gridData);
this.subscriptionLabel = new Label(composite, SWT.LEFT);
this.subscriptionLabel.setText("Choose the subscription to use when creating the new virtual machine:");
this.subscriptionComboBox = new Combo(composite, SWT.READ_ONLY);
gridData = new GridData();
// gridData.widthHint = 182;
gridData.grabExcessHorizontalSpace = true;
gridData.horizontalAlignment = SWT.FILL;
subscriptionComboBox.setLayoutData(gridData);
subscriptionComboBox.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
if (subscriptionComboBox.getText() != null && !(subscriptionComboBox.getText().length() == 0)) {
wizard.setSubscription((SubscriptionDetail) subscriptionComboBox.getData(subscriptionComboBox.getText()));
}
}
});
loadSubscriptions();
}
Aggregations