lttng ui: fix handling of command output for verbose commands
authorBernd Hufmann <bhufmann@gmail.com>
Wed, 6 Mar 2013 18:17:35 +0000 (13:17 -0500)
committerBernd Hufmann <bhufmann@gmail.com>
Wed, 6 Mar 2013 19:55:25 +0000 (14:55 -0500)
When executing commands with preference verbose the command output
parsing of certain commands were not correct and caused
ExecutionExceptions in Eclipse even if the command was successfully
executed. This has been corrected with this commit. Also, this
commit contains JUnit tests to verify the updates.

Change-Id: I24196959a28093a292f599f93f6b78f6fd76c69e
Signed-off-by: Bernd Hufmann <bhufmann@gmail.com>
Reviewed-on: https://git.eclipse.org/r/10864
Tested-by: Hudson CI
Reviewed-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
IP-Clean: Matthew Khouzam <matthew.khouzam@ericsson.com>
Tested-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
org.eclipse.linuxtools.lttng2.ui.tests/src/org/eclipse/linuxtools/lttng2/ui/tests/control/service/LTTngControlServiceTest.java
org.eclipse.linuxtools.lttng2.ui.tests/testfiles/LTTngServiceTest.cfg
org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/service/LTTngControlService.java
org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/service/LTTngControlServiceConstants.java
org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/service/LTTngControlServiceFactory.java

index 2c991064789c41099a89fdb1254b41f06c5469ff..2d23d2c3b3d4ac8db0f8c5f1434b92bbce173826 100644 (file)
 
 package org.eclipse.linuxtools.lttng2.ui.tests.control.service;
 
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
 
 import java.io.File;
 import java.net.URL;
@@ -41,9 +44,13 @@ import org.eclipse.linuxtools.internal.lttng2.core.control.model.TraceSessionSta
 import org.eclipse.linuxtools.internal.lttng2.core.control.model.impl.ChannelInfo;
 import org.eclipse.linuxtools.internal.lttng2.stubs.service.CommandShellFactory;
 import org.eclipse.linuxtools.internal.lttng2.stubs.shells.LTTngToolsFileShell;
+import org.eclipse.linuxtools.internal.lttng2.ui.Activator;
+import org.eclipse.linuxtools.internal.lttng2.ui.views.control.logging.ControlCommandLogger;
+import org.eclipse.linuxtools.internal.lttng2.ui.views.control.preferences.ControlPreferences;
 import org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService;
 import org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.LTTngControlService;
 import org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.LTTngControlServiceFactory;
+import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
 import org.osgi.framework.FrameworkUtil;
