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