Remove swagger and minor feature extensions and bug fixes
- Various Bug fixes and improvements - Management API extended - Swagger removed - Guava Upgraded to 19
This commit is contained in:
0
hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/cache/CacheWriteNotify.java
vendored
Executable file → Normal file
0
hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/cache/CacheWriteNotify.java
vendored
Executable file → Normal file
4
hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/controller/ArtifactStoreController.java
Executable file → Normal file
4
hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/controller/ArtifactStoreController.java
Executable file → Normal file
@@ -35,7 +35,6 @@ import org.springframework.core.env.Environment;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.security.web.bind.annotation.AuthenticationPrincipal;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
@@ -55,7 +54,6 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
*
|
||||
*/
|
||||
@RestController
|
||||
@Transactional
|
||||
@RequestMapping(ControllerConstants.ARTIFACTS_V1_REQUEST_MAPPING)
|
||||
public class ArtifactStoreController implements EnvironmentAware {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(ArtifactStoreController.class);
|
||||
@@ -101,7 +99,7 @@ public class ArtifactStoreController implements EnvironmentAware {
|
||||
public ResponseEntity<Void> downloadArtifactByFilename(@PathVariable final String fileName,
|
||||
final HttpServletResponse response, final HttpServletRequest request,
|
||||
@AuthenticationPrincipal final String targetid) {
|
||||
ResponseEntity<Void> result = null;
|
||||
ResponseEntity<Void> result;
|
||||
|
||||
final List<LocalArtifact> foundArtifacts = artifactManagement.findLocalArtifactByFilename(fileName);
|
||||
|
||||
|
||||
6
hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/controller/ControllerConstants.java
Executable file → Normal file
6
hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/controller/ControllerConstants.java
Executable file → Normal file
@@ -27,12 +27,12 @@ public final class ControllerConstants {
|
||||
/**
|
||||
* Deployment action resources.
|
||||
*/
|
||||
static final String DEPLOYMENT_BASE_ACTION = "deploymentBase";
|
||||
public static final String DEPLOYMENT_BASE_ACTION = "deploymentBase";
|
||||
|
||||
/**
|
||||
* Cancel action resources.
|
||||
*/
|
||||
static final String CANCEL_ACTION = "cancelAction";
|
||||
public static final String CANCEL_ACTION = "cancelAction";
|
||||
|
||||
/**
|
||||
* Feedback channel.
|
||||
@@ -42,7 +42,7 @@ public final class ControllerConstants {
|
||||
/**
|
||||
* Config data action resources.
|
||||
*/
|
||||
static final String CONFIG_DATA_ACTION = "configData";
|
||||
public static final String CONFIG_DATA_ACTION = "configData";
|
||||
|
||||
/**
|
||||
* The artifact URL mapping rest resource.
|
||||
|
||||
50
hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/controller/DataConversionHelper.java
Executable file → Normal file
50
hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/controller/DataConversionHelper.java
Executable file → Normal file
@@ -23,15 +23,12 @@ import org.eclipse.hawkbit.controller.model.Chunk;
|
||||
import org.eclipse.hawkbit.controller.model.Config;
|
||||
import org.eclipse.hawkbit.controller.model.ControllerBase;
|
||||
import org.eclipse.hawkbit.controller.model.Polling;
|
||||
import org.eclipse.hawkbit.controller.model.SoftwareModule;
|
||||
import org.eclipse.hawkbit.repository.model.Action;
|
||||
import org.eclipse.hawkbit.repository.model.Action.Status;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSet;
|
||||
import org.eclipse.hawkbit.repository.model.LocalArtifact;
|
||||
import org.eclipse.hawkbit.repository.model.Target;
|
||||
import org.eclipse.hawkbit.rest.resource.model.artifact.ArtifactHash;
|
||||
import org.eclipse.hawkbit.tenancy.TenantAware;
|
||||
import org.springframework.hateoas.Link;
|
||||
|
||||
import com.google.common.base.Charsets;
|
||||
|
||||
@@ -57,34 +54,6 @@ public final class DataConversionHelper {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates all available (rest) software modules for a given distributionSet
|
||||
* set.
|
||||
*
|
||||
* @param targetid
|
||||
* of the target
|
||||
* @param assignedDistributionSet
|
||||
* the assigned distribution set
|
||||
* @param tenantAware
|
||||
* of the tenant
|
||||
* @return a list of software modules or a empty list. Cannot be <null>.
|
||||
*/
|
||||
public static List<SoftwareModule> createSoftwareModules(final String targetid,
|
||||
final DistributionSet assignedDistributionSet, final TenantAware tenantAware) {
|
||||
return assignedDistributionSet.getModules().stream()
|
||||
.map(module -> createSoftwareModul(targetid, module, tenantAware)).collect(Collectors.toList());
|
||||
|
||||
}
|
||||
|
||||
private static SoftwareModule createSoftwareModul(final String targetid,
|
||||
final org.eclipse.hawkbit.repository.model.SoftwareModule module, final TenantAware tenantAware) {
|
||||
final List<Link> links = new ArrayList<Link>();
|
||||
module.getLocalArtifacts().forEach(artifact -> createAndAddLinks(targetid, tenantAware, artifact, links));
|
||||
|
||||
return new SoftwareModule(module.getId(), module.getType().getKey(), module.getVersion(), module.getName(),
|
||||
links);
|
||||
}
|
||||
|
||||
private static String mapChunkLegacyKeys(final String key) {
|
||||
if ("application".equals(key)) {
|
||||
return "bApp";
|
||||
@@ -98,7 +67,7 @@ public final class DataConversionHelper {
|
||||
|
||||
/**
|
||||
* Creates all (rest) artifacts for a given software module.
|
||||
*
|
||||
*
|
||||
* @param targetid
|
||||
* of the target
|
||||
* @param module
|
||||
@@ -109,26 +78,23 @@ public final class DataConversionHelper {
|
||||
*/
|
||||
public static List<Artifact> createArtifacts(final String targetid,
|
||||
final org.eclipse.hawkbit.repository.model.SoftwareModule module, final TenantAware tenantAware) {
|
||||
final List<Artifact> files = new ArrayList<Artifact>();
|
||||
final List<Artifact> files = new ArrayList<>();
|
||||
module.getLocalArtifacts().forEach(artifact -> {
|
||||
final Artifact file = new Artifact();
|
||||
file.setHashes(new ArtifactHash(artifact.getSha1Hash(), artifact.getMd5Hash()));
|
||||
file.setFilename(artifact.getFilename());
|
||||
file.setSize(artifact.getSize());
|
||||
createAndAddLinks(targetid, tenantAware, artifact, file.getLinks());
|
||||
|
||||
file.add(linkTo(methodOn(RootController.class, tenantAware.getCurrentTenant()).downloadArtifact(targetid,
|
||||
artifact.getSoftwareModule().getId(), artifact.getFilename(), null, null)).withRel("download"));
|
||||
file.add(linkTo(methodOn(RootController.class, tenantAware.getCurrentTenant()).downloadArtifactMd5(targetid,
|
||||
artifact.getSoftwareModule().getId(), artifact.getFilename(), null, null)).withRel("md5sum"));
|
||||
|
||||
files.add(file);
|
||||
});
|
||||
return files;
|
||||
}
|
||||
|
||||
private static void createAndAddLinks(final String targetid, final TenantAware tenantAware,
|
||||
final LocalArtifact artifact, final List<Link> links) {
|
||||
links.add(linkTo(methodOn(RootController.class, tenantAware.getCurrentTenant()).downloadArtifact(targetid,
|
||||
artifact.getSoftwareModule().getId(), artifact.getFilename(), null, null)).withRel("download"));
|
||||
links.add(linkTo(methodOn(RootController.class, tenantAware.getCurrentTenant()).downloadArtifactMd5(targetid,
|
||||
artifact.getSoftwareModule().getId(), artifact.getFilename(), null, null)).withRel("md5sum"));
|
||||
}
|
||||
|
||||
static ControllerBase fromTarget(final Target target, final List<Action> actions,
|
||||
final String defaultControllerPollTime, final TenantAware tenantAware) {
|
||||
final ControllerBase result = new ControllerBase(new Config(new Polling(defaultControllerPollTime)));
|
||||
|
||||
0
hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/controller/EnableDirectDeviceApi.java
Executable file → Normal file
0
hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/controller/EnableDirectDeviceApi.java
Executable file → Normal file
0
hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/controller/FileSteamingFailedException.java
Executable file → Normal file
0
hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/controller/FileSteamingFailedException.java
Executable file → Normal file
153
hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/controller/RootController.java
Executable file → Normal file
153
hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/controller/RootController.java
Executable file → Normal file
@@ -8,11 +8,7 @@
|
||||
*/
|
||||
package org.eclipse.hawkbit.controller;
|
||||
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
@@ -40,7 +36,6 @@ import org.eclipse.hawkbit.repository.model.Action;
|
||||
import org.eclipse.hawkbit.repository.model.Action.Status;
|
||||
import org.eclipse.hawkbit.repository.model.ActionStatus;
|
||||
import org.eclipse.hawkbit.repository.model.Artifact;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSet;
|
||||
import org.eclipse.hawkbit.repository.model.LocalArtifact;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModule;
|
||||
import org.eclipse.hawkbit.repository.model.Target;
|
||||
@@ -58,7 +53,6 @@ import org.springframework.core.env.Environment;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
@@ -80,8 +74,6 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping(ControllerConstants.BASE_V1_REQUEST_MAPPING)
|
||||
@Transactional
|
||||
@Api(value = "/", description = "SP Direct Device Integration API")
|
||||
public class RootController implements EnvironmentAware {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(RootController.class);
|
||||
@@ -130,7 +122,6 @@ public class RootController implements EnvironmentAware {
|
||||
*/
|
||||
@RequestMapping(method = RequestMethod.GET, value = "/{targetid}/softwaremodules/{softwareModuleId}/artifacts", produces = {
|
||||
"application/hal+json", MediaType.APPLICATION_JSON_VALUE })
|
||||
@ApiOperation(response = org.eclipse.hawkbit.controller.model.Artifact.class, value = "Returns artifacts of given software module", notes = "Returns all artifacts whichs is assigned to the software module")
|
||||
public ResponseEntity<List<org.eclipse.hawkbit.controller.model.Artifact>> getSoftwareModulesArtifacts(
|
||||
@PathVariable final String targetid, @PathVariable final Long softwareModuleId) {
|
||||
LOG.debug("getSoftwareModulesArtifacts({})", targetid);
|
||||
@@ -147,36 +138,6 @@ public class RootController implements EnvironmentAware {
|
||||
HttpStatus.OK);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all available software modules for a given target.
|
||||
*
|
||||
* @param targetid
|
||||
* of the {@link Target} that matches to
|
||||
* {@link Target#getControllerId()}
|
||||
* @param request
|
||||
* the HTTP request injected by spring
|
||||
* @return the response
|
||||
*/
|
||||
@RequestMapping(method = RequestMethod.GET, value = "/{targetid}/softwaremodules/", produces = {
|
||||
"application/hal+json", MediaType.APPLICATION_JSON_VALUE })
|
||||
@ApiOperation(response = SoftwareModule.class, value = " Returns software modules of given target", notes = "Returns all available software modules for a given target")
|
||||
public ResponseEntity<List<org.eclipse.hawkbit.controller.model.SoftwareModule>> getSoftwareModules(
|
||||
@PathVariable final String targetid, final HttpServletRequest request) {
|
||||
LOG.debug("getSoftwareModules({})", targetid);
|
||||
|
||||
final Target target = controllerManagement.updateLastTargetQuery(targetid,
|
||||
IpUtil.getClientIpFromRequest(request, requestHeader));
|
||||
|
||||
final DistributionSet assignedDistributionSet = target.getAssignedDistributionSet();
|
||||
|
||||
if (assignedDistributionSet == null) {
|
||||
return new ResponseEntity<>(new ArrayList<>(), HttpStatus.OK);
|
||||
}
|
||||
|
||||
return new ResponseEntity<>(DataConversionHelper.createSoftwareModules(targetid, assignedDistributionSet,
|
||||
tenantAware), HttpStatus.OK);
|
||||
}
|
||||
|
||||
/**
|
||||
* Root resource for an individual {@link Target}.
|
||||
*
|
||||
@@ -189,9 +150,6 @@ public class RootController implements EnvironmentAware {
|
||||
*/
|
||||
@RequestMapping(method = RequestMethod.GET, value = "/{targetid}", produces = { "application/hal+json",
|
||||
MediaType.APPLICATION_JSON_VALUE })
|
||||
@ApiOperation(response = ControllerBase.class, value = "Controller base poll resource", notes = "This base resource can be regularly polled by the controller on the provisiong target or device "
|
||||
+ "in order to retrieve actions that need to be executed. The resource supports Etag based modification "
|
||||
+ "checks in order to save traffic.")
|
||||
public ResponseEntity<ControllerBase> getControllerBase(@PathVariable final String targetid,
|
||||
final HttpServletRequest request) {
|
||||
LOG.debug("getControllerBase({})", targetid);
|
||||
@@ -205,7 +163,7 @@ public class RootController implements EnvironmentAware {
|
||||
System.currentTimeMillis(), IpUtil.getClientIpFromRequest(request, requestHeader));
|
||||
}
|
||||
|
||||
return new ResponseEntity<ControllerBase>(DataConversionHelper.fromTarget(target,
|
||||
return new ResponseEntity<>(DataConversionHelper.fromTarget(target,
|
||||
controllerManagement.findActionByTargetAndActive(target), controllerPollProperties.getPollingTime(),
|
||||
tenantAware), HttpStatus.OK);
|
||||
}
|
||||
@@ -230,13 +188,10 @@ public class RootController implements EnvironmentAware {
|
||||
* {@link HttpStatus#PARTIAL_CONTENT}.
|
||||
*/
|
||||
@RequestMapping(method = RequestMethod.GET, value = "/{targetid}/softwaremodules/{softwareModuleId}/artifacts/{fileName}")
|
||||
@ApiOperation(response = Void.class, value = "Downstream of given artifact", notes = "Download resource for artifacts. The resource supports partial download "
|
||||
+ "as specified by RFC7233 (range requests). Keep in mind that the controller "
|
||||
+ "needs to have the artifact assigned in order to be granted permission to download.")
|
||||
public ResponseEntity<Void> downloadArtifact(@PathVariable final String targetid,
|
||||
@PathVariable final Long softwareModuleId, @PathVariable final String fileName,
|
||||
final HttpServletResponse response, final HttpServletRequest request) {
|
||||
ResponseEntity<Void> result = null;
|
||||
ResponseEntity<Void> result;
|
||||
|
||||
final Target target = controllerManagement.updateLastTargetQuery(targetid,
|
||||
IpUtil.getClientIpFromRequest(request, requestHeader));
|
||||
@@ -283,7 +238,7 @@ public class RootController implements EnvironmentAware {
|
||||
return action;
|
||||
}
|
||||
|
||||
private boolean checkModule(final String fileName, final SoftwareModule module) {
|
||||
private static boolean checkModule(final String fileName, final SoftwareModule module) {
|
||||
return null == module || !module.getLocalArtifactByFilename(fileName).isPresent();
|
||||
}
|
||||
|
||||
@@ -306,9 +261,6 @@ public class RootController implements EnvironmentAware {
|
||||
*/
|
||||
@RequestMapping(method = RequestMethod.GET, value = "/{targetid}/softwaremodules/{softwareModuleId}/artifacts/{fileName}"
|
||||
+ ControllerConstants.ARTIFACT_MD5_DWNL_SUFFIX, produces = MediaType.TEXT_PLAIN_VALUE)
|
||||
@ApiOperation(response = Void.class, value = "Downstream of given artifacts MD5SUM file", notes = "Download resource for MD5SUM file is an optional functionally especially usefull for "
|
||||
+ "Linux based devices on order to check artifact coonsitency after download by using the md5sum "
|
||||
+ "command line tool. The MD5 and SHA1 are in addition available as metadata in the deployment command itself.")
|
||||
public ResponseEntity<Void> downloadArtifactMd5(@PathVariable final String targetid,
|
||||
@PathVariable final Long softwareModuleId, @PathVariable final String fileName,
|
||||
final HttpServletResponse response, final HttpServletRequest request) {
|
||||
@@ -350,7 +302,6 @@ public class RootController implements EnvironmentAware {
|
||||
* @return the response
|
||||
*/
|
||||
@RequestMapping(value = "/{targetid}/" + ControllerConstants.DEPLOYMENT_BASE_ACTION + "/{actionId}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
||||
@ApiOperation(response = DeploymentBase.class, value = "Deployment or update action", notes = "Core resource for deployment operations. Contains all information necessary in order to execute the operation.")
|
||||
public ResponseEntity<DeploymentBase> getControllerBasedeploymentAction(
|
||||
@PathVariable @NotEmpty final String targetid, @PathVariable @NotEmpty final Long actionId,
|
||||
@RequestParam(value = "c", required = false, defaultValue = "-1") final int resource,
|
||||
@@ -380,10 +331,10 @@ public class RootController implements EnvironmentAware {
|
||||
controllerManagement.registerRetrieved(action,
|
||||
"Controller retrieved update action and should start now the download.");
|
||||
|
||||
return new ResponseEntity<DeploymentBase>(base, HttpStatus.OK);
|
||||
return new ResponseEntity<>(base, HttpStatus.OK);
|
||||
}
|
||||
|
||||
return new ResponseEntity<DeploymentBase>(HttpStatus.NOT_FOUND);
|
||||
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -403,12 +354,9 @@ public class RootController implements EnvironmentAware {
|
||||
*/
|
||||
@RequestMapping(value = "/{targetid}/" + ControllerConstants.DEPLOYMENT_BASE_ACTION + "/{actionId}/"
|
||||
+ ControllerConstants.FEEDBACK, method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE)
|
||||
@ApiOperation(response = ActionFeedback.class, value = "Feedback channel for update actions", notes = "Feedback channel. It is up to the device to decided how much intermediate feedback is "
|
||||
+ "provided. However, the action will be kept open until the controller on the device reports a "
|
||||
+ "finished (either successfull or error).")
|
||||
public ResponseEntity<ActionFeedback> postBasedeploymentActionFeedback(
|
||||
@Valid @RequestBody final ActionFeedback feedback, @PathVariable final String targetid,
|
||||
@PathVariable @NotEmpty final Long actionId, final HttpServletRequest request) {
|
||||
public ResponseEntity<Void> postBasedeploymentActionFeedback(@Valid @RequestBody final ActionFeedback feedback,
|
||||
@PathVariable final String targetid, @PathVariable @NotEmpty final Long actionId,
|
||||
final HttpServletRequest request) {
|
||||
LOG.debug("provideBasedeploymentActionFeedback for target [{},{}]: {}", targetid, actionId, feedback);
|
||||
|
||||
final Target target = controllerManagement.updateLastTargetQuery(targetid,
|
||||
@@ -418,7 +366,7 @@ public class RootController implements EnvironmentAware {
|
||||
LOG.warn(
|
||||
"provideBasedeploymentActionFeedback: action in payload ({}) was not identical to action in path ({}).",
|
||||
feedback.getId(), actionId);
|
||||
return new ResponseEntity<ActionFeedback>(HttpStatus.NOT_FOUND);
|
||||
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
|
||||
}
|
||||
|
||||
final Action action = findActionWithExceptionIfNotFound(actionId);
|
||||
@@ -430,13 +378,13 @@ public class RootController implements EnvironmentAware {
|
||||
if (!action.isActive()) {
|
||||
LOG.warn("Updating action {} with feedback {} not possible since action not active anymore.",
|
||||
action.getId(), feedback.getId());
|
||||
return new ResponseEntity<ActionFeedback>(HttpStatus.GONE);
|
||||
return new ResponseEntity<>(HttpStatus.GONE);
|
||||
}
|
||||
|
||||
controllerManagement.addUpdateActionStatus(generateUpdateStatus(feedback, targetid, feedback.getId(), action),
|
||||
action);
|
||||
|
||||
return new ResponseEntity<ActionFeedback>(HttpStatus.OK);
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
|
||||
}
|
||||
|
||||
@@ -461,25 +409,10 @@ public class RootController implements EnvironmentAware {
|
||||
actionStatus.addMessage("Controller reported internal ERROR and REJECTED update.");
|
||||
break;
|
||||
case CLOSED:
|
||||
LOG.debug("Controller reported closed (actionid: {}, targetid: {}) as we got {} report.", actionid,
|
||||
targetid, feedback.getStatus().getExecution());
|
||||
if (feedback.getStatus().getResult().getFinished() == FinalResult.FAILURE) {
|
||||
actionStatus.setStatus(Status.ERROR);
|
||||
actionStatus.addMessage("Controller reported CLOSED with ERROR!");
|
||||
} else {
|
||||
actionStatus.setStatus(Status.FINISHED);
|
||||
actionStatus.addMessage("Controller reported CLOSED with OK!");
|
||||
}
|
||||
handleClosedUpdateStatus(feedback, targetid, actionid, actionStatus);
|
||||
break;
|
||||
default:
|
||||
LOG.debug("Controller reported intermediate status (actionid: {}, targetid: {}) as we got {} report.",
|
||||
actionid, targetid, feedback.getStatus().getExecution());
|
||||
actionStatus.setStatus(Status.RUNNING);
|
||||
// MECS-400: we should not use the unstructed message list for
|
||||
// the
|
||||
// server comment on the
|
||||
// status.
|
||||
actionStatus.addMessage("Controller reported: " + feedback.getStatus().getExecution());
|
||||
handleDefaultUpdateStatus(feedback, targetid, actionid, actionStatus);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -495,6 +428,29 @@ public class RootController implements EnvironmentAware {
|
||||
return actionStatus;
|
||||
}
|
||||
|
||||
private static void handleDefaultUpdateStatus(final ActionFeedback feedback, final String targetid,
|
||||
final Long actionid, final ActionStatus actionStatus) {
|
||||
LOG.debug("Controller reported intermediate status (actionid: {}, targetid: {}) as we got {} report.",
|
||||
actionid, targetid, feedback.getStatus().getExecution());
|
||||
actionStatus.setStatus(Status.RUNNING);
|
||||
// MECS-400: we should not use the unstructed message list for
|
||||
// the server comment on the status.
|
||||
actionStatus.addMessage("Controller reported: " + feedback.getStatus().getExecution());
|
||||
}
|
||||
|
||||
private static void handleClosedUpdateStatus(final ActionFeedback feedback, final String targetid,
|
||||
final Long actionid, final ActionStatus actionStatus) {
|
||||
LOG.debug("Controller reported closed (actionid: {}, targetid: {}) as we got {} report.", actionid, targetid,
|
||||
feedback.getStatus().getExecution());
|
||||
if (feedback.getStatus().getResult().getFinished() == FinalResult.FAILURE) {
|
||||
actionStatus.setStatus(Status.ERROR);
|
||||
actionStatus.addMessage("Controller reported CLOSED with ERROR!");
|
||||
} else {
|
||||
actionStatus.setStatus(Status.FINISHED);
|
||||
actionStatus.addMessage("Controller reported CLOSED with OK!");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This is the feedback channel for the config data action.
|
||||
*
|
||||
@@ -508,16 +464,13 @@ public class RootController implements EnvironmentAware {
|
||||
* @return status of the request
|
||||
*/
|
||||
@RequestMapping(value = "/{targetid}/" + ControllerConstants.CONFIG_DATA_ACTION, method = RequestMethod.PUT, consumes = MediaType.APPLICATION_JSON_VALUE)
|
||||
@ApiOperation(response = ConfigData.class, value = "Response to a requested metadata pull from the provisioning target device.", notes = "The usual behaviour is that when a new device resgisters at the server it is "
|
||||
+ "requested to provide the meta information that will allow the server to identify the device on a "
|
||||
+ "hardware level (e.g. hardware revision, mac address, serial number etc.).")
|
||||
public ResponseEntity<ConfigData> putConfigData(@Valid @RequestBody final ConfigData configData,
|
||||
public ResponseEntity<Void> putConfigData(@Valid @RequestBody final ConfigData configData,
|
||||
@PathVariable final String targetid, final HttpServletRequest request) {
|
||||
controllerManagement.updateLastTargetQuery(targetid, IpUtil.getClientIpFromRequest(request, requestHeader));
|
||||
|
||||
controllerManagement.updateControllerAttributes(targetid, configData.getData());
|
||||
|
||||
return new ResponseEntity<ConfigData>(HttpStatus.OK);
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -533,8 +486,6 @@ public class RootController implements EnvironmentAware {
|
||||
* @return the {@link Cancel} response
|
||||
*/
|
||||
@RequestMapping(value = "/{targetid}/" + ControllerConstants.CANCEL_ACTION + "/{actionId}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
||||
@ApiOperation(response = Cancel.class, value = "Cancel an action", notes = "The SP server might cancel an operation, e.g. an unfinished update has a sucessor. "
|
||||
+ "It is up to the provisiong target to decide to accept the cancelation or reject it.")
|
||||
public ResponseEntity<Cancel> getControllerCancelAction(@PathVariable @NotEmpty final String targetid,
|
||||
@PathVariable @NotEmpty final Long actionId, final HttpServletRequest request) {
|
||||
LOG.debug("getControllerCancelAction({})", targetid);
|
||||
@@ -557,10 +508,10 @@ public class RootController implements EnvironmentAware {
|
||||
controllerManagement.registerRetrieved(action,
|
||||
"Controller retrieved cancel action and should start now the cancelation.");
|
||||
|
||||
return new ResponseEntity<Cancel>(cancel, HttpStatus.OK);
|
||||
return new ResponseEntity<>(cancel, HttpStatus.OK);
|
||||
}
|
||||
|
||||
return new ResponseEntity<Cancel>(HttpStatus.NOT_FOUND);
|
||||
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -578,12 +529,10 @@ public class RootController implements EnvironmentAware {
|
||||
*
|
||||
* @return the {@link ActionFeedback} response
|
||||
*/
|
||||
|
||||
@RequestMapping(value = "/{targetid}/" + ControllerConstants.CANCEL_ACTION + "/{actionId}/"
|
||||
+ ControllerConstants.FEEDBACK, method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE)
|
||||
@ApiOperation(response = Cancel.class, value = "Feedback channel for cancel actions", notes = "It is up to the device to decided how much intermediate feedback is "
|
||||
+ "provided. However, the action will be kept open until the controller on the device reports a "
|
||||
+ "finished (either successfull or error) or rejects the oprtioan, e.g. the canceled actions have been started already.")
|
||||
public ResponseEntity<ActionFeedback> postCancelActionFeedback(@Valid @RequestBody final ActionFeedback feedback,
|
||||
public ResponseEntity<Void> postCancelActionFeedback(@Valid @RequestBody final ActionFeedback feedback,
|
||||
@PathVariable @NotEmpty final String targetid, @PathVariable @NotEmpty final Long actionId,
|
||||
final HttpServletRequest request) {
|
||||
LOG.debug("provideCancelActionFeedback for target [{}]: {}", targetid, feedback);
|
||||
@@ -595,7 +544,7 @@ public class RootController implements EnvironmentAware {
|
||||
LOG.warn(
|
||||
"provideBasedeploymentActionFeedback: action in payload ({}) was not identical to action in path ({}).",
|
||||
feedback.getId(), actionId);
|
||||
return new ResponseEntity<ActionFeedback>(HttpStatus.NOT_FOUND);
|
||||
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
|
||||
}
|
||||
|
||||
final Action action = findActionWithExceptionIfNotFound(actionId);
|
||||
@@ -606,7 +555,7 @@ public class RootController implements EnvironmentAware {
|
||||
|
||||
controllerManagement.addCancelActionStatus(
|
||||
generateActionCancelStatus(feedback, target, feedback.getId(), action), action);
|
||||
return new ResponseEntity<ActionFeedback>(HttpStatus.OK);
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
|
||||
private static ActionStatus generateActionCancelStatus(final ActionFeedback feedback, final Target target,
|
||||
@@ -629,11 +578,7 @@ public class RootController implements EnvironmentAware {
|
||||
actionStatus.setStatus(Status.WARNING);
|
||||
break;
|
||||
case CLOSED:
|
||||
if (feedback.getStatus().getResult().getFinished() == FinalResult.FAILURE) {
|
||||
actionStatus.setStatus(Status.ERROR);
|
||||
} else {
|
||||
actionStatus.setStatus(Status.CANCELED);
|
||||
}
|
||||
handleClosedCancelStatus(feedback, actionStatus);
|
||||
break;
|
||||
default:
|
||||
actionStatus.setStatus(Status.RUNNING);
|
||||
@@ -653,6 +598,14 @@ public class RootController implements EnvironmentAware {
|
||||
|
||||
}
|
||||
|
||||
private static void handleClosedCancelStatus(final ActionFeedback feedback, final ActionStatus actionStatus) {
|
||||
if (feedback.getStatus().getResult().getFinished() == FinalResult.FAILURE) {
|
||||
actionStatus.setStatus(Status.ERROR);
|
||||
} else {
|
||||
actionStatus.setStatus(Status.CANCELED);
|
||||
}
|
||||
}
|
||||
|
||||
private Action findActionWithExceptionIfNotFound(final Long actionId) {
|
||||
final Action findAction = controllerManagement.findActionWithDetails(actionId);
|
||||
if (findAction == null) {
|
||||
|
||||
18
hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/controller/model/ActionFeedback.java
Executable file → Normal file
18
hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/controller/model/ActionFeedback.java
Executable file → Normal file
@@ -10,15 +10,10 @@ package org.eclipse.hawkbit.controller.model;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
import org.eclipse.hawkbit.rest.resource.model.doc.ApiModelProperties;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
|
||||
/**
|
||||
*
|
||||
* <p>
|
||||
@@ -38,23 +33,12 @@ import io.swagger.annotations.ApiModelProperty;
|
||||
* "success", "progress": {} } "details": [], } }
|
||||
* </p>
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
@ApiModel("SP Target Action Feedback")
|
||||
public class ActionFeedback {
|
||||
|
||||
@ApiModelProperty(value = ApiModelProperties.ACTION_ID)
|
||||
private final Long id;
|
||||
|
||||
@ApiModelProperty(value = ApiModelProperties.TARGET_TIME)
|
||||
private final String time;
|
||||
|
||||
@ApiModelProperty(value = ApiModelProperties.TARGET_STATUS, required = true)
|
||||
@NotNull
|
||||
private final Status status;
|
||||
|
||||
@@ -90,7 +74,7 @@ public class ActionFeedback {
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
*
|
||||
* @see java.lang.Object#toString()
|
||||
*/
|
||||
@Override
|
||||
|
||||
11
hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/controller/model/Artifact.java
Executable file → Normal file
11
hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/controller/model/Artifact.java
Executable file → Normal file
@@ -11,34 +11,23 @@ package org.eclipse.hawkbit.controller.model;
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
import org.eclipse.hawkbit.rest.resource.model.artifact.ArtifactHash;
|
||||
import org.eclipse.hawkbit.rest.resource.model.doc.ApiModelProperties;
|
||||
import org.springframework.hateoas.ResourceSupport;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
|
||||
/**
|
||||
* Download information for all artifacts related to a specific {@link Chunk}.
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
@ApiModel(ApiModelProperties.ARTIFACTS)
|
||||
public class Artifact extends ResourceSupport {
|
||||
|
||||
@ApiModelProperty(value = ApiModelProperties.ARTIFACT_PROVIDED_FILENAME, required = true)
|
||||
@NotNull
|
||||
@JsonProperty
|
||||
private String filename;
|
||||
|
||||
@ApiModelProperty(value = ApiModelProperties.ARTIFACT_HASHES)
|
||||
@JsonProperty
|
||||
private ArtifactHash hashes;
|
||||
|
||||
@ApiModelProperty(value = ApiModelProperties.ARTIFACT_SIZE)
|
||||
@JsonProperty
|
||||
private Long size;
|
||||
|
||||
|
||||
14
hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/controller/model/Cancel.java
Executable file → Normal file
14
hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/controller/model/Cancel.java
Executable file → Normal file
@@ -10,29 +10,19 @@ package org.eclipse.hawkbit.controller.model;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
import org.eclipse.hawkbit.rest.resource.model.doc.ApiModelProperties;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
|
||||
/**
|
||||
* Cancel action to be provided to the target.
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
@ApiModel("SP Target Cancel Action")
|
||||
public class Cancel {
|
||||
@ApiModelProperty(value = ApiModelProperties.ACTION_ID)
|
||||
private final String id;
|
||||
|
||||
@ApiModelProperty(value = ApiModelProperties.CANCEL_ACTION, required = true)
|
||||
@NotNull
|
||||
private final CancelActionToStop cancelAction;
|
||||
|
||||
/**
|
||||
* Parameterized constructor.
|
||||
*
|
||||
*
|
||||
* @param id
|
||||
* of the {@link CancelAction}
|
||||
* @param cancelAction
|
||||
@@ -60,7 +50,7 @@ public class Cancel {
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
*
|
||||
* @see java.lang.Object#toString()
|
||||
*/
|
||||
@Override
|
||||
|
||||
12
hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/controller/model/CancelActionToStop.java
Executable file → Normal file
12
hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/controller/model/CancelActionToStop.java
Executable file → Normal file
@@ -11,27 +11,19 @@ package org.eclipse.hawkbit.controller.model;
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
import org.eclipse.hawkbit.repository.model.Action;
|
||||
import org.eclipse.hawkbit.rest.resource.model.doc.ApiModelProperties;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
|
||||
/**
|
||||
* The {@link Action} that has to be stopped by the target.
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
@ApiModel(ApiModelProperties.CANCEL_ACTION)
|
||||
public class CancelActionToStop {
|
||||
|
||||
@ApiModelProperty(value = ApiModelProperties.ACTION_ID, required = true)
|
||||
@NotNull
|
||||
private final String stopId;
|
||||
|
||||
/**
|
||||
* Parameterized constructor.
|
||||
*
|
||||
*
|
||||
* @param stopId
|
||||
* ID of the {@link Action} to be stoppedW
|
||||
*/
|
||||
@@ -49,7 +41,7 @@ public class CancelActionToStop {
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
*
|
||||
* @see java.lang.Object#toString()
|
||||
*/
|
||||
@Override
|
||||
|
||||
14
hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/controller/model/Chunk.java
Executable file → Normal file
14
hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/controller/model/Chunk.java
Executable file → Normal file
@@ -12,35 +12,21 @@ import java.util.List;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
import org.eclipse.hawkbit.rest.resource.model.doc.ApiModelProperties;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
|
||||
/**
|
||||
* Deployment chunks.
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
@ApiModel(ApiModelProperties.CHUNK)
|
||||
public class Chunk {
|
||||
|
||||
@ApiModelProperty(value = ApiModelProperties.CHUNK_TYPE, required = true)
|
||||
@NotNull
|
||||
private final String part;
|
||||
|
||||
@ApiModelProperty(value = ApiModelProperties.CHUNK_VERSION, required = true)
|
||||
@NotNull
|
||||
private final String version;
|
||||
|
||||
@ApiModelProperty(value = ApiModelProperties.CHUNK_NAME, required = true)
|
||||
@NotNull
|
||||
private final String name;
|
||||
|
||||
@ApiModelProperty(value = ApiModelProperties.ARTIFACTS)
|
||||
private final List<Artifact> artifacts;
|
||||
|
||||
/**
|
||||
|
||||
11
hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/controller/model/Config.java
Executable file → Normal file
11
hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/controller/model/Config.java
Executable file → Normal file
@@ -8,23 +8,12 @@
|
||||
*/
|
||||
package org.eclipse.hawkbit.controller.model;
|
||||
|
||||
import org.eclipse.hawkbit.rest.resource.model.doc.ApiModelProperties;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
|
||||
/**
|
||||
* Standard configuration for the target.
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
@ApiModel(ApiModelProperties.TARGET_CONFIGURATION)
|
||||
public class Config {
|
||||
|
||||
@ApiModelProperty(value = ApiModelProperties.TARGET_POLL_TIME)
|
||||
private final Polling polling;
|
||||
|
||||
/**
|
||||
|
||||
14
hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/controller/model/ConfigData.java
Executable file → Normal file
14
hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/controller/model/ConfigData.java
Executable file → Normal file
@@ -10,27 +10,17 @@ package org.eclipse.hawkbit.controller.model;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.hawkbit.rest.resource.model.doc.ApiModelProperties;
|
||||
import org.hibernate.validator.constraints.NotEmpty;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
|
||||
/**
|
||||
* feedback channel for ConfigData action.
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
* Feedback channel for ConfigData action.
|
||||
*
|
||||
*/
|
||||
@ApiModel("Configuration or metadata that is reponded by the target")
|
||||
public class ConfigData extends ActionFeedback {
|
||||
|
||||
@ApiModelProperty(ApiModelProperties.TARGET_CONFIG_DATA)
|
||||
@NotEmpty
|
||||
private final Map<String, String> data;
|
||||
|
||||
@@ -64,7 +54,7 @@ public class ConfigData extends ActionFeedback {
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
*
|
||||
* @see java.lang.Object#toString()
|
||||
*/
|
||||
@Override
|
||||
|
||||
12
hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/controller/model/ControllerBase.java
Executable file → Normal file
12
hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/controller/model/ControllerBase.java
Executable file → Normal file
@@ -8,24 +8,14 @@
|
||||
*/
|
||||
package org.eclipse.hawkbit.controller.model;
|
||||
|
||||
import org.eclipse.hawkbit.rest.resource.model.doc.ApiModelProperties;
|
||||
import org.springframework.hateoas.ResourceSupport;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
|
||||
/**
|
||||
* {@link ControllerBase} ressource content.
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
* {@link ControllerBase} resource content.
|
||||
*
|
||||
*/
|
||||
@ApiModel("SP target base poll resource")
|
||||
public class ControllerBase extends ResourceSupport {
|
||||
|
||||
@ApiModelProperty(ApiModelProperties.TARGET_CONFIGURATION)
|
||||
private final Config config;
|
||||
|
||||
/**
|
||||
|
||||
19
hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/controller/model/Deployment.java
Executable file → Normal file
19
hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/controller/model/Deployment.java
Executable file → Normal file
@@ -11,31 +11,19 @@ package org.eclipse.hawkbit.controller.model;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.hawkbit.repository.model.Action;
|
||||
import org.eclipse.hawkbit.rest.resource.model.doc.ApiModelProperties;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonValue;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
|
||||
/**
|
||||
* Detailed {@link UpdateAction} information.
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
@ApiModel(ApiModelProperties.DEPLOYMENT)
|
||||
public class Deployment {
|
||||
|
||||
@ApiModelProperty(value = ApiModelProperties.HANDLING_DOWNLOAD)
|
||||
private final HandlingType download;
|
||||
|
||||
@ApiModelProperty(value = ApiModelProperties.HANDLING_UPDATE)
|
||||
private final HandlingType update;
|
||||
|
||||
@ApiModelProperty(value = ApiModelProperties.CHUNK)
|
||||
private final List<Chunk> chunks;
|
||||
|
||||
/**
|
||||
@@ -70,12 +58,7 @@ public class Deployment {
|
||||
/**
|
||||
* The handling type for the update {@link Action}.
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
@ApiModel("Handling type for the deployment part")
|
||||
public enum HandlingType {
|
||||
/**
|
||||
* Not necessary for the command.
|
||||
@@ -109,7 +92,7 @@ public class Deployment {
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
*
|
||||
* @see java.lang.Object#toString()
|
||||
*/
|
||||
@Override
|
||||
|
||||
15
hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/controller/model/DeploymentBase.java
Executable file → Normal file
15
hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/controller/model/DeploymentBase.java
Executable file → Normal file
@@ -10,31 +10,20 @@ package org.eclipse.hawkbit.controller.model;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
import org.eclipse.hawkbit.rest.resource.model.doc.ApiModelProperties;
|
||||
import org.springframework.hateoas.ResourceSupport;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
|
||||
/**
|
||||
* {@link UpdateAction} ressource.
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
* {@link UpdateAction} resource.
|
||||
*
|
||||
*/
|
||||
@ApiModel("Deployment or update action")
|
||||
public class DeploymentBase extends ResourceSupport {
|
||||
|
||||
@ApiModelProperty(value = ApiModelProperties.ITEM_ID, required = false)
|
||||
@JsonProperty("id")
|
||||
@NotNull
|
||||
private final String deplyomentId;
|
||||
|
||||
@ApiModelProperty(value = ApiModelProperties.DEPLOYMENT, required = false)
|
||||
@NotNull
|
||||
private final Deployment deployment;
|
||||
|
||||
@@ -57,7 +46,7 @@ public class DeploymentBase extends ResourceSupport {
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
*
|
||||
* @see java.lang.Object#toString()
|
||||
*/
|
||||
@Override
|
||||
|
||||
11
hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/controller/model/Polling.java
Executable file → Normal file
11
hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/controller/model/Polling.java
Executable file → Normal file
@@ -8,23 +8,12 @@
|
||||
*/
|
||||
package org.eclipse.hawkbit.controller.model;
|
||||
|
||||
import org.eclipse.hawkbit.rest.resource.model.doc.ApiModelProperties;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
|
||||
/**
|
||||
* Polling interval for the SP target.
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
@ApiModel(value = ApiModelProperties.TARGET_POLL_TIME)
|
||||
public class Polling {
|
||||
|
||||
@ApiModelProperty(value = ApiModelProperties.TARGET_SLEEP)
|
||||
private final String sleep;
|
||||
|
||||
/**
|
||||
|
||||
14
hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/controller/model/Progress.java
Executable file → Normal file
14
hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/controller/model/Progress.java
Executable file → Normal file
@@ -10,31 +10,19 @@ package org.eclipse.hawkbit.controller.model;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
import org.eclipse.hawkbit.rest.resource.model.doc.ApiModelProperties;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
|
||||
/**
|
||||
* Action fulfillment progress by means of gives the achieved amount of maximal
|
||||
* of possible levels.
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
@ApiModel(ApiModelProperties.TARGET_RESULT_PROGRESS)
|
||||
public class Progress {
|
||||
|
||||
@ApiModelProperty(value = ApiModelProperties.TARGET_PROGRESS_CNT, required = true)
|
||||
@NotNull
|
||||
private final Integer cnt;
|
||||
|
||||
@ApiModelProperty(value = ApiModelProperties.TARGET_PROGRESS_OF)
|
||||
private final Integer of;
|
||||
|
||||
/**
|
||||
@@ -62,7 +50,7 @@ public class Progress {
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
*
|
||||
* @see java.lang.Object#toString()
|
||||
*/
|
||||
@Override
|
||||
|
||||
17
hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/controller/model/Result.java
Executable file → Normal file
17
hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/controller/model/Result.java
Executable file → Normal file
@@ -8,33 +8,23 @@
|
||||
*/
|
||||
package org.eclipse.hawkbit.controller.model;
|
||||
|
||||
import org.eclipse.hawkbit.rest.resource.model.doc.ApiModelProperties;
|
||||
import org.hibernate.validator.constraints.NotEmpty;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.annotation.JsonValue;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
|
||||
/**
|
||||
* Result information of the action progress which can by an intermediate or
|
||||
* final update.
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
@ApiModel(ApiModelProperties.TARGET_RESULT_VALUE)
|
||||
public class Result {
|
||||
|
||||
@ApiModelProperty(value = ApiModelProperties.TARGET_RESULT_FINISHED, required = true)
|
||||
@NotEmpty
|
||||
private final FinalResult finished;
|
||||
|
||||
@ApiModelProperty(value = ApiModelProperties.TARGET_RESULT_PROGRESS)
|
||||
private final Progress progress;
|
||||
|
||||
/**
|
||||
@@ -64,12 +54,7 @@ public class Result {
|
||||
/**
|
||||
* Defined status of the final result.
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
@ApiModel(value = ApiModelProperties.TARGET_RESULT_FINISHED)
|
||||
public enum FinalResult {
|
||||
/**
|
||||
* Execution was successful.
|
||||
@@ -104,7 +89,7 @@ public class Result {
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
*
|
||||
* @see java.lang.Object#toString()
|
||||
*/
|
||||
@Override
|
||||
|
||||
@@ -1,94 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2015 Bosch Software Innovations GmbH and others.
|
||||
*
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*/
|
||||
package org.eclipse.hawkbit.controller.model;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
import org.eclipse.hawkbit.rest.resource.model.doc.ApiModelProperties;
|
||||
import org.springframework.hateoas.Link;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
@ApiModel(ApiModelProperties.SOFTWARE_MODUL)
|
||||
public class SoftwareModule {
|
||||
|
||||
@ApiModelProperty(value = ApiModelProperties.SOFTWARE_MODUL_TYPE, required = true)
|
||||
@NotNull
|
||||
private final Long id;
|
||||
|
||||
@ApiModelProperty(value = ApiModelProperties.SOFTWARE_MODUL_TYPE, required = true)
|
||||
@NotNull
|
||||
private final String type;
|
||||
|
||||
@ApiModelProperty(value = ApiModelProperties.SOFTWARE_MODULE_VERSION, required = true)
|
||||
@NotNull
|
||||
private final String version;
|
||||
|
||||
@ApiModelProperty(value = ApiModelProperties.SOFTWARE_MODULE_NAME, required = true)
|
||||
@NotNull
|
||||
private final String name;
|
||||
|
||||
@ApiModelProperty(value = ApiModelProperties.SOFTWARE_MODULE_ARTIFACT_LINKS)
|
||||
private final List<Link> artifactLinks;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param id
|
||||
* of the software module
|
||||
* @param type
|
||||
* of the deployment software module
|
||||
* @param version
|
||||
* of the software module
|
||||
* @param name
|
||||
* of the software module
|
||||
* @param artifactLinks
|
||||
* the links to the artifacts of the software module
|
||||
*/
|
||||
public SoftwareModule(final Long id, final String type, final String version, final String name,
|
||||
final List<Link> artifactLinks) {
|
||||
this.id = id;
|
||||
this.type = type;
|
||||
this.version = version;
|
||||
this.name = name;
|
||||
this.artifactLinks = artifactLinks;
|
||||
}
|
||||
|
||||
@JsonProperty("links")
|
||||
public List<Link> getArtifactLinks() {
|
||||
return artifactLinks;
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public String getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
}
|
||||
20
hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/controller/model/Status.java
Executable file → Normal file
20
hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/controller/model/Status.java
Executable file → Normal file
@@ -12,35 +12,22 @@ import java.util.List;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
import org.eclipse.hawkbit.rest.resource.model.doc.ApiModelProperties;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.annotation.JsonValue;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
|
||||
/**
|
||||
* Details status information concerning the action processing.
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
@ApiModel(ApiModelProperties.TARGET_STATUS)
|
||||
public class Status {
|
||||
|
||||
@ApiModelProperty(value = ApiModelProperties.TARGET_EXEC_STATUS, required = true)
|
||||
@NotNull
|
||||
private final ExecutionStatus execution;
|
||||
|
||||
@ApiModelProperty(value = ApiModelProperties.TARGET_RESULT_VALUE, required = true)
|
||||
@NotNull
|
||||
private final Result result;
|
||||
|
||||
@ApiModelProperty(value = ApiModelProperties.TARGET_RESULT_DETAILS)
|
||||
private final List<String> details;
|
||||
|
||||
/**
|
||||
@@ -78,12 +65,7 @@ public class Status {
|
||||
* The element status contains information about the execution of the
|
||||
* operation.
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
@ApiModel(ApiModelProperties.TARGET_EXEC_STATUS)
|
||||
public enum ExecutionStatus {
|
||||
/**
|
||||
* Execution of the action has finished.
|
||||
@@ -132,7 +114,7 @@ public class Status {
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
*
|
||||
* @see java.lang.Object#toString()
|
||||
*/
|
||||
@Override
|
||||
|
||||
65
hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/DistributionSetMapper.java
Executable file → Normal file
65
hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/DistributionSetMapper.java
Executable file → Normal file
@@ -23,7 +23,7 @@ import org.eclipse.hawkbit.repository.model.DistributionSetMetadata;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSetType;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModule;
|
||||
import org.eclipse.hawkbit.rest.resource.model.MetadataRest;
|
||||
import org.eclipse.hawkbit.rest.resource.model.distributionset.DistributionSetRequestBodyCreate;
|
||||
import org.eclipse.hawkbit.rest.resource.model.distributionset.DistributionSetRequestBodyPost;
|
||||
import org.eclipse.hawkbit.rest.resource.model.distributionset.DistributionSetRest;
|
||||
import org.eclipse.hawkbit.rest.resource.model.distributionset.DistributionSetsRest;
|
||||
import org.eclipse.hawkbit.rest.resource.model.distributionset.TargetAssignmentResponseBody;
|
||||
@@ -36,7 +36,7 @@ import org.eclipse.hawkbit.rest.resource.model.distributionset.TargetAssignmentR
|
||||
*
|
||||
*
|
||||
*/
|
||||
final class DistributionSetMapper {
|
||||
public final class DistributionSetMapper {
|
||||
private DistributionSetMapper() {
|
||||
// Utility class
|
||||
}
|
||||
@@ -57,14 +57,14 @@ final class DistributionSetMapper {
|
||||
final DistributionSetType module = distributionSetManagement
|
||||
.findDistributionSetTypeByKey(distributionSetTypekey);
|
||||
if (module == null) {
|
||||
throw new EntityNotFoundException(
|
||||
"DistributionSetType with key {" + distributionSetTypekey + "} does not exist");
|
||||
throw new EntityNotFoundException("DistributionSetType with key {" + distributionSetTypekey
|
||||
+ "} does not exist");
|
||||
}
|
||||
return module;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@link DistributionSetRequestBodyCreate}s to {@link DistributionSet}s.
|
||||
* {@link DistributionSetRequestBodyPost}s to {@link DistributionSet}s.
|
||||
*
|
||||
* @param sets
|
||||
* to convert
|
||||
@@ -72,11 +72,11 @@ final class DistributionSetMapper {
|
||||
* to use for conversion
|
||||
* @return converted list of {@link DistributionSet}s
|
||||
*/
|
||||
static List<DistributionSet> dsFromRequest(final Iterable<DistributionSetRequestBodyCreate> sets,
|
||||
static List<DistributionSet> dsFromRequest(final Iterable<DistributionSetRequestBodyPost> sets,
|
||||
final SoftwareManagement softwareManagement, final DistributionSetManagement distributionSetManagement) {
|
||||
|
||||
final List<DistributionSet> mappedList = new ArrayList<>();
|
||||
for (final DistributionSetRequestBodyCreate dsRest : sets) {
|
||||
for (final DistributionSetRequestBodyPost dsRest : sets) {
|
||||
mappedList.add(fromRequest(dsRest, softwareManagement, distributionSetManagement));
|
||||
}
|
||||
return mappedList;
|
||||
@@ -84,7 +84,7 @@ final class DistributionSetMapper {
|
||||
}
|
||||
|
||||
/**
|
||||
* {@link DistributionSetRequestBodyCreate} to {@link DistributionSet}.
|
||||
* {@link DistributionSetRequestBodyPost} to {@link DistributionSet}.
|
||||
*
|
||||
* @param dsRest
|
||||
* to convert
|
||||
@@ -92,7 +92,7 @@ final class DistributionSetMapper {
|
||||
* to use for conversion
|
||||
* @return converted {@link DistributionSet}
|
||||
*/
|
||||
static DistributionSet fromRequest(final DistributionSetRequestBodyCreate dsRest,
|
||||
static DistributionSet fromRequest(final DistributionSetRequestBodyPost dsRest,
|
||||
final SoftwareManagement softwareManagement, final DistributionSetManagement distributionSetManagement) {
|
||||
|
||||
final DistributionSet result = new DistributionSet();
|
||||
@@ -108,18 +108,18 @@ final class DistributionSetMapper {
|
||||
}
|
||||
|
||||
if (dsRest.getApplication() != null) {
|
||||
result.addModule(
|
||||
findSoftwareModuleWithExceptionIfNotFound(dsRest.getApplication().getId(), softwareManagement));
|
||||
result.addModule(findSoftwareModuleWithExceptionIfNotFound(dsRest.getApplication().getId(),
|
||||
softwareManagement));
|
||||
}
|
||||
|
||||
if (dsRest.getRuntime() != null) {
|
||||
result.addModule(
|
||||
findSoftwareModuleWithExceptionIfNotFound(dsRest.getRuntime().getId(), softwareManagement));
|
||||
result.addModule(findSoftwareModuleWithExceptionIfNotFound(dsRest.getRuntime().getId(), softwareManagement));
|
||||
}
|
||||
|
||||
if (dsRest.getModules() != null) {
|
||||
dsRest.getModules().forEach(module -> result
|
||||
.addModule(findSoftwareModuleWithExceptionIfNotFound(module.getId(), softwareManagement)));
|
||||
dsRest.getModules().forEach(
|
||||
module -> result.addModule(findSoftwareModuleWithExceptionIfNotFound(module.getId(),
|
||||
softwareManagement)));
|
||||
}
|
||||
|
||||
return result;
|
||||
@@ -144,7 +144,14 @@ final class DistributionSetMapper {
|
||||
return mappedList;
|
||||
}
|
||||
|
||||
static DistributionSetRest toResponse(final DistributionSet distributionSet) {
|
||||
/**
|
||||
* Create a response for distribution set.
|
||||
*
|
||||
* @param distributionSet
|
||||
* the ds set
|
||||
* @return the response
|
||||
*/
|
||||
public static DistributionSetRest toResponse(final DistributionSet distributionSet) {
|
||||
if (distributionSet == null) {
|
||||
return null;
|
||||
}
|
||||
@@ -156,22 +163,23 @@ final class DistributionSetMapper {
|
||||
response.setComplete(distributionSet.isComplete());
|
||||
response.setType(distributionSet.getType().getKey());
|
||||
|
||||
distributionSet.getModules()
|
||||
.forEach(module -> response.getModules().add(SoftwareModuleMapper.toResponse(module)));
|
||||
distributionSet.getModules().forEach(
|
||||
module -> response.getModules().add(SoftwareModuleMapper.toResponse(module)));
|
||||
|
||||
response.setRequiredMigrationStep(distributionSet.isRequiredMigrationStep());
|
||||
|
||||
response.add(
|
||||
linkTo(methodOn(DistributionSetResource.class).getDistributionSet(response.getDsId())).withRel("self"));
|
||||
response.add(linkTo(methodOn(DistributionSetResource.class).getDistributionSet(response.getDsId())).withRel(
|
||||
"self"));
|
||||
|
||||
response.add(linkTo(
|
||||
methodOn(DistributionSetTypeResource.class).getDistributionSetType(distributionSet.getType().getId()))
|
||||
.withRel("type"));
|
||||
.withRel("type"));
|
||||
|
||||
response.add(linkTo(methodOn(DistributionSetResource.class).getMetadata(response.getDsId(),
|
||||
Integer.parseInt(RestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET),
|
||||
Integer.parseInt(RestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT), null, null))
|
||||
.withRel("metadata"));
|
||||
response.add(linkTo(
|
||||
methodOn(DistributionSetResource.class).getMetadata(response.getDsId(),
|
||||
Integer.parseInt(RestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET),
|
||||
Integer.parseInt(RestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT), null, null)).withRel(
|
||||
"metadata"));
|
||||
|
||||
return response;
|
||||
}
|
||||
@@ -186,8 +194,11 @@ final class DistributionSetMapper {
|
||||
|
||||
static DistributionSetsRest toResponseDistributionSets(final Iterable<DistributionSet> sets) {
|
||||
final DistributionSetsRest response = new DistributionSetsRest();
|
||||
for (final DistributionSet set : sets) {
|
||||
response.add(toResponse(set));
|
||||
if (sets != null) {
|
||||
|
||||
for (final DistributionSet set : sets) {
|
||||
response.add(toResponse(set));
|
||||
}
|
||||
}
|
||||
return response;
|
||||
}
|
||||
|
||||
225
hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/DistributionSetResource.java
Executable file → Normal file
225
hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/DistributionSetResource.java
Executable file → Normal file
@@ -8,12 +8,6 @@
|
||||
*/
|
||||
package org.eclipse.hawkbit.rest.resource;
|
||||
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.annotations.ApiParam;
|
||||
import io.swagger.annotations.ApiResponse;
|
||||
import io.swagger.annotations.ApiResponses;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
@@ -21,7 +15,6 @@ import java.util.stream.Collectors;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
|
||||
import org.eclipse.hawkbit.im.authentication.SpPermission;
|
||||
import org.eclipse.hawkbit.repository.DeploymentManagement;
|
||||
import org.eclipse.hawkbit.repository.DistributionSetAssignmentResult;
|
||||
import org.eclipse.hawkbit.repository.DistributionSetFields;
|
||||
@@ -40,19 +33,17 @@ import org.eclipse.hawkbit.repository.model.SoftwareModule;
|
||||
import org.eclipse.hawkbit.repository.model.Target;
|
||||
import org.eclipse.hawkbit.repository.rsql.RSQLUtility;
|
||||
import org.eclipse.hawkbit.rest.resource.helper.RestResourceConversionHelper;
|
||||
import org.eclipse.hawkbit.rest.resource.model.ExceptionInfo;
|
||||
import org.eclipse.hawkbit.rest.resource.model.MetadataRest;
|
||||
import org.eclipse.hawkbit.rest.resource.model.MetadataRestPageList;
|
||||
import org.eclipse.hawkbit.rest.resource.model.distributionset.DistributionSetPagedList;
|
||||
import org.eclipse.hawkbit.rest.resource.model.distributionset.DistributionSetRequestBodyCreate;
|
||||
import org.eclipse.hawkbit.rest.resource.model.distributionset.DistributionSetRequestBodyUpdate;
|
||||
import org.eclipse.hawkbit.rest.resource.model.distributionset.DistributionSetRequestBodyPost;
|
||||
import org.eclipse.hawkbit.rest.resource.model.distributionset.DistributionSetRequestBodyPut;
|
||||
import org.eclipse.hawkbit.rest.resource.model.distributionset.DistributionSetRest;
|
||||
import org.eclipse.hawkbit.rest.resource.model.distributionset.DistributionSetsRest;
|
||||
import org.eclipse.hawkbit.rest.resource.model.distributionset.TargetAssignmentRequestBody;
|
||||
import org.eclipse.hawkbit.rest.resource.model.distributionset.TargetAssignmentResponseBody;
|
||||
import org.eclipse.hawkbit.rest.resource.model.softwaremodule.SoftwareModuleAssigmentRest;
|
||||
import org.eclipse.hawkbit.rest.resource.model.softwaremodule.SoftwareModulePagedList;
|
||||
import org.eclipse.hawkbit.rest.resource.model.softwaremodule.SoftwareModuleRest;
|
||||
import org.eclipse.hawkbit.rest.resource.model.target.TargetPagedList;
|
||||
import org.eclipse.hawkbit.tenancy.TenantAware;
|
||||
import org.slf4j.Logger;
|
||||
@@ -64,7 +55,6 @@ import org.springframework.data.domain.Sort;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
@@ -80,9 +70,7 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
*
|
||||
*/
|
||||
@RestController
|
||||
@Transactional(readOnly = true)
|
||||
@RequestMapping(RestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING)
|
||||
@Api(value = "distributionsets", description = "Distribution Set Management API")
|
||||
public class DistributionSetResource {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(DistributionSetResource.class);
|
||||
|
||||
@@ -128,18 +116,11 @@ public class DistributionSetResource {
|
||||
* JsonResponseExceptionHandler is handling the response.
|
||||
*/
|
||||
@RequestMapping(method = RequestMethod.GET, produces = { "application/hal+json", MediaType.APPLICATION_JSON_VALUE })
|
||||
@ApiOperation(response = DistributionSetPagedList.class, value = "Get paged list of Distribution Sets", notes = "Handles the GET request of retrieving all distribution sets within SP. Required Permission: "
|
||||
+ SpPermission.READ_REPOSITORY)
|
||||
public ResponseEntity<DistributionSetPagedList> getDistributionSets(
|
||||
@RequestParam(value = RestConstants.REQUEST_PARAMETER_PAGING_OFFSET, defaultValue = RestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET) final int pagingOffsetParam,
|
||||
@RequestParam(value = RestConstants.REQUEST_PARAMETER_PAGING_LIMIT, defaultValue = RestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT) final int pagingLimitParam,
|
||||
@RequestParam(value = RestConstants.REQUEST_PARAMETER_SORTING, required = false) final String sortParam,
|
||||
@ApiParam(required = false, value = "FIQL syntax search query"
|
||||
+ "<table border=0>"
|
||||
+ "<tr><td>version==1.0.0</td><td>distribution sets with version 1.0.0</td></tr>"
|
||||
+ "<tr><td>version=ge=2.0.0</td><td>distribution sets with version greater-equal 2.0.0</td></tr>"
|
||||
+ "<tr><td>name=li=%25hotfix%25,description=li=%25hotfix%25</td><td>distribution sets with either 'hotfix' in name or description ignore case</td></tr>"
|
||||
+ "</table>") @RequestParam(value = RestConstants.REQUEST_PARAMETER_SEARCH, required = false) final String rsqlParam) {
|
||||
@RequestParam(value = RestConstants.REQUEST_PARAMETER_SEARCH, required = false) final String rsqlParam) {
|
||||
|
||||
final int sanitizedOffsetParam = PagingUtility.sanitizeOffsetParam(pagingOffsetParam);
|
||||
final int sanitizedLimitParam = PagingUtility.sanitizePageLimitParam(pagingLimitParam);
|
||||
@@ -172,12 +153,10 @@ public class DistributionSetResource {
|
||||
*/
|
||||
@RequestMapping(method = RequestMethod.GET, value = "/{distributionSetId}", produces = { "application/hal+json",
|
||||
MediaType.APPLICATION_JSON_VALUE })
|
||||
@ApiOperation(response = DistributionSetRest.class, value = "Get Distribution Set", notes = "Handles the GET request of retrieving a single distribution set within SP. Required Permission: "
|
||||
+ SpPermission.READ_REPOSITORY)
|
||||
public ResponseEntity<DistributionSetRest> getDistributionSet(@PathVariable final Long distributionSetId) {
|
||||
final DistributionSet foundDs = findDistributionSetWithExceptionIfNotFound(distributionSetId);
|
||||
|
||||
return new ResponseEntity<DistributionSetRest>(DistributionSetMapper.toResponse(foundDs), HttpStatus.OK);
|
||||
return new ResponseEntity<>(DistributionSetMapper.toResponse(foundDs), HttpStatus.OK);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -192,29 +171,18 @@ public class DistributionSetResource {
|
||||
* failure the JsonResponseExceptionHandler is handling the
|
||||
* response.
|
||||
*/
|
||||
@RequestMapping(method = RequestMethod.POST, consumes = { MediaType.APPLICATION_JSON_VALUE, "application/hal+json" }, produces = {
|
||||
"application/hal+json", MediaType.APPLICATION_JSON_VALUE })
|
||||
@ApiOperation(response = DistributionSetsRest.class, value = "Create Distribution Sets", notes = "Handles the POST request of creating new distribution sets within SP. The request body must always be a list of sets. Required Permission: "
|
||||
+ SpPermission.CREATE_REPOSITORY)
|
||||
@ApiResponses(@ApiResponse(code = 409, message = "Conflict", response = ExceptionInfo.class))
|
||||
@Transactional
|
||||
@RequestMapping(method = RequestMethod.POST, consumes = { MediaType.APPLICATION_JSON_VALUE,
|
||||
"application/hal+json" }, produces = { "application/hal+json", MediaType.APPLICATION_JSON_VALUE })
|
||||
public ResponseEntity<DistributionSetsRest> createDistributionSets(
|
||||
@RequestBody final List<DistributionSetRequestBodyCreate> sets) {
|
||||
@RequestBody final List<DistributionSetRequestBodyPost> sets) {
|
||||
|
||||
LOG.debug("creating {} distribution sets", sets.size());
|
||||
// set default Ds type if ds type is null
|
||||
sets.stream()
|
||||
.filter(ds -> ds.getType() == null)
|
||||
.forEach(
|
||||
ds -> ds.setType(systemManagement.getTenantMetadata(currentTenant.getCurrentTenant())
|
||||
.getDefaultDsType().getKey()));
|
||||
sets.stream().filter(ds -> ds.getType() == null).forEach(ds -> ds.setType(
|
||||
systemManagement.getTenantMetadata(currentTenant.getCurrentTenant()).getDefaultDsType().getKey()));
|
||||
|
||||
final Iterable<DistributionSet> createdDSets = distributionSetManagement
|
||||
.createDistributionSets(DistributionSetMapper.dsFromRequest(sets, softwareManagement,
|
||||
distributionSetManagement));
|
||||
|
||||
// we flush to ensure that entity is generated and we can return ID etc.
|
||||
entityManager.flush();
|
||||
final Iterable<DistributionSet> createdDSets = distributionSetManagement.createDistributionSets(
|
||||
DistributionSetMapper.dsFromRequest(sets, softwareManagement, distributionSetManagement));
|
||||
|
||||
LOG.debug("{} distribution sets created, return status {}", sets.size(), HttpStatus.CREATED);
|
||||
return new ResponseEntity<>(DistributionSetMapper.toResponseDistributionSets(createdDSets), HttpStatus.CREATED);
|
||||
@@ -230,10 +198,6 @@ public class DistributionSetResource {
|
||||
*
|
||||
*/
|
||||
@RequestMapping(method = RequestMethod.DELETE, value = "/{distributionSetId}")
|
||||
@ApiOperation(value = "Delete Distribution Set", notes = "Handles the DELETE request for a single Distribution Set within SP. Required Permission: "
|
||||
+ SpPermission.DELETE_REPOSITORY)
|
||||
@ApiResponses(@ApiResponse(code = 404, message = "Not Found Distribution Set", response = ExceptionInfo.class))
|
||||
@Transactional
|
||||
public ResponseEntity<Void> deleteDistributionSet(@PathVariable final Long distributionSetId) {
|
||||
final DistributionSet set = findDistributionSetWithExceptionIfNotFound(distributionSetId);
|
||||
|
||||
@@ -256,12 +220,8 @@ public class DistributionSetResource {
|
||||
*/
|
||||
@RequestMapping(method = RequestMethod.PUT, value = "/{distributionSetId}", consumes = { "application/hal+json",
|
||||
MediaType.APPLICATION_JSON_VALUE }, produces = { MediaType.APPLICATION_JSON_VALUE, "application/hal+json" })
|
||||
@ApiOperation(response = DistributionSetRest.class, value = "Update Distribution Set", notes = "Handles the UPDATE request for a single Distribution Set within SP. Required Permission: "
|
||||
+ SpPermission.UPDATE_REPOSITORY)
|
||||
@ApiResponses(@ApiResponse(code = 404, message = "Not Found Distribution Set", response = ExceptionInfo.class))
|
||||
@Transactional
|
||||
public ResponseEntity<DistributionSetRest> updateDistributionSet(@PathVariable final Long distributionSetId,
|
||||
@RequestBody final DistributionSetRequestBodyUpdate toUpdate) {
|
||||
@RequestBody final DistributionSetRequestBodyPut toUpdate) {
|
||||
final DistributionSet set = findDistributionSetWithExceptionIfNotFound(distributionSetId);
|
||||
|
||||
if (toUpdate.getDescription() != null) {
|
||||
@@ -275,18 +235,14 @@ public class DistributionSetResource {
|
||||
if (toUpdate.getVersion() != null) {
|
||||
set.setVersion(toUpdate.getVersion());
|
||||
}
|
||||
|
||||
// we flush to ensure that entity is generated and we can return ID etc.
|
||||
entityManager.flush();
|
||||
|
||||
return new ResponseEntity<DistributionSetRest>(DistributionSetMapper.toResponse(distributionSetManagement
|
||||
.updateDistributionSet(set)), HttpStatus.OK);
|
||||
return new ResponseEntity<>(
|
||||
DistributionSetMapper.toResponse(distributionSetManagement.updateDistributionSet(set)), HttpStatus.OK);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the GET request of retrieving assigned targets to a specific
|
||||
* distribution set.
|
||||
*
|
||||
*
|
||||
* @param distributionSetId
|
||||
* the ID of the distribution set to retrieve the assigned
|
||||
* targets
|
||||
@@ -307,18 +263,11 @@ public class DistributionSetResource {
|
||||
*/
|
||||
@RequestMapping(method = RequestMethod.GET, value = "/{distributionSetId}/assignedTargets", produces = {
|
||||
MediaType.APPLICATION_JSON_VALUE, "application/hal+json" })
|
||||
@ApiOperation(response = TargetPagedList.class, value = "Get assigned targets", notes = "Handles the GET request for retrieving assigned targets of a single distribution set. Required Permission: "
|
||||
+ SpPermission.READ_REPOSITORY + " and " + SpPermission.READ_TARGET)
|
||||
@ApiResponses(@ApiResponse(code = 404, message = "Not Found Distribution Set", response = ExceptionInfo.class))
|
||||
public ResponseEntity<TargetPagedList> getAssignedTargets(
|
||||
@PathVariable final Long distributionSetId,
|
||||
public ResponseEntity<TargetPagedList> getAssignedTargets(@PathVariable final Long distributionSetId,
|
||||
@RequestParam(value = RestConstants.REQUEST_PARAMETER_PAGING_OFFSET, defaultValue = RestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET) final int pagingOffsetParam,
|
||||
@RequestParam(value = RestConstants.REQUEST_PARAMETER_PAGING_LIMIT, defaultValue = RestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT) final int pagingLimitParam,
|
||||
@RequestParam(value = RestConstants.REQUEST_PARAMETER_SORTING, required = false) final String sortParam,
|
||||
@ApiParam(required = false, value = "FIQL syntax search query" + "<table border=0>"
|
||||
+ "<tr><td>controllerId==0815</td><td>targets with the id '0815'</td></tr>"
|
||||
+ "<tr><td>name=li=%25ccu%25</td><td>targets which contains 'ccu' in their ignore case</td></tr>"
|
||||
+ "</table>") @RequestParam(value = RestConstants.REQUEST_PARAMETER_SEARCH, required = false) final String rsqlParam) {
|
||||
@RequestParam(value = RestConstants.REQUEST_PARAMETER_SEARCH, required = false) final String rsqlParam) {
|
||||
|
||||
// check if distribution set exists otherwise throw exception
|
||||
// immediately
|
||||
@@ -344,7 +293,7 @@ public class DistributionSetResource {
|
||||
/**
|
||||
* Handles the GET request of retrieving installed targets to a specific
|
||||
* distribution set.
|
||||
*
|
||||
*
|
||||
* @param distributionSetId
|
||||
* the ID of the distribution set to retrieve the assigned
|
||||
* targets
|
||||
@@ -365,18 +314,11 @@ public class DistributionSetResource {
|
||||
*/
|
||||
@RequestMapping(method = RequestMethod.GET, value = "/{distributionSetId}/installedTargets", produces = {
|
||||
MediaType.APPLICATION_JSON_VALUE, "application/hal+json" })
|
||||
@ApiOperation(response = TargetPagedList.class, value = "Get installed targets", notes = "Handles the GET request for retrieving installed targets of a single distribution set. Required Permission: "
|
||||
+ SpPermission.READ_REPOSITORY + " and " + SpPermission.READ_TARGET)
|
||||
@ApiResponses(@ApiResponse(code = 404, message = "Not Found Distribution Set", response = ExceptionInfo.class))
|
||||
public ResponseEntity<TargetPagedList> getInstalledTargets(
|
||||
@PathVariable final Long distributionSetId,
|
||||
public ResponseEntity<TargetPagedList> getInstalledTargets(@PathVariable final Long distributionSetId,
|
||||
@RequestParam(value = RestConstants.REQUEST_PARAMETER_PAGING_OFFSET, defaultValue = RestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET) final int pagingOffsetParam,
|
||||
@RequestParam(value = RestConstants.REQUEST_PARAMETER_PAGING_LIMIT, defaultValue = RestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT) final int pagingLimitParam,
|
||||
@RequestParam(value = RestConstants.REQUEST_PARAMETER_SORTING, required = false) final String sortParam,
|
||||
@ApiParam(required = false, value = "FIQL syntax search query" + "<table border=0>"
|
||||
+ "<tr><td>controllerId==0815</td><td>targets with the id '0815'</td></tr>"
|
||||
+ "<tr><td>name=li=%25ccu%25</td><td>targets which contains 'ccu' in their ignore case</td></tr>"
|
||||
+ "</table>") @RequestParam(value = RestConstants.REQUEST_PARAMETER_SEARCH, required = false) final String rsqlParam) {
|
||||
@RequestParam(value = RestConstants.REQUEST_PARAMETER_SEARCH, required = false) final String rsqlParam) {
|
||||
// check if distribution set exists otherwise throw exception
|
||||
// immediately
|
||||
findDistributionSetWithExceptionIfNotFound(distributionSetId);
|
||||
@@ -401,7 +343,7 @@ public class DistributionSetResource {
|
||||
/**
|
||||
* Handles the POST request of assigning multiple targets to a single
|
||||
* distribution set.
|
||||
*
|
||||
*
|
||||
* @param distributionSetId
|
||||
* the ID of the distribution set within the URL path parameter
|
||||
* @param targetIds
|
||||
@@ -412,33 +354,24 @@ public class DistributionSetResource {
|
||||
* targets and the already assigned targets counters
|
||||
*/
|
||||
@RequestMapping(method = RequestMethod.POST, value = "/{distributionSetId}/assignedTargets", consumes = {
|
||||
"application/hal+json", MediaType.APPLICATION_JSON_VALUE }, produces = { MediaType.APPLICATION_JSON_VALUE,
|
||||
"application/hal+json" })
|
||||
@ApiOperation(response = TargetAssignmentResponseBody.class, value = "Assign targets to a distribution set", notes = "Handles the POST request for assigning multiple targets to a distribution set.The request body must always be a list of target IDs."
|
||||
+ " Required Permission: " + SpPermission.READ_REPOSITORY + " and " + SpPermission.UPDATE_TARGET)
|
||||
@ApiResponses(@ApiResponse(code = 404, message = "Not Found Distribution Set", response = ExceptionInfo.class))
|
||||
@Transactional
|
||||
public ResponseEntity<TargetAssignmentResponseBody> createAssignedTarget(
|
||||
@PathVariable final Long distributionSetId,
|
||||
@RequestBody @ApiParam(value = "List of target IDs", required = true) final List<TargetAssignmentRequestBody> targetIds) {
|
||||
"application/hal+json",
|
||||
MediaType.APPLICATION_JSON_VALUE }, produces = { MediaType.APPLICATION_JSON_VALUE, "application/hal+json" })
|
||||
public ResponseEntity<TargetAssignmentResponseBody> createAssignedTarget(@PathVariable final Long distributionSetId,
|
||||
@RequestBody final List<TargetAssignmentRequestBody> targetIds) {
|
||||
|
||||
final DistributionSetAssignmentResult assignDistributionSet = deployManagament.assignDistributionSet(
|
||||
distributionSetId,
|
||||
targetIds
|
||||
.stream()
|
||||
.map(t -> new TargetWithActionType(t.getId(), RestResourceConversionHelper.convertActionType(t
|
||||
.getType()), t.getForcetime())).collect(Collectors.toList()));
|
||||
targetIds.stream()
|
||||
.map(t -> new TargetWithActionType(t.getId(),
|
||||
RestResourceConversionHelper.convertActionType(t.getType()), t.getForcetime()))
|
||||
.collect(Collectors.toList()));
|
||||
|
||||
// we flush to ensure that entity is generated and we can return ID etc.
|
||||
entityManager.flush();
|
||||
|
||||
return new ResponseEntity<TargetAssignmentResponseBody>(
|
||||
DistributionSetMapper.toResponse(assignDistributionSet), HttpStatus.OK);
|
||||
return new ResponseEntity<>(DistributionSetMapper.toResponse(assignDistributionSet), HttpStatus.OK);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a paged list of meta data for a distribution set.
|
||||
*
|
||||
*
|
||||
* @param distributionSetId
|
||||
* the ID of the distribution set for the meta data
|
||||
* @param pagingOffsetParam
|
||||
@@ -458,20 +391,11 @@ public class DistributionSetResource {
|
||||
*/
|
||||
@RequestMapping(method = RequestMethod.GET, value = "/{distributionSetId}/metadata", produces = {
|
||||
MediaType.APPLICATION_JSON_VALUE, "application/hal+json" })
|
||||
@ApiOperation(response = MetadataRestPageList.class, value = "Get a paged list of meta data", notes = " Get a paged list of meta data for a distribution set."
|
||||
+ " Required Permission: " + SpPermission.READ_REPOSITORY)
|
||||
@ApiResponses(@ApiResponse(code = 404, message = "Not Found Distribution Set", response = ExceptionInfo.class))
|
||||
@Transactional
|
||||
public ResponseEntity<MetadataRestPageList> getMetadata(
|
||||
@PathVariable final Long distributionSetId,
|
||||
public ResponseEntity<MetadataRestPageList> getMetadata(@PathVariable final Long distributionSetId,
|
||||
@RequestParam(value = RestConstants.REQUEST_PARAMETER_PAGING_OFFSET, defaultValue = RestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET) final int pagingOffsetParam,
|
||||
@RequestParam(value = RestConstants.REQUEST_PARAMETER_PAGING_LIMIT, defaultValue = RestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT) final int pagingLimitParam,
|
||||
@RequestParam(value = RestConstants.REQUEST_PARAMETER_SORTING, required = false) final String sortParam,
|
||||
@ApiParam(required = false, value = "FIQL syntax search query"
|
||||
+ "<table border=0>"
|
||||
+ "<tr><td>key==aKey,key==bKey</td><td>metadata with the key 'aKey' or 'bKey'</td></tr>"
|
||||
+ "<tr><td>value=li=%25someValue%25</td><td>metadata which contains 'someValue' in the value ignore case</td></tr>"
|
||||
+ "</table>") @RequestParam(value = RestConstants.REQUEST_PARAMETER_SEARCH, required = false) final String rsqlParam) {
|
||||
@RequestParam(value = RestConstants.REQUEST_PARAMETER_SEARCH, required = false) final String rsqlParam) {
|
||||
|
||||
// check if distribution set exists otherwise throw exception
|
||||
// immediately
|
||||
@@ -492,14 +416,16 @@ public class DistributionSetResource {
|
||||
pageable);
|
||||
}
|
||||
|
||||
return new ResponseEntity<>(new MetadataRestPageList(DistributionSetMapper.toResponseDsMetadata(metaDataPage
|
||||
.getContent()), metaDataPage.getTotalElements()), HttpStatus.OK);
|
||||
return new ResponseEntity<>(
|
||||
new MetadataRestPageList(DistributionSetMapper.toResponseDsMetadata(metaDataPage.getContent()),
|
||||
metaDataPage.getTotalElements()),
|
||||
HttpStatus.OK);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a single meta data value for a specific key of a distribution set.
|
||||
*
|
||||
*
|
||||
* @param distributionSetId
|
||||
* the ID of the distribution set to get the meta data from
|
||||
* @param metadataKey
|
||||
@@ -507,24 +433,21 @@ public class DistributionSetResource {
|
||||
* @return status OK if get request is successful with the value of the meta
|
||||
* data
|
||||
*/
|
||||
@RequestMapping(method = RequestMethod.GET, value = "/{distributionSetId}/metadata/{metadataKey}", produces = { MediaType.APPLICATION_JSON_VALUE })
|
||||
@ApiOperation(response = MetadataRest.class, value = "Get a single meta data value", notes = " Get a single meta data value for a meta data key."
|
||||
+ " Required Permission: " + SpPermission.READ_REPOSITORY)
|
||||
@ApiResponses(@ApiResponse(code = 404, message = "Not Found Distribution Set or meta data key", response = ExceptionInfo.class))
|
||||
@Transactional
|
||||
@RequestMapping(method = RequestMethod.GET, value = "/{distributionSetId}/metadata/{metadataKey}", produces = {
|
||||
MediaType.APPLICATION_JSON_VALUE })
|
||||
public ResponseEntity<MetadataRest> getMetadataValue(@PathVariable final Long distributionSetId,
|
||||
@PathVariable final String metadataKey) {
|
||||
// check if distribution set exists otherwise throw exception
|
||||
// immediately
|
||||
final DistributionSet ds = findDistributionSetWithExceptionIfNotFound(distributionSetId);
|
||||
final DistributionSetMetadata findOne = distributionSetManagement.findOne(new DsMetadataCompositeKey(ds,
|
||||
metadataKey));
|
||||
final DistributionSetMetadata findOne = distributionSetManagement
|
||||
.findOne(new DsMetadataCompositeKey(ds, metadataKey));
|
||||
return ResponseEntity.<MetadataRest> ok(DistributionSetMapper.toResponseDsMetadata(findOne));
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates a single meta data value of a distribution set.
|
||||
*
|
||||
*
|
||||
* @param distributionSetId
|
||||
* the ID of the distribution set to update the meta data entry
|
||||
* @param metadataKey
|
||||
@@ -534,10 +457,6 @@ public class DistributionSetResource {
|
||||
*/
|
||||
@RequestMapping(method = RequestMethod.PUT, value = "/{distributionSetId}/metadata/{metadataKey}", produces = {
|
||||
MediaType.APPLICATION_JSON_VALUE, "application/hal+json" })
|
||||
@ApiOperation(response = MetadataRest.class, value = "Update a single meta data value", notes = " Update a single meta data value for speficic key."
|
||||
+ " Required Permission: " + SpPermission.UPDATE_REPOSITORY)
|
||||
@ApiResponses(@ApiResponse(code = 404, message = "Not Found Distribution Set or meta data key", response = ExceptionInfo.class))
|
||||
@Transactional
|
||||
public ResponseEntity<MetadataRest> updateMetadata(@PathVariable final Long distributionSetId,
|
||||
@PathVariable final String metadataKey, @RequestBody final MetadataRest metadata) {
|
||||
// check if distribution set exists otherwise throw exception
|
||||
@@ -550,7 +469,7 @@ public class DistributionSetResource {
|
||||
|
||||
/**
|
||||
* Deletes a single meta data entry from the distribution set.
|
||||
*
|
||||
*
|
||||
* @param distributionSetId
|
||||
* the ID of the distribution set to delete the meta data entry
|
||||
* @param metadataKey
|
||||
@@ -558,10 +477,6 @@ public class DistributionSetResource {
|
||||
* @return status OK if the delete request is successful
|
||||
*/
|
||||
@RequestMapping(method = RequestMethod.DELETE, value = "/{distributionSetId}/metadata/{metadataKey}")
|
||||
@ApiOperation(value = "Delete a single meta data", notes = " Delete a single meta data." + " Required Permission: "
|
||||
+ SpPermission.UPDATE_REPOSITORY)
|
||||
@ApiResponses(@ApiResponse(code = 404, message = "Not Found Distribution Set or meta data key", response = ExceptionInfo.class))
|
||||
@Transactional
|
||||
public ResponseEntity<Void> deleteMetadata(@PathVariable final Long distributionSetId,
|
||||
@PathVariable final String metadataKey) {
|
||||
// check if distribution set exists otherwise throw exception
|
||||
@@ -573,7 +488,7 @@ public class DistributionSetResource {
|
||||
|
||||
/**
|
||||
* Creates a list of meta data for a specific distribution set.
|
||||
*
|
||||
*
|
||||
* @param distributionSetId
|
||||
* the ID of the distribution set to create meta data for
|
||||
* @param metadataRest
|
||||
@@ -582,13 +497,8 @@ public class DistributionSetResource {
|
||||
* the created meta data
|
||||
*/
|
||||
@RequestMapping(method = RequestMethod.POST, value = "/{distributionSetId}/metadata", consumes = {
|
||||
MediaType.APPLICATION_JSON_VALUE, "application/hal+json" }, produces = { MediaType.APPLICATION_JSON_VALUE,
|
||||
"application/hal+json" })
|
||||
@ApiOperation(response = MetadataRest.class, value = "Create a list of meta data entries", notes = "Create a list of meta data entries"
|
||||
+ " Required Permission: " + SpPermission.READ_REPOSITORY + " and " + SpPermission.UPDATE_TARGET)
|
||||
@ApiResponses({ @ApiResponse(code = 409, message = "Conflict", response = ExceptionInfo.class),
|
||||
@ApiResponse(code = 404, message = "Not Found Distribution Set", response = ExceptionInfo.class) })
|
||||
@Transactional
|
||||
MediaType.APPLICATION_JSON_VALUE,
|
||||
"application/hal+json" }, produces = { MediaType.APPLICATION_JSON_VALUE, "application/hal+json" })
|
||||
public ResponseEntity<List<MetadataRest>> createMetadata(@PathVariable final Long distributionSetId,
|
||||
@RequestBody final List<MetadataRest> metadataRest) {
|
||||
// check if distribution set exists otherwise throw exception
|
||||
@@ -597,44 +507,33 @@ public class DistributionSetResource {
|
||||
|
||||
final List<DistributionSetMetadata> created = distributionSetManagement
|
||||
.createDistributionSetMetadata(DistributionSetMapper.fromRequestDsMetadata(ds, metadataRest));
|
||||
|
||||
// we flush to ensure that entity is generated and we can return ID etc.
|
||||
entityManager.flush();
|
||||
|
||||
return new ResponseEntity<List<MetadataRest>>(DistributionSetMapper.toResponseDsMetadata(created),
|
||||
HttpStatus.CREATED);
|
||||
return new ResponseEntity<>(DistributionSetMapper.toResponseDsMetadata(created), HttpStatus.CREATED);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Assigns a list of software modules to a distribution set.
|
||||
*
|
||||
*
|
||||
* @param distributionSetId
|
||||
* the ID of the distribution set to assign software modules for
|
||||
* @param softwareModuleIDs
|
||||
* the list of software modules ids to assign
|
||||
* @return {@link HttpStatus#OK}
|
||||
*
|
||||
*
|
||||
* @throws EntityNotFoundException
|
||||
* in case no distribution set with the given
|
||||
* {@code distributionSetId} exists.
|
||||
*/
|
||||
@RequestMapping(method = RequestMethod.POST, value = "/{distributionSetId}/assignedSM", consumes = {
|
||||
MediaType.APPLICATION_JSON_VALUE, "application/hal+json" }, produces = { "application/hal+json",
|
||||
MediaType.APPLICATION_JSON_VALUE })
|
||||
@ApiOperation(response = SoftwareModuleRest.class, value = "Assign Software Modules to Distribution Set", notes = "Handles the POST request for assigning multiple software modules to a distribution set.The request body must always be a list of software module IDs."
|
||||
+ " Required Permission: " + SpPermission.READ_REPOSITORY + " and " + SpPermission.UPDATE_REPOSITORY)
|
||||
@ApiResponses({
|
||||
@ApiResponse(code = 423, message = "In use of Distribution Set by Target", response = ExceptionInfo.class),
|
||||
@ApiResponse(code = 404, message = "Not Found Distribution Set key or Software Module IDs", response = ExceptionInfo.class) })
|
||||
@Transactional
|
||||
MediaType.APPLICATION_JSON_VALUE,
|
||||
"application/hal+json" }, produces = { "application/hal+json", MediaType.APPLICATION_JSON_VALUE })
|
||||
public ResponseEntity<Void> assignSoftwareModules(@PathVariable final Long distributionSetId,
|
||||
@RequestBody final List<SoftwareModuleAssigmentRest> softwareModuleIDs) {
|
||||
// check if distribution set exists otherwise throw exception
|
||||
// immediately
|
||||
final DistributionSet ds = findDistributionSetWithExceptionIfNotFound(distributionSetId);
|
||||
|
||||
final Set<SoftwareModule> softwareModuleToBeAssigned = new HashSet<SoftwareModule>();
|
||||
final Set<SoftwareModule> softwareModuleToBeAssigned = new HashSet<>();
|
||||
for (final SoftwareModuleAssigmentRest sm : softwareModuleIDs) {
|
||||
final SoftwareModule softwareModule = softwareManagement.findSoftwareModuleById(sm.getId());
|
||||
if (softwareModule != null) {
|
||||
@@ -650,7 +549,7 @@ public class DistributionSetResource {
|
||||
|
||||
/**
|
||||
* Deletes the assignment of the software module form the distribution set.
|
||||
*
|
||||
*
|
||||
* @param distributionSetId
|
||||
* the ID of the distribution set to reject the software module
|
||||
* for
|
||||
@@ -663,12 +562,6 @@ public class DistributionSetResource {
|
||||
* {@code distributionSetId} exists.
|
||||
*/
|
||||
@RequestMapping(method = RequestMethod.DELETE, value = "/{distributionSetId}/assignedSM/{softwareModuleId}")
|
||||
@ApiOperation(value = "Delete assignment of Software Module", notes = " Delete a assignment."
|
||||
+ " Required Permission: " + SpPermission.UPDATE_REPOSITORY)
|
||||
@ApiResponses({
|
||||
@ApiResponse(code = 423, message = "In use of Distribution Set by Target", response = ExceptionInfo.class),
|
||||
@ApiResponse(code = 404, message = "Not Found Distribution Set key or Software Module key", response = ExceptionInfo.class) })
|
||||
@Transactional
|
||||
public ResponseEntity<Void> deleteAssignSoftwareModules(@PathVariable final Long distributionSetId,
|
||||
@PathVariable final Long softwareModuleId) {
|
||||
// check if distribution set and software module exist otherwise throw
|
||||
@@ -682,7 +575,7 @@ public class DistributionSetResource {
|
||||
/**
|
||||
* Handles the GET request for retrieving the assigned software modules of a
|
||||
* specific distribution set.
|
||||
*
|
||||
*
|
||||
* @param distributionSetId
|
||||
* the ID of the distribution to retrieve
|
||||
* @param pagingOffsetParam
|
||||
@@ -702,8 +595,6 @@ public class DistributionSetResource {
|
||||
*/
|
||||
@RequestMapping(method = RequestMethod.GET, value = "/{distributionSetId}/assignedSM", produces = {
|
||||
"application/hal+json", MediaType.APPLICATION_JSON_VALUE })
|
||||
@ApiOperation(response = SoftwareModuleRest.class, value = "Get assigned Software Modules", notes = "Handles the GET request of retrieving a single distribution set within SP. Required Permission: "
|
||||
+ SpPermission.READ_REPOSITORY)
|
||||
public ResponseEntity<SoftwareModulePagedList> getAssignedSoftwareModules(
|
||||
@PathVariable final Long distributionSetId,
|
||||
@RequestParam(value = RestConstants.REQUEST_PARAMETER_PAGING_OFFSET, defaultValue = RestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET) final int pagingOffsetParam,
|
||||
@@ -718,8 +609,10 @@ public class DistributionSetResource {
|
||||
final Pageable pageable = new OffsetBasedPageRequest(sanitizedOffsetParam, sanitizedLimitParam, sorting);
|
||||
final Page<SoftwareModule> softwaremodules = softwareManagement.findSoftwareModuleByAssignedTo(pageable,
|
||||
foundDs);
|
||||
return new ResponseEntity<>(new SoftwareModulePagedList(SoftwareModuleMapper.toResponse(softwaremodules
|
||||
.getContent()), softwaremodules.getTotalElements()), HttpStatus.OK);
|
||||
return new ResponseEntity<>(
|
||||
new SoftwareModulePagedList(SoftwareModuleMapper.toResponse(softwaremodules.getContent()),
|
||||
softwaremodules.getTotalElements()),
|
||||
HttpStatus.OK);
|
||||
}
|
||||
|
||||
private DistributionSet findDistributionSetWithExceptionIfNotFound(final Long distributionSetId) {
|
||||
|
||||
@@ -0,0 +1,351 @@
|
||||
/**
|
||||
* Copyright (c) 2015 Bosch Software Innovations GmbH and others.
|
||||
*
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*/
|
||||
package org.eclipse.hawkbit.rest.resource;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
|
||||
import org.eclipse.hawkbit.repository.DistributionSetManagement;
|
||||
import org.eclipse.hawkbit.repository.TagFields;
|
||||
import org.eclipse.hawkbit.repository.TagManagement;
|
||||
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSet;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSetTag;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSetTagAssigmentResult;
|
||||
import org.eclipse.hawkbit.repository.rsql.RSQLUtility;
|
||||
import org.eclipse.hawkbit.rest.resource.model.distributionset.DistributionSetsRest;
|
||||
import org.eclipse.hawkbit.rest.resource.model.tag.AssignedDistributionSetRequestBody;
|
||||
import org.eclipse.hawkbit.rest.resource.model.tag.DistributionSetTagAssigmentResultRest;
|
||||
import org.eclipse.hawkbit.rest.resource.model.tag.TagPagedList;
|
||||
import org.eclipse.hawkbit.rest.resource.model.tag.TagRequestBodyPut;
|
||||
import org.eclipse.hawkbit.rest.resource.model.tag.TagRest;
|
||||
import org.eclipse.hawkbit.rest.resource.model.tag.TagsRest;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.domain.Slice;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* REST Resource handling for {@link DistributionSetTag} CRUD operations.
|
||||
*
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping(RestConstants.DISTRIBUTIONSET_TAG_V1_REQUEST_MAPPING)
|
||||
public class DistributionSetTagResource {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(DistributionSetTagResource.class);
|
||||
|
||||
@Autowired
|
||||
private TagManagement tagManagement;
|
||||
|
||||
@Autowired
|
||||
private DistributionSetManagement distributionSetManagement;
|
||||
|
||||
@Autowired
|
||||
private EntityManager entityManager;
|
||||
|
||||
/**
|
||||
* Handles the GET request of retrieving all DistributionSet tags.
|
||||
*
|
||||
* @param pagingOffsetParam
|
||||
* the offset of list of DistributionSet tags for pagination,
|
||||
* might not be present in the rest request then default value
|
||||
* will be applied
|
||||
* @param pagingLimitParam
|
||||
* the limit of the paged request, might not be present in the
|
||||
* rest request then default value will be applied
|
||||
* @param sortParam
|
||||
* the sorting parameter in the request URL, syntax
|
||||
* {@code field:direction, field:direction}
|
||||
* @param rsqlParam
|
||||
* the search parameter in the request URL, syntax
|
||||
* {@code q=name==abc}
|
||||
* @return a list of all target tags for a defined or default page request
|
||||
* with status OK. The response is always paged. In any failure the
|
||||
* JsonResponseExceptionHandler is handling the response.
|
||||
*/
|
||||
@RequestMapping(method = RequestMethod.GET, produces = { "application/hal+json", MediaType.APPLICATION_JSON_VALUE })
|
||||
public ResponseEntity<TagPagedList> getDistributionSetTags(
|
||||
@RequestParam(value = RestConstants.REQUEST_PARAMETER_PAGING_OFFSET, defaultValue = RestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET) final int pagingOffsetParam,
|
||||
@RequestParam(value = RestConstants.REQUEST_PARAMETER_PAGING_LIMIT, defaultValue = RestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT) final int pagingLimitParam,
|
||||
@RequestParam(value = RestConstants.REQUEST_PARAMETER_SORTING, required = false) final String sortParam,
|
||||
@RequestParam(value = RestConstants.REQUEST_PARAMETER_SEARCH, required = false) final String rsqlParam) {
|
||||
|
||||
final int sanitizedOffsetParam = PagingUtility.sanitizeOffsetParam(pagingOffsetParam);
|
||||
final int sanitizedLimitParam = PagingUtility.sanitizePageLimitParam(pagingLimitParam);
|
||||
final Sort sorting = PagingUtility.sanitizeTargetSortParam(sortParam);
|
||||
|
||||
final Pageable pageable = new OffsetBasedPageRequest(sanitizedOffsetParam, sanitizedLimitParam, sorting);
|
||||
final Slice<DistributionSetTag> findTargetsAll;
|
||||
final Long countTargetsAll;
|
||||
if (rsqlParam == null) {
|
||||
findTargetsAll = tagManagement.findAllDistributionSetTags(pageable);
|
||||
countTargetsAll = tagManagement.countTargetTags();
|
||||
|
||||
} else {
|
||||
final Page<DistributionSetTag> findTargetPage = tagManagement.findAllDistributionSetTags(
|
||||
RSQLUtility.parse(rsqlParam, TagFields.class, entityManager), pageable);
|
||||
countTargetsAll = findTargetPage.getTotalElements();
|
||||
findTargetsAll = findTargetPage;
|
||||
|
||||
}
|
||||
|
||||
final List<TagRest> rest = TagMapper.toResponseDistributionSetTag(findTargetsAll.getContent());
|
||||
return new ResponseEntity<>(new TagPagedList(rest, countTargetsAll), HttpStatus.OK);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the GET request of retrieving a single distribution set tag.
|
||||
*
|
||||
* @param distributionsetTagId
|
||||
* the ID of the distribution set tag to retrieve
|
||||
*
|
||||
* @return a single distribution set tag with status OK.
|
||||
* @throws EntityNotFoundException
|
||||
* in case the given {@code distributionsetTagId} doesn't
|
||||
* exists.
|
||||
*/
|
||||
@RequestMapping(method = RequestMethod.GET, value = "/{distributionsetTagId}", produces = { "application/hal+json",
|
||||
MediaType.APPLICATION_JSON_VALUE })
|
||||
public ResponseEntity<TagRest> getDistributionSetTag(@PathVariable final Long distributionsetTagId) {
|
||||
final DistributionSetTag tag = findDistributionTagById(distributionsetTagId);
|
||||
return new ResponseEntity<>(TagMapper.toResponse(tag), HttpStatus.OK);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the POST request of creating new distribution set tag. The
|
||||
* request body must always be a list of tags.
|
||||
*
|
||||
* @param tags
|
||||
* the distribution set tags to be created.
|
||||
* @return In case all modules could successful created the ResponseEntity
|
||||
* with status code 201 - Created. The Response Body are the created
|
||||
* distribution set tags but without ResponseBody.
|
||||
*/
|
||||
@RequestMapping(method = RequestMethod.POST, consumes = { "application/hal+json", MediaType.APPLICATION_JSON_VALUE }, produces = {
|
||||
"application/hal+json", MediaType.APPLICATION_JSON_VALUE })
|
||||
public ResponseEntity<TagsRest> createDistributionSetTags(@RequestBody final List<TagRequestBodyPut> tags) {
|
||||
LOG.debug("creating {} ds tags", tags.size());
|
||||
|
||||
final List<DistributionSetTag> createdTags = tagManagement.createDistributionSetTags(TagMapper
|
||||
.mapDistributionSetTagFromRequest(tags));
|
||||
|
||||
return new ResponseEntity<>(TagMapper.toResponseDistributionSetTag(createdTags), HttpStatus.CREATED);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Handles the PUT request of updating a single distribution set tag.
|
||||
*
|
||||
* @param distributionsetTagId
|
||||
* the ID of the distribution set tag
|
||||
* @param restDSTagRest
|
||||
* the the request body to be updated
|
||||
* @return status OK if update is successful and the updated distribution
|
||||
* set tag.
|
||||
* @throws EntityNotFoundException
|
||||
* in case the given {@code distributionsetTagId} doesn't
|
||||
* exists.
|
||||
*/
|
||||
@RequestMapping(method = RequestMethod.PUT, value = "/{distributionsetTagId}", consumes = { "application/hal+json",
|
||||
MediaType.APPLICATION_JSON_VALUE }, produces = { "application/hal+json", MediaType.APPLICATION_JSON_VALUE })
|
||||
public ResponseEntity<TagRest> updateDistributionSetTag(@PathVariable final Long distributionsetTagId,
|
||||
@RequestBody final TagRequestBodyPut restDSTagRest) {
|
||||
LOG.debug("update {} ds tag", restDSTagRest);
|
||||
|
||||
final DistributionSetTag distributionSetTag = findDistributionTagById(distributionsetTagId);
|
||||
TagMapper.updateTag(restDSTagRest, distributionSetTag);
|
||||
final DistributionSetTag updateDistributionSetTag = tagManagement.updateDistributionSetTag(distributionSetTag);
|
||||
|
||||
LOG.debug("ds tag updated");
|
||||
|
||||
return new ResponseEntity<>(TagMapper.toResponse(updateDistributionSetTag), HttpStatus.OK);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the DELETE request for a single distribution set tag.
|
||||
*
|
||||
* @param distributionsetTagId
|
||||
* the ID of the distribution set tag
|
||||
* @return status OK if delete as successfully.
|
||||
* @throws EntityNotFoundException
|
||||
* in case the given {@code distributionsetTagId} doesn't
|
||||
* exists.
|
||||
*
|
||||
*/
|
||||
@RequestMapping(method = RequestMethod.DELETE, value = "/{distributionsetTagId}")
|
||||
public ResponseEntity<Void> deleteDistributionSetTag(@PathVariable final Long distributionsetTagId) {
|
||||
LOG.debug("Delete {} distribution set tag", distributionsetTagId);
|
||||
final DistributionSetTag tag = findDistributionTagById(distributionsetTagId);
|
||||
|
||||
tagManagement.deleteDistributionSetTag(tag.getName());
|
||||
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the GET request of retrieving all assigned distribution sets by
|
||||
* the given tag id.
|
||||
*
|
||||
* @param distributionsetTagId
|
||||
* the ID of the distribution set tag
|
||||
*
|
||||
* @return the list of assigned distribution sets.
|
||||
* @throws EntityNotFoundException
|
||||
* in case the given {@code distributionsetTagId} doesn't
|
||||
* exists.
|
||||
*/
|
||||
@RequestMapping(method = RequestMethod.GET, value = RestConstants.DISTRIBUTIONSET_REQUEST_MAPPING)
|
||||
public ResponseEntity<DistributionSetsRest> getAssignedDistributionSets(
|
||||
@PathVariable final Long distributionsetTagId) {
|
||||
final DistributionSetTag tag = findDistributionTagById(distributionsetTagId);
|
||||
return new ResponseEntity<>(
|
||||
DistributionSetMapper.toResponseDistributionSets(tag.getAssignedToDistributionSet()), HttpStatus.OK);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the POST request to toggle the assignment of distribution sets by
|
||||
* the given tag id.
|
||||
*
|
||||
* @param distributionsetTagIds
|
||||
* the ID of the distribution set tag to retrieve
|
||||
* @param assignedDSRequestBodies
|
||||
* list of distribution set ids to be toggled
|
||||
*
|
||||
* @return the list of assigned distribution sets and unassigned
|
||||
* distribution sets.
|
||||
* @throws EntityNotFoundException
|
||||
* in case the given {@code distributionsetTagId} doesn't
|
||||
* exists.
|
||||
*/
|
||||
@RequestMapping(method = RequestMethod.POST, value = RestConstants.DISTRIBUTIONSET_REQUEST_MAPPING
|
||||
+ "/toggleTagAssignment")
|
||||
public ResponseEntity<DistributionSetTagAssigmentResultRest> toggleTagAssignment(
|
||||
@PathVariable final Long distributionsetTagId,
|
||||
@RequestBody final List<AssignedDistributionSetRequestBody> assignedDSRequestBodies) {
|
||||
LOG.debug("Toggle distribution set assignment {} for ds tag {}", assignedDSRequestBodies.size(),
|
||||
distributionsetTagId);
|
||||
|
||||
final DistributionSetTag tag = findDistributionTagById(distributionsetTagId);
|
||||
|
||||
final DistributionSetTagAssigmentResult assigmentResult = distributionSetManagement.toggleTagAssignment(
|
||||
findDistributionSetIds(assignedDSRequestBodies), tag.getName());
|
||||
|
||||
final DistributionSetTagAssigmentResultRest tagAssigmentResultRest = new DistributionSetTagAssigmentResultRest();
|
||||
tagAssigmentResultRest.setAssignedDistributionSets(DistributionSetMapper
|
||||
.toResponseDistributionSets(assigmentResult.getAssignedDs()));
|
||||
tagAssigmentResultRest.setUnassignedDistributionSets(DistributionSetMapper
|
||||
.toResponseDistributionSets(assigmentResult.getUnassignedDs()));
|
||||
|
||||
LOG.debug("Toggled assignedDS {} and unassignedDS{}", assigmentResult.getAssigned(),
|
||||
assigmentResult.getUnassigned());
|
||||
|
||||
return new ResponseEntity<>(tagAssigmentResultRest, HttpStatus.OK);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the POST request to assign distribution sets to the given tag id.
|
||||
*
|
||||
* @param distributionsetTagId
|
||||
* the ID of the distribution set tag to retrieve
|
||||
* @param assignedDSRequestBodies
|
||||
* list of distribution sets ids to be assigned
|
||||
*
|
||||
* @return the list of assigned distribution set.
|
||||
* @throws EntityNotFoundException
|
||||
* in case the given {@code distributionsetTagId} doesn't
|
||||
* exists.
|
||||
*/
|
||||
@RequestMapping(method = RequestMethod.POST, value = RestConstants.DISTRIBUTIONSET_REQUEST_MAPPING)
|
||||
public ResponseEntity<DistributionSetsRest> assignDistributionSets(@PathVariable final Long distributionsetTagId,
|
||||
@RequestBody final List<AssignedDistributionSetRequestBody> assignedDSRequestBodies) {
|
||||
LOG.debug("Assign DistributionSet {} for ds tag {}", assignedDSRequestBodies.size(), distributionsetTagId);
|
||||
final DistributionSetTag tag = findDistributionTagById(distributionsetTagId);
|
||||
|
||||
final List<DistributionSet> assignedDs = distributionSetManagement.assignTag(
|
||||
findDistributionSetIds(assignedDSRequestBodies), tag);
|
||||
LOG.debug("Assignd DistributionSet {}", assignedDs.size());
|
||||
return new ResponseEntity<>(DistributionSetMapper.toResponseDistributionSets(assignedDs), HttpStatus.OK);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the DELETE request to unassign all distribution set from the
|
||||
* given tag id.
|
||||
*
|
||||
* @param distributionsetTagId
|
||||
* the ID of the distribution set tag to retrieve
|
||||
* @return http status code
|
||||
* @throws EntityNotFoundException
|
||||
* in case the given {@code distributionsetTagId} doesn't
|
||||
* exists.
|
||||
*/
|
||||
@RequestMapping(method = RequestMethod.DELETE, value = RestConstants.DISTRIBUTIONSET_REQUEST_MAPPING)
|
||||
public ResponseEntity<Void> unassignDistributionSets(@PathVariable final Long distributionsetTagId) {
|
||||
LOG.debug("Unassign all DS for ds tag {}", distributionsetTagId);
|
||||
final DistributionSetTag tag = findDistributionTagById(distributionsetTagId);
|
||||
if (tag.getAssignedToDistributionSet() == null) {
|
||||
LOG.debug("No assigned ds founded");
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
|
||||
final List<DistributionSet> distributionSets = distributionSetManagement.unAssignAllDistributionSetsByTag(tag);
|
||||
LOG.debug("Unassigned ds {}", distributionSets.size());
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the DELETE request to unassign one distribution set from the
|
||||
* given tag id.
|
||||
*
|
||||
* @param distributionsetTagId
|
||||
* the ID of the distribution set tag
|
||||
* @param distributionsetId
|
||||
* the ID of the distribution set to unassign
|
||||
* @return http status code
|
||||
* @throws EntityNotFoundException
|
||||
* in case the given {@code distributionsetTagId} doesn't
|
||||
* exists.
|
||||
*/
|
||||
@RequestMapping(method = RequestMethod.DELETE, value = RestConstants.DISTRIBUTIONSET_REQUEST_MAPPING
|
||||
+ "/{distributionsetId}")
|
||||
public ResponseEntity<Void> unassignDistributionSet(@PathVariable final Long distributionsetTagId,
|
||||
@PathVariable final Long distributionsetId) {
|
||||
LOG.debug("Unassign ds {} for ds tag {}", distributionsetId, distributionsetTagId);
|
||||
final DistributionSetTag tag = findDistributionTagById(distributionsetTagId);
|
||||
distributionSetManagement.unAssignTag(distributionsetId, tag);
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
|
||||
private DistributionSetTag findDistributionTagById(final Long distributionsetTagId) {
|
||||
final DistributionSetTag tag = tagManagement.findDistributionSetTagById(distributionsetTagId);
|
||||
if (tag == null) {
|
||||
throw new EntityNotFoundException("Distribution Tag with Id {" + distributionsetTagId + "} does not exist");
|
||||
}
|
||||
return tag;
|
||||
}
|
||||
|
||||
private List<Long> findDistributionSetIds(
|
||||
final List<AssignedDistributionSetRequestBody> assignedDistributionSetRequestBodies) {
|
||||
return assignedDistributionSetRequestBodies.stream().map(request -> request.getDistributionSetId())
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
8
hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/DistributionSetTypeMapper.java
Executable file → Normal file
8
hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/DistributionSetTypeMapper.java
Executable file → Normal file
@@ -18,7 +18,7 @@ import org.eclipse.hawkbit.repository.SoftwareManagement;
|
||||
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSetType;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModuleType;
|
||||
import org.eclipse.hawkbit.rest.resource.model.distributionsettype.DistributionSetTypeRequestBodyCreate;
|
||||
import org.eclipse.hawkbit.rest.resource.model.distributionsettype.DistributionSetTypeRequestBodyPost;
|
||||
import org.eclipse.hawkbit.rest.resource.model.distributionsettype.DistributionSetTypeRest;
|
||||
import org.eclipse.hawkbit.rest.resource.model.distributionsettype.DistributionSetTypesRest;
|
||||
|
||||
@@ -38,17 +38,17 @@ final class DistributionSetTypeMapper {
|
||||
}
|
||||
|
||||
static List<DistributionSetType> smFromRequest(final SoftwareManagement softwareManagement,
|
||||
final Iterable<DistributionSetTypeRequestBodyCreate> smTypesRest) {
|
||||
final Iterable<DistributionSetTypeRequestBodyPost> smTypesRest) {
|
||||
final List<DistributionSetType> mappedList = new ArrayList<>();
|
||||
|
||||
for (final DistributionSetTypeRequestBodyCreate smRest : smTypesRest) {
|
||||
for (final DistributionSetTypeRequestBodyPost smRest : smTypesRest) {
|
||||
mappedList.add(fromRequest(softwareManagement, smRest));
|
||||
}
|
||||
return mappedList;
|
||||
}
|
||||
|
||||
static DistributionSetType fromRequest(final SoftwareManagement softwareManagement,
|
||||
final DistributionSetTypeRequestBodyCreate smsRest) {
|
||||
final DistributionSetTypeRequestBodyPost smsRest) {
|
||||
|
||||
final DistributionSetType result = new DistributionSetType(smsRest.getKey(), smsRest.getName(),
|
||||
smsRest.getDescription());
|
||||
|
||||
181
hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/DistributionSetTypeResource.java
Executable file → Normal file
181
hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/DistributionSetTypeResource.java
Executable file → Normal file
@@ -8,17 +8,10 @@
|
||||
*/
|
||||
package org.eclipse.hawkbit.rest.resource;
|
||||
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.annotations.ApiParam;
|
||||
import io.swagger.annotations.ApiResponse;
|
||||
import io.swagger.annotations.ApiResponses;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
|
||||
import org.eclipse.hawkbit.im.authentication.SpPermission;
|
||||
import org.eclipse.hawkbit.repository.DistributionSetManagement;
|
||||
import org.eclipse.hawkbit.repository.DistributionSetTypeFields;
|
||||
import org.eclipse.hawkbit.repository.SoftwareManagement;
|
||||
@@ -28,12 +21,10 @@ import org.eclipse.hawkbit.repository.model.DistributionSetType;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModule;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModuleType;
|
||||
import org.eclipse.hawkbit.repository.rsql.RSQLUtility;
|
||||
import org.eclipse.hawkbit.rest.resource.model.ExceptionInfo;
|
||||
import org.eclipse.hawkbit.rest.resource.model.IdRest;
|
||||
import org.eclipse.hawkbit.rest.resource.model.action.ActionPagedList;
|
||||
import org.eclipse.hawkbit.rest.resource.model.distributionsettype.DistributionSetTypePagedList;
|
||||
import org.eclipse.hawkbit.rest.resource.model.distributionsettype.DistributionSetTypeRequestBodyCreate;
|
||||
import org.eclipse.hawkbit.rest.resource.model.distributionsettype.DistributionSetTypeRequestBodyUpdate;
|
||||
import org.eclipse.hawkbit.rest.resource.model.distributionsettype.DistributionSetTypeRequestBodyPost;
|
||||
import org.eclipse.hawkbit.rest.resource.model.distributionsettype.DistributionSetTypeRequestBodyPut;
|
||||
import org.eclipse.hawkbit.rest.resource.model.distributionsettype.DistributionSetTypeRest;
|
||||
import org.eclipse.hawkbit.rest.resource.model.distributionsettype.DistributionSetTypesRest;
|
||||
import org.eclipse.hawkbit.rest.resource.model.softwaremoduletype.SoftwareModuleTypeRest;
|
||||
@@ -46,7 +37,6 @@ import org.springframework.data.domain.Sort;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
@@ -63,9 +53,7 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
*
|
||||
*/
|
||||
@RestController
|
||||
@Transactional(readOnly = true)
|
||||
@RequestMapping(RestConstants.DISTRIBUTIONSETTYPE_V1_REQUEST_MAPPING)
|
||||
@Api(value = "distributionsettypes", description = "Distribution Set Types Management API")
|
||||
public class DistributionSetTypeResource {
|
||||
|
||||
@Autowired
|
||||
@@ -100,17 +88,12 @@ public class DistributionSetTypeResource {
|
||||
* handling the response.
|
||||
*/
|
||||
@RequestMapping(method = RequestMethod.GET, produces = { "application/hal+json", MediaType.APPLICATION_JSON_VALUE })
|
||||
@ApiOperation(response = DistributionSetTypePagedList.class, value = "Get distribution det types", notes = "Handles the GET request of retrieving all distribution set types within SP. Required Permission: "
|
||||
+ SpPermission.READ_REPOSITORY)
|
||||
public ResponseEntity<DistributionSetTypePagedList> getTypes(
|
||||
|
||||
public ResponseEntity<DistributionSetTypePagedList> getDistributionSetTypes(
|
||||
@RequestParam(value = RestConstants.REQUEST_PARAMETER_PAGING_OFFSET, defaultValue = RestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET) final int pagingOffsetParam,
|
||||
@RequestParam(value = RestConstants.REQUEST_PARAMETER_PAGING_LIMIT, defaultValue = RestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT) final int pagingLimitParam,
|
||||
@RequestParam(value = RestConstants.REQUEST_PARAMETER_SORTING, required = false) final String sortParam,
|
||||
@ApiParam(required = false, value = "FIQL syntax search query"
|
||||
+ "<table border=0>"
|
||||
+ "<tr><td>id=1,key=vhicletypex2015</td><td>Distribution Set Types with id 1 or key vhicletypex2015</td></tr>"
|
||||
+ "<tr><td>name=VehicleSeriesA</td><td>Distribution Set Types with name VehicleSeriesA</td></tr>"
|
||||
+ "</table>") @RequestParam(value = RestConstants.REQUEST_PARAMETER_SEARCH, required = false) final String rsqlParam) {
|
||||
@RequestParam(value = RestConstants.REQUEST_PARAMETER_SEARCH, required = false) final String rsqlParam) {
|
||||
|
||||
final int sanitizedOffsetParam = PagingUtility.sanitizeOffsetParam(pagingOffsetParam);
|
||||
final int sanitizedLimitParam = PagingUtility.sanitizePageLimitParam(pagingLimitParam);
|
||||
@@ -129,8 +112,8 @@ public class DistributionSetTypeResource {
|
||||
countModulesAll = distributionSetManagement.countDistributionSetTypesAll();
|
||||
}
|
||||
|
||||
final List<DistributionSetTypeRest> rest = DistributionSetTypeMapper.toListResponse(findModuleTypessAll
|
||||
.getContent());
|
||||
final List<DistributionSetTypeRest> rest = DistributionSetTypeMapper
|
||||
.toListResponse(findModuleTypessAll.getContent());
|
||||
return new ResponseEntity<>(new DistributionSetTypePagedList(rest, countModulesAll), HttpStatus.OK);
|
||||
}
|
||||
|
||||
@@ -145,12 +128,10 @@ public class DistributionSetTypeResource {
|
||||
* @throws EntityNotFoundException
|
||||
* in case no with the given {@code softwareModuleId} exists.
|
||||
*/
|
||||
@RequestMapping(method = RequestMethod.GET, value = "/{distributionSetTypeId}", produces = {
|
||||
"application/hal+json", MediaType.APPLICATION_JSON_VALUE })
|
||||
@ApiOperation(response = DistributionSetTypeRest.class, value = "Get distribution set type", notes = "Handles the GET request of retrieving a single distribution set type within SP. Required Permission: "
|
||||
+ SpPermission.READ_REPOSITORY)
|
||||
@ApiResponses(@ApiResponse(code = 404, message = "Not found distribution set type", response = ExceptionInfo.class))
|
||||
public ResponseEntity<DistributionSetTypeRest> getDistributionSetType(@PathVariable final Long distributionSetTypeId) {
|
||||
@RequestMapping(method = RequestMethod.GET, value = "/{distributionSetTypeId}", produces = { "application/hal+json",
|
||||
MediaType.APPLICATION_JSON_VALUE })
|
||||
public ResponseEntity<DistributionSetTypeRest> getDistributionSetType(
|
||||
@PathVariable final Long distributionSetTypeId) {
|
||||
final DistributionSetType foundType = findDistributionSetTypeWithExceptionIfNotFound(distributionSetTypeId);
|
||||
|
||||
return new ResponseEntity<>(DistributionSetTypeMapper.toResponse(foundType), HttpStatus.OK);
|
||||
@@ -165,10 +146,6 @@ public class DistributionSetTypeResource {
|
||||
*
|
||||
*/
|
||||
@RequestMapping(method = RequestMethod.DELETE, value = "/{distributionSetTypeId}")
|
||||
@ApiOperation(value = "Delete distribution set type", notes = "Handles the DELETE request for a single distribution set type within SP. Required Permission: "
|
||||
+ SpPermission.DELETE_REPOSITORY)
|
||||
@ApiResponses(@ApiResponse(code = 404, message = "Not found distribution set type", response = ExceptionInfo.class))
|
||||
@Transactional
|
||||
public ResponseEntity<Void> deleteDistributionSetType(@PathVariable final Long distributionSetTypeId) {
|
||||
final DistributionSetType module = findDistributionSetTypeWithExceptionIfNotFound(distributionSetTypeId);
|
||||
|
||||
@@ -186,16 +163,11 @@ public class DistributionSetTypeResource {
|
||||
* the module type to be updated.
|
||||
* @return status OK if update is successful
|
||||
*/
|
||||
@RequestMapping(method = RequestMethod.PUT, value = "/{distributionSetTypeId}", consumes = {
|
||||
"application/hal+json", MediaType.APPLICATION_JSON_VALUE }, produces = { "application/hal+json",
|
||||
MediaType.APPLICATION_JSON_VALUE })
|
||||
@ApiOperation(value = "Update distribution set type", notes = "Handles the PUT request for a single distribution set type within SP. Required Permission: "
|
||||
+ SpPermission.UPDATE_REPOSITORY)
|
||||
@ApiResponses(@ApiResponse(code = 404, message = "Not Found distribution set type", response = ExceptionInfo.class))
|
||||
@Transactional
|
||||
@RequestMapping(method = RequestMethod.PUT, value = "/{distributionSetTypeId}", consumes = { "application/hal+json",
|
||||
MediaType.APPLICATION_JSON_VALUE }, produces = { "application/hal+json", MediaType.APPLICATION_JSON_VALUE })
|
||||
public ResponseEntity<DistributionSetTypeRest> updateDistributionSetType(
|
||||
@PathVariable final Long distributionSetTypeId,
|
||||
@RequestBody final DistributionSetTypeRequestBodyUpdate restDistributionSetType) {
|
||||
@RequestBody final DistributionSetTypeRequestBodyPut restDistributionSetType) {
|
||||
final DistributionSetType type = findDistributionSetTypeWithExceptionIfNotFound(distributionSetTypeId);
|
||||
|
||||
// only description can be modified
|
||||
@@ -206,9 +178,6 @@ public class DistributionSetTypeResource {
|
||||
final DistributionSetType updatedDistributionSetType = distributionSetManagement
|
||||
.updateDistributionSetType(type);
|
||||
|
||||
// we flush to ensure that entity is generated and we can return ID etc.
|
||||
entityManager.flush();
|
||||
|
||||
return new ResponseEntity<>(DistributionSetTypeMapper.toResponse(updatedDistributionSetType), HttpStatus.OK);
|
||||
}
|
||||
|
||||
@@ -223,23 +192,13 @@ public class DistributionSetTypeResource {
|
||||
* failure the JsonResponseExceptionHandler is handling the
|
||||
* response.
|
||||
*/
|
||||
@RequestMapping(method = RequestMethod.POST, consumes = { "application/hal+json", MediaType.APPLICATION_JSON_VALUE }, produces = {
|
||||
"application/hal+json", MediaType.APPLICATION_JSON_VALUE })
|
||||
@ApiOperation(response = DistributionSetTypesRest.class, value = "Create distribution set types", notes = "Handles the POST request for creating new distribution set types within SP. The request body must always be a list of types. Required Permission: "
|
||||
+ SpPermission.CREATE_REPOSITORY)
|
||||
@ApiResponses({
|
||||
@ApiResponse(code = 404, message = "Not Found Distribution Set Type", response = ExceptionInfo.class),
|
||||
@ApiResponse(code = 409, message = "Conflict Distribution Set Type already exists", response = ExceptionInfo.class) })
|
||||
@Transactional
|
||||
@RequestMapping(method = RequestMethod.POST, consumes = { "application/hal+json",
|
||||
MediaType.APPLICATION_JSON_VALUE }, produces = { "application/hal+json", MediaType.APPLICATION_JSON_VALUE })
|
||||
public ResponseEntity<DistributionSetTypesRest> createDistributionSetTypes(
|
||||
@RequestBody final List<DistributionSetTypeRequestBodyCreate> distributionSetTypes) {
|
||||
@RequestBody final List<DistributionSetTypeRequestBodyPost> distributionSetTypes) {
|
||||
|
||||
final List<DistributionSetType> createdSoftwareModules = distributionSetManagement
|
||||
.createDistributionSetTypes(DistributionSetTypeMapper.smFromRequest(softwareManagement,
|
||||
distributionSetTypes));
|
||||
|
||||
// we flush to ensure that entity is generated and we can return ID etc.
|
||||
entityManager.flush();
|
||||
final List<DistributionSetType> createdSoftwareModules = distributionSetManagement.createDistributionSetTypes(
|
||||
DistributionSetTypeMapper.smFromRequest(softwareManagement, distributionSetTypes));
|
||||
|
||||
return new ResponseEntity<>(DistributionSetTypeMapper.toTypesResponse(createdSoftwareModules),
|
||||
HttpStatus.CREATED);
|
||||
@@ -248,8 +207,8 @@ public class DistributionSetTypeResource {
|
||||
private DistributionSetType findDistributionSetTypeWithExceptionIfNotFound(final Long distributionSetTypeId) {
|
||||
final DistributionSetType module = distributionSetManagement.findDistributionSetTypeById(distributionSetTypeId);
|
||||
if (module == null) {
|
||||
throw new EntityNotFoundException("DistributionSetType with Id {" + distributionSetTypeId
|
||||
+ "} does not exist");
|
||||
throw new EntityNotFoundException(
|
||||
"DistributionSetType with Id {" + distributionSetTypeId + "} does not exist");
|
||||
}
|
||||
return module;
|
||||
}
|
||||
@@ -264,10 +223,7 @@ public class DistributionSetTypeResource {
|
||||
*/
|
||||
@RequestMapping(method = RequestMethod.GET, value = "/{distributionSetTypeId}/"
|
||||
+ RestConstants.DISTRIBUTIONSETTYPE_V1_MANDATORY_MODULE_TYPES, produces = { "application/hal+json",
|
||||
MediaType.APPLICATION_JSON_VALUE })
|
||||
@ApiOperation(response = ActionPagedList.class, value = "Lists all mandatory software module types", notes = "Handles the GET request of retrieving the list of mandatory software module types in that distribution set type. Required Permission: "
|
||||
+ SpPermission.READ_REPOSITORY)
|
||||
@ApiResponses(@ApiResponse(code = 404, message = "Not Found distribution set type", response = ExceptionInfo.class))
|
||||
MediaType.APPLICATION_JSON_VALUE })
|
||||
public ResponseEntity<SoftwareModuleTypesRest> getMandatoryModules(@PathVariable final Long distributionSetTypeId) {
|
||||
|
||||
final DistributionSetType foundType = findDistributionSetTypeWithExceptionIfNotFound(distributionSetTypeId);
|
||||
@@ -289,11 +245,8 @@ public class DistributionSetTypeResource {
|
||||
* @return Unpaged list of module types and OK in case of success.
|
||||
*/
|
||||
@RequestMapping(method = RequestMethod.GET, value = "/{distributionSetTypeId}/"
|
||||
+ RestConstants.DISTRIBUTIONSETTYPE_V1_MANDATORY_MODULE_TYPES + "/{softwareModuleTypeId}", produces = {
|
||||
"application/hal+json", MediaType.APPLICATION_JSON_VALUE })
|
||||
@ApiOperation(response = ActionPagedList.class, value = "Retrieve mandatory software module type", notes = " Handles the GET request of retrieving the single mandatory software module type in that distribution set type. Required Permission: "
|
||||
+ SpPermission.READ_REPOSITORY)
|
||||
@ApiResponses(@ApiResponse(code = 404, message = "Not Found distribution set type", response = ExceptionInfo.class))
|
||||
+ RestConstants.DISTRIBUTIONSETTYPE_V1_MANDATORY_MODULE_TYPES
|
||||
+ "/{softwareModuleTypeId}", produces = { "application/hal+json", MediaType.APPLICATION_JSON_VALUE })
|
||||
public ResponseEntity<SoftwareModuleTypeRest> getMandatoryModule(@PathVariable final Long distributionSetTypeId,
|
||||
@PathVariable final Long softwareModuleTypeId) {
|
||||
|
||||
@@ -306,8 +259,7 @@ public class DistributionSetTypeResource {
|
||||
"Software module with given ID is not part of this distribution set type!");
|
||||
}
|
||||
|
||||
return new ResponseEntity<SoftwareModuleTypeRest>(SoftwareModuleTypeMapper.toResponse(foundSmType),
|
||||
HttpStatus.OK);
|
||||
return new ResponseEntity<>(SoftwareModuleTypeMapper.toResponse(foundSmType), HttpStatus.OK);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -321,11 +273,8 @@ public class DistributionSetTypeResource {
|
||||
* @return Unpaged list of module types and OK in case of success.
|
||||
*/
|
||||
@RequestMapping(method = RequestMethod.GET, value = "/{distributionSetTypeId}/"
|
||||
+ RestConstants.DISTRIBUTIONSETTYPE_V1_OPTIONAL_MODULE_TYPES + "/{softwareModuleTypeId}", produces = {
|
||||
"application/hal+json", MediaType.APPLICATION_JSON_VALUE })
|
||||
@ApiOperation(response = ActionPagedList.class, value = "Retrieve optional software module type", notes = " Handles the GET request of retrieving the single optional software module type in that distribution set type. Required Permission: "
|
||||
+ SpPermission.READ_REPOSITORY)
|
||||
@ApiResponses(@ApiResponse(code = 404, message = "Not Found distribution set type", response = ExceptionInfo.class))
|
||||
+ RestConstants.DISTRIBUTIONSETTYPE_V1_OPTIONAL_MODULE_TYPES
|
||||
+ "/{softwareModuleTypeId}", produces = { "application/hal+json", MediaType.APPLICATION_JSON_VALUE })
|
||||
public ResponseEntity<SoftwareModuleTypeRest> getOptionalModule(@PathVariable final Long distributionSetTypeId,
|
||||
@PathVariable final Long softwareModuleTypeId) {
|
||||
|
||||
@@ -338,8 +287,7 @@ public class DistributionSetTypeResource {
|
||||
"Software module with given ID is not part of this distribution set type!");
|
||||
}
|
||||
|
||||
return new ResponseEntity<SoftwareModuleTypeRest>(SoftwareModuleTypeMapper.toResponse(foundSmType),
|
||||
HttpStatus.OK);
|
||||
return new ResponseEntity<>(SoftwareModuleTypeMapper.toResponse(foundSmType), HttpStatus.OK);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -352,10 +300,7 @@ public class DistributionSetTypeResource {
|
||||
*/
|
||||
@RequestMapping(method = RequestMethod.GET, value = "/{distributionSetTypeId}/"
|
||||
+ RestConstants.DISTRIBUTIONSETTYPE_V1_OPTIONAL_MODULE_TYPES, produces = { "application/hal+json",
|
||||
MediaType.APPLICATION_JSON_VALUE })
|
||||
@ApiOperation(response = ActionPagedList.class, value = "Lists all optional software module types", notes = "Handles the GET request of retrieving the list of optional software module types in that distribution set type. Required Permission: "
|
||||
+ SpPermission.READ_REPOSITORY)
|
||||
@ApiResponses(@ApiResponse(code = 404, message = "Not Found distribution set type", response = ExceptionInfo.class))
|
||||
MediaType.APPLICATION_JSON_VALUE })
|
||||
public ResponseEntity<SoftwareModuleTypesRest> getOptionalModules(@PathVariable final Long distributionSetTypeId) {
|
||||
|
||||
final DistributionSetType foundType = findDistributionSetTypeWithExceptionIfNotFound(distributionSetTypeId);
|
||||
@@ -378,18 +323,20 @@ public class DistributionSetTypeResource {
|
||||
* @return OK if the request was successful
|
||||
*/
|
||||
@RequestMapping(method = RequestMethod.DELETE, value = "/{distributionSetTypeId}/"
|
||||
+ RestConstants.DISTRIBUTIONSETTYPE_V1_MANDATORY_MODULE_TYPES + "/{softwareModuleTypeId}", produces = {
|
||||
"application/hal+json", MediaType.APPLICATION_JSON_VALUE })
|
||||
@ApiOperation(response = ActionPagedList.class, value = "Remove mandatory module from distribution set type", notes = "Handles the GET request of retrieving the list of software module types in that distribution set. "
|
||||
+ "Note that a DS type cannot be changed after it has been used by a DS. Required Permission: "
|
||||
+ SpPermission.UPDATE_REPOSITORY + " and " + SpPermission.READ_REPOSITORY)
|
||||
@ApiResponses(@ApiResponse(code = 404, message = "Not Found distribution set type", response = ExceptionInfo.class))
|
||||
@Transactional
|
||||
+ RestConstants.DISTRIBUTIONSETTYPE_V1_MANDATORY_MODULE_TYPES
|
||||
+ "/{softwareModuleTypeId}", produces = { "application/hal+json", MediaType.APPLICATION_JSON_VALUE })
|
||||
public ResponseEntity<Void> removeMandatoryModule(@PathVariable final Long distributionSetTypeId,
|
||||
@PathVariable final Long softwareModuleTypeId) {
|
||||
|
||||
final DistributionSetType foundType = findDistributionSetTypeWithExceptionIfNotFound(distributionSetTypeId);
|
||||
|
||||
final SoftwareModuleType foundSmType = findSoftwareModuleTypeWithExceptionIfNotFound(softwareModuleTypeId);
|
||||
|
||||
if (!foundType.containsMandatoryModuleType(foundSmType)) {
|
||||
throw new EntityNotFoundException(
|
||||
"Software module with given ID is not mandatory part of this distribution set type!");
|
||||
}
|
||||
|
||||
foundType.removeModuleType(softwareModuleTypeId);
|
||||
|
||||
distributionSetManagement.updateDistributionSetType(foundType);
|
||||
@@ -409,16 +356,24 @@ public class DistributionSetTypeResource {
|
||||
* @return OK if the request was successful
|
||||
*/
|
||||
@RequestMapping(method = RequestMethod.DELETE, value = "/{distributionSetTypeId}/"
|
||||
+ RestConstants.DISTRIBUTIONSETTYPE_V1_OPTIONAL_MODULE_TYPES + "/{softwareModuleTypeId}", produces = {
|
||||
"application/hal+json", MediaType.APPLICATION_JSON_VALUE })
|
||||
@ApiOperation(response = ActionPagedList.class, value = "Remove optional module from distribution set type", notes = "Handles DELETE request for removing an optional module from the distribution set type."
|
||||
+ "Note that a DS type cannot be changed after it has been used by a DS. Required Permission: "
|
||||
+ SpPermission.UPDATE_REPOSITORY + " and " + SpPermission.READ_REPOSITORY)
|
||||
@ApiResponses(@ApiResponse(code = 404, message = "Not Found distribution set type", response = ExceptionInfo.class))
|
||||
@Transactional
|
||||
+ RestConstants.DISTRIBUTIONSETTYPE_V1_OPTIONAL_MODULE_TYPES
|
||||
+ "/{softwareModuleTypeId}", produces = { "application/hal+json", MediaType.APPLICATION_JSON_VALUE })
|
||||
public ResponseEntity<Void> removeOptionalModule(@PathVariable final Long distributionSetTypeId,
|
||||
@PathVariable final Long softwareModuleTypeId) {
|
||||
return removeMandatoryModule(distributionSetTypeId, softwareModuleTypeId);
|
||||
final DistributionSetType foundType = findDistributionSetTypeWithExceptionIfNotFound(distributionSetTypeId);
|
||||
|
||||
final SoftwareModuleType foundSmType = findSoftwareModuleTypeWithExceptionIfNotFound(softwareModuleTypeId);
|
||||
|
||||
if (!foundType.containsOptionalModuleType(foundSmType)) {
|
||||
throw new EntityNotFoundException(
|
||||
"Software module with given ID is not optional part of this distribution set type!");
|
||||
}
|
||||
|
||||
foundType.removeModuleType(softwareModuleTypeId);
|
||||
|
||||
distributionSetManagement.updateDistributionSetType(foundType);
|
||||
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -434,14 +389,10 @@ public class DistributionSetTypeResource {
|
||||
*/
|
||||
@RequestMapping(method = RequestMethod.POST, value = "/{distributionSetTypeId}/"
|
||||
+ RestConstants.DISTRIBUTIONSETTYPE_V1_MANDATORY_MODULE_TYPES, consumes = { "application/hal+json",
|
||||
MediaType.APPLICATION_JSON_VALUE }, produces = { "application/hal+json", MediaType.APPLICATION_JSON_VALUE })
|
||||
@ApiOperation(response = Void.class, value = "Add mandatory software module type", notes = "Handles the POST request for adding a mandatory software module type to a distribution set type."
|
||||
+ "Note that a DS type cannot be changed after it has been used by a DS. Required Permission: "
|
||||
+ SpPermission.UPDATE_REPOSITORY + " and " + SpPermission.READ_REPOSITORY)
|
||||
@ApiResponses(@ApiResponse(code = 404, message = "Not Found DS type or SP type", response = ExceptionInfo.class))
|
||||
@Transactional
|
||||
MediaType.APPLICATION_JSON_VALUE }, produces = { "application/hal+json",
|
||||
MediaType.APPLICATION_JSON_VALUE })
|
||||
public ResponseEntity<Void> addMandatoryModule(@PathVariable final Long distributionSetTypeId,
|
||||
@RequestBody @ApiParam(value = "Software module type ID", required = true) final IdRest smtId) {
|
||||
@RequestBody final IdRest smtId) {
|
||||
|
||||
final DistributionSetType foundType = findDistributionSetTypeWithExceptionIfNotFound(distributionSetTypeId);
|
||||
|
||||
@@ -449,6 +400,8 @@ public class DistributionSetTypeResource {
|
||||
|
||||
foundType.addMandatoryModuleType(smType);
|
||||
|
||||
distributionSetManagement.updateDistributionSetType(foundType);
|
||||
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
|
||||
@@ -465,14 +418,10 @@ public class DistributionSetTypeResource {
|
||||
*/
|
||||
@RequestMapping(method = RequestMethod.POST, value = "/{distributionSetTypeId}/"
|
||||
+ RestConstants.DISTRIBUTIONSETTYPE_V1_OPTIONAL_MODULE_TYPES, consumes = { "application/hal+json",
|
||||
MediaType.APPLICATION_JSON_VALUE }, produces = { "application/hal+json", MediaType.APPLICATION_JSON_VALUE })
|
||||
@ApiOperation(response = Void.class, value = "Add optional software module type", notes = "Handles the POST request for adding an optional software module type to a distribution set type."
|
||||
+ "Note that a DS type cannot be changed after it has been used by a DS. Required Permission: "
|
||||
+ SpPermission.UPDATE_REPOSITORY + " and " + SpPermission.READ_REPOSITORY)
|
||||
@ApiResponses(@ApiResponse(code = 404, message = "Not Found DS type or SP type", response = ExceptionInfo.class))
|
||||
@Transactional
|
||||
MediaType.APPLICATION_JSON_VALUE }, produces = { "application/hal+json",
|
||||
MediaType.APPLICATION_JSON_VALUE })
|
||||
public ResponseEntity<Void> addOptionalModule(@PathVariable final Long distributionSetTypeId,
|
||||
@RequestBody @ApiParam(value = "Software module type ID", required = true) final IdRest smtId) {
|
||||
@RequestBody final IdRest smtId) {
|
||||
|
||||
final DistributionSetType foundType = findDistributionSetTypeWithExceptionIfNotFound(distributionSetTypeId);
|
||||
|
||||
@@ -480,6 +429,8 @@ public class DistributionSetTypeResource {
|
||||
|
||||
foundType.addOptionalModuleType(smType);
|
||||
|
||||
distributionSetManagement.updateDistributionSetType(foundType);
|
||||
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
|
||||
}
|
||||
@@ -487,8 +438,8 @@ public class DistributionSetTypeResource {
|
||||
private SoftwareModuleType findSoftwareModuleTypeWithExceptionIfNotFound(final Long softwareModuleTypeId) {
|
||||
final SoftwareModuleType module = softwareManagement.findSoftwareModuleTypeById(softwareModuleTypeId);
|
||||
if (module == null) {
|
||||
throw new EntityNotFoundException("SoftwareModuleType with Id {" + softwareModuleTypeId
|
||||
+ "} does not exist");
|
||||
throw new EntityNotFoundException(
|
||||
"SoftwareModuleType with Id {" + softwareModuleTypeId + "} does not exist");
|
||||
}
|
||||
return module;
|
||||
}
|
||||
|
||||
0
hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/DownloadResource.java
Executable file → Normal file
0
hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/DownloadResource.java
Executable file → Normal file
0
hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/EnableRestResources.java
Executable file → Normal file
0
hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/EnableRestResources.java
Executable file → Normal file
0
hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/MessageNotReadableException.java
Executable file → Normal file
0
hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/MessageNotReadableException.java
Executable file → Normal file
0
hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/OffsetBasedPageRequest.java
Executable file → Normal file
0
hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/OffsetBasedPageRequest.java
Executable file → Normal file
0
hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/PagingUtility.java
Executable file → Normal file
0
hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/PagingUtility.java
Executable file → Normal file
13
hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/ResponseExceptionHandler.java
Executable file → Normal file
13
hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/ResponseExceptionHandler.java
Executable file → Normal file
@@ -8,7 +8,7 @@
|
||||
*/
|
||||
package org.eclipse.hawkbit.rest.resource;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.EnumMap;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
@@ -28,7 +28,7 @@ import org.springframework.web.multipart.MultipartException;
|
||||
|
||||
/**
|
||||
* General controller advice for exception handling.
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
@@ -37,7 +37,7 @@ import org.springframework.web.multipart.MultipartException;
|
||||
public class ResponseExceptionHandler {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(ResponseExceptionHandler.class);
|
||||
private static final Map<SpServerError, HttpStatus> ERROR_TO_HTTP_STATUS = new HashMap<>();
|
||||
private static final Map<SpServerError, HttpStatus> ERROR_TO_HTTP_STATUS = new EnumMap<>(SpServerError.class);
|
||||
private static final HttpStatus DEFAULT_RESPONSE_STATUS = HttpStatus.INTERNAL_SERVER_ERROR;
|
||||
|
||||
static {
|
||||
@@ -58,6 +58,7 @@ public class ResponseExceptionHandler {
|
||||
ERROR_TO_HTTP_STATUS.put(SpServerError.SP_ACTION_STATUS_TO_MANY_ENTRIES, HttpStatus.FORBIDDEN);
|
||||
ERROR_TO_HTTP_STATUS.put(SpServerError.SP_ATTRIBUTES_TO_MANY_ENTRIES, HttpStatus.FORBIDDEN);
|
||||
ERROR_TO_HTTP_STATUS.put(SpServerError.SP_ACTION_NOT_CANCELABLE, HttpStatus.METHOD_NOT_ALLOWED);
|
||||
ERROR_TO_HTTP_STATUS.put(SpServerError.SP_ACTION_NOT_FORCE_QUITABLE, HttpStatus.METHOD_NOT_ALLOWED);
|
||||
ERROR_TO_HTTP_STATUS.put(SpServerError.SP_DS_CREATION_FAILED_MISSING_MODULE, HttpStatus.BAD_REQUEST);
|
||||
ERROR_TO_HTTP_STATUS.put(SpServerError.SP_DS_MODULE_UNSUPPORTED, HttpStatus.BAD_REQUEST);
|
||||
ERROR_TO_HTTP_STATUS.put(SpServerError.SP_DS_TYPE_UNDEFINED, HttpStatus.BAD_REQUEST);
|
||||
@@ -96,7 +97,7 @@ public class ResponseExceptionHandler {
|
||||
} else {
|
||||
responseStatus = DEFAULT_RESPONSE_STATUS;
|
||||
}
|
||||
return new ResponseEntity<ExceptionInfo>(response, responseStatus);
|
||||
return new ResponseEntity<>(response, responseStatus);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -119,7 +120,7 @@ public class ResponseExceptionHandler {
|
||||
response.setErrorCode(SpServerError.SP_REST_BODY_NOT_READABLE.getKey());
|
||||
response.setMessage(SpServerError.SP_REST_BODY_NOT_READABLE.getMessage());
|
||||
response.setExceptionClass(MessageNotReadableException.class.getName());
|
||||
return new ResponseEntity<ExceptionInfo>(response, HttpStatus.BAD_REQUEST);
|
||||
return new ResponseEntity<>(response, HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -151,7 +152,7 @@ public class ResponseExceptionHandler {
|
||||
response.setExceptionClass(MultipartException.class.getName());
|
||||
}
|
||||
|
||||
return new ResponseEntity<ExceptionInfo>(response, HttpStatus.BAD_REQUEST);
|
||||
return new ResponseEntity<>(response, HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
|
||||
private static boolean searchForCause(final Throwable t, final Class<?> lookFor) {
|
||||
|
||||
@@ -1,162 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2015 Bosch Software Innovations GmbH and others.
|
||||
*
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*/
|
||||
package org.eclipse.hawkbit.rest.resource;
|
||||
|
||||
/**
|
||||
* Constants for RESTful API.
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
public final class RestConstants {
|
||||
|
||||
/**
|
||||
* API version definition. We are using only major versions.
|
||||
*/
|
||||
public static final String API_VERSION = "v1";
|
||||
|
||||
/**
|
||||
* The base URL mapping for the spring acuator management context path.
|
||||
*/
|
||||
public static final String BASE_SYSTEM_MAPPING = "/system";
|
||||
|
||||
/**
|
||||
* URL mapping for system admin operations.
|
||||
*/
|
||||
public static final String SYSTEM_ADMIN_MAPPING = BASE_SYSTEM_MAPPING + "/admin";
|
||||
|
||||
/**
|
||||
* The base URL mapping of the SP rest resources.
|
||||
*/
|
||||
public static final String BASE_V1_REQUEST_MAPPING = "/rest/v1";
|
||||
|
||||
/**
|
||||
* The default limit parameter in case the limit parameter is not present in
|
||||
* the request.
|
||||
*
|
||||
* @see #REQUEST_PARAMETER_PAGING_LIMIT
|
||||
*/
|
||||
public static final int REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT_VALUE = 50;
|
||||
|
||||
/**
|
||||
* String representation of
|
||||
* {@link #REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT_VALUE}.
|
||||
*/
|
||||
public static final String REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT = "50";
|
||||
|
||||
/**
|
||||
* The default offset parameter in case the offset parameter is not present
|
||||
* in the request.
|
||||
*
|
||||
* @see #REQUEST_PARAMETER_PAGING_OFFSET
|
||||
*/
|
||||
public static final String REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET = "0";
|
||||
|
||||
/**
|
||||
* Limit http parameter for the limitation of returned values for a paged
|
||||
* request.
|
||||
*/
|
||||
public static final String REQUEST_PARAMETER_PAGING_LIMIT = "limit";
|
||||
/**
|
||||
* The maximum limit of entities returned by rest resources.
|
||||
*/
|
||||
public static final int REQUEST_PARAMETER_PAGING_MAX_LIMIT = 500;
|
||||
|
||||
/**
|
||||
* Paging http parameter for the offset for a paged request.
|
||||
*/
|
||||
public static final String REQUEST_PARAMETER_PAGING_OFFSET = "offset";
|
||||
|
||||
/**
|
||||
* The request parameter for sorting. The value of the sort parameter must
|
||||
* be in the following pattern. Example:
|
||||
* http://www.bosch.com/iap/sp/rest/targets?sort=field_1:ASC,field_2:DESC,
|
||||
* field_3:ASC
|
||||
*/
|
||||
public static final String REQUEST_PARAMETER_SORTING = "sort";
|
||||
|
||||
/**
|
||||
* The request parameter for searching. The value of the search parameter
|
||||
* must be in the FIQL syntax.
|
||||
*/
|
||||
public static final String REQUEST_PARAMETER_SEARCH = "q";
|
||||
|
||||
/**
|
||||
* The target URL mapping, href link for assigned distribution set.
|
||||
*/
|
||||
public static final String TARGET_V1_ASSIGNED_DISTRIBUTION_SET = "assignedDS";
|
||||
/**
|
||||
* The target URL mapping, href link for installed distribution set.
|
||||
*/
|
||||
public static final String TARGET_V1_INSTALLED_DISTRIBUTION_SET = "installedDS";
|
||||
/**
|
||||
* The target URL mapping, href link for target attributes.
|
||||
*/
|
||||
public static final String TARGET_V1_ATTRIBUTES = "attributes";
|
||||
/**
|
||||
* The target URL mapping, href link for target actions.
|
||||
*/
|
||||
public static final String TARGET_V1_ACTIONS = "actions";
|
||||
/**
|
||||
* The target URL mapping, href link for canceled actions.
|
||||
*/
|
||||
public static final String TARGET_V1_CANCELED_ACTION = "canceledaction";
|
||||
/**
|
||||
* The target URL mapping, href link for canceled actions.
|
||||
*/
|
||||
public static final String TARGET_V1_ACTION_STATUS = "status";
|
||||
|
||||
/**
|
||||
* The target URL mapping rest resource.
|
||||
*/
|
||||
public static final String TARGET_V1_REQUEST_MAPPING = BASE_V1_REQUEST_MAPPING + "/targets";
|
||||
/**
|
||||
* The software module URL mapping rest resource.
|
||||
*/
|
||||
public static final String SOFTWAREMODULE_V1_REQUEST_MAPPING = BASE_V1_REQUEST_MAPPING + "/softwaremodules";
|
||||
|
||||
/**
|
||||
* The software module type URL mapping rest resource.
|
||||
*/
|
||||
public static final String SOFTWAREMODULETYPE_V1_REQUEST_MAPPING = BASE_V1_REQUEST_MAPPING + "/softwaremoduletypes";
|
||||
|
||||
public static final String DISTRIBUTIONSETTYPE_V1_REQUEST_MAPPING = BASE_V1_REQUEST_MAPPING
|
||||
+ "/distributionsettypes";
|
||||
|
||||
/**
|
||||
* The software module URL mapping rest resource.
|
||||
*/
|
||||
public static final String DISTRIBUTIONSET_V1_REQUEST_MAPPING = BASE_V1_REQUEST_MAPPING + "/distributionsets";
|
||||
|
||||
/**
|
||||
* The target URL mapping, href link for artifact download.
|
||||
*/
|
||||
public static final String SOFTWAREMODULE_V1_ARTIFACT = "artifacts";
|
||||
|
||||
/**
|
||||
* The target URL mapping, href link for type information.
|
||||
*/
|
||||
public static final String SOFTWAREMODULE_V1_TYPE = "type";
|
||||
|
||||
public static final String DISTRIBUTIONSETTYPE_V1_OPTIONAL_MODULES = "optionalmodules";
|
||||
|
||||
public static final String DISTRIBUTIONSETTYPE_V1_MANDATORY_MODULES = "mandatorymodules";
|
||||
|
||||
public static final String DISTRIBUTIONSETTYPE_V1_OPTIONAL_MODULE_TYPES = "optionalmoduletypes";
|
||||
|
||||
public static final String DISTRIBUTIONSETTYPE_V1_MANDATORY_MODULE_TYPES = "mandatorymoduletypes";
|
||||
|
||||
public static final String DOWNLOAD_ID_V1_REQUEST_MAPPING_BASE = "/api/" + API_VERSION + "/downloadserver/";
|
||||
public static final String DOWNLOAD_ID_V1_REQUEST_MAPPING = "downloadId/{downloadId}";
|
||||
|
||||
// constant class, private constructor.
|
||||
private RestConstants() {
|
||||
|
||||
}
|
||||
}
|
||||
0
hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/RestModelMapper.java
Executable file → Normal file
0
hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/RestModelMapper.java
Executable file → Normal file
47
hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/SoftwareModuleMapper.java
Executable file → Normal file
47
hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/SoftwareModuleMapper.java
Executable file → Normal file
@@ -37,7 +37,7 @@ import org.eclipse.hawkbit.rest.resource.model.softwaremodule.SoftwareModulesRes
|
||||
*
|
||||
*
|
||||
*/
|
||||
final class SoftwareModuleMapper {
|
||||
public final class SoftwareModuleMapper {
|
||||
private SoftwareModuleMapper() {
|
||||
// Utility class
|
||||
}
|
||||
@@ -60,8 +60,7 @@ final class SoftwareModuleMapper {
|
||||
smsRest.getName(), smsRest.getVersion(), smsRest.getDescription(), smsRest.getVendor());
|
||||
}
|
||||
|
||||
static List<SoftwareModuleMetadata> fromRequestSwMetadata(final SoftwareModule sw,
|
||||
final List<MetadataRest> metadata) {
|
||||
static List<SoftwareModuleMetadata> fromRequestSwMetadata(final SoftwareModule sw, final List<MetadataRest> metadata) {
|
||||
final List<SoftwareModuleMetadata> mappedList = new ArrayList<>(metadata.size());
|
||||
for (final MetadataRest metadataRest : metadata) {
|
||||
if (metadataRest.getKey() == null) {
|
||||
@@ -81,7 +80,14 @@ final class SoftwareModuleMapper {
|
||||
return mappedList;
|
||||
}
|
||||
|
||||
static List<SoftwareModuleRest> toResponse(final List<SoftwareModule> baseSoftareModules) {
|
||||
/**
|
||||
* Create response for sw modules.
|
||||
*
|
||||
* @param baseSoftareModules
|
||||
* the modules
|
||||
* @return the response
|
||||
*/
|
||||
public static List<SoftwareModuleRest> toResponse(final List<SoftwareModule> baseSoftareModules) {
|
||||
final List<SoftwareModuleRest> mappedList = new ArrayList<>();
|
||||
if (baseSoftareModules != null) {
|
||||
for (final SoftwareModule target : baseSoftareModules) {
|
||||
@@ -116,7 +122,14 @@ final class SoftwareModuleMapper {
|
||||
return metadataRest;
|
||||
}
|
||||
|
||||
static SoftwareModuleRest toResponse(final SoftwareModule baseSofwareModule) {
|
||||
/**
|
||||
* Create response for one sw module.
|
||||
*
|
||||
* @param baseSofwareModule
|
||||
* the sw module
|
||||
* @return the response
|
||||
*/
|
||||
public static SoftwareModuleRest toResponse(final SoftwareModule baseSofwareModule) {
|
||||
if (baseSofwareModule == null) {
|
||||
return null;
|
||||
}
|
||||
@@ -128,15 +141,20 @@ final class SoftwareModuleMapper {
|
||||
response.setType(baseSofwareModule.getType().getKey());
|
||||
response.setVendor(baseSofwareModule.getVendor());
|
||||
|
||||
response.add(linkTo(methodOn(SoftwareModuleResource.class).getArtifacts(response.getModuleId()))
|
||||
.withRel(RestConstants.SOFTWAREMODULE_V1_ARTIFACT));
|
||||
response.add(linkTo(methodOn(SoftwareModuleResource.class).getSoftwareModule(response.getModuleId()))
|
||||
.withRel("self"));
|
||||
response.add(linkTo(methodOn(SoftwareModuleResource.class).getArtifacts(response.getModuleId())).withRel(
|
||||
RestConstants.SOFTWAREMODULE_V1_ARTIFACT));
|
||||
response.add(linkTo(methodOn(SoftwareModuleResource.class).getSoftwareModule(response.getModuleId())).withRel(
|
||||
"self"));
|
||||
|
||||
response.add(linkTo(
|
||||
methodOn(SoftwareModuleTypeResource.class).getSoftwareModuleType(baseSofwareModule.getType().getId()))
|
||||
.withRel(RestConstants.SOFTWAREMODULE_V1_TYPE));
|
||||
.withRel(RestConstants.SOFTWAREMODULE_V1_TYPE));
|
||||
|
||||
response.add(linkTo(
|
||||
methodOn(SoftwareModuleResource.class).getMetadata(response.getModuleId(),
|
||||
Integer.parseInt(RestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET),
|
||||
Integer.parseInt(RestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT), null, null)).withRel(
|
||||
"metadata"));
|
||||
return response;
|
||||
}
|
||||
|
||||
@@ -160,12 +178,13 @@ final class SoftwareModuleMapper {
|
||||
|
||||
RestModelMapper.mapBaseToBase(artifactRest, artifact);
|
||||
|
||||
artifactRest.add(linkTo(methodOn(SoftwareModuleResource.class).getArtifact(artifact.getSoftwareModule().getId(),
|
||||
artifact.getId())).withRel("self"));
|
||||
artifactRest.add(linkTo(
|
||||
methodOn(SoftwareModuleResource.class).getArtifact(artifact.getSoftwareModule().getId(),
|
||||
artifact.getId())).withRel("self"));
|
||||
|
||||
if (artifact instanceof LocalArtifact) {
|
||||
artifactRest.add(
|
||||
linkTo(methodOn(SoftwareModuleResource.class).downloadArtifact(artifact.getSoftwareModule().getId(),
|
||||
artifactRest.add(linkTo(
|
||||
methodOn(SoftwareModuleResource.class).downloadArtifact(artifact.getSoftwareModule().getId(),
|
||||
artifact.getId(), null, null)).withRel("download"));
|
||||
}
|
||||
|
||||
|
||||
141
hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/SoftwareModuleResource.java
Executable file → Normal file
141
hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/SoftwareModuleResource.java
Executable file → Normal file
@@ -8,12 +8,6 @@
|
||||
*/
|
||||
package org.eclipse.hawkbit.rest.resource;
|
||||
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.annotations.ApiParam;
|
||||
import io.swagger.annotations.ApiResponse;
|
||||
import io.swagger.annotations.ApiResponses;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
@@ -22,7 +16,6 @@ import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.eclipse.hawkbit.artifact.repository.model.DbArtifact;
|
||||
import org.eclipse.hawkbit.im.authentication.SpPermission;
|
||||
import org.eclipse.hawkbit.repository.ArtifactManagement;
|
||||
import org.eclipse.hawkbit.repository.SoftwareManagement;
|
||||
import org.eclipse.hawkbit.repository.SoftwareModuleFields;
|
||||
@@ -35,7 +28,6 @@ import org.eclipse.hawkbit.repository.model.SoftwareModuleMetadata;
|
||||
import org.eclipse.hawkbit.repository.model.SwMetadataCompositeKey;
|
||||
import org.eclipse.hawkbit.repository.rsql.RSQLUtility;
|
||||
import org.eclipse.hawkbit.rest.resource.helper.RestResourceConversionHelper;
|
||||
import org.eclipse.hawkbit.rest.resource.model.ExceptionInfo;
|
||||
import org.eclipse.hawkbit.rest.resource.model.MetadataRest;
|
||||
import org.eclipse.hawkbit.rest.resource.model.MetadataRestPageList;
|
||||
import org.eclipse.hawkbit.rest.resource.model.artifact.ArtifactRest;
|
||||
@@ -55,7 +47,6 @@ import org.springframework.data.domain.Sort;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
@@ -74,9 +65,7 @@ import org.springframework.web.multipart.MultipartFile;
|
||||
*
|
||||
*/
|
||||
@RestController
|
||||
@Transactional(readOnly = true)
|
||||
@RequestMapping(RestConstants.SOFTWAREMODULE_V1_REQUEST_MAPPING)
|
||||
@Api(value = "softwaremodules", description = "Software Modules Management API")
|
||||
public class SoftwareModuleResource {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(SoftwareModuleResource.class);
|
||||
|
||||
@@ -108,17 +97,13 @@ public class SoftwareModuleResource {
|
||||
*/
|
||||
@RequestMapping(method = RequestMethod.POST, value = "/{softwareModuleId}/artifacts", produces = {
|
||||
"application/hal+json", MediaType.APPLICATION_JSON_VALUE })
|
||||
@ApiOperation(response = ArtifactRest.class, value = "Upload Artifact", notes = "Handles POST request for artifact upload. Required Permission: "
|
||||
+ SpPermission.CREATE_REPOSITORY)
|
||||
@ApiResponses(@ApiResponse(code = 404, message = "Not Found Software Module", response = ExceptionInfo.class))
|
||||
@Transactional
|
||||
public ResponseEntity<ArtifactRest> uploadArtifact(@PathVariable final Long softwareModuleId,
|
||||
@RequestParam("file") final MultipartFile file,
|
||||
@RequestParam(value = "filename", required = false) final String optionalFileName,
|
||||
@RequestParam(value = "md5sum", required = false) final String md5Sum,
|
||||
@RequestParam(value = "sha1sum", required = false) final String sha1Sum) {
|
||||
|
||||
Artifact result = null;
|
||||
Artifact result;
|
||||
if (!file.isEmpty()) {
|
||||
String fileName = optionalFileName;
|
||||
|
||||
@@ -138,10 +123,7 @@ public class SoftwareModuleResource {
|
||||
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
|
||||
// we flush to ensure that entity is generated and we can return ID etc.
|
||||
entityManager.flush();
|
||||
|
||||
return new ResponseEntity<ArtifactRest>(SoftwareModuleMapper.toResponse(result), HttpStatus.CREATED);
|
||||
return new ResponseEntity<>(SoftwareModuleMapper.toResponse(result), HttpStatus.CREATED);
|
||||
|
||||
}
|
||||
|
||||
@@ -157,15 +139,11 @@ public class SoftwareModuleResource {
|
||||
*/
|
||||
@RequestMapping(method = RequestMethod.GET, value = "/{softwareModuleId}/artifacts", produces = {
|
||||
"application/hal+json", MediaType.APPLICATION_JSON_VALUE })
|
||||
@ApiOperation(response = ArtifactsRest.class, value = "List Artifacts Metadata", notes = "Handles the GET request of retrieving all meta data of artifacts assigned to a software module. Required Permission: "
|
||||
+ SpPermission.READ_REPOSITORY)
|
||||
@ApiResponses(@ApiResponse(code = 404, message = "Not Found Software Module", response = ExceptionInfo.class))
|
||||
@ResponseBody
|
||||
public ResponseEntity<ArtifactsRest> getArtifacts(@PathVariable final Long softwareModuleId) {
|
||||
final SoftwareModule module = findSoftwareModuleWithExceptionIfNotFound(softwareModuleId, null);
|
||||
|
||||
return new ResponseEntity<ArtifactsRest>(SoftwareModuleMapper.artifactsToResponse(module.getArtifacts()),
|
||||
HttpStatus.OK);
|
||||
return new ResponseEntity<>(SoftwareModuleMapper.artifactsToResponse(module.getArtifacts()), HttpStatus.OK);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -184,9 +162,6 @@ public class SoftwareModuleResource {
|
||||
* successful
|
||||
*/
|
||||
@RequestMapping(method = RequestMethod.GET, value = "/{softwareModuleId}/artifacts/{artifactId}/download")
|
||||
@ApiOperation(response = Void.class, value = "Download Artifact", notes = "Handles the GET request for downloading an artifact. Required Permission: "
|
||||
+ SpPermission.READ_REPOSITORY)
|
||||
@ApiResponses(@ApiResponse(code = 404, message = "Not Found Software Module or Artifact", response = ExceptionInfo.class))
|
||||
@ResponseBody
|
||||
public ResponseEntity<Void> downloadArtifact(@PathVariable final Long softwareModuleId,
|
||||
@PathVariable final Long artifactId, final HttpServletResponse servletResponse,
|
||||
@@ -223,16 +198,13 @@ public class SoftwareModuleResource {
|
||||
*/
|
||||
@RequestMapping(method = RequestMethod.GET, value = "/{softwareModuleId}/artifacts/{artifactId}", produces = {
|
||||
"application/hal+json", MediaType.APPLICATION_JSON_VALUE })
|
||||
@ApiOperation(response = ArtifactRest.class, value = "Get Artifact Metadata", notes = "Handles the GET request of retrieving a single Artifact meta data request. Required Permission: "
|
||||
+ SpPermission.READ_REPOSITORY)
|
||||
@ApiResponses(@ApiResponse(code = 404, message = "Not Found Software Module or Artifact", response = ExceptionInfo.class))
|
||||
@ResponseBody
|
||||
public ResponseEntity<ArtifactRest> getArtifact(@PathVariable final Long softwareModuleId,
|
||||
@PathVariable final Long artifactId) {
|
||||
final SoftwareModule module = findSoftwareModuleWithExceptionIfNotFound(softwareModuleId, artifactId);
|
||||
|
||||
return new ResponseEntity<ArtifactRest>(SoftwareModuleMapper.toResponse(module.getLocalArtifact(artifactId)
|
||||
.get()), HttpStatus.OK);
|
||||
return new ResponseEntity<>(SoftwareModuleMapper.toResponse(module.getLocalArtifact(artifactId).get()),
|
||||
HttpStatus.OK);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -246,11 +218,7 @@ public class SoftwareModuleResource {
|
||||
* @return status OK if delete as successful.
|
||||
*/
|
||||
@RequestMapping(method = RequestMethod.DELETE, value = "/{softwareModuleId}/artifacts/{artifactId}")
|
||||
@ApiOperation(value = "Delete Artifact", notes = "Handles the DELETE request for a single SoftwareModule within SP. Required Permission: "
|
||||
+ SpPermission.DELETE_REPOSITORY)
|
||||
@ApiResponses(@ApiResponse(code = 404, message = "Not Found Software Module or Artifact", response = ExceptionInfo.class))
|
||||
@ResponseBody
|
||||
@Transactional
|
||||
public ResponseEntity<Void> deleteArtifact(@PathVariable final Long softwareModuleId,
|
||||
@PathVariable final Long artifactId) {
|
||||
findSoftwareModuleWithExceptionIfNotFound(softwareModuleId, artifactId);
|
||||
@@ -282,18 +250,11 @@ public class SoftwareModuleResource {
|
||||
* JsonResponseExceptionHandler is handling the response.
|
||||
*/
|
||||
@RequestMapping(method = RequestMethod.GET, produces = { "application/hal+json", MediaType.APPLICATION_JSON_VALUE })
|
||||
@ApiOperation(response = SoftwareModulePagedList.class, value = "Get Software Modules", notes = "Handles the GET request of retrieving all softwaremodules within SP. Required Permission: "
|
||||
+ SpPermission.READ_REPOSITORY)
|
||||
public ResponseEntity<SoftwareModulePagedList> getSoftwareModules(
|
||||
@RequestParam(value = RestConstants.REQUEST_PARAMETER_PAGING_OFFSET, defaultValue = RestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET) final int pagingOffsetParam,
|
||||
@RequestParam(value = RestConstants.REQUEST_PARAMETER_PAGING_LIMIT, defaultValue = RestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT) final int pagingLimitParam,
|
||||
@RequestParam(value = RestConstants.REQUEST_PARAMETER_SORTING, required = false) final String sortParam,
|
||||
@ApiParam(required = false, value = "FIQL syntax search query"
|
||||
+ "<table border=0>"
|
||||
+ "<tr><td>version==1.0.0</td><td>softwaremodules with version 1.0.0</td></tr>"
|
||||
+ "<tr><td>version=ge=2.0.0</td><td>softwaremodules with version greater-equal 2.0.0</td></tr>"
|
||||
+ "<tr><td>version==1.0.0;type=application</td><td>softwaremodules with version 1.0.0 and type application</td></tr>"
|
||||
+ "<tr><td>id=1,type=os</td><td>softwaremodules with id 1 or type os</td></tr>" + "</table>") @RequestParam(value = RestConstants.REQUEST_PARAMETER_SEARCH, required = false) final String rsqlParam) {
|
||||
@RequestParam(value = RestConstants.REQUEST_PARAMETER_SEARCH, required = false) final String rsqlParam) {
|
||||
|
||||
final int sanitizedOffsetParam = PagingUtility.sanitizeOffsetParam(pagingOffsetParam);
|
||||
final int sanitizedLimitParam = PagingUtility.sanitizePageLimitParam(pagingLimitParam);
|
||||
@@ -328,9 +289,6 @@ public class SoftwareModuleResource {
|
||||
*/
|
||||
@RequestMapping(method = RequestMethod.GET, value = "/{softwareModuleId}", produces = { "application/hal+json",
|
||||
MediaType.APPLICATION_JSON_VALUE })
|
||||
@ApiOperation(response = SoftwareModuleRest.class, value = "Get Software Module", notes = "Handles the GET request of retrieving a single softwaremodule within SP. Required Permission: "
|
||||
+ SpPermission.READ_REPOSITORY)
|
||||
@ApiResponses(@ApiResponse(code = 404, message = "Not Found Software Module", response = ExceptionInfo.class))
|
||||
public ResponseEntity<SoftwareModuleRest> getSoftwareModule(@PathVariable final Long softwareModuleId) {
|
||||
final SoftwareModule findBaseSoftareModule = findSoftwareModuleWithExceptionIfNotFound(softwareModuleId, null);
|
||||
|
||||
@@ -349,14 +307,8 @@ public class SoftwareModuleResource {
|
||||
* failure the JsonResponseExceptionHandler is handling the
|
||||
* response.
|
||||
*/
|
||||
@RequestMapping(method = RequestMethod.POST, consumes = { "application/hal+json", MediaType.APPLICATION_JSON_VALUE }, produces = {
|
||||
"application/hal+json", MediaType.APPLICATION_JSON_VALUE })
|
||||
@ApiOperation(response = SoftwareModulesRest.class, value = "Create Software Modules", notes = "Handles the POST request of creating new software modules within SP. The request body must always be a list of modules. Required Permission: "
|
||||
+ SpPermission.CREATE_REPOSITORY)
|
||||
@ApiResponses({
|
||||
@ApiResponse(code = 404, message = "Not Found Software Module", response = ExceptionInfo.class),
|
||||
@ApiResponse(code = 409, message = "Conflict Software Module already exists", response = ExceptionInfo.class) })
|
||||
@Transactional
|
||||
@RequestMapping(method = RequestMethod.POST, consumes = { "application/hal+json",
|
||||
MediaType.APPLICATION_JSON_VALUE }, produces = { "application/hal+json", MediaType.APPLICATION_JSON_VALUE })
|
||||
public ResponseEntity<SoftwareModulesRest> createSoftwareModules(
|
||||
@RequestBody final List<SoftwareModuleRequestBodyPost> softwareModules) {
|
||||
LOG.debug("creating {} softwareModules", softwareModules.size());
|
||||
@@ -364,9 +316,6 @@ public class SoftwareModuleResource {
|
||||
.createSoftwareModule(SoftwareModuleMapper.smFromRequest(softwareModules, softwareManagement));
|
||||
LOG.debug("{} softwareModules created, return status {}", softwareModules.size(), HttpStatus.CREATED);
|
||||
|
||||
// we flush to ensure that entity is generated and we can return ID etc.
|
||||
entityManager.flush();
|
||||
|
||||
return new ResponseEntity<>(SoftwareModuleMapper.toResponseSoftwareModules(createdSoftwareModules),
|
||||
HttpStatus.CREATED);
|
||||
}
|
||||
@@ -383,10 +332,6 @@ public class SoftwareModuleResource {
|
||||
*/
|
||||
@RequestMapping(method = RequestMethod.PUT, value = "/{softwareModuleId}", consumes = { "application/hal+json",
|
||||
MediaType.APPLICATION_JSON_VALUE }, produces = { "application/hal+json", MediaType.APPLICATION_JSON_VALUE })
|
||||
@ApiOperation(value = "Update Software Module", notes = "Handles the PUT request for a single softwaremodule within SP. Required Permission: "
|
||||
+ SpPermission.UPDATE_REPOSITORY)
|
||||
@ApiResponses(@ApiResponse(code = 404, message = "Not Found Software Module", response = ExceptionInfo.class))
|
||||
@Transactional
|
||||
public ResponseEntity<SoftwareModuleRest> updateSoftwareModule(@PathVariable final Long softwareModuleId,
|
||||
@RequestBody final SoftwareModuleRequestBodyPut restSoftwareModule) {
|
||||
final SoftwareModule module = findSoftwareModuleWithExceptionIfNotFound(softwareModuleId, null);
|
||||
@@ -400,10 +345,6 @@ public class SoftwareModuleResource {
|
||||
}
|
||||
|
||||
final SoftwareModule updateSoftwareModule = softwareManagement.updateSoftwareModule(module);
|
||||
|
||||
// we flush to ensure that entity is generated and we can return ID etc.
|
||||
entityManager.flush();
|
||||
|
||||
return new ResponseEntity<>(SoftwareModuleMapper.toResponse(updateSoftwareModule), HttpStatus.OK);
|
||||
}
|
||||
|
||||
@@ -416,10 +357,6 @@ public class SoftwareModuleResource {
|
||||
*
|
||||
*/
|
||||
@RequestMapping(method = RequestMethod.DELETE, value = "/{softwareModuleId}")
|
||||
@ApiOperation(value = "Delete Software Module", notes = "Handles the DELETE request for a single softwaremodule within SP. Required Permission: "
|
||||
+ SpPermission.DELETE_REPOSITORY)
|
||||
@ApiResponses(@ApiResponse(code = 404, message = "Not Found Software Module", response = ExceptionInfo.class))
|
||||
@Transactional
|
||||
public ResponseEntity<Void> deleteSoftwareModule(@PathVariable final Long softwareModuleId) {
|
||||
final SoftwareModule module = findSoftwareModuleWithExceptionIfNotFound(softwareModuleId, null);
|
||||
|
||||
@@ -430,7 +367,7 @@ public class SoftwareModuleResource {
|
||||
|
||||
/**
|
||||
* Gets a paged list of meta data for a software module.
|
||||
*
|
||||
*
|
||||
* @param softwareModuleId
|
||||
* the ID of the software module for the meta data
|
||||
* @param pagingOffsetParam
|
||||
@@ -450,20 +387,11 @@ public class SoftwareModuleResource {
|
||||
*/
|
||||
@RequestMapping(method = RequestMethod.GET, value = "/{softwareModuleId}/metadata", produces = {
|
||||
MediaType.APPLICATION_JSON_VALUE, "application/hal+json" })
|
||||
@ApiOperation(response = MetadataRestPageList.class, value = "Get a paged list of meta data", notes = " Get a paged list of meta data for a software module."
|
||||
+ " Required Permission: " + SpPermission.READ_REPOSITORY)
|
||||
@ApiResponses(@ApiResponse(code = 404, message = "Not Found Software Module", response = ExceptionInfo.class))
|
||||
@Transactional
|
||||
public ResponseEntity<MetadataRestPageList> getMetadata(
|
||||
@PathVariable final Long softwareModuleId,
|
||||
public ResponseEntity<MetadataRestPageList> getMetadata(@PathVariable final Long softwareModuleId,
|
||||
@RequestParam(value = RestConstants.REQUEST_PARAMETER_PAGING_OFFSET, defaultValue = RestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET) final int pagingOffsetParam,
|
||||
@RequestParam(value = RestConstants.REQUEST_PARAMETER_PAGING_LIMIT, defaultValue = RestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT) final int pagingLimitParam,
|
||||
@RequestParam(value = RestConstants.REQUEST_PARAMETER_SORTING, required = false) final String sortParam,
|
||||
@ApiParam(required = false, value = "FIQL syntax search query"
|
||||
+ "<table border=0>"
|
||||
+ "<tr><td>key==aKey,key==bKey</td><td>metadata with the key 'aKey' or 'bKey'</td></tr>"
|
||||
+ "<tr><td>value=li=%25someValue%25</td><td>metadata which contains 'someValue' in the value ignore case</td></tr>"
|
||||
+ "</table>") @RequestParam(value = RestConstants.REQUEST_PARAMETER_SEARCH, required = false) final String rsqlParam) {
|
||||
@RequestParam(value = RestConstants.REQUEST_PARAMETER_SEARCH, required = false) final String rsqlParam) {
|
||||
|
||||
// check if software module exists otherwise throw exception immediately
|
||||
findSoftwareModuleWithExceptionIfNotFound(softwareModuleId, null);
|
||||
@@ -482,13 +410,15 @@ public class SoftwareModuleResource {
|
||||
metaDataPage = softwareManagement.findSoftwareModuleMetadataBySoftwareModuleId(softwareModuleId, pageable);
|
||||
}
|
||||
|
||||
return new ResponseEntity<>(new MetadataRestPageList(SoftwareModuleMapper.toResponseSwMetadata(metaDataPage
|
||||
.getContent()), metaDataPage.getTotalElements()), HttpStatus.OK);
|
||||
return new ResponseEntity<>(
|
||||
new MetadataRestPageList(SoftwareModuleMapper.toResponseSwMetadata(metaDataPage.getContent()),
|
||||
metaDataPage.getTotalElements()),
|
||||
HttpStatus.OK);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a single meta data value for a specific key of a software module.
|
||||
*
|
||||
*
|
||||
* @param softwareModuleId
|
||||
* the ID of the software module to get the meta data from
|
||||
* @param metadataKey
|
||||
@@ -496,11 +426,8 @@ public class SoftwareModuleResource {
|
||||
* @return status OK if get request is successful with the value of the meta
|
||||
* data
|
||||
*/
|
||||
@RequestMapping(method = RequestMethod.GET, value = "/{softwareModuleId}/metadata/{metadataKey}", produces = { MediaType.APPLICATION_JSON_VALUE })
|
||||
@ApiOperation(response = MetadataRest.class, value = "Get a single meta data value", notes = " Get a single meta data value for a meta data key."
|
||||
+ " Required Permission: " + SpPermission.READ_REPOSITORY)
|
||||
@ApiResponses(@ApiResponse(code = 404, message = "Not Found Software Module or meta data key", response = ExceptionInfo.class))
|
||||
@Transactional
|
||||
@RequestMapping(method = RequestMethod.GET, value = "/{softwareModuleId}/metadata/{metadataKey}", produces = {
|
||||
MediaType.APPLICATION_JSON_VALUE })
|
||||
public ResponseEntity<MetadataRest> getMetadataValue(@PathVariable final Long softwareModuleId,
|
||||
@PathVariable final String metadataKey) {
|
||||
// check if distribution set exists otherwise throw exception
|
||||
@@ -512,7 +439,7 @@ public class SoftwareModuleResource {
|
||||
|
||||
/**
|
||||
* Updates a single meta data value of a software module.
|
||||
*
|
||||
*
|
||||
* @param softwareModuleId
|
||||
* the ID of the software module to update the meta data entry
|
||||
* @param metadataKey
|
||||
@@ -522,10 +449,6 @@ public class SoftwareModuleResource {
|
||||
*/
|
||||
@RequestMapping(method = RequestMethod.PUT, value = "/{softwareModuleId}/metadata/{metadataKey}", produces = {
|
||||
MediaType.APPLICATION_JSON_VALUE, "application/hal+json" })
|
||||
@ApiOperation(response = MetadataRest.class, value = "Update a single meta data value", notes = " Update a single meta data value for speficic key."
|
||||
+ " Required Permission: " + SpPermission.UPDATE_REPOSITORY)
|
||||
@ApiResponses(@ApiResponse(code = 404, message = "Not Found Software Module or meta data key", response = ExceptionInfo.class))
|
||||
@Transactional
|
||||
public ResponseEntity<MetadataRest> updateMetadata(@PathVariable final Long softwareModuleId,
|
||||
@PathVariable final String metadataKey, @RequestBody final MetadataRest metadata) {
|
||||
// check if software module exists otherwise throw exception immediately
|
||||
@@ -537,7 +460,7 @@ public class SoftwareModuleResource {
|
||||
|
||||
/**
|
||||
* Deletes a single meta data entry from the software module.
|
||||
*
|
||||
*
|
||||
* @param softwareModuleId
|
||||
* the ID of the software module to delete the meta data entry
|
||||
* @param metadataKey
|
||||
@@ -545,10 +468,6 @@ public class SoftwareModuleResource {
|
||||
* @return status OK if the delete request is successful
|
||||
*/
|
||||
@RequestMapping(method = RequestMethod.DELETE, value = "/{softwareModuleId}/metadata/{metadataKey}")
|
||||
@ApiOperation(value = "Delete a single meta data", notes = " Delete a single meta data." + " Required Permission: "
|
||||
+ SpPermission.UPDATE_REPOSITORY)
|
||||
@ApiResponses(@ApiResponse(code = 404, message = "Not Found Software Module or meta data key", response = ExceptionInfo.class))
|
||||
@Transactional
|
||||
public ResponseEntity<Void> deleteMetadata(@PathVariable final Long softwareModuleId,
|
||||
@PathVariable final String metadataKey) {
|
||||
// check if software module exists otherwise throw exception immediately
|
||||
@@ -559,7 +478,7 @@ public class SoftwareModuleResource {
|
||||
|
||||
/**
|
||||
* Creates a list of meta data for a specific software module.
|
||||
*
|
||||
*
|
||||
* @param softwareModuleId
|
||||
* the ID of the distribution set to create meta data for
|
||||
* @param metadataRest
|
||||
@@ -568,13 +487,8 @@ public class SoftwareModuleResource {
|
||||
* the created meta data
|
||||
*/
|
||||
@RequestMapping(method = RequestMethod.POST, value = "/{softwareModuleId}/metadata", consumes = {
|
||||
MediaType.APPLICATION_JSON_VALUE, "application/hal+json" }, produces = { MediaType.APPLICATION_JSON_VALUE,
|
||||
"application/hal+json" })
|
||||
@ApiOperation(response = MetadataRest.class, value = "Create a list of meta data entries", notes = "Create a list of meta data entries"
|
||||
+ " Required Permission: " + SpPermission.READ_REPOSITORY + " and " + SpPermission.UPDATE_TARGET)
|
||||
@ApiResponses({ @ApiResponse(code = 409, message = "Conflict", response = ExceptionInfo.class),
|
||||
@ApiResponse(code = 404, message = "Not Found Distribution Set", response = ExceptionInfo.class) })
|
||||
@Transactional
|
||||
MediaType.APPLICATION_JSON_VALUE,
|
||||
"application/hal+json" }, produces = { MediaType.APPLICATION_JSON_VALUE, "application/hal+json" })
|
||||
public ResponseEntity<List<MetadataRest>> createMetadata(@PathVariable final Long softwareModuleId,
|
||||
@RequestBody final List<MetadataRest> metadataRest) {
|
||||
// check if software module exists otherwise throw exception immediately
|
||||
@@ -583,15 +497,12 @@ public class SoftwareModuleResource {
|
||||
final List<SoftwareModuleMetadata> created = softwareManagement
|
||||
.createSoftwareModuleMetadata(SoftwareModuleMapper.fromRequestSwMetadata(sw, metadataRest));
|
||||
|
||||
// we flush to ensure that entity is generated and we can return ID etc.
|
||||
entityManager.flush();
|
||||
|
||||
return new ResponseEntity<List<MetadataRest>>(SoftwareModuleMapper.toResponseSwMetadata(created),
|
||||
HttpStatus.CREATED);
|
||||
return new ResponseEntity<>(SoftwareModuleMapper.toResponseSwMetadata(created), HttpStatus.CREATED);
|
||||
|
||||
}
|
||||
|
||||
private SoftwareModule findSoftwareModuleWithExceptionIfNotFound(final Long softwareModuleId, final Long artifactId) {
|
||||
private SoftwareModule findSoftwareModuleWithExceptionIfNotFound(final Long softwareModuleId,
|
||||
final Long artifactId) {
|
||||
final SoftwareModule module = softwareManagement.findSoftwareModuleById(softwareModuleId);
|
||||
if (module == null) {
|
||||
throw new EntityNotFoundException("SoftwareModule with Id {" + softwareModuleId + "} does not exist");
|
||||
|
||||
0
hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/SoftwareModuleTypeMapper.java
Executable file → Normal file
0
hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/SoftwareModuleTypeMapper.java
Executable file → Normal file
54
hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/SoftwareModuleTypeResource.java
Executable file → Normal file
54
hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/SoftwareModuleTypeResource.java
Executable file → Normal file
@@ -8,17 +8,10 @@
|
||||
*/
|
||||
package org.eclipse.hawkbit.rest.resource;
|
||||
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.annotations.ApiParam;
|
||||
import io.swagger.annotations.ApiResponse;
|
||||
import io.swagger.annotations.ApiResponses;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
|
||||
import org.eclipse.hawkbit.im.authentication.SpPermission;
|
||||
import org.eclipse.hawkbit.repository.SoftwareManagement;
|
||||
import org.eclipse.hawkbit.repository.SoftwareModuleTypeFields;
|
||||
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
|
||||
@@ -26,7 +19,6 @@ import org.eclipse.hawkbit.repository.model.Artifact;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModule;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModuleType;
|
||||
import org.eclipse.hawkbit.repository.rsql.RSQLUtility;
|
||||
import org.eclipse.hawkbit.rest.resource.model.ExceptionInfo;
|
||||
import org.eclipse.hawkbit.rest.resource.model.softwaremoduletype.SoftwareModuleTypePagedList;
|
||||
import org.eclipse.hawkbit.rest.resource.model.softwaremoduletype.SoftwareModuleTypeRequestBodyPost;
|
||||
import org.eclipse.hawkbit.rest.resource.model.softwaremoduletype.SoftwareModuleTypeRequestBodyPut;
|
||||
@@ -40,7 +32,6 @@ import org.springframework.data.domain.Sort;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
@@ -57,9 +48,7 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
*
|
||||
*/
|
||||
@RestController
|
||||
@Transactional(readOnly = true)
|
||||
@RequestMapping(RestConstants.SOFTWAREMODULETYPE_V1_REQUEST_MAPPING)
|
||||
@Api(value = "softwaremoduletypes", description = "Software Module Types Management API")
|
||||
public class SoftwareModuleTypeResource {
|
||||
@Autowired
|
||||
private SoftwareManagement softwareManagement;
|
||||
@@ -89,16 +78,11 @@ public class SoftwareModuleTypeResource {
|
||||
* JsonResponseExceptionHandler is handling the response.
|
||||
*/
|
||||
@RequestMapping(method = RequestMethod.GET, produces = { "application/hal+json", MediaType.APPLICATION_JSON_VALUE })
|
||||
@ApiOperation(response = SoftwareModuleTypePagedList.class, value = "Get Software Module Types", notes = "Handles the GET request of retrieving all software module types within SP. Required Permission: "
|
||||
+ SpPermission.READ_REPOSITORY)
|
||||
public ResponseEntity<SoftwareModuleTypePagedList> getTypes(
|
||||
@RequestParam(value = RestConstants.REQUEST_PARAMETER_PAGING_OFFSET, defaultValue = RestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET) final int pagingOffsetParam,
|
||||
@RequestParam(value = RestConstants.REQUEST_PARAMETER_PAGING_LIMIT, defaultValue = RestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT) final int pagingLimitParam,
|
||||
@RequestParam(value = RestConstants.REQUEST_PARAMETER_SORTING, required = false) final String sortParam,
|
||||
@ApiParam(required = false, value = "FIQL syntax search query" + "<table border=0>"
|
||||
+ "<tr><td>id=1,key=os</td><td>software module types with id 1 or key os</td></tr>"
|
||||
+ "<tr><td>name=Application</td><td>software module types with name Application</td></tr>"
|
||||
+ "</table>") @RequestParam(value = RestConstants.REQUEST_PARAMETER_SEARCH, required = false) final String rsqlParam) {
|
||||
@RequestParam(value = RestConstants.REQUEST_PARAMETER_SEARCH, required = false) final String rsqlParam) {
|
||||
|
||||
final int sanitizedOffsetParam = PagingUtility.sanitizeOffsetParam(pagingOffsetParam);
|
||||
final int sanitizedLimitParam = PagingUtility.sanitizePageLimitParam(pagingLimitParam);
|
||||
@@ -117,8 +101,8 @@ public class SoftwareModuleTypeResource {
|
||||
countModulesAll = softwareManagement.countSoftwareModuleTypesAll();
|
||||
}
|
||||
|
||||
final List<SoftwareModuleTypeRest> rest = SoftwareModuleTypeMapper.toListResponse(findModuleTypessAll
|
||||
.getContent());
|
||||
final List<SoftwareModuleTypeRest> rest = SoftwareModuleTypeMapper
|
||||
.toListResponse(findModuleTypessAll.getContent());
|
||||
return new ResponseEntity<>(new SoftwareModuleTypePagedList(rest, countModulesAll), HttpStatus.OK);
|
||||
}
|
||||
|
||||
@@ -135,9 +119,6 @@ public class SoftwareModuleTypeResource {
|
||||
*/
|
||||
@RequestMapping(method = RequestMethod.GET, value = "/{softwareModuleTypeId}", produces = { "application/hal+json",
|
||||
MediaType.APPLICATION_JSON_VALUE })
|
||||
@ApiOperation(response = SoftwareModuleTypeRest.class, value = "Get Software Module Type", notes = "Handles the GET request of retrieving a single software module type within SP. Required Permission: "
|
||||
+ SpPermission.READ_REPOSITORY)
|
||||
@ApiResponses(@ApiResponse(code = 404, message = "Not Found Software Module Type", response = ExceptionInfo.class))
|
||||
public ResponseEntity<SoftwareModuleTypeRest> getSoftwareModuleType(@PathVariable final Long softwareModuleTypeId) {
|
||||
final SoftwareModuleType foundType = findSoftwareModuleTypeWithExceptionIfNotFound(softwareModuleTypeId);
|
||||
|
||||
@@ -153,10 +134,6 @@ public class SoftwareModuleTypeResource {
|
||||
*
|
||||
*/
|
||||
@RequestMapping(method = RequestMethod.DELETE, value = "/{softwareModuleTypeId}")
|
||||
@ApiOperation(value = "Delete Software Module Type", notes = "Handles the DELETE request for a single software module Type within SP. Required Permission: "
|
||||
+ SpPermission.DELETE_REPOSITORY)
|
||||
@ApiResponses(@ApiResponse(code = 404, message = "Not Found Software Module Type", response = ExceptionInfo.class))
|
||||
@Transactional
|
||||
public ResponseEntity<Void> deleteSoftwareModuleType(@PathVariable final Long softwareModuleTypeId) {
|
||||
final SoftwareModuleType module = findSoftwareModuleTypeWithExceptionIfNotFound(softwareModuleTypeId);
|
||||
|
||||
@@ -176,10 +153,6 @@ public class SoftwareModuleTypeResource {
|
||||
*/
|
||||
@RequestMapping(method = RequestMethod.PUT, value = "/{softwareModuleTypeId}", consumes = { "application/hal+json",
|
||||
MediaType.APPLICATION_JSON_VALUE }, produces = { "application/hal+json", MediaType.APPLICATION_JSON_VALUE })
|
||||
@ApiOperation(value = "Updates Software Module Type", notes = "Handles the PUT request for a single software module type within SP. Required Permission: "
|
||||
+ SpPermission.UPDATE_REPOSITORY)
|
||||
@ApiResponses(@ApiResponse(code = 404, message = "Not Found Software Module", response = ExceptionInfo.class))
|
||||
@Transactional
|
||||
public ResponseEntity<SoftwareModuleTypeRest> updateSoftwareModuleType(
|
||||
@PathVariable final Long softwareModuleTypeId,
|
||||
@RequestBody final SoftwareModuleTypeRequestBodyPut restSoftwareModuleType) {
|
||||
@@ -191,10 +164,6 @@ public class SoftwareModuleTypeResource {
|
||||
}
|
||||
|
||||
final SoftwareModuleType updatedSoftwareModuleType = softwareManagement.updateSoftwareModuleType(type);
|
||||
|
||||
// we flush to ensure that entity is generated and we can return ID etc.
|
||||
entityManager.flush();
|
||||
|
||||
return new ResponseEntity<>(SoftwareModuleTypeMapper.toResponse(updatedSoftwareModuleType), HttpStatus.OK);
|
||||
}
|
||||
|
||||
@@ -209,23 +178,14 @@ public class SoftwareModuleTypeResource {
|
||||
* failure the JsonResponseExceptionHandler is handling the
|
||||
* response.
|
||||
*/
|
||||
@RequestMapping(method = RequestMethod.POST, consumes = { "application/hal+json", MediaType.APPLICATION_JSON_VALUE }, produces = {
|
||||
"application/hal+json", MediaType.APPLICATION_JSON_VALUE })
|
||||
@ApiOperation(response = SoftwareModuleTypesRest.class, value = "Create Software Module Types", notes = "Handles the POST request of creating new software module types within SP. The request body must always be a list of module types. Required Permission: "
|
||||
+ SpPermission.CREATE_REPOSITORY)
|
||||
@ApiResponses({
|
||||
@ApiResponse(code = 404, message = "Not Found Software Module Type", response = ExceptionInfo.class),
|
||||
@ApiResponse(code = 409, message = "Conflict Software Module Type already exists", response = ExceptionInfo.class) })
|
||||
@Transactional
|
||||
@RequestMapping(method = RequestMethod.POST, consumes = { "application/hal+json",
|
||||
MediaType.APPLICATION_JSON_VALUE }, produces = { "application/hal+json", MediaType.APPLICATION_JSON_VALUE })
|
||||
public ResponseEntity<SoftwareModuleTypesRest> createSoftwareModuleTypes(
|
||||
@RequestBody final List<SoftwareModuleTypeRequestBodyPost> softwareModuleTypes) {
|
||||
|
||||
final List<SoftwareModuleType> createdSoftwareModules = softwareManagement
|
||||
.createSoftwareModuleTypes(SoftwareModuleTypeMapper.smFromRequest(softwareModuleTypes));
|
||||
|
||||
// we flush to ensure that entity is generated and we can return ID etc.
|
||||
entityManager.flush();
|
||||
|
||||
return new ResponseEntity<>(SoftwareModuleTypeMapper.toTypesResponse(createdSoftwareModules),
|
||||
HttpStatus.CREATED);
|
||||
}
|
||||
@@ -233,8 +193,8 @@ public class SoftwareModuleTypeResource {
|
||||
private SoftwareModuleType findSoftwareModuleTypeWithExceptionIfNotFound(final Long softwareModuleTypeId) {
|
||||
final SoftwareModuleType module = softwareManagement.findSoftwareModuleTypeById(softwareModuleTypeId);
|
||||
if (module == null) {
|
||||
throw new EntityNotFoundException("SoftwareModuleType with Id {" + softwareModuleTypeId
|
||||
+ "} does not exist");
|
||||
throw new EntityNotFoundException(
|
||||
"SoftwareModuleType with Id {" + softwareModuleTypeId + "} does not exist");
|
||||
}
|
||||
return module;
|
||||
}
|
||||
|
||||
0
hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/SortDirection.java
Executable file → Normal file
0
hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/SortDirection.java
Executable file → Normal file
0
hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/SortParameterSyntaxErrorException.java
Executable file → Normal file
0
hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/SortParameterSyntaxErrorException.java
Executable file → Normal file
0
hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/SortParameterUnsupportedDirectionException.java
Executable file → Normal file
0
hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/SortParameterUnsupportedDirectionException.java
Executable file → Normal file
0
hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/SortParameterUnsupportedFieldException.java
Executable file → Normal file
0
hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/SortParameterUnsupportedFieldException.java
Executable file → Normal file
0
hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/SortUtility.java
Executable file → Normal file
0
hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/SortUtility.java
Executable file → Normal file
50
hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/SystemManagementResource.java
Executable file → Normal file
50
hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/SystemManagementResource.java
Executable file → Normal file
@@ -14,19 +14,23 @@ import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.eclipse.hawkbit.im.authentication.SpPermission.SpringEvalExpressions;
|
||||
import org.eclipse.hawkbit.report.model.SystemUsageReport;
|
||||
import org.eclipse.hawkbit.report.model.TenantUsage;
|
||||
import org.eclipse.hawkbit.repository.SystemManagement;
|
||||
import org.eclipse.hawkbit.repository.model.TenantConfiguration;
|
||||
import org.eclipse.hawkbit.rest.resource.model.system.CacheRest;
|
||||
import org.eclipse.hawkbit.rest.resource.model.system.SystemStatisticsRest;
|
||||
import org.eclipse.hawkbit.rest.resource.model.system.TenantConfigurationRest;
|
||||
import org.eclipse.hawkbit.rest.resource.model.system.TenantSystemUsageRest;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cache.Cache;
|
||||
import org.springframework.cache.CacheManager;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
@@ -35,14 +39,13 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* {@link SystemManagement} capabilities by REST.
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping(RestConstants.SYSTEM_ADMIN_MAPPING)
|
||||
@Transactional(readOnly = true)
|
||||
public class SystemManagementResource {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(SystemManagementResource.class);
|
||||
@@ -55,22 +58,53 @@ public class SystemManagementResource {
|
||||
|
||||
/**
|
||||
* Deletes the tenant data of a given tenant. USE WITH CARE!
|
||||
*
|
||||
*
|
||||
* @param tenant
|
||||
* to delete
|
||||
* @return HttpStatus.OK
|
||||
*/
|
||||
@RequestMapping(method = RequestMethod.DELETE, value = "/tenants/{tenant}")
|
||||
@Transactional
|
||||
public ResponseEntity<Void> deleteTenant(@PathVariable final String tenant) {
|
||||
systemManagement.deleteTenant(tenant);
|
||||
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
|
||||
/**
|
||||
* Collects and returns system usage statistics. It provides a system wide
|
||||
* overview and tenant based stats.
|
||||
*
|
||||
* @return system usage statistics
|
||||
*/
|
||||
@RequestMapping(method = RequestMethod.GET, value = "/usage", produces = { "application/hal+json",
|
||||
MediaType.APPLICATION_JSON_VALUE })
|
||||
public ResponseEntity<SystemStatisticsRest> getSystemUsageStats() {
|
||||
final SystemUsageReport report = systemManagement.getSystemUsageStatistics();
|
||||
|
||||
final SystemStatisticsRest result = new SystemStatisticsRest().setOverallActions(report.getOverallActions())
|
||||
.setOverallArtifacts(report.getOverallArtifacts())
|
||||
.setOverallArtifactVolumeInBytes(report.getOverallArtifactVolumeInBytes())
|
||||
.setOverallTargets(report.getOverallTargets()).setOverallTenants(report.getTenants().size());
|
||||
|
||||
result.setTenantStats(report.getTenants().stream().map(tenant -> convertTenant(tenant))
|
||||
.collect(Collectors.toList()));
|
||||
|
||||
return ResponseEntity.ok(result);
|
||||
}
|
||||
|
||||
private static TenantSystemUsageRest convertTenant(final TenantUsage tenant) {
|
||||
final TenantSystemUsageRest result = new TenantSystemUsageRest(tenant.getTenantName());
|
||||
result.setActions(tenant.getActions());
|
||||
result.setArtifacts(tenant.getArtifacts());
|
||||
result.setOverallArtifactVolumeInBytes(tenant.getOverallArtifactVolumeInBytes());
|
||||
result.setTargets(tenant.getTargets());
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of all caches containing currently.
|
||||
*
|
||||
*
|
||||
* @return a list of caches for all tenants
|
||||
*/
|
||||
@RequestMapping(method = RequestMethod.GET, value = "/caches")
|
||||
@@ -83,7 +117,7 @@ public class SystemManagementResource {
|
||||
|
||||
/**
|
||||
* Invalidates all caches for all tenants.
|
||||
*
|
||||
*
|
||||
* @return a list of cache names which has been invalidated
|
||||
*/
|
||||
@RequestMapping(method = RequestMethod.DELETE, value = "/caches")
|
||||
@@ -98,7 +132,7 @@ public class SystemManagementResource {
|
||||
/**
|
||||
* Adds or updates a configuration for a specific tenant to the tenant
|
||||
* configuration.
|
||||
*
|
||||
*
|
||||
* @param configuration
|
||||
* the configuration value to add or update
|
||||
* @param key
|
||||
|
||||
@@ -0,0 +1,136 @@
|
||||
/**
|
||||
* Copyright (c) 2015 Bosch Software Innovations GmbH and others.
|
||||
*
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*/
|
||||
package org.eclipse.hawkbit.rest.resource;
|
||||
|
||||
import static org.springframework.hateoas.mvc.ControllerLinkBuilder.linkTo;
|
||||
import static org.springframework.hateoas.mvc.ControllerLinkBuilder.methodOn;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSetTag;
|
||||
import org.eclipse.hawkbit.repository.model.Tag;
|
||||
import org.eclipse.hawkbit.repository.model.TargetTag;
|
||||
import org.eclipse.hawkbit.rest.resource.model.tag.TagRequestBodyPut;
|
||||
import org.eclipse.hawkbit.rest.resource.model.tag.TagRest;
|
||||
import org.eclipse.hawkbit.rest.resource.model.tag.TagsRest;
|
||||
|
||||
/**
|
||||
* A mapper which maps repository model to RESTful model representation and
|
||||
* back.
|
||||
*
|
||||
*/
|
||||
final class TagMapper {
|
||||
private TagMapper() {
|
||||
// Utility class
|
||||
}
|
||||
|
||||
static TagsRest toResponse(final List<TargetTag> targetTags) {
|
||||
final TagsRest tagsRest = new TagsRest();
|
||||
if (targetTags == null) {
|
||||
return tagsRest;
|
||||
}
|
||||
|
||||
for (final TargetTag target : targetTags) {
|
||||
final TagRest response = toResponse(target);
|
||||
|
||||
tagsRest.add(response);
|
||||
}
|
||||
return tagsRest;
|
||||
}
|
||||
|
||||
static TagRest toResponse(final TargetTag targetTag) {
|
||||
final TagRest response = new TagRest();
|
||||
if (targetTag == null) {
|
||||
return response;
|
||||
}
|
||||
|
||||
mapTag(response, targetTag);
|
||||
|
||||
response.add(linkTo(methodOn(TargetTagResource.class).getTargetTag(targetTag.getId())).withRel("self"));
|
||||
|
||||
response.add(linkTo(methodOn(TargetTagResource.class).getAssignedTargets(targetTag.getId())).withRel(
|
||||
"assignedTargets"));
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
static TagsRest toResponseDistributionSetTag(final List<DistributionSetTag> distributionSetTags) {
|
||||
final TagsRest tagsRest = new TagsRest();
|
||||
if (distributionSetTags == null) {
|
||||
return tagsRest;
|
||||
}
|
||||
|
||||
for (final DistributionSetTag distributionSetTag : distributionSetTags) {
|
||||
final TagRest response = toResponse(distributionSetTag);
|
||||
|
||||
tagsRest.add(response);
|
||||
}
|
||||
return tagsRest;
|
||||
}
|
||||
|
||||
static TagRest toResponse(final DistributionSetTag distributionSetTag) {
|
||||
final TagRest response = new TagRest();
|
||||
if (distributionSetTag == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
mapTag(response, distributionSetTag);
|
||||
|
||||
response.add(linkTo(
|
||||
methodOn(DistributionSetTagResource.class).getDistributionSetTag(distributionSetTag.getId())).withRel(
|
||||
"self"));
|
||||
|
||||
response.add(linkTo(
|
||||
methodOn(DistributionSetTagResource.class).getAssignedDistributionSets(distributionSetTag.getId()))
|
||||
.withRel("assignedDistributionSets"));
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
static List<TargetTag> mapTargeTagFromRequest(final Iterable<TagRequestBodyPut> tags) {
|
||||
final List<TargetTag> mappedList = new ArrayList<>();
|
||||
for (final TagRequestBodyPut targetTagRest : tags) {
|
||||
mappedList.add(new TargetTag(targetTagRest.getName(), targetTagRest.getDescription(), targetTagRest
|
||||
.getColour()));
|
||||
}
|
||||
return mappedList;
|
||||
}
|
||||
|
||||
static List<DistributionSetTag> mapDistributionSetTagFromRequest(final Iterable<TagRequestBodyPut> tags) {
|
||||
final List<DistributionSetTag> mappedList = new ArrayList<>();
|
||||
for (final TagRequestBodyPut targetTagRest : tags) {
|
||||
mappedList.add(new DistributionSetTag(targetTagRest.getName(), targetTagRest.getDescription(),
|
||||
targetTagRest.getColour()));
|
||||
}
|
||||
return mappedList;
|
||||
}
|
||||
|
||||
private static void mapTag(final TagRest response, final Tag tag) {
|
||||
RestModelMapper.mapNamedToNamed(response, tag);
|
||||
response.setTagId(tag.getId());
|
||||
response.setColour(tag.getColour());
|
||||
}
|
||||
|
||||
static void updateTag(final TagRequestBodyPut response, final Tag tag) {
|
||||
if (response.getDescription() != null) {
|
||||
tag.setDescription(response.getDescription());
|
||||
}
|
||||
|
||||
if (response.getColour() != null) {
|
||||
tag.setColour(response.getColour());
|
||||
}
|
||||
|
||||
if (response.getName() != null) {
|
||||
tag.setName(response.getName());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
314
hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/TargetMapper.java
Executable file → Normal file
314
hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/TargetMapper.java
Executable file → Normal file
@@ -17,6 +17,7 @@ import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.hawkbit.repository.ActionFields;
|
||||
import org.eclipse.hawkbit.repository.model.Action;
|
||||
import org.eclipse.hawkbit.repository.model.ActionStatus;
|
||||
import org.eclipse.hawkbit.repository.model.Target;
|
||||
@@ -35,17 +36,198 @@ import org.eclipse.hawkbit.rest.resource.model.target.TargetsRest;
|
||||
* A mapper which maps repository model to RESTful model representation and
|
||||
* back.
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
final class TargetMapper {
|
||||
final public class TargetMapper {
|
||||
|
||||
private TargetMapper() {
|
||||
// Utility class
|
||||
}
|
||||
|
||||
/**
|
||||
* Add links to a target response.
|
||||
*
|
||||
* @param response
|
||||
* the target response
|
||||
*/
|
||||
public static void addTargetLinks(final TargetRest response) {
|
||||
response.add(linkTo(methodOn(TargetResource.class).getAssignedDistributionSet(response.getControllerId()))
|
||||
.withRel(RestConstants.TARGET_V1_ASSIGNED_DISTRIBUTION_SET));
|
||||
response.add(linkTo(methodOn(TargetResource.class).getInstalledDistributionSet(response.getControllerId()))
|
||||
.withRel(RestConstants.TARGET_V1_INSTALLED_DISTRIBUTION_SET));
|
||||
response.add(linkTo(methodOn(TargetResource.class).getAttributes(response.getControllerId())).withRel(
|
||||
RestConstants.TARGET_V1_ATTRIBUTES));
|
||||
response.add(linkTo(
|
||||
methodOn(TargetResource.class).getActionHistory(response.getControllerId(), 0,
|
||||
RestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT_VALUE,
|
||||
ActionFields.ID.getFieldName() + ":" + SortDirection.DESC, null)).withRel(
|
||||
RestConstants.TARGET_V1_ACTIONS));
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the pollstatus to a target response.
|
||||
*
|
||||
* @param target
|
||||
* the target
|
||||
* @param targetRest
|
||||
* the response
|
||||
*/
|
||||
public static void addPollStatus(final Target target, final TargetRest targetRest) {
|
||||
final PollStatus pollStatus = target.getTargetInfo().getPollStatus();
|
||||
if (pollStatus != null) {
|
||||
final PollStatusRest pollStatusRest = new PollStatusRest();
|
||||
pollStatusRest.setLastRequestAt(Date.from(
|
||||
pollStatus.getLastPollDate().atZone(ZoneId.systemDefault()).toInstant()).getTime());
|
||||
pollStatusRest.setNextExpectedRequestAt(Date.from(
|
||||
pollStatus.getNextPollDate().atZone(ZoneId.systemDefault()).toInstant()).getTime());
|
||||
pollStatusRest.setOverdue(pollStatus.isOverdue());
|
||||
targetRest.setPollStatus(pollStatusRest);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a response which includes links and pollstatus for all targets.
|
||||
*
|
||||
* @param targets
|
||||
* the targets
|
||||
* @return the response
|
||||
*/
|
||||
public static TargetsRest toResponseWithLinksAndPollStatus(final Iterable<Target> targets) {
|
||||
final TargetsRest mappedList = new TargetsRest();
|
||||
if (targets != null) {
|
||||
for (final Target target : targets) {
|
||||
final TargetRest response = toResponse(target);
|
||||
addPollStatus(target, response);
|
||||
addTargetLinks(response);
|
||||
mappedList.add(response);
|
||||
}
|
||||
}
|
||||
return mappedList;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a response for targets.
|
||||
*
|
||||
* @param targets
|
||||
* list of targets
|
||||
* @return the response
|
||||
*/
|
||||
public static TargetsRest toResponse(final Iterable<Target> targets) {
|
||||
final TargetsRest mappedList = new TargetsRest();
|
||||
if (targets != null) {
|
||||
for (final Target target : targets) {
|
||||
final TargetRest response = toResponse(target);
|
||||
mappedList.add(response);
|
||||
}
|
||||
}
|
||||
return mappedList;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a response for target.
|
||||
*
|
||||
* @param target
|
||||
* the target
|
||||
* @return the response
|
||||
*/
|
||||
public static TargetRest toResponse(final Target target) {
|
||||
if (target == null) {
|
||||
return null;
|
||||
}
|
||||
final TargetRest targetRest = new TargetRest();
|
||||
targetRest.setControllerId(target.getControllerId());
|
||||
targetRest.setDescription(target.getDescription());
|
||||
targetRest.setName(target.getName());
|
||||
targetRest.setUpdateStatus(getUpdateStatusName(target.getTargetInfo().getUpdateStatus()));
|
||||
|
||||
final URI address = target.getTargetInfo().getAddress();
|
||||
if (address != null) {
|
||||
targetRest.setIpAddress(address.getHost());
|
||||
targetRest.setAddress(address.toString());
|
||||
}
|
||||
|
||||
targetRest.setCreatedBy(target.getCreatedBy());
|
||||
targetRest.setLastModifiedBy(target.getLastModifiedBy());
|
||||
|
||||
targetRest.setCreatedAt(target.getCreatedAt());
|
||||
targetRest.setLastModifiedAt(target.getLastModifiedAt());
|
||||
|
||||
targetRest.setSecurityToken(target.getSecurityToken());
|
||||
|
||||
// last target query is the last controller request date
|
||||
final Long lastTargetQuery = target.getTargetInfo().getLastTargetQuery();
|
||||
final Long installationDate = target.getTargetInfo().getInstallationDate();
|
||||
|
||||
if (lastTargetQuery != null) {
|
||||
targetRest.setLastControllerRequestAt(lastTargetQuery);
|
||||
}
|
||||
if (installationDate != null) {
|
||||
targetRest.setInstalledAt(installationDate);
|
||||
}
|
||||
|
||||
targetRest.add(linkTo(methodOn(TargetResource.class).getTarget(target.getControllerId())).withRel("self"));
|
||||
|
||||
return targetRest;
|
||||
}
|
||||
|
||||
static List<Target> fromRequest(final Iterable<TargetRequestBody> targetsRest) {
|
||||
final List<Target> mappedList = new ArrayList<>();
|
||||
for (final TargetRequestBody targetRest : targetsRest) {
|
||||
mappedList.add(fromRequest(targetRest));
|
||||
}
|
||||
return mappedList;
|
||||
}
|
||||
|
||||
static Target fromRequest(final TargetRequestBody targetRest) {
|
||||
final Target target = new Target(targetRest.getControllerId());
|
||||
target.setDescription(targetRest.getDescription());
|
||||
target.setName(targetRest.getName());
|
||||
return target;
|
||||
}
|
||||
|
||||
static ActionStatussRest toActionStatusRestResponse(final Action action, final List<ActionStatus> actionStatus) {
|
||||
final ActionStatussRest mappedList = new ActionStatussRest();
|
||||
|
||||
if (actionStatus != null) {
|
||||
for (final ActionStatus status : actionStatus) {
|
||||
final ActionStatusRest response = toResponse(action, status);
|
||||
mappedList.add(response);
|
||||
}
|
||||
}
|
||||
|
||||
return mappedList;
|
||||
}
|
||||
|
||||
static ActionRest toResponse(final String targetId, final Action action, final boolean isActive) {
|
||||
final ActionRest result = new ActionRest();
|
||||
|
||||
result.setActionId(action.getId());
|
||||
result.setType(getType(action));
|
||||
|
||||
if (isActive) {
|
||||
result.setStatus(ActionRest.ACTION_PENDING);
|
||||
} else {
|
||||
result.setStatus(ActionRest.ACTION_FINISHED);
|
||||
}
|
||||
|
||||
RestModelMapper.mapBaseToBase(result, action);
|
||||
|
||||
result.add(linkTo(methodOn(TargetResource.class).getAction(targetId, action.getId())).withRel("self"));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static ActionsRest toResponse(final String targetId, final List<Action> actions) {
|
||||
final ActionsRest mappedList = new ActionsRest();
|
||||
|
||||
for (final Action action : actions) {
|
||||
final ActionRest response = toResponse(targetId, action, action.isActive());
|
||||
mappedList.add(response);
|
||||
}
|
||||
return mappedList;
|
||||
}
|
||||
|
||||
private static String getNameOfActionStatusType(final Action.Status type) {
|
||||
String result = null;
|
||||
String result;
|
||||
|
||||
switch (type) {
|
||||
case CANCELED:
|
||||
@@ -86,7 +268,7 @@ final class TargetMapper {
|
||||
}
|
||||
|
||||
private static String getUpdateStatusName(final TargetUpdateStatus updatestatus) {
|
||||
String result = null;
|
||||
String result;
|
||||
|
||||
switch (updatestatus) {
|
||||
case ERROR:
|
||||
@@ -111,87 +293,6 @@ final class TargetMapper {
|
||||
return result;
|
||||
}
|
||||
|
||||
static ActionRest toResponse(final String targetId, final Action action, final boolean isActive) {
|
||||
final ActionRest result = new ActionRest();
|
||||
|
||||
result.setActionId(action.getId());
|
||||
result.setType(getType(action));
|
||||
|
||||
if (isActive) {
|
||||
result.setStatus(ActionRest.ACTION_PENDING);
|
||||
} else {
|
||||
result.setStatus(ActionRest.ACTION_FINISHED);
|
||||
}
|
||||
|
||||
RestModelMapper.mapBaseToBase(result, action);
|
||||
|
||||
result.add(linkTo(methodOn(TargetResource.class).getAction(targetId, action.getId())).withRel("self"));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static ActionsRest toResponse(final String targetId, final List<Action> actions) {
|
||||
final ActionsRest mappedList = new ActionsRest();
|
||||
|
||||
for (final Action action : actions) {
|
||||
final ActionRest response = toResponse(targetId, action, action.isActive());
|
||||
mappedList.add(response);
|
||||
}
|
||||
return mappedList;
|
||||
}
|
||||
|
||||
static TargetRest toResponse(final Target target, final boolean includePollStatus) {
|
||||
if (target == null) {
|
||||
return null;
|
||||
}
|
||||
final TargetRest targetRest = new TargetRest();
|
||||
targetRest.setControllerId(target.getControllerId());
|
||||
targetRest.setDescription(target.getDescription());
|
||||
targetRest.setName(target.getName());
|
||||
targetRest.setUpdateStatus(getUpdateStatusName(target.getTargetInfo().getUpdateStatus()));
|
||||
|
||||
final URI address = target.getTargetInfo().getAddress();
|
||||
if (address != null) {
|
||||
targetRest.setIpAddress(address.getHost());
|
||||
targetRest.setAddress(address.toString());
|
||||
}
|
||||
|
||||
targetRest.setCreatedBy(target.getCreatedBy());
|
||||
targetRest.setLastModifiedBy(target.getLastModifiedBy());
|
||||
|
||||
targetRest.setCreatedAt(target.getCreatedAt());
|
||||
targetRest.setLastModifiedAt(target.getLastModifiedAt());
|
||||
|
||||
targetRest.setSecurityToken(target.getSecurityToken());
|
||||
|
||||
// last target query is the last controller request date
|
||||
final Long lastTargetQuery = target.getTargetInfo().getLastTargetQuery();
|
||||
final Long installationDate = target.getTargetInfo().getInstallationDate();
|
||||
|
||||
if (lastTargetQuery != null) {
|
||||
targetRest.setLastControllerRequestAt(lastTargetQuery);
|
||||
}
|
||||
if (installationDate != null) {
|
||||
targetRest.setInstalledAt(installationDate);
|
||||
}
|
||||
|
||||
if (includePollStatus) {
|
||||
final PollStatus pollStatus = target.getTargetInfo().getPollStatus();
|
||||
if (pollStatus != null) {
|
||||
final PollStatusRest pollStatusRest = new PollStatusRest();
|
||||
pollStatusRest.setLastRequestAt(
|
||||
Date.from(pollStatus.getLastPollDate().atZone(ZoneId.systemDefault()).toInstant()).getTime());
|
||||
pollStatusRest.setNextExpectedRequestAt(
|
||||
Date.from(pollStatus.getNextPollDate().atZone(ZoneId.systemDefault()).toInstant()).getTime());
|
||||
pollStatusRest.setOverdue(pollStatus.isOverdue());
|
||||
targetRest.setPollStatus(pollStatusRest);
|
||||
}
|
||||
}
|
||||
targetRest.add(linkTo(methodOn(TargetResource.class).getTarget(target.getControllerId())).withRel("self"));
|
||||
|
||||
return targetRest;
|
||||
}
|
||||
|
||||
private static ActionStatusRest toResponse(final Action action, final ActionStatus actionStatus) {
|
||||
final ActionStatusRest result = new ActionStatusRest();
|
||||
|
||||
@@ -203,43 +304,4 @@ final class TargetMapper {
|
||||
return result;
|
||||
}
|
||||
|
||||
static List<Target> fromRequest(final Iterable<TargetRequestBody> targetsRest) {
|
||||
final List<Target> mappedList = new ArrayList<>();
|
||||
for (final TargetRequestBody targetRest : targetsRest) {
|
||||
mappedList.add(fromRequest(targetRest));
|
||||
}
|
||||
return mappedList;
|
||||
}
|
||||
|
||||
static Target fromRequest(final TargetRequestBody targetRest) {
|
||||
final Target target = new Target(targetRest.getControllerId());
|
||||
target.setDescription(targetRest.getDescription());
|
||||
target.setName(targetRest.getName());
|
||||
return target;
|
||||
}
|
||||
|
||||
static ActionStatussRest toActionStatusRestResponse(final Action action, final List<ActionStatus> actionStatus) {
|
||||
final ActionStatussRest mappedList = new ActionStatussRest();
|
||||
|
||||
if (actionStatus != null) {
|
||||
for (final ActionStatus status : actionStatus) {
|
||||
final ActionStatusRest response = toResponse(action, status);
|
||||
mappedList.add(response);
|
||||
}
|
||||
}
|
||||
|
||||
return mappedList;
|
||||
}
|
||||
|
||||
static TargetsRest toResponse(final Iterable<Target> targets) {
|
||||
final TargetsRest mappedList = new TargetsRest();
|
||||
if (targets != null) {
|
||||
for (final Target target : targets) {
|
||||
// to single response without pollstatus in the list
|
||||
final TargetRest response = toResponse(target, false);
|
||||
mappedList.add(response);
|
||||
}
|
||||
}
|
||||
return mappedList;
|
||||
}
|
||||
}
|
||||
|
||||
135
hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/TargetResource.java
Executable file → Normal file
135
hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/TargetResource.java
Executable file → Normal file
@@ -10,11 +10,6 @@ package org.eclipse.hawkbit.rest.resource;
|
||||
|
||||
import static org.springframework.hateoas.mvc.ControllerLinkBuilder.linkTo;
|
||||
import static org.springframework.hateoas.mvc.ControllerLinkBuilder.methodOn;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.annotations.ApiParam;
|
||||
import io.swagger.annotations.ApiResponse;
|
||||
import io.swagger.annotations.ApiResponses;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
@@ -22,7 +17,6 @@ import java.util.Map;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
|
||||
import org.eclipse.hawkbit.im.authentication.SpPermission;
|
||||
import org.eclipse.hawkbit.repository.ActionFields;
|
||||
import org.eclipse.hawkbit.repository.ActionStatusFields;
|
||||
import org.eclipse.hawkbit.repository.DeploymentManagement;
|
||||
@@ -36,7 +30,6 @@ import org.eclipse.hawkbit.repository.model.ActionStatus;
|
||||
import org.eclipse.hawkbit.repository.model.Target;
|
||||
import org.eclipse.hawkbit.repository.rsql.RSQLUtility;
|
||||
import org.eclipse.hawkbit.rest.resource.helper.RestResourceConversionHelper;
|
||||
import org.eclipse.hawkbit.rest.resource.model.ExceptionInfo;
|
||||
import org.eclipse.hawkbit.rest.resource.model.action.ActionPagedList;
|
||||
import org.eclipse.hawkbit.rest.resource.model.action.ActionRest;
|
||||
import org.eclipse.hawkbit.rest.resource.model.action.ActionStatusPagedList;
|
||||
@@ -58,7 +51,6 @@ import org.springframework.data.jpa.domain.Specification;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
@@ -74,9 +66,7 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
*
|
||||
*/
|
||||
@RestController
|
||||
@Transactional(readOnly = true)
|
||||
@RequestMapping(RestConstants.TARGET_V1_REQUEST_MAPPING)
|
||||
@Api(value = "targets", description = "Provisioning Target Management API")
|
||||
public class TargetResource {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(TargetResource.class);
|
||||
|
||||
@@ -100,25 +90,12 @@ public class TargetResource {
|
||||
*/
|
||||
@RequestMapping(method = RequestMethod.GET, value = "/{targetId}", produces = { "application/hal+json",
|
||||
MediaType.APPLICATION_JSON_VALUE })
|
||||
@ApiOperation(response = TargetRest.class, value = "Get single Target", notes = "Handles the GET request of retrieving a single target within SP. Required Permission: "
|
||||
+ SpPermission.READ_TARGET)
|
||||
@ApiResponses(@ApiResponse(code = 404, message = "Not Found Target", response = ExceptionInfo.class))
|
||||
public ResponseEntity<TargetRest> getTarget(@PathVariable final String targetId) {
|
||||
final Target findTarget = findTargetWithExceptionIfNotFound(targetId);
|
||||
// to single response include poll status
|
||||
final TargetRest response = TargetMapper.toResponse(findTarget, true);
|
||||
// add links
|
||||
response.add(linkTo(methodOn(TargetResource.class).getAssignedDistributionSet(response.getControllerId()))
|
||||
.withRel(RestConstants.TARGET_V1_ASSIGNED_DISTRIBUTION_SET));
|
||||
response.add(linkTo(methodOn(TargetResource.class).getInstalledDistributionSet(response.getControllerId()))
|
||||
.withRel(RestConstants.TARGET_V1_INSTALLED_DISTRIBUTION_SET));
|
||||
response.add(linkTo(methodOn(TargetResource.class).getAttributes(response.getControllerId())).withRel(
|
||||
RestConstants.TARGET_V1_ATTRIBUTES));
|
||||
response.add(linkTo(
|
||||
methodOn(TargetResource.class).getActionHistory(response.getControllerId(), 0,
|
||||
RestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT_VALUE,
|
||||
ActionFields.ID.getFieldName() + ":" + SortDirection.DESC, null)).withRel(
|
||||
RestConstants.TARGET_V1_ACTIONS));
|
||||
final TargetRest response = TargetMapper.toResponse(findTarget);
|
||||
TargetMapper.addPollStatus(findTarget, response);
|
||||
TargetMapper.addTargetLinks(response);
|
||||
|
||||
return new ResponseEntity<>(response, HttpStatus.OK);
|
||||
}
|
||||
@@ -143,20 +120,11 @@ public class TargetResource {
|
||||
* JsonResponseExceptionHandler is handling the response.
|
||||
*/
|
||||
@RequestMapping(method = RequestMethod.GET, produces = { "application/hal+json", MediaType.APPLICATION_JSON_VALUE })
|
||||
@ApiOperation(response = TargetPagedList.class, value = "Get paged list of Targets", notes = "Handles the GET request of retrieving all targets within SP. Required Permission: "
|
||||
+ SpPermission.READ_TARGET)
|
||||
public ResponseEntity<TargetPagedList> getTargets(
|
||||
@RequestParam(value = RestConstants.REQUEST_PARAMETER_PAGING_OFFSET, defaultValue = RestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET) final int pagingOffsetParam,
|
||||
@RequestParam(value = RestConstants.REQUEST_PARAMETER_PAGING_LIMIT, defaultValue = RestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT) final int pagingLimitParam,
|
||||
@RequestParam(value = RestConstants.REQUEST_PARAMETER_SORTING, required = false) final String sortParam,
|
||||
@ApiParam(required = false, value = "FIQL syntax search query"
|
||||
+ "<table border=0>"
|
||||
+ "<tr><td>updatestatus==unknown,updatestatus==error</td><td>targets with status 'unknown' or 'error'</td></tr>"
|
||||
+ "<tr><td>installedAt=ge=1424699220</td><td>targets which installation date later than 1424699220</td></tr>"
|
||||
+ "<tr><td>name=li=%25ccu%25</td><td>targets which contain 'ccu' in their name ingore case</td></tr>"
|
||||
+ "<tr><td>controllerId==target0815</td><td>target which has the ID 'target0815'</td></tr>"
|
||||
+ "<tr><td>ipaddress=li=171.%25</td><td>target which starts with IP address '171.'</td></tr>"
|
||||
+ "</table>") @RequestParam(value = RestConstants.REQUEST_PARAMETER_SEARCH, required = false) final String rsqlParam) {
|
||||
@RequestParam(value = RestConstants.REQUEST_PARAMETER_SEARCH, required = false) final String rsqlParam) {
|
||||
|
||||
final int sanitizedOffsetParam = PagingUtility.sanitizeOffsetParam(pagingOffsetParam);
|
||||
final int sanitizedLimitParam = PagingUtility.sanitizePageLimitParam(pagingLimitParam);
|
||||
@@ -193,19 +161,10 @@ public class TargetResource {
|
||||
*/
|
||||
@RequestMapping(method = RequestMethod.POST, consumes = { "application/hal+json", MediaType.APPLICATION_JSON_VALUE }, produces = {
|
||||
"application/hal+json", MediaType.APPLICATION_JSON_VALUE })
|
||||
@ApiOperation(response = TargetsRest.class, value = "Create list of Targets", notes = "Handles the POST request of creating new targets within SP. The request body must always be a list of targets. Required Permission: "
|
||||
+ SpPermission.CREATE_TARGET)
|
||||
@ApiResponses(@ApiResponse(code = 409, message = "Conflict", response = ExceptionInfo.class))
|
||||
@Transactional
|
||||
public ResponseEntity<TargetsRest> createTargets(
|
||||
@RequestBody @ApiParam(value = "List of targets", required = true) final List<TargetRequestBody> targets) {
|
||||
public ResponseEntity<TargetsRest> createTargets(@RequestBody final List<TargetRequestBody> targets) {
|
||||
LOG.debug("creating {} targets", targets.size());
|
||||
final Iterable<Target> createdTargets = targetManagement.createTargets(TargetMapper.fromRequest(targets));
|
||||
LOG.debug("{} targets created, return status {}", targets.size(), HttpStatus.CREATED);
|
||||
|
||||
// we flush to ensure that entity is generated and we can return ID etc.
|
||||
entityManager.flush();
|
||||
|
||||
return new ResponseEntity<>(TargetMapper.toResponse(createdTargets), HttpStatus.CREATED);
|
||||
}
|
||||
|
||||
@@ -213,7 +172,7 @@ public class TargetResource {
|
||||
* Handles the PUT request of updating a target within SP. The ID is within
|
||||
* the URL path of the request. A given ID in the request body is ignored.
|
||||
* It's not possible to set fields to {@code null} values.
|
||||
*
|
||||
*
|
||||
* @param targetId
|
||||
* the path parameter which contains the ID of the target
|
||||
* @param targetRest
|
||||
@@ -225,12 +184,8 @@ public class TargetResource {
|
||||
*/
|
||||
@RequestMapping(method = RequestMethod.PUT, value = "/{targetId}", consumes = { "application/hal+json",
|
||||
MediaType.APPLICATION_JSON_VALUE }, produces = { "application/hal+json", MediaType.APPLICATION_JSON_VALUE })
|
||||
@ApiOperation(response = TargetRest.class, value = "Updates a target", notes = "Handles the PUT request of updating a target within SP. Required Permission: "
|
||||
+ SpPermission.UPDATE_TARGET)
|
||||
@ApiResponses(@ApiResponse(code = 404, message = "Not Found Target", response = ExceptionInfo.class))
|
||||
@Transactional
|
||||
public ResponseEntity<TargetRest> updateTarget(@PathVariable final String targetId,
|
||||
@RequestBody @ApiParam(value = "Target to be updated", required = true) final TargetRequestBody targetRest) {
|
||||
@RequestBody final TargetRequestBody targetRest) {
|
||||
final Target existingTarget = findTargetWithExceptionIfNotFound(targetId);
|
||||
LOG.debug("updating target {}", existingTarget.getId());
|
||||
if (targetRest.getDescription() != null) {
|
||||
@@ -240,17 +195,13 @@ public class TargetResource {
|
||||
existingTarget.setName(targetRest.getName());
|
||||
}
|
||||
final Target updateTarget = targetManagement.updateTarget(existingTarget);
|
||||
LOG.debug("target {} updated, return status {}", updateTarget.getId(), HttpStatus.OK);
|
||||
|
||||
// we flush to ensure that entity is generated and we can return ID etc.
|
||||
entityManager.flush();
|
||||
|
||||
return new ResponseEntity<>(TargetMapper.toResponse(updateTarget, false), HttpStatus.OK);
|
||||
return new ResponseEntity<>(TargetMapper.toResponse(updateTarget), HttpStatus.OK);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the DELETE request of deleting a target within SP.
|
||||
*
|
||||
*
|
||||
* @param targetId
|
||||
* the ID of the target to be deleted
|
||||
* @return If the given targetId could exists and could be deleted Http OK.
|
||||
@@ -259,10 +210,6 @@ public class TargetResource {
|
||||
*/
|
||||
@RequestMapping(method = RequestMethod.DELETE, value = "/{targetId}", produces = { "application/hal+json",
|
||||
MediaType.APPLICATION_JSON_VALUE })
|
||||
@ApiOperation(value = "Deletes a target", notes = "Handles the DELETE request of deleting a single target within SP. Required Permission: "
|
||||
+ SpPermission.DELETE_TARGET)
|
||||
@ApiResponses(@ApiResponse(code = 404, message = "Not Found Target", response = ExceptionInfo.class))
|
||||
@Transactional
|
||||
public ResponseEntity<Void> deleteTarget(@PathVariable final String targetId) {
|
||||
final Target target = findTargetWithExceptionIfNotFound(targetId);
|
||||
targetManagement.deleteTargets(target.getId());
|
||||
@@ -282,9 +229,6 @@ public class TargetResource {
|
||||
*/
|
||||
@RequestMapping(method = RequestMethod.GET, value = "/{targetId}/attributes", produces = { "application/hal+json",
|
||||
MediaType.APPLICATION_JSON_VALUE })
|
||||
@ApiOperation(response = TargetAttributes.class, value = "Get attributes of Target", notes = "Handles the GET request of retrieving the attributes of a specific target. Reponse is a key/value list. Required Permission: "
|
||||
+ SpPermission.READ_TARGET)
|
||||
@ApiResponses(@ApiResponse(code = 404, message = "Not Found Target", response = ExceptionInfo.class))
|
||||
public ResponseEntity<TargetAttributes> getAttributes(@PathVariable final String targetId) {
|
||||
final Target foundTarget = findTargetWithExceptionIfNotFound(targetId);
|
||||
final Map<String, String> controllerAttributes = foundTarget.getTargetInfo().getControllerAttributes();
|
||||
@@ -323,18 +267,12 @@ public class TargetResource {
|
||||
*/
|
||||
@RequestMapping(method = RequestMethod.GET, value = "/{targetId}/actions", produces = { "application/hal+json",
|
||||
MediaType.APPLICATION_JSON_VALUE })
|
||||
@ApiOperation(response = ActionPagedList.class, value = "List all actions of Target", notes = "Handles the GET request of retrieving the full action history of a specific target. Required Permission: "
|
||||
+ SpPermission.READ_TARGET)
|
||||
@ApiResponses(@ApiResponse(code = 404, message = "Not Found Target", response = ExceptionInfo.class))
|
||||
public ResponseEntity<ActionPagedList> getActionHistory(
|
||||
@PathVariable final String targetId,
|
||||
@RequestParam(value = RestConstants.REQUEST_PARAMETER_PAGING_OFFSET, defaultValue = RestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET) final int pagingOffsetParam,
|
||||
@RequestParam(value = RestConstants.REQUEST_PARAMETER_PAGING_LIMIT, defaultValue = RestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT) final int pagingLimitParam,
|
||||
@RequestParam(value = RestConstants.REQUEST_PARAMETER_SORTING, required = false) final String sortParam,
|
||||
@ApiParam(required = false, value = "FIQL syntax search query" + "<table border=0>"
|
||||
+ "<tr><td>status==finished</td><td>actions which are already 'finished'</td></tr>"
|
||||
+ "<tr><td>status==pending</td><td>actions which are currently in 'pending' state</td></tr>"
|
||||
+ "</table>") @RequestParam(value = RestConstants.REQUEST_PARAMETER_SEARCH, required = false) final String rsqlParam) {
|
||||
@RequestParam(value = RestConstants.REQUEST_PARAMETER_SEARCH, required = false) final String rsqlParam) {
|
||||
|
||||
final Target foundTarget = findTargetWithExceptionIfNotFound(targetId);
|
||||
|
||||
@@ -354,8 +292,8 @@ public class TargetResource {
|
||||
totalActionCount = deploymentManagement.countActionsByTarget(foundTarget);
|
||||
}
|
||||
|
||||
return new ResponseEntity<ActionPagedList>(new ActionPagedList(TargetMapper.toResponse(targetId,
|
||||
activeActions.getContent()), totalActionCount), HttpStatus.OK);
|
||||
return new ResponseEntity<>(new ActionPagedList(TargetMapper.toResponse(targetId, activeActions.getContent()),
|
||||
totalActionCount), HttpStatus.OK);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -370,9 +308,6 @@ public class TargetResource {
|
||||
*/
|
||||
@RequestMapping(method = RequestMethod.GET, value = "/{targetId}/actions/{actionId}", produces = {
|
||||
"application/hal+json", MediaType.APPLICATION_JSON_VALUE })
|
||||
@ApiOperation(response = ActionRest.class, value = "Get assigned action of Target", notes = "Handles the GET request of retrieving a specific action on a specific target. Required Permission: "
|
||||
+ SpPermission.READ_TARGET)
|
||||
@ApiResponses(@ApiResponse(code = 404, message = "Not Found Target or Action", response = ExceptionInfo.class))
|
||||
public ResponseEntity<ActionRest> getAction(@PathVariable final String targetId, @PathVariable final Long actionId) {
|
||||
final Target target = findTargetWithExceptionIfNotFound(targetId);
|
||||
|
||||
@@ -399,17 +334,19 @@ public class TargetResource {
|
||||
ActionStatusFields.ID.getFieldName() + ":" + SortDirection.DESC)).withRel(
|
||||
RestConstants.TARGET_V1_ACTION_STATUS));
|
||||
|
||||
return new ResponseEntity<ActionRest>(result, HttpStatus.OK);
|
||||
return new ResponseEntity<>(result, HttpStatus.OK);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the DELETE request of canceling an specific {@link Action}s of a
|
||||
* specific {@link Target}.
|
||||
*
|
||||
*
|
||||
* @param targetId
|
||||
* the ID of the target in the URL path parameter
|
||||
* @param actionId
|
||||
* the ID of the action in the URL path parameter
|
||||
* @param force
|
||||
* optional parameter, which indicates a force cancel
|
||||
* @return status no content in case cancellation was successful
|
||||
* @throws CancelActionNotAllowedException
|
||||
* if the given action is not active and cannot be canceled.
|
||||
@@ -417,20 +354,20 @@ public class TargetResource {
|
||||
* if the target or the action is not found
|
||||
*/
|
||||
@RequestMapping(method = RequestMethod.DELETE, value = "/{targetId}/actions/{actionId}")
|
||||
@ApiOperation(value = "Cancels an active action", notes = "Cancels an active action, only active actions can be deleted. Required Permission: "
|
||||
+ SpPermission.UPDATE_TARGET)
|
||||
@ApiResponses(@ApiResponse(code = 404, message = "Not Found Target or Action", response = ExceptionInfo.class))
|
||||
public ResponseEntity<Void> cancelAction(@PathVariable final String targetId, @PathVariable final Long actionId) {
|
||||
public ResponseEntity<Void> cancelAction(@PathVariable final String targetId, @PathVariable final Long actionId,
|
||||
@RequestParam(required = false, defaultValue = "false") final boolean force) {
|
||||
final Target target = findTargetWithExceptionIfNotFound(targetId);
|
||||
final Action action = findActionWithExceptionIfNotFound(actionId);
|
||||
|
||||
// cancel action will throw an exception if action cannot be canceled
|
||||
// which is mapped by
|
||||
// response exception handler.
|
||||
deploymentManagement.cancelAction(action, target);
|
||||
|
||||
return new ResponseEntity<Void>(HttpStatus.NO_CONTENT);
|
||||
if (force) {
|
||||
deploymentManagement.forceQuitAction(action, target);
|
||||
} else {
|
||||
deploymentManagement.cancelAction(action, target);
|
||||
}
|
||||
// both functions will throw an exception, when action is in wrong
|
||||
// state, which is mapped by ResponseExceptionHandler.
|
||||
|
||||
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -457,9 +394,6 @@ public class TargetResource {
|
||||
*/
|
||||
@RequestMapping(method = RequestMethod.GET, value = "/{targetId}/actions/{actionId}/status", produces = {
|
||||
"application/hal+json", MediaType.APPLICATION_JSON_VALUE })
|
||||
@ApiOperation(response = ActionStatusPagedList.class, value = "Get assigned action of Target", notes = "Handles the GET request of retrieving a specific action on a specific target. Required Permission: "
|
||||
+ SpPermission.READ_TARGET)
|
||||
@ApiResponses(@ApiResponse(code = 404, message = "Not Found Target or Action", response = ExceptionInfo.class))
|
||||
public ResponseEntity<ActionStatusPagedList> getActionStatusList(
|
||||
@PathVariable final String targetId,
|
||||
@PathVariable final Long actionId,
|
||||
@@ -500,9 +434,6 @@ public class TargetResource {
|
||||
*/
|
||||
@RequestMapping(method = RequestMethod.GET, value = "/{targetId}/assignedDS", produces = { "application/hal+json",
|
||||
MediaType.APPLICATION_JSON_VALUE })
|
||||
@ApiOperation(response = DistributionSetRest.class, value = "Get assigned Distribution Set of Target", notes = "Handles the GET request of retrieving the assigned distribution set of an specific target. Required Permission: "
|
||||
+ SpPermission.READ_TARGET)
|
||||
@ApiResponses(@ApiResponse(code = 404, message = "Not Found Target", response = ExceptionInfo.class))
|
||||
public ResponseEntity<DistributionSetRest> getAssignedDistributionSet(@PathVariable final String targetId) {
|
||||
final Target findTarget = findTargetWithExceptionIfNotFound(targetId);
|
||||
final DistributionSetRest distributionSetRest = DistributionSetMapper.toResponse(findTarget
|
||||
@@ -531,13 +462,8 @@ public class TargetResource {
|
||||
*/
|
||||
@RequestMapping(method = RequestMethod.POST, value = "/{targetId}/assignedDS", consumes = { "application/hal+json",
|
||||
MediaType.APPLICATION_JSON_VALUE }, produces = { "application/hal+json", MediaType.APPLICATION_JSON_VALUE })
|
||||
@ApiOperation(response = Void.class, value = "Assigned Distribution Set to Target", notes = "Handles the POST request for assigning a distribution set to a specific target. Required Permission: "
|
||||
+ SpPermission.READ_REPOSITORY + " and " + SpPermission.UPDATE_TARGET)
|
||||
@ApiResponses(@ApiResponse(code = 404, message = "Not Found Target", response = ExceptionInfo.class))
|
||||
@Transactional
|
||||
public ResponseEntity<Void> postAssignedDistributionSet(
|
||||
@PathVariable final String targetId,
|
||||
@RequestBody @ApiParam(value = "Distribution Set ID", required = true) final DistributionSetAssigmentRest dsId) {
|
||||
public ResponseEntity<Void> postAssignedDistributionSet(@PathVariable final String targetId,
|
||||
@RequestBody final DistributionSetAssigmentRest dsId) {
|
||||
|
||||
findTargetWithExceptionIfNotFound(targetId);
|
||||
final ActionType type = (dsId.getType() != null) ? RestResourceConversionHelper.convertActionType(dsId
|
||||
@@ -558,7 +484,7 @@ public class TargetResource {
|
||||
/**
|
||||
* Handles the GET request of retrieving the installed distribution set of
|
||||
* an specific target.
|
||||
*
|
||||
*
|
||||
* @param targetId
|
||||
* the ID of the target to retrieve
|
||||
* @return the assigned installed set with status OK, if none is installed
|
||||
@@ -568,9 +494,6 @@ public class TargetResource {
|
||||
*/
|
||||
@RequestMapping(method = RequestMethod.GET, value = "/{targetId}/installedDS", produces = { "application/hal+json",
|
||||
MediaType.APPLICATION_JSON_VALUE })
|
||||
@ApiOperation(response = DistributionSetRest.class, value = "Get installed Distribution Set of Target", notes = "Handles the GET request of retrieving the installed distribution set of an specific target. Required Permission: "
|
||||
+ SpPermission.READ_TARGET)
|
||||
@ApiResponses(@ApiResponse(code = 404, message = "Not Found Target", response = ExceptionInfo.class))
|
||||
public ResponseEntity<DistributionSetRest> getInstalledDistributionSet(@PathVariable final String targetId) {
|
||||
final Target findTarget = findTargetWithExceptionIfNotFound(targetId);
|
||||
final DistributionSetRest distributionSetRest = DistributionSetMapper.toResponse(findTarget.getTargetInfo()
|
||||
|
||||
@@ -0,0 +1,320 @@
|
||||
/**
|
||||
* Copyright (c) 2015 Bosch Software Innovations GmbH and others.
|
||||
*
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*/
|
||||
package org.eclipse.hawkbit.rest.resource;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
|
||||
import org.eclipse.hawkbit.repository.TagFields;
|
||||
import org.eclipse.hawkbit.repository.TagManagement;
|
||||
import org.eclipse.hawkbit.repository.TargetManagement;
|
||||
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
|
||||
import org.eclipse.hawkbit.repository.model.Target;
|
||||
import org.eclipse.hawkbit.repository.model.TargetTag;
|
||||
import org.eclipse.hawkbit.repository.model.TargetTagAssigmentResult;
|
||||
import org.eclipse.hawkbit.repository.rsql.RSQLUtility;
|
||||
import org.eclipse.hawkbit.rest.resource.model.tag.AssignedTargetRequestBody;
|
||||
import org.eclipse.hawkbit.rest.resource.model.tag.TagPagedList;
|
||||
import org.eclipse.hawkbit.rest.resource.model.tag.TagRequestBodyPut;
|
||||
import org.eclipse.hawkbit.rest.resource.model.tag.TagRest;
|
||||
import org.eclipse.hawkbit.rest.resource.model.tag.TagsRest;
|
||||
import org.eclipse.hawkbit.rest.resource.model.tag.TargetTagAssigmentResultRest;
|
||||
import org.eclipse.hawkbit.rest.resource.model.target.TargetsRest;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.domain.Slice;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* REST Resource handling for {@link Tag} CRUD operations.
|
||||
*
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping(RestConstants.TARGET_TAG_V1_REQUEST_MAPPING)
|
||||
public class TargetTagResource {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(TargetTagResource.class);
|
||||
private static final String TARGET_TAG_TAGERTS_REQUEST_MAPPING = RestConstants.TARGET_TAG_TAGERTS_REQUEST_MAPPING;
|
||||
|
||||
@Autowired
|
||||
private TagManagement tagManagement;
|
||||
|
||||
@Autowired
|
||||
private TargetManagement targetManagement;
|
||||
|
||||
@Autowired
|
||||
private EntityManager entityManager;
|
||||
|
||||
/**
|
||||
* Handles the GET request of retrieving all target tags.
|
||||
*
|
||||
* @param pagingOffsetParam
|
||||
* the offset of list of target tags for pagination, might not be
|
||||
* present in the rest request then default value will be applied
|
||||
* @param pagingLimitParam
|
||||
* the limit of the paged request, might not be present in the
|
||||
* rest request then default value will be applied
|
||||
* @param sortParam
|
||||
* the sorting parameter in the request URL, syntax
|
||||
* {@code field:direction, field:direction}
|
||||
* @param rsqlParam
|
||||
* the search parameter in the request URL, syntax
|
||||
* {@code q=name==abc}
|
||||
* @return a list of all target tags for a defined or default page request
|
||||
* with status OK. The response is always paged. In any failure the
|
||||
* JsonResponseExceptionHandler is handling the response.
|
||||
*/
|
||||
@RequestMapping(method = RequestMethod.GET, produces = { "application/hal+json", MediaType.APPLICATION_JSON_VALUE })
|
||||
public ResponseEntity<TagPagedList> getTargetTags(
|
||||
@RequestParam(value = RestConstants.REQUEST_PARAMETER_PAGING_OFFSET, defaultValue = RestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET) final int pagingOffsetParam,
|
||||
@RequestParam(value = RestConstants.REQUEST_PARAMETER_PAGING_LIMIT, defaultValue = RestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT) final int pagingLimitParam,
|
||||
@RequestParam(value = RestConstants.REQUEST_PARAMETER_SORTING, required = false) final String sortParam,
|
||||
@RequestParam(value = RestConstants.REQUEST_PARAMETER_SEARCH, required = false) final String rsqlParam) {
|
||||
|
||||
final int sanitizedOffsetParam = PagingUtility.sanitizeOffsetParam(pagingOffsetParam);
|
||||
final int sanitizedLimitParam = PagingUtility.sanitizePageLimitParam(pagingLimitParam);
|
||||
final Sort sorting = PagingUtility.sanitizeTargetSortParam(sortParam);
|
||||
|
||||
final Pageable pageable = new OffsetBasedPageRequest(sanitizedOffsetParam, sanitizedLimitParam, sorting);
|
||||
final Slice<TargetTag> findTargetsAll;
|
||||
final Long countTargetsAll;
|
||||
if (rsqlParam == null) {
|
||||
findTargetsAll = tagManagement.findAllTargetTags(pageable);
|
||||
countTargetsAll = tagManagement.countTargetTags();
|
||||
|
||||
} else {
|
||||
final Page<TargetTag> findTargetPage = tagManagement.findAllTargetTags(
|
||||
RSQLUtility.parse(rsqlParam, TagFields.class, entityManager), pageable);
|
||||
countTargetsAll = findTargetPage.getTotalElements();
|
||||
findTargetsAll = findTargetPage;
|
||||
|
||||
}
|
||||
|
||||
final List<TagRest> rest = TagMapper.toResponse(findTargetsAll.getContent());
|
||||
return new ResponseEntity<>(new TagPagedList(rest, countTargetsAll), HttpStatus.OK);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the GET request of retrieving a single target tag.
|
||||
*
|
||||
* @param targetTagId
|
||||
* the ID of the target tag to retrieve
|
||||
*
|
||||
* @return a single target tag with status OK.
|
||||
* @throws EntityNotFoundException
|
||||
* in case the given {@code targetTagId} doesn't exists.
|
||||
*/
|
||||
@RequestMapping(method = RequestMethod.GET, value = "/{targetTagId}", produces = { "application/hal+json",
|
||||
MediaType.APPLICATION_JSON_VALUE })
|
||||
public ResponseEntity<TagRest> getTargetTag(@PathVariable final Long targetTagId) {
|
||||
final TargetTag tag = findTargetTagById(targetTagId);
|
||||
return new ResponseEntity<>(TagMapper.toResponse(tag), HttpStatus.OK);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the POST request of creating new target tag. The request body
|
||||
* must always be a list of tags.
|
||||
*
|
||||
* @param tags
|
||||
* the target tags to be created.
|
||||
* @return In case all modules could successful created the ResponseEntity
|
||||
* with status code 201 - Created. The Response Body are the created
|
||||
* target tags but without ResponseBody.
|
||||
*/
|
||||
@RequestMapping(method = RequestMethod.POST, consumes = { "application/hal+json", MediaType.APPLICATION_JSON_VALUE }, produces = {
|
||||
"application/hal+json", MediaType.APPLICATION_JSON_VALUE })
|
||||
public ResponseEntity<TagsRest> createTargetTags(@RequestBody final List<TagRequestBodyPut> tags) {
|
||||
LOG.debug("creating {} target tags", tags.size());
|
||||
final List<TargetTag> createdTargetTags = tagManagement
|
||||
.createTargetTags(TagMapper.mapTargeTagFromRequest(tags));
|
||||
return new ResponseEntity<>(TagMapper.toResponse(createdTargetTags), HttpStatus.CREATED);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Handles the PUT request of updating a single targetr tag.
|
||||
*
|
||||
* @param targetTagId
|
||||
* the ID of the target tag
|
||||
* @param restTargetTagRest
|
||||
* the the request body to be updated
|
||||
* @return status OK if update is successful and the updated target tag.
|
||||
* @throws EntityNotFoundException
|
||||
* in case the given {@code targetTagId} doesn't exists.
|
||||
*/
|
||||
@RequestMapping(method = RequestMethod.PUT, value = "/{targetTagId}", consumes = { "application/hal+json",
|
||||
MediaType.APPLICATION_JSON_VALUE }, produces = { "application/hal+json", MediaType.APPLICATION_JSON_VALUE })
|
||||
public ResponseEntity<TagRest> updateTagretTag(@PathVariable final Long targetTagId,
|
||||
@RequestBody final TagRequestBodyPut restTargetTagRest) {
|
||||
LOG.debug("update {} target tag", restTargetTagRest);
|
||||
|
||||
final TargetTag targetTag = findTargetTagById(targetTagId);
|
||||
TagMapper.updateTag(restTargetTagRest, targetTag);
|
||||
final TargetTag updateTargetTag = tagManagement.updateTargetTag(targetTag);
|
||||
|
||||
LOG.debug("target tag updated");
|
||||
|
||||
return new ResponseEntity<>(TagMapper.toResponse(updateTargetTag), HttpStatus.OK);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the DELETE request for a single target tag.
|
||||
*
|
||||
* @param targetTagId
|
||||
* the ID of the target tag
|
||||
* @return status OK if delete as successfully.
|
||||
* @throws EntityNotFoundException
|
||||
* in case the given {@code targetTagId} doesn't exists.
|
||||
*
|
||||
*/
|
||||
@RequestMapping(method = RequestMethod.DELETE, value = "/{targetTagId}")
|
||||
public ResponseEntity<Void> deleteTargetTag(@PathVariable final Long targetTagId) {
|
||||
LOG.debug("Delete {} target tag", targetTagId);
|
||||
final TargetTag targetTag = findTargetTagById(targetTagId);
|
||||
|
||||
tagManagement.deleteTargetTag(targetTag.getName());
|
||||
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the GET request of retrieving all assigned targets by the given
|
||||
* tag id.
|
||||
*
|
||||
* @param targetTagId
|
||||
* the ID of the target tag to retrieve
|
||||
*
|
||||
* @return the list of assigned targets.
|
||||
* @throws EntityNotFoundException
|
||||
* in case the given {@code targetTagId} doesn't exists.
|
||||
*/
|
||||
@RequestMapping(method = RequestMethod.GET, value = TARGET_TAG_TAGERTS_REQUEST_MAPPING)
|
||||
public ResponseEntity<TargetsRest> getAssignedTargets(@PathVariable final Long targetTagId) {
|
||||
final TargetTag targetTag = findTargetTagById(targetTagId);
|
||||
return new ResponseEntity<>(TargetMapper.toResponseWithLinksAndPollStatus(targetTag.getAssignedToTargets()),
|
||||
HttpStatus.OK);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the POST request to toggle the assignment of targets by the given
|
||||
* tag id.
|
||||
*
|
||||
* @param targetTagId
|
||||
* the ID of the target tag to retrieve
|
||||
* @param assignedTargetRequestBodies
|
||||
* list of target ids to be toggled
|
||||
*
|
||||
* @return the list of assigned targets and unassigned targets.
|
||||
* @throws EntityNotFoundException
|
||||
* in case the given {@code targetTagId} doesn't exists.
|
||||
*/
|
||||
@RequestMapping(method = RequestMethod.POST, value = TARGET_TAG_TAGERTS_REQUEST_MAPPING + "/toggleTagAssignment")
|
||||
public ResponseEntity<TargetTagAssigmentResultRest> toggleTagAssignment(@PathVariable final Long targetTagId,
|
||||
@RequestBody final List<AssignedTargetRequestBody> assignedTargetRequestBodies) {
|
||||
LOG.debug("Toggle Target assignment {} for target tag {}", assignedTargetRequestBodies.size(), targetTagId);
|
||||
|
||||
final TargetTag targetTag = findTargetTagById(targetTagId);
|
||||
final TargetTagAssigmentResult assigmentResult = targetManagement.toggleTagAssignment(
|
||||
findTargetControllerIds(assignedTargetRequestBodies), targetTag.getName());
|
||||
|
||||
final TargetTagAssigmentResultRest tagAssigmentResultRest = new TargetTagAssigmentResultRest();
|
||||
tagAssigmentResultRest.setAssignedTargets(TargetMapper.toResponse(assigmentResult.getAssignedTargets()));
|
||||
tagAssigmentResultRest.setUnassignedTargets(TargetMapper.toResponse(assigmentResult.getUnassignedTargets()));
|
||||
return new ResponseEntity<>(tagAssigmentResultRest, HttpStatus.OK);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the POST request to assign targets to the given tag id.
|
||||
*
|
||||
* @param targetTagId
|
||||
* the ID of the target tag to retrieve
|
||||
* @param assignedTargetRequestBodies
|
||||
* list of target ids to be assigned
|
||||
*
|
||||
* @return the list of assigned targets.
|
||||
* @throws EntityNotFoundException
|
||||
* in case the given {@code targetTagId} doesn't exists.
|
||||
*/
|
||||
@RequestMapping(method = RequestMethod.POST, value = TARGET_TAG_TAGERTS_REQUEST_MAPPING)
|
||||
public ResponseEntity<TargetsRest> assignTargets(@PathVariable final Long targetTagId,
|
||||
@RequestBody final List<AssignedTargetRequestBody> assignedTargetRequestBodies) {
|
||||
LOG.debug("Assign Targets {} for target tag {}", assignedTargetRequestBodies.size(), targetTagId);
|
||||
final TargetTag targetTag = findTargetTagById(targetTagId);
|
||||
final List<Target> assignedTarget = targetManagement.assignTag(
|
||||
findTargetControllerIds(assignedTargetRequestBodies), targetTag);
|
||||
return new ResponseEntity<>(TargetMapper.toResponseWithLinksAndPollStatus(assignedTarget), HttpStatus.OK);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the DELETE request to unassign all targets from the given tag id.
|
||||
*
|
||||
* @param targetTagId
|
||||
* the ID of the target tag to retrieve
|
||||
* @return http status code
|
||||
* @throws EntityNotFoundException
|
||||
* in case the given {@code targetTagId} doesn't exists.
|
||||
*/
|
||||
@RequestMapping(method = RequestMethod.DELETE, value = TARGET_TAG_TAGERTS_REQUEST_MAPPING)
|
||||
public ResponseEntity<Void> unassignTargets(@PathVariable final Long targetTagId) {
|
||||
LOG.debug("Unassign all Targets for target tag {}", targetTagId);
|
||||
final TargetTag targetTag = findTargetTagById(targetTagId);
|
||||
if (targetTag.getAssignedToTargets() == null) {
|
||||
LOG.debug("No assigned targets found");
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
targetManagement.unAssignAllTargetsByTag(targetTag);
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the DELETE request to unassign one target from the given tag id.
|
||||
*
|
||||
* @param targetTagId
|
||||
* the ID of the target tag
|
||||
* @param controllerId
|
||||
* the ID of the target to unassign
|
||||
* @return http status code
|
||||
* @throws EntityNotFoundException
|
||||
* in case the given {@code targetTagId} doesn't exists.
|
||||
*/
|
||||
@RequestMapping(method = RequestMethod.DELETE, value = TARGET_TAG_TAGERTS_REQUEST_MAPPING + "/{controllerId}")
|
||||
public ResponseEntity<Void> unassignTarget(@PathVariable final Long targetTagId,
|
||||
@PathVariable final String controllerId) {
|
||||
LOG.debug("Unassign target {} for target tag {}", controllerId, targetTagId);
|
||||
final TargetTag targetTag = findTargetTagById(targetTagId);
|
||||
targetManagement.unAssignTag(controllerId, targetTag);
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
|
||||
private TargetTag findTargetTagById(final Long targetTagId) {
|
||||
final TargetTag tag = tagManagement.findTargetTagById(targetTagId);
|
||||
if (tag == null) {
|
||||
throw new EntityNotFoundException("Target Tag with Id {" + targetTagId + "} does not exist");
|
||||
}
|
||||
return tag;
|
||||
}
|
||||
|
||||
private List<String> findTargetControllerIds(final List<AssignedTargetRequestBody> assignedTargetRequestBodies) {
|
||||
return assignedTargetRequestBodies.stream().map(request -> request.getControllerId())
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
0
hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/helper/ByteRange.java
Executable file → Normal file
0
hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/helper/ByteRange.java
Executable file → Normal file
0
hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/helper/RestResourceConversionHelper.java
Executable file → Normal file
0
hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/helper/RestResourceConversionHelper.java
Executable file → Normal file
0
hawkbit-rest-resource/src/test/java/org/eclipse/hawkbit/MockMvcResultPrinter.java
Executable file → Normal file
0
hawkbit-rest-resource/src/test/java/org/eclipse/hawkbit/MockMvcResultPrinter.java
Executable file → Normal file
0
hawkbit-rest-resource/src/test/java/org/eclipse/hawkbit/controller/ArtifactDownloadTest.java
Executable file → Normal file
0
hawkbit-rest-resource/src/test/java/org/eclipse/hawkbit/controller/ArtifactDownloadTest.java
Executable file → Normal file
0
hawkbit-rest-resource/src/test/java/org/eclipse/hawkbit/controller/CancelActionTest.java
Executable file → Normal file
0
hawkbit-rest-resource/src/test/java/org/eclipse/hawkbit/controller/CancelActionTest.java
Executable file → Normal file
0
hawkbit-rest-resource/src/test/java/org/eclipse/hawkbit/controller/ConfigDataTest.java
Executable file → Normal file
0
hawkbit-rest-resource/src/test/java/org/eclipse/hawkbit/controller/ConfigDataTest.java
Executable file → Normal file
65
hawkbit-rest-resource/src/test/java/org/eclipse/hawkbit/controller/DeploymentBaseTest.java
Executable file → Normal file
65
hawkbit-rest-resource/src/test/java/org/eclipse/hawkbit/controller/DeploymentBaseTest.java
Executable file → Normal file
@@ -57,8 +57,8 @@ import ru.yandex.qatools.allure.annotations.Stories;
|
||||
public class DeploymentBaseTest extends AbstractIntegrationTestWithMongoDB {
|
||||
|
||||
@Test()
|
||||
@Description("Ensures that artifact not found, when softare module not exists ")
|
||||
public void testArtifactsNotFound() throws Exception {
|
||||
@Description("Ensures that artifacts are not found, when softare module does not exists.")
|
||||
public void artifactsNotFound() throws Exception {
|
||||
final Target target = TestDataUtil.createTarget(targetManagement);
|
||||
final Long softwareModuleIdNotExist = 1l;
|
||||
mvc.perform(get("/{tenant}/controller/v1/{targetNotExist}/softwaremodules/{softwareModuleId}/artifacts",
|
||||
@@ -67,8 +67,8 @@ public class DeploymentBaseTest extends AbstractIntegrationTestWithMongoDB {
|
||||
}
|
||||
|
||||
@Test()
|
||||
@Description("Ensures that artifact are found, when softare module exists ")
|
||||
public void testArtifactsExists() throws Exception {
|
||||
@Description("Ensures that artifacts are found, when software module exists.")
|
||||
public void artifactsExists() throws Exception {
|
||||
final Target target = TestDataUtil.createTarget(targetManagement);
|
||||
final DistributionSet distributionSet = TestDataUtil.generateDistributionSet("", softwareManagement,
|
||||
distributionSetManagement);
|
||||
@@ -91,24 +91,6 @@ public class DeploymentBaseTest extends AbstractIntegrationTestWithMongoDB {
|
||||
|
||||
}
|
||||
|
||||
@Test()
|
||||
@Description("Ensures that software modules are found, when assigned distribution set exists with modules and atrifacts")
|
||||
public void testAvailableSoftwareModulesWithArtifacts() throws Exception {
|
||||
final Target target = TestDataUtil.createTarget(targetManagement);
|
||||
final DistributionSet distributionSet = TestDataUtil.generateDistributionSet("", softwareManagement,
|
||||
distributionSetManagement);
|
||||
|
||||
deploymentManagement.assignDistributionSet(distributionSet.getId(), new String[] { target.getName() });
|
||||
final Long softwareModuleId = distributionSet.getModules().stream().findFirst().get().getId();
|
||||
TestDataUtil.generateArtifacts(artifactManagement, softwareModuleId);
|
||||
|
||||
final int modulesSize = distributionSet.getModules().size();
|
||||
|
||||
mvc.perform(get("/{tenant}/controller/v1/{targetExist}/softwaremodules/", tenantAware.getCurrentTenant(),
|
||||
target.getName())).andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$", hasSize(modulesSize)));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Forced deployment to a controller. Checks if the resource reponse payload for a given deployment is as expected.")
|
||||
public void deplomentForceAction() throws Exception {
|
||||
@@ -160,7 +142,6 @@ public class DeploymentBaseTest extends AbstractIntegrationTestWithMongoDB {
|
||||
assertThat(actionStatusRepository.findAll()).hasSize(2);
|
||||
|
||||
current = System.currentTimeMillis();
|
||||
Thread.sleep(1);
|
||||
|
||||
final DistributionSet findDistributionSetByAction = distributionSetManagement
|
||||
.findDistributionSetByAction(action);
|
||||
@@ -284,7 +265,6 @@ public class DeploymentBaseTest extends AbstractIntegrationTestWithMongoDB {
|
||||
assertThat(actionStatusRepository.findAll()).hasSize(2);
|
||||
|
||||
current = System.currentTimeMillis();
|
||||
Thread.sleep(1);
|
||||
|
||||
final DistributionSet findDistributionSetByAction = distributionSetManagement
|
||||
.findDistributionSetByAction(action);
|
||||
@@ -407,7 +387,6 @@ public class DeploymentBaseTest extends AbstractIntegrationTestWithMongoDB {
|
||||
assertThat(actionStatusRepository.findAll()).hasSize(2);
|
||||
|
||||
current = System.currentTimeMillis();
|
||||
Thread.sleep(1);
|
||||
|
||||
final DistributionSet findDistributionSetByAction = distributionSetManagement
|
||||
.findDistributionSetByAction(action);
|
||||
@@ -584,17 +563,11 @@ public class DeploymentBaseTest extends AbstractIntegrationTestWithMongoDB {
|
||||
|
||||
long current = System.currentTimeMillis();
|
||||
long lastModified = targetManagement.findTargetByControllerID("4712").getLastModifiedAt();
|
||||
Thread.sleep(1); // is required: otherwise processing the next line is
|
||||
// often too fast and
|
||||
// the following assert will fail
|
||||
mvc.perform(post("/{tenant}/controller/v1/4712/deploymentBase/" + action1.getId() + "/feedback",
|
||||
tenantAware.getCurrentTenant())
|
||||
.content(JsonBuilder.deploymentActionFeedback(action1.getId().toString(), "closed"))
|
||||
.contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON))
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk());
|
||||
Thread.sleep(1); // is required: otherwise processing the next line is
|
||||
// often too fast and
|
||||
// the following assert will fail
|
||||
myT = targetManagement.findTargetByControllerIDWithDetails("4712");
|
||||
assertThat(myT.getTargetInfo().getLastTargetQuery()).isLessThanOrEqualTo(System.currentTimeMillis());
|
||||
assertThat(myT.getTargetInfo().getLastTargetQuery()).isGreaterThanOrEqualTo(current);
|
||||
@@ -615,17 +588,11 @@ public class DeploymentBaseTest extends AbstractIntegrationTestWithMongoDB {
|
||||
// action2 done
|
||||
current = System.currentTimeMillis();
|
||||
lastModified = targetManagement.findTargetByControllerID("4712").getLastModifiedAt();
|
||||
Thread.sleep(1); // is required: otherwise processing the next line is
|
||||
// often too fast and
|
||||
// the following assert will fail
|
||||
mvc.perform(post("/{tenant}/controller/v1/4712/deploymentBase/" + action2.getId() + "/feedback",
|
||||
tenantAware.getCurrentTenant())
|
||||
.content(JsonBuilder.deploymentActionFeedback(action2.getId().toString(), "closed"))
|
||||
.contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON))
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk());
|
||||
Thread.sleep(1); // is required: otherwise processing the next line is
|
||||
// often too fast and
|
||||
// the following assert will fail
|
||||
myT = targetManagement.findTargetByControllerIDWithDetails("4712");
|
||||
assertThat(myT.getTargetInfo().getLastTargetQuery()).isLessThanOrEqualTo(System.currentTimeMillis());
|
||||
assertThat(myT.getTargetInfo().getLastTargetQuery()).isGreaterThanOrEqualTo(current);
|
||||
@@ -641,18 +608,11 @@ public class DeploymentBaseTest extends AbstractIntegrationTestWithMongoDB {
|
||||
// action3 done
|
||||
current = System.currentTimeMillis();
|
||||
lastModified = targetManagement.findTargetByControllerID("4712").getLastModifiedAt();
|
||||
Thread.sleep(1); // is required: otherwise processing the next line is
|
||||
// often too fast and
|
||||
// the following assert will fail
|
||||
mvc.perform(post("/{tenant}/controller/v1/4712/deploymentBase/" + action3.getId() + "/feedback",
|
||||
tenantAware.getCurrentTenant())
|
||||
.content(JsonBuilder.deploymentActionFeedback(action3.getId().toString(), "closed"))
|
||||
.contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON))
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk());
|
||||
Thread.sleep(1); // is required: otherwise processing the next line is
|
||||
// often too fast and
|
||||
// the following assert will fail
|
||||
|
||||
myT = targetManagement.findTargetByControllerID("4712");
|
||||
assertThat(myT.getTargetInfo().getLastTargetQuery()).isLessThanOrEqualTo(System.currentTimeMillis());
|
||||
assertThat(myT.getTargetInfo().getLastTargetQuery()).isGreaterThanOrEqualTo(current);
|
||||
@@ -684,17 +644,12 @@ public class DeploymentBaseTest extends AbstractIntegrationTestWithMongoDB {
|
||||
|
||||
long current = System.currentTimeMillis();
|
||||
long lastModified = targetManagement.findTargetByControllerID("4712").getLastModifiedAt();
|
||||
Thread.sleep(1); // is required: otherwise processing the next line is
|
||||
// often too fast and
|
||||
// the following assert will fail
|
||||
mvc.perform(post("/{tenant}/controller/v1/4712/deploymentBase/" + action.getId() + "/feedback",
|
||||
tenantAware.getCurrentTenant())
|
||||
.content(JsonBuilder.deploymentActionFeedback(action.getId().toString(), "closed", "failure"))
|
||||
.content(JsonBuilder.deploymentActionFeedback(action.getId().toString(), "closed", "failure",
|
||||
"error message"))
|
||||
.contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON))
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk());
|
||||
Thread.sleep(1); // is required: otherwise processing the next line is
|
||||
// often too fast and
|
||||
// the following assert will fail
|
||||
Target myT = targetManagement.findTargetByControllerID("4712");
|
||||
assertThat(myT.getTargetInfo().getLastTargetQuery()).isLessThanOrEqualTo(System.currentTimeMillis());
|
||||
assertThat(myT.getTargetInfo().getLastTargetQuery()).isGreaterThanOrEqualTo(current);
|
||||
@@ -720,17 +675,13 @@ public class DeploymentBaseTest extends AbstractIntegrationTestWithMongoDB {
|
||||
final Action action2 = deploymentManagement.findActiveActionsByTarget(myT).get(0);
|
||||
current = System.currentTimeMillis();
|
||||
lastModified = targetManagement.findTargetByControllerID("4712").getLastModifiedAt();
|
||||
Thread.sleep(1); // is required: otherwise processing the next line is
|
||||
// often too fast and
|
||||
// the following assert will fail
|
||||
|
||||
mvc.perform(post("/{tenant}/controller/v1/4712/deploymentBase/" + action2.getId() + "/feedback",
|
||||
tenantAware.getCurrentTenant())
|
||||
.content(JsonBuilder.deploymentActionFeedback(action2.getId().toString(), "closed", "success"))
|
||||
.contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON))
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk());
|
||||
Thread.sleep(1); // is required: otherwise processing the next line is
|
||||
// often too fast and
|
||||
// the following assert will fail
|
||||
|
||||
myT = targetManagement.findTargetByControllerID("4712");
|
||||
assertThat(myT.getTargetInfo().getLastTargetQuery()).isLessThanOrEqualTo(System.currentTimeMillis());
|
||||
assertThat(myT.getTargetInfo().getLastTargetQuery()).isGreaterThanOrEqualTo(current);
|
||||
|
||||
57
hawkbit-rest-resource/src/test/java/org/eclipse/hawkbit/controller/RootControllerTest.java
Executable file → Normal file
57
hawkbit-rest-resource/src/test/java/org/eclipse/hawkbit/controller/RootControllerTest.java
Executable file → Normal file
@@ -10,7 +10,6 @@ package org.eclipse.hawkbit.controller;
|
||||
|
||||
import static org.fest.assertions.api.Assertions.assertThat;
|
||||
import static org.hamcrest.CoreMatchers.equalTo;
|
||||
import static org.hamcrest.Matchers.hasSize;
|
||||
import static org.hamcrest.Matchers.startsWith;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||
@@ -22,9 +21,8 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
import org.eclipse.hawkbit.AbstractIntegrationTest;
|
||||
import org.eclipse.hawkbit.AbstractIntegrationTestWithMongoDB;
|
||||
import org.eclipse.hawkbit.MockMvcResultPrinter;
|
||||
import org.eclipse.hawkbit.TestDataUtil;
|
||||
import org.eclipse.hawkbit.WithSpringAuthorityRule;
|
||||
@@ -51,40 +49,7 @@ import ru.yandex.qatools.allure.annotations.Stories;
|
||||
@Stories("Root Poll Resource")
|
||||
// TODO: fully document tests -> @Description for long text and reasonable
|
||||
// method name as short text
|
||||
public class RootControllerTest extends AbstractIntegrationTest {
|
||||
|
||||
@Test()
|
||||
@Description("Ensures that software modules are not found, when target does not exists ")
|
||||
public void testSoftwareModulesIfTargetNotExists() throws Exception {
|
||||
final String targetNotExist = "targetNotExist";
|
||||
mvc.perform(get("/{tenant}/controller/v1/{targetNotExist}/softwaremodules/", tenantAware.getCurrentTenant(),
|
||||
targetNotExist)).andDo(MockMvcResultPrinter.print()).andExpect(status().isNotFound());
|
||||
|
||||
}
|
||||
|
||||
@Test()
|
||||
@Description("Ensures that software modules are not found, when assigned distribution set exists with no modules")
|
||||
public void testSoftwareModulesEmptyIfDistributionSetNotExists() throws Exception {
|
||||
mvc.perform(get("/{tenant}/controller/v1/{targetExist}/softwaremodules/", tenantAware.getCurrentTenant(),
|
||||
TestDataUtil.createTarget(targetManagement).getName())).andDo(MockMvcResultPrinter.print())
|
||||
.andExpect(status().isOk()).andExpect(jsonPath("$", hasSize(0)));
|
||||
}
|
||||
|
||||
@Test()
|
||||
@Description("Ensures that software modules are found, when assigned distribution set exists with modules")
|
||||
public void testAvailableSoftwareModulesWithNoArtifacts() throws Exception {
|
||||
final Target target = TestDataUtil.createTarget(targetManagement);
|
||||
final DistributionSet distributionSet = TestDataUtil.generateDistributionSet("", softwareManagement,
|
||||
distributionSetManagement);
|
||||
|
||||
deploymentManagement.assignDistributionSet(distributionSet.getId(), new String[] { target.getName() });
|
||||
|
||||
final int modulesSize = distributionSet.getModules().size();
|
||||
|
||||
mvc.perform(get("/{tenant}/controller/v1/{targetExist}/softwaremodules/", tenantAware.getCurrentTenant(),
|
||||
target.getName())).andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$", hasSize(modulesSize)));
|
||||
}
|
||||
public class RootControllerTest extends AbstractIntegrationTestWithMongoDB {
|
||||
|
||||
@Test()
|
||||
@Description("Ensures that targets cannot be created e.g. in plug'n play scenarios when tenant does not exists but can be created if the tenant exists.")
|
||||
@@ -105,7 +70,6 @@ public class RootControllerTest extends AbstractIntegrationTest {
|
||||
|
||||
mvc.perform(get("/{}/controller/v1/aControllerId", tenantAware.getCurrentTenant()))
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isBadRequest());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -123,15 +87,11 @@ public class RootControllerTest extends AbstractIntegrationTest {
|
||||
// make a poll, audit information should not be changed, run as
|
||||
// controller principal!
|
||||
securityRule.runAs(
|
||||
WithSpringAuthorityRule.withUser("controller", SpringEvalExpressions.CONTROLLER_ROLE_ANONYMOUS),
|
||||
new Callable<Void>() {
|
||||
@Override
|
||||
public Void call() throws Exception {
|
||||
mvc.perform(get("/{tenant}/controller/v1/" + knownTargetControllerId,
|
||||
tenantAware.getCurrentTenant())).andDo(MockMvcResultPrinter.print())
|
||||
.andExpect(status().isOk());
|
||||
return null;
|
||||
}
|
||||
WithSpringAuthorityRule.withUser("controller", SpringEvalExpressions.CONTROLLER_ROLE_ANONYMOUS), () -> {
|
||||
mvc.perform(
|
||||
get("/{tenant}/controller/v1/" + knownTargetControllerId, tenantAware.getCurrentTenant()))
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk());
|
||||
return null;
|
||||
});
|
||||
|
||||
// verify that audit information has not changed
|
||||
@@ -249,9 +209,6 @@ public class RootControllerTest extends AbstractIntegrationTest {
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
|
||||
.andExpect(content().contentType(MediaTypes.HAL_JSON))
|
||||
.andExpect(jsonPath("$config.polling.sleep", equalTo("00:01:00")));
|
||||
Thread.sleep(1); // is required: otherwise processing the next line is
|
||||
// often too fast and
|
||||
// the following assert will fail
|
||||
assertThat(targetManagement.findTargetByControllerID("4711").getTargetInfo().getLastTargetQuery())
|
||||
.isLessThanOrEqualTo(System.currentTimeMillis());
|
||||
assertThat(targetManagement.findTargetByControllerID("4711").getTargetInfo().getLastTargetQuery())
|
||||
|
||||
388
hawkbit-rest-resource/src/test/java/org/eclipse/hawkbit/rest/resource/DistributionSetResourceTest.java
Executable file → Normal file
388
hawkbit-rest-resource/src/test/java/org/eclipse/hawkbit/rest/resource/DistributionSetResourceTest.java
Executable file → Normal file
@@ -30,6 +30,11 @@ import org.eclipse.hawkbit.AbstractIntegrationTest;
|
||||
import org.eclipse.hawkbit.MockMvcResultPrinter;
|
||||
import org.eclipse.hawkbit.TestDataUtil;
|
||||
import org.eclipse.hawkbit.WithUser;
|
||||
import org.eclipse.hawkbit.repository.ActionRepository;
|
||||
import org.eclipse.hawkbit.repository.ControllerManagement;
|
||||
import org.eclipse.hawkbit.repository.DistributionSetManagement;
|
||||
import org.eclipse.hawkbit.repository.SoftwareManagement;
|
||||
import org.eclipse.hawkbit.repository.TargetManagement;
|
||||
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
|
||||
import org.eclipse.hawkbit.repository.model.Action;
|
||||
import org.eclipse.hawkbit.repository.model.Action.Status;
|
||||
@@ -48,12 +53,12 @@ import org.springframework.context.annotation.Description;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.web.servlet.MvcResult;
|
||||
|
||||
import ru.yandex.qatools.allure.annotations.Features;
|
||||
import ru.yandex.qatools.allure.annotations.Stories;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.jayway.jsonpath.JsonPath;
|
||||
|
||||
import ru.yandex.qatools.allure.annotations.Features;
|
||||
import ru.yandex.qatools.allure.annotations.Stories;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
@@ -78,7 +83,7 @@ public class DistributionSetResourceTest extends AbstractIntegrationTest {
|
||||
|
||||
@Test
|
||||
@Description("This test verifies the deletion of a assigned Software Module of a Distribution Set can not be achieved when that Distribution Set has been assigned or installed to a target.")
|
||||
public void testDeleteFailureWhenDistributionSetInUse() throws Exception {
|
||||
public void deleteFailureWhenDistributionSetInUse() throws Exception {
|
||||
|
||||
// create DisSet
|
||||
final DistributionSet disSet = TestDataUtil.generateDistributionSetWithNoSoftwareModules("Eris", "560a",
|
||||
@@ -92,10 +97,9 @@ public class DistributionSetResourceTest extends AbstractIntegrationTest {
|
||||
smList.put(new JSONObject().put("id", Long.valueOf(smID)));
|
||||
}
|
||||
// post assignment
|
||||
mvc.perform(
|
||||
post(RestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + disSet.getId() + "/assignedSM")
|
||||
.contentType(MediaType.APPLICATION_JSON).content(smList.toString()))
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk());
|
||||
mvc.perform(post(RestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + disSet.getId() + "/assignedSM")
|
||||
.contentType(MediaType.APPLICATION_JSON).content(smList.toString())).andDo(MockMvcResultPrinter.print())
|
||||
.andExpect(status().isOk());
|
||||
|
||||
// create targets and assign DisSet to target
|
||||
final String[] knownTargetIds = new String[] { "1", "2" };
|
||||
@@ -105,32 +109,29 @@ public class DistributionSetResourceTest extends AbstractIntegrationTest {
|
||||
list.put(new JSONObject().put("id", Long.valueOf(targetId)));
|
||||
}
|
||||
deploymentManagement.assignDistributionSet(disSet.getId(), knownTargetIds[0]);
|
||||
mvc.perform(
|
||||
post(RestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + disSet.getId() + "/assignedTargets")
|
||||
.contentType(MediaType.APPLICATION_JSON).content(list.toString()))
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.assigned", equalTo(knownTargetIds.length - 1)))
|
||||
mvc.perform(post(RestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + disSet.getId() + "/assignedTargets")
|
||||
.contentType(MediaType.APPLICATION_JSON).content(list.toString())).andDo(MockMvcResultPrinter.print())
|
||||
.andExpect(status().isOk()).andExpect(jsonPath("$.assigned", equalTo(knownTargetIds.length - 1)))
|
||||
.andExpect(jsonPath("$.alreadyAssigned", equalTo(1)))
|
||||
.andExpect(jsonPath("$.total", equalTo(knownTargetIds.length)));
|
||||
|
||||
// try to delete the Software Module from DisSet that has been assigned
|
||||
// try to delete the Software Module from DistSet that has been assigned
|
||||
// to the target.
|
||||
mvc.perform(
|
||||
delete(
|
||||
RestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + disSet.getId() + "/assignedSM/"
|
||||
+ smIDs.get(0)).contentType(MediaType.APPLICATION_JSON))
|
||||
mvc.perform(delete(
|
||||
RestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + disSet.getId() + "/assignedSM/" + smIDs.get(0))
|
||||
.contentType(MediaType.APPLICATION_JSON))
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isLocked())
|
||||
.andExpect(jsonPath("$.errorCode", equalTo("hawkbit.server.error.entitiylocked")));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("This test verifies that the assignment of a Software Module to a Distribution Set can not be achieved when that Distribution Set has been assigned or installed to a target.")
|
||||
public void testAssignmentFailureWhenAssigningToUsedDistributionSet() throws Exception {
|
||||
public void assignmentFailureWhenAssigningToUsedDistributionSet() throws Exception {
|
||||
|
||||
// create DisSet
|
||||
final DistributionSet disSet = TestDataUtil.generateDistributionSetWithNoSoftwareModules("Mars", "686,980",
|
||||
distributionSetManagement);
|
||||
final List<Long> smIDs = new ArrayList<Long>();
|
||||
final List<Long> smIDs = new ArrayList<>();
|
||||
SoftwareModule sm = new SoftwareModule(osType, "Phobos", "0,3189", null, null);
|
||||
sm = softwareManagement.createSoftwareModule(sm);
|
||||
smIDs.add(sm.getId());
|
||||
@@ -139,10 +140,9 @@ public class DistributionSetResourceTest extends AbstractIntegrationTest {
|
||||
smList.put(new JSONObject().put("id", Long.valueOf(smID)));
|
||||
}
|
||||
// post assignment
|
||||
mvc.perform(
|
||||
post(RestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + disSet.getId() + "/assignedSM")
|
||||
.contentType(MediaType.APPLICATION_JSON).content(smList.toString()))
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk());
|
||||
mvc.perform(post(RestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + disSet.getId() + "/assignedSM")
|
||||
.contentType(MediaType.APPLICATION_JSON).content(smList.toString())).andDo(MockMvcResultPrinter.print())
|
||||
.andExpect(status().isOk());
|
||||
|
||||
// create Targets
|
||||
final String[] knownTargetIds = new String[] { "1", "2" };
|
||||
@@ -153,11 +153,9 @@ public class DistributionSetResourceTest extends AbstractIntegrationTest {
|
||||
}
|
||||
// assign DisSet to target and test assignment
|
||||
deploymentManagement.assignDistributionSet(disSet.getId(), knownTargetIds[0]);
|
||||
mvc.perform(
|
||||
post(RestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + disSet.getId() + "/assignedTargets")
|
||||
.contentType(MediaType.APPLICATION_JSON).content(list.toString()))
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.assigned", equalTo(knownTargetIds.length - 1)))
|
||||
mvc.perform(post(RestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + disSet.getId() + "/assignedTargets")
|
||||
.contentType(MediaType.APPLICATION_JSON).content(list.toString())).andDo(MockMvcResultPrinter.print())
|
||||
.andExpect(status().isOk()).andExpect(jsonPath("$.assigned", equalTo(knownTargetIds.length - 1)))
|
||||
.andExpect(jsonPath("$.alreadyAssigned", equalTo(1)))
|
||||
.andExpect(jsonPath("$.total", equalTo(knownTargetIds.length)));
|
||||
|
||||
@@ -171,9 +169,8 @@ public class DistributionSetResourceTest extends AbstractIntegrationTest {
|
||||
smList2.put(new JSONObject().put("id", Long.valueOf(smID)));
|
||||
}
|
||||
|
||||
mvc.perform(
|
||||
post(RestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + disSet.getId() + "/assignedSM")
|
||||
.contentType(MediaType.APPLICATION_JSON).content(smList2.toString()))
|
||||
mvc.perform(post(RestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + disSet.getId() + "/assignedSM")
|
||||
.contentType(MediaType.APPLICATION_JSON).content(smList2.toString()))
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isLocked())
|
||||
.andExpect(jsonPath("$.errorCode", equalTo("hawkbit.server.error.entitiylocked")));
|
||||
}
|
||||
@@ -205,10 +202,9 @@ public class DistributionSetResourceTest extends AbstractIntegrationTest {
|
||||
list.put(new JSONObject().put("id", Long.valueOf(smID)));
|
||||
}
|
||||
// post assignment
|
||||
mvc.perform(
|
||||
post(RestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + disSet.getId() + "/assignedSM")
|
||||
.contentType(MediaType.APPLICATION_JSON).content(list.toString()))
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk());
|
||||
mvc.perform(post(RestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + disSet.getId() + "/assignedSM")
|
||||
.contentType(MediaType.APPLICATION_JSON).content(list.toString())).andDo(MockMvcResultPrinter.print())
|
||||
.andExpect(status().isOk());
|
||||
// Test if size is 3
|
||||
mvc.perform(get(RestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + disSet.getId() + "/assignedSM"))
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
|
||||
@@ -216,7 +212,7 @@ public class DistributionSetResourceTest extends AbstractIntegrationTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("This test verifies the rejection of Software Modules of a Distribution Set through the RESTful API.")
|
||||
@Description("This test verifies the removal of Software Modules of a Distribution Set through the RESTful API.")
|
||||
public void unassignSoftwaremoduleFromDistributionSet() throws Exception {
|
||||
|
||||
// Create DistributionSet with three software modules
|
||||
@@ -226,11 +222,11 @@ public class DistributionSetResourceTest extends AbstractIntegrationTest {
|
||||
mvc.perform(get(RestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + set.getId() + "/assignedSM"))
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.size", equalTo(amountOfSM)));
|
||||
// test the rejection of all assigned software modules one by one
|
||||
// test the removal of all software modules one by one
|
||||
for (final Iterator<SoftwareModule> iter = set.getModules().iterator(); iter.hasNext();) {
|
||||
final Long smId = iter.next().getId();
|
||||
mvc.perform(
|
||||
delete(RestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + set.getId() + "/assignedSM/" + smId))
|
||||
mvc.perform(delete(
|
||||
RestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + set.getId() + "/assignedSM/" + smId))
|
||||
.andExpect(status().isOk());
|
||||
mvc.perform(get(RestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + set.getId() + "/assignedSM"))
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
|
||||
@@ -255,8 +251,8 @@ public class DistributionSetResourceTest extends AbstractIntegrationTest {
|
||||
|
||||
mvc.perform(
|
||||
post(RestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + createdDs.getId() + "/assignedTargets")
|
||||
.contentType(MediaType.APPLICATION_JSON).content(list.toString())).andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.assigned", equalTo(knownTargetIds.length - 1)))
|
||||
.contentType(MediaType.APPLICATION_JSON).content(list.toString()))
|
||||
.andExpect(status().isOk()).andExpect(jsonPath("$.assigned", equalTo(knownTargetIds.length - 1)))
|
||||
.andExpect(jsonPath("$.alreadyAssigned", equalTo(1)))
|
||||
.andExpect(jsonPath("$.total", equalTo(knownTargetIds.length)));
|
||||
}
|
||||
@@ -299,7 +295,8 @@ public class DistributionSetResourceTest extends AbstractIntegrationTest {
|
||||
// assign knownTargetId to distribution set
|
||||
deploymentManagement.assignDistributionSet(createdDs.getId(), knownTargetId);
|
||||
// make it in install state
|
||||
sendUpdateActionStatusToTargets(createdDs, Lists.newArrayList(createTarget), Status.FINISHED, "some message");
|
||||
sendUpdateActionStatusToTargets(controllerManagament, targetManagement, actionRepository, createdDs,
|
||||
Lists.newArrayList(createTarget), Status.FINISHED, "some message");
|
||||
|
||||
mvc.perform(
|
||||
get(RestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + createdDs.getId() + "/installedTargets"))
|
||||
@@ -308,7 +305,7 @@ public class DistributionSetResourceTest extends AbstractIntegrationTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetDistributionSetsWithoutAddtionalRequestParameters() throws Exception {
|
||||
public void getDistributionSetsWithoutAddtionalRequestParameters() throws Exception {
|
||||
final int modules = 5;
|
||||
createDistributionSetsAlphabetical(modules);
|
||||
mvc.perform(get(RestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING)).andDo(MockMvcResultPrinter.print())
|
||||
@@ -319,13 +316,12 @@ public class DistributionSetResourceTest extends AbstractIntegrationTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetDistributionSetsWithPagingLimitRequestParameter() throws Exception {
|
||||
public void getDistributionSetsWithPagingLimitRequestParameter() throws Exception {
|
||||
final int modules = 5;
|
||||
final int limitSize = 1;
|
||||
createDistributionSetsAlphabetical(modules);
|
||||
mvc.perform(
|
||||
get(RestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING).param(
|
||||
RestConstants.REQUEST_PARAMETER_PAGING_LIMIT, String.valueOf(limitSize)))
|
||||
mvc.perform(get(RestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING)
|
||||
.param(RestConstants.REQUEST_PARAMETER_PAGING_LIMIT, String.valueOf(limitSize)))
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
|
||||
.andExpect(jsonPath(TargetResourceTest.JSON_PATH_PAGED_LIST_TOTAL, equalTo(modules)))
|
||||
.andExpect(jsonPath(TargetResourceTest.JSON_PATH_PAGED_LIST_SIZE, equalTo(limitSize)))
|
||||
@@ -333,15 +329,14 @@ public class DistributionSetResourceTest extends AbstractIntegrationTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetDistributionSetsWithPagingLimitAndOffsetRequestParameter() throws Exception {
|
||||
public void getDistributionSetsWithPagingLimitAndOffsetRequestParameter() throws Exception {
|
||||
final int modules = 5;
|
||||
final int offsetParam = 2;
|
||||
final int expectedSize = modules - offsetParam;
|
||||
createDistributionSetsAlphabetical(modules);
|
||||
mvc.perform(
|
||||
get(RestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING).param(
|
||||
RestConstants.REQUEST_PARAMETER_PAGING_OFFSET, String.valueOf(offsetParam)).param(
|
||||
RestConstants.REQUEST_PARAMETER_PAGING_LIMIT, String.valueOf(modules)))
|
||||
mvc.perform(get(RestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING)
|
||||
.param(RestConstants.REQUEST_PARAMETER_PAGING_OFFSET, String.valueOf(offsetParam))
|
||||
.param(RestConstants.REQUEST_PARAMETER_PAGING_LIMIT, String.valueOf(modules)))
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
|
||||
.andExpect(jsonPath(TargetResourceTest.JSON_PATH_PAGED_LIST_TOTAL, equalTo(modules)))
|
||||
.andExpect(jsonPath(TargetResourceTest.JSON_PATH_PAGED_LIST_SIZE, equalTo(expectedSize)))
|
||||
@@ -350,12 +345,12 @@ public class DistributionSetResourceTest extends AbstractIntegrationTest {
|
||||
|
||||
@Test
|
||||
@WithUser(principal = "uploadTester", allSpPermissions = true)
|
||||
public void testGetDistributionSets() throws Exception {
|
||||
public void getDistributionSets() throws Exception {
|
||||
// prepare test data
|
||||
assertThat(distributionSetManagement.findDistributionSetsAll(pageReq, false, true)).hasSize(0);
|
||||
|
||||
DistributionSet set = TestDataUtil
|
||||
.generateDistributionSet("one", softwareManagement, distributionSetManagement);
|
||||
DistributionSet set = TestDataUtil.generateDistributionSet("one", softwareManagement,
|
||||
distributionSetManagement);
|
||||
set.setRequiredMigrationStep(set.isRequiredMigrationStep());
|
||||
set = distributionSetManagement.updateDistributionSet(set);
|
||||
|
||||
@@ -369,12 +364,10 @@ public class DistributionSetResourceTest extends AbstractIntegrationTest {
|
||||
|
||||
// perform request
|
||||
mvc.perform(get("/rest/v1/distributionsets").accept(MediaType.APPLICATION_JSON))
|
||||
.andDo(MockMvcResultPrinter.print())
|
||||
.andExpect(status().isOk())
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
|
||||
.andExpect(content().contentType(MediaType.APPLICATION_JSON))
|
||||
.andExpect(
|
||||
jsonPath("$content.[0]._links.self.href", equalTo("http://localhost/rest/v1/distributionsets/"
|
||||
+ set.getId())))
|
||||
.andExpect(jsonPath("$content.[0]._links.self.href",
|
||||
equalTo("http://localhost/rest/v1/distributionsets/" + set.getId())))
|
||||
.andExpect(jsonPath("$content.[0].id", equalTo(set.getId().intValue())))
|
||||
.andExpect(jsonPath("$content.[0].name", equalTo(set.getName())))
|
||||
.andExpect(jsonPath("$content.[0].requiredMigrationStep", equalTo(set.isRequiredMigrationStep())))
|
||||
@@ -386,41 +379,25 @@ public class DistributionSetResourceTest extends AbstractIntegrationTest {
|
||||
.andExpect(jsonPath("$content.[0].lastModifiedBy", equalTo(set.getLastModifiedBy())))
|
||||
.andExpect(jsonPath("$content.[0].lastModifiedAt", equalTo(set.getLastModifiedAt())))
|
||||
.andExpect(jsonPath("$content.[0].version", equalTo(set.getVersion())))
|
||||
.andExpect(
|
||||
jsonPath("$content.[0].modules.[?(@.type==" + runtimeType.getKey() + ")][0].id", equalTo(set
|
||||
.findFirstModuleByType(runtimeType).getId().intValue())))
|
||||
.andExpect(
|
||||
jsonPath("$content.[0].modules.[?(@.type==" + appType.getKey() + ")][0].id", equalTo(set
|
||||
.findFirstModuleByType(appType).getId().intValue())))
|
||||
.andExpect(
|
||||
jsonPath("$content.[0].modules.[?(@.type==" + osType.getKey() + ")][0].id", equalTo(set
|
||||
.findFirstModuleByType(osType).getId().intValue())));
|
||||
.andExpect(jsonPath("$content.[0].modules.[?(@.type==" + runtimeType.getKey() + ")][0].id",
|
||||
equalTo(set.findFirstModuleByType(runtimeType).getId().intValue())))
|
||||
.andExpect(jsonPath("$content.[0].modules.[?(@.type==" + appType.getKey() + ")][0].id",
|
||||
equalTo(set.findFirstModuleByType(appType).getId().intValue())))
|
||||
.andExpect(jsonPath("$content.[0].modules.[?(@.type==" + osType.getKey() + ")][0].id",
|
||||
equalTo(set.findFirstModuleByType(osType).getId().intValue())));
|
||||
}
|
||||
|
||||
@Test
|
||||
@WithUser(principal = "uploadTester", allSpPermissions = true)
|
||||
public void testGetDistributionSet() throws Exception {
|
||||
// prepare test data
|
||||
assertThat(distributionSetManagement.findDistributionSetsAll(pageReq, false, true)).hasSize(0);
|
||||
|
||||
DistributionSet set = TestDataUtil
|
||||
.generateDistributionSet("one", softwareManagement, distributionSetManagement);
|
||||
set.setVersion("anotherVersion");
|
||||
set = distributionSetManagement.updateDistributionSet(set);
|
||||
|
||||
// load also lazy stuff
|
||||
set = distributionSetManagement.findDistributionSetByIdWithDetails(set.getId());
|
||||
|
||||
assertThat(distributionSetManagement.findDistributionSetsAll(pageReq, false, true)).hasSize(1);
|
||||
public void getDistributionSet() throws Exception {
|
||||
final DistributionSet set = createTestDistributionSet(softwareManagement, distributionSetManagement);
|
||||
|
||||
// perform request
|
||||
mvc.perform(get("/rest/v1/distributionsets/{dsId}", set.getId()).accept(MediaType.APPLICATION_JSON))
|
||||
.andDo(MockMvcResultPrinter.print())
|
||||
.andExpect(status().isOk())
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
|
||||
.andExpect(content().contentType(MediaType.APPLICATION_JSON))
|
||||
.andExpect(
|
||||
jsonPath("$_links.self.href",
|
||||
equalTo("http://localhost/rest/v1/distributionsets/" + set.getId())))
|
||||
.andExpect(jsonPath("$_links.self.href",
|
||||
equalTo("http://localhost/rest/v1/distributionsets/" + set.getId())))
|
||||
.andExpect(jsonPath("$id", equalTo(set.getId().intValue())))
|
||||
.andExpect(jsonPath("$name", equalTo(set.getName())))
|
||||
.andExpect(jsonPath("$type", equalTo(set.getType().getKey())))
|
||||
@@ -432,29 +409,26 @@ public class DistributionSetResourceTest extends AbstractIntegrationTest {
|
||||
.andExpect(jsonPath("$lastModifiedBy", equalTo(set.getLastModifiedBy())))
|
||||
.andExpect(jsonPath("$lastModifiedAt", equalTo(set.getLastModifiedAt())))
|
||||
.andExpect(jsonPath("$version", equalTo(set.getVersion())))
|
||||
.andExpect(
|
||||
jsonPath("$modules.[?(@.type==" + runtimeType.getKey() + ")][0].id", equalTo(set
|
||||
.findFirstModuleByType(runtimeType).getId().intValue())))
|
||||
.andExpect(
|
||||
jsonPath("$modules.[?(@.type==" + appType.getKey() + ")][0].id", equalTo(set
|
||||
.findFirstModuleByType(appType).getId().intValue())))
|
||||
.andExpect(
|
||||
jsonPath("$modules.[?(@.type==" + osType.getKey() + ")][0].id", equalTo(set
|
||||
.findFirstModuleByType(osType).getId().intValue())));
|
||||
.andExpect(jsonPath("$modules.[?(@.type==" + runtimeType.getKey() + ")][0].id",
|
||||
equalTo(set.findFirstModuleByType(runtimeType).getId().intValue())))
|
||||
.andExpect(jsonPath("$modules.[?(@.type==" + appType.getKey() + ")][0].id",
|
||||
equalTo(set.findFirstModuleByType(appType).getId().intValue())))
|
||||
.andExpect(jsonPath("$modules.[?(@.type==" + osType.getKey() + ")][0].id",
|
||||
equalTo(set.findFirstModuleByType(osType).getId().intValue())));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@WithUser(principal = "uploadTester", allSpPermissions = true)
|
||||
public void testCreateDistributionSets() throws JSONException, Exception {
|
||||
public void createDistributionSets() throws JSONException, Exception {
|
||||
assertThat(distributionSetManagement.findDistributionSetsAll(pageReq, false, true)).hasSize(0);
|
||||
|
||||
final SoftwareModule ah = softwareManagement.createSoftwareModule(new SoftwareModule(appType, "agent-hub",
|
||||
"1.0.1", null, ""));
|
||||
final SoftwareModule jvm = softwareManagement.createSoftwareModule(new SoftwareModule(runtimeType,
|
||||
"oracle-jre", "1.7.2", null, ""));
|
||||
final SoftwareModule os = softwareManagement.createSoftwareModule(new SoftwareModule(osType, "poky", "3.0.2",
|
||||
null, ""));
|
||||
final SoftwareModule ah = softwareManagement
|
||||
.createSoftwareModule(new SoftwareModule(appType, "agent-hub", "1.0.1", null, ""));
|
||||
final SoftwareModule jvm = softwareManagement
|
||||
.createSoftwareModule(new SoftwareModule(runtimeType, "oracle-jre", "1.7.2", null, ""));
|
||||
final SoftwareModule os = softwareManagement
|
||||
.createSoftwareModule(new SoftwareModule(osType, "poky", "3.0.2", null, ""));
|
||||
|
||||
DistributionSet one = TestDataUtil.buildDistributionSet("one", "one", standardDsType, os, jvm, ah);
|
||||
DistributionSet two = TestDataUtil.buildDistributionSet("two", "two", standardDsType, os, jvm, ah);
|
||||
@@ -469,11 +443,9 @@ public class DistributionSetResourceTest extends AbstractIntegrationTest {
|
||||
final long current = System.currentTimeMillis();
|
||||
|
||||
final MvcResult mvcResult = mvc
|
||||
.perform(
|
||||
post("/rest/v1/distributionsets/").content(JsonBuilder.distributionSets(sets))
|
||||
.contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON))
|
||||
.andDo(MockMvcResultPrinter.print())
|
||||
.andExpect(status().isCreated())
|
||||
.perform(post("/rest/v1/distributionsets/").content(JsonBuilder.distributionSets(sets))
|
||||
.contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON))
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isCreated())
|
||||
.andExpect(content().contentType(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath("[0]name", equalTo(one.getName())))
|
||||
.andExpect(jsonPath("[0]description", equalTo(one.getDescription())))
|
||||
@@ -482,30 +454,24 @@ public class DistributionSetResourceTest extends AbstractIntegrationTest {
|
||||
.andExpect(jsonPath("[0]version", equalTo(one.getVersion())))
|
||||
.andExpect(jsonPath("[0]complete", equalTo(Boolean.TRUE)))
|
||||
.andExpect(jsonPath("[0]requiredMigrationStep", equalTo(one.isRequiredMigrationStep())))
|
||||
.andExpect(
|
||||
jsonPath("[0].modules.[?(@.type==" + runtimeType.getKey() + ")][0].id", equalTo(one
|
||||
.findFirstModuleByType(runtimeType).getId().intValue())))
|
||||
.andExpect(
|
||||
jsonPath("[0].modules.[?(@.type==" + appType.getKey() + ")][0].id", equalTo(one
|
||||
.findFirstModuleByType(appType).getId().intValue())))
|
||||
.andExpect(
|
||||
jsonPath("[0].modules.[?(@.type==" + osType.getKey() + ")][0].id", equalTo(one
|
||||
.findFirstModuleByType(osType).getId().intValue())))
|
||||
.andExpect(jsonPath("[0].modules.[?(@.type==" + runtimeType.getKey() + ")][0].id",
|
||||
equalTo(one.findFirstModuleByType(runtimeType).getId().intValue())))
|
||||
.andExpect(jsonPath("[0].modules.[?(@.type==" + appType.getKey() + ")][0].id",
|
||||
equalTo(one.findFirstModuleByType(appType).getId().intValue())))
|
||||
.andExpect(jsonPath("[0].modules.[?(@.type==" + osType.getKey() + ")][0].id",
|
||||
equalTo(one.findFirstModuleByType(osType).getId().intValue())))
|
||||
.andExpect(jsonPath("[1]name", equalTo(two.getName())))
|
||||
.andExpect(jsonPath("[1]description", equalTo(two.getDescription())))
|
||||
.andExpect(jsonPath("[1]complete", equalTo(Boolean.TRUE)))
|
||||
.andExpect(jsonPath("[1]type", equalTo(standardDsType.getKey())))
|
||||
.andExpect(jsonPath("[1]createdBy", equalTo("uploadTester")))
|
||||
.andExpect(jsonPath("[1]version", equalTo(two.getVersion())))
|
||||
.andExpect(
|
||||
jsonPath("[1].modules.[?(@.type==" + runtimeType.getKey() + ")][0].id", equalTo(two
|
||||
.findFirstModuleByType(runtimeType).getId().intValue())))
|
||||
.andExpect(
|
||||
jsonPath("[1].modules.[?(@.type==" + appType.getKey() + ")][0].id", equalTo(two
|
||||
.findFirstModuleByType(appType).getId().intValue())))
|
||||
.andExpect(
|
||||
jsonPath("[1].modules.[?(@.type==" + osType.getKey() + ")][0].id", equalTo(two
|
||||
.findFirstModuleByType(osType).getId().intValue())))
|
||||
.andExpect(jsonPath("[1].modules.[?(@.type==" + runtimeType.getKey() + ")][0].id",
|
||||
equalTo(two.findFirstModuleByType(runtimeType).getId().intValue())))
|
||||
.andExpect(jsonPath("[1].modules.[?(@.type==" + appType.getKey() + ")][0].id",
|
||||
equalTo(two.findFirstModuleByType(appType).getId().intValue())))
|
||||
.andExpect(jsonPath("[1].modules.[?(@.type==" + osType.getKey() + ")][0].id",
|
||||
equalTo(two.findFirstModuleByType(osType).getId().intValue())))
|
||||
.andExpect(jsonPath("[1]requiredMigrationStep", equalTo(two.isRequiredMigrationStep())))
|
||||
.andExpect(jsonPath("[2]name", equalTo(three.getName())))
|
||||
.andExpect(jsonPath("[2]description", equalTo(three.getDescription())))
|
||||
@@ -513,51 +479,48 @@ public class DistributionSetResourceTest extends AbstractIntegrationTest {
|
||||
.andExpect(jsonPath("[2]type", equalTo(standardDsType.getKey())))
|
||||
.andExpect(jsonPath("[2]createdBy", equalTo("uploadTester")))
|
||||
.andExpect(jsonPath("[2]version", equalTo(three.getVersion())))
|
||||
.andExpect(
|
||||
jsonPath("[2].modules.[?(@.type==" + runtimeType.getKey() + ")][0].id", equalTo(three
|
||||
.findFirstModuleByType(runtimeType).getId().intValue())))
|
||||
.andExpect(
|
||||
jsonPath("[2].modules.[?(@.type==" + appType.getKey() + ")][0].id", equalTo(three
|
||||
.findFirstModuleByType(appType).getId().intValue())))
|
||||
.andExpect(
|
||||
jsonPath("[2].modules.[?(@.type==" + osType.getKey() + ")][0].id", equalTo(three
|
||||
.findFirstModuleByType(osType).getId().intValue())))
|
||||
.andExpect(jsonPath("[2].modules.[?(@.type==" + runtimeType.getKey() + ")][0].id",
|
||||
equalTo(three.findFirstModuleByType(runtimeType).getId().intValue())))
|
||||
.andExpect(jsonPath("[2].modules.[?(@.type==" + appType.getKey() + ")][0].id",
|
||||
equalTo(three.findFirstModuleByType(appType).getId().intValue())))
|
||||
.andExpect(jsonPath("[2].modules.[?(@.type==" + osType.getKey() + ")][0].id",
|
||||
equalTo(three.findFirstModuleByType(osType).getId().intValue())))
|
||||
.andExpect(jsonPath("[2]requiredMigrationStep", equalTo(three.isRequiredMigrationStep()))).andReturn();
|
||||
|
||||
one = distributionSetManagement.findDistributionSetByIdWithDetails(distributionSetManagement
|
||||
.findDistributionSetByNameAndVersion("one", "one").getId());
|
||||
two = distributionSetManagement.findDistributionSetByIdWithDetails(distributionSetManagement
|
||||
.findDistributionSetByNameAndVersion("two", "two").getId());
|
||||
three = distributionSetManagement.findDistributionSetByIdWithDetails(distributionSetManagement
|
||||
.findDistributionSetByNameAndVersion("three", "three").getId());
|
||||
one = distributionSetManagement.findDistributionSetByIdWithDetails(
|
||||
distributionSetManagement.findDistributionSetByNameAndVersion("one", "one").getId());
|
||||
two = distributionSetManagement.findDistributionSetByIdWithDetails(
|
||||
distributionSetManagement.findDistributionSetByNameAndVersion("two", "two").getId());
|
||||
three = distributionSetManagement.findDistributionSetByIdWithDetails(
|
||||
distributionSetManagement.findDistributionSetByNameAndVersion("three", "three").getId());
|
||||
|
||||
assertThat(
|
||||
JsonPath.compile("[0]_links.self.href").read(mvcResult.getResponse().getContentAsString()).toString())
|
||||
.isEqualTo("http://localhost/rest/v1/distributionsets/" + one.getId());
|
||||
.isEqualTo("http://localhost/rest/v1/distributionsets/" + one.getId());
|
||||
assertThat(
|
||||
JsonPath.compile("[0]_links.type.href").read(mvcResult.getResponse().getContentAsString()).toString())
|
||||
.isEqualTo("http://localhost/rest/v1/distributionsettypes/" + one.getType().getId());
|
||||
.isEqualTo("http://localhost/rest/v1/distributionsettypes/" + one.getType().getId());
|
||||
|
||||
assertThat(JsonPath.compile("[0]id").read(mvcResult.getResponse().getContentAsString()).toString()).isEqualTo(
|
||||
String.valueOf(one.getId()));
|
||||
assertThat(JsonPath.compile("[0]id").read(mvcResult.getResponse().getContentAsString()).toString())
|
||||
.isEqualTo(String.valueOf(one.getId()));
|
||||
assertThat(
|
||||
JsonPath.compile("[1]_links.self.href").read(mvcResult.getResponse().getContentAsString()).toString())
|
||||
.isEqualTo("http://localhost/rest/v1/distributionsets/" + two.getId());
|
||||
.isEqualTo("http://localhost/rest/v1/distributionsets/" + two.getId());
|
||||
assertThat(
|
||||
JsonPath.compile("[1]_links.type.href").read(mvcResult.getResponse().getContentAsString()).toString())
|
||||
.isEqualTo("http://localhost/rest/v1/distributionsettypes/" + two.getType().getId());
|
||||
.isEqualTo("http://localhost/rest/v1/distributionsettypes/" + two.getType().getId());
|
||||
|
||||
assertThat(JsonPath.compile("[1]id").read(mvcResult.getResponse().getContentAsString()).toString()).isEqualTo(
|
||||
String.valueOf(two.getId()));
|
||||
assertThat(JsonPath.compile("[1]id").read(mvcResult.getResponse().getContentAsString()).toString())
|
||||
.isEqualTo(String.valueOf(two.getId()));
|
||||
assertThat(
|
||||
JsonPath.compile("[2]_links.self.href").read(mvcResult.getResponse().getContentAsString()).toString())
|
||||
.isEqualTo("http://localhost/rest/v1/distributionsets/" + three.getId());
|
||||
.isEqualTo("http://localhost/rest/v1/distributionsets/" + three.getId());
|
||||
assertThat(
|
||||
JsonPath.compile("[2]_links.type.href").read(mvcResult.getResponse().getContentAsString()).toString())
|
||||
.isEqualTo("http://localhost/rest/v1/distributionsettypes/" + three.getType().getId());
|
||||
.isEqualTo("http://localhost/rest/v1/distributionsettypes/" + three.getType().getId());
|
||||
|
||||
assertThat(JsonPath.compile("[2]id").read(mvcResult.getResponse().getContentAsString()).toString()).isEqualTo(
|
||||
String.valueOf(three.getId()));
|
||||
assertThat(JsonPath.compile("[2]id").read(mvcResult.getResponse().getContentAsString()).toString())
|
||||
.isEqualTo(String.valueOf(three.getId()));
|
||||
|
||||
// check in database
|
||||
assertThat(distributionSetManagement.findDistributionSetsAll(pageReq, false, true)).hasSize(3);
|
||||
@@ -611,7 +574,7 @@ public class DistributionSetResourceTest extends AbstractIntegrationTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateDistributionSet() throws Exception {
|
||||
public void updateDistributionSet() throws Exception {
|
||||
|
||||
// prepare test data
|
||||
assertThat(distributionSetManagement.findDistributionSetsAll(pageReq, false, true)).hasSize(0);
|
||||
@@ -626,21 +589,19 @@ public class DistributionSetResourceTest extends AbstractIntegrationTest {
|
||||
update.setName(null);
|
||||
update.setType(standardDsType);
|
||||
|
||||
mvc.perform(
|
||||
put("/rest/v1/distributionsets/{dsId}", set.getId()).content(JsonBuilder.distributionSet(update))
|
||||
.contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON))
|
||||
mvc.perform(put("/rest/v1/distributionsets/{dsId}", set.getId()).content(JsonBuilder.distributionSet(update))
|
||||
.contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON))
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk());
|
||||
|
||||
assertThat(
|
||||
distributionSetManagement.findDistributionSetsAll(pageReq, false, true).getContent().get(0)
|
||||
.getVersion()).isEqualTo("anotherVersion");
|
||||
assertThat(distributionSetManagement.findDistributionSetsAll(pageReq, false, true).getContent().get(0)
|
||||
.getVersion()).isEqualTo("anotherVersion");
|
||||
assertThat(
|
||||
distributionSetManagement.findDistributionSetsAll(pageReq, false, true).getContent().get(0).getName())
|
||||
.isEqualTo(set.getName());
|
||||
.isEqualTo(set.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInvalidRequestsOnDistributionSetsResource() throws Exception {
|
||||
public void invalidRequestsOnDistributionSetsResource() throws Exception {
|
||||
final DistributionSet set = TestDataUtil.generateDistributionSet("one", softwareManagement,
|
||||
distributionSetManagement);
|
||||
|
||||
@@ -659,15 +620,13 @@ public class DistributionSetResourceTest extends AbstractIntegrationTest {
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isBadRequest());
|
||||
|
||||
// bad request - bad content
|
||||
mvc.perform(
|
||||
post("/rest/v1/distributionsets").content("sdfjsdlkjfskdjf".getBytes()).contentType(
|
||||
MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print())
|
||||
mvc.perform(post("/rest/v1/distributionsets").content("sdfjsdlkjfskdjf".getBytes())
|
||||
.contentType(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print())
|
||||
.andExpect(status().isBadRequest());
|
||||
|
||||
// unsupported media type
|
||||
mvc.perform(
|
||||
post("/rest/v1/distributionsets").content(JsonBuilder.distributionSets(sets)).contentType(
|
||||
MediaType.APPLICATION_OCTET_STREAM)).andDo(MockMvcResultPrinter.print())
|
||||
mvc.perform(post("/rest/v1/distributionsets").content(JsonBuilder.distributionSets(sets))
|
||||
.contentType(MediaType.APPLICATION_OCTET_STREAM)).andDo(MockMvcResultPrinter.print())
|
||||
.andExpect(status().isUnsupportedMediaType());
|
||||
|
||||
// not allowed methods
|
||||
@@ -697,19 +656,18 @@ public class DistributionSetResourceTest extends AbstractIntegrationTest {
|
||||
jsonArray.put(new JSONObject().put("key", knownKey1).put("value", knownValue1));
|
||||
jsonArray.put(new JSONObject().put("key", knownKey2).put("value", knownValue2));
|
||||
|
||||
mvc.perform(
|
||||
post("/rest/v1/distributionsets/{dsId}/metadata", testDS.getId()).contentType(
|
||||
MediaType.APPLICATION_JSON).content(jsonArray.toString())).andDo(MockMvcResultPrinter.print())
|
||||
.andExpect(status().isCreated()).andExpect(content().contentType(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath("[0]key", equalTo(knownKey1)))
|
||||
.andExpect(jsonPath("[0]value", equalTo(knownValue1)))
|
||||
mvc.perform(post("/rest/v1/distributionsets/{dsId}/metadata", testDS.getId())
|
||||
.contentType(MediaType.APPLICATION_JSON).content(jsonArray.toString()))
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isCreated())
|
||||
.andExpect(content().contentType(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath("[0]key", equalTo(knownKey1))).andExpect(jsonPath("[0]value", equalTo(knownValue1)))
|
||||
.andExpect(jsonPath("[1]key", equalTo(knownKey2)))
|
||||
.andExpect(jsonPath("[1]value", equalTo(knownValue2)));
|
||||
|
||||
final DistributionSetMetadata metaKey1 = distributionSetManagement.findOne(new DsMetadataCompositeKey(testDS,
|
||||
knownKey1));
|
||||
final DistributionSetMetadata metaKey2 = distributionSetManagement.findOne(new DsMetadataCompositeKey(testDS,
|
||||
knownKey2));
|
||||
final DistributionSetMetadata metaKey1 = distributionSetManagement
|
||||
.findOne(new DsMetadataCompositeKey(testDS, knownKey1));
|
||||
final DistributionSetMetadata metaKey2 = distributionSetManagement
|
||||
.findOne(new DsMetadataCompositeKey(testDS, knownKey2));
|
||||
|
||||
assertThat(metaKey1.getValue()).isEqualTo(knownValue1);
|
||||
assertThat(metaKey2.getValue()).isEqualTo(knownValue2);
|
||||
@@ -724,19 +682,19 @@ public class DistributionSetResourceTest extends AbstractIntegrationTest {
|
||||
|
||||
final DistributionSet testDS = TestDataUtil.generateDistributionSet("one", softwareManagement,
|
||||
distributionSetManagement);
|
||||
distributionSetManagement.createDistributionSetMetadata(new DistributionSetMetadata(knownKey, testDS,
|
||||
knownValue));
|
||||
distributionSetManagement
|
||||
.createDistributionSetMetadata(new DistributionSetMetadata(knownKey, testDS, knownValue));
|
||||
|
||||
final JSONObject jsonObject = new JSONObject().put("key", knownKey).put("value", updateValue);
|
||||
|
||||
mvc.perform(
|
||||
put("/rest/v1/distributionsets/{dsId}/metadata/{key}", testDS.getId(), knownKey).contentType(
|
||||
MediaType.APPLICATION_JSON).content(jsonObject.toString())).andDo(MockMvcResultPrinter.print())
|
||||
.andExpect(status().isOk()).andExpect(content().contentType(MediaType.APPLICATION_JSON))
|
||||
mvc.perform(put("/rest/v1/distributionsets/{dsId}/metadata/{key}", testDS.getId(), knownKey)
|
||||
.contentType(MediaType.APPLICATION_JSON).content(jsonObject.toString()))
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
|
||||
.andExpect(content().contentType(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath("key", equalTo(knownKey))).andExpect(jsonPath("value", equalTo(updateValue)));
|
||||
|
||||
final DistributionSetMetadata assertDS = distributionSetManagement.findOne(new DsMetadataCompositeKey(testDS,
|
||||
knownKey));
|
||||
final DistributionSetMetadata assertDS = distributionSetManagement
|
||||
.findOne(new DsMetadataCompositeKey(testDS, knownKey));
|
||||
assertThat(assertDS.getValue()).isEqualTo(updateValue);
|
||||
|
||||
}
|
||||
@@ -749,8 +707,8 @@ public class DistributionSetResourceTest extends AbstractIntegrationTest {
|
||||
|
||||
final DistributionSet testDS = TestDataUtil.generateDistributionSet("one", softwareManagement,
|
||||
distributionSetManagement);
|
||||
distributionSetManagement.createDistributionSetMetadata(new DistributionSetMetadata(knownKey, testDS,
|
||||
knownValue));
|
||||
distributionSetManagement
|
||||
.createDistributionSetMetadata(new DistributionSetMetadata(knownKey, testDS, knownValue));
|
||||
|
||||
mvc.perform(delete("/rest/v1/distributionsets/{dsId}/metadata/{key}", testDS.getId(), knownKey))
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk());
|
||||
@@ -770,8 +728,8 @@ public class DistributionSetResourceTest extends AbstractIntegrationTest {
|
||||
final String knownValue = "knownValue";
|
||||
final DistributionSet testDS = TestDataUtil.generateDistributionSet("one", softwareManagement,
|
||||
distributionSetManagement);
|
||||
distributionSetManagement.createDistributionSetMetadata(new DistributionSetMetadata(knownKey, testDS,
|
||||
knownValue));
|
||||
distributionSetManagement
|
||||
.createDistributionSetMetadata(new DistributionSetMetadata(knownKey, testDS, knownValue));
|
||||
|
||||
mvc.perform(get("/rest/v1/distributionsets/{dsId}/metadata/{key}", testDS.getId(), knownKey))
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
|
||||
@@ -793,10 +751,12 @@ public class DistributionSetResourceTest extends AbstractIntegrationTest {
|
||||
distributionSetManagement.findDistributionSetById(testDS.getId()), knownValuePrefix + index));
|
||||
}
|
||||
|
||||
mvc.perform(
|
||||
get("/rest/v1/distributionsets/{dsId}/metadata?offset=" + offsetParam + "&limit=" + limitParam,
|
||||
testDS.getId())).andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
|
||||
.andExpect(jsonPath("size", equalTo(limitParam))).andExpect(jsonPath("total", equalTo(totalMetadata)));
|
||||
mvc.perform(get("/rest/v1/distributionsets/{dsId}/metadata?offset=" + offsetParam + "&limit=" + limitParam,
|
||||
testDS.getId())).andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
|
||||
.andExpect(jsonPath("size", equalTo(limitParam))).andExpect(jsonPath("total", equalTo(totalMetadata)))
|
||||
.andExpect(jsonPath("content[0].key", equalTo("knownKey0")))
|
||||
.andExpect(jsonPath("content[0].value", equalTo("knownValue0")));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -848,10 +808,9 @@ public class DistributionSetResourceTest extends AbstractIntegrationTest {
|
||||
final String rsqlFindTargetId1 = "controllerId==1";
|
||||
|
||||
mvc.perform(
|
||||
get(
|
||||
RestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + createdDs.getId()
|
||||
+ "/assignedTargets?q=" + rsqlFindTargetId1).contentType(MediaType.APPLICATION_JSON)
|
||||
.content(list.toString())).andExpect(status().isOk()).andExpect(jsonPath("total", equalTo(1)))
|
||||
get(RestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + createdDs.getId() + "/assignedTargets?q="
|
||||
+ rsqlFindTargetId1).contentType(MediaType.APPLICATION_JSON).content(list.toString()))
|
||||
.andExpect(status().isOk()).andExpect(jsonPath("total", equalTo(1)))
|
||||
.andExpect(jsonPath("size", equalTo(1))).andExpect(jsonPath("content[0].controllerId", equalTo("1")));
|
||||
}
|
||||
|
||||
@@ -886,19 +845,22 @@ public class DistributionSetResourceTest extends AbstractIntegrationTest {
|
||||
return created;
|
||||
}
|
||||
|
||||
private List<Target> sendUpdateActionStatusToTargets(final DistributionSet dsA, final Iterable<Target> targs,
|
||||
final Status status, final String... msgs) {
|
||||
public static List<Target> sendUpdateActionStatusToTargets(final ControllerManagement controllerManagament,
|
||||
final TargetManagement targetManagement, final ActionRepository actionRepository, final DistributionSet dsA,
|
||||
final Iterable<Target> targs, final Status status, final String... msgs) {
|
||||
final List<Target> result = new ArrayList<Target>();
|
||||
for (final Target t : targs) {
|
||||
final List<Action> findByTarget = actionRepository.findByTarget(t);
|
||||
for (final Action action : findByTarget) {
|
||||
result.add(sendUpdateActionStatusToTarget(status, action, t, msgs));
|
||||
result.add(sendUpdateActionStatusToTarget(controllerManagament, targetManagement, status, action, t,
|
||||
msgs));
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private Target sendUpdateActionStatusToTarget(final Status status, final Action updActA, final Target t,
|
||||
private static Target sendUpdateActionStatusToTarget(final ControllerManagement controllerManagament,
|
||||
final TargetManagement targetManagement, final Status status, final Action updActA, final Target t,
|
||||
final String... msgs) {
|
||||
updActA.setStatus(status);
|
||||
|
||||
@@ -913,4 +875,24 @@ public class DistributionSetResourceTest extends AbstractIntegrationTest {
|
||||
return targetManagement.findTargetByControllerID(t.getControllerId());
|
||||
}
|
||||
|
||||
public static DistributionSet createTestDistributionSet(final SoftwareManagement softwareManagement,
|
||||
final DistributionSetManagement distributionSetManagement) {
|
||||
|
||||
DistributionSet set = TestDataUtil.generateDistributionSet("one", softwareManagement,
|
||||
distributionSetManagement);
|
||||
set.setVersion("anotherVersion");
|
||||
set = distributionSetManagement.updateDistributionSet(set);
|
||||
|
||||
set.getModules().forEach(module -> {
|
||||
module.setDescription("updated description");
|
||||
softwareManagement.updateSoftwareModule(module);
|
||||
});
|
||||
|
||||
// load also lazy stuff
|
||||
set = distributionSetManagement.findDistributionSetByIdWithDetails(set.getId());
|
||||
|
||||
assertThat(distributionSetManagement.findDistributionSetsAll(pageReq, false, true)).hasSize(1);
|
||||
return set;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
0
hawkbit-rest-resource/src/test/java/org/eclipse/hawkbit/rest/resource/DistributionSetTypeResourceTest.java
Executable file → Normal file
0
hawkbit-rest-resource/src/test/java/org/eclipse/hawkbit/rest/resource/DistributionSetTypeResourceTest.java
Executable file → Normal file
0
hawkbit-rest-resource/src/test/java/org/eclipse/hawkbit/rest/resource/DownloadResourceTest.java
Executable file → Normal file
0
hawkbit-rest-resource/src/test/java/org/eclipse/hawkbit/rest/resource/DownloadResourceTest.java
Executable file → Normal file
183
hawkbit-rest-resource/src/test/java/org/eclipse/hawkbit/rest/resource/JsonBuilder.java
Executable file → Normal file
183
hawkbit-rest-resource/src/test/java/org/eclipse/hawkbit/rest/resource/JsonBuilder.java
Executable file → Normal file
@@ -58,6 +58,41 @@ public abstract class JsonBuilder {
|
||||
|
||||
}
|
||||
|
||||
public static String softwareModulesCreatableFieldsOnly(final List<SoftwareModule> modules) throws JSONException {
|
||||
final StringBuilder builder = new StringBuilder();
|
||||
|
||||
builder.append("[");
|
||||
int i = 0;
|
||||
for (final SoftwareModule module : modules) {
|
||||
try {
|
||||
builder.append(new JSONObject().put("name", module.getName())
|
||||
.put("description", module.getDescription()).put("type", module.getType().getKey())
|
||||
.put("vendor", module.getVendor()).put("version", module.getVersion()).toString());
|
||||
} catch (final Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
if (++i < modules.size()) {
|
||||
builder.append(",");
|
||||
}
|
||||
}
|
||||
|
||||
builder.append("]");
|
||||
|
||||
return builder.toString();
|
||||
|
||||
}
|
||||
|
||||
public static String softwareModuleUpdatableFieldsOnly(final SoftwareModule module) throws JSONException {
|
||||
final StringBuilder builder = new StringBuilder();
|
||||
|
||||
builder.append(new JSONObject().put("description", module.getDescription()).put("vendor", module.getVendor())
|
||||
.toString());
|
||||
|
||||
return builder.toString();
|
||||
|
||||
}
|
||||
|
||||
public static String softwareModuleTypes(final List<SoftwareModuleType> types) throws JSONException {
|
||||
final StringBuilder builder = new StringBuilder();
|
||||
|
||||
@@ -85,9 +120,35 @@ public abstract class JsonBuilder {
|
||||
|
||||
}
|
||||
|
||||
public static String softwareModuleTypesCreatableFieldsOnly(final List<SoftwareModuleType> types)
|
||||
throws JSONException {
|
||||
final StringBuilder builder = new StringBuilder();
|
||||
|
||||
builder.append("[");
|
||||
int i = 0;
|
||||
for (final SoftwareModuleType module : types) {
|
||||
try {
|
||||
builder.append(new JSONObject().put("name", module.getName())
|
||||
.put("description", module.getDescription()).put("key", module.getKey())
|
||||
.put("maxAssignments", module.getMaxAssignments()).toString());
|
||||
} catch (final Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
if (++i < types.size()) {
|
||||
builder.append(",");
|
||||
}
|
||||
}
|
||||
|
||||
builder.append("]");
|
||||
|
||||
return builder.toString();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* builds a json string for the feedback for the execution "proceeding".
|
||||
*
|
||||
*
|
||||
* @param id
|
||||
* of the Action feedback refers to
|
||||
* @return the built string
|
||||
@@ -99,7 +160,7 @@ public abstract class JsonBuilder {
|
||||
|
||||
/**
|
||||
* builds a certain json string for a action feedback.
|
||||
*
|
||||
*
|
||||
* @param id
|
||||
* of the action the feedback refers to
|
||||
* @param execution
|
||||
@@ -108,14 +169,20 @@ public abstract class JsonBuilder {
|
||||
* @throws JSONException
|
||||
*/
|
||||
public static String deploymentActionFeedback(final String id, final String execution) throws JSONException {
|
||||
return deploymentActionFeedback(id, execution, "none");
|
||||
return deploymentActionFeedback(id, execution, "none", RandomStringUtils.randomAscii(1000));
|
||||
|
||||
}
|
||||
|
||||
public static String deploymentActionFeedback(final String id, final String execution, final String finished)
|
||||
public static String deploymentActionFeedback(final String id, final String execution, final String message)
|
||||
throws JSONException {
|
||||
return deploymentActionFeedback(id, execution, "none", message);
|
||||
|
||||
}
|
||||
|
||||
public static String deploymentActionFeedback(final String id, final String execution, final String finished,
|
||||
final String message) throws JSONException {
|
||||
final List<String> messages = new ArrayList<String>();
|
||||
messages.add(RandomStringUtils.randomAscii(1000));
|
||||
messages.add(message);
|
||||
|
||||
return new JSONObject().put("id", id).put("time", "20140511T121314")
|
||||
.put("status",
|
||||
@@ -166,6 +233,38 @@ public abstract class JsonBuilder {
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
public static String distributionSetTypesCreateValidFieldsOnly(final List<DistributionSetType> types) {
|
||||
final StringBuilder builder = new StringBuilder();
|
||||
|
||||
builder.append("[");
|
||||
int i = 0;
|
||||
for (final DistributionSetType module : types) {
|
||||
|
||||
try {
|
||||
|
||||
final JSONArray osmTypes = new JSONArray();
|
||||
module.getOptionalModuleTypes().forEach(smt -> osmTypes.put(new JSONObject().put("id", smt.getId())));
|
||||
|
||||
final JSONArray msmTypes = new JSONArray();
|
||||
module.getMandatoryModuleTypes().forEach(smt -> msmTypes.put(new JSONObject().put("id", smt.getId())));
|
||||
|
||||
builder.append(new JSONObject().put("name", module.getName())
|
||||
.put("description", module.getDescription()).put("key", module.getKey())
|
||||
.put("optionalmodules", osmTypes).put("mandatorymodules", msmTypes).toString());
|
||||
} catch (final Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
if (++i < types.size()) {
|
||||
builder.append(",");
|
||||
}
|
||||
}
|
||||
|
||||
builder.append("]");
|
||||
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
public static String distributionSets(final List<DistributionSet> sets) throws JSONException {
|
||||
final StringBuilder builder = new StringBuilder();
|
||||
|
||||
@@ -189,6 +288,64 @@ public abstract class JsonBuilder {
|
||||
|
||||
}
|
||||
|
||||
public static String distributionSetsCreateValidFieldsOnly(final List<DistributionSet> sets) throws JSONException {
|
||||
final StringBuilder builder = new StringBuilder();
|
||||
|
||||
builder.append("[");
|
||||
int i = 0;
|
||||
for (final DistributionSet set : sets) {
|
||||
try {
|
||||
builder.append(distributionSetCreateValidFieldsOnly(set));
|
||||
} catch (final Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
if (++i < sets.size()) {
|
||||
builder.append(",");
|
||||
}
|
||||
}
|
||||
|
||||
builder.append("]");
|
||||
|
||||
return builder.toString();
|
||||
|
||||
}
|
||||
|
||||
public static String distributionSetCreateValidFieldsOnly(final DistributionSet set) throws JSONException {
|
||||
|
||||
final List<JSONObject> modules = set.getModules().stream().map(module -> {
|
||||
try {
|
||||
return new JSONObject().put("id", module.getId());
|
||||
} catch (final Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return null;
|
||||
}).collect(Collectors.toList());
|
||||
|
||||
return new JSONObject().put("name", set.getName()).put("description", set.getDescription())
|
||||
.put("type", set.getType() == null ? null : set.getType().getKey()).put("version", set.getVersion())
|
||||
.put("requiredMigrationStep", set.isRequiredMigrationStep()).put("modules", modules).toString();
|
||||
|
||||
}
|
||||
|
||||
public static String distributionSetUpdateValidFieldsOnly(final DistributionSet set) throws JSONException {
|
||||
|
||||
final List<JSONObject> modules = set.getModules().stream().map(module -> {
|
||||
try {
|
||||
return new JSONObject().put("id", module.getId());
|
||||
} catch (final Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return null;
|
||||
}).collect(Collectors.toList());
|
||||
|
||||
return new JSONObject().put("name", set.getName()).put("description", set.getDescription())
|
||||
.put("version", set.getVersion()).toString();
|
||||
|
||||
}
|
||||
|
||||
public static String distributionSet(final DistributionSet set) throws JSONException {
|
||||
|
||||
final List<JSONObject> modules = set.getModules().stream().map(module -> {
|
||||
@@ -202,10 +359,10 @@ public abstract class JsonBuilder {
|
||||
}).collect(Collectors.toList());
|
||||
|
||||
return new JSONObject().put("name", set.getName()).put("description", set.getDescription())
|
||||
.put("type", set.getType().getKey()).put("id", Long.MAX_VALUE).put("version", set.getVersion())
|
||||
.put("createdAt", "0").put("updatedAt", "0").put("createdBy", "fghdfkjghdfkjh")
|
||||
.put("updatedBy", "fghdfkjghdfkjh").put("requiredMigrationStep", set.isRequiredMigrationStep())
|
||||
.put("modules", modules).toString();
|
||||
.put("type", set.getType() == null ? null : set.getType().getKey()).put("id", Long.MAX_VALUE)
|
||||
.put("version", set.getVersion()).put("createdAt", "0").put("updatedAt", "0")
|
||||
.put("createdBy", "fghdfkjghdfkjh").put("updatedBy", "fghdfkjghdfkjh")
|
||||
.put("requiredMigrationStep", set.isRequiredMigrationStep()).put("modules", modules).toString();
|
||||
|
||||
}
|
||||
|
||||
@@ -239,8 +396,14 @@ public abstract class JsonBuilder {
|
||||
}
|
||||
|
||||
public static String cancelActionFeedback(final String id, final String execution) throws JSONException {
|
||||
return cancelActionFeedback(id, execution, RandomStringUtils.randomAscii(1000));
|
||||
|
||||
}
|
||||
|
||||
public static String cancelActionFeedback(final String id, final String execution, final String message)
|
||||
throws JSONException {
|
||||
final List<String> messages = new ArrayList<String>();
|
||||
messages.add(RandomStringUtils.randomAscii(1000));
|
||||
messages.add(message);
|
||||
return new JSONObject().put("id", id).put("time", "20140511T121314")
|
||||
.put("status",
|
||||
new JSONObject().put("execution", execution)
|
||||
|
||||
0
hawkbit-rest-resource/src/test/java/org/eclipse/hawkbit/rest/resource/RSQLUtilityTest.java
Executable file → Normal file
0
hawkbit-rest-resource/src/test/java/org/eclipse/hawkbit/rest/resource/RSQLUtilityTest.java
Executable file → Normal file
0
hawkbit-rest-resource/src/test/java/org/eclipse/hawkbit/rest/resource/ResourceUtility.java
Executable file → Normal file
0
hawkbit-rest-resource/src/test/java/org/eclipse/hawkbit/rest/resource/ResourceUtility.java
Executable file → Normal file
0
hawkbit-rest-resource/src/test/java/org/eclipse/hawkbit/rest/resource/SMRessourceMisingMongoDbConnectionTest.java
Executable file → Normal file
0
hawkbit-rest-resource/src/test/java/org/eclipse/hawkbit/rest/resource/SMRessourceMisingMongoDbConnectionTest.java
Executable file → Normal file
119
hawkbit-rest-resource/src/test/java/org/eclipse/hawkbit/rest/resource/SoftwareModuleResourceTest.java
Executable file → Normal file
119
hawkbit-rest-resource/src/test/java/org/eclipse/hawkbit/rest/resource/SoftwareModuleResourceTest.java
Executable file → Normal file
@@ -64,16 +64,14 @@ import ru.yandex.qatools.allure.annotations.Stories;
|
||||
/**
|
||||
* Tests for {@link SoftwareModuleResource} {@link RestController}.
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
@Features("Component Tests - Management RESTful API")
|
||||
@Stories("Software Module Resource")
|
||||
// TODO: fully document tests -> @Description for long text and reasonable
|
||||
// method name as short text
|
||||
public class SoftwareModuleResourceTest extends AbstractIntegrationTestWithMongoDB {
|
||||
|
||||
@Test
|
||||
@Description("Tests the update of software module metadata. It is verfied that only the selected fields for the update are really updated and the modification values are filled (i.e. updated by and at).")
|
||||
@WithUser(principal = "smUpdateTester", allSpPermissions = true)
|
||||
public void updateSoftwareModuleOnlyDescriptionAndVendorNameUntouched() throws Exception {
|
||||
final String knownSWName = "name1";
|
||||
final String knownSWVersion = "version1";
|
||||
@@ -99,10 +97,16 @@ public class SoftwareModuleResourceTest extends AbstractIntegrationTestWithMongo
|
||||
final String body = new JSONObject().put("vendor", updateVendor).put("description", updateDescription)
|
||||
.put("name", "nameShouldNotBeChanged").toString();
|
||||
|
||||
// ensures that we are not to fast so that last modified is not set
|
||||
// correctly
|
||||
Thread.sleep(1);
|
||||
|
||||
mvc.perform(put("/rest/v1/softwaremodules/{smId}", sm.getId()).content(body)
|
||||
.contentType(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$id", equalTo(sm.getId().intValue())))
|
||||
.andExpect(jsonPath("$vendor", equalTo(updateVendor)))
|
||||
.andExpect(jsonPath("$lastModifiedBy", equalTo("smUpdateTester")))
|
||||
.andExpect(jsonPath("$lastModifiedAt", not(equalTo(sm.getLastModifiedAt()))))
|
||||
.andExpect(jsonPath("$description", equalTo(updateDescription)))
|
||||
.andExpect(jsonPath("$name", equalTo(knownSWName))).andReturn();
|
||||
|
||||
@@ -112,12 +116,13 @@ public class SoftwareModuleResourceTest extends AbstractIntegrationTestWithMongo
|
||||
* Test method for
|
||||
* {@link org.eclipse.hawkbit.rest.resource.SoftwareModuleResource#uploadArtifact(java.lang.Long, org.springframework.web.multipart.MultipartFile)}
|
||||
* .
|
||||
*
|
||||
*
|
||||
* @throws Exception
|
||||
* if test fails
|
||||
*/
|
||||
@Test
|
||||
public void testUploadArtifact() throws Exception {
|
||||
@Description("Tests the uppload of an artifact binary. The upload is executed and the content checked in the repository for completenes.")
|
||||
public void uploadArtifact() throws Exception {
|
||||
// prepare repo
|
||||
assertThat(softwareManagement.findSoftwareModulesAll(pageReq)).hasSize(0);
|
||||
assertThat(artifactRepository.findAll()).hasSize(0);
|
||||
@@ -139,6 +144,7 @@ public class SoftwareModuleResourceTest extends AbstractIntegrationTestWithMongo
|
||||
.andExpect(content().contentType(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath("$type", equalTo("local"))).andExpect(jsonPath("$hashes.md5", equalTo(md5sum)))
|
||||
.andExpect(jsonPath("$hashes.sha1", equalTo(sha1sum)))
|
||||
.andExpect(jsonPath("$size", equalTo(random.length)))
|
||||
.andExpect(jsonPath("$providedFilename", equalTo("origFilename"))).andReturn();
|
||||
|
||||
// check rest of response compared to DB
|
||||
@@ -179,7 +185,8 @@ public class SoftwareModuleResourceTest extends AbstractIntegrationTestWithMongo
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEmptyUploadArtifact() throws Exception {
|
||||
@Description("Verfies that the system does not accept empty artifact uploads. Expected response: BAD REQUEST")
|
||||
public void emptyUploadArtifact() throws Exception {
|
||||
assertThat(softwareManagement.findSoftwareModulesAll(pageReq)).hasSize(0);
|
||||
assertThat(artifactRepository.findAll()).hasSize(0);
|
||||
|
||||
@@ -194,7 +201,8 @@ public class SoftwareModuleResourceTest extends AbstractIntegrationTestWithMongo
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDuplicateUploadArtifact() throws Exception {
|
||||
@Description("Verfies that the system does not accept identical artifacts uploads for the same software module. Expected response: CONFLICT")
|
||||
public void duplicateUploadArtifact() throws Exception {
|
||||
assertThat(softwareManagement.findSoftwareModulesAll(pageReq)).hasSize(0);
|
||||
assertThat(artifactRepository.findAll()).hasSize(0);
|
||||
|
||||
@@ -218,7 +226,8 @@ public class SoftwareModuleResourceTest extends AbstractIntegrationTestWithMongo
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUploadArtifactWithCustomName() throws Exception {
|
||||
@Description("verfies that option to upload artifacts with a custom defined by metadata, i.e. not the file name of the binary itself.")
|
||||
public void uploadArtifactWithCustomName() throws Exception {
|
||||
// prepare repo
|
||||
assertThat(softwareManagement.findSoftwareModulesAll(pageReq)).hasSize(0);
|
||||
assertThat(artifactRepository.findAll()).hasSize(0);
|
||||
@@ -247,7 +256,8 @@ public class SoftwareModuleResourceTest extends AbstractIntegrationTestWithMongo
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUploadArtifactWithHashCheck() throws Exception {
|
||||
@Description("Verfies that the system refuses upload of an artifact where the provided hash sums do not match. Expected result: BAD REQUEST")
|
||||
public void uploadArtifactWithHashCheck() throws Exception {
|
||||
// prepare repo
|
||||
assertThat(softwareManagement.findSoftwareModulesAll(pageReq)).hasSize(0);
|
||||
assertThat(artifactRepository.findAll()).hasSize(0);
|
||||
@@ -310,16 +320,9 @@ public class SoftwareModuleResourceTest extends AbstractIntegrationTestWithMongo
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for
|
||||
* {@link org.eclipse.hawkbit.rest.resource.SoftwareModuleResource#downloadArtifact(java.lang.Long, javax.servlet.http.HttpServletResponse)}
|
||||
* .
|
||||
*
|
||||
* @throws Exception
|
||||
* if test fails
|
||||
*/
|
||||
@Test
|
||||
public void testDownloadArtifact() throws Exception {
|
||||
@Description("Tests binary download of an artifact including verfication that the downloaded binary is consistent and that the etag header is as expected identical to the SHA1 hash of the file.")
|
||||
public void downloadArtifact() throws Exception {
|
||||
assertThat(softwareManagement.findSoftwareModulesAll(pageReq)).hasSize(0);
|
||||
assertThat(artifactRepository.findAll()).hasSize(0);
|
||||
|
||||
@@ -336,13 +339,16 @@ public class SoftwareModuleResourceTest extends AbstractIntegrationTestWithMongo
|
||||
final MvcResult result = mvc
|
||||
.perform(
|
||||
get("/rest/v1/softwaremodules/{smId}/artifacts/{artId}/download", sm.getId(), artifact.getId()))
|
||||
.andExpect(header().string("ETag", artifact.getSha1Hash())).andReturn();
|
||||
.andExpect(header().string("ETag", artifact.getSha1Hash()))
|
||||
.andExpect(content().contentType(MediaType.APPLICATION_OCTET_STREAM)).andReturn();
|
||||
|
||||
assertTrue(Arrays.equals(result.getResponse().getContentAsByteArray(), random));
|
||||
|
||||
final MvcResult result2 = mvc.perform(
|
||||
get("/rest/v1/softwaremodules/{smId}/artifacts/{artId}/download", sm.getId(), artifact2.getId()))
|
||||
.andExpect(header().string("ETag", artifact2.getSha1Hash())).andReturn();
|
||||
final MvcResult result2 = mvc
|
||||
.perform(get("/rest/v1/softwaremodules/{smId}/artifacts/{artId}/download", sm.getId(),
|
||||
artifact2.getId()))
|
||||
.andExpect(header().string("ETag", artifact2.getSha1Hash()))
|
||||
.andExpect(content().contentType(MediaType.APPLICATION_OCTET_STREAM)).andReturn();
|
||||
|
||||
assertTrue(Arrays.equals(result2.getResponse().getContentAsByteArray(), random));
|
||||
|
||||
@@ -351,7 +357,8 @@ public class SoftwareModuleResourceTest extends AbstractIntegrationTestWithMongo
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetArtifact() throws Exception {
|
||||
@Description("Verifies the listing of one defined artifact assigned to a given software module. That includes the artifact metadata and download links.")
|
||||
public void getArtifact() throws Exception {
|
||||
// check baseline
|
||||
assertThat(softwareManagement.findSoftwareModulesAll(pageReq)).hasSize(0);
|
||||
assertThat(artifactRepository.findAll()).hasSize(0);
|
||||
@@ -381,7 +388,8 @@ public class SoftwareModuleResourceTest extends AbstractIntegrationTestWithMongo
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetArtifacts() throws Exception {
|
||||
@Description("Verifies the listing of all artifacts assigned to a software module. That includes the artifact metadata and download links.")
|
||||
public void getArtifacts() throws Exception {
|
||||
SoftwareModule sm = new SoftwareModule(osType, "name 1", "version 1", null, null);
|
||||
sm = softwareManagement.createSoftwareModule(sm);
|
||||
|
||||
@@ -420,7 +428,8 @@ public class SoftwareModuleResourceTest extends AbstractIntegrationTestWithMongo
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInvalidRequestsOnArtifactResource() throws Exception {
|
||||
@Description("Verfies that the system refuses unsupported request types and answers as defined to them, e.g. NOT FOUND on a non existing resource. Or a HTTP POST for updating a resource results in METHOD NOT ALLOWED etc.")
|
||||
public void invalidRequestsOnArtifactResource() throws Exception {
|
||||
final byte random[] = RandomStringUtils.random(5 * 1024).getBytes();
|
||||
final MockMultipartFile file = new MockMultipartFile("file", "orig", null, random);
|
||||
|
||||
@@ -455,7 +464,8 @@ public class SoftwareModuleResourceTest extends AbstractIntegrationTestWithMongo
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInvalidRequestsOnSoftwaremodulesResource() throws Exception {
|
||||
@Description("Verfies that the system refuses unsupported request types and answers as defined to them, e.g. NOT FOUND on a non existing resource. Or a HTTP POST for updating a resource results in METHOD NOT ALLOWED etc.")
|
||||
public void invalidRequestsOnSoftwaremodulesResource() throws Exception {
|
||||
SoftwareModule sm = new SoftwareModule(osType, "name 1", "version 1", null, null);
|
||||
sm = softwareManagement.createSoftwareModule(sm);
|
||||
|
||||
@@ -493,7 +503,8 @@ public class SoftwareModuleResourceTest extends AbstractIntegrationTestWithMongo
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetSoftwareModulesWithoutAddtionalRequestParameters() throws Exception {
|
||||
@Description("Test of modules retrieval without any parameters. Will return all modules in the system as defined by standard page size.")
|
||||
public void getSoftwareModulesWithoutAddtionalRequestParameters() throws Exception {
|
||||
final int modules = 5;
|
||||
createSoftwareModulesAlphabetical(modules);
|
||||
mvc.perform(get(RestConstants.SOFTWAREMODULE_V1_REQUEST_MAPPING)).andDo(MockMvcResultPrinter.print())
|
||||
@@ -504,7 +515,8 @@ public class SoftwareModuleResourceTest extends AbstractIntegrationTestWithMongo
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetSoftwareModulesWithPagingLimitRequestParameter() throws Exception {
|
||||
@Description("Test of modules retrieval with paging limit parameter. Will return all modules in the system as defined by given page size.")
|
||||
public void detSoftwareModulesWithPagingLimitRequestParameter() throws Exception {
|
||||
final int modules = 5;
|
||||
final int limitSize = 1;
|
||||
createSoftwareModulesAlphabetical(modules);
|
||||
@@ -517,7 +529,8 @@ public class SoftwareModuleResourceTest extends AbstractIntegrationTestWithMongo
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetSoftwareModulesWithPagingLimitAndOffsetRequestParameter() throws Exception {
|
||||
@Description("Test of modules retrieval with paging limit offset parameters. Will return all modules in the system as defined by given page size starting from given offset.")
|
||||
public void getSoftwareModulesWithPagingLimitAndOffsetRequestParameter() throws Exception {
|
||||
final int modules = 5;
|
||||
final int offsetParam = 2;
|
||||
final int expectedSize = modules - offsetParam;
|
||||
@@ -533,7 +546,8 @@ public class SoftwareModuleResourceTest extends AbstractIntegrationTestWithMongo
|
||||
|
||||
@Test
|
||||
@WithUser(principal = "uploadTester", allSpPermissions = true)
|
||||
public void testGetSoftwareModules() throws Exception {
|
||||
@Description("Test retrieval of all software modules the user has access to.")
|
||||
public void getSoftwareModules() throws Exception {
|
||||
assertThat(softwareManagement.findSoftwareModulesAll(pageReq)).hasSize(0);
|
||||
|
||||
SoftwareModule os = new SoftwareModule(osType, "name1", "version1", "description1", "vendor1");
|
||||
@@ -559,6 +573,11 @@ public class SoftwareModuleResourceTest extends AbstractIntegrationTestWithMongo
|
||||
equalTo("http://localhost/rest/v1/softwaremoduletypes/" + osType.getId())))
|
||||
.andExpect(jsonPath("$content.[?(@.id==" + os.getId() + ")][0]._links.self.href",
|
||||
equalTo("http://localhost/rest/v1/softwaremodules/" + os.getId())))
|
||||
.andExpect(jsonPath("$content.[?(@.id==" + os.getId() + ")][0]._links.artifacts.href",
|
||||
equalTo("http://localhost/rest/v1/softwaremodules/" + os.getId() + "/artifacts")))
|
||||
.andExpect(jsonPath("$content.[?(@.id==" + os.getId() + ")][0]._links.metadata.href",
|
||||
equalTo("http://localhost/rest/v1/softwaremodules/" + os.getId()
|
||||
+ "/metadata?offset=0&limit=50")))
|
||||
.andExpect(jsonPath("$content.[?(@.id==" + jvm.getId() + ")][0].name", equalTo("name1")))
|
||||
.andExpect(jsonPath("$content.[?(@.id==" + jvm.getId() + ")][0].version", equalTo("version1")))
|
||||
.andExpect(jsonPath("$content.[?(@.id==" + jvm.getId() + ")][0].description", equalTo("description1")))
|
||||
@@ -571,6 +590,11 @@ public class SoftwareModuleResourceTest extends AbstractIntegrationTestWithMongo
|
||||
equalTo("http://localhost/rest/v1/softwaremoduletypes/" + runtimeType.getId())))
|
||||
.andExpect(jsonPath("$content.[?(@.id==" + jvm.getId() + ")][0]._links.self.href",
|
||||
equalTo("http://localhost/rest/v1/softwaremodules/" + jvm.getId())))
|
||||
.andExpect(jsonPath("$content.[?(@.id==" + jvm.getId() + ")][0]._links.artifacts.href",
|
||||
equalTo("http://localhost/rest/v1/softwaremodules/" + jvm.getId() + "/artifacts")))
|
||||
.andExpect(jsonPath("$content.[?(@.id==" + jvm.getId() + ")][0]._links.metadata.href",
|
||||
equalTo("http://localhost/rest/v1/softwaremodules/" + jvm.getId()
|
||||
+ "/metadata?offset=0&limit=50")))
|
||||
.andExpect(jsonPath("$content.[?(@.id==" + ah.getId() + ")][0].name", equalTo("name1")))
|
||||
.andExpect(jsonPath("$content.[?(@.id==" + ah.getId() + ")][0].version", equalTo("version1")))
|
||||
.andExpect(jsonPath("$content.[?(@.id==" + ah.getId() + ")][0].description", equalTo("description1")))
|
||||
@@ -578,6 +602,11 @@ public class SoftwareModuleResourceTest extends AbstractIntegrationTestWithMongo
|
||||
.andExpect(jsonPath("$content.[?(@.id==" + ah.getId() + ")][0].type", equalTo("application")))
|
||||
.andExpect(jsonPath("$content.[?(@.id==" + ah.getId() + ")][0].createdBy", equalTo("uploadTester")))
|
||||
.andExpect(jsonPath("$content.[?(@.id==" + ah.getId() + ")][0].createdAt", equalTo(ah.getCreatedAt())))
|
||||
.andExpect(jsonPath("$content.[?(@.id==" + ah.getId() + ")][0]._links.artifacts.href",
|
||||
equalTo("http://localhost/rest/v1/softwaremodules/" + ah.getId() + "/artifacts")))
|
||||
.andExpect(jsonPath("$content.[?(@.id==" + ah.getId() + ")][0]._links.metadata.href",
|
||||
equalTo("http://localhost/rest/v1/softwaremodules/" + ah.getId()
|
||||
+ "/metadata?offset=0&limit=50")))
|
||||
.andExpect(jsonPath("$content.[?(@.id==" + ah.getId() + ")][0]._links.type.href",
|
||||
equalTo("http://localhost/rest/v1/softwaremoduletypes/" + appType.getId())))
|
||||
.andExpect(jsonPath("$content.[?(@.id==" + ah.getId() + ")][0]._links.self.href",
|
||||
@@ -587,7 +616,8 @@ public class SoftwareModuleResourceTest extends AbstractIntegrationTestWithMongo
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetSoftwareModulesWithFilterParameters() throws Exception {
|
||||
@Description("Test the various filter parameters, e.g. filter by name or type of the module.")
|
||||
public void getSoftwareModulesWithFilterParameters() throws Exception {
|
||||
assertThat(softwareManagement.findSoftwareModulesAll(pageReq)).hasSize(0);
|
||||
|
||||
SoftwareModule os1 = new SoftwareModule(osType, "osName1", "1.0.0", "description1", "vendor1");
|
||||
@@ -663,14 +693,16 @@ public class SoftwareModuleResourceTest extends AbstractIntegrationTestWithMongo
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetSoftwareModulesWithSyntaxErrorFilterParameter() throws Exception {
|
||||
@Description("Verfies that the system answers as defined in case of a wrong filter parameter syntax. Expected result: BAD REQUEST with error description.")
|
||||
public void getSoftwareModulesWithSyntaxErrorFilterParameter() throws Exception {
|
||||
mvc.perform(get("/rest/v1/softwaremodules?q=wrongFIQLSyntax").accept(MediaType.APPLICATION_JSON))
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isBadRequest())
|
||||
.andExpect(jsonPath("$errorCode", equalTo("hawkbit.server.error.rest.param.rsqlParamSyntax")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetSoftwareModulesWithUnknownFieldErrorFilterParameter() throws Exception {
|
||||
@Description("Verfies that the system answers as defined in case of a wnon extsing field used in filter. Expected result: BAD REQUEST with error description.")
|
||||
public void getSoftwareModulesWithUnknownFieldErrorFilterParameter() throws Exception {
|
||||
mvc.perform(get("/rest/v1/softwaremodules?q=wrongField==abc").accept(MediaType.APPLICATION_JSON))
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isBadRequest())
|
||||
.andExpect(jsonPath("$errorCode", equalTo("hawkbit.server.error.rest.param.rsqlInvalidField")));
|
||||
@@ -693,6 +725,9 @@ public class SoftwareModuleResourceTest extends AbstractIntegrationTestWithMongo
|
||||
.andExpect(jsonPath("$vendor", equalTo("vendor1"))).andExpect(jsonPath("$type", equalTo("os")))
|
||||
.andExpect(jsonPath("$createdBy", equalTo("uploadTester")))
|
||||
.andExpect(jsonPath("$createdAt", equalTo(os.getCreatedAt())))
|
||||
.andExpect(jsonPath("$_links.metadata.href",
|
||||
equalTo("http://localhost/rest/v1/softwaremodules/" + os.getId()
|
||||
+ "/metadata?offset=0&limit=50")))
|
||||
.andExpect(jsonPath("$_links.type.href",
|
||||
equalTo("http://localhost/rest/v1/softwaremoduletypes/" + osType.getId())))
|
||||
.andExpect(jsonPath("$_links.artifacts.href",
|
||||
@@ -709,6 +744,9 @@ public class SoftwareModuleResourceTest extends AbstractIntegrationTestWithMongo
|
||||
.andExpect(jsonPath("$vendor", equalTo("vendor1"))).andExpect(jsonPath("$type", equalTo("runtime")))
|
||||
.andExpect(jsonPath("$createdBy", equalTo("uploadTester")))
|
||||
.andExpect(jsonPath("$createdAt", equalTo(jvm.getCreatedAt())))
|
||||
.andExpect(jsonPath("$_links.metadata.href",
|
||||
equalTo("http://localhost/rest/v1/softwaremodules/" + jvm.getId()
|
||||
+ "/metadata?offset=0&limit=50")))
|
||||
.andExpect(jsonPath("$_links.type.href",
|
||||
equalTo("http://localhost/rest/v1/softwaremoduletypes/" + runtimeType.getId())))
|
||||
.andExpect(jsonPath("$_links.artifacts.href",
|
||||
@@ -725,6 +763,9 @@ public class SoftwareModuleResourceTest extends AbstractIntegrationTestWithMongo
|
||||
.andExpect(jsonPath("$vendor", equalTo("vendor1"))).andExpect(jsonPath("$type", equalTo("application")))
|
||||
.andExpect(jsonPath("$createdBy", equalTo("uploadTester")))
|
||||
.andExpect(jsonPath("$createdAt", equalTo(ah.getCreatedAt())))
|
||||
.andExpect(jsonPath("$_links.metadata.href",
|
||||
equalTo("http://localhost/rest/v1/softwaremodules/" + ah.getId()
|
||||
+ "/metadata?offset=0&limit=50")))
|
||||
.andExpect(jsonPath("$_links.type.href",
|
||||
equalTo("http://localhost/rest/v1/softwaremoduletypes/" + appType.getId())))
|
||||
.andExpect(jsonPath("$_links.artifacts.href",
|
||||
@@ -735,6 +776,7 @@ public class SoftwareModuleResourceTest extends AbstractIntegrationTestWithMongo
|
||||
|
||||
@Test
|
||||
@WithUser(principal = "uploadTester", allSpPermissions = true)
|
||||
@Description("Verfies that the create request actually results in the creation of the modules in the repository.")
|
||||
public void createSoftwareModules() throws JSONException, Exception {
|
||||
assertThat(softwareManagement.findSoftwareModulesAll(pageReq)).hasSize(0);
|
||||
|
||||
@@ -812,6 +854,7 @@ public class SoftwareModuleResourceTest extends AbstractIntegrationTestWithMongo
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Verifies successfull deletion of software modules that are not in use, i.e. assigned to a DS.")
|
||||
public void deleteUnassignedSoftwareModule() throws Exception {
|
||||
assertThat(softwareManagement.findSoftwareModulesAll(pageReq)).isEmpty();
|
||||
assertThat(artifactRepository.findAll()).isEmpty();
|
||||
@@ -837,6 +880,7 @@ public class SoftwareModuleResourceTest extends AbstractIntegrationTestWithMongo
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Verifies successfull deletion of software modules that are in use, i.e. assigned to a DS which should result in movinf the module to the archive.")
|
||||
public void deleteAssignedSoftwareModule() throws Exception {
|
||||
// check baseline
|
||||
assertThat(softwareManagement.findSoftwareModulesAll(pageReq)).isEmpty();
|
||||
@@ -868,7 +912,8 @@ public class SoftwareModuleResourceTest extends AbstractIntegrationTestWithMongo
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteArtifact() throws Exception {
|
||||
@Description("Tests the deletion of an artifact including verfication that the artifact is actually erased in the repository and removed from the software module.")
|
||||
public void deleteArtifact() throws Exception {
|
||||
assertThat(softwareManagement.findSoftwareModulesAll(pageReq)).isEmpty();
|
||||
assertThat(artifactRepository.findAll()).isEmpty();
|
||||
|
||||
@@ -902,6 +947,7 @@ public class SoftwareModuleResourceTest extends AbstractIntegrationTestWithMongo
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Verfies the successfull creation of metadata.")
|
||||
public void createMetadata() throws Exception {
|
||||
|
||||
final String knownKey1 = "knownKey1";
|
||||
@@ -931,6 +977,7 @@ public class SoftwareModuleResourceTest extends AbstractIntegrationTestWithMongo
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Verfies the successfull update of metadata based on given key.")
|
||||
public void updateMetadata() throws Exception {
|
||||
// prepare and create metadata for update
|
||||
final String knownKey = "knownKey";
|
||||
@@ -954,6 +1001,7 @@ public class SoftwareModuleResourceTest extends AbstractIntegrationTestWithMongo
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Verfies the successfull deletion of metadata entry.")
|
||||
public void deleteMetadata() throws Exception {
|
||||
// prepare and create metadata for deletion
|
||||
final String knownKey = "knownKey";
|
||||
@@ -975,6 +1023,7 @@ public class SoftwareModuleResourceTest extends AbstractIntegrationTestWithMongo
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Verfies the successfull search of a metadata entry based on value.")
|
||||
public void searchSoftwareModuleMetadataRsql() throws Exception {
|
||||
final int totalMetadata = 10;
|
||||
final String knownKeyPrefix = "knownKey";
|
||||
|
||||
0
hawkbit-rest-resource/src/test/java/org/eclipse/hawkbit/rest/resource/SoftwareModuleTypeResourceTest.java
Executable file → Normal file
0
hawkbit-rest-resource/src/test/java/org/eclipse/hawkbit/rest/resource/SoftwareModuleTypeResourceTest.java
Executable file → Normal file
0
hawkbit-rest-resource/src/test/java/org/eclipse/hawkbit/rest/resource/SortUtilityTest.java
Executable file → Normal file
0
hawkbit-rest-resource/src/test/java/org/eclipse/hawkbit/rest/resource/SortUtilityTest.java
Executable file → Normal file
100
hawkbit-rest-resource/src/test/java/org/eclipse/hawkbit/rest/resource/SystemManagementResourceTest.java
Executable file → Normal file
100
hawkbit-rest-resource/src/test/java/org/eclipse/hawkbit/rest/resource/SystemManagementResourceTest.java
Executable file → Normal file
@@ -9,17 +9,28 @@
|
||||
package org.eclipse.hawkbit.rest.resource;
|
||||
|
||||
import static org.fest.assertions.api.Assertions.assertThat;
|
||||
import static org.hamcrest.CoreMatchers.equalTo;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
import org.eclipse.hawkbit.AbstractIntegrationTest;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import org.eclipse.hawkbit.AbstractIntegrationTestWithMongoDB;
|
||||
import org.eclipse.hawkbit.MockMvcResultPrinter;
|
||||
import org.eclipse.hawkbit.TestDataUtil;
|
||||
import org.eclipse.hawkbit.WithSpringAuthorityRule;
|
||||
import org.eclipse.hawkbit.WithUser;
|
||||
import org.eclipse.hawkbit.im.authentication.SpPermission;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSet;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModule;
|
||||
import org.eclipse.hawkbit.repository.model.Target;
|
||||
import org.junit.Test;
|
||||
import org.springframework.http.MediaType;
|
||||
|
||||
import ru.yandex.qatools.allure.annotations.Description;
|
||||
import ru.yandex.qatools.allure.annotations.Features;
|
||||
@@ -31,7 +42,37 @@ import ru.yandex.qatools.allure.annotations.Stories;
|
||||
*/
|
||||
@Features("Component Tests - System Management RESTful API")
|
||||
@Stories("System Management Resource")
|
||||
public class SystemManagementResourceTest extends AbstractIntegrationTest {
|
||||
public class SystemManagementResourceTest extends AbstractIntegrationTestWithMongoDB {
|
||||
|
||||
@Test
|
||||
@WithUser(tenantId = "mytenant", authorities = { SpPermission.SYSTEM_ADMIN })
|
||||
@Description("Tests that the system is able to collect statistics for the entire system.")
|
||||
public void collectSystemStatistics() throws Exception {
|
||||
createTestTenantsForSystemStatistics(2, 2000, 100, 2);
|
||||
|
||||
mvc.perform(get("/system/admin/usage").accept(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print())
|
||||
.andExpect(status().isOk()).andExpect(content().contentType(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath("$tenantStats.[?(@.tenantName==tenant0)][0].targets", equalTo(100)))
|
||||
.andExpect(jsonPath("$tenantStats.[?(@.tenantName==tenant0)][0].overallArtifactVolumeInBytes",
|
||||
equalTo(2000)))
|
||||
.andExpect(jsonPath("$tenantStats.[?(@.tenantName==tenant0)][0].artifacts", equalTo(1)))
|
||||
.andExpect(jsonPath("$tenantStats.[?(@.tenantName==tenant0)][0].actions", equalTo(200)))
|
||||
.andExpect(jsonPath("$overallTargets", equalTo(200)))
|
||||
.andExpect(jsonPath("$overallArtifacts", equalTo(2)))
|
||||
.andExpect(jsonPath("$overallArtifactVolumeInBytes", equalTo(4000)))
|
||||
.andExpect(jsonPath("$overallActions", equalTo(400)))
|
||||
.andExpect(jsonPath("$overallTenants", equalTo(4)));
|
||||
}
|
||||
|
||||
@Test
|
||||
@WithUser(tenantId = "mytenant", authorities = { SpPermission.DELETE_TARGET, SpPermission.DELETE_REPOSITORY,
|
||||
SpPermission.CREATE_REPOSITORY, SpPermission.READ_REPOSITORY })
|
||||
@Description("Tests that the system is not able to collect statistics for the entire system if the .")
|
||||
public void collectSystemStatisticsWithMissingPermissionFails() throws Exception {
|
||||
|
||||
mvc.perform(get("/system/admin/usage").accept(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print())
|
||||
.andExpect(status().isForbidden());
|
||||
}
|
||||
|
||||
@Test
|
||||
@WithUser(tenantId = "mytenant", allSpPermissions = true)
|
||||
@@ -76,4 +117,59 @@ public class SystemManagementResourceTest extends AbstractIntegrationTest {
|
||||
mvc.perform(delete("/system/admin/caches")).andDo(MockMvcResultPrinter.print()).andExpect(status().isOk());
|
||||
}
|
||||
|
||||
private byte[] createTestTenantsForSystemStatistics(final int tenants, final int artifactSize, final int targets,
|
||||
final int updates) throws Exception {
|
||||
final Random randomgen = new Random();
|
||||
final byte random[] = new byte[artifactSize];
|
||||
randomgen.nextBytes(random);
|
||||
|
||||
for (int i = 0; i < tenants; i++) {
|
||||
final String tenantname = "tenant" + i;
|
||||
securityRule.runAs(WithSpringAuthorityRule.withUserAndTenant("bumlux", tenantname), () -> {
|
||||
systemManagement.getTenantMetadata(tenantname);
|
||||
if (artifactSize > 0) {
|
||||
createTestArtifact(random);
|
||||
createDeletedTestArtifact(random);
|
||||
}
|
||||
if (targets > 0) {
|
||||
final List<Target> createdTargets = createTestTargets(targets);
|
||||
if (updates > 0) {
|
||||
for (int x = 0; x < updates; x++) {
|
||||
final DistributionSet ds = TestDataUtil.generateDistributionSet("to be deployed" + x,
|
||||
softwareManagement, distributionSetManagement, true);
|
||||
|
||||
deploymentManagement.assignDistributionSet(ds, createdTargets);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
return random;
|
||||
}
|
||||
|
||||
private List<Target> createTestTargets(final int targets) {
|
||||
return targetManagement
|
||||
.createTargets(TestDataUtil.buildTargetFixtures(targets, "testTargetOfTenant", "testTargetOfTenant"));
|
||||
}
|
||||
|
||||
private void createTestArtifact(final byte[] random) {
|
||||
SoftwareModule sm = new SoftwareModule(softwareManagement.findSoftwareModuleTypeByKey("os"), "name 1",
|
||||
"version 1", null, null);
|
||||
sm = softwareModuleRepository.save(sm);
|
||||
|
||||
artifactManagement.createLocalArtifact(new ByteArrayInputStream(random), sm.getId(), "file1", false);
|
||||
}
|
||||
|
||||
private void createDeletedTestArtifact(final byte[] random) {
|
||||
final DistributionSet ds = TestDataUtil.generateDistributionSet("deleted garbage", softwareManagement,
|
||||
distributionSetManagement, true);
|
||||
ds.getModules().stream().forEach(module -> {
|
||||
artifactManagement.createLocalArtifact(new ByteArrayInputStream(random), module.getId(), "file1", false);
|
||||
softwareManagement.deleteSoftwareModule(module);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
82
hawkbit-rest-resource/src/test/java/org/eclipse/hawkbit/rest/resource/TargetResourceTest.java
Executable file → Normal file
82
hawkbit-rest-resource/src/test/java/org/eclipse/hawkbit/rest/resource/TargetResourceTest.java
Executable file → Normal file
@@ -61,6 +61,7 @@ import org.springframework.test.web.servlet.MvcResult;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.jayway.jsonpath.JsonPath;
|
||||
|
||||
import ru.yandex.qatools.allure.annotations.Description;
|
||||
import ru.yandex.qatools.allure.annotations.Features;
|
||||
import ru.yandex.qatools.allure.annotations.Stories;
|
||||
|
||||
@@ -228,24 +229,14 @@ public class TargetResourceTest extends AbstractIntegrationTest {
|
||||
@Test
|
||||
public void cancelActionOK() throws Exception {
|
||||
// prepare test
|
||||
final DistributionSet dsA = TestDataUtil.generateDistributionSet("", softwareManagement,
|
||||
distributionSetManagement);
|
||||
;
|
||||
final Target tA = targetManagement
|
||||
.createTarget(TestDataUtil.buildTargetFixture("target-id-A", "first description"));
|
||||
// assign a distribution set so we get an active update action
|
||||
deploymentManagement.assignDistributionSet(dsA, Lists.newArrayList(tA));
|
||||
|
||||
// verify active action
|
||||
final Slice<Action> actionsByTarget = deploymentManagement.findActionsByTarget(new PageRequest(0, 100), tA);
|
||||
assertThat(actionsByTarget.getContent()).hasSize(1);
|
||||
Target tA = createTargetAndStartAction();
|
||||
|
||||
// test - cancel the active action
|
||||
mvc.perform(delete(RestConstants.TARGET_V1_REQUEST_MAPPING + "/{targetId}/actions/{actionId}",
|
||||
tA.getControllerId(), actionsByTarget.getContent().get(0).getId())).andDo(MockMvcResultPrinter.print())
|
||||
tA.getControllerId(), tA.getActions().get(0).getId())).andDo(MockMvcResultPrinter.print())
|
||||
.andExpect(status().isNoContent());
|
||||
|
||||
final Action action = deploymentManagement.findAction(actionsByTarget.getContent().get(0).getId());
|
||||
final Action action = deploymentManagement.findAction(tA.getActions().get(0).getId());
|
||||
// still active because in "canceling" state and waiting for controller
|
||||
// feedback
|
||||
assertThat(action.isActive()).isTrue();
|
||||
@@ -261,18 +252,10 @@ public class TargetResourceTest extends AbstractIntegrationTest {
|
||||
@Test
|
||||
public void cancelAnCancelActionIsNotAllowed() throws Exception {
|
||||
// prepare test
|
||||
final DistributionSet dsA = TestDataUtil.generateDistributionSet("", softwareManagement,
|
||||
distributionSetManagement);
|
||||
;
|
||||
Target tA = targetManagement.createTarget(TestDataUtil.buildTargetFixture("target-id-A", "first description"));
|
||||
// assign a distribution set so we get an active update action
|
||||
deploymentManagement.assignDistributionSet(dsA, Lists.newArrayList(tA));
|
||||
// verify active action
|
||||
final Slice<Action> actionsByTarget = deploymentManagement.findActionsByTarget(new PageRequest(0, 100), tA);
|
||||
assertThat(actionsByTarget.getContent()).hasSize(1);
|
||||
Target tA = createTargetAndStartAction();
|
||||
|
||||
// cancel the active action
|
||||
tA = targetManagement.findTargetByControllerID(tA.getControllerId());
|
||||
deploymentManagement.cancelAction(actionsByTarget.getContent().get(0), tA);
|
||||
deploymentManagement.cancelAction(tA.getActions().get(0), tA);
|
||||
|
||||
// find the current active action
|
||||
final List<Action> cancelActions = deploymentManagement.findActionsByTarget(new PageRequest(0, 100), tA)
|
||||
@@ -285,6 +268,39 @@ public class TargetResourceTest extends AbstractIntegrationTest {
|
||||
.andExpect(status().isMethodNotAllowed());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Force Quit an Action, which is already canceled. Expected Result is an HTTP response code 204.")
|
||||
public void forceQuitAnCanceledActionReturnsOk() throws Exception {
|
||||
|
||||
Target tA = createTargetAndStartAction();
|
||||
|
||||
// cancel the active action
|
||||
deploymentManagement.cancelAction(tA.getActions().get(0), tA);
|
||||
|
||||
// find the current active action
|
||||
final List<Action> cancelActions = deploymentManagement.findActionsByTarget(new PageRequest(0, 100), tA)
|
||||
.getContent().stream().filter(action -> action.isCancelingOrCanceled()).collect(Collectors.toList());
|
||||
assertThat(cancelActions).hasSize(1);
|
||||
assertThat(cancelActions.get(0).isCancelingOrCanceled()).isTrue();
|
||||
|
||||
// test - force quit an canceled action should return 204
|
||||
mvc.perform(delete(RestConstants.TARGET_V1_REQUEST_MAPPING + "/{targetId}/actions/{actionId}?force=true",
|
||||
tA.getControllerId(), cancelActions.get(0).getId())).andDo(MockMvcResultPrinter.print())
|
||||
.andExpect(status().isNoContent());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Force Quit an Action, which is not canceled. Expected Result is an HTTP response code 405.")
|
||||
public void forceQuitAnNotCanceledActionReturnsMethodNotAllowed() throws Exception {
|
||||
|
||||
Target tA = createTargetAndStartAction();
|
||||
|
||||
// test - cancel an cancel action returns forbidden
|
||||
mvc.perform(delete(RestConstants.TARGET_V1_REQUEST_MAPPING + "/{targetId}/actions/{actionId}?force=true",
|
||||
tA.getControllerId(), tA.getActions().get(0).getId())).andDo(MockMvcResultPrinter.print())
|
||||
.andExpect(status().isMethodNotAllowed());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void deleteTargetReturnsOK() throws Exception {
|
||||
final String knownControllerId = "knownControllerIdDelete";
|
||||
@@ -1206,4 +1222,22 @@ public class TargetResourceTest extends AbstractIntegrationTest {
|
||||
final ActionStatus actionStatus = new ActionStatus(action, Status.FINISHED, 0l);
|
||||
controllerManagement.addUpdateActionStatus(actionStatus, action);
|
||||
}
|
||||
|
||||
/**
|
||||
* helper method to create a target and start an action on it.
|
||||
*
|
||||
* @return The targetid of the created target.
|
||||
*/
|
||||
private Target createTargetAndStartAction() {
|
||||
// prepare test
|
||||
final DistributionSet dsA = TestDataUtil.generateDistributionSet("", softwareManagement,
|
||||
distributionSetManagement);
|
||||
Target tA = targetManagement.createTarget(TestDataUtil.buildTargetFixture("target-id-A", "first description"));
|
||||
// assign a distribution set so we get an active update action
|
||||
deploymentManagement.assignDistributionSet(dsA, Lists.newArrayList(tA));
|
||||
// verify active action
|
||||
final Slice<Action> actionsByTarget = deploymentManagement.findActionsByTarget(new PageRequest(0, 100), tA);
|
||||
assertThat(actionsByTarget.getContent()).hasSize(1);
|
||||
return targetManagement.findTargetByControllerID(tA.getControllerId());
|
||||
}
|
||||
}
|
||||
|
||||
0
hawkbit-rest-resource/src/test/java/org/eclipse/hawkbit/rest/resource/model/ExceptionInfoTest.java
Executable file → Normal file
0
hawkbit-rest-resource/src/test/java/org/eclipse/hawkbit/rest/resource/model/ExceptionInfoTest.java
Executable file → Normal file
0
hawkbit-rest-resource/src/test/java/org/eclipse/hawkbit/rest/resource/model/PagedListTest.java
Executable file → Normal file
0
hawkbit-rest-resource/src/test/java/org/eclipse/hawkbit/rest/resource/model/PagedListTest.java
Executable file → Normal file
0
hawkbit-rest-resource/src/test/resources/application-test.properties
Executable file → Normal file
0
hawkbit-rest-resource/src/test/resources/application-test.properties
Executable file → Normal file
26
hawkbit-rest-resource/src/test/resources/log4j2.xml
Normal file
26
hawkbit-rest-resource/src/test/resources/log4j2.xml
Normal file
@@ -0,0 +1,26 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
|
||||
Copyright (c) 2015 Bosch Software Innovations GmbH and others.
|
||||
|
||||
All rights reserved. This program and the accompanying materials
|
||||
are made available under the terms of the Eclipse Public License v1.0
|
||||
which accompanies this distribution, and is available at
|
||||
http://www.eclipse.org/legal/epl-v10.html
|
||||
|
||||
-->
|
||||
<Configuration status="WARN" monitorInterval="30">
|
||||
|
||||
<Appenders>
|
||||
<Console name="Console" target="SYSTEM_OUT" follow="true">
|
||||
<PatternLayout pattern="[%t] [%-5level] %logger{36} - %msg%n" charset="UTF-8"/>
|
||||
</Console>
|
||||
</Appenders>
|
||||
<Loggers>
|
||||
<Logger name="org.eclipse.hawkbit.MockMvcResultPrinter" level="debug" />
|
||||
|
||||
<Root level="error">
|
||||
<AppenderRef ref="Console"/>
|
||||
</Root>
|
||||
</Loggers>
|
||||
</Configuration>
|
||||
Reference in New Issue
Block a user