Search in sources :

Example 1 with Subscription

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

the class CreateRedisCacheForm method createDialogArea.

/**
 * Create contents of the dialog.
 *
 * @param parent
 */
@Override
protected Control createDialogArea(Composite parent) {
    resourceBundle = MessageHandler.getResourceBundle(MODULE_NAME);
    if (resourceBundle == null) {
        return null;
    }
    setTitle(MessageHandler.getResourceString(resourceBundle, DIALOG_TITLE));
    setMessage(MessageHandler.getResourceString(resourceBundle, DIALOG_MESSAGE));
    Composite area = (Composite) super.createDialogArea(parent);
    Composite container = new Composite(area, SWT.NONE);
    GridLayout glContainer = new GridLayout(4, false);
    glContainer.horizontalSpacing = LAYOUT_SPACING;
    glContainer.verticalSpacing = LAYOUT_SPACING;
    container.setLayout(glContainer);
    container.setLayoutData(new GridData(GridData.FILL_BOTH));
    Label lblDnsName = new Label(container, SWT.NONE);
    lblDnsName.setText(MessageHandler.getResourceString(resourceBundle, LABEL_DNS_NAME));
    txtDnsName = new Text(container, SWT.BORDER);
    txtDnsName.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    decoratorDnsName = new ControlDecoration(txtDnsName, SWT.CENTER);
    decoratorDnsName.setDescriptionText(MessageHandler.getResourceString(resourceBundle, DECORACTOR_DNS));
    FieldDecoration fieldDecoration = FieldDecorationRegistry.getDefault().getFieldDecoration(FieldDecorationRegistry.DEC_ERROR);
    if (fieldDecoration != null) {
        Image image = fieldDecoration.getImage();
        decoratorDnsName.setImage(image);
    }
    Label lblDnsSuffix = new Label(container, SWT.NONE);
    lblDnsSuffix.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 2, 1));
    lblDnsSuffix.setText(MessageHandler.getResourceString(resourceBundle, LABEL_DNS_SUFFIX));
    Label lblSubscription = new Label(container, SWT.NONE);
    lblSubscription.setText(MessageHandler.getResourceString(resourceBundle, LABEL_SUBSCRIPTION));
    cbSubs = new Combo(container, SWT.READ_ONLY);
    cbSubs.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 3, 1));
    Label lblResourceGroup = new Label(container, SWT.NONE);
    lblResourceGroup.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 4, 1));
    lblResourceGroup.setText(MessageHandler.getResourceString(resourceBundle, LABEL_RESOURCE_GRP));
    rdoCreateNew = new Button(container, SWT.RADIO);
    rdoCreateNew.setText(MessageHandler.getResourceString(resourceBundle, RADIOBUTTON_NEW_GRP));
    rdoCreateNew.setSelection(true);
    txtNewResGrpName = new Text(container, SWT.BORDER);
    txtNewResGrpName.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 3, 1));
    txtNewResGrpName.setEnabled(true);
    decoratorResGrpName = new ControlDecoration(txtNewResGrpName, SWT.CENTER);
    decoratorResGrpName.setDescriptionText(MessageHandler.getResourceString(resourceBundle, RES_GRP_NAME_RULE));
    if (fieldDecoration != null) {
        Image image = fieldDecoration.getImage();
        decoratorResGrpName.setImage(image);
    }
    rdoUseExisting = new Button(container, SWT.RADIO);
    rdoUseExisting.setText(MessageHandler.getResourceString(resourceBundle, RADIOBUTTON_USE_EXIST_GRP));
    rdoUseExisting.setSelection(false);
    cbUseExisting = new Combo(container, SWT.READ_ONLY);
    cbUseExisting.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 3, 1));
    cbUseExisting.add(MessageHandler.getResourceString(resourceBundle, LOADING));
    cbUseExisting.select(0);
    cbUseExisting.setEnabled(false);
    Label lblLocation = new Label(container, SWT.NONE);
    lblLocation.setText(MessageHandler.getResourceString(resourceBundle, LABEL_LOCTION));
    cbLocations = new Combo(container, SWT.READ_ONLY);
    cbLocations.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 3, 1));
    cbLocations.add(MessageHandler.getResourceString(resourceBundle, LOADING));
    cbLocations.select(0);
    cbLocations.setEnabled(false);
    Label lblPricingTier = new Label(container, SWT.READ_ONLY);
    lblPricingTier.setText(MessageHandler.getResourceString(resourceBundle, LABEL_PRICING));
    cbPricetiers = new Combo(container, SWT.READ_ONLY);
    cbPricetiers.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));
    for (PricingTier price : PricingTier.values()) {
        cbPricetiers.add(price.toString());
    }
    cbPricetiers.select(0);
    selectedPriceTierValue = cbPricetiers.getText();
    Link lnkPrice = new Link(container, SWT.NONE);
    lnkPrice.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false, 1, 1));
    lnkPrice.setText(MessageHandler.getResourceString(resourceBundle, LINK_PRICE));
    lnkPrice.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent event) {
            try {
                PlatformUI.getWorkbench().getBrowserSupport().getExternalBrowser().openURL(new URL(event.text));
            } catch (Exception ex) {
                LOG.log(MessageHandler.getCommonStr(OPEN_BROWSER_ERROR), ex);
            }
        }
    });
    chkUnblockPort = new Button(container, SWT.CHECK);
    chkUnblockPort.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 4, 1));
    chkUnblockPort.setText(MessageHandler.getResourceString(resourceBundle, CHECKBOX_SSL));
    this.setHelpAvailable(false);
    txtDnsName.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent arg0) {
            dnsNameValue = txtDnsName.getText();
            validateFields();
        }
    });
    for (Subscription sub : selectedSubscriptions) {
        cbSubs.add(String.format(SUBS_COMBO_ITEMS_FORMAT, sub.getName(), sub.getId()));
    }
    cbSubs.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            currentSub = selectedSubscriptions.get(cbSubs.getSelectionIndex());
            if (loaded) {
                fillLocationsAndResourceGrps(currentSub);
            }
            validateFields();
        }
    });
    if (selectedSubscriptions.size() > 0) {
        cbSubs.select(0);
    }
    rdoCreateNew.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            txtNewResGrpName.setEnabled(true);
            cbUseExisting.setEnabled(false);
            newResGrp = true;
            selectedResGrpValue = txtNewResGrpName.getText();
            validateFields();
        }
    });
    rdoUseExisting.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            txtNewResGrpName.setEnabled(false);
            cbUseExisting.setEnabled(true);
            if (loaded) {
                newResGrp = false;
                selectedResGrpValue = sortedGroups.get(cbUseExisting.getSelectionIndex());
                validateFields();
            }
        }
    });
    txtNewResGrpName.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent arg0) {
            selectedResGrpValue = txtNewResGrpName.getText();
            validateFields();
        }
    });
    cbUseExisting.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            selectedResGrpValue = cbUseExisting.getText();
            validateFields();
        }
    });
    cbLocations.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            selectedLocationValue = sortedLocations.get(cbLocations.getSelectionIndex()).getLabel();
            validateFields();
        }
    });
    cbPricetiers.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            selectedPriceTierValue = cbPricetiers.getText();
            validateFields();
        }
    });
    chkUnblockPort.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            Button btn = (Button) e.getSource();
            if (btn.getSelection()) {
                noSSLPort = true;
            } else {
                noSSLPort = false;
            }
        }
    });
    AzureTaskManager.getInstance().runInBackground(MessageHandler.getResourceString(resourceBundle, LOADING_LOCATION_AND_GRPS), false, () -> {
        try {
            DefaultLoader.getIdeHelper().invokeLater(new Runnable() {

                @Override
                public void run() {
                    fillLocationsAndResourceGrps(currentSub);
                    cbLocations.setEnabled(true);
                    loaded = true;
                    validateFields();
                }
            });
        } catch (Exception ex) {
            LOG.log(MessageHandler.getCommonStr(LOAD_LOCATION_AND_RESOURCE_ERROR), ex);
        }
    });
    return area;
}
Also used : PricingTier(com.microsoft.azure.toolkit.redis.PricingTier) Composite(org.eclipse.swt.widgets.Composite) ModifyListener(org.eclipse.swt.events.ModifyListener) FieldDecoration(org.eclipse.jface.fieldassist.FieldDecoration) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Label(org.eclipse.swt.widgets.Label) Text(org.eclipse.swt.widgets.Text) Combo(org.eclipse.swt.widgets.Combo) Image(org.eclipse.swt.graphics.Image) URL(java.net.URL) InvalidFormDataException(com.microsoft.azuretools.azurecommons.exceptions.InvalidFormDataException) IOException(java.io.IOException) GridLayout(org.eclipse.swt.layout.GridLayout) ModifyEvent(org.eclipse.swt.events.ModifyEvent) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) ControlDecoration(org.eclipse.jface.fieldassist.ControlDecoration) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Subscription(com.microsoft.azure.toolkit.lib.common.model.Subscription) Link(org.eclipse.swt.widgets.Link)

