Search in sources :

Example 1 with TracePackageElement

use of org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageElement in project tracecompass by tracecompass.

the class ImportHandler method execute.

// ------------------------------------------------------------------------
// Operations
// ------------------------------------------------------------------------
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    if (window == null) {
        return false;
    }
    CommandParameter param;
    fLock.lock();
    try {
        param = fParam;
        if (param == null) {
            return null;
        }
        param = param.clone();
    } finally {
        fLock.unlock();
    }
    // create default project
    IProject project = TmfProjectRegistry.createProject(RemoteFetchLogWizardRemotePage.DEFAULT_REMOTE_PROJECT_NAME, null, null);
    if (param.getSession().isLiveTrace()) {
        importLiveTrace(new LttngRelaydConnectionInfo(param.getSession().getLiveUrl(), param.getSession().getLivePort(), param.getSession().getName()), project);
        return null;
    } else if (param.getSession().isStreamedTrace()) {
        IPreferenceStore store = Activator.getDefault().getPreferenceStore();
        String notify = store.getString(NOTIFY_IMPORT_STREAMED_PREF_KEY);
        if (!MessageDialogWithToggle.ALWAYS.equals(notify)) {
            MessageDialogWithToggle.openInformation(window.getShell(), null, Messages.TraceControl_ImportDialogStreamedTraceNotification, Messages.TraceControl_ImportDialogStreamedTraceNotificationToggle, false, store, NOTIFY_IMPORT_STREAMED_PREF_KEY);
        }
        // Streamed trace
        TmfProjectElement projectElement = TmfProjectRegistry.getProject(project, true);
        TmfTraceFolder traceFolder = projectElement.getTracesFolder();
        ImportTraceWizard wizard = new ImportTraceWizard();
        wizard.init(PlatformUI.getWorkbench(), new StructuredSelection(traceFolder));
        WizardDialog dialog = new WizardDialog(window.getShell(), wizard);
        dialog.open();
        return null;
    }
    // Generate the profile
    TraceSessionComponent session = param.getSession();
    // $NON-NLS-1$
    RemoteImportProfileElement profile = new RemoteImportProfileElement(null, "LTTng Remote Traces");
    RemoteSystemProxy proxy = session.getTargetNode().getRemoteSystemProxy();
    IRemoteConnection rc = proxy.getRemoteConnection();
    String name = rc.getName();
    if (!rc.hasService(IRemoteConnectionHostService.class)) {
        return null;
    }
    String scheme = rc.getConnectionType().getScheme();
    IRemoteConnectionHostService hostService = checkNotNull(rc.getService(IRemoteConnectionHostService.class));
    String address = hostService.getHostname();
    String user = hostService.getUsername();
    int port = hostService.getPort();
    URI remoteUri;
    try {
        remoteUri = new URI(scheme, user, address, port, null, null, null);
    } catch (URISyntaxException e) {
        return false;
    }
    RemoteImportConnectionNodeElement connection = new RemoteImportConnectionNodeElement(profile, name, remoteUri.toString());
    String pathString = session.isSnapshotSession() ? session.getSnapshotInfo().getSnapshotPath() : session.getSessionPath();
    IPath path = new Path(pathString);
    RemoteImportTraceGroupElement group = new RemoteImportTraceGroupElement(connection, path.toString());
    group.setRecursive(true);
    // $NON-NLS-1$//$NON-NLS-2$
    TracePackageElement element = new TracePackageTraceElement(group, "", "");
    // $NON-NLS-1$
    new TracePackageFilesElement(element, ".*");
    String experimentName = path.lastSegment();
    if (!experimentName.startsWith(session.getName())) {
        experimentName = session.getName();
    }
    RemoteFetchLogWizard wizard = new RemoteFetchLogWizard(profile, experimentName);
    wizard.init(PlatformUI.getWorkbench(), StructuredSelection.EMPTY);
    WizardDialog dialog = new WizardDialog(window.getShell(), wizard);
    dialog.open();
    return null;
}
Also used : RemoteImportConnectionNodeElement(org.eclipse.tracecompass.internal.tmf.remote.ui.wizards.fetch.model.RemoteImportConnectionNodeElement) IRemoteConnectionHostService(org.eclipse.remote.core.IRemoteConnectionHostService) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) TmfProjectElement(org.eclipse.tracecompass.tmf.ui.project.model.TmfProjectElement) URISyntaxException(java.net.URISyntaxException) RemoteImportProfileElement(org.eclipse.tracecompass.internal.tmf.remote.ui.wizards.fetch.model.RemoteImportProfileElement) URI(java.net.URI) ImportTraceWizard(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.importtrace.ImportTraceWizard) TmfTraceFolder(org.eclipse.tracecompass.tmf.ui.project.model.TmfTraceFolder) TracePackageElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageElement) TracePackageTraceElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageTraceElement) RemoteFetchLogWizard(org.eclipse.tracecompass.internal.tmf.remote.ui.wizards.fetch.RemoteFetchLogWizard) IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) TraceSessionComponent(org.eclipse.tracecompass.internal.lttng2.control.ui.views.model.impl.TraceSessionComponent) IPath(org.eclipse.core.runtime.IPath) IRemoteConnection(org.eclipse.remote.core.IRemoteConnection) TracePackageFilesElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageFilesElement) RemoteImportTraceGroupElement(org.eclipse.tracecompass.internal.tmf.remote.ui.wizards.fetch.model.RemoteImportTraceGroupElement) IProject(org.eclipse.core.resources.IProject) RemoteSystemProxy(org.eclipse.tracecompass.tmf.remote.core.proxy.RemoteSystemProxy) LttngRelaydConnectionInfo(org.eclipse.tracecompass.internal.lttng2.control.ui.relayd.LttngRelaydConnectionInfo) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) WizardDialog(org.eclipse.jface.wizard.WizardDialog)

