Search in sources :

Example 96 with Subscription

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

the class SettingPanel method apply.

/**
 * Function triggered by any content change events.
 *
 * @param webAppOnLinuxDeployConfiguration configuration instance
 */
@Override
public void apply(WebAppOnLinuxDeployConfiguration webAppOnLinuxDeployConfiguration) {
    webAppOnLinuxDeployConfiguration.setDockerFilePath(containerSettingPanel.getDockerPath());
    // set ACR info
    webAppOnLinuxDeployConfiguration.setPrivateRegistryImageSetting(new PrivateRegistryImageSetting(containerSettingPanel.getServerUrl().replaceFirst("^https?://", "").replaceFirst("/$", ""), containerSettingPanel.getUserName(), containerSettingPanel.getPassword(), containerSettingPanel.getImageTag(), containerSettingPanel.getStartupFile()));
    final ISecureStore secureStore = AzureStoreManager.getInstance().getSecureStore();
    secureStore.savePassword(PRIVATE_DOCKER_REGISTRY, containerSettingPanel.getServerUrl(), containerSettingPanel.getUserName(), containerSettingPanel.getPassword());
    webAppOnLinuxDeployConfiguration.setTargetPath(getTargetPath());
    webAppOnLinuxDeployConfiguration.setTargetName(getTargetName());
    // set web app info
    if (rdoUseExist.isSelected()) {
        // existing web app
        webAppOnLinuxDeployConfiguration.setCreatingNewWebAppOnLinux(false);
        IWebApp selectedWebApp = null;
        final int index = webAppTable.getSelectedRow();
        if (cachedWebAppList != null && index >= 0 && index < cachedWebAppList.size()) {
            selectedWebApp = cachedWebAppList.get(webAppTable.getSelectedRow());
        }
        if (selectedWebApp != null) {
            webAppOnLinuxDeployConfiguration.setWebAppId(selectedWebApp.id());
            webAppOnLinuxDeployConfiguration.setAppName(selectedWebApp.name());
            webAppOnLinuxDeployConfiguration.setSubscriptionId(selectedWebApp.subscriptionId());
            webAppOnLinuxDeployConfiguration.setResourceGroupName(selectedWebApp.resourceGroup());
        } else {
            webAppOnLinuxDeployConfiguration.setWebAppId(null);
            webAppOnLinuxDeployConfiguration.setAppName(null);
            webAppOnLinuxDeployConfiguration.setSubscriptionId(null);
            webAppOnLinuxDeployConfiguration.setResourceGroupName(null);
        }
    } else if (rdoCreateNew.isSelected()) {
        // create new web app
        webAppOnLinuxDeployConfiguration.setCreatingNewWebAppOnLinux(true);
        webAppOnLinuxDeployConfiguration.setWebAppId("");
        webAppOnLinuxDeployConfiguration.setAppName(textAppName.getText());
        final Subscription selectedSubscription = (Subscription) comboSubscription.getSelectedItem();
        if (selectedSubscription != null) {
            webAppOnLinuxDeployConfiguration.setSubscriptionId(selectedSubscription.getId());
        }
        // resource group
        if (rdoUseExistResGrp.isSelected()) {
            // existing RG
            webAppOnLinuxDeployConfiguration.setCreatingNewResourceGroup(false);
            final ResourceGroup selectedRg = (ResourceGroup) comboResourceGroup.getSelectedItem();
            if (selectedRg != null) {
                webAppOnLinuxDeployConfiguration.setResourceGroupName(selectedRg.getName());
            } else {
                webAppOnLinuxDeployConfiguration.setResourceGroupName(null);
            }
        } else if (rdoCreateResGrp.isSelected()) {
            // new RG
            webAppOnLinuxDeployConfiguration.setCreatingNewResourceGroup(true);
            webAppOnLinuxDeployConfiguration.setResourceGroupName(txtNewResGrp.getText());
        }
        // app service plan
        if (rdoCreateAppServicePlan.isSelected()) {
            webAppOnLinuxDeployConfiguration.setCreatingNewAppServicePlan(true);
            webAppOnLinuxDeployConfiguration.setAppServicePlanName(txtCreateAppServicePlan.getText());
            final Region selectedLocation = (Region) cbLocation.getSelectedItem();
            if (selectedLocation != null) {
                webAppOnLinuxDeployConfiguration.setLocationName(selectedLocation.getName());
            } else {
                webAppOnLinuxDeployConfiguration.setLocationName(null);
            }
            final PricingTier selectedPricingTier = (PricingTier) cbPricing.getSelectedItem();
            if (selectedPricingTier != null) {
                webAppOnLinuxDeployConfiguration.setPricingSkuTier(selectedPricingTier.getTier());
                webAppOnLinuxDeployConfiguration.setPricingSkuSize(selectedPricingTier.getSize());
            } else {
                webAppOnLinuxDeployConfiguration.setPricingSkuTier(null);
                webAppOnLinuxDeployConfiguration.setPricingSkuSize(null);
            }
        } else if (rdoUseExistAppServicePlan.isSelected()) {
            webAppOnLinuxDeployConfiguration.setCreatingNewAppServicePlan(false);
            final AppServicePlan selectedAsp = (AppServicePlan) cbExistAppServicePlan.getSelectedItem();
            if (selectedAsp != null) {
                webAppOnLinuxDeployConfiguration.setAppServicePlanId(selectedAsp.id());
            } else {
                webAppOnLinuxDeployConfiguration.setAppServicePlanId(null);
            }
        }
    }
}
Also used : PrivateRegistryImageSetting(com.microsoft.azuretools.core.mvp.model.webapp.PrivateRegistryImageSetting) PricingTier(com.microsoft.azure.toolkit.lib.appservice.model.PricingTier) ISecureStore(com.microsoft.azure.toolkit.ide.common.store.ISecureStore) Region(com.microsoft.azure.toolkit.lib.common.model.Region) Subscription(com.microsoft.azure.toolkit.lib.common.model.Subscription) ResourceGroup(com.microsoft.azure.toolkit.lib.common.model.ResourceGroup) IWebApp(com.microsoft.azure.toolkit.lib.appservice.service.IWebApp) IAppServicePlan(com.microsoft.azure.toolkit.lib.appservice.service.IAppServicePlan) AppServicePlan(com.microsoft.azure.toolkit.lib.appservice.service.impl.AppServicePlan)

