Search in sources :

Example 11 with Subscription

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

the class AppServiceCreateDialog method fillAppServicePlans.

protected void fillAppServicePlans() {
    Subscription selectedSubscription = getSelectedSubscription();
    if (selectedSubscription == null) {
        return;
    }
    OperatingSystem os = getSelectedOS();
    setComboRefreshingStatus(comboAppServicePlan, true);
    Mono.fromCallable(() -> {
        return Azure.az(AzureAppService.class).appServicePlans(selectedSubscription.getId(), false).stream().filter(asp -> asp.entity().getOperatingSystem() == null || asp.entity().getOperatingSystem() == os).collect(Collectors.toList());
    }).subscribeOn(Schedulers.boundedElastic()).subscribe(appServicePlans -> {
        appServicePlans.sort(Comparator.comparing(IAppServicePlan::name));
        DefaultLoader.getIdeHelper().invokeLater(() -> {
            setComboRefreshingStatus(comboAppServicePlan, false);
            binderAppServicePlan = new ArrayList<>();
            for (IAppServicePlan asp : appServicePlans) {
                binderAppServicePlan.add(asp);
                comboAppServicePlan.add(asp.name());
            }
            if (comboAppServicePlan.getItemCount() > 0) {
                comboAppServicePlan.select(0);
            }
            String aspName = CommonUtils.getPreference(CommonUtils.ASP_NAME);
            CommonUtils.selectComboIndex(comboAppServicePlan, aspName);
            fillAppServicePlansDetails();
        });
    });
}
Also used : OperatingSystem(com.microsoft.azure.toolkit.lib.appservice.model.OperatingSystem) Arrays(java.util.Arrays) Azure(com.microsoft.azure.toolkit.lib.Azure) IDialogConstants(org.eclipse.jface.dialogs.IDialogConstants) FocusEvent(org.eclipse.swt.events.FocusEvent) StringUtils(org.apache.commons.lang3.StringUtils) Point(org.eclipse.swt.graphics.Point) CommonUtils(com.microsoft.azuretools.webapp.util.CommonUtils) PluginUtil(com.microsoft.azuretools.core.utils.PluginUtil) Composite(org.eclipse.swt.widgets.Composite) PartInitException(org.eclipse.ui.PartInitException) Map(java.util.Map) AzureGroup(com.microsoft.azure.toolkit.lib.resource.AzureGroup) TraverseEvent(org.eclipse.swt.events.TraverseEvent) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Text(org.eclipse.swt.widgets.Text) ILog(org.eclipse.core.runtime.ILog) PlatformUI(org.eclipse.ui.PlatformUI) Runtime(com.microsoft.azure.toolkit.lib.appservice.model.Runtime) Status(org.eclipse.core.runtime.Status) JavaVersion(com.microsoft.azure.toolkit.lib.appservice.model.JavaVersion) TraverseListener(org.eclipse.swt.events.TraverseListener) Window(org.eclipse.jface.window.Window) AzureAccount(com.microsoft.azure.toolkit.lib.auth.AzureAccount) SWT(org.eclipse.swt.SWT) EventUtil(com.microsoft.azuretools.telemetrywrapper.EventUtil) OperatingSystem(com.microsoft.azure.toolkit.lib.appservice.model.OperatingSystem) SelectionListener(org.eclipse.swt.events.SelectionListener) AzureUIRefreshCore(com.microsoft.azuretools.utils.AzureUIRefreshCore) SimpleDateFormat(java.text.SimpleDateFormat) ArrayList(java.util.ArrayList) IProject(org.eclipse.core.resources.IProject) Listener(org.eclipse.swt.widgets.Listener) ErrorWindow(com.microsoft.azuretools.core.ui.ErrorWindow) DefaultLoader(com.microsoft.tooling.msservices.components.DefaultLoader) Font(org.eclipse.swt.graphics.Font) GridData(org.eclipse.swt.layout.GridData) Link(org.eclipse.swt.widgets.Link) Nullable(javax.annotation.Nullable) Subscription(com.microsoft.azure.toolkit.lib.common.model.Subscription) TableItem(org.eclipse.swt.widgets.TableItem) FontDescriptor(org.eclipse.jface.resource.FontDescriptor) Shell(org.eclipse.swt.widgets.Shell) Mono(reactor.core.publisher.Mono) Field(java.lang.reflect.Field) ResourceGroup(com.microsoft.azure.toolkit.lib.common.model.ResourceGroup) ASP_CREATE_PRICING(com.microsoft.azuretools.webapp.util.CommonUtils.ASP_CREATE_PRICING) ProgressDialog(com.microsoft.azuretools.core.utils.ProgressDialog) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) GridLayout(org.eclipse.swt.layout.GridLayout) TableEditor(org.eclipse.swt.custom.TableEditor) Activator(com.microsoft.azuretools.webapp.Activator) URL(java.net.URL) Date(java.util.Date) TableColumn(org.eclipse.swt.widgets.TableColumn) CommonUtils.getSelectedItem(com.microsoft.azuretools.webapp.util.CommonUtils.getSelectedItem) MavenUtils(com.microsoft.azuretools.core.utils.MavenUtils) IStatus(org.eclipse.core.runtime.IStatus) WebContainer(com.microsoft.azure.toolkit.lib.appservice.model.WebContainer) AzureWebAppMvpModel(com.microsoft.azuretools.core.mvp.model.webapp.AzureWebAppMvpModel) Button(org.eclipse.swt.widgets.Button) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Display(org.eclipse.swt.widgets.Display) Collectors(java.util.stream.Collectors) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) Objects(java.util.Objects) ISharedImages(org.eclipse.ui.ISharedImages) List(java.util.List) CREATE_WEBAPP(com.microsoft.azuretools.telemetry.TelemetryConstants.CREATE_WEBAPP) Modifier(java.lang.reflect.Modifier) Optional(java.util.Optional) AzureMvpModel(com.microsoft.azuretools.core.mvp.model.AzureMvpModel) Label(org.eclipse.swt.widgets.Label) WEBAPP(com.microsoft.azuretools.telemetry.TelemetryConstants.WEBAPP) ControlDecoration(org.eclipse.jface.fieldassist.ControlDecoration) Image(org.eclipse.swt.graphics.Image) Rectangle(org.eclipse.swt.graphics.Rectangle) HashMap(java.util.HashMap) PricingTier(com.microsoft.azure.toolkit.lib.appservice.model.PricingTier) Table(org.eclipse.swt.widgets.Table) IWebApp(com.microsoft.azure.toolkit.lib.appservice.service.IWebApp) Event(org.eclipse.swt.widgets.Event) Region(com.microsoft.azure.toolkit.lib.common.model.Region) IAppServicePlan(com.microsoft.azure.toolkit.lib.appservice.service.IAppServicePlan) ObjectUtils(org.apache.commons.lang3.ObjectUtils) Schedulers(reactor.core.scheduler.Schedulers) LinkedList(java.util.LinkedList) FillLayout(org.eclipse.swt.layout.FillLayout) AzureAppService(com.microsoft.azure.toolkit.lib.appservice.AzureAppService) Combo(org.eclipse.swt.widgets.Combo) MalformedURLException(java.net.MalformedURLException) AzureUIRefreshEvent(com.microsoft.azuretools.utils.AzureUIRefreshEvent) Group(org.eclipse.swt.widgets.Group) ASP_CREATE_LOCATION(com.microsoft.azuretools.webapp.util.CommonUtils.ASP_CREATE_LOCATION) EventType(com.microsoft.azuretools.telemetrywrapper.EventType) AccessibilityUtils(com.microsoft.azuretools.core.utils.AccessibilityUtils) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Comparator(java.util.Comparator) FocusAdapter(org.eclipse.swt.events.FocusAdapter) WebAppSettingModel(com.microsoft.azuretools.core.mvp.model.webapp.WebAppSettingModel) Control(org.eclipse.swt.widgets.Control) IAppServicePlan(com.microsoft.azure.toolkit.lib.appservice.service.IAppServicePlan) Subscription(com.microsoft.azure.toolkit.lib.common.model.Subscription)

