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;
}
use of com.microsoft.azuretools.sdkmanage.AzureManager in project azure-tools-for-java by Microsoft.
the class ApplicationInsightsNewDialog method populateResourceGroupValues.
private void populateResourceGroupValues(String subscriptionId, String valtoSet) {
try {
com.microsoft.azuretools.sdkmanage.AzureManager azureManager = AuthMethodManager.getInstance().getAzureManager();
Azure azure = azureManager.getAzure(subscriptionId);
List<com.microsoft.azure.management.resources.ResourceGroup> groups = azure.resourceGroups().list();
List<String> groupStringList = groups.stream().map(com.microsoft.azure.management.resources.ResourceGroup::name).collect(Collectors.toList());
if (groupStringList.size() > 0) {
String[] groupArray = groupStringList.toArray(new String[groupStringList.size()]);
comboGrp.removeAllItems();
comboGrp.setModel(new DefaultComboBoxModel(groupArray));
if (valtoSet == null || valtoSet.isEmpty() || !groupStringList.contains(valtoSet)) {
comboGrp.setSelectedItem(groupArray[0]);
} else {
comboGrp.setSelectedItem(valtoSet);
}
}
} catch (Exception ex) {
AzurePlugin.log(message("getValuesErrMsg"), ex);
}
}
use of com.microsoft.azuretools.sdkmanage.AzureManager in project azure-tools-for-java by Microsoft.
the class CreateNewDockerHostAction method actionPerformed.
@Override
public void actionPerformed(NodeActionEvent e) {
try {
if (!AzureSignInAction.doSignIn(AuthMethodManager.getInstance(), project))
return;
AzureManager azureAuthManager = AuthMethodManager.getInstance().getAzureManager();
// not signed in
if (azureAuthManager == null) {
return;
}
AzureDockerHostsManager dockerManager = AzureDockerHostsManager.getAzureDockerHostsManagerEmpty(azureAuthManager);
if (!dockerManager.isInitialized()) {
AzureDockerUIResources.updateAzureResourcesWithProgressDialog(project);
if (AzureDockerUIResources.CANCELED) {
return;
}
dockerManager = AzureDockerHostsManager.getAzureDockerHostsManagerEmpty(null);
}
if (dockerManager.getSubscriptionsMap().isEmpty()) {
PluginUtil.displayErrorDialog("Create Docker Host", "Must select an Azure subscription first");
return;
}
AzureNewDockerWizardModel newDockerHostModel = new AzureNewDockerWizardModel(project, dockerManager);
AzureNewDockerWizardDialog wizard = new AzureNewDockerWizardDialog(newDockerHostModel);
wizard.setTitle("Create Docker Host");
wizard.show();
if (wizard.getExitCode() == 0) {
dockerHost = newDockerHostModel.getDockerHost();
wizard.create();
System.out.println("New Docker host will be created at: " + dockerHost.apiUrl);
}
} catch (Exception ex1) {
ex1.printStackTrace();
}
}
use of com.microsoft.azuretools.sdkmanage.AzureManager in project azure-tools-for-java by Microsoft.
the class AzureModelController method updateResourceGroupMaps.
public static synchronized void updateResourceGroupMaps(IProgressIndicator progressIndicator) throws IOException, CanceledByUserException, AuthException {
AzureManager azureManager = AuthMethodManager.getInstance().getAzureManager();
// not signed in
if (azureManager == null) {
return;
}
updateSubscriptionMaps(progressIndicator);
AzureModel azureModel = AzureModel.getInstance();
Map<ResourceGroup, List<WebApp>> rgwaMap = azureModel.createResourceGroupToWebAppMap();
Map<ResourceGroup, List<AppServicePlan>> rgspMap = azureModel.createResourceGroupToAppServicePlanMap();
for (SubscriptionDetail sd : azureModel.getSubscriptionToResourceGroupMap().keySet()) {
if (progressIndicator != null && progressIndicator.isCanceled()) {
clearAll();
throw new CanceledByUserException();
}
List<ResourceGroup> rgList = azureModel.getSubscriptionToResourceGroupMap().get(sd);
if (rgList.size() == 0) {
System.out.println("no resource groups found!");
continue;
}
Azure azure = azureManager.getAzure(sd.getSubscriptionId());
updateResGrDependency(azure, rgList, progressIndicator, rgwaMap, rgspMap);
}
azureModel.setResourceGroupToWebAppMap(rgwaMap);
azureModel.setResourceGroupToAppServicePlanMap(rgspMap);
}
Aggregations