Search in sources :

Example 1 with RequestMapping

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);
            }
        }
    }
}
Also used : TestLogResponse(org.apache.hive.ptest.api.response.TestLogResponse) RandomAccessFile(java.io.RandomAccessFile) PTest(org.apache.hive.ptest.execution.PTest) IOException(java.io.IOException) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 2 with RequestMapping

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());
}
Also used : PTest(org.apache.hive.ptest.execution.PTest) TestStatusResponse(org.apache.hive.ptest.api.response.TestStatusResponse) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 3 with RequestMapping

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());
}
Also used : TestStopResponse(org.apache.hive.ptest.api.response.TestStopResponse) PTest(org.apache.hive.ptest.execution.PTest) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 4 with RequestMapping

use of org.springframework.web.bind.annotation.RequestMapping in project spring-boot-admin by codecentric.

the class NotificationFilterController method addFilter.

@RequestMapping(method = { RequestMethod.POST }, produces = MimeTypeUtils.APPLICATION_JSON_VALUE)
public ResponseEntity<?> addFilter(@RequestParam(name = "id", required = false) String id, @RequestParam(name = "name", required = false) String name, @RequestParam(name = "ttl", required = false, defaultValue = "-1") long ttl) {
    if (hasText(id) || hasText(name)) {
        NotificationFilter filter = createFilter(id, name, ttl);
        String filterId = filteringNotifier.addFilter(filter);
        return ResponseEntity.ok(Collections.singletonMap(filterId, filter));
    } else {
        return ResponseEntity.badRequest().body("Either 'id' or 'name' must be set");
    }
}
Also used : NotificationFilter(de.codecentric.boot.admin.notify.filter.NotificationFilter) ApplicationIdNotificationFilter(de.codecentric.boot.admin.notify.filter.ApplicationIdNotificationFilter) ApplicationNameNotificationFilter(de.codecentric.boot.admin.notify.filter.ApplicationNameNotificationFilter) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 5 with RequestMapping

use of org.springframework.web.bind.annotation.RequestMapping in project spring-boot-admin by codecentric.

the class RegistryController method get.

/**
	 * Get a single application out of the registry.
	 *
	 * @param id The application identifier.
	 * @return The registered application.
	 */
@RequestMapping(value = "/{id}", method = RequestMethod.GET)
public ResponseEntity<?> get(@PathVariable String id) {
    LOGGER.debug("Deliver registered application with ID '{}'", id);
    Application application = registry.getApplication(id);
    if (application != null) {
        return ResponseEntity.ok(application);
    } else {
        return ResponseEntity.notFound().build();
    }
}
Also used : Application(de.codecentric.boot.admin.model.Application) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1622 ModelAndView (org.springframework.web.servlet.ModelAndView)401 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)375 ArrayList (java.util.ArrayList)177 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)175 HashMap (java.util.HashMap)147 WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)124 IOException (java.io.IOException)83 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)75 Date (java.util.Date)73 ApiOperation (io.swagger.annotations.ApiOperation)68 User (org.hisp.dhis.user.User)59 HttpServletResponse (javax.servlet.http.HttpServletResponse)56 ResponseEntity (org.springframework.http.ResponseEntity)56 InputStream (java.io.InputStream)53 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)51 Locale (java.util.Locale)50 CommandStringBuilder (org.apache.geode.management.internal.cli.util.CommandStringBuilder)47 DBObject (com.mongodb.DBObject)46 Aggregation (org.springframework.data.mongodb.core.aggregation.Aggregation)45