Example 2 with Subscription

use of com.microsoft.azure.toolkit.lib.common.model.Subscription 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 java.io.IOException
 * @throws RestOperationException
 * @throws AzureCmdException
 */
public static void updateApplicationInsightsResourceRegistry(List<Subscription> subList) throws Exception {
    for (Subscription sub : subList) {
        if (sub.isSelected()) {
            try {
                // fetch resources available for particular subscription
                List<ApplicationInsightsComponent> resourceList = AzureSDKManager.getInsightsResources(sub.getId());
                // Removal logic
                List<ApplicationInsightsResource> registryList = ApplicationInsightsResourceRegistry.getResourceListAsPerSub(sub.getId());
                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 (ApplicationInsightsComponent resource : resourceList) {
                    ApplicationInsightsResource resourceToAdd = new ApplicationInsightsResource(resource, sub, true);
                    if (list.contains(resourceToAdd)) {
                        int index = ApplicationInsightsResourceRegistry.getResourceIndexAsPerKey(resource.instrumentationKey());
                        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.getName()), e);
            }
        }
    }
    ApplicationInsightsPreferences.save();
    ApplicationInsightsPreferences.setLoaded(true);
}
Also used : ApplicationInsightsResource(com.microsoft.applicationinsights.preference.ApplicationInsightsResource) ApplicationInsightsComponent(com.microsoft.azure.management.applicationinsights.v2015_05_01.ApplicationInsightsComponent) Subscription(com.microsoft.azure.toolkit.lib.common.model.Subscription) IOException(java.io.IOException) AzureCmdException(com.microsoft.azuretools.azurecommons.helpers.AzureCmdException)

