Search in sources :

Example 16 with PrivateRegistryImageSetting

use of com.microsoft.azuretools.core.mvp.model.webapp.PrivateRegistryImageSetting in project azure-tools-for-java by Microsoft.

the class ContainerRegistryPropertyView method pullImage.

private void pullImage() {
    final AzureString title = AzureOperationBundle.title("docker|image.pull", currentRepo);
    AzureTaskManager.getInstance().runInBackground(new AzureTask(null, title, false, () -> {
        try {
            if (Utils.isEmptyString(currentRepo) || Utils.isEmptyString(currentTag)) {
                throw new Exception(REPO_TAG_NOT_AVAILABLE);
            }
            final Registry registry = ContainerRegistryMvpModel.getInstance().getContainerRegistry(subscriptionId, registryId);
            final PrivateRegistryImageSetting setting = ContainerRegistryMvpModel.getInstance().createImageSettingWithRegistry(registry);
            final String image = String.format("%s:%s", currentRepo, currentTag);
            final String fullImageTagName = String.format("%s/%s", registry.loginServerUrl(), image);
            DockerClient docker = DefaultDockerClient.fromEnv().build();
            DockerUtil.pullImage(docker, registry.loginServerUrl(), setting.getUsername(), setting.getPassword(), fullImageTagName);
            String message = String.format(IMAGE_PULL_SUCCESS, fullImageTagName);
            UIUtils.showNotification(statusBar, message, MessageType.INFO);
            sendTelemetry(true, subscriptionId, null);
        } catch (Exception e) {
            UIUtils.showNotification(statusBar, e.getMessage(), MessageType.ERROR);
            sendTelemetry(false, subscriptionId, e.getMessage());
        }
    }));
}
Also used : PrivateRegistryImageSetting(com.microsoft.azuretools.core.mvp.model.webapp.PrivateRegistryImageSetting) DockerClient(com.spotify.docker.client.DockerClient) DefaultDockerClient(com.spotify.docker.client.DefaultDockerClient) Registry(com.microsoft.azure.management.containerregistry.Registry) AzureString(com.microsoft.azure.toolkit.lib.common.bundle.AzureString) AzureTask(com.microsoft.azure.toolkit.lib.common.task.AzureTask) AzureString(com.microsoft.azure.toolkit.lib.common.bundle.AzureString)

Example 17 with PrivateRegistryImageSetting

use of com.microsoft.azuretools.core.mvp.model.webapp.PrivateRegistryImageSetting in project azure-tools-for-java by Microsoft.

the class SettingPanel method resetFromConfig.

/**
 * Function triggered in constructing the panel.
 *
 * @param conf configuration instance
 */
@Override
public void resetFromConfig(PushImageRunConfiguration conf) {
    if (!isMavenProject()) {
        containerSettingPanel.setDockerPath(DockerUtil.getDefaultDockerFilePathIfExist(getProjectBasePath()));
    }
    PrivateRegistryImageSetting acrInfo = conf.getPrivateRegistryImageSetting();
    if (StringUtils.isEmpty(acrInfo.getPassword())) {
        final ISecureStore secureStore = AzureStoreManager.getInstance().getSecureStore();
        secureStore.migratePassword(containerSettingPanel.getServerUrl(), containerSettingPanel.getUserName(), PRIVATE_DOCKER_REGISTRY, containerSettingPanel.getServerUrl(), containerSettingPanel.getUserName());
        acrInfo.setPassword(secureStore.loadPassword(PRIVATE_DOCKER_REGISTRY, acrInfo.getServerUrl(), acrInfo.getUsername()));
    }
    containerSettingPanel.setTxtFields(acrInfo);
    // load dockerFile path from existing configuration.
    if (!Utils.isEmptyString(conf.getDockerFilePath())) {
        containerSettingPanel.setDockerPath(conf.getDockerFilePath());
    }
    containerSettingPanel.onListRegistries();
}
Also used : PrivateRegistryImageSetting(com.microsoft.azuretools.core.mvp.model.webapp.PrivateRegistryImageSetting) ISecureStore(com.microsoft.azure.toolkit.ide.common.store.ISecureStore)

Example 18 with PrivateRegistryImageSetting

use of com.microsoft.azuretools.core.mvp.model.webapp.PrivateRegistryImageSetting in project azure-tools-for-java by Microsoft.

