control: Add support for saving session
authorBernd Hufmann <Bernd.Hufmann@ericsson.com>
Tue, 2 Jun 2015 20:06:20 +0000 (16:06 -0400)
committerBernd Hufmann <bernd.hufmann@ericsson.com>
Wed, 28 Oct 2015 14:30:19 +0000 (10:30 -0400)
This commit adds support for saving one or more session in
default location and force overwrite

Change-Id: I6996415456c86b9bc82df6504af04ee1a13f1440
Signed-off-by: Bernd Hufmann <Bernd.Hufmann@ericsson.com>
Reviewed-on: https://git.eclipse.org/r/57683
Reviewed-by: Hudson CI
Reviewed-by: Patrick Tasse <patrick.tasse@gmail.com>
Tested-by: Patrick Tasse <patrick.tasse@gmail.com>
lttng/org.eclipse.tracecompass.lttng2.control.ui/icons/elcl16/export_button.png [new file with mode: 0644]
lttng/org.eclipse.tracecompass.lttng2.control.ui/plugin.properties
lttng/org.eclipse.tracecompass.lttng2.control.ui/plugin.xml
lttng/org.eclipse.tracecompass.lttng2.control.ui/src/org/eclipse/tracecompass/internal/lttng2/control/ui/views/handlers/SaveHandler.java [new file with mode: 0644]
lttng/org.eclipse.tracecompass.lttng2.control.ui/src/org/eclipse/tracecompass/internal/lttng2/control/ui/views/messages/Messages.java
lttng/org.eclipse.tracecompass.lttng2.control.ui/src/org/eclipse/tracecompass/internal/lttng2/control/ui/views/messages/messages.properties
lttng/org.eclipse.tracecompass.lttng2.control.ui/src/org/eclipse/tracecompass/internal/lttng2/control/ui/views/model/impl/NullControlService.java
lttng/org.eclipse.tracecompass.lttng2.control.ui/src/org/eclipse/tracecompass/internal/lttng2/control/ui/views/model/impl/TraceSessionComponent.java
lttng/org.eclipse.tracecompass.lttng2.control.ui/src/org/eclipse/tracecompass/internal/lttng2/control/ui/views/service/ILttngControlService.java
lttng/org.eclipse.tracecompass.lttng2.control.ui/src/org/eclipse/tracecompass/internal/lttng2/control/ui/views/service/LTTngControlService.java
lttng/org.eclipse.tracecompass.lttng2.control.ui/src/org/eclipse/tracecompass/internal/lttng2/control/ui/views/service/LTTngControlServiceConstants.java

diff --git a/lttng/org.eclipse.tracecompass.lttng2.control.ui/icons/elcl16/export_button.png b/lttng/org.eclipse.tracecompass.lttng2.control.ui/icons/elcl16/export_button.png
new file mode 100644 (file)
index 0000000..f2b8528
Binary files /dev/null and b/lttng/org.eclipse.tracecompass.lttng2.control.ui/icons/elcl16/export_button.png differ
index a74074897c0d5b1bb47e8688fd22831b5db0c67c..3a93d8af2f67b665adc5b81ba5351af842c4cb24 100644 (file)
@@ -145,6 +145,9 @@ commands.control.wizard.description=Create automated tracing session
 commands.control.load=Load...
 commands.control.load.description=Load session(s)
 
+commands.control.save=Save
+commands.control.save.description=Save session(s)
+
 preference.page.control.name=LTTng Tracer Control Preferences
 preferences.page.remote.profiles.name=LTTng Remote Profiles
 
index d8bf2f3c32f2d6417d1964e80a7577789c463706..d65be69dcd5a099ff69ee2fe149227f1f356e8af 100644 (file)
             id="org.eclipse.linuxtools.internal.lttng2.ui.commands.control.load"
             name="%commands.control.load">
       </command>
