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());
}
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());
}
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());
}
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());
}
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<>();
}
Aggregations