Search in sources :

Example 11 with GridRestResponse

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);
    }
}
Also used : RestUserActionRequest(org.apache.ignite.internal.processors.rest.request.RestUserActionRequest) GridRestCommand(org.apache.ignite.internal.processors.rest.GridRestCommand) IgniteSecurity(org.apache.ignite.internal.processors.security.IgniteSecurity) GridRestResponse(org.apache.ignite.internal.processors.rest.GridRestResponse) GridFinishedFuture(org.apache.ignite.internal.util.future.GridFinishedFuture)

Example 12 with GridRestResponse

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());
}
Also used : RestQueryRequest(org.apache.ignite.internal.processors.rest.request.RestQueryRequest) GridRestResponse(org.apache.ignite.internal.processors.rest.GridRestResponse)

Example 13 with GridRestResponse

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);
    }
}
Also used : IgniteClusterEx(org.apache.ignite.internal.cluster.IgniteClusterEx) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) HashSet(java.util.HashSet) Set(java.util.Set) GridRestResponse(org.apache.ignite.internal.processors.rest.GridRestResponse) GridRestBaselineRequest(org.apache.ignite.internal.processors.rest.request.GridRestBaselineRequest) Collection(java.util.Collection) GridFinishedFuture(org.apache.ignite.internal.util.future.GridFinishedFuture)

Example 14 with GridRestResponse

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

Example 15 with GridRestResponse

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());
}
Also used : GridRestCommandHandler(org.apache.ignite.internal.processors.rest.handlers.GridRestCommandHandler) GridProbeCommandHandler(org.apache.ignite.internal.processors.rest.handlers.probe.GridProbeCommandHandler) GridRestCacheRequest(org.apache.ignite.internal.processors.rest.request.GridRestCacheRequest) GridRestResponse(org.apache.ignite.internal.processors.rest.GridRestResponse) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Aggregations

GridRestResponse (org.apache.ignite.internal.processors.rest.GridRestResponse)24 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)11 Test (org.junit.Test)11 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)8 GridRestLogRequest (org.apache.ignite.internal.processors.rest.request.GridRestLogRequest)8 GridTestKernalContext (org.apache.ignite.testframework.junits.GridTestKernalContext)7 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)6 GridRestCacheRequest (org.apache.ignite.internal.processors.rest.request.GridRestCacheRequest)4 GridFutureAdapter (org.apache.ignite.internal.util.future.GridFutureAdapter)4 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)3 GridRestCommand (org.apache.ignite.internal.processors.rest.GridRestCommand)3 RestQueryRequest (org.apache.ignite.internal.processors.rest.request.RestQueryRequest)3 GridFinishedFuture (org.apache.ignite.internal.util.future.GridFinishedFuture)3 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 HashSet (java.util.HashSet)2 Map (java.util.Map)2 Set (java.util.Set)2 UUID (java.util.UUID)2 IgniteException (org.apache.ignite.IgniteException)2