+      <command
+            categoryId="org.eclipse.linuxtools.internal.lttng2.ui.commands.control.category"
+            description="%commands.control.save.description"
+            id="org.eclipse.linuxtools.internal.lttng2.ui.commands.control.save"
+            name="%commands.control.save">
+      </command>
 
    </extension>
    <extension
                </with>
             </visibleWhen>
          </command>
+         <command
+               commandId="org.eclipse.linuxtools.internal.lttng2.ui.commands.control.save"
+               icon="icons/elcl16/export_button.png"
+               label="%commands.control.save"
+               style="push">
+            <visibleWhen
+                  checkEnabled="false">
+               <with
+                     variable="activeMenuSelection">
+                    <iterate
+                         operator="or">
+                         <instanceof
+                               value="org.eclipse.tracecompass.internal.lttng2.control.ui.views.model.impl.TraceSessionComponent">
+                         </instanceof>
+                      </iterate>
+               </with>
+            </visibleWhen>
+         </command>
          <separator
                name="org.eclipse.linuxtools.internal.lttng2.ui.views.control.popup.separator2"
                visible="true">
             </with>
          </activeWhen>
       </handler>
+      <handler
+            class="org.eclipse.tracecompass.internal.lttng2.control.ui.views.handlers.SaveHandler"
+            commandId="org.eclipse.linuxtools.internal.lttng2.ui.commands.control.save">
+         <activeWhen>
+            <with
+                  variable="selection">
+                  <iterate
+                        operator="or">
+                     <instanceof
+                           value="org.eclipse.tracecompass.internal.lttng2.control.ui.views.model.impl.TraceSessionComponent">
+                     </instanceof>
+                  </iterate>
+            </with>
+         </activeWhen>
+      </handler>
       <handler
             class="org.eclipse.tracecompass.internal.lttng2.control.ui.views.handlers.EnableChannelOnSessionHandler"
             commandId="org.eclipse.linuxtools.internal.lttng2.ui.commands.control.enableChannelOnSession">
