Search in sources :

Example 1 with IWebApp

use of com.microsoft.azure.toolkit.lib.appservice.service.IWebApp 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 2 with IWebApp

use of com.microsoft.azure.toolkit.lib.appservice.service.IWebApp in project azure-tools-for-java by Microsoft.

the class PublishWebAppOnLinuxDialog method execute.

private void execute() {
    Operation operation = TelemetryManager.createOperation(WEBAPP, DEPLOY_WEBAPP_CONTAINER);
    Observable.fromCallable(() -> {
        ConsoleLogger.info("Starting job ...  ");
        operation.start();
        if (basePath == null) {
            ConsoleLogger.error("Project base path is null.");
            throw new FileNotFoundException("Project base path is null.");
        }
        // locate artifact to specified location
        String targetFilePath = model.getTargetPath();
        ConsoleLogger.info(String.format("Locating artifact ... [%s]", targetFilePath));
        // validate dockerfile
        Path targetDockerfile = Paths.get(model.getDockerFilePath());
        ConsoleLogger.info(String.format("Validating dockerfile ... [%s]", targetDockerfile));
        if (!targetDockerfile.toFile().exists()) {
            throw new FileNotFoundException("Dockerfile not found.");
        }
        // replace placeholder if exists
        String content = new String(Files.readAllBytes(targetDockerfile));
        content = content.replaceAll(Constant.DOCKERFILE_ARTIFACT_PLACEHOLDER, Paths.get(basePath).toUri().relativize(Paths.get(targetFilePath).toUri()).getPath());
        Files.write(targetDockerfile, content.getBytes());
        // build image
        PrivateRegistryImageSetting acrInfo = model.getPrivateRegistryImageSetting();
        ConsoleLogger.info(String.format("Building image ...  [%s]", acrInfo.getImageTagWithServerUrl()));
        DockerClient docker = DefaultDockerClient.fromEnv().build();
        DockerUtil.ping(docker);
        DockerUtil.buildImage(docker, acrInfo.getImageTagWithServerUrl(), targetDockerfile.getParent(), targetDockerfile.getFileName().toString(), new DockerProgressHandler());
        // push to ACR
        ConsoleLogger.info(String.format("Pushing to ACR ... [%s] ", acrInfo.getServerUrl()));
        DockerUtil.pushImage(docker, acrInfo.getServerUrl(), acrInfo.getUsername(), acrInfo.getPassword(), acrInfo.getImageTagWithServerUrl(), new DockerProgressHandler());
        // deploy
        if (model.isCreatingNewWebAppOnLinux()) {
            // create new WebApp
            ConsoleLogger.info(String.format("Creating new WebApp ... [%s]", model.getWebAppName()));
            IWebApp app = AzureWebAppMvpModel.getInstance().createAzureWebAppWithPrivateRegistryImage(model);
            if (app != null && app.name() != null) {
                ConsoleLogger.info(String.format("URL:  http://%s.azurewebsites.net/", app.name()));
                AzureUIRefreshCore.execute(new AzureUIRefreshEvent(AzureUIRefreshEvent.EventType.REFRESH, null));
            }
        } else {
            // update WebApp
            ConsoleLogger.info(String.format("Updating WebApp ... [%s]", model.getWebAppName()));
            IWebApp app = AzureWebAppMvpModel.getInstance().updateWebAppOnDocker(model.getWebAppId(), acrInfo);
            if (app != null && app.name() != null) {
                ConsoleLogger.info(String.format("URL:  http://%s.azurewebsites.net/", app.name()));
            }
        }
        return null;
    }).subscribeOn(SchedulerProviderFactory.getInstance().getSchedulerProvider().io()).subscribe(ret -> {
        ConsoleLogger.info("Job done");
        if (model.isCreatingNewWebAppOnLinux() && AzureUIRefreshCore.listeners != null) {
            AzureUIRefreshCore.execute(new AzureUIRefreshEvent(AzureUIRefreshEvent.EventType.REFRESH, null));
        }
        sendTelemetry(true, null);
        operation.complete();
    }, err -> {
        err.printStackTrace();
        ConsoleLogger.error(err.getMessage());
        EventUtil.logError(operation, ErrorType.systemError, new Exception(err), null, null);
        operation.complete();
        sendTelemetry(false, err.getMessage());
    });
}
Also used : Path(java.nio.file.Path) PrivateRegistryImageSetting(com.microsoft.azuretools.core.mvp.model.webapp.PrivateRegistryImageSetting) DockerProgressHandler(com.microsoft.azuretools.container.DockerProgressHandler) DockerClient(com.spotify.docker.client.DockerClient) DefaultDockerClient(com.spotify.docker.client.DefaultDockerClient) FileNotFoundException(java.io.FileNotFoundException) Operation(com.microsoft.azuretools.telemetrywrapper.Operation) AzureUIRefreshEvent(com.microsoft.azuretools.utils.AzureUIRefreshEvent) InvalidFormDataException(com.microsoft.azuretools.azurecommons.exceptions.InvalidFormDataException) FileNotFoundException(java.io.FileNotFoundException) IWebApp(com.microsoft.azure.toolkit.lib.appservice.service.IWebApp)

