use of org.apache.ignite.internal.processors.rest.GridRestResponse in project ignite by apache.
the class UserActionCommandHandler method handleAsync.
/**
* {@inheritDoc}
*/
@Override
public IgniteInternalFuture<GridRestResponse> handleAsync(GridRestRequest req) {
assert req != null;
if (log.isDebugEnabled())
log.debug("Handling topology REST request: " + req);
RestUserActionRequest req0 = (RestUserActionRequest) req;
try {
GridRestCommand cmd = req.command();
IgniteSecurity security = ctx.security();
switch(cmd) {
case ADD_USER:
security.createUser(req0.user(), req0.password().toCharArray());
break;
case REMOVE_USER:
security.dropUser(req0.user());
break;
case UPDATE_USER:
security.alterUser(req0.user(), req0.password().toCharArray());
break;
}
if (log.isDebugEnabled())
log.debug("Handled topology REST request [req=" + req + ']');
return new GridFinishedFuture<>(new GridRestResponse(true));
} catch (Throwable e) {
log.error("Failed to handle REST request [req=" + req + ']', e);
return new GridFinishedFuture<>(e);
}
}
use of org.apache.ignite.internal.processors.rest.GridRestResponse in project ignite by apache.
the class GridQueryCommandHandlerTest method testNullCache.
/**
* @throws Exception If failed.
*/
public void testNullCache() throws Exception {
QueryCommandHandler cmdHnd = new QueryCommandHandler(grid().context());
Integer arg1 = 1000;
Object[] arr = new Object[] { arg1, arg1 };
RestQueryRequest req = new RestQueryRequest();
req.command(GridRestCommand.EXECUTE_SQL_QUERY);
req.queryType(RestQueryRequest.QueryType.SCAN);
req.typeName(Integer.class.getName());
req.pageSize(10);
req.sqlQuery("salary+>+%3F+and+salary+<%3D+%3F");
req.arguments(arr);
req.cacheName(null);
IgniteInternalFuture<GridRestResponse> resp = cmdHnd.handleAsync(req);
resp.get();
// If cache name is not set server uses name 'default'.
assertEquals("Failed to find cache with name: default", resp.result().getError());
assertEquals(GridRestResponse.STATUS_FAILED, resp.result().getSuccessStatus());
assertNull(resp.result().getResponse());
}
use of org.apache.ignite.internal.processors.rest.GridRestResponse in project ignite by apache.
the class GridBaselineCommandHandler method handleAsync.
/**
* {@inheritDoc}
*/
@Override
public IgniteInternalFuture<GridRestResponse> handleAsync(GridRestRequest req) {
assert req != null;
assert SUPPORTED_COMMANDS.contains(req.command());
assert req instanceof GridRestBaselineRequest : "Invalid type of baseline request.";
if (log.isDebugEnabled())
log.debug("Handling baseline REST request: " + req);
GridRestBaselineRequest req0 = (GridRestBaselineRequest) req;
try {
IgniteClusterEx cluster = ctx.grid().cluster();
List<Object> consistentIds = req0.consistentIds();
switch(req0.command()) {
case BASELINE_CURRENT_STATE:
{
break;
}
case BASELINE_SET:
{
Long topVer = req0.topologyVersion();
if (topVer == null && consistentIds == null)
throw new IgniteCheckedException("Failed to handle request (either topVer or consistentIds should be specified).");
if (topVer != null)
cluster.setBaselineTopology(topVer);
else
cluster.setBaselineTopology(filterServerNodesByConsId(consistentIds));
break;
}
case BASELINE_ADD:
{
if (consistentIds == null)
throw new IgniteCheckedException(missingParameter("consistentIds"));
Set<BaselineNode> baselineTop = new HashSet<>(currentBaseLine());
baselineTop.addAll(filterServerNodesByConsId(consistentIds));
cluster.setBaselineTopology(baselineTop);
break;
}
case BASELINE_REMOVE:
{
if (consistentIds == null)
throw new IgniteCheckedException(missingParameter("consistentIds"));
Collection<BaselineNode> baseline = currentBaseLine();
Set<BaselineNode> baselineTop = new HashSet<>(baseline);
baselineTop.removeAll(filterNodesByConsId(baseline, consistentIds));
cluster.setBaselineTopology(baselineTop);
break;
}
default:
assert false : "Invalid command for baseline handler: " + req;
}
return new GridFinishedFuture<>(new GridRestResponse(currentState()));
} catch (IgniteCheckedException e) {
return new GridFinishedFuture<>(e);
} finally {
if (log.isDebugEnabled())
log.debug("Handled baseline REST request: " + req);
}
}
use of org.apache.ignite.internal.processors.rest.GridRestResponse 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<>();
}
use of org.apache.ignite.internal.processors.rest.GridRestResponse in project ignite by apache.
the class GridProbeCommandTest method testRestProbeCommand.
/**
* Test for the REST probe command
*
* @throws Exception If failed.
*/
@Test
public void testRestProbeCommand() throws Exception {
startGrid("regular");
GridRestCommandHandler hnd = new GridProbeCommandHandler((grid("regular")).context());
GridRestCacheRequest req = new GridRestCacheRequest();
req.command(GridRestCommand.PROBE);
IgniteInternalFuture<GridRestResponse> resp = hnd.handleAsync(req);
resp.get();
assertEquals(GridRestResponse.STATUS_SUCCESS, resp.result().getSuccessStatus());
assertEquals("grid has started", resp.result().getResponse());
}
Aggregations