Search in sources :

Example 11 with AzureUIRefreshEvent

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);
    }
}
Also used : Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) AzureUIRefreshEvent(com.microsoft.azuretools.utils.AzureUIRefreshEvent) PartInitException(org.eclipse.ui.PartInitException) MalformedURLException(java.net.MalformedURLException)

Example 12 with AzureUIRefreshEvent

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;
}
Also used : FunctionAppConfig(com.microsoft.azure.toolkit.lib.function.FunctionAppConfig) IFunctionApp(com.microsoft.azure.toolkit.lib.appservice.service.IFunctionApp) AzureUIRefreshEvent(com.microsoft.azuretools.utils.AzureUIRefreshEvent)

Example 13 with AzureUIRefreshEvent

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;
    }
}
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 14 with AzureUIRefreshEvent

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());
    });
}
Also used : Path(java.nio.file.Path) PrivateRegistryImageSetting(com.microsoft.azuretools.core.mvp.model.webapp.PrivateRegistryImageSetting) DockerProgressHandler(com.microsoft.azuretools.container.DockerProgressHandler) DockerClient(com.spotify.docker.client.DockerClient) DefaultDockerClient(com.spotify.docker.client.DefaultDockerClient) FileNotFoundException(java.io.FileNotFoundException) Operation(com.microsoft.azuretools.telemetrywrapper.Operation) AzureUIRefreshEvent(com.microsoft.azuretools.utils.AzureUIRefreshEvent) InvalidFormDataException(com.microsoft.azuretools.azurecommons.exceptions.InvalidFormDataException) FileNotFoundException(java.io.FileNotFoundException) IWebApp(com.microsoft.azure.toolkit.lib.appservice.service.IWebApp)

Aggregations

AzureUIRefreshEvent (com.microsoft.azuretools.utils.AzureUIRefreshEvent)14 DockerHost (com.microsoft.azure.docker.model.DockerHost)4 Azure (com.microsoft.azure.management.Azure)4 VirtualMachine (com.microsoft.azure.management.compute.VirtualMachine)4 IWebApp (com.microsoft.azure.toolkit.lib.appservice.service.IWebApp)4 AzureOperation (com.microsoft.azure.toolkit.lib.common.operation.AzureOperation)4 PrivateRegistryImageSetting (com.microsoft.azuretools.core.mvp.model.webapp.PrivateRegistryImageSetting)4 DefaultDockerClient (com.spotify.docker.client.DefaultDockerClient)4 DockerClient (com.spotify.docker.client.DockerClient)4 FileNotFoundException (java.io.FileNotFoundException)4 Path (java.nio.file.Path)4 Date (java.util.Date)4 AzureDockerHostsManager (com.microsoft.azure.docker.AzureDockerHostsManager)3 MalformedURLException (java.net.MalformedURLException)3 AzureDockerPreferredSettings (com.microsoft.azure.docker.model.AzureDockerPreferredSettings)2 DockerProgressHandler (com.microsoft.azure.toolkit.intellij.webapp.docker.utils.DockerProgressHandler)2 IFunctionApp (com.microsoft.azure.toolkit.lib.appservice.service.IFunctionApp)2 FunctionAppConfig (com.microsoft.azure.toolkit.lib.function.FunctionAppConfig)2 InvalidFormDataException (com.microsoft.azuretools.azurecommons.exceptions.InvalidFormDataException)2 DockerProgressHandler (com.microsoft.azuretools.container.DockerProgressHandler)2