Skip to content

Commit 2314cbb

Browse files
committed
Issue #165: Support opening shell into application container
1 parent 1fc8e32 commit 2314cbb

File tree

9 files changed

+113
-7
lines changed

9 files changed

+113
-7
lines changed

dev/com.ibm.microclimate.core/src/com/ibm/microclimate/core/internal/MCEclipseApplication.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,9 @@ public class MCEclipseApplication extends MicroclimateApplication {
6464
private ILaunch launch = null;
6565

6666
MCEclipseApplication(MicroclimateConnection mcConnection,
67-
String id, String name, ProjectType projectType, String pathInWorkspace, String contextRoot)
67+
String id, String name, ProjectType projectType, String pathInWorkspace, String containerId, String contextRoot)
6868
throws MalformedURLException {
69-
super(mcConnection, id, name, projectType, pathInWorkspace, contextRoot);
69+
super(mcConnection, id, name, projectType, pathInWorkspace, containerId, contextRoot);
7070
}
7171

7272
public synchronized boolean hasAppConsole() {

dev/com.ibm.microclimate.core/src/com/ibm/microclimate/core/internal/MicroclimateApplication.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public class MicroclimateApplication {
3030
public final String contextRoot; // can be null
3131
public final IPath fullLocalPath;
3232
public final ProjectType projectType;
33+
public final String containerId;
3334

3435
private StartMode startMode;
3536
private AppState appState;
@@ -46,13 +47,14 @@ public class MicroclimateApplication {
4647
private int httpPort = -1, debugPort = -1;
4748

4849
MicroclimateApplication(MicroclimateConnection mcConnection,
49-
String id, String name, ProjectType projectType, String pathInWorkspace, String contextRoot)
50+
String id, String name, ProjectType projectType, String pathInWorkspace, String containerId, String contextRoot)
5051
throws MalformedURLException {
5152

5253
this.mcConnection = mcConnection;
5354
this.projectID = id;
5455
this.name = name;
5556
this.projectType = projectType;
57+
this.containerId = containerId;
5658
this.contextRoot = contextRoot;
5759
this.host = mcConnection.baseUrl.getHost();
5860

dev/com.ibm.microclimate.core/src/com/ibm/microclimate/core/internal/MicroclimateApplicationFactory.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,15 @@ public static MicroclimateApplication createApp(MicroclimateConnection mcConnect
8989
}
9090

9191
String loc = appJso.getString(MCConstants.KEY_LOC_DISK);
92+
93+
String containerId = appJso.getString(MCConstants.KEY_CONTAINER_ID);
9294

9395
String contextRoot = null;
9496
if(appJso.has(MCConstants.KEY_CONTEXTROOT)) {
9597
contextRoot = appJso.getString(MCConstants.KEY_CONTEXTROOT);
9698
}
9799

98-
MicroclimateApplication mcApp = MicroclimateObjectFactory.createMicroclimateApplication(mcConnection, id, name, type, loc, contextRoot);
100+
MicroclimateApplication mcApp = MicroclimateObjectFactory.createMicroclimateApplication(mcConnection, id, name, type, loc, containerId, contextRoot);
99101

100102
updateApp(mcApp, appJso);
101103
return mcApp;

dev/com.ibm.microclimate.core/src/com/ibm/microclimate/core/internal/MicroclimateObjectFactory.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ public static MicroclimateConnection createMicroclimateConnection(URI uri) throw
2121
}
2222

2323
public static MicroclimateApplication createMicroclimateApplication(MicroclimateConnection mcConnection,
24-
String id, String name, ProjectType projectType, String pathInWorkspace, String contextRoot) throws Exception {
25-
return new MCEclipseApplication(mcConnection, id, name, projectType, pathInWorkspace, contextRoot);
24+
String id, String name, ProjectType projectType, String pathInWorkspace, String containerId, String contextRoot) throws Exception {
25+
return new MCEclipseApplication(mcConnection, id, name, projectType, pathInWorkspace, containerId, contextRoot);
2626
}
2727

2828
}

dev/com.ibm.microclimate.core/src/com/ibm/microclimate/core/internal/constants/MCConstants.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ private MCConstants() {}
3939
KEY_BUILD_TYPE = "buildType",
4040
KEY_LOC_DISK = "locOnDisk",
4141
KEY_CONTEXTROOT = "contextroot",
42+
KEY_CONTAINER_ID = "containerId",
4243

4344
KEY_BUILD_LOG = "build-log",
4445
KEY_BUILD_LOG_LAST_MODIFIED = "build-log-last-modified",

dev/com.ibm.microclimate.ui/META-INF/MANIFEST.MF

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ Require-Bundle: org.eclipse.ui,
1818
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
1919
Automatic-Module-Name: com.ibm.microclimate.ui;singleton:=true
2020
Bundle-ActivationPolicy: lazy
21-
Import-Package: org.eclipse.ui.console,
21+
Import-Package: org.eclipse.tm.terminal.view.core.interfaces.constants,
22+
org.eclipse.tm.terminal.view.ui.interfaces,
23+
org.eclipse.tm.terminal.view.ui.launcher,
24+
org.eclipse.ui.console,
2225
org.eclipse.ui.navigator,
2326
org.eclipse.ui.internal.wizards.datatransfer

dev/com.ibm.microclimate.ui/plugin.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Bundle-Name = Microclimate UI Plugin
1616
ACTION_REMOVE_CONNECTION=&Remove Connection
1717

1818
ACTION_OPEN_APP=&Open Application
19+
ACTION_CONTAINER_SHELL=Open &container shell
1920
ACTION_START_BUILD=Start &Build
2021
ACTION_IMPORT_PROJECT=&Import Project
2122
ACTION_SHOW_APP_CONSOLE=&Show App Console

dev/com.ibm.microclimate.ui/plugin.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,12 @@
114114
icon="%IMPORT_ICON_PATH"
115115
label="%ACTION_IMPORT_PROJECT"
116116
class="com.ibm.microclimate.ui.internal.actions.ImportProjectAction"/>
117+
<action
118+
id="com.ibm.microclimate.ui.containerShell"
119+
enablesFor="1"
120+
menubarPath="group.open"
121+
label="%ACTION_CONTAINER_SHELL"
122+
class="com.ibm.microclimate.ui.internal.actions.ContainerShellAction"/>
117123
<action
118124
id="com.ibm.microclimate.ui.openApplication"
119125
enablesFor="1"
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
/*******************************************************************************
2+
* IBM Confidential
3+
* OCO Source Materials
4+
* (C) Copyright IBM Corp. 2018 All Rights Reserved.
5+
* The source code for this program is not published or otherwise
6+
* divested of its trade secrets, irrespective of what has
7+
* been deposited with the U.S. Copyright Office.
8+
*******************************************************************************/
9+
10+
package com.ibm.microclimate.ui.internal.actions;
11+
12+
import java.util.HashMap;
13+
import java.util.Map;
14+
15+
import org.eclipse.jface.action.IAction;
16+
import org.eclipse.jface.viewers.ISelection;
17+
import org.eclipse.jface.viewers.IStructuredSelection;
18+
import org.eclipse.tm.terminal.view.core.interfaces.constants.ITerminalsConnectorConstants;
19+
import org.eclipse.tm.terminal.view.ui.interfaces.ILauncherDelegate;
20+
import org.eclipse.tm.terminal.view.ui.launcher.LauncherDelegateManager;
21+
import org.eclipse.ui.IObjectActionDelegate;
22+
import org.eclipse.ui.IWorkbenchPart;
23+
24+
import com.ibm.microclimate.core.internal.MCLogger;
25+
import com.ibm.microclimate.core.internal.MicroclimateApplication;
26+
27+
public class ContainerShellAction implements IObjectActionDelegate {
28+
29+
private static final String LAUNCHER_DELEGATE_ID = "org.eclipse.tm.terminal.connector.local.launcher.local"; //$NON-NLS-1$
30+
31+
protected MicroclimateApplication app;
32+
protected ILauncherDelegate delegate;
33+
34+
public ContainerShellAction() {
35+
delegate = LauncherDelegateManager.getInstance().getLauncherDelegate(LAUNCHER_DELEGATE_ID, false);
36+
if (delegate == null) {
37+
MCLogger.logError("Could not get the local terminal launcher delegate.");
38+
}
39+
}
40+
41+
@Override
42+
public void selectionChanged(IAction action, ISelection selection) {
43+
if (delegate == null || !(selection instanceof IStructuredSelection)) {
44+
action.setEnabled(false);
45+
return;
46+
}
47+
48+
IStructuredSelection sel = (IStructuredSelection) selection;
49+
if (sel.size() == 1) {
50+
Object obj = sel.getFirstElement();
51+
if (obj instanceof MicroclimateApplication) {
52+
app = (MicroclimateApplication)obj;
53+
action.setEnabled(app.isEnabled());
54+
return;
55+
}
56+
}
57+
action.setEnabled(false);
58+
}
59+
60+
@Override
61+
public void run(IAction action) {
62+
if (app == null) {
63+
// should not be possible
64+
MCLogger.logError("ContainerShellAction ran but no Microclimate application was selected"); //$NON-NLS-1$
65+
return;
66+
}
67+
68+
if (app.containerId == null || app.containerId.isEmpty()) {
69+
MCLogger.logError("ContainerShellAction ran but the container id for the application is not set: " + app.name); //$NON-NLS-1$
70+
return;
71+
}
72+
73+
if (delegate == null) {
74+
// should not be possible
75+
MCLogger.logError("ContainerShellAction ran but the local terminal laucher delegate is null"); //$NON-NLS-1$
76+
return;
77+
}
78+
79+
Map<String, Object> properties = new HashMap<>();
80+
properties.put(ITerminalsConnectorConstants.PROP_DELEGATE_ID, delegate.getId());
81+
properties.put(ITerminalsConnectorConstants.PROP_TITLE, app.name);
82+
properties.put(ITerminalsConnectorConstants.PROP_PROCESS_PATH, "docker");
83+
properties.put(ITerminalsConnectorConstants.PROP_PROCESS_ARGS, "exec -it " + app.containerId + " bash");
84+
delegate.execute(properties, null);
85+
}
86+
87+
@Override
88+
public void setActivePart(IAction arg0, IWorkbenchPart arg1) {
89+
// nothing
90+
}
91+
}

0 commit comments

Comments
 (0)