Example 3 with IWebApp

use of com.microsoft.azure.toolkit.lib.appservice.service.IWebApp in project azure-tools-for-java by Microsoft.

the class AzureWebAppMvpModel method deployArtifactsToWebApp.

@AzureOperation(name = "webapp|artifact.upload", params = { "file.getName()", "deployTarget.name()" }, type = AzureOperation.Type.SERVICE)
public void deployArtifactsToWebApp(@NotNull final IWebAppBase deployTarget, @NotNull final File file, boolean isDeployToRoot, @NotNull final IProgressIndicator progressIndicator) {
    if (!(deployTarget instanceof IWebApp || deployTarget instanceof IWebAppDeploymentSlot)) {
        final String error = "the deployment target is not a valid (deployment slot of) Web App";
        final String action = "select a valid Web App or deployment slot to deploy the artifact";
        throw new AzureToolkitRuntimeException(error, action);
    }
    // stop target app service
    String stopMessage = deployTarget instanceof IWebApp ? STOP_WEB_APP : STOP_DEPLOYMENT_SLOT;
    progressIndicator.setText(stopMessage);
    deployTarget.stop();
    final DeployType deployType = getDeployTypeByWebContainer(deployTarget.getRuntime().getWebContainer());
    // java se runtime will always deploy to root
    if (isDeployToRoot || Objects.equals(deployTarget.getRuntime().getWebContainer(), com.microsoft.azure.toolkit.lib.appservice.model.WebContainer.JAVA_SE)) {
        deployTarget.deploy(deployType, file);
    } else {
        final String webappPath = String.format("webapps/%s", FilenameUtils.getBaseName(file.getName()).replaceAll("#", StringUtils.EMPTY));
        deployTarget.deploy(deployType, file, webappPath);
    }
    String successMessage = deployTarget instanceof IWebApp ? DEPLOY_SUCCESS_WEB_APP : DEPLOY_SUCCESS_DEPLOYMENT_SLOT;
    progressIndicator.setText(successMessage);
    deployTarget.start();
}
Also used : DeployType(com.microsoft.azure.toolkit.lib.appservice.model.DeployType) IWebAppDeploymentSlot(com.microsoft.azure.toolkit.lib.appservice.service.IWebAppDeploymentSlot) AzureToolkitRuntimeException(com.microsoft.azure.toolkit.lib.common.exception.AzureToolkitRuntimeException) IWebApp(com.microsoft.azure.toolkit.lib.appservice.service.IWebApp) AzureOperation(com.microsoft.azure.toolkit.lib.common.operation.AzureOperation)

Example 4 with IWebApp

use of com.microsoft.azure.toolkit.lib.appservice.service.IWebApp in project azure-tools-for-java by Microsoft.

the class SettingPanel method renderWebAppOnLinuxList.