diff --git a/lttng/org.eclipse.tracecompass.lttng2.control.ui/src/org/eclipse/tracecompass/internal/lttng2/control/ui/views/handlers/SaveHandler.java b/lttng/org.eclipse.tracecompass.lttng2.control.ui/src/org/eclipse/tracecompass/internal/lttng2/control/ui/views/handlers/SaveHandler.java
new file mode 100644 (file)
index 0000000..697ae28
--- /dev/null
@@ -0,0 +1,128 @@
+/**********************************************************************
+ * Copyright (c) 2015 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *   Bernd Hufmann - Initial API and implementation
+ **********************************************************************/
+package org.eclipse.tracecompass.internal.lttng2.control.ui.views.handlers;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.tracecompass.internal.lttng2.control.core.model.TraceSessionState;
+import org.eclipse.tracecompass.internal.lttng2.control.ui.Activator;
+import org.eclipse.tracecompass.internal.lttng2.control.ui.views.ControlView;
+import org.eclipse.tracecompass.internal.lttng2.control.ui.views.messages.Messages;
+import org.eclipse.tracecompass.internal.lttng2.control.ui.views.model.impl.TraceSessionComponent;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.PlatformUI;
+
+
+/**
+ * Command handler for saving sessions
+ * @author Bernd Hufmann
+ *
+ */
+public class SaveHandler extends BaseControlViewHandler {
+
+    // ------------------------------------------------------------------------
+    // Attributes
+    // ------------------------------------------------------------------------
+    /**
+     * The list of session components the command is to be executed on.
+     */
+    protected List<TraceSessionComponent> fSessions = new ArrayList<>();
+
+    // ------------------------------------------------------------------------
+    // Operations
+    // ------------------------------------------------------------------------
+
+    @Override
+    public Object execute(ExecutionEvent event) throws ExecutionException {
+
+        IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
+
+        if (window == null) {
+            return false;
+        }
+
+        fLock.lock();
+        try {
+
+            final List<TraceSessionComponent> sessions = new ArrayList<>();
+            sessions.addAll(fSessions);
+
+            Job job = new Job(Messages.TraceControl_SaveJob) {
+                @Override
+                protected IStatus run(IProgressMonitor monitor) {
+                    try {
+                        for (TraceSessionComponent session : sessions) {
+                            session.saveSession(null, null, true, monitor);
+                        }
+                    } catch (ExecutionException e) {
+                        return new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.TraceControl_SaveFailure, e);
+                    }
+                    return Status.OK_STATUS;
+                }
+            };
+            job.setUser(true);
+            job.schedule();
+        } finally {
+            fLock.unlock();
+        }
+        return null;
+    }
+
+    @Override
+    public boolean isEnabled() {
+        // Get workbench page for the Control View
+        IWorkbenchPage page = getWorkbenchPage();
+        if (page == null) {
+            return false;
+        }
+
+        List<TraceSessionComponent> sessions = new ArrayList<>(0);
+
+        // Check if one or more session are selected
+        ISelection selection = page.getSelection(ControlView.ID);
+        if (selection instanceof StructuredSelection) {
+            StructuredSelection structered = ((StructuredSelection) selection);
+            for (Iterator<?> iterator = structered.iterator(); iterator.hasNext();) {
+                Object element = iterator.next();
+                if (element instanceof TraceSessionComponent) {
+                    // Add only TraceSessionComponents that are inactive and not destroyed
+                    TraceSessionComponent session = (TraceSessionComponent) element;
+                    if ((session.getSessionState() == TraceSessionState.INACTIVE) && (!session.isDestroyed())) {
+                        sessions.add(session);
+                    }
+                }
+            }
+        }
+        boolean isEnabled = !sessions.isEmpty();
+        fLock.lock();
+        try {
+            fSessions = null;
+            if (isEnabled) {
+                fSessions = sessions;
+            }
+        } finally {
+            fLock.unlock();
+        }
+        return isEnabled;
+    }
+}
\ No newline at end of file
index 4c28b473333538e1680881ad65ce1328ef4d839e..c9a84af88a0d5aa572ef87d1466c6c802ed388bb 100644 (file)
@@ -81,6 +81,9 @@ public final class Messages extends NLS {
     public static String TraceControl_LoadTask;
     public static String TraceControl_LoadFailure;
 
+    public static String TraceControl_SaveJob;
+    public static String TraceControl_SaveFailure;
+
     public static String TraceControl_ChangeSessionStateJob;
     public static String TraceControl_ChangeSessionStateFailure;
 
index 25b6d9db38aadcdec5e455e629db7fe645dfb377..ea877158c4ce1464df23a88431f27aa976ce3224 100644 (file)
@@ -66,6 +66,9 @@ TraceControl_LoadJob=Loading Session Profiles...
 TraceControl_LoadTask=Loading profile ''{0}''
 TraceControl_LoadFailure=Command to load session(s) failed
 
+TraceControl_SaveJob=Saving Session(s)...
+TraceControl_SaveFailure=Command to save session(s) failed
+
 TraceControl_ChangeSessionStateJob=Changing Session State...
 TraceControl_ChangeSessionStateFailure=Command to change session state failed...
 
index d240090e38cb136146e085d5b7bc0bfcb3cf3e38..fa7346dfba7c00a633db7df2439ea65a3e789d16 100644 (file)
@@ -147,4 +147,8 @@ class NullControlService implements ILttngControlService {
     @Override
     public void loadSession(@Nullable String inputPath, boolean isForce, IProgressMonitor monitor) throws ExecutionException {
     }
+
+    @Override
+    public void saveSession(String session, String outputPath, boolean isForce, IProgressMonitor monitor) throws ExecutionException {
+    }
 }
index 749a30b86242bfbb8879a8452825e72413e8255d..92733ea15827c35f90f375a3550ef2baf59fe130 100644 (file)
@@ -450,6 +450,24 @@ public class TraceSessionComponent extends TraceControlComponent {
         getControlService().recordSnapshot(getName(), monitor);
     }
 
+    /**
+     * Save all or a given session.
+     *
+     * @param session
+     *            a session name to save or null for all
+     * @param outputPath
+     *            a path to save session or null for default location
+     * @param isForce
+     *            flag whether to overwrite existing or not
+     * @param monitor
+     *            a progress monitor
+     * @throws ExecutionException
+     *             If the command fails
+     */
+    public void saveSession(String session, String outputPath, boolean isForce, IProgressMonitor monitor) throws ExecutionException {
+        getControlService().saveSession(session, outputPath, isForce, monitor);
+    }
+
     /**
      * Returns if session is live.
      * @return <code>true</code> if session if live else <code>false</code>
index 0e23d0fed2c0d7a52084415542ade246b6a24aa3..675111e9ce5f9ae9fd4b9b87f340edacb51e146f 100644 (file)
@@ -415,4 +415,21 @@ public interface ILttngControlService {
      */
     void loadSession(@Nullable String inputPath, boolean isForce, IProgressMonitor monitor)
             throws ExecutionException;
+
+    /**
+     * Save all or a given session.
+     *
+     * @param session
+     *            a session name to save or null for all
+     * @param outputPath
+     *            a path to save session or null for default location
+     * @param isForce
+     *            flag whether to overwrite existing or not
+     * @param monitor
+     *            a progress monitor
+     * @throws ExecutionException
+     *             If the command fails
+     */
+    void saveSession(@Nullable String session, @Nullable String outputPath, boolean isForce, IProgressMonitor monitor)
+            throws ExecutionException;
 }
