Search in sources :

Example 6 with IWebApp

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

the class WebAppRunState method getOrCreateWebappFromAppSettingModel.

private IWebApp getOrCreateWebappFromAppSettingModel(AzureAppService azureAppService, RunProcessHandler processHandler) throws Exception {
    final WebAppEntity entity = WebAppEntity.builder().id(webAppSettingModel.getWebAppId()).subscriptionId(webAppSettingModel.getSubscriptionId()).resourceGroup(webAppSettingModel.getResourceGroup()).name(webAppSettingModel.getWebAppName()).build();
    final IWebApp webApp = azureAppService.webapp(entity);
    if (webApp.exists()) {
        return webApp;
    }
    if (webAppSettingModel.isCreatingNew()) {
        processHandler.setText(message("webapp.deploy.hint.creatingWebApp"));
        return AzureWebAppMvpModel.getInstance().createWebAppFromSettingModel(webAppSettingModel);
    } else {
        processHandler.setText(message("appService.deploy.hint.failed"));
        throw new Exception(message("webapp.deploy.error.noWebApp"));
    }
}
Also used : WebAppEntity(com.microsoft.azure.toolkit.lib.appservice.entity.WebAppEntity) AzureExecutionException(com.microsoft.azure.toolkit.lib.common.exception.AzureExecutionException) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) IWebApp(com.microsoft.azure.toolkit.lib.appservice.service.IWebApp)

Example 7 with IWebApp

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

the class WebAppRunState method getOrCreateDeployTargetFromAppSettingModel.

@NotNull
private IWebAppBase getOrCreateDeployTargetFromAppSettingModel(@NotNull RunProcessHandler processHandler) throws Exception {
    final AzureAppService azureAppService = AzureWebAppMvpModel.getInstance().getAzureAppServiceClient(webAppSettingModel.getSubscriptionId());
    final IWebApp webApp = getOrCreateWebappFromAppSettingModel(azureAppService, processHandler);
    if (!isDeployToSlot()) {
        return webApp;
    }
    // todo: add new boolean indicator instead of comparing string values
    if (StringUtils.equals(webAppSettingModel.getSlotName(), Constants.CREATE_NEW_SLOT)) {
        return createDeploymentSlot(webApp, processHandler);
    } else {
        return webApp.deploymentSlot(webAppSettingModel.getSlotName());
    }
}
Also used : AzureAppService(com.microsoft.azure.toolkit.lib.appservice.AzureAppService) IWebApp(com.microsoft.azure.toolkit.lib.appservice.service.IWebApp) NotNull(org.jetbrains.annotations.NotNull)

Example 8 with IWebApp

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

the class WebAppRunState method updateApplicationSettings.

private void updateApplicationSettings(IAppService deployTarget, RunProcessHandler processHandler) {
    final Map<String, String> applicationSettings = webAppConfiguration.getApplicationSettings();
    if (MapUtils.isEmpty(applicationSettings)) {
        return;
    }
    if (deployTarget instanceof IWebApp) {
        processHandler.setText("Updating application settings...");
        IWebApp webApp = (IWebApp) deployTarget;
        webApp.update().withAppSettings(applicationSettings).commit();
        processHandler.setText("Update application settings successfully.");
    } else if (deployTarget instanceof IWebAppDeploymentSlot) {
        processHandler.setText("Updating deployment slot application settings...");
        AzureWebAppMvpModel.getInstance().updateDeploymentSlotAppSettings((IWebAppDeploymentSlot) deployTarget, applicationSettings);
        processHandler.setText("Update deployment slot application settings successfully.");
    }
}
Also used : IWebAppDeploymentSlot(com.microsoft.azure.toolkit.lib.appservice.service.IWebAppDeploymentSlot) IWebApp(com.microsoft.azure.toolkit.lib.appservice.service.IWebApp)

Example 9 with IWebApp

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

the class WebAppOnLinuxDeployState method executeSteps.

