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