index 30b2a80d85fde8ef0e26ba05008aee9c0b677ad1..e531a4a21dd4d373ec4497c575bde16f26d25ef8 100644 (file)
@@ -1036,6 +1036,25 @@ public class LTTngControlService implements ILttngControlService {
         executeCommand(command, monitor);
     }
 
+    @Override
+    public void saveSession(String session, String outputPath, boolean isForce, IProgressMonitor monitor) throws ExecutionException {
+        ICommandInput command = createCommand(LTTngControlServiceConstants.COMMAND_SAVE_SESSION);
+
+        if (outputPath != null) {
+            command.add(LTTngControlServiceConstants.OPTION_OUTPUT_PATH);
+            command.add(outputPath);
+        }
+
+        if (isForce) {
+            command.add(LTTngControlServiceConstants.OPTION_FORCE);
+        }
+
+        if (session != null) {
+            command.add(session);
+        }
+        executeCommand(command, monitor);
+    }
+
     @Override
     public void runCommands(IProgressMonitor monitor, List<String> commandLines) throws ExecutionException {
         for (String commandLine : commandLines) {
index aeadfe49d637c8f459e605ba9c6feb3be3f17bd0..4511e75c2189945f35aeab42eb63d7411cec1abd 100644 (file)
@@ -97,10 +97,6 @@ public interface LTTngControlServiceConstants {
      * Command to destroy a session.
      */
     String COMMAND_START_SESSION = "start"; //$NON-NLS-1$
-    /**
-     * Command to load a session.
-     */
-    String COMMAND_LOAD_SESSION = "load"; //$NON-NLS-1$
     /**
      * Command to destroy a session.
      */
@@ -141,6 +137,14 @@ public interface LTTngControlServiceConstants {
      * Command to record a snapshot
      */
     String COMMAND_RECORD_SNAPSHOT = "record"; //$NON-NLS-1$
+    /**
+     * Command to load a session.
+     */
+    String COMMAND_LOAD_SESSION = "load"; //$NON-NLS-1$
+    /**
+     * Command to save a session
+     */
+    String COMMAND_SAVE_SESSION = "save"; //$NON-NLS-1$
 
     // ------------------------------------------------------------------------
     // Command line options constants
@@ -293,7 +297,6 @@ public interface LTTngControlServiceConstants {
      * Command line option for specifying input path
      */
     String OPTION_INPUT_PATH = "-i"; //$NON-NLS-1$
-
     /**
      * Maximum live timer interval value
      */
This page took 0.033126 seconds and 5 git commands to generate.