the class SettingPanel method resetFromConfig.

/**
 * Function triggered in constructing the panel.
 *
 * @param conf configuration instance
 */
@Override
public void resetFromConfig(@NotNull WebAppOnLinuxDeployConfiguration conf) {
    if (!isMavenProject()) {
        containerSettingPanel.setDockerPath(DockerUtil.getDefaultDockerFilePathIfExist(getProjectBasePath()));
    }
    // load dockerFile path from existing configuration.
    if (!Utils.isEmptyString(conf.getDockerFilePath())) {
        containerSettingPanel.setDockerPath(conf.getDockerFilePath());
    }
    final PrivateRegistryImageSetting acrInfo = conf.getPrivateRegistryImageSetting();
    if (StringUtils.isNotEmpty(acrInfo.getServerUrl())) {
        final ISecureStore secureStore = AzureStoreManager.getInstance().getSecureStore();
        secureStore.migratePassword(acrInfo.getServerUrl(), acrInfo.getUsername(), PRIVATE_DOCKER_REGISTRY, acrInfo.getServerUrl(), acrInfo.getUsername());
        acrInfo.setPassword(secureStore.loadPassword(PRIVATE_DOCKER_REGISTRY, acrInfo.getServerUrl(), acrInfo.getUsername()));
    }
    containerSettingPanel.setTxtFields(acrInfo);
    // cache for table/combo selection
    defaultSubscriptionId = conf.getSubscriptionId();
    defaultWebAppId = conf.getWebAppId();
    defaultLocationName = conf.getLocationName();
    defaultPricingTier = StringUtils.isEmpty(conf.getPricingSkuTier()) ? Constant.WEBAPP_CONTAINER_DEFAULT_PRICING_TIER : new PricingTier(conf.getPricingSkuTier(), conf.getPricingSkuSize()).toString();
    defaultResourceGroup = conf.getResourceGroupName();
    defaultAppServicePlanId = conf.getAppServicePlanId();
    // pnlUseExisting
    loadWebAppList();
    // pnlCreateNew
    // including related RG & Region
    webAppOnLinuxDeployPresenter.onLoadSubscriptionList();
    webAppOnLinuxDeployPresenter.onLoadPricingTierList();
    final boolean creatingRg = conf.isCreatingNewResourceGroup();
    rdoCreateResGrp.setSelected(creatingRg);
    rdoUseExistResGrp.setSelected(!creatingRg);
    updateResourceGroupEnabled();
    if (creatingRg) {
        txtNewResGrp.setText(conf.getResourceGroupName());
    }
    final boolean creatingAsp = conf.isCreatingNewAppServicePlan();
    rdoCreateAppServicePlan.setSelected(creatingAsp);
    rdoUseExistAppServicePlan.setSelected(!creatingAsp);
    updateAppServicePlanEnabled();
    if (creatingAsp) {
        txtCreateAppServicePlan.setText(conf.getAppServicePlanName());
    }
    // active panel
    final boolean creatingApp = conf.isCreatingNewWebAppOnLinux();
    if (creatingApp) {
        textAppName.setText(conf.getAppName());
    }
    rdoCreateNew.setSelected(creatingApp);
    rdoUseExist.setSelected(!creatingApp);
    updatePanelVisibility();
    // default value for new resources
    final DateFormat df = new SimpleDateFormat("yyMMddHHmmss");
    final String date = df.format(new Date());
    if (Utils.isEmptyString(textAppName.getText())) {
        textAppName.setText(String.format("%s-%s", APP_NAME_PREFIX, date));
    }
    if (Utils.isEmptyString(txtNewResGrp.getText())) {
        txtNewResGrp.setText(String.format("%s-%s", RESOURCE_GROUP_NAME_PREFIX, date));
    }
    if (Utils.isEmptyString(txtCreateAppServicePlan.getText())) {
        txtCreateAppServicePlan.setText(String.format("%s-%s", APP_SERVICE_PLAN_NAME_PREFIX, date));
    }
}
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) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Example 19 with PrivateRegistryImageSetting

use of com.microsoft.azuretools.core.mvp.model.webapp.PrivateRegistryImageSetting 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 20 with PrivateRegistryImageSetting

