Search in sources :

Example 1 with GridClientTopologyRequest

use of org.apache.ignite.internal.processors.rest.client.message.GridClientTopologyRequest in project ignite by apache.

the class GridClientNioTcpConnection method node.

/**
 * {@inheritDoc}
 */
@SuppressWarnings("unchecked")
@Override
public GridClientFuture<GridClientNode> node(String ipAddr, boolean inclAttrs, boolean includeMetrics, UUID destNodeId) throws GridClientConnectionResetException, GridClientClosedException {
    GridClientTopologyRequest msg = new GridClientTopologyRequest();
    TcpClientFuture fut = new TcpClientFuture() {

        @Override
        public void onDone(Object res) {
            GridClientNodeImpl node = nodeBeanToNode((GridClientNodeBean) res);
            if (node != null)
                super.onDone(top.updateNode(node));
            else
                super.onDone(node);
        }
    };
    msg.nodeIp(ipAddr);
    setupMessage(inclAttrs, includeMetrics, destNodeId, msg);
    return makeRequest(msg, fut);
}
Also used : GridClientNodeImpl(org.apache.ignite.internal.client.impl.GridClientNodeImpl) GridClientTopologyRequest(org.apache.ignite.internal.processors.rest.client.message.GridClientTopologyRequest)

Example 2 with GridClientTopologyRequest

use of org.apache.ignite.internal.processors.rest.client.message.GridClientTopologyRequest in project ignite by apache.

the class GridClientNioTcpConnection method topology.

/**
 * {@inheritDoc}
 */
@SuppressWarnings("unchecked")
@Override
public GridClientFuture<List<GridClientNode>> topology(boolean inclAttrs, boolean inclMetrics, UUID destNodeId) throws GridClientConnectionResetException, GridClientClosedException {
    GridClientTopologyRequest msg = new GridClientTopologyRequest();
    TcpClientFuture fut = new TcpClientFuture() {

        @Override
        public void onDone(Object res) {
            Collection<GridClientNodeBean> beans = (Collection<GridClientNodeBean>) res;
            Collection<GridClientNodeImpl> nodes = new ArrayList<>(beans.size());
            for (GridClientNodeBean bean : beans) nodes.add(nodeBeanToNode(bean));
            super.onDone(top.updateTopology(nodes));
        }
    };
    setupMessage(inclAttrs, inclMetrics, destNodeId, msg);
    return makeRequest(msg, fut);
}
Also used : GridClientNodeBean(org.apache.ignite.internal.processors.rest.client.message.GridClientNodeBean) GridClientNodeImpl(org.apache.ignite.internal.client.impl.GridClientNodeImpl) ArrayList(java.util.ArrayList) Collection(java.util.Collection) GridClientTopologyRequest(org.apache.ignite.internal.processors.rest.client.message.GridClientTopologyRequest)

Example 3 with GridClientTopologyRequest

use of org.apache.ignite.internal.processors.rest.client.message.GridClientTopologyRequest in project ignite by apache.

the class GridClientNioTcpConnection method node.

/**
 * {@inheritDoc}
 */
@SuppressWarnings("unchecked")
@Override
public GridClientFuture<GridClientNode> node(final UUID id, boolean inclAttrs, boolean inclMetrics, UUID destNodeId) throws GridClientConnectionResetException, GridClientClosedException {
    assert id != null;
    TcpClientFuture fut = refreshNodeReqs.get(id);
    // Return request that is in progress.
    if (fut != null)
        return fut;
    GridClientTopologyRequest msg = new GridClientTopologyRequest();
    fut = new TcpClientFuture() {

        @Override
        public void onDone(Object res) {
            // Clean up the node id requests map.
            refreshNodeReqs.remove(id);
            GridClientNodeImpl node = nodeBeanToNode((GridClientNodeBean) res);
            if (node != null)
                top.updateNode(node);
            super.onDone(node);
        }
    };
    GridClientFutureAdapter old = refreshNodeReqs.putIfAbsent(id, fut);
    // If concurrent thread put request, do not send the message.
    if (old != null)
        return old;
    msg.nodeId(id);
    setupMessage(inclAttrs, inclMetrics, destNodeId, msg);
    return makeRequest(msg, fut);
}
Also used : GridClientNodeBean(org.apache.ignite.internal.processors.rest.client.message.GridClientNodeBean) GridClientNodeImpl(org.apache.ignite.internal.client.impl.GridClientNodeImpl) GridClientTopologyRequest(org.apache.ignite.internal.processors.rest.client.message.GridClientTopologyRequest) GridClientFutureAdapter(org.apache.ignite.internal.client.impl.GridClientFutureAdapter)

Example 4 with GridClientTopologyRequest

use of org.apache.ignite.internal.processors.rest.client.message.GridClientTopologyRequest in project ignite by apache.

the class GridTcpRestNioListener method createRestRequest.

/**
 * Creates a REST request object from client TCP binary packet.
 *
 * @param ses NIO session.
 * @param msg Request message.
 * @return REST request object.
 */
