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;
}
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;
}
});
}
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));
}
}
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));
}
}
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>
* <?xml version="1.0" encoding="UTF-8" standalone="no"?>
* <profiles>
* <version>0.1</version>
* <profile name="myProfile">
* <node name="myhost">
* <uri>ssh://user@127.0.0.1:22</uri>
* <traceGroup root="/home/user/lttng-traces/" recursive="true">
* <trace name="" type="org.eclipse.linuxtools.tmf.ui.type.ctf">
* <file name=".*" />
* </trace>
* </traceGroup>
* </node>
* </profile>
* </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);
}
Aggregations