1 /**********************************************************************
2 * Copyright (c) 2012, 2015 Ericsson
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
10 * Bernd Hufmann - Initial API and implementation
11 * Bernd Hufmann - Updated for support of LTTng Tools 2.1
12 * Markus Schorn - Bug 448058: Use org.eclipse.remote in favor of RSE
13 * Bernd Hufmann - Update to org.eclipse.remote API 2.0
14 **********************************************************************/
15 package org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.model
.impl
;
17 import static java
.text
.MessageFormat
.format
;
18 import static org
.eclipse
.tracecompass
.common
.core
.NonNullUtils
.checkNotNull
;
20 import java
.util
.List
;
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
;
26 import org
.eclipse
.core
.runtime
.jobs
.IJobChangeEvent
;
27 import org
.eclipse
.core
.runtime
.jobs
.Job
;
28 import org
.eclipse
.core
.runtime
.jobs
.JobChangeAdapter
;
29 import org
.eclipse
.jdt
.annotation
.NonNull
;
30 import org
.eclipse
.jdt
.annotation
.Nullable
;
31 import org
.eclipse
.jface
.dialogs
.ErrorDialog
;
32 import org
.eclipse
.remote
.core
.IRemoteConnection
;
33 import org
.eclipse
.remote
.core
.IRemoteConnectionChangeListener
;
34 import org
.eclipse
.remote
.core
.RemoteConnectionChangeEvent
;
35 import org
.eclipse
.swt
.graphics
.Image
;
36 import org
.eclipse
.swt
.widgets
.Display
;
37 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.model
.TraceDomainType
;
38 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.model
.TargetNodeState
;
39 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.Activator
;
40 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.messages
.Messages
;
41 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.model
.ITraceControlComponent
;
42 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.property
.TargetNodePropertySource
;
43 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.service
.ILttngControlService
;
44 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.service
.LTTngControlServiceFactory
;
45 import org
.eclipse
.tracecompass
.tmf
.remote
.core
.proxy
.RemoteSystemProxy
;
46 import org
.eclipse
.tracecompass
.tmf
.remote
.core
.shell
.ICommandShell
;
47 import org
.eclipse
.ui
.PlatformUI
;
48 import org
.eclipse
.ui
.views
.properties
.IPropertySource
;
52 * Implementation of the trace node component.
55 * @author Bernd Hufmann
57 public class TargetNodeComponent
extends TraceControlComponent
implements IRemoteConnectionChangeListener
{
59 // ------------------------------------------------------------------------
61 // ------------------------------------------------------------------------
64 * Path to icon file for this component (state connected).
66 public static final String TARGET_NODE_CONNECTED_ICON_FILE
= "icons/obj16/target_connected.gif"; //$NON-NLS-1$
68 * Path to icon file for this component (state disconnected).
70 public static final String TARGET_NODE_DISCONNECTED_ICON_FILE
= "icons/obj16/target_disconnected.gif"; //$NON-NLS-1$
72 private static final ILttngControlService NULL_CONTROL_SERVICE
= new NullControlService();
74 // ------------------------------------------------------------------------
76 // ------------------------------------------------------------------------
79 * The node connection state.
81 private TargetNodeState fState
= TargetNodeState
.DISCONNECTED
;
83 * The image to be displayed in state disconnected.
85 private Image fDisconnectedImage
= null;
87 * The remote proxy implementation.
89 private @NonNull RemoteSystemProxy fRemoteProxy
;
91 * The control service for LTTng specific commands.
93 private ILttngControlService fService
= null;
95 * The command shell for issuing commands.
97 private ICommandShell fShell
= null;
99 // ------------------------------------------------------------------------
101 // ------------------------------------------------------------------------
107 * the name of the component
109 * the parent of the component
111 * the remote proxy implementation
113 public TargetNodeComponent(String name
, ITraceControlComponent parent
, @NonNull RemoteSystemProxy proxy
) {
115 setImage(TARGET_NODE_CONNECTED_ICON_FILE
);
116 fDisconnectedImage
= Activator
.getDefault().loadIcon(TARGET_NODE_DISCONNECTED_ICON_FILE
);
117 fRemoteProxy
= proxy
;
118 fRemoteProxy
.getRemoteConnection().addConnectionChangeListener(this);
119 setToolTip(fRemoteProxy
.getRemoteConnection().getName());
123 * Constructor (using default proxy)
126 * the name of the component
128 * the parent of the component
130 * the host connection implementation
132 public TargetNodeComponent(String name
, ITraceControlComponent parent
, @NonNull IRemoteConnection host
) {
133 this(name
, parent
, new RemoteSystemProxy(host
));
137 public void dispose() {
138 fRemoteProxy
.getRemoteConnection().removeConnectionChangeListener(this);
139 fRemoteProxy
.dispose();
140 disposeControlService();
143 private void disposeControlService() {
145 final ICommandShell shell
= fShell
;
152 // ------------------------------------------------------------------------
154 // ------------------------------------------------------------------------
157 public Image
getImage() {
158 if (fState
== TargetNodeState
.CONNECTED
) {
159 return super.getImage();
161 return fDisconnectedImage
;
165 public TargetNodeState
getTargetNodeState() {
170 public void setTargetNodeState(TargetNodeState state
) {
172 fireComponentChanged(TargetNodeComponent
.this);
176 public ILttngControlService
getControlService() {
177 return fService
== null ? NULL_CONTROL_SERVICE
: fService
;
181 public void setControlService(ILttngControlService service
) {
186 public <T
> @Nullable T
getAdapter(Class
<T
> adapter
) {
187 if (adapter
== IPropertySource
.class) {
188 return adapter
.cast(new TargetNodePropertySource(this));
194 * @return remote system proxy implementation
196 public @NonNull RemoteSystemProxy
getRemoteSystemProxy() {
201 * @return all available sessions.
203 public @NonNull TraceSessionComponent
[] getSessions() {
204 List
<ITraceControlComponent
> compenents
= getChildren(TraceSessionGroup
.class);
205 if (compenents
.size() > 0) {
206 TraceSessionGroup group
= (TraceSessionGroup
)compenents
.get(0);
207 List
<ITraceControlComponent
> sessions
= group
.getChildren(TraceSessionComponent
.class);
208 return sessions
.toArray(new @NonNull TraceSessionComponent
[sessions
.size()]);
210 return new TraceSessionComponent
[0];
214 * @return node version
216 public String
getNodeVersion() {
217 // Control service is null during connection to node
218 if (getControlService() != NULL_CONTROL_SERVICE
) {
219 return getControlService().getVersionString();
221 return ""; //$NON-NLS-1$
225 * Returns if node supports filtering of events
226 * @param domain - the domain type ({@link TraceDomainType})
227 * @return <code>true</code> if node supports filtering else <code>false</code>
229 public boolean isEventFilteringSupported(TraceDomainType domain
) {
230 if (domain
.equals(TraceDomainType
.KERNEL
)) {
231 return getControlService().isVersionSupported("2.7.0"); //$NON-NLS-1$
233 return getControlService().isVersionSupported("2.1.0"); //$NON-NLS-1$
237 * Returns if node supports networks streaming or not
238 * @return <code>true</code> if node supports filtering else <code>false</code>
241 public boolean isNetworkStreamingSupported() {
242 return getControlService().isVersionSupported("2.1.0"); //$NON-NLS-1$
246 * Returns if node supports configuring buffer type or not
247 * @return <code>true</code> if node supports buffer type configuration else <code>false</code>
249 public boolean isBufferTypeConfigSupported() {
250 return getControlService().isVersionSupported("2.2.0"); //$NON-NLS-1$
254 * Returns if node supports trace file rotation or not
255 * @return <code>true</code> if node supports trace file rotation else <code>false</code>
257 public boolean isTraceFileRotationSupported() {
258 return getControlService().isVersionSupported("2.2.0"); //$NON-NLS-1$
262 * Returns if node supports periodical flush for metadata or not
263 * @return <code>true</code> if node supports periodical flush for metadata else <code>false</code>
265 public boolean isPeriodicalMetadataFlushSupported() {
266 return getControlService().isVersionSupported("2.2.0"); //$NON-NLS-1$
269 * Returns if node supports snapshots or not
270 * @return <code>true</code> if it supports snapshots else <code>false</code>
273 public boolean isSnapshotSupported() {
274 return getControlService().isVersionSupported("2.3.0"); //$NON-NLS-1$
277 * Returns if node supports live or not
278 * @return <code>true</code> if it supports live else <code>false</code>
281 public boolean isLiveSupported() {
283 // FIXME: Disable Live support until we have a better implementation
284 //return getControlService().isVersionSupported("2.4.0"); //$NON-NLS-1$;
287 * Returns if node supports adding contexts on event
288 * @return <code>true</code> if it supports adding contexts on events else <code>false</code>
291 public boolean isContextOnEventSupported() {
292 return !getControlService().isVersionSupported("2.2.0"); //$NON-NLS-1$
296 * Checks if enabling of per syscall event is supported
298 * @return <code>true</code> if enabling of per syscall event is supported else <code>false</code>
300 public boolean isPerSyscallEventsSupported() {
301 return getControlService().isVersionSupported("2.6.0"); //$NON-NLS-1$
304 * Returns if node supports JUL logging or not
305 * @return <code>true</code> if it supports JUL logging else <code>false</code>
308 public boolean isJulLoggingSupported() {
309 return getControlService().isVersionSupported("2.6.0"); //$NON-NLS-1$
312 * Returns if node supports LOG4J logging or not
313 * @return <code>true</code> if it supports LOG4J logging else <code>false</code>
316 public boolean isLog4jLoggingSupported() {
317 return getControlService().isVersionSupported("2.6.0"); //$NON-NLS-1$
320 * Returns if node supports Python logging or not
321 * @return <code>true</code> if it supports Python logging else <code>false</code>
324 public boolean isPythonLoggingSupported() {
325 return getControlService().isVersionSupported("2.7.0"); //$NON-NLS-1$
329 * Checks if given version is supported by this ILTTngControlService implementation.
331 * @param version The version to check
332 * @return <code>true</code> if version is supported else <code>false</code>
334 public boolean isVersionSupported(String version
) {
335 return getControlService().isVersionSupported(version
);
338 // ------------------------------------------------------------------------
340 // ------------------------------------------------------------------------
343 public void connectionChanged(RemoteConnectionChangeEvent e
) {
344 if (fState
== TargetNodeState
.CONNECTING
) {
348 switch (e
.getType()) {
349 case RemoteConnectionChangeEvent
.CONNECTION_CLOSED
:
350 case RemoteConnectionChangeEvent
.CONNECTION_ABORTED
:
351 handleDisconnected();
353 case RemoteConnectionChangeEvent
.CONNECTION_OPENED
:
362 * Method to connect this node component to the remote target node.
364 public void connect() {
365 if (fState
== TargetNodeState
.DISCONNECTED
) {
367 setTargetNodeState(TargetNodeState
.CONNECTING
);
368 Job job
= new Job(format(Messages
.TraceControl_OpenConnectionTo
, getName())) {
370 protected IStatus
run(IProgressMonitor monitor
) {
372 fRemoteProxy
.connect(checkNotNull(monitor
));
373 return Status
.OK_STATUS
;
374 } catch (Exception e
) {
375 return new Status(IStatus
.ERROR
, Activator
.PLUGIN_ID
, Messages
.TraceControl_ConnectionFailure
, e
);
379 job
.addJobChangeListener(new JobChangeAdapter() {
381 public void done(IJobChangeEvent event
) {
382 IStatus status
= event
.getResult();
386 handleDisconnected();
387 if (status
.getSeverity() != IStatus
.CANCEL
) {
388 Activator
.getDefault().getLog().log(status
);
394 } catch (Exception e
) {
395 setTargetNodeState(TargetNodeState
.DISCONNECTED
);
396 Activator
.getDefault().logError(Messages
.TraceControl_ConnectionFailure
+ " (" + getName() + "). \n", e
); //$NON-NLS-1$ //$NON-NLS-2$
402 * Method to disconnect this node component to the remote target node.
404 public void disconnect() {
405 if (fState
== TargetNodeState
.CONNECTED
) {
407 setTargetNodeState(TargetNodeState
.DISCONNECTING
);
408 fRemoteProxy
.disconnect();
409 } catch (Exception e
) {
410 Activator
.getDefault().logError(Messages
.TraceControl_DisconnectionFailure
+ " (" + getName() + "). \n", e
); //$NON-NLS-1$ //$NON-NLS-2$
412 handleDisconnected();
418 * Retrieves the trace configuration from the target node and populates the
419 * information in the tree model. The execution is done in a own job.
421 public void getConfigurationFromNode() {
422 Job job
= new Job(Messages
.TraceControl_RetrieveNodeConfigurationJob
) {
424 protected IStatus
run(IProgressMonitor monitor
) {
427 // Get provider information from node
428 TraceProviderGroup providerGroup
= new TraceProviderGroup(Messages
.TraceControl_ProviderDisplayName
, TargetNodeComponent
.this);
429 addChild(providerGroup
);
431 // Get session information from node
432 TraceSessionGroup sessionGroup
= new TraceSessionGroup(Messages
.TraceControl_AllSessionsDisplayName
, TargetNodeComponent
.this);
433 addChild(sessionGroup
);
435 providerGroup
.getProviderFromNode(monitor
);
436 sessionGroup
.getSessionsFromNode(monitor
);
437 } catch (ExecutionException e
) {
439 return new Status(IStatus
.ERROR
, Activator
.PLUGIN_ID
, Messages
.TraceControl_RetrieveNodeConfigurationFailure
, e
);
442 return Status
.OK_STATUS
;
450 * Refresh the node configuration
452 public void refresh() {
454 getConfigurationFromNode();
457 // ------------------------------------------------------------------------
459 // ------------------------------------------------------------------------
462 * @return returns the control service for LTTng specific commands.
463 * @throws ExecutionException
465 private ILttngControlService
createControlService() throws ExecutionException
{
466 if (fService
== null) {
468 ICommandShell shell
= fRemoteProxy
.createCommandShell();
470 fService
= LTTngControlServiceFactory
.getLttngControlService(shell
);
471 } catch (ExecutionException e
) {
472 disposeControlService();
480 * Handles the connected event.
482 private void handleConnected() {
484 createControlService();
485 getConfigurationFromNode();
486 // Set connected only after the control service has been created and the jobs for creating the
487 // sub-nodes are scheduled.
488 setTargetNodeState(TargetNodeState
.CONNECTED
);
489 } catch (final ExecutionException e
) {
490 // Disconnect only if no control service, otherwise stay connected.
491 if (getControlService() == NULL_CONTROL_SERVICE
) {
492 fState
= TargetNodeState
.CONNECTED
;
497 Display
.getDefault().asyncExec(new Runnable() {
500 ErrorDialog er
= new ErrorDialog(PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getShell(),
501 Messages
.TraceControl_ErrorTitle
, Messages
.TraceControl_RetrieveNodeConfigurationFailure
,
502 new Status(IStatus
.ERROR
, Activator
.PLUGIN_ID
, e
.getMessage(), e
),
507 Activator
.getDefault().logError(Messages
.TraceControl_RetrieveNodeConfigurationFailure
+ " (" + getName() + "). \n", e
); //$NON-NLS-1$ //$NON-NLS-2$
512 * Handles the disconnected event.
514 private void handleDisconnected() {
515 disposeControlService();
516 setTargetNodeState(TargetNodeState
.DISCONNECTED
);
521 public void addChild(ITraceControlComponent component
) {
522 if (getTargetNodeState() == TargetNodeState
.DISCONNECTED
) {
525 super.addChild(component
);