Example 97 with Subscription

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

the class ContainerRegistryMvpModelTest method testListContainerRegistries.

@Test
public void testListContainerRegistries() throws IOException {
    List<Subscription> subscriptions = new ArrayList<Subscription>();
    Subscription sub1 = mock(Subscription.class);
    when(sub1.getId()).thenReturn("1");
    Subscription sub2 = mock(Subscription.class);
    when(sub2.getId()).thenReturn("2");
    Subscription sub3 = mock(Subscription.class);
    when(sub3.getId()).thenReturn("3");
    when(mvpModel.getSelectedSubscriptions()).thenReturn(subscriptions);
    ContainerRegistryMvpModel mockModel = spy(containerRegistryMvpModel);
    when(authMethodManagerMock.getAzureClient(anyString())).thenReturn(azureMock);
    when(registriesMock.list()).thenReturn(new PagedList<Registry>() {

        @Override
        public Page<Registry> nextPage(String nextPageLink) throws RestException, IOException {
            return null;
        }
    });
    mockModel.listContainerRegistries(false);
    verify(mockModel, times(0)).listRegistryBySubscriptionId(anyString(), eq(false));
    subscriptions.add(sub1);
    subscriptions.add(sub2);
    subscriptions.add(sub3);
    mockModel.listContainerRegistries(false);
    verify(mockModel, times(3)).listRegistryBySubscriptionId(anyString(), eq(false));
    reset(mockModel);
    mockModel.listContainerRegistries(true);
    verify(mockModel, times(3)).listRegistryBySubscriptionId(anyString(), eq(true));
}
Also used : ArrayList(java.util.ArrayList) RestException(com.microsoft.rest.RestException) Page(com.microsoft.azure.Page) Registry(com.microsoft.azure.management.containerregistry.Registry) Mockito.anyString(org.mockito.Mockito.anyString) IOException(java.io.IOException) Subscription(com.microsoft.azure.toolkit.lib.common.model.Subscription) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 98 with Subscription

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

the class ContainerRegistryMvpModel method listContainerRegistries.

/**
 * Get Registry instances mapped by Subscription id.
 */
public List<ResourceEx<Registry>> listContainerRegistries(boolean force) {
    List<ResourceEx<Registry>> registryList = new ArrayList<>();
    List<Subscription> subscriptions = az(AzureAccount.class).account().getSelectedSubscriptions();
    for (Subscription sub : subscriptions) {
        registryList.addAll(listRegistryBySubscriptionId(sub.getId(), force));
    }
    return registryList;
}
Also used : ArrayList(java.util.ArrayList) Subscription(com.microsoft.azure.toolkit.lib.common.model.Subscription) ResourceEx(com.microsoft.azuretools.core.mvp.model.ResourceEx)

Example 99 with Subscription

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

the class AzureManagerBase method getSubscriptionsWithTenant.

