Search in sources :

Example 56 with AzureOperation

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

the class WebAppService method convertConfig2Settings.

@AzureOperation(name = "webapp.init_config", type = AzureOperation.Type.TASK)
public static WebAppSettingModel convertConfig2Settings(final WebAppConfig config) {
    final WebAppSettingModel settings = new WebAppSettingModel();
    settings.setSubscriptionId(config.getSubscription().getId());
    // creating if id is empty
    settings.setCreatingResGrp(config.getResourceGroup() instanceof Draft || StringUtils.isEmpty(config.getResourceGroup().getId()));
    settings.setResourceGroup(config.getResourceGroup().getName());
    settings.setWebAppName(config.getName());
    settings.setRegion(config.getRegion().getName());
    settings.saveRuntime(config.getRuntime());
    // creating if id is empty
    settings.setCreatingAppServicePlan(config.getServicePlan() instanceof Draft || StringUtils.isEmpty(config.getServicePlan().getId()));
    if (settings.isCreatingAppServicePlan()) {
        settings.setAppServicePlanName(config.getServicePlan().getName());
    } else {
        settings.setAppServicePlanId(config.getServicePlan().getId());
    }
    settings.setPricing(config.getServicePlan().getPricingTier().getSize());
    final MonitorConfig monitorConfig = config.getMonitorConfig();
    if (monitorConfig != null) {
        final DiagnosticConfig diagnosticConfig = monitorConfig.getDiagnosticConfig();
        settings.setEnableApplicationLog(diagnosticConfig.isEnableApplicationLog());
        settings.setApplicationLogLevel(diagnosticConfig.getApplicationLogLevel() == null ? null : diagnosticConfig.getApplicationLogLevel().getValue());
        settings.setEnableWebServerLogging(diagnosticConfig.isEnableWebServerLogging());
        settings.setWebServerLogQuota(diagnosticConfig.getWebServerLogQuota());
        settings.setWebServerRetentionPeriod(diagnosticConfig.getWebServerRetentionPeriod());
        settings.setEnableDetailedErrorMessage(diagnosticConfig.isEnableDetailedErrorMessage());
        settings.setEnableFailedRequestTracing(diagnosticConfig.isEnableFailedRequestTracing());
    }
    settings.setTargetName(config.getApplication() == null ? null : config.getApplication().toFile().getName());
    settings.setTargetPath(config.getApplication() == null ? null : config.getApplication().toString());
    return settings;
}
Also used : Draft(com.microsoft.azure.toolkit.intellij.common.Draft) WebAppSettingModel(com.microsoft.azuretools.core.mvp.model.webapp.WebAppSettingModel) DiagnosticConfig(com.microsoft.azure.toolkit.lib.appservice.model.DiagnosticConfig) MonitorConfig(com.microsoft.azure.toolkit.lib.appservice.MonitorConfig) AzureOperation(com.microsoft.azure.toolkit.lib.common.operation.AzureOperation)

Example 57 with AzureOperation

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

the class AddDockerSupportAction method onActionPerformed.

