Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for data provider capabilities in server and InAndOut analysis #138

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.eclipse.tracecompass.tmf.core.dataprovider.IDataProviderDescriptor.ProviderType;
import org.eclipse.tracecompass.tmf.core.dataprovider.IDataProviderFactory;
import org.eclipse.tracecompass.tmf.core.exceptions.TmfConfigurationException;
import org.eclipse.tracecompass.tmf.core.model.DataProviderCapabilities;
import org.eclipse.tracecompass.tmf.core.model.DataProviderDescriptor;
import org.eclipse.tracecompass.tmf.core.model.tree.ITmfTreeDataProvider;
import org.eclipse.tracecompass.tmf.core.signal.TmfSignalManager;
Expand Down Expand Up @@ -72,6 +73,7 @@ public class InAndOutDataProviderFactoryTest {
.setName(EXPECTED_CONFIGURATOR_NAME)
.setDescription(EXPECTED_CONFIGURATOR_DESCRIPTION)
.setProviderType(ProviderType.NONE)
.setCapabilities(new DataProviderCapabilities.Builder().setCanCreate(true).build())
.build();

private static InAndOutDataProviderFactory sfFixture = new InAndOutDataProviderFactory();
Expand Down Expand Up @@ -166,6 +168,7 @@ public void testCreateAndDeleteDataProviderDescriptor() throws TmfConfigurationE
assertEquals(CUSTOM_IN_AND_OUT_ANALYSIS_DESCRIPTION, descriptor.getDescription());
assertEquals(ProviderType.NONE, descriptor.getType());
assertEquals(EXPECTED_FACTORY_ID, descriptor.getParentId());
assertEquals(new DataProviderCapabilities.Builder().setCanDelete(true).build(), descriptor.getCapabilities());
ITmfConfiguration config = descriptor.getConfiguration();
assertNotNull(config);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2024 Ericsson
* Copyright (c) 2024, 2025 Ericsson
*
* All rights reserved. This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0 which
Expand Down Expand Up @@ -37,6 +37,7 @@
import org.eclipse.tracecompass.tmf.core.dataprovider.IDataProviderDescriptor.ProviderType;
import org.eclipse.tracecompass.tmf.core.dataprovider.IDataProviderFactory;
import org.eclipse.tracecompass.tmf.core.exceptions.TmfConfigurationException;
import org.eclipse.tracecompass.tmf.core.model.DataProviderCapabilities;
import org.eclipse.tracecompass.tmf.core.model.DataProviderDescriptor;
import org.eclipse.tracecompass.tmf.core.model.tree.ITmfTreeDataModel;
import org.eclipse.tracecompass.tmf.core.model.tree.ITmfTreeDataProvider;
Expand Down Expand Up @@ -98,6 +99,7 @@ public class InAndOutDataProviderFactory implements IDataProviderFactory, ITmfDa
.setName(CONFIGURATOR_NAME)
.setDescription(CONFIGURATOR_DESCRIPTION)
.setProviderType(ProviderType.NONE)
.setCapabilities(new DataProviderCapabilities.Builder().setCanCreate(true).build())
.build();

/**
Expand Down Expand Up @@ -264,6 +266,7 @@ private static IDataProviderDescriptor getDescriptorFromConfig(ITmfConfiguration
.setDescription(NLS.bind(CUSTOM_IN_AND_OUT_ANALYSIS_DESCRIPTION, config.getName()))
.setProviderType(ProviderType.NONE)
.setConfiguration(config)
.setCapabilities(new DataProviderCapabilities.Builder().setCanDelete(true).build())
.build();
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2018, 2024 Ericsson
* Copyright (c) 2018, 2025 Ericsson
*
* All rights reserved. This program and the accompanying materials are
* made available under the terms of the Eclipse Public License 2.0 which
Expand All @@ -14,7 +14,9 @@
import java.io.IOException;

import org.eclipse.tracecompass.tmf.core.config.ITmfConfiguration;
import org.eclipse.tracecompass.tmf.core.dataprovider.IDataProviderCapabilities;
import org.eclipse.tracecompass.tmf.core.dataprovider.IDataProviderDescriptor;
import org.eclipse.tracecompass.tmf.core.model.DataProviderCapabilities;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.SerializerProvider;
Expand Down Expand Up @@ -55,6 +57,13 @@ public void serialize(IDataProviderDescriptor value, JsonGenerator gen, Serializ
if (config != null) {
gen.writeObjectField("configuration", config); //$NON-NLS-1$
}
IDataProviderCapabilities cap = value.getCapabilities();
if (cap != DataProviderCapabilities.NULL_INSTANCE) {
gen.writeObjectFieldStart("capabilities"); //$NON-NLS-1$
gen.writeBooleanField("canCreate", cap.canCreate()); //$NON-NLS-1$
gen.writeBooleanField("canDelete", cap.canDelete()); //$NON-NLS-1$
gen.writeEndObject();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would this be the same as using writeObjectField on the capabilities?
The difference could be that we are fixing the capabilities to serialize even if new ones are added to the class.

Copy link
Contributor Author

@bhufmann bhufmann Jan 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The method getCapabilities returns an instance of IDataProviderCapabilities, but it doesn't guarantee that it is DataProviderCapabilities object which has 2 boolean fields canDelete and canCreate. It could be just an anonymous class that returns hardcoded values for methods canDelete and canCreate. For that case, the serialization would cause an exception. To rely on writeObjectField we would have to have jackson annotated classes. Not sure if it would work if the annotation is on the interface methods.

Besides, we have not added the jackson dependency to Trace Compass core for that, because our stand was that the TSP client to trace server interface is not the same than the trace server to Trace Compass core interface, where the latter is the Trace Compass interface, that is also used in classic Trace Compass. If we had started without the legacy code and the TSP as main interface, then we probably would have done it differently.

Copy link
Contributor Author

@bhufmann bhufmann Jan 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note, it would be possible to re-visit how internal data structures are serialized over the TSP using jackson annotation. But that should be a separate task for all TSP data structures.

}
gen.writeEndObject();
}

Expand Down
Loading