@Override
@AzureOperation(name = "account|subscription.list.tenant|authorized", type = AzureOperation.Type.SERVICE)
public List<Pair<Subscription, Tenant>> getSubscriptionsWithTenant() {
    final List<Pair<Subscription, Tenant>> subscriptions = new LinkedList<>();
    final Azure.Authenticated authentication = authTenant(getCurrentTenantId());
    // could be multi tenant - return all subscriptions for the current account
    final List<Tenant> tenants = getTenants(authentication);
    final List<String> failedTenantIds = new ArrayList<>();
    for (final Tenant tenant : tenants) {
        try {
            final Azure.Authenticated tenantAuthentication = authTenant(tenant.tenantId());
            final List<Subscription> tenantSubscriptions = getSubscriptions(tenantAuthentication);
            for (final Subscription subscription : tenantSubscriptions) {
                subscriptions.add(new Pair<>(subscription, tenant));
            }
        } catch (final Exception e) {
            // just skip for cases user failing to get subscriptions of tenants he/she has no permission to get access token.
            LOGGER.log(Level.WARNING, e.getMessage(), e);
            failedTenantIds.add(tenant.tenantId());
        }
    }
    if (!failedTenantIds.isEmpty()) {
        final INotification nw = CommonSettings.getUiFactory().getNotificationWindow();
        nw.deliver("Lack permission for some tenants", "You don't have permission on the tenant(s): " + StringUtils.join(failedTenantIds, ","));
    }
    return subscriptions;
}
Also used : Azure(com.microsoft.azure.management.Azure) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) Tenant(com.microsoft.azure.management.resources.Tenant) INotification(com.microsoft.azuretools.authmanage.interact.INotification) Subscription(com.microsoft.azure.toolkit.lib.common.model.Subscription) Pair(com.microsoft.azuretools.utils.Pair) AzureOperation(com.microsoft.azure.toolkit.lib.common.operation.AzureOperation)

Example 100 with Subscription

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

the class WebAppDeployDialog method fillAppServiceDetails.

private void fillAppServiceDetails() {
    validated();
    int selectedRow = table.getSelectionIndex();
    if (selectedRow < 0) {
        browserAppServiceDetails.setText("");
        btnDelete.setEnabled(false);
        return;
    }
    btnDelete.setEnabled(true);
    String appServiceName = table.getItems()[selectedRow].getText(0);
    IWebApp webApp = webAppDetailsMap.get(appServiceName);
    IAppServicePlan asp = webApp.plan();
    Subscription subscription = Azure.az(AzureAccount.class).account().getSubscription(webApp.subscriptionId());
    StringBuilder sb = new StringBuilder();
    sb.append(String.format("App Service name: %s \n", appServiceName));
    sb.append(String.format("Subscription name: %s ; id: %s \n", subscription.getName(), subscription.getId()));
    String aspName = asp == null ? "N/A" : asp.name();
    String aspPricingTier = asp == null ? "N/A" : asp.entity().getPricingTier().toString();
    sb.append(String.format("App Service Plan name: %s ; Pricing tier: %s \n", aspName, aspPricingTier));
    String link = buildSiteLink(webApp, null);
    sb.append(String.format("Link: <a href=\"%s\">%s</a> \n", link, link));
    sb.append(String.format("<a href=\"%s\">%s</a> \n", ftpLinkString, "Show FTP deployment credentials"));
    browserAppServiceDetails.setText(sb.toString());
}
Also used : IAppServicePlan(com.microsoft.azure.toolkit.lib.appservice.service.IAppServicePlan) Subscription(com.microsoft.azure.toolkit.lib.common.model.Subscription) Point(org.eclipse.swt.graphics.Point) IWebApp(com.microsoft.azure.toolkit.lib.appservice.service.IWebApp)

Aggregations

Subscription (com.microsoft.azure.toolkit.lib.common.model.Subscription)130 ResourceGroup (com.microsoft.azure.toolkit.lib.common.model.ResourceGroup)26 Region (com.microsoft.azure.toolkit.lib.common.model.Region)18 AzureManager (com.microsoft.azuretools.sdkmanage.AzureManager)18 AzureAccount (com.microsoft.azure.toolkit.lib.auth.AzureAccount)15 ArrayList (java.util.ArrayList)14 IOException (java.io.IOException)10 SelectionEvent (org.eclipse.swt.events.SelectionEvent)10 Project (com.intellij.openapi.project.Project)8 Azure (com.microsoft.azure.toolkit.lib.Azure)8 IAppServicePlan (com.microsoft.azure.toolkit.lib.appservice.service.IAppServicePlan)8 IWebApp (com.microsoft.azure.toolkit.lib.appservice.service.IWebApp)8 AzureOperation (com.microsoft.azure.toolkit.lib.common.operation.AzureOperation)8 HashMap (java.util.HashMap)8 List (java.util.List)8 StringUtils (org.apache.commons.lang3.StringUtils)8 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)8 Point (org.eclipse.swt.graphics.Point)8 GridData (org.eclipse.swt.layout.GridData)8 Combo (org.eclipse.swt.widgets.Combo)8