Search in sources :

Example 11 with SubscriptionDetail

use of com.microsoft.azuretools.authmanage.models.SubscriptionDetail in project azure-tools-for-java by Microsoft.

the class AppServiceCreateDialog method validated.

protected boolean validated() {
    cleanError();
    model.collectData();
    String webappName = model.webAppName;
    if (webappName.length() > 60 || !webappName.matches("^[A-Za-z0-9][A-Za-z0-9-]*[A-Za-z0-9]$")) {
        StringBuilder builder = new StringBuilder();
        builder.append("The name can contain letters, numbers and hyphens but the first and last characters must be a letter or number. ");
        builder.append("The length can be between 2 and 60 characters. ");
        setError(dec_textAppName, builder.toString());
        return false;
    } else {
        for (List<WebApp> wal : AzureModel.getInstance().getResourceGroupToWebAppMap().values()) {
            for (WebApp wa : wal) {
                if (wa.name().toLowerCase().equals(webappName.toLowerCase())) {
                    setError(dec_textAppName, "The name is already taken");
                    return false;
                }
            }
        }
    }
    if (model.webContainer == null) {
        setError(dec_comboWebContainer, "Select a valid web container.");
        return false;
    }
    if (model.subscriptionDetail == null) {
        setError(dec_comboSubscription, "Select a valid subscription.");
        return false;
    }
    if (model.isAppServicePlanCreateNew) {
        if (model.appServicePlanNameCreateNew.isEmpty()) {
            setError(dec_textAppSevicePlanName, "Enter a valid App Service Plan name.");
            return false;
        } else {
            if (!model.appServicePlanNameCreateNew.matches("^[A-Za-z0-9-]*[A-Za-z0-9-]$")) {
                setError(dec_textAppSevicePlanName, "App Service Plan name can only include alphanumeric characters and hyphens.");
                return false;
            }
            // App service plan name must be unique in each subscription
            SubscriptionDetail sd = model.subscriptionDetail;
            List<ResourceGroup> rgl = AzureModel.getInstance().getSubscriptionToResourceGroupMap().get(sd);
            for (ResourceGroup rg : rgl) {
                List<AppServicePlan> aspl = AzureModel.getInstance().getResourceGroupToAppServicePlanMap().get(rg);
                for (AppServicePlan asp : aspl) {
                    if (asp.name().toLowerCase().equals(model.appServicePlanNameCreateNew.toLowerCase())) {
                        setError(dec_textAppSevicePlanName, "App service plan name must be unuque in each subscription.");
                        return false;
                    }
                }
            }
        }
        if (model.appServicePlanLocationCreateNew == null) {
            setError(dec_comboAppServicePlanLocation, "Select a location.");
            return false;
        }
    } else {
        if (model.appServicePlan == null) {
            setError(dec_comboAppServicePlan, "Select a valid App Service Plan.");
            return false;
        }
    }
    if (model.isResourceGroupCreateNew) {
        if (model.resourceGroupNameCreateNew.isEmpty()) {
            setError(dec_textNewResGrName, "Enter a valid resource group name");
            return false;
        } else {
            if (!model.resourceGroupNameCreateNew.matches("^[A-Za-z0-9-_()\\.]*[A-Za-z0-9-_()]$")) {
                setError(dec_textNewResGrName, "Resounce group name can only include alphanumeric characters, periods, underscores, hyphens, and parenthesis and can't end in a period.");
                return false;
            }
            for (List<ResourceGroup> rgl : AzureModel.getInstance().getSubscriptionToResourceGroupMap().values()) {
                for (ResourceGroup rg : rgl) {
                    if (rg.name().toLowerCase().equals(model.resourceGroupNameCreateNew.toLowerCase())) {
                        setError(dec_textNewResGrName, "The name is already taken");
                        return false;
                    }
                }
            }
        }
    } else {
        if (model.resourceGroup == null) {
            setError(dec_comboSelectResGr, "Select a valid resource group.");
            return false;
        }
    }
    return volidatedJdkTab();
}
Also used : SubscriptionDetail(com.microsoft.azuretools.authmanage.models.SubscriptionDetail) ResourceGroup(com.microsoft.azure.management.resources.ResourceGroup) WebApp(com.microsoft.azure.management.appservice.WebApp) AppServicePlan(com.microsoft.azure.management.appservice.AppServicePlan)

Example 12 with SubscriptionDetail

use of com.microsoft.azuretools.authmanage.models.SubscriptionDetail in project azure-tools-for-java by Microsoft.

the class AppServiceCreateDialog method doFillSubscriptions.

