Search in sources :

Example 1 with AuthorizationException

use of backtype.storm.generated.AuthorizationException in project jstorm by alibaba.

the class DRPCSpout method nextTuple.

@Override
public void nextTuple() {
    boolean gotRequest = false;
    if (_local_drpc_id == null) {
        int size = 0;
        synchronized (_clients) {
            // This will only ever grow, so no need to worry about falling off the end
            size = _clients.size();
        }
        for (int i = 0; i < size; i++) {
            DRPCInvocationsClient client;
            synchronized (_clients) {
                client = _clients.get(i);
            }
            if (!client.isConnected()) {
                continue;
            }
            try {
                DRPCRequest req = client.fetchRequest(_function);
                if (req.get_request_id().length() > 0) {
                    Map returnInfo = new HashMap();
                    returnInfo.put("id", req.get_request_id());
                    returnInfo.put("host", client.getHost());
                    returnInfo.put("port", client.getPort());
                    gotRequest = true;
                    _collector.emit(new Values(req.get_func_args(), JSONValue.toJSONString(returnInfo)), new DRPCMessageId(req.get_request_id(), i));
                    break;
                }
            } catch (AuthorizationException aze) {
                reconnect(client);
                LOG.error("Not authorized to fetch DRPC result from DRPC server", aze);
            } catch (TException e) {
                reconnect(client);
                LOG.error("Failed to fetch DRPC result from DRPC server", e);
            } catch (Exception e) {
                LOG.error("Failed to fetch DRPC result from DRPC server", e);
            }
        }
        JStormServerUtils.checkFutures(_futures);
    } else {
        DistributedRPCInvocations.Iface drpc = (DistributedRPCInvocations.Iface) ServiceRegistry.getService(_local_drpc_id);
        if (drpc != null) {
            // can happen during shutdown of drpc while topology is still up
            try {
                DRPCRequest req = drpc.fetchRequest(_function);
                if (req.get_request_id().length() > 0) {
                    Map returnInfo = new HashMap();
                    returnInfo.put("id", req.get_request_id());
                    returnInfo.put("host", _local_drpc_id);
                    returnInfo.put("port", 0);
                    gotRequest = true;
                    _collector.emit(new Values(req.get_func_args(), JSONValue.toJSONString(returnInfo)), new DRPCMessageId(req.get_request_id(), 0));
                }
            } catch (TException e) {
                throw new RuntimeException(e);
            }
        }
    }
    if (!gotRequest) {
        Utils.sleep(1);
    }
}
Also used : TException(org.apache.thrift.TException) AuthorizationException(backtype.storm.generated.AuthorizationException) Values(backtype.storm.tuple.Values) DistributedRPCInvocations(backtype.storm.generated.DistributedRPCInvocations) TException(org.apache.thrift.TException) AuthorizationException(backtype.storm.generated.AuthorizationException) DRPCRequest(backtype.storm.generated.DRPCRequest)

Example 2 with AuthorizationException

use of backtype.storm.generated.AuthorizationException in project jstorm by alibaba.

the class ReturnResults method execute.

@Override
public void execute(Tuple input) {
    String result = (String) input.getValue(0);
    String returnInfo = (String) input.getValue(1);
    // LOG.info("Receive one message, resultInfo:{}, result:{}", returnInfo, result);
    if (returnInfo != null) {
        Map retMap = (Map) JSONValue.parse(returnInfo);
        final String host = (String) retMap.get("host");
        final int port = Utils.getInt(retMap.get("port"));
        String hostPort = host + ":" + port;
        String id = (String) retMap.get("id");
        DistributedRPCInvocations.Iface client;
        if (local) {
            client = (DistributedRPCInvocations.Iface) ServiceRegistry.getService(host);
        } else {
            List server = new ArrayList() {

                {
                    add(host);
                    add(port);
                }
            };
            if (!_clients.containsKey(server)) {
                try {
                    _clients.put(server, new DRPCInvocationsClient(_conf, host, port));
                } catch (TTransportException ex) {
                    throw new RuntimeException(ex);
                }
            }
            client = _clients.get(server);
        }
        try {
            client.result(id, result);
            _collector.ack(input);
        } catch (AuthorizationException aze) {
            LOG.error("Not authorized to return results to DRPC server " + hostPort, aze);
            _collector.fail(input);
            if (client instanceof DRPCInvocationsClient) {
                try {
                    LOG.info("reconnecting... ");
                    // Blocking call
                    ((DRPCInvocationsClient) client).reconnectClient();
                } catch (TException e2) {
                    throw new RuntimeException(e2);
                }
            }
        } catch (TException e) {
            LOG.error("Failed to return results to DRPC server " + hostPort, e);
            _collector.fail(input);
            if (client instanceof DRPCInvocationsClient) {
                try {
                    LOG.info("reconnecting... ");
                    // Blocking call
                    ((DRPCInvocationsClient) client).reconnectClient();
                } catch (TException e2) {
                    throw new RuntimeException(e2);
                }
            }
        }
    }
}
Also used : TException(org.apache.thrift.TException) AuthorizationException(backtype.storm.generated.AuthorizationException) ArrayList(java.util.ArrayList) DistributedRPCInvocations(backtype.storm.generated.DistributedRPCInvocations) TTransportException(org.apache.thrift.transport.TTransportException) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map)

Example 3 with AuthorizationException

use of backtype.storm.generated.AuthorizationException in project jstorm by alibaba.

the class ReturnResultsReducer method complete.

@Override
public void complete(ReturnResultsState state, TridentCollector collector) {
    // only one of the multireducers will receive the tuples
    if (state.returnInfo != null) {
        String result = JSONValue.toJSONString(state.results);
        Map retMap = (Map) JSONValue.parse(state.returnInfo);
        final String host = (String) retMap.get("host");
        final int port = Utils.getInt(retMap.get("port"));
        String id = (String) retMap.get("id");
        DistributedRPCInvocations.Iface client;
        if (local) {
            client = (DistributedRPCInvocations.Iface) ServiceRegistry.getService(host);
        } else {
            List server = new ArrayList() {

                {
                    add(host);
                    add(port);
                }
            };
            if (!_clients.containsKey(server)) {
                try {
                    _clients.put(server, new DRPCInvocationsClient(conf, host, port));
                } catch (TTransportException ex) {
                    throw new RuntimeException(ex);
                }
            }
            client = _clients.get(server);
        }
        try {
            client.result(id, result);
        } catch (AuthorizationException aze) {
            collector.reportError(aze);
        } catch (TException e) {
            collector.reportError(e);
        }
    }
}
Also used : DRPCInvocationsClient(backtype.storm.drpc.DRPCInvocationsClient) TException(org.apache.thrift.TException) AuthorizationException(backtype.storm.generated.AuthorizationException) ArrayList(java.util.ArrayList) DistributedRPCInvocations(backtype.storm.generated.DistributedRPCInvocations) TTransportException(org.apache.thrift.transport.TTransportException) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

AuthorizationException (backtype.storm.generated.AuthorizationException)3 DistributedRPCInvocations (backtype.storm.generated.DistributedRPCInvocations)3 TException (org.apache.thrift.TException)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 TTransportException (org.apache.thrift.transport.TTransportException)2 DRPCInvocationsClient (backtype.storm.drpc.DRPCInvocationsClient)1 DRPCRequest (backtype.storm.generated.DRPCRequest)1 Values (backtype.storm.tuple.Values)1