@@ -66,11 +73,13 @@ public class LTTngControlServiceTest {
     private static final String SCEN_NO_SESSION_AVAILABLE = "NoSessionAvailable";
     private static final String SCEN_GET_SESSION_NAMES1 = "GetSessionNames1";
     private static final String SCEN_GET_SESSION_NAME_NOT_EXIST = "GetSessionNameNotExist";
+    private static final String SCEN_GET_SESSION_NAME_NOT_EXIST_VERBOSE = "GetSessionNameNotExistVerbose";
     private static final String SCEN_GET_SESSION_GARBAGE_OUT = "GetSessionGarbageOut";
     private static final String SCEN_GET_SESSION1 = "GetSession1";
     private static final String SCEN_GET_KERNEL_PROVIDER1 = "GetKernelProvider1";
     private static final String SCEN_LIST_WITH_NO_KERNEL1 = "ListWithNoKernel1";
     private static final String SCEN_LIST_WITH_NO_KERNEL2 = "ListWithNoKernel2";
+    private static final String SCEN_LIST_WITH_NO_KERNEL_VERBOSE = "ListWithNoKernelVerbose";
     private static final String SCEN_GET_UST_PROVIDER1 = "GetUstProvider1";
     private static final String SCEN_GET_UST_PROVIDER2 = "GetUstProvider2";
     private static final String SCEN_GET_UST_PROVIDER3 = "GetUstProvider3";
@@ -78,12 +87,14 @@ public class LTTngControlServiceTest {
     private static final String SCEN_CREATE_SESSION_WITH_PROMPT = "CreateSessionWithPrompt";
     private static final String SCEN_CREATE_SESSION_VARIANTS = "CreateSessionVariants";
     private static final String SCEN_DESTROY_SESSION1 = "DestroySession1";
+    private static final String SCEN_DESTROY_SESSION_VERBOSE = "DestroySessionVerbose";
     private static final String SCEN_CHANNEL_HANDLING = "ChannelHandling";
     private static final String SCEN_EVENT_HANDLING = "EventHandling";
     private static final String SCEN_CONTEXT_HANDLING = "ContextHandling";
     private static final String SCEN_CONTEXT_ERROR_HANDLING = "ContextErrorHandling";
     private static final String SCEN_CALIBRATE_HANDLING = "CalibrateHandling";
     private static final String SCEN_CREATE_SESSION_2_1 = "CreateSessionLttng2.1";
+    private static final String SCEN_CREATE_SESSION_VERBOSE_2_1 = "CreateSessionLttngVerbose2.1";
 
     // ------------------------------------------------------------------------
     // Test data
@@ -115,6 +126,14 @@ public class LTTngControlServiceTest {
         fShell = fShellFactory.getFileShell();
         fShell.loadScenarioFile(fTestfile);
         fService = new LTTngControlService(fShell);
+
+        ControlPreferences.getInstance().init(Activator.getDefault().getPreferenceStore());
+    }
+
+    @After
+    public void tearDown() {
+        disableVerbose();
+        ControlPreferences.getInstance().dispose();
     }
 
     // ------------------------------------------------------------------------
@@ -220,6 +239,21 @@ public class LTTngControlServiceTest {
         }
     }
 
+    @Test
+    public void testGetSessionNotExistVerbose() {
+        try {
+            enableVerbose();
+            fShell.setScenario(SCEN_GET_SESSION_NAME_NOT_EXIST_VERBOSE);
+            fService.getSessionNames(new NullProgressMonitor());
+            fail("No exeption thrown");
+
+        } catch (ExecutionException e) {
+            // success
+        } finally {
+            disableVerbose();
+        }
+    }
+
     @Test
     public void testGetSessionNameGarbage() {
         try {
@@ -412,6 +446,24 @@ public class LTTngControlServiceTest {
         }
     }
 
+    @Test
+    public void testGetKernelProviderNoKernelVerbose() {
+        try {
+            enableVerbose();
+            fShell.setScenario(SCEN_LIST_WITH_NO_KERNEL_VERBOSE);
+            List<IBaseEventInfo> events = fService.getKernelProvider(new NullProgressMonitor());
+
+            // Verify event info
+            assertNotNull(events);
+            assertEquals(0, events.size());
+
+        } catch (ExecutionException e) {
+            fail(e.toString());
+        } finally {
+            disableVerbose();
+        }
+    }
+
     @Test
     public void testGetUstProvider() {
         try {
@@ -654,6 +706,19 @@ public class LTTngControlServiceTest {
         }
     }
 
+    @Test
+    public void testDestroySessionVerbose() {
+        try {
+            enableVerbose();
+            fShell.setScenario(SCEN_DESTROY_SESSION_VERBOSE);
+            fService.destroySession("mysession2", new NullProgressMonitor());
+        } catch (ExecutionException e) {
+            fail(e.toString());
+        } finally {
+            disableVerbose();
+        }
+    }
+
     @Test
     public void testCreateChannel() {
         try {
@@ -741,17 +806,6 @@ public class LTTngControlServiceTest {
         }
     }
 
-//    public void tesEnableChannelNoTracer() {
-//        try {
-//            ILttngControlService service = new LTTngControlService(fShellFactory.getShellForChannelNoTracer());
-//            service.getSessionNames(new NullProgressMonitor());
-//            fail("No exeption thrown");
-//
-//        } catch (ExecutionException e) {
-//            // success
-//        }
-//    }
-
     @Test
     public void testEnableEvents() {
         try {
@@ -966,20 +1020,20 @@ public class LTTngControlServiceTest {
             assertNotNull(info);
             assertEquals("mysession", info.getName());
             assertEquals("file:///tmp", info.getSessionPath());
-            assertTrue(info.isStreamedTrace());
+            assertTrue(!info.isStreamedTrace());
             fService.destroySession("mysession", new NullProgressMonitor());
 
             info = fService.createSession("mysession", "file:///tmp", null, null, new NullProgressMonitor());
             assertNotNull(info);
             assertEquals("mysession", info.getName());
             assertEquals("file:///tmp", info.getSessionPath());
-            assertTrue(info.isStreamedTrace());
+            assertTrue(!info.isStreamedTrace());
             fService.destroySession("mysession", new NullProgressMonitor());
 
             info = fService.createSession("mysession", null, "tcp://172.0.0.1", "tcp://172.0.0.1:5343", new NullProgressMonitor());
             assertNotNull(info);
             assertEquals("mysession", info.getName());
-            assertEquals("", info.getSessionPath()); // TODO: currently there is a bug in LTTng tracer and it returns string null
+            assertEquals("", info.getSessionPath()); // the complete network path is not available at this point
             assertTrue(info.isStreamedTrace());
             fService.destroySession("mysession", new NullProgressMonitor());
 
@@ -990,8 +1044,51 @@ public class LTTngControlServiceTest {
             assertTrue(info.isStreamedTrace());
             fService.destroySession("mysession", new NullProgressMonitor());
 
+            // verbose
+            enableVerbose();
+            info = fService.createSession("mysession", "net://172.0.0.1", null, null, new NullProgressMonitor());
+            assertNotNull(info);
+            assertEquals("mysession", info.getName());
+            assertEquals("net://172.0.0.1", info.getSessionPath());
+            assertTrue(info.isStreamedTrace());
+            disableVerbose();
+            fService.destroySession("mysession", new NullProgressMonitor());
+
+
+        } catch (ExecutionException e) {
+            fail(e.toString());
+        }
+    }
+
+    @Test
+    public void testCreateSessionVerbose2_1() {
+        try {
+            fShell.setScenario(SCEN_CREATE_SESSION_VERBOSE_2_1);
+
+            enableVerbose();
+            ISessionInfo info = fService.createSession("mysession", "net://172.0.0.1", null, null, new NullProgressMonitor());
+            assertNotNull(info);
+            assertEquals("mysession", info.getName());
+            assertEquals("net://172.0.0.1", info.getSessionPath());
+            assertTrue(info.isStreamedTrace());
+            fService.destroySession("mysession", new NullProgressMonitor());
         } catch (ExecutionException e) {
             fail(e.toString());
+        } finally {
+            disableVerbose();
         }
     }
+
+    private static void enableVerbose() {
+        // verbose
+        ControlCommandLogger.init(ControlPreferences.getInstance().getLogfilePath(), false);
+        ControlPreferences.getInstance().getPreferenceStore().setDefault(ControlPreferences.TRACE_CONTROL_LOG_COMMANDS_PREF, true);
+        ControlPreferences.getInstance().getPreferenceStore().setDefault(ControlPreferences.TRACE_CONTROL_VERBOSE_LEVEL_PREF, ControlPreferences.TRACE_CONTROL_VERBOSE_LEVEL_V_V_VERBOSE);
+    }
+
+    private static void disableVerbose() {
+        ControlPreferences.getInstance().getPreferenceStore().setDefault(ControlPreferences.TRACE_CONTROL_LOG_COMMANDS_PREF, false);
+    }
+
+
 }
index 9c6e49573fe89d29cfbd895ce1ffc067c799a4c9..e9341e54d505a8d015952de92943023ec51b1946 100644 (file)
@@ -155,6 +155,26 @@ Error: Session name not found
 </COMMAND_OUTPUT>
 </SCENARIO>
 
+####################################################################
+# Scenario: Test lttng -vvv list <name> where session doesn't exist
+####################################################################
+<SCENARIO>
+GetSessionNameNotExistVerbose
+<COMMAND_INPUT>
+lttng -vvv  list test
+</COMMAND_INPUT>
+<COMMAND_RESULT>
+1
+</COMMAND_RESULT>
+<COMMAND_OUTPUT>
+DEBUG2: Session name: test [in cmd_list() at commands/list.c:618]
+DEBUG1: Session count 1 [in list_sessions() at commands/list.c:485]
+Error: Session 'test' not found
+Error: Command error
+DEBUG1: Clean exit [in clean_exit() at lttng.c:165]
+</COMMAND_OUTPUT>
+</SCENARIO>
+
 ####################################################################
 # Scenario: Test lttng list with garbage output 
 ####################################################################
@@ -319,6 +339,25 @@ Error: Unable to list kernel events
 </COMMAND_OUTPUT>
 </SCENARIO>
 
+####################################################################
+# Scenario: Test "lttng list -k" with no kernel, with session daemon and verbose
+####################################################################
+<SCENARIO>
+ListWithNoKernelVerbose
+<COMMAND_INPUT>
+lttng -vvv  list -k
+</COMMAND_INPUT>
+<COMMAND_RESULT>
+1
+</COMMAND_RESULT>
+<COMMAND_OUTPUT>
+DEBUG2: Session name: (null) [in cmd_list() at commands/list.c:618]
+DEBUG1: Getting kernel tracing events [in list_kernel_events() at commands/list.c:309]
+Error: Unable to list kernel events
+DEBUG1: Clean exit [in clean_exit() at lttng.c:165]
+</COMMAND_OUTPUT>
+</SCENARIO>
+
 ####################################################################
 # Scenario: Test "lttng list -u" with sample output 
 ####################################################################
@@ -509,6 +548,26 @@ Session mysession2 destroyed.
 </COMMAND_OUTPUT>
 </SCENARIO>
 
+####################################################################
+# Scenario: Test "lttng -vvv destroy <session>"
+####################################################################
+
+<SCENARIO>
+DestroySessionVerbose
+<COMMAND_INPUT>
+lttng -vvv  destroy mysession2
+</COMMAND_INPUT>
+<COMMAND_RESULT>
+0
+</COMMAND_RESULT>
+<COMMAND_OUTPUT>
+DEBUG2: Config file path found: /home/eedbhu [in get_session_name() at utils.c:98]
+DEBUG1: Session name found: mysession2 [in get_session_name() at utils.c:99]
+Session mysession2 destroyed at /home/eedbhu
+</COMMAND_OUTPUT>
+</SCENARIO>
+
+
 ####################################################################
 # Scenario: Test "lttng enable-channel ..." with different inputs 
 ####################################################################
@@ -902,4 +961,53 @@ lttng destroy mysession
 Session mysession destroyed.
 </COMMAND_OUTPUT>
 
+<COMMAND_INPUT>
+lttng -vvv  create mysession -U net://172.0.0.1
+</COMMAND_INPUT>
+<COMMAND_RESULT>
+0
+</COMMAND_RESULT>
+<COMMAND_OUTPUT>
+DEBUG3: URI string: net://172.0.0.1 [in uri_parse() at uri.c:253]
+DEBUG2: IP address resolved to 172.0.0.1 [in set_ip_address() at uri.c:132]
+DEBUG3: URI dtype: 1, proto: 1, host: 172.0.0.1, subdir: , ctrl: 0, data: 0 [in uri_parse() at uri.c:467]
+DEBUG1: LSM cmd type : 8 [in send_session_msg() at lttng-ctl.c:261]
+Session mysession created.
+Traces will be written in net://172.0.0.1
+DEBUG1: Init config session in /home/bernd [in config_init() at conf.c:294]
+</COMMAND_OUTPUT>
+
 </SCENARIO>
+
+####################################################################
+# Scenario: Test "lttng -vvv create <session> with LTTng 2.1 options"
+####################################################################
+<SCENARIO>
+CreateSessionLttngVerbose2.1
+<COMMAND_INPUT>
+lttng -vvv  create mysession -U net://172.0.0.1
+</COMMAND_INPUT>
+<COMMAND_RESULT>
+0
+</COMMAND_RESULT>
+<COMMAND_OUTPUT>
+DEBUG3: URI string: net://172.0.0.1 [in uri_parse() at uri.c:253]
+DEBUG2: IP address resolved to 172.0.0.1 [in set_ip_address() at uri.c:132]
+DEBUG3: URI dtype: 1, proto: 1, host: 172.0.0.1, subdir: , ctrl: 0, data: 0 [in uri_parse() at uri.c:467]
+DEBUG1: LSM cmd type : 8 [in send_session_msg() at lttng-ctl.c:261]
+Session mysession created.
+Traces will be written in net://172.0.0.1
+DEBUG1: Init config session in /home/bernd [in config_init() at conf.c:294]
+</COMMAND_OUTPUT>
+
+<COMMAND_INPUT>
+lttng -vvv  destroy mysession
+</COMMAND_INPUT>
+<COMMAND_RESULT>
+0
+</COMMAND_RESULT>
+<COMMAND_OUTPUT>
+Session mysession destroyed.
+</COMMAND_OUTPUT>
+
+</SCENARIO>
\ No newline at end of file
index fd056175be7c0b36642796b654501079544af7e6..294124e9cab5c78d503881807e22cd7ab516599e 100644 (file)
@@ -265,10 +265,14 @@ public class LTTngControlService implements ILttngControlService {
             // or:
             // Error: Unable to list kernel events
             //
-
-            if ((result.getOutput().length > 0) && (LTTngControlServiceConstants.LIST_KERNEL_NO_KERNEL_PROVIDER_PATTERN.matcher(result.getOutput()[0]).matches()) ||
-               ((result.getOutput().length > 1) && (LTTngControlServiceConstants.LIST_KERNEL_NO_KERNEL_PROVIDER_PATTERN.matcher(result.getOutput()[1]).matches()))) {
-                return events;
+            int index = 0;
+            while (index < result.getOutput().length) {
+                String line = result.getOutput()[index];
+                Matcher matcher = LTTngControlServiceConstants.LIST_KERNEL_NO_KERNEL_PROVIDER_PATTERN.matcher(line);
+                if (matcher.matches()) {
+                    return events;
+                }
+                index++;
             }
         }
 
@@ -380,19 +384,24 @@ public class LTTngControlService implements ILttngControlService {
         //Traces will be written in /home/user/lttng-traces/myssession2-20120209-095418
         String[] output = result.getOutput();
 
-        // Get and verify session name
-        Matcher matcher = LTTngControlServiceConstants.CREATE_SESSION_NAME_PATTERN.matcher(output[0]);
+        // Get and session name and path
         String name = null;
+        String path = null;
 
-        if (matcher.matches()) {
-            name = String.valueOf(matcher.group(1).trim());
-        } else {
-            // Output format not expected
-            throw new ExecutionException(Messages.TraceControl_CommandError + " " + command + "\n" + //$NON-NLS-1$ //$NON-NLS-2$
-                    Messages.TraceControl_UnexpectedCommandOutputFormat + ":\n" + //$NON-NLS-1$
-                    formatOutput(result));
+        int index = 0;
+        while (index < output.length) {
+            String line = output[index];
+            Matcher nameMatcher = LTTngControlServiceConstants.CREATE_SESSION_NAME_PATTERN.matcher(line);
+            Matcher pathMatcher = LTTngControlServiceConstants.CREATE_SESSION_PATH_PATTERN.matcher(line);
+            if (nameMatcher.matches()) {
+                name = String.valueOf(nameMatcher.group(1).trim());
+            } else if (pathMatcher.matches()) {
+                path = String.valueOf(pathMatcher.group(1).trim());
+            }
+            index++;
         }
 
+        // Verify session name
         if ((name == null) || (!"".equals(sessionName) && !name.equals(sessionName))) { //$NON-NLS-1$
             // Unexpected name returned
             throw new ExecutionException(Messages.TraceControl_CommandError + " " + command + "\n" + //$NON-NLS-1$ //$NON-NLS-2$
@@ -401,24 +410,13 @@ public class LTTngControlService implements ILttngControlService {
 
         SessionInfo sessionInfo = new SessionInfo(name);
 
-        // Get and verify session path
-        matcher = LTTngControlServiceConstants.CREATE_SESSION_PATH_PATTERN.matcher(output[1]);
-        String path = null;
-
-        if (matcher.matches()) {
-            path = String.valueOf(matcher.group(1).trim());
-        } else {
-            // Output format not expected
-            throw new ExecutionException(Messages.TraceControl_CommandError + " " + command + "\n" + //$NON-NLS-1$ //$NON-NLS-2$
-                    Messages.TraceControl_UnexpectedCommandOutputFormat + ":\n" + //$NON-NLS-1$
-                    formatOutput(result));
-        }
-
+        // Verify session path
         if ((path == null) || ((sessionPath != null) && (!path.contains(sessionPath)))) {
             // Unexpected path
             throw new ExecutionException(Messages.TraceControl_CommandError + " " + command + "\n" + //$NON-NLS-1$ //$NON-NLS-2$
                     Messages.TraceControl_UnexpectedPathError + ": " + name); //$NON-NLS-1$
         }
+
         sessionInfo.setSessionPath(path);
 
         return sessionInfo;
@@ -448,45 +446,56 @@ public class LTTngControlService implements ILttngControlService {
 
         ICommandResult result = executeCommand(command.toString(), monitor);
 
-        //Session myssession2 created.
-        //Traces will be written in /home/user/lttng-traces/myssession2-20120209-095418
+        // Verify output
         String[] output = result.getOutput();
 
-        // Get and verify session name
-        Matcher matcher = LTTngControlServiceConstants.CREATE_SESSION_NAME_PATTERN.matcher(output[0]);
+        // Get and session name and path
         String name = null;
+        String path = null;
 
-        if (matcher.matches()) {
-            name = String.valueOf(matcher.group(1).trim());
-        } else {
-            // Output format not expected
+        int index = 0;
+        while (index < output.length) {
+            String line = output[index];
+            Matcher nameMatcher = LTTngControlServiceConstants.CREATE_SESSION_NAME_PATTERN.matcher(line);
+            Matcher pathMatcher = LTTngControlServiceConstants.CREATE_SESSION_PATH_PATTERN.matcher(line);
+
+            if (nameMatcher.matches()) {
+                name = String.valueOf(nameMatcher.group(1).trim());
+            } else if (pathMatcher.matches() && (networkUrl != null)) {
+                path = String.valueOf(pathMatcher.group(1).trim());
+            }
+            index++;
+        }
+
+        // Verify session name
+        if ((name == null) || (!"".equals(sessionName) && !name.equals(sessionName))) { //$NON-NLS-1$
+            // Unexpected name returned
             throw new ExecutionException(Messages.TraceControl_CommandError + " " + command + "\n" + //$NON-NLS-1$ //$NON-NLS-2$
-                    Messages.TraceControl_UnexpectedCommandOutputFormat + ":\n" + //$NON-NLS-1$
-                    formatOutput(result));
+                    Messages.TraceControl_UnexpectedNameError + ": " + name); //$NON-NLS-1$
         }
-        // Get and verify session path
-        matcher = LTTngControlServiceConstants.CREATE_SESSION_PATH_PATTERN.matcher(output[1]);
-        String path = null;
 
         SessionInfo sessionInfo = new SessionInfo(name);
-        if (networkUrl != null) {
-            if (matcher.matches()) {
-                path = String.valueOf(matcher.group(1).trim());
-            } else {
-                // Output format not expected
-                throw new ExecutionException(Messages.TraceControl_CommandError + " " + command + "\n" + //$NON-NLS-1$ //$NON-NLS-2$
-                        Messages.TraceControl_UnexpectedCommandOutputFormat + ":\n" + //$NON-NLS-1$
-                        formatOutput(result));
-            }
 
+        sessionInfo.setStreamedTrace(true);
+
+        // Verify session path
+        if (networkUrl != null) {
             if (path == null) {
                 // Unexpected path
                 throw new ExecutionException(Messages.TraceControl_CommandError + " " + command + "\n" + //$NON-NLS-1$ //$NON-NLS-2$
                         Messages.TraceControl_UnexpectedPathError + ": " + name); //$NON-NLS-1$
             }
+
             sessionInfo.setSessionPath(path);
+
+            // Check file protocol
+            Matcher matcher = LTTngControlServiceConstants.TRACE_FILE_PROTOCOL_PATTERN.matcher(path);
+            if (matcher.matches()) {
+                sessionInfo.setStreamedTrace(false);
+            }
         }
-        sessionInfo.setStreamedTrace(true);
+        // When using controlUrl and dataUrl the full session path is not known yet
+        // and will be set later on when listing the session
 
         return sessionInfo;
     }
@@ -500,9 +509,24 @@ public class LTTngControlService implements ILttngControlService {
         ICommandResult result = executeCommand(command.toString(), monitor, false);
         String[] output = result.getOutput();
 
-        if (isError(result) && ((output == null) || (!LTTngControlServiceConstants.SESSION_NOT_FOUND_ERROR_PATTERN.matcher(output[0]).matches()))) {
-                throw new ExecutionException(Messages.TraceControl_CommandError + " " + command.toString() + "\n" + formatOutput(result)); //$NON-NLS-1$ //$NON-NLS-2$
-       }
+        boolean isError = isError(result);
+        if (isError && (output != null)) {
+            int index = 0;
+            while (index < output.length) {
+                String line = output[index];
+                Matcher matcher = LTTngControlServiceConstants.SESSION_NOT_FOUND_ERROR_PATTERN.matcher(line);
+                if (matcher.matches()) {
+                    // Don't treat this as an error
+                    isError = false;
+                }
+                index++;
+            }
+        }
+
+        if (isError) {
+            throw new ExecutionException(Messages.TraceControl_CommandError + " " + command.toString() + "\n" + formatOutput(result)); //$NON-NLS-1$ //$NON-NLS-2$
+        }
+
         //Session <sessionName> destroyed
     }
 
@@ -934,9 +958,22 @@ public class LTTngControlService implements ILttngControlService {
      * @return true if error else false
      */
     protected boolean isError(ICommandResult result) {
-        if ((result.getResult()) != 0 || (result.getOutput().length < 1 || LTTngControlServiceConstants.ERROR_PATTERN.matcher(result.getOutput()[0]).matches())) {
+        // Check return code and length of returned strings
+        if ((result.getResult()) != 0 || (result.getOutput().length < 1)) {
             return true;
         }
+
+        // Look for error pattern
+        int index = 0;
+        while (index < result.getOutput().length) {
+            String line = result.getOutput()[index];
+            Matcher matcher = LTTngControlServiceConstants.ERROR_PATTERN.matcher(line);
+            if (matcher.matches()) {
+                return true;
+            }
+            index++;
+        }
+
         return false;
     }
 
index 79295b5fada539793e1afb999a0edea8b79a3b05..76528af0b5966c124e16855a97ff74c3cba0b58a 100644 (file)
@@ -242,7 +242,11 @@ public class LTTngControlServiceConstants {
      * Pattern to match session path for network tracing (lttng list <session>)
      * Note: file for protocol is not considered as network trace since local consumer will be used.
      */
-    public final static Pattern TRACE_NETWORK_PATH_PATTERN = Pattern.compile("\\s*Trace\\s+path\\:\\s+(net|net6|tcp|tcp6|)\\:\\/\\/(.*)(\\:(\\d*)\\/(.*)\\[data\\:\\s+(\\d*)\\]){0,1}"); //$NON-NLS-1$
+    public final static Pattern TRACE_NETWORK_PATH_PATTERN = Pattern.compile("\\s*Trace\\s+path\\:\\s+(net|net6|tcp|tcp6)\\:\\/\\/(.*)(\\:(\\d*)\\/(.*)\\[data\\:\\s+(\\d*)\\]){0,1}"); //$NON-NLS-1$
+    /**
+     * Sub-pattern to pattern TRACE_NETWORK_PATH_PATTERN to match file protocol
+     */
+    public final static Pattern TRACE_FILE_PROTOCOL_PATTERN = Pattern.compile("(file)\\:\\/\\/(.*)"); //$NON-NLS-1$
     /**
      * Pattern to match for kernel domain information (lttng list <session>)
      */
index 77d1d858f807859411afe5bb0e0afc3d164417cc..7488b09dff6f1ad99ec947ab8262b0525401d842 100644 (file)
@@ -1,5 +1,5 @@
 /**********************************************************************
- * Copyright (c) 2012 Ericsson
+ * Copyright (c) 2012. 2013 Ericsson
  *
  * All rights reserved. This program and the accompanying materials are
  * made available under the terms of the Eclipse Public License v1.0 which
@@ -91,7 +91,7 @@ public class LTTngControlServiceFactory {
             ControlCommandLogger.log(LTTngControlService.formatOutput(result));
         }
 
-        if ((result != null) && (result.getResult() == 0) && (result.getOutput().length >= 1) && (!LTTngControlServiceConstants.ERROR_PATTERN.matcher(result.getOutput()[0]).matches())) {
+        if ((result != null) && (result.getResult() == 0) && (result.getOutput().length >= 1)) {
             int index = 0;
             while (index < result.getOutput().length) {
                 String line = result.getOutput()[index];
This page took 0.040271 seconds and 5 git commands to generate.