lttng: Support for existing live sessions
authorMarc-Andre Laperle <marc-andre.laperle@ericsson.com>
Fri, 17 Oct 2014 16:59:00 +0000 (12:59 -0400)
committerMarc-Andre Laperle <marc-andre.laperle@ericsson.com>
Mon, 27 Oct 2014 20:53:47 +0000 (16:53 -0400)
With this change, it is now possible to create a live session from the
command line and connect to it using the Control view as a live session.
We use the live timer interval as an indicator of whether or not a
session is live. The information about the host and the port is not
available with 'lttng list' but only local host is supported for now
anyway (127.0.0.1). For the port, we try use the default (5344). For
now, if the default port is incorrect, an error message "The connection
could not be established" is shown. As a future enhancement, there
should be a dialog to configure the relayd connection independently from
the session.

Change-Id: I9a56426ca011441ed5ebb3d8f936ababf6cdbce1
Signed-off-by: Marc-Andre Laperle <marc-andre.laperle@ericsson.com>
Reviewed-on: https://git.eclipse.org/r/35287
Tested-by: Hudson CI
Reviewed-by: Genevieve Bastien <gbastien+lttng@versatic.net>
Tested-by: Genevieve Bastien <gbastien+lttng@versatic.net>
Reviewed-by: Bernd Hufmann <bernd.hufmann@ericsson.com>
Tested-by: Bernd Hufmann <bernd.hufmann@ericsson.com>
org.eclipse.tracecompass.lttng2.control.core/src/org/eclipse/tracecompass/internal/lttng2/control/core/model/impl/SessionInfo.java
org.eclipse.tracecompass.lttng2.control.ui/src/org/eclipse/tracecompass/internal/lttng2/control/ui/relayd/LttngRelaydConsumer.java
org.eclipse.tracecompass.lttng2.control.ui/src/org/eclipse/tracecompass/internal/lttng2/control/ui/views/dialogs/CreateSessionDialog.java
org.eclipse.tracecompass.lttng2.control.ui/src/org/eclipse/tracecompass/internal/lttng2/control/ui/views/handlers/ImportHandler.java
org.eclipse.tracecompass.lttng2.control.ui/src/org/eclipse/tracecompass/internal/lttng2/control/ui/views/model/impl/TraceSessionComponent.java
org.eclipse.tracecompass.lttng2.control.ui/src/org/eclipse/tracecompass/internal/lttng2/control/ui/views/service/LTTngControlService.java
org.eclipse.tracecompass.lttng2.control.ui/src/org/eclipse/tracecompass/internal/lttng2/control/ui/views/service/LTTngControlServiceConstants.java

