Search in sources :

Example 1 with AzureOperation

use of com.microsoft.azure.toolkit.lib.common.operation.AzureOperation 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 2 with AzureOperation

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

the class AzureWebAppMvpModel method createAzureWebAppWithPrivateRegistryImage.

/**
 * API to create Web App on Docker.
 *
 * @param model parameters
 * @return instance of created WebApp
 */
@AzureOperation(name = "docker.create_from_private_image", params = { "model.getWebAppName()", "model.getSubscriptionId()", "model.getPrivateRegistryImageSetting().getImageNameWithTag()" }, type = AzureOperation.Type.SERVICE)
public IWebApp createAzureWebAppWithPrivateRegistryImage(@NotNull WebAppOnLinuxDeployModel model) {
    final ResourceGroup resourceGroup = getOrCreateResourceGroup(model.getSubscriptionId(), model.getResourceGroupName(), model.getLocationName());
    final AppServicePlanEntity servicePlanEntity = AppServicePlanEntity.builder().id(model.getAppServicePlanId()).subscriptionId(model.getSubscriptionId()).name(model.getAppServicePlanName()).resourceGroup(model.getResourceGroupName()).region(model.getLocationName()).operatingSystem(com.microsoft.azure.toolkit.lib.appservice.model.OperatingSystem.DOCKER).pricingTier(com.microsoft.azure.toolkit.lib.appservice.model.PricingTier.fromString(model.getPricingSkuSize())).build();
    final IAppServicePlan appServicePlan = getOrCreateAppServicePlan(servicePlanEntity);
    final PrivateRegistryImageSetting pr = model.getPrivateRegistryImageSetting();
    // todo: support start up file in docker configuration
    final DockerConfiguration dockerConfiguration = DockerConfiguration.builder().image(pr.getImageTagWithServerUrl()).registryUrl(pr.getServerUrl()).userName(pr.getUsername()).password(pr.getPassword()).startUpCommand(pr.getStartupFile()).build();
    return getAzureAppServiceClient(model.getSubscriptionId()).webapp(model.getResourceGroupName(), model.getWebAppName()).create().withName(model.getWebAppName()).withResourceGroup(resourceGroup.getName()).withPlan(appServicePlan.id()).withRuntime(Runtime.DOCKER).withDockerConfiguration(dockerConfiguration).commit();
}
Also used : AppServicePlanEntity(com.microsoft.azure.toolkit.lib.appservice.entity.AppServicePlanEntity) DockerConfiguration(com.microsoft.azure.toolkit.lib.appservice.model.DockerConfiguration) IAppServicePlan(com.microsoft.azure.toolkit.lib.appservice.service.IAppServicePlan) ResourceGroup(com.microsoft.azure.toolkit.lib.common.model.ResourceGroup) AzureOperation(com.microsoft.azure.toolkit.lib.common.operation.AzureOperation)

Example 3 with AzureOperation

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

the class AzureWebAppMvpModel method createWebAppFromSettingModel.

/**
 * API to create new Web App by setting model.
 */
@AzureOperation(name = "webapp.create_detail", params = { "model.getWebAppName()" }, type = AzureOperation.Type.SERVICE)
public IWebApp createWebAppFromSettingModel(@NotNull WebAppSettingModel model) {
    final ResourceGroup resourceGroup = getOrCreateResourceGroup(model.getSubscriptionId(), model.getResourceGroup(), model.getRegion());
    final AppServicePlanEntity servicePlanEntity = AppServicePlanEntity.builder().id(model.getAppServicePlanId()).subscriptionId(model.getSubscriptionId()).name(model.getAppServicePlanName()).resourceGroup(model.getResourceGroup()).region(model.getRegion()).operatingSystem(com.microsoft.azure.toolkit.lib.appservice.model.OperatingSystem.fromString(model.getOperatingSystem())).pricingTier(com.microsoft.azure.toolkit.lib.appservice.model.PricingTier.fromString(model.getPricing())).build();
    final IAppServicePlan appServicePlan = getOrCreateAppServicePlan(servicePlanEntity);
    final DiagnosticConfig diagnosticConfig = DiagnosticConfig.builder().enableApplicationLog(model.isEnableApplicationLog()).applicationLogLevel(com.microsoft.azure.toolkit.lib.appservice.model.LogLevel.fromString(model.getApplicationLogLevel())).enableWebServerLogging(model.isEnableWebServerLogging()).webServerLogQuota(model.getWebServerLogQuota()).webServerRetentionPeriod(model.getWebServerRetentionPeriod()).enableDetailedErrorMessage(model.isEnableDetailedErrorMessage()).enableFailedRequestTracing(model.isEnableFailedRequestTracing()).build();
    return getAzureAppServiceClient(model.getSubscriptionId()).webapp(model.getResourceGroup(), model.getWebAppName()).create().withName(model.getWebAppName()).withResourceGroup(resourceGroup.getName()).withPlan(appServicePlan.id()).withRuntime(model.getRuntime()).withDiagnosticConfig(diagnosticConfig).commit();
}
Also used : AppServicePlanEntity(com.microsoft.azure.toolkit.lib.appservice.entity.AppServicePlanEntity) IAppServicePlan(com.microsoft.azure.toolkit.lib.appservice.service.IAppServicePlan) DiagnosticConfig(com.microsoft.azure.toolkit.lib.appservice.model.DiagnosticConfig) ResourceGroup(com.microsoft.azure.toolkit.lib.common.model.ResourceGroup) AzureOperation(com.microsoft.azure.toolkit.lib.common.operation.AzureOperation)