Example 2 with TracePackageElement

use of org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageElement in project tracecompass by tracecompass.

the class RemoteFetchLogWizardRemotePage method createElementViewer.

@Override
protected void createElementViewer(Composite compositeParent) {
    super.createElementViewer(compositeParent);
    CheckboxTreeViewer elementViewer = getElementViewer();
    elementViewer.setLabelProvider(new TracePackageLabelProvider() {

        @Override
        public String getText(Object element) {
            if (element instanceof TracePackageTraceElement) {
                for (TracePackageElement files : ((TracePackageTraceElement) element).getChildren()) {
                    if (files instanceof TracePackageFilesElement) {
                        return ((TracePackageFilesElement) files).getFileName();
                    }
                }
            }
            return super.getText(element);
        }

        @Override
        public Image getImage(Object element) {
            if (element instanceof TracePackageTraceElement) {
                for (TracePackageElement files : ((TracePackageTraceElement) element).getChildren()) {
                    return files.getImage();
                }
            }
            return super.getImage(element);
        }
    });
    elementViewer.setComparator(new ViewerComparator() {

        @Override
        public int category(Object element) {
            if (element instanceof TracePackageTraceElement) {
                return 1;
            }
            return 0;
        }
    });
}
Also used : CheckboxTreeViewer(org.eclipse.jface.viewers.CheckboxTreeViewer) TracePackageFilesElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageFilesElement) ViewerComparator(org.eclipse.jface.viewers.ViewerComparator) TracePackageElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageElement) TracePackageTraceElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageTraceElement) TracePackageLabelProvider(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageLabelProvider) Image(org.eclipse.swt.graphics.Image)

Example 3 with TracePackageElement

use of org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageElement in project tracecompass by tracecompass.

the class ExtractRemoteProfilesOperation method run.

/**
 * Run the extract profiles operation. The status (result) of the operation
 * can be obtained with {@link #getStatus}
 *
 * @param progressMonitor
 *            the progress monitor to use to display progress and receive
 *            requests for cancellation
 */