@Nullable
private GridRestRequest createRestRequest(GridNioSession ses, GridClientMessage msg) {
    GridRestRequest restReq = null;
    if (msg instanceof GridClientAuthenticationRequest) {
        GridClientAuthenticationRequest req = (GridClientAuthenticationRequest) msg;
        restReq = new GridRestAuthenticationRequest();
        restReq.command(NOOP);
        ses.addMeta(CREDS_KEY, req.credentials());
        ses.addMeta(USER_ATTR_KEY, req.userAttributes());
    } else if (msg instanceof GridClientCacheRequest) {
        GridClientCacheRequest req = (GridClientCacheRequest) msg;
        GridRestCacheRequest restCacheReq = new GridRestCacheRequest();
        restCacheReq.cacheName(req.cacheName());
        restCacheReq.cacheFlags(req.cacheFlagsOn());
        restCacheReq.key(req.key());
        restCacheReq.value(req.value());
        restCacheReq.value2(req.value2());
        Map vals = req.values();
        if (vals != null)
            restCacheReq.values(new HashMap<Object, Object>(vals));
        restCacheReq.command(cacheCmdMap.get(req.operation()));
        restReq = restCacheReq;
    } else if (msg instanceof GridClientTaskRequest) {
        GridClientTaskRequest req = (GridClientTaskRequest) msg;
        GridRestTaskRequest restTaskReq = new GridRestTaskRequest();
        restTaskReq.command(EXE);
        restTaskReq.taskName(req.taskName());
        restTaskReq.params(Arrays.asList(req.argument()));
        restReq = restTaskReq;
    } else if (msg instanceof GridClientTopologyRequest) {
        GridClientTopologyRequest req = (GridClientTopologyRequest) msg;
        GridRestTopologyRequest restTopReq = new GridRestTopologyRequest();
        restTopReq.includeMetrics(req.includeMetrics());
        restTopReq.includeAttributes(req.includeAttributes());
        if (req.nodeId() != null) {
            restTopReq.command(NODE);
            restTopReq.nodeId(req.nodeId());
        } else if (req.nodeIp() != null) {
            restTopReq.command(NODE);
            restTopReq.nodeIp(req.nodeIp());
        } else
            restTopReq.command(TOPOLOGY);
        restReq = restTopReq;
    } else if (msg instanceof GridClientStateRequest) {
        GridClientStateRequest req = (GridClientStateRequest) msg;
        GridRestChangeStateRequest restChangeReq = new GridRestChangeStateRequest();
        if (req.isReqCurrentState()) {
            restChangeReq.reqCurrentState();
            restChangeReq.command(CLUSTER_CURRENT_STATE);
        } else {
            restChangeReq.active(req.active());
            restChangeReq.command(req.active() ? CLUSTER_ACTIVATE : CLUSTER_DEACTIVATE);
        }
        restReq = restChangeReq;
    } else if (msg instanceof GridClientClusterStateRequest) {
        GridClientClusterStateRequest req = (GridClientClusterStateRequest) msg;
        boolean forceDeactivation = !(msg instanceof GridClientClusterStateRequestV2) || ((GridClientClusterStateRequestV2) msg).forceDeactivation();
        GridRestClusterStateRequest restChangeReq = new GridRestClusterStateRequest();
        if (req.isReqCurrentState()) {
            restChangeReq.reqCurrentMode();
            restChangeReq.command(CLUSTER_STATE);
        } else {
            restChangeReq.state(req.state());
            restChangeReq.command(CLUSTER_SET_STATE);
            restChangeReq.forceDeactivation(forceDeactivation);
        }
        restReq = restChangeReq;
    } else if (msg instanceof GridClientClusterNameRequest)
        restReq = new GridRestClusterNameRequest();
    else if (msg instanceof GridClientNodeStateBeforeStartRequest) {
        GridClientNodeStateBeforeStartRequest reqClient = (GridClientNodeStateBeforeStartRequest) msg;
        if (reqClient instanceof GridClientWarmUpRequest) {
            GridClientWarmUpRequest warmUpReqClient = (GridClientWarmUpRequest) reqClient;
            restReq = new GridRestWarmUpRequest().stopWarmUp(warmUpReqClient.stopWarmUp());
            restReq.command(WARM_UP);
        } else {
            restReq = new GridRestNodeStateBeforeStartRequest();
            restReq.command(NODE_STATE_BEFORE_START);
        }
    }
    if (restReq != null) {
        restReq.destinationId(msg.destinationId());
        restReq.clientId(msg.clientId());
        restReq.sessionToken(msg.sessionToken());
        restReq.address(ses.remoteAddress());
        restReq.certificates(ses.certificates());
        restReq.credentials(ses.meta(CREDS_KEY));
        restReq.userAttributes(ses.meta(USER_ATTR_KEY));
    }
    return restReq;
}
Also used : GridRestClusterStateRequest(org.apache.ignite.internal.processors.rest.request.GridRestClusterStateRequest) GridClientAuthenticationRequest(org.apache.ignite.internal.processors.rest.client.message.GridClientAuthenticationRequest) GridRestClusterNameRequest(org.apache.ignite.internal.processors.rest.request.GridRestClusterNameRequest) GridClientWarmUpRequest(org.apache.ignite.internal.processors.rest.client.message.GridClientWarmUpRequest) GridRestTopologyRequest(org.apache.ignite.internal.processors.rest.request.GridRestTopologyRequest) GridClientClusterNameRequest(org.apache.ignite.internal.processors.rest.client.message.GridClientClusterNameRequest) GridClientNodeStateBeforeStartRequest(org.apache.ignite.internal.processors.rest.client.message.GridClientNodeStateBeforeStartRequest) GridRestNodeStateBeforeStartRequest(org.apache.ignite.internal.processors.rest.request.GridRestNodeStateBeforeStartRequest) GridRestWarmUpRequest(org.apache.ignite.internal.processors.rest.request.GridRestWarmUpRequest) GridClientClusterStateRequestV2(org.apache.ignite.internal.processors.rest.client.message.GridClientClusterStateRequestV2) GridClientClusterStateRequest(org.apache.ignite.internal.processors.rest.client.message.GridClientClusterStateRequest) GridRestCacheRequest(org.apache.ignite.internal.processors.rest.request.GridRestCacheRequest) GridRestChangeStateRequest(org.apache.ignite.internal.processors.rest.request.GridRestChangeStateRequest) GridRestTaskRequest(org.apache.ignite.internal.processors.rest.request.GridRestTaskRequest) GridClientStateRequest(org.apache.ignite.internal.processors.rest.client.message.GridClientStateRequest) GridRestAuthenticationRequest(org.apache.ignite.internal.processors.rest.request.GridRestAuthenticationRequest) GridClientTopologyRequest(org.apache.ignite.internal.processors.rest.client.message.GridClientTopologyRequest) GridRestRequest(org.apache.ignite.internal.processors.rest.request.GridRestRequest) GridClientCacheRequest(org.apache.ignite.internal.processors.rest.client.message.GridClientCacheRequest) Map(java.util.Map) EnumMap(java.util.EnumMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) GridClientTaskRequest(org.apache.ignite.internal.processors.rest.client.message.GridClientTaskRequest) Nullable(org.jetbrains.annotations.Nullable)

