diff --git a/trace-server/org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core.tests/META-INF/MANIFEST.MF b/trace-server/org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core.tests/META-INF/MANIFEST.MF index 3cb671102..eb3510cc3 100644 --- a/trace-server/org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core.tests/META-INF/MANIFEST.MF +++ b/trace-server/org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core.tests/META-INF/MANIFEST.MF @@ -30,10 +30,14 @@ Export-Package: org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core.tests.utils Import-Package: com.fasterxml.jackson.annotation, com.fasterxml.jackson.core, + com.fasterxml.jackson.core.type, com.fasterxml.jackson.jaxrs.base, com.fasterxml.jackson.jaxrs.json, com.google.common.base, com.google.common.collect, + com.google.gson;version="2.8.2", + com.google.gson.annotations;version="2.8.2", + com.google.gson.reflect;version="2.8.2", javax.ws.rs, javax.ws.rs.client, javax.ws.rs.core, diff --git a/trace-server/org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core.tests/build.properties b/trace-server/org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core.tests/build.properties index e3b4e8580..4f810c643 100644 --- a/trace-server/org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core.tests/build.properties +++ b/trace-server/org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core.tests/build.properties @@ -16,4 +16,5 @@ bin.includes = META-INF/,\ about.html,\ plugin.properties,\ plugin.xml,\ - schema/ + schema/,\ + config/ diff --git a/trace-server/org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core.tests/config/custom-execution-analysis.json b/trace-server/org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core.tests/config/custom-execution-analysis.json new file mode 100644 index 000000000..f19ee4041 --- /dev/null +++ b/trace-server/org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core.tests/config/custom-execution-analysis.json @@ -0,0 +1,5 @@ +{ + "cpus": ["0", "1", "2"], + "thread": "my-thread", + "phone": "(123)345-567" +} diff --git a/trace-server/org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core.tests/src/org/eclipse/tracecompass/incubator/trace/server/jersey/rest/core/tests/services/ConfigurationManagerServiceTest.java b/trace-server/org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core.tests/src/org/eclipse/tracecompass/incubator/trace/server/jersey/rest/core/tests/services/ConfigurationManagerServiceTest.java index d082b12a6..c521d1e8f 100644 --- a/trace-server/org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core.tests/src/org/eclipse/tracecompass/incubator/trace/server/jersey/rest/core/tests/services/ConfigurationManagerServiceTest.java +++ b/trace-server/org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core.tests/src/org/eclipse/tracecompass/incubator/trace/server/jersey/rest/core/tests/services/ConfigurationManagerServiceTest.java @@ -13,11 +13,14 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import java.io.File; +import java.io.FileInputStream; import java.io.IOException; +import java.io.InputStream; import java.net.URISyntaxException; import java.net.URL; import java.util.Collections; @@ -33,14 +36,18 @@ import javax.ws.rs.core.Response; import org.eclipse.core.runtime.FileLocator; +import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.Platform; import org.eclipse.jdt.annotation.NonNull; +import org.eclipse.jdt.annotation.Nullable; +import org.eclipse.tracecompass.incubator.internal.trace.server.jersey.rest.core.model.views.ConfigurationQueryParameters; import org.eclipse.tracecompass.incubator.internal.trace.server.jersey.rest.core.model.views.QueryParameters; import org.eclipse.tracecompass.incubator.internal.trace.server.jersey.rest.core.services.ConfigurationManagerService; import org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core.tests.stubs.ExperimentModelStub; import org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core.tests.stubs.TmfConfigurationSourceTypeStub; import org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core.tests.stubs.TmfConfigurationStub; +import org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core.tests.stubs.config.TestSchemaConfigurationSource.Parameters; import org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core.tests.utils.RestServerTest; import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.module.XmlUtils; import org.eclipse.tracecompass.tmf.core.config.ITmfConfigParamDescriptor; @@ -50,7 +57,10 @@ import org.junit.Test; import org.osgi.framework.Bundle; +import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.google.gson.Gson; /** * Basic test for the {@link ConfigurationManagerService}. @@ -60,6 +70,7 @@ @SuppressWarnings("restriction") public class ConfigurationManagerServiceTest extends RestServerTest { + private static final Bundle TEST_BUNDLE = Platform.getBundle("org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core.tests"); private static final Bundle XML_CORE_TESTS = Platform.getBundle("org.eclipse.tracecompass.tmf.analysis.xml.core.tests"); private static final String UNKNOWN_TYPE = "test-test-test"; @@ -67,6 +78,7 @@ public class ConfigurationManagerServiceTest extends RestServerTest { private static final String PATH_VALID = "test_xml_files/test_valid/"; private static final String PATH = "path"; private static final String XML_ANALYSIS_TYPE_ID = "org.eclipse.tracecompass.tmf.core.config.xmlsourcetype"; + private static final String CONFIG_WITH_SCHEMA_ANALYSIS_TYPE_ID = "org.eclipse.tracecompass.tmf.core.config.testschemasourcetype"; private static final String EXPECTED_TYPE_NAME = "XML Data-driven analyses"; //$NON-NLS-1$ private static final String EXPECTED_TYPE_DESCRIPTION = "Data-driven analyses described in XML"; //$NON-NLS-1$ private static final String EXPECTED_KEY_NAME = "path"; @@ -80,6 +92,12 @@ public class ConfigurationManagerServiceTest extends RestServerTest { private static final String EXPECTED_CONFIG_DESCRIPTION = "XML Data-driven analysis: " + VALID_NAME; private static final String PATH_TO_INVALID_PATH = getPath(PATH_INVALID + INVALID_XML_FILE); private static final String PATH_TO_VALID_PATH = getPath(PATH_VALID + VALID_XML_FILE); + private static final String CONFIG_FOLDER_NAME = "config"; + private static final String VALID_JSON_FILENAME = "custom-execution-analysis.json"; + + private static final String EXPECTED_JSON_CONFIG_NAME = "My Config Name"; + private static final String EXPECTED_JSON_CONFIG_DESCRIPTION = "My Config Description"; + private static final String EXPECTED_JSON_CONFIG_ID = "My Config Id"; private static final GenericType CONFIGURATION = new GenericType<>() { }; private static final GenericType> LIST_CONFIGURATION_TYPE = new GenericType<>() { }; @@ -204,6 +222,37 @@ public void testCreateGetAndDelete() { } } + /** + * Test POST to create configurations using a schema. + * + * @throws IOException + * if exception occurs + * @throws URISyntaxException + * if exception occurs + */ + @Test + public void testCreateGetAndDeleteSchema() throws URISyntaxException, IOException { + try (Response response = createJsonConfig(VALID_JSON_FILENAME)) { + assertEquals(200, response.getStatus()); + TmfConfigurationStub config = response.readEntity(CONFIGURATION); + assertNotNull(config); + validateJsonConfig(config); + } + + List configurations = getConfigurations(CONFIG_WITH_SCHEMA_ANALYSIS_TYPE_ID); + assertEquals("Valid JSON configuration should be added", 1, configurations.size()); + assertTrue("Valid configuration instance should exist", configurations.stream().anyMatch(conf -> conf.getName().equals(EXPECTED_JSON_CONFIG_NAME))); + + TmfConfigurationStub config = getConfiguration(CONFIG_WITH_SCHEMA_ANALYSIS_TYPE_ID, configurations.get(0).getId()); + assertNotNull(config); + assertTrue("JSON configuration instance should exist", config.getId().equals(EXPECTED_JSON_CONFIG_ID)); + + try (Response response = deleteConfig(CONFIG_WITH_SCHEMA_ANALYSIS_TYPE_ID, config.getId())) { + assertEquals(200, response.getStatus()); + assertEquals("JSON configuration should have been deleted", 0, getConfigurations(CONFIG_WITH_SCHEMA_ANALYSIS_TYPE_ID).size()); + } + } + /** * Test PUT to update configurations using XML configuration source type. */ @@ -317,7 +366,26 @@ private static Response createConfig(String path, boolean isCorrectType) { parameters.put(PATH, path); } return endpoint.request(MediaType.APPLICATION_JSON) - .post(Entity.json(new QueryParameters(parameters, Collections.emptyList()))); + .post(Entity.json(new ConfigurationQueryParameters(parameters))); + } + + private static Response createJsonConfig(String jsonFileName) throws URISyntaxException, IOException { + String typeId = CONFIG_WITH_SCHEMA_ANALYSIS_TYPE_ID; + WebTarget endpoint = getApplicationEndpoint() + .path(CONFIG_PATH) + .path(TYPES_PATH) + .path(typeId) + .path(CONFIG_INSTANCES_PATH); + + IPath defaultPath = new org.eclipse.core.runtime.Path(CONFIG_FOLDER_NAME).append(jsonFileName); + URL url = FileLocator.find(TEST_BUNDLE, defaultPath, null); + File jsonFile = new File(FileLocator.toFileURL(url).toURI()); + try (InputStream inputStream = new FileInputStream(jsonFile)) { + ObjectMapper mapper = new ObjectMapper(); + Map params = mapper.readValue(inputStream, new TypeReference>() {}); + return endpoint.request(MediaType.APPLICATION_JSON) + .post(Entity.json(new ConfigurationQueryParameters(params))); + } } private static Response updateConfig(String path, String id) { @@ -349,32 +417,57 @@ private static Response updateConfig(String path, String id, boolean isCorrectTy parameters.put(PATH, path); } return endpoint.request(MediaType.APPLICATION_JSON) - .put(Entity.json(new QueryParameters(parameters, Collections.emptyList()))); + .put(Entity.json(new ConfigurationQueryParameters(parameters))); } private static Response deleteConfig(String id) { + return deleteConfig(null, id); + } + + private static Response deleteConfig(String type, String id) { + String requestType = type; + if (requestType == null) { + requestType = XML_ANALYSIS_TYPE_ID; + } WebTarget endpoint = getApplicationEndpoint() .path(CONFIG_PATH) .path(TYPES_PATH) - .path(XML_ANALYSIS_TYPE_ID) + .path(requestType) .path(CONFIG_INSTANCES_PATH); return endpoint.path(id).request().delete(); } private static List getConfigurations() { + return getConfigurations(null); + } + + private static List getConfigurations(@Nullable String type) { + String requestType = type; + if (requestType == null) { + requestType = XML_ANALYSIS_TYPE_ID; + } + WebTarget endpoint = getApplicationEndpoint() .path(CONFIG_PATH) .path(TYPES_PATH) - .path(XML_ANALYSIS_TYPE_ID) + .path(requestType) .path(CONFIG_INSTANCES_PATH); return endpoint.request().get(LIST_CONFIGURATION_TYPE); } private static TmfConfigurationStub getConfiguration(String configId) { + return getConfiguration(null, configId); + } + + private static TmfConfigurationStub getConfiguration(String type, String configId) { + String requestType = type; + if (requestType == null) { + requestType = XML_ANALYSIS_TYPE_ID; + } WebTarget endpoint = getApplicationEndpoint() .path(CONFIG_PATH) .path(TYPES_PATH) - .path(XML_ANALYSIS_TYPE_ID) + .path(requestType) .path(CONFIG_INSTANCES_PATH) .path(configId); return endpoint.request().get(CONFIGURATION); @@ -388,4 +481,22 @@ private static void validateConfig(ITmfConfiguration config) { assertEquals(EXPECTED_CONFIG_DESCRIPTION, config.getDescription()); assertTrue(config.getParameters().isEmpty()); } + + @SuppressWarnings("null") + private static void validateJsonConfig(ITmfConfiguration config) { + assertEquals(EXPECTED_JSON_CONFIG_NAME, config.getName()); + assertEquals(EXPECTED_JSON_CONFIG_ID, config.getId()); + assertEquals(CONFIG_WITH_SCHEMA_ANALYSIS_TYPE_ID, config.getSourceTypeId()); + assertEquals(EXPECTED_JSON_CONFIG_DESCRIPTION, config.getDescription()); + Map parameters = config.getParameters(); + assertNotNull(parameters); + String json = new Gson().toJson(parameters); + Parameters paramObj = new Gson().fromJson(json, Parameters.class); + assertNotNull(paramObj); + assertNotNull(paramObj.getCpus()); + assertEquals(3, paramObj.getCpus().size()); + assertEquals("(123)345-567", paramObj.getPhone()); + assertEquals("my-thread", paramObj.getThread()); + assertNull(paramObj.getLabel()); + } } diff --git a/trace-server/org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core.tests/src/org/eclipse/tracecompass/incubator/trace/server/jersey/rest/core/tests/stubs/config/TestSchemaConfigurationSource.java b/trace-server/org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core.tests/src/org/eclipse/tracecompass/incubator/trace/server/jersey/rest/core/tests/stubs/config/TestSchemaConfigurationSource.java index c7f6d438e..262c91cb9 100644 --- a/trace-server/org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core.tests/src/org/eclipse/tracecompass/incubator/trace/server/jersey/rest/core/tests/stubs/config/TestSchemaConfigurationSource.java +++ b/trace-server/org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core.tests/src/org/eclipse/tracecompass/incubator/trace/server/jersey/rest/core/tests/stubs/config/TestSchemaConfigurationSource.java @@ -28,10 +28,15 @@ 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.TmfConfigurationSourceType; import org.eclipse.tracecompass.tmf.core.exceptions.TmfConfigurationException; import org.osgi.framework.Bundle; +import com.google.common.collect.ImmutableList; +import com.google.gson.annotations.Expose; +import com.google.gson.annotations.SerializedName; + /** * Test class */ @@ -43,6 +48,12 @@ public class TestSchemaConfigurationSource implements ITmfConfigurationSource { private static final @NonNull String NAME = nullToEmptyString("Test Schema Type"); //$NON-NLS-1$ private static final @NonNull String DESCRIPTION = nullToEmptyString("Test Type with schema"); //$NON-NLS-1$ + private static final @NonNull String TEST_CONFIG_ID = "My Config Id"; //$NON-NLS-1$ + private static final @NonNull String TEST_CONFIG_NAME = "My Config Name"; //$NON-NLS-1$ + private static final @NonNull String TEST_CONFIG_DESCRIPTION = "My Config Description"; //$NON-NLS-1$ + + private ITmfConfiguration fConfiguration; + static { Bundle bundle = Platform.getBundle("org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core.tests"); IPath defaultPath = new org.eclipse.core.runtime.Path("schema/custom-execution-analysis.json"); //$NON-NLS-1$ @@ -74,7 +85,16 @@ public TestSchemaConfigurationSource() { @Override public @NonNull ITmfConfiguration create(@NonNull Map<@NonNull String, @NonNull Object> parameters) throws TmfConfigurationException { - throw new TmfConfigurationException("Not implemented yet"); //$NON-NLS-1$ + TmfConfiguration.Builder builder = new TmfConfiguration.Builder(); + ITmfConfiguration configuration = builder.setId(TEST_CONFIG_ID) + .setSourceTypeId(TEST_ANALYSIS_TYPE_ID) + .setDescription(TEST_CONFIG_DESCRIPTION) // should be taken from json string + .setName(TEST_CONFIG_NAME) // should be taken from json string + .setParameters(parameters) + .build(); + fConfiguration = configuration; + return configuration; + } @Override @@ -84,25 +104,100 @@ public TestSchemaConfigurationSource() { @Override public @Nullable ITmfConfiguration get(@NonNull String id) { - return null; + return fConfiguration; } @Override public @Nullable ITmfConfiguration remove(@NonNull String id) { - return null; + ITmfConfiguration configuration = fConfiguration; + fConfiguration = null; + return configuration; } @Override public boolean contains(@NonNull String id) { - return false; + ITmfConfiguration configuration = fConfiguration; + return configuration != null; } @Override public @NonNull List<@NonNull ITmfConfiguration> getConfigurations() { - return Collections.emptyList(); + ITmfConfiguration configuration = fConfiguration; + if (configuration == null) { + return Collections.emptyList(); + } + return ImmutableList.of(configuration); } @Override public void dispose() { } + + /** + * Class to deserialize json string + */ + public class Parameters { + @Expose + @SerializedName(value = "label") + private String fLabel; + @Expose + @SerializedName(value = "thread") + private String fThread; + @Expose + @SerializedName(value = "phone") + private String fPhone; + @Expose + @SerializedName(value = "cpus") + private List fCpus; + + /** + * Default constructor for GSON + */ + public Parameters() { + fLabel = ""; //$NON-NLS-1$ + fThread = ""; //$NON-NLS-1$ + fPhone = ""; //$NON-NLS-1$ + fCpus = Collections.emptyList(); //$NON-NLS-1$ + } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + return builder.append("[label=").append(fLabel) + .append(", thread=").append(fThread) + .append(", phone=").append("phone") + .append(", fCpus=").append(fCpus) + .append("]") + .toString(); + } + + /** + * @return list of cpus + */ + public List getCpus() { + return fCpus; + } + + /** + * @return phone number string + */ + public String getPhone() { + return fPhone; + } + + /** + * @return label + */ + public String getLabel() { + return fLabel; + } + + /** + * @return thread name + */ + public String getThread() { + return fThread; + } + } + } diff --git a/trace-server/org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core/src/org/eclipse/tracecompass/incubator/internal/trace/server/jersey/rest/core/model/Configuration.java b/trace-server/org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core/src/org/eclipse/tracecompass/incubator/internal/trace/server/jersey/rest/core/model/Configuration.java index bad5d21c0..5fd16babc 100644 --- a/trace-server/org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core/src/org/eclipse/tracecompass/incubator/internal/trace/server/jersey/rest/core/model/Configuration.java +++ b/trace-server/org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core/src/org/eclipse/tracecompass/incubator/internal/trace/server/jersey/rest/core/model/Configuration.java @@ -50,6 +50,6 @@ public interface Configuration { * @return parameters to return. Can be used to show * more details to users of the configuration instance */ - @Schema(description = "Optional informational parameters to return. Can be used to show more details to users of the configuration instance.") + @Schema(description = "Optional parameters representing the configuration parameters used to create this configuration.") Map getParameters(); } diff --git a/trace-server/org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core/src/org/eclipse/tracecompass/incubator/internal/trace/server/jersey/rest/core/model/ConfigurationQueryParameters.java b/trace-server/org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core/src/org/eclipse/tracecompass/incubator/internal/trace/server/jersey/rest/core/model/ConfigurationQueryParameters.java index 1de79b266..4d43fad21 100644 --- a/trace-server/org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core/src/org/eclipse/tracecompass/incubator/internal/trace/server/jersey/rest/core/model/ConfigurationQueryParameters.java +++ b/trace-server/org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core/src/org/eclipse/tracecompass/incubator/internal/trace/server/jersey/rest/core/model/ConfigurationQueryParameters.java @@ -15,6 +15,8 @@ import org.eclipse.jdt.annotation.NonNull; +import com.fasterxml.jackson.annotation.JsonProperty; + import io.swagger.v3.oas.annotations.media.Schema; /** @@ -23,9 +25,36 @@ public interface ConfigurationQueryParameters { /** - * @return The query parameter map. + * @return The parameters. */ @NonNull - @Schema(required = true, description = "Parameters as specified in corresponding ConfigurationTypeDescriptor. Use key `path` for file URI string values.") - Map getParameters(); + @Schema(required = true) + ConfigurationParameters getParameters(); + + /** + * No expected properties below, as per current trace-server protocol. + */ + interface ConfigurationParameters { + /** + * @return the name of the configuration + */ + @Schema(required = true, description = "Unique name of the configuration. If omitted a unique name will be generated.") + String getName(); + /** + * @return the description of the configuration + */ + @Schema(required = false, description = "Optional description of the configuration.") + String getDescription(); + /** + * @return the typeId of the configuration according to the {@link ConfigurationSourceType} + */ + @Schema(required = false, description = "Optional typeId of the configuration according to the corresponding ConfigurationTypeDescriptor. Omit if it's part of the endpoint URI.") + @JsonProperty("typeId") + String getTypeId(); + /** + * @return properties map as defined in the corresponding {@link ConfigurationSourceType} + */ + @Schema(required = true, description = "Properties as specified in the schema or list of ConfigurationParameterDescriptor of the corresponding ConfigurationTypeDescriptor.") + Map getProperties(); + } } diff --git a/trace-server/org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core/src/org/eclipse/tracecompass/incubator/internal/trace/server/jersey/rest/core/model/views/ConfigurationQueryParameters.java b/trace-server/org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core/src/org/eclipse/tracecompass/incubator/internal/trace/server/jersey/rest/core/model/views/ConfigurationQueryParameters.java new file mode 100644 index 000000000..f211d3f83 --- /dev/null +++ b/trace-server/org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core/src/org/eclipse/tracecompass/incubator/internal/trace/server/jersey/rest/core/model/views/ConfigurationQueryParameters.java @@ -0,0 +1,58 @@ +/******************************************************************************* + * Copyright (c) 2024 Ericsson + * + * All rights reserved. This program and the accompanying materials are + * made available under the terms of the Eclipse Public License 2.0 which + * accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + *******************************************************************************/ + +package org.eclipse.tracecompass.incubator.internal.trace.server.jersey.rest.core.model.views; + +import java.util.HashMap; +import java.util.Map; + +import org.eclipse.jdt.annotation.NonNull; + +import io.swagger.v3.oas.annotations.Hidden; + +/** + * Definition of a parameters object received by the server from a client for configurations. + */ +public class ConfigurationQueryParameters { + private @NonNull Map parameters; + + /** + * Constructor for Jackson + */ + public ConfigurationQueryParameters() { + // Default constructor for Jackson + this.parameters = new HashMap<>(); + } + + /** + * Constructor. + * + * @param parameters + * Map of parameters + */ + public ConfigurationQueryParameters(Map parameters) { + this.parameters = parameters != null ? parameters : new HashMap<>(); + } + + /** + * @return Map of parameters + */ + @Hidden + public @NonNull Map getParameters() { + return parameters; + } + + @SuppressWarnings("nls") + @Override + public String toString() { + return "ConfigurationQueryParameters [parameters=" + parameters + "]"; + } +} diff --git a/trace-server/org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core/src/org/eclipse/tracecompass/incubator/internal/trace/server/jersey/rest/core/services/ConfigurationManagerService.java b/trace-server/org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core/src/org/eclipse/tracecompass/incubator/internal/trace/server/jersey/rest/core/services/ConfigurationManagerService.java index e1ddfb7f0..adc3a335f 100644 --- a/trace-server/org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core/src/org/eclipse/tracecompass/incubator/internal/trace/server/jersey/rest/core/services/ConfigurationManagerService.java +++ b/trace-server/org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core/src/org/eclipse/tracecompass/incubator/internal/trace/server/jersey/rest/core/services/ConfigurationManagerService.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2023 Ericsson + * Copyright (c) 2023, 2024 Ericsson * * All rights reserved. This program and the accompanying materials are * made available under the terms of the Eclipse Public License 2.0 which @@ -19,8 +19,6 @@ import static org.eclipse.tracecompass.incubator.internal.trace.server.jersey.rest.core.services.EndpointConstants.CFG_UPDATE_DESC; import static org.eclipse.tracecompass.incubator.internal.trace.server.jersey.rest.core.services.EndpointConstants.INVALID_PARAMETERS; -import java.util.Map; - import javax.ws.rs.Consumes; import javax.ws.rs.DELETE; import javax.ws.rs.GET; @@ -33,9 +31,7 @@ import javax.ws.rs.core.Response; import javax.ws.rs.core.Response.Status; -import org.eclipse.jdt.annotation.NonNull; -import org.eclipse.tracecompass.incubator.internal.trace.server.jersey.rest.core.model.ConfigurationQueryParameters; -import org.eclipse.tracecompass.incubator.internal.trace.server.jersey.rest.core.model.views.QueryParameters; +import org.eclipse.tracecompass.incubator.internal.trace.server.jersey.rest.core.model.views.ConfigurationQueryParameters; import org.eclipse.tracecompass.tmf.core.config.ITmfConfiguration; import org.eclipse.tracecompass.tmf.core.config.ITmfConfigurationSource; import org.eclipse.tracecompass.tmf.core.config.TmfConfigurationSourceManager; @@ -132,6 +128,7 @@ public Response getConfigurations(@Parameter(description = CFG_TYPE_ID) @PathPar * the query parameters * @return status and collection of configuration descriptor, if successful */ + @SuppressWarnings("null") @POST @Path("/types/{typeId}/configs") @Consumes(MediaType.APPLICATION_JSON) @@ -145,8 +142,8 @@ public Response getConfigurations(@Parameter(description = CFG_TYPE_ID) @PathPar public Response postConfiguration(@Parameter(description = CFG_TYPE_ID) @PathParam("typeId") String typeId, @RequestBody(description = CFG_CREATE_DESC + " " + CFG_KEYS_DESC, content = { @Content(examples = @ExampleObject("{\"parameters\":{" + CFG_PATH_EX + - "}}"), schema = @Schema(implementation = ConfigurationQueryParameters.class)) - }, required = true) QueryParameters queryParameters) { + "}}"), schema = @Schema(implementation = org.eclipse.tracecompass.incubator.internal.trace.server.jersey.rest.core.model.ConfigurationQueryParameters.class)) + }, required = true) ConfigurationQueryParameters queryParameters) { ITmfConfigurationSource configurationSource = fConfigSourceManager.getConfigurationSource(typeId); if (configurationSource == null) { return Response.status(Status.NOT_FOUND).entity("Configuration source type doesn't exist").build(); //$NON-NLS-1$ @@ -155,11 +152,8 @@ public Response postConfiguration(@Parameter(description = CFG_TYPE_ID) @PathPar return Response.status(Status.BAD_REQUEST).entity(EndpointConstants.MISSING_PARAMETERS).build(); } - @SuppressWarnings("null") - @NonNull Map<@NonNull String, @NonNull Object> params = queryParameters.getParameters(); - try { - ITmfConfiguration config = configurationSource.create(params); + ITmfConfiguration config = configurationSource.create(queryParameters.getParameters()); return Response.ok(config).build(); } catch (TmfConfigurationException e) { return Response.status(Status.BAD_REQUEST).entity(e.getMessage()).build(); @@ -219,12 +213,13 @@ public Response getConfiguration(@Parameter(description = CFG_TYPE_ID) @PathPara @ApiResponse(responseCode = "404", description = EndpointConstants.NO_SUCH_CONFIGURATION, content = @Content(schema = @Schema(implementation = String.class))), @ApiResponse(responseCode = "500", description = "Internal trace-server error while trying to update configuration instance", content = @Content(schema = @Schema(implementation = String.class))) }) + @SuppressWarnings("null") public Response putConfiguration(@Parameter(description = CFG_TYPE_ID) @PathParam("typeId") String typeId, @Parameter(description = CFG_CONFIG_ID) @PathParam("configId") String configId, @RequestBody(description = CFG_UPDATE_DESC + " " + CFG_KEYS_DESC, content = { @Content(examples = @ExampleObject("{\"parameters\":{" + CFG_PATH_EX + - "}}"), schema = @Schema(implementation = ConfigurationQueryParameters.class)) - }, required = true) QueryParameters queryParameters) { + "}}"), schema = @Schema(implementation = org.eclipse.tracecompass.incubator.internal.trace.server.jersey.rest.core.model.ConfigurationQueryParameters.class)) + }, required = true) ConfigurationQueryParameters queryParameters) { ITmfConfigurationSource configurationSource = fConfigSourceManager.getConfigurationSource(typeId); if (configurationSource == null) { return Response.status(Status.NOT_FOUND).entity("Configuration source type doesn't exist").build(); //$NON-NLS-1$ @@ -237,10 +232,8 @@ public Response putConfiguration(@Parameter(description = CFG_TYPE_ID) @PathPara return Response.status(Status.NOT_FOUND).entity("Configuration instance doesn't exist for type " + typeId).build(); //$NON-NLS-1$ } - @SuppressWarnings("null") - @NonNull Map<@NonNull String, @NonNull Object> params = queryParameters.getParameters(); try { - ITmfConfiguration config = configurationSource.update(configId, params); + ITmfConfiguration config = configurationSource.update(configId, queryParameters.getParameters()); return Response.ok(config).build(); } catch (TmfConfigurationException e) { return Response.status(Status.BAD_REQUEST).entity(e.getMessage()).build(); diff --git a/trace-server/org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core/src/org/eclipse/tracecompass/incubator/internal/trace/server/jersey/rest/core/webapp/TmfConfigurationSerializer.java b/trace-server/org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core/src/org/eclipse/tracecompass/incubator/internal/trace/server/jersey/rest/core/webapp/TmfConfigurationSerializer.java index a75326fd0..f146f2f66 100644 --- a/trace-server/org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core/src/org/eclipse/tracecompass/incubator/internal/trace/server/jersey/rest/core/webapp/TmfConfigurationSerializer.java +++ b/trace-server/org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core/src/org/eclipse/tracecompass/incubator/internal/trace/server/jersey/rest/core/webapp/TmfConfigurationSerializer.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2023 Ericsson + * Copyright (c) 2023, 2024 Ericsson * * All rights reserved. This program and the accompanying materials are * made available under the terms of the Eclipse Public License 2.0 which @@ -47,7 +47,7 @@ public void serialize(ITmfConfiguration value, JsonGenerator gen, SerializerProv gen.writeStringField("description", value.getDescription()); //$NON-NLS-1$ gen.writeStringField("sourceTypeId", value.getSourceTypeId()); //$NON-NLS-1$ // if (!value.getParameters().isEmpty()) { - gen.writeObjectField("parameters", value.getParameters()); //$NON-NLS-1$ + gen.writeObjectField("parameters", value.getParameters()); //$NON-NLS-1$ // } gen.writeEndObject(); }