use of com.microsoft.azuretools.utils.AzureUIRefreshEvent in project azure-tools-for-java by Microsoft.
the class AppServiceCreateDialog method okPressed.
@Override
protected void okPressed() {
String errTitle = ERROR_DIALOG_TITLE;
cleanError();
collectData();
recordUserSettings();
final Map<String, String> properties = model.getTelemetryProperties(new HashMap<String, String>());
if (!validated()) {
return;
}
try {
ProgressDialog.get(this.getShell(), CREATE_APP_SERVICE_PROGRESS_TITLE).run(true, true, (monitor) -> {
monitor.beginTask(VALIDATING_FORM_FIELDS, IProgressMonitor.UNKNOWN);
monitor.setTaskName(CREATING_APP_SERVICE);
if (monitor.isCanceled()) {
Display.getDefault().asyncExec(() -> AppServiceCreateDialog.super.cancelPressed());
}
EventUtil.executeWithLog(WEBAPP, CREATE_WEBAPP, (operation) -> {
EventUtil.logEvent(EventType.info, operation, properties);
webApp = AzureWebAppMvpModel.getInstance().createWebAppFromSettingModel(model);
if (!appSettings.isEmpty()) {
webApp.update().withAppSettings(appSettings).commit();
}
monitor.setTaskName(UPDATING_AZURE_LOCAL_CACHE);
Display.getDefault().asyncExec(() -> AppServiceCreateDialog.super.okPressed());
if (AzureUIRefreshCore.listeners != null) {
AzureUIRefreshCore.execute(new AzureUIRefreshEvent(AzureUIRefreshEvent.EventType.REFRESH, null));
}
}, (ex) -> {
LOG.log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "run@ProgressDialog@okPressed@AppServiceCreateDialog", ex));
Display.getDefault().asyncExec(() -> ErrorWindow.go(getShell(), ex.getMessage(), errTitle));
});
});
} catch (Exception ex) {
LOG.log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "okPressed@AppServiceCreateDialog", ex));
ErrorWindow.go(getShell(), ex.getMessage(), errTitle);
}
}
use of com.microsoft.azuretools.utils.AzureUIRefreshEvent in project azure-tools-for-java by microsoft.
the class FunctionDeploymentState method createFunctionApp.
private IFunctionApp createFunctionApp(@NotNull RunProcessHandler processHandler) {
IFunctionApp functionApp = Azure.az(AzureAppService.class).subscription(functionDeployConfiguration.getSubscriptionId()).functionApp(functionDeployConfiguration.getConfig().getResourceGroup().getName(), functionDeployConfiguration.getAppName());
if (functionApp.exists()) {
return functionApp;
}
processHandler.setText(message("function.create.hint.creating", functionDeployConfiguration.getAppName()));
// Load app settings from security storage
final FunctionAppConfig config = deployModel.getFunctionAppConfig();
config.setAppSettings(FunctionUtils.loadAppSettingsFromSecurityStorage(functionDeployConfiguration.getAppSettingsKey()));
// create function app
functionApp = FunctionAppService.getInstance().createFunctionApp(config);
// update run configuration
functionDeployConfiguration.setFunctionId(functionApp.id());
// Notify explorer refresh
AzureUIRefreshCore.execute(new AzureUIRefreshEvent(AzureUIRefreshEvent.EventType.REFRESH, functionApp));
processHandler.setText(message("function.create.hint.created", functionDeployConfiguration.getAppName()));
return functionApp;
}
use of com.microsoft.azuretools.utils.AzureUIRefreshEvent 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.azuretools.utils.AzureUIRefreshEvent 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());
});
}
Aggregations