private void doFillSubscriptions() {
    try {
        // reset model
        Set<SubscriptionDetail> sdl = AzureModel.getInstance().getSubscriptionToResourceGroupMap().keySet();
        if (sdl == null) {
            System.out.println("sdl is null");
            return;
        }
        comboSubscription.removeAll();
        ;
        binderSubscriptionDetails = new ArrayList<SubscriptionDetail>();
        for (SubscriptionDetail sd : sdl) {
            if (!sd.isSelected())
                continue;
            comboSubscription.add(sd.getSubscriptionName());
            binderSubscriptionDetails.add(sd);
        }
        if (comboSubscription.getItemCount() > 0) {
            comboSubscription.select(0);
        }
    } catch (Exception ex) {
        ex.printStackTrace();
        LOG.log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "doFillSubscriptions@AppServiceCreateDialog", ex));
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) SubscriptionDetail(com.microsoft.azuretools.authmanage.models.SubscriptionDetail) PartInitException(org.eclipse.ui.PartInitException) InvocationTargetException(java.lang.reflect.InvocationTargetException) MalformedURLException(java.net.MalformedURLException)

Example 13 with SubscriptionDetail

use of com.microsoft.azuretools.authmanage.models.SubscriptionDetail in project azure-tools-for-java by Microsoft.

the class ApplicationInsightsResourceRegistryEclipse method updateApplicationInsightsResourceRegistry.

/**
	 * Method updates application insights registry by adding, removing or updating resources.
	 * @param client
	 * @throws IOException
	 * @throws RestOperationException
	 * @throws AzureCmdException 
	 */
public static void updateApplicationInsightsResourceRegistry(List<SubscriptionDetail> subList) throws Exception {
    for (SubscriptionDetail sub : subList) {
        if (sub.isSelected()) {
            try {
                // fetch resources available for particular subscription
                List<Resource> resourceList = AzureSDKManager.getApplicationInsightsResources(sub);
                // Removal logic
                List<ApplicationInsightsResource> registryList = ApplicationInsightsResourceRegistry.getResourceListAsPerSub(sub.getSubscriptionId());
                List<ApplicationInsightsResource> importedList = ApplicationInsightsResourceRegistry.prepareAppResListFromRes(resourceList, sub);
                List<String> inUsekeyList = getInUseInstrumentationKeys();
                for (ApplicationInsightsResource registryRes : registryList) {
                    if (!importedList.contains(registryRes)) {
                        String key = registryRes.getInstrumentationKey();
                        int index = ApplicationInsightsResourceRegistry.getResourceIndexAsPerKey(key);
                        if (inUsekeyList.contains(key)) {
                            // key is used by project but not present in
                            // cloud,
                            // so make it as manually added resource and not
                            // imported.
                            ApplicationInsightsResource resourceToAdd = new ApplicationInsightsResource(key, key, Messages.unknown, Messages.unknown, Messages.unknown, Messages.unknown, false);
                            ApplicationInsightsResourceRegistry.getAppInsightsResrcList().set(index, resourceToAdd);
                        } else {
                            // key is not used by any project then delete
                            // it.
                            ApplicationInsightsResourceRegistry.getAppInsightsResrcList().remove(index);
                        }
                    }
                }
                // Addition logic
                List<ApplicationInsightsResource> list = ApplicationInsightsResourceRegistry.getAppInsightsResrcList();
                for (Resource resource : resourceList) {
                    ApplicationInsightsResource resourceToAdd = new ApplicationInsightsResource(resource.getName(), resource.getInstrumentationKey(), sub.getSubscriptionName(), sub.getSubscriptionId(), resource.getLocation(), resource.getResourceGroup(), true);
                    if (list.contains(resourceToAdd)) {
                        int index = ApplicationInsightsResourceRegistry.getResourceIndexAsPerKey(resource.getInstrumentationKey());
                        ApplicationInsightsResource objectFromRegistry = list.get(index);
                        if (!objectFromRegistry.isImported()) {
                            ApplicationInsightsResourceRegistry.getAppInsightsResrcList().set(index, resourceToAdd);
                        }
                    } else {
                        ApplicationInsightsResourceRegistry.getAppInsightsResrcList().add(resourceToAdd);
                    }
                }
            } catch (Exception e) {
                Activator.getDefault().log(String.format(Messages.aiListErr, sub.getSubscriptionName()), e);
            }
        }
    }
    ApplicationInsightsPreferences.save();
    ApplicationInsightsPreferences.setLoaded(true);
}
Also used : ApplicationInsightsResource(com.microsoft.applicationinsights.preference.ApplicationInsightsResource) Resource(com.microsoft.applicationinsights.management.rest.model.Resource) ApplicationInsightsResource(com.microsoft.applicationinsights.preference.ApplicationInsightsResource) SubscriptionDetail(com.microsoft.azuretools.authmanage.models.SubscriptionDetail) IOException(java.io.IOException) RestOperationException(com.microsoft.applicationinsights.management.rest.client.RestOperationException) AzureCmdException(com.microsoft.azuretools.azurecommons.helpers.AzureCmdException)

Example 14 with SubscriptionDetail

use of com.microsoft.azuretools.authmanage.models.SubscriptionDetail in project azure-tools-for-java by Microsoft.

