Skip to content

Commit

Permalink
tmf: Use ITmfConfiguration configuration create and update methods
Browse files Browse the repository at this point in the history
- Add new API and default implementation of create and update methods in
ITmfConfigurationSource.
- Change create method of ITmfDataProviderConfigurator. It has not been
released and can be changed.

This is as alternative to Map<String, Object>.

[Added] ITmfConfiguration configuration create and update methods

Signed-off-by: Bernd Hufmann <[email protected]>
  • Loading branch information
bhufmann committed Oct 21, 2024
1 parent b4d59f0 commit fc2ecef
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.eclipse.tracecompass.tmf.core.config.ITmfConfiguration;
import org.eclipse.tracecompass.tmf.core.config.ITmfConfigurationSource;
import org.eclipse.tracecompass.tmf.core.config.ITmfConfigurationSourceType;
import org.eclipse.tracecompass.tmf.core.config.TmfConfiguration;
import org.eclipse.tracecompass.tmf.core.config.TmfConfigurationSourceManager;
import org.eclipse.tracecompass.tmf.core.exceptions.TmfConfigurationException;
import org.junit.After;
Expand Down Expand Up @@ -184,6 +185,58 @@ public void testCreation() {
}
}


/**
* Test the creation of a configuration instance
*/
@Test
public void testCreationNewApi() {
// Test missing path
Map<String, Object> param = Collections.emptyMap();

TmfConfiguration.Builder builder = new TmfConfiguration.Builder();
builder.setId("test.id")
.setName("Dummy")
.setDescription("Dummy")
.setName(EXPECTED_CONFIG_NAME)
.setSourceTypeId(XML_ANALYSIS_TYPE_ID)
.setParameters(param);

ITmfConfiguration config = builder.build();
try {
sfXmlConfigSource.create(config);
} catch (TmfConfigurationException e) {
// success
assertEquals(EXPECTED_MESSAGE_NO_PATH, e.getMessage());
}

// Test XML file doesn't exist
param = ImmutableMap.of(EXPECTED_KEY_NAME, XmlUtils.getXmlFilesPath().append(UNKNOWN_TYPE).toOSString());
config = builder.setParameters(param).build();
try {
sfXmlConfigSource.create(config);
} catch (TmfConfigurationException e) {
// success
assertEquals(EXPECTED_MESSAGE_FILE_NOT_FOUND, e.getMessage());
}

// Test invalid XML file
config = builder.setParameters(INVALID_PARAM).build();
try {
sfXmlConfigSource.create(config);
} catch (TmfConfigurationException e) {
// success
}

config = builder.setParameters(VALID_PARAM).build();
try {
ITmfConfiguration configInstance = sfXmlConfigSource.create(config);
validateConfig(PATH_TO_VALID_FILE, configInstance);
} catch (TmfConfigurationException e) {
fail();
}
}

/**
* Test the update of a configuration instance
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,23 @@ public interface ITmfConfigurationSource {
*/
ITmfConfiguration create(Map<String, Object> parameters) throws TmfConfigurationException;

/**
* Creates a new configuration instance.
* <p>
* The parameters to be provided are described by
* {@link ITmfConfigurationSourceType#getConfigParamDescriptors()}.
*
* @param configuration
* The input configuration parameters to create a configuration instance.
* @return a new {@link ITmfConfiguration} if successful
* @throws TmfConfigurationException
* If the creation of the configuration fails
* @since 9.5
*/
default ITmfConfiguration create(ITmfConfiguration configuration) throws TmfConfigurationException {
return create(configuration.getParameters());
}

/**
* Updates a configuration instance.
* <p>
Expand All @@ -59,6 +76,25 @@ public interface ITmfConfigurationSource {
*/
ITmfConfiguration update(String id, Map<String, Object> parameters) throws TmfConfigurationException;

/**
* Updates a configuration instance.
* <p>
* The parameters to be provided are described by
* {@link ITmfConfigurationSourceType#getConfigParamDescriptors()}.
*
* @param id
* The configuration ID of the configuration to update
* @param configuration
* The input configuration parameters to update a configuration instance.
* @return a new {@link ITmfConfiguration} if successful
* @throws TmfConfigurationException
* If the update of the configuration fails
* @since 9.5
*/
default ITmfConfiguration update(String id, ITmfConfiguration configuration) throws TmfConfigurationException {
return update(id, configuration.getParameters());
}

/**
* Gets a configuration instance.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
package org.eclipse.tracecompass.tmf.core.config;

import java.util.List;
import java.util.Map;

import org.eclipse.tracecompass.tmf.core.dataprovider.DataProviderManager;
import org.eclipse.tracecompass.tmf.core.dataprovider.IDataProviderDescriptor;
Expand Down Expand Up @@ -40,24 +39,21 @@ public interface ITmfDataProviderConfigurator {
* creation configuration through
* {@link IDataProviderDescriptor#getConfiguration()}.
*
* @param typeId
* The Configuration type ID specified in corresponding
* {@link ITmfConfigurationSourceType}
* @param trace
* The trace (or experiment) instance
* @param parameters
* @param configuration
* The configuration parameters.
* @return a data provider descriptor corresponding to the derived data
* provider.
*
* @throws TmfConfigurationException
* if an error occurs
*/
IDataProviderDescriptor createDataProviderDescriptors(String typeId, ITmfTrace trace, Map<String, Object> parameters) throws TmfConfigurationException;
IDataProviderDescriptor createDataProviderDescriptors(ITmfTrace trace, ITmfConfiguration configuration) throws TmfConfigurationException;

/**
* Remove a data provider provider that was created by
* {@link #createDataProviderDescriptors(String, ITmfTrace, Map)}
* {@link #createDataProviderDescriptors(ITmfTrace, ITmfConfiguration)}
*
* @param trace
* The trace (or experiment) instance
Expand Down

0 comments on commit fc2ecef

Please sign in to comment.