tmf: lttngControl: mi: support session creation
authorJonathan Rajotte Julien <jonathan.rajotte-julien@ericsson.com>
Wed, 6 Aug 2014 22:06:31 +0000 (18:06 -0400)
committerBernd Hufmann <bernd.hufmann@ericsson.com>
Wed, 27 Aug 2014 15:33:56 +0000 (11:33 -0400)
Change-Id: Ieaef13801acd1741dfdcc837abb96db4f55d371b
Signed-off-by: Jonathan Rajotte Julien <jonathan.rajotte-julien@ericsson.com>
Reviewed-on: https://git.eclipse.org/r/31392
Tested-by: Hudson CI
Reviewed-by: Bernd Hufmann <bernd.hufmann@ericsson.com>
Tested-by: Bernd Hufmann <bernd.hufmann@ericsson.com>
Reviewed-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
org.eclipse.linuxtools.lttng2.control.ui/src/org/eclipse/linuxtools/internal/lttng2/control/ui/views/messages/Messages.java
org.eclipse.linuxtools.lttng2.control.ui/src/org/eclipse/linuxtools/internal/lttng2/control/ui/views/messages/messages.properties
org.eclipse.linuxtools.lttng2.control.ui/src/org/eclipse/linuxtools/internal/lttng2/control/ui/views/service/LTTngControlService.java
org.eclipse.linuxtools.lttng2.control.ui/src/org/eclipse/linuxtools/internal/lttng2/control/ui/views/service/LTTngControlServiceMI.java

