Batch system config update (#1402)

* Added an endpoint for batch update of system configurations

Signed-off-by: Denislav Prinov <denislav.prinov@bosch.com>

* batch db save

Signed-off-by: Denislav Prinov <denislav.prinov@bosch.com>

* Review changes and added tests

Signed-off-by: Denislav Prinov <denislav.prinov@bosch.com>

* Evict cache only if transaction is commited - such as @CacheEvict

Signed-off-by: Denislav Prinov <denislav.prinov@bosch.com>

* refactoring

Signed-off-by: Denislav Prinov <denislav.prinov@bosch.com>

* Using AfterTransactionCommitExecutor for cache eviction

Signed-off-by: Denislav Prinov <denislav.prinov@bosch.com>

* Change request body

Signed-off-by: Denislav Prinov <denislav.prinov@bosch.com>

---------

Signed-off-by: Denislav Prinov <denislav.prinov@bosch.com>
This commit is contained in:
Denislav Prinov
2023-08-02 11:15:27 +03:00
committed by GitHub
parent 1dc1bdbe94
commit fb30999d73
7 changed files with 201 additions and 28 deletions

View File

@@ -9,7 +9,9 @@
package org.eclipse.hawkbit.mgmt.rest.resource;
import java.io.Serializable;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import org.eclipse.hawkbit.mgmt.json.model.system.MgmtSystemTenantConfigurationValue;
import org.eclipse.hawkbit.mgmt.json.model.system.MgmtSystemTenantConfigurationValueRequest;
@@ -76,4 +78,22 @@ public class MgmtTenantManagementResource implements MgmtTenantManagementRestApi
return ResponseEntity.ok(MgmtTenantManagementMapper.toResponse(keyName, updatedValue));
}
@Override
public ResponseEntity<List<MgmtSystemTenantConfigurationValue>> updateTenantConfiguration(
Map<String, Serializable> configurationValueMap) {
boolean containsNull = configurationValueMap.keySet().stream()
.anyMatch(Objects::isNull);
if (containsNull) {
return ResponseEntity.badRequest().build();
}
Map<String, TenantConfigurationValue<Serializable>> tenantConfigurationValues = tenantConfigurationManagement
.addOrUpdateConfiguration(configurationValueMap);
return ResponseEntity.ok(tenantConfigurationValues.entrySet().stream().map(entry ->
MgmtTenantManagementMapper.toResponse(entry.getKey(), entry.getValue())).toList());
}
}

View File

@@ -32,6 +32,14 @@ public class MgmtTenantManagementResourceTest extends AbstractManagementApiInteg
private static final String KEY_MULTI_ASSIGNMENTS = "multi.assignments.enabled";
private static final String KEY_AUTO_CLOSE = "repository.actions.autoclose.enabled";
private static final String ROLLOUT_APPROVAL_ENABLED = "rollout.approval.enabled";
private static final String AUTHENTICATION_GATEWAYTOKEN_ENABLED = "authentication.gatewaytoken.enabled";
private static final String AUTHENTICATION_GATEWAYTOKEN_KEY = "authentication.gatewaytoken.key";
@Test
@Description("The 'multi.assignments.enabled' property must not be changed to false.")
@@ -48,6 +56,36 @@ public class MgmtTenantManagementResourceTest extends AbstractManagementApiInteg
.andExpect(status().isForbidden());
}
@Test
@Description("The Batch configuration should be applied")
public void changeBatchConfiguration() throws Exception {
JSONObject configuration = new JSONObject();
configuration.put(ROLLOUT_APPROVAL_ENABLED, true);
configuration.put(AUTHENTICATION_GATEWAYTOKEN_ENABLED, true);
configuration.put(AUTHENTICATION_GATEWAYTOKEN_KEY, "1234");
String body = configuration.toString();
mvc.perform(put(MgmtRestConstants.SYSTEM_V1_REQUEST_MAPPING + "/configs")
.content(body).contentType(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk());
}
@Test
@Description("The Batch configuration should not be applied")
public void changeBatchConfigurationFail() throws Exception {
JSONObject configuration = new JSONObject();
configuration.put(ROLLOUT_APPROVAL_ENABLED, true);
configuration.put(AUTHENTICATION_GATEWAYTOKEN_ENABLED, "wrong");
configuration.put(AUTHENTICATION_GATEWAYTOKEN_KEY, "1234");
String body = configuration.toString();
mvc.perform(put(MgmtRestConstants.SYSTEM_V1_REQUEST_MAPPING + "/configs")
.content(body).contentType(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print())
.andExpect(status().isBadRequest());
}
@Test
@Description("The 'repository.actions.autoclose.enabled' property must not be modified if Multi-Assignments is enabled.")
public void autoCloseCannotBeModifiedIfMultiAssignmentIsEnabled() throws Exception {