Example 5 with GridClientTopologyRequest

use of org.apache.ignite.internal.processors.rest.client.message.GridClientTopologyRequest in project ignite by apache.

the class TestBinaryClient method topology.

/**
 * @param includeAttrs Whether to include attributes.
 * @param includeMetrics Whether to include metrics.
 * @return Nodes.
 * @throws IgniteCheckedException In case of error.
 */
public List<GridClientNodeBean> topology(boolean includeAttrs, boolean includeMetrics) throws IgniteCheckedException {
    GridClientTopologyRequest msg = new GridClientTopologyRequest();
    msg.includeAttributes(includeAttrs);
    msg.includeMetrics(includeMetrics);
    return makeRequest(msg).getObject();
}
Also used : GridClientTopologyRequest(org.apache.ignite.internal.processors.rest.client.message.GridClientTopologyRequest)

Aggregations

GridClientTopologyRequest (org.apache.ignite.internal.processors.rest.client.message.GridClientTopologyRequest)7 GridClientNodeImpl (org.apache.ignite.internal.client.impl.GridClientNodeImpl)3 GridClientNodeBean (org.apache.ignite.internal.processors.rest.client.message.GridClientNodeBean)2 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 EnumMap (java.util.EnumMap)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 GridClientFutureAdapter (org.apache.ignite.internal.client.impl.GridClientFutureAdapter)1 GridClientAuthenticationRequest (org.apache.ignite.internal.processors.rest.client.message.GridClientAuthenticationRequest)1 GridClientCacheRequest (org.apache.ignite.internal.processors.rest.client.message.GridClientCacheRequest)1 GridClientClusterNameRequest (org.apache.ignite.internal.processors.rest.client.message.GridClientClusterNameRequest)1 GridClientClusterStateRequest (org.apache.ignite.internal.processors.rest.client.message.GridClientClusterStateRequest)1 GridClientClusterStateRequestV2 (org.apache.ignite.internal.processors.rest.client.message.GridClientClusterStateRequestV2)1 GridClientNodeStateBeforeStartRequest (org.apache.ignite.internal.processors.rest.client.message.GridClientNodeStateBeforeStartRequest)1 GridClientStateRequest (org.apache.ignite.internal.processors.rest.client.message.GridClientStateRequest)1 GridClientTaskRequest (org.apache.ignite.internal.processors.rest.client.message.GridClientTaskRequest)1 GridClientWarmUpRequest (org.apache.ignite.internal.processors.rest.client.message.GridClientWarmUpRequest)1 GridRestAuthenticationRequest (org.apache.ignite.internal.processors.rest.request.GridRestAuthenticationRequest)1