use of com.infiniteautomation.mango.rest.latest.util.SystemActionTemporaryResource in project ma-modules-public by infiniteautomation.
the class SystemActionRestController method performAction.
@ApiOperation(value = "Perform an Action", notes = "Kicks off action and returns temporary URL for status")
@ApiResponses({ @ApiResponse(code = 500, message = "Internal error", response = ResponseEntity.class), @ApiResponse(code = 404, message = "Not Found", response = ResponseEntity.class) })
@RequestMapping(method = RequestMethod.PUT, value = "/trigger/{action}")
public ResponseEntity<SystemActionTemporaryResource> performAction(@ApiParam(value = "Valid System Action", required = true, allowMultiple = false) @PathVariable String action, @ApiParam(value = "Input for task", required = false, allowMultiple = false) @RequestBody(required = false) JsonNode input, @RequestParam(required = false, defaultValue = "12000000") Long timeout, @AuthenticationPrincipal PermissionHolder user, UriComponentsBuilder builder) {
// Kick off action
SystemActionDefinition def = ModuleRegistry.getSystemActionDefinition(action);
if (def == null)
throw new NotFoundRestException();
String resourceId = resources.generateResourceId();
SystemActionTemporaryResource resource = new SystemActionTemporaryResource(resourceId, def.getTask(user, input), resources, new Date(System.currentTimeMillis() + timeout));
// Resource can live for up to 10 minutes (TODO Configurable?)
resources.put(resourceId, resource);
URI location = builder.path("/actions/status/{resourceId}").buildAndExpand(resourceId).toUri();
HttpHeaders headers = new HttpHeaders();
headers.setLocation(location);
return new ResponseEntity<>(resource, headers, HttpStatus.OK);
}
use of com.infiniteautomation.mango.rest.latest.util.SystemActionTemporaryResource in project ma-modules-public by infiniteautomation.
the class SystemActionRestController method cancel.
@ApiOperation(value = "Cancel Action", notes = "No Guarantees that the cancel will work, this is task dependent.")
@ApiResponses({ @ApiResponse(code = 401, message = "Unauthorized user access", response = ResponseEntity.class), @ApiResponse(code = 404, message = "No resource exists with given id", response = ResponseEntity.class), @ApiResponse(code = 500, message = "Error processing request", response = ResponseEntity.class) })
@RequestMapping(method = { RequestMethod.PUT }, value = { "/cancel/{resourceId}" })
public ResponseEntity<SystemActionTemporaryResource> cancel(HttpServletRequest request, @ApiParam(value = "Resource id", required = true, allowMultiple = false) @PathVariable String resourceId, @AuthenticationPrincipal PermissionHolder user) {
SystemActionTemporaryResource resource = resources.get(resourceId);
resource.cancel();
return new ResponseEntity<>(resource, HttpStatus.OK);
}
Aggregations