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
.jface
.dialogs
.ErrorDialog
;
31 import org
.eclipse
.remote
.core
.IRemoteConnection
;
32 import org
.eclipse
.remote
.core
.IRemoteConnectionChangeListener
;
33 import org
.eclipse
.remote
.core
.RemoteConnectionChangeEvent
;
34 import org
.eclipse
.swt
.graphics
.Image
;
35 import org
.eclipse
.swt
.widgets
.Display
;
36 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.model
.TargetNodeState
;
37 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.Activator
;
38 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.messages
.Messages
;
39 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.model
.ITraceControlComponent
;
40 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.property
.TargetNodePropertySource
;
41 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.service
.ILttngControlService
;
42 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.service
.LTTngControlServiceFactory
;
43 import org
.eclipse
.tracecompass
.tmf
.remote
.core
.proxy
.RemoteSystemProxy
;
44 import org
.eclipse
.tracecompass
.tmf
.remote
.core
.shell
.ICommandShell
;
45 import org
.eclipse
.ui
.PlatformUI
;
46 import org
.eclipse
.ui
.views
.properties
.IPropertySource
;
50 * Implementation of the trace node component.
53 * @author Bernd Hufmann
55 public class TargetNodeComponent
extends TraceControlComponent
implements IRemoteConnectionChangeListener
{
57 // ------------------------------------------------------------------------
59 // ------------------------------------------------------------------------
62 * Path to icon file for this component (state connected).
64 public static final String TARGET_NODE_CONNECTED_ICON_FILE
= "icons/obj16/target_connected.gif"; //$NON-NLS-1$
66 * Path to icon file for this component (state disconnected).
68 public static final String TARGET_NODE_DISCONNECTED_ICON_FILE
= "icons/obj16/target_disconnected.gif"; //$NON-NLS-1$
70 private static final ILttngControlService NULL_CONTROL_SERVICE
= new NullControlService();
72 // ------------------------------------------------------------------------
74 // ------------------------------------------------------------------------
77 * The node connection state.
79 private TargetNodeState fState
= TargetNodeState
.DISCONNECTED
;
81 * The image to be displayed in state disconnected.
83 private Image fDisconnectedImage
= null;
85 * The remote proxy implementation.
87 private @NonNull RemoteSystemProxy fRemoteProxy
;
89 * The control service for LTTng specific commands.
91 private ILttngControlService fService
= null;
93 * The command shell for issuing commands.
95 private ICommandShell fShell
= null;
97 // ------------------------------------------------------------------------
99 // ------------------------------------------------------------------------
105 * the name of the component
107 * the parent of the component
109 * the remote proxy implementation
111 public TargetNodeComponent(String name
, ITraceControlComponent parent
, @NonNull RemoteSystemProxy proxy
) {
113 setImage(TARGET_NODE_CONNECTED_ICON_FILE
);
114 fDisconnectedImage
= Activator
.getDefault().loadIcon(TARGET_NODE_DISCONNECTED_ICON_FILE
);
115 fRemoteProxy
= proxy
;
116 fRemoteProxy
.getRemoteConnection().addConnectionChangeListener(this);
117 setToolTip(fRemoteProxy
.getRemoteConnection().getName());
121 * Constructor (using default proxy)
124 * the name of the component
126 * the parent of the component
128 * the host connection implementation
130 public TargetNodeComponent(String name
, ITraceControlComponent parent
, @NonNull IRemoteConnection host
) {
131 this(name
, parent
, new RemoteSystemProxy(host
));
135 public void dispose() {
136 fRemoteProxy
.getRemoteConnection().removeConnectionChangeListener(this);
137 fRemoteProxy
.dispose();
138 disposeControlService();
141 private void disposeControlService() {
143 final ICommandShell shell
= fShell
;
150 // ------------------------------------------------------------------------
152 // ------------------------------------------------------------------------
155 public Image
getImage() {
156 if (fState
== TargetNodeState
.CONNECTED
) {
157 return super.getImage();
159 return fDisconnectedImage
;
163 public TargetNodeState
getTargetNodeState() {
168 public void setTargetNodeState(TargetNodeState state
) {
170 fireComponentChanged(TargetNodeComponent
.this);
174 public ILttngControlService
getControlService() {
175 return fService
== null ? NULL_CONTROL_SERVICE
: fService
;
179 public void setControlService(ILttngControlService service
) {
184 public Object
getAdapter(Class adapter
) {
185 if (adapter
== IPropertySource
.class) {
186 return new TargetNodePropertySource(this);
192 * @return remote system proxy implementation
194 public @NonNull RemoteSystemProxy
getRemoteSystemProxy() {
199 * @return all available sessions.
201 public TraceSessionComponent
[] getSessions() {
202 List
<ITraceControlComponent
> compenents
= getChildren(TraceSessionGroup
.class);
203 if (compenents
.size() > 0) {
204 TraceSessionGroup group
= (TraceSessionGroup
)compenents
.get(0);
205 List
<ITraceControlComponent
> sessions
= group
.getChildren(TraceSessionComponent
.class);
206 return sessions
.toArray(new TraceSessionComponent
[sessions
.size()]);
208 return new TraceSessionComponent
[0];
212 * @return node version
214 public String
getNodeVersion() {
215 // Control service is null during connection to node
216 if (getControlService() != NULL_CONTROL_SERVICE
) {
217 return getControlService().getVersionString();
219 return ""; //$NON-NLS-1$
223 * Returns if node supports filtering of events
224 * @return <code>true</code> if node supports filtering else <code>false</code>
226 public boolean isEventFilteringSupported() {
227 return getControlService().isVersionSupported("2.1.0"); //$NON-NLS-1$
231 * Returns if node supports networks streaming or not
232 * @return <code>true</code> if node supports filtering else <code>false</code>
235 public boolean isNetworkStreamingSupported() {
236 return getControlService().isVersionSupported("2.1.0"); //$NON-NLS-1$
240 * Returns if node supports configuring buffer type or not
241 * @return <code>true</code> if node supports buffer type configuration else <code>false</code>
243 public boolean isBufferTypeConfigSupported() {
244 return getControlService().isVersionSupported("2.2.0"); //$NON-NLS-1$
248 * Returns if node supports trace file rotation or not
249 * @return <code>true</code> if node supports trace file rotation else <code>false</code>
251 public boolean isTraceFileRotationSupported() {
252 return getControlService().isVersionSupported("2.2.0"); //$NON-NLS-1$
256 * Returns if node supports periodical flush for metadata or not
257 * @return <code>true</code> if node supports periodical flush for metadata else <code>false</code>
259 public boolean isPeriodicalMetadataFlushSupported() {
260 return getControlService().isVersionSupported("2.2.0"); //$NON-NLS-1$
263 * Returns if node supports snapshots or not
264 * @return <code>true</code> if it supports snapshots else <code>false</code>
267 public boolean isSnapshotSupported() {
268 return getControlService().isVersionSupported("2.3.0"); //$NON-NLS-1$
271 * Returns if node supports live or not
272 * @return <code>true</code> if it supports live else <code>false</code>
275 public boolean isLiveSupported() {
276 return getControlService().isVersionSupported("2.4.0"); //$NON-NLS-1$;
279 * Returns if node supports adding contexts on event
280 * @return <code>true</code> if it supports adding contexts on events else <code>false</code>
283 public boolean isContextOnEventSupported() {
284 return !getControlService().isVersionSupported("2.2.0"); //$NON-NLS-1$
288 * Checks if given version is supported by this ILTTngControlService implementation.
290 * @param version The version to check
291 * @return <code>true</code> if version is supported else <code>false</code>
293 public boolean isVersionSupported(String version
) {
294 return getControlService().isVersionSupported(version
);
297 // ------------------------------------------------------------------------
299 // ------------------------------------------------------------------------
302 public void connectionChanged(RemoteConnectionChangeEvent e
) {
303 if (fState
== TargetNodeState
.CONNECTING
) {
307 switch (e
.getType()) {
308 case RemoteConnectionChangeEvent
.CONNECTION_CLOSED
:
309 case RemoteConnectionChangeEvent
.CONNECTION_ABORTED
:
310 handleDisconnected();
312 case RemoteConnectionChangeEvent
.CONNECTION_OPENED
:
321 * Method to connect this node component to the remote target node.
323 public void connect() {
324 if (fState
== TargetNodeState
.DISCONNECTED
) {
326 setTargetNodeState(TargetNodeState
.CONNECTING
);
327 Job job
= new Job(format(Messages
.TraceControl_OpenConnectionTo
, getName())) {
329 protected IStatus
run(IProgressMonitor monitor
) {
331 fRemoteProxy
.connect(checkNotNull(monitor
));
332 return Status
.OK_STATUS
;
333 } catch (Exception e
) {
334 return new Status(IStatus
.ERROR
, Activator
.PLUGIN_ID
, Messages
.TraceControl_ConnectionFailure
, e
);
338 job
.addJobChangeListener(new JobChangeAdapter() {
340 public void done(IJobChangeEvent event
) {
341 IStatus status
= event
.getResult();
345 handleDisconnected();
346 if (status
.getSeverity() != IStatus
.CANCEL
) {
347 Activator
.getDefault().getLog().log(status
);
353 } catch (Exception e
) {
354 setTargetNodeState(TargetNodeState
.DISCONNECTED
);
355 Activator
.getDefault().logError(Messages
.TraceControl_ConnectionFailure
+ " (" + getName() + "). \n", e
); //$NON-NLS-1$ //$NON-NLS-2$
361 * Method to disconnect this node component to the remote target node.
363 public void disconnect() {
364 if (fState
== TargetNodeState
.CONNECTED
) {
366 setTargetNodeState(TargetNodeState
.DISCONNECTING
);
367 fRemoteProxy
.disconnect();
368 } catch (Exception e
) {
369 Activator
.getDefault().logError(Messages
.TraceControl_DisconnectionFailure
+ " (" + getName() + "). \n", e
); //$NON-NLS-1$ //$NON-NLS-2$
371 handleDisconnected();
377 * Retrieves the trace configuration from the target node and populates the
378 * information in the tree model. The execution is done in a own job.
380 public void getConfigurationFromNode() {
381 Job job
= new Job(Messages
.TraceControl_RetrieveNodeConfigurationJob
) {
383 protected IStatus
run(IProgressMonitor monitor
) {
386 // Get provider information from node
387 TraceProviderGroup providerGroup
= new TraceProviderGroup(Messages
.TraceControl_ProviderDisplayName
, TargetNodeComponent
.this);
388 addChild(providerGroup
);
390 // Get session information from node
391 TraceSessionGroup sessionGroup
= new TraceSessionGroup(Messages
.TraceControl_AllSessionsDisplayName
, TargetNodeComponent
.this);
392 addChild(sessionGroup
);
394 providerGroup
.getProviderFromNode(monitor
);
395 sessionGroup
.getSessionsFromNode(monitor
);
396 } catch (ExecutionException e
) {
398 return new Status(IStatus
.ERROR
, Activator
.PLUGIN_ID
, Messages
.TraceControl_RetrieveNodeConfigurationFailure
, e
);
401 return Status
.OK_STATUS
;
409 * Refresh the node configuration
411 public void refresh() {
413 getConfigurationFromNode();
416 // ------------------------------------------------------------------------
418 // ------------------------------------------------------------------------
421 * @return returns the control service for LTTng specific commands.
422 * @throws ExecutionException
424 private ILttngControlService
createControlService() throws ExecutionException
{
425 if (fService
== null) {
427 ICommandShell shell
= fRemoteProxy
.createCommandShell();
429 fService
= LTTngControlServiceFactory
.getLttngControlService(shell
);
430 } catch (ExecutionException e
) {
431 disposeControlService();
439 * Handles the connected event.
441 private void handleConnected() {
443 createControlService();
444 getConfigurationFromNode();
445 // Set connected only after the control service has been created and the jobs for creating the
446 // sub-nodes are scheduled.
447 setTargetNodeState(TargetNodeState
.CONNECTED
);
448 } catch (final ExecutionException e
) {
449 // Disconnect only if no control service, otherwise stay connected.
450 if (getControlService() == NULL_CONTROL_SERVICE
) {
451 fState
= TargetNodeState
.CONNECTED
;
456 Display
.getDefault().asyncExec(new Runnable() {
459 ErrorDialog er
= new ErrorDialog(PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getShell(),
460 Messages
.TraceControl_ErrorTitle
, Messages
.TraceControl_RetrieveNodeConfigurationFailure
,
461 new Status(IStatus
.ERROR
, Activator
.PLUGIN_ID
, e
.getMessage(), e
),
466 Activator
.getDefault().logError(Messages
.TraceControl_RetrieveNodeConfigurationFailure
+ " (" + getName() + "). \n", e
); //$NON-NLS-1$ //$NON-NLS-2$
471 * Handles the disconnected event.
473 private void handleDisconnected() {
474 disposeControlService();
475 setTargetNodeState(TargetNodeState
.DISCONNECTED
);
480 public void addChild(ITraceControlComponent component
) {
481 if (getTargetNodeState() == TargetNodeState
.DISCONNECTED
) {
484 super.addChild(component
);