github.com/ijc/docker-app@v0.6.1-0.20181012090447-c7ca8bc483fb/integrations/intellij/src/main/java/DeployApp.java (about)

     1  import com.intellij.notification.Notification;
     2  import com.intellij.notification.Notifications;
     3  import com.intellij.notification.NotificationType;
     4  import com.intellij.openapi.actionSystem.*;
     5  import com.intellij.openapi.diagnostic.FrequentEventDetector;
     6  import com.intellij.openapi.diagnostic.Logger;
     7  import com.intellij.openapi.project.Project;
     8  import com.intellij.openapi.ui.Messages;
     9  import com.intellij.ide.util.PropertiesComponent;
    10  import org.apache.log4j.Level;
    11  
    12  import java.io.BufferedReader;
    13  import java.io.File;
    14  import java.io.InputStreamReader;
    15  import java.util.Scanner;
    16  
    17  
    18  public class DeployApp extends AnAction {
    19      public DeployApp() {
    20          super("DeployApp");
    21      }
    22  
    23      public void actionPerformed(AnActionEvent event) {
    24          Project project = event.getProject();
    25          PropertiesComponent pc = PropertiesComponent.getInstance(project);
    26          String appPath = pc.getValue("docker_app_path");
    27          try {
    28              String orchestrator = "swarm";
    29              if (pc.getValue("docker_app_orchestrator").equals("kubernetes"))
    30                  orchestrator = "kubernetes";
    31              String rawSettings = pc.getValue("docker_app_overrides");
    32              String settings = "";
    33              if (!rawSettings.isEmpty()) {
    34                  String[] split = rawSettings.split("\n");
    35                  for (String l: split) {
    36                      settings += " -s " + l;
    37                  }
    38              }
    39              String kubeconfig = pc.getValue("docker_app_kubeconfig");
    40              if (!kubeconfig.isEmpty()) {
    41                  kubeconfig = " --kubeconfig " + kubeconfig;
    42              }
    43              String namespace = pc.getValue("docker_app_namespace");
    44              if (!namespace.isEmpty()) {
    45                  namespace = " --namespace " + namespace;
    46              }
    47              String name = pc.getValue("docker_app_name");
    48              if (!name.isEmpty()) {
    49                  name = " --name " + name;
    50              }
    51              String cmd = "docker-app deploy " + appPath
    52                      + " --orchestrator="+orchestrator
    53                      + kubeconfig
    54                      + namespace
    55                      + name
    56                      + settings;
    57              Process p = Runtime.getRuntime().exec(cmd,null, new File(project.getBasePath()));
    58              BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()));
    59              String line;
    60              while ((line = input.readLine()) != null) {
    61                  Notification n = new Notification("docker-app", "deploy", line, NotificationType.INFORMATION);
    62                  Notifications.Bus.notify(n);
    63              }
    64              BufferedReader error = new BufferedReader(new InputStreamReader(p.getErrorStream()));
    65              while ((line = error.readLine()) != null) {
    66                  Notification n = new Notification("docker-app", "deploy", line, NotificationType.ERROR);
    67                  Notifications.Bus.notify(n);
    68              }
    69          } catch (Exception e) {
    70              Messages.showMessageDialog(project, "docker-app invocation failed with " + e.toString(), "Render Failure", Messages.getInformationIcon());
    71              e.printStackTrace();
    72          }
    73  
    74      }
    75  }