Fix document tenant configuration api (#567)

* Added link to system docu
* Rename feign client to MgmtTenantManagementClient

Signed-off-by: Jonathan Philip Knoblauch <JonathanPhilip.Knoblauch@bosch-si.com>
This commit is contained in:
Jonathan Knoblauch
2017-08-15 08:17:56 +02:00
committed by Michael Hirsch
parent 4fab134168
commit 4f79b8ba47
5 changed files with 45 additions and 91 deletions

View File

@@ -37,6 +37,7 @@ Available Management APIs resources are:
* [Target Tag](https://docs.bosch-iot-rollouts.com/documentation/rest-api/targettag-api-guide.html) * [Target Tag](https://docs.bosch-iot-rollouts.com/documentation/rest-api/targettag-api-guide.html)
* [Distribution Set Tag](https://docs.bosch-iot-rollouts.com/documentation/rest-api/distributionsettag-api-guide.html) * [Distribution Set Tag](https://docs.bosch-iot-rollouts.com/documentation/rest-api/distributionsettag-api-guide.html)
* [Rollouts](https://docs.bosch-iot-rollouts.com/documentation/rest-api/rollout-api-guide.html) * [Rollouts](https://docs.bosch-iot-rollouts.com/documentation/rest-api/rollout-api-guide.html)
* [Tenant](https://docs.bosch-iot-rollouts.com/documentation/rest-api/tenant-api-guide.html)
## Headers ## Headers

View File

@@ -8,13 +8,13 @@
*/ */
package org.eclipse.hawkbit.mgmt.client.resource; package org.eclipse.hawkbit.mgmt.client.resource;
import org.eclipse.hawkbit.mgmt.rest.api.MgmtSystemRestApi; import org.eclipse.hawkbit.mgmt.rest.api.MgmtTenantManagementRestApi;
import org.springframework.cloud.netflix.feign.FeignClient; import org.springframework.cloud.netflix.feign.FeignClient;
/** /**
* Client binding for the {@link MgmtSystemRestApi}. * Client binding for the {@link MgmtTenantManagementRestApi}.
* *
*/ */
@FeignClient(name = "MgmtSystemClient", url = "${hawkbit.url:localhost:8080}") @FeignClient(name = "MgmtTenantManagementClient", url = "${hawkbit.url:localhost:8080}")
public interface MgmtSystemClientResource extends MgmtSystemRestApi { public interface MgmtTenantManagementClientResource extends MgmtTenantManagementRestApi {
} }

View File

@@ -13,7 +13,6 @@ import java.util.Map;
import org.eclipse.hawkbit.mgmt.json.model.system.MgmtSystemTenantConfigurationValue; import org.eclipse.hawkbit.mgmt.json.model.system.MgmtSystemTenantConfigurationValue;
import org.eclipse.hawkbit.mgmt.json.model.system.MgmtSystemTenantConfigurationValueRequest; import org.eclipse.hawkbit.mgmt.json.model.system.MgmtSystemTenantConfigurationValueRequest;
import org.springframework.hateoas.MediaTypes; import org.springframework.hateoas.MediaTypes;
import org.springframework.hateoas.ResourceSupport;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PathVariable;
@@ -21,68 +20,67 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestMethod;
/** /**
* REST Resource handling tenant specific configuration operations. * REST Resource for handling tenant specific configuration operations.
*
* *
*/ */
@RequestMapping(MgmtRestConstants.SYSTEM_V1_REQUEST_MAPPING) @RequestMapping(MgmtRestConstants.SYSTEM_V1_REQUEST_MAPPING)
public interface MgmtSystemRestApi { public interface MgmtTenantManagementRestApi {
@RequestMapping(method = RequestMethod.GET, produces = { MediaTypes.HAL_JSON_VALUE,
MediaType.APPLICATION_JSON_VALUE })
ResponseEntity<ResourceSupport> getSystem();
/** /**
* @return a Map of all configuration values. * Handles the GET request for receiving all tenant specific configuration
* values.
*
* @return a map of all configuration values.
*/ */
@RequestMapping(method = RequestMethod.GET, value = "/configs", produces = { MediaTypes.HAL_JSON_VALUE, @RequestMapping(method = RequestMethod.GET, value = "/configs", produces = { MediaTypes.HAL_JSON_VALUE,
MediaType.APPLICATION_JSON_VALUE }) MediaType.APPLICATION_JSON_VALUE })
ResponseEntity<Map<String, MgmtSystemTenantConfigurationValue>> getSystemConfiguration(); ResponseEntity<Map<String, MgmtSystemTenantConfigurationValue>> getTenantConfiguration();
/** /**
* Handles the DELETE request of deleting a tenant specific configuration * Handles the DELETE request of deleting a tenant specific configuration
* value within SP. * value.
* *
* @param keyName * @param keyName
* the Name of the configuration key * the Name of the configuration key
* @return If the given configuration value exists and could be deleted Http * @return if the given configuration value exists and could be deleted HTTP
* OK. In any failure the JsonResponseExceptionHandler is handling * OK. In any failure the JsonResponseExceptionHandler is handling
* the response. * the response.
*/ */
@RequestMapping(method = RequestMethod.DELETE, value = "/configs/{keyName}", produces = { MediaTypes.HAL_JSON_VALUE, @RequestMapping(method = RequestMethod.DELETE, value = "/configs/{keyName}", produces = { MediaTypes.HAL_JSON_VALUE,
MediaType.APPLICATION_JSON_VALUE }) MediaType.APPLICATION_JSON_VALUE })
ResponseEntity<Void> deleteConfigurationValue(@PathVariable("keyName") String keyName); ResponseEntity<Void> deleteTenantConfigurationValue(@PathVariable("keyName") String keyName);
/** /**
* Handles the GET request of deleting a tenant specific configuration value * Handles the GET request of receiving a tenant specific configuration
* within SP. * value.
* *
* @param keyName * @param keyName
* the Name of the configuration key * the name of the configuration key
* @return If the given configuration value exists and could be get Http OK. * @return if the given configuration value exists and could be get HTTP OK.
* In any failure the JsonResponseExceptionHandler is handling the * In any failure the JsonResponseExceptionHandler is handling the
* response. * response.
*/ */
@RequestMapping(method = RequestMethod.GET, value = "/configs/{keyName}", produces = { MediaTypes.HAL_JSON_VALUE, @RequestMapping(method = RequestMethod.GET, value = "/configs/{keyName}", produces = { MediaTypes.HAL_JSON_VALUE,
MediaType.APPLICATION_JSON_VALUE }) MediaType.APPLICATION_JSON_VALUE })
ResponseEntity<MgmtSystemTenantConfigurationValue> getConfigurationValue(@PathVariable("keyName") String keyName); ResponseEntity<MgmtSystemTenantConfigurationValue> getTenantConfigurationValue(
@PathVariable("keyName") String keyName);
/** /**
* Handles the GET request of deleting a tenant specific configuration value * Handles the PUT request for updating a tenant specific configuration
* within SP. * value.
* *
* @param keyName * @param keyName
* the Name of the configuration key * the name of the configuration key
* @param configurationValueRest * @param configurationValueRest
* the new value for the configuration * the new value for the configuration
* @return If the given configuration value exists and could be get Http OK. * @return if the given configuration value exists and could be get HTTP OK.
* In any failure the JsonResponseExceptionHandler is handling the * In any failure the JsonResponseExceptionHandler is handling the
* response. * response.
*/ */
@RequestMapping(method = RequestMethod.PUT, value = "/configs/{keyName}", consumes = { MediaTypes.HAL_JSON_VALUE, @RequestMapping(method = RequestMethod.PUT, value = "/configs/{keyName}", consumes = { MediaTypes.HAL_JSON_VALUE,
MediaType.APPLICATION_JSON_VALUE }, produces = { MediaTypes.HAL_JSON_VALUE, MediaType.APPLICATION_JSON_VALUE }, produces = { MediaTypes.HAL_JSON_VALUE,
MediaType.APPLICATION_JSON_VALUE }) MediaType.APPLICATION_JSON_VALUE })
ResponseEntity<MgmtSystemTenantConfigurationValue> updateConfigurationValue(@PathVariable("keyName") String keyName, ResponseEntity<MgmtSystemTenantConfigurationValue> updateTenantConfigurationValue(
MgmtSystemTenantConfigurationValueRequest configurationValueRest); @PathVariable("keyName") String keyName, MgmtSystemTenantConfigurationValueRequest configurationValueRest);
} }

View File

@@ -24,9 +24,9 @@ import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationProperties.T
* A mapper which maps repository model to RESTful model representation and * A mapper which maps repository model to RESTful model representation and
* back. * back.
*/ */
public final class MgmtSystemMapper { public final class MgmtTenantManagementMapper {
private MgmtSystemMapper() { private MgmtTenantManagementMapper() {
// Utility class // Utility class
} }
@@ -50,7 +50,8 @@ public final class MgmtSystemMapper {
restConfValue.setLastModifiedAt(repoConfValue.getLastModifiedAt()); restConfValue.setLastModifiedAt(repoConfValue.getLastModifiedAt());
restConfValue.setLastModifiedBy(repoConfValue.getLastModifiedBy()); restConfValue.setLastModifiedBy(repoConfValue.getLastModifiedBy());
restConfValue.add(linkTo(methodOn(MgmtSystemResource.class).getConfigurationValue(key)).withSelfRel()); restConfValue.add(
linkTo(methodOn(MgmtTenantManagementResource.class).getTenantConfigurationValue(key)).withSelfRel());
return restConfValue; return restConfValue;
} }

View File

@@ -8,22 +8,18 @@
*/ */
package org.eclipse.hawkbit.mgmt.rest.resource; 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.io.Serializable; import java.io.Serializable;
import java.util.Map; import java.util.Map;
import org.eclipse.hawkbit.mgmt.json.model.system.MgmtSystemTenantConfigurationValue; import org.eclipse.hawkbit.mgmt.json.model.system.MgmtSystemTenantConfigurationValue;
import org.eclipse.hawkbit.mgmt.json.model.system.MgmtSystemTenantConfigurationValueRequest; import org.eclipse.hawkbit.mgmt.json.model.system.MgmtSystemTenantConfigurationValueRequest;
import org.eclipse.hawkbit.mgmt.rest.api.MgmtSystemRestApi; import org.eclipse.hawkbit.mgmt.rest.api.MgmtTenantManagementRestApi;
import org.eclipse.hawkbit.repository.TenantConfigurationManagement; import org.eclipse.hawkbit.repository.TenantConfigurationManagement;
import org.eclipse.hawkbit.repository.model.TenantConfigurationValue; import org.eclipse.hawkbit.repository.model.TenantConfigurationValue;
import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationProperties; import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationProperties;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.hateoas.ResourceSupport;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PathVariable;
@@ -31,51 +27,31 @@ import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
/** /**
* REST Resource handling tenant specific configuration operations. * REST Resource for handling tenant specific configuration operations.
*/ */
@RestController @RestController
public class MgmtSystemResource implements MgmtSystemRestApi { public class MgmtTenantManagementResource implements MgmtTenantManagementRestApi {
private static final Logger LOG = LoggerFactory.getLogger(MgmtSystemResource.class); private static final Logger LOG = LoggerFactory.getLogger(MgmtTenantManagementResource.class);
private final TenantConfigurationManagement tenantConfigurationManagement; private final TenantConfigurationManagement tenantConfigurationManagement;
private final TenantConfigurationProperties tenantConfigurationProperties; private final TenantConfigurationProperties tenantConfigurationProperties;
@Autowired @Autowired
MgmtSystemResource(final TenantConfigurationManagement tenantConfigurationManagement, MgmtTenantManagementResource(final TenantConfigurationManagement tenantConfigurationManagement,
final TenantConfigurationProperties tenantConfigurationProperties) { final TenantConfigurationProperties tenantConfigurationProperties) {
this.tenantConfigurationManagement = tenantConfigurationManagement; this.tenantConfigurationManagement = tenantConfigurationManagement;
this.tenantConfigurationProperties = tenantConfigurationProperties; this.tenantConfigurationProperties = tenantConfigurationProperties;
} }
@Override @Override
public ResponseEntity<ResourceSupport> getSystem() { public ResponseEntity<Map<String, MgmtSystemTenantConfigurationValue>> getTenantConfiguration() {
final ResourceSupport resourceSupport = new ResourceSupport(); return ResponseEntity.ok(
resourceSupport.add(linkTo(methodOn(MgmtSystemResource.class).getSystemConfiguration()).withRel("configs")); MgmtTenantManagementMapper.toResponse(tenantConfigurationManagement, tenantConfigurationProperties));
return ResponseEntity.ok(resourceSupport);
} }
/**
* @return a Map of all configuration values.
*/
@Override @Override
public ResponseEntity<Map<String, MgmtSystemTenantConfigurationValue>> getSystemConfiguration() { public ResponseEntity<Void> deleteTenantConfigurationValue(@PathVariable("keyName") final String keyName) {
return ResponseEntity
.ok(MgmtSystemMapper.toResponse(tenantConfigurationManagement, tenantConfigurationProperties));
}
/**
* Handles the DELETE request of deleting a tenant specific configuration
* value within SP.
*
* @param keyName
* the Name of the configuration key
* @return If the given configuration value exists and could be deleted Http
* OK. In any failure the JsonResponseExceptionHandler is handling
* the response.
*/
@Override
public ResponseEntity<Void> deleteConfigurationValue(@PathVariable("keyName") final String keyName) {
tenantConfigurationManagement.deleteConfiguration(keyName); tenantConfigurationManagement.deleteConfiguration(keyName);
@@ -83,45 +59,23 @@ public class MgmtSystemResource implements MgmtSystemRestApi {
return ResponseEntity.ok().build(); return ResponseEntity.ok().build();
} }
/**
* Handles the GET request of deleting a tenant specific configuration value
* within SP.
*
* @param keyName
* the Name of the configuration key
* @return If the given configuration value exists and could be get Http OK.
* In any failure the JsonResponseExceptionHandler is handling the
* response.
*/
@Override @Override
public ResponseEntity<MgmtSystemTenantConfigurationValue> getConfigurationValue( public ResponseEntity<MgmtSystemTenantConfigurationValue> getTenantConfigurationValue(
@PathVariable("keyName") final String keyName) { @PathVariable("keyName") final String keyName) {
LOG.debug("{} config value getted, return status {}", keyName, HttpStatus.OK); LOG.debug("{} config value getted, return status {}", keyName, HttpStatus.OK);
return ResponseEntity return ResponseEntity.ok(MgmtTenantManagementMapper.toResponse(keyName,
.ok(MgmtSystemMapper.toResponse(keyName, tenantConfigurationManagement.getConfigurationValue(keyName))); tenantConfigurationManagement.getConfigurationValue(keyName)));
} }
/**
* Handles the GET request of deleting a tenant specific configuration value
* within SP.
*
* @param keyName
* the Name of the configuration key
* @param configurationValueRest
* the new value for the configuration
* @return If the given configuration value exists and could be get Http OK.
* In any failure the JsonResponseExceptionHandler is handling the
* response.
*/
@Override @Override
public ResponseEntity<MgmtSystemTenantConfigurationValue> updateConfigurationValue( public ResponseEntity<MgmtSystemTenantConfigurationValue> updateTenantConfigurationValue(
@PathVariable("keyName") final String keyName, @PathVariable("keyName") final String keyName,
@RequestBody final MgmtSystemTenantConfigurationValueRequest configurationValueRest) { @RequestBody final MgmtSystemTenantConfigurationValueRequest configurationValueRest) {
final TenantConfigurationValue<? extends Serializable> updatedValue = tenantConfigurationManagement final TenantConfigurationValue<? extends Serializable> updatedValue = tenantConfigurationManagement
.addOrUpdateConfiguration(keyName, configurationValueRest.getValue()); .addOrUpdateConfiguration(keyName, configurationValueRest.getValue());
return ResponseEntity.ok(MgmtSystemMapper.toResponse(keyName, updatedValue)); return ResponseEntity.ok(MgmtTenantManagementMapper.toResponse(keyName, updatedValue));
} }
} }