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