Example 12 with Subscription

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

the class AppServiceCreateDialog method fillRegions.

protected void fillRegions() {
    Subscription selectedSubscription = getSelectedSubscription();
    if (selectedSubscription == null) {
        return;
    }
    setComboRefreshingStatus(comboAppServicePlanLocation, true);
    Mono.fromCallable(() -> Azure.az(AzureAccount.class).listRegions(selectedSubscription.getId())).subscribeOn(Schedulers.boundedElastic()).subscribe(locl -> {
        if (locl != null) {
            binderAppServicePlanLocation = new ArrayList<>();
            DefaultLoader.getIdeHelper().invokeLater(() -> {
                for (int i = 0; i < locl.size(); i++) {
                    Region loc = locl.get(i);
                    comboAppServicePlanLocation.add(loc.getLabel());
                    binderAppServicePlanLocation.add(loc);
                    if (Objects.equals(loc, DEFAULT_REGION)) {
                        comboAppServicePlanLocation.select(i);
                    }
                }
                if (comboAppServicePlanLocation.getSelectionIndex() < 0 && comboAppServicePlanLocation.getItemCount() > 0) {
                    comboAppServicePlanLocation.select(0);
                }
                String aspLocation = CommonUtils.getPreference(ASP_CREATE_LOCATION);
                CommonUtils.selectComboIndex(comboAppServicePlanLocation, aspLocation);
            });
        }
    });
}
Also used : Region(com.microsoft.azure.toolkit.lib.common.model.Region) Subscription(com.microsoft.azure.toolkit.lib.common.model.Subscription) Point(org.eclipse.swt.graphics.Point)