@Override
@AzureOperation(name = "docker.add_docker_support.configuration", type = AzureOperation.Type.ACTION)
public boolean onActionPerformed(@NotNull AnActionEvent anActionEvent, @Nullable Operation operation) {
    module = DataKeys.MODULE.getData(anActionEvent.getDataContext());
    if (module == null) {
        notifyError(Constant.ERROR_NO_SELECTED_PROJECT);
        return true;
    }
    pomXmlBasePath = Paths.get(module.getModuleFilePath()).getParent().toString();
    String artifactRelativePath = Constant.DOCKERFILE_ARTIFACT_PLACEHOLDER;
    String dockerFileContent = Constant.DOCKERFILE_CONTENT_TOMCAT;
    List<MavenProject> mavenProjects = MavenProjectsManager.getInstance(module.getProject()).getProjects();
    Optional<MavenProject> res = mavenProjects.stream().filter(mvnprj -> Comparing.equal(Paths.get(mvnprj.getDirectory()).normalize(), Paths.get(pomXmlBasePath).normalize())).findFirst();
    if (res.isPresent()) {
        MavenProject mvnPrj = res.get();
        String artifactName = mvnPrj.getFinalName() + "." + mvnPrj.getPackaging();
        artifactRelativePath = Paths.get(pomXmlBasePath).toUri().relativize(Paths.get(mvnPrj.getBuildDirectory(), artifactName).toUri()).getPath();
        // pre-define dockerfile content according to artifact type
        if (MavenConstants.TYPE_WAR.equals(mvnPrj.getPackaging())) {
            // maven war: tomcat
            dockerFileContent = Constant.DOCKERFILE_CONTENT_TOMCAT;
        } else if (MavenConstants.TYPE_JAR.equals(mvnPrj.getPackaging())) {
            // maven jar: spring boot
            dockerFileContent = Constant.DOCKERFILE_CONTENT_SPRING;
        }
    }
    final Path path = Paths.get(pomXmlBasePath, Constant.DOCKERFILE_FOLDER, Constant.DOCKERFILE_NAME);
    try {
        // create docker file
        DockerUtil.createDockerFile(pomXmlBasePath, Constant.DOCKERFILE_FOLDER, Constant.DOCKERFILE_NAME, String.format(dockerFileContent, artifactRelativePath));
        VirtualFileManager.getInstance().asyncRefresh(() -> {
            VirtualFile virtualDockerFile = LocalFileSystem.getInstance().findFileByPath(path.toString());
            if (virtualDockerFile != null) {
                new OpenFileDescriptor(module.getProject(), virtualDockerFile).navigate(true);
            }
        });
    } catch (IOException e) {
        EventUtil.logError(operation, ErrorType.userError, e, null, null);
        e.printStackTrace();
        notifyError(e.getMessage());
        return true;
    }
    // detect docker daemon
    String defaultDockerHost = null;
    try {
        defaultDockerHost = DefaultDockerClient.fromEnv().uri().toString();
    } catch (DockerCertificateException e) {
        EventUtil.logError(operation, ErrorType.userError, e, null, null);
        e.printStackTrace();
    // leave defaultDockerHost null
    }
    // print instructions
    String notificationContent = "";
    notificationContent += String.format(Constant.MESSAGE_DOCKERFILE_CREATED, path.normalize()) + "\n";
    notificationContent += String.format(Constant.MESSAGE_DOCKER_HOST_INFO, defaultDockerHost) + "\n";
    notificationContent += Constant.MESSAGE_ADD_DOCKER_SUPPORT_OK + "\n";
    notificationContent += Constant.MESSAGE_INSTRUCTION + "\n";
    notifyInfo(notificationContent);
    return true;
}
Also used : AzureOperation(com.microsoft.azure.toolkit.lib.common.operation.AzureOperation) DockerCertificateException(com.spotify.docker.client.exceptions.DockerCertificateException) DataKeys(com.intellij.openapi.actionSystem.DataKeys) VirtualFile(com.intellij.openapi.vfs.VirtualFile) Constant(com.microsoft.azure.toolkit.intellij.webapp.docker.utils.Constant) VirtualFileManager(com.intellij.openapi.vfs.VirtualFileManager) Comparing(com.intellij.openapi.util.Comparing) DefaultDockerClient(com.spotify.docker.client.DefaultDockerClient) AzureAnAction(com.microsoft.intellij.AzureAnAction) MavenConstants(org.jetbrains.idea.maven.model.MavenConstants) Module(com.intellij.openapi.module.Module) Path(java.nio.file.Path) Notifications(com.intellij.notification.Notifications) OpenFileDescriptor(com.intellij.openapi.fileEditor.OpenFileDescriptor) MavenProject(org.jetbrains.idea.maven.project.MavenProject) ErrorType(com.microsoft.azuretools.telemetrywrapper.ErrorType) Operation(com.microsoft.azuretools.telemetrywrapper.Operation) IOException(java.io.IOException) LocalFileSystem(com.intellij.openapi.vfs.LocalFileSystem) NotificationType(com.intellij.notification.NotificationType) MavenProjectsManager(org.jetbrains.idea.maven.project.MavenProjectsManager) Notification(com.intellij.notification.Notification) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) TelemetryConstants(com.microsoft.azuretools.telemetry.TelemetryConstants) Paths(java.nio.file.Paths) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) Optional(java.util.Optional) EventUtil(com.microsoft.azuretools.telemetrywrapper.EventUtil) NotNull(org.jetbrains.annotations.NotNull) DockerUtil(com.microsoft.azure.toolkit.intellij.webapp.docker.utils.DockerUtil) Path(java.nio.file.Path) VirtualFile(com.intellij.openapi.vfs.VirtualFile) MavenProject(org.jetbrains.idea.maven.project.MavenProject) OpenFileDescriptor(com.intellij.openapi.fileEditor.OpenFileDescriptor) IOException(java.io.IOException) DockerCertificateException(com.spotify.docker.client.exceptions.DockerCertificateException) AzureOperation(com.microsoft.azure.toolkit.lib.common.operation.AzureOperation)

Example 58 with AzureOperation

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

the class CreateWebAppAction method createWebApp.

@AzureOperation(name = "webapp.create_detail", params = { "config.getName()" }, type = AzureOperation.Type.ACTION)
private Single<IWebApp> createWebApp(final WebAppConfig config) {
    final AzureString title = title("webapp.create_detail", config.getName());
    final AzureTask<IWebApp> task = new AzureTask<>(null, title, false, () -> {
        final ProgressIndicator indicator = ProgressManager.getInstance().getProgressIndicator();
        indicator.setIndeterminate(true);
        return webappService.createWebApp(config);
    });
    return AzureTaskManager.getInstance().runInModalAsObservable(task).toSingle().doOnSuccess(app -> {
        this.notifyCreationSuccess(app);
        this.refreshAzureExplorer(app);
    });
}
Also used : ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) AzureTask(com.microsoft.azure.toolkit.lib.common.task.AzureTask) AzureString(com.microsoft.azure.toolkit.lib.common.bundle.AzureString) IWebApp(com.microsoft.azure.toolkit.lib.appservice.service.IWebApp) AzureOperation(com.microsoft.azure.toolkit.lib.common.operation.AzureOperation)

Example 59 with AzureOperation

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

the class CreateWebAppAction method actionPerformed.

@Override
@AzureOperation(name = "webapp.create", type = AzureOperation.Type.ACTION)
public void actionPerformed(NodeActionEvent e) {
    final Project project = (Project) webappModule.getProject();
    AzureSignInAction.requireSignedIn(project, () -> this.openDialog(project, null));
}
Also used : Project(com.intellij.openapi.project.Project) AzureOperation(com.microsoft.azure.toolkit.lib.common.operation.AzureOperation)

Example 60 with AzureOperation

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

the class PushImageAction method onActionPerformed.

@Override
@AzureOperation(name = "docker|image.push.configuration", type = AzureOperation.Type.ACTION)
public boolean onActionPerformed(@NotNull AnActionEvent event, @Nullable Operation operation) {
    Module module = DataKeys.MODULE.getData(event.getDataContext());
    if (module == null) {
        notifyError(Constant.ERROR_NO_SELECTED_PROJECT);
        return true;
    }
    AzureTaskManager.getInstance().runLater(() -> runConfiguration(module));
    return true;
}
Also used : Module(com.intellij.openapi.module.Module) 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