@Override
public void run(IProgressMonitor progressMonitor) {
    TracePackageElement[] elements = null;
    try {
        progressMonitor.worked(1);
        File file = new File(getFileName());
        progressMonitor.worked(1);
        if (!file.exists()) {
            // $NON-NLS-1$
            setStatus(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Invalid format"));
            return;
        }
        // TODO backwards compatibility for location
        try (FileInputStream inputStream = new FileInputStream(file)) {
            RemoteImportProfilesReader.validate(inputStream);
        }
        try (FileInputStream inputStream = new FileInputStream(file)) {
            elements = RemoteImportProfilesReader.loadElementsFromProfiles(inputStream);
        }
        progressMonitor.worked(1);
        setResultElements(elements);
        setStatus(Status.OK_STATUS);
    } catch (Exception e) {
        // $NON-NLS-1$
        setStatus(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Error reading profiles", e));
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) TracePackageElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageElement) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 4 with TracePackageElement

use of org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageElement in project tracecompass by tracecompass.

the class RemoteGenerateManifestOperation method run.

// ------------------------------------------------------------------------
// Operation(s)
// ------------------------------------------------------------------------
@Override
public void run(IProgressMonitor monitor) {
    try {
        monitor.worked(1);
        String root = null;
        List<TracePackageElement> resultElementList = new ArrayList<>();
        SubMonitor subMonitor = SubMonitor.convert(monitor, fProfile.getChildren().length * 2);
        List<RemoteImportConnectionNodeElement> connectionNodes = fProfile.getConnectionNodeElements();
        for (RemoteImportConnectionNodeElement connectionNode : connectionNodes) {
            RemoteSystemProxy proxy = connectionNode.getRemoteSystemProxy();
            // create new element to decouple from input element
            RemoteImportConnectionNodeElement outputConnectionNode = new RemoteImportConnectionNodeElement(null, connectionNode.getName(), connectionNode.getURI());
            resultElementList.add(outputConnectionNode);
            for (TracePackageElement element : connectionNode.getChildren()) {
                if (element instanceof RemoteImportTraceGroupElement) {
                    ModalContext.checkCanceled(monitor);
                    RemoteImportTraceGroupElement traceGroup = (RemoteImportTraceGroupElement) element;
                    root = traceGroup.getRootImportPath();
                    TracePackageElement[] traceElements = traceGroup.getChildren();
                    fTemplatePatternsToTraceElements = generatePatterns(traceElements);
                    IRemoteFileService fs = proxy.getRemoteConnection().getService(IRemoteFileService.class);
                    if (fs == null) {
                        continue;
                    }
                    final IFileStore remoteFolder = fs.getResource(root);
                    // make sure that remote directory is read and not cached
                    int recursionLevel = 0;
                    // create new element to decouple from input element
                    RemoteImportTraceGroupElement outputTraceGroup = new RemoteImportTraceGroupElement(outputConnectionNode, traceGroup.getRootImportPath());
                    outputTraceGroup.setRecursive(traceGroup.isRecursive());
                    generateElementsFromArchive(outputTraceGroup, outputTraceGroup, remoteFolder, recursionLevel, subMonitor.newChild(1));
                    filterElements(outputTraceGroup);
                }
            }
        }
        setResultElements(resultElementList.toArray(new TracePackageElement[0]));
        setStatus(Status.OK_STATUS);
    } catch (InterruptedException e) {
        setStatus(Status.CANCEL_STATUS);
    } catch (Exception e) {
        setStatus(new Status(IStatus.ERROR, Activator.PLUGIN_ID, NLS.bind(RemoteMessages.RemoteGenerateManifest_GenerateProfileManifestError, fProfile.getText()), e));
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) ArrayList(java.util.ArrayList) SubMonitor(org.eclipse.core.runtime.SubMonitor) CoreException(org.eclipse.core.runtime.CoreException) RemoteSystemProxy(org.eclipse.tracecompass.tmf.remote.core.proxy.RemoteSystemProxy) TracePackageElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageElement) IFileStore(org.eclipse.core.filesystem.IFileStore) IRemoteFileService(org.eclipse.remote.core.IRemoteFileService)

Example 5 with TracePackageElement

use of org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageElement in project tracecompass by tracecompass.

the class RemoteImportProfilesReader method loadElementsFromProfiles.

/**
 * Load profile model elements the profiles file (input stream).
 *
 * The file format looks like this:
 * <pre>
 * &lt;?xml version="1.0" encoding="UTF-8" standalone="no"?>
 * &lt;profiles>
 *   &lt;version>0.1&lt;/version>
 *   &lt;profile name="myProfile">
 *     &lt;node name="myhost">
 *       &lt;uri>ssh://user@127.0.0.1:22&lt;/uri>
 *       &lt;traceGroup root="/home/user/lttng-traces/" recursive="true">
 *         &lt;trace name="" type="org.eclipse.linuxtools.tmf.ui.type.ctf">
 *           &lt;file name=".*" />
 *         &lt;/trace>
 *       &lt;/traceGroup>
 *     &lt;/node>
 *   &lt;/profile>
 * &lt;/profiles>
 * </pre>
 * See schema/remote-profile.xsd for details.
 *
 * @param inputStream
 *            the input stream that contains the profiles
 * @return the loaded elements
 * @throws IOException
 *             when an error occurs when parsing
 * @throws SAXException
 *             when an error occurs when parsing
 * @throws ParserConfigurationException
 *             when an error occurs when parsing
 */
public static TracePackageElement[] loadElementsFromProfiles(InputStream inputStream) throws IOException, SAXException, ParserConfigurationException {
    List<TracePackageElement> packageElements = new ArrayList<>();
    RemoteImportProfileElement profile = null;
    Document doc = XmlUtils.newSafeDocumentBuilderFactory().newDocumentBuilder().parse(inputStream);
    NodeList profileNodes = doc.getDocumentElement().getElementsByTagName(RemoteImportProfileConstants.PROFILE_ELEMENT);
    for (int i = 0; i < profileNodes.getLength(); i++) {
        Node profileNode = profileNodes.item(i);
        if (profileNode.getNodeType() == Node.ELEMENT_NODE) {
            Element profileElement = (Element) profileNode;
            String traceName = profileElement.getAttribute(RemoteImportProfileConstants.PROFILE_NAME_ATTRIB);
            profile = new RemoteImportProfileElement(null, traceName);
            NodeList nodeNodes = profileElement.getElementsByTagName(RemoteImportProfileConstants.NODE_ELEMENT);
            for (int j = 0; j < nodeNodes.getLength(); j++) {
                Node nodeNode = nodeNodes.item(j);
                if (nodeNode.getNodeType() == Node.ELEMENT_NODE) {
                    Element nodeElement = (Element) nodeNode;
                    String nameAttr = nodeElement.getAttribute(RemoteImportProfileConstants.NODE_NAME_ATTRIB);
                    NodeList uriNodes = nodeElement.getElementsByTagName(RemoteImportProfileConstants.NODE_URI_ELEMENT);
                    // $NON-NLS-1$
                    String uri = "";
                    for (int k = 0; k < uriNodes.getLength(); k++) {
                        Node uriNode = uriNodes.item(k);
                        if (uriNode.getNodeType() == Node.ELEMENT_NODE) {
                            Element uriElement = (Element) uriNode;
                            uri = uriElement.getFirstChild().getNodeValue();
                            break;
                        }
                    }
                    RemoteImportConnectionNodeElement connectionNode = new RemoteImportConnectionNodeElement(profile, nameAttr, uri);
                    NodeList traceGroupNodes = nodeElement.getElementsByTagName(RemoteImportProfileConstants.TRACE_GROUP_ELEMENT);
                    for (int k = 0; k < traceGroupNodes.getLength(); k++) {
                        Node traceGroupNode = traceGroupNodes.item(k);
                        if (traceGroupNode.getNodeType() == Node.ELEMENT_NODE) {
                            Element traceGroupElement = (Element) traceGroupNode;
                            String rootAttr = traceGroupElement.getAttribute(RemoteImportProfileConstants.TRACE_GROUP_ROOT_ATTRIB);
                            String recursiveAttr = traceGroupElement.getAttribute(RemoteImportProfileConstants.TRACE_GROUP_RECURSIVE_ATTRIB);
                            RemoteImportTraceGroupElement traceGroup = new RemoteImportTraceGroupElement(connectionNode, rootAttr);
                            traceGroup.setRecursive(Boolean.TRUE.toString().equals(recursiveAttr));
                            TracePackageElement[] e = ManifestReader.loadElementsFromNode(traceGroupElement);
                            for (TracePackageElement a : e) {
                                traceGroup.addChild(a);
                            }
                        }
                    }
                }
            }
            packageElements.add(profile);
        }
    }
    return packageElements.toArray(EMPTY_ARRAY);
}
Also used : NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) TracePackageElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageElement) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) Document(org.w3c.dom.Document) TracePackageElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageElement)