@Override
public void renderWebAppOnLinuxList(List<IWebApp> webAppOnLinuxList) {
    btnRefresh.setEnabled(true);
    webAppTable.getEmptyText().setText(TABLE_EMPTY_MESSAGE);
    final List<IWebApp> sortedList = webAppOnLinuxList.stream().sorted((a, b) -> a.subscriptionId().compareToIgnoreCase(b.subscriptionId())).collect(Collectors.toList());
    cachedWebAppList = sortedList;
    if (cachedWebAppList.size() > 0) {
        final DefaultTableModel model = (DefaultTableModel) webAppTable.getModel();
        model.getDataVector().clear();
        for (final IWebApp resource : sortedList) {
            model.addRow(new String[] { resource.name(), resource.resourceGroup() });
        }
    }
    // select active web app
    for (int index = 0; index < cachedWebAppList.size(); index++) {
        if (StringUtils.equals(cachedWebAppList.get(index).id(), defaultWebAppId)) {
            webAppTable.setRowSelectionInterval(index, index);
            // defaultWebAppId = null; // clear to select nothing in future refreshing
            break;
        }
    }
}
Also used : ISecureStore(com.microsoft.azure.toolkit.ide.common.store.ISecureStore) ListSelectionModel(javax.swing.ListSelectionModel) AllIcons(com.intellij.icons.AllIcons) SimpleListCellRenderer(com.intellij.ui.SimpleListCellRenderer) JTextField(javax.swing.JTextField) Date(java.util.Date) Constant(com.microsoft.azure.toolkit.intellij.webapp.docker.utils.Constant) SimpleDateFormat(java.text.SimpleDateFormat) PricingTier(com.microsoft.azure.toolkit.lib.appservice.model.PricingTier) Artifact(com.intellij.packaging.artifacts.Artifact) IWebApp(com.microsoft.azure.toolkit.lib.appservice.service.IWebApp) ToolbarDecorator(com.intellij.ui.ToolbarDecorator) StringUtils(org.apache.commons.lang3.StringUtils) ActionToolbarPosition(com.intellij.openapi.actionSystem.ActionToolbarPosition) Region(com.microsoft.azure.toolkit.lib.common.model.Region) IAppServicePlan(com.microsoft.azure.toolkit.lib.appservice.service.IAppServicePlan) WebAppOnLinuxDeployConfiguration(com.microsoft.azure.toolkit.intellij.webapp.docker.webapponlinux.WebAppOnLinuxDeployConfiguration) AppServicePlan(com.microsoft.azure.toolkit.lib.appservice.service.impl.AppServicePlan) Project(com.intellij.openapi.project.Project) MavenIcons(icons.MavenIcons) WebAppOnLinuxDeployView(com.microsoft.tooling.msservices.serviceexplorer.azure.container.WebAppOnLinuxDeployView) JComboBox(javax.swing.JComboBox) AnActionButton(com.intellij.ui.AnActionButton) DateFormat(java.text.DateFormat) Subscription(com.microsoft.azure.toolkit.lib.common.model.Subscription) HideableDecorator(com.intellij.ui.HideableDecorator) MavenProject(org.jetbrains.idea.maven.project.MavenProject) ItemEvent(java.awt.event.ItemEvent) WebAppOnLinuxDeployPresenter(com.microsoft.tooling.msservices.serviceexplorer.azure.container.WebAppOnLinuxDeployPresenter) DefaultTableModel(javax.swing.table.DefaultTableModel) JList(javax.swing.JList) AzureStoreManager(com.microsoft.azure.toolkit.ide.common.store.AzureStoreManager) AzureSettingPanel(com.microsoft.azure.toolkit.intellij.common.AzureSettingPanel) ResourceGroup(com.microsoft.azure.toolkit.lib.common.model.ResourceGroup) Collectors(java.util.stream.Collectors) JRadioButton(javax.swing.JRadioButton) JBTable(com.intellij.ui.table.JBTable) List(java.util.List) JLabel(javax.swing.JLabel) ContainerSettingPanel(com.microsoft.azure.toolkit.intellij.webapp.docker.ContainerSettingPanel) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) NotNull(org.jetbrains.annotations.NotNull) Utils(com.microsoft.azuretools.azurecommons.util.Utils) PrivateRegistryImageSetting(com.microsoft.azuretools.core.mvp.model.webapp.PrivateRegistryImageSetting) JPanel(javax.swing.JPanel) DockerUtil(com.microsoft.azure.toolkit.intellij.webapp.docker.utils.DockerUtil) PRIVATE_DOCKER_REGISTRY(com.microsoft.azure.toolkit.intellij.webapp.docker.pushimage.ui.SettingPanel.PRIVATE_DOCKER_REGISTRY) DefaultTableModel(javax.swing.table.DefaultTableModel) IWebApp(com.microsoft.azure.toolkit.lib.appservice.service.IWebApp)

Example 5 with IWebApp