Example 4 with AzureOperation

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

the class WebAppRunState method onSuccess.

@Override
@AzureOperation(name = "webapp.complete_starting.state", type = AzureOperation.Type.ACTION)
protected void onSuccess(IAppService result, @NotNull RunProcessHandler processHandler) {
    if (webAppSettingModel.isCreatingNew() && AzureUIRefreshCore.listeners != null) {
        AzureUIRefreshCore.execute(new AzureUIRefreshEvent(AzureUIRefreshEvent.EventType.REFRESH, result));
    }
    updateConfigurationDataModel(result);
    int indexOfDot = webAppSettingModel.getTargetName().lastIndexOf(".");
    final String fileName = webAppSettingModel.getTargetName().substring(0, indexOfDot);
    final String fileType = webAppSettingModel.getTargetName().substring(indexOfDot + 1);
    final String url = getUrl(result, fileName, fileType);
    processHandler.setText(message("appService.deploy.hint.succeed"));
    processHandler.setText("URL: " + url);
    if (webAppSettingModel.isOpenBrowserAfterDeployment()) {
        openWebAppInBrowser(url, processHandler);
    }
    processHandler.notifyComplete();
}
Also used : AzureUIRefreshEvent(com.microsoft.azuretools.utils.AzureUIRefreshEvent) AzureOperation(com.microsoft.azure.toolkit.lib.common.operation.AzureOperation)

Example 5 with AzureOperation

use of com.microsoft.azure.toolkit.lib.common.operation.AzureOperation 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)

Aggregations

AzureOperation (com.microsoft.azure.toolkit.lib.common.operation.AzureOperation)64 AzureString (com.microsoft.azure.toolkit.lib.common.bundle.AzureString)11 AzureToolkitRuntimeException (com.microsoft.azure.toolkit.lib.common.exception.AzureToolkitRuntimeException)11 IOException (java.io.IOException)10 Project (com.intellij.openapi.project.Project)9 ArrayList (java.util.ArrayList)9 AzureTask (com.microsoft.azure.toolkit.lib.common.task.AzureTask)8 Operation (com.microsoft.azuretools.telemetrywrapper.Operation)6 Path (java.nio.file.Path)6 Module (com.intellij.openapi.module.Module)5 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)5 VirtualFile (com.intellij.openapi.vfs.VirtualFile)5 IWebApp (com.microsoft.azure.toolkit.lib.appservice.service.IWebApp)5 Azure (com.microsoft.azure.management.Azure)4 IFunctionApp (com.microsoft.azure.toolkit.lib.appservice.service.IFunctionApp)4 AzureUIRefreshEvent (com.microsoft.azuretools.utils.AzureUIRefreshEvent)4 Action (com.microsoft.azure.toolkit.lib.common.action.Action)3 ResourceGroup (com.microsoft.azure.toolkit.lib.common.model.ResourceGroup)3 Subscription (com.microsoft.azure.toolkit.lib.common.model.Subscription)3 AzureTaskManager (com.microsoft.azure.toolkit.lib.common.task.AzureTaskManager)3