Aggregations

TracePackageElement (org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageElement)41 TracePackageTraceElement (org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageTraceElement)26 TracePackageFilesElement (org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageFilesElement)20 ArrayList (java.util.ArrayList)12 Element (org.w3c.dom.Element)11 RemoteImportProfileElement (org.eclipse.tracecompass.internal.tmf.remote.ui.wizards.fetch.model.RemoteImportProfileElement)9 IStatus (org.eclipse.core.runtime.IStatus)8 RemoteImportConnectionNodeElement (org.eclipse.tracecompass.internal.tmf.remote.ui.wizards.fetch.model.RemoteImportConnectionNodeElement)8 TracePackageExperimentElement (org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageExperimentElement)8 IPath (org.eclipse.core.runtime.IPath)7 Status (org.eclipse.core.runtime.Status)6 RemoteImportTraceGroupElement (org.eclipse.tracecompass.internal.tmf.remote.ui.wizards.fetch.model.RemoteImportTraceGroupElement)6 TracePackageBookmarkElement (org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageBookmarkElement)6 TracePackageSupplFileElement (org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageSupplFileElement)6 TracePackageSupplFilesElement (org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageSupplFilesElement)6 TmfCommonProjectElement (org.eclipse.tracecompass.tmf.ui.project.model.TmfCommonProjectElement)6 HashMap (java.util.HashMap)5 Path (org.eclipse.core.runtime.Path)5 Document (org.w3c.dom.Document)5 IFileStore (org.eclipse.core.filesystem.IFileStore)4