Kris20030907 opened a new issue, #508:
URL: https://github.com/apache/rocketmq-dashboard/issues/508

   ## Background
   
   The RocketMQ Studio settings page now calls the backend data source APIs. 
When a user creates a data source, the frontend submits the editable form 
fields but does not provide a `key`, because the identifier should be assigned 
by the server.
   
   The backend currently passes this request directly to 
`InMemorySettingsRepository`, which uses `dataSource.getKey()` as a 
`ConcurrentHashMap` key. `ConcurrentHashMap` does not allow null keys, so a 
normal create request fails.
   
   ## Steps to reproduce
   
   1. Start the RocketMQ Studio backend.
   2. Send a request equivalent to the settings form:
   
   ```bash
   curl -X POST http://127.0.0.1:8888/api/settings/datasources/create \
     -H 'Content-Type: application/json' \
     -d '{
       "name": "Local Prometheus",
       "type": "Prometheus",
       "url": "http://127.0.0.1:9090";,
       "auth": "None"
     }'
   ```
   
   ## Actual behavior
   
   The endpoint returns HTTP 500:
   
   ```json
   {
     "code": 500,
     "message": "Internal Server Error",
     "data": null
   }
   ```
   
   The server log contains:
   
   ```text
   java.lang.NullPointerException
       at java.util.concurrent.ConcurrentHashMap.put(...)
       at 
com.rocketmq.studio.settings.InMemorySettingsRepository.saveDataSource(...)
       at com.rocketmq.studio.settings.SettingsService.createDataSource(...)
   ```
   
   ## Expected behavior
   
   - The server should assign a unique key when creating a data source.
   - The create endpoint should return HTTP 200 with the generated key.
   - The created data source should be available for subsequent list, update, 
and delete operations.
   - A client-provided key on the create endpoint should not overwrite an 
existing data source.
   
   ## Proposed change
   
   - Generate a UUID in `SettingsService.createDataSource()` before saving the 
data source.
   - Always replace a client-provided key for create requests.
   - Add service tests for missing and client-provided keys.
   - Add a repository test covering create, update, lookup, and delete by key.
   
   ## Scope
   
   This issue only fixes identifier assignment for data source creation. 
Persistent storage and real data source connection testing are outside its 
scope.
   
   ## Acceptance criteria
   
   - Creating a data source without a key succeeds and returns a non-empty 
server-generated key.
   - Creating a data source with a client-provided key still generates a new 
key.
   - The generated key can be used to update and delete the data source.
   - Relevant backend tests pass.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to