Search in sources :

Example 16 with Subscription

use of com.microsoft.azure.toolkit.lib.common.model.Subscription in project azure-tools-for-java by Microsoft.

the class AzureSDKManager method getLocationsForInsights.

public static List<String> getLocationsForInsights(String subscriptionId) throws IOException {
    final HttpGet request = new HttpGet(INSIGHTS_REGION_LIST_URL);
    final AzureManager azureManager = AuthMethodManager.getInstance().getAzureManager();
    if (azureManager == null) {
        return Collections.emptyList();
    }
    Subscription subscription = com.microsoft.azure.toolkit.lib.Azure.az(AzureAccount.class).account().getSubscription(subscriptionId);
    final String accessToken = azureManager.getAccessToken(subscription.getTenantId());
    request.setHeader("Authorization", String.format("Bearer %s", accessToken));
    final CloseableHttpResponse response = HttpClients.createDefault().execute(request);
    final InputStream responseStream = response.getEntity().getContent();
    try (final InputStreamReader isr = new InputStreamReader(responseStream)) {
        final Gson gson = new Gson();
        final JsonObject jsonContent = (gson).fromJson(isr, JsonObject.class);
        final JsonArray jsonResourceTypes = jsonContent.getAsJsonArray("resourceTypes");
        for (int i = 0; i < jsonResourceTypes.size(); ++i) {
            Object obj = jsonResourceTypes.get(i);
            if (obj instanceof JsonObject) {
                JsonObject jsonResourceType = (JsonObject) obj;
                String resourceType = jsonResourceType.get("resourceType").getAsString();
                if (resourceType.equalsIgnoreCase("components")) {
                    JsonArray jsonLocations = jsonResourceType.getAsJsonArray("locations");
                    return gson.fromJson(jsonLocations, new ArrayList().getClass());
                }
            }
        }
    } catch (IOException | JsonParseException e) {
        Log.error(e);
    }
    return Collections.emptyList();
}
Also used : AzureManager(com.microsoft.azuretools.sdkmanage.AzureManager) InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) HttpGet(org.apache.http.client.methods.HttpGet) ArrayList(java.util.ArrayList) Gson(com.google.gson.Gson) JsonObject(com.google.gson.JsonObject) IOException(java.io.IOException) JsonParseException(com.google.gson.JsonParseException) JsonArray(com.google.gson.JsonArray) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) JsonObject(com.google.gson.JsonObject) Subscription(com.microsoft.azure.toolkit.lib.common.model.Subscription)

Example 17 with Subscription

use of com.microsoft.azure.toolkit.lib.common.model.Subscription in project azure-tools-for-java by Microsoft.

the class CreateArmStorageAccountForm method fillRegions.

private void fillRegions() {
    Subscription subs = (Subscription) subscriptionComboBox.getData(subscriptionComboBox.getText());
    final List<Region> locations = Azure.az(AzureAccount.class).listRegions(subs.getId());
    AzureTaskManager.getInstance().runLater(() -> {
        for (Region location : locations) {
            regionComboBox.add(location.getLabel());
            regionComboBox.setData(location.getLabel(), location);
        }
        if (locations.size() > 0) {
            regionComboBox.select(0);
        }
    });
}
Also used : Region(com.microsoft.azure.toolkit.lib.common.model.Region) AzureAccount(com.microsoft.azure.toolkit.lib.auth.AzureAccount) Subscription(com.microsoft.azure.toolkit.lib.common.model.Subscription)

Example 18 with Subscription

use of com.microsoft.azure.toolkit.lib.common.model.Subscription in project azure-tools-for-java by Microsoft.

the class CreateArmStorageAccountForm method loadRegionsAndGroups.

public void loadRegionsAndGroups() {
    subscriptionComboBox.getData(subscriptionComboBox.getText()).toString();
    Subscription subs = (Subscription) subscriptionComboBox.getData(subscriptionComboBox.getText());
    if (subs != null) {
        AzureTaskManager.getInstance().runInBackground("Loading Available Locations...", () -> {
            try {
                // warm cache
                Azure.az(AzureAccount.class).listRegions(subs.getId());
                AzureTaskManager.getInstance().runLater(new Runnable() {

                    @Override
                    public void run() {
                        fillRegions();
                        fillGroups();
                    }
                });
            } catch (Exception ex) {
                PluginUtil.displayErrorDialogWithAzureMsg(PluginUtil.getParentShell(), Messages.err, "Error loading locations", ex);
            }
        });
    } else {
        fillRegions();
        fillGroups();
    }
}
Also used : AzureAccount(com.microsoft.azure.toolkit.lib.auth.AzureAccount) Subscription(com.microsoft.azure.toolkit.lib.common.model.Subscription)

