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
;
19 import java
.util
.List
;
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
;
25 import org
.eclipse
.core
.runtime
.jobs
.IJobChangeEvent
;
26 import org
.eclipse
.core
.runtime
.jobs
.Job
;
27 import org
.eclipse
.core
.runtime
.jobs
.JobChangeAdapter
;
28 import org
.eclipse
.jface
.dialogs
.ErrorDialog
;
29 import org
.eclipse
.remote
.core
.IRemoteConnection
;
30 import org
.eclipse
.remote
.core
.IRemoteConnectionChangeListener
;
31 import org
.eclipse
.remote
.core
.RemoteConnectionChangeEvent
;
32 import org
.eclipse
.swt
.graphics
.Image
;
33 import org
.eclipse
.swt
.widgets
.Display
;
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
.service
.ILttngControlService
;
40 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.service
.LTTngControlServiceFactory
;
41 import org
.eclipse
.tracecompass
.tmf
.remote
.core
.proxy
.IRemoteSystemProxy
;
42 import org
.eclipse
.tracecompass
.tmf
.remote
.core
.proxy
.RemoteSystemProxy
;
43 import org
.eclipse
.tracecompass
.tmf
.remote
.core
.shell
.ICommandShell
;
44 import org
.eclipse
.ui
.PlatformUI
;
45 import org
.eclipse
.ui
.views
.properties
.IPropertySource
;
49 * Implementation of the trace node component.
52 * @author Bernd Hufmann
54 public class TargetNodeComponent
extends TraceControlComponent
implements IRemoteConnectionChangeListener
{
56 // ------------------------------------------------------------------------
58 // ------------------------------------------------------------------------
61 * Path to icon file for this component (state connected).
63 public static final String TARGET_NODE_CONNECTED_ICON_FILE
= "icons/obj16/target_connected.gif"; //$NON-NLS-1$
65 * Path to icon file for this component (state disconnected).
67 public static final String TARGET_NODE_DISCONNECTED_ICON_FILE
= "icons/obj16/target_disconnected.gif"; //$NON-NLS-1$
69 private static final ILttngControlService NULL_CONTROL_SERVICE
= new NullControlService();
71 // ------------------------------------------------------------------------
73 // ------------------------------------------------------------------------
76 * The node connection state.
78 private TargetNodeState fState
= TargetNodeState
.DISCONNECTED
;
80 * The image to be displayed in state disconnected.
82 private Image fDisconnectedImage
= null;
84 * The connection implementation.
86 private IRemoteConnection fHost
= null;
88 * The remote proxy implementation.
90 private IRemoteSystemProxy fRemoteProxy
= null;
92 * The control service for LTTng specific commands.
94 private ILttngControlService fService
= null;
96 * The command shell for issuing commands.
98 private ICommandShell fShell
= null;
100 // ------------------------------------------------------------------------
102 // ------------------------------------------------------------------------
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
111 public TargetNodeComponent(String name
, ITraceControlComponent parent
, IRemoteConnection host
, IRemoteSystemProxy proxy
) {
113 setImage(TARGET_NODE_CONNECTED_ICON_FILE
);
114 fDisconnectedImage
= Activator
.getDefault().loadIcon(TARGET_NODE_DISCONNECTED_ICON_FILE
);
116 fRemoteProxy
= proxy
;
117 fRemoteProxy
.addConnectionChangeListener(this);
118 setToolTip(fHost
.getName());
122 * Constructor (using default proxy)
123 * @param name - the name of the component
124 * @param parent - the parent of the component
125 * @param host - the host connection implementation
127 public TargetNodeComponent(String name
, ITraceControlComponent parent
, IRemoteConnection host
) {
128 this(name
, parent
, host
, new RemoteSystemProxy(host
));
132 public void dispose() {
133 fRemoteProxy
.removeConnectionChangeListener(this);
134 fRemoteProxy
.dispose();
135 disposeControlService();
138 private void disposeControlService() {
140 final ICommandShell shell
= fShell
;
147 // ------------------------------------------------------------------------
149 // ------------------------------------------------------------------------
152 public Image
getImage() {
153 if (fState
== TargetNodeState
.CONNECTED
) {
154 return super.getImage();
156 return fDisconnectedImage
;
160 public TargetNodeState
getTargetNodeState() {
165 public void setTargetNodeState(TargetNodeState state
) {
167 fireComponentChanged(TargetNodeComponent
.this);
171 public ILttngControlService
getControlService() {
172 return fService
== null ? NULL_CONTROL_SERVICE
: fService
;
176 public void setControlService(ILttngControlService service
) {
181 public Object
getAdapter(Class adapter
) {
182 if (adapter
== IPropertySource
.class) {
183 return new TargetNodePropertySource(this);
189 * @return the remote connection associated with this node
191 public IRemoteConnection
getRemoteConnection() {
196 * @return remote system proxy implementation
198 public IRemoteSystemProxy
getRemoteSystemProxy() {
203 * @return all available sessions.
205 public TraceSessionComponent
[] getSessions() {
206 List
<ITraceControlComponent
> compenents
= getChildren(TraceSessionGroup
.class);
207 if (compenents
.size() > 0) {
208 TraceSessionGroup group
= (TraceSessionGroup
)compenents
.get(0);
209 List
<ITraceControlComponent
> sessions
= group
.getChildren(TraceSessionComponent
.class);
210 return sessions
.toArray(new TraceSessionComponent
[sessions
.size()]);
212 return new TraceSessionComponent
[0];
216 * @return node version
218 public String
getNodeVersion() {
219 // Control service is null during connection to node
220 if (getControlService() != NULL_CONTROL_SERVICE
) {
221 return getControlService().getVersionString();
223 return ""; //$NON-NLS-1$
227 * Returns if node supports filtering of events
228 * @return <code>true</code> if node supports filtering else <code>false</code>
230 public boolean isEventFilteringSupported() {
231 return getControlService().isVersionSupported("2.1.0"); //$NON-NLS-1$
235 * Returns if node supports networks streaming or not
236 * @return <code>true</code> if node supports filtering else <code>false</code>
239 public boolean isNetworkStreamingSupported() {
240 return getControlService().isVersionSupported("2.1.0"); //$NON-NLS-1$
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>
247 public boolean isBufferTypeConfigSupported() {
248 return getControlService().isVersionSupported("2.2.0"); //$NON-NLS-1$
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>
255 public boolean isTraceFileRotationSupported() {
256 return getControlService().isVersionSupported("2.2.0"); //$NON-NLS-1$
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>
263 public boolean isPeriodicalMetadataFlushSupported() {
264 return getControlService().isVersionSupported("2.2.0"); //$NON-NLS-1$
267 * Returns if node supports snapshots or not
268 * @return <code>true</code> if it supports snapshots else <code>false</code>
271 public boolean isSnapshotSupported() {
272 return getControlService().isVersionSupported("2.3.0"); //$NON-NLS-1$
275 * Returns if node supports live or not
276 * @return <code>true</code> if it supports live else <code>false</code>
279 public boolean isLiveSupported() {
280 return getControlService().isVersionSupported("2.4.0"); //$NON-NLS-1$;
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>
287 public boolean isContextOnEventSupported() {
288 return !getControlService().isVersionSupported("2.2.0"); //$NON-NLS-1$
291 // ------------------------------------------------------------------------
293 // ------------------------------------------------------------------------
296 public void connectionChanged(RemoteConnectionChangeEvent e
) {
297 if (fState
== TargetNodeState
.CONNECTING
) {
301 switch (e
.getType()) {
302 case RemoteConnectionChangeEvent
.CONNECTION_CLOSED
:
303 case RemoteConnectionChangeEvent
.CONNECTION_ABORTED
:
304 handleDisconnected();
306 case RemoteConnectionChangeEvent
.CONNECTION_OPENED
:
315 * Method to connect this node component to the remote target node.
317 public void connect() {
318 if (fState
== TargetNodeState
.DISCONNECTED
) {
320 setTargetNodeState(TargetNodeState
.CONNECTING
);
321 Job job
= new Job(format(Messages
.TraceControl_OpenConnectionTo
, getName())) {
323 protected IStatus
run(IProgressMonitor monitor
) {
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
);
332 job
.addJobChangeListener(new JobChangeAdapter() {
334 public void done(IJobChangeEvent event
) {
335 IStatus status
= event
.getResult();
339 handleDisconnected();
340 if (status
.getSeverity() != IStatus
.CANCEL
) {
341 Activator
.getDefault().getLog().log(status
);
347 } catch (Exception e
) {
348 setTargetNodeState(TargetNodeState
.DISCONNECTED
);
349 Activator
.getDefault().logError(Messages
.TraceControl_ConnectionFailure
+ " (" + getName() + "). \n", e
); //$NON-NLS-1$ //$NON-NLS-2$
355 * Method to disconnect this node component to the remote target node.
357 public void disconnect() {
358 if (fState
== TargetNodeState
.CONNECTED
) {
360 setTargetNodeState(TargetNodeState
.DISCONNECTING
);
361 fRemoteProxy
.disconnect();
362 } catch (Exception e
) {
363 Activator
.getDefault().logError(Messages
.TraceControl_DisconnectionFailure
+ " (" + getName() + "). \n", e
); //$NON-NLS-1$ //$NON-NLS-2$
365 handleDisconnected();
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.
374 public void getConfigurationFromNode() {
375 Job job
= new Job(Messages
.TraceControl_RetrieveNodeConfigurationJob
) {
377 protected IStatus
run(IProgressMonitor monitor
) {
380 // Get provider information from node
381 TraceProviderGroup providerGroup
= new TraceProviderGroup(Messages
.TraceControl_ProviderDisplayName
, TargetNodeComponent
.this);
382 addChild(providerGroup
);
384 // Get session information from node
385 TraceSessionGroup sessionGroup
= new TraceSessionGroup(Messages
.TraceControl_AllSessionsDisplayName
, TargetNodeComponent
.this);
386 addChild(sessionGroup
);
388 providerGroup
.getProviderFromNode(monitor
);
389 sessionGroup
.getSessionsFromNode(monitor
);
390 } catch (ExecutionException e
) {
392 return new Status(IStatus
.ERROR
, Activator
.PLUGIN_ID
, Messages
.TraceControl_RetrieveNodeConfigurationFailure
, e
);
395 return Status
.OK_STATUS
;
403 * Refresh the node configuration
405 public void refresh() {
407 getConfigurationFromNode();
410 // ------------------------------------------------------------------------
412 // ------------------------------------------------------------------------
415 * @return returns the control service for LTTng specific commands.
416 * @throws ExecutionException
418 private ILttngControlService
createControlService() throws ExecutionException
{
419 if (fService
== null) {
421 fShell
= fRemoteProxy
.createCommandShell();
422 fService
= LTTngControlServiceFactory
.getInstance().getLttngControlService(fShell
);
423 } catch (ExecutionException e
) {
424 disposeControlService();
432 * Handles the connected event.
434 private void handleConnected() {
436 createControlService();
437 getConfigurationFromNode();
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
);
441 } catch (final ExecutionException e
) {
442 // Disconnect only if no control service, otherwise stay connected.
443 if (getControlService() == NULL_CONTROL_SERVICE
) {
444 fState
= TargetNodeState
.CONNECTED
;
449 Display
.getDefault().asyncExec(new Runnable() {
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
),
459 Activator
.getDefault().logError(Messages
.TraceControl_RetrieveNodeConfigurationFailure
+ " (" + getName() + "). \n", e
); //$NON-NLS-1$ //$NON-NLS-2$
464 * Handles the disconnected event.
466 private void handleDisconnected() {
467 disposeControlService();
468 setTargetNodeState(TargetNodeState
.DISCONNECTED
);
473 public void addChild(ITraceControlComponent component
) {
474 if (getTargetNodeState() == TargetNodeState
.DISCONNECTED
) {
477 super.addChild(component
);