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$
305 * Checks if given version is supported by this ILTTngControlService implementation.
307 * @param version The version to check
308 * @return <code>true</code> if version is supported else <code>false</code>
310 public boolean isVersionSupported(String version
) {
311 return getControlService().isVersionSupported(version
);
314 // ------------------------------------------------------------------------
316 // ------------------------------------------------------------------------
319 public void connectionChanged(RemoteConnectionChangeEvent e
) {
320 if (fState
== TargetNodeState
.CONNECTING
) {
324 switch (e
.getType()) {
325 case RemoteConnectionChangeEvent
.CONNECTION_CLOSED
:
326 case RemoteConnectionChangeEvent
.CONNECTION_ABORTED
:
327 handleDisconnected();
329 case RemoteConnectionChangeEvent
.CONNECTION_OPENED
:
338 * Method to connect this node component to the remote target node.
340 public void connect() {
341 if (fState
== TargetNodeState
.DISCONNECTED
) {
343 setTargetNodeState(TargetNodeState
.CONNECTING
);
344 Job job
= new Job(format(Messages
.TraceControl_OpenConnectionTo
, getName())) {
346 protected IStatus
run(IProgressMonitor monitor
) {
348 fRemoteProxy
.connect(checkNotNull(monitor
));
349 return Status
.OK_STATUS
;
350 } catch (Exception e
) {
351 return new Status(IStatus
.ERROR
, Activator
.PLUGIN_ID
, Messages
.TraceControl_ConnectionFailure
, e
);
355 job
.addJobChangeListener(new JobChangeAdapter() {
357 public void done(IJobChangeEvent event
) {
358 IStatus status
= event
.getResult();
362 handleDisconnected();
363 if (status
.getSeverity() != IStatus
.CANCEL
) {
364 Activator
.getDefault().getLog().log(status
);
370 } catch (Exception e
) {
371 setTargetNodeState(TargetNodeState
.DISCONNECTED
);
372 Activator
.getDefault().logError(Messages
.TraceControl_ConnectionFailure
+ " (" + getName() + "). \n", e
); //$NON-NLS-1$ //$NON-NLS-2$
378 * Method to disconnect this node component to the remote target node.
380 public void disconnect() {
381 if (fState
== TargetNodeState
.CONNECTED
) {
383 setTargetNodeState(TargetNodeState
.DISCONNECTING
);
384 fRemoteProxy
.disconnect();
385 } catch (Exception e
) {
386 Activator
.getDefault().logError(Messages
.TraceControl_DisconnectionFailure
+ " (" + getName() + "). \n", e
); //$NON-NLS-1$ //$NON-NLS-2$
388 handleDisconnected();
394 * Retrieves the trace configuration from the target node and populates the
395 * information in the tree model. The execution is done in a own job.
397 public void getConfigurationFromNode() {
398 Job job
= new Job(Messages
.TraceControl_RetrieveNodeConfigurationJob
) {
400 protected IStatus
run(IProgressMonitor monitor
) {
403 // Get provider information from node
404 TraceProviderGroup providerGroup
= new TraceProviderGroup(Messages
.TraceControl_ProviderDisplayName
, TargetNodeComponent
.this);
405 addChild(providerGroup
);
407 // Get session information from node
408 TraceSessionGroup sessionGroup
= new TraceSessionGroup(Messages
.TraceControl_AllSessionsDisplayName
, TargetNodeComponent
.this);
409 addChild(sessionGroup
);
411 providerGroup
.getProviderFromNode(monitor
);
412 sessionGroup
.getSessionsFromNode(monitor
);
413 } catch (ExecutionException e
) {
415 return new Status(IStatus
.ERROR
, Activator
.PLUGIN_ID
, Messages
.TraceControl_RetrieveNodeConfigurationFailure
, e
);
418 return Status
.OK_STATUS
;
426 * Refresh the node configuration
428 public void refresh() {
430 getConfigurationFromNode();
433 // ------------------------------------------------------------------------
435 // ------------------------------------------------------------------------
438 * @return returns the control service for LTTng specific commands.
439 * @throws ExecutionException
441 private ILttngControlService
createControlService() throws ExecutionException
{
442 if (fService
== null) {
444 ICommandShell shell
= fRemoteProxy
.createCommandShell();
446 fService
= LTTngControlServiceFactory
.getLttngControlService(shell
);
447 } catch (ExecutionException e
) {
448 disposeControlService();
456 * Handles the connected event.
458 private void handleConnected() {
460 createControlService();
461 getConfigurationFromNode();
462 // Set connected only after the control service has been created and the jobs for creating the
463 // sub-nodes are scheduled.
464 setTargetNodeState(TargetNodeState
.CONNECTED
);
465 } catch (final ExecutionException e
) {
466 // Disconnect only if no control service, otherwise stay connected.
467 if (getControlService() == NULL_CONTROL_SERVICE
) {
468 fState
= TargetNodeState
.CONNECTED
;
473 Display
.getDefault().asyncExec(new Runnable() {
476 ErrorDialog er
= new ErrorDialog(PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getShell(),
477 Messages
.TraceControl_ErrorTitle
, Messages
.TraceControl_RetrieveNodeConfigurationFailure
,
478 new Status(IStatus
.ERROR
, Activator
.PLUGIN_ID
, e
.getMessage(), e
),
483 Activator
.getDefault().logError(Messages
.TraceControl_RetrieveNodeConfigurationFailure
+ " (" + getName() + "). \n", e
); //$NON-NLS-1$ //$NON-NLS-2$
488 * Handles the disconnected event.
490 private void handleDisconnected() {
491 disposeControlService();
492 setTargetNodeState(TargetNodeState
.DISCONNECTED
);
497 public void addChild(ITraceControlComponent component
) {
498 if (getTargetNodeState() == TargetNodeState
.DISCONNECTED
) {
501 super.addChild(component
);