@Override
@AzureOperation(name = "docker.deploy_image.state", type = AzureOperation.Type.ACTION)
public IAppService executeSteps(@NotNull RunProcessHandler processHandler, @NotNull Operation operation) throws Exception {
    processHandler.setText("Starting job ...  ");
    final String basePath = project.getBasePath();
    if (basePath == null) {
        processHandler.println("Project base path is null.", ProcessOutputTypes.STDERR);
        throw new FileNotFoundException("Project base path is null.");
    }
    // locate artifact to specified location
    final String targetFilePath = deployModel.getTargetPath();
    processHandler.setText(String.format("Locating artifact ... [%s]", targetFilePath));
    // validate dockerfile
    final Path targetDockerfile = Paths.get(deployModel.getDockerFilePath());
    processHandler.setText(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
    final PrivateRegistryImageSetting acrInfo = deployModel.getPrivateRegistryImageSetting();
    processHandler.setText(String.format("Building image ...  [%s]", acrInfo.getImageTagWithServerUrl()));
    final DockerClient docker = DefaultDockerClient.fromEnv().build();
    DockerUtil.ping(docker);
    DockerUtil.buildImage(docker, acrInfo.getImageTagWithServerUrl(), targetDockerfile.getParent(), targetDockerfile.getFileName().toString(), new DockerProgressHandler(processHandler));
    // push to ACR
    processHandler.setText(String.format("Pushing to ACR ... [%s] ", acrInfo.getServerUrl()));
    DockerUtil.pushImage(docker, acrInfo.getServerUrl(), acrInfo.getUsername(), acrInfo.getPassword(), acrInfo.getImageTagWithServerUrl(), new DockerProgressHandler(processHandler));
    // deploy
    if (deployModel.isCreatingNewWebAppOnLinux()) {
        // create new WebApp
        processHandler.setText(String.format("Creating new WebApp ... [%s]", deployModel.getWebAppName()));
        final IWebApp app = AzureWebAppMvpModel.getInstance().createAzureWebAppWithPrivateRegistryImage(deployModel);
        if (app != null && app.name() != null) {
            processHandler.setText(String.format("URL:  http://%s.azurewebsites.net/", app.name()));
            updateConfigurationDataModel(app);
            AzureUIRefreshCore.execute(new AzureUIRefreshEvent(AzureUIRefreshEvent.EventType.REFRESH, null));
        }
        return app;
    } else {
        // update WebApp
        processHandler.setText(String.format("Updating WebApp ... [%s]", deployModel.getWebAppName()));
        final IWebApp app = AzureWebAppMvpModel.getInstance().updateWebAppOnDocker(deployModel.getWebAppId(), acrInfo);
        if (app != null && app.name() != null) {
            processHandler.setText(String.format("URL:  http://%s.azurewebsites.net/", app.name()));
        }
        return app;
    }
}
Also used : Path(java.nio.file.Path) PrivateRegistryImageSetting(com.microsoft.azuretools.core.mvp.model.webapp.PrivateRegistryImageSetting) DockerProgressHandler(com.microsoft.azure.toolkit.intellij.webapp.docker.utils.DockerProgressHandler) DockerClient(com.spotify.docker.client.DockerClient) DefaultDockerClient(com.spotify.docker.client.DefaultDockerClient) FileNotFoundException(java.io.FileNotFoundException) AzureUIRefreshEvent(com.microsoft.azuretools.utils.AzureUIRefreshEvent) IWebApp(com.microsoft.azure.toolkit.lib.appservice.service.IWebApp) AzureOperation(com.microsoft.azure.toolkit.lib.common.operation.AzureOperation)

Example 10 with IWebApp

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

the class WebAppDeployDialog method fillSlot.

private void fillSlot() {
    if (!isDeployToSlot) {
        return;
    }
    int selectedRow = table.getSelectionIndex();
    comboSlot.removeAll();
    comboSlotConf.removeAll();
    if (selectedRow < 0) {
        return;
    }
    String appServiceName = table.getItems()[selectedRow].getText(0);
    IWebApp webApp = webAppDetailsMap.get(appServiceName);
    if (webApp == null) {
        return;
    }
    List<IWebAppDeploymentSlot> deploymentSlots = webApp.deploymentSlots(false);
    for (IWebAppDeploymentSlot deploymentSlot : deploymentSlots) {
        comboSlot.add(deploymentSlot.name());
        comboSlotConf.add(deploymentSlot.name());
    }
    if (comboSlot.getItemCount() > 0) {
        comboSlot.select(0);
    }
    comboSlotConf.add(webApp.name());
    comboSlotConf.add(DONOT_CLONE_SLOT_CONF);
    comboSlotConf.select(0);
}
Also used : IWebAppDeploymentSlot(com.microsoft.azure.toolkit.lib.appservice.service.IWebAppDeploymentSlot) Point(org.eclipse.swt.graphics.Point) 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