Example 19 with Subscription

use of com.microsoft.azure.toolkit.lib.common.model.Subscription in project azure-tools-for-java by Microsoft.

the class CreateArmStorageAccountForm method fillGroups.

public void fillGroups() {
    final Subscription subs = (Subscription) subscriptionComboBox.getData(subscriptionComboBox.getText());
    List<ResourceGroup> resourceGroups = Azure.az(AzureGroup.class).list(subs.getId(), true);
    List<String> sortedGroups = resourceGroups.stream().map(ResourceGroup::getName).sorted().collect(Collectors.toList());
    AzureTaskManager.getInstance().runLater(new Runnable() {

        @Override
        public void run() {
            final Vector<Object> vector = new Vector<Object>();
            vector.addAll(sortedGroups);
            resourceGroupViewer.setInput(vector);
            if (sortedGroups.size() > 0) {
                resourceGrpCombo.select(0);
            }
        }
    });
}
Also used : AzureGroup(com.microsoft.azure.toolkit.lib.resource.AzureGroup) Subscription(com.microsoft.azure.toolkit.lib.common.model.Subscription) Vector(java.util.Vector) DraftResourceGroup(com.microsoft.azuretools.azureexplorer.forms.common.DraftResourceGroup) ResourceGroup(com.microsoft.azure.toolkit.lib.common.model.ResourceGroup)

Example 20 with Subscription

use of com.microsoft.azure.toolkit.lib.common.model.Subscription in project azure-tools-for-java by Microsoft.

the class AppInsightsMngmtPanel method refreshDataForDialog.

public static void refreshDataForDialog() {
    try {
        Project project = PluginUtil.getSelectedProject();
        if (AuthMethodManager.getInstance().isSignedIn()) {
            List<Subscription> subList = AuthMethodManager.getInstance().getAzureManager().getSelectedSubscriptions();
            // authenticated using AD. Proceed for updating application insights registry.
            updateApplicationInsightsResourceRegistry(subList, project);
        } else {
            // Neither clear subscription list nor show sign in dialog as user may just want to add key manually.
            keeepManuallyAddedList(project);
        }
    } catch (Exception ex) {
        AzurePlugin.log(ex.getMessage());
    }
}
Also used : Project(com.intellij.openapi.project.Project) Subscription(com.microsoft.azure.toolkit.lib.common.model.Subscription)

Aggregations

Subscription (com.microsoft.azure.toolkit.lib.common.model.Subscription)64 ResourceGroup (com.microsoft.azure.toolkit.lib.common.model.ResourceGroup)13 Region (com.microsoft.azure.toolkit.lib.common.model.Region)9 AzureManager (com.microsoft.azuretools.sdkmanage.AzureManager)9 AzureAccount (com.microsoft.azure.toolkit.lib.auth.AzureAccount)7 ArrayList (java.util.ArrayList)7 SelectionEvent (org.eclipse.swt.events.SelectionEvent)5 Project (com.intellij.openapi.project.Project)4 Azure (com.microsoft.azure.toolkit.lib.Azure)4 IAppServicePlan (com.microsoft.azure.toolkit.lib.appservice.service.IAppServicePlan)4 IWebApp (com.microsoft.azure.toolkit.lib.appservice.service.IWebApp)4 IOException (java.io.IOException)4 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)4 Point (org.eclipse.swt.graphics.Point)4 GridData (org.eclipse.swt.layout.GridData)4 Combo (org.eclipse.swt.widgets.Combo)4 PricingTier (com.microsoft.azure.toolkit.lib.appservice.model.PricingTier)3 AzureOperation (com.microsoft.azure.toolkit.lib.common.operation.AzureOperation)3 EventType (com.microsoft.azuretools.telemetrywrapper.EventType)3 EventUtil (com.microsoft.azuretools.telemetrywrapper.EventUtil)3