index d050c75e3d2bc86dcc4e671156c9bc6cfbe4814d..fafc039396da82121f3dba2dec98b9a353b8729e 100644 (file)
@@ -35,7 +35,12 @@ public class SessionInfo extends TraceInfo implements ISessionInfo {
     /**
      * The default network URL when creating a live session.
      */
-    public static final String DEFAULT_LIVE_NETWORK_URK = "net://127.0.0.1"; //$NON-NLS-1$
+    public static final String DEFAULT_LIVE_NETWORK_URL = "net://127.0.0.1"; //$NON-NLS-1$
+
+    /**
+     * The default live port for a live session.
+     */
+    public static final int DEFAULT_LIVE_PORT = 5344;
 
     // ------------------------------------------------------------------------
     // Attributes
index 523c57b69a191c4183924c0c2a4c6a75b3e97f95..2aa1b66512dacc05d8aad25be6b9bf802a5a5c2c 100644 (file)
@@ -16,6 +16,8 @@ import java.io.IOException;
 import java.io.UnsupportedEncodingException;
 import java.net.Socket;
 import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 
 import org.eclipse.core.runtime.CoreException;
 import org.eclipse.core.runtime.IProgressMonitor;
@@ -47,6 +49,7 @@ import org.eclipse.tracecompass.tmf.ctf.core.CtfTmfTrace;
  */
 public final class LttngRelaydConsumer {
 
+    private static final Pattern PROTOCOL_HOST_PATTERN = Pattern.compile("(\\S+://)*(\\d+\\.\\d+\\.\\d+\\.\\d+)"); //$NON-NLS-1$
     private static final int SIGNAL_THROTTLE_NANOSEC = 10_000_000;
     private static final String ENCODING_UTF_8 = "UTF-8"; //$NON-NLS-1$
 
@@ -104,7 +107,17 @@ public final class LttngRelaydConsumer {
         }
 
         try {
-            fConnection = new Socket(fConnectionInfo.getHost(), fConnectionInfo.getPort());
+            Matcher matcher = PROTOCOL_HOST_PATTERN.matcher(fConnectionInfo.getHost());
+            String host = null;
+            if (matcher.matches()) {
+                host = matcher.group(2);
+            }
+
+            if (host == null || host.isEmpty()) {
+                throw new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.LttngRelaydConsumer_ErrorConnecting));
+            }
+
+            fConnection = new Socket(host, fConnectionInfo.getPort());
             fRelayd = LttngRelaydConnectorFactory.getNewConnector(fConnection);
             List<SessionResponse> sessions = fRelayd.getSessions();
             SessionResponse selectedSession = null;
index d300ac262577397fa8417db7758ac8acc654479c..384b9091b68e8d242fc977ae782ab71c206a7ee9 100644 (file)
@@ -70,21 +70,6 @@ public class CreateSessionDialog extends TitleAreaDialog implements ICreateSessi
      */
     private static final String DEFAULT_TEXT = "<" + Messages.EnableChannelDialog_DefaultMessage + ">"; //$NON-NLS-1$ //$NON-NLS-2$
 
-    /**
-     * The default port for the connection to Relayd. This actual value is
-     * needed because this is not an optional argument to a command; this is
-     * what is used to connect directly to Relayd from Java through a socket.
-     * There is also currently no way to know the default value by issuing a
-     * command.
-     */
-    private static final int DEFAULT_LIVE_PORT = 5344;
-
-    /**
-     * The default address for the connection to Relayd. Only local is supported
-     * for now. See above comment for why it's needed.
-     */
-    private static final String DEFAULT_LIVE_URL = "127.0.0.1"; //$NON-NLS-1$
-
     /**
      * Supported network protocols for streaming
      */
@@ -723,7 +708,7 @@ public class CreateSessionDialog extends TitleAreaDialog implements ICreateSessi
             label.setLayoutData(layoutData);
 
             fLiveHostAddressText = new Text(fLiveGroup, SWT.NONE);
-            fLiveHostAddressText.setText(DEFAULT_LIVE_URL);
+            fLiveHostAddressText.setText(SessionInfo.DEFAULT_LIVE_NETWORK_URL);
             fLiveHostAddressText.setEnabled(false);
             fLiveHostAddressText.setToolTipText(Messages.TraceControl_CreateSessionLiveConnectionUrlTooltip);
             layoutData = new GridData(GridData.FILL_HORIZONTAL);
@@ -731,7 +716,7 @@ public class CreateSessionDialog extends TitleAreaDialog implements ICreateSessi
             fLiveHostAddressText.setLayoutData(layoutData);
 
             fLivePortText = new Text(fLiveGroup, SWT.NONE);
-            fLivePortText.setText(Integer.toString(DEFAULT_LIVE_PORT));
+            fLivePortText.setText(Integer.toString(SessionInfo.DEFAULT_LIVE_PORT));
             fLivePortText.setToolTipText(Messages.TraceControl_CreateSessionLiveConnectionPortTooltip);
             layoutData = new GridData(GridData.FILL_HORIZONTAL);
             fLivePortText.setLayoutData(layoutData);
@@ -823,8 +808,8 @@ public class CreateSessionDialog extends TitleAreaDialog implements ICreateSessi
         if (fParent.isLiveSupported() && fLiveButton != null) {
             fIsLive = fLiveButton.getSelection();
             fLiveDelay = LTTngControlServiceConstants.UNUSED_VALUE;
-            fLiveUrl = DEFAULT_LIVE_URL;
-            fLivePort = DEFAULT_LIVE_PORT;
+            fLiveUrl = SessionInfo.DEFAULT_LIVE_NETWORK_URL;
+            fLivePort = SessionInfo.DEFAULT_LIVE_PORT;
         }
 
         if (!"".equals(fSessionPath)) { //$NON-NLS-1$
@@ -922,7 +907,7 @@ public class CreateSessionDialog extends TitleAreaDialog implements ICreateSessi
         }
 
         if (fIsLive && fNetworkUrl == null && fControlUrl == null && fDataUrl == null) {
-            fNetworkUrl = SessionInfo.DEFAULT_LIVE_NETWORK_URK;
+            fNetworkUrl = SessionInfo.DEFAULT_LIVE_NETWORK_URL;
         }
 
         // Check for invalid names
index fef5685344beae972249b34197c75f8b9d09d726..eaf5d00eee260e5b18d7f52dbfcda4d53037b894 100644 (file)
@@ -329,7 +329,7 @@ public class ImportHandler extends BaseControlViewHandler {
                     try {
                         lttngRelaydConsumer.connect();
                     } catch (CoreException e) {
-                        new Status(IStatus.ERROR, Activator.PLUGIN_ID, org.eclipse.tracecompass.internal.lttng2.control.ui.relayd.Messages.LttngRelaydConnectionManager_ConnectionError, e);
+                        return new Status(IStatus.ERROR, Activator.PLUGIN_ID, org.eclipse.tracecompass.internal.lttng2.control.ui.relayd.Messages.LttngRelaydConnectionManager_ConnectionError, e);
                     }
                     initializeTraceResource(connectionInfo, lttngRelaydConsumer.getTracePath(), project);
                     return Status.OK_STATUS;
index 3b37b6af69802f3abedfa24dc6b5a7eb2ae876e6..2575b92df5bb85dbbdf7201743cff84a8d2f7ebc 100644 (file)
@@ -109,10 +109,12 @@ public class TraceSessionComponent extends TraceControlComponent {
 
     private void copyLiveInfo(ISessionInfo sessionInfo) {
         // Since we can't retrieve this information from the node, we copy it over
-        fSessionInfo.setLive(sessionInfo.isLive());
-        fSessionInfo.setLiveDelay(sessionInfo.getLiveDelay());
-        fSessionInfo.setLivePort(sessionInfo.getLivePort());
-        fSessionInfo.setLiveUrl(sessionInfo.getLiveUrl());
+        if (sessionInfo.getLivePort() != null) {
+            fSessionInfo.setLivePort(sessionInfo.getLivePort());
+        }
+        if (sessionInfo.getLiveUrl() != null) {
+            fSessionInfo.setLiveUrl(sessionInfo.getLiveUrl());
+        }
     }
 
     // ------------------------------------------------------------------------
index 260b7ff22e546f2efe7193da61cd2153cc802680..8ea853fbfb1f9fa7f782e1f58b29854db2c0024f 100644 (file)
@@ -282,6 +282,19 @@ public class LTTngControlService implements ILttngControlService {
                 }
                 continue;
             }
+            matcher = LTTngControlServiceConstants.LIST_LIVE_TIMER_INTERVAL_PATTERN.matcher(line);
+            if (matcher.matches()) {
+                int liveDelay = Integer.parseInt(matcher.group(1));
+                if (liveDelay > 0) {
+                    sessionInfo.setLive(true);
+                    sessionInfo.setLiveUrl(SessionInfo.DEFAULT_LIVE_NETWORK_URL);
+                    sessionInfo.setLivePort(SessionInfo.DEFAULT_LIVE_PORT);
+                    sessionInfo.setLiveDelay(liveDelay);
+                }
+                index++;
+                continue;
+            }
+
             index++;
         }
 
index 1e8a7873365e218bfbca82bf07d034f02c836c2f..79fb5c239a831e53b9c9abd90be922d81f8ce098 100644 (file)
@@ -447,6 +447,10 @@ public interface LTTngControlServiceConstants {
      * Pattern to match for list snapshot information (lttng snapshot list-output)
      */
     static final Pattern LIST_SNAPSHOT_OUTPUT_PATTERN = Pattern.compile("\\s+\\[(\\d+)\\]\\s+(\\S*)\\:\\s+(\\S*)(.*)"); //$NON-NLS-1$
+    /**
+     * Pattern to match the live timer interval line of session list.
+     */
+    static final Pattern LIST_LIVE_TIMER_INTERVAL_PATTERN = Pattern.compile("\\s*Live\\stimer\\sinterval\\s\\(usec\\):\\s(\\d+)"); //$NON-NLS-1$
     /**
      * Pattern to match snapshot path for network tracing (lttng list <session>)
      * Note: file for protocol is not considered as network trace since local consumer will be used.
This page took 0.03127 seconds and 5 git commands to generate.