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();
}
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();
}
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();
}
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();
}
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;
}
}
Aggregations