lttng.control: Add support for enabling syscall by name
[deliverable/tracecompass.git] / lttng / org.eclipse.tracecompass.lttng2.control.ui / src / org / eclipse / tracecompass / internal / lttng2 / control / ui / views / model / impl / TargetNodeComponent.java
1 /**********************************************************************
2 * Copyright (c) 2012, 2015 Ericsson
3 *
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
8 *
9 * Contributors:
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;
16
17 import static java.text.MessageFormat.format;
18 import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull;
19
20 import java.util.List;
21
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;
49
50 /**
51 * <p>
52 * Implementation of the trace node component.
53 * </p>
54 *
55 * @author Bernd Hufmann
56 */
57 public class TargetNodeComponent extends TraceControlComponent implements IRemoteConnectionChangeListener {
58
59 // ------------------------------------------------------------------------
60 // Constants
61 // ------------------------------------------------------------------------
62
63 /**
64 * Path to icon file for this component (state connected).
65 */
66 public static final String TARGET_NODE_CONNECTED_ICON_FILE = "icons/obj16/target_connected.gif"; //$NON-NLS-1$
67 /**
68 * Path to icon file for this component (state disconnected).
69 */
70 public static final String TARGET_NODE_DISCONNECTED_ICON_FILE = "icons/obj16/target_disconnected.gif"; //$NON-NLS-1$
71
72 private static final ILttngControlService NULL_CONTROL_SERVICE = new NullControlService();
73
74 // ------------------------------------------------------------------------
75 // Attributes
76 // ------------------------------------------------------------------------
77
78 /**
79 * The node connection state.
80 */
81 private TargetNodeState fState = TargetNodeState.DISCONNECTED;
82 /**
83 * The image to be displayed in state disconnected.
84 */
85 private Image fDisconnectedImage = null;
86 /**
87 * The remote proxy implementation.
88 */
89 private @NonNull RemoteSystemProxy fRemoteProxy;
90 /**
91 * The control service for LTTng specific commands.
92 */
93 private ILttngControlService fService = null;
94 /**
95 * The command shell for issuing commands.
96 */
97 private ICommandShell fShell = null;
98
99 // ------------------------------------------------------------------------
100 // Constructors
101 // ------------------------------------------------------------------------
102
103 /**
104 * Constructor
105 *
106 * @param name
107 * the name of the component
108 * @param parent
109 * the parent of the component
110 * @param proxy
111 * the remote proxy implementation
112 */
113 public TargetNodeComponent(String name, ITraceControlComponent parent, @NonNull RemoteSystemProxy proxy) {
114 super(name, parent);
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());
120 }
121
122 /**
123 * Constructor (using default proxy)
124 *
125 * @param name
126 * the name of the component
127 * @param parent
128 * the parent of the component
129 * @param host
130 * the host connection implementation
131 */
132 public TargetNodeComponent(String name, ITraceControlComponent parent, @NonNull IRemoteConnection host) {
133 this(name, parent, new RemoteSystemProxy(host));
134 }
135
136 @Override
137 public void dispose() {
138 fRemoteProxy.getRemoteConnection().removeConnectionChangeListener(this);
139 fRemoteProxy.dispose();
140 disposeControlService();
141 }
142
143 private void disposeControlService() {
144 fService = null;
145 final ICommandShell shell = fShell;
146 if (shell != null) {
147 shell.dispose();
148 fShell = null;
149 }
150 }
151
152 // ------------------------------------------------------------------------
153 // Accessors
154 // ------------------------------------------------------------------------
155
156 @Override
157 public Image getImage() {
158 if (fState == TargetNodeState.CONNECTED) {
159 return super.getImage();
160 }
161 return fDisconnectedImage;
162 }
163
164 @Override
165 public TargetNodeState getTargetNodeState() {
166 return fState;
167 }
168
169 @Override
170 public void setTargetNodeState(TargetNodeState state) {
171 fState = state;
172 fireComponentChanged(TargetNodeComponent.this);
173 }
174
175 @Override
176 public ILttngControlService getControlService() {
177 return fService == null ? NULL_CONTROL_SERVICE : fService;
178 }
179
180 @Override
181 public void setControlService(ILttngControlService service) {
182 fService = service;
183 }
184
185 @Override
186 public <T> @Nullable T getAdapter(Class<T> adapter) {
187 if (adapter == IPropertySource.class) {
188 return adapter.cast(new TargetNodePropertySource(this));
189 }
190 return null;
191 }
192
193 /**
194 * @return remote system proxy implementation
195 */
196 public @NonNull RemoteSystemProxy getRemoteSystemProxy() {
197 return fRemoteProxy;
198 }
199
200 /**
201 * @return all available sessions.
202 */
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()]);
209 }
210 return new TraceSessionComponent[0];
211 }
212
213 /**
214 * @return node version
215 */
216 public String getNodeVersion() {
217 // Control service is null during connection to node
218 if (getControlService() != NULL_CONTROL_SERVICE) {
219 return getControlService().getVersionString();
220 }
221 return ""; //$NON-NLS-1$
222 }
223
224 /**
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>
228 */
229 public boolean isEventFilteringSupported(TraceDomainType domain) {
230 if (domain.equals(TraceDomainType.KERNEL)) {
231 return getControlService().isVersionSupported("2.7.0"); //$NON-NLS-1$
232 }
233 return getControlService().isVersionSupported("2.1.0"); //$NON-NLS-1$
234 }
235
236 /**
237 * Returns if node supports networks streaming or not
238 * @return <code>true</code> if node supports filtering else <code>false</code>
239 *
240 */
241 public boolean isNetworkStreamingSupported() {
242 return getControlService().isVersionSupported("2.1.0"); //$NON-NLS-1$
243 }
244
245 /**
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>
248 */
249 public boolean isBufferTypeConfigSupported() {
250 return getControlService().isVersionSupported("2.2.0"); //$NON-NLS-1$
251 }
252
253 /**
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>
256 */
257 public boolean isTraceFileRotationSupported() {
258 return getControlService().isVersionSupported("2.2.0"); //$NON-NLS-1$
259 }
260
261 /**
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>
264 */
265 public boolean isPeriodicalMetadataFlushSupported() {
266 return getControlService().isVersionSupported("2.2.0"); //$NON-NLS-1$
267 }
268 /**
269 * Returns if node supports snapshots or not
270 * @return <code>true</code> if it supports snapshots else <code>false</code>
271 *
272 */
273 public boolean isSnapshotSupported() {
274 return getControlService().isVersionSupported("2.3.0"); //$NON-NLS-1$
275 }
276 /**
277 * Returns if node supports live or not
278 * @return <code>true</code> if it supports live else <code>false</code>
279 *
280 */
281 public boolean isLiveSupported() {
282 return false;
283 // FIXME: Disable Live support until we have a better implementation
284 //return getControlService().isVersionSupported("2.4.0"); //$NON-NLS-1$;
285 }
286 /**
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>
289 *
290 */
291 public boolean isContextOnEventSupported() {
292 return !getControlService().isVersionSupported("2.2.0"); //$NON-NLS-1$
293 }
294
295 /**
296 * Checks if enabling of per syscall event is supported
297 *
298 * @return <code>true</code> if enabling of per syscall event is supported else <code>false</code>
299 */
300 public boolean isPerSyscallEventsSupported() {
301 return getControlService().isVersionSupported("2.6.0"); //$NON-NLS-1$
302 }
303
304 /**
305 * Checks if given version is supported by this ILTTngControlService implementation.
306 *
307 * @param version The version to check
308 * @return <code>true</code> if version is supported else <code>false</code>
309 */
310 public boolean isVersionSupported(String version) {
311 return getControlService().isVersionSupported(version);
312 }
313
314 // ------------------------------------------------------------------------
315 // Operations
316 // ------------------------------------------------------------------------
317
318 @Override
319 public void connectionChanged(RemoteConnectionChangeEvent e) {
320 if (fState == TargetNodeState.CONNECTING) {
321 return;
322 }
323
324 switch (e.getType()) {
325 case RemoteConnectionChangeEvent.CONNECTION_CLOSED:
326 case RemoteConnectionChangeEvent.CONNECTION_ABORTED:
327 handleDisconnected();
328 break;
329 case RemoteConnectionChangeEvent.CONNECTION_OPENED:
330 handleConnected();
331 break;
332 default:
333 break;
334 }
335 }
336
337 /**
338 * Method to connect this node component to the remote target node.
339 */
340 public void connect() {
341 if (fState == TargetNodeState.DISCONNECTED) {
342 try {
343 setTargetNodeState(TargetNodeState.CONNECTING);
344 Job job = new Job(format(Messages.TraceControl_OpenConnectionTo, getName())) {
345 @Override
346 protected IStatus run(IProgressMonitor monitor) {
347 try {
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);
352 }
353 }
354 };
355 job.addJobChangeListener(new JobChangeAdapter() {
356 @Override
357 public void done(IJobChangeEvent event) {
358 IStatus status = event.getResult();
359 if (status.isOK()) {
360 handleConnected();
361 } else {
362 handleDisconnected();
363 if (status.getSeverity() != IStatus.CANCEL) {
364 Activator.getDefault().getLog().log(status);
365 }
366 }
367 }
368 });
369 job.schedule();
370 } catch (Exception e) {
371 setTargetNodeState(TargetNodeState.DISCONNECTED);
372 Activator.getDefault().logError(Messages.TraceControl_ConnectionFailure + " (" + getName() + "). \n", e); //$NON-NLS-1$ //$NON-NLS-2$
373 }
374 }
375 }
376
377 /**
378 * Method to disconnect this node component to the remote target node.
379 */
380 public void disconnect() {
381 if (fState == TargetNodeState.CONNECTED) {
382 try {
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$
387 } finally {
388 handleDisconnected();
389 }
390 }
391 }
392
393 /**
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.
396 */
397 public void getConfigurationFromNode() {
398 Job job = new Job(Messages.TraceControl_RetrieveNodeConfigurationJob) {
399 @Override
400 protected IStatus run(IProgressMonitor monitor) {
401
402 try {
403 // Get provider information from node
404 TraceProviderGroup providerGroup = new TraceProviderGroup(Messages.TraceControl_ProviderDisplayName, TargetNodeComponent.this);
405 addChild(providerGroup);
406
407 // Get session information from node
408 TraceSessionGroup sessionGroup = new TraceSessionGroup(Messages.TraceControl_AllSessionsDisplayName, TargetNodeComponent.this);
409 addChild(sessionGroup);
410
411 providerGroup.getProviderFromNode(monitor);
412 sessionGroup.getSessionsFromNode(monitor);
413 } catch (ExecutionException e) {
414 removeAllChildren();
415 return new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.TraceControl_RetrieveNodeConfigurationFailure, e);
416 }
417
418 return Status.OK_STATUS;
419 }
420 };
421 job.setUser(true);
422 job.schedule();
423 }
424
425 /**
426 * Refresh the node configuration
427 */
428 public void refresh() {
429 removeAllChildren();
430 getConfigurationFromNode();
431 }
432
433 // ------------------------------------------------------------------------
434 // Helper function
435 // ------------------------------------------------------------------------
436
437 /**
438 * @return returns the control service for LTTng specific commands.
439 * @throws ExecutionException
440 */
441 private ILttngControlService createControlService() throws ExecutionException {
442 if (fService == null) {
443 try {
444 ICommandShell shell = fRemoteProxy.createCommandShell();
445 fShell = shell;
446 fService = LTTngControlServiceFactory.getLttngControlService(shell);
447 } catch (ExecutionException e) {
448 disposeControlService();
449 throw e;
450 }
451 }
452 return fService;
453 }
454
455 /**
456 * Handles the connected event.
457 */
458 private void handleConnected() {
459 try {
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;
469 disconnect();
470 }
471
472 // Notify user
473 Display.getDefault().asyncExec(new Runnable() {
474 @Override
475 public void run() {
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),
479 IStatus.ERROR);
480 er.open();
481 }
482 });
483 Activator.getDefault().logError(Messages.TraceControl_RetrieveNodeConfigurationFailure + " (" + getName() + "). \n", e); //$NON-NLS-1$ //$NON-NLS-2$
484 }
485 }
486
487 /**
488 * Handles the disconnected event.
489 */
490 private void handleDisconnected() {
491 disposeControlService();
492 setTargetNodeState(TargetNodeState.DISCONNECTED);
493 removeAllChildren();
494 }
495
496 @Override
497 public void addChild(ITraceControlComponent component) {
498 if (getTargetNodeState() == TargetNodeState.DISCONNECTED) {
499 return;
500 }
501 super.addChild(component);
502 }
503 }
This page took 0.074309 seconds and 5 git commands to generate.