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
.TargetNodeState
;
38 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.Activator
;
39 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.messages
.Messages
;
40 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.model
.ITraceControlComponent
;
41 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.property
.TargetNodePropertySource
;
42 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.service
.ILttngControlService
;
43 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.service
.LTTngControlServiceFactory
;
44 import org
.eclipse
.tracecompass
.tmf
.remote
.core
.proxy
.RemoteSystemProxy
;
45 import org
.eclipse
.tracecompass
.tmf
.remote
.core
.shell
.ICommandShell
;
46 import org
.eclipse
.ui
.PlatformUI
;
47 import org
.eclipse
.ui
.views
.properties
.IPropertySource
;
51 * Implementation of the trace node component.
54 * @author Bernd Hufmann
56 public class TargetNodeComponent
extends TraceControlComponent
implements IRemoteConnectionChangeListener
{
58 // ------------------------------------------------------------------------
60 // ------------------------------------------------------------------------
63 * Path to icon file for this component (state connected).
65 public static final String TARGET_NODE_CONNECTED_ICON_FILE
= "icons/obj16/target_connected.gif"; //$NON-NLS-1$
67 * Path to icon file for this component (state disconnected).
69 public static final String TARGET_NODE_DISCONNECTED_ICON_FILE
= "icons/obj16/target_disconnected.gif"; //$NON-NLS-1$
71 private static final ILttngControlService NULL_CONTROL_SERVICE
= new NullControlService();
73 // ------------------------------------------------------------------------
75 // ------------------------------------------------------------------------
78 * The node connection state.
80 private TargetNodeState fState
= TargetNodeState
.DISCONNECTED
;
82 * The image to be displayed in state disconnected.
84 private Image fDisconnectedImage
= null;
86 * The remote proxy implementation.
88 private @NonNull RemoteSystemProxy fRemoteProxy
;
90 * The control service for LTTng specific commands.
92 private ILttngControlService fService
= null;
94 * The command shell for issuing commands.
96 private ICommandShell fShell
= null;
98 // ------------------------------------------------------------------------
100 // ------------------------------------------------------------------------
106 * the name of the component
108 * the parent of the component
110 * the remote proxy implementation
112 public TargetNodeComponent(String name
, ITraceControlComponent parent
, @NonNull RemoteSystemProxy proxy
) {
114 setImage(TARGET_NODE_CONNECTED_ICON_FILE
);
115 fDisconnectedImage
= Activator
.getDefault().loadIcon(TARGET_NODE_DISCONNECTED_ICON_FILE
);
116 fRemoteProxy
= proxy
;
117 fRemoteProxy
.getRemoteConnection().addConnectionChangeListener(this);
118 setToolTip(fRemoteProxy
.getRemoteConnection().getName());
122 * Constructor (using default proxy)
125 * the name of the component
127 * the parent of the component
129 * the host connection implementation
131 public TargetNodeComponent(String name
, ITraceControlComponent parent
, @NonNull IRemoteConnection host
) {
132 this(name
, parent
, new RemoteSystemProxy(host
));
136 public void dispose() {
137 fRemoteProxy
.getRemoteConnection().removeConnectionChangeListener(this);
138 fRemoteProxy
.dispose();
139 disposeControlService();
142 private void disposeControlService() {
144 final ICommandShell shell
= fShell
;
151 // ------------------------------------------------------------------------
153 // ------------------------------------------------------------------------
156 public Image
getImage() {
157 if (fState
== TargetNodeState
.CONNECTED
) {
158 return super.getImage();
160 return fDisconnectedImage
;
164 public TargetNodeState
getTargetNodeState() {
169 public void setTargetNodeState(TargetNodeState state
) {
171 fireComponentChanged(TargetNodeComponent
.this);
175 public ILttngControlService
getControlService() {
176 return fService
== null ? NULL_CONTROL_SERVICE
: fService
;
180 public void setControlService(ILttngControlService service
) {
185 public <T
> @Nullable T
getAdapter(Class
<T
> adapter
) {
186 if (adapter
== IPropertySource
.class) {
187 return adapter
.cast(new TargetNodePropertySource(this));
193 * @return remote system proxy implementation
195 public @NonNull RemoteSystemProxy
getRemoteSystemProxy() {
200 * @return all available sessions.
202 public @NonNull TraceSessionComponent
[] getSessions() {
203 List
<ITraceControlComponent
> compenents
= getChildren(TraceSessionGroup
.class);
204 if (compenents
.size() > 0) {
205 TraceSessionGroup group
= (TraceSessionGroup
)compenents
.get(0);
206 List
<ITraceControlComponent
> sessions
= group
.getChildren(TraceSessionComponent
.class);
207 return sessions
.toArray(new @NonNull TraceSessionComponent
[sessions
.size()]);
209 return new TraceSessionComponent
[0];
213 * @return node version
215 public String
getNodeVersion() {
216 // Control service is null during connection to node
217 if (getControlService() != NULL_CONTROL_SERVICE
) {
218 return getControlService().getVersionString();
220 return ""; //$NON-NLS-1$
224 * Returns if node supports filtering of events
225 * @param isKernel - <code>true</code> for kernel provider else <code>false</code>
226 * @return <code>true</code> if node supports filtering else <code>false</code>
228 public boolean isEventFilteringSupported(boolean isKernel
) {
230 return getControlService().isVersionSupported("2.7.0"); //$NON-NLS-1$
232 return getControlService().isVersionSupported("2.1.0"); //$NON-NLS-1$
236 * Returns if node supports networks streaming or not
237 * @return <code>true</code> if node supports filtering else <code>false</code>
240 public boolean isNetworkStreamingSupported() {
241 return getControlService().isVersionSupported("2.1.0"); //$NON-NLS-1$
245 * Returns if node supports configuring buffer type or not
246 * @return <code>true</code> if node supports buffer type configuration else <code>false</code>
248 public boolean isBufferTypeConfigSupported() {
249 return getControlService().isVersionSupported("2.2.0"); //$NON-NLS-1$
253 * Returns if node supports trace file rotation or not
254 * @return <code>true</code> if node supports trace file rotation else <code>false</code>
256 public boolean isTraceFileRotationSupported() {
257 return getControlService().isVersionSupported("2.2.0"); //$NON-NLS-1$
261 * Returns if node supports periodical flush for metadata or not
262 * @return <code>true</code> if node supports periodical flush for metadata else <code>false</code>
264 public boolean isPeriodicalMetadataFlushSupported() {
265 return getControlService().isVersionSupported("2.2.0"); //$NON-NLS-1$
268 * Returns if node supports snapshots or not
269 * @return <code>true</code> if it supports snapshots else <code>false</code>
272 public boolean isSnapshotSupported() {
273 return getControlService().isVersionSupported("2.3.0"); //$NON-NLS-1$
276 * Returns if node supports live or not
277 * @return <code>true</code> if it supports live else <code>false</code>
280 public boolean isLiveSupported() {
281 return getControlService().isVersionSupported("2.4.0"); //$NON-NLS-1$;
284 * Returns if node supports adding contexts on event
285 * @return <code>true</code> if it supports adding contexts on events else <code>false</code>
288 public boolean isContextOnEventSupported() {
289 return !getControlService().isVersionSupported("2.2.0"); //$NON-NLS-1$
293 * Checks if given version is supported by this ILTTngControlService implementation.
295 * @param version The version to check
296 * @return <code>true</code> if version is supported else <code>false</code>
298 public boolean isVersionSupported(String version
) {
299 return getControlService().isVersionSupported(version
);
302 // ------------------------------------------------------------------------
304 // ------------------------------------------------------------------------
307 public void connectionChanged(RemoteConnectionChangeEvent e
) {
308 if (fState
== TargetNodeState
.CONNECTING
) {
312 switch (e
.getType()) {
313 case RemoteConnectionChangeEvent
.CONNECTION_CLOSED
:
314 case RemoteConnectionChangeEvent
.CONNECTION_ABORTED
:
315 handleDisconnected();
317 case RemoteConnectionChangeEvent
.CONNECTION_OPENED
:
326 * Method to connect this node component to the remote target node.
328 public void connect() {
329 if (fState
== TargetNodeState
.DISCONNECTED
) {
331 setTargetNodeState(TargetNodeState
.CONNECTING
);
332 Job job
= new Job(format(Messages
.TraceControl_OpenConnectionTo
, getName())) {
334 protected IStatus
run(IProgressMonitor monitor
) {
336 fRemoteProxy
.connect(checkNotNull(monitor
));
337 return Status
.OK_STATUS
;
338 } catch (Exception e
) {
339 return new Status(IStatus
.ERROR
, Activator
.PLUGIN_ID
, Messages
.TraceControl_ConnectionFailure
, e
);
343 job
.addJobChangeListener(new JobChangeAdapter() {
345 public void done(IJobChangeEvent event
) {
346 IStatus status
= event
.getResult();
350 handleDisconnected();
351 if (status
.getSeverity() != IStatus
.CANCEL
) {
352 Activator
.getDefault().getLog().log(status
);
358 } catch (Exception e
) {
359 setTargetNodeState(TargetNodeState
.DISCONNECTED
);
360 Activator
.getDefault().logError(Messages
.TraceControl_ConnectionFailure
+ " (" + getName() + "). \n", e
); //$NON-NLS-1$ //$NON-NLS-2$
366 * Method to disconnect this node component to the remote target node.
368 public void disconnect() {
369 if (fState
== TargetNodeState
.CONNECTED
) {
371 setTargetNodeState(TargetNodeState
.DISCONNECTING
);
372 fRemoteProxy
.disconnect();
373 } catch (Exception e
) {
374 Activator
.getDefault().logError(Messages
.TraceControl_DisconnectionFailure
+ " (" + getName() + "). \n", e
); //$NON-NLS-1$ //$NON-NLS-2$
376 handleDisconnected();
382 * Retrieves the trace configuration from the target node and populates the
383 * information in the tree model. The execution is done in a own job.
385 public void getConfigurationFromNode() {
386 Job job
= new Job(Messages
.TraceControl_RetrieveNodeConfigurationJob
) {
388 protected IStatus
run(IProgressMonitor monitor
) {
391 // Get provider information from node
392 TraceProviderGroup providerGroup
= new TraceProviderGroup(Messages
.TraceControl_ProviderDisplayName
, TargetNodeComponent
.this);
393 addChild(providerGroup
);
395 // Get session information from node
396 TraceSessionGroup sessionGroup
= new TraceSessionGroup(Messages
.TraceControl_AllSessionsDisplayName
, TargetNodeComponent
.this);
397 addChild(sessionGroup
);
399 providerGroup
.getProviderFromNode(monitor
);
400 sessionGroup
.getSessionsFromNode(monitor
);
401 } catch (ExecutionException e
) {
403 return new Status(IStatus
.ERROR
, Activator
.PLUGIN_ID
, Messages
.TraceControl_RetrieveNodeConfigurationFailure
, e
);
406 return Status
.OK_STATUS
;
414 * Refresh the node configuration
416 public void refresh() {
418 getConfigurationFromNode();
421 // ------------------------------------------------------------------------
423 // ------------------------------------------------------------------------
426 * @return returns the control service for LTTng specific commands.
427 * @throws ExecutionException
429 private ILttngControlService
createControlService() throws ExecutionException
{
430 if (fService
== null) {
432 ICommandShell shell
= fRemoteProxy
.createCommandShell();
434 fService
= LTTngControlServiceFactory
.getLttngControlService(shell
);
435 } catch (ExecutionException e
) {
436 disposeControlService();
444 * Handles the connected event.
446 private void handleConnected() {
448 createControlService();
449 getConfigurationFromNode();
450 // Set connected only after the control service has been created and the jobs for creating the
451 // sub-nodes are scheduled.
452 setTargetNodeState(TargetNodeState
.CONNECTED
);
453 } catch (final ExecutionException e
) {
454 // Disconnect only if no control service, otherwise stay connected.
455 if (getControlService() == NULL_CONTROL_SERVICE
) {
456 fState
= TargetNodeState
.CONNECTED
;
461 Display
.getDefault().asyncExec(new Runnable() {
464 ErrorDialog er
= new ErrorDialog(PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getShell(),
465 Messages
.TraceControl_ErrorTitle
, Messages
.TraceControl_RetrieveNodeConfigurationFailure
,
466 new Status(IStatus
.ERROR
, Activator
.PLUGIN_ID
, e
.getMessage(), e
),
471 Activator
.getDefault().logError(Messages
.TraceControl_RetrieveNodeConfigurationFailure
+ " (" + getName() + "). \n", e
); //$NON-NLS-1$ //$NON-NLS-2$
476 * Handles the disconnected event.
478 private void handleDisconnected() {
479 disposeControlService();
480 setTargetNodeState(TargetNodeState
.DISCONNECTED
);
485 public void addChild(ITraceControlComponent component
) {
486 if (getTargetNodeState() == TargetNodeState
.DISCONNECTED
) {
489 super.addChild(component
);