From 3d99d53314011dfa0cb5a30f30f1bec7981c6916 Mon Sep 17 00:00:00 2001 From: Bernd Hufmann Date: Tue, 2 Jun 2015 16:06:20 -0400 Subject: [PATCH] control: Add support for saving session This commit adds support for saving one or more session in default location and force overwrite Change-Id: I6996415456c86b9bc82df6504af04ee1a13f1440 Signed-off-by: Bernd Hufmann Reviewed-on: https://git.eclipse.org/r/57683 Reviewed-by: Hudson CI Reviewed-by: Patrick Tasse Tested-by: Patrick Tasse --- .../icons/elcl16/export_button.png | Bin 0 -> 516 bytes .../plugin.properties | 3 + .../plugin.xml | 39 ++++++ .../ui/views/handlers/SaveHandler.java | 128 ++++++++++++++++++ .../control/ui/views/messages/Messages.java | 3 + .../ui/views/messages/messages.properties | 3 + .../views/model/impl/NullControlService.java | 4 + .../model/impl/TraceSessionComponent.java | 18 +++ .../views/service/ILttngControlService.java | 17 +++ .../ui/views/service/LTTngControlService.java | 19 +++ .../service/LTTngControlServiceConstants.java | 13 +- 11 files changed, 242 insertions(+), 5 deletions(-) create mode 100644 lttng/org.eclipse.tracecompass.lttng2.control.ui/icons/elcl16/export_button.png create mode 100644 lttng/org.eclipse.tracecompass.lttng2.control.ui/src/org/eclipse/tracecompass/internal/lttng2/control/ui/views/handlers/SaveHandler.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 index 0000000000000000000000000000000000000000..f2b85285c0b5902738591fb4fcb6157cb48f458f GIT binary patch literal 516 zcmV+f0{i`mP))L_t(I%cYaQOI$$^$3OEhV4GBi zTxSB8{~!@W38b|MHfd4>8%sMA6$HWJENl`4g#$^@5Yk%&L^wE8q!27Th@FBK0rd{e zzJ0qpDb_pg<({Otfq~iC`Stzoju_+UM-uv!fwpn<>sY`4r~`0ze$M#F^IYIweV>Oz zLjb&dHp0^&MP4lKyU#v7jG{AI8;I6kSHK15Mwf*^cKimg3V%qdnem>P$pOx za9#=~@IvYWwP zG(_fAI6l1(SZo#$$xn~~%q%VU5LRk^;!*1}tLtlwl`i5-`G9o+-^GEnm+9R~MOPQz z1Mp_ + + + + + + + + + + + + @@ -1014,6 +1038,21 @@ + + + + + + + + + + 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 index 0000000000..697ae28806 --- /dev/null +++ b/lttng/org.eclipse.tracecompass.lttng2.control.ui/src/org/eclipse/tracecompass/internal/lttng2/control/ui/views/handlers/SaveHandler.java @@ -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 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 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 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 diff --git a/lttng/org.eclipse.tracecompass.lttng2.control.ui/src/org/eclipse/tracecompass/internal/lttng2/control/ui/views/messages/Messages.java b/lttng/org.eclipse.tracecompass.lttng2.control.ui/src/org/eclipse/tracecompass/internal/lttng2/control/ui/views/messages/Messages.java index 4c28b47333..c9a84af88a 100644 --- a/lttng/org.eclipse.tracecompass.lttng2.control.ui/src/org/eclipse/tracecompass/internal/lttng2/control/ui/views/messages/Messages.java +++ b/lttng/org.eclipse.tracecompass.lttng2.control.ui/src/org/eclipse/tracecompass/internal/lttng2/control/ui/views/messages/Messages.java @@ -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; diff --git a/lttng/org.eclipse.tracecompass.lttng2.control.ui/src/org/eclipse/tracecompass/internal/lttng2/control/ui/views/messages/messages.properties b/lttng/org.eclipse.tracecompass.lttng2.control.ui/src/org/eclipse/tracecompass/internal/lttng2/control/ui/views/messages/messages.properties index 25b6d9db38..ea877158c4 100644 --- a/lttng/org.eclipse.tracecompass.lttng2.control.ui/src/org/eclipse/tracecompass/internal/lttng2/control/ui/views/messages/messages.properties +++ b/lttng/org.eclipse.tracecompass.lttng2.control.ui/src/org/eclipse/tracecompass/internal/lttng2/control/ui/views/messages/messages.properties @@ -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... diff --git a/lttng/org.eclipse.tracecompass.lttng2.control.ui/src/org/eclipse/tracecompass/internal/lttng2/control/ui/views/model/impl/NullControlService.java b/lttng/org.eclipse.tracecompass.lttng2.control.ui/src/org/eclipse/tracecompass/internal/lttng2/control/ui/views/model/impl/NullControlService.java index d240090e38..fa7346dfba 100644 --- a/lttng/org.eclipse.tracecompass.lttng2.control.ui/src/org/eclipse/tracecompass/internal/lttng2/control/ui/views/model/impl/NullControlService.java +++ b/lttng/org.eclipse.tracecompass.lttng2.control.ui/src/org/eclipse/tracecompass/internal/lttng2/control/ui/views/model/impl/NullControlService.java @@ -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 { + } } diff --git a/lttng/org.eclipse.tracecompass.lttng2.control.ui/src/org/eclipse/tracecompass/internal/lttng2/control/ui/views/model/impl/TraceSessionComponent.java b/lttng/org.eclipse.tracecompass.lttng2.control.ui/src/org/eclipse/tracecompass/internal/lttng2/control/ui/views/model/impl/TraceSessionComponent.java index 749a30b862..92733ea158 100644 --- a/lttng/org.eclipse.tracecompass.lttng2.control.ui/src/org/eclipse/tracecompass/internal/lttng2/control/ui/views/model/impl/TraceSessionComponent.java +++ b/lttng/org.eclipse.tracecompass.lttng2.control.ui/src/org/eclipse/tracecompass/internal/lttng2/control/ui/views/model/impl/TraceSessionComponent.java @@ -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 true if session if live else false diff --git a/lttng/org.eclipse.tracecompass.lttng2.control.ui/src/org/eclipse/tracecompass/internal/lttng2/control/ui/views/service/ILttngControlService.java b/lttng/org.eclipse.tracecompass.lttng2.control.ui/src/org/eclipse/tracecompass/internal/lttng2/control/ui/views/service/ILttngControlService.java index 0e23d0fed2..675111e9ce 100644 --- a/lttng/org.eclipse.tracecompass.lttng2.control.ui/src/org/eclipse/tracecompass/internal/lttng2/control/ui/views/service/ILttngControlService.java +++ b/lttng/org.eclipse.tracecompass.lttng2.control.ui/src/org/eclipse/tracecompass/internal/lttng2/control/ui/views/service/ILttngControlService.java @@ -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; } diff --git a/lttng/org.eclipse.tracecompass.lttng2.control.ui/src/org/eclipse/tracecompass/internal/lttng2/control/ui/views/service/LTTngControlService.java b/lttng/org.eclipse.tracecompass.lttng2.control.ui/src/org/eclipse/tracecompass/internal/lttng2/control/ui/views/service/LTTngControlService.java index 30b2a80d85..e531a4a21d 100644 --- a/lttng/org.eclipse.tracecompass.lttng2.control.ui/src/org/eclipse/tracecompass/internal/lttng2/control/ui/views/service/LTTngControlService.java +++ b/lttng/org.eclipse.tracecompass.lttng2.control.ui/src/org/eclipse/tracecompass/internal/lttng2/control/ui/views/service/LTTngControlService.java @@ -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 commandLines) throws ExecutionException { for (String commandLine : commandLines) { diff --git a/lttng/org.eclipse.tracecompass.lttng2.control.ui/src/org/eclipse/tracecompass/internal/lttng2/control/ui/views/service/LTTngControlServiceConstants.java b/lttng/org.eclipse.tracecompass.lttng2.control.ui/src/org/eclipse/tracecompass/internal/lttng2/control/ui/views/service/LTTngControlServiceConstants.java index aeadfe49d6..4511e75c21 100644 --- a/lttng/org.eclipse.tracecompass.lttng2.control.ui/src/org/eclipse/tracecompass/internal/lttng2/control/ui/views/service/LTTngControlServiceConstants.java +++ b/lttng/org.eclipse.tracecompass.lttng2.control.ui/src/org/eclipse/tracecompass/internal/lttng2/control/ui/views/service/LTTngControlServiceConstants.java @@ -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 */ -- 2.34.1