-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #168 from nocalhost/dev
- Loading branch information
Showing
53 changed files
with
962 additions
and
224 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
src/main/java/dev/nocalhost/plugin/intellij/commands/data/NhctlCrdKind.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package dev.nocalhost.plugin.intellij.commands.data; | ||
|
||
import com.google.gson.annotations.SerializedName; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
public class NhctlCrdKind { | ||
@SerializedName("info") | ||
private Spec info; | ||
|
||
@Getter | ||
public class Spec { | ||
@SerializedName("Kind") | ||
private String kind; | ||
|
||
@SerializedName("Group") | ||
private String group; | ||
|
||
@SerializedName("Version") | ||
private String version; | ||
|
||
@SerializedName("Resource") | ||
private String resource; | ||
|
||
@SerializedName("Namespaced") | ||
private boolean namespaced; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
src/main/java/dev/nocalhost/plugin/intellij/commands/data/NhctlProxy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package dev.nocalhost.plugin.intellij.commands.data; | ||
|
||
import com.google.gson.annotations.SerializedName; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
public class NhctlProxy { | ||
@SerializedName("status") | ||
private String status; | ||
|
||
@SerializedName("belongsToMe") | ||
private boolean belongsToMe; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
src/main/java/dev/nocalhost/plugin/intellij/nhctl/NhctlCrdListCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package dev.nocalhost.plugin.intellij.nhctl; | ||
|
||
import com.intellij.openapi.project.Project; | ||
import com.google.common.collect.Lists; | ||
import java.util.List; | ||
|
||
public class NhctlCrdListCommand extends BaseCommand { | ||
public NhctlCrdListCommand(Project project) { | ||
super(project, false); | ||
} | ||
|
||
@Override | ||
protected List<String> compute() { | ||
List<String> args = Lists.newArrayList(getBinaryPath(), "get", "crd-list"); | ||
args.add("--outputType"); | ||
args.add("json"); | ||
return fulfill(args); | ||
} | ||
} |
72 changes: 72 additions & 0 deletions
72
src/main/java/dev/nocalhost/plugin/intellij/nhctl/NhctlProxyCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package dev.nocalhost.plugin.intellij.nhctl; | ||
|
||
import org.apache.commons.lang3.StringUtils; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import com.intellij.openapi.application.ApplicationManager; | ||
import com.intellij.openapi.project.Project; | ||
import com.intellij.openapi.util.SystemInfo; | ||
|
||
import com.google.common.base.Charsets; | ||
import com.google.common.collect.Lists; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.util.List; | ||
|
||
import dev.nocalhost.plugin.intellij.ui.dialog.SudoPasswordDialog; | ||
import dev.nocalhost.plugin.intellij.utils.NhctlUtil; | ||
import dev.nocalhost.plugin.intellij.utils.SudoUtil; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
@Getter | ||
@Setter | ||
public class NhctlProxyCommand extends BaseCommand { | ||
private String action; | ||
private String workload; | ||
|
||
public NhctlProxyCommand(Project project) { | ||
super(project); | ||
} | ||
|
||
@Override | ||
protected List<String> compute() { | ||
List<String> args = Lists.newArrayList(getBinaryPath(), "vpn", action); | ||
if (StringUtils.isNotEmpty(workload)) { | ||
args.add("--workloads"); | ||
args.add(workload); | ||
} | ||
return fulfill(args); | ||
} | ||
|
||
@Override | ||
protected void onError(@NotNull Process process) { | ||
int b; | ||
var output = new StringBuilder(); | ||
var reader = new InputStreamReader(process.getErrorStream(), Charsets.UTF_8); | ||
try (var br = new BufferedReader(reader)) { | ||
while ((b = br.read()) != -1) { | ||
output.append((char) b); | ||
stderr.set(output.toString()); | ||
if (SystemInfo.isWindows) { | ||
continue; | ||
} | ||
if (StringUtils.contains(output.toString(), "Password:")) { | ||
output.setLength(0); | ||
ApplicationManager.getApplication().invokeLater(() -> { | ||
var dialog = new SudoPasswordDialog(project, NhctlUtil.binaryPath()); | ||
if (dialog.showAndGet()) { | ||
SudoUtil.inputPassword(process, dialog.getPassword()); | ||
} else { | ||
process.destroy(); | ||
} | ||
}); | ||
} | ||
} | ||
} catch (IOException ex) { | ||
// ignore | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,15 +2,16 @@ | |
|
||
import com.google.common.collect.Lists; | ||
|
||
import com.intellij.ide.BrowserUtil; | ||
import com.intellij.openapi.application.ApplicationManager; | ||
import com.intellij.openapi.progress.ProgressIndicator; | ||
import com.intellij.openapi.progress.ProgressManager; | ||
import com.intellij.openapi.project.Project; | ||
|
||
import org.apache.commons.lang3.StringUtils; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import java.nio.file.Paths; | ||
import java.util.List; | ||
|
||
import dev.nocalhost.plugin.intellij.api.data.Application; | ||
|
@@ -19,28 +20,24 @@ | |
import dev.nocalhost.plugin.intellij.exception.NocalhostNotifier; | ||
import dev.nocalhost.plugin.intellij.topic.NocalhostTreeUpdateNotifier; | ||
import dev.nocalhost.plugin.intellij.utils.ErrorUtil; | ||
import dev.nocalhost.plugin.intellij.utils.Constants; | ||
import lombok.SneakyThrows; | ||
|
||
public class InstallApplicationTask extends BaseBackgroundTask { | ||
private static final List<String> BOOKINFO_URLS = Lists.newArrayList( | ||
private static final List<String> BOOKINFO_GITS = Lists.newArrayList( | ||
"https://github.com/nocalhost/bookinfo.git", | ||
"[email protected]:nocalhost/bookinfo.git", | ||
"https://e.coding.net/nocalhost/nocalhost/bookinfo.git", | ||
"[email protected]:nocalhost/nocalhost/bookinfo.git" | ||
); | ||
|
||
private static final List<String> BOOKINFO_APP_NAME = Lists.newArrayList( | ||
"bookinfo" | ||
); | ||
|
||
private final Project project; | ||
|
||
private final Application application; | ||
private final NhctlInstallOptions opts; | ||
|
||
private final OutputCapturedNhctlCommand outputCapturedNhctlCommand; | ||
|
||
private String productPagePort; | ||
|
||
public InstallApplicationTask(@Nullable Project project, Application application, NhctlInstallOptions opts) { | ||
super(project, "Deploying application: " + application.getContext().getApplicationName(), true); | ||
this.project = project; | ||
|
@@ -53,20 +50,15 @@ public InstallApplicationTask(@Nullable Project project, Application application | |
@Override | ||
public void onSuccess() { | ||
super.onSuccess(); | ||
bookinfo(); | ||
ApplicationManager.getApplication().getMessageBus().syncPublisher( | ||
NocalhostTreeUpdateNotifier.NOCALHOST_TREE_UPDATE_NOTIFIER_TOPIC).action(); | ||
|
||
NocalhostNotifier.getInstance(project).notifySuccess( | ||
"Application " + application.getContext().getApplicationName() + " Deployed", | ||
""); | ||
} | ||
|
||
private void bookinfo() { | ||
if (BOOKINFO_APP_NAME.contains(application.getContext().getApplicationName()) | ||
&& BOOKINFO_URLS.contains(application.getContext().getApplicationUrl()) | ||
&& StringUtils.isNotBlank(productPagePort)) { | ||
BrowserUtil.browse("http://127.0.0.1:" + productPagePort + "/productpage"); | ||
if (StringUtils.equals(Constants.DEMO_NAME, application.getContext().getApplicationName()) && BOOKINFO_GITS.contains(application.getContext().getApplicationUrl())) { | ||
ProgressManager.getInstance().run(new BrowseDemoTask(project, Paths.get(opts.getKubeconfig()), opts.getNamespace())); | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.