Custom Tenant configuration. (#395)

* Tenant configuration configurable.
Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>
This commit is contained in:
Kai Zimmermann
2016-12-23 07:19:46 +01:00
committed by GitHub
parent 4d35413f71
commit feb3369858
53 changed files with 730 additions and 447 deletions

View File

@@ -11,13 +11,14 @@ package org.eclipse.hawkbit.mgmt.rest.resource;
import static org.springframework.hateoas.mvc.ControllerLinkBuilder.linkTo;
import static org.springframework.hateoas.mvc.ControllerLinkBuilder.methodOn;
import java.util.HashMap;
import java.util.Map;
import java.util.stream.Collectors;
import org.eclipse.hawkbit.mgmt.json.model.system.MgmtSystemTenantConfigurationValue;
import org.eclipse.hawkbit.repository.TenantConfigurationManagement;
import org.eclipse.hawkbit.repository.model.TenantConfigurationValue;
import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationKey;
import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationProperties;
import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationProperties.TenantConfigurationKey;
/**
* A mapper which maps repository model to RESTful model representation and
@@ -32,19 +33,17 @@ public final class MgmtSystemMapper {
/**
* @param tenantConfigurationManagement
* instance of TenantConfigurationManagement
* @param tenantConfigurationProperties
* to get defined keys
* @return a map of all existing configuration values
*/
public static Map<String, MgmtSystemTenantConfigurationValue> toResponse(
final TenantConfigurationManagement tenantConfigurationManagement) {
final TenantConfigurationManagement tenantConfigurationManagement,
final TenantConfigurationProperties tenantConfigurationProperties) {
final Map<String, MgmtSystemTenantConfigurationValue> configurationMap = new HashMap<>();
for (final TenantConfigurationKey key : TenantConfigurationKey.values()) {
configurationMap.put(key.getKeyName(),
toResponse(key.getKeyName(), tenantConfigurationManagement.getConfigurationValue(key)));
}
return configurationMap;
return tenantConfigurationProperties.getConfigurationKeys().stream()
.collect(Collectors.toMap(TenantConfigurationKey::getKeyName, key -> toResponse(key.getKeyName(),
tenantConfigurationManagement.getConfigurationValue(key.getKeyName()))));
}
/**

View File

@@ -19,7 +19,7 @@ import org.eclipse.hawkbit.mgmt.json.model.system.MgmtSystemTenantConfigurationV
import org.eclipse.hawkbit.mgmt.rest.api.MgmtSystemRestApi;
import org.eclipse.hawkbit.repository.TenantConfigurationManagement;
import org.eclipse.hawkbit.repository.model.TenantConfigurationValue;
import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationKey;
import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationProperties;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@@ -38,8 +38,15 @@ public class MgmtSystemResource implements MgmtSystemRestApi {
private static final Logger LOG = LoggerFactory.getLogger(MgmtSystemResource.class);
private final TenantConfigurationManagement tenantConfigurationManagement;
private final TenantConfigurationProperties tenantConfigurationProperties;
@Autowired
private TenantConfigurationManagement tenantConfigurationManagement;
MgmtSystemResource(final TenantConfigurationManagement tenantConfigurationManagement,
final TenantConfigurationProperties tenantConfigurationProperties) {
this.tenantConfigurationManagement = tenantConfigurationManagement;
this.tenantConfigurationProperties = tenantConfigurationProperties;
}
@Override
public ResponseEntity<ResourceSupport> getSystem() {
@@ -53,7 +60,9 @@ public class MgmtSystemResource implements MgmtSystemRestApi {
*/
@Override
public ResponseEntity<Map<String, MgmtSystemTenantConfigurationValue>> getSystemConfiguration() {
return new ResponseEntity<>(MgmtSystemMapper.toResponse(tenantConfigurationManagement), HttpStatus.OK);
return new ResponseEntity<>(
MgmtSystemMapper.toResponse(tenantConfigurationManagement, tenantConfigurationProperties),
HttpStatus.OK);
}
/**
@@ -69,9 +78,7 @@ public class MgmtSystemResource implements MgmtSystemRestApi {
@Override
public ResponseEntity<Void> deleteConfigurationValue(@PathVariable("keyName") final String keyName) {
final TenantConfigurationKey configKey = TenantConfigurationKey.fromKeyName(keyName);
tenantConfigurationManagement.deleteConfiguration(configKey);
tenantConfigurationManagement.deleteConfiguration(keyName);
LOG.debug("{} config value deleted, return status {}", keyName, HttpStatus.OK);
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
@@ -91,11 +98,10 @@ public class MgmtSystemResource implements MgmtSystemRestApi {
public ResponseEntity<MgmtSystemTenantConfigurationValue> getConfigurationValue(
@PathVariable("keyName") final String keyName) {
final TenantConfigurationKey configKey = TenantConfigurationKey.fromKeyName(keyName);
LOG.debug("{} config value getted, return status {}", keyName, HttpStatus.OK);
return new ResponseEntity<>(MgmtSystemMapper.toResponse(configKey.getKeyName(),
tenantConfigurationManagement.getConfigurationValue(configKey)), HttpStatus.OK);
return new ResponseEntity<>(
MgmtSystemMapper.toResponse(keyName, tenantConfigurationManagement.getConfigurationValue(keyName)),
HttpStatus.OK);
}
/**
@@ -115,10 +121,8 @@ public class MgmtSystemResource implements MgmtSystemRestApi {
@PathVariable("keyName") final String keyName,
@RequestBody final MgmtSystemTenantConfigurationValueRequest configurationValueRest) {
final TenantConfigurationKey configKey = TenantConfigurationKey.fromKeyName(keyName);
final TenantConfigurationValue<? extends Serializable> updatedValue = tenantConfigurationManagement
.addOrUpdateConfiguration(configKey, configurationValueRest.getValue());
.addOrUpdateConfiguration(keyName, configurationValueRest.getValue());
return new ResponseEntity<>(MgmtSystemMapper.toResponse(keyName, updatedValue), HttpStatus.OK);
}

View File

@@ -50,4 +50,12 @@ MYSQL.spring.datasource.password=
# SP Controller configuration
hawkbit.controller.pollingTime=00:01:00
hawkbit.controller.pollingOverdueTime=00:01:00
hawkbit.controller.pollingOverdueTime=00:01:00
hawkbit.server.tenant.configuration.polling-time.keyName=pollingTime
hawkbit.server.tenant.configuration.polling-time.defaultValue=${hawkbit.controller.pollingTime}
hawkbit.server.tenant.configuration.polling-time.validator=org.eclipse.hawkbit.tenancy.configuration.validator.TenantConfigurationPollingDurationValidator
hawkbit.server.tenant.configuration.polling-overdue-time.keyName=pollingOverdueTime
hawkbit.server.tenant.configuration.polling-overdue-time.defaultValue=${hawkbit.controller.pollingOverdueTime}
hawkbit.server.tenant.configuration.polling-overdue-time.validator=org.eclipse.hawkbit.tenancy.configuration.validator.TenantConfigurationPollingDurationValidator