Add a controller management api to get the polling time
Signed-off-by: SirWayne <dennis.melzer@bosch-si.com>
This commit is contained in:
@@ -33,7 +33,9 @@ import org.eclipse.hawkbit.repository.model.Target;
|
|||||||
import org.eclipse.hawkbit.repository.model.TargetInfo;
|
import org.eclipse.hawkbit.repository.model.TargetInfo;
|
||||||
import org.eclipse.hawkbit.repository.model.TargetUpdateStatus;
|
import org.eclipse.hawkbit.repository.model.TargetUpdateStatus;
|
||||||
import org.eclipse.hawkbit.repository.model.Target_;
|
import org.eclipse.hawkbit.repository.model.Target_;
|
||||||
|
import org.eclipse.hawkbit.repository.model.TenantConfiguration;
|
||||||
import org.eclipse.hawkbit.security.HawkbitSecurityProperties;
|
import org.eclipse.hawkbit.security.HawkbitSecurityProperties;
|
||||||
|
import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationKey;
|
||||||
import org.hibernate.validator.constraints.NotEmpty;
|
import org.hibernate.validator.constraints.NotEmpty;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
@@ -86,6 +88,33 @@ public class ControllerManagement {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private HawkbitSecurityProperties securityProperties;
|
private HawkbitSecurityProperties securityProperties;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private TenantConfigurationRepository tenantConfigurationRepository;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private TenantConfigurationManagement tenantConfigurationManagement;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves all {@link SoftwareModule}s which are assigned to the given
|
||||||
|
* {@link DistributionSet}.
|
||||||
|
*
|
||||||
|
* @param distributionSet
|
||||||
|
* the distribution set which should be assigned to the returned
|
||||||
|
* {@link SoftwareModule}s
|
||||||
|
* @return a list of {@link SoftwareModule}s assigned to given
|
||||||
|
* {@code distributionSet}
|
||||||
|
*/
|
||||||
|
@PreAuthorize(SpringEvalExpressions.IS_CONTROLLER)
|
||||||
|
public String findPollingTime() {
|
||||||
|
final TenantConfigurationKey configurationKey = TenantConfigurationKey.POLLING_TIME_INTERVAL;
|
||||||
|
final Class<String> propertyType = String.class;
|
||||||
|
tenantConfigurationManagement.validateTenantConfigurationDataType(configurationKey, propertyType);
|
||||||
|
final TenantConfiguration tenantConfiguration = tenantConfigurationRepository
|
||||||
|
.findByKey(configurationKey.getKeyName());
|
||||||
|
return tenantConfigurationManagement
|
||||||
|
.buildTenantConfigurationValueByKey(configurationKey, propertyType, tenantConfiguration).getValue();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Refreshes the time of the last time the controller has been connected to
|
* Refreshes the time of the last time the controller has been connected to
|
||||||
* the server.
|
* the server.
|
||||||
|
|||||||
@@ -85,16 +85,47 @@ public class TenantConfigurationManagement implements EnvironmentAware {
|
|||||||
+ SpringEvalExpressions.IS_SYSTEM_CODE)
|
+ SpringEvalExpressions.IS_SYSTEM_CODE)
|
||||||
public <T> TenantConfigurationValue<T> getConfigurationValue(final TenantConfigurationKey configurationKey,
|
public <T> TenantConfigurationValue<T> getConfigurationValue(final TenantConfigurationKey configurationKey,
|
||||||
final Class<T> propertyType) {
|
final Class<T> propertyType) {
|
||||||
|
validateTenantConfigurationDataType(configurationKey, propertyType);
|
||||||
|
|
||||||
|
final TenantConfiguration tenantConfiguration = tenantConfigurationRepository
|
||||||
|
.findByKey(configurationKey.getKeyName());
|
||||||
|
|
||||||
|
return buildTenantConfigurationValueByKey(configurationKey, propertyType, tenantConfiguration);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validates the data type of the tenant configuration. If it is possible to
|
||||||
|
* cast to the given data type.
|
||||||
|
*
|
||||||
|
* @param configurationKey
|
||||||
|
* the key
|
||||||
|
* @param propertyType
|
||||||
|
* the class
|
||||||
|
*/
|
||||||
|
protected <T> void validateTenantConfigurationDataType(final TenantConfigurationKey configurationKey,
|
||||||
|
final Class<T> propertyType) {
|
||||||
if (!configurationKey.getDataType().isAssignableFrom(propertyType)) {
|
if (!configurationKey.getDataType().isAssignableFrom(propertyType)) {
|
||||||
throw new TenantConfigurationValidatorException(
|
throw new TenantConfigurationValidatorException(
|
||||||
String.format("Cannot parse the database value of type %s into the type %s.",
|
String.format("Cannot parse the database value of type %s into the type %s.",
|
||||||
configurationKey.getDataType(), propertyType));
|
configurationKey.getDataType(), propertyType));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
final TenantConfiguration tenantConfiguration = tenantConfigurationRepository
|
/**
|
||||||
.findByKey(configurationKey.getKeyName());
|
* Build the tenant configuration by the given key
|
||||||
|
*
|
||||||
|
* @param configurationKey
|
||||||
|
* the key
|
||||||
|
* @param propertyType
|
||||||
|
* the property type
|
||||||
|
* @param tenantConfiguration
|
||||||
|
* the configuration
|
||||||
|
* @return <null> if no default value is set and no database value available
|
||||||
|
* or returns the tenant configuration value
|
||||||
|
*/
|
||||||
|
protected <T> TenantConfigurationValue<T> buildTenantConfigurationValueByKey(
|
||||||
|
final TenantConfigurationKey configurationKey, final Class<T> propertyType,
|
||||||
|
final TenantConfiguration tenantConfiguration) {
|
||||||
if (tenantConfiguration != null) {
|
if (tenantConfiguration != null) {
|
||||||
return TenantConfigurationValue.<T> builder().isGlobal(false).createdBy(tenantConfiguration.getCreatedBy())
|
return TenantConfigurationValue.<T> builder().isGlobal(false).createdBy(tenantConfiguration.getCreatedBy())
|
||||||
.createdAt(tenantConfiguration.getCreatedAt())
|
.createdAt(tenantConfiguration.getCreatedAt())
|
||||||
|
|||||||
@@ -30,7 +30,6 @@ import org.eclipse.hawkbit.controller.model.Result.FinalResult;
|
|||||||
import org.eclipse.hawkbit.repository.ArtifactManagement;
|
import org.eclipse.hawkbit.repository.ArtifactManagement;
|
||||||
import org.eclipse.hawkbit.repository.ControllerManagement;
|
import org.eclipse.hawkbit.repository.ControllerManagement;
|
||||||
import org.eclipse.hawkbit.repository.SoftwareManagement;
|
import org.eclipse.hawkbit.repository.SoftwareManagement;
|
||||||
import org.eclipse.hawkbit.repository.TenantConfigurationManagement;
|
|
||||||
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
|
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
|
||||||
import org.eclipse.hawkbit.repository.model.Action;
|
import org.eclipse.hawkbit.repository.model.Action;
|
||||||
import org.eclipse.hawkbit.repository.model.Action.Status;
|
import org.eclipse.hawkbit.repository.model.Action.Status;
|
||||||
@@ -43,7 +42,6 @@ import org.eclipse.hawkbit.repository.model.TargetUpdateStatus;
|
|||||||
import org.eclipse.hawkbit.rest.resource.helper.RestResourceConversionHelper;
|
import org.eclipse.hawkbit.rest.resource.helper.RestResourceConversionHelper;
|
||||||
import org.eclipse.hawkbit.security.HawkbitSecurityProperties;
|
import org.eclipse.hawkbit.security.HawkbitSecurityProperties;
|
||||||
import org.eclipse.hawkbit.tenancy.TenantAware;
|
import org.eclipse.hawkbit.tenancy.TenantAware;
|
||||||
import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationKey;
|
|
||||||
import org.eclipse.hawkbit.util.IpUtil;
|
import org.eclipse.hawkbit.util.IpUtil;
|
||||||
import org.hibernate.validator.constraints.NotEmpty;
|
import org.hibernate.validator.constraints.NotEmpty;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
@@ -93,9 +91,6 @@ public class RootController {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private TenantAware tenantAware;
|
private TenantAware tenantAware;
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private TenantConfigurationManagement tenantConfigurationManagement;
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private HawkbitSecurityProperties securityProperties;
|
private HawkbitSecurityProperties securityProperties;
|
||||||
|
|
||||||
@@ -153,11 +148,10 @@ public class RootController {
|
|||||||
IpUtil.getClientIpFromRequest(request, securityProperties.getClients().getRemoteIpHeader()));
|
IpUtil.getClientIpFromRequest(request, securityProperties.getClients().getRemoteIpHeader()));
|
||||||
}
|
}
|
||||||
|
|
||||||
final String pollingTime = tenantConfigurationManagement
|
return new ResponseEntity<>(
|
||||||
.getConfigurationValue(TenantConfigurationKey.POLLING_TIME_INTERVAL, String.class).getValue();
|
DataConversionHelper.fromTarget(target, controllerManagement.findActionByTargetAndActive(target),
|
||||||
|
controllerManagement.findPollingTime(), tenantAware),
|
||||||
return new ResponseEntity<>(DataConversionHelper.fromTarget(target,
|
HttpStatus.OK);
|
||||||
controllerManagement.findActionByTargetAndActive(target), pollingTime, tenantAware), HttpStatus.OK);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user