use of com.microsoft.azure.management.Azure in project azure-tools-for-java by Microsoft.
the class DeleteDockerHostAction method actionPerformed.
@Override
public void actionPerformed(NodeActionEvent e) {
try {
dockerHost = dockerManager.getDockerHostForURL(dockerHost.apiUrl);
Azure azureClient = dockerManager.getSubscriptionsMap().get(dockerHost.sid).azureClient;
int option = AzureDockerUIResources.deleteAzureDockerHostConfirmationDialog(azureClient, dockerHost);
if (option != 1 && option != 2) {
if (AzureDockerUtils.DEBUG)
System.out.format("User canceled delete Docker host op: %d\n", option);
return;
}
DefaultLoader.getIdeHelper().invokeLater(new Runnable() {
@Override
public void run() {
// instruct parent node to remove this node
dockerHostNode.getParent().removeDirectChildNode(dockerHostNode);
}
});
AzureDockerUIResources.deleteDockerHost(project, azureClient, dockerHost, option, new Runnable() {
@Override
public void run() {
dockerManager.getDockerHostsList().remove(dockerHost);
}
});
} catch (Exception ex) {
DefaultLoader.getUIHelper().logError("DeleteDockerHostAction", ex);
}
}
use of com.microsoft.azure.management.Azure in project azure-tools-for-java by Microsoft.
the class AzureNewDockerHostStep method updateDockerHostVMSizeComboBox.
private void updateDockerHostVMSizeComboBox(boolean prefferedSizesOnly) {
DefaultComboBoxModel<String> dockerHostVMSizeComboModel = new DefaultComboBoxModel<>();
if (prefferedSizesOnly) {
for (KnownDockerVirtualMachineSizes knownDockerVirtualMachineSize : KnownDockerVirtualMachineSizes.values()) {
dockerHostVMSizeComboModel.addElement(knownDockerVirtualMachineSize.name());
}
if (dockerHostVMSizeComboModel.getSize() > 0) {
dockerHostVMSizeComboModel.setSelectedItem(dockerHostVMSizeComboModel.getElementAt(0));
}
} else {
dockerHostVMSizeComboModel.addElement("<Loading...>");
ProgressManager.getInstance().run(new Task.Backgroundable(model.getProject(), "Loading VM Sizes...", false) {
@Override
public void run(@NotNull ProgressIndicator progressIndicator) {
progressIndicator.setIndeterminate(true);
Azure azureClient = ((AzureDockerSubscription) dockerSubscriptionComboBox.getSelectedItem()).azureClient;
PagedList<VirtualMachineSize> sizes = null;
try {
sizes = azureClient.virtualMachines().sizes().listByRegion(preferredLocation);
Collections.sort(sizes, new Comparator<VirtualMachineSize>() {
@Override
public int compare(VirtualMachineSize size1, VirtualMachineSize size2) {
if (size1.name().contains("Basic") && size2.name().contains("Basic")) {
return size1.name().compareTo(size2.name());
} else if (size1.name().contains("Basic")) {
return -1;
} else if (size2.name().contains("Basic")) {
return 1;
}
int coreCompare = Integer.valueOf(size1.numberOfCores()).compareTo(size2.numberOfCores());
if (coreCompare == 0) {
return Integer.valueOf(size1.memoryInMB()).compareTo(size2.memoryInMB());
} else {
return coreCompare;
}
}
});
} catch (Exception notHandled) {
}
PagedList<VirtualMachineSize> sortedSizes = sizes;
ApplicationManager.getApplication().invokeAndWait(new Runnable() {
@Override
public void run() {
dockerHostVMSizeComboModel.removeAllElements();
if (sortedSizes != null) {
for (VirtualMachineSize vmSize : sortedSizes) {
dockerHostVMSizeComboModel.addElement(vmSize.name());
}
}
dockerHostVMSizeComboBox.repaint();
}
}, ModalityState.any());
}
});
}
dockerHostVMSizeComboBox.setModel(dockerHostVMSizeComboModel);
dockerHostVMSizeComboBox.setSelectedItem(newHost.hostVM.vmSize);
if (!newHost.hostVM.vmSize.equals((String) dockerHostVMSizeComboBox.getSelectedItem())) {
dockerHostVMSizeComboModel.addElement(newHost.hostVM.vmSize);
dockerHostVMSizeComboBox.setSelectedItem(newHost.hostVM.vmSize);
}
updateDockerSelectStorageComboBox((AzureDockerSubscription) dockerSubscriptionComboBox.getSelectedItem());
}
use of com.microsoft.azure.management.Azure in project azure-tools-for-java by Microsoft.
the class ServicePrincipalAzureManager method getAzure.
@Override
public Azure getAzure(String sid) throws IOException {
if (sidToAzureMap.containsKey(sid)) {
return sidToAzureMap.get(sid);
}
Azure azure = auth().withSubscription(sid);
// TODO: remove this call after Azure SDK properly implements handling of unregistered provider namespaces
AzureRegisterProviderNamespaces.registerAzureNamespaces(azure);
sidToAzureMap.put(sid, azure);
return azure;
}
use of com.microsoft.azure.management.Azure 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);
}
use of com.microsoft.azure.management.Azure in project azure-tools-for-java by Microsoft.
the class WebAppUtils method deleteAppService.
public static void deleteAppService(WebAppDetails webAppDetails) throws IOException {
AzureManager azureManager = AuthMethodManager.getInstance().getAzureManager();
Azure azure = azureManager.getAzure(webAppDetails.subscriptionDetail.getSubscriptionId());
azure.webApps().deleteById(webAppDetails.webApp.id());
// check asp still exists
AppServicePlan asp = azure.appServices().appServicePlans().getById(webAppDetails.appServicePlan.id());
System.out.println("asp is " + (asp == null ? "null -> removing form cache" : asp.name()));
// update cache
AzureModelController.removeWebAppFromResourceGroup(webAppDetails.resourceGroup, webAppDetails.webApp);
if (asp == null) {
AzureModelController.removeAppServicePlanFromResourceGroup(webAppDetails.appServicePlanResourceGroup, webAppDetails.appServicePlan);
}
}
Aggregations