the class SubscriptionStep method loadSubscriptions.

private void loadSubscriptions() {
    try {
        AzureManager azureManager = AuthMethodManager.getInstance().getAzureManager();
        // not signed in
        if (azureManager == null) {
            return;
        }
        /*
			 * if (manager.authenticated()) { String upn =
			 * manager.getUserInfo().getUniqueName();
			 * userInfoLabel.setText("Signed in as: " + (upn.contains("#") ?
			 * upn.split("#")[1] : upn)); } else { userInfoLabel.setText(""); }
			 */
        SubscriptionManager subscriptionManager = azureManager.getSubscriptionManager();
        List<SubscriptionDetail> subscriptionDetails = subscriptionManager.getSubscriptionDetails();
        for (SubscriptionDetail subscription : subscriptionDetails) {
            if (subscription.isSelected()) {
                subscriptionComboBox.add(subscription.getSubscriptionName());
                subscriptionComboBox.setData(subscription.getSubscriptionName(), subscription);
            }
        }
        if (!subscriptionDetails.isEmpty()) {
            subscriptionComboBox.select(0);
            wizard.setSubscription((SubscriptionDetail) subscriptionComboBox.getData(subscriptionComboBox.getText()));
        }
        setPageComplete(!subscriptionDetails.isEmpty());
    } catch (Exception ex) {
        DefaultLoader.getUIHelper().logError("An error occurred when trying to load Subscriptions\n\n" + ex.getMessage(), ex);
    }
}
Also used : AzureManager(com.microsoft.azuretools.sdkmanage.AzureManager) SubscriptionDetail(com.microsoft.azuretools.authmanage.models.SubscriptionDetail) SubscriptionManager(com.microsoft.azuretools.authmanage.SubscriptionManager)

Example 15 with SubscriptionDetail

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();
    webAppDetailsMap.clear();
    table.removeAll();
    for (SubscriptionDetail sd : srgMap.keySet()) {
        if (!sd.isSelected())
            continue;
        Map<String, WebAppUtils.AspDetails> aspMap = new HashMap<>();
        for (ResourceGroup rg : srgMap.get(sd)) {
            for (AppServicePlan asp : rgaspMap.get(rg)) {
                aspMap.put(asp.id(), new WebAppUtils.AspDetails(asp, rg));
            }
        }
        for (ResourceGroup rg : srgMap.get(sd)) {
            for (WebApp wa : rgwaMap.get(rg)) {
                TableItem item = new TableItem(table, SWT.NULL);
                if (wa.javaVersion() != JavaVersion.OFF) {
                    item.setText(new String[] { wa.name(), wa.javaVersion().toString(), wa.javaContainer() + " " + wa.javaContainerVersion(), wa.resourceGroupName() });
                } else {
                    item.setText(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();
                webAppDetailsMap.put(wa.name(), webAppDetails);
            }
        }
    }
}
Also used : WebAppDetails(com.microsoft.azuretools.utils.WebAppUtils.WebAppDetails) HashMap(java.util.HashMap) TableItem(org.eclipse.swt.widgets.TableItem) WebAppUtils(com.microsoft.azuretools.utils.WebAppUtils) AppServicePlan(com.microsoft.azure.management.appservice.AppServicePlan) SubscriptionDetail(com.microsoft.azuretools.authmanage.models.SubscriptionDetail) List(java.util.List) ResourceGroup(com.microsoft.azure.management.resources.ResourceGroup) WebApp(com.microsoft.azure.management.appservice.WebApp)

Aggregations

SubscriptionDetail (com.microsoft.azuretools.authmanage.models.SubscriptionDetail)52 AzureManager (com.microsoft.azuretools.sdkmanage.AzureManager)17 ResourceGroup (com.microsoft.azure.management.resources.ResourceGroup)13 SubscriptionManager (com.microsoft.azuretools.authmanage.SubscriptionManager)13 IOException (java.io.IOException)9 AppServicePlan (com.microsoft.azure.management.appservice.AppServicePlan)7 Location (com.microsoft.azure.management.resources.Location)7 List (java.util.List)7 WebApp (com.microsoft.azure.management.appservice.WebApp)5 AzureCmdException (com.microsoft.azuretools.azurecommons.helpers.AzureCmdException)5 SelectionEvent (org.eclipse.swt.events.SelectionEvent)5 Azure (com.microsoft.azure.management.Azure)4 Subscription (com.microsoft.azure.management.resources.Subscription)4 WebAppDetails (com.microsoft.azuretools.utils.WebAppUtils.WebAppDetails)4 HashMap (java.util.HashMap)4 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)4 GridData (org.eclipse.swt.layout.GridData)4 Label (org.eclipse.swt.widgets.Label)4 AccessTokenAzureManager (com.microsoft.azuretools.sdkmanage.AccessTokenAzureManager)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)3