use of com.microsoft.azuretools.core.mvp.model.webapp.PrivateRegistryImageSetting in project azure-tools-for-java by Microsoft.

the class PushToContainerRegistryAction method runConfiguration.

@SuppressWarnings({ "deprecation", "Duplicates" })
private void runConfiguration(@NotNull Project project) {
    final RunManagerEx manager = RunManagerEx.getInstanceEx(project);
    final ConfigurationFactory factory = configType.getPushImageRunConfigurationFactory();
    RunnerAndConfigurationSettings settings = manager.findConfigurationByName(String.format("%s: %s", factory.getName(), project.getName()));
    Observable.fromCallable(() -> {
        Registry registry = ContainerRegistryMvpModel.getInstance().getContainerRegistry(currentNode.getSubscriptionId(), currentNode.getResourceId());
        return ContainerRegistryMvpModel.getInstance().createImageSettingWithRegistry(registry);
    }).subscribeOn(SchedulerProviderFactory.getInstance().getSchedulerProvider().io()).subscribe(ret -> {
        if (settings != null) {
            PushImageRunConfiguration conf = (PushImageRunConfiguration) settings.getConfiguration();
            PrivateRegistryImageSetting imageSetting = conf.getPrivateRegistryImageSetting();
            imageSetting.setServerUrl(ret.getServerUrl());
            imageSetting.setUsername(ret.getUsername());
            imageSetting.setPassword(ret.getPassword());
            AzureTaskManager.getInstance().runLater(() -> openRunDialog(project, settings));
            return;
        }
        AzureTaskManager.getInstance().runLater(() -> openRunDialog(project, ret));
    }, err -> {
        err.printStackTrace();
        Notification notification = new Notification(NOTIFICATION_GROUP_ID, DIALOG_TITLE, err.getMessage(), NotificationType.ERROR);
        Notifications.Bus.notify(notification);
    });
}
Also used : PrivateRegistryImageSetting(com.microsoft.azuretools.core.mvp.model.webapp.PrivateRegistryImageSetting) RunManagerEx(com.intellij.execution.RunManagerEx) ConfigurationFactory(com.intellij.execution.configurations.ConfigurationFactory) RunnerAndConfigurationSettings(com.intellij.execution.RunnerAndConfigurationSettings) PushImageRunConfiguration(com.microsoft.azure.toolkit.intellij.webapp.docker.pushimage.PushImageRunConfiguration) Registry(com.microsoft.azure.management.containerregistry.Registry) Notification(com.intellij.notification.Notification)

Aggregations

PrivateRegistryImageSetting (com.microsoft.azuretools.core.mvp.model.webapp.PrivateRegistryImageSetting)21 DefaultDockerClient (com.spotify.docker.client.DefaultDockerClient)6 DockerClient (com.spotify.docker.client.DockerClient)6 Registry (com.microsoft.azure.management.containerregistry.Registry)5 ISecureStore (com.microsoft.azure.toolkit.ide.common.store.ISecureStore)4 IWebApp (com.microsoft.azure.toolkit.lib.appservice.service.IWebApp)4 InvalidFormDataException (com.microsoft.azuretools.azurecommons.exceptions.InvalidFormDataException)4 FileNotFoundException (java.io.FileNotFoundException)4 Path (java.nio.file.Path)4 PricingTier (com.microsoft.azure.toolkit.lib.appservice.model.PricingTier)3 Gson (com.google.gson.Gson)2 ConfigurationException (com.intellij.openapi.options.ConfigurationException)2 AccessKeyType (com.microsoft.azure.management.containerregistry.AccessKeyType)2 RegistryCredentials (com.microsoft.azure.management.containerregistry.RegistryCredentials)2 DockerProgressHandler (com.microsoft.azure.toolkit.intellij.webapp.docker.utils.DockerProgressHandler)2 IAppServicePlan (com.microsoft.azure.toolkit.lib.appservice.service.IAppServicePlan)2 Region (com.microsoft.azure.toolkit.lib.common.model.Region)2 ResourceGroup (com.microsoft.azure.toolkit.lib.common.model.ResourceGroup)2 Subscription (com.microsoft.azure.toolkit.lib.common.model.Subscription)2 DockerProgressHandler (com.microsoft.azuretools.container.DockerProgressHandler)2