Example 3 with Subscription

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

the class PublishWebAppOnLinuxDialog method onResourceGroupSelection.

private void onResourceGroupSelection() {
    cpNew.cbExistingAppServicePlan.removeAll();
    cpNew.lblLocationValue.setText("");
    cpNew.lblPricingTierValue.setText("");
    Subscription sub = getSelectedSubscription();
    ResourceGroup rg = getSelectedResourceGroup();
    if (sub != null && rg != null) {
        // TODO: a minor bug here, if rg is null, related labels should be set to "N/A"
        webAppOnLinuxDeployPresenter.onLoadAppServicePlan(sub.getId(), rg.getName());
    }
}
Also used : Subscription(com.microsoft.azure.toolkit.lib.common.model.Subscription) ResourceGroup(com.microsoft.azure.toolkit.lib.common.model.ResourceGroup)

Example 4 with Subscription

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

the class PublishWebAppOnLinuxDialog method apply.

private void apply() {
    model.setDockerFilePath(cpAcr.getDockerfilePath());
    // set ACR info
    model.setPrivateRegistryImageSetting(new PrivateRegistryImageSetting(cpAcr.getServerUrl(), cpAcr.getUserName(), cpAcr.getPassword(), cpAcr.getImageTag(), cpAcr.getStartupFile()));
    // set target
    model.setTargetPath(targetPath);
    model.setTargetName(Paths.get(targetPath).getFileName().toString());
    // set web app info
    if (rdoExistingWebApp.getSelection()) {
        // existing web app
        model.setCreatingNewWebAppOnLinux(false);
        IWebApp selectedWebApp = getSelectedWebApp();
        if (selectedWebApp != null) {
            model.setWebAppId(selectedWebApp.id());
            model.setWebAppName(selectedWebApp.name());
            model.setSubscriptionId(selectedWebApp.subscriptionId());
            model.setResourceGroupName(selectedWebApp.resourceGroup());
        } else {
            model.setWebAppId(null);
            model.setWebAppName(null);
            model.setSubscriptionId(null);
            model.setResourceGroupName(null);
        }
    } else if (rdoNewWebApp.getSelection()) {
        // create new web app
        model.setCreatingNewWebAppOnLinux(true);
        model.setWebAppId("");
        model.setWebAppName(cpNew.txtAppName.getText());
        Subscription selectedSubscription = getSelectedSubscription();
        if (selectedSubscription != null) {
            model.setSubscriptionId(selectedSubscription.getId());
        }
        // resource group
        if (cpNew.rdoExistingResourceGroup.getSelection()) {
            // existing RG
            model.setCreatingNewResourceGroup(false);
            ResourceGroup selectedRg = getSelectedResourceGroup();
            if (selectedRg != null) {
                model.setResourceGroupName(selectedRg.getName());
            } else {
                model.setResourceGroupName(null);
            }
        } else if (cpNew.rdoNewResourceGroup.getSelection()) {
            // new RG
            model.setCreatingNewResourceGroup(true);
            model.setResourceGroupName(cpNew.txtNewResourceGroupName.getText());
        }
        // app service plan
        if (cpNew.rdoNewAppServicePlan.getSelection()) {
            model.setCreatingNewAppServicePlan(true);
            model.setAppServicePlanName(cpNew.txtAppServicePlanName.getText());
            Region selectedLocation = getSelectedLocation();
            if (selectedLocation != null) {
                model.setLocationName(selectedLocation.getLabel());
            } else {
                model.setLocationName(null);
            }
            PricingTier selectedPricingTier = getSelectedPricingTier();
            if (selectedPricingTier != null) {
                model.setPricingSkuTier(selectedPricingTier.getTier());
                model.setPricingSkuSize(selectedPricingTier.getSize());
            } else {
                model.setPricingSkuTier(null);
                model.setPricingSkuSize(null);
            }
        } else if (cpNew.rdoExistingAppServicePlan.getSelection()) {
            model.setCreatingNewAppServicePlan(false);
            IAppServicePlan selectedAsp = getSelectedAppServicePlan();
            if (selectedAsp != null) {
                model.setAppServicePlanId(selectedAsp.id());
            } else {
                model.setAppServicePlanId(null);
            }
        }
    }
}
Also used : PrivateRegistryImageSetting(com.microsoft.azuretools.core.mvp.model.webapp.PrivateRegistryImageSetting) PricingTier(com.microsoft.azure.toolkit.lib.appservice.model.PricingTier) IAppServicePlan(com.microsoft.azure.toolkit.lib.appservice.service.IAppServicePlan) 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)

Example 5 with Subscription

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

the class PublishWebAppOnLinuxDialog method renderSubscriptionList.

@Override
public void renderSubscriptionList(List<Subscription> list) {
    subscriptionList = list;
    cpNew.cbSubscription.removeAll();
    for (Subscription sub : subscriptionList) {
        cpNew.cbSubscription.add(sub.getName());
    }
    if (cpNew.cbSubscription.getItemCount() > 0) {
        cpNew.cbSubscription.select(0);
    }
    onSubscriptionSelection();
}
Also used : 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