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; |
33d432d5 | 116 | fRemoteProxy.getRemoteConnection().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() { | |
33d432d5 | 136 | fRemoteProxy.getRemoteConnection().removeConnectionChangeListener(this); |
b732adaa MS |
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 | ||
6f40b641 BH |
287 | /** |
288 | * Checks if given version is supported by this ILTTngControlService implementation. | |
289 | * | |
290 | * @param version The version to check | |
291 | * @return <code>true</code> if version is supported else <code>false</code> | |
292 | */ | |
293 | public boolean isVersionSupported(String version) { | |
294 | return getControlService().isVersionSupported(version); | |
295 | } | |
296 | ||
eb1bab5b BH |
297 | // ------------------------------------------------------------------------ |
298 | // Operations | |
299 | // ------------------------------------------------------------------------ | |
cfdb727a | 300 | |
b732adaa | 301 | @Override |
533d0bc3 | 302 | public void connectionChanged(RemoteConnectionChangeEvent e) { |
b732adaa MS |
303 | if (fState == TargetNodeState.CONNECTING) { |
304 | return; | |
305 | } | |
306 | ||
307 | switch (e.getType()) { | |
533d0bc3 BH |
308 | case RemoteConnectionChangeEvent.CONNECTION_CLOSED: |
309 | case RemoteConnectionChangeEvent.CONNECTION_ABORTED: | |
b732adaa MS |
310 | handleDisconnected(); |
311 | break; | |
533d0bc3 | 312 | case RemoteConnectionChangeEvent.CONNECTION_OPENED: |
b732adaa MS |
313 | handleConnected(); |
314 | break; | |
315 | default: | |
316 | break; | |
317 | } | |
eb1bab5b BH |
318 | } |
319 | ||
b732adaa MS |
320 | /** |
321 | * Method to connect this node component to the remote target node. | |
322 | */ | |
323 | public void connect() { | |
324 | if (fState == TargetNodeState.DISCONNECTED) { | |
325 | try { | |
326 | setTargetNodeState(TargetNodeState.CONNECTING); | |
327 | Job job = new Job(format(Messages.TraceControl_OpenConnectionTo, getName())) { | |
328 | @Override | |
329 | protected IStatus run(IProgressMonitor monitor) { | |
330 | try { | |
d8a4fd60 | 331 | fRemoteProxy.connect(checkNotNull(monitor)); |
b732adaa MS |
332 | return Status.OK_STATUS; |
333 | } catch (Exception e) { | |
334 | return new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.TraceControl_ConnectionFailure, e); | |
335 | } | |
336 | } | |
337 | }; | |
338 | job.addJobChangeListener(new JobChangeAdapter() { | |
339 | @Override | |
340 | public void done(IJobChangeEvent event) { | |
341 | IStatus status = event.getResult(); | |
342 | if (status.isOK()) { | |
343 | handleConnected(); | |
344 | } else { | |
345 | handleDisconnected(); | |
346 | if (status.getSeverity() != IStatus.CANCEL) { | |
347 | Activator.getDefault().getLog().log(status); | |
348 | } | |
349 | } | |
350 | } | |
351 | }); | |
352 | job.schedule(); | |
353 | } catch (Exception e) { | |
354 | setTargetNodeState(TargetNodeState.DISCONNECTED); | |
355 | Activator.getDefault().logError(Messages.TraceControl_ConnectionFailure + " (" + getName() + "). \n", e); //$NON-NLS-1$ //$NON-NLS-2$ | |
356 | } | |
357 | } | |
358 | } | |
359 | ||
360 | /** | |
361 | * Method to disconnect this node component to the remote target node. | |
362 | */ | |
eb1bab5b BH |
363 | public void disconnect() { |
364 | if (fState == TargetNodeState.CONNECTED) { | |
365 | try { | |
366 | setTargetNodeState(TargetNodeState.DISCONNECTING); | |
367 | fRemoteProxy.disconnect(); | |
368 | } catch (Exception e) { | |
9fa32496 | 369 | Activator.getDefault().logError(Messages.TraceControl_DisconnectionFailure + " (" + getName() + "). \n", e); //$NON-NLS-1$ //$NON-NLS-2$ |
eb1bab5b | 370 | } finally { |
cfdb727a | 371 | handleDisconnected(); |
eb1bab5b BH |
372 | } |
373 | } | |
374 | } | |
375 | ||
376 | /** | |
cfdb727a AM |
377 | * Retrieves the trace configuration from the target node and populates the |
378 | * information in the tree model. The execution is done in a own job. | |
eb1bab5b | 379 | */ |
d132bcc7 | 380 | public void getConfigurationFromNode() { |
eb1bab5b BH |
381 | Job job = new Job(Messages.TraceControl_RetrieveNodeConfigurationJob) { |
382 | @Override | |
383 | protected IStatus run(IProgressMonitor monitor) { | |
384 | ||
385 | try { | |
386 | // Get provider information from node | |
387 | TraceProviderGroup providerGroup = new TraceProviderGroup(Messages.TraceControl_ProviderDisplayName, TargetNodeComponent.this); | |
388 | addChild(providerGroup); | |
cfdb727a | 389 | |
eb1bab5b BH |
390 | // Get session information from node |
391 | TraceSessionGroup sessionGroup = new TraceSessionGroup(Messages.TraceControl_AllSessionsDisplayName, TargetNodeComponent.this); | |
392 | addChild(sessionGroup); | |
b732adaa MS |
393 | |
394 | providerGroup.getProviderFromNode(monitor); | |
eb1bab5b BH |
395 | sessionGroup.getSessionsFromNode(monitor); |
396 | } catch (ExecutionException e) { | |
397 | removeAllChildren(); | |
973e19d6 | 398 | return new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.TraceControl_RetrieveNodeConfigurationFailure, e); |
cfdb727a | 399 | } |
eb1bab5b BH |
400 | |
401 | return Status.OK_STATUS; | |
402 | } | |
403 | }; | |
404 | job.setUser(true); | |
405 | job.schedule(); | |
d132bcc7 | 406 | } |
eb1bab5b | 407 | |
8577ed1e BH |
408 | /** |
409 | * Refresh the node configuration | |
410 | */ | |
d132bcc7 BH |
411 | public void refresh() { |
412 | removeAllChildren(); | |
413 | getConfigurationFromNode(); | |
eb1bab5b | 414 | } |
cfdb727a | 415 | |
eb1bab5b BH |
416 | // ------------------------------------------------------------------------ |
417 | // Helper function | |
418 | // ------------------------------------------------------------------------ | |
11252342 | 419 | |
eb1bab5b BH |
420 | /** |
421 | * @return returns the control service for LTTng specific commands. | |
422 | * @throws ExecutionException | |
423 | */ | |
424 | private ILttngControlService createControlService() throws ExecutionException { | |
b732adaa MS |
425 | if (fService == null) { |
426 | try { | |
13729cbc BH |
427 | ICommandShell shell = fRemoteProxy.createCommandShell(); |
428 | fShell = shell; | |
429 | fService = LTTngControlServiceFactory.getLttngControlService(shell); | |
b732adaa MS |
430 | } catch (ExecutionException e) { |
431 | disposeControlService(); | |
432 | throw e; | |
433 | } | |
eb1bab5b | 434 | } |
eb1bab5b BH |
435 | return fService; |
436 | } | |
437 | ||
438 | /** | |
cfdb727a | 439 | * Handles the connected event. |
eb1bab5b BH |
440 | */ |
441 | private void handleConnected() { | |
eb1bab5b BH |
442 | try { |
443 | createControlService(); | |
444 | getConfigurationFromNode(); | |
b732adaa MS |
445 | // Set connected only after the control service has been created and the jobs for creating the |
446 | // sub-nodes are scheduled. | |
447 | setTargetNodeState(TargetNodeState.CONNECTED); | |
973e19d6 BH |
448 | } catch (final ExecutionException e) { |
449 | // Disconnect only if no control service, otherwise stay connected. | |
b732adaa MS |
450 | if (getControlService() == NULL_CONTROL_SERVICE) { |
451 | fState = TargetNodeState.CONNECTED; | |
973e19d6 BH |
452 | disconnect(); |
453 | } | |
454 | ||
455 | // Notify user | |
456 | Display.getDefault().asyncExec(new Runnable() { | |
457 | @Override | |
458 | public void run() { | |
459 | ErrorDialog er = new ErrorDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), | |
460 | Messages.TraceControl_ErrorTitle, Messages.TraceControl_RetrieveNodeConfigurationFailure, | |
461 | new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e), | |
462 | IStatus.ERROR); | |
463 | er.open(); | |
464 | } | |
465 | }); | |
466 | Activator.getDefault().logError(Messages.TraceControl_RetrieveNodeConfigurationFailure + " (" + getName() + "). \n", e); //$NON-NLS-1$ //$NON-NLS-2$ | |
eb1bab5b BH |
467 | } |
468 | } | |
469 | ||
470 | /** | |
cfdb727a | 471 | * Handles the disconnected event. |
eb1bab5b BH |
472 | */ |
473 | private void handleDisconnected() { | |
b732adaa | 474 | disposeControlService(); |
eb1bab5b | 475 | setTargetNodeState(TargetNodeState.DISCONNECTED); |
b732adaa MS |
476 | removeAllChildren(); |
477 | } | |
478 | ||
479 | @Override | |
480 | public void addChild(ITraceControlComponent component) { | |
481 | if (getTargetNodeState() == TargetNodeState.DISCONNECTED) { | |
482 | return; | |
483 | } | |
484 | super.addChild(component); | |
eb1bab5b BH |
485 | } |
486 | } |