Commit | Line | Data |
---|---|---|
eb1bab5b | 1 | /********************************************************************** |
533d0bc3 | 2 | * Copyright (c) 2012, 2015 Ericsson |
cfdb727a | 3 | * |
eb1bab5b BH |
4 | * All rights reserved. This program and the accompanying materials are |
5 | * made available under the terms of the Eclipse Public License v1.0 which | |
6 | * accompanies this distribution, and is available at | |
7 | * http://www.eclipse.org/legal/epl-v10.html | |
cfdb727a AM |
8 | * |
9 | * Contributors: | |
eb1bab5b | 10 | * Bernd Hufmann - Initial API and implementation |
ba3a9bd2 | 11 | * Bernd Hufmann - Updated for support of LTTng Tools 2.1 |
b732adaa | 12 | * Markus Schorn - Bug 448058: Use org.eclipse.remote in favor of RSE |
533d0bc3 | 13 | * Bernd Hufmann - Update to org.eclipse.remote API 2.0 |
eb1bab5b | 14 | **********************************************************************/ |
9bc60be7 | 15 | package org.eclipse.tracecompass.internal.lttng2.control.ui.views.model.impl; |
eb1bab5b | 16 | |
b732adaa | 17 | import static java.text.MessageFormat.format; |
d8a4fd60 | 18 | import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull; |
b732adaa | 19 | |
6503ae0f BH |
20 | import java.util.List; |
21 | ||
eb1bab5b BH |
22 | import org.eclipse.core.commands.ExecutionException; |
23 | import org.eclipse.core.runtime.IProgressMonitor; | |
24 | import org.eclipse.core.runtime.IStatus; | |
25 | import org.eclipse.core.runtime.Status; | |
b732adaa | 26 | import org.eclipse.core.runtime.jobs.IJobChangeEvent; |
eb1bab5b | 27 | import org.eclipse.core.runtime.jobs.Job; |
b732adaa | 28 | import org.eclipse.core.runtime.jobs.JobChangeAdapter; |
d8a4fd60 | 29 | import org.eclipse.jdt.annotation.NonNull; |
973e19d6 | 30 | import org.eclipse.jface.dialogs.ErrorDialog; |
b732adaa | 31 | import org.eclipse.remote.core.IRemoteConnection; |
b732adaa | 32 | import org.eclipse.remote.core.IRemoteConnectionChangeListener; |
533d0bc3 | 33 | import org.eclipse.remote.core.RemoteConnectionChangeEvent; |
eb1bab5b | 34 | import org.eclipse.swt.graphics.Image; |
973e19d6 | 35 | import org.eclipse.swt.widgets.Display; |
9bc60be7 AM |
36 | import org.eclipse.tracecompass.internal.lttng2.control.core.model.TargetNodeState; |
37 | import org.eclipse.tracecompass.internal.lttng2.control.ui.Activator; | |
38 | import org.eclipse.tracecompass.internal.lttng2.control.ui.views.messages.Messages; | |
39 | import org.eclipse.tracecompass.internal.lttng2.control.ui.views.model.ITraceControlComponent; | |
40 | import org.eclipse.tracecompass.internal.lttng2.control.ui.views.property.TargetNodePropertySource; | |
9bc60be7 AM |
41 | import org.eclipse.tracecompass.internal.lttng2.control.ui.views.service.ILttngControlService; |
42 | import org.eclipse.tracecompass.internal.lttng2.control.ui.views.service.LTTngControlServiceFactory; | |
ec619615 BH |
43 | import org.eclipse.tracecompass.tmf.remote.core.proxy.RemoteSystemProxy; |
44 | import org.eclipse.tracecompass.tmf.remote.core.shell.ICommandShell; | |
973e19d6 | 45 | import org.eclipse.ui.PlatformUI; |
eb1bab5b BH |
46 | import org.eclipse.ui.views.properties.IPropertySource; |
47 | ||
48 | /** | |
eb1bab5b BH |
49 | * <p> |
50 | * Implementation of the trace node component. | |
51 | * </p> | |
cfdb727a | 52 | * |
dbd4432d | 53 | * @author Bernd Hufmann |
eb1bab5b | 54 | */ |
b732adaa | 55 | public class TargetNodeComponent extends TraceControlComponent implements IRemoteConnectionChangeListener { |
eb1bab5b BH |
56 | |
57 | // ------------------------------------------------------------------------ | |
58 | // Constants | |
59 | // ------------------------------------------------------------------------ | |
11252342 | 60 | |
eb1bab5b BH |
61 | /** |
62 | * Path to icon file for this component (state connected). | |
63 | */ | |
64 | public static final String TARGET_NODE_CONNECTED_ICON_FILE = "icons/obj16/target_connected.gif"; //$NON-NLS-1$ | |
65 | /** | |
66 | * Path to icon file for this component (state disconnected). | |
67 | */ | |
68 | public static final String TARGET_NODE_DISCONNECTED_ICON_FILE = "icons/obj16/target_disconnected.gif"; //$NON-NLS-1$ | |
69 | ||
b732adaa MS |
70 | private static final ILttngControlService NULL_CONTROL_SERVICE = new NullControlService(); |
71 | ||
eb1bab5b BH |
72 | // ------------------------------------------------------------------------ |
73 | // Attributes | |
74 | // ------------------------------------------------------------------------ | |
11252342 | 75 | |
eb1bab5b BH |
76 | /** |
77 | * The node connection state. | |
78 | */ | |
79 | private TargetNodeState fState = TargetNodeState.DISCONNECTED; | |
80 | /** | |
81 | * The image to be displayed in state disconnected. | |
82 | */ | |
83 | private Image fDisconnectedImage = null; | |
eb1bab5b BH |
84 | /** |
85 | * The remote proxy implementation. | |
86 | */ | |
d8a4fd60 | 87 | private @NonNull RemoteSystemProxy fRemoteProxy; |
eb1bab5b BH |
88 | /** |
89 | * The control service for LTTng specific commands. | |
90 | */ | |
91 | private ILttngControlService fService = null; | |
92 | /** | |
93 | * The command shell for issuing commands. | |
94 | */ | |
95 | private ICommandShell fShell = null; | |
96 | ||
97 | // ------------------------------------------------------------------------ | |
98 | // Constructors | |
99 | // ------------------------------------------------------------------------ | |
11252342 | 100 | |
eb1bab5b | 101 | /** |
cfdb727a | 102 | * Constructor |
d8a4fd60 BH |
103 | * |
104 | * @param name | |
105 | * the name of the component | |
106 | * @param parent | |
107 | * the parent of the component | |
108 | * @param proxy | |
109 | * the remote proxy implementation | |
eb1bab5b | 110 | */ |
d8a4fd60 | 111 | public TargetNodeComponent(String name, ITraceControlComponent parent, @NonNull RemoteSystemProxy proxy) { |
eb1bab5b BH |
112 | super(name, parent); |
113 | setImage(TARGET_NODE_CONNECTED_ICON_FILE); | |
31a6a4e4 | 114 | fDisconnectedImage = Activator.getDefault().loadIcon(TARGET_NODE_DISCONNECTED_ICON_FILE); |
eb1bab5b | 115 | fRemoteProxy = proxy; |
b732adaa | 116 | fRemoteProxy.addConnectionChangeListener(this); |
d8a4fd60 | 117 | setToolTip(fRemoteProxy.getRemoteConnection().getName()); |
eb1bab5b BH |
118 | } |
119 | ||
120 | /** | |
cfdb727a | 121 | * Constructor (using default proxy) |
d8a4fd60 BH |
122 | * |
123 | * @param name | |
124 | * the name of the component | |
125 | * @param parent | |
126 | * the parent of the component | |
127 | * @param host | |
128 | * the host connection implementation | |
eb1bab5b | 129 | */ |
d8a4fd60 BH |
130 | public TargetNodeComponent(String name, ITraceControlComponent parent, @NonNull IRemoteConnection host) { |
131 | this(name, parent, new RemoteSystemProxy(host)); | |
eb1bab5b BH |
132 | } |
133 | ||
b732adaa MS |
134 | @Override |
135 | public void dispose() { | |
136 | fRemoteProxy.removeConnectionChangeListener(this); | |
137 | fRemoteProxy.dispose(); | |
138 | disposeControlService(); | |
139 | } | |
140 | ||
141 | private void disposeControlService() { | |
142 | fService = null; | |
143 | final ICommandShell shell = fShell; | |
144 | if (shell != null) { | |
13729cbc | 145 | shell.dispose(); |
b732adaa MS |
146 | fShell = null; |
147 | } | |
148 | } | |
149 | ||
eb1bab5b BH |
150 | // ------------------------------------------------------------------------ |
151 | // Accessors | |
152 | // ------------------------------------------------------------------------ | |
11252342 | 153 | |
eb1bab5b BH |
154 | @Override |
155 | public Image getImage() { | |
156 | if (fState == TargetNodeState.CONNECTED) { | |
157 | return super.getImage(); | |
158 | } | |
159 | return fDisconnectedImage; | |
160 | } | |
cfdb727a | 161 | |
eb1bab5b BH |
162 | @Override |
163 | public TargetNodeState getTargetNodeState() { | |
164 | return fState; | |
165 | } | |
cfdb727a | 166 | |
eb1bab5b BH |
167 | @Override |
168 | public void setTargetNodeState(TargetNodeState state) { | |
169 | fState = state; | |
4775bcbf | 170 | fireComponentChanged(TargetNodeComponent.this); |
eb1bab5b | 171 | } |
cfdb727a | 172 | |
eb1bab5b BH |
173 | @Override |
174 | public ILttngControlService getControlService() { | |
b732adaa | 175 | return fService == null ? NULL_CONTROL_SERVICE : fService; |
eb1bab5b BH |
176 | } |
177 | ||
eb1bab5b BH |
178 | @Override |
179 | public void setControlService(ILttngControlService service) { | |
cfdb727a | 180 | fService = service; |
eb1bab5b BH |
181 | } |
182 | ||
eb1bab5b BH |
183 | @Override |
184 | public Object getAdapter(Class adapter) { | |
185 | if (adapter == IPropertySource.class) { | |
186 | return new TargetNodePropertySource(this); | |
187 | } | |
188 | return null; | |
cfdb727a AM |
189 | } |
190 | ||
bbb3538a BH |
191 | /** |
192 | * @return remote system proxy implementation | |
193 | */ | |
d8a4fd60 | 194 | public @NonNull RemoteSystemProxy getRemoteSystemProxy() { |
bbb3538a BH |
195 | return fRemoteProxy; |
196 | } | |
197 | ||
6503ae0f BH |
198 | /** |
199 | * @return all available sessions. | |
200 | */ | |
201 | public TraceSessionComponent[] getSessions() { | |
202 | List<ITraceControlComponent> compenents = getChildren(TraceSessionGroup.class); | |
203 | if (compenents.size() > 0) { | |
cfdb727a | 204 | TraceSessionGroup group = (TraceSessionGroup)compenents.get(0); |
6503ae0f | 205 | List<ITraceControlComponent> sessions = group.getChildren(TraceSessionComponent.class); |
cfdb727a | 206 | return sessions.toArray(new TraceSessionComponent[sessions.size()]); |
6503ae0f BH |
207 | } |
208 | return new TraceSessionComponent[0]; | |
209 | } | |
cfdb727a | 210 | |
cfe737e4 BH |
211 | /** |
212 | * @return node version | |
213 | */ | |
214 | public String getNodeVersion() { | |
215 | // Control service is null during connection to node | |
b732adaa | 216 | if (getControlService() != NULL_CONTROL_SERVICE) { |
0df4af5f | 217 | return getControlService().getVersionString(); |
cfe737e4 BH |
218 | } |
219 | return ""; //$NON-NLS-1$ | |
220 | } | |
221 | ||
d4514365 BH |
222 | /** |
223 | * Returns if node supports filtering of events | |
224 | * @return <code>true</code> if node supports filtering else <code>false</code> | |
225 | */ | |
226 | public boolean isEventFilteringSupported() { | |
227 | return getControlService().isVersionSupported("2.1.0"); //$NON-NLS-1$ | |
228 | } | |
229 | ||
f3b33d40 BH |
230 | /** |
231 | * Returns if node supports networks streaming or not | |
232 | * @return <code>true</code> if node supports filtering else <code>false</code> | |
ba3a9bd2 | 233 | * |
f3b33d40 BH |
234 | */ |
235 | public boolean isNetworkStreamingSupported() { | |
236 | return getControlService().isVersionSupported("2.1.0"); //$NON-NLS-1$ | |
237 | } | |
238 | ||
e799e5f3 | 239 | /** |
83051fc3 BH |
240 | * Returns if node supports configuring buffer type or not |
241 | * @return <code>true</code> if node supports buffer type configuration else <code>false</code> | |
e799e5f3 | 242 | */ |
83051fc3 | 243 | public boolean isBufferTypeConfigSupported() { |
e799e5f3 SD |
244 | return getControlService().isVersionSupported("2.2.0"); //$NON-NLS-1$ |
245 | } | |
246 | ||
247 | /** | |
248 | * Returns if node supports trace file rotation or not | |
249 | * @return <code>true</code> if node supports trace file rotation else <code>false</code> | |
250 | */ | |
251 | public boolean isTraceFileRotationSupported() { | |
252 | return getControlService().isVersionSupported("2.2.0"); //$NON-NLS-1$ | |
253 | } | |
254 | ||
255 | /** | |
256 | * Returns if node supports periodical flush for metadata or not | |
257 | * @return <code>true</code> if node supports periodical flush for metadata else <code>false</code> | |
258 | */ | |
259 | public boolean isPeriodicalMetadataFlushSupported() { | |
260 | return getControlService().isVersionSupported("2.2.0"); //$NON-NLS-1$ | |
261 | } | |
589d0d33 BH |
262 | /** |
263 | * Returns if node supports snapshots or not | |
264 | * @return <code>true</code> if it supports snapshots else <code>false</code> | |
265 | * | |
266 | */ | |
267 | public boolean isSnapshotSupported() { | |
268 | return getControlService().isVersionSupported("2.3.0"); //$NON-NLS-1$ | |
269 | } | |
81d5dc3a MAL |
270 | /** |
271 | * Returns if node supports live or not | |
272 | * @return <code>true</code> if it supports live else <code>false</code> | |
273 | * | |
274 | */ | |
275 | public boolean isLiveSupported() { | |
276 | return getControlService().isVersionSupported("2.4.0"); //$NON-NLS-1$; | |
277 | } | |
bd9f92a8 BH |
278 | /** |
279 | * Returns if node supports adding contexts on event | |
280 | * @return <code>true</code> if it supports adding contexts on events else <code>false</code> | |
281 | * | |
282 | */ | |
283 | public boolean isContextOnEventSupported() { | |
284 | return !getControlService().isVersionSupported("2.2.0"); //$NON-NLS-1$ | |
285 | } | |
286 | ||
eb1bab5b BH |
287 | // ------------------------------------------------------------------------ |
288 | // Operations | |
289 | // ------------------------------------------------------------------------ | |
cfdb727a | 290 | |
b732adaa | 291 | @Override |
533d0bc3 | 292 | public void connectionChanged(RemoteConnectionChangeEvent e) { |
b732adaa MS |
293 | if (fState == TargetNodeState.CONNECTING) { |
294 | return; | |
295 | } | |
296 | ||
297 | switch (e.getType()) { | |
533d0bc3 BH |
298 | case RemoteConnectionChangeEvent.CONNECTION_CLOSED: |
299 | case RemoteConnectionChangeEvent.CONNECTION_ABORTED: | |
b732adaa MS |
300 | handleDisconnected(); |
301 | break; | |
533d0bc3 | 302 | case RemoteConnectionChangeEvent.CONNECTION_OPENED: |
b732adaa MS |
303 | handleConnected(); |
304 | break; | |
305 | default: | |
306 | break; | |
307 | } | |
eb1bab5b BH |
308 | } |
309 | ||
b732adaa MS |
310 | /** |
311 | * Method to connect this node component to the remote target node. | |
312 | */ | |
313 | public void connect() { | |
314 | if (fState == TargetNodeState.DISCONNECTED) { | |
315 | try { | |
316 | setTargetNodeState(TargetNodeState.CONNECTING); | |
317 | Job job = new Job(format(Messages.TraceControl_OpenConnectionTo, getName())) { | |
318 | @Override | |
319 | protected IStatus run(IProgressMonitor monitor) { | |
320 | try { | |
d8a4fd60 | 321 | fRemoteProxy.connect(checkNotNull(monitor)); |
b732adaa MS |
322 | return Status.OK_STATUS; |
323 | } catch (Exception e) { | |
324 | return new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.TraceControl_ConnectionFailure, e); | |
325 | } | |
326 | } | |
327 | }; | |
328 | job.addJobChangeListener(new JobChangeAdapter() { | |
329 | @Override | |
330 | public void done(IJobChangeEvent event) { | |
331 | IStatus status = event.getResult(); | |
332 | if (status.isOK()) { | |
333 | handleConnected(); | |
334 | } else { | |
335 | handleDisconnected(); | |
336 | if (status.getSeverity() != IStatus.CANCEL) { | |
337 | Activator.getDefault().getLog().log(status); | |
338 | } | |
339 | } | |
340 | } | |
341 | }); | |
342 | job.schedule(); | |
343 | } catch (Exception e) { | |
344 | setTargetNodeState(TargetNodeState.DISCONNECTED); | |
345 | Activator.getDefault().logError(Messages.TraceControl_ConnectionFailure + " (" + getName() + "). \n", e); //$NON-NLS-1$ //$NON-NLS-2$ | |
346 | } | |
347 | } | |
348 | } | |
349 | ||
350 | /** | |
351 | * Method to disconnect this node component to the remote target node. | |
352 | */ | |
eb1bab5b BH |
353 | public void disconnect() { |
354 | if (fState == TargetNodeState.CONNECTED) { | |
355 | try { | |
356 | setTargetNodeState(TargetNodeState.DISCONNECTING); | |
357 | fRemoteProxy.disconnect(); | |
358 | } catch (Exception e) { | |
9fa32496 | 359 | Activator.getDefault().logError(Messages.TraceControl_DisconnectionFailure + " (" + getName() + "). \n", e); //$NON-NLS-1$ //$NON-NLS-2$ |
eb1bab5b | 360 | } finally { |
cfdb727a | 361 | handleDisconnected(); |
eb1bab5b BH |
362 | } |
363 | } | |
364 | } | |
365 | ||
366 | /** | |
cfdb727a AM |
367 | * Retrieves the trace configuration from the target node and populates the |
368 | * information in the tree model. The execution is done in a own job. | |
eb1bab5b | 369 | */ |
d132bcc7 | 370 | public void getConfigurationFromNode() { |
eb1bab5b BH |
371 | Job job = new Job(Messages.TraceControl_RetrieveNodeConfigurationJob) { |
372 | @Override | |
373 | protected IStatus run(IProgressMonitor monitor) { | |
374 | ||
375 | try { | |
376 | // Get provider information from node | |
377 | TraceProviderGroup providerGroup = new TraceProviderGroup(Messages.TraceControl_ProviderDisplayName, TargetNodeComponent.this); | |
378 | addChild(providerGroup); | |
cfdb727a | 379 | |
eb1bab5b BH |
380 | // Get session information from node |
381 | TraceSessionGroup sessionGroup = new TraceSessionGroup(Messages.TraceControl_AllSessionsDisplayName, TargetNodeComponent.this); | |
382 | addChild(sessionGroup); | |
b732adaa MS |
383 | |
384 | providerGroup.getProviderFromNode(monitor); | |
eb1bab5b BH |
385 | sessionGroup.getSessionsFromNode(monitor); |
386 | } catch (ExecutionException e) { | |
387 | removeAllChildren(); | |
973e19d6 | 388 | return new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.TraceControl_RetrieveNodeConfigurationFailure, e); |
cfdb727a | 389 | } |
eb1bab5b BH |
390 | |
391 | return Status.OK_STATUS; | |
392 | } | |
393 | }; | |
394 | job.setUser(true); | |
395 | job.schedule(); | |
d132bcc7 | 396 | } |
eb1bab5b | 397 | |
8577ed1e BH |
398 | /** |
399 | * Refresh the node configuration | |
400 | */ | |
d132bcc7 BH |
401 | public void refresh() { |
402 | removeAllChildren(); | |
403 | getConfigurationFromNode(); | |
eb1bab5b | 404 | } |
cfdb727a | 405 | |
eb1bab5b BH |
406 | // ------------------------------------------------------------------------ |
407 | // Helper function | |
408 | // ------------------------------------------------------------------------ | |
11252342 | 409 | |
eb1bab5b BH |
410 | /** |
411 | * @return returns the control service for LTTng specific commands. | |
412 | * @throws ExecutionException | |
413 | */ | |
414 | private ILttngControlService createControlService() throws ExecutionException { | |
b732adaa MS |
415 | if (fService == null) { |
416 | try { | |
13729cbc BH |
417 | ICommandShell shell = fRemoteProxy.createCommandShell(); |
418 | fShell = shell; | |
419 | fService = LTTngControlServiceFactory.getLttngControlService(shell); | |
b732adaa MS |
420 | } catch (ExecutionException e) { |
421 | disposeControlService(); | |
422 | throw e; | |
423 | } | |
eb1bab5b | 424 | } |
eb1bab5b BH |
425 | return fService; |
426 | } | |
427 | ||
428 | /** | |
cfdb727a | 429 | * Handles the connected event. |
eb1bab5b BH |
430 | */ |
431 | private void handleConnected() { | |
eb1bab5b BH |
432 | try { |
433 | createControlService(); | |
434 | getConfigurationFromNode(); | |
b732adaa MS |
435 | // Set connected only after the control service has been created and the jobs for creating the |
436 | // sub-nodes are scheduled. | |
437 | setTargetNodeState(TargetNodeState.CONNECTED); | |
973e19d6 BH |
438 | } catch (final ExecutionException e) { |
439 | // Disconnect only if no control service, otherwise stay connected. | |
b732adaa MS |
440 | if (getControlService() == NULL_CONTROL_SERVICE) { |
441 | fState = TargetNodeState.CONNECTED; | |
973e19d6 BH |
442 | disconnect(); |
443 | } | |
444 | ||
445 | // Notify user | |
446 | Display.getDefault().asyncExec(new Runnable() { | |
447 | @Override | |
448 | public void run() { | |
449 | ErrorDialog er = new ErrorDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), | |
450 | Messages.TraceControl_ErrorTitle, Messages.TraceControl_RetrieveNodeConfigurationFailure, | |
451 | new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e), | |
452 | IStatus.ERROR); | |
453 | er.open(); | |
454 | } | |
455 | }); | |
456 | Activator.getDefault().logError(Messages.TraceControl_RetrieveNodeConfigurationFailure + " (" + getName() + "). \n", e); //$NON-NLS-1$ //$NON-NLS-2$ | |
eb1bab5b BH |
457 | } |
458 | } | |
459 | ||
460 | /** | |
cfdb727a | 461 | * Handles the disconnected event. |
eb1bab5b BH |
462 | */ |
463 | private void handleDisconnected() { | |
b732adaa | 464 | disposeControlService(); |
eb1bab5b | 465 | setTargetNodeState(TargetNodeState.DISCONNECTED); |
b732adaa MS |
466 | removeAllChildren(); |
467 | } | |
468 | ||
469 | @Override | |
470 | public void addChild(ITraceControlComponent component) { | |
471 | if (getTargetNodeState() == TargetNodeState.DISCONNECTED) { | |
472 | return; | |
473 | } | |
474 | super.addChild(component); | |
eb1bab5b BH |
475 | } |
476 | } |