Commit | Line | Data |
---|---|---|
eb1bab5b | 1 | /********************************************************************** |
ba3a9bd2 | 2 | * Copyright (c) 2012, 2013 Ericsson |
cfdb727a | 3 | * |
eb1bab5b BH |
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 | |
cfdb727a AM |
8 | * |
9 | * Contributors: | |
eb1bab5b | 10 | * Bernd Hufmann - Initial API and implementation |
ba3a9bd2 | 11 | * Bernd Hufmann - Updated for support of LTTng Tools 2.1 |
eb1bab5b | 12 | **********************************************************************/ |
115b4a01 | 13 | package org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl; |
eb1bab5b | 14 | |
6503ae0f BH |
15 | import java.util.List; |
16 | ||
eb1bab5b BH |
17 | import org.eclipse.core.commands.ExecutionException; |
18 | import org.eclipse.core.runtime.IProgressMonitor; | |
19 | import org.eclipse.core.runtime.IStatus; | |
20 | import org.eclipse.core.runtime.Status; | |
21 | import org.eclipse.core.runtime.jobs.Job; | |
973e19d6 | 22 | import org.eclipse.jface.dialogs.ErrorDialog; |
9315aeee | 23 | import org.eclipse.linuxtools.internal.lttng2.core.control.model.TargetNodeState; |
115b4a01 | 24 | import org.eclipse.linuxtools.internal.lttng2.ui.Activator; |
9315aeee | 25 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.messages.Messages; |
115b4a01 | 26 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.ITraceControlComponent; |
115b4a01 | 27 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.property.TargetNodePropertySource; |
9315aeee | 28 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.remote.ICommandShell; |
115b4a01 BH |
29 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.remote.IRemoteSystemProxy; |
30 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.remote.RemoteSystemProxy; | |
115b4a01 | 31 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService; |
276c17e7 | 32 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.LTTngControlServiceFactory; |
8577ed1e | 33 | import org.eclipse.rse.core.RSECorePlugin; |
eb1bab5b BH |
34 | import org.eclipse.rse.core.model.IHost; |
35 | import org.eclipse.rse.core.model.IRSECallback; | |
8577ed1e | 36 | import org.eclipse.rse.core.model.ISystemRegistry; |
eb1bab5b BH |
37 | import org.eclipse.rse.core.subsystems.CommunicationsEvent; |
38 | import org.eclipse.rse.core.subsystems.ICommunicationsListener; | |
39 | import org.eclipse.swt.graphics.Image; | |
973e19d6 BH |
40 | import org.eclipse.swt.widgets.Display; |
41 | import org.eclipse.ui.PlatformUI; | |
eb1bab5b BH |
42 | import org.eclipse.ui.views.properties.IPropertySource; |
43 | ||
44 | /** | |
eb1bab5b BH |
45 | * <p> |
46 | * Implementation of the trace node component. | |
47 | * </p> | |
cfdb727a | 48 | * |
dbd4432d | 49 | * @author Bernd Hufmann |
eb1bab5b BH |
50 | */ |
51 | public class TargetNodeComponent extends TraceControlComponent implements ICommunicationsListener { | |
52 | ||
53 | // ------------------------------------------------------------------------ | |
54 | // Constants | |
55 | // ------------------------------------------------------------------------ | |
11252342 | 56 | |
eb1bab5b BH |
57 | /** |
58 | * Path to icon file for this component (state connected). | |
59 | */ | |
60 | public static final String TARGET_NODE_CONNECTED_ICON_FILE = "icons/obj16/target_connected.gif"; //$NON-NLS-1$ | |
61 | /** | |
62 | * Path to icon file for this component (state disconnected). | |
63 | */ | |
64 | public static final String TARGET_NODE_DISCONNECTED_ICON_FILE = "icons/obj16/target_disconnected.gif"; //$NON-NLS-1$ | |
65 | ||
66 | // ------------------------------------------------------------------------ | |
67 | // Attributes | |
68 | // ------------------------------------------------------------------------ | |
11252342 | 69 | |
eb1bab5b BH |
70 | /** |
71 | * The node connection state. | |
72 | */ | |
73 | private TargetNodeState fState = TargetNodeState.DISCONNECTED; | |
74 | /** | |
75 | * The image to be displayed in state disconnected. | |
76 | */ | |
77 | private Image fDisconnectedImage = null; | |
78 | /** | |
79 | * The connection implementation. | |
80 | */ | |
81 | private IHost fHost = null; | |
82 | /** | |
83 | * The remote proxy implementation. | |
84 | */ | |
85 | private IRemoteSystemProxy fRemoteProxy = null; | |
86 | /** | |
87 | * The control service for LTTng specific commands. | |
88 | */ | |
89 | private ILttngControlService fService = null; | |
90 | /** | |
91 | * The command shell for issuing commands. | |
92 | */ | |
93 | private ICommandShell fShell = null; | |
94 | ||
95 | // ------------------------------------------------------------------------ | |
96 | // Constructors | |
97 | // ------------------------------------------------------------------------ | |
11252342 | 98 | |
eb1bab5b | 99 | /** |
cfdb727a | 100 | * Constructor |
eb1bab5b BH |
101 | * @param name - the name of the component |
102 | * @param parent - the parent of the component | |
103 | * @param host - the host connection implementation | |
104 | * @param proxy - the remote proxy implementation | |
105 | */ | |
106 | public TargetNodeComponent(String name, ITraceControlComponent parent, IHost host, IRemoteSystemProxy proxy) { | |
107 | super(name, parent); | |
108 | setImage(TARGET_NODE_CONNECTED_ICON_FILE); | |
31a6a4e4 | 109 | fDisconnectedImage = Activator.getDefault().loadIcon(TARGET_NODE_DISCONNECTED_ICON_FILE); |
eb1bab5b BH |
110 | fHost = host; |
111 | fRemoteProxy = proxy; | |
112 | setToolTip(fHost.getHostName()); | |
113 | } | |
114 | ||
115 | /** | |
cfdb727a | 116 | * Constructor (using default proxy) |
eb1bab5b BH |
117 | * @param name - the name of the component |
118 | * @param parent - the parent of the component | |
119 | * @param host - the host connection implementation | |
120 | */ | |
121 | public TargetNodeComponent(String name, ITraceControlComponent parent, IHost host) { | |
122 | this(name, parent, host, new RemoteSystemProxy(host)); | |
123 | } | |
124 | ||
125 | // ------------------------------------------------------------------------ | |
126 | // Accessors | |
127 | // ------------------------------------------------------------------------ | |
11252342 | 128 | |
eb1bab5b BH |
129 | @Override |
130 | public Image getImage() { | |
131 | if (fState == TargetNodeState.CONNECTED) { | |
132 | return super.getImage(); | |
133 | } | |
134 | return fDisconnectedImage; | |
135 | } | |
cfdb727a | 136 | |
eb1bab5b BH |
137 | @Override |
138 | public TargetNodeState getTargetNodeState() { | |
139 | return fState; | |
140 | } | |
cfdb727a | 141 | |
eb1bab5b BH |
142 | @Override |
143 | public void setTargetNodeState(TargetNodeState state) { | |
144 | fState = state; | |
4775bcbf | 145 | fireComponentChanged(TargetNodeComponent.this); |
eb1bab5b | 146 | } |
cfdb727a | 147 | |
eb1bab5b BH |
148 | @Override |
149 | public ILttngControlService getControlService() { | |
150 | return fService; | |
151 | } | |
152 | ||
eb1bab5b BH |
153 | @Override |
154 | public void setControlService(ILttngControlService service) { | |
cfdb727a | 155 | fService = service; |
eb1bab5b BH |
156 | } |
157 | ||
eb1bab5b BH |
158 | @Override |
159 | public Object getAdapter(Class adapter) { | |
160 | if (adapter == IPropertySource.class) { | |
161 | return new TargetNodePropertySource(this); | |
162 | } | |
163 | return null; | |
cfdb727a AM |
164 | } |
165 | ||
bbb3538a BH |
166 | /** |
167 | * @return remote host name | |
168 | */ | |
eb1bab5b BH |
169 | public String getHostName() { |
170 | return fHost.getHostName(); | |
171 | } | |
172 | ||
bbb3538a BH |
173 | /** |
174 | * @return remote system proxy implementation | |
175 | */ | |
176 | public IRemoteSystemProxy getRemoteSystemProxy() { | |
177 | return fRemoteProxy; | |
178 | } | |
179 | ||
00de7b32 BH |
180 | /** |
181 | * @return port of IP connection (shell) to be used | |
182 | */ | |
183 | public int getPort() { | |
184 | return fRemoteProxy.getPort(); | |
185 | } | |
186 | ||
187 | /** | |
188 | * Sets the port of the IP connections of the shell | |
189 | * @param port - the IP port to set | |
190 | */ | |
191 | public void setPort(int port) { | |
192 | fRemoteProxy.setPort(port); | |
193 | } | |
194 | ||
6503ae0f BH |
195 | /** |
196 | * @return all available sessions. | |
197 | */ | |
198 | public TraceSessionComponent[] getSessions() { | |
199 | List<ITraceControlComponent> compenents = getChildren(TraceSessionGroup.class); | |
200 | if (compenents.size() > 0) { | |
cfdb727a | 201 | TraceSessionGroup group = (TraceSessionGroup)compenents.get(0); |
6503ae0f | 202 | List<ITraceControlComponent> sessions = group.getChildren(TraceSessionComponent.class); |
cfdb727a | 203 | return sessions.toArray(new TraceSessionComponent[sessions.size()]); |
6503ae0f BH |
204 | } |
205 | return new TraceSessionComponent[0]; | |
206 | } | |
cfdb727a | 207 | |
cfe737e4 BH |
208 | /** |
209 | * @return node version | |
210 | */ | |
211 | public String getNodeVersion() { | |
212 | // Control service is null during connection to node | |
213 | if (getControlService() != null) { | |
214 | return getControlService().getVersion(); | |
215 | } | |
216 | return ""; //$NON-NLS-1$ | |
217 | } | |
218 | ||
d4514365 BH |
219 | /** |
220 | * Returns if node supports filtering of events | |
221 | * @return <code>true</code> if node supports filtering else <code>false</code> | |
222 | */ | |
223 | public boolean isEventFilteringSupported() { | |
224 | return getControlService().isVersionSupported("2.1.0"); //$NON-NLS-1$ | |
225 | } | |
226 | ||
f3b33d40 BH |
227 | /** |
228 | * Returns if node supports networks streaming or not | |
229 | * @return <code>true</code> if node supports filtering else <code>false</code> | |
ba3a9bd2 | 230 | * |
f3b33d40 BH |
231 | */ |
232 | public boolean isNetworkStreamingSupported() { | |
233 | return getControlService().isVersionSupported("2.1.0"); //$NON-NLS-1$ | |
234 | } | |
235 | ||
e799e5f3 | 236 | /** |
83051fc3 BH |
237 | * Returns if node supports configuring buffer type or not |
238 | * @return <code>true</code> if node supports buffer type configuration else <code>false</code> | |
e799e5f3 | 239 | */ |
83051fc3 | 240 | public boolean isBufferTypeConfigSupported() { |
e799e5f3 SD |
241 | return getControlService().isVersionSupported("2.2.0"); //$NON-NLS-1$ |
242 | } | |
243 | ||
244 | /** | |
245 | * Returns if node supports trace file rotation or not | |
246 | * @return <code>true</code> if node supports trace file rotation else <code>false</code> | |
247 | */ | |
248 | public boolean isTraceFileRotationSupported() { | |
249 | return getControlService().isVersionSupported("2.2.0"); //$NON-NLS-1$ | |
250 | } | |
251 | ||
252 | /** | |
253 | * Returns if node supports periodical flush for metadata or not | |
254 | * @return <code>true</code> if node supports periodical flush for metadata else <code>false</code> | |
255 | */ | |
256 | public boolean isPeriodicalMetadataFlushSupported() { | |
257 | return getControlService().isVersionSupported("2.2.0"); //$NON-NLS-1$ | |
258 | } | |
589d0d33 BH |
259 | /** |
260 | * Returns if node supports snapshots or not | |
261 | * @return <code>true</code> if it supports snapshots else <code>false</code> | |
262 | * | |
263 | */ | |
264 | public boolean isSnapshotSupported() { | |
265 | return getControlService().isVersionSupported("2.3.0"); //$NON-NLS-1$ | |
266 | } | |
e799e5f3 | 267 | |
eb1bab5b BH |
268 | // ------------------------------------------------------------------------ |
269 | // Operations | |
270 | // ------------------------------------------------------------------------ | |
cfdb727a | 271 | |
eb1bab5b BH |
272 | @Override |
273 | public void communicationsStateChange(CommunicationsEvent e) { | |
274 | if (e.getState() == CommunicationsEvent.AFTER_DISCONNECT || | |
275 | e.getState() == CommunicationsEvent.CONNECTION_ERROR) { | |
276 | handleDisconnected(); | |
277 | } if ((e.getState() == CommunicationsEvent.AFTER_CONNECT) && (fState != TargetNodeState.CONNECTING)) { | |
278 | handleConnected(); | |
279 | } | |
280 | } | |
281 | ||
eb1bab5b BH |
282 | @Override |
283 | public boolean isPassiveCommunicationsListener() { | |
284 | return true; | |
285 | } | |
286 | ||
eb1bab5b BH |
287 | @Override |
288 | public void dispose() { | |
289 | fRemoteProxy.removeCommunicationListener(this); | |
290 | } | |
291 | ||
292 | /** | |
293 | * Method to connect this node component to the remote target node. | |
294 | */ | |
295 | public void connect() { | |
296 | if (fState == TargetNodeState.DISCONNECTED) { | |
297 | try { | |
298 | setTargetNodeState(TargetNodeState.CONNECTING); | |
299 | fRemoteProxy.connect(new IRSECallback() { | |
300 | @Override | |
301 | public void done(IStatus status, Object result) { | |
302 | // Note: result might be null! | |
303 | if(status.isOK()) { | |
304 | handleConnected(); | |
06b9339e BH |
305 | } else { |
306 | handleDisconnected(); | |
eb1bab5b BH |
307 | } |
308 | } | |
309 | }); | |
310 | } catch (Exception e) { | |
311 | setTargetNodeState(TargetNodeState.DISCONNECTED); | |
9fa32496 | 312 | Activator.getDefault().logError(Messages.TraceControl_ConnectionFailure + " (" + getName() + "). \n", e); //$NON-NLS-1$ //$NON-NLS-2$ |
eb1bab5b BH |
313 | } |
314 | } | |
315 | } | |
316 | ||
317 | /** | |
318 | * Method to disconnect this node component to the remote target node. | |
319 | */ | |
320 | public void disconnect() { | |
321 | if (fState == TargetNodeState.CONNECTED) { | |
322 | try { | |
323 | setTargetNodeState(TargetNodeState.DISCONNECTING); | |
324 | fRemoteProxy.disconnect(); | |
325 | } catch (Exception e) { | |
9fa32496 | 326 | Activator.getDefault().logError(Messages.TraceControl_DisconnectionFailure + " (" + getName() + "). \n", e); //$NON-NLS-1$ //$NON-NLS-2$ |
eb1bab5b | 327 | } finally { |
cfdb727a | 328 | handleDisconnected(); |
eb1bab5b BH |
329 | } |
330 | } | |
331 | } | |
332 | ||
333 | /** | |
cfdb727a AM |
334 | * Retrieves the trace configuration from the target node and populates the |
335 | * information in the tree model. The execution is done in a own job. | |
eb1bab5b | 336 | */ |
d132bcc7 | 337 | public void getConfigurationFromNode() { |
eb1bab5b BH |
338 | Job job = new Job(Messages.TraceControl_RetrieveNodeConfigurationJob) { |
339 | @Override | |
340 | protected IStatus run(IProgressMonitor monitor) { | |
341 | ||
342 | try { | |
343 | // Get provider information from node | |
344 | TraceProviderGroup providerGroup = new TraceProviderGroup(Messages.TraceControl_ProviderDisplayName, TargetNodeComponent.this); | |
345 | addChild(providerGroup); | |
346 | providerGroup.getProviderFromNode(monitor); | |
cfdb727a | 347 | |
eb1bab5b BH |
348 | // Get session information from node |
349 | TraceSessionGroup sessionGroup = new TraceSessionGroup(Messages.TraceControl_AllSessionsDisplayName, TargetNodeComponent.this); | |
350 | addChild(sessionGroup); | |
351 | sessionGroup.getSessionsFromNode(monitor); | |
352 | } catch (ExecutionException e) { | |
353 | removeAllChildren(); | |
973e19d6 | 354 | return new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.TraceControl_RetrieveNodeConfigurationFailure, e); |
cfdb727a | 355 | } |
eb1bab5b BH |
356 | |
357 | return Status.OK_STATUS; | |
358 | } | |
359 | }; | |
360 | job.setUser(true); | |
361 | job.schedule(); | |
d132bcc7 | 362 | } |
eb1bab5b | 363 | |
8577ed1e BH |
364 | /** |
365 | * Refresh the node configuration | |
366 | */ | |
d132bcc7 BH |
367 | public void refresh() { |
368 | removeAllChildren(); | |
369 | getConfigurationFromNode(); | |
eb1bab5b | 370 | } |
cfdb727a | 371 | |
8577ed1e BH |
372 | /** |
373 | * Deregisters host from registry. | |
374 | */ | |
375 | public void deregister() { | |
376 | ISystemRegistry registry = RSECorePlugin.getTheSystemRegistry(); | |
377 | registry.deleteHost(fHost); | |
378 | } | |
eb1bab5b BH |
379 | |
380 | // ------------------------------------------------------------------------ | |
381 | // Helper function | |
382 | // ------------------------------------------------------------------------ | |
11252342 | 383 | |
eb1bab5b BH |
384 | /** |
385 | * @return returns the control service for LTTng specific commands. | |
386 | * @throws ExecutionException | |
387 | */ | |
388 | private ILttngControlService createControlService() throws ExecutionException { | |
389 | if (fShell == null) { | |
390 | fShell = fRemoteProxy.createCommandShell(); | |
391 | fRemoteProxy.addCommunicationListener(this); | |
392 | } | |
276c17e7 | 393 | fService = LTTngControlServiceFactory.getInstance().getLttngControlService(fShell); |
eb1bab5b BH |
394 | return fService; |
395 | } | |
396 | ||
397 | /** | |
cfdb727a | 398 | * Handles the connected event. |
eb1bab5b BH |
399 | */ |
400 | private void handleConnected() { | |
401 | setTargetNodeState(TargetNodeState.CONNECTED); | |
402 | try { | |
403 | createControlService(); | |
404 | getConfigurationFromNode(); | |
973e19d6 BH |
405 | } catch (final ExecutionException e) { |
406 | // Disconnect only if no control service, otherwise stay connected. | |
407 | if (getControlService() == null) { | |
408 | disconnect(); | |
409 | } | |
410 | ||
411 | // Notify user | |
412 | Display.getDefault().asyncExec(new Runnable() { | |
413 | @Override | |
414 | public void run() { | |
415 | ErrorDialog er = new ErrorDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), | |
416 | Messages.TraceControl_ErrorTitle, Messages.TraceControl_RetrieveNodeConfigurationFailure, | |
417 | new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e), | |
418 | IStatus.ERROR); | |
419 | er.open(); | |
420 | } | |
421 | }); | |
422 | Activator.getDefault().logError(Messages.TraceControl_RetrieveNodeConfigurationFailure + " (" + getName() + "). \n", e); //$NON-NLS-1$ //$NON-NLS-2$ | |
eb1bab5b BH |
423 | } |
424 | } | |
425 | ||
426 | /** | |
cfdb727a | 427 | * Handles the disconnected event. |
eb1bab5b BH |
428 | */ |
429 | private void handleDisconnected() { | |
430 | removeAllChildren(); | |
431 | setTargetNodeState(TargetNodeState.DISCONNECTED); | |
432 | fShell = null; | |
433 | fService = null; | |
434 | } | |
435 | } |