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