use of com.microsoft.azure.toolkit.lib.appservice.service.IWebApp in project azure-tools-for-java by Microsoft.

the class WebAppConfiguration method saveModel.

public void saveModel(final WebAppComboBoxModel webAppComboBoxModel) {
    setWebAppId(webAppComboBoxModel.getResourceId());
    setWebAppName(webAppComboBoxModel.getAppName());
    setResourceGroup(webAppComboBoxModel.getResourceGroup());
    setSubscriptionId(webAppComboBoxModel.getSubscriptionId());
    if (webAppComboBoxModel.isNewCreateResource()) {
        setCreatingNew(true);
        final WebAppSettingModel settingModel = webAppComboBoxModel.getWebAppSettingModel();
        setCreatingResGrp(settingModel.isCreatingResGrp());
        setCreatingAppServicePlan(settingModel.isCreatingAppServicePlan());
        setAppServicePlanName(settingModel.getAppServicePlanName());
        setRegion(settingModel.getRegion());
        setPricing(settingModel.getPricing());
        setAppServicePlanId(settingModel.getAppServicePlanId());
        saveRuntime(settingModel.getRuntime());
        setCreatingResGrp(settingModel.isCreatingResGrp());
        setCreatingAppServicePlan(settingModel.isCreatingAppServicePlan());
        webAppSettingModel.setEnableApplicationLog(settingModel.isEnableApplicationLog());
        webAppSettingModel.setApplicationLogLevel(settingModel.getApplicationLogLevel());
        webAppSettingModel.setEnableWebServerLogging(settingModel.isEnableWebServerLogging());
        webAppSettingModel.setWebServerLogQuota(settingModel.getWebServerLogQuota());
        webAppSettingModel.setWebServerRetentionPeriod(settingModel.getWebServerRetentionPeriod());
        webAppSettingModel.setEnableDetailedErrorMessage(settingModel.isEnableDetailedErrorMessage());
        webAppSettingModel.setEnableFailedRequestTracing(settingModel.isEnableFailedRequestTracing());
    } else {
        setCreatingNew(false);
        final IWebApp webApp = webAppComboBoxModel.getResource();
        if (webApp != null) {
            saveRuntime(webApp.getRuntime());
            setAppServicePlanId(webApp.entity().getAppServicePlanId());
            setRegion(webApp.entity().getRegion().getName());
        }
    }
}
Also used : WebAppSettingModel(com.microsoft.azuretools.core.mvp.model.webapp.WebAppSettingModel) IWebApp(com.microsoft.azure.toolkit.lib.appservice.service.IWebApp)

Aggregations

IWebApp (com.microsoft.azure.toolkit.lib.appservice.service.IWebApp)24 Point (org.eclipse.swt.graphics.Point)8 IAppServicePlan (com.microsoft.azure.toolkit.lib.appservice.service.IAppServicePlan)5 Subscription (com.microsoft.azure.toolkit.lib.common.model.Subscription)5 PrivateRegistryImageSetting (com.microsoft.azuretools.core.mvp.model.webapp.PrivateRegistryImageSetting)5 IWebAppDeploymentSlot (com.microsoft.azure.toolkit.lib.appservice.service.IWebAppDeploymentSlot)4 AzureOperation (com.microsoft.azure.toolkit.lib.common.operation.AzureOperation)4 IOException (java.io.IOException)4 AzureAppService (com.microsoft.azure.toolkit.lib.appservice.AzureAppService)3 PricingTier (com.microsoft.azure.toolkit.lib.appservice.model.PricingTier)3 Region (com.microsoft.azure.toolkit.lib.common.model.Region)3 ResourceGroup (com.microsoft.azure.toolkit.lib.common.model.ResourceGroup)3 Operation (com.microsoft.azuretools.telemetrywrapper.Operation)3 FileNotFoundException (java.io.FileNotFoundException)3 ISecureStore (com.microsoft.azure.toolkit.ide.common.store.ISecureStore)2 WebAppSettingModel (com.microsoft.azuretools.core.mvp.model.webapp.WebAppSettingModel)2 AzureUIRefreshEvent (com.microsoft.azuretools.utils.AzureUIRefreshEvent)2 DefaultDockerClient (com.spotify.docker.client.DefaultDockerClient)2 DockerClient (com.spotify.docker.client.DockerClient)2 Path (java.nio.file.Path)2