index 1b2a06513e24d24d8f9904cfcd3bdb1fcba88334..9bd58c264714aa4b29f4d36f3ec4f5f47dfafec9 100644 (file)
@@ -45,6 +45,7 @@ public final class Messages extends NLS {
     public static String TraceControl_UnexpectedCommandOutputFormat;
     public static String TraceControl_UnexpectedNameError;
     public static String TraceControl_UnexpectedPathError;
+    public static String TraceControl_UnexpectedNumberOfElementError;
 
     public static String TraceControl_UnsupportedVersionError;
     public static String TraceControl_GettingVersionError;
index a82547ebe74be0eca331675d8e4cd58432b38dc6..b5539f11d73f2a6e7a77755c7a901c51266eaf39 100644 (file)
@@ -25,6 +25,7 @@ TraceControl_CommandError=Command failed! Command:
 TraceControl_UnexpectedCommandOutputFormat=Unexpected command output
 TraceControl_UnexpectedNameError=Unexpected session name returned
 TraceControl_UnexpectedPathError=Unexpected session path returned
+TraceControl_UnexpectedNumberOfElementError=Unexpected number of elements {0} returned
 
 TraceControl_UnsupportedVersionError=Unsupported LTTng Tracer Control version
 TraceControl_GettingVersionError=Could not get version of LTTng Tracer Control
index 6e1083cd2c268d73ca76441219f22f138dc515d1..d734b2076f15ec4e50b6f55c60c12154b0cc9608 100644 (file)
@@ -431,19 +431,7 @@ public class LTTngControlService implements ILttngControlService {
             return createStreamedSession(sessionInfo, monitor);
         }
 
-        String newName = formatParameter(sessionInfo.getName());
-        String newPath = formatParameter(sessionInfo.getSessionPath());
-
-        StringBuffer command = createCommand(LTTngControlServiceConstants.COMMAND_CREATE_SESSION, newName);
-
-        if (newPath != null && !"".equals(newPath)) { //$NON-NLS-1$
-            command.append(LTTngControlServiceConstants.OPTION_OUTPUT_PATH);
-            command.append(newPath);
-        }
-
-        if (sessionInfo.isSnapshotSession()) {
-            command.append(LTTngControlServiceConstants.OPTION_SNAPSHOT);
-        }
+        StringBuffer command = prepareSessionCreationCommand(sessionInfo);
 
         ICommandResult result = executeCommand(command.toString(), monitor);
 
@@ -496,30 +484,30 @@ public class LTTngControlService implements ILttngControlService {
 
     }
 
-    private ISessionInfo createStreamedSession(ISessionInfo sessionInfo, IProgressMonitor monitor) throws ExecutionException {
-
+    /**
+     * @param sessionInfo
+     * @return
+     */
+    protected StringBuffer prepareSessionCreationCommand(ISessionInfo sessionInfo) {
         String newName = formatParameter(sessionInfo.getName());
+        String newPath = formatParameter(sessionInfo.getSessionPath());
+
         StringBuffer command = createCommand(LTTngControlServiceConstants.COMMAND_CREATE_SESSION, newName);
 
+        if (newPath != null && !"".equals(newPath)) { //$NON-NLS-1$
+            command.append(LTTngControlServiceConstants.OPTION_OUTPUT_PATH);
+            command.append(newPath);
+        }
+
         if (sessionInfo.isSnapshotSession()) {
             command.append(LTTngControlServiceConstants.OPTION_SNAPSHOT);
-        } else if (sessionInfo.isLive()) {
-            command.append(LTTngControlServiceConstants.OPTION_LIVE);
-            if (sessionInfo.getLiveDelay() != LTTngControlServiceConstants.UNUSED_VALUE) {
-                command.append(sessionInfo.getLiveDelay());
-            }
         }
+        return command;
+    }
 
-        if (sessionInfo.getNetworkUrl() != null) {
-            command.append(LTTngControlServiceConstants.OPTION_NETWORK_URL);
-            command.append(sessionInfo.getNetworkUrl());
-        } else {
-            command.append(LTTngControlServiceConstants.OPTION_CONTROL_URL);
-            command.append(sessionInfo.getControlUrl());
+    private ISessionInfo createStreamedSession(ISessionInfo sessionInfo, IProgressMonitor monitor) throws ExecutionException {
 
-            command.append(LTTngControlServiceConstants.OPTION_DATA_URL);
-            command.append(sessionInfo.getDataUrl());
-        }
+        StringBuffer command = prepareStreamedSessionCreationCommand(sessionInfo);
 
         ICommandResult result = executeCommand(command.toString(), monitor);
 
@@ -581,6 +569,36 @@ public class LTTngControlService implements ILttngControlService {
         return sessionInfo;
     }
 
+    /**
+     * @param sessionInfo
+     * @return
+     */
+    protected StringBuffer prepareStreamedSessionCreationCommand(ISessionInfo sessionInfo) {
+        String newName = formatParameter(sessionInfo.getName());
+        StringBuffer command = createCommand(LTTngControlServiceConstants.COMMAND_CREATE_SESSION, newName);
+
+        if (sessionInfo.isSnapshotSession()) {
+            command.append(LTTngControlServiceConstants.OPTION_SNAPSHOT);
+        } else if (sessionInfo.isLive()) {
+            command.append(LTTngControlServiceConstants.OPTION_LIVE);
+            if (sessionInfo.getLiveDelay() != LTTngControlServiceConstants.UNUSED_VALUE) {
+                command.append(sessionInfo.getLiveDelay());
+            }
+        }
+
+        if (sessionInfo.getNetworkUrl() != null) {
+            command.append(LTTngControlServiceConstants.OPTION_NETWORK_URL);
+            command.append(sessionInfo.getNetworkUrl());
+        } else {
+            command.append(LTTngControlServiceConstants.OPTION_CONTROL_URL);
+            command.append(sessionInfo.getControlUrl());
+
+            command.append(LTTngControlServiceConstants.OPTION_DATA_URL);
+            command.append(sessionInfo.getDataUrl());
+        }
+        return command;
+    }
+
     @Override
     public void destroySession(String sessionName, IProgressMonitor monitor) throws ExecutionException {
         String newName = formatParameter(sessionName);
index 2ab11b6f92dd43c06f0d1711a317c8103d9acfb7..3e72f1a8376480522d5d3a6da76fee36da09a8da 100644 (file)
@@ -53,6 +53,7 @@ import org.eclipse.linuxtools.internal.lttng2.control.ui.views.handlers.XmlMiVal
 import org.eclipse.linuxtools.internal.lttng2.control.ui.views.messages.Messages;
 import org.eclipse.linuxtools.internal.lttng2.control.ui.views.remote.ICommandResult;
 import org.eclipse.linuxtools.internal.lttng2.control.ui.views.remote.ICommandShell;
+import org.eclipse.osgi.util.NLS;
 import org.w3c.dom.Document;
 import org.w3c.dom.Node;
 import org.w3c.dom.NodeList;
@@ -228,10 +229,34 @@ public class LTTngControlServiceMI extends LTTngControlService {
         }
 
         // Populate session information
-        NodeList rawSessionInfos = sessionsNode.item(0).getChildNodes();
+        Node rawSession = sessionsNode.item(0);
+        parseSession(sessionInfo, rawSession);
+
+        // Fetch the snapshot info
+        if (sessionInfo.isSnapshotSession()) {
+            ISnapshotInfo snapshot = getSnapshotInfo(sessionName, monitor);
+            sessionInfo.setSnapshotInfo(snapshot);
+        }
+
+        return sessionInfo;
+    }
+
+    /**
+     * @param sessionInfo
+     * @param rawSession
+     * @throws ExecutionException
+     */
+    private void parseSession(ISessionInfo sessionInfo, Node rawSession) throws ExecutionException {
+        if (!rawSession.getNodeName().equalsIgnoreCase(MIStrings.SESSION)) {
+            throw new ExecutionException(Messages.TraceControl_MiInvalidElementError);
+        }
+        NodeList rawSessionInfos = rawSession.getChildNodes();
         for (int i = 0; i < rawSessionInfos.getLength(); i++) {
             Node rawInfo = rawSessionInfos.item(i);
             switch (rawInfo.getNodeName()) {
+            case MIStrings.NAME:
+                sessionInfo.setName(rawInfo.getTextContent());
+                break;
             case MIStrings.PATH:
                 sessionInfo.setSessionPath(rawInfo.getTextContent());
                 break;
@@ -270,15 +295,6 @@ public class LTTngControlServiceMI extends LTTngControlService {
                 sessionInfo.setStreamedTrace(true);
             }
         }
-
-
-        // Fetch the snapshot info
-        if (sessionInfo.isSnapshotSession()) {
-            ISnapshotInfo snapshot = getSnapshotInfo(sessionName, monitor);
-            sessionInfo.setSnapshotInfo(snapshot);
-        }
-
-        return sessionInfo;
     }
 
     /**
@@ -504,8 +520,105 @@ public class LTTngControlServiceMI extends LTTngControlService {
 
     @Override
     public ISessionInfo createSession(ISessionInfo sessionInfo, IProgressMonitor monitor) throws ExecutionException {
-        // TODO Auto-generated method stub
-        return null;
+        if (sessionInfo.isStreamedTrace()) {
+            return createStreamedSession(sessionInfo, monitor);
+        }
+
+        StringBuffer command = prepareSessionCreationCommand(sessionInfo);
+
+        ICommandResult result = executeCommand(command.toString(), monitor);
+
+        Document document = getDocumentFromStrings(result.getOutput());
+        NodeList sessions = document.getElementsByTagName(MIStrings.SESSION);
+
+        // Number of session should be equal to 1
+        if (sessions.getLength() != 1) {
+            throw new ExecutionException(Messages.TraceControl_CommandError + " " + command + "\n" //$NON-NLS-1$//$NON-NLS-2$
+                    + NLS.bind(Messages.TraceControl_UnexpectedNumberOfElementError, MIStrings.SESSION) + " " + sessions.getLength()); //$NON-NLS-1$
+        }
+
+        // Fetch a session from output
+        ISessionInfo outputSession = new SessionInfo(""); //$NON-NLS-1$
+        parseSession(outputSession, sessions.item(0));
+
+        // Verify session name
+        if ((outputSession.getName().equals("")) || (!"".equals(sessionInfo.getName()) && !outputSession.getName().equals(sessionInfo.getName()))) { //$NON-NLS-1$ //$NON-NLS-2$
+            // Unexpected name returned
+            throw new ExecutionException(Messages.TraceControl_CommandError + " " + command + "\n" + //$NON-NLS-1$ //$NON-NLS-2$
+                    Messages.TraceControl_UnexpectedNameError + ": " + outputSession.getName()); //$NON-NLS-1$
+        }
+
+        // Verify session path
+        if (!sessionInfo.isSnapshotSession() &&
+                ((outputSession.getSessionPath() == null) || ((sessionInfo.getSessionPath() != null) && (!outputSession.getSessionPath().contains(sessionInfo.getSessionPath()))))) {
+            // Unexpected path
+            throw new ExecutionException(Messages.TraceControl_CommandError + " " + command + "\n" + //$NON-NLS-1$ //$NON-NLS-2$
+                    Messages.TraceControl_UnexpectedPathError + ": " + outputSession.getName()); //$NON-NLS-1$
+        }
+
+        if (sessionInfo.isSnapshotSession()) {
+            // Make it a snapshot session - content of snapshot info need to
+            // set afterwards using getSession() or getSnapshotInfo()
+            outputSession.setSnapshotInfo(new SnapshotInfo("")); //$NON-NLS-1$
+        }
+
+        return outputSession;
+    }
+
+    private ISessionInfo createStreamedSession(ISessionInfo sessionInfo, IProgressMonitor monitor) throws ExecutionException {
+
+        StringBuffer command = prepareStreamedSessionCreationCommand(sessionInfo);
+
+        ICommandResult result = executeCommand(command.toString(), monitor);
+
+        Document document = getDocumentFromStrings(result.getOutput());
+        NodeList sessions = document.getElementsByTagName(MIStrings.SESSION);
+
+        // Number of session should be equal to 1
+        if (sessions.getLength() != 1) {
+            throw new ExecutionException(Messages.TraceControl_CommandError + " " + command + "\n" //$NON-NLS-1$//$NON-NLS-2$
+                    + NLS.bind(Messages.TraceControl_UnexpectedNumberOfElementError, MIStrings.SESSION) + " " + sessions.getLength()); //$NON-NLS-1$
+        }
+
+        // Fetch a session from output
+        ISessionInfo outputSession = new SessionInfo(""); //$NON-NLS-1$
+        parseSession(outputSession, sessions.item(0));
+
+        // Verify session name
+        if ((outputSession.getName().equals("")) || (!"".equals(sessionInfo.getName()) && !outputSession.getName().equals(sessionInfo.getName()))) { //$NON-NLS-1$ //$NON-NLS-2$
+            // Unexpected name returned
+            throw new ExecutionException(Messages.TraceControl_CommandError + " " + command + "\n" + //$NON-NLS-1$ //$NON-NLS-2$
+                    Messages.TraceControl_UnexpectedNameError + ": " + outputSession.getName()); //$NON-NLS-1$
+        }
+
+        sessionInfo.setName(outputSession.getName());
+        sessionInfo.setStreamedTrace(true);
+
+        // Verify session path
+        if (sessionInfo.getNetworkUrl() != null) {
+            if (!sessionInfo.isSnapshotSession() && (outputSession.getSessionPath() == null)) {
+                // Unexpected path
+                throw new ExecutionException(Messages.TraceControl_CommandError + " " + command + "\n" + //$NON-NLS-1$ //$NON-NLS-2$
+                        Messages.TraceControl_UnexpectedPathError + ": " + outputSession.getName()); //$NON-NLS-1$
+            }
+
+            if (sessionInfo.isSnapshotSession()) {
+                sessionInfo.setStreamedTrace(false);
+            } else {
+                sessionInfo.setSessionPath(outputSession.getSessionPath());
+                // Check file protocol
+                Matcher matcher = LTTngControlServiceConstants.TRACE_FILE_PROTOCOL_PATTERN.matcher(outputSession.getSessionPath());
+                if (matcher.matches()) {
+                    sessionInfo.setStreamedTrace(false);
+                }
+            }
+        }
+
+        // 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;
+
     }
 
     @Override
This page took 0.032154 seconds and 5 git commands to generate.