Example 13 with Subscription

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

the class DatabaseResourcePanel method onSubscriptionChanged.

private void onSubscriptionChanged(final ItemEvent e) {
    if (e.getStateChange() == ItemEvent.SELECTED) {
        final Subscription subscription = (Subscription) e.getItem();
        this.serverComboBox.setSubscription(subscription);
    } else if (e.getStateChange() == ItemEvent.DESELECTED) {
        this.serverComboBox.setSubscription(null);
    }
}
Also used : Subscription(com.microsoft.azure.toolkit.lib.common.model.Subscription)

Example 14 with Subscription

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

the class CreateDeploymentForm method doOKAction.

@Override
protected void doOKAction() {
    deploymentName = deploymentNameTextField.getText();
    final AzureString title = AzureOperationBundle.title("arm|deployment.deploy", deploymentName);
    AzureTaskManager.getInstance().runInBackground(new AzureTask(project, title, false, () -> {
        EventUtil.executeWithLog(TelemetryConstants.ARM, TelemetryConstants.CREATE_DEPLOYMENT, (operation -> {
            Subscription subs = (Subscription) subscriptionCb.getSelectedItem();
            com.microsoft.azure.management.Azure azure = AuthMethodManager.getInstance().getAzureClient(subs.getId());
            WithTemplate template;
            if (createNewRgButton.isSelected()) {
                rgName = rgNameTextFiled.getText();
                final Region region = (Region) regionCb.getSelectedItem();
                template = azure.deployments().define(deploymentName).withNewResourceGroup(rgNameTextFiled.getText(), com.microsoft.azure.management.resources.fluentcore.arm.Region.fromName(region.getName()));
            } else {
                ResourceGroup rg = (ResourceGroup) rgNameCb.getSelectedItem();
                List<ResourceEx<Deployment>> deployments = AzureMvpModel.getInstance().getDeploymentByRgName(subs.getId(), rg.getName());
                boolean isExist = deployments.parallelStream().anyMatch(deployment -> deployment.getResource().name().equals(deploymentName));
                if (isExist) {
                    throw new RuntimeException(DUPLICATED_DEPLOYMENT_NAME);
                }
                rgName = rg.getName();
                template = azure.deployments().define(deploymentName).withExistingResourceGroup(rg.getName());
            }
            String fileText = templateTextField.getText();
            String content = IOUtils.toString(new FileReader(fileText));
            String parametersPath = parametersTextField.getText();
            String parameters = StringUtils.isEmpty(parametersPath) ? "{}" : IOUtils.toString(new FileReader(parametersPath));
            parameters = DeploymentUtils.parseParameters(parameters);
            template.withTemplate(content).withParameters(parameters).withMode(DeploymentMode.INCREMENTAL).create();
            UIUtils.showNotification(statusBar, NOTIFY_CREATE_DEPLOYMENT_SUCCESS, MessageType.INFO);
            updateUI();
        }), (ex) -> {
            UIUtils.showNotification(statusBar, NOTIFY_CREATE_DEPLOYMENT_FAIL + ", " + ex.getMessage(), MessageType.ERROR);
            updateUI();
        });
    }));
    close(DialogWrapper.OK_EXIT_CODE, true);
}
Also used : AuthMethodManager(com.microsoft.azuretools.authmanage.AuthMethodManager) Azure(com.microsoft.azure.toolkit.lib.Azure) NOTIFY_CREATE_DEPLOYMENT_FAIL(com.microsoft.azure.toolkit.intellij.arm.action.CreateDeploymentAction.NOTIFY_CREATE_DEPLOYMENT_FAIL) MessageType(com.intellij.openapi.ui.MessageType) SimpleListCellRenderer(com.intellij.ui.SimpleListCellRenderer) TextFieldWithBrowseButton(com.intellij.openapi.ui.TextFieldWithBrowseButton) StringUtils(org.apache.commons.lang3.StringUtils) HyperlinkLabel(com.intellij.ui.HyperlinkLabel) NOTIFY_CREATE_DEPLOYMENT_SUCCESS(com.microsoft.azure.toolkit.intellij.arm.action.CreateDeploymentAction.NOTIFY_CREATE_DEPLOYMENT_SUCCESS) StatusBar(com.intellij.openapi.wm.StatusBar) WithTemplate(com.microsoft.azure.management.resources.Deployment.DefinitionStages.WithTemplate) ResourceManagementNode(com.microsoft.tooling.msservices.serviceexplorer.azure.arm.ResourceManagementNode) AzureString(com.microsoft.azure.toolkit.lib.common.bundle.AzureString) JComboBox(javax.swing.JComboBox) ResourceEx(com.microsoft.azuretools.core.mvp.model.ResourceEx) WindowManager(com.intellij.openapi.wm.WindowManager) JRadioButton(javax.swing.JRadioButton) RegionComboBox(com.microsoft.azure.toolkit.intellij.common.component.RegionComboBox) IOUtils(org.apache.commons.io.IOUtils) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) AzureAccount(com.microsoft.azure.toolkit.lib.auth.AzureAccount) AzureMvpModel(com.microsoft.azuretools.core.mvp.model.AzureMvpModel) EventUtil(com.microsoft.azuretools.telemetrywrapper.EventUtil) JPanel(javax.swing.JPanel) AzureTaskManager(com.microsoft.azure.toolkit.lib.common.task.AzureTaskManager) FileChooserDescriptorFactory(com.intellij.openapi.fileChooser.FileChooserDescriptorFactory) JTextField(javax.swing.JTextField) AzureUIRefreshCore(com.microsoft.azuretools.utils.AzureUIRefreshCore) AzureOperationBundle(com.microsoft.azure.toolkit.lib.common.operation.AzureOperationBundle) AzureTask(com.microsoft.azure.toolkit.lib.common.task.AzureTask) Region(com.microsoft.azure.toolkit.lib.common.model.Region) DeploymentMode(com.microsoft.azure.management.resources.DeploymentMode) DialogWrapper(com.intellij.openapi.ui.DialogWrapper) Project(com.intellij.openapi.project.Project) Subscription(com.microsoft.azure.toolkit.lib.common.model.Subscription) JComponent(javax.swing.JComponent) Deployment(com.microsoft.azure.management.resources.Deployment) ButtonGroup(javax.swing.ButtonGroup) UIUtils(com.microsoft.intellij.ui.util.UIUtils) AzureUIRefreshEvent(com.microsoft.azuretools.utils.AzureUIRefreshEvent) JList(javax.swing.JList) ResourceGroup(com.microsoft.azure.toolkit.lib.common.model.ResourceGroup) EventType(com.microsoft.azuretools.telemetrywrapper.EventType) TelemetryConstants(com.microsoft.azuretools.telemetry.TelemetryConstants) JLabel(javax.swing.JLabel) FileReader(java.io.FileReader) SubscriptionComboBox(com.microsoft.azure.toolkit.intellij.common.component.SubscriptionComboBox) BROWSE_TEMPLATE_SAMPLES(com.microsoft.azuretools.telemetry.TelemetryConstants.BROWSE_TEMPLATE_SAMPLES) AzureString(com.microsoft.azure.toolkit.lib.common.bundle.AzureString) AzureString(com.microsoft.azure.toolkit.lib.common.bundle.AzureString) WithTemplate(com.microsoft.azure.management.resources.Deployment.DefinitionStages.WithTemplate) Region(com.microsoft.azure.toolkit.lib.common.model.Region) FileReader(java.io.FileReader) AzureTask(com.microsoft.azure.toolkit.lib.common.task.AzureTask) Subscription(com.microsoft.azure.toolkit.lib.common.model.Subscription) ResourceEx(com.microsoft.azuretools.core.mvp.model.ResourceEx) ResourceGroup(com.microsoft.azure.toolkit.lib.common.model.ResourceGroup)

Example 15 with Subscription

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

the class CreateDeploymentForm method fillResourceGroup.

private void fillResourceGroup() {
    if (subscriptionCb.getSelectedItem() == null) {
        return;
    }
    String sid = ((Subscription) subscriptionCb.getSelectedItem()).getId();
    rgNameCb.removeAllItems();
    for (ResourceEx<ResourceGroup> rg : AzureMvpModel.getInstance().getResourceGroups(sid)) {
        rgNameCb.addItem(rg.getResource());
    }
}
Also used : AzureString(com.microsoft.azure.toolkit.lib.common.bundle.AzureString) Subscription(com.microsoft.azure.toolkit.lib.common.model.Subscription) ResourceGroup(com.microsoft.azure.toolkit.lib.common.model.ResourceGroup)

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