Search in sources :

Example 6 with GridRestLogRequest

use of org.apache.ignite.internal.processors.rest.request.GridRestLogRequest in project ignite by apache.

the class GridLogCommandHandlerTest method testHandleAsyncFromAndToNotSet.

/**
 * @throws Exception If failed.
 */
@Test
public void testHandleAsyncFromAndToNotSet() throws Exception {
    IgniteConfiguration cfg = new IgniteConfiguration();
    cfg.setIgniteHome(igniteHome);
    GridTestKernalContext ctx = newContext(cfg);
    GridLogCommandHandler cmdHandler = new GridLogCommandHandler(ctx);
    GridRestLogRequest req = new GridRestLogRequest();
    req.path(igniteHome + "/work/log/" + "test.log");
    IgniteInternalFuture<GridRestResponse> resp = cmdHandler.handleAsync(req);
    assertNull(resp.result().getError());
    assertEquals(GridRestResponse.STATUS_SUCCESS, resp.result().getSuccessStatus());
    assertNotNull(resp.result().getResponse());
}
Also used : IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) GridTestKernalContext(org.apache.ignite.testframework.junits.GridTestKernalContext) GridRestResponse(org.apache.ignite.internal.processors.rest.GridRestResponse) GridRestLogRequest(org.apache.ignite.internal.processors.rest.request.GridRestLogRequest) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 7 with GridRestLogRequest

use of org.apache.ignite.internal.processors.rest.request.GridRestLogRequest in project ignite by apache.

the class GridLogCommandHandlerTest method testHandleAsyncPathIsOutsideIgniteHome.

/**
 * @throws Exception If failed.
 */
@Test
public void testHandleAsyncPathIsOutsideIgniteHome() throws Exception {
    IgniteConfiguration cfg = new IgniteConfiguration();
    cfg.setIgniteHome(igniteHome);
    GridTestKernalContext ctx = newContext(cfg);
    GridLogCommandHandler cmdHandler = new GridLogCommandHandler(ctx);
    GridRestLogRequest req = new GridRestLogRequest();
    req.to(5);
    req.from(2);
    req.path("/home/users/mytest.log");
    IgniteInternalFuture<GridRestResponse> resp = cmdHandler.handleAsync(req);
    assertEquals("Request parameter 'path' must contain a path to valid log file.", resp.result().getError());
    assertEquals(GridRestResponse.STATUS_FAILED, resp.result().getSuccessStatus());
    assertNull(resp.result().getResponse());
}
Also used : IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) GridTestKernalContext(org.apache.ignite.testframework.junits.GridTestKernalContext) GridRestResponse(org.apache.ignite.internal.processors.rest.GridRestResponse) GridRestLogRequest(org.apache.ignite.internal.processors.rest.request.GridRestLogRequest) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 8 with GridRestLogRequest

use of org.apache.ignite.internal.processors.rest.request.GridRestLogRequest in project ignite by apache.

the class GridLogCommandHandlerTest method testHandleAsync.

/**
 * @throws Exception If failed.
 */
@Test
public void testHandleAsync() throws Exception {
    IgniteConfiguration cfg = new IgniteConfiguration();
    cfg.setIgniteHome(igniteHome);
    GridTestKernalContext ctx = newContext(cfg);
    GridLogCommandHandler cmdHandler = new GridLogCommandHandler(ctx);
    GridRestLogRequest req = new GridRestLogRequest();
    req.to(5);
    req.from(2);
    req.path(igniteHome + "/work/log/" + "test.log");
    IgniteInternalFuture<GridRestResponse> resp = cmdHandler.handleAsync(req);
    assertNull(resp.result().getError());
    assertEquals(GridRestResponse.STATUS_SUCCESS, resp.result().getSuccessStatus());
    assertNotNull(resp.result().getResponse());
}
Also used : IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) GridTestKernalContext(org.apache.ignite.testframework.junits.GridTestKernalContext) GridRestResponse(org.apache.ignite.internal.processors.rest.GridRestResponse) GridRestLogRequest(org.apache.ignite.internal.processors.rest.request.GridRestLogRequest) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 9 with GridRestLogRequest

use of org.apache.ignite.internal.processors.rest.request.GridRestLogRequest in project ignite by apache.

the class GridLogCommandHandlerTest method testHandleAsyncFromEqualTo.

/**
 * @throws Exception If failed.
 */
@Test
public void testHandleAsyncFromEqualTo() throws Exception {
    IgniteConfiguration cfg = new IgniteConfiguration();
    cfg.setIgniteHome(igniteHome);
    GridTestKernalContext ctx = newContext(cfg);
    GridLogCommandHandler cmdHandler = new GridLogCommandHandler(ctx);
    GridRestLogRequest req = new GridRestLogRequest();
    req.to(5);
    req.from(5);
    req.path(igniteHome + "/work/log/" + "test.log");
    IgniteInternalFuture<GridRestResponse> resp = cmdHandler.handleAsync(req);
    assertEquals("Request parameter 'from' must be less than 'to'.", resp.result().getError());
    assertEquals(GridRestResponse.STATUS_FAILED, resp.result().getSuccessStatus());
    assertNull(resp.result().getResponse());
}
Also used : IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) GridTestKernalContext(org.apache.ignite.testframework.junits.GridTestKernalContext) GridRestResponse(org.apache.ignite.internal.processors.rest.GridRestResponse) GridRestLogRequest(org.apache.ignite.internal.processors.rest.request.GridRestLogRequest) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 10 with GridRestLogRequest

use of org.apache.ignite.internal.processors.rest.request.GridRestLogRequest in project ignite by apache.

the class GridLogCommandHandler method handleAsync.

/**
 * {@inheritDoc}
 */
@Override
public IgniteInternalFuture<GridRestResponse> handleAsync(GridRestRequest req) {
    assert req != null;
    if (req.command() == LOG) {
        if (log.isDebugEnabled())
            log.debug("Handling log REST request: " + req);
        GridRestLogRequest req0 = (GridRestLogRequest) req;
        if (req0.from() < -1 || req0.to() < -1)
            return new GridFinishedFuture<>(new GridRestResponse(GridRestResponse.STATUS_FAILED, "One of the request parameters is invalid [from=" + req0.from() + ", to=" + req0.to() + ']'));
        int from;
        if (req0.from() != -1) {
            if (req0.to() == -1)
                return new GridFinishedFuture<>(new GridRestResponse(GridRestResponse.STATUS_FAILED, "Request parameter 'to' is not set."));
            from = req0.from();
        } else
            from = DEFAULT_FROM;
        int to;
        if (req0.to() != -1) {
            if (req0.from() == -1)
                return new GridFinishedFuture<>(new GridRestResponse(GridRestResponse.STATUS_FAILED, "Request parameter 'from' is not set."));
            to = req0.to();
        } else
            to = DEFAULT_TO;
        if (from >= to)
            return new GridFinishedFuture<>(new GridRestResponse(GridRestResponse.STATUS_FAILED, "Request parameter 'from' must be less than 'to'."));
        File logFile;
        try {
            if (req0.path() != null) {
                if (log.fileName() != null) {
                    if (!req0.path().equals(log.fileName())) {
                        return new GridFinishedFuture<>(new GridRestResponse(GridRestResponse.STATUS_FAILED, "Request parameter 'path' must contain a path to valid log file."));
                    } else
                        logFile = new File(req0.path());
                } else if (req0.path().startsWith(ctx.config().getIgniteHome()))
                    logFile = new File(req0.path());
                else {
                    return new GridFinishedFuture<>(new GridRestResponse(GridRestResponse.STATUS_FAILED, "Request parameter 'path' must contain a path to valid log file."));
                }
            } else if (log.fileName() == null)
                logFile = new File(ctx.config().getIgniteHome() + "/work/log/ignite.log");
            else
                logFile = new File(log.fileName());
        } catch (InvalidPathException e) {
            return new GridFinishedFuture<>(new GridRestResponse(GridRestResponse.STATUS_FAILED, "Incorrect path to a log file [msg=" + e.getMessage() + ']'));
        }
        try {
            String content = readLog(from, to, logFile);
            return new GridFinishedFuture<>(new GridRestResponse(content));
        } catch (IgniteCheckedException e) {
            return new GridFinishedFuture<>(new GridRestResponse(GridRestResponse.STATUS_FAILED, e.getMessage()));
        }
    }
    return new GridFinishedFuture<>();
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) GridRestResponse(org.apache.ignite.internal.processors.rest.GridRestResponse) GridRestLogRequest(org.apache.ignite.internal.processors.rest.request.GridRestLogRequest) File(java.io.File) InvalidPathException(java.nio.file.InvalidPathException) GridFinishedFuture(org.apache.ignite.internal.util.future.GridFinishedFuture)

Aggregations

GridRestLogRequest (org.apache.ignite.internal.processors.rest.request.GridRestLogRequest)10 GridRestResponse (org.apache.ignite.internal.processors.rest.GridRestResponse)8 GridTestKernalContext (org.apache.ignite.testframework.junits.GridTestKernalContext)7 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)7 Test (org.junit.Test)7 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)6 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)3 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 IOException (java.io.IOException)2 InetSocketAddress (java.net.InetSocketAddress)2 Iterator (java.util.Iterator)2 LinkedList (java.util.LinkedList)2 List (java.util.List)2 Map (java.util.Map)2 CacheConfigurationOverride (org.apache.ignite.internal.processors.cache.CacheConfigurationOverride)2 DataStructuresRequest (org.apache.ignite.internal.processors.rest.request.DataStructuresRequest)2 GridRestCacheRequest (org.apache.ignite.internal.processors.rest.request.GridRestCacheRequest)2 GridRestChangeStateRequest (org.apache.ignite.internal.processors.rest.request.GridRestChangeStateRequest)2 GridRestRequest (org.apache.ignite.internal.processors.rest.request.GridRestRequest)2 GridRestTaskRequest (org.apache.ignite.internal.processors.rest.request.GridRestTaskRequest)2