Skip to content

Commit dd13928

Browse files
authored
Merge pull request #81 from eharris369/41-NoAppMonitorActionIfNotSupported
Issue #41: Hide app monitor action when not supported
2 parents 5652422 + b4de428 commit dd13928

File tree

10 files changed

+69
-27
lines changed

10 files changed

+69
-27
lines changed

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ public class MicroclimateApplication {
4949
private ProjectCapabilities projectCapabilities;
5050
private String action;
5151
private List<ProjectLogInfo> logInfos;
52+
private boolean metricsAvailable = false;
5253

5354
// Must be updated whenever httpPort changes. Can be null
5455
private URL baseUrl;
@@ -137,6 +138,10 @@ public synchronized void setLogInfos(List<ProjectLogInfo> logInfos) {
137138
this.logInfos = logInfos;
138139
}
139140

141+
public synchronized void setMetricsAvailable(boolean value) {
142+
metricsAvailable = value;
143+
}
144+
140145
/**
141146
* Can return null if this project hasn't started yet (ie httpPort == -1)
142147
*/
@@ -208,6 +213,10 @@ public List<ProjectLogInfo> getLogInfos() {
208213
public boolean hasBuildLog() {
209214
return (!projectType.isType(ProjectType.TYPE_NODEJS));
210215
}
216+
217+
public synchronized boolean getMetricsAvailable() {
218+
return metricsAvailable;
219+
}
211220

212221
public synchronized void setHttpPort(int httpPort) {
213222
MCLogger.log("Set HTTP port for " + baseUrl + " to " + httpPort); //$NON-NLS-1$ //$NON-NLS-2$

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,5 +226,17 @@ public static void updateApp(MicroclimateApplication mcApp, JSONObject appJso) {
226226
MCLogger.logError("An error occurred while updating the log information for project: " + mcApp.name, e);
227227
}
228228

229+
// Check for metrics support
230+
boolean metricsAvailable = true;
231+
try {
232+
JSONObject obj = mcApp.mcConnection.requestProjectMetricsStatus(mcApp);
233+
if (obj != null && obj.has(MCConstants.KEY_METRICS_AVAILABLE)) {
234+
metricsAvailable = obj.getBoolean(MCConstants.KEY_METRICS_AVAILABLE);
235+
}
236+
} catch (Exception e) {
237+
MCLogger.logError("An error occurred checking if metrics are available: " + mcApp.name, e);
238+
}
239+
mcApp.setMetricsAvailable(metricsAvailable);
240+
229241
}
230242
}

dev/com.ibm.microclimate.core/src/com/ibm/microclimate/core/internal/connection/MicroclimateConnection.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,20 @@ else if (result.response == null) {
417417
MCLogger.log("Didn't find status info for project " + app.name); //$NON-NLS-1$
418418
return null;
419419
}
420+
421+
public JSONObject requestProjectMetricsStatus(MicroclimateApplication app) throws IOException, JSONException {
422+
if (!app.mcConnection.checkVersion(1905, "2019_M5_E")) {
423+
return null;
424+
}
425+
String endpoint = MCConstants.APIPATH_PROJECT_LIST + "/" //$NON-NLS-1$
426+
+ app.projectID + "/" //$NON-NLS-1$
427+
+ MCConstants.APIPATH_METRICS_STATUS;
428+
429+
URI uri = baseUrl.resolve(endpoint);
430+
HttpResult result = HttpUtil.get(uri);
431+
checkResult(result, uri, true);
432+
return new JSONObject(result.response);
433+
}
420434

421435
/**
422436
* Request a build on an application
@@ -439,6 +453,11 @@ public void requestProjectBuild(MicroclimateApplication app, String action)
439453
}
440454

441455
public List<ProjectLogInfo> requestProjectLogs(MicroclimateApplication app) throws JSONException, IOException {
456+
List<ProjectLogInfo> logList = new ArrayList<ProjectLogInfo>();
457+
if (!app.mcConnection.checkVersion(1905, "2019_M5_E")) {
458+
return logList;
459+
}
460+
442461
String endpoint = MCConstants.APIPATH_PROJECT_LIST + "/" //$NON-NLS-1$
443462
+ app.projectID + "/" //$NON-NLS-1$
444463
+ MCConstants.APIPATH_LOGS;
@@ -447,7 +466,6 @@ public List<ProjectLogInfo> requestProjectLogs(MicroclimateApplication app) thro
447466
HttpResult result = HttpUtil.get(uri);
448467
checkResult(result, uri, true);
449468

450-
List<ProjectLogInfo> logList = new ArrayList<ProjectLogInfo>();
451469
JSONObject logs = new JSONObject(result.response);
452470
JSONArray buildLogs = logs.getJSONArray(MCConstants.KEY_LOG_BUILD);
453471
logList.addAll(getLogs(buildLogs, MCConstants.KEY_LOG_BUILD));

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ private MCConstants() {}
3636
APIPATH_OPEN = "open",
3737
APIPATH_CAPABILITIES = "capabilities",
3838
APIPATH_LOGS = "logs",
39+
APIPATH_METRICS_STATUS = "metrics/status",
3940

4041
// JSON keys
4142
KEY_PROJECT_ID = "projectID",
@@ -106,6 +107,7 @@ private MCConstants() {}
106107
KEY_CAPABILIITES = "capabilities",
107108
KEY_START_MODES = "startModes",
108109
KEY_CONTROL_COMMANDS = "controlCommands",
110+
KEY_METRICS_AVAILABLE = "metricsAvailable",
109111

110112
KEY_AUTO_GENERATE = "autoGenerate",
111113

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ ACTION_IMPORT_PROJECT=&Import Project
2929
ACTION_RESTART_RUN_MODE=Restart in &Run Mode
3030
ACTION_RESTART_DEBUG_MODE=Restart in &Debug Mode
3131
ACTION_ENABLE_DISABLE_AUTO_BUILD=Disable &Auto Build
32-
ACTION_OPEN_APP_MONITOR=Open Application &Monitor
3332
ACTION_OPEN_APP_OVERVIEW=Open Project O&verview
3433

3534
PREFS_PARENT_PAGE_NAME=Microclimate

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

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -118,13 +118,6 @@
118118
<objectContribution
119119
id="com.ibm.microclimate.ui.appObjectActions"
120120
objectClass="com.ibm.microclimate.core.internal.MicroclimateApplication">
121-
<action
122-
id="com.ibm.microclimate.ui.openAppMonitor"
123-
enablesFor="1"
124-
menubarPath="group.open"
125-
icon="%OPEN_BROWSER_ICON_PATH"
126-
label="%ACTION_OPEN_APP_MONITOR"
127-
class="com.ibm.microclimate.ui.internal.actions.OpenAppMonitorAction"/>
128121
<action
129122
id="com.ibm.microclimate.ui.containerShell"
130123
enablesFor="1"

dev/com.ibm.microclimate.ui/src/com/ibm/microclimate/ui/internal/actions/MicroclimateApplicationActionProvider.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2018 IBM Corporation and others.
2+
* Copyright (c) 2018, 2019 IBM Corporation and others.
33
* All rights reserved. This program and the accompanying materials
44
* are made available under the terms of the Eclipse Public License v2.0
55
* which accompanies this distribution, and is available at
@@ -24,13 +24,15 @@ public class MicroclimateApplicationActionProvider extends CommonActionProvider
2424

2525
private ValidateAction validateAction;
2626
private AttachDebuggerAction attachDebuggerAction;
27+
private OpenAppMonitorAction openAppMonitorAction;
2728

2829
@Override
2930
public void init(ICommonActionExtensionSite aSite) {
3031
super.init(aSite);
3132
ISelectionProvider selProvider = aSite.getStructuredViewer();
3233
validateAction = new ValidateAction(selProvider);
3334
attachDebuggerAction = new AttachDebuggerAction(selProvider);
35+
openAppMonitorAction = new OpenAppMonitorAction(selProvider);
3436
}
3537

3638
@Override
@@ -41,6 +43,9 @@ public void fillContextMenu(IMenuManager menu) {
4143
if (attachDebuggerAction.showAction()) {
4244
menu.appendToGroup(ICommonMenuConstants.GROUP_GENERATE, attachDebuggerAction);
4345
}
46+
if (openAppMonitorAction.showAction()) {
47+
menu.appendToGroup(ICommonMenuConstants.GROUP_OPEN, openAppMonitorAction);
48+
}
4449
}
4550

4651
}

dev/com.ibm.microclimate.ui/src/com/ibm/microclimate/ui/internal/actions/OpenAppMonitorAction.java

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,13 @@
1515

1616
import org.eclipse.jface.action.IAction;
1717
import org.eclipse.jface.viewers.ISelection;
18+
import org.eclipse.jface.viewers.ISelectionProvider;
1819
import org.eclipse.jface.viewers.IStructuredSelection;
1920
import org.eclipse.osgi.util.NLS;
20-
import org.eclipse.ui.IObjectActionDelegate;
2121
import org.eclipse.ui.IWorkbenchPart;
2222
import org.eclipse.ui.PartInitException;
2323
import org.eclipse.ui.PlatformUI;
24+
import org.eclipse.ui.actions.SelectionProviderAction;
2425
import org.eclipse.ui.browser.IWebBrowser;
2526
import org.eclipse.ui.browser.IWorkbenchBrowserSupport;
2627

@@ -34,31 +35,31 @@
3435
/**
3536
* Action to open the application monitor in a browser.
3637
*/
37-
public class OpenAppMonitorAction implements IObjectActionDelegate {
38+
public class OpenAppMonitorAction extends SelectionProviderAction {
3839

3940
protected MicroclimateApplication app;
41+
42+
public OpenAppMonitorAction(ISelectionProvider selectionProvider) {
43+
super(selectionProvider, Messages.ActionOpenAppMonitor);
44+
selectionChanged(getStructuredSelection());
45+
}
4046

41-
@Override
42-
public void selectionChanged(IAction action, ISelection selection) {
43-
if (!(selection instanceof IStructuredSelection)) {
44-
action.setEnabled(false);
45-
return;
46-
}
4747

48-
IStructuredSelection sel = (IStructuredSelection) selection;
48+
@Override
49+
public void selectionChanged(IStructuredSelection sel) {
4950
if (sel.size() == 1) {
5051
Object obj = sel.getFirstElement();
5152
if (obj instanceof MicroclimateApplication) {
5253
app = (MicroclimateApplication)obj;
53-
action.setEnabled(app.isAvailable() && app.getAppState() == AppState.STARTED);
54+
setEnabled(app.isAvailable() && app.getAppState() == AppState.STARTED);
5455
return;
5556
}
5657
}
57-
action.setEnabled(false);
58+
setEnabled(false);
5859
}
5960

6061
@Override
61-
public void run(IAction action) {
62+
public void run() {
6263
if (app == null) {
6364
// should not be possible
6465
MCLogger.logError("OpenAppMonitorAction ran but no Microclimate application was selected");
@@ -92,9 +93,8 @@ public void run(IAction action) {
9293
MCLogger.logError("Error opening the app monitor in browser", e); //$NON-NLS-1$
9394
}
9495
}
95-
96-
@Override
97-
public void setActivePart(IAction arg0, IWorkbenchPart arg1) {
98-
// nothing
99-
}
96+
97+
public boolean showAction() {
98+
return app != null && app.getMetricsAvailable();
99+
}
100100
}

dev/com.ibm.microclimate.ui/src/com/ibm/microclimate/ui/internal/messages/Messages.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ public class Messages extends NLS {
7474

7575
public static String ActionNewConnection;
7676

77+
public static String ActionOpenAppMonitor;
78+
7779
public static String ValidateLabel;
7880
public static String AttachDebuggerLabel;
7981
public static String LaunchDebugSessionLabel;

dev/com.ibm.microclimate.ui/src/com/ibm/microclimate/ui/internal/messages/messages.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ ErrorOnShowLogFileDialogTitle=An error occurred while opening or closing the str
6767

6868
ActionNewConnection=&New Microclimate Connection
6969

70+
ActionOpenAppMonitor=Open Application &Monitor
71+
7072
ValidateLabel=Validate
7173
AttachDebuggerLabel=A&ttach Debugger
7274
LaunchDebugSessionLabel=&Launch Debug Session

0 commit comments

Comments
 (0)