use of org.springframework.web.bind.annotation.RequestMapping in project spring-boot-admin by codecentric.
the class RegistryController method register.
/**
* Register an application within this admin application.
*
* @param application The application infos.
* @return The registered application.
*/
@RequestMapping(method = RequestMethod.POST)
public ResponseEntity<Application> register(@RequestBody Application application) {
Application applicationWithSource = Application.copyOf(application).withSource("http-api").build();
LOGGER.debug("Register application {}", applicationWithSource.toString());
Application registeredApp = registry.register(applicationWithSource);
return ResponseEntity.status(HttpStatus.CREATED).body(registeredApp);
}
use of org.springframework.web.bind.annotation.RequestMapping in project spring-boot-admin by codecentric.
the class RegistryController method unregister.
/**
* Unregister an application within this admin application.
*
* @param id The application id.
* @return the unregistered application.
*/
@RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
public ResponseEntity<?> unregister(@PathVariable String id) {
LOGGER.debug("Unregister application with ID '{}'", id);
Application application = registry.deregister(id);
if (application != null) {
return ResponseEntity.ok(application);
} else {
return ResponseEntity.notFound().build();
}
}
use of org.springframework.web.bind.annotation.RequestMapping in project hive by apache.
the class ExecutionController method testLog.
@RequestMapping(value = "/testLog", method = RequestMethod.POST)
@ResponseBody
public TestLogResponse testLog(@RequestBody TestLogRequest logsRequest, BindingResult result) {
String testHandle = logsRequest.getTestHandle();
Test testExecution = mTests.get(testHandle);
if (result.hasErrors() || Strings.nullToEmpty(logsRequest.getTestHandle()).trim().isEmpty() || testExecution == null || logsRequest.getLength() > MAX_READ_SIZE) {
return new TestLogResponse(Status.illegalArgument());
}
File outputFile = testExecution.getOutputFile();
if (outputFile == null || logsRequest.getOffset() > outputFile.length()) {
return new TestLogResponse(Status.illegalArgument());
}
RandomAccessFile fileHandle = null;
try {
fileHandle = new RandomAccessFile(outputFile, "r");
long offset = logsRequest.getOffset();
fileHandle.seek(offset);
int readLength = 0;
if (offset < fileHandle.length()) {
readLength = (int) Math.min(fileHandle.length() - offset, logsRequest.getLength());
}
byte[] buffer = new byte[readLength];
fileHandle.readFully(buffer);
offset += readLength;
return new TestLogResponse(Status.ok(), offset, new String(buffer, Charsets.UTF_8));
} catch (IOException e) {
LOG.info("Unexpected IO error reading " + testExecution.getOutputFile(), e);
return new TestLogResponse(Status.internalError(e.getMessage()));
} finally {
if (fileHandle != null) {
try {
fileHandle.close();
} catch (IOException e) {
LOG.warn("Error closing " + outputFile, e);
}
}
}
}
use of org.springframework.web.bind.annotation.RequestMapping in project hive by apache.
the class ExecutionController method testStatus.
@RequestMapping(value = "/testStatus", method = RequestMethod.POST)
@ResponseBody
public TestStatusResponse testStatus(@RequestBody TestStopRequest stopRequest, BindingResult result) {
String testHandle = stopRequest.getTestHandle();
Test test = mTests.get(testHandle);
if (result.hasErrors() || Strings.nullToEmpty(stopRequest.getTestHandle()).trim().isEmpty() || test == null) {
return new TestStatusResponse(Status.illegalArgument());
}
return new TestStatusResponse(Status.ok(), test.toTestStatus());
}
use of org.springframework.web.bind.annotation.RequestMapping in project hive by apache.
the class ExecutionController method testStop.
@RequestMapping(value = "/testStop", method = RequestMethod.POST)
@ResponseBody
public TestStopResponse testStop(@RequestBody TestStopRequest stopRequest, BindingResult result) {
String testHandle = stopRequest.getTestHandle();
Test test = mTests.get(testHandle);
if (result.hasErrors() || Strings.nullToEmpty(stopRequest.getTestHandle()).trim().isEmpty() || test == null) {
return new TestStopResponse(Status.illegalArgument());
}
test.setStopRequested(true);
return new